/*****************************************************************************
AUTHOR: 		Timothy Lam
DATE CREATED:	04/02/2001
 
MODIFICATION LOG:
DATE        AUTHOR          MODIFICATION
==========  =============   ===============================================
04/02/2001	Tim				Functions checkAlphaOnly(), checkNumsOnly(), 
							validatePhoneNumber(), validateSSN(), printable(),
							and chkdate() have been modified or added so that 
							all javascript alerts have been taken out.  This will 
							allow developers to create generic messages based on 
							the return value of the function.

04/02/2001	Tim				Functions AlphaOnly(), NumsOnly(), formatPhoneNumber(), 
							formatSSN(), checkPrintable(), and checkDate() have 
							been modified or added so that default javascript alerts 
							are displayed.  
														
04/03/2001	Tim				Added 2 new functions to the library validateSelection()
							and validateRadio()

05/31/2001  Scott     Added 5 new functions to the library validateZipCode(),
              validateZipExt(), checkSpecialAlpha(), SpecialAlphaOnly(), and emailCheck()

05/31/2001  Scott     Changed checkDate() to accept an optional second parameter
              to specify a field to set focus on in the case of dates being
              split into mutiple fields

******************************************************************************/

/*****************************************************************************
  Purpose:	Checks the string to see if it is a valid zip code. Returns true or false.
  Usage:	This function can be used in the onchange event handler and can be
  			used in a form validation function called using the onsubmit event 
			handler.

  <input type="text" name="zipcode" size="5" maxlength="5" onChange="return checkZipCode(this);">

MODIFICATION LOG:
CHANGE NUMBER   DATE      AUTHOR               MODIFICATION
===========     ======  =============  ===============================================

******************************************************************************/
  function validateZipCode(input){
    var error_msg = "Zip Code is not valid.";
    if(input.value.length > 0){
      if(input.value.length != 5){
        alert(error_msg);
        return false;
      } else {
    	  if(!checkNumsOnly(input)){
          alert(error_msg);
          return false;
        }
      }
    }
    return true;
  }
  
/*****************************************************************************
  Purpose:	Checks the string to see if it is a valid zip code extension. Returns true or false.
  Usage:	This function can be used in the onchange event handler and can be
  			used in a form validation function called using the onsubmit event 
			handler.

  <input type="text" name="zipext" size="5" maxlength="5" onChange="return checkZipExt(this);">

MODIFICATION LOG:
CHANGE NUMBER   DATE      AUTHOR               MODIFICATION
===========     ======  =============  ===============================================

******************************************************************************/
  function validateZipExt(input){
    var error_msg = "Zip Code Extension is not valid.";
    if(input.value.length > 0){
      if(input.value.length != 4){
        alert(error_msg);
        return false;
      } else {
    	  if(!checkNumsOnly(input)){
          alert(error_msg);
          return false;
        }
      }
    }
    return true;
  }

/*****************************************************************************
  Purpose:	Checks if the browser supports cookies
  Usage:	Implement is the onload attribute of the body tag.
  			Must include the meta tags below: 
  <meta http-equiv="Set-Cookie" content="BROWSER=SUPPORTS_COOKIES; path=/">
  <meta http-equiv="Set-Cookie" content="Cookie=Non-Exchange; path=/">

MODIFICATION LOG:
CHANGE NUMBER   DATE      AUTHOR               MODIFICATION
===========     ======  =============  ===============================================
CN1				4/2/01	Tim				Removed alerts from the script
******************************************************************************/
  function cookieCheck(){ 
    if (document.cookie.length > 0){
  	  return true;
    }
    else{
	  return false;
    }
  }
  
/*****************************************************************************
  Purpose:	Checks if the browser supports the print function.
  Usage:	This function is a helper function.  A default function (checkPrintable()) 
            is defined below and can be used, if you do not wish to generate your own 
			error messages.
  Example:
  
    <input type="button" value="Print" onclick="javascript:if (printable()){window.print();}">

MODIFICATION LOG:
CHANGE NUMBER   DATE      AUTHOR               MODIFICATION
===========     ======  =============  ===============================================
 
******************************************************************************/
  function printable(){
    // Netscape Navigator
    if (document.layers){
	  return true;
	}
	// IE
	else if (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion > "4.0"){
	  return true;
	}
	return false;
  }
  
