function getIndex (form,field) {
  for (i = 0; i < form.elements.length; i++) {
    if (form.elements[i].name == field.name) {
      return i;
    }
  }
}

function focusNext(form,field) {
  var index = getIndex(form,field);
  for (i = index + 1; i < form.elements.length; i++) {
    if ((form.elements[i].type != "hidden") && (form.elements[i].disabled != true)) {
      form.elements[i].focus();
      break;
    }
  }
}

// Change Hyperlink when hovering hyperlink
function setStatus(msg) {
    window.status=msg;
    return true;
}


//Date Validation
function VerifyDate(datefrom)
{
 if(datefrom.value!='')
  {
  var dtstr='date';
  var dtDD='day';
  var dtMM='Month';
  var dtYYYY='Year';
  var dtCentury='Century';
  var Montharray= new Array('01','02','03','04','05','06','07','08','09','10','11','12');
  var dayarray= new Array('31','28','31','30','31','30','31','31','30','31','30','31');

  // pull out any seperators to check for validation
  for (var i=0, output='', valid="/-"; i < datefrom.value.length; i++)
    {
    if (valid.indexOf(datefrom.value.charAt(i)) == -1)
    output += datefrom.value.charAt(i)
    dtstr=output;
    }

  //dtstr=datefrom.value;
  dtDD=dtstr.substring(2,4); 
  dtMM=dtstr.substring(0,2);
  dtYYYY=dtstr.substring(4,8);
  dtCentury=dtstr.substring(4,6);

  if((dtYYYY%4==0 && dtYYYY%100!=0)||(dtYYYY%100==0 && dtYYYY%400==0))
    dayarray[1]=29;
  else
    dayarray[1]=28;

  if(isNaN(dtstr) || dtstr.length<8) {
    alert('Invalid Date. \nFormat should be MM/DD/YYYY.')
    datefrom.value='';
//    datefrom.focus(); 
	}
  else 
  if(dtCentury>=10) {
    if(dtMM>=1 && dtMM<=12) {
      for(i=0;i<Montharray.length;i++) { 
        if(Montharray[i]==dtMM) {
          if(dtDD>dayarray[i] || dtDD==0) {
            //alert for wrong days
            alert('Invalid Date. \nFormat should be MM/DD/YYYY.');
            datefrom.value='';
            datefrom.focus(); 
		  }
        break;
      }
    }
  }
  else
  {
    // alert for wrong month
    alert('Invalid Date. \nFormat should be MM/DD/YYYY.');
    datefrom.value='';
    datefrom.focus();}
  }
  else
  {
    //alert for wrong century
    alert('Invalid Date. \nFormat should be MM/DD/YYYY.');
    datefrom.value='';
    datefrom.focus();}
  }
  // return the date with seperators
  if(datefrom.value!='') {
    datefrom.value =  dtMM + '/' + dtDD + '/' + dtYYYY;
    return true;
  }
}


// Numeric Validation
function VerifyNum(number)
{
 if(isNaN(number.value))
 {
  alert("Enter a valid numeric value");
  number.focus();
  number.value=''
  return false;
 }
 else
 {
 return true;
 }
}

// Empty Field Validation
function notblank(fld)
{
 if(fld.value=='')
 {
  alert("Field Should not be blank");
  fld.focus();
  return false;  
 }
 else
 {
  return true;
 } 
}

// New Empty Field Validation
function forceText(fld)
{
 if(fld.value=='')
 {
  alert(fld.name + " should not be blank");
  fld.focus();
  return false;  
 }
 else
 {
  return true;
 } 
}

// New Numeric Validation
function forceNum(fld)
{
 if(isNaN(fld.value))
 {
  alert(fld.name + " should be a numeric value");
  fld.focus();
  fld.value=''
  return false;
 }
 else
 {
 return true;
 }
}

// Time Validation
function VerifyTime(Stime,format)
{
 if(Stime.value!='')
 { 
  var tmstr='time';
  var tmHH='hrs';
  var tmMM='Minuts';
  var tmSS='Seconds';
  var tmFormat=format;
  tmstr=Stime.value;
  tmHH=tmstr.substring(0,2); 
  tmMM=tmstr.substring(3,5);
  tmSS=tmstr.substring(6,8);
 
 TMnum=tmHH+tmMM+tmSS;

 if(isNaN(TMnum) || tmstr.length!=tmFormat.length)
  {alert('Invalid Time \nEnter the valid Time In the given format')
   Stime.focus();}
 else if(tmHH>24 || tmHH < 0)
  {alert('invalid Hrs should be 0 to 24');
   Stime.focus();}
 else if(tmMM>=60)
  {alert('invalid minutes should  be < 60');
   Stime.focus();}
 else if(tmSS>=60)
  {alert('invalid Second should  be < 60');
   Stime.focus();}
 else if(tmHH==24 && tmMM>0 || tmHH==24 && tmSS>0)
  {alert('invalid Time');
   Stime.focus();}
 else if(tmHH==0 && tmMM==0 && tmSS==0)
  {alert('invalid Time');
   Stime.focus();}
 else
  return true;

 }
}

