var USStateCodeDelimiter = "|";
var USStateCodes = "AL|AK|AS|AZ|AR|CA|CN|CO|CT|DE|DC|FM|FL|GA|GU|HI|ID|IL|IN|IA|KS|KY|LA|ME|MH|MD|MA|MI|MN|MS|MO|MT|NE|NV|NH|NJ|NM|NY|NC|ND|MP|OH|OK|OR|PW|PA|PR|RI|SC|SD|TN|TX|UT|VT|VI|VA|WA|WV|WI|WY|AE|AA|AE|AE|AP"
var iStateCode = "This field must be a valid two character U.S. state abbreviation (like FL for Florida). Please reenter a valid state abbreviation."
var digits = "0123456789";
var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz"
var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

// CONSTANT STRING DECLARATIONS
// (grouped for ease of translation and localization)

// m is an abbreviation for "missing"

var mPrefix = "\""
var mSuffix = "\" is a required field. Please enter it now."

// s is an abbreviation for "string"

var sZIPCode = "ZIP Code"
var sPhone = "Phone Number"
var sFax = "Fax Number"
var sSSN = "Social Security Number"

// i is an abbreviation for "invalid"

var iZIPCode = "This field must be a 5 or 9 digit U.S. ZIP Code (like 94043). Please reenter it now."
var iUSPhone = "This field must be a 10 digit U.S. phone number (like 415 555 1212). Please reenter it now."
var iSSN = "This field must be a 9 digit U.S. social security number (like 123 45 6789). Please reenter it now."

// p is an abbreviation for "prompt"

var pEntryPrompt = "Please enter a "
var pZIPCode = "5 or 9 digit U.S. ZIP Code (like 94043)."
var pUSPhone = "10 digit U.S. phone number (like 415 555 1212)."
var pSSN = "9 digit U.S. social security number (like 123 45 6789)."

// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";

// characters which are allowed in US phone numbers
var validUSPhoneChars = digits + phoneNumberDelimiters;

// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = digits + phoneNumberDelimiters + "+";

// non-digit characters which are allowed in 
// Social Security Numbers
var SSNDelimiters = "- ";

// characters which are allowed in Social Security Numbers
var validSSNChars = digits + SSNDelimiters;

// U.S. Social Security Numbers have 9 digits.
// They are formatted as 123-45-6789.
var digitsInSocialSecurityNumber = 9;

// U.S. phone numbers have 10 digits.
// They are formatted as 123 456 7890 or (123) 456-7890.
var digitsInUSPhoneNumber = 10;

// non-digit characters which are allowed in ZIP Codes
var ZIPCodeDelimiters = "-";

// our preferred delimiter for reformatting ZIP Codes
var ZIPCodeDelimeter = "-"

// characters which are allowed in Social Security Numbers
var validZIPCodeChars = digits + ZIPCodeDelimiters

// U.S. ZIP codes have 5 or 9 digits.
// They are formatted as 12345 or 12345-6789.
var digitsInZIPCode1 = 5
var digitsInZIPCode2 = 9

// validate.js
//
// This is a set of JavaScript functions and associated variables for validating input on 
// an HTML form. 
//

// Global variable defaultEmptyOK defines default return value 
// for many functions when they are passed the empty string. 
// By default, they will return defaultEmptyOK.
//
// defaultEmptyOK is false, which means that by default, 
// these functions will do "strict" validation. 
//
// Most of these functions have an optional argument emptyOK
// which allows you to override the default behavior for 
// the duration of a function call.

var defaultEmptyOK = false


// whitespace characters
var whitespace = " \t\n\r";

function warnInvalid (theField, s)
{ 
	alert(s);
	theField.focus();
    theField.select();
    return false;
}


//function to strip out .00 from amount

function stripDecimal(normalizedAmount)
{
	if (normalizedAmount.indexOf(".") != -1)
		return normalizedAmount.substring(0,normalizedAmount.indexOf("."));
	else
		return normalizedAmount;
}	


// 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;
}

// Returns true if character c is a digit 
// (0 .. 9).

function isDigit(c)
{   
	return ((c >= "0") && (c <= "9"))
}


