<!--
//********************************************************************************************************
//	Reusable Javascript functions
//	Note: Please do not change any variable names
//********************************************************************************************************

//GLOBAL VARIABLES
// whitespace characters
var whitespace = " \t\n\r";
// decimal point character
var decimalPointDelimiter = "."

//********************************************************************************************************
//STRING FUNCTIONS
//********************************************************************************************************
// 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;
}

// Removes all characters which appear in string bag from string s.
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;
}

// Removes all characters which do NOT appear in string bag 
// from string s.

function stripCharsNotInBag (s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is 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;
}

// Removes initial (leading) whitespace characters from s.
function stripInitialWhitespace (s)

{   var i = 0;
    while ((i < s.length) && charInString (s.charAt(i), whitespace))
       i++;    
    return s.substring (i, s.length);
}

// Returns true if single character c (actually a string)
// is contained within string s.
function charInString (c, s)
{   for (i = 0; i < s.length; i++)
    {   if (s.charAt(i) == c) return true;
    }
    return false
}

//function returns the number of occurences of character 'c' in string 's'.
function numberofOccurences(c,s) {
	bOccur = 0;
	for (i = 0; i < s.length; i++)
    	{ if (s.charAt(i) == c) { bOccur = bOccur + 1 } 	}
	return bOccur;	
}

// Returns true if character c is an English letter 
// (A .. Z, a..z).
function isLetter (c)
{   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}

// isEmail (STRING s [, BOOLEAN emptyOK])
// 
// Email address must be of form a@b.c -- in other words:
// * 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.

var defaultEmptyOK = false

function isEmail (s) { 
var s= alltrim(s); 
	if (isEmpty(s)) 
     if (isEmail.arguments.length == 1) return defaultEmptyOK;
     else return (isEmail.arguments[1] == true);

  // is s whitespace?
  if (isWhitespace(s)) return false;
		
	// Check the white space in the email address
 	if (Checkbetweenwhitespace(s)) return false;
 	
  // there must be >= 1 character before @, so we
  // start looking at character position 1 
  // (i.e. second character)
  var i = 1;
  var sLength = s.length;

  // 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;

	// Check there is no invalid chars in the address
	var specialChars="<>,;:()"
	for (i = 0; i < s.length; i++) {
		if (charInString(s.charAt(i), specialChars)) // Returns true if single character c (actually a string)
			return false;
	}
// Check there is only 1 @ in the address
	j = 0;
	for (i = 0; i < s.length; i++) {
		if (s.charAt(i) == "@") j++
	}
	if (j > 1) return false;
// Check we do not have .. in the address
	for (i = 0; i < s.length-1; i++) {
		if (s.charAt(i) == "@" && s.charAt(i+1) == ".") return false;
		if (s.charAt(i) == "." && s.charAt(i+1) == ".") return false;
	}

// Check that the end part of the email address looks correct		
	var suffix=s.substring(s.lastIndexOf(".")+1,s.length)
	suffix=suffix.toUpperCase()
	if (!(suffix == "NET" || suffix == "COM" || suffix == "EDU" || suffix == "ORG" || suffix == "GOV" || suffix == "MIL" || suffix == "US" || suffix == "CA" || suffix == "UK")) {
		var bchoice = window.confirm("The end part of the email address is not one of the more common endings (e.g. COM, NET etc.).\nPlease check it is correct, Press 'OK' to continue or 'Cancel' to correct it.");
		if (!bchoice == true)
			return false;
	}

  return true;
}

//function to trim the leading and trailing spaces
//s is the string to trimmed
function stripSpaces(s) {
    while (s.substring(0,1) == ' ') s = s.substring(1);
    while (s.substring(s.length-1,s.length) == ' ') s = s.substring(0,s.length-1);
	return s
}

// Returns true if character c is a letter or digit.
function isLetterOrDigit (c)
{   return (isLetter(c) || isDigit(c))
}