function VerifyDate1(dateto)
{
if(dateto.value!='')
 { 
  var dtstr='date';
  var dtDD='day';
  var dtMM='Month';
  var dtYYYY='Year';
  var dtCentury='Century'
  var Montharray= new Array('01','02','03','04','05','06','07','08','09','10','11','12');
  var dayarray=  new Array('31','28','31','30','31','30','31','31','30','31','30','31');

   dtstr=dateto.value;
   dtDD=dtstr.substring(0,2); 
   dtMM=dtstr.substring(3,5);
   dtYYYY=dtstr.substring(6,10);
   dtCentury=dtstr.substring(6,8);
   dtnum=dtDD+dtMM+dtYYYY;
if((dtYYYY%4==0 && dtYYYY%100!=0)||(dtYYYY%100==0 && dtYYYY%400==0))
   dayarray[1]=29;
else
dayarray[1]=28;

  if(isNaN(dtnum) || dtstr.length<10)
  { alert('Invalid Date. \nFormat should be DD/MM/YYYY.')
   dateto.focus();}
   else if(dtCentury>=10)
   {
    if(dtMM>=1 && dtMM<=12)
    {
     for(i=0;i<Montharray.length;i++)
     { 
      if(Montharray[i]==dtMM)
      {
       if(dtDD>dayarray[i] || dtDD==0)
	   //alert for wrong days
        { alert('Invalid Date. \nFormat should be DD/MM/YYYY.');
        dateto.focus();
        }
       break;
      }
     }
   }
   else
    {
	//alert for wrong month
	alert('Invalid Date. \nFormat should be DD/MM/YYYY.');
    dateto.focus();}
  }
 else
  {
  //alert for wrong century
  alert('Invalid Date. \nFormat should be DD/MM/YYYY.');
   dateto.focus();}

 }
}




function chkdate(recdate)
{ 
  var dtDD='day';
  var dtMM='Month';
  var dtYYYY='Year';
  var dtstr=recdate;
  
  var cdate=new Date();
  var entdate=new Date();

  dtDD=dtstr.substring(0,2); 
  dtMM=dtstr.substring(3,5);
  dtYYYY=dtstr.substring(6,10);

  entdate.setDate(dtDD);
  entdate.setMonth(dtMM-1);
  entdate.setYear(dtYYYY);

 if(entdate<cdate)
 return true;
 else
 return false;

}


function Comparedates(Fdate,Tdate,Seperator)
{ 
  var FdtDD='Day';
  var FdtMM='Month';
  var FdtYYYY='Year';

  var TdtDD='day';
  var TdtMM='Month';
  var TdtYYYY='Year';

  var FromDatestr=Fdate;
  var ToDatestr=Tdate;
  var DSeperator=Seperator;

  var Fromdate=new Date();
  var Todate=new Date();

 if(FromDatestr!='' && ToDatestr!='')
 {

  if(DSeperator!='')
  { 
   FdtDD=FromDatestr.substring(0,2); 
   FdtMM=FromDatestr.substring(3,5);
   FdtYYYY=FromDatestr.substring(6,10);

   TdtDD=ToDatestr.substring(0,2); 
   TdtMM=ToDatestr.substring(3,5);
   TdtYYYY=ToDatestr.substring(6,10);
  
  }
  else 
  {
   FdtDD=FromDatestr.substring(0,2); 
   FdtMM=FromDatestr.substring(2,4);
   FdtYYYY=FromDatestr.substring(4,8);

   TdtDD=ToDatestr.substring(0,2); 
   TdtMM=ToDatestr.substring(2,4);
   TdtYYYY=ToDatestr.substring(4,8);
  }


 
  Fromdate.setYear(FdtYYYY);
  Fromdate.setMonth(FdtMM-1);
  Fromdate.setDate(FdtDD);
 
  Todate.setYear(TdtYYYY);
  Todate.setMonth(TdtMM-1);
  Todate.setDate(TdtDD);

  if(Todate<Fromdate)
  return true;
  else
  return false;
 }
else
  return false;

}



