

/* SIS **************************************************************
Danet GmbH

Complex        : Cargo Management (CM)
Module         : Web
Unit           : /trx/classfncs/classfnc.js

Initial Author : HoW

Unit  Purpose  : Provides javascript functions to check the
                 entries of the form
                 Called by: /trx/rmstatistic/form.php
                            /trx/route_maps/form.php
                 calls    : nothing

---------------------------------------------------------------------
Change History

$Log: .../htdocs/trx/classfncs/classfnc.js $
 *


---------------------------------------------------------------------

************************************************************** SIS */


/*===================================================================
  SourceSafe control information
  static char acRcsId[] =
"$Header: /htdocs/trx/classfncs/classfnc.js     21.11.00 12:45 Ah $";
===================================================================*/

/* global variables: */

/* bitmask values for checks (powers of 2): */
var nCheckNone = 0;
var nCheckMandatory = 1;
var nCheckDate = 2;
var nCheckAwbNumber = 4;
var nCheckAwbNumbers = 8;
var nCheckDigits = 16;

/* checks for forms with PIMA, start and end date: */
/* applies to query 1,3,7,10 */
var aCheckPimaDates = new Array(3);
aCheckPimaDates[0] = nCheckMandatory;               /* PIMA mandatory */
aCheckPimaDates[1] = nCheckMandatory | nCheckDate;  /* start date mandatory */
aCheckPimaDates[2] = nCheckDate;                    /* end date optional */

/* checks for forms with PIMA, msg type, start and end date: */
/* applies to query 14 */
var aCheckPimaMsgtypeDates = new Array(4);
aCheckPimaMsgtypeDates[0] = nCheckMandatory;               /* PIMA mandatory */
aCheckPimaMsgtypeDates[1] = nCheckMandatory;               /* msgtype mandatory */
aCheckPimaMsgtypeDates[2] = nCheckMandatory | nCheckDate;  /* start date mandatory */
aCheckPimaMsgtypeDates[3] = nCheckDate;                    /* end date optional */

/* checks for forms with PIMAs, msg type, logical msg type, start and end date: */
/* applies to query 14 */
var aCheckPimaLogMsgtypeDates = new Array(4);
aCheckPimaLogMsgtypeDates[0] = nCheckMandatory;               /* PIMA 1 mandatory */
aCheckPimaLogMsgtypeDates[1] = nCheckMandatory;               /* PIMA 2 mandatory */
aCheckPimaLogMsgtypeDates[2] = nCheckMandatory;               /* msgtype mandatory */
aCheckPimaLogMsgtypeDates[3] = nCheckMandatory;               /* logical msgtype mandatory */
aCheckPimaLogMsgtypeDates[4] = nCheckMandatory | nCheckDate;  /* start date mandatory */
aCheckPimaLogMsgtypeDates[5] = nCheckDate;                    /* end date optional */


/* checks for forms with 1 AWB: */
/* applies to query 2,12 */
var aCheckAwb = new Array(1);
aCheckAwb[0] = nCheckMandatory | nCheckAwbNumber;  /* AWB mandatory */

/* checks for forms with 1-n AWBs: */
/* applies to query 4,5 */
var aCheckAwbs = new Array(1);
aCheckAwbs[0] = nCheckMandatory | nCheckAwbNumbers; /* AWB mandatory */

/* checks for forms with AWB, PIMA: */
/* applies to query 6 */
var aCheckAwbPima = new Array(2);
aCheckAwbPima[0] = nCheckMandatory | nCheckAwbNumber; /* AWB mandatory */
aCheckAwbPima[1] = nCheckMandatory;                   /* PIMA mandatory */

/* checks for forms with msg key: */
/* applies to query 11 */
var aCheckMsgKey = new Array(1);
/* aCheckMsgKey[0] = nCheckMandatory | nCheckDigits; hm 13.3.05 */ /* msg key mandatory */
aCheckMsgKey[0] = nCheckMandatory; /* msg key mandatory */

/* SIS -------------------------------------------------------------

FUNCTION:
     CheckParams

PURPOSE:
    checks, if parameters of form are correct

DESCRIPTION:


REMARKS:


USAGE:
    in dynamic HTML
     echo "<input ...  onChange="CheckParams(Checks)">";

RETURN VALUE:
    true, if form input is correct, false otherwise

SYNOPSIS:
------------------------------------------------------------------ */

