<!-- Begin to hide script contents from old browsers.

///////////////////////////////////////////////////////////////////////////////
//
// IntToChar
//
//   Return "char" value for the given int.  (Note: A - z only)
//
///////////////////////////////////////////////////////////////////////////////

var CharArray = new Array(
 "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T",
 "U","V","W","X","Y","Z","","","","","","",
 "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t",
 "u","v","w","x","y","z");

function IntToChar(intValue) {

  if ( intValue < 65 || intValue > 122 ) {
    return "";
  }

  var adjIntValue = intValue - 65;

  return CharArray[adjIntValue];
  
}

///////////////////////////////////////////////////////////////////////////////
//
// IsDate
//
//   Check if dVal is a valid date
//
// Valid formats:  MM (or) M / DD (or) D / Y (or) YY (or) YYYY
//                 YY > 50 should be 19YY
//                 YY <= 50 should be 20YY
//
///////////////////////////////////////////////////////////////////////////////

function IsDate(dVal) {
	var strBuffer= new String(dVal);
	var cDelimiter='';
	var strMonth=0, strDay=0, strYear=0;
	var nPos=-1;

	if (IsEmpty(strBuffer))
		return true;
	if (IsWhitespace(strBuffer))
		return false;

	// Get the delimiter used
	if (Occurs('/', strBuffer) == 2)
		cDelimiter = '/';
	else if (Occurs('-', strBuffer) == 2)
		cDelimiter = '-';

	// If no '/' or '-' found return false
	if (cDelimiter == '')
		return false;

	// validate month, date, and year (Y, YY, YYYY are valid year formats)
	nPos = strBuffer.indexOf(cDelimiter);
	strMonth = strBuffer.substring(0, nPos);
	if (strMonth.length > 2 || !IsDigit(strMonth))
		return false;
	strBuffer = strBuffer.substring(nPos+1);
	nPos = strBuffer.indexOf(cDelimiter);
	strDay = strBuffer.substring(0, nPos);
	if (strDay.length > 2 || !IsDigit(strDay))
		return false;
	strBuffer = strBuffer.substring(nPos+1);
	strYear = strBuffer;
	if ((strYear.length > 4) || (strYear.length == 3) || !IsDigit(strYear))
		return false;

	// if YY < 50 then YYYY=20YY, else if YY >= 50 then YYYY=19YY
	var iYear = parseInt(strYear);
	if (iYear < 50)
		strYear = "20" + (strYear < 10 ? '0' + strYear:strYear);
	else if (iYear >= 50 && iYear < 100)
		strYear = "19" + strYear;

	strBuffer = strMonth + cDelimiter + strDay + cDelimiter + strYear;

	// validate date
	var dBuffer = new Date(strBuffer);
	if (dBuffer.getDate() != parseInt(strDay) || 
				dBuffer.getMonth()+1 != parseInt(strMonth) || 
				dBuffer.getFullYear() != parseInt(strYear))
		return false;

	return true;
}

// IsZipcode: check if valid US zip code (##### or #####-####)
function IsZipcode(strZip) {
	var strLeft="", strRight="", strVal = new String(strZip);

	if (IsEmpty(strVal))
		return true;
	if (IsWhitespace(strVal))
		return false;

	if (strVal.length != 5 && strVal.length != 10)
		return false;

	if ((strVal.length == 5) && IsDigit(strVal))
		return true;

	if ((strVal.length == 10) && IsDigit(strVal.substring(0, 5)) && 
						IsDigit(strVal.substring(6)))
		return true;

	return false;
}

// IsDatePart: check if nVal is valid day: 1-31, month:1-12, year:YYYY
function IsDatePart(nVal, strType) {
	var strBuffer = new String(nVal);

	if (IsEmpty(strBuffer) || IsWhitespace(strBuffer))
		return false;
	
	nVal = parseInt(strBuffer);
	if (!IsDigit(nVal))
		return false;

	if ((strType == "Year") && (nVal < 0 || (nVal > 99 && nVal < 1000) || nVal > 9999))
		return false;
	else if ((strType == "Month") && (nVal < 1 || nVal > 12))
		return false;
	else if ((strType == "Day") && (nVal < 1 || nVal > 31))
		return false;

	return true;
}

///////////////////////////////////////////////////////////////////////////////
//
// ValidateField
//
// NOTE: 
//  -- always RemoveSpaces field value before calling any of these functions
//  -- if field is empty, the function call will return true
//
///////////////////////////////////////////////////////////////////////////////