function VerifyDateNul(dateto,DateOrigin)
{
if(dateto.value!='')
 { 
  var dtstr='date';
  var dtDD='day';
  var dtMM='Month';
  var dtYYYY='Year';
  var dtCentury='Century'
  var Montharray= new Array('01','02','03','04','05','06','07','08','09','10','11','12');
  var dayarray=  new Array('31','28','31','30','31','30','31','31','30','31','30','31');

   dtstr=dateto.value;
   dtDD=dtstr.substring(0,2); 
   dtMM=dtstr.substring(3,5);
   dtYYYY=dtstr.substring(6,10);
   dtCentury=dtstr.substring(6,8);
   dtnum=dtDD+dtMM+dtYYYY;
if((dtYYYY%4==0 && dtYYYY%100!=0)||(dtYYYY%100==0 && dtYYYY%400==0))
   dayarray[1]=29;
else
dayarray[1]=28;

if(dtCentury>=10)
   {
    if(dtMM>=1 && dtMM<=12)
    {
     for(i=0;i<Montharray.length;i++)
     { 
      if(Montharray[i]==dtMM)
      {
       if(dtDD>dayarray[i] || dtDD==0)
		{
        //alert for wrong days
		alert('Invalid Date. \nFormat should be DDMMYYYY.');
		dateto.value=DateOrigin;
		dateto.focus();
        }
       break;
      }
     }
   }
   else
   {
   // alert for wrong month
   alert('Invalid Date. \nFormat should be DDMMYYYY.');
	dateto.value=DateOrigin;
	dateto.focus();}
  }
 else
  {
  //alert for wrong century
  alert('Invalid Date. \nFormat should be DDMMYYYY.');
	dateto.value=DateOrigin;
	dateto.focus();}

 }
}

function chkdateNul(recdate)
{ 
alert(recdate);

  var dtDD='day';
  var dtMM='Month';
  var dtYYYY='Year';
  var dtstr=recdate;
  
  var cdate=new Date();
  var entdate=new Date();

  dtDD=dtstr.substring(0,2); 
  dtMM=dtstr.substring(3,5);
  dtYYYY=dtstr.substring(6,10);

  entdate.setDate(dtDD);
  entdate.setMonth(dtMM-1);
  entdate.setYear(dtYYYY);

if(entdate<cdate)
 return true;
 else
 return false;
}

//the following function checks if the user's browser supports such advanced features as DIVs.
function OldBrowser()
{
var iePos = navigator.appVersion.indexOf("MSIE");
if (iePos>0)
	ver=parseInt(navigator.appVersion.substring(iePos+5,iePos+7));
else
	ver=parseInt(navigator.appVersion);

if (ver<5)
	return true;
else
	return false;
}

function radio_checker()
{
  // set var radio_choice to false
  var radio_choice = false;

  // Test if has only one record on the form
  if (document.forms[0].REC.value==null) {
    // Loop from zero to the one minus the number of radio button selections
    for (counter = 0; counter < document.forms[0].REC.length; counter++)
    {
      // If a radio button has been selected it will return true
      // (If not it will return false)
      if (document.forms[0].REC[counter].checked) {
        radio_choice = true;
        document.forms[0].selectedrec.value = document.forms[0].REC[counter].value
      }
    }
  }
  else {
    radio_choice = true;
	document.forms[0].selectedrec.value = document.forms[0].REC.value;
  }


  if (!radio_choice)
  {
    // If there were no selections made display an alert box 
    alert("Please select a record.")
    return (false);
  }
  return (true);
}

function openNewWindow(theURL,winName,features) 
{ //v2.0
  window.open(theURL,winName,features);
}

//Cookie functions
function SetCookie (name, value, expires, path, domain, secure) {
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +	
	((secure == true) ? "; secure" : "");
}

// Get Cookie Value function
function getCookieVal(offset) {
   var endstr = document.cookie.indexOf (";", offset);
   if (endstr == -1) endstr = document.cookie.length;
   return unescape (document.cookie.substring(offset, endstr));
}

// Get Cookie function
function GetCookie(name) {
   var arg = name+"=";
   var alen = arg.length;
   var clen = document.cookie.length;
   var i = 0;
   while (i < clen) {
      var j = i + alen;
      if (document.cookie.substring(i, j) == arg) return getCookieVal(j);
      i = document.cookie.indexOf(" ", i) + 1;
      if (i == 0) break;
   }
   return null;
}

