//validation for login
function checkform(){
	var Invalid=" ";
	var frm = document.form1;
	
	if(frm.txtfname.value==""){
		alert("Please enter your first name");
		frm.txtfname.focus();
		return false;
	}
	else {
		
		if(!hasWhiteSpace(frm.txtfname.value))
 {
	 document.frm.txtfname.value="";
			document.frm.txtfname.focus();
  return false;
   }
	}
	if(frm.txtlname.value==""){
		alert("Please enter your last name");
		frm.txtlname.focus();
		return false;
	}
	else {
		if(!hasWhiteSpace(frm.txtlname.value))
 {
	 document.frm.txtlname.value="";
			document.frm.txtlname.focus();
  return false;
   }
	}

if(frm.txtemail.value==""){
		alert("Please enter your email id");
		frm.txtemail.focus();
		return false;
	}
else {
		if(!hasWhiteSpace(frm.txtemail.value))
 {
	 document.frm.txtemail.value="";
			document.frm.txtemail.focus();
	 
  return false;
   }
	
if (frm.txtemail.value.indexOf(Invalid) > -1)
 {
alert("Sorry, spaces are not allowed.");
frm.txtemail.value="";
frm.txtemail.focus();
return false;
}

	var str = frm.txtemail.value;
	if(!emailCheck(str)){
		frm.txtemail.focus();
		return false;
	}
}

if(frm.security_code.value==""){
		alert("Please enter security code as shown in graphic");
		frm.security_code.focus();
		return false;
	}

	
}
function hasWhiteSpace(s)
      {
     reWhiteSpace = new RegExp(/^\s+$/);
           // Check for white space
           if (reWhiteSpace.test(s)) {
                alert("Sorry, Spaces are not allowed");
                return false;
           }
      return true;
      } 

//validation for email
function emailCheck(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("Enter the valid e-mail id !")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){           
            alert("Enter the valid e-mail id")
		    return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
			alert("Enter the valid e-mail id");
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
			alert("Enter the valid e-mail id");
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
			alert("Enter the valid e-mail id");
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
			alert("Enter the valid e-mail id");
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Enter the valid e-mail id !");
		    return false;
		 }
 		 return true					
}

