
function validateForm(theForm){

	if (theForm.company.value == ""){
		alert('Please enter company name.');
		return false;
	}
	if (theForm.firstname.value == ""){
		alert('Please enter your first name.');
		return false;
	}
	if (theForm.lastname.value == ""){
		alert('Please enter your last name.');
		return false;
	}
	if (theForm.phone.value == ""){
		alert('Please enter your phone number.');
		return false;
	}
	if (theForm.email.value == ""){
		alert('Please enter your email address.');
		return false;
	}
	if( !(theForm.email.value == theForm.email2.value) ){
		alert('email addresses are not matching.');
		return false;
	}
	if	(!validEmail(theForm.email.value)){
		alert("Please check your email address.")
		return false
	}	
	
	
	function validEmail(email) {
		invalidChars = "#?%^&*!() /:;,";
		if(email == "") {
			return false;
		}
		for(i=0; i<invalidChars.length; i++) {
			badChar=invalidChars.charAt(i);
			if (email.indexOf(badChar,0) != -1) {
				return false;
			}
		}
		atPos = email.indexOf("@",1);

		if(atPos == -1) {return false;}
		if (email.indexOf("@", atPos+1) != -1) {return false;}
		periodPos = email.indexOf(".",atPos);
		if(periodPos == -1) {return false;}
		if(periodPos+3>email.length) {return false;}
		return true;
	}




	// all ok
	return true;

}