/*****************************************************************************
  Purpose:	Checks if the browser supports the print function.  If not a message is 
  			displayed to the user instructing them how to print the page.
  Usage:	The function can be called using the onclick action.
  Example:
  
    <input type="button" value="Print" onclick="javascript:if (checkPrintable()){window.print();}">

MODIFICATION LOG:
CHANGE NUMBER   DATE      AUTHOR               MODIFICATION
===========     ======  =============  ===============================================
 
******************************************************************************/
  function checkPrintable(){
    if (!printable()){
	  alert("This browser does not support the print button feature.  To print go to the file menu at the top of the browser and select the print option.");
	  return false;
	}
	else{
	  return true;
	}
  }

/*****************************************************************************
  Purpose:	Formats the Date in this format mm/dd/yyyy.  If the date is not a 
  			valid format an error message will be displayed.  The month can be
			entered as 1 or 2 digits, the days can be entered as 1 or 2 digits, 
			and the month must be entered as 4 digits.
  Usage:	This function can be used in the onchange event handler and can be
  			used in a form validation function called using the onsubmit event 
			handler.
  Example:  
  
    <input type="text" name="date" size="10" maxlength="10" onchange="return checkDate(this);">
  
MODIFICATION LOG:
CHANGE NUMBER   DATE        AUTHOR               MODIFICATION
===========     ======      =============  ===============================================
CN1             05/31/2001  Scott          Changed checkDate() to accept an optional second parameter
                                           to specify a field to set focus on in the case of dates being
                                           split into mutiple fields

******************************************************************************/
  
  function checkDate(){
    if(checkDate.arguments.length < 1){
      return false;
    }
    var datefield = checkDate.arguments[0];
    if(chkdate(datefield) == false){
      alert("The date is not valid.  Dates should be in the format mm/dd/yyyy.");
      if(checkDate.arguments.length == 2){
        var focusField = checkDate.arguments[1];
        focusField.setFocus();
      } else {
        datefield.focus();
      }
      return false;
    }
    else
    {
      return true;
    }
  }

/*****************************************************************************
  Purpose:  Checks the string to see if it is a valid date.  
  Usage:	The function should be used to as a helper function in a function
  			that you have defined in your javascript.  A default date formatting 
			function (checkDate()) is defined and can be used, if you do not wish 
			to generate your own error messages.

MODIFICATION LOG:
CHANGE NUMBER   DATE      AUTHOR               MODIFICATION
===========     ======  =============  ===============================================

******************************************************************************/

  function chkdate(objName){
    var strDate;
    var strDateArray;
    var strDay;
    var strMonth;
    var strYear;
    var intday;
    var intMonth;
    var intYear;
    var booFound = false;
    var datefield = objName;
    var strSeparator = "/";
    var intElementNr;
    var err = 0;
    var strMonthArray = new Array(12);
    strMonthArray[0] = "Jan";
    strMonthArray[1] = "Feb";
    strMonthArray[2] = "Mar";
    strMonthArray[3] = "Apr";
    strMonthArray[4] = "May";
    strMonthArray[5] = "Jun";
    strMonthArray[6] = "Jul";
    strMonthArray[7] = "Aug";
    strMonthArray[8] = "Sep";
    strMonthArray[9] = "Oct";
    strMonthArray[10] = "Nov";
    strMonthArray[11] = "Dec";
    strDate = datefield.value;
    if(strDate.length < 1){
      return true;
    }
    if(strDate.indexOf(strSeparator) != -1){
      strDateArray = strDate.split(strSeparator);
      if(strDateArray.length != 3){
        err = 1;
        return false;
      }
      else{ 
        strMonth = strDateArray[0];
        strDay = strDateArray[1];
        strYear = strDateArray[2];
      }
      booFound = true;
    }
    if(booFound == false){
      if(strDate.length > 5){
        strMonth = strDate.substr(0, 2);
        strDay = strDate.substr(2, 2);
        strYear = strDate.substr(4);
      }
    }
    if(strYear.length < 4){
      err = 4;
      return false;
    }
    intday = parseInt(strDay, 10);
    if(isNaN(intday)){
      err = 2;
      return false;
    }
    intMonth = parseInt(strMonth, 10);
    if(isNaN(intMonth)){
      err = 3;
      return false;
    }
    intYear = parseInt(strYear, 10);
    if(isNaN(intYear)){
      err = 4;
      return false;
    }
    if(intMonth > 12 || intMonth < 1){
      err = 5;
      return false;
    }
    if((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)){
      err = 6;
      return false;
    }
    if((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)){
      err = 7;
      return false;
    }
    if(intMonth == 2){
      if(intday < 1){
        err = 8;
        return false;
      }
      if(LeapYear(intYear) == true){
        if(intday > 29){
          err = 9;
          return false;
        }
      }
      else{
        if(intday > 28){
          err = 10;
          return false;
        }
      }
    }
    if(intMonth < 10){
      intMonth = "0" + intMonth;
    }
    if(intday < 10){
      intday = "0" + intday;
    }
    datefield.value = intMonth + "/" + intday + "/" + strYear;
    return true;
  }

  function LeapYear(intYear){
    if(intYear % 100 == 0){
      if(intYear % 400 == 0){
        return true;
      }
    }
    else{
      if((intYear % 4) == 0){
        return true;
      }
    }
    return false;
  }
  