function ValidateField(objFld, strType) {
	objFld.value = RemoveSpaces(objFld.value);
	if (IsEmpty(objFld.value))
		return true;

	// Remove commas from Integer and Float fields
	if ((strType == "Integer") || (strType == "Float"))
		objFld.value = ReplaceAll(objFld.value, ",", "");

	if ((strType == "Digit") && !IsDigit(objFld.value))
	{
		alert("Please enter a response in numerical format (please " + 
			"exclude dollar signs, commas, parenthesis or any other " + 
			"non-numeric symbols).");
		objFld.value = "";
		objFld.focus();
		return false;
	}

	if (strType == "Integer") 
		if (!IsInteger(parseInt(objFld.value)))
		{
			alert("Please enter a response in numerical format (please " + 
				"exclude dollar signs, commas, parenthesis or any other " + 
				"non-numeric symbols).");
			objFld.value = "";
			objFld.focus();
			return false;
		}
		else
			objFld.value = parseInt(objFld.value);

	if (strType == "Float") 
		if (!IsFloat(parseFloat(objFld.value)))
		{
			alert("Please enter a response in numerical format (please " + 
				"exclude dollar signs, commas, parenthesis or any other " + 
				"non-numeric symbols).");
			objFld.value = "";
			objFld.focus();
			return false;
		}
		else
			objFld.value = parseFloat(objFld.value);

	if (strType == "ZIP") 
		if (!IsZipcode(objFld.value))
		{
			alert("Please enter valid zip code value");
			objFld.value = "";
			objFld.focus();
			return false;
		}

	if (strType == "Date") 
		if (!IsDate(objFld.value))
		{
			alert("Please enter valid date value (MM/DD/YYYY)");
			objFld.value = "";
			objFld.focus();
			return false;
		}

	if (strType == "DatePartYear" && ValidateField(objFld, "Digit"))
	{
		if (!IsDatePart(objFld.value, "Year"))
		{
			alert("Please enter valid year value");
			objFld.value = "";
			objFld.focus();
			return false;
		}
		else if (objFld.value < 100)
			objFld.value = (objFld.value < 50 ? 2000:1900) + parseInt(objFld.value);
	}


	return true;
}

///////////////////////////////////////////////////////////////////////////////
//
// ValidateRange
//
//   Check the range of the field value.
//
// Parameters:  objFld - Field reference
//              fLower - Inclusive lower boundary
//              fUpper - Inclusive upper boundary
//
///////////////////////////////////////////////////////////////////////////////

function ValidateRange(objFld, fLower, fUpper) {
  var fVal = 0.0;

  if (IsEmpty(objFld.value)) {
    return true;
  }

  /*
  if (!IsFloat(objFld.value)) {
    return false;
  }
  */

  fVal = parseFloat(objFld.value);

  if ((fVal >= fLower) && (fVal <= fUpper))
    return true;

  if ( fLower == fUpper ) {
    alert("Value can only be " + fUpper);
  } else if ( fUpper < fLower ) {
    alert("There is no valid value that can be specified");
  } else {
    alert("Value needs be between " + fLower + " and " + fUpper);
  }

  objFld.value = "";
  objFld.focus();

  return false;
}

///////////////////////////////////////////////////////////////////////////////
//
// ValidateMinValue
//
//   Check to see if the field value is greater than the minimum value
//
// Parameters:  objFld - Field reference
//              minVal - Minimum value
//
///////////////////////////////////////////////////////////////////////////////

function ValidateMinValue(objFld, minVal) {
  var fVal = 0.0;

  if (IsEmpty(objFld.value))
    return true;
  if (!IsFloat(objFld.value))
    return false;

  fVal = parseFloat(objFld.value);

  if (fVal >= minVal)
    return true;

  alert("Value needs to be greater than or equal to " + minVal);
  objFld.value = "";
  objFld.focus();

  return false;
}

///////////////////////////////////////////////////////////////////////////////
//
// ValidateLength
//
//   Check the length of the field value.
//
// Parameters:  objFld - Field reference
//              strType - field type ( Digit, Char )
//              minLength - Min length
//              maxLength - Max length
//
///////////////////////////////////////////////////////////////////////////////

function ValidateLength(objFld, strType, minLength, maxLength) {

  var strVal = new String(objFld.value);
  var displayType;

  if ( strType == "Digit" ) {
    displayType = "digits";
  }
  else {
    displayType = "characters";
  }

  if (strVal.length < minLength) {
    alert("Minimum number of " + displayType + " required is " + minLength + ".");
    objFld.value = "";
    objFld.focus();
    return false;
  }

  if (strVal.length > maxLength) {
    alert("Maximum number of " + displayType + " allowed is " + maxLength + ".");
    objFld.value = "";
    objFld.focus();
    return false;
  }

  return true;

}


///////////////////////////////////////////////////////////////////////////////
//
// ConvertNumber
//
// The following function is used to convert a value to a number to a specified precision.
//
// Input:  Number or String
//         Precision
//
// Return: Rounded number as a string
//
///////////////////////////////////////////////////////////////////////////////

function ConvertNumber(objFld, precision) {

  if ( IsEmpty( objFld.value ) ) {
    objFld.value = '0.00';
  }

	if (!IsFloat(parseFloat(objFld.value))) {
			objFld.value = "0.00";
	} else {
    objFld.value = FormatNumber( objFld.value, precision );
  }

  return true;
}

///////////////////////////////////////////////////////////////////////////////
//
// ValidateEmail
//
// Email address must be of form a@b.c i.e., 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.
// 
// Parameters:  objFld - Field reference
//
///////////////////////////////////////////////////////////////////////////////

