var emailAddress='';
var Ginterest='';
var gposition = '';
var ismultymedia = '';
var gPosY = null;

function useAjaxDependingOnBrowserTP(etfUrl, printUrl,pArchiveUrl, etfCoords, printCoords,pArchiveCoords, mapPosition, mapName)
{
	//alert(mapPosition+", "+etfCoords+", "+printCoords+", ");
	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>");
	//return false;
}
function useAjaxDependingOnBrowser(etfUrl, printUrl, etfCoords, printCoords, mapPosition, mapName, interest)
{
	Ginterest = interest;
	if (printUrl.indexOf('jewlariousMultiMedia') != -1 || Ginterest == 'salomonSays') 
	{
		ismultymedia = 'yes';
	}
	//alert(mapPosition+", "+etfCoords+", "+printCoords+", ");
	document.write("<map name=\""+mapName+"\">");
	document.write("<area shape=\"rect\" coords=\""+printCoords+"\" href=\""+printUrl+"\" >");
	//alert(detectBrowser());
	//if (detectBrowser() =="Safari")
	//{
		//document.write("<area shape=\"rect\" coords=\""+etfCoords+"\" href=\""+etfUrl+"\" >");
	//}
	//else
	//{
		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);
//alert("init");  
}
/**************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)
	{
		//alert("page");
		//posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{
		//alert("client");
		//posx = e.clientX;
		posy = e.clientY;
		if (detectBrowser()=="Internet Explorer")
		{//alert("body");
			//posx += document.body.scrollLeft;
			//alert(posx );
			posy += document.body.scrollTop;
			//alert(posy );
		}
	}
  }
	gPosY = posy - 40 ;
	document.getElementById("etfAjaxPopup").style.top=posy - 40 + "px";
	//alert(gPosY);
	//return false;
}

function showEtfForm(position,interest)
{
  // alert('showetfinns7');
   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";
  //interest = salomonSays
  
   document.getElementById("etfAjaxBg_png").style.visibility="visible";
 
 if (Ginterest == 'dayInJewishHistory') 
 {
	 document.getElementById("etfAjaxPopup").style.top="300px";
	 document.getElementById("etfAjaxPopup").style.left="450px";
 }
 
 if (position=='top')
   {
   	document.getElementById("etfAjaxPopup").style.top="300px";
   }
    else if (position == '0' )//for jokes.asp and comix.asp:first joke
   {
 		document.getElementById("etfAjaxPopup").style.top=gPosY + "px";
   }
   else if (position == '1' || position == '2')//2nd and 3 jokes
   {
	   document.getElementById("etfAjaxPopup").style.top=(gPosY - 200 )+ "px";
   }
	else if  (position=='bottomJoke') //for  single joke
   {
 		//document.getElementById("etfAjaxPopup").style.top="300px";
		document.getElementById("etfAjaxPopup").style.top=(document.body.scrollHeight - 465 - 140 )+ "px";

   }   
   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";

//   lower_ssi_confirm_email_form.email.value=lower_SSI_subscribe_email_form.email.value;
}
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";
  // document.getElementById("AJAX_ETF_backBtn").style.visibility="hidden";

//   lower_ssi_confirm_email_form.email.value=lower_SSI_subscribe_email_form.email.value;
}

var etfCbFunc = function etfShowResult(doc)
{
	
  // alert('in showResult');
   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";
    //document.getElementById("AJAX_ETF_backBtn").style.visibility="visible";
  }
   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";
       //document.getElementById("AJAX_ETF_backBtn").style.visibility="visible";
	   textObj.innerHTML =  doc;
   }
   
   
}

function processETF()
{
   var AJAX_ETF_form=document.form1;
   //alert('document.form1');

   AJAX_ETF_form.style.visibility="hidden";
  //document.getElementById("etfAjaxDisplayBlock").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.aish.com/components/print/emailToFriend.asp';
	if (AJAX_ETF_form.sendToSender.checked)
	{
		var sendToSender="yes";
	}
	else
	{
		var sendToSender="";
	}

   //if (AJAX_ETF_form.articleNum.value==8057) alert(AJAX_ETF_form.articleNum.value);
	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&isJoke='+AJAX_ETF_form.isJoke.value+'&isComic='+AJAX_ETF_form.isComic.value+
					  '&historyMonth='+AJAX_ETF_form.historyMonth.value+'&historyDay='+AJAX_ETF_form.historyDay.value;
	queryString = queryString.replace(/ /g,'+');		
    /* if (document.getElementById("form1").elements[8].value == 1)
	 {
		 document.write(urlString+'?'+queryString);
	 }*/
	//alert(queryString);
	//if (AJAX_ETF_form.articleNum.value==8057) document.write(urlString+'?'+queryString);
	emailAddress=document.getElementById("form1").elements[2].value;
    AJAX_submitForm(urlString+'?'+queryString, '', 'GET', etfCbFunc);
	//AJAX_ETF_form.submitBtn.disabled=true;
	
	
}

function hideEtfPopup() 
{
//alert('hiding popup');
	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"
   //document.getElementById("AJAX_ETF_closeBtn").style.visibility="hidden";

}

function setEtfData(emailContent, title, articleNum/*, articleURL*/)
{
	
	document.getElementById("AJAX_ETF_form_header").innerHTML="E-mail this " + emailContent+":<br />"+title;
	//document.getElementById("articleNum").value=articleNum;
	//document.getElementById("title").value=title;
	if (articleNum ==1) //for the day in jewish history
    	{
			Ginterest = 'dayInJewishHistory';
			document.getElementById("form1").elements[6].value=title;     //("title")
		}
		
    document.getElementById("form1").elements[8].value=articleNum;     //("articleNum")
    //document.getElementById("form1").elements[11].value=articleURL;     //("articleURL")
	
	//for day in jewish history email 
	
}