function deleteCookie (name,path,domain) {
  if (GetCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function deleteOACCookies() {

	deleteCookie('oac_racfid',"/scripts/");
	deleteCookie('oac_pwd',"/scripts/");
	deleteCookie('oac_court',"/scripts/");
	deleteCookie('topRacfid',"/scripts/");
	deleteCookie('topPerson',"/scripts/");
	deleteCookie('topPerTK',"/scripts/");
        deleteCookie('BKREFCS',"/scripts/");
        deleteCookie('BKREFCS_TK',"/scripts/");
	return;
}

function setOACCookies() {

	// sets expiry date
   	var expdate = new Date ();
   	expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000 * 31));
	
	//stores cookies below
	SetCookie ("oac_racfid","allo",expdate,"/scripts/");
	SetCookie ("oac_pwd","allo",expdate,"/scripts/");
	SetCookie ("oac_court","allo",expdate,"/scripts/");
	
return;
}

function Login() {
  // sets expiry date
  var expdate = new Date ();
  expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000 * 31));
  
  //Different behavior if Netscape
  if(parent.document.layers) {
    parent.document.layers["loginLayer"].document.superForm.action = parent.document.forms[0].FORMACTION.value;
    parent.document.layers["loginLayer"].document.superForm.APPNAME.value = parent.document.forms[0].APPNAME.value;
    parent.document.layers["loginLayer"].document.superForm.PRGNAME.value = parent.document.forms[0].PRGNAME.value;
	SetCookie ("oac_racfid",parent.document.layers["loginLayer"].document.superForm.LOGINRACFID.value,expdate,"/scripts/");
	SetCookie ("oac_pwd",parent.document.layers["loginLayer"].document.superForm.PWD.value,expdate,"/scripts/");
	SetCookie ("oac_court",parent.document.layers["loginLayer"].document.superForm.COURT.value,expdate,"/scripts/");
  }
  else {
    parent.textFrame.document.superForm.action = parent.document.forms[0].FORMACTION.value;
    parent.textFrame.document.superForm.APPNAME.value = parent.document.forms[0].APPNAME.value;
    parent.textFrame.document.superForm.PRGNAME.value = parent.document.forms[0].PRGNAME.value;
	SetCookie ("oac_racfid",parent.textFrame.document.superForm.LOGINRACFID.value,expdate,"/scripts/");
	SetCookie ("oac_pwd",parent.textFrame.document.superForm.PWD.value,expdate,"/scripts/");
	SetCookie ("oac_court",parent.textFrame.document.superForm.COURT.value,expdate,"/scripts/");
  }
  
}

<!-- Prev next buttons
function initButtons() {
  var currForm=document.forms[0];
  preloadNavButtons('/IMAGES/bpushPrev.gif','/IMAGES/bpushNext.gif','/IMAGES/benablPrev.gif','/IMAGES/benablNext.gif');
  if (currForm.PrevEnabled.value=='true') {
    currForm.Prev.src = '/IMAGES/benablPrev.gif';
	currForm.Prev.Usrc = '/IMAGES/benablPrev.gif';
	currForm.Prev.Psrc = '/IMAGES/bpushPrev.gif';
	currForm.Prev.enbl = true;
	} else currForm.Prev.enbl = false;
  if (currForm.NextEnabled.value=='true') {
    currForm.Next.src = '/IMAGES/benablNext.gif';
	currForm.Next.Usrc = '/IMAGES/benablNext.gif';
	currForm.Next.Psrc = '/IMAGES/bpushNext.gif';
	currForm.Next.enbl = true;
	} else currForm.Next.enbl = false;
}

function preloadNavButtons() { //v3.0
  var d=document; if(d.images){ if(!d.p) d.p=new Array();
    var i,j=d.p.length,a=preloadNavButtons.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}

function findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function navButtonRestore() { //v3.0
  var x,a=navButtonRestore.arguments;
   if ((x=findObj(a[0]))!=null){
     if (x.enbl) {
	   x.src=x.Usrc;
	   return true;
     } else return false;
   };
}

function navButtonSwap() { //v3.0
  var x,a=navButtonSwap.arguments;
   if ((x=findObj(a[0]))!=null){
     if (x.enbl) {
	   x.src=x.Psrc;
	   return true;
     } else return false;
   };
}
//-->

function setWaitPointer() {
 if (document.all)
  for (var i=0;i < document.all.length; i++)
   document.all(i).style.cursor = 'wait';
}
function resetPointer() {
 if (document.all)
  for (var i=0;i < document.all.length; i++) document.all(i).style.cursor = 'default';
}
function PictureNum(expr,decplaces) {
// Example: x=PictureNum("10.5",2) ---> x="10.50"
	var str = (Math.round(parseFloat(expr) * Math.pow(10,decplaces))).toString()
	if (str=="NaN") str="0"
	while (str.length <= decplaces) {
		str = "0" + str
	} 
	var decpoint = str.length - decplaces
	return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length)
}