/*****************************************************************************
  Purpose:  Checks the string to see if it is a valid date.  
  Usage:	The function should be used to as a helper function in a function
  			that you have defined in your javascript.  A default date formatting 
			function (checkDate()) is defined and can be used, if you do not wish 
			to generate your own error messages.

MODIFICATION LOG:
CHANGE NUMBER   DATE      AUTHOR               MODIFICATION
===========     ======  =============  ===============================================

******************************************************************************/

  function checkSplitDate(obj1, obj2, obj3){
    var strDay;
    var strMonth;
    var strYear;
    var intday;
    var intMonth;
    var intYear;
    var intElementNr;
    var err = 0;
    var strMonthArray = new Array(12);
    strMonthArray[0] = "Jan";
    strMonthArray[1] = "Feb";
    strMonthArray[2] = "Mar";
    strMonthArray[3] = "Apr";
    strMonthArray[4] = "May";
    strMonthArray[5] = "Jun";
    strMonthArray[6] = "Jul";
    strMonthArray[7] = "Aug";
    strMonthArray[8] = "Sep";
    strMonthArray[9] = "Oct";
    strMonthArray[10] = "Nov";
    strMonthArray[11] = "Dec";
    
    strMonth = obj1.value;
    strDay = obj2.value;
    strYear = obj3.value;
    
    if(strYear.length < 4){
      err = 4;
      return false;
    }
    intday = parseInt(strDay, 10);
    if(isNaN(intday)){
      err = 2;
      return false;
    }
    intMonth = parseInt(strMonth, 10);
    if(isNaN(intMonth)){
      err = 3;
      return false;
    }
    intYear = parseInt(strYear, 10);
    if(isNaN(intYear)){
      err = 4;
      return false;
    }
    if(intMonth > 12 || intMonth < 1){
      err = 5;
      return false;
    }
    if((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)){
      err = 6;
      return false;
    }
    if((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)){
      err = 7;
      return false;
    }
    if(intMonth == 2){
      if(intday < 1){
        err = 8;
        return false;
      }
      if(LeapYear(intYear) == true){
        if(intday > 29){
          err = 9;
          return false;
        }
      }
      else{
        if(intday > 28){
          err = 10;
          return false;
        }
      }
    }
    if(intMonth < 10){
      intMonth = "0" + intMonth;
    }
    if(intday < 10){
      intday = "0" + intday;
    }
    obj1.value = intMonth;
    obj2.value = intday;
    obj3.value = strYear;
    return true;
  }