function isNumericInRange (s,fieldDescription,varMin,varMax)
{   var i;

    if (isEmpty(s.value))
    { 
       if (isNumericInRange.arguments.length == 1) return defaultEmptyOK;
       else return (isNumericInRange.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.

	//** Strip out all dollar mask values
	var normalizedAmount = stripCharsInBag(s.value, "$,")

	normalizedAmount = stripDecimal(normalizedAmount) 
			
	for (i = 0; i < normalizedAmount.length; i++)
	{   
		// Check that current character is number.
		var c = normalizedAmount.charAt(i);

		//if (!isDigit(c)) return false;
        
		if (!isDigit(c))
		{
			return warnInvalid (s, "This field accepts numeric values only.  Please reenter a numeric value.");
		}			
	}
	
	if (s.value < varMin || s.value > varMax)
	{
		return warnInvalid (s, "The amount entered for " + fieldDescription + " is not within the required range.  The required amount is between $" + varMin + " and $" + varMax + ".");
	}			
	

    // All characters are numbers and numeric value is within the required range.
    s.value = normalizedAmount;
    return true;
}


// 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 isNumeric (s)

{   var i;
	
    if (isEmpty(s.value))
    { 
       if (isNumeric.arguments.length == 1) return defaultEmptyOK;
       else return (isNumeric.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.

	//** Strip out all dollar mask values
	var normalizedAmount = stripCharsInBag(s.value, "$,")

	normalizedAmount = stripDecimal(normalizedAmount) 
			
	for (i = 0; i < normalizedAmount.length; i++)
	{   
		// Check that current character is number.
		var c = normalizedAmount.charAt(i);

		//if (!isDigit(c)) return false;
        
		if (!isDigit(c))
		{
			return warnInvalid (s, "This field accepts numeric values only.  Please reenter a numeric value.");
		}			
	}

    // All characters are numbers.
    s.value = normalizedAmount;
    return true;
}

// checkStringNS (TEXTFIELD theField, STRING s, [, BOOLEAN emptyOK==false])
// Check that string theField.value is not all whitespace.

function checkStringNS (theField, s, emptyOK)
{   // Next line is needed on NN3 to avoid "undefined is not a number" error
    // in equality comparison below.
    
    if (checkStringNS.arguments.length == 2) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField))) return true;
    
    if (isWhitespace(theField))
       return warnEmpty (theField, s);
    else return true;
}


// checkString (TEXTFIELD theField, STRING s, [, BOOLEAN emptyOK==false])
// Check that string theField.value is not all whitespace.

function checkString (theField, s, emptyOK)
{   // Next line is needed on NN3 to avoid "undefined is not a number" error
    // in equality comparison below.
    
    if (checkString.arguments.length == 2) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    
    //alert(theField.selectedIndex);
    //alert(parseInt(theField.selected));
    //if (theField.selectedIndex >= 0 && theField.selectedIndex <= 20)
    //{
		//strValue = theField.options[theField.selectedIndex].value;
	//	return true;
	//}		
	//else
	//{
		//strValue = theField.value;
    //}
     
    if (isWhitespace(theField.value)) 
    {
		return warnEmpty (theField, s);
    }   
		else
    {
	    return true;
    }
}

// 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;
}

// Notify user that required field theField is empty.
// String s describes expected contents of theField.value.
// Put focus in theField and return false.

function warnEmpty (theField, s)
{   
	alert(mPrefix + s + mSuffix)
	theField.focus()
    return false
}

// Check whether string s is empty.

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

// 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;
}

function validDate(DateValue) 
{
	var err = 0;
	string = DateValue.value;
	var valid = "-0123456789/";
	var ok = "yes";
	var temp;
	
	for (var i=0; i< string.length; i++) {
		temp = "" + string.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") err = 1;		
	}
	
	if (string.length != 8) err=1;	
	
	b = string.substring(0, 2); // month
	c = string.substring(2, 3);// '/'
	d = string.substring(3, 5); // day
	e = string.substring(5, 6);// '/'
	f = string.substring(6, 8); // year
	if (b<1 || b>12) err = 1;	
	
	if (c != '/' && c != '-') err = 1;
	
	if (d<1 || d>31) err = 1;	
	
	if (c != '/' && c != '-') err = 1;
	
	if (f<0 || f>99) err = 1;
	
	if (b==4 || b==6 || b==9 || b==11){
		if (d==31) err=1;
	}
	
	if (b==2){
		var g=parseInt(f/4)
		if (isNaN(g)) err=1;		
		if (d>29) err=1;
		if (d==29 && ((f/4)!=parseInt(f/4))) err=1;
	}
	if (err==1) {
		alert('Invalid Date! Example: MM/DD/YY');	
		DateValue.value	= '';	
	}
}

// isStateCode (STRING s [, BOOLEAN emptyOK])
// 
// Return true if s is a valid U.S. Postal Code 
// (abbreviation for state).
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isStateCode(s)
{   if (isEmpty(s)) 
       if (isStateCode.arguments.length == 1) return defaultEmptyOK;
       else return (isStateCode.arguments[1] == true);
    return ( (USStateCodes.indexOf(s) != -1) &&
             (s.indexOf(USStateCodeDelimiter) == -1) )
}