// VARIABLE DECLARATIONS

var digits = "0123456789";
var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz";
var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

// whitespace characters
var whitespace = " \t\n\r";

// decimal point character differs by language and culture
var decimalPointDelimiter = "."

// 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

var defaultEmptyOK = false

// i is an abbreviation for "invalid"
var iStateCode = "This field must be a valid two character U.S. state abbreviation (like CA for California). Please reenter it now."
var iZIPCode = "This field must be a 5-digit U.S. ZIP Code (like 90210). Please reenter it now."
var iCountryCode = "This field must be a 2-character code from one of the following codes US (United States), CA (Canada), or MX (Mexico)."
var iUSPhone = "This field must be a 10-digit U.S. phone number (like 415 555 1212). Please reenter it now."
var iWorldPhone = "This field must be a valid international phone number. 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."
var iEmail = "This field must be a valid email address (like foo@bar.com). Please reenter it now."
var iDay = "This field must be a day number between 1 and 31.  Please reenter it now."
var iMonth = "This field must be a month number between 1 and 12.  Please reenter it now."
var iYear = "This field must be a 2 or 4 digit year number.  Please reenter it now."
var iDatePrefix = "The Day, Month, and Year for "
var iDateSuffix = " do not form a valid date.  Please reenter them now."

// Notify user that contents of field theField are invalid.
// String s describes expected contents of theField.value.
// Put select theField, pu focus in it, and return false.
function warnInvalid (theField, s) {
    theField.focus()
    theField.select()
    alert(s)
    return false
}

// Attempting to make this library run on Navigator 2.0,
// so I'm supplying this array creation routine as per
// JavaScript 1.0 documentation.  If you're using 
// Navigator 3.0 or later, you don't need to do this;
// you can use the Array constructor instead.

function makeArray(n) {
//*** BUG: If I put this line in, I get two error messages:
//(1) Window.length can't be set by assignment
//(2) daysInMonth has no property indexed by 4
//If I leave it out, the code works fine.
//   this.length = n;
   for (var i = 1; i <= n; i++) {
      this[i] = 0
   } 
   return this
}

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;

// Valid U.S. Postal Codes for states, territories, armed forces, etc.
// See http://www.usps.gov/ncsc/lookups/abbr_state.txt.

var USStateCodeDelimiter = "|";
var USStateCodes = "AK|AL|AR|AZ|CA|CO|CT|DC|DE|FL|GA|HI|IA|ID|IL|IN|KS|KY|LA|MA|MD|ME|MI|MN|MO|MS|MT|NC|ND|NE|NH|NJ|NM|NM|NY|OH|OK|OR|PA|PR|RI|SC|SD|TN|TX|UT|VA|VT|WA|WI|WV|WY"

// Valid Country Codes
var CountryCodeDelimiter = "|";
var CountryCodes = "US|CA|MX"

// 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 all whitespace characters from s.
// Global variable whitespace (see above)
// defines which characters are considered whitespace.
function stripWhitespace (s) {
    return stripCharsInBag (s, whitespace)
}

// WORKAROUND FUNCTION FOR NAVIGATOR 2.0.2 COMPATIBILITY.
//
// The below function *should* be unnecessary.  In general,
// avoid using it.  Use the standard method indexOf instead.
//
// However, because of an apparent bug in indexOf on 
// Navigator 2.0.2, the below loop does not work as the
// body of stripInitialWhitespace:
//
// while ((i < s.length) && (whitespace.indexOf(s.charAt(i)) != -1))
//   i++;
//
// ... so we provide this workaround function charInString
// instead.
//
// charInString (CHARACTER c, STRING s)
//
// 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
}

// Removes initial (leading) whitespace characters from s.
// Global variable whitespace (see above)
// defines which characters are considered whitespace.
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 character c is an English letter 
// (A .. Z, a..z).
//
// NOTE: Need i18n version to support European characters.
// This could be tricky due to different character
// sets and orderings for various languages and platforms.

function isLetter (c) {
    return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}

// Returns true if character c is a digit 
// (0 .. 9).
function isDigit (c) {
    return ((c >= "0") && (c <= "9"))
}

// Returns true if character c is a letter or digit.
function isLetterOrDigit (c) {
    return (isLetter(c) || isDigit(c))
}
 
