// JavaScript Document
function validate(){
	var fieldName = new Array("userId",
	"pwd",
	"confPwd",
	"answer",
	"company",
	"contactPerson",
	"email",
	"telephone"
	);

	var fieldMsg = new Array("User Id",
	"Password",
	"Confirm Password",
	"Answer",
	"Company Name",
	"Contact Person",
	"Email",
	"Telephone"
	);
	
	for(var i=0; i<fieldName.length; i++){
		tmp = eval("document.addUser."+fieldName[i]);
		if(tmp.value==""){//checks that field is not left blank 
			alert(fieldMsg[i]+" Cannot be left Blank");
			tmp.focus();
			return false;
		}else if(trim(tmp.value)==""){//checks that field does not contain blank spaces
			alert(fieldMsg[i]+" Cannot contain Spaces");
			tmp.value="";
			tmp.focus();
			return false;
		}
	}

   //check to see that Password is minimum 5 chars
   if(document.addUser.pwd.value.length < 5 ){
	   alert("The Password should contain atleast 5 characters");
	   document.addUser.pwd.value="";
	   document.addUser.confPwd.value="";
	   document.addUser.pwd.focus();
   	   return false;
   }
   //check to see if Password and Confirm Password Matches
   if(document.addUser.pwd.value != document.addUser.confPwd.value){
	   alert("The Password and Confirm Password Do Not Match");
	   document.addUser.pwd.value="";
	   document.addUser.confPwd.value="";
	   document.addUser.pwd.focus();
   	   return false;
   }
   //check to see that postalCode is minimum 6 chars
/*
   if(document.addUser.postalCode.value.length < 6 ){
	   alert("The Postal Code should contain atleast 6 characters");
	   document.addUser.postalCode.focus();
   	   return false;
   }
*/
   //validates email address
   if(!emailCheck(document.addUser.email.value)){
  	 document.addUser.email.focus();
  	 return false;
   }
   
   return true;
}
