<!-- Hide from old browsers
function blockError(){return false;}

function FieldNull(inField, inMsg)
{
window.onerror = blockError;
try {
  if (inField.value == "")
  {
  alert(inMsg);
  inField.focus();
  return true;
  }
  return false;
}catch (e)
{return false;}
}



//ID validation
function CheckIdno (inID, inSex, inBdt)
{
  var vID = inID.value;
  inSex = inSex.value;
  inBdt = inBdt.value;
  if (vID.length != 0)
  {
    if (vID.length != 13)
    {
      alert("Identity number validation failed, please supply a valid 13 digit Identity Number.");
      inID.focus();
      inID.select();
      return true;
    }
    var vDay = inBdt.substring(0,inBdt.indexOf("-"));
    var vMonth = inBdt.substring(inBdt.indexOf("-") + 1, inBdt.lastIndexOf("-"));
    if (vMonth == "JAN" ) vMonth="01";
    else if (vMonth == "FEB") vMonth="02";
    else if (vMonth == "MAR") vMonth="03";
    else if (vMonth == "APR") vMonth="04";
    else if (vMonth == "MAY") vMonth="05";
    else if (vMonth == "JUN") vMonth="06";
    else if (vMonth == "JUL") vMonth="07";
    else if (vMonth == "AUG") vMonth="08";
    else if (vMonth == "SEP") vMonth="09";
    else if (vMonth == "OCT") vMonth="10";
    else if (vMonth == "NOV") vMonth="11";
    else if (vMonth == "DEC") vMonth="12";
    var vYear = inBdt.substring(inBdt.lastIndexOf("-") + 1, inBdt.length);
    if (vDay.length == 1) { vDay = "0" + vDay; }
    var vBirthDate = vYear.substring(2,4) + vMonth + vDay;
    if (vID.substring(0,6) != vBirthDate)
    {
      alert("Identity number validation failed, The first 6 digits of the ID number must correspond with the supplied birth date.");
      inID.focus();
      inID.select();
      return true;
    }
    var vGndr = vID.substring(6,10);
    if (((inSex == "M") && (parseInt(vGndr) <= 5000)) || ((inSex == "F") && (parseInt(vGndr) >= 5000)))
    {
      alert("Identity number validation failed, Incorrect gender identification.");
      inID.focus();
      inID.select();
      return true;
    }
    var vOdd = "";
    var vEven = "";
    for(i = 0;i < vID.length - 1;i++)
    {
      if (i%2 == 0) vOdd += vID.charAt(i);
      else vEven += vID.charAt(i);
    }
    vEven = vEven * 2;
    vEven += "";
    var vTotEven = 0;
    for(i = 0;i < vEven.length; i++)
    {
      vTotEven += parseInt(vEven.charAt(i));
    }
    var vTotOdd = 0;
    for(i = 0;i < vOdd.length; i++)
    {
      vTotOdd += parseInt(vOdd.charAt(i));
    }
    var vSum = vTotEven + vTotOdd;
    vSum += "";
    var vCdv = 10 - parseInt(vSum.charAt(1));

    if (vCdv != parseInt(vID.charAt(12)))
    {
      alert("Identity number validation failed, Incorrect CDV check digit.");
      inID.focus();
      inID.select();
      return true;
    }
  }
}
//Matric date validation
function CheckMatdate(inField)
{
  var vFieldVal = inField.value;
  if (vFieldVal.length < 6)
  {
    alert("Matric date validation failed, please supply a valid 6 digit Matriculation Date (YYYYMM).");
    inField.focus();
    inField.select();
    return true;
  }
  if ((parseInt(vFieldVal.substring(0,4)) < 1900) || (parseInt(vFieldVal.substring(0,4)) > 2100))
  {
    alert("Matric date validation failed, The year must fall between 1900 and 2100.");
    inField.focus();
    inField.select();
    return true;
  }
  if ((parseInt(vFieldVal.substring(4,6)) < 1) || (parseInt(vFieldVal.substring(4,6)) > 12))
  {
    alert("Matric date validation failed, The month must fall between 01 and 12.");
    inField.focus();
    inField.select();
    return true;
  }
}


