var IEloadingimgtop = 0;
var setonce = 0;

function ajaxFunction()
{
	document.getElementById("loadingimg").style.visibility = "visible";

	var xmlHttp;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");

			if(setonce == 0)
			{
				document.getElementById("loadingimg").style.top = (IEloadingimgtop + 147) + "px"
				IEloadingimgtop = 28;
				setonce = 1
			}
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");

				if(setonce == 0)
				{
					document.getElementById("loadingimg").style.top = (IEloadingimgtop + 147) + "px"
					IEloadingimgtop = 28;
					setonce = 1
				}
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			document.getElementById("loadingimg").style.visibility = "hidden";

			document.getElementById("resulttext").innerHTML = "Thank you for signing up.<br />You can enter another email address below.";
			document.signupform.email.value = "";

			document.getElementById("loadingimg").style.top = (134 + IEloadingimgtop) + "px";
		}
	}
	rqst = new String();
		
	rqst = "requestfile.jsp?";
	rqst = rqst + "e=" + document.signupform.email.value;

	xmlHttp.open("POST",rqst,true);
	xmlHttp.send(null);
}

function validate()
{
msg = "";
email = document.signupform.email.value;

if(email.length==0){
	msg = "Please enter your email address";
	document.signupform.email.focus();
   }

else if(!check_email(email)){
	msg = "Please enter a valid email address";
	document.signupform.email.select();
   }

if (msg.length==0){

	document.getElementById("validate_responce").innerHTML = ""

	ajaxFunction()
	}

else
 { 
	//alert(msg);
	document.getElementById("validate_responce").innerHTML = msg;
 }
}

function check_email(e){
  ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
  for(i=0; i < e.length ;i++){
	  if(ok.indexOf(e.charAt(i))<0){
		  return (false);
		}	
	}	 

  if (document.images){
	  re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
	 re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;

	 if (!e.match(re) && e.match(re_two)){
		 return (-1);		
		} 
	}
}