/*********Global variables*************/
var emailAddress = '';
var gcategory = '';
var gGraphicClickedOn =' ';
var frmclickedonObj = '';

/*******ARRAY FOR THE DIFFERENT STYLES OF THE FORM****/
var arrStyleofForms = new Array();
arrStyleofForms[0] = new Array();
//0=lower_ppg lower_momBlog,1=lower_article,2=homePage_top
arrStyleofForms[0][0] = "<TD nowrap align=right width=\"50%\" bgcolor=\"#7098E8\">";
arrStyleofForms[0][1] = "<TD nowrap align=left width=\"50%\" bgcolor=#7098E8 valign=\"bottom\"><input name=\"lower_article\" type=\"image\" id=submit src=\"http://www.aish.com/graphics/nav/buttonJoin_59x27.gif\" alt=\"Join\" align=\"bottom\" width=59 height=27 hspace=2 vspace=0 border=0> <span style=\'font-size:10px;color:#eeeeee;font-family:Verdana, Arial\'>Your email address is kept private.</span></TD>";
arrStyleofForms[1] = new Array();
arrStyleofForms[1][0] = "<TD nowrap align=right width=\"50%\">";
arrStyleofForms[1][1] = "<TD nowrap align=left width=\"50%\"  valign=\"bottom\" style=\"padding-top:3px;\">\&nbsp\;<input type=\"image\"  align=\"bottom\" width=136 height=19 hspace=2 vspace=0 border=0 src=\"http://www.aish.com/graphics/nav/subscribe136x19.gif\" width=136 height=19 alt=\"Subscribe for Free\" border=\"0\"></TD>";
/*********************************************************/


/*************INIT THE MOUSE EVENT FOR FIREFOX*******************/
function init(subsID)
{
//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("subscribe" + subsID);
 fobj.onmouseup = clicktest; // 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 clicktest(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 );
		}
	}
  }



	document.getElementById("ajax_subscribe_popup").style.top=posy - 40 + "px";
	document.getElementById("ajax_subscribe_popup").style.left=posx - 150 + "px";
	
	return false;
}


function SUBSCRIBE_FUNCS_JS_ShowPopupDependOnBrowser(category,GraphicClickedOn,adType,formName,Mychosen)
{
	gcategory = category;
	gGraphicClickedOn=GraphicClickedOn;
	frmclickedonObj = formName;

	//right article side bar, jewlarious:page_main,lower article: setting the event of the clicking on the form to set the top and left of the popup, there.
	if(formName == 'HomePage_subscribe_email_form' || formName == 'right_article_subscribe_email_form_2' || formName == 'jewlarious_quiz' || formName == 'right_article_subscribe_email_form_1' || formName == 'lower_SSI_subscribe_email_form' || formName=='movies')
		{
			if (detectBrowser() == "Internet Explorer")//IN IE THE EVENT IS SENDED TO THE FUNCTIOON WHEN YOU CLICK ON THE ELEMENT 
			{
						document.write("<form  id=\""+formName+"\" name=\""+formName+"\"  action=\"javascript:showEmailConfirmationForm(\'"+formName+"\');\" method=\"post\"  onSubmit=\"javascript:clicktest();\" >");
			}
			
			else//FOR FIREFOX WE NEED TO DECLARE THE EVENT BEFORE THE CLICKING ON THE ELEMENT
			{			//those id's of div's elements are declared in the following pages,
						
						//on the right_article_side_bar-upper box
						if(formName == 'right_article_subscribe_email_form_1') var subs_id = 1;
						//on the right_article_side_bar-lower box ,jewlarious:page_main
						else if(formName == 'right_article_subscribe_email_form_2') var subs_id = 2;
						//on the lower of the articles:simple,blogs,jewlarious
						else if(formName == 'lower_SSI_subscribe_email_form') var subs_id = 3;
						//on the jewlarious quiz
						else if(formName == 'jewlarious_quiz') var subs_id = 4;
						//on the movies
						else if(formName == 'movies') var subs_id = 5
						//on the homepage
						else if(formName == 'HomePage_subscribe_email_form') var subs_id = 6
						init(subs_id);
						document.write("<form  id=\""+formName+"\" name=\""+formName+"\"  action=\"javascript:showEmailConfirmationForm(\'"+formName+"\');\" method=\"post\"   >");
			}
		}
	else if (formName == 'his_pop_subscribe_email_form')
	{
			//alert("shown");
			document.write("<form id=\""+formName+"\" name=\""+formName+"\"  action=\"javascript:proccessSubDayInJewishHistory(\'"+formName+"\');\" method=\"post\">");

	}
	else
		{
			document.write("<form id=\""+formName+"\" name=\""+formName+"\"  action=\"javascript:showEmailConfirmationForm(\'"+formName+"\');\" method=\"get\">");
		}
		//the elements of the form for the lower articles
	//if(gcategory != 'page_header' && gcategory != 'home_page' && formName != 'right_article_subscribe_email_form_1' && formName!= 'podcast_text_subscribe_email_form' && formName != 'right_article_subscribe_email_form_2' && formName != 'jewlarious_Top_subscribe_email_form' && formName != 'jewlarious_HomePage_Top_subscribe_email_form' )
	  if(formName == 'lower_SSI_subscribe_email_form')	
		{
			//upper style of form according to the place that it comes from
			if(gcategory =='ppg' || gcategory =='momblog')
			{
				
				document.write(arrStyleofForms[0][0]);
			}
			
			else //regular lower_article
			{
				
				document.write(arrStyleofForms[1][0]);
			}
			document.write("<INPUT onblur=\"if(this.value==\' \') {this.value=\'email\';}\" onfocus=\"if(this.value==\'email\') {this.value=\' \';}\" size=13 value=email name=email id=\"subsemail\" type=\"text\"></TD>") ;
			document.write("<input NAME=\"chosen\" VALUE=\""+Mychosen+"\" type=\"hidden\">");
			document.write("<input type=\"hidden\" name=\"subscribe\" value=\"y\">");
			document.write("<input NAME=\"weeklyUpdateGraphicClickedOn\" VALUE=\""+gGraphicClickedOn+"\" type=\"hidden\" >");
			document.write("<input NAME=\"adType\" VALUE=\""+adType+"\" type=\"hidden\" >");
			document.write("<input type=hidden name=hasJS value=\"1\">");
			document.write("<input type=hidden name=hasFlash value=\"1\">");
			//alert(Mychosen);
			//bottom style of form according to the place that it comes from
			if(gcategory =='ppg' || gcategory =='momblog')
			{
				
				document.write(arrStyleofForms[0][1]);
			}
			else//regular lower article	
			{
				
				document.write(arrStyleofForms[1][1]);
				
			}
			document.write("</form>");
		}//close 'if' : if it  comes from lower articles
		
}

