// JavaScript Document
function chk(form){
	if(form.sameAddr.checked==true){
		form.CPaddress.disabled=true;
		form.CPPostalCode.disabled=true;
		form.CPmobile.disabled=true;
		form.CPfax.disabled=true;
		form.CPtelephone.disabled=true;
		form.CPemail.disabled=true;		
	}else{
		form.CPaddress.disabled=false;
		form.CPPostalCode.disabled=false;
		form.CPmobile.disabled=false;
		form.CPfax.disabled=false;
		form.CPtelephone.disabled=false;
		form.CPemail.disabled=false;		
	}
}

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",
	"E-mail",
	"Telephone"
	);
	
	for(var i=0; i<fieldName.length; i++){
		tmp = eval("document.adForm."+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.adForm.pwd.value.length < 5 ){
	   alert("The Password should contain atleast 5 characters");
	   document.adForm.pwd.value="";
	   document.adForm.confPwd.value="";
	   document.adForm.pwd.focus();
   	   return false;
   }
   //check to see if Password and Confirm Password Matches
   if(document.adForm.pwd.value != document.adForm.confPwd.value){
	   alert("The Password and Confirm Password Do Not Match");
	   document.adForm.pwd.value="";
	   document.adForm.confPwd.value="";
	   document.adForm.pwd.focus();
   	   return false;
   }
   //validates email address
   if(!emailCheck(document.adForm.email.value)){
  	 document.adForm.email.focus();
  	 return false;
   }

   //checks if atleast one of the Categories is selected
   if((document.adForm.muCategories.selectedIndex < 1)
   && (document.adForm.osCategories.selectedIndex < 1)
   && (document.adForm.categories.selectedIndex < 1)
	){
		alert("Select atleast One Category you want to Advertise In");
		document.adForm.muCategories.focus();
		return false;
	}
	return true;
}

