<!--
/**********************************
   Generic Global Variables
**********************************/
var reEmail = /^.+\@.+\..+$/
var whitespace = " \t\n\r";
var defaultEmptyOK = false

/*******************************************************/
/* General purpose utility functions used primarily for CSV
of site-wide feedback forms*/
/*******************************************************/


/* FUNCTIONS TO INTERACTIVELY CHECK VARIOUS FIELDS. */


// Returns true if character c is a digit
// (0 .. 9).

function isDigit(c) {
	return ((c >= "0") && (c <= "9"))
}

// isInteger (STRING s [, BOOLEAN emptyOK])
//
// Returns true if all characters in string s are numbers.
//
// Accepts non-signed integers only. Does not accept floating
// point, exponential notation, etc.
//
// We don't use parseInt because that would accept a string
// with trailing non-numeric characters.
//
// By default, returns defaultEmptyOK if s is empty.
// There is an optional second argument called emptyOK.
// emptyOK is used to override for a single function call
//      the default behavior which is specified globally by
//      defaultEmptyOK.
// If emptyOK is false (or any value other than true),
//      the function will return false if s is empty.
// If emptyOK is true, the function will return true if s is empty.
//
// EXAMPLE FUNCTION CALL:     RESULT:
// isInteger ("5")            true
// isInteger ("")             defaultEmptyOK
// isInteger ("-5")           false
// isInteger ("", true)       true
// isInteger ("", false)      false
// isInteger ("5", false)     true

function isInteger(s) {

	var i;

	if (isEmpty(s)) {
		if (isInteger.arguments.length == 1) {
			return defaultEmptyOK;
		} else {
			return (isInteger.arguments[1] == true);
		}
	}

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++) {

        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

// checkString (TEXTFIELD theField, STRING s, [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is not all whitespace.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function checkString (theField, emptyOK) {
	// Next line is needed on NN3 to avoid "undefined is not a number" error
    // in equality comparison below.
    if (checkString.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (isWhitespace(theField.value)) {
		return false;
    } else return true;
}

// Check whether string s is empty.

function isEmpty(s) {
	return ((s == null) || (s.length == 0))
}

// Returns true if string s is empty or
// whitespace characters only.

function isWhitespace (s) {
	var i;

    // Is s 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.

    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;
}

// checkEmail (TEXTFIELD theField [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is a valid Email.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function checkEmail (theField, emptyOK) {
    if (checkEmail.arguments.length == 1) {
        emptyOK = defaultEmptyOK;
    }   
    if ((emptyOK == true) && (isEmpty(theField.value))) {
		return true;
    } else if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(theField.value))) {
		return false;
    } else {
        return true;
    }
}

// isEmail (STRING s [, BOOLEAN emptyOK])
//
// Email address must be of form a@b.c -- in other words:
// * there can be no embedded white-space
// * there must be at least one character before the @
// * there must be at least one character before and after the .
// * the characters @ and . are both required
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isEmail (s) {

	if (isEmpty(s))
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);

    var i;
    var sLength = s.length;

    // s cannot have embedded whitespace
    for (i = 0; i < sLength; i++)
    {
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (whitespace.indexOf(c) != -1) return false;
    }

    // there must be >= 1 character before @, so we
    // start looking at character position 1
    // (i.e. second character)
	i = 1;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}


	function checkDate(field) {
		var RegExPattern = /^(?=\d)(?:(?:(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})|(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2}))($|\ (?=\d)))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$/;
		if (field.value.match(RegExPattern)) {
			return true;
		} else {
			return false;
		} 
	}

	function checkYear(field) {
		var RegExPattern = /\d{4}/;
		if (field.value.match(RegExPattern)) {
			return true;
		} else {
			return false;
		} 
	}
	
	
	// check5DigitZIP(TEXTFIELD theField [, BOOLEAN emptyOK==false])
	//
	// Check that string theField.value is a valid ZIP code.
	//
	// For explanation of optional argument emptyOK,
	// see comments of function isInteger.
	
	function check5DigitZIP(theField, emptyOK) {
		if (check5DigitZIP.arguments.length == 1) emptyOK = defaultEmptyOK;
		if ((emptyOK == true) && (isEmpty(theField.value))) {
			return true;
		} else {
			if (!isInteger(theField.value) || theField.value.length != 5) {
				return false;
			}
		}
	
		return true;
	}
	
	function checkURL(value) {
		var urlregex = new RegExp("^(http:\/\/|https:\/\/|ftp:\/\/){1}([0-9A-Za-z]+\.)");
		return urlregex.test(value);
	}
	
	function createNamedElement(type, name) {
		var element;
		try {
			element = document.createElement('<'+type+' name="'+name+'">');
		} catch (e) { }
			if (!element || !element.name) { // Not in IE, then
				element = document.createElement(type)
				element.name = name;
			}
		return element;
	}
	
	function createCaptchaTextField(type, name, value, size) {
		var element = createNamedElement(type, name);
		element.setAttribute("id", name);
		element.setAttribute("value", value);
		element.size = Number(size);
		return element;
	}
	
	function createCaptchaHiddenField(name, value) {
		var element = createNamedElement('input', name);
		element.setAttribute("type", "hidden");
		element.setAttribute("id", name);
		element.setAttribute("value", value);
		return element;
	}
		
	function autoSelect(id) {
		
		var el = document.getElementById(id);
		
		if(el && (el.tagName == "TEXTAREA" || (el.tagName == "INPUT" && el.type == "text"))) {
			el.select();
			return;
		}
		
		if(el && window.getSelection) { // FF, Safari, Opera
			var sel = window.getSelection();
			var range = document.createRange();
			range.selectNodeContents(el);
			sel.removeAllRanges();
			sel.addRange(range);
		} else if(el) { // IE
			document.selection.empty();
			var range = document.body.createTextRange();
			range.moveToElementText(el);
			range.select();
			window.status="Contents highlighted and copied to clipboard!";
			setTimeout("window.status=''",1800);
		}
	}
//-->