var userCbFunc = function showResult(Doc)
{
   document.getElementById("ajax_subscribe_popup").style.visibility="visible";
    document.getElementById("ajax_subscribe_popup_msg").style.visibility="hidden";
  // alert('textObj');
   var textObj= document.getElementById('AJAX_SUBS_msg');
 
// alert(subscribeResultDoc);
   textObj.innerHTML = emailAddress + ', '+ Doc ;
   //alert(textObj.innerHTML);
     document.getElementById('AJAX_SUBS_msg').style.display="block";
     document.getElementById('AJAX_SUBS_msg').style.visibility="visible";
	 //alert("close");
	document.getElementById("AJAX_popup_closeBtn").style.display="block";
	document.getElementById("AJAX_popup_closeBtn").style.visibility="visible";
}

function processMovies(frmclickedon)
{
}

function showEmailConfirmationForm(frmclickedon)
{
   frmclickedonObj = frmclickedon;
    document.getElementById("subscribeTop").style.visibility="visible";
   document.getElementById("subscribeTop").style.display="block";

   document.getElementById("subscribeBtm").style.visibility="visible";
  document.getElementById("subscribeBtm").style.display="block";

   document.getElementById("ajax_subscribe_popup").style.visibility="visible";
   document.getElementById("ajax_subscribe_popup").style.display="block";
   
   document.getElementById("ajax_subscribe_popup_msg").innerHTML='Please check that your email address is correct.';
   document.getElementById("ajax_subscribe_popup_msg").style.display="block";
   document.getElementById("ajax_subscribe_popup_msg").style.visibility="visible";
   document.getElementById("ajax_subscribe_popup_txtbx").innerHTML='<INPUT onblur=\"if(this.value==\'\') {this.value=\'email\';}\"onfocus=\"if(this.value==\'email\') {this.value=\'\';}\" size=13 value=\"email\" name=\"email\" type=\"text\">'
   document.getElementById("ajax_subscribe_popup_txtbx").style.display="block";
   document.getElementById("ajax_subscribe_popup_txtbx").style.visibility="visible";
   document.getElementById("ajax_subscribe_popup_btn").style.display="block";
    document.getElementById("ajax_subscribe_popup_btn").style.visibility="visible";
  
  
 
    if(frmclickedon == 'page_header_subscribe_email_form' )
    {
	   document.getElementById("ajax_subscribe_popup").style.top="0px";
	   document.getElementById("ajax_subscribe_popup").style.left="400px";
	}
	
	else if(frmclickedon == 'HomePage_subscribe_email_form')
	{
		document.getElementById("ajax_subscribe_popup").style.top="0px";
	   document.getElementById("ajax_subscribe_popup").style.left="400px";
	}
	
	else if(frmclickedon == 'jewlarious_HomePage_Top_subscribe_email_form')
	{
		document.getElementById("ajax_subscribe_popup").style.top="0px";
	   document.getElementById("ajax_subscribe_popup").style.left="500px";
	}
	else if(frmclickedon == 'movies')
	{
		document.getElementById("movielist").style.visibility="hidden";
	}
   
  
  document.getElementById("ajax_confirm_email_form").email.value = document.getElementById(frmclickedonObj).email.value ;

   
}