// reformat (TARGETSTRING, STRING, INTEGER, STRING, INTEGER ... )       
//
// Handy function for arbitrarily inserting formatting characters
// or delimiters of various kinds within TARGETSTRING.
//
// reformat takes one named argument, a string s, and any number
// of other arguments.  The other arguments must be integers or
// strings.  These other arguments specify how string s is to be
// reformatted and how and where other strings are to be inserted
// into it.
//
// reformat processes the other arguments in order one by one.
// * If the argument is an integer, reformat appends that number 
//   of sequential characters from s to the resultString.
// * If the argument is a string, reformat appends the string
//   to the resultString.
//
// NOTE: The first argument after TARGETSTRING must be a string.
// (It can be empty.)  The second argument must be an integer.
// Thereafter, integers and strings must alternate.  This is to
// provide backward compatibility to Navigator 2.0.2 JavaScript
// by avoiding use of the typeof operator.
//
// It is the caller's responsibility to make sure that we do not
// try to copy more characters from s than s.length.
//
// EXAMPLES:
//
// * To reformat a 10-digit U.S. phone number from "1234567890"
//   to "(123) 456-7890" make this function call:
//   reformat("1234567890", "(", 3, ") ", 3, "-", 4)
//
// * To reformat a 9-digit U.S. Social Security number from
//   "123456789" to "123-45-6789" make this function call:
//   reformat("123456789", "", 3, "-", 2, "-", 4)
//
// HINT:
//
// If you have a string which is already delimited in one way
// (example: a phone number delimited with spaces as "123 456 7890")
// and you want to delimit it in another way using function reformat,
// call function stripCharsNotInBag to remove the unwanted 
// characters, THEN call function reformat to delimit as desired.
//
// EXAMPLE:
//
// reformat (stripCharsNotInBag ("123 456 7890", digits),
//           "(", 3, ") ", 3, "-", 4)

function reformat (s)
{   var arg;
    var sPos = 0;
    var resultString = "";

    for (var i = 1; i < reformat.arguments.length; i++) {
       arg = reformat.arguments[i];
       if (i % 2 == 1) resultString += arg;
       else {
           resultString += s.substring(sPos, sPos + arg);
           sPos += arg;
       }
    }
    return resultString;
}

/*
This function capitalizes the first letter of a the word passed in the parameter s.
*/
function initCap(s) {
	var index;
	var tmpStr;
	var tmpChar;
	var preString;
	var postString;
	var strlen;
	tmpStr = s.toLowerCase();
	strLen = tmpStr.length;
	if (strLen > 0)  {
		for (index = 0; index < strLen; index++)  
		{
		if (index == 0)  {
			tmpChar = tmpStr.substring(0,1).toUpperCase();
			postString = tmpStr.substring(1,strLen);
			tmpStr = tmpChar + postString;
			}
		else {
			tmpChar = tmpStr.substring(index, index+1);
			if (tmpChar == " " && index < (strLen-1))  {
					tmpChar = tmpStr.substring(index+1, index+2).toUpperCase();
					preString = tmpStr.substring(0, index+1);
					postString = tmpStr.substring(index+2,strLen);
					tmpStr = preString + tmpChar + postString;
         }
      }
   }
}
s = tmpStr;
return s
}

/*Number format function
s - string to be converted
lead-lead character such as $
sep - seperator character, such as ,
*/
function numFormat(s, lead, sep)
{
	if (s == '') return s;
	s=replaceChars(s,'$', '');
	s=replaceChars(s,',', '');
	s=replaceChars(s,'%', '');
	var value = parseInt(s, 10);
	if (0 > value) value = 0;
	if (isNaN(value)) {
		alert('Invalid Number. \nPlease check your information and try again.');
		s = '';
		return false;
	}
	s = format(value, lead, sep);
	return s;
}

function format(value, lead, sep)
{
	var strValue = new String(value);
	var len = strValue.length;
	var n;
	var strRet = '';
	var ctChar = 3 - (len%3);
	if (ctChar == 3) ctChar =0;
	for (n=0; len > n; n++) {
		if (ctChar == 3) {
			strRet += sep;
			ctChar = 0;
		}
		ctChar++;
		strRet += strValue.substring(n,n+1)		
	}
	if (lead == '%') {
		return strRet + lead;
	}
	else {
		return lead + strRet;
	}
}

// function to replace single or multiple chars in a string with new strings
//s is the original string, out are chars to be replaced and add are the chars to be replaced with
// i.e., replace ALL 'out' chars in 's' with 'add' chars

function replaceChars(s,out,add) {
	temp = "" + s; // temporary holder
	while (temp.indexOf(out)>-1) {
		pos= temp.indexOf(out);
		temp = "" + (temp.substring(0, pos) + add + 
		temp.substring((pos + out.length), temp.length));
	}
	return temp;
}