// 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.
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;
}

// isSignedInteger (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if all characters are numbers; 
// first character is allowed to be + or - as well.
//
// Does not accept floating point, exponential notation, etc.
//
// We don't use parseInt because that would accept a string
// with trailing non-numeric characters.
function isSignedInteger (s) {
    if (isEmpty(s)) 
       if (isSignedInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isSignedInteger.arguments[1] == true);

    else {
        var startPos = 0;
        var secondArg = defaultEmptyOK;

        if (isSignedInteger.arguments.length > 1)
            secondArg = isSignedInteger.arguments[1];

        // skip leading + or -
        if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
           startPos = 1;    
        return (isInteger(s.substring(startPos, s.length), secondArg))
    }
}

// isPositiveInteger (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if string s is an integer > 0.
//
function isPositiveInteger (s) {
    var secondArg = defaultEmptyOK;

    if (isPositiveInteger.arguments.length > 1)
        secondArg = isPositiveInteger.arguments[1];

    // The next line is a bit byzantine.  What it means is:
    // a) s must be a signed integer, AND
    // b) one of the following must be true:
    //    i)  s is empty and we are supposed to return true for
    //        empty strings
    //    ii) this is a positive, not negative, number

    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s) > 0) ) );
}

// isNonnegativeInteger (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if string s is an integer >= 0.
//
function isNonnegativeInteger (s) {
    var secondArg = defaultEmptyOK;

    if (isNonnegativeInteger.arguments.length > 1)
        secondArg = isNonnegativeInteger.arguments[1];

    // The next line is a bit byzantine.  What it means is:
    // a) s must be a signed integer, AND
    // b) one of the following must be true:
    //    i)  s is empty and we are supposed to return true for
    //        empty strings
    //    ii) this is a number >= 0

    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s) >= 0) ) );
}

// isNegativeInteger (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if string s is an integer < 0.
function isNegativeInteger (s) {
    var secondArg = defaultEmptyOK;

    if (isNegativeInteger.arguments.length > 1)
        secondArg = isNegativeInteger.arguments[1];

    // The next line is a bit byzantine.  What it means is:
    // a) s must be a signed integer, AND
    // b) one of the following must be true:
    //    i)  s is empty and we are supposed to return true for
    //        empty strings
    //    ii) this is a negative, not positive, number

    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s) < 0) ) );
}

// isNonpositiveInteger (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if string s is an integer <= 0.
function isNonpositiveInteger (s) {
    var secondArg = defaultEmptyOK;

    if (isNonpositiveInteger.arguments.length > 1)
        secondArg = isNonpositiveInteger.arguments[1];

    // The next line is a bit byzantine.  What it means is:
    // a) s must be a signed integer, AND
    // b) one of the following must be true:
    //    i)  s is empty and we are supposed to return true for
    //        empty strings
    //    ii) this is a number <= 0

    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s) <= 0) ) );
}

// isFloat (STRING s [, BOOLEAN emptyOK])
// 
// True if string s is an unsigned floating point (real) number. 
function isFloat (s) {
    var i;
    var seenDecimalPoint = false;

    if (isEmpty(s)) 
       if (isFloat.arguments.length == 1) return defaultEmptyOK;
       else return (isFloat.arguments[1] == true);

    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;
}

// isSignedFloat (STRING s [, BOOLEAN emptyOK])
// 
// True if string s is a signed or unsigned floating point 
// (real) number. First character is allowed to be + or -.
function isSignedFloat (s) {
    if (isEmpty(s)) 
       if (isSignedFloat.arguments.length == 1) return defaultEmptyOK;
       else return (isSignedFloat.arguments[1] == true);

    else {
        var startPos = 0;
        var secondArg = defaultEmptyOK;

        if (isSignedFloat.arguments.length > 1)
            secondArg = isSignedFloat.arguments[1];

        // skip leading + or -
        if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
           startPos = 1;    
        return (isFloat(s.substring(startPos, s.length), secondArg))
    }
}

// isAlphabetic (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if string s is English letters 
// (A .. Z, a..z) only.
function isAlphabetic (s) {
    var i;

    if (isEmpty(s)) 
       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.length; i++)
    {   
        // Check that current character is letter.
        var c = s.charAt(i);

        if (!isLetter(c))
        return false;
    }

    // All characters are letters.
    return true;
}

// isAlphanumeric (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if string s is English letters 
// (A .. Z, a..z) and numbers only.
function isAlphanumeric (s) {
    var i;

    if (isEmpty(s)) 
       if (isAlphanumeric.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphanumeric.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-alphanumeric 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 or letter.
        var c = s.charAt(i);

        if (! (isLetter(c) || isDigit(c) ) )
        return false;
    }

    // All characters are numbers or letters.
    return true;
}

