var strPossibChars = "'- 0123456789ABCDEFGHIJKLMNÑOPQRSTUVWXYZabcdefghijklmnñopqrstuvwxyz";
var strPossibNums = "0123456789";

function trimSpaces(strValue)
{
  while(''+strValue.charAt(0)==' ')
    strValue=strValue.substring(1);
  while(''+strValue.charAt(strValue.length-1)==' ')
    strValue=strValue.substring(0,strValue.length-1);
  return strValue;
}

function checkChars(validChars, controlValue)
{
  var checkOK = validChars;
  var checkStr = controlValue;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    allNum += ch;
  }
  return allValid;
}


function ValidateEntries(theForm) {

  var commCodes = window.parent.parent.CodesFrame;

  theForm.txt_BatchReqNo.value = trimSpaces(theForm.txt_BatchReqNo.value);
  theForm.txt_ReqRefNo.value = trimSpaces(theForm.txt_ReqRefNo.value);
  theForm.txt_AccessID.value = trimSpaces(theForm.txt_AccessID.value);
  theForm.txt_Password.value = trimSpaces(theForm.txt_Password.value);

  if ((theForm.txt_BatchReqNo.value != "" || theForm.txt_ReqRefNo.value != "") && (theForm.txt_AccessID.value != "" || theForm.txt_Password.value != ""))
  {
    alert("Please enter information either in the \"Public Users\" or in the \"Travel Agencies and Partners\" query form.  The user cannot use both forms at the same time.  For more details please read the \"Instructions\" for this page.");
    theForm.txt_BatchReqNo.focus();
    return (false);
  }
  if (theForm.txt_BatchReqNo.value != "" || theForm.txt_ReqRefNo.value != "")
  {
    if (theForm.txt_BatchReqNo.value == "")
    {
      if (theForm.txt_ReqRefNo.value == "")
      {
        alert("Please enter a value in the \"Batch Request Number\" or the \"Request Reference Number\" field.");
        theForm.txt_BatchReqNo.focus();
        return (false);
      }
    }
    if (theForm.txt_BatchReqNo.value != "")
    {
      if (!checkChars("0123456789", theForm.txt_BatchReqNo.value))
      {
        alert("Please enter only digits in the \"Batch Request Number\" field.");
        theForm.txt_BatchReqNo.focus();
        return (false);
      }
    }
    if (theForm.txt_BatchReqNo.value != "")
    {
      if (theForm.txt_BatchReqNo.value.length != 16)
      {
        alert("Please enter 16 digits in the \"Batch Request Number\" field.");
        theForm.txt_BatchReqNo.focus();
        return (false);
      }
    }
    if (theForm.txt_ReqRefNo.value != "")
    {
      if (!checkChars("0123456789", theForm.txt_ReqRefNo.value))
      {
        alert("Please enter only digits in the \"Request Reference Number\" field.");
        theForm.txt_ReqRefNo.focus();
        return (false);
      }
    }
    if (theForm.txt_ReqRefNo.value != "")
    {
      if (theForm.txt_ReqRefNo.value.length != 16)
      {
        if (theForm.txt_ReqRefNo.value.length != 10)
        {
          alert("Invalid input in the \"Request Reference Number\" field.  Please try again.");
          theForm.txt_ReqRefNo.focus();
          return (false);
        }
      }
    }
    if (theForm.txt_BatchReqNo.value != "")
    {
      if (theForm.txt_ReqRefNo.value != "")
      {
        var SeriesNo = theForm.txt_BatchReqNo.value;
        var AllValid = true;
        for (i = 0; i < 10; i++)
        {
          if (SeriesNo.charAt(i) != theForm.txt_ReqRefNo.value.charAt(i))
          {
            AllValid = false;
            break;
          }
          if (i == 10)
          {
            break;
          }
        }  
        if (!AllValid)
        {
          alert("The entered \"Batch Request Number\" and \"Request Reference Number\" have conflicting values.  Please input again.");
          theForm.txt_BatchReqNo.focus();
          return (false);
        }
      }
    }
  }                 


  /* Validation for travel agencies and partners */
  else if (theForm.txt_AccessID.value != "" || theForm.txt_Password.value != "")
  {

    /* Customer Access ID */
    var strObject = theForm.txt_AccessID;
    if (strObject.value == "")
    {
      alert("Please enter a value in the \"Customer Access ID\" field.");
      strObject.focus();
      return (false);
    }

    /* Password */
    var strObject = theForm.txt_Password;
    if (strObject.value == "")
    {
      alert("Please enter a value in the \"Password\" field.");
      strObject.focus();
      return (false);
    }


    /* Request Start Date */

    if (parseInt(theForm.cboFromMonth.options[theForm.cboFromMonth.selectedIndex].value, 10) == 0)
    {
      alert("Please enter a value in the \"Request Start Date: Month\" field.");
      theForm.cboFromMonth.focus();
      return (false);
    }
    if (parseInt(theForm.cboFromDay.options[theForm.cboFromDay.selectedIndex].value, 10) == 0)
    {
      alert("Please enter a value in the \"Request Start Date: Day\" field.");
      theForm.cboFromDay.focus();
      return (false);
    }
    theForm.txtFromYear.value = commCodes.trimSpaces(theForm.txtFromYear.value);
    if (theForm.txtFromYear.value == "")
    {
      alert("Please enter a value in the \"Request Start Date: Year\" field.");
      theForm.txtFromYear.focus();
      return (false);
    }
    if (theForm.txtFromYear.value.length < 3)
    {
      alert("Please enter 4 characters in the \"Request Start Date: Year\" field.");
      theForm.txtFromYear.focus();
      return (false);
    }
    if (theForm.txtFromYear.value.length = 4)
    {
      if (!commCodes.checkChars(strPossibNums, theForm.txtFromYear.value))
      {
        alert("Please enter digits in the \"Request Start Date: Year\" field.");
        theForm.txtFromYear.focus();
        return (false);
      }
    }
    if (commCodes.isDateValid(theForm.cboFromMonth.options[theForm.cboFromMonth.selectedIndex].value,theForm.cboFromDay.options[theForm.cboFromDay.selectedIndex].value,theForm.txtFromYear.value,1)==false)
    {
      return (false);
    }


    /* Request End Date */

    if (parseInt(theForm.cboToMonth.options[theForm.cboToMonth.selectedIndex].value, 10) == 0)
    {
      alert("Please enter a value in the \"Request End Date: Month\" field.");
      theForm.cboToMonth.focus();
      return (false);
    }
    if (parseInt(theForm.cboToDay.options[theForm.cboToDay.selectedIndex].value, 10) == 0)
    {
      alert("Please enter a value in the \"Request End Date: Day\" field.");
      theForm.cboToDay.focus();
      return (false);
    }
    theForm.txtToYear.value = commCodes.trimSpaces(theForm.txtToYear.value);
    if (theForm.txtToYear.value == "")
    {
      alert("Please enter a value in the \"Request End Date: Year\" field.");
      theForm.txtToYear.focus();
      return (false);
    }
    if (theForm.txtToYear.value.length < 3)
    {
      alert("Please enter 4 characters in the \"Request End Date: Year\" field.");
      theForm.txtToYear.focus();
      return (false);
    }
    if (theForm.txtToYear.value.length = 4)
    {
      if (!commCodes.checkChars(strPossibNums, theForm.txtToYear.value))
      {
        alert("Please enter digits in the \"Request End Date: Year\" field.");
        theForm.txtToYear.focus();
        return (false);
      }
    }

    var fromDate = new Date(theForm.txtFromYear.value, theForm.cboFromMonth.options[theForm.cboFromMonth.selectedIndex].value-1, theForm.cboFromDay.options[theForm.cboFromDay.selectedIndex].value);
    var toDate = new Date(theForm.txtToYear.value, theForm.cboToMonth.options[theForm.cboToMonth.selectedIndex].value-1, theForm.cboToDay.options[theForm.cboToDay.selectedIndex].value);

    if (commCodes.isDateValid(theForm.cboToMonth.options[theForm.cboToMonth.selectedIndex].value,theForm.cboToDay.options[theForm.cboToDay.selectedIndex].value,theForm.txtToYear.value,2)==false)
    {
      return (false);
    }

    if (fromDate > toDate)
    {
      alert("\"Request End Date\" should occur after or equal to the \"Request Start Date\".");
      theForm.cboToMonth.focus;
      return(false);
    }
    else
    {
      return (true);
    }
  }
  else
  {
    alert("Please enter information either in the \"Public Users\" or in the \"Travel Agencies and Partners\" query form.  The user cannot use both forms at the same time.  For more details please read the \"Instructions\" for this page.");
    theForm.txt_BatchReqNo.focus();
    return (false);
  }
  return (true);


}





            