// Returns true if string s is ' 
var invalidChars = "'"; 	//Invalid character for sql
function isInvalidChar(s) {
var i;
	// Search through string's characters one by one
	// until we find a ' character.
	// When we do, return false; if we don't, return true.
	for (i = 0; i < s.length; i++) {
		if (s.charAt(i) == "'") {
			return false;
		}
	}
	return true;
}

//********************************************************************************************************
//DATE FUNCTIONS
//example : function to check if a date is valid.
/*
function chkdate() {
	parsedate(document.myform.datefield.value);
	alert(isDate(CurrDate_Array[1],CurrDate_Array[0],CurrDate_Array[2]))	
	}
the above function return true if date passed is a valid date and false if not	
*/
//**************************************************************************************************
//seperates out the month, day and year out of a date string passed.  The delimiter is "/"
function parsedate(CurrDate)
{	
	CurrDate_Array=CurrDate.split("/");
	return CurrDate_Array
}

//This function is used to resolve a 4 digit y2k year.  if the number is passed is less than 50 then it is treated 
// as a year in 21st century otherwise a year in the 20th century
function y2k(number) 
{ 
// Firefox returns year as 101 in a lot of instances, so this will convert that
	if (eval(number) < 200)
	{
		if ( eval(number) < 50)
		{
			number=	eval(number) + 2000
		}
		else 
		{
			number=eval(number)+1900
		}
	}
	return number;
}

// isDate (STRING year, STRING month, STRING day)
// isDate returns true if string arguments year, month, and day  form a valid date.
//I must still look into developing this function. currently it takes only 2 and 4 digit dates

function isDate (year, month, day)
{  
// if the values passed in are not integers then return false
	if(!(isInteger(year) && isInteger(month) && isInteger(day)) ) return false
	if ((month*1 > 12) || (day*1 > 31) || (month*1 < 1) || (day*1 < 1)) return false

	thisyear=y2k(year);
	if(thisyear < 1900) return false;
	thismonth=month*1-1;	//it is a 0 based month
	thisday=day;	
	
	/* Using form values, create a new date object
	which looks like "Wed Jan 1 00:00:00 EST 1975". */
	var myDate = new Date(thisyear,thismonth,thisday);

	// Convert the date to a string so we can parse it.
	var myDate_string = myDate.toGMTString();

	/* Split the string at every space and put the values into an array so,
	using the previous example, the first element in the array is "Wed", the
	second element is "Jan", the third element is "1", etc. */
	var myDate_array = myDate_string.split(' ');
	
	/* If we entered "Feb 31, 1975" in the form, the "new Date()" function
	converts the value to "Mar 3, 1975". Therefore, we compare the month
	in the array with the month we entered into the form. If they match,
	then the date is valid, otherwise, the date is NOT valid. */

	if ( myDate_array[2] != monthName[month*1].substring(0,3) ) return false
	else return true;
}

// isIntegerInRange (STRING s, INTEGER a, INTEGER b )
// 
// isIntegerInRange returns true if string s is an integer 
// within the range of integer arguments a and b, inclusive.

function isIntegerInRange (s, a, b)
{   
    // Catch non-integer strings to avoid creating a NaN below, 
    // which isn't available on JavaScript 1.0 for Windows.
    if (!isInteger(s, false)) return false;
    // Now, 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));
}


// isYear (STRING s )
// isYear returns true if string s is a valid Year number.  Must be 2 or 4 digits only.
// For Year 2000 compliance, you are advised to use 4-digit year numbers everywhere.

function isYear (s)
{  
	alert(isYear.arguments[1]);
	if (isEmpty(s)) 
       if (isYear.arguments.length == 1) return false;
       else return (isYear.arguments[1] == true);
//    if (!isNonnegativeInteger(s)) return false;
    return ((s.length == 2) || (s.length == 4));
}


// isMonth (STRING s)
// 
// isMonth returns true if string s is a valid 
// month number between 1 and 12.

function isMonth (s)
{   if (isEmpty(s)) 
       if (isMonth.arguments.length == 1) return false;
       else return (isMonth.arguments[1] == true);
    return isIntegerInRange (s, 1, 12);
}

// isDay (STRING s)
// 
// isDay returns true if string s is a valid 
// day number between 1 and 31.

function isDay (s)
{   if (isEmpty(s)) 
       if (isDay.arguments.length == 1) return false;
       else return (isDay.arguments[1] == true);   
    return isIntegerInRange (s, 1, 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 );
}


function makeArray(n) {
   for (var i = 1; i <= n; i++) {
      this[i] = 0
   } 
   return this
}