// 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;
}

// 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.
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)
}

// 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.
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)
}

// isInternationalPhoneNumber (STRING s [, BOOLEAN emptyOK])
// 
// isInternationalPhoneNumber returns true if string s is a valid 
// international phone number.  Must be digits only; any length OK.
// May be prefixed by + character.
function isInternationalPhoneNumber (s) {
    if (isEmpty(s)) 
       if (isInternationalPhoneNumber.arguments.length == 1) return defaultEmptyOK;
       else return (isInternationalPhoneNumber.arguments[1] == true);
    return (isPositiveInteger(s))
}

// 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.
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)))
}

// isStateCode (STRING s [, BOOLEAN emptyOK])
// 
// Return true if s is a valid U.S. Postal Code 
// (abbreviation for state).
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) )
}

// isCountryCode (STRING s [, BOOLEAN emptyOK])
// 
// Return true if s is a valid Countrry Code 
// (abbreviation for country).
function isCountryCode(s) {
    if (isEmpty(s)) 
       if (isCountryCode.arguments.length == 1) return defaultEmptyOK;
       else return (isCountryCode.arguments[1] == true);
    return ( (CountryCodes.indexOf(s) != -1) &&
             (s.indexOf(CountryCodeDelimiter) == -1) )
}

// 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
function isEmail (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;
    
    // 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;
    else return true;
}

// isYear (STRING s [, BOOLEAN emptyOK])
// 
// isYear returns true if string s is a valid 
// Year number.  Must be 2 or 4 digits only.
function isYear (s) {
    if (isEmpty(s)) 
       if (isYear.arguments.length == 1) return defaultEmptyOK;
       else return (isYear.arguments[1] == true);
    if (!isNonnegativeInteger(s)) return false;
    return ((s.length == 2) || (s.length == 4));
}

// isIntegerInRange (STRING s, INTEGER a, INTEGER b [, BOOLEAN emptyOK])
// 
// isIntegerInRange returns true if string s is an integer 
// within the range of integer arguments a and b, inclusive.
function isIntegerInRange (s, a, b) {
    if (isEmpty(s)) 
       if (isIntegerInRange.arguments.length == 1) return defaultEmptyOK;
       else return (isIntegerInRange.arguments[1] == true);

    // 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));
}

// isMonth (STRING s [, BOOLEAN emptyOK])
// 
// 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 defaultEmptyOK;
       else return (isMonth.arguments[1] == true);
    return isIntegerInRange (s, 1, 12);
}

// isDay (STRING s [, BOOLEAN emptyOK])
// 
// 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 defaultEmptyOK;
       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 );
}

// isDate (STRING year, STRING month, STRING day)
//
// isDate returns true if string arguments year, month, and day 
// form a valid date.
// 
function isDate (year, month, day) {
    // catch invalid years (not 2- or 4-digit) and invalid months and days.
    if (! (isYear(year, false) && isMonth(month, false) && isDay(day, false))) return false;

    // Explicitly change type to integer to make code work in both
    // JavaScript 1.1 and JavaScript 1.2.
    var intYear = parseInt(year);
    var intMonth = parseInt(month);
    var intDay = parseInt(day);

    // catch invalid days, except for February
    if (intDay > daysInMonth[intMonth]) return false; 

    if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;

    return true;
}

// 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;
    if (isWhitespace(theField.value)) 
       return warnEmpty (theField, s);
    else return true;
}

// checkStateCode (TEXTFIELD theField [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is a valid U.S. state code.
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)) || (theField.value.length < 2)) 
          return warnInvalid (theField, iStateCode);
       else return true;
    }
}

// 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.
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;
      }
    }
}

// checkCountryCode (TEXTFIELD theField [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is a valid country code code.
function checkCountryCode (theField, emptyOK) {
    if (checkCountryCode.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else
    {  theField.value = theField.value.toUpperCase();
       if (!isCountryCode(theField.value, false)) 
          return warnInvalid (theField, iCountryCode);
       else return true;
    }
}

// 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.
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;
       }
    }
}

// checkEmail (TEXTFIELD theField [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is a valid Email.
function checkEmail (theField, emptyOK) {
    if (checkEmail.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else if (!isEmail(theField.value, false)) 
       return warnInvalid (theField, iEmail);
    else return true;
}

// takes SSN, a string of 9 digits
// and reformats as 123-45-6789
function reformatSSN (SSN) {
    return (reformat (SSN, "", 3, "-", 2, "-", 4))
}

// 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;
       }
    }
}

