// JavaScript validation
function checkWholeForm(form1) {
	var why = "";
	var theForm	 = document.form1;
	
	 why += checkUsername(theForm.name.value);
	 why +=	checkAddress(theForm.address.value);
	 why +=	checkZip(theForm.zip.value);
	 why +=	checkEmail(theForm.email.value);
	 why +=	checkPhone(theForm.telephone.value);
	  why += checkLogin(theForm.loginName.value);
	  why +=  checkPassword(theForm.password.value);
	  why += checkconfirmPassword(theForm.confirmPass.value,theForm.password.value);
	  
	if (why != "") {
       alert("Please enter the following fields.\n" + why);
       return false;
    }
theForm.submit();
return true;
}

function checkUsername (strng) {

var error = "";
if (strng == "") {
   error = "Name.\n";
}


   /* var illegalChars = /\W/; // allow letters, numbers, and underscores
    if (illegalChars.test(strng)) {
    error = "The username contains illegal characters.\n";
    } */
return error;

 }
 function checkAddress(strng) {

	var error = "";
	if (strng == "") {
	   error = "Address.\n";
	 }
	 return error;
}
function checkZip(strng)
{
	var error = "";
	if (strng == "") {
	   error = "Zip Code.\n";
	 }
	 return error;
	
}
function checkEmail (strng) {
var error="";
if (strng == "") {
   error = "Email address.\n";
}

	
    /*  splitVal = strng.split('@');

        if(splitVal.length <= 1) 
		{
               // alert("Please enter a valid email address");
   				error = "Email address.\n";
                return error;
        } 
        if(splitVal[0].length <= 0 || splitVal[1].length <= 0) 
		{
              //  alert("Please enter a valid email address");
   				error = "Please enter a valid email address.\n";
                return error;
        }

        splitDomain = splitVal[1].split('.');
        if(splitDomain.length <= 1) 
		{
                //alert("Please enter a valid email address");
   				error = "Please enter a valid email address.\n";
                return error;
        	}
        if(splitDomain[0].length <= 0 || splitDomain[1].length <= 1) 
		{
                //alert("Please enter a valid email address");
   				error = "Please enter a valid email address.\n";
                return error;
       	 	}
		var v = new RegExp(); 
		v.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$"); 
		
		
     return true;  */

 var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid email address.\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.\n";
       }
    }
return error;    
}

function checkPhone (strng) {
var error = "";
if (strng == "") {
   error = "Phone number.\n";
}

return error;
}

function checkLogin (strng) {

var error = "";
if (strng == "") {
   error = "Login ID.\n";
}


   /* var illegalChars = /\W/; // allow letters, numbers, and underscores
    if (illegalChars.test(strng)) {
    error = "The username contains illegal characters.\n";
    } */
return error;

 }

function checkPassword (strng) {
var error = "";
if (strng == "") {
   error = "Password.\n";
}

 /*   var illegalChars = /[\W_]/; // allow only letters and numbers
    
    if (illegalChars.test(strng)) {
      error = "The password contains illegal characters.\n";
    } */
   
return error;    
}    

function checkconfirmPassword (strng,str) {
var error = "";
	if (strng == "") {
 	  error = "Confirm password.\n";
	}
	else if(strng != str){
		
	  error	= "Your password entries did not match.\n";
		
	}
	
 /*   var illegalChars = /[\W_]/; // allow only letters and numbers
    
    if (illegalChars.test(strng)) {
      error = "The confirm password contains illegal characters.\n";
    } 
  if(str != strng)
		{
		error = "Please enter Same Password";
		//theForm.confirmPass.focus();
		
		}*/
return error;    
}   


function numValidation(key){
	if(key==9 || key==8 || key==96 || key==97 || key==98 || key==99 || key==100 || key==101 || key==102 || key==103 || key==104 || key==105) 
		return true; 
	else if(key < 46 || key > 57) 
		return false;
}

function validTelephone(key){
	if(key==9 || key==8 || key==96 || key==97 || key==98 || key==99 || key==100 || key==101 || key==102 || key==103 || key==104 || key==105 || key==189 ) 
		return true; 
	else if(key < 46 || key > 57) 
		return false;
}
function validZip(key){
	if(key==9 || key==8 || key==96 || key==97 || key==98 || key==99 || key==100 || key==101 || key==102 || key==103 || key==104 || key==105 || key==189) 
		return true; 
	else if(key < 46 || key > 57) 
		return false;
}

function checkContactForm(form2) {
	var why = "";
	//var theForm	=	document.form2;
	 why += checkUsername(document.form2.name.value);
	 why +=	checkAddress(document.form2.address.value);
	 why +=	checkEmail(document.form2.email.value);
	 why +=	checkPhone(document.form2.telephone.value);
	 why += checkMessage(document.form2.message.value);
	 if (why != "") {
       alert("Please enter the following fields.\n" + why);
       return false;
    }
document.form2.submit();
return true;
}

	
function checkUsername (strng) {

var error = "";
if (strng == "") {
   error = "Name.\n";
}
  
return error;

 }
  function checkAddress(strng) {

	var error = "";
	if (strng == "") {
	   error = "Address.\n";
	 }
	 return error;
}

function checkEmail (strng) {
var error="";
if (strng == "") {
   error = "Email address.\n";
}
  
 var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid email address.\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.\n";
       }
    }
return error;    
}

function checkPhone (strng) {
var error = "";
if (strng == "") {
   error = "Phone number.\n";
}

return error;
}
function checkMessage(strng)
{
	var error	= "";
	if(strng	==	""){
		error	=	"Message.\n";
	}
	return error;	
}
function checkVehicleForm(form2)
{
	alert("gsdfsdhgg");
	/*var why = "";
	//var theForm	=	document.form2;
	 why += checkVehicleNo(document.form2.vehicleno.value);
	 if (why != "") {
       alert("Please enter the following fields.\n" + why);
       return false;
    }
document.form2.submit();
return true;
}*/
	
}
function checkVehicleNo (strng) {

var error = "";
if (strng == "") {
   error = "VehicleNo.\n";
}
  
return error;

 }