var monthName = new Array(12);
monthName[1] = 'January'
monthName[2] = 'February'
monthName[3] = 'March'
monthName[4] = 'April'
monthName[5] = 'May'
monthName[6] = 'June'
monthName[7] = 'July'
monthName[8] = 'August'
monthName[9] = 'September'
monthName[10] = 'October'
monthName[11] = 'November'
monthName[12] = 'December'
	
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;

function isValidDate(f) {
	slash1 = f.indexOf("/")
	slash2 = f.indexOf("/", slash1 + 1)
	sMonth = f.substring(0,slash1)
	month = parseInt(sMonth,10)
	sDay = f.substring(slash1+1,slash2)
	day = parseInt(sDay,10)
	sYear = f.substring(slash2+1,99)
	year = parseInt(sYear,10)
	var months = new Array("","January","February","March","April","May","June","July","August","September","October","November","December")
	if (slash1 == "" || slash1 == -1) {
		alert("Invalid Date, it must be in the format mm/dd/yyyy");//Must be first slash 
		return false;
	}
	if (slash2 == "" || slash2 == -1) {
		alert("Invalid Date, it must be in the format mm/dd/yyyy");//Must be second slash 
		return false;
	}
	if(!isNum(sMonth)){
		alert("Invalid Month, only numbers please 1 thru 12 in the format mm/dd/yyyy");
		return false;
	}
	if(!isNum(sDay)){
		alert("Invalid Day, only numbers please 1 thru 31 in the format mm/dd/yyyy");
		return false;
	}
	if(!isNum(sYear)){
		alert("Invalid Year, only numbers please 0 thru 9 in the format mm/dd/yyyy");
		return false;
	}
	if(month < 1 || month > 12) { //month is not valid
		alert("Month must be between 1 and 12");
		return false;
	}
	if(day < 1 || day > 31) { //day is not valid
		alert("Day must be between 1 and 31 depending on the month and year");
		return false;
	}
	if(sYear.length < 4) {
		if(sYear.length == 3){
			alert("The year must be four digits");
			return false;
		}
		if(sYear.length == 2) {
			if(parseInt(sYear) < 20){
				sYear = "20" + sYear;
			}else{
				sYear = "19" + sYear
			}
		}
		if(sYear.length == 1) {
			sYear = "200" + sYear;
		}
		if(sYear.length == 0) {
			alert("The year must be four digits");
			return false;
		}
	}
	if(sYear < 1940 || sYear > 2070) {
		alert("The year entered is not valid");
		return false;
	}

	month = parseInt(sMonth)

	if((month == 4 || month == 6 || month == 9 || month == 11) && day > 30) {
		alert(months[month] + " has only 30 days.");
		return false;
	}
	else if (day > 31) {
		alert(months[month] + " has only 31 days.");
		return false;
	}
		
	if(month==2) { //Check for a leap year
		if((year % 4 ==0 && year % 100 !=0) || year % 400 == 0){
			if(day > 29) {
				alert("February of " + year + " has only 29 days.");
				return false;
			}
		} else if(day > 28) {
			alert("February of " + year + " has only 28 days.");
			return false;
		}
	}
return true;
}
function doDateCheck(d1,d2) {
	if (Date.parse(d1) <= Date.parse(d2)) {
		return true;
	}
	else {
		return false;
  }
}
function isValidTime(s) {
	var sHour = s.substring(hour).length
	if(sHour < 5) {
		alert("The time must be in the format hh:mm");
		return false;
	}
	var colon = s.substring(2,3)
	var hour = s.substring(0,2)
	var minute = s.substring(3,5)
	
	hour = (parseInt(hour));
	minute = (parseInt(minute));
	if (colon != ":") {
		alert("The time must be in the format hh:mm");
		return false;
	}
		
	if (hour < 0  || hour > 23) {
		alert("Hour must be between 0 and 23 for military time)");
		return false;
	}
	
	if (minute < 0 || minute > 59) {
		alert ("Minute must be between 0 and 59.");
		return false;
	}
	
return true;
}

function doTimeCheck(s1,s2) {
	var colonS = s1.indexOf(":")
	var sHourS = s1.substring(0,colonS)
	var sMinS = s1.substring(colonS+1,5)
	var colonE = s2.indexOf(":")
	var sHourE = s2.substring(0,colonE)
	var sMinE = s2.substring(colonE+1,5)

	if ((parseInt(sHourS)) >= (parseInt(sHourE)) ) {
		if( (parseInt(sMinS)) >= (parseInt(sMinE)) ) {
			alert("Start time must occur before End time");
			return false;
		}
	}
	return true;
}

