
function toggle(box,theId) { 
if(document.getElementById) { 
var cell = document.getElementById(theId); 
if(box.checked) { 
cell.className = "on"; 
} 
else { 
cell.className = "off"; 
} 
} 
} 

//validating the fields when user clicks submit
function validate() {
	if(document.frmContact.txtName.value=="") {
		alert("Please fill in your name.");
		document.frmContact.txtName.focus();
		return false;
	}else if(document.frmContact.txtAddress.value=="") {
		alert("Please fill in your address.");
		document.frmContact.txtAddress.focus();
		return false;
	}else if(document.frmContact.txtCity.value=="") {
		alert("Please fill in your city.");
		document.frmContact.txtCity.focus();
		return false;
	}else if(document.frmContact.txtState.value=="") {
		alert("Please fill in your state.");
		document.frmContact.txtState.focus();
		return false;
	}else if(document.frmContact.txtZip.value=="") {
		alert("Please fill in your zip code.");
		document.frmContact.txtZip.focus();
		return false;
	//}else if(document.frmContact.txtPhone.value=="") {
		//alert("Please fill in your Phone Number.");
		//document.frmContact.txtPhone.focus();
		//return false;
	}else if(!checkPhone(document.frmContact.txtPhone1.value,document.frmContact.txtPhone2.value,document.frmContact.txtPhone3.value)) {
		alert("Please fill in a valid phone number.");
		document.frmContact.txtPhone1.focus();
		return false;	
	}else if(!checkEmail(document.frmContact.txtEmail.value)) {
		alert("Please fill in your valid email address.");
		document.frmContact.txtEmail.focus();
		return false;
	}else if(document.frmContact.txtComments.value=="") {
		alert("Please fill in your Question or Testimonial.");
		document.frmContact.txtComments.focus();
		return false;
	}	
	return true;	
}

function checkPhone(txtphone1, txtphone2, txtphone3) {
	var phoneRegEx1 = /^\d{3}$/;
	var phoneRegEx2 = /^\d{4}$/;
	if(txtphone1.match(phoneRegEx1) && txtphone2.match(phoneRegEx1) && txtphone3.match(phoneRegEx2)) {
		return true;
	}else {
		return false;
	}
}

function checkEmail(email) {
	var emailpat = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(\.[a-zA-Z0-9_-]+)+$/;
	if(emailpat.test(email)) {
		return true;
	}else{
		return false;
	}
}