/*****************************************************************************
  Purpose:  Checks the string to see if it is a valid ssn.  Returns appropriate 
  			return codes.
  Usage:	The function should be used to as a helper function in a function
  			that you have defined in your javascript.  Custom error messages can 
			be generated using the following return codes:

			RETURN CODES:
			100 - Valid SSN
			101 - (9 characters) Valid SSN (Without dashes)
			102 - (9 characters) Input only allows numbers or '-'
			103 - Invalid SSN length (SSN must be 9 digits or 11 digits with dashes) 
			104 - (11 characters) Input only allows numbers or '-'
			105 - (11 characters but does not have 2 '-') Please check your SSN input
			106 - (11 characters but dashes are not in the 4 and 7 positions in the string)
			      Please check your input

			A default ssn formatting function (formatSSN()) is defined below and can be
			used, if you do not wish to generate your own error messages.

MODIFICATION LOG:
CHANGE NUMBER   DATE      AUTHOR               MODIFICATION
===========     ======  =============  ===============================================
CN1				4/02/01	Tim				Removed document.forms[0].ssn and replaced it with 
										an input parameter that is passed to the function.
										This change was made through out the function.
******************************************************************************/

  function validateSSN(input){
    var str = input.value;
	var return_code = 100;

	// String is 9 characters long
    if (str.length == "9") {
	  // SSN is 9 and not numbers only
	  if (!checkNumsOnly(input)){
	    return_code = 102;
	  }
	  // SSN is 9 digits
	  else{
	    return_code = 101;
	  }       
    }
	// String is 11 characters long
    else if (str.length == "11"){
      var countHyphen = 0;
	  // Loop through the string and check for digits and dashes
      for (var i = 0; i < str.length; i++){
        var ch = str.substring(i, i + 1);
        if (ch == "-"){
          countHyphen = countHyphen + 1;
        }       
        if ((ch < "0" || "9" < ch) && (ch != "-")){
	      return_code = 104;
        }               
      }
	  // Input does not have 2 dashes
      if (countHyphen != "2"){
	    return_code = 105;
      }
	  // Input does not have dashes at the 4 at 7 positions in the string
      if ((str.charAt(3)!='-') || (str.charAt(6)!='-')){
	    return_code = 106;
      }
    }
	// String is not 9 or 11 characters long
	else{
	  return_code = 103;
	}
	return return_code;
  }

/*****************************************************************************
  Purpose:	Formats the SSN to the valid SSN format XXX-XX-XXXX.  If the SSN 
  			is not valid an error message will be displayed.
  Usage:	This function can be used in the onchange event handler or it can be 
  			used in a function that validates the form when the form is submitted.

  Example:
  
    <input type="text" name="ssn" size="12" maxlength="11" onchange="javascript:formatSSN();">

MODIFICATION LOG:
CHANGE NUMBER   DATE      AUTHOR               MODIFICATION
===========     ======  =============  ===============================================

******************************************************************************/
  function formatSSN(input){
    var str = input.value;
	var return_code = validateSSN(input);
	var message = "";
    if (return_code == 101){
      input.value = str.substring(0,3) + "-" + str.substring(3,5) + "-" + str.substring(5,9);
	}
	else if ((return_code == 102) || (return_code == 104)){
	  message = "Input only allows numbers or '-'";
	}
	else if (return_code == 103){
	  message = "Invalid SSN (SSN length must be 9 digits or 9 digits seperated by 2 '-')";
	}
	else if ((return_code == 105) || (return_code == 106)){
	  message = "Invalid SSN (SSN must be in this format 999999999 or 999-99-9999)";
	}
	// Prints the appropriate error message if ssn is invalid
	if ((return_code != 100) && (return_code != 101)){
          input.focus();
	  alert(message);
	  return false;
	}
	return true;
  }
  