// checkStateCode (TEXTFIELD theField [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is a valid U.S. state code.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function checkStateCode (theField, emptyOK)
{   if (checkStateCode.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else
    {  theField.value = theField.value.toUpperCase();
       if (!isStateCode(theField.value, false)) 
          return warnInvalid (theField, iStateCode);
       else return true;
    }
}


// isUSPhoneNumber (STRING s [, BOOLEAN emptyOK])
// 
// isUSPhoneNumber returns true if string s is a valid U.S. Phone
// Number.  Must be 10 digits.
//
// NOTE: Strip out any delimiters (spaces, hyphens, parentheses, etc.)
// from string s before calling this function.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isUSPhoneNumber (s)
{   
	if (isEmpty(s)) 
       if (isUSPhoneNumber.arguments.length == 1) return defaultEmptyOK;
       else return (isUSPhoneNumber.arguments[1] == true);
    return (isInteger(s) && s.length == digitsInUSPhoneNumber)
	
}

// takes USPhone, a string of 10 digits
// and reformats as (123) 456-789

function reformatUSPhone (USPhone)
{   return (reformat (USPhone, "(", 3, ")", 3, "-", 4))
}

// checkUSPhone (TEXTFIELD theField [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is a valid US Phone.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function checkUSPhone (theField, emptyOK)
{   if (checkUSPhone.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else
    {  var normalizedPhone = stripCharsInBag(theField.value, phoneNumberDelimiters)
       if (!isUSPhoneNumber(normalizedPhone, false)) 
          return warnInvalid (theField, iUSPhone);
       else 
       {  // if you don't want to reformat as (123) 456-789, comment next line out
          theField.value = reformatUSPhone(normalizedPhone)
          return true;
       }
    }
}

// isSSN (STRING s [, BOOLEAN emptyOK])
// 
// isSSN returns true if string s is a valid U.S. Social
// Security Number.  Must be 9 digits.
//
// NOTE: Strip out any delimiters (spaces, hyphens, etc.)
// from string s before calling this function.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isSSN (s)
{   if (isEmpty(s)) 
       if (isSSN.arguments.length == 1) return defaultEmptyOK;
       else return (isSSN.arguments[1] == true);
    return (isInteger(s) && s.length == digitsInSocialSecurityNumber)
}

// takes SSN, a string of 9 digits
// and reformats as 123-45-6789

function reformatSSN (SSN)
{   return (reformat (SSN, "", 3, "-", 2, "-", 4))
}

function reformatDate (sDate)
{   return (reformat (sDate, "", 2, "-", 2, "-", 2))
}

// Check that string theField.value is a valid SSN.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function checkSSN (theField, emptyOK)
{	
    if (checkSSN.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else
    {  var normalizedSSN = stripCharsInBag(theField.value, SSNDelimiters)
       if (!isSSN(normalizedSSN, false)) 
          return warnInvalid (theField, iSSN);
       else 
       {  // if you don't want to reformats as 123-456-7890, comment next line out
          theField.value = reformatSSN(normalizedSSN)
          return true;
       }
    }
}

// isZIPCode (STRING s [, BOOLEAN emptyOK])
// 
// isZIPCode returns true if string s is a valid 
// U.S. ZIP code.  Must be 5 or 9 digits only.
//
// NOTE: Strip out any delimiters (spaces, hyphens, etc.)
// from string s before calling this function.  
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isZIPCode (s)
{  if (isEmpty(s)) 
       if (isZIPCode.arguments.length == 1) return defaultEmptyOK;
       else return (isZIPCode.arguments[1] == true);
   return (isInteger(s) && 
            ((s.length == digitsInZIPCode1) ||
             (s.length == digitsInZIPCode2)))
}

// takes ZIPString, a string of 5 or 9 digits;
// if 9 digits, inserts separator hyphen

function reformatZIPCode (ZIPString)
{   if (ZIPString.length == 5) return ZIPString;
    else return (reformat (ZIPString, "", 5, "-", 4));
}

// checkZIPCode (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 checkZIPCode (theField, emptyOK)
{   if (checkZIPCode.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else
    { var normalizedZIP = stripCharsInBag(theField.value, ZIPCodeDelimiters)
      if (!isZIPCode(normalizedZIP, false)) 
         return warnInvalid (theField, iZIPCode);
      else 
      {  // if you don't want to insert a hyphen, comment next line out
         theField.value = reformatZIPCode(normalizedZIP)
         return true;
      }
    }
}


// Main Validate Function
// Call this from the forms
// Pass it the form name and it will look for the string Reqd_ in the Object Name
// attach to form element like this <form name="frmMain" method="post" action="frm_agentapp_submit.asp" onSubmit="return ValidateRequiredFormItems(frmMain)" class="formText">

function ValidateRequiredFormItems(tform){   
	var intLen;
	var ret;
	var intStart;
	var c;
	
	var pass=true;
	for (i=0;i<tform.length;i++) {
		var tempobj=tform.elements[i];
						
		//alert(tempobj.name);						
		intStart = tempobj.name.indexOf("Reqd_");
	  	if (intStart != -1)
	  	{
	  		if (((tempobj.type=="text"||tempobj.type=="textarea")&&
				tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
				tempobj.selectedIndex==0 && tempobj.options[0].value.charAt(0)==" "))
	  		{
	  			intLen = tempobj.name.length;
	  			//return warnEmpty (tempobj, tempobj.name.substring((intStart+5),intLen));
				return warnEmpty (tempobj, tempobj.title)
	  			break;
	  		}
	  		//intLen = tempobj.name.length;
	  		//ret = checkString(tempobj,tempobj.name.substring((intStart+5),intLen)); 		
	  		//if (ret == false) return ret;
		}	
	}
  	return ret;
  
  
	// **********************************************************************  
	/* FOR IN STATEMENT DOES NOT WORK WITH NETSCAPE!!!!!!!!!!!!!!!!!!!!!!!!!!
	for (i in tform.elements)
	{
	  intStart = i.indexOf("Reqd_");
		if (intStart != -1)
		{
			intLen = i.length;
			ret = checkString(tform.elements[i],i.substring((intStart+5),intLen));
			if (ret == false) return ret;
	  }	
	}
	return ret;*/
	
	/*if (tempobj.name.substring(0,5)=="Reqd_") {
			if (((tempobj.type=="text"||tempobj.type=="textarea")&&
				tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
				tempobj.selectedIndex==0)) 
			{
				pass=false;
				break;
			}
		}*/
	// FOR IN STATEMENT DOES NOT WORK WITH NETSCAPE!!!!!!!!!!!!!!!!!!!!!!!!!!		
	// **********************************************************************
}

//** New Date Functions

   function isNum(arg) {
      // Internal function to test whether argument is a number
      if (arg == "")
         return false;
      for (i=0; i<arg.length; i++) {
         if (arg.charAt(i) < "0" || arg.charAt(i) > "9") {
            return false;
         }
      }
      return true;
   }

   function monthToNum(monthStr) {
      // Internal function to convert a month string to numeric 1-12
      if (monthStr=="")
         return false;
      var m = monthStr;
      if (monthStr.length>3)
         var m = monthStr.substring(0,2);
      if (m=="jan" || m=="Jan" || m=="JAN")
         return 1;
      else if (m=="feb" || m=="Feb" || m=="FEB")
         return 2;
      else if (m=="mar" || m=="Mar" || m=="MAR")
         return 3;
      else if (m=="apr" || m=="Apr" || m=="APR")
         return 4;
      else if (m=="may" || m=="May" || m=="MAY")
         return 5;
      else if (m=="jun" || m=="Jun" || m=="JUN")
         return 6;
      else if (m=="jul" || m=="Jul" || m=="JUL")
         return 7;
      else if (m=="aug" || m=="Aug" || m=="AUG")
         return 8;
      else if (m=="sep" || m=="Sep" || m=="SEP")
         return 9;
      else if (m=="oct" || m=="Oct" || m=="OCT")
         return 10;
      else if (m=="nov" || m=="Nov" || m=="NOV")
         return 11;
      else if (m=="dec" || m=="Dec" || m=="DEC")
         return 12;
      else
         return 0;
   }

   function checkDate(dateField) {
      // Validates a date input field
      // Arguments: 1. reference to the date-entry field:
      //    2. error message (if passed empty, uses default)
      //    3. date display format (defaults to 'dd MMM yyyy')
      // Called as onChange="return validDate(this,'Duh!','0')"
      // Function converts date to a standard database format
      //    or selects invalid entry and prompts the user
      // If year does not include century, and year < 10 (n),
      //    converts the century to 2K+
      
      var errMsg = "Invalid date! Please re-enter using a MM-DD-YY."
      var fmt = 7;
      
      var ds = dateField.value;
      // bail if the date parameter is empty
      if (ds == "")
         return true;
      
      // Check browser type
      var agt = navigator.userAgent.toLowerCase();
	  var isIE = (agt.indexOf("msie") != -1);
	  if (!isIE){
		if (ds.charAt(2) != "-" || ds.charAt(5) != "-"){
			return warnInvalid(dateField,errMsg); 
		}
		else
		{
			return true;	
		}
	  }
      
      // suppress browser error dialogs on date function calls
      window.onerror = null;
      
      // declare local variables
      var n = 10;   // the Y2K offset in years
      var today = new Date();
      var err = 0;  // error flag
      var month = "";
      var d;
      var m;
      var y;
      var p1 = 0;
      var p2 = 0;
      var dd = 0;
      var mm = 0;
      var yy = 0;
      
      var e = errMsg;
      if (errMsg == "") {
         // default error message if second parameter is empty 
         e = "Invalid date! Please re-enter using a standard format...";
      }
      
      // strip leading and trailing spaces
      while (ds.charAt(0) == " ") {
            ds = ds.substring(1,ds.length);
            dateField.value = ds;
      }
      while (ds.charAt(ds.length-1) == " ") {
            ds = ds.substring(0,ds.length-1);
            dateField.value = ds;
      }  
      
      // handle common data-entry shortcuts
      if (ds == "t" || ds == "today" || ds == "0") {
            dd = today.getDate();
            mm = today.getMonth() + 1;
            yy = today.getYear();
            ds = mm + "/" + dd + "/" + yy;
      }
      else if (ds.length < 3 && isNum(ds)) {
         // try as a date in the current month and year
         if (parseInt(ds) < 32) {
            dd = ds;
            mm = today.getMonth() + 1;
            yy = today.getYear();
            ds = mm + "/" + dd + "/" + yy;
         }
      }
      else if (ds.length == 3 && monthToNum(ds) > 0) {
         // assume it's a month string, set date as 1st
         dd = 1;
         mm = monthToNum(ds);
         yy = today.getYear();
         ds = mm + "/" + dd + "/" + yy;
      }
      else if (ds.length == 4 && isNum(ds)) {
         // assume it's a year (yyyy), set date as 1st January
         dd = 1;
         mm = 1;
         yy = ds;
         ds = mm + "/" + dd + "/" + yy;
      }
      else if (ds.length>4 && ds.length<7 && monthToNum(ds.substring(0,3))>0 && ds.indexOf(" ",0)>0) {
         // assume it's a month and day (mmm d[d]), set year as current
         p1 = ds.indexOf(" ");   // position of space
         dd = ds.substring(p1+1,ds.length);
         mm = monthToNum(ds.substring(0,3));
         yy = today.getYear();
         ds = mm + "/" + dd + "/" + yy;
      }
      else if (ds.length>2 && ds.length<6 && ds.indexOf("~",0)>0 && ds.indexOf("~",0)==ds.lastIndexOf("~")) {
         // assume it's a month and day (mm/dd), set year as current
         p1 = ds.indexOf("/");   // position of slash
         mm = ds.substring(0,p1);
         dd = ds.substring(p1+1,p1+3);
         yy = today.getYear();
         if (dd.charAt(0) == "0") dd = dd.substring(1,2);
         if (mm.charAt(0) == "0") mm = mm.substring(1,2);
         ds = mm + "/" + dd + "/" + yy;
      }
      else if (ds.length>2 && ds.length<6 && ds.indexOf(" ",0)>0 && ds.indexOf(" ",0)==ds.lastIndexOf(" ")) {
         // assume it's a month and day (mm dd), set year as current
         p1 = ds.indexOf(" ");   // position of space
         mm = ds.substring(0,p1);
         dd = ds.substring(p1+1,p1+3);
         yy = today.getYear();
         if (dd.charAt(0) == "0") dd = dd.substring(1,2);
         if (mm.charAt(0) == "0") mm = mm.substring(1,2);
         ds = mm + "/" + dd + "/" + yy;
      }
      else if (ds.length>2 && ds.length<6 && ds.indexOf("~",0)>0 && ds.indexOf("~",0)==ds.lastIndexOf("~")) {
         // assume it's a day and month (dd-mm), set year as current
         p1 = ds.indexOf("/");   // position of dash
         dd = ds.substring(0,p1);
         mm = ds.substring(p1+1,ds.length);
         yy = today.getYear();
         if (dd.charAt(0) == "0") dd = dd.substring(1,2);
         if (mm.charAt(0) == "0") mm = mm.substring(1,2);
         ds = mm + "/" + dd + "/" + yy;
      }
      
      if (ds.indexOf("~",0)>0 && ds.indexOf("~",0)<3) {
         // test for DD-MMM-YYYY standard format
         if (ds.length == 11 && ds.indexOf("/",0) == 2 && ds.lastIndexOf("/") == 6) {
            dd = ds.substring(0,2);
            mm = monthToNum(ds.substring(3,6));
            yy = ds.substring(7,11);
            if (dd.charAt(0) == "0") dd = dd.substring(1,2);
            if (isNum(mm+dd+yy)) {
               ds = mm + "/" + dd + "/" + yy;
            }
            else {
               mm = 0;
               dd = 0;
               yy = 0;
            }
         }
         // test for DD-MMM-YY abbreviated format
         else if (ds.length == 9 && ds.indexOf("~",0) == 2 && ds.lastIndexOf("~") == 6) {
            dd = ds.substring(0,2);
            mm = monthToNum(ds.substring(3,6));
            yy = (parseInt(ds.substring(7,9))<n) ? ("20" + ds.substring(7,9)) : ("19" + ds.substring(7,9));
            if (dd.charAt(0) == "0") dd = dd.substring(1,2);
            if (isNum(mm+dd+yy)) {
               ds = mm + "/" + dd + "/" + yy;
            }
            else {
               mm = 0;
               dd = 0;
               yy = 0;
            }
         }
         // test for DD-MM-YY[YY] format
         else {
            p1 = ds.indexOf("/");   // position of first dash
            dd = ds.substring(0,p1);
            p2 = ds.lastIndexOf("/");   // position of last dash
            mm = ds.substring(p1+1,p2);
            yy = ds.substring(p2+1,ds.length);
            if (dd.charAt(0) == "0") dd = dd.substring(1,2);
            if (mm.charAt(0) == "0") mm = mm.substring(1,2);
            if (yy.length > 4) yy = yy.substring(0,4);
            if (dd==0 || mm==0) {
                  mm = 0;
                  dd = 0;
                  yy = 0;
            }
            else {
               if (yy == "0" || yy == "00" || yy == "000") yy = "2000";
               while (yy.substring(0,1)=="0") {
                  yy = yy.substring(1,yy.length);  // remove leading zeroes
               }
               if (yy == "") yy = today.getYear();
               if (isNum(mm+dd+yy)) {
                  if (yy > 0 && yy < 100) {
                     yy = (yy < n) ? (2000 + parseInt(yy)) : (1900 + parseInt(yy));
                  }
                  ds = mm + "/" + dd + "/" + yy;
               }
               else {
                     mm = 0;
                     dd = 0;
                     yy = 0;
               }
            }
         }
      }
      
      // test for MMDDYY patterned formats
      else if (ds.length == 6 && isNum(ds)) {
         dd = ds.substring(2,4);
         mm = ds.substring(0,2);
         yy = ds.substring(4,6);
         if (dd.charAt(0) == "0") dd = dd.substring(1,2);
         if (mm.charAt(0) == "0") mm = mm.substring(1,2);
         if (yy.charAt(0) == "0") yy = yy.substring(1,2);
         if (yy == "0" || yy == "00") yy = "2000";
         if (yy > 0 && yy < 100) {
            yy = (yy < n) ? (2000 + parseInt(yy)) : (1900 + parseInt(yy));
         }
         ds = mm + "/" + dd + "/" + yy;
      }
      
      // test for MMDDYYYY patterned formats
      else if (ds.length == 8  && isNum(ds)) {
         dd = ds.substring(2,4);
         mm = ds.substring(0,2);
         yy = ds.substring(4,8);
         if (yy == "0" || yy == "00" || yy == "000") yy = "2000";
         if (dd.charAt(0) == "0") dd = dd.substring(1,2);
         if (mm.charAt(0) == "0") mm = mm.substring(1,2);
         ds = mm + "/" + dd + "/" + yy;
      }
      
      // convert year 2K+ for MM/DD/YY[YY] pattern formats
      else if (ds.indexOf("/",0) > 0 && (ds.length-ds.lastIndexOf("/")) < 6) {
         p1 = ds.indexOf("/");   // position of first slash
         mm = ds.substring(0,p1);
         p2 = ds.lastIndexOf("/");   // position of last slash
         dd = ds.substring(p1+1,p2);
         yy = ds.substring(p2+1,ds.length);
         if (dd.charAt(0) == "0") dd = dd.substring(1,2);
         if (mm.charAt(0) == "0") mm = mm.substring(1,2);
         if (yy.length > 4) yy = yy.substring(0,4);
         if (yy == "0" || yy == "00" || yy == "000") yy = "2000";
         while (yy.substring(0,1)=="0") {
            yy = yy.substring(1,yy.length);  // remove leading zeroes
         }
         if (yy == "") yy = today.getYear();
         if (isNum(mm+dd+yy)) {
            if (yy > 0 && yy < 100) {
               yy = (yy < n) ? (2000 + parseInt(yy)) : (1900 + parseInt(yy));
            }
            ds = mm + "/" + dd + "/" + yy;
         }
         else {
               mm = 0;
               dd = 0;
               yy = 0;
         }
      }
      
      // convert year 2K+ for MM.DD.YY[YY] pattern formats
      else if (ds.indexOf(".",0) > 0 && (ds.length-ds.lastIndexOf(".")) < 6) {
         p1 = ds.indexOf(".");   // position of first dot
         mm = ds.substring(0,p1);
         p2 = ds.lastIndexOf(".");   // position of last dot
         dd = ds.substring(p1+1,p2);
         yy = ds.substring(p2+1,ds.length);
         if (dd.charAt(0) == "0") dd = dd.substring(1,2);
         if (mm.charAt(0) == "0") mm = mm.substring(1,2);
         if (yy.length > 4) yy = yy.substring(0,4);
         if (yy == "0" || yy == "00" || yy == "000") yy = "2000";
         while (yy.substring(0,1)=="0") {
            yy = yy.substring(1,yy.length);  // remove leading zeroes
         }
         if (yy == "") yy = today.getYear();
         if (isNum(mm+dd+yy)) {
            if (yy > 0 && yy < 100) {
               yy = (yy < n) ? (2000 + parseInt(yy)) : (1900 + parseInt(yy));
            }
            ds = mm + "/" + dd + "/" + yy;
         }
         else {
               mm = 0;
               dd = 0;
               yy = 0;
         }
      }
      
      // validate the standard space-delimited formats
      else if (ds.indexOf(" ",0)>0 && (ds.length-ds.lastIndexOf(" "))<6) {
         if (ds.indexOf(",",0) > 0) {
            // validate 'mmm[...] dd, yy[yy]' type formats
            p1 = ds.indexOf(" ");   // position of first space
            mm = monthToNum(ds.substring(0,3));
            dd = ds.substring(p1+1,ds.indexOf(",",0));
            p2 = ds.lastIndexOf(" ");   // position of last space
            yy = ds.substring(p2+1,ds.length);
            if (dd.charAt(0) == "0") dd = dd.substring(1,2);
            if (yy.length > 4) yy = yy.substring(0,4);
            if (yy == "0" || yy == "00" || yy == "000") yy = "2000";
            while (yy.substring(0,1)=="0") {
               yy = yy.substring(1,yy.length);  // remove leading zeroes
            }
            if (yy == "") yy = today.getYear();
            if (isNum(mm+dd+yy)) {
               if (yy > 0 && yy < 100) {
                  yy = (yy < n) ? (2000 + parseInt(yy)) : (1900 + parseInt(yy));
               }
               ds = mm + "/" + dd + "/" + yy;
            }
            else {
               mm = 0;
               dd = 0;
               yy = 0;
            }
         }
         
         else if (monthToNum(ds.substring(ds.indexOf(" ")+1,ds.indexOf(" ")+4))>0) {
            // validate 'dd mmm[...] yy[yy]' type formats
            p1 = ds.indexOf(" ");   // position of first space
            dd = ds.substring(0,p1);
            if (dd.charAt(0) == "0") dd = dd.substring(1,2);
            p2 = ds.lastIndexOf(" ");   // position of last space
            mm = monthToNum(ds.substring(p1+1,p1+4));   // extract 3 bytes for month
            yy = ds.substring(p2+1,ds.length);
            if (yy.length > 4) yy = yy.substring(0,4);
            if (yy == "0" || yy == "00" || yy == "000") yy = "2000";
            while (yy.substring(0,1) == "0") {
               yy = yy.substring(1,yy.length);  // remove leading zeroes
            }
            if (yy == "") yy = today.getYear();
            if (isNum(mm+dd+yy)) {
               if (yy > 0 && yy < 100) {
                  yy = (yy < n) ? (2000 + parseInt(yy)) : (1900 + parseInt(yy));
               }
               ds = mm + "/" + dd + "/" + yy;
            }
            else {
               mm = 0;
               dd = 0;
               yy = 0;
            }
         }
         
         // validate 'MM DD YY[YY]' formats
         else {
            p1 = ds.indexOf(" ");   // position of first space
            mm = ds.substring(0,p1);
            p2 = ds.lastIndexOf(" ");   // position of last space
            dd = ds.substring(p1+1,p2);
            yy = ds.substring(p2+1,ds.length);
            if (dd.charAt(0) == "0") dd = dd.substring(1,2);
            if (mm.charAt(0) == "0") mm = mm.substring(1,2);
            if (yy.length > 4) yy = yy.substring(0,4);
            if (yy == "0" || yy == "00" || yy == "000") yy = "2000";
            while (yy.substring(0,1)=="0") {
               yy = yy.substring(1,yy.length);  // remove leading zeroes
            }
            if (yy == "") yy = today.getYear();
            if (isNum(mm+dd+yy)) {
               if (yy > 0 && yy < 100) {
                  yy = (yy < n) ? (2000 + parseInt(yy)) : (1900 + parseInt(yy));
               }
               ds = mm + "/" + dd + "/" + yy;
            }
            else {
               mm = 0;
               dd = 0;
               yy = 0;
            }
         }
      }
      
      // attempt to parse any other dates with valid IETF formats
      if (dd==0 && mm==0 && yy==0) {
         d = new Date(Date.parse(ds));
         dd = d.getDate();
         mm = (d.getMonth() + 1);
         // Netscape returns last 2 digits of years 1900-1999,
         // and the full year (4 char) string for dates > 2000 or < 1900;
         // IE returns 1900 minus the current year in all cases,
         // <duh> except IE3, when the year is earlier than 1970 </duh>
         if (d.getYear() > 2000) {
            yy = d.getYear();  // Netscape
         }
         else if (d.getYear() < 1900 && d.getYear() > 200) {
            yy = d.getYear();  // Netscape, date prior to 1900
         }
         else {
            yy = (1900 + d.getYear());
         }
         if (dd == 31 && mm == 12 && yy == 1969) {
            // IE's start-epoch date
            mm = 0;
            dd = 0;
            yy = 0;
         }
         ds = mm + "/" + dd + "/" + yy;
      }
      
      // verify the date components
      if (parseInt(dd)>0 && parseInt(mm)>0 && parseInt(yy)+1>0) {
         if (mm < 1 || mm > 12) err = 1;
         if (dd < 1 || dd > 31) err = 1;
         if (yy < 1000 || yy > 9999) err = 1;
         
         // check the months with 30 days
         if (mm == 4 || mm == 6 || mm == 9 || mm == 11) {
            if (dd == 31) {
               dd = 1;  // flick it forward a day
               mm = mm + 1;
            }
         }
         // check February and leap years
         if (mm == 2) {
            if (dd > 29) err = 1;
            if (dd == 29 && ((yy/4) != parseInt(yy/4))) {
               dd = 1;  // flick it forward a day
               mm = 3;
            }
         }
      }
      
      // finally, test whether the input string can be Date.parsed
      d = new Date(Date.parse(ds));
      if (!d.getDate()) err = 1;
      
      if (err==1 || dd==0 || mm==0) {
         alert(e);
         dateField.select();
         dateField.focus();
         return false;
      }
      
      // we have a valid IETF date, so convert it to
      // the specified standard format for database entry
      if (parseInt(dd)<10 && (fmt < 4 || fmt > 6))
         dd = "0" + dd;   // add leading zero to days 1-9
      
      // convert month numeric to string
      if (mm == 1)
         month = "Jan";
      else if (mm == 2)
         month = "Feb";
      else if (mm == 3)
         month = "Mar";
      else if (mm == 4)
         month = "Apr";
      else if (mm == 5)
         month = "May";
      else if (mm == 6)
         month = "Jun";
      else if (mm == 7)
         month = "Jul";
      else if (mm == 8)
         month = "Aug";
      else if (mm == 9)
         month = "Sep";
      else if (mm == 10)
         month = "Oct";
      else if (mm == 11)
         month = "Nov";
      else if (mm == 12)
         month = "Dec";
      else month == "";
      // add leading zero to months 1-9 for mm formats
      if (fmt > 6 && mm < 10) mm = "0" + mm;

      // trim for yy formats
      if ((yy>99) && (fmt==0 || fmt==2 || fmt==5 || fmt==7 || fmt==9)) {
         yy = yy - (parseInt(yy/100)*100);
         if (yy < 10) yy = "0" + yy;
      }
      
      // re-test the date components
      if (dd==0 || dd=="" || month=="" || mm==0 || mm=="" || yy=="") {
         alert(e);
         dateField.select();
         dateField.focus();
         return false;
      }
      
      // redraw the date input field per format parameter:
      /*  0 = "dd mmm yy"     e.g. 27 Jan 99
          1 = "dd mmm yyyy"   e.g. 27 Jan 1999
          2 = "dd-mmm-yy"     e.g. 05-Aug-98
          3 = "dd-mmm-yyyy"   e.g. 05-Aug-1998
          4 = "mmm d, yyyy"   e.g. Aug 5, 1999
          5 = "m/d/yy"        e.g. 8/5/98
          6 = "m/d/yyyy"      e.g. 8/5/1998
          7 = "mm-dd-yy"      e.g. 09/21/56
          8 = "mm/dd/yyyy"    e.g. 08/05/1998
          9 = "mm dd yy"      e.g. 08 15 98
          10 = "mm dd yyyy"   e.g. 21 09 1956  */
           
      if (fmt == 1)
         dateField.value = dd + " " + month + " " + yy;
      else if (fmt == 2)
         dateField.value = dd + "-" + month + "-" + yy;
      else if (fmt == 3)
         dateField.value = dd + "-" + month + "-" + yy;
      else if (fmt == 4)
         dateField.value = month + " " + dd + ", " + yy;
      else if (fmt == 5)
         dateField.value = mm + "/" + dd + "/" + yy;
      else if (fmt == 6)
         dateField.value = mm + "/" + dd + "/" + yy;
      else if (fmt == 7)
         dateField.value = mm + "-" + dd + "-" + yy;
      else if (fmt == 8)
         dateField.value = mm + "/" + dd + "/" + yy;
      else if (fmt == 9)
         dateField.value = mm + " " + dd + " " + yy;
      else if (fmt == 10)
         dateField.value = mm + " " + dd + " " + yy;
      else
         dateField.value = dd + " " + month + " " + yy;
            
      return true;
   }


function isLetter (c)
{   
	return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}

function isAlphabetic (s)
{   var i;

    if (isEmpty(s.value)) 
       if (isAlphabetic.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphabetic.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-alphabetic character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.value.length; i++)
    {   
        // Check that current character is letter.
        var c = s.value.charAt(i);

        //if (!isLetter(c))
        if (isDigit(c))
        {
			return warnInvalid (s, "This field accepts alphabetic characters only.  Please reenter an character value.");
        }
    }

    // All characters are letters.
    return 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;
}

//20080630 syskar
function isAlphaNumeric (s)
{   var i;

    if (isEmpty(s.value)) 
       if (isAlphabetic.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphabetic.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-alphabetic character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.value.length; i++)
    {   
        // Check that current character is letter.
        var c = s.value.charAt(i);

		if (!isLetter(c) && !isDigit(c))
        //if (isDigit(c))
        {			
			return warnInvalid (s, "This field accepts alphanumeric characters only.  Please reenter a different value.");
        }
    }

    // All characters are letters.
    return true;
}

// Function to validate the zip code against the state code
//NJ, PA, FL added by Liz Johnson 1/29/02
function isValidStateZip(zip,state)
{   var i;

    if (isEmpty(zip.value))
    {
		return true;
	}
		
    //   if (isValidStateZip.arguments.length == 1) return defaultEmptyOK;
    //   else return (isValidStateZip.arguments[1] == true);

	if (state == "CA")
	{
		if ((zip.value >= "90000") && (zip.value <= "96699"))
		{
			return true;
		}	
		else
		{
			return warnInvalid (zip, "Please reenter a valid California zip code.");
		}
	}

	if (state == "CO")
	{
		if ((zip.value >= "80000") && (zip.value <= "81699"))
		{
			return true;
		}	
		else
		{
			return warnInvalid (zip, "Please reenter a valid Colorado zip code.");
		}
	}
	
		if (state == "NJ")
	{
		if ((zip.value >= "07001") && (zip.value <= "08989"))
		{
			return true;
		}	
		else
		{
			return warnInvalid (zip, "Please reenter a valid New Jersey zip code.");
		}
	}
		
		if (state == "PA")
	{
		if ((zip.value >= "15001") && (zip.value <= "19640"))
		{
			return true;
		}	
		else
		{
			return warnInvalid (zip, "Please reenter a valid Pennsylvania zip code.");
		}
	}
		if (state == "FL")
	{
		if ((zip.value >= "32003") && (zip.value <= "34997"))
		{
			return true;
		}	
		else
		{
			return warnInvalid (zip, "Please reenter a valid Florida zip code.");
		}
	}	
	

    // All characters are numbers.
    return true;
}
// Function to round to the nearest whole 1000 dollar value.  This is for
// LibertyAmerican rating filing where is this rule is specified.
// Written by: Liz Johnson 07-17-01
function roundCeiling(s)
{
  if (isNumeric(s) == 1) 
  {
	thisField = s
	s = s.value
	s = s / 1000
	s = Math.ceil(s)
	s = s * 1000
	thisField.value = s
  }
}

//20080630 syskar
function isValidEmail(s)
{   
	if (isEmpty(s.value) || s.value.indexOf(".") < 0 || s.value.indexOf("@") < 0 || s.value.lastIndexOf(".") > s.value.length - 2 || s.value.lastIndexOf(".") < s.value.indexOf("@")  )
	{
		return warnInvalid (s, "You have entered an invalid email address. Please try again.");
	}
	
    // All characters are letters.
    return true;
}