function CheckParams(Checks)
{
  var retval = true;

//alert ("CheckParams");

  for (i=0; i < Checks.length; i++)
  {
//alert ("Check elem " + i + " mask=" + Checks[i]);
    if (Checks[i] & nCheckMandatory)
    {
      retval = CheckMandatory(i);
//alert ("Checked man ret=" + retval);
      if (retval == false)
      {
        break;
      }
    }
    if (Checks[i] & nCheckDate)
    {
      retval = CheckDate(i);
//alert ("Checked date ret=" + retval);
      if (retval == false)
      {
        break;
      }
    }
    if (Checks[i] & nCheckAwbNumber)
    {
      retval = CheckAwbNumber(i, "single");
//alert ("Checked AWB ret=" + retval);
      if (retval == false)
      {
        break;
      }
    }
    if (Checks[i] & nCheckAwbNumbers)
    {
      retval = CheckAwbNumber(i, "multiple");
//alert ("Checked AWBs ret=" + retval);
      if (retval == false)
      {
        break;
      }
    }
    if (Checks[i] & nCheckDigits)
    {
      retval = CheckDigits(i);
//alert ("Checked digits ret=" + retval);
      if (retval == false)
      {
        break;
      }
    }
  }
  return retval;
}

/* SIS -------------------------------------------------------------

FUNCTION:
     CheckPimaDates

PURPOSE:
    checks, if parameters of form with PIMA, start and end date (optional) are correct

DESCRIPTION:


REMARKS:


USAGE:
    in dynamic HTML
     echo "<form ...  onSubmit="CheckPimaDates()">";

RETURN VALUE:
    true, if form input is correct, false otherwise

SYNOPSIS:
------------------------------------------------------------------ */

function CheckPimaDates()
{
//alert ("CheckPimaDates");
  return CheckParams(aCheckPimaDates);
}


/* SIS -------------------------------------------------------------

FUNCTION:
     CheckPimaMsgtypeDates

PURPOSE:
    checks, if parameters of form with PIMA, msgtype, start and end date (optional) are correct

DESCRIPTION:


REMARKS:


USAGE:
    in dynamic HTML
     echo "<form ...  onSubmit="CheckPimaMsgtypeDates()">";

RETURN VALUE:
    true, if form input is correct, false otherwise

SYNOPSIS:
------------------------------------------------------------------ */

function CheckPimaMsgtypeDates()
{
//alert ("CheckPimaMsgtypeDates");
  return CheckParams(aCheckPimaMsgtypeDates);
}

/* SIS -------------------------------------------------------------

FUNCTION:
     CheckPimaLogMsgtypeDates

PURPOSE:
    checks, if parameters of form with PIMAs, msgtype, logical msg type, start and end date (optional) are correct

DESCRIPTION:


REMARKS:


USAGE:
    in dynamic HTML
     echo "<form ...  onSubmit="CheckPimaLogMsgtypeDates()">";

RETURN VALUE:
    true, if form input is correct, false otherwise

SYNOPSIS:
------------------------------------------------------------------ */

function CheckPimaLogMsgtypeDates()
{
//alert ("CheckPimaMsgtypeDates");
  return CheckParams(aCheckPimaLogMsgtypeDates);
}

/* SIS -------------------------------------------------------------

FUNCTION:
     CheckAwb

PURPOSE:
    checks, if parameters of form with AWB are correct

DESCRIPTION:


REMARKS:


USAGE:
    in dynamic HTML
     echo "<form ...  onSubmit="CheckAwb()">";

RETURN VALUE:
    true, if form input is correct, false otherwise

SYNOPSIS:
------------------------------------------------------------------ */

function CheckAwb()
{
//alert ("CheckAwb");
  return CheckParams(aCheckAwb);
}


/* SIS -------------------------------------------------------------

FUNCTION:
     CheckAwbs

PURPOSE:
    checks, if parameters of form with AWBs are correct

DESCRIPTION:


REMARKS:


USAGE:
    in dynamic HTML
     echo "<form ...  onSubmit="CheckAwbs()">";

RETURN VALUE:
    true, if form input is correct, false otherwise

SYNOPSIS:
------------------------------------------------------------------ */

function CheckAwbs()
{
//alert ("CheckAwbs");
  return CheckParams(aCheckAwbs);
}

