// JavaScript Document
var time_variable;
var responseType = "alert";
var responseObj = "";
function emailCheck(emailId)
{
	if(emailId.value == "" || emailId.value.indexOf("@",1)==-1 || emailId.value.indexOf(".",0)==-1) 	return false;
	
	var iChars ="*|,\":<>[]{}`\';()&$#%/";
	for (var i = 0;i< emailId.value.length;i++) 
	{
	  if (iChars.indexOf(emailId.value.charAt(i)) != -1) return false;
	}
	return true;
}

function getXMLObject()  //XML OBJECT
{
   var xmlHttpObj = false;
   try {xmlHttpObj = new ActiveXObject("Msxml2.XMLHTTP")  /* For Old Microsoft Browsers */  }
   catch (e) {
     try {xmlHttpObj = new ActiveXObject("Microsoft.XMLHTTP")  /* For Microsoft IE 6.0+ */   }
     catch (e2) {xmlHttpObj = false   /* No Browser accepts the XMLHTTP Object then false */  }
   }
   
   if (!xmlHttpObj && typeof XMLHttpRequest != 'undefined') { xmlHttpObj = new XMLHttpRequest(); /*For Mozilla, Opera Browsers*/ }
   
   return xmlHttpObj;  // Mandatory Statement returning the ajax object created
}
 
var xmlHttp = new getXMLObject();	//xmlhttp holds the ajax object

function ajaxFunction( postValue , postPage) {
  var getdate = new Date();  //Used to prevent caching during ajax call
  if(xmlHttp) {
    xmlHttp.open("POST",postPage,true); //calling testing.php using POST method
    xmlHttp.onreadystatechange  = handleServerResponse;
    xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlHttp.send(postValue); //Posting txtname to PHP File
  }
}

function handleServerResponse() {
	if(xmlHttp.readyState == 1){}
	else if (xmlHttp.readyState == 2){}
	else if (xmlHttp.readyState == 3){}
	else if (xmlHttp.readyState == 4){ 	
		if(responseType == "alert" || responseType == "" ){ alert(xmlHttp.responseText); }
		else if( responseType == "popup" ){ document.getElementById(responseObj).innerHTML =xmlHttp.responseText;  callpopup(responseObj); }
		else{
			if(document.getElementById(responseObj)){
				if(document.getElementById(responseObj).innerHTML){document.getElementById(responseObj).innerHTML =xmlHttp.responseText; }
				else{
					if(document.getElementById(responseObj).innerText ){document.getElementById(responseObj).innerText  =xmlHttp.responseText; }
					else{
						if(document.getElementById(responseObj).value ){document.getElementById(responseObj).value  =xmlHttp.responseText; }	
						else{alert("Error during AJAX call response. Please try again");}
					}
				}
			}
		}
	}
}

function chkNL(VerifyEmail){ 	 
if(emailCheck(VerifyEmail)){
	responseType = "popup";
	responseObj = "divSubscriberACT";
	var postValue = "email=" + VerifyEmail.value+"&section=NW";
	if  (document.getElementById("cmbBlack")){
		if  (document.getElementById("cmbBlack").style.display=="block"){postValue = postValue + "&Black=B";}
	}
	 
	var postPage = "subscribe.php";
	ajaxFunction(postValue,postPage);
 }
 else{
	 alert ("Please enter a valid email");
	 VerifyEmail.focus();
	 return false;
 }  
}		
 
function chkSP(CatchID){  
  var EmailId = document.getElementById(CatchID);
  if(EmailId.value=="" || (EmailId.value.indexOf("@",3)==-1) || (EmailId.value.indexOf(".",0)==-1))
	{
		alert ("Please enter a valid email");
		EmailId.focus();
		return false;
	}

  	var iChars ="*|,\":<>[]{}`\';()&$#%/";
	for (var i = 0;i<EmailId.value.length;i++) 
	{
	  if (iChars.indexOf(EmailId.value.charAt(i)) != -1)
	  {
		  alert ("Please enter a valid email");
		  EmailId.focus(); 
		  return false;
	  }
	}
	return true;
}

function callpopup(popUpId){
	embeds = document.getElementsByTagName('embed');
	for(i = 0; i < embeds.length; i++) {
	embeds[i].style.visibility = 'hidden';
	}
	objects = document.getElementsByTagName('object');
	for(i = 0; i < objects.length; i++) {
	objects[i].style.visibility = 'hidden';
	}
	var popWidth=300;
	 
	//Fade in the Popup and add close button
	$('#' + popUpId).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="images/close_pop30.png" border="0" class="btn_close" title="Close Window" alt="Close" /><\/a>');

	//Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
	var popMargTop = ($('#' + popUpId).height() + 80) / 2;
	var popMargLeft = ($('#' + popUpId).width() + 80) / 2;

	//Apply Margin to Popup
	$('#' + popUpId).css({
		'margin-top' : -popMargTop,
		'margin-left' : -popMargLeft
	});

	//Fade in Background
	$('body').append('<div id="fade"><\/div>'); //Add the fade layer to bottom of the body tag.
	$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies 

	return false;
}