function processSubscribe()
{
   //alert("processSubscribe");
   document.getElementById("ajax_subscribe_popup_txtbx").style.display="none";
   document.getElementById("ajax_subscribe_popup_btn").style.display="none";
  emailAddress = document.getElementById("ajax_confirm_email_form").email.value ;
   emailAddress.replace(" ","");
  var frmObj = document.getElementById(frmclickedonObj);
 
 //alert(frmObj.chosen.value);
  var textObj= document.getElementById('ajax_subscribe_popup_msg');
   textObj.innerHTML = 'Processing...';
	var urlString= 'http://www.aish.com/lists/subscribeEmail.asp';
//	alert(urlString);
	//emailAddress=document.getElementById("ajax_confirm_email_form").email.value;
	//alert(emailAddress);
	var queryString = 'email='+emailAddress+'&adType='+frmObj.adType.value+'&chosen='+frmObj.chosen.value+
					  '&weeklyUpdateGraphicClickedOn='+frmObj.weeklyUpdateGraphicClickedOn.value+
					  '&subscribe=y&hasJS=1&hasFlash=1&ajaxMethod=true';
    if (gcategory == 'wallcam_home_page') queryString  =queryString +'&submitwallajax=yes';
	//if(frmclickedonObj == 'lower_SSI_subscribe_email_form') document.write(urlString+'?'+queryString)																									
	//alert(queryString);
	//http://www.aish.com/lists/subscribeEmail.asp?email=sgoldberg%40aish.com&lower_article.x=73&lower_article.y=19&chosen=28&subscribe=y&adType=28-article_right_side_bar&weeklyUpdateGraphicClickedOn=28-article_right_side_bar&textOnly=0
	subscribeAsync(urlString, queryString, userCbFunc, emailAddress);
	//AJAX_submitForm(urlString+'?'+queryString, '', 'GET', userCbFunc);
}

function hidePopup()
{


  document.getElementById("ajax_subscribe_popup").style.visibility="hidden";
  document.getElementById("subscribeTop").style.visibility="hidden";
    document.getElementById("subscribeBtm").style.visibility="hidden";
  document.getElementById("ajax_subscribe_popup_msg").style.display="none";
   document.getElementById("ajax_subscribe_popup_btn").style.display="none";
   document.getElementById("ajax_subscribe_popup_btn").style.visibility="hidden";

document.getElementById("ajax_subscribe_popup_txtbx").style.display="none";
document.getElementById("ajax_subscribe_popup_txtbx").style.visibility="hidden";

document.getElementById("AJAX_popup_closeBtn").style.display="none";
document.getElementById("AJAX_popup_closeBtn").style.visibility="hidden";

   document.getElementById("AJAX_SUBS_msg").style.visibility="hidden";
   document.getElementById("AJAX_SUBS_msg").style.display="none";
   
   document.getElementById("img_midd_subs").style.height="125px";
  if(gcategory.indexOf('jewlarious') != -1 ) 
			{//alert(gcategory);
   document.getElementById("img_midd_subs").style.height="150px";}
   
    if(document.getElementById("movielist")!=null)
	{
		document.getElementById("movielist").style.visibility="visible";
	}

}
/**********************************************************************
PROCCESSING THE SUBSCRIPTION FOR DAY IN JEWISH HISTORY ON THE HOME PAGE
***********************************************************************/
function proccessSubDayInJewishHistory(frmclickedon)
{
   //alert("showEmailConfirmationForm");
	 var frmObj = document.getElementById(frmclickedon);
	 emailAddress = frmObj.email.value ;
	 emailAddress.replace(" ","");
	 
	 document.getElementById('his_subscribe_frm').style.display="none";
	 var textObj= document.getElementById('text_for_subscription');
	 textObj.style.display="block";
	 //textObj.innerHTML = 'Processing...';
	 textObj.innerHTML = "<table width=300 border=1 cellpadding=15 cellspacing=0 bgcolor=#FFCC00 bordercolor=#CC6600> <tr> <td style=\"font-size:18px; font-weight:600;color:#CC6600;\">Processing ... please wait.</td> </tr></table>";
		
	 var urlString= 'http://www.aish.com/lists/subscribeEmail.asp';

	 var queryString = 'email='+emailAddress+'&adType='+frmObj.adType.value+'&chosen='+frmObj.chosen.value+
					  '&weeklyUpdateGraphicClickedOn='+frmObj.weeklyUpdateGraphicClickedOn.value+
					  '&subscribe=y&hasJS=1&hasFlash=1&ajaxMethod=true';
	 subscribeAsync(urlString, queryString, userCbFuncFor_his_pop, emailAddress);
				  
   
}

/**********************************************************************************
THE SHOW RESULT FUNCTION OF THE SUBSCRIPTION TO DAY IN JEWISH HISTORY ON HOME -PAGE
***********************************************************************************/
	
var userCbFuncFor_his_pop = function showResult(Doc)
{
	 var textObj = document.getElementById('text_for_subscription');
	 
	 
	 textObj.innerHTML = "<table width=300 border=1 cellpadding=15 cellspacing=0 bgcolor=#66FF33 bordercolor=#336600><tr><td style=\"font-size:18px; font-weight:600; color:#336600; \">"+emailAddress + ',<BR> '+ Doc+"</td> </tr></table>";

	// setTimeout('backToHisPop()', 3000);
	 
}