/*****************************************************************************
  Purpose:	Formats the Phone Number to the valid Phone Number format.  If the 
            Phone Number is not valid an error message will be displayed.
  Usage:	The function should be used to as a helper function in a function
  			that you have defined in your javascript.  The inputs are the form
			element and a delimiter Custom error messages can be generated using 
			the following return codes:

			RETURN CODES:
			100 - Valid Phone Number
			101 - (10 characters) Valid Phone Number (Without dashes)
			102 - Invalid Phone Number length (Phone Number must be 10 digits 
				  or 12 digits with dashes)
			103 - Invalid Phone Number length (Phone Number must be 10 digits or 
			      12 digits with delimiter) 
			104 - (12 characters) Input only allows numbers or '-'
			105 - (12 characters but does not have 2 delimiters) Please check your Phone 
			      Number input
			106 - (12 characters but dashes are not in the 4 and 8 positions in the string)
			      Please check your input
				  
			A default phone number formatting function (formatPhoneNumber()) is 
			defined below and can be used, if you do not wish to generate your 
			own error messages.

MODIFICATION LOG:
CHANGE NUMBER   DATE      AUTHOR               MODIFICATION
===========     ======  =============  ===============================================
 
******************************************************************************/
  
  function validatePhoneNumber(input, delimiter){
	var formattedPhone = "";
	var str = input.value;
	var return_code = 100;

	if (str.length == "10"){                
	  // Phone Number is 10 and not numbers only
	  if (!checkNumsOnly(input)){
	    return_code = 102;
	  }
	  // Phone Number is 10 digits
	  else{
	    return_code = 101;
	  }
	}
	else if (str.length == "12"){
	  var countHyphen = 0;
	  for (var i = 0; i < str.length; i++){
	    var ch = str.substring(i, i + 1)
		if (ch == delimiter){
		  countHyphen = countHyphen + 1;
		}       
		if ((ch < "0" || "9" < ch) && (ch != delimiter)){
	      return_code = 104;
		} 
	  }
	  // Input does not have 2 dashes
      if (countHyphen != "2"){
	    return_code = 105;
      }
	  // Input does not have dashes at the 4 at 8 positions in the string
      if ((str.charAt(3) != delimiter) || (str.charAt(7) != delimiter)){
	    return_code = 106;
      }
	}
	else{
	  return_code = 103;
	}
	return return_code;
  }

/*****************************************************************************
  Purpose:	Formats the Phone Number to the valid Phone Number format 
            XXX[delimiter]XXX[delimiter]XXXX.  If the Phone Number is not valid 
			an error message will be displayed.
  Usage:	This function can be used in the onchange event handler or it can be 
  			used in a function that validates the form when the form is submitted.

  Example:
  
    <input type="text" name="phone_number" size="13" maxlength="12" onchange="javascript:formatPhoneNumber();">

MODIFICATION LOG:
CHANGE NUMBER   DATE      AUTHOR               MODIFICATION
===========     ======  =============  ===============================================

******************************************************************************/
  function formatPhoneNumber(input, delimiter){
    var str = input.value;
	var return_code = validatePhoneNumber(input, delimiter);
	var message = "";
	
    if (return_code == 101){
	  input.value = str.substring(0,3)+ delimiter + str.substring(3,6) + delimiter + str.substring(6,10);
	}
	else if ((return_code == 102) || (return_code == 104)){
	  message = "Input only allows numbers or '" + delimiter + "'";
	}
	else if (return_code == 103){
	  message = "Invalid Phone Number (Phone Number length must be 10 digits or 10 digits seperated by 2 '" + delimiter + "')";
	}
	else if ((return_code == 105) || (return_code == 106)){
	  message = "Invalid Phone Number (Phone Number must be in this format 9999999999 or 999" + delimiter + "999" + delimiter + "9999)";
	}
	// Prints the appropriate error message if Phone Number is invalid
	if ((return_code != 100) && (return_code != 101)){
	  input.focus();
	  alert(message);
	  return false;
	}
	return true;
  }

/*****************************************************************************
  Purpose:	Automically tabs from one field to the next according to the 
  			specified length that is input.
  Usage:	The function can be called using the onKeyUp event handler
  Example:  
    <input type="text" size="4" maxlength="4" onKeyUp="autoTab(this, 4);">

MODIFICATION LOG:
CHANGE NUMBER   DATE      AUTHOR               MODIFICATION
===========     ======  =============  ===============================================
 
******************************************************************************/
// len is the number of chars that autotab will automatically tab when reached
  function autoTab(input, myLen){
    var len = parseInt(myLen);
    if(input.value.length >= len){
      input.value = input.value.slice(0, len);
      input.form[(getIndex(input)+1) % input.form.length].focus();
	  if ((input.form[(getIndex(input)+1) % input.form.length]).type == "text")
	    input.form[(getIndex(input)+1) % input.form.length].select();
    }
    function getIndex(input){
      var index = -1, i = 0, found = false;
      while (i < input.form.length && index == -1)
        if (input.form[i] == input) index = i;
        else i++;
      return index;
    }
    return true;
  }

