// JavaScript Document

<!--
	
	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
	}
	
	function emailVar() {
		if (!validEmail(document.CBDcontactForm.CBDemail.value)) {
			return false;
		}
		return true;
	}
	
	
	/*function phoneArea() {
		if (document.CBDcontactForm.CBDarea.value.length !=3 ){
			return false
		}
		return true
	}
	function phoneOne() {
		if (document.CBDcontactForm.CBDphone1.value.length !=3){
			return false
		}
		return true
	}
	function phoneTwo() {
		if (document.CBDcontactForm.CBDphone2.value.length !=4){
			return false
		}
		return true
	}*/
	
	re1 = /^\d{3}$/
	re2 = /^\d{3}$/
	re3 = /^\d{4}$/
	function validPhone() {
		validArea = re1.exec(document.CBDcontactForm.CBDarea.value)
		validPrefix = re2.exec(document.CBDcontactForm.CBDphone1.value)
		validSuffix = re3.exec(document.CBDcontactForm.CBDphone2.value)
		if (validArea && validPrefix && validSuffix) {
			return true
		}
		return false
	}
	
	/*function phoneVar(){
		if (phoneArea() && phoneOne() && phoneTwo() && validPhone()){
			return true
		}
		return false
	}*/
	
	function emailOrPhone(){
		if (emailVar() || validPhone()) {
			return true
		}
		return false
	}
	
	function emailAndPhone() {
		if (emailVar() && validPhone()){
			if (document.CBDcontactForm.CBDpreferred.value == ""){
				return false;
			}
			return true;
		}
		return true
	}
	
	
	

	function validateForm(CBDcontactForm) {
		
		
		if (document.CBDcontactForm.CBDname.value=="") {
			alert ("Please enter your name.");
			document.CBDcontactForm.CBDname.focus();
			return false;
		}
		if (document.CBDcontactForm.CBDcompany.value=="") {
			alert ("Please enter the name of your company.");
			document.CBDcontactForm.CBDcompany.focus();
			return false;
		}
	
		if (!emailOrPhone()){
			alert ("Please enter either a valid email address or a complete phone number.");
			document.CBDcontactForm.CBDemail.focus();
			return false;
		}
		
		if (!emailAndPhone()) {
			alert ("Since you gave us both an email address and a phone number, please select which method of contact you prefer.");
			document.CBDcontactForm.CBDpreferred.focus;
			return false;
		}

		if (document.CBDcontactForm.CBDinquiry.value=="") {
			alert ("Please tell us how we can help you.");
			document.CBDcontactForm.CBDinquiry.focus();
			return false;
		}
	}