/* SIS -------------------------------------------------------------

FUNCTION:
     CheckAwbPima

PURPOSE:
    checks, if parameters of form with AWB and PIMA are correct

DESCRIPTION:


REMARKS:


USAGE:
    in dynamic HTML
     echo "<form ...  onSubmit="CheckAwbPima()">";

RETURN VALUE:
    true, if form input is correct, false otherwise

SYNOPSIS:
------------------------------------------------------------------ */

function CheckAwbPima()
{
//alert ("CheckAwbPima");
  return CheckParams(aCheckAwbPima);
}

/* SIS -------------------------------------------------------------

FUNCTION:
     CheckMsgKey

PURPOSE:
    checks, if parameters of form with AWB are correct

DESCRIPTION:


REMARKS:


USAGE:
    in dynamic HTML
     echo "<form ...  onSubmit="CheckMsgKey()">";

RETURN VALUE:
    true, if form input is correct, false otherwise

SYNOPSIS:
------------------------------------------------------------------ */

function CheckMsgKey()
{
//alert ("CheckMsgKey");
  return CheckParams(aCheckMsgKey);
}

/* SIS -------------------------------------------------------------

FUNCTION:
     CheckAwbNumber

PURPOSE:
    checks, if given awb-number is correct

DESCRIPTION:


REMARKS:


USAGE:
    in dynamic HTML
     echo "<input ... onChange="CheckAwbNumber(elem, "single")">";

RETURN VALUE:
    true, if awb number is correct, false otherwise

SYNOPSIS:
------------------------------------------------------------------ */

function CheckAwbNumber(elem, mode)
{
  var retval = false;

//alert ("CheckAwbNumber " + mode + " " + document.forms[0].elements[elem].name + " val=[" + document.forms[0].elements[elem].value + "]");

  if (document.forms[0].elements[elem].value.length == 0)
  {
    /* This is OK */
    retval = true;
  }
  else
  {
    if (mode == "single")
    {
      if (document.forms[0].elements[elem].value.length == 12)
      {
        if (document.forms[0].elements[elem].value.match("[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]"))
        {
          /* This is OK */
          retval = true;
        }
      }
    }
    else
    {
      if (document.forms[0].elements[elem].value.match("^([0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9] *\r*\n*)*$"))
      {
        /* This is OK */
        retval = true;
      }
    }
  }

  if (retval == false)
  {
    alert("Error in AWB number(s)");
    document.forms[0].elements[elem].focus();
  }
  return retval;
}

/* SIS -------------------------------------------------------------

FUNCTION:
     CheckDate

PURPOSE:
    checks, if date was in correct format

DESCRIPTION:


REMARKS:


USAGE:
    in dynamic HTML
     echo "<input ...  onChange="CheckDate(elem)">";

RETURN VALUE:
    true, if date is correct, false otherwise

SYNOPSIS:
------------------------------------------------------------------ */


function CheckDate(elem)
{
  var retval = false;

//alert ("CheckDate " + document.forms[0].elements[elem].name + " val=" + document.forms[0].elements[elem].value);

  if (document.forms[0].elements[elem].value.length == 0)
  {
    /* This is OK */
    retval = true;
  }
  else if (document.forms[0].elements[elem].value.length == 8)
  {
    if (document.forms[0].elements[elem].value.match("[0-9][0-9]-[0-1][0-9]-[0-3][0-9]"))
    {
      /* This is OK */
      retval = true;
    }
  }
  else if (document.forms[0].elements[elem].value.length == 10)
  {
    if (document.forms[0].elements[elem].value.match("[0-9][0-9][0-9][0-9]-[0-1][0-9]-[0-3][0-9]"))
    {
      /* This is OK */
      retval = true;
    }
  }
  else if (document.forms[0].elements[elem].value.length == 17)
  {
    if (document.forms[0].elements[elem].value.match("[0-9][0-9]-[0-1][0-9]-[0-3][0-9] [0-2][0-9]:[0-5][0-9]:[0-5][0-9]"))
    {
      /* This is OK */
      retval = true;
    }
  }
  else if (document.forms[0].elements[elem].value.length == 19)
  {
    if (document.forms[0].elements[elem].value.match("[0-9][0-9][0-9][0-9]-[0-1][0-9]-[0-3][0-9] [0-2][0-9]:[0-5][0-9]:[0-5][0-9]"))
    {
      /* This is OK */
      retval = true;
    }
  }

  if (retval == false)
  {
    alert("Error in date format");
    document.forms[0].elements[elem].focus();
  }
  return retval;
}

