function formatPhone(phone)
{
	return  '(' + phone.substring(0, 3) + ') ' + phone.substring(3, 6) + '-' + phone.substring(6, 10);
}
function isValidText(text, minValue, maxValue, required)
{
	if ((text.length < minValue && (required != false)) || ((!isNaN(maxValue) && maxValue != '' && maxValue != null) && text.length > maxValue))
		return false;
	return true;
}
function isValidZip(zip)
{
	switch (zip.length)
	{
		case 5:
			// us zip, no extension
			return !isNaN(zip);
			break;
		case 10:
			// us zip, 4 digit extension  00000-1111
			var zipMain = zip.substring(0, 5); // 00000
			var dash = zip.substring(5, 6); // -
			var ext = zip.substring(6); // 1111
			return (!isNaN(zipMain) && dash == "-" && !isNaN(ext));
			break;
		case 7:
			// canadian zip K0C 1P0
			var regexp = new RegExp("[A-Za-z][0-9][A-Za-z] [0-9][A-Za-z][0-9]");
			return regexp.test(zip);
			break;
		default:
			return false;
	}
	return true;
}
function isValidPhone(phone, required)
{
	if ((phone.length == 10 || (phone.length == 0 && required == false)) && !isNaN(phone))
	{
		return true;
	}
	return false;
}
function parseZip(zip)
{
	zip = (zip.toUpperCase()).replace(/[^0-9A-Z]/, "");
	zip = zip.replace(' ', '');
	if (zip.length == 9) // us zip with extension
	{
		zip1 = zip.substring(0, 5);
		zip2 = zip.substring(5);
		return (zip1 + "-" + zip2);
	}
	else if (zip.length == 6)
	{
		zip1 = zip.substring(0, 3);
		zip2 = zip.substring(3);
		return (zip1 + " " + zip2);
	}
	else
	{
		return zip;
	}
}
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}
function checkNumber(fieldName, fieldValue)
{
	// this function is for making sure no non-numeric characters are in the given field
	// use it for phone/fax fields, call it on keyup and keypress
	var fieldValue2 = fieldValue.replace(/[^0-9]/, "");
	if (fieldValue != fieldValue2)
	{
		var field = document.getElementsByName(fieldName);
		field[0].value = fieldValue2;
	}
}