		String.prototype.trim = function() {
			return this.replace(/^\s+|\s+$/g,"");
		}
		
		function isFieldEmpty(theField) {
			if (theField.value.length > 0) {
				return false;
			} else {
				theField.focus();
				return true;
			}		
		}

	function check(theTextArea,fieldName,limit) {
		if(theTextArea.value.length > limit) {
			alert('Maximum length exceeded for field ' + fieldName + '.');
			theTextArea.focus();
			return false; 
		}
		else
			return true; 
	}
	
	function update(theTextArea,divElementId,maxChars) {
		var newCount = theTextArea.value.length;
		if (newCount > maxChars) {
			alert('Character limit of ' + maxChars + ' exceeded.');
			theTextArea.value = theTextArea.value.substring(0,maxChars);
		}
	}

	function isFieldValid(theField,fieldType,isRequired,fieldDesc) {
		if (isRequired) {
			if (isFieldEmpty(theField)) {
				alert("Please enter " + fieldDesc);
				theField.focus();
				return false;
			}
		}
		if (fieldType == 'ZIP') {
			var zipMsg = validateZIP(theField);
			if (zipMsg.length > 0) {
				alert("Please check " + fieldDesc + "  " + zipMsg);
				theField.focus();
				return false;
			}
		}
		if (fieldType == 'PHONE') {
			var phoneMsg = validatePhone(theField);
			if (phoneMsg.length > 0) {
				alert("Please check " + fieldDesc + "  " + phoneMsg);
				theField.focus();
				return false;
			}
		}
		if (fieldType == 'EMAIL') {
			var emailMsg = validateEmail(theField);
			if (emailMsg.length > 0) {
				alert("Please check " + fieldDesc + "  " + emailMsg);
				theField.focus();
				return false;
			}
		}
		if (fieldType == 'STATE') {
			var stateMsg = validateState(theField);
			if (stateMsg.length > 0) {
				alert("Please check " + fieldDesc + "  " + stateMsg);
				theField.focus();
				return false;
			}
		}
		if (fieldType == 'NUMBER') {
			if (isNaN(theField.value)) {
				alert("Please enter a numeric value.");
				theField.focus();
				return false;
			}
		}
		return true;
	}
			
/**
 * DHTML phone number validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
	s=stripCharsInBag(strPhone,validWorldPhoneChars);
	return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function checkInternationalPhone(strPhone){
	s=stripCharsInBag(strPhone,validWorldPhoneChars);
	return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function validatePhone(phoneField) {
	if (phoneField.value == '') {
		return "";
	}
	
	var phone = stripCharsInBag(phoneField.value,validWorldPhoneChars);
	
	if (!isInteger(phone)) {
		return "Phone number contains invalid characters.";
	}
	
	if (phone.length<10) {
		return "Phone number must include at least ten digits.";
	}

	return "";
}

function validateZIP(zipField) {
	if (zipField.value == '') {
		return "";
	}
	
	var zip = stripCharsInBag(zipField.value,"- ");
	
	if (!isInteger(zip)) {
		return "ZIP code contains invalid characters.";
	}
	
	if (zip.length!=5 && zip.length!=9) {
		return "ZIP code must be either a 5 digit or 5 digit + 4 digit code.";
	}

	return "";
}

function validateEmail(emailField) {
	if (emailField.value == '') {
		return "";
	}
	
	var email = emailField.value;

	var atPos = email.indexOf("@");
	var periodPos = email.lastIndexOf(".");
	
	if (atPos == -1) {
		return "E-mail address must contain an @ symbol.";
	}
	
	if ((periodPos == -1) || (periodPos < atPos) || (periodPos - atPos == 1)) {
		return "E-mail address must contain a domain name (ie. xyz.com, xyz.net, something.something).";
	}
	
	return "";
}

function validateState(stateField) {
	if (stateField.value == '') {
		return "";
	}
	
	var validStateList = "AK|AL|AR|AZ|CA|CO|CT|DC|DE|FL|GA|HI|IA|ID|IL|IN|KS|KY|LA|MA|MD|ME|MI|MN|MO|MS|MT|NB|NC|ND|NH|NJ|NM|NV|NY|OH|OK|OR|PA|RI|SC|SD|TN|TX|UT|VA|VT|WA|WI|WV|WY";
	var enteredState = stateField.value.toUpperCase();
	
	var validStateListBound = "|" + validStateList + "|";
	if (validStateListBound.indexOf("|" + enteredState + "|") < 0) {
		return "State abbreviation must be be one of the following: " + validStateList.replace(/\|/g,", ") + ".";
	}
	
	return "";
}
