function validateForm(form)
{
	var zipPattern=/(^\d{5}$)|(^\D{1}\d{1}\D{1}\s\d{1}\D{1}\d{1}$)/;
	var emailPattern=/^[A-Za-z][A-Za-z0-9_.-]*@[A-Za-z0-9_-]+\.[A-Za-z0-9_.]+[A-za-z]$/;
	if ( form.locationNumber.value.length != 0 ) {
	    for(var i=0; i < form.locationNumber.value.length; i++) {
	    if (form.locationNumber.value.charAt(i) < "0" || form.locationNumber.value.charAt(i) > "9") {
		    alert("Please enter a numerical value.");
		    form.locationNumber.value="";
		    form.locationNumber.focus();
		    return false;
		    }
		}
	}
	if ( form.fname.value == "" )
	{
		alert("Please enter a contact name.");
		form.fname.focus();
		return false;
	}
	if ( form.fname.value.indexOf("|") != -1 )
	{
		alert("The contact name field cannot contain the pipe '|' character.");
		form.fname.focus();
		return false;
	}
	if ( form.businessname.value == "" )
	{
		alert("Please enter a business name.");
		form.businessname.focus();
		return false;
	}
	if ( form.businessname.value.indexOf("|") != -1 )
	{
		alert("The business name field cannot contain the pipe '|' character.");
		form.businessname.focus();
		return false;
	}
	if ( form.businesstype.value.indexOf("|") != -1 )
	{
		alert("The business type field cannot contain the pipe '|' character.");
		form.businesstype.focus();
		return false;
	}
	if ( form.address.value == "" )
	{
		alert("Please enter an address.");
		form.address.focus();
		return false;
	}
	if ( form.address.value.indexOf("|") != -1 )
	{
		alert("The address field cannot contain the pipe '|' character.");
		form.address.focus();
		return false;
	}
	if ( form.city.value == "" )
	{
		alert("Please enter a city.");
		form.city.focus();
		return false;
	}
	if ( form.city.value.indexOf("|") != -1 )
	{
		alert("The city field cannot contain the pipe '|' character.");
		form.city.focus();
		return false;
	}
	if ( form.state.value == "" )
	{
		alert("Please enter a state or province.");
		form.state.focus();
		return false;
	}
	if ( form.state.value.indexOf("|") != -1 )
	{
		alert("The state/province field cannot contain the pipe '|' character.");
		form.state.focus();
		return false;
	}
	if (!zipPattern.test(form.zip.value) || empty(strip(form.zip.value)))
	{
		alert("Please enter a valid zip or postal code.");
		form.zip.focus();
		return false;
	}
	if (empty(strip(form.phone.value)))
	{
		alert("Please enter a phone.");
		form.phone.focus();
		return false;
	} else if (!validatePhone(form.phone.value)) {
		alert("Please enter a valid phone.  Format 111-111-1111.");
		form.phone.focus();
		return false;
	}
	if (!empty(strip(form.fax.value)))
	{
		if (!validatePhone(form.fax.value)) {
			alert("Please enter a valid fax.  Format 111-111-1111.");
			form.fax.focus();
			return false;
		}
	}
	if ( form.contactTime.value.indexOf("|") != -1 )
	{
		alert("The fax field cannot contain the pipe '|' character.");
		form.contactTime.focus();
		return false;
	}
	if (!emailPattern.test(form.email.value) || empty(strip(form.email.value)))
	{
		alert("Please enter a valid email address.");
		form.email.focus();
		return false;
	}
	if ( form.comments.length > 255 )
	{
		alert("The maximum length of the comments field is 255 characters.");
		form.comments.focus();
		return false;
	}
	if ( form.comments.value.indexOf("|") != -1 )
	{
		alert("The comments field cannot contain the pipe '|' character.");
		form.comments.focus();
		return false;
	}
}

function twoFiftyChar()
{
	document.request.commentsCount.value = 255 - document.request.comments.value.length
	if( document.request.commentsCount.value < 0 )
	{
		tooLong = document.request.comments.value.length
		cutOff = tooLong - 255
		alert("The comments entry has a maximum length of 255 characters, your entry has been trimmed to fit that length.")
		document.request.comments.value = document.request.comments.value.slice(0, -cutOff)
		document.request.commentsCount.value = 255 - document.request.comments.value.length
	}
}

function empty(x) { 
    if (x.length > 0) {
		return false; 
    }
    return true;    
}
function strip(x) {
    if (x.length < 1) { 
		return x;
    } 
    return x.replace(/^\s+|\s+$/g,'');
}

function validatePhone(phone) {
	var filter = /^[1-9]\d{2}-\d{3}-\d{4}$/;
	if (!filter.test(strip(phone))) {
		return false;
	}
	return true;
}