function validateForm(){
	if (email_Length() && email_Valid(document.freereg.email.value) && validateNames() && user_chk_addr()){
		return true;
	}else{
		return false;
	}
}


function email_Length(){

	var emailID=document.freereg.email.value;
	if ((emailID==null)||(emailID=="")){
		alert("Please enter your Email address.");
		document.freereg.email.focus();
		return false;
	}
	if ((emailID.length < 5)){
		alert("Email address should be a valid one and more than 5 characters.");
		document.freereg.email.focus();
		return false;
	}
	return true;
	
}

function email_Valid(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("OOPS! The e-mail you entered is not valid. Please edit and try again. Thanks");
	   document.freereg.email.focus();
	   return false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		alert("OOPS! The e-mail you entered is not valid. Please edit and try again. Thanks");
		document.freereg.email.focus();
		return false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert("OOPS! The e-mail you entered is not valid. Please edit and try again. Thanks");
		document.freereg.email.focus();
		return false;
	}

	if (str.indexOf(at,(lat+1))!=-1){
		alert("OOPS! The e-mail you entered is not valid. Please edit and try again. Thanks");
		document.freereg.email.focus();
		return false;
	}

	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("OOPS! The e-mail you entered is not valid. Please edit and try again. Thanks");
		document.freereg.email.focus();
		return false;
	}

	if (str.indexOf(dot,(lat+2))==-1){
		alert("OOPS! The e-mail you entered is not valid. Please edit and try again. Thanks");
		document.freereg.email.focus();
		return false;
	}
		
	if (str.indexOf(" ")!=-1){
		alert("OOPS! The e-mail you entered is not valid. Please edit and try again. Thanks");
		document.freereg.email.focus();
		return false;
	}

 	return true;
}

function validateNames(){
	var firstname=document.freereg.fname.value;
	var lastname=document.freereg.lname.value;
	
	if (firstname==null || firstname==""){
		alert ("Please enter your First Name");
		document.freereg.fname.focus();
		return false;
	}

	if (lastname==null || lastname==""){
		alert ("Please enter your Last Name");
		document.freereg.lname.focus();
		return false;
	}
	return true;
}

function p_valid(){ 
  if ((document.freereg.pwd.value == null) || (document.freereg.pwd.value == "")) {
  	alert("Please enter your Password.");
	document.freereg.pwd.focus();
    return false;
  }
  
  if (document.freereg.pwd.value.length < 6){
    alert("Password should be more than 6 characters. Please try again.");
    document.freereg.pwd.value=""
	document.freereg.pwd.focus();
    return false;
  }
  return true;
}


function c_valid(){ 
  if ((document.freereg.cpwd.value == null) || (document.freereg.cpwd.value == "")){
  	alert("Please confirm your Password.");
	document.freereg.cpwd.focus();
    return false;
  }
  
  if (document.freereg.cpwd.value.length < 5){
    alert("Password should be more than 5 characters. Please try again.");
    document.freereg.cpwd.value=""
	document.freereg.cpwd.focus();
    return false;
  }
  return true;
}


function pwdcmp(){
	if ((p_valid()==true) && (c_valid()==true)){
		if (document.freereg.pwd.value!=document.freereg.cpwd.value){
  			alert("'Confirm Password' is not matching with 'Password'. Please try again.");
			document.freereg.pwd.value="";
			document.freereg.cpwd.value="";
			document.freereg.pwd.focus();
			return false;	
		}
		else
			return true;	
	}
	return false;
}

function user_chk_addr(){
	if ((document.freereg.address1.value==null) || (document.freereg.address1.value=="")){
		alert("Please enter your Billing Address.");
		document.freereg.address1.focus();
		return false;
	}
	
	if ((document.freereg.city.value==null) || (document.freereg.city.value=="")){
		alert("Please enter your City.");
		document.freereg.city.focus();
		return false;
	}
	
	var stateselect=document.freereg.statesel.options[document.freereg.statesel.selectedIndex].text;
	if (stateselect=="SELECT"){
		if ((document.freereg.state.value==null) || (document.freereg.state.value=="")){
			alert("Please select your State");
			return false;
		}
	}
	
	if ((document.freereg.zip.value==null) || (document.freereg.zip.value=="")){
		alert("Please enter your Zip code.");
		document.freereg.zip.focus();
		return false;
	}
	
	var ctry=document.freereg.country.options[document.freereg.country.selectedIndex].text;
	if (ctry == "SELECT"){
		alert ("Please select your country.");
		document.freereg.country.focus();
		return false;
	}
	
	return true;
}

function user_altMailValid(){
  var str=document.freereg.alt_email.value;
  
	if ((str!=null) && (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 Alternate Email address. Please enter again.");
		   //document.freereg.alt_email.focus();
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
			alert("Invalid Alternate Email address. Please enter again.");
			//document.freereg.alt_email.focus();
			return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
			alert("Invalid Alternate Email address. Please enter again.");
			//document.freereg.alt_email.focus();
			return false;
		}

		if (str.indexOf(at,(lat+1))!=-1){
			alert("Invalid Alternate Email address. Please enter again.");
			//document.freereg.alt_email.focus();
			return false;
		}

		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
			alert("Invalid Alternate Email address. Please enter again.");
			//document.freereg.alt_email.focus();
			return false;
		}

		if (str.indexOf(dot,(lat+2))==-1){
			alert("Invalid Alternate Email address. Please enter again.");
			//document.freereg.alt_email.focus();
			return false;
		}
		
		if (str.indexOf(" ")!=-1){
			alert("Invalid Alternate Email address. Please enter again.");
			//document.freereg.alt_email.focus();
			return false;
		}
		return true;
	}
  return true;
}