function ValidateEmail(objFld) {

  var strInvalid = "*?#&^~`'\\[]<>;/:\" ";
  var bAliasedEmail = false;
  var strAliasedEmail="";
  var i = 0, bValid = true;

  objFld.value = RemoveSpaces(objFld.value);
  if (IsEmpty(objFld.value))
    return true;

  var strEmail = new String(objFld.value);

  // Assumption: if strEmail contains < and >, Email is between < and >
  if (strEmail.indexOf('<') < strEmail.indexOf('>') && strEmail.indexOf('<') >= 0) {
    bAliasedEmail = true;
    strAliasedEmail = strEmail;
    strEmail = strEmail.substring(strEmail.indexOf('<')+1, 
        strEmail.indexOf('>'));
  }

  if (strEmail.length < 5)  // check the length
    bValid = false;
  else if (strEmail.lastIndexOf("@") <= 0 ||            // check positions of @ and .
           (strEmail.lastIndexOf(".") - strEmail.lastIndexOf("@") <= 1))
    bValid = false;
  else if (Occurs('@', strEmail) > 1) // check if @ occurs more than once
    bValid = false
  else {  // check if any invalid characters present
    for (i = 0; i < strEmail.length; i++) {
      if (strInvalid.indexOf(strEmail.charAt(i)) >= 0) {
        bValid = false;
        break;
      }
    }
  }
  
  if (!bValid) {
    alert("Please enter a valid email address");
    objFld.value = "";
    objFld.focus();
    return bValid;
  }
  if (bAliasedEmail)
    objFld.value = strAliasedEmail;
  else
    objFld.value = strEmail;

  return bValid;

}

///////////////////////////////////////////////////////////////////////////////
//
// ValidateInputType
//
//   Validate input types "Text", "Select", and "Radio"
//
///////////////////////////////////////////////////////////////////////////////

function ValidateInputType(objField,desc,inputType) {
  var strVal;
  strVal = "";

  if (inputType == "Text") {
    strVal = objField.value;
  }
  else if (inputType == "Radio") {
    var iLen = objField.length;
    for (var iEle = 0; iEle < iLen; iEle++)
      if (objField[iEle].checked) {
        strVal = objField[iEle].value;						
        break;					
      }
  }
  else if (inputType == "Select") {
    var iIdx = objField.selectedIndex;
    if (iIdx > -1)
      strVal = objField[iIdx].value;
    else
      strVal = "";
  }

  if (strVal == "") {
    alert("Please enter a value for " + desc);

    if (inputType == "Radio")
      objField[0].focus();
    else
      objField.focus();

    return false;
  }

	return true;
}

///////////////////////////////////////////////////////////////////////////////
//
// ValidateRequired
//
//   Check required fields on the form
//
//   Pre-requisites:  Required array needs to be defined for each form
//                    Required[<field-name-string>] = new Array(<message-string>,
//                                                              <input-type-string>,
//                                                              <focus-on-string>);
//
//                    <message-string>: message to be displayed on mandatory check failure
//                    (NOTE: system dispalyes "<message-string> is mandatory")
//
//                    <input-type-string>: "TEXT", "RADIO", etc
//
//                    <focus-on-string>: name of the field where focus should
//                                       be placed on mandatory check failure.
//                                       if this is "" then focus is place on
//                                       <field-name-string>
//
///////////////////////////////////////////////////////////////////////////////

var Required = new Array();

function ValidateRequired(objForm) {
	for (var iLoop in Required)
	{
		var strVal;
		strVal = "";
		if (Required[iLoop][1] == "Text")
			strVal = eval("objForm." + iLoop + ".value");
		else if (Required[iLoop][1] == "Radio") {
			var oEle = eval("objForm." + iLoop);
			var iLen = oEle.length;
			for (var iEle = 0; iEle < iLen; iEle++)
				if (oEle[iEle].checked)
				{
					strVal = oEle[iEle].value;						
					break;					
				}
		}
		else if (Required[iLoop][1] == "Select") {
			var iIdx = eval("objForm." + iLoop + ".selectedIndex");
			if (iIdx > -1)
				strVal = eval("objForm." + iLoop + "[" + iIdx + "].value");
			else
				strVal = "";
		}
		if (strVal == "")
		{
			alert("Please enter a value for " + Required[iLoop][0]);
			if (Required[iLoop][2] != "")
				eval("objForm." + Required[iLoop][2] + ".focus()");
			else
			{
				if (Required[iLoop][1] == "Radio")
					eval("objForm." + iLoop + "[0].focus()");
				else
					eval("objForm." + iLoop + ".focus()");
			}
			return false;
		}
	}
	return true;
}

///////////////////////////////////////////////////////////////////////////////
//
// ValidateForm
//
//   Validate the form.
//
// NOTE: ValidateSpecial should be defined on each HTML
//       page.  It is where special field validation can be done.
//
///////////////////////////////////////////////////////////////////////////////

function ValidateForm(objForm) {
  var bRetVal;
  bRetVal = ValidateRequired(objForm);
  if (!bRetVal)
    return bRetVal;
  bRetVal = ValidateSpecial(objForm);
  if (!bRetVal)
    return false;

  return true;
}

// End the hiding here. -->
