<!-- // Begin hiding from old browsers

/*	
	Javascript functions:
	isEmpty(STRING s)
	isWhitespace(STRING s)
	stripCharsInBag(STRING s, STRING bag)
	stripWhitespace(STRING s, STRING whitespace)
	charInString(STRING c, STRING s)
	stripInitialWhitespace(STRING s)
	isEmail(STRING s)
	hasQuotes(STRING s)
	hasAnyQuotes(STRING s)
	hasDollar(STRING s)
	hasCommas(STRING s) 
	chkLength(STRING s, INTEGER l)
	isDigit(STRING s)
	isInteger(STRING s)
	isDecimalNumber(STRING s, INTEGER l)
	isIntegerInRange (s, a, b)
	makeArray(INTEGER n): makes array of length n
	daysInFebruary(INTEGER year)
	isDate(INTEGER year, INTEGER month, INTEGER day)
	isMonth(INTEGER month)
	isAlphaNumeric(STRING s)
	chkDateMDY(STRING s)
	chkTimeHHMM(STRING s)
	formatMilitaryTime(STRING time, STRING meridiem)
	compareTimes(STRING time1, STRING time2)
	isDecimalNumber(STRING string, INTEGER decplaces)
	compareDates(STRING date1, STRING date2)
	isLogin(STRING string)
	emailCheck(STRING string)
*/

//	load whitespace characters: space,\n:manual line feed,\t:tab, and \r:carriage return
var whitespace = " \t\n\r";

//	load double quote character 
var quotes = "\""

//	load both quote characters
var bquotes = "\'\""

//  load alphanumeric characters
var alphanumeric="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

/*	isEmpty(STRING s): returns true if string s is empty */
function isEmpty(s) 
{   
	return ((s == null) || (s.length == 0))
}

/*	isWhitespace(STRING s): returns true if string s is empty or 
	whitespace characters only. Calls isEmpty */
function isWhitespace(s)
{   
	var i;
    if (isEmpty(s)) return true;
    // search string until non-whitespace character found. 
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (whitespace.indexOf(c) == -1) return false;
    }
    return true;
}

/*	hasWhitespace(STRING s):  returns true if string s has 
	whitespace characters */
function hasWhitespace(s)
{   
	var i;
    // search string until whitespace character found.
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (whitespace.indexOf(c) != -1) return true;
    }
    return false;
}

/*	stripCharsInBag(STRING s, STRING bag): removes all characters 
	which appear in string bag. */
function stripCharsInBag (s, bag)
{   
	var i;
    var returnString = "";
    // search string removing bag characters
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

/*	stripWhitespace(STRING s, STRING whitespace): removes all 
	whitespace characters from string s.  Calls stripCharsInBag */
function stripWhitespace(s)
{   
	return stripCharsInBag(s, whitespace)
}

/*	charInString(STRING c, STRING s):  finds a character in a string 
	s.  */
function charInString (c, s)
{   
	for (i = 0; i < s.length; i++)
    {   
		if (s.charAt(i) == c) return true;
    }
    return false
}

/*	stripInitialWhitespace(STRING s): removes initial whitespaces 
	from string s. Calls charInString */
function stripInitialWhitespace (s)
{   var i = 0;
    while ((i < s.length) && charInString (s.charAt(i), whitespace))
		i++;
    var newstr = s.substring (i, s.length);
    return(newstr);
}


/*	isEmail(STRING s): returns true if valid email address from 
	string s.  Must be of form a@b.c:
	- 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
	- only one @  */
function isEmail(s)
{   
	var i = 1;
    var sLength = s.length;
    
    // search for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { 
		i++
    }
    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;
    
    // search for period
    while ((i < sLength) && (s.charAt(i) != "."))
    { 
		i++
    }
    
    // must be at least one character after the period
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    
    // only one @
    var j = 0, k = 0;
    while (j < sLength)
    { 
		if (s.charAt(j) == "@") k = k + 1;
    	j++
    }
    if (k != 1) return false;    
    else return true;
}


/*	hasQuotes(STRING s): returns true if string s has double quote 
	character function */
function hasQuotes(s)
{   
	var i;
    for (i = 0; i < s.length; i++)
    {   
		var c = s.charAt(i);
        if (quotes.indexOf(c) != -1) return true;
    }
    return false;
}