// Check that string theField.value is a valid Year.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
function checkYear (theField, emptyOK) {
    if (checkYear.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (!isYear(theField.value, false)) 
       return warnInvalid (theField, iYear);
    else return true;
}

// Check that string theField.value is a valid Month.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
function checkMonth (theField, emptyOK) {
    if (checkMonth.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (!isMonth(theField.value, false)) 
       return warnInvalid (theField, iMonth);
    else return true;
}


// Check that string theField.value is a valid Day.
function checkDay (theField, emptyOK) {
    if (checkDay.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (!isDay(theField.value, false)) 
       return warnInvalid (theField, iDay);
    else return true;
}

// checkDate (yearField, monthField, dayField, STRING labelString [, OKtoOmitDay==false])
//
// Check that yearField.value, monthField.value, and dayField.value 
// form a valid date.
function checkDate (yearField, monthField, dayField, labelString, OKtoOmitDay) {
    // Next line is needed on NN3 to avoid "undefined is not a number" error
    // in equality comparison below.
    if (checkDate.arguments.length == 4) OKtoOmitDay = false;
    if (!isYear(yearField.value)) return warnInvalid (yearField, iYear);
    if (!isMonth(monthField.value)) return warnInvalid (monthField, iMonth);
    if ( (OKtoOmitDay == true) && isEmpty(dayField.value) ) return true;
    else if (!isDay(dayField.value)) 
       return warnInvalid (dayField, iDay);
    if (isDate (yearField.value, monthField.value, dayField.value))
       return true;
    alert (iDatePrefix + labelString + iDateSuffix)
    return false
}

// Begin NEW VALIDATE DATE Functions  **********************************************************************************************************

function getvaliddate(objName) { 
var datefield = objName;
if (validdate(objName) == false) {
//datefield.select();
alert("The date is invalid.  Please try again.");
//datefield.focus();
return false;
}
else {
return true;
   }
}

function validdate(objName) {

var strDatestyle = "US"; //United States date style
//var strDatestyle = "EU";  //European date style
var datefield = objName;
var strDate = datefield.value;
var strDateArray;
var strDay;
var strMonth;
var strintDay;
var strintMonth;
var strYear = " ";
var intday;
var intMonth;
var intYear;
var booFound = false;
var strSeparatorArray = new Array("-"," ","/",".");
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";

if ( strDate.length < 1) {
return false;
}
for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
	if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
		strDateArray = strDate.split(strSeparatorArray[intElementNr]);
		if (strDateArray.length != 3) {
			err = 1;
			return false;
		}else {
			strDay = strDateArray[0];
			strMonth = strDateArray[1];
			strYear = strDateArray[2];
		}
		booFound = true;
   }
}
if (booFound == false)  {
	if (strDate.length >5)  {
		strDay = strDate.substr(0, 2);
		strMonth = strDate.substr(2, 2);
		strYear = strDate.substr(4);
   }
}
if (strYear.length == 2) {
strYear = '20' + strYear;
}
if (strYear.length <2) {
strYear = "2003";
}
// US style
if (strDatestyle == "US") {
strTemp = strDay;
strDay = strMonth;
strMonth = strTemp;
}
intday = parseInt(strDay, 10);
if (isNaN(intday)) {
err = 2;
return false;
}
intMonth = parseInt(strMonth, 10);
if (isNaN(intMonth)) {
for (i = 0;i<12;i++) {
if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
intMonth = i+1;
strMonth = strMonthArray[i];
i = 12;
   }
}
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;
}
}
}


// this will fill the month and days lowers than 10 with a cero to standarize the date picture  JDA 02/13/2004.

if (intMonth<10) {
	strintMonth="0" + intMonth;
}
else {
	strintMonth= String (intMonth);
}
if (intday<10) {
	strintDay="0" + intday;
}
else {
	strintDay= String (intday);
}


if (strDatestyle == "US") {
// datefield.value = strMonthArray[intMonth-1] + " " + intday+" " + strYear;
//datefield.value = intMonth + "/" + intday+"/" + strYear;
datefield.value = strintMonth + "/" + strintDay+"/" + strYear;
}
else {
// datefield.value = intday + " " + strMonthArray[intMonth-1] + " " + strYear;
//datefield.value = intday + "/" + intMonth + "/" + strYear;
datefield.value = strintDay + "/" + strintMonth + "/" + 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;
}


// end new validate date functions    **********************************************************************************************************