//********************************************************************************************************
//NUMBER FUNCTIONS
//********************************************************************************************************
// Returns true if character c is a digit (0 .. 9).
function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

// Returns true if all characters in string s are numbers.
function isInteger (s)

{   var i;

    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return false;
       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;
}

//converts 'c' to percetage format
	function percent(c) { 
		return Math.round((c-0)*100) + '%'; 
	}

// isFloat (STRING s)
// True if string s is a floating point (real) number. 
// Also returns true for unsigned integers. If you wish
// to distinguish between integers and floating point numbers,
// first call isInteger, then call isFloat.
// Does not accept exponential notation.
function isFloat (s)
{   
	var i;
    var seenDecimalPoint = false;
    if (s == decimalPointDelimiter) return false;
    // 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 ((c == decimalPointDelimiter) && !seenDecimalPoint) seenDecimalPoint = true;
        else if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}	

function isNum(s) {
 var i;
	// This function dectects if there is any non-numeric data in a string.
	// Returns true if all numeric, or false if non-numeric found
	
	for (i = 0; i < s.length; i++) {
		var oneChar = s.charAt(i);
		if (oneChar < "0" || oneChar > "9" ) {
			return false;
		}
	}
	return true;
}

function isAmount(s) {
var i;
var seenDecimalPoint = false;
	if (s == ".") return false;
	// 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 ((c == ".") && !seenDecimalPoint) seenDecimalPoint = true;
		else if (c < "0" || c > "9") return false;
	}
// All characters are numbers.
return true;
}

//********************************************************************************************************
//COOKIE FUNCTIONS
// name - name of the cookie
// value - value assigned to the cookie
// expires - the date when the cookiw will expire, if you are paasing the expire date, make sure you pass
//the date through the IsDate function
// REMEMBER: In the Set_Cookie function if you do not specify the expiration date then the cookie is available 
// for the current session only.  One way you can use this is to logout a user automatically when user closes
//browser.
//********************************************************************************************************

//Get the value of given cookie
function Get_Cookie(name) {
    var start = document.cookie.indexOf(name+"=");
    var len = start+name.length+1;
    if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
    if (start == -1) return null;
    var end = document.cookie.indexOf(";",len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len,end));
}

//Create a cookie, name and value are reuired.  expires indicates when the cookie will expire
function Set_Cookie(name,value,expires) {
    document.cookie = name + "=" +escape(value) +
        ( (expires) ? ";expires=" + expires.toGMTString() : "") 
}

//deleting the cookie is done by setting the expiration date of the cookie in the past.
function Delete_Cookie(name) {
    if (Get_Cookie(name)) document.cookie = name + "=" +
        ";expires=Thu, 01-Jan-70 00:00:01 GMT";
}

//********************************************************************************************************
//FORM FIELD FUNCTIONS
//********************************************************************************************************
// Get checked value from radio button.
function getRadioButtonValue (radio)
{   for (var i = 0; i < radio.length; i++)
    {   if (radio[i].checked) { break }
    }
    return radio[i].value
}

// funtion to reorder items in a list box i.e., move up or move down
//bDir is the direction you want to move false-down and true-up
//f is the form name
//lName is the listbox(select) control name

function move(f,bDir,lName) {
//	var el = f.elements[lName]
	var el=eval('document.' + f + '.' + lName)
	 var idx = el.selectedIndex
	 if (idx==-1) 
	  alert("You must first select the item to reorder.")
	 else 
	{
	  var nxidx = idx+( bDir? -1 : 1)
	  if (nxidx<0) nxidx=el.length-1
	  if (nxidx>=el.length) nxidx=0
	  var oldVal = el[idx].value
	  var oldText = el[idx].text
	  el[idx].value = el[nxidx].value
	  el[idx].text = el[nxidx].text
	  el[nxidx].value = oldVal
	  el[nxidx].text = oldText
	  el.selectedIndex = nxidx
 }
}

//functions to support the select drop down list box
//function deletes the selected option
function deleteOption(object) {
    var Current = object.selectedIndex;
    object.options[Current] = null;
}

//delete the ith option from the list
function deleteOptioni(object,i) {
    object.options[i] = null;
}

