function Ajax_News_Letter_SignUp()	{
		var flg_news = Validate_News_Letter_Email() ;
		if(flg_news == false) return false;		
		xmlHttp=GetXmlHttpObject();			
		if(xmlHttp == null) {
			alert("Browser doesnt support ajax");
			return;
		}
		var url="Ajax_News_Letter_SignUp.php?eid=" + document.getElementById('news_email').value;
		xmlHttp.onreadystatechange=Ajax_News_Letter_SignUp_response;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
		return false;
}

function Ajax_News_Letter_SignUp_response() 
{
	if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete") 
	{
		response=xmlHttp.responseText;
		alert(response);
		RemoveLightBox();
		return false;
	}
}

function DisplayLightBox ()	{
	document.getElementById('fade').style.display='block';
	document.getElementById('light').style.display='block';
	document.getElementById('news_email').focus();
	arrayPageSizeWithScroll = getPageSizeWithScroll();
	document.getElementById('fade').style.height = arrayPageSizeWithScroll[1] + "px";
	return false;
}

function getPageSizeWithScroll(){
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	//alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
	return arrayPageSizeWithScroll;
}

function key_event(evt)
{
    if(evt == 27) 
		RemoveLightBox(); 
    if(evt == 13) 
		Ajax_News_Letter_SignUp(); 
}

function RemoveLightBox ()	{
	document.getElementById('fade').style.display='none';
	document.getElementById('light').style.display='none';
	return false;
}

function Validate_News_Letter_Email(){
	var emailID=document.getElementById('news_email');
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
}

function echeck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
}
