var emailAddress='';
var Ginterest='';
var gposition = '';
var ismultymedia = '';
var gPosY = null;

function useAjaxDependingOnBrowserTP(etfUrl, printUrl,pArchiveUrl, etfCoords, printCoords,pArchiveCoords, mapPosition, mapName)
{
	
	document.write("<map name=\""+mapName+"\">");
	document.write("<area shape=\"rect\" coords=\""+printCoords+"\" href=\""+printUrl+"\" >");
	document.write("<area shape=\"rect\" coords=\""+pArchiveCoords+"\" href=\""+pArchiveUrl+"\" >");
	
	document.write("<area shape=\"rect\" coords=\""+etfCoords+"\" href=\"javascript:showEtfForm(\'"+mapPosition+"\');\">");
	
	if (mapPosition =="bottom")
	{
		document.write("<area shape=\"rect\" coords=\"0,0,94,16\" href=\"#top\" >");
	}
	document.write("</map>");
}
function useAjaxDependingOnBrowser(etfUrl, printUrl, etfCoords, printCoords, mapPosition, mapName, interest)
{
//	alert(etfUrl+ "\n" +  printUrl+ "\n" + etfCoords+ "\n" +  printCoords+ "\n" +   mapPosition+ "\n" +  mapName);
	document.write("<map name=\""+mapName+"\">");
	document.write("<area shape=\"rect\" coords=\""+printCoords+"\" href=\""+printUrl+"\" >");
		document.write("<area shape=\"rect\" coords=\""+etfCoords+"\" href=\"javascript:showEtfForm(\'"+mapPosition+"\');\">");
	
	if (mapPosition =="bottom")
	{
		document.write("<area shape=\"rect\" coords=\"0,0,94,16\" href=\"#top\" >");
	}
	document.write("</map>");
	//return false;
}