function addOption(object,currentText,currentValue,defaultSelected,Selected) {	
	if(!arguments[2]) defaultSelected = true;
	if(!arguments[3]) Selected = true;
    var optionName = new Option(currentText, currentValue, defaultSelected, Selected)
    object.options[object.options.length] = optionName;	
}

function deleteAllOptions(object) {
	object.options.length = 0
}

/*transfer options from listA to listB only - Single Select Listboxes only*/
function transferOption_Single(objectFrom,objectTo) {
    var index = objectFrom.selectedIndex;
    if (index > 0) {
        var newoption = new Option(objectFrom.options[index].text, objectFrom.options[index].value, true, true);
        objectTo.options[objectTo.length] = newoption;		
    }
}

/* transfer options from listA to listB only - MULTI/SINGLE List boxes */
function transferOption_Multi(objFrom,objTo) {
    objFrom_Len = objFrom.length ;
	objTo_Len = objTo.length ;
    for ( i=0; i<objFrom_Len ; i++){
        if (objFrom.options[i].selected == true ) {
            objTo_Len = objTo.length;			
            objTo.options[objTo_Len]= new Option(objFrom.options[i].text,objFrom.options[i].value,true,true);			
        }
    }

    for ( i = (objFrom_Len -1); i>=0; i--){
        if (objFrom.options[i].selected == true ) {
            objFrom.options[i] = null;
        }
    }
}

/*function to create a button
type - type of the button i.e, Button, Submit, Reset
bFunc - function to be called OnClick of the button
val - value assigned to the button
name - name of the field
*/
function makeBtn(type,bFunc,name,val) {
	var str='';
	str = "<INPUT TYPE=\"" + type + "\"  VALUE=\"" + val + "\" NAME=\"" + name + "\"";
	if (!isWhitespace(bFunc))  str +=" ONCLICK=\"" + bFunc + "\"" ;
	str += ">&nbsp;"  ;
	return	str
}

/*function to create a textbox	
	type - text or password
	val - value assigned to the field (textbox)
	name - name of the field
	bFunc - function to be called OnBlur of the field
	size - size of the field
	maxlen - maximum characters allowed in the field
*/

function makeTxtBox(type,name,val,size,maxlen,bFunc) {
	var str='';
	str = "<INPUT TYPE=\"" + type + "\"  VALUE=\"" + val + "\" NAME=\"" + name + "\" SIZE=\"" + size + "\" MAXLENGTH=\"" + maxlen + "\"";
	if (!isWhitespace(bFunc))  str += " ONBLUR=\"" + bFunc + "\""; 
	str += ">";
	return str;
}

/* check to see how many characters were entered in the field applies to text areas and text boxes only
	obj 		-	field
	maxChars  	- 	max characters allowed
*/		
function textCounter(obj,maxChars) {
	retVal=0;
	if (obj.value.length > maxChars) // if too long...	
	{
		obj.value = obj.value.substring(0, maxChars);	//resets the text in the field
		retVal=1;
	}
	return retVal;
}

//********************************************************************************************************
//PARSING URL PARAMETERS
//********************************************************************************************************

function Get_URL(name) {
	//URL param names are case sensitive
	var pname=name
	var str=location.href;
	var blank='';
	
    var start = str.indexOf(pname+"=");
    var len = start+pname.length+1;
    if ((!start) && (pname != str.substring(0,pname.length))) return blank;
    if (start == -1) return blank;
    var end = str.indexOf("&",len);
    if (end == -1) end = str.length;
    return unescape(str.substring(len,end));
}


//********************************************************************************************************
//OPEN NEW WINDOW
//********************************************************************************************************
function openWindow(winName,newUrl,w,h,X,Y) {
	if (!winName) winName = "NewWindow";
	if (!X) X = 0;
	if (!Y) Y = 0;
	if (!w) w = 400;
	if (!h) h = 400;
    var NWnd = window.open(newUrl,winName,"toolbar=no,location=no,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=Yes,copyhistory=no,width=" + w + ",height=" + h + ",screenX=" + X + ",screenY=" + Y + ",left=" + X + ",top=" + Y);		
	if (NWnd.focus != null) NWnd.focus();
}	


