
 
var url = "username.php?param=";

 
function updateName() { 
document.getElementById('checked').innerHTML = "<img src='images/loading.gif'>"; 
var name = document.getElementById("email").value; 
http.open("GET", url + escape(name), true); 
http.onreadystatechange = handleHttpResponse; 
http.send(null); 
}
 
function handleHttpResponse() { 
if (http.readyState == 4) { 
 results = http.responseText; 
 var name = document.getElementById("email").value; 
 /* If the username is available, Print this message: */ 
 if(results == "") 
  results = "<INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Submit\" ><font color=\"green\"><i>"+name+"</i> Is Available!</font>"; 
  document.getElementById('checked').innerHTML = results; 
  } 
 }
 
function getHTTPObject() { 
var xmlhttp; 
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') { 
try { xmlhttp = new XMLHttpRequest(); } 
catch (e) { xmlhttp = false; } } return xmlhttp; } 
var http = getHTTPObject(); 

function validateForm(frm) {	
			var emailID=document.form1.email

			
			if(document.form1.email.value==""){
				alert ("Email is a required field!");
				document.form1.email.focus()
				return false;
			}
			
			if(document.form1.password.value==""){
				alert ("Password is a required field!");
				document.form1.password.focus()
				return false;
			}
			
			if(document.form1.fname.value==""){
				alert ("First Name is a required field!");
				document.form1.fname.focus()
				return false;
			}
			
			if (echeck(emailID.value)==false){
				emailID.value=""
				alert ("Email is in an invalid format!");
				emailID.focus()
				return false
			}

}

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 is not saved. Please go back to this form before submitting your application")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID is not saved. Please go back to this form before submitting your application")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Invalid E-mail ID is not saved. Please go back to this form before submitting your application")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("Invalid E-mail ID is not saved. Please go back to this form before submitting your application")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //alert("Invalid E-mail ID is not saved. Please go back to this form before submitting your application")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Invalid E-mail ID is not saved. Please go back to this form before submitting your application")
		    return false
		 }

		 if (str.indexOf(" ")!=-1){
		    //alert("Invalid E-mail ID is not saved. Please go back to this form before submitting your application")
		    return false
		 }

 		 return true
	}