/*************INIT THE MOUSE EVENT FOR FIREFOX*******************/
function initTheEvent(etfID)
{
//this element is declared in the page itself.I put the subscribe form on the page in between a div element that called:"subscribe1","subscribe2","subscribe3" 
var fobj = document.getElementById("etf_pop" + etfID);

		fobj.onmouseup= clickOnDiv; // update(event) implied on NS, update(null) implied on IE
	
 if (fobj.captureEvents) fobj.captureEvents(Event.MOUSEUP);
}
/**************USE THE MOUSE EVENT FOOR THE TOP AND LEFT OF THE POPUP*******************/
function clickOnDiv(e)
{
	var posx,posy;
	
	if (!e) e = window.event; // works on IE, but not NS (we rely on NS passing us the event)
 
  if (e)
  { 
	if (e.pageX || e.pageY)
	{
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{
		posy = e.clientY;
		if (detectBrowser()=="Internet Explorer")
		{
			posy += document.body.scrollTop;
		}
	}
  }
	gPosY = posy - 40 ;
	document.getElementById("etfAjaxPopup").style.top=posy - 40 + "px";
}

function showEtfForm(position,interest)
{
   gposition = position;
   document.getElementById("form1").elements[0].value="";   //("wi_recipmail")
    document.getElementById("form1").elements[1].value="";   //("wi_sendername")
    document.getElementById("form1").elements[2].value="";    //("wi_sendermail")
    document.getElementById("form1").elements[3].value="";     //("wi_sendmessage")
   document.getElementById("etfAjax_BgImage").style.height="400px";
   document.getElementById("AJAX_ETF_msg").className="etfAjaxText";
   document.getElementById("AJAX_ETF_closeBtn").style.display="none";
  
   document.getElementById("etfAjaxBg_png").style.visibility="visible";
 
 
 if (position=='top')
   {
   	document.getElementById("etfAjaxPopup").style.top="300px";
   }
   else
   {
 		document.getElementById("etfAjaxPopup").style.top=null;
   }
   if(ismultymedia == 'yes' && gposition=='top')//for SalomonSays and jewlariousMulti-media, which are with video component
   {
  	document.getElementById("etfAjaxPopup").style.top="0px";
	document.getElementById("etfAjaxPopup").style.left="500px";
  }
   document.getElementById("etfAjaxPopup").style.visibility="visible";
   document.getElementById("etfAjaxTopImg").style.visibility="visible";
   document.getElementById("form1").style.visibility="visible";
   document.getElementById("etfAjaxDisplayBlock").style.visibility="visible";
   document.getElementById("etfAjaxBottomImg").style.visibility="visible";
   document.getElementById("etfAjaxBottomImg").style.visibility="visible";
   document.getElementById("AJAX_ETF_msg").style.display="none";

}
function backToForm()
{
   //alert('backToForm()');
   document.getElementById("form1").style.visibility="visible";
   document.getElementById("etfAjaxBg_png").style.visibility="visible";
   document.getElementById("etfAjaxPopup").style.visibility="visible";
   document.getElementById("etfAjaxTopImg").style.visibility="visible";
   document.getElementById("AJAX_ETF_form").style.visibility="visible";
   document.getElementById("etfAjaxDisplayBlock").style.visibility="visible";
   document.getElementById("etfAjaxBottomImg").style.visibility="visible";
   document.getElementById("etfAjaxBottomImg").style.visibility="visible";
   document.getElementById("AJAX_ETF_msg").style.display="none";
}

var etfCbFunc = function etfShowResult(doc)
{
	
   var textObj= document.getElementById('AJAX_ETF_msg');
   if (doc.search(/Error/)==-1)
   {
	   //not error
       if (document.getElementById("form1").elements[1].value!="")   //("wi_sendername")
		{
			
			textObj.innerHTML = document.getElementById("form1").elements[1].value + ', '+ doc ;
		}
		else
		{

			var reEmAdd = insertCharInString(doc.substring(doc.lastIndexOf(':')+1)+' ',49,'<br>')
			var cutDoc = doc.substring(0,doc.lastIndexOf(':')+1)
			textObj.innerHTML = emailAddress + ', '+ cutDoc +reEmAdd;
		}
	document.getElementById("AJAX_ETF_closeBtn").style.display="block";
  }
   else
   {
	   document.getElementById("AJAX_ETF_msg").className="etfAjaxTextError";
	   document.getElementById("etfAjax_BgImage").style.height="465";
	   document.getElementById("form1").style.visibility="visible";
	   document.getElementById("etfAjaxBg_png").style.visibility="visible";
	   document.getElementById("etfAjaxPopup").style.visibility="visible";
	   document.getElementById("etfAjaxTopImg").style.visibility="visible";
	   document.getElementById("AJAX_ETF_form").style.visibility="visible";
	   document.getElementById("etfAjaxDisplayBlock").style.visibility="visible";
	   document.getElementById("etfAjaxBottomImg").style.visibility="visible";
	   document.getElementById("etfAjaxBottomImg").style.visibility="visible";
       textObj.innerHTML =  doc;
   }
   
   
}

function processETF()
{
   	var AJAX_ETF_form=document.form1;

   	AJAX_ETF_form.style.visibility="hidden";

	document.getElementById("etfAjaxDisplayBlock").style.visibility="hidden";
 	document.getElementById("AJAX_ETF_msg").style.visibility="visible";
   	document.getElementById("etfAjax_BgImage").style.height="200";
   	document.getElementById("AJAX_ETF_msg").className="etfAjaxText";
   	var textObj= document.getElementById('AJAX_ETF_msg');
   	textObj.innerHTML = 'Processing...';
   	document.getElementById("AJAX_ETF_msg").style.display="block";
   	document.getElementById("AJAX_ETF_msg").style.visibility="visible";
	
	var urlString= 'http://www.kiruv.com/components/print/emailToFriend.asp';
	if (AJAX_ETF_form.sendToSender.checked)
	{
		var sendToSender="yes";
	}
	else
	{
		var sendToSender="";
	}

	var queryString = 'title='+AJAX_ETF_form.title.value+'&path='+AJAX_ETF_form.title.value+
	                  '&articleNum='+AJAX_ETF_form.articleNum.value+'&articleURL='+AJAX_ETF_form.articleURL.value+
					  '&wi_recipmail='+AJAX_ETF_form.wi_recipmail.value+'&wi_sendername='+AJAX_ETF_form.wi_sendername.value+
					  '&wi_sendermail='+AJAX_ETF_form.wi_sendermail.value+'&sendToSender='+sendToSender+
					  '&wi_sendmessage='+AJAX_ETF_form.wi_sendmessage.value+'&sent='+AJAX_ETF_form.Sent.value+'&ajax=yes';
	emailAddress=document.getElementById("form1").elements[2].value;
   	//textObj.innerHTML = 'Processing...' + "\n" + urlString + "?" + queryString;
	
    AJAX_submitForm(urlString+'?'+queryString, '', 'GET', etfCbFunc);
	
	
}

function hideEtfPopup() 
{
	document.getElementById("etfAjaxBg_png").style.visibility="hidden";
	document.getElementById("etfAjaxPopup").style.visibility="hidden";
   document.getElementById("etfAjaxTopImg").style.visibility="hidden";
   document.getElementById("AJAX_ETF_form").style.visibility="hidden";
   document.getElementById("etfAjaxDisplayBlock").style.visibility="hidden";
   document.getElementById("etfAjaxBottomImg").style.visibility="hidden";
   document.getElementById("AJAX_ETF_msg").style.display="none";
   document.getElementById("form1").style.visibility="hidden";
   document.getElementById("AJAX_ETF_closeBtn").style.display="none";
   if(ismultymedia == 'yes' && gposition=='top'){
	document.getElementById("etfAjaxPopup").style.left="200px";
  }
   document.getElementById("etfAjaxPopup").style.left = "200px"

}

function setEtfData(emailContent, title, articleNum/*, articleURL*/)
{
	
	document.getElementById("AJAX_ETF_form_header").innerHTML="E-mail this " + emailContent+":<br />"+title;
    document.getElementById("form1").elements[8].value=articleNum;     //("articleNum")
	
}