function isPhoneN(s){
	var sPhone = "";
	var oneChar = "";
	for(i=0; i< s.value.length; i++){
		oneChar = s.value.substring(i,i+1);
		if(oneChar >="0" && oneChar<= "9") {
			sPhone = sPhone + oneChar;
			//alert(sPhone);
		} 	
   }
	 if(sPhone.length != 10) {
	 	alert("The telephone must be 10 digits including the area code");
	 	return false;
	 }
	 s.value = sPhone; // Write back edited value of phone with '(', '-' or ' ' removed.
	 return true;
}

function isPhoneEx(s){
	var sPhone = "";
	var oneChar = "";
	for(i=0; i< s.length; i++){
		oneChar = s.substring(i,i+1);
		if(oneChar >="0" && oneChar<= "9") {
			sPhone = sPhone + oneChar;
		} 	
   }
	 if(sPhone.length > 5 ) {
	 	alert("The telephone extension must be no longer than 5 digits");
	 	return false;
	 }
	 return true;
}

var oWin;
function PopupWindow(url, width, height) {
  oWin = window.open("","PopupWindow",'width=' + width + ',height=' + height + ',resizable=1,scrollbars=yes,menubar=no,copyhistory=no,toolbar=0,location=0,statusbar=0' );
	oWin.location=url;
	oWin.focus();
}

// States array DC included as a State
var USStates = new Array(51)
USStates["AL"] = "ALABAMA"
USStates["AK"] = "ALASKA"
USStates["AZ"] = "ARIZONA"
USStates["AR"] = "ARKANSAS"
USStates["CA"] = "CALIFORNIA"
USStates["CO"] = "COLORADO"
USStates["CT"] = "CONNECTICUT"
USStates["DE"] = "DELAWARE"
USStates["DC"] = "DISTRICT OF COLUMBIA"
USStates["FL"] = "FLORIDA"
USStates["GA"] = "GEORGIA"
USStates["HI"] = "HAWAII"
USStates["ID"] = "IDAHO"
USStates["IL"] = "ILLINOIS"
USStates["IN"] = "INDIANA"
USStates["IA"] = "IOWA"
USStates["KS"] = "KANSAS"
USStates["KY"] = "KENTUCKY"
USStates["LA"] = "LOUISIANA"
USStates["ME"] = "MAINE"
USStates["MD"] = "MARYLAND"
USStates["MA"] = "MASSACHUSETTS"
USStates["MI"] = "MICHIGAN"
USStates["MN"] = "MINNESOTA"
USStates["MS"] = "MISSISSIPPI"
USStates["MO"] = "MISSOURI"
USStates["MT"] = "MONTANA"
USStates["NE"] = "NEBRASKA"
USStates["NV"] = "NEVADA"
USStates["NH"] = "NEW HAMPSHIRE"
USStates["NJ"] = "NEW JERSEY"
USStates["NM"] = "NEW MEXICO"
USStates["NY"] = "NEW YORK"
USStates["NC"] = "NORTH CAROLINA"
USStates["ND"] = "NORTH DAKOTA"
USStates["OH"] = "OHIO"
USStates["OK"] = "OKLAHOMA"
USStates["OR"] = "OREGON"
USStates["PA"] = "PENNSYLVANIA"
USStates["RI"] = "RHODE ISLAND"
USStates["SC"] = "SOUTH CAROLINA"
USStates["SD"] = "SOUTH DAKOTA"
USStates["TN"] = "TENNESSEE"
USStates["TX"] = "TEXAS"
USStates["UT"] = "UTAH"
USStates["VT"] = "VERMONT"
USStates["VA"] = "VIRGINIA"
USStates["WA"] = "WASHINGTON"
USStates["WV"] = "WEST VIRGINIA"
USStates["WI"] = "WISCONSIN"
USStates["WY"] = "WYOMING"

// input value is a U.S. state abbreviation; set entered value to all uppercase
//this is not used below
// also set companion field (NAME="<xxx>_expand") to full state name

function isUSState(s) {
var inputStr = s.toUpperCase()
	if (inputStr.length > 0 && USStates[inputStr] == null) {
var msg = ""
var firstChar = inputStr.charAt(0)
	if (firstChar == "A") {
	msg += "\n(Alabama = AL; Alaska = AK; Arizona = AZ; Arkansas = AR)"
	}
	if (firstChar == "D") {
	msg += "\n(Delaware = DE; District of Columbia = DC)"
	}
	if (firstChar == "I") {
	msg += "\n(Idaho = ID; Illinois = IL; Indiana = IN; Iowa = IA)"
	}
	if (firstChar == "M") {
	msg += "\n(Maine = ME; Maryland = MD; Massachusetts = MA; Michigan = MI; Minnesota = MN; Mississippi = MS; Missouri = MO; Montana = MT)"
	}
	if (firstChar == "N") {
	msg += "\n(Nebraska = NE; Nevada = NV; New Jersey = NJ; New York = NY)"
	}
	alert("Check the spelling of the state abbreviation." + msg);
	return false;
	}
	return true;
}

