//validate.js -- form validation

function strltrim() {
	return this.replace(/^\s+/,'');
}

function strrtrim() {
	return this.replace(/\s+$/,'');
}
function strtrim() {
	return this.replace(/^\s+/,'').replace(/\s+$/,'');
}

String.prototype.ltrim = strltrim;
String.prototype.rtrim = strrtrim;
String.prototype.trim = strtrim;

function validateEMail(theForm, fieldName, fieldDescription)
{
	strEmail = theForm[fieldName].value;
	var filter=/^[A-Za-z0-9-_\.]+@+[A-Za-z0-9-_\.]+\.+[A-Za-z]{2,4}$/;
	if (!filter.test(strEmail)){
		alert("Please provide a valid E-Mail address for the \"" + fieldDescription +  "\"  field.");
		theForm[fieldName].focus();
		return (false);
	}
	return (true);
}

function validatePhone(theForm, fieldName, fieldDescription)
{
	strPhone = theForm[fieldName].value;
	var filter=/^[0-9-()\.]{7,14}$/;
	if (!filter.test(strPhone)){
		alert("Please provide a valid phone number for the \"" + fieldDescription +  "\"  field.");
		theForm[fieldName].focus();
		return (false);
	}
	return (true);
}


function validateTextBox(theForm, fieldName, fieldDescription)
{
	sText = theForm[fieldName].value.trim();
	if (sText.length==0)
	{
		alert("Please enter a value for the \"" + fieldDescription +  "\" field.");
		theForm[fieldName].focus();
		return (false);
	}
	return (true);
}

function clearOnChange(theField, sVal)
{
	strText = theField.value;
	if (strText.indexOf(sVal,0) > -1){
		theField.value = '';
		return (true);
	}
	return (false);
}

