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 checkemail(){
	var emailID=document.regform.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;
	}
	
	
if(window.XMLHttpRequest){
oRequest = new XMLHttpRequest();
}
else if(window.ActiveXObject){
oRequest = new ActiveXObject("MMSXML2.ServerXMLHTTP");

}

oRequest.open("POST", "check.asp", true);
oRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
oRequest.send("flag=check&stremail=" + document.regform.email.value);

oRequest.onreadystatechange = UpdateCheckAvailability;

}



function UpdateCheckAvailability(){
var emailID = document.regform.email
var str = eval(oRequest.responseText)

if(oRequest.readyState == 4 && oRequest.status == 200){

if 	(str == 1) {

alert('Email Address Already in Database, Please Use forgot Password Link to retrieve your password.')
document.regform.submitreg.disabled = true;
document.regform.email.focus();

}

if 	(str == 0) {
document.regform.submitreg.disabled = false;
}

  
}
}


function ValidateForm(){

	var emailID = document.regform.email.value;
	var iChars = "!#$%^&*()+=-[]\\\';,./{}|\":<>?";

  if ((document.regform.firstname.value=="")||(document.regform.firstname.value.length < 2)) {
  self.alert("Please enter First Name or Your First Name is too short" ); err=1;
	document.regform.firstname.focus() ;

	return false;
}


  for (var i = 0; i < document.regform.firstname.value.length; i++) {
  	if (iChars.indexOf(document.regform.firstname.value.charAt(i)) != -1) {
  	alert ("Your First name has special characters. \ These are not allowed.\n Please remove them and try again.");
  	return false;
  	}
  }

  if ((document.regform.lastname.value=="")||(document.regform.lastname.value.length < 2)) {
  self.alert("Please enter Last Name or Your Last Name is too short" ); err=1;
	document.regform.lastname.focus() ;

	return false;
}


  for (var i = 0; i < document.regform.lastname.value.length; i++) {
  	if (iChars.indexOf(document.regform.lastname.value.charAt(i)) != -1) {
  	alert ("Your Last name has special characters. \ These are not allowed.\n Please remove them and try again.");
  	return false;
  	}
  }

 if ((document.regform.company.value=="")||(document.regform.company.value.length < 6)) {
  self.alert("Please enter Company Name or Your Company Name is too short, minimum 6 characters long" ); err=1;
	document.regform.company.focus() ;

	return false;
}



  if ((document.regform.displayname.value=="")||(document.regform.displayname.value.length < 4)) {
  self.alert("Please enter Display Name or Your First Name is too short" ); err=1;
	document.regform.displayname.focus() ;

	return false;
}


  for (var i = 0; i < document.regform.displayname.value.length; i++) {
  	if (iChars.indexOf(document.regform.displayname.value.charAt(i)) != -1) {
  	alert ("Your Display name has special characters. \ These are not allowed.\n Please remove them and try again.");
  	return false;
  	}
  }

  if ((document.regform.password.value=="")||(document.regform.password.value.length < 6)) {
  self.alert("Please enter Password or Your Password is too short, minimum 6 characters long" ); err=1;
	document.regform.password.focus() ;

	return false;
}


  for (var i = 0; i < document.regform.password.value.length; i++) {
  	if (iChars.indexOf(document.regform.password.value.charAt(i)) != -1) {
  	alert ("Your Password has special characters. \ These are not allowed.\n Please remove them and try again.");
  	return false;
  	}
  }

  if ((document.regform.cpassword.value=="")||(document.regform.cpassword.value.length < 6)) {
  self.alert("Please enter Password or Your Password is too short, minimum 6 characters long" ); err=1;
	document.regform.cpassword.focus() ;

	return false;
}


  for (var i = 0; i < document.regform.cpassword.value.length; i++) {
  	if (iChars.indexOf(document.regform.cpassword.value.charAt(i)) != -1) {
  	alert ("Your Password has special characters. \ These are not allowed.\n Please remove them and try again.");
  	return false;
  	}
  }
  
  
   if (document.regform.cpassword.value !== document.regform.password.value) {
  self.alert("Your Confirmed Password does not match with your Password Field, please re-enter to Match" ); err=1;
	document.regform.cpassword.focus() ;

	return false;
}


if ((document.regform.country.value=="select")||(document.regform.country.value=="")) {
  self.alert("Please select your Country from the List" ); err=1;
	document.regform.country.focus() ;

	return false;
}

document.regform.submit();
return true;

  
}



