﻿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 ValidateForm(){
	var Uname = document.reg.userName;
	var pass = document.reg.password;
	var Cpass = document.reg.password_c;
	var emailID = document.reg.email;
	var code = document.reg.code;
	var Scode = document.reg.security_code;
	var terms = document.reg.agree;
	
	if ((Uname.value==null)||(Uname.value=="")){
		alert("Please Enter User Name");
		Uname.focus();
		return false;
		}
		
	else if (Uname.value.length <= 4){
		alert("User Name Must be at Least Five Characters");
		Uname.focus();
		return false;
		}
		
	else if ((pass.value==null)||(pass.value=="")){
		alert("Please Enter your Password");
		pass.focus();
		return false;
		}
	
	else if ((Cpass.value==null)||(Cpass.value=="")){
		alert("Please Enter your Password Confirmation");
		Cpass.focus();
		return false;
		}
		
	else if (pass.value != Cpass.value){
		alert("Your Password and Confirm Password are not the same.");
		pass.focus();
		return false;
		}
		
	else if (echeck(emailID.value) == false){
		emailID.value="";
		emailID.focus();
		return false;
		}
	
	else if ((Scode.value==null) || (Scode.value=="")){
		alert("Please Enter the Validation Code");
		code.focus();
		return false;
		}
		
	else if (Scode.value != code.value){
		alert("The Validation Code is Incorrect");
		Scode.focus();
		return false;
		}
		
	else if(terms.checked==false)
	{
		alert("You must agree to the terms in order to register.");
		return false; 
	}
	
	else
	{
		document.reg.submit(); 
 	}
 }