/* SIS -------------------------------------------------------------

FUNCTION:
     CheckDigits

PURPOSE:
    checks, if number was in correct format

DESCRIPTION:


REMARKS:


USAGE:
    in dynamic HTML
     echo "<input ...  onChange="CheckDigits(elem)">";

RETURN VALUE:
    true, if date is correct, false otherwise

SYNOPSIS:
------------------------------------------------------------------ */


function CheckDigits(elem)
{
  var retval = false;

//alert ("CheckDigits " + document.forms[0].elements[elem].name + " val=" + document.forms[0].elements[elem].value);

  if (document.forms[0].elements[elem].value.length == 0)
  {
    /* This is OK */
    retval = true;
  }
  else if (document.forms[0].elements[elem].value.match("^[0-9]*$"))
  {
    /* This is OK */
    retval = true;
  }

  if (retval == false)
  {
    alert("Error in digit format");
    document.forms[0].elements[elem].focus();
  }
  return retval;
}

/* SIS -------------------------------------------------------------

FUNCTION:
     CheckMandatory

PURPOSE:
    checks, if parameter is given
DESCRIPTION:


REMARKS:


USAGE:
    in dynamic HTML
     echo "<input ...  onChange="CheckMandatory(elem)">";

RETURN VALUE:
    true, if parameter is given, false otherwise

SYNOPSIS:
------------------------------------------------------------------ */


function CheckMandatory(elem)
{
  var retval = true;
  
//alert ("CheckMandatory " + document.forms[0].elements[elem].name + " val=" + document.forms[0].elements[elem].value);

  if (document.forms[0].elements[elem].value.length == 0)
  {
    /* This is not OK */
    retval = false;
    alert("Mandatory parameter missing");
    document.forms[0].elements[elem].focus();
  }
  return retval;
}


/* old stuff */

/* SIS -------------------------------------------------------------

FUNCTION:
     checkInput

PURPOSE:
    checks entries of form

DESCRIPTION:


REMARKS:


USAGE:
    in dynamic HTML
     <form onSubmit="return CheckInput();" ...>

RETURN VALUE:
    nothing

SYNOPSIS:
------------------------------------------------------------------ */


function CheckInput()
{
  if (document.RouteMap.awb_pre.value == "" ||
      document.RouteMap.awb_post.value == "")
  {
    document.RouteMap.awb_number.value="";
  }
  else
  {
    document.RouteMap.awb_number.value = document.RouteMap.awb_pre.value + "-"
        + document.RouteMap.awb_post.value;
  }
}


/* SIS -------------------------------------------------------------

FUNCTIONS:
     reset_rm, reset_stat

PURPOSE:
    deletes entries of a form onClick 

DESCRIPTION:


REMARKS:


USAGE:
    in dynamic HTML
     echo "<input ... onClick="reset_rm()">";

RETURN VALUE:
    

SYNOPSIS:
------------------------------------------------------------------ */
function reset_rm()
{
  document.forms[0].awb_number.value = "";
  document.forms[0].awb_pre.value = "";
  document.forms[0].awb_post.value = "";
  document.forms[0].discrepant.checked = false;
  document.forms[0].detailed.checked = false;
  document.forms[0].alias_agent.selectedIndex = 0;
  document.forms[0].alias_airline.selectedIndex = 0;
  document.forms[0].shipment_status.selectedIndex = 0;
  document.forms[0].airport_origin.value = "";
  document.forms[0].airport_destination.value = "";
  document.forms[0].import_export.value = "";
  document.forms[0].time_from.value = "";
  document.forms[0].time_to.value = "";
}

function reset_stat()
{
  document.forms[0].report[0].checked = true;
  document.forms[0].report.value = "report";
  document.forms[0].accumulate.checked = false;
  document.forms[0].alias_agent.selectedIndex = 0;
  document.forms[0].alias_airline.selectedIndex = 0;
  document.forms[0].airport_origin.value = "";
  document.forms[0].airport_destination.value = "";
  document.forms[0].time_from.value = "";
  document.forms[0].time_to.value = "";
}
