var digits = "0123456789";
var digitsdot = "0123456789.";

function isInt(elm) {
	var elmstr = elm.value + "";
	if (elmstr == '') return false;
	for (var i = 0; i < elmstr.length; i++) {
		if (elmstr.charAt(i) < "0" || elmstr.charAt(i) > "9") {
			return false;
		}
	}
	return true;
}
function stringInt(elm) {
	var elmstr = elm;
	if (elmstr == '') return false;
	for (var i = 0; i < elmstr.length; i++) {
		if (elmstr.charAt(i) < "0" || elmstr.charAt(i) > "9") {
			return false;
		}
	}
	return true;
}
function stripNotInList(s,list)
{
	var i;
	var returnString = "";
	for (i=0; i<s.length; i++)
	{
		var c = s.charAt(i);
		if (list.indexOf(c) != -1) returnString += c;
	}
	return returnString;
}
function CheckContactForm()
{
	var obj_form = document.contactus;
	if (obj_form.first.value.length < 2)
	{
		alert("Please enter your First Name");
		obj_form.first.focus(); return false;
	}
	if (obj_form.last.value.length < 2)
	{
		alert("Please enter your Last Name");
		obj_form.last.focus(); return false;
	}
	if (obj_form.address.value.length < 2)
	{
		alert("Please enter your Address");
		obj_form.address.focus(); return false;
	}
	if (obj_form.city.value.length < 2)
	{
		alert("Please enter your City");
		obj_form.city.focus(); return false;
	}
	if (obj_form.state.selectedIndex == 0)
	{
		alert("Please select the State in which you live");
		obj_form.state.focus(); return false;
	}
	if ( ! ( isInt(obj_form.zipcode) &&	( (obj_form.zipcode.value.length == 5) || (obj_form.zipcode.value.length == 9) ) ) )
	{
		alert("Please enter your 5 or 9 digit ZIP Code");
		obj_form.zipcode.focus(); return false;
	}
	tempDayPhone = stripNotInList(obj_form.phone.value,digits);
	tempNightPhone = stripNotInList(obj_form.nightphone.value,digits);
	tempCellPhone = stripNotInList(obj_form.cellPhone.value,digits);
	if (tempDayPhone + tempNightPhone + tempCellPhone == '') {
		alert("Please enter at least one phone number");
		return false;
	}
	if ( tempDayPhone != '' && ((tempDayPhone.length < 10) || !stringInt(tempDayPhone)) )
	{
		alert("Please enter your Work Phone Number in XXX-XXX-XXXX format");
		obj_form.phone.focus(); return false;
	}
	if ( tempNightPhone != '' && ((tempNightPhone.length < 10) || !stringInt(tempNightPhone)) )
	{
		alert("Please enter your Home Phone Number in XXX-XXX-XXXX format");
		obj_form.nightphone.focus(); return false;
	}
	if ( tempCellPhone != '' && ((tempCellPhone.length < 10) || !stringInt(tempCellPhone)) )
	{
		alert("Please enter your Mobile Phone Number in XXX-XXX-XXXX format");
		obj_form.cellPhone.focus(); return false;
	}
	if (obj_form.sex.selectedIndex == 0)
	{
		alert("Please indicate your gender");
		obj_form.sex.focus(); return false;
	}
	if (!stringInt(stripNotInList(obj_form.age.value,digits)))
	{
		alert("Please enter your age");
		obj_form.age.focus(); return false;
	}
	if (obj_form.foundout.selectedIndex == 0)
	{
		alert("Please tell us how you found out about us");
		obj_form.foundout.focus(); return false;
	}
	if (obj_form.procedure.selectedIndex == 0)
	{
		alert("Please indicate the procedure or treatment you are interested in");
		obj_form.procedure.focus(); return false;
	}
	if (obj_form.contact.selectedIndex == 0)
	{
		alert("Please indicate the best way to contact you");
		obj_form.contact.focus(); return false;
	}
	return true;
}