/*	hasAnyQuotes(STRING s): returns true if string s has either 
	single or double quote characters */
function hasAnyQuotes(s)
{   
	var i;
    for (i = 0; i < s.length; i++)
    {   
		var c = s.charAt(i);
        if (bquotes.indexOf(c) != -1) 
			return true;
    }
    return false;
}


//	hasDollar(STRING s): returns true if string s has dollar char
function hasDollar(s)
{   
	for (var i = 0; i < s.length; i++) 
	{
		if (s.charAt(i) == '$') 
		{
			return true
		}
	}
	return false;
}
   
//	hasCommas(STRING s) : returns true if string s has commas
function hasCommas(s)
{   
	for (var i = 0; i < s.length; i++) 
	{
		if (s.charAt(i) == ',') 
		{
			return true
		}
	}
	return false;
}

/*	chkLength(STRING s, INTEGER l): returns true if string s is 
	longer than integer l */
function chkLength(s,	l)
{	
	var strLen = s.length;
	if (strLen > l) {return true;} else {return false};
}

//	isDigit(STRING s):  return true if character is a digit
function isDigit (c)
{   
	return ((c >= "0") && (c <= "9"))
}

/*	isInteger(STRING s):  returns true if string s in an integer.
	Calls isDigit. */
function isInteger(s)
{   
	var i;
    for (i = 0; i < s.length; i++)
    {   
		var c = s.charAt(i);
        if (!isDigit(c)) return false;
    }
    return true;
}

/*	isPositiveInteger(STRING s):  returns true if string s in a positive integer.
	Calls isDigit. */
function isPositiveInteger(s)
{   
	var i;
    for (i = 0; i < s.length; i++)
    {   
		var c = s.charAt(i);
        if (!isDigit(c)) return false;
    }
    if (s <= 0) return false;
    return true;
}


/*	isIntegerInRange(STRING S, INTEGER a, INTEGER b):  returns true 
	if integer string s is with range established by a and b */
function isIntegerInRange(s, a, b)
{   // explicitly change the type to integer via parseInt
    // so that the comparison code below will work both on 
    // JavaScript 1.2 (which typechecks in equality comparisons)
    // and JavaScript 1.1 and before (which doesn't).
    var num = parseInt (s);
    return ((num >= a) && (num <= b));
}

//	makeArray(INTEGER n): makes array of length n
function makeArray(n)
{
//   this.length = n;
   for (var i = 1; i <= n; i++) 
   {
      this[i] = 0
   } 
   return this
}

//	make array for isDate function
var daysInMonth = makeArray(12);
daysInMonth[1] = 31;
daysInMonth[2] = 29;   // must programmatically check this
daysInMonth[3] = 31;
daysInMonth[4] = 30;
daysInMonth[5] = 31;
daysInMonth[6] = 30;
daysInMonth[7] = 31;
daysInMonth[8] = 31;
daysInMonth[9] = 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;

/*	daysInFebruary(INTEGER year): Given integer argument year, 
	returns number of days in February of that year. */
