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					

	}

function chk_ref_code()
{
	browser=navigator.userAgent.toLowerCase();
	//alert (browser);
	if (document.getElementById("txt_name").value=="")
	{
		alert ("Please enter name");
		document.getElementById("txt_name").focus();
		return false;
	}
	if (document.getElementById("txt_lname").value=="")
	{
		alert ("Please enter last name");
		document.getElementById("txt_lname").focus();
		return false;
	}
	if (document.getElementById("txt_cname").value=="")
	{
		alert ("Please enter company name");
		document.getElementById("txt_cname").focus();
		return false;
	}
	if (document.getElementById("txt_uname").value=="")
	{
		alert ("Please enter user name");
		document.getElementById("txt_uname").focus();
		return false;
	}
	if (document.getElementById("txt_password").value=="")
	{
		alert ("Please enter password");
		document.getElementById("txt_password").focus();
		return false;
	}
	if (document.getElementById("txt_cpassword").value=="")
	{
		alert ("Please enter confirm password");
		document.getElementById("txt_cpassword").focus();
		return false;
	}
	if (document.getElementById("txt_cpassword").value!=document.getElementById("txt_password").value)
	{
		alert ("Password mismatch");
		document.getElementById("txt_cpassword").value="";
		document.getElementById("txt_cpassword").focus();
		return false;
	}
	if (document.getElementById("txt_email").value=="")
	{
		alert ("Please enter emailID");
		document.getElementById("txt_email").focus();
		return false;
	}
	var emailID=document.getElementById("txt_email")
	
	if (echeck(emailID.value)==false){

		emailID.value=""

		emailID.focus()

		return false
	}
	if (document.getElementById("txt_cemail").value=="")
	{
		alert ("Please enter confirm emailID");
		document.getElementById("txt_cemail").focus();
		return false;
	}
	if (document.getElementById("txt_email").value!=document.getElementById("txt_cemail").value)
	{
		alert ("Email IDs mismatch");
		document.getElementById("txt_cemail").value="";
		document.getElementById("txt_cemail").focus();
		return false;
	}
	if (document.getElementById("txt_ph").value=="")
	{
		alert ("Please enter phone");
		document.getElementById("txt_ph").focus();
		return false;
	}
	if (document.getElementById("txt_add").value=="")
	{
		alert ("Please enter address");
		document.getElementById("txt_add").focus();
		return false;
	}
	if (document.getElementById("txt_city").value=="")
	{
		alert ("Please enter city");
		document.getElementById("txt_city").focus();
		return false;
	}
	if (document.getElementById("txt_county").value=="")
	{
		alert ("Please enter country");
		document.getElementById("txt_county").focus();
		return false;
	}
	if (document.getElementById("txt_pin").value=="")
	{
		alert ("Please enter Postcode/Zip code");
		document.getElementById("txt_pin").focus();
		return false;
	}
	if (document.getElementById("txt_country").value=="")
	{
		alert ("Please select country");
		document.getElementById("txt_country").focus();
		return false;
	}
	if (document.getElementById("termconditions").checked!=true)
	{
		alert ("Please accept terms and conditions");
		return false;
	}

	var ref_code_no=document.getElementById("txt_ref_code").value;
	var xmlhttp=false;
	if(ref_code_no=="")
	{
		var frm=document.getElementById("frm_reg"); 
		frm.submit();
	}
	else			{
		//create browser specific objects
		
		
		if(browser.indexOf("msie")!=-1)
		{
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		else
		{
			xmlhttp=new XMLHttpRequest();
		}

		loginurl="chk_ref_code.php?txt_ref_code_no="+ref_code_no;
		xmlhttp.open("GET",loginurl,true);
		xmlhttp.send(null);
		xmlhttp.onreadystatechange=function()
		{
			if(xmlhttp.readyState==4)
			{
				var result=xmlhttp.responseText;
				//alert (result);
				if(result>0)
				{
					window.status="";
					var frm=document.getElementById("frm_reg"); 
					frm.submit();
				}
				else
				{
					window.status="";
					alert("Invalid Promo code");
				}
			}
			else
			{
				window.status="Please wait while the coede is being validated";
			}
		} 
	}
}