// Leap year test
function isLeapYear (inYear) {
  if (((inYear % 4) == 0) && ((inYear % 100) != 0) || ((inYear % 400) == 0))
  {
  return (true);
  }
  else
  {
  return (false);
  }
}


//Date validations
function DateCheck(inDate, inField) {
   if (inDate == "") { return true; }
   if (inDate.indexOf('-') >= 0)
   {
     var inDay = inDate.substring(0,inDate.indexOf("-"));
     if (inDay.substring(0,1) == "0" && inDay.length > 1)
     {
       inDay = inDay.substring(1,inDay.length);
       inDay = parseInt(inDay);
     }
     else
     {
       inDay = parseInt(inDay);
     }
     if (inDay < 1 || inDay > 31)
     {
       alert("Sorry, Day must be between 1 and 31.");
       inField.focus();
       inField.select();
       return true;
     }
     if (inDate.lastIndexOf("-") == inDate.indexOf("-"))
     {
       alert("Sorry, Invalid date format use DD-MON-YYYY.");
       inField.focus();
       inField.select();
       return true;
     }
     else
     {
       var inMonth = inDate.substring(inDate.indexOf("-") + 1, inDate.lastIndexOf("-"));
       if (inMonth == "JAN" ) inMonth="01";
       else if (inMonth == "FEB") inMonth="02";
       else if (inMonth == "MAR") inMonth="03";
       else if (inMonth == "APR") inMonth="04";
       else if (inMonth == "MAY") inMonth="05";
       else if (inMonth == "JUN") inMonth="06";
       else if (inMonth == "JUL") inMonth="07";
       else if (inMonth == "AUG") inMonth="08";
       else if (inMonth == "SEP") inMonth="09";
       else if (inMonth == "OCT") inMonth="10";
       else if (inMonth == "NOV") inMonth="11";
       else if (inMonth == "DEC") inMonth="12";
       else
       {
         alert("Sorry, Invalid month format used, please use JAN for January, FEB for February etc.");
         inField.focus();
         inField.select();
         return true;
       }
     }
     var now = new Date();
     var strCurrYear = "Sorry, Invalid year format please use YYYY e.g. ";
     strCurrYear = strCurrYear += now.getFullYear()
     var inYear = inDate.substring(inDate.lastIndexOf("-") + 1, inDate.length);
     if (inYear.length != 4)
     {
       alert(strCurrYear);
       inField.focus();
       inField.select();
       return true;
     }
     else if (inYear < 1900 || inYear > 2100)
     {
       alert("Sorry, Valid year range 1900 to 2100");
       inField.focus();
       inField.select();
       return true;
     }
     
//Test days of month
     if (inMonth == "04" || inMonth == "06" || inMonth == "09" || inMonth == "11")
     {
       if (inDay > 30)
       {
         alert("Sorry, Invalid day entered, the month indicates that the day may not be > 30");
         inField.focus();
         inField.select();
         return true;
       }
     }
     else if (inMonth == "02")
     {
       if (isLeapYear(inYear))
       {
          if (inDay > 29)
          {
            alert("Sorry, Invalid day entered, the month indicates that the day may not be > 29");
            inField.focus();
            inField.select();
            return true;
          }
       }
       else
       {
         if (inDay > 28)
         {
            alert("Sorry, Invalid day entered, the month indicates that the day may not be > 28");
            inField.focus();
            inField.select();
            return true;
         }
       }
     }
   }
   else
   {
     alert("Sorry, Invalid date format use DD-MON-YYYY.");
     inField.focus();
     inField.select();
     return true;
   }
}


