<!--
/*
	Function list and explanation
	
	isEmpty(s)							This checks to see if a string is empty.
	isBlank(s)							This checks to see if a string is empty or conatins only whitespace.
	ltrim(s)							Trims whitespace from the left of a string.
	rtrim(s)							Trims whitespace from the right of a string.
	trim(s)								Trims withespace from both sides of a string.
	isValidPhoneNum(s)					Checks for a phone number in xxx-xxx-xxxx format.
	isValidPhoneExt(s)					Ensures that a phone extension is 1 - 10 numbers in length
	isValidZipCode(s)					Checks for a zip code in xxxxx format.
	isValidEmail(s)						Checks for a valid email address.
	replaceChars(theStr, remove, add)	Replace some characters with others.
	containsWhiteSpace(s)				Lets you know if a string contains whitespace.
	textCounter(field, countfield, max)	Counts the characters remaining in a text area.
	convertBR(input)					Converts carriage returns to <BR> for display in HTML
*/

//****** Variable declarations ******

var defaultEmptyOK = false;		// default falue to not allow a string to be empty
var whitespace = " \t\n\r";		// whitespace characters

// Detect if browser is Netscape 3 + or IE 4 +.
bName = navigator.appName;
bVer = parseInt(navigator.appVersion);
if ((bName == "Netscape" && bVer >= 3) || 
	(bName == "Microsoft Internet Explorer" && bVer >= 4)) br = "n3"; 
else br = "n2";
// End browser detect

//*****End Variable declarations ****

// Check whether a string is empty.
function isEmpty(s) {
	return ((s == null) || (s.length == 0));
}


// Returns true if the string is empty or contains only whitespace characters
function isBlank(s) {
    // See if the string is empty
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.
	var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
		if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}

// Trim white space on the left
function ltrim(s) {
	return s.replace(/^\s*/, "")
}

// Trim white space on the right
function rtrim(s) {
	return s.replace(/\s*$/, "");
}

// Trim white space on both ends
function trim(s) {
	return rtrim(ltrim(s));
}

// This function ensures that a phone number is in the xxx-xxx-xxxx format
function isValidPhoneNum(s) {
	var PhoneRegEx = new RegExp(/^\d{3}-\d{3}-\d{4}$/);
	
	return (s.match(PhoneRegEx));
}

// This function ensures that a phone extension is 1 - x numbers in length
function isValidPhoneExt(s) {
	var ExtRegEx = new RegExp(/^\d{1,10}$/);
	
	return (s.match(ExtRegEx));
}

// This function ensures that a zip code is in the xxxxx format
function isValidZipCode(s) {
	var ZipRegEx = new RegExp(/^\d{5}$/);
	
	return (s.match(ZipRegEx));
}

// This function checks to see if an email address is valid
function isValidEmail(s) {
	var EmailRegEx = new RegExp(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/);
	
	return (s.match(EmailRegEx));
}

// Replace a set of characters with another set
function replaceChars(theStr, remove, add) {
	tempString = theStr; // temporary holder

	while (tempString.indexOf(remove) > -1) {
		pos = tempString.indexOf(remove);
		tempString = "" + (tempString.substring(0, pos) + add + 
		tempString.substring((pos + remove.length), tempString.length));
	}
	return tempString;
}

// Function to let us know if a string contains any whitespace
function containsWhiteSpace(s) {
	var WSRegEx = new RegExp(/\s/)
	
	return (s.match(WSRegEx));
}

// Count the characters remaining in the text area
function textCounter(field, countfield, max) {
	if (field.value.length > max) // if too long...trim it!
		field.value = field.value.substring(0, max);
	// otherwise, update 'characters left' counter
	else 
	countfield.value = max - field.value.length;
}

// Converts carriage returns to <br> for display in HTML
function convertBR(input) {
	var output = "";
	for (var i = 0; i < input.length; i++) {
		if ((input.charCodeAt(i) == 13) && (input.charCodeAt(i + 1) == 10)) {
			i++;
			output += "<br>";
		} 
		else {
			output += input.charAt(i);
		}
	}
	
	return output;
}

//-->