/*****************************************************************************
  Purpose:	Removes non-numeric and non-period (".") characters.
  Usage:	The function can be called using the onchange event handler or 
  			onsubmit in the form validation function
  Example:  
    <input type="text" size="4" maxlength="4" onchange="FormatNumber(this);">

MODIFICATION LOG:
CHANGE NUMBER   DATE      AUTHOR               MODIFICATION
===========     ======  =============  ===============================================
 
******************************************************************************/
  function FormatNumber(input){
    s = input.value;
	// bag contains all valid characters.  Anything not is bag will be removed
    bag = "1234567890.";
    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++){   
      var c = s.charAt(i);
      if (bag.indexOf(c) != -1) returnString += c;
    }
    // sets the field to contain the formatted string
    input.value = returnString;
  }

/*****************************************************************************
  Purpose:	Checks to see if the input is numbers only if not an error message
  			is displayed, the value is cleared, and focus given to the field
  Usage:	The function can be called using the onchange event handler or 
  			onsubmit in the form validation function
  Example:  
    <input type="text" size="4" maxlength="4" onchange="NumsOnly(this);">

MODIFICATION LOG:
CHANGE NUMBER   DATE      AUTHOR               MODIFICATION
===========     ======  =============  ===============================================
 
******************************************************************************/
  function NumsOnly(input){
    if (!checkNumsOnly(input)){
	  // if it isn't a number
	  alert("Please make sure entry is numbers only");
	  input.focus();
	  return false;
	}
	return true;
  }
  
/*****************************************************************************
  Purpose:	Checks to see if the input is numbers only 
  Usage:	This function returns a true or a false based on the input given

MODIFICATION LOG:
CHANGE NUMBER   DATE      AUTHOR               MODIFICATION
===========     ======  =============  ===============================================
CN1				4/2/01	Tim				Removed alerts from the function.
 
******************************************************************************/
  function checkNumsOnly(input){
    var str = input.value;
    var i;
    // loops through the length of the string
    for (i=0; i<str.length; i++){
      // extracts a character and stores it in c
      var c = str.charAt(i);
      // checks whether it is a number
      if (c < "0" || c > "9"){
		return false;
      }
    }
    return true;
  }
  
/*****************************************************************************
  Purpose:	Checks to see if the input is alpha only 
  Usage:	The function can be called using the onchange event handler or 
  			onsubmit in the form validation function
  Example:  
    <input type="text" size="4" maxlength="4" onchange="NumsOnly(this);">

MODIFICATION LOG:
CHANGE NUMBER   DATE      AUTHOR               MODIFICATION
===========     ======  =============  ===============================================
 
******************************************************************************/
  function AlphaOnly(input){
    if (!checkAlphaOnly(input)){
	  // if it isn't an alpha
	  alert("Alphabetic characters only.");
	  input.focus();
	  return false;
	}
	return true;
  }

/*****************************************************************************
  Purpose:	Checks to see if the input is alpha only 
  Usage:	This function returns a true or a false based on the input given

MODIFICATION LOG:
CHANGE NUMBER   DATE      AUTHOR               MODIFICATION
===========     ======  =============  ===============================================
 
******************************************************************************/
  function checkAlphaOnly(input){
    var str = input.value;
	// Begins with an alphabetic character or ',' or ' ' and ends with one
	var pattern = /^[a-zA-Z, ]*$/
	// tests the regular expression for the pattern
	var isalpha = pattern.test(str);
	if (!isalpha){
	  return false;
	}
	return true;
  }
  
  /*****************************************************************************
    Purpose:	Checks to see if the input's first character is alpha 
    Usage:	This function returns a true or a false based on the input given
  
  MODIFICATION LOG:
  CHANGE NUMBER   DATE      AUTHOR               MODIFICATION
  ===========     ======  =============  ===============================================
   
  ******************************************************************************/
    function checkFirstCharacterAlphaOnly(input){
      var str = input.value.substring(0,1);
  	// Begins with an alphabetic character
  	var pattern = /[a-zA-Z]/
  	// tests the regular expression for the pattern
  	var isalpha = pattern.test(str);
  	if (!isalpha){
  	  return false;
  	}
  	return true;
  }