function isZip(s) {
	if (s.length !=5)
		return false;
	if (isWhitespace(s))
		return false;
	if ((Number(s) > 0))
		return true;
	return false;
}	

function FormatDate(f) {
	out = "-"; // replace this
	add = "/"; // with this
	temp = "" + f.value; // temporary holder
	while (temp.indexOf(out)>-1) {
		pos= temp.indexOf(out);
		temp = "" + (temp.substring(0, pos) + add + 
		temp.substring((pos + out.length), temp.length));
	}

	var gameDate = temp;
	gameDate_Array=gameDate.split("/");
	if (gameDate_Array.length == 2) { // otherwise we do not have correct format
		if (gameDate_Array[2].length == 2) {
			if(parseInt(gameDate_Array[2]) < 30)
				gameDate_Array[2] = '20' + gameDate_Array[2]; // Add '20' to year if neccessary
			else
				gameDate_Array[2] = '19' + gameDate_Array[2]; // Add '19' to year if neccessary
		}
		else if (gameDate_Array[2].length == 1)
			gameDate_Array[2] = '200' + gameDate_Array[2];
	
		f.value = gameDate_Array[0] + "/" + gameDate_Array[1] + "/" + gameDate_Array[2]
	}
}

function Checkbetweenwhitespace(s)
{  for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
		if (whitespace.indexOf(c) == "") return true;
    }
// For WebTV users we needed to default return false if we found no bad characters
    return false;
}

function alltrim(obj){
  
	 var trimmedstring="";
	 var startpos=0; 
	 var endpos=obj.length - 1

   while (startpos<=obj.length && obj.substring(startpos, startpos+1)==" ") {
           startpos++ ;
   }
	 
   /* null string */
	  if (endpos == -1) {
     endpos=0
   }
   /* find end position of string */
   while (endpos >= 0 && obj.substring(endpos,endpos+1)==" ") {
           endpos--
   }
   /* replace value with trimmed string */
   obj=obj.substring(startpos,endpos+1)
   return obj
}

function PopIt(label, msg, width, height) {
	// Set up Page Colors & Table
	var s1 = "<TITLE>Help</TITLE>" +
		"<BODY BGCOLOR='ffffff'><TABLE BORDER=0>"
	var s2 = "<TR><TD><FONT COLOR='FF0000'><B>"+label+"</B></FONT><BR><BR>"

	var s3 =  "</TD></TR><TR><TD VALIGN=TOP ALIGN=RIGHT>"+ 
		"<FORM id=form1 name=form1><INPUT TYPE='BUTTON' name='BUTTON' VALUE='Close' onClick='self.close()'" + 
		" Style='BACKGROUND-COLOR: Navy;BORDER-BOTTOM: white outset;BORDER-LEFT: white outset;BORDER-RIGHT: white outset;BORDER-TOP: white outset;COLOR: white;FONT-FAMILY: Arial;FONT-SIZE: 8pt;FONT-WEIGHT: bolder;TEXT-ALIGN: center;'" +
		"</FORM></TD></TR></TABLE></BODY>"

	popup = window.open("","popDialog",'personalbar=no,toolbar=no,status=no,scrollbars=yes,location=no,resizable=yes,menubar=no,width=' + width + ',height=' + height);
	popup.document.write(s1+s2+msg+s3)
	popup.document.close()
}

function isSSN(pssn) {
// The field is passed in rather than the value so that if we strip out the '-', only the numeric portion is returned
	if (pssn.value.length > 9) { // Strip any edit characters '-'
		var ssn=""
		var singchar
		for (cnt = 0; cnt <pssn.value.length; cnt++) {
	  	singchar = pssn.value.charAt(cnt);
	  	if (singchar != "-" ) 
				ssn = ssn + singchar;
		}	
		pssn.value = ssn
	}
	if (pssn.value.length != 9) // Length must be 9
		return false;		
	if (isWhitespace(pssn.value)) // Cannot be spaces
		return false;
	if (Number(pssn.value) > 0) 
		return true
	else	
		return false // If not a number
}

//-->