function JSLReplace(pstr1, pstr2, pstr3) {
   if (pstr1 != "") {
     var rtnstr = "";
     var searchstr = pstr1;
     var addlen = pstr2.length;
     var indx = pstr1.indexOf(pstr2);
     while ((indx != -1) && (searchstr != "")) {
       rtnstr = rtnstr + searchstr.substring(0, indx);
       if (pstr3 != null) {
         rtnstr = rtnstr + pstr3;
       }
       searchstr = searchstr.substring(indx + addlen, searchstr.length);
       if (searchstr != "") {
          indx = searchstr.indexOf(pstr2);
       }
       else { indx = -1; }
     }
     return (rtnstr + searchstr);
   }
   else {
     return "";
   }
}


function JSLGetValue(pctl, ptype, pfalse) {
   var i = 0;
   if (ptype == null) { return pctl.value; }
   if (ptype == "CHECK") {
      if (pctl.checked) { return pctl.value; }
      else { return pfalse; }
   }
   if (ptype == "RADIO") {
      for (i=0;i<pctl.length;i++) {
         if (pctl[i].checked) { return pctl[i].value; }
      }
      return "";
   }
   if (ptype == "LIST") {
      if (pctl.selectedIndex >= 0) {
         if (pctl.options[pctl.selectedIndex].value != "") {
            return pctl.options[pctl.selectedIndex].value;
         }
         else { return pctl.options[pctl.selectedIndex].text; }
      }
      else { return ""; }
   }
}


function JSLStripMask(p_val) {
  if (p_val == "") { return ""; }
  var str = p_val;
  str = JSLReplace(str, " ");
  str = JSLReplace(str, ",");
  str = JSLReplace(str, "$");
  str = JSLReplace(str, "USD");

  if ((str.substring(0, 1) == "<") && (str.substring(str.length -1, str.length) == ">")) {
      str = "-" + str.substring(1, str.length - 1);
  }
  if (str.substring(str.length -1, str.length) == "-") {
    str = "-" + str.substring(0, str.length - 1);
  }
  if (str.substring(str.length -1, str.length) == "+") {
    str = str.substring(0, str.length - 1);
  }
  return str;
}


function JSLToNumber(p_val) {
   var lval = JSLStripMask(p_val);
   if (lval == "") { return ""; }
   else { return parseFloat(lval); }
}


function JSLChkNumScale (pctl, pval, pscale, pmsg) {
  if (pval != "") {
    var PointPos = pval.indexOf(".");
    if (PointPos != -1) {
      var Scale = pval.length - PointPos - 1;
      if (Scale > pscale) {
        alert(pmsg);
        pctl.focus();
        return false;
      }
    }
  }
  return true;
}


function JSLChkNumPrecision(pctl, pval, pprecision, pmsg) {
  if (pval != "") {
    var Prec = 0;
    var PointPos = pval.indexOf(".");
    // If a decimal point was not found
    // validate the number of digits in the whole string
    if (PointPos == -1) {
      Prec = pval.length;
    }
    else {  // Validate the number of digits before the decimal point
      Prec = PointPos;
    }

    if (Prec > pprecision) 
       {
       alert(pmsg);
       pctl.focus();
       return false;
       }
  }
   return true;
}
function JSLMakeUpper(pctl) {
   pctl.value = pctl.value.toUpperCase();
}


function DO_LOV(target) {
   var filter = "";
   var the_pathname = location.pathname;
   var i            = the_pathname.indexOf ('/:');
   var j            = the_pathname.indexOf ('/', ++i);

   if (i != -1)
   {

     // Syntactically incorrect url so it needs to be corrected

     the_pathname = the_pathname.substring (j, the_pathname.length);

   }; // (i != -1)

   frmLOV = open(target +
                 "?Z_FILTER=" + escape(filter) + "&Z_MODE=D" +
                 "&Z_CALLER_URL=" + escape(location.protocol + '//' + location.host + the_pathname + location.search) +
                 "&Z_ISSUE_WAIT=Y",
                 "winLOV", "scrollbars=yes,resizable=yes,width=400,height=400");
   if (frmLOV.opener == null) {
      frmLOV.opener = self;
   }
}