/*****************************************************************************
  Purpose:	Checks the radio button group to see if an element of the group has
  			been checked.  If an element is checked the function will return a 
			true else the function will return a false.
  Usage:	This function can be used within your form validation function to 
  			check to see if certain radio button groups have been checked.

MODIFICATION LOG:
CHANGE NUMBER   DATE      AUTHOR               MODIFICATION
===========     ======  =============  ===============================================
 
******************************************************************************/

  function validateRadio(input){
    var i = 0;
	var isChecked = false;
	// loops until the length of the radio button group array has been exceeded or 
	// until a checked radio button has been found.
    while ((i < input.length) && (isChecked == false)){
	  if (input[i].checked == true){
	    isChecked = true;
	  }
	  i++;
	}
	return isChecked;
  }
  
/*****************************************************************************
  Purpose:	Checks the drop down to see if an element has been selected other 
  			than the element at the index.  If the element at the index is not
			selected the function will return a true else the function will 
			return a false.
  Usage:	This function can be used within your form validation function to 
  			check to see if a selection has been made.

MODIFICATION LOG:
CHANGE NUMBER   DATE      AUTHOR               MODIFICATION
===========     ======  =============  ===============================================
 
******************************************************************************/

  function validateSelection(input, index){
    // Returns true is the element at index is not selected
	// else it returns a true
	return (input[index].selected == false);	 
  }
  
/*****************************************************************************
  Purpose:	Checks to see if the input is alpha only plus special characters 
  Usage:	The function can be called using the onchange event handler or 
  			onsubmit in the form validation function
  Example:  
    <input type="text" size="4" maxlength="4" onchange="SpecialAlphaOnly(this);">

MODIFICATION LOG:
CHANGE NUMBER   DATE      AUTHOR               MODIFICATION
===========     ======  =============  ===============================================
 
******************************************************************************/
  function SpecialAlphaOnly(input){
    if (!checkSpecialAlpha(input)){
	  // if it isn't an alpha
	  alert("Alphabetic characters only.");
	  input.focus();
	  return false;
	}
	return true;
  }
  
/*****************************************************************************
  Purpose:	Checks to see if the input is alpha only plus special characters
  Usage:	This function returns a true or a false based on the input given

MODIFICATION LOG:
CHANGE NUMBER   DATE      AUTHOR               MODIFICATION
===========     ======  =============  ===============================================
                4-16-02    DCH         Added a check to verify the first char is alphabetic 
******************************************************************************/
  function checkSpecialAlpha(input){
    var str = input.value;
	// Begins with an alphabetic character or ',' or ' ' and ends with one
	var pattern = /^([a-zA-Z., ']|-)*$/
	// tests the regular expression for the pattern
	var isalpha = pattern.test(str);
	if (!isalpha){
	  return false;
	}
	else
	{
	  return checkFirstCharacterAlphaOnly(input);
	}
  }
  
/*****************************************************************************
  Purpose:	Checks to see if the input is is a valid email address
  Usage:	This function returns a true or a false based on the input given

MODIFICATION LOG:
CHANGE NUMBER   DATE      AUTHOR               MODIFICATION
===========     ======  =============  ===============================================
 
******************************************************************************/
function emailCheck(input){
  if(input.value.length > 0){
    var emailStr = input.value;
    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 +")*$");
    var matchArray = emailStr.match(emailPat);

    if (matchArray == null){
    	alert("Email address is incorrect (check @ and .'s)");
      input.focus();
    	return false;
    }

    var user = matchArray[1];
    var domain = matchArray[2];

    if(user.match(userPat) == null){
      alert("The username doesn't seem to be valid.");
      input.focus();
      return false;
    }

    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!");
          input.focus();
      		return false;
  	    }
      }
      return true;
    }

    var domainArray = domain.match(domainPat);

    if(domainArray == null){
  	  alert("The domain name is invalid.");
      input.focus();
      return false;
    }

    var atomPat = new RegExp(atom, "g");
    var domArr = domain.match(atomPat);
    var len = domArr.length;

    if(domArr[domArr.length - 1].length < 2 || domArr[domArr.length - 1].length > 3){
      alert("Email address must end in a three-letter domain, or two letter country.");
      input.focus();
      return false;
    }

    if(len < 2){
      var errStr = "Email address is missing a hostname!";
      alert(errStr);
      input.focus();
      return false;
    }
  }
  return true;
}