function isNumeric(char) {
	valid = "1234567890";
	if (valid.indexOf(char) > -1) { return true; }
	else { return false; }
}

function validateContactEntry() {

	//Validate  Phone
    thisObject = document.getElementById( "phone" );
    thisField = trim( thisObject.value );
    	
	thisObject.value = thisField;

		if (validatePhoneNumber(thisField)==false)
		{
			thisObject.focus();
			return false;
		}
	return true;
}

function validatePhoneNumber(usPhoneNumber)
{
    if(usPhoneNumber.search(/^(\d\d\d)\-?(\d\d\d)\-?(\d\d\d\d)$/)==-1)    {
    	return false;
    }
    return true;

} // validatePhoneNumber

function trim( inputString )
{
	var trimmedString;
	var ch;

	if (typeof inputString != "string")
	{
		return inputString;
	}

	trimmedString = inputString;
	ch = trimmedString.substring(0, 1);

	// Check for spaces at the beginning of the string: \t\n\r
	while ((ch == " ") || (ch == "\n") || (ch == "\n") || (ch == "\r") || (ch == "\t"))
	{
		trimmedString = trimmedString.substring(1, trimmedString.length);
		ch = trimmedString.substring(0, 1);
	}

	// Check for spaces at the end of the string
	ch = trimmedString.substring(trimmedString.length-1, trimmedString.length);
	while (ch == " ")
	{
		trimmedString = trimmedString.substring(0, trimmedString.length-1);
		ch = trimmedString.substring(trimmedString.length-1, trimmedString.length);
	}

	return trimmedString;

} // trim

function verify() {
	var intro = "Sorry, we could not submit your Email.\r\nPlease fix the following:\r\n\r\n";
	var themessage = intro;
	// validate name field
	if (document.contactForm.name.value.length < 2 || document.contactForm.name.value=="") {
		themessage = themessage + "Name - Please enter your name.\r\n";
	}
	
	// validate Email field
	if (document.contactForm.email.value.length > 0)
	{
		if (document.contactForm.email.value.indexOf(' ') != -1 || document.contactForm.email.value.indexOf('@') < 2 || document.contactForm.email.value.indexOf('@')+6 > document.contactForm.email.value.length || document.contactForm.email.value.length < 9 || document.contactForm.email.value=="") {
			themessage = themessage + "Email Address - Please enter a valid Email address.\r\n";
		}
	}
	
	// validate phone field
	/*number = document.contactForm.phone.value;
	numCount = 0;
	for(x=0;x<number.length;x++)
	{
		if (isNumeric(number[x])) { numCount++; }
	}
		
	if (numCount < 10 || numCount > 11 || document.contactForm.phone.value.length < 10 || document.contactForm.phone.value.length > 14) {
		themessage = themessage + "Phone Number - Please enter a valid phone number and area code.";
	}*/

	if(!validateContactEntry()) {themessage = themessage + "Phone Number - Please enter a valid phone number and area code.";}


	
	// validate comments field
	if (document.contactForm.comment.value.length > 500) {
		themessage = themessage + "Comments - Please limit your comments to 500 characters or less.";
	}

	//alert if fields are empty and cancel form submit
	if (themessage == intro) {
		document.contactForm.submit();
	}
	else {
		alert(themessage);
		return false;
	}
}