function daysInFebruary(year)
{   // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}

/*	isDate(STRING year, STRING month, STRING day): returns true 
	if string arguments year, month, and day form a valid date. */
function isDate(year, month, day)
{   // Explicitly change type to integer to make code work in both
    // JavaScript 1.1 and JavaScript 1.2.
    var intYear = parseInt(year);
    var intMonth = parseInt(month);
    var intDay = parseInt(day);

    // catch invalid days, except for February
    if (intDay > daysInMonth[intMonth]) return false; 
    if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;
    return true;
}

/* isMonth(STRING month): return true if month is valid */
function isMonth(month) 
{	if (!isInteger(month)) return false;
	var intMonth = parseInt(month);
	if (!isIntegerInRange(intMonth, 1, 12)) return false;
	return true;
}

/* isDay(STRING day): return true if day is valid */
function isDay(day) 
{	if (!isInteger(day)) return false;
	var intDay = parseInt(day);
	if (!isIntegerInRange(intDay, 1, 31)) return false;
	return true;
}

/* isYear(STRING year): return true if year is valid */
function isYear(year) 
{	if (!isInteger(year)) return false;
	if (year.length != 4) return false;
	var intYear = parseInt(year);
	var Today = new Date();
	var yrToday = Today.getFullYear();
	if (intYear < yrToday) return false;
	return true;
}

/* isHour(STRING hour): return true if hour is valid */
function isHour(hour) 
{	if (!isInteger(hour)) return false;
	var intHour = parseInt(hour);
	if (!isIntegerInRange(intHour, 0, 23)) return false;
	return true;
}

/* isMinute(STRING minute): return true if minute is valid */
function isMinute(minute) 
{	if (!isInteger(minute)) return false;
	var intMinute = parseInt(minute);
	if (!isIntegerInRange(intMinute, 0, 59)) return false;
	return true;
}

/* isAlphaNumeric(STRING S): determines if string S is entirely composed of 
alpha numeric characters */
function isAlphaNumeric(string) 
{
	for (var i = 0; i < string.length; i++) 
	{
        if (alphanumeric.indexOf(string.charAt(i)) < 0)
        {
            return false;
        }
    }
    return true;
}

/* chkDateMDY(STRING S): determines if string S is a valid date submitted in 
format MM/DD/YYYY */
function chkDateMDY(string)
{
	// verify it is not an empty string
	if (isEmpty(string)) { return false; };
	var slash1 = string.indexOf("/"); 
	var slash2 = string.indexOf("/", slash1 + 1); 
	// verify two slashes present in string
	if ( (slash1 < 0) || (slash2 < 0) ) { return false; }
	// parse string by slashes
	var month = string.substring(0, slash1);
	var day = string.substring(slash1 + 1, slash2);
	var year = string.substring(slash2 + 1, string.length);
	// verify each substring is nonempty
	if ( isWhitespace(month) || isWhitespace(day) || isWhitespace(year)) { return false };
	// verify each substring is a number
	if ( isNaN(month) || isNaN(day) || isNaN(year) ) { return false; }
	// verify each substring is a positive integer
	if ( (parseInt(month) < 1) || (parseInt(day) < 1) || (parseInt(year) < 1) ) { return false; }
	// verify the string is a valid date
	if (!isDate(year, month, day)) { return false; }
	return true;
}

/* chkTimeHHMM(STRING S): determines if string S is a valid time submitted in 
format HH:MM */
function chkTimeHHMM(string)
{
	// verify it is not an empty string
	if (isEmpty(string)) { return false; };
	// verify presence of colon
	var colon1 = string.indexOf(":"); 
	if (colon1 < 0) { return false; }
	// parse string by colon
	var hour = string.substring(0, colon1);
	var minute = string.substring(colon1 + 1, string.length);
	// verify each substring is nonempty
	if ( isWhitespace(hour) || isWhitespace(minute) ) { return false };
	// verify each substring is a number
	if ( isNaN(hour) || isNaN(minute) ) { return false; }
	// verify hour is between 1 and 12
	if ( (parseInt(hour) < 1) || (parseInt(hour) > 12) ) { return false; }
	// verify minute is between 0 and 59
	if ( (parseInt(minute) < 0) || (parseInt(minute) > 59) ) { return false; }
	return true;
}


/* formatMilitaryTime(time, meridiem): converts time with AM/PM to military time */
function formatMilitaryTime(time, meridiem)
{
	// separate hours/minutes of time
	var colon = time.indexOf(":"); 
	var hour = time.substring(0, colon);
	var minute = time.substring(colon + 1, time.length);
	// make sure values treated as numbers
	hour = hour * 1;
	minute = minute * 1;
	// adjust based on 24 format
	if ( (meridiem == "AM") && (hour == 12) ) { hour = 0; }
	if ( (meridiem == "PM") && (hour != 12) ) { hour = hour + 12; }
	// add 0 characters if necessary
	if (hour < 10) { hour = '0' + hour; }
	if (minute < 10) { minute = '0' + minute; }
	var newtime = hour + ":" + minute
	return newtime;
}

/* compareTimes(time1, time2): compares two times in HH:MM military format */
function compareTimes(time1, time2)
{
	// separate hours/minutes of time1
	var colon1 = time1.indexOf(":"); 
	var hour1 = time1.substring(0, colon1);
	var minute1 = time1.substring(colon1 + 1, time1.length);
	var colon2 = time2.indexOf(":"); 
	var hour2 = time2.substring(0, colon2);
	var minute2 = time2.substring(colon2 + 1, time2.length);
	// make sure values treated as numbers
	hour1 = hour1 * 1;
	minute1 = minute1 * 1;
	hour2 = hour2 * 1;
	minute2 = minute2 * 1;
	// do comparison
	if (hour2 < hour1) { return false; }
	if ( (hour2 == hour1) && (minute2 <= minute1) ) { return false; }
	return true;
}

/* isDecimalNumber(STRING s, INTEGER l): verifies that the string s is number, and it is 
at most l digits behind the decimal point */
function isDecimalNumber(string, decplaces)
{
	if (isNaN(string)) return false;
	if (string.indexOf('.') == -1) string += ".";
	var dectext = string.substring(string.indexOf('.')+1, string.length);
	if (dectext.length > decplaces) return false;
	return true;
}

/* compareDates (STRING date1, STRING date2): compares two dates values. Returns
0 if the same, -1 if date1 is earlier, 1 if date2 is earlier */
function compareDates(date1, date2) 
{
	var day1, day2;
	var month1, month2;
	var year1, year2;

	month1 = date1.substring(0, date1.indexOf("/"));
	day1 = date1.substring(date1.indexOf("/") + 1, date1.lastIndexOf("/"));
	year1 = date1.substring (date1.lastIndexOf("/") + 1, date1.length);
	
	month2 = parseInt( date2.substring (0, date2.indexOf("/")) );
	day2 = parseInt( date2.substring (date2.indexOf("/") + 1, date2.lastIndexOf("/")) );
	year2 = parseInt( date2.substring (date2.lastIndexOf("/") + 1, date2.length) );

	month1 = parseInt(month1);
	day1 = parseInt(day1);
	year1 = parseInt(year1);

	month2 = parseInt(month2);
	day2 = parseInt(day2);
	year2 = parseInt(year2);
	
	if (year1 > year2) return 1;
	else if (year1 < year2) return -1;
	else if (month1 > month2) return 1;
	else if (month1 < month2) return -1;
	else if (day1 > day2) return 1;
	else if (day1 < day2) return -1;
	else return 0;
} 

/* isLogin(string): determines if string is a valid login */
function isLogin(string)
{
	// possible e-mail?
	if ( string.indexOf("@") != -1 )
	{
		return emailCheck(string);
	} else
	{
		// must be alphanumeric
		if ( !isAlphaNumeric(string) )
		{
			alert('Username is invalid format.');
			return false;
		} else
		{
			return true;
		}
	}
}

/* emailCheck(string): verifies an string is in email format */
function emailCheck(emailStr) 
{
	var emailPat = /^(.+)@(.+)$/;
	var specialChars = "\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars = "\[^\\s" + specialChars + "\]";
	var quotedUser = "(\"[^\"]*\")";
	var ipDomainPat = /^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom = validChars + '+';
	var word = "(" + atom + "|" + quotedUser + ")";
	var userPat = new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

	// break up address
	var matchArray = emailStr.match(emailPat);

	if (matchArray == null) 
	{
		alert("Email address seems incorrect (check @ and .'s)");
		return false;
	}

	var user = matchArray[1];
	var domain = matchArray[2];

	// check that only basic ASCII characters are in the strings
	for (i = 0; i < user.length; i++) 
	{
		if (user.charCodeAt(i) > 127) 
		{
			alert("Username contains invalid characters.");
			return false;
		}
	}

	for (i = 0; i < domain.length; i++) 
	{
		if (domain.charCodeAt(i) > 127) 
		{
			alert("Domain name contains invalid characters.");
			return false;
		}
	}

	// "user" valid 
	if (user.match(userPat) == null) 
	{
		// user is not valid
		alert("Username doesn't seem to be valid.");
		return false;
	}

	// valid IP e-mail address?
	var IPArray=domain.match(ipDomainPat);

	if (IPArray != null) 
	{
		for (var i = 1; i <= 4; i++)
		{
			if (IPArray[i] > 255) 
			{
				alert("Destination IP address is invalid!");
				return false;
			}
		}
		return true;
	}

	// validate domain symbolic name
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	
	for (i = 0; i < len; i++) 
	{
		if (domArr[i].search(atomPat) == -1) 
		{
			alert("The domain name does not seem to be valid.");
			return false;
		}
	}

	// validate host name 
	if (len < 2) 
	{
		alert("This address is missing a hostname!");
		return false;
	}

	// validated
	return true;

}

// End of hide -->
