/*==============================================================================

File: utility.js

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11/14/2001 AEB Aldrin Edison Baroi (Creation)
                Utility java script functions.


==============================================================================*/
/*==============================================================================

Function: writeUrl

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12/12/2002 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
function writeUrl(name, url, target)
{
  var str;
  var _target = new String(target);
  str = "<a href='" + url + "'";
  if (_target.length > 0)
  {
    str = str + " target='" + target + "'";
  }
  str = str + ">" + name + "</a>";

  document.write(str);
}
/*==============================================================================

Function: saveFile

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12/13/2002 AEB Aldrin Edison Baroi (Creation)
                * Note this script only works with the
                  JSP file /jsp/download.jsp.

==============================================================================*/
function saveFile(fileName)
{
  var f, t, p, w;
  f = fileName; // s"/html/Department-Publications/mis/directdb.dll";
  t = "";
  p = "height=0,width=0,location=0,menubar=0,resizeabe=0,scrollbars=0,status=0,toolbar=0,visible=0";
  alert(f);
  w = window.open(f,t,p);
  w.blur();
  // rest of the script is in /jsp/download.jsp file
}

/*==============================================================================

Function: writeSaveFileUrl

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12/13/2002 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
function writeSaveFileUrl(name, url, fontName, fontSize, target)
{
  var str;
  var _target = new String(target);
  str = "<font face='" + fontName + "' size='" + fontSize + "'>" +
        "<a href='#' onclick='saveFile(\"" + url + "\")'";
  if (_target.length > 0)
  {
    str = str + " target='" + target + "'";
  }
  str = str + ">" + name + "</a></font>";

  document.write(str);
}
/*==============================================================================

Function: MouseRightClick

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12/13/2002 AEB Aldrin Edison Baroi (Creation)

                Disable Right Click

==============================================================================*/
function __rightClick(e)
{
  var msg = "Right Click is Disabled!\nPlease Click on the Link to Access the Resource.";

  if (document.all)
  {
    if (event.button == 2 || event.button == 3)
    {
      alert(msg);
      return false;
    }
  }

  if (document.layers)
  {
    if (e.which == 2 || e.which == 3)
    {
      alert(msg);
      return false;
    }
  }
}
function __noAction(e)
{
if (navigator.appName == 'Netscape' &&
(e.which == 3 || e.which == 2))
return false;
else if (navigator.appName == 'Microsoft Internet Explorer' &&
(event.button == 2 || event.button == 3)) {
//alert("Sorry, you do not have permission to right click.");
return false;
}
return true;
}

function __disableRightClick()
{
  document.onmousedown = __rightClick;
  document.onmouseup   = __rightClick;
  if (document.layers)
  {
    window.captureEvents(Event.MOUSEDOWN);
    window.captureEvents(Event.MOUSEUP);
  }
  window.onmousedown = __rightClick;
  window.onmouseup   = __rightClick;
}
function __setNoAction()
{
  document.onmousedown = __noAction;
  document.onmouseup   = __noAction;
  if (document.layers)
  {
    window.captureEvents(Event.MOUSEDOWN);
    window.captureEvents(Event.MOUSEUP);
  }
  window.onmousedown = __noAction;
  window.onmouseup   = __noAction;
}

function MouseRightClick()
{
  this.disable = __disableRightClick;
  this.setNoAction = __setNoAction;
}
/*==============================================================================

Function: writeText

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12/20/2002 AEB Aldrin Edison Baroi (Creation)


==============================================================================*/
function writeText(text)
{
  document.write(text);
}

/*==============================================================================

Function: getBrowserType

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
01/02/2003 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
function getBrowserType()
{
  var netscape = "Netscape";
  var microsoft = "Microsoft";
  var unknown = "unknown";
  var appName = new String(navigator.appName);
  var type = null;
  if (appName.indexOf("Microsoft") > -1)
  {
    type = microsoft;
  }
  else if (appName.indexOf("Netscape") > -1)
  {
    type = netscape;
  }
  else
  {
    type = unknown;
  }
  return type;
}
/*==============================================================================

Function: downloadFile

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
01/02/2003 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
function downloadFile(fileName)
{
  var windowTitle, windowAttribute, a1, a2, a3, bt;
  var windowHeight, windowWidth;
  var windowTop, windowLeft;

  windowHeight = 250;
  windowWidth = 250;
  windowTitle = "DownloadFile";

  a1 = "location=0,menubar=0,resizeabe=0,scrollbars=0,status=1,toolbar=0,visible=0";
  a2 = "height=" + windowHeight + ",width=" + windowWidth;

  bt = new String(getBrowserType());

  if (bt == "Netscape")
  {
     windowLeft = window.screenX + ((window.outerWidth - windowWidth) / 2);
     windowTop = window.screenY + ((window.outerHeight - windowHeight) / 2);
     a3 = "screenX=" + windowLeft + ",screenY=" + windowTop;
  }
  else
  {
     windowLeft = (screen.width - windowWidth) / 2;
     windowTop = (screen.height - windowHeight) / 2;
     a3 = "left=" + windowLeft + ",top=" + windowTop;
  }


  windowAttribute = a1 + "," + a2 + "," + a3;

  window.open(fileName,windowTitle,windowAttribute);
}

/*==============================================================================

Function: writeDownloadFileUrl

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
01/02/2003 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
function writeDownloadFileUrl(name, url, fontName, fontSize, target)
{
  var str;
  var _target = new String(target);
  str = // "<font face='" + fontName + "' size='" + fontSize + "'>" +
        "<a href='javascript:downloadFile(\"" + url + "\")'";
  str = str + ">" + name + "</a>"; //</font>";

  document.write(str);
}
/*==============================================================================

Function: isNumber

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
03/06/2003 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
function isNumber(obj)
{
  var numExp = /(^\d+$)|(^\d+\.\d+$)/

  if (numExp.test(obj))
    return true;
  else
    return false;

}
/*==============================================================================

Function: isLeapYear

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
03/06/2003 AEB Aldrin Edison Baroi (Creation)
                Can check only of format mm/dd/yyyy

==============================================================================*/
function isLeapYear(intYear)
{
  if ((intYear % 100 == 0) && (intYear % 400 == 0))
  {
    return true;
  }
  else
  {
    if ((intYear % 4) == 0)
    {
      return true;
    }
  }
  return false;
}

/*==============================================================================

Function: isDate

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
03/06/2003 AEB Aldrin Edison Baroi (Creation)
                Can check only of format mm/dd/yyyy

                *BUG ALERT:
                 THERE IS A BUG IS JAVASCRIPT, IF THE STRING
                 CONTAINS "08" OR "09" THEN <parseInt()>
                 RETURNS ZERO(0), SO CHECKED TO SEE IF THE
                 STRING STARTS WITH "0" AND REMOVED IT.

==============================================================================*/
function isDate(obj)
{
  var dateExp = /^\d{2}\/\d{2}\/\d{4}$/

  if (dateExp.test(obj))
  {
    var daysInMonth = [31,28,31,30,31,30,31,31,30,31,30,31];
    var dateStr     = new String(obj);
    var monthStr    = new String(dateStr.substr(0,2));
    var dayStr      = new String(dateStr.substr(3,2));
    var yearStr     = new String(dateStr.substr(6,4));

    // THERE IS A BUG IS JAVASCRIPT, IF THE STRING CONTAINS
    // "08" OR "09" THEN <parseInt()> RETURNS ZERO(0), SO
    // CHECKING TO SEE IF THE STRING STARTS WITH "0" AND
    // REMOVED IT.
    if (monthStr.charAt(0) == '0')
      monthStr = monthStr.substr(1, (monthStr.length -1));
    if (dayStr.charAt(0) == '0')
      dayStr = dayStr.substr(1, (dayStr.length -1));

    var month       = parseInt(monthStr);
    var day         = parseInt(dayStr);
    var year        = parseInt(yearStr);

    if (!(day >= 1 && day <= daysInMonth[month -1]))
    {
       // if month is February, check for leapyear
       if (month == 2 && day == 29 && isLeapYear(year))
         return true;
       else
         return false;
    }
    return true;
  }
  else
    return false;

}
/*==============================================================================

Function: downloadFile

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
03/27/2003 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
function uploadFile(fileName)
{
  var windowTitle, windowAttribute, a1, a2, a3, bt;
  var windowHeight, windowWidth;
  var windowTop, windowLeft;

  windowHeight = 200;
  windowWidth  = 450;
  windowTitle  = "UploadFile";

  a1 = "location=0,menubar=0,resizeabe=0,scrollbars=0,status=1,toolbar=0,visible=0";
  a2 = "height=" + windowHeight + ",width=" + windowWidth;

  bt = new String(getBrowserType());

  if (bt == "Netscape")
  {
     windowLeft = window.screenX + ((window.outerWidth - windowWidth) / 2);
     windowTop = window.screenY + ((window.outerHeight - windowHeight) / 2);
     a3 = "screenX=" + windowLeft + ",screenY=" + windowTop;
  }
  else
  {
     windowLeft = (screen.width - windowWidth) / 2;
     windowTop = (screen.height - windowHeight) / 2;
     a3 = "left=" + windowLeft + ",top=" + windowTop;
  }


  windowAttribute = a1 + "," + a2 + "," + a3;

  window.open(fileName,windowTitle,windowAttribute);
}
/*==============================================================================

Function: URLEncode

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
07/24/2003 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
function URLEncode(sStr)
{
    return escape(sStr).replace(/\+/g, '%2C').replace(/\"/g,'%22').replace(/\'/g, '%27');
}
/*==============================================================================

Function: trim

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
07/28/2003 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
String.prototype.trim = function()
{
   return this.replace(/^\s+/,'').replace(/\s+$/,'');
}
/*==============================================================================

Function: ltrim

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12/09/2003 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
String.prototype.ltrim = function()
{
   return this.replace(/^\s+/,'');
}
/*==============================================================================

Function: rtrim

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12/09/2003 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
String.prototype.rtrim = function()
{
   return this.replace(/\s+$/,'');
}
/*==============================================================================

Function: today

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
07/24/2003 AEB Aldrin Edison Baroi (Creation)
12/04/2003 AEB Updated to add (1) to month, since getMonth()
                return 0 for January, 1 for February, etc.

==============================================================================*/
function today()
{
  var dt = new Date();
  var m = dt.getMonth() + 1;
  var d = dt.getDate();
  var y = dt.getYear();
  if (m < 10) m = '0' + m;
  if (d < 10) d = '0' + d;
  var ds = m + '/' + d + '/' + y;
  return ds;
}
/*==============================================================================

Function: js_today

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
06/04/2004 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
function js_today()
{
  var dt = new Date();
  var m = dt.getMonth() + 1;
  var d = dt.getDate();
  var y = dt.getYear();
  if (m < 10) m = '0' + m;
  if (d < 10) d = '0' + d;
  var ds = m + '/' + d + '/' + y;
  document.write(ds);
}
/*==============================================================================

Function: Hashtable

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11/05/2003 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
function Hashtable()
{
  this.hashtable = new Array();
}

Hashtable.prototype.clear = function()
{
  this.hashtable = new Array();
}

Hashtable.prototype.containsKey = function(key)
{
  var exists = false;
  for (var i in this.hashtable)
  {
    if (i == key && this.hashtable[i] != null)
    {
      exists = true;
      break;
    }
  }
  return exists;
}

Hashtable.prototype.containsValue = function(value)
{
    var contains = false;
    if (value != null)
    {
        for (var i in this.hashtable)
        {
            if (this.hashtable[i] == value)
            {
                contains = true;
                break;
            }
        }
    }
    return contains;
}

Hashtable.prototype.get = function(key)
{
    return this.hashtable[key];
}

Hashtable.prototype.isEmpty = function()
{
    return (parseInt(this.size()) == 0) ? true : false;
}

Hashtable.prototype.keys = function()
{
    var keys = new Array();
    for (var i in this.hashtable)
    {
        if (this.hashtable[i] != null)
            keys.push(i);
    }
    return keys;
}

Hashtable.prototype.put = function(key, value)
{
    if (key == null || value == null) {
        throw "NullPointerException {" + key + "},{" + value + "}";
    }else{
        this.hashtable[key] = value;
    }
}

Hashtable.prototype.remove = function(key)
{
    var rtn = this.hashtable[key];
    this.hashtable[key] = null;
    return rtn;
}

Hashtable.prototype.size = function()
{
    var size = 0;
    for (var i in this.hashtable) {
        if (this.hashtable[i] != null)
            size ++;
    }
    return size;
}

Hashtable.prototype.toString = function()
{
    var result = "";
    for (var i in this.hashtable)
    {
        if (this.hashtable[i] != null)
            result += "{" + i + "},{" + this.hashtable[i] + "}\n";
    }
    return result;
}

Hashtable.prototype.values = function()
{
    var values = new Array();
    for (var i in this.hashtable)
    {
        if (this.hashtable[i] != null)
            values.push(this.hashtable[i]);
    }
    return values;
}
/*==============================================================================

Function: XML

@TODO   : Update XMLFactory for cross browser functionality.

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11/05/2003 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
function XMLFactory()
{
}
XMLFactory.create = function()
{
  var factory = new ActiveXObject("Microsoft.XMLDOM");
  return factory;
}
function XML()
{
  this.xmlData;
  this.xmlFile;
  this.xmlDoc;
  this.rootNode;
}
XML.prototype.createDocumentFromString = function(xmlDataStr)
{
  this.xmlDoc = XMLFactory.create();
  this.xmlDoc.async = false;
  this.xmlDoc.loadXML(xmlDataStr);
  this.rootNode = this.xmlDoc.documentElement;
}

XML.prototype.createDocumentFromFile = function(xmlFile)
{
  this.xmlDoc = XMLFactory.create();
  this.xmlDoc.async = false;
  this.xmlDoc.load(xmlFile);
  this.rootNode = this.xmlDoc.documentElement;
}

XML.prototype.getDoc = function()
{
  return this.xmlDoc;
}

XML.prototype.parse = function(ht, node)
{
  var nodeName;
  var nodeValue;
  if (node)
  {
    nodeName = node.nodeName;
    if (node.childNodes.length > 0)
    {
      var i = 0;
      for(i = 0; i < node.childNodes.length; i++)
      {
        var childNode = node.childNodes[i];
        var nodeType = childNode.nodeType;
        if (nodeType == 3)
        {
          nodeValue = childNode.nodeValue;
          ht.put(nodeName, nodeValue);
        }
        else
          this.parse(ht, childNode);
      }
    }
  }
}

XML.prototype.getHashedData = function()
{
  var ht = new Hashtable();
  this.parse(ht, this.rootNode);
  return ht;
}
/*==============================================================================

Function: popup_openWindow
           popup_getTargetName
           popup_setValue
           popup_returnValue

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10/30/2003 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
var __targetName;

/*

Implement this callback function where popup
window is opened for input

function popup_setValue(value)
{
  if (popup_getTargetName() == "[TARGET NAME SPECIFIED IN popup_openWindow()]")
    [YOUR TARGET INPUT FIELD] = value;
}

Example:
function popup_setValue(value)
{
  var targetName = popup_TragetName();
  if (targetname == "NAME") document.MyForm.name.value = value;
  if (targetName == "AGE")  document.MyForm.age.value = value;
}


Implement this function in the popped up window.

function popup_setInitValues(xmlDataStr)
{
  var xml = new XML();
  xml.createDocumentFromString(xmlDataStr);
  var ht = xml.getHashedData();
  .......
}

Example:
function popup_setInitValues(xmlDataStr)
{
  var xml = new XML();
  xml.createDocumentFromString(xmlDataStr);
  var ht = xml.getHashedData();
  var custCode = ht.get("custCode");
  var custName = ht.get("custName");
  if (custCode) document.orderForm.custCode.value = value;
  if (custName) document.orderForm.custName.value = value;
}

*/
/*------------------------------------------------------------

Functio: popup_getTargetName

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10/30/2003 AEB Aldrin Edison Baroi (Creation)

------------------------------------------------------------*/
function popup_getTargetName()
{
  return __targetName;
}
/*------------------------------------------------------------

Functio: popup_getTargetName

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10/30/2003 AEB Aldrin Edison Baroi (Creation)

------------------------------------------------------------*/

function popup_returnValue(value)
{
  window.opener.popup_setValue(value);
  window.close();
}
/*------------------------------------------------------------

Functio: popup_getTargetName

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10/30/2003 AEB Aldrin Edison Baroi (Creation)

------------------------------------------------------------*/
var __win;

function popup_openWindow(url, targetName, initValuesXML, width, height)
{
  var popupSize=",width=" + width + ",height=" + height;
  var popupPos = "";
  var winW, winH, top, left;
  __targetName = targetName;
  var bt = new String(getBrowserType());
  var statusBar = arguments[5];
  if (statusBar != false) statusBar = true;
  if (bt == "Microsoft")
  {
    if (window.top)
    {
      //winW = window.top.screenX;
      //winH = window.top.screenY;
      winW = window.top.document.body.offsetWidth;
      winH = window.top.document.body.offsetHeight;
    }
    else
    {
      //winW = window.screenX;
      //winH = window.screenY;
      winW = window.document.body.offsetWidth;
      winH = window.document.body.offsetHeight;
    }
    top = 50 + parseInt((winH - height) / 2);
    left = parseInt((winW - width) / 2);
    popupPos = ",top="  + top + ",left=" + left;
  }
  else if (bt == "NS")
  {
    if (window.top)
    {
      winW = window.top.innerWidth;
      winH = window.top.innerHeight;
    }
    else
    {
      winW = window.innerWidth;
      winH = window.innerHeight;
    }
    top = 50 + parseInt((winH - height) / 2);
    left = parseInt((winW - width) / 2);
    popupPos = ",top="  + top + ",left=" + left;
  }
  else
  {
    popupPos = "";
  }
  var winProp = "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,resizable=no,copyhistory=no";
  if (statusBar == true) winProp = winProp + ",status=yes";
  else winProp = winProp + ",status=no";
  winProp = winProp + popupSize + popupPos;
  var msg = "winW=" + winW + " winH=" + winH + " // " + winProp;
  var xmlDataStr = new String(initValuesXML);
  if (__win)
  {
    try { __win.close(); }catch(e) {}
  }
  __win = window.open("", "POPUPINPUT", winProp);
  sleep(1000);
  __win.location = url;
  __win.opener = window;
  __win.focus();
  setTimeout("__popup_setInitValues('" + xmlDataStr + "');",200);
}

function __popup_closeWindow()
{
  window.close();
}

function __popup_startWindowCloseTimer(sec)
{
  sec = sec * 1000;
  setTimeout("__popup_closeWindow()", sec);
}

function __popup_setInitValues(xmlDataStr)
{
  try
  {
    __win.popup_setInitValues(xmlDataStr);
    __win.__popup_startWindowCloseTimer(60);
  }
  catch(e)
  {
    setTimeout("__popup_setInitValues('" + xmlDataStr + "');",200);
  }
}

function popup_setCommand()
{
  try
  {
    var e1 = document.getElementsByName('command')
    if (e1)
    {
      var command = e1[0];
      if (command)
      {
         var e2 = window.opener.document.getElementsByName('command');
         if (e2)
         {
           var openerCommand = e2[0];
           if (openerCommand)
           {
             command.value = openerCommand.value;
           }
         }
      }
    }
  }
  catch(e) {}
}

/*------------------------------------------------------------

  __sleepHelper

------------------------------------------------------------*/
function __sleepHelper()
{
  // dummy function
  var doNothing;
  doNothing = true;
}
function sleep(millisec)
{
  setTimeout("__sleepHelper()", millisec)
}
/*==============================================================================

Function: EmailAddress

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11/25/2003 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
function EmailAddress(emailAddress)
{
  this.emailAddress = new String(emailAddress);
}

EmailAddress.prototype.isValid = function()
{
 alert(this.emailAddress);
  var emailReg = new RegExp("^[a-z|A-Z|0-9]([a-z|A-Z|0-9|_|.]*[-]*)*[@][a-z|A-Z|0-9]+(([a-z|A-Z|0-9]*[-][a-z|A-Z|0-9]+)*|([a-z|A-Z|0-9]*[.][a-z|A-Z|0-9]+)*)*[.]?$");
  if (emailReg.test(this.emailAddress))
  {
  return true;
  }
  else
  {
  return false;
  }
}
EmailAddress.prototype.getAddress = function()
{
  return this.emailAddress;
}
/*==============================================================================

Function: blink

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11/26/2003 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
var __blinkerFlag = 0;
var __blinkTimeout = null;
var __blinkIdName = "";
var __blinkHTML = ""

function blink(idName)
{
  __blinkIdName = idName;
  if (__blinkTimeout)
  {
    clearTimeout(__blinkTimeout);
  }
  var blinkElement = document.getElementById(idName);
  if (__blinkerFlag == 0)
  {
    blinkElement.style.visibility = "hidden";
    __blinkerFlag = 1;
  }
  else
  {
    blinkElement.style.visibility = "visible";
    __blinkerFlag = 0;
  }
  __blinkTimeout = setTimeout("blink('" + idName + "')", 500);
}
/*==============================================================================

Function: blink_start, blink_stop

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12/04/2003 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
function blink_start(idName)
{
  blink(idName);
}
function blink_stop()
{
  try
  {
    clearTimeout(__blinkTimeout);
    var blinkElement = document.getElementById(__blinkIdName);
    blinkElement.style.visibility = "visible";
  }
  catch(e)
  {
  }
}
/*==============================================================================

Function: formatDate

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11/26/2003 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
function formatDate()
{
   var dbDateStr = arguments[0] ? arguments[0] : null;
   if (dbDateStr == null)
   {
     return "";
   }
   dbDateStr = new String(dbDateStr);
   var formatedDateStr = dbDateStr.substr(5,2) + "/" + dbDateStr.substr(8,2) + "/" + dbDateStr.substr(0,4);
   return formatedDateStr;
}
/*==============================================================================

Function: ZipCode

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12/09/2003 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
function ZipCode(zipCode)
{
  this.zipCode = zipCode || "";
}
ZipCode.prototype.setCode = function(zipCode)
{
  this.zipCode = zipCode || "";
}
ZipCode.prototype.getCode = function()
{
  return this.zipCode;
}
ZipCode.prototype.isValid = function()
{
  var zipRE = /^\d{5}$|^\d{5}-\d{4}$|^[a-zA-Z][0-9][a-zA-Z]\s?[0-9][a-zA-Z][0-9]$/; //added for Canada
  if (zipRE.test(this.zipCode))
    return true;
  else
  {
    // Mexican Zip
    zipRE = /^([c|C][p|P])\s\d{5}$|^([c|C][p|P])\s\d{5}-\d{4}$/;
    if (zipRE.test(this.zipCode))
      return true;
    else
      return false;
  }
}
/*==============================================================================

Function: Window

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
01/06/2004 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
function Window()
{
  if (window.top)
  {
    this.winW = window.top.document.body.offsetWidth;
    this.winH = window.top.document.body.offsetHeight;
  }
  else
  {
    this.winW = window.document.body.offsetWidth;
    this.winH = window.document.body.offsetHeight;
  }
}
Window.prototype.getHeight = function()
{
  return this.winH;
}
Window.prototype.getWidth = function()
{
  return this.winW;
}
/*==============================================================================

Function: FormMode

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
04/29/2004 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
function FormMode()
{
  this.inputModes = new Array();
  this.inputModes[0] = "Add";
  this.inputModes[1] = "Update";
  this.inputModes[2] = "Delete";
  this.inputModes[3] = "Query";
  this.inputModes[4] = "View";
  this.inputModes[5] = "NotSet";
  this.inputModes[6] = "AddItem";
  this.mode = this.inputModes[6];
}
FormMode.prototype.setAdd = function()
{
  this.mode = this.inputModes[0];
}
FormMode.prototype.setUpdate = function()
{
  this.mode = this.inputModes[1];
}
FormMode.prototype.setDelete = function()
{
  this.mode = this.inputModes[2];
}
FormMode.prototype.setQuery = function()
{
  this.mode = this.inputModes[3];
}
FormMode.prototype.setView = function()
{
  this.mode = this.inputModes[4];
}
FormMode.prototype.setNotSet = function()
{
  this.mode = this.inputModes[5];
}
FormMode.prototype.setAddItem = function()
{
  this.mode = this.inputModes[6];
}
FormMode.prototype.isAdd = function()
{
  if (this.mode == this.inputModes[0])
    return true;
  else
    return false;
}
FormMode.prototype.isUpdate = function()
{
  if (this.mode == this.inputModes[1])
    return true;
  else
    return false;
}
FormMode.prototype.isDelete = function()
{
  if (this.mode == this.inputModes[2])
    return true;
  else
    return false;
}
FormMode.prototype.isQuery = function()
{
  if (this.mode == this.inputModes[3])
    return true;
  else
    return false;
}
FormMode.prototype.isView = function()
{
  if (this.mode == this.inputModes[4])
    return true;
  else
    return false;
}
FormMode.prototype.isNotSet = function()
{
  if (this.mode == this.inputModes[5])
    return true;
  else
    return false;
}
FormMode.prototype.isAddItem = function()
{
  if (this.mode == this.inputModes[6])
    return true;
  else
    return false;
}
FormMode.prototype.toString = function()
{
  return this.mode;
}
/*==============================================================================

Function: Form

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10/20/2003 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
function Form(form)
{
  this.form = form;
  this.elements = new Hashtable();
  this.backgrounds = new Hashtable();
  this.mode = new FormMode();

  for(var i = 0; i < this.form.elements.length; i++)
  {
    var e = this.form.elements[i];
    var b = e.style.backgroundColor;
    this.elements.put(e.name, e);
    this.backgrounds.put(e.name, b);
  }
}
Form.prototype.disableAll = function()
{
  for(var i = 0; i < this.form.elements.length; i++)
  {
    var e  = this.form.elements[i];
    e.disabled = true;
    e.style.backgroundColor = "#DDDDDD";
  }
}
Form.prototype.enableAll = function()
{
  for(var i = 0; i < this.form.elements.length; i++)
  {
    var e  = this.form.elements[i];
    var b = this.backgrounds.get(e.name);
    e.disabled = false;
    e.style.backgroundColor = b;
  }
}
Form.prototype.enable = function(elementName)
{
  if (this.elements.containsKey(elementName))
  {
    var e = this.elements.get(elementName);
    var b = this.backgrounds.get(e.name);
    e.disabled = false;
    e.style.backgroundColor = b;
  }
}
Form.prototype.disable = function(elementName)
{
  if (this.elements.containsKey(elementName))
  {
    var e = this.elements.get(elementName);
    e.disabled = true;
    e.style.backgroundColor = "#DDDDDD";
  }
}
Form.prototype.setInputTypeUpperCase = function(elementName)
{
  if (this.elements.containsKey(elementName))
  {
    var e = this.elements.get(elementName);
    e.style.textTransform = "uppercase";
  }
}
Form.prototype.setMaxLength = function(elementName, maxLength)
{
  if (this.elements.containsKey(elementName))
  {
    var e = this.elements.get(elementName);
    e.maxLength = maxLength;
  }
}
Form.prototype.setValue = function(elementName, elementValue)
{
  if (this.elements.containsKey(elementName))
  {
    var e = this.elements.get(elementName);
    e.value = elementValue;
  }
}
Form.prototype.getValue = function(elementName)
{
  if (this.elements.containsKey(elementName))
  {
    var e = this.elements.get(elementName);
    return e.value;
  }
  else
  {
    return "";
  }
}
Form.prototype.getMode = function()
{
  return this.mode;
}
Form.prototype.submit = function()
{
  this.form.submit();
}
Form.prototype.reset = function()
{
  this.form.reset();
}
Form.prototype.setFocus = function(elementName)
{
  if (this.elements.containsKey(elementName))
  {
    var e = this.elements.get(elementName);
    e.focus();
  }
}
/*==============================================================================

Function: Button

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10/20/2003 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
var buttons = new Hashtable();
function Button(id)
{
  this.id = id;
  this.buttonElement = document.getElementById(id);
  this.enabled = true;
}
Button.prototype.getId = function()
{
  return this.id;
}
Button.prototype.isEnabled = function()
{
  return ((this.enabled == true) ? true : false);
}
Button.prototype.setEnabled = function(trueFalse)
{
  this.buttonElement = document.getElementById(this.id);
  if (trueFalse == true)
  {

    this.buttonElement.cssText = "";
    this.buttonElement.className = "button";
  }
  else
  {
    this.buttonElement.cssText = "";
    this.buttonElement.className = "button_disabled";
  }
  this.enabled = trueFalse;
}
Button.prototype.enable = function()
{
  this.buttonElement = document.getElementById(this.id);
  this.buttonElement.cssText = "";
  this.buttonElement.className = "button";
  this.enabled = true;
}
Button.prototype.disable = function()
{
  this.buttonElement = document.getElementById(this.id);
  this.buttonElement.cssText = "";
  this.buttonElement.className = "button_disabled";
  this.enabled = false;
}
Button.prototype.setLabel = function(label)
{
  this.buttonElement = document.getElementById(this.id);
  //this.buttonElement.childNodes.item(0).innerHTML = label;
  this.buttonElement.innerHTML = label;
}
Button.prototype.registerOnClick = function(onClick_call_back_function)
{
  this.onClick = onClick_call_back_function;
}
Button.prototype.onClick = function()
{
  if (this.enabled == true)
  {
    this.onClick();
  }
}
function processOnClick(obj)
{
  try
  {
    var id = obj.id;
    var button = buttons.get(id);
    if (button.isEnabled() == true)
    {
      button.onClick(id);
    }
  }
  catch(e) { }
}
/*==============================================================================

Function: HelpText

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
04/28/2004 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
var __helpText;
var __displayContainerId;
var __infoIcon = "/images/info_3.gif";
function HelpText(displayContainerId)
{
  __displayContainerId = displayContainerId;
  __helpText = new Hashtable();
}
HelpText.prototype.add = function(id, text)
{
  try
  {
    __helpText.put(id, text);
    var e = document.getElementById(id);
    e.onmouseover = this.show;
    e.onmouseout  = this.clear;
  }
  catch(e)
  {
    // id does not exist on the page
  }
}
HelpText.prototype.show = function()
{
  var text = __helpText.get(window.event.srcElement.id);
  var html =  "<table bgColor='#DDDDDD'>" +
              "  <tr>"    +
              "    <td>"  +
              "      <img src='" + __infoIcon + "'/>" +
              "    </td>" +
              "    <td>"  +
                     text +
              "    </td>" +
              "  </tr>"   +
              "</table>";
  var f = document.getElementById(__displayContainerId);
  f.innerHTML = html;
}
HelpText.prototype.clear = function()
{
  var f = document.getElementById(__displayContainerId);
  f.innerHTML = "";
}
/*==============================================================================

Function: HelpText2

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11/15/2004 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
var __helpText2;
var __displayContainerId2;
var __infoIcon2 = "/images/info_3.gif";

function HelpText2(displayContainerId2)
{
  __displayContainerId2 = displayContainerId2;
  __helpText2 = new Hashtable();
}
HelpText2.prototype.add = function(id, text)
{
  try
  {
    __helpText2.put(id, text);
    var e = document.getElementById(id);
    e.onmouseover = this.show;
    e.onmouseout  = this.clear;
  }
  catch(e)
  {
    // id does not exist on the page
  }
}
HelpText2.prototype.show = function()
{
  var text = __helpText2.get(window.event.srcElement.id);
  var html =  "<table class='TableElement' bgColor='#DDDDDD'>" +
              "  <tr>"    +
              "    <td class='Label'>"  +
              //"      <img src='" + __infoIcon2 + "' height='6' align='center'/>" +
              "    </td>" +
              "    <td class='Label'>"  +
                     text +
              "    </td>" +
              "  </tr>"   +
              "</table>";
  var f = document.getElementById(__displayContainerId2);
  f.innerHTML = html;
}
HelpText2.prototype.clear = function()
{
  var f = document.getElementById(__displayContainerId2);
  var html =  "<table class='TableElement' bgColor='#DDDDDD'>" +
              "  <tr>"    +
              "    <td class='Label'>&#160;"  +
              "    </td>" +
              "    <td class='Label'>&#160;"  +
              "    </td>" +
              "  </tr>"   +
              "</table>";
  f.innerHTML = html;
}
/*==============================================================================

Function: HelpText3

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11/15/2004 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
function HelpText3()
{
  var helpText;
  var displayContainerId;
  var helpIcon;

  // DEFAULTS
  var defaultDisplayContainer = "HELP";
  var defaultHelpIcon = "/images/info_4.gif";

  displayContainerId = arguments[0] ? arguments[0] : defaultDisplayContainer;
  helpIcon = null; //arguments[1] ? arguments[1] : defaultHelpIcon;

  helpText = new Hashtable();
  var displayContainer = document.getElementById(displayContainerId);

  this.add = function(id, text)
  {
    try
    {
      helpText.put(id, text);
      var e = document.getElementById(id);
      e.onmouseover = this.show;
      e.onmouseout  = this.clear;
    }
    catch(e)
    {
      // id does not exist on the page
    }
  }

  this.show = function()
  {
    var text = helpText.get(window.event.srcElement.id);
    html = "<span style='background:#DDDDDD;width:100%'>";
    if (helpIcon)
    {
      html = "<img src='" + helpIcon + "' align='center'/>";
    }
    html += text + "</span>";
    displayContainer.innerHTML = html;
  }

  this.clear = function()
  {
    var html = "<span style='background:#DDDDDD;width:100%'>" +
                 "&nbsp;" +
               "</span>";
    displayContainer.innerHTML = html;
  }

  this.clear();
}

/*==============================================================================

Function: confirmDeleteAction

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
04/29/2004 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
function confirmDeleteAction()
{
  var _delete = confirm("Are you sure you want to delete this record?");
  if (_delete == false)
  {
    return false;
  }
  else
  {
    return true;
  }
}
/*==============================================================================

Function: Element

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
05/29/2004 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
function Element(id)
{
  this.id = id;
  this.element = document.getElementById(id);
}
Element.prototype.getLeft = function()
{
  var obj = this.element;
  var curleft = 0;
  if (obj.offsetParent)
  {
    while (obj.offsetParent)
    {
      curleft += obj.offsetLeft
      obj = obj.offsetParent;
    }
  }
  else if (obj.x)
    curleft += obj.x;
  return curleft;
}
Element.prototype.setLeft = function(left)
{
  this.element.style.left = left;
}
Element.prototype.getTop = function()
{
  var obj = this.element;
  	 var curtop = 0;
	 if (obj.offsetParent)
	 {
	   while (obj.offsetParent)
	   {
	     curtop += obj.offsetTop
	     obj = obj.offsetParent;
	   }
	 }
	 else if (obj.y)
	   curtop += obj.y;
	 return curtop;
}
Element.prototype.setTop = function(top)
{
  this.element.style.top = top;
}
Element.prototype.getBottom = function()
{
  return (this.getTop() + this.getHeight());
}
Element.prototype.getHeight = function()
{
  return (this.element.offsetHeight);
}
Element.prototype.getWidth = function()
{
  return (this.element.offsetWidth);
}
Element.prototype.getRight = function()
{
  return (this.getLeft() + this.getWidth());
}
Element.prototype.setVisible = function()
{
  this.element.style.visibility="visible";
}
Element.prototype.setHidden = function()
{
  this.element.style.visibility="hidden";
}
Element.prototype.setBackgroundColor = function(color)
{
  this.element.style.backgroundColor = color;
}
Element.prototype.getObject = function()
{
  return this.element;
}
/*==============================================================================

Function: popupCalendar

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
08/11/2004 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
var __popupCalendarTargetId = null;
function popupCalendar(id)
{
  __popupCalendarTargetId = id;
  popup_openWindow("/js/popupCalendar.html",'MY_DATE','',180,154,false);
}
function popupCalendarSetDate(date)
{
  var e = document.getElementById(__popupCalendarTargetId);
  e.value = date;
}
/*==============================================================================

Function: Popup

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
01/19/2005 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
function Popup()
{
  this.id = arguments[0];
  this.url = arguments[1];
  this.width = arguments[2] ? arguments[2] : 550;
  this.height = arguments[3] ? arguments[3] : 350;
  this.popupWindow = null;
  this.initData = null;
  this.title = this.id;
  this.browserType = getBrowserType();
  this.popupPos = null;
  this.h = 0;
  this.w = 0;
  this.top = 0;
  this.left = 0;
  this.popupSize = "";
  this.statusBar = true;
  this.props = null;
  this.winProp = null;

  if (this.browserType = "Microsoft")
  {
    if (window.top)
    {
      this.w = window.top.document.body.offsetWidth;
      this.h = window.top.document.body.offsetHeight;
    }
    else
    {
      this.w = window.document.body.offsetWidth;
      this.h = window.document.body.offsetHeight;
    }
  }
  else if (this.browserType = "Netscape")
  {
    if (window.top)
    {
      this.w = window.top.innerWidth;
      this.h = window.top.innerHeight;
    }
    else
    {
      this.w = window.innerWidth;
      this.h = window.innerHeight;
    }
  }
  else
  {
    this.popupPos = "";
  }

  this.setId = function()
  {
    this.id = arguments[0];
  }

  this.setTitle = function()
  {
    this.title = arguments[0];
  }

  this.setURL = function()
  {
    this.url = arguments[0];
  }

  this.setWidth = function()
  {
    this.width = arguments[0];
  }

  this.setHeight = function()
  {
    this.height = arguments[0];
  }

  this.setStatusBar = function()
  {
    this.statusBar = arguments[0] ? ((arguments[0] == true) ? true : false) : false;
  }

  this.setInitData = function()
  {
    this.initData = arguments[0];
  }

  this.getInitData = function()
  {
    return this.initData;
  }

  this.close = function()
  {
    if (this != arguments.callee._oScope)
    {
      return arguments.callee.apply(arguments.callee._oScope, arguments);
    }
    if (this.popupWindow)
    {
      this.popupWindow.close();
    }
  }
  this.close._oScope = this;

  this.setPopupParent = function()
  {
    if (this != arguments.callee._oScope)
    {
      return arguments.callee.apply(arguments.callee._oScope, arguments);
    }
    try
    {
      this.popupWindow.popupParent = this;
      if (this.popupWindow.popupParent)
      {
        this.setInitDate();
        return;
      }
    }
    catch(e) { }
    setTimeout(this.setPopupParent, 250);
  }
  this.setPopupParent._oScope = this;

  this.setInitData = function()
  {
    if (this != arguments.callee._oScope)
    {
      return arguments.callee.apply(arguments.callee._oScope, arguments);
    }
    try
    {
      if (this.popupWindow.popup_setInitData)
      {
        this.popupWindow.popup_setInitData(this.initData);
      }
      return;
    }
    catch(e) {}
    setTimeout(this.setInitData, 250);
  }
  this.setInitData._oScope = this;

  this.open = function()
  {
    this.top = 50 + parseInt((this.h - this.height) / 2);
    this.left = parseInt((this.w - this.width) / 2);
    this.popupPos = ",top="  + this.top + ",left=" + this.left;
    this.popupSize = ",width=" + this.width + ",height=" + this.height;
    this.winProp = "toolbar=no,location=no,directories=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no";
    if (this.statusBar == true)
    {
      this.winProp = this.winProp + ",status=yes";
    }
    else
    {
      this.winProp = this.winProp + ",status=no";
    }
    this.winProp = this.winProp + this.popupSize + this.popupPos;
    //
    this.popupWindow = window.open(this.url, this.title, this.winProp);
    try
    {
      this.popupWindow.popupParent = this;
    }
    catch(e)
    {
      alert(e.message);
    }
    setTimeout(this.setPopupParent, 1000);
    this.popupWindow.focus();
    this.popupWindow.onblur = function () { window.close(); }
  }

  this.isOpen = function()
  {
    if (this.popupWindow.location)
    {
      return true;
    }
    else
    {
      return false;
    }
  }

  this.write = function(txt)
  {
    this.popupWindow.document.write(txt);
  }

  this.callbackMethodNotRegistered = function()
  {
    var id = this.id ? this.id : "Un-titled";
    alert("Popup: Callback method not registered for [" + id + "] popup window!");
  }

  this.callbackMethod = this.callbackMethodNotRegistered;

  this.registerCallbackMethod = function()
  {
    this.callbackMethod = arguments[0] ? arguments[0] : this.callbackMethodNotRegistered;
  }

  this.executeCallbackMethod = function()
  {
    this.close();
    var args = new Array();
    var passedArgs = arguments[0] ? arguments[0] : null;
    if (passedArgs)
    {
      for(var i = 0; i < passedArgs.length ; i++)
      {
        var a = new Object(passedArgs[i]);
        args.push(a);
      }
    }
    this.callbackMethod.apply(this, args);
  }

  this.setTimeout = function(seconds)
  {
    setTimeout(this.close, (seconds * 1000));
  }

}
//
//  Call this method to return value from the popup window
//
Popup.returnValue = function()
{
  try
  {
    window.popupParent.executeCallbackMethod(arguments);
  }
  catch(e)
  {
    alert(e.message);
  }
}
/*==============================================================================

Function: PopupCalendar

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
02/07/2005 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
function PopupCalendar(id)
{
  var targetId = id;
  var popup = null;

  var defaultCallbackMethod = function() {}

  var callbackMethod = defaultCallbackMethod;

  this.registerCallbackMethod = function()
  {
    callbackMethod = arguments[0] ? arguments[0] : defaultCallbackMethod;
  }

  this.setDate = function()
  {
    if (this != arguments.callee._oScope)
    {
      return arguments.callee.apply(arguments.callee._oScope, arguments);
    }
    var e = document.getElementById(targetId);
    e.value = arguments[0];
    popup.close();
    callbackMethod.apply(this, arguments);
  }
  this.setDate._oScope = this;

  popup = new Popup("POPUP_CALENDAR","/js/popupCalendar2.html",180,154);
  popup.setTimeout(10);
  popup.registerCallbackMethod(this.setDate);
  popup.setStatusBar(false);

  this.open = function open()
  {
    popup.open();
  }
}

/*==============================================================================

Function: Blinker

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
01/19/2005 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
function Blinker()
{
  this.blinking = false;
  this.timeOut = null;
  this.blinkElementId = arguments[0];
  this.blinkElement = document.getElementById(this.blinkElementId);
  this.blinkElementHTML = "";
  this.started = false;

  this.start = function()
  {
    if (!this.started)
    {
      this.blinkElementHTML = this.blinkElement.innerHTML;
      if (this.blinkElementHTML)
      {
        var txt = new String(this.blinkElementHTML)
        if (txt.trim().length > 0 && txt.trim() != "&nbsp;")
        {
          this.started = true;
          this.__blink__();
        }
      }
    }
  }

  this.stop = function()
  {
    if (this.started)
    {
      clearTimeout(this.timeOut);
      this.timeOut = null;
      this.blinkElement.innerHTML = this.blinkElementHTML;
      this.started = false;
    }
  }

  this.__blink__ = function()
  {
    if (this != arguments.callee._oScope)
    {
      return arguments.callee.apply(arguments.callee._oScope);
    }
    if (this.started)
    {
      if (this.blinking == true)
      {
        this.blinking = false;
        this.blinkElement.innerHTML = "&nbsp;";
      }
      else
      {
        this.blinking = true;
        this.blinkElement.innerHTML = this.blinkElementHTML;
      }
      this.timeOut = setTimeout(this.__blink__, '500');
    }
  }
  this.__blink__._oScope = this;

}
/*==============================================================================

Function: Message

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
01/04/2004 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
function Message()
{
  // DEFAULTS
  var defaultDisplayContainer = "MESSAGE";
  var defaultBackgroundColor = "#99CCFF";
  var defaultTitleColor = "darkblue";
  var defaultTextColor = "blue";
  var defaultTitleWarningColor = "#19890B";
  var defaultTextWarningColor = "#A6C704";
  var defaultTitleErrorColor = "#FF0C05";
  var defaultTextErrorColor = "#FF0000";

  this.currentTitleColor = defaultTitleColor;
  this.currentTextColor = defaultTextColor;
  this.messageText = null;
  this.messageIcon = null;
  this.displayContainerId = null;
  this.currentMsg = null;
  this.backgroundColor = null;
  this.textColor = null;

  this.displayContainerId = arguments[0] ? arguments[0] : defaultDisplayContainer;
  this.messageIcon = arguments[1] ? arguments[1] : null;
  this.backgroundColor = defaultBackgroundColor;
  this.textColor = defaultTextColor;
  this.titleColor = defaultTitleColor;
  this.textWarningColor = defaultTextWarningColor;
  this.titleWarningColor = defaultTitleWarningColor;
  this.textErrorColor = defaultTextErrorColor;
  this.titleErrorColor = defaultTitleErrorColor;

  this.messageText = new Hashtable();
  this.displayContainer = document.getElementById(this.displayContainerId);
  this.displayContainer.style.backgroundColor = this.backgroundColor;
  this.displayContainer.style.color = this.textColor;

  this.add = function(id, text)
  {
    try
    {
      var e = document.getElementById(id);
      e.onmouseover = this.show;
      e.onmouseout  = this.clear;
      this.messageText.put(id, text);
    }
    catch(e)
    {
      // id does not exist on the page
    }
  }

  this.getDisplayContainerId = function()
  {
    return this.displayContainerId;
  }

  this.__renderMessage__ = function()
  {
    this.blinker.stop();
    var text   = null;
    var text_1 = arguments[0] ? arguments[0] : null;
    var text_2 = arguments[1] ? arguments[1] : null;
    if (text_2 == null)
    {
      text = "<span style='color:" + this.currentTextColor + ";margin-left:3px;'>" + text_1 + "</span>";
      this.currentMsg = text_1;
    }
    else if (text_1 != null && text_2 != null)
    {
      text = "<span style='color:" + this.currentTitleColor + ";margin-left:3px;'>" + text_1 + ": </span>" +
             "<span style='color:" + this.currentTextColor + ";margin-left:3px;'>" + text_2 + "</span>";
      this.currentMsg = text_2;
    }
    if (text == null)
    {
      text = messageText.get(window.event.srcElement.id);
      this.currentMsg = text;
    }
    var html = "";
    if (this.messageIcon)
    {
      html = "<img src='" + this.messageIcon + "' align='center'/>" + text;
    }
    else
    {
      html = text;
    }
    this.displayContainer.innerHTML = html;
  }

  this.show = function()
  {
    this.currentTitleColor = this.titleColor;
    this.currentTextColor = this.textColor;
    this.__renderMessage__.apply(this, arguments);
  }

  this.clear = function()
  {
    this.stopBlinking();
    var html = "&nbsp;";
    this.displayContainer.innerHTML = html;
  }

  this.setBackgroundColor = function()
  {
    this.backgroundColor = arguments[0] ? arguments[0] : defaultBackgroundColor;
    this.displayContainer.style.background = this.backgroundColor;
  }

  this.setTextColor = function()
  {
    this.textColor = arguments[0] ? arguments[0] : defaultTextColor;
    this.displayContainer.style.color = this.textColor;
  }

  this.setTitleColor = function()
  {
    this.titleColor = arguments[0] ? arguments[0] : defaultTitleColor;
  }

  this.setBorder = function()
  {
    var left   = arguments[0];
    var top    = arguments[1];
    var right  = arguments[2];
    var bottom = arguments[3];
    if (left)   { this.displayContainer.style.borderLeft   = left;   }
    if (top)    { this.displayContainer.style.borderTop    = top;    }
    if (right)  { this.displayContainer.style.borderRight  = right;  }
    if (bottom) { this.displayContainer.style.borderBottom = bottom; }
  }

  this.blinker = new Blinker(this.getDisplayContainerId());

  this.showBlinking = function()
  {
    var text_1 = arguments[0] ? arguments[0] : null;
    var text_2 = arguments[1] ? arguments[1] : null;
    this.currentTitleColor = this.titleColor;
    this.currentTextColor = this.textColor;
    //if (text_1 && text_2)
    //{
    //  this.show(text_1, text_2);
    //}
    //else if (text_1)
    //{
    //  this.show(text_1);
    //}
    this.__renderMessage__.apply(this, arguments);
    this.blinker.start();
  }

  this.startBlinking = function()
  {
    this.blinker.start();
  }

  this.stopBlinking = function()
  {
    this.blinker.stop();
  }


  this.showWarning = function()
  {
    this.currentTitleColor = this.titleWarningColor;
    this.currentTextColor = this.textWarningColor;
    this.__renderMessage__.apply(this, arguments);
  }

  this.showError = function()
  {
    this.currentTitleColor = this.titleErrorColor;
    this.currentTextColor = this.textErrorColor;
    this.__renderMessage__.apply(this, arguments);
  }
}
/*===============================================================================

 Method: getDDFName

         Used by getElementValue()

 No. Modified   By  Purpose
 ~~~ ~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 001 01/06/2005 AEB Aldrin Edison Baroi

================================================================================*/
function getDDFElementId()
{
  var arg1 = new String(arguments[0] ? arguments[0] : "");
  var arg2 = arguments[1] ? arguments[1] : "";
  var ddfName = null;
  if (isNumber(arg2))
  {
    ddfName = (arg1.trim() + "_" + arg2);
  }
  else
  {
    ddfName = arg1.trim();
  }
  return ddfName;
}
/*===============================================================================

 Method: getElementValue

         Used by "dd.js" data definition functions.

 No. Modified   By  Purpose
 ~~~ ~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 001 01/06/2005 AEB Aldrin Edison Baroi

================================================================================*/
function getElementValue(id)
{
  var arg1 = arguments[0];
  var arg2 = arguments[1];
  var eId  = getDDFElementId(arg1, arg2);
  if (eId)
  {
    var e = document.getElementById(eId);
    if (e)
    {
      return (new String(e.value));
    }
  }
  return "";
}
/*==============================================================================

Function: Net

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
01/13/2005 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
function Net()
{
  this.url = location.href;
  this.protocol = null;
  this.host = null;
  this.port = null;
  this.uri =  null;
  this.tokens = this.url.split("://");
  this.protocol = new String(this.tokens[0]);
  if (this.protocol == "file")
  {
     this.host = new String(this.tokens[1].split(":")[0]);
  }
  else
  {
    this.host = new String(this.tokens[1].split("/")[0]);
    if (this.host.indexOf(":") > 0)
    {
      this.tokens = this.host.split(":");
      this.host   = this.tokens[0];
      this.port   = this.tokens[1];
    }
  }
  if (!this.port)
  {
    if (this.protocol == "http")
    {
      this.port = "80";
    }
    else if (this.protocol == "ftp")
    {
      this.port = "21";
    }
    else if (this.protocol == "file")
    {
      this.port = ""; // No Port
    }
    else if (this.protocol == "smtp")
    {
      this.port = "21";
    }
    else if (this.protocol == "https")
    {
      this.port = "443";
    }
    else
    {
      this.port = "";
    }
  }

  this.prefix = this.protocol + "://" + this.host;
  this.len    = this.prefix.length;
  this.uri    = this.url.substr(this.len + 1);

  this.getURI = function()
  {
    return this.uri;
  }

  this.getURL = function()
  {
    return this.url;
  }

  this.getProtocol = function()
  {
    return this.protocol;
  }

  this.getHost = function()
  {
    return this.host;
  }

  this.getPort = function()
  {
    return this.port;
  }
}
/*==============================================================================

Function: URL

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
01/13/2005 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
function URL()
{
  this.net = new Net();
  this.protocol = null;
  this.host = null;
  this.port = null;
  this.uri = null;

  if (arguments.length == 4)
  {
    this.protocol = arguments[0];
    this.host     = arguments[1];
    this.port     = arguments[2];
    this.uri      = argumnets[3];
  }
  else if (arguments.length == 3)
  {
    this.protocol = arguments[0];
    this.host     = arguments[1];
    this.uri      = argumnets[2];
  }
  else if (arguments.length == 2)
  {
    this.protocol = this.net.getProtocol();
    this.host     = arguments[0];
    this.uri      = argumnets[1];
  }
  else if (arguments.length == 1)
  {
    this.protocol = this.net.getProtocol();
    this.host     = this.net.getHost();
    this.uri      = arguments[0];
  }
  else
  {
    this.protocol = this.net.getProtocol();
    this.host     = this.net.getHost();
    this.uri      = this.net.getURI();
  }

  if (this.uri.indexOf("/") == 0)
  {
    this.uri = this.uri.substr(1);
  }

  function getHost(protocol, host)
  {
     if (protocol == "file")
     {
       return host + ":"
     }
     else
     {
       return host;
     }
  }

  this.getURL = function()
  {
    var url = null;
    if (this.port)
    {
      url = this.protocol + "://" + getHost(this.protocol, this.host) + ":" + this.port + "/" + uri;
    }
    else
    {
      url = this.protocol + "://" + getHost(this.protocol, this.host) + "/" + this.uri;
    }
    return url;
  }
}
/*==============================================================================

Function: CommandURL

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
01/18/2005 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
//
// Helper
//
function CommandParameter()
{
  this.name = arguments[0];
  this.value = arguments[1];

  this.getName = function()
  {
    return this.name;
  }

  this.getValue = function()
  {
    return this.value;
  }

  this.toString = function()
  {
    return this.name + "=" + this.value;
  }
}
//
// CommandURL
//
function CommandURL()
{
  this.command   = arguments[0];
  this.action    = arguments[1];
  this.uriPrefix = "";
  this.parameters = new Array();

  if (this.command)
  {
    this.uriPrefix = "/Elkay.ePortal/Director?command=" + this.command;
  }
  else
  {
    throw "Please command module name!";
  }
  if (this.action)
  {
    this.uriPrefix = this.uriPrefix + "&action=" + this.action
  }
  else
  {
    throw "Please specify command action!";
  }

  this.addParameter = function(name, value)
  {
    if (name && value)
    {
      this.parameters.push(new CommandParameter(name, value));
    }
  }

  this.getURL = function()
  {
    var url = null;
    for(i = 0; i < this.parameters.length; i++)
    {
      if (i == 0)
      {
        url = this.parameters[i].toString();
      }
      else
      {
        url = url + "&" + this.parameters[i].toString();
      }
    }
    if (url)
    {
      url = this.uriPrefix + "&" + url;
    }
    else
    {
      url = this.uriPrefix;
    }
    return url;
  }

}
/*==============================================================================

File: lookup.js

Description: This is an abstruct class for lookup function.

Implemantaion Guide:

              Implement concrete class as follows:

                1. Suppose we want to implement user lookup and Elkay.ePortal
                   command module name is "UserLookup".

                     function UserLookup()
                     {
                       this.superClass = AbstructLookup;
                       this.superClass("UserLookup");
                       this.superClass = null;
                     }

                2. Suppose we want to implement user lookup and Elkay.ePortal
                   command module name is "UserLookup", also the command module
                   need the form name that it need to display for input.  Let the
                   form name be "UserLookupForm".

                     function UserLookup()
                     {
                       this.superClass = AbstructLookup;
                       this.superClass("UserLookup", "UserLookupForm");
                       this.superClass = null;
                     }

Note:

    The implementation requires a call back method to return value.  Return value is a HashTable.

    Call back method signature:

      void methodName(hashTable)

Example (Complete):

    Suppose concrete implementation is:

    function CustomerLookup()
    {
      this.superClass = AbstructLookup;
      this.superClass("CustomerLookup");
      this.superClass = null;
    }

    Now, the application code will lookup like the following:

    function myCustomerCallbackMethod(customerHashtable)
    {
       var custNum = customerHashtable.get("CustNum");
       var custName = customerHashtable.get("CustName");
       document.CustomerForm.custNum.value = custNum;
       document.CustomerForm.custName.value = custName;
    }

    var customerLookup = new CustomerLookup();
    customerLookup.registerCallbackMethod(myCustomerCallbackMethod);
    customerLookup.lookup()

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
01/12/2005 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
/*==============================================================================

Function: AbstructLookup

Description: This is an abstruct class

NOTE       : Only one lookup can execute at any time becuase of limitation
              of call back method preserving pointer to current lookup object.

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
01/12/2005 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
var currentLookupClass = null;
var original_popup_setValue = null;

function lookup_setCurrentLookupClass(clazz)
{
  original_popup_setValue = window.popup_setValue;
  window.popup_setValue = lookup_setValue;
  currentLookupClass = clazz;
}

function lookup_setValue(xmlData)
{
  window.popup_setValue = original_popup_setValue;
  if (currentLookupClass)
  {
    currentLookupClass.executeCallbackMethod(xmlData);
  }
}

function AbstractLookup()
{
  // defaults
  var defaultWindowHeight = 550;
  var defaultWindowWidth = 350;

  this.lookupEnabled = true;
  this.commandModule = arguments[0];
  this.formName = arguments[1];
  this.id  = null;
  this.url = null;
  this.windowHeight = defaultWindowHeight;
  this.windowWidth = defaultWindowWidth;

  if (this.commandModule)
  {
    this.id = this.commandModule;
    var uri = "Elkay.ePortal/Director?command=" + this.commandModule + "&amp;action=showForm"
    if (this.formName)
    {
      uri = uri + "&amp;formName=" + this.formName;
    }
    this.url = (new URL(uri)).getURL();
  }

  this.enabled = function()
  {
    var trueFalse = arguments[0];
    if (trueFalse == true)
    {
      this.lookupEnabled = true;
    }
    else
    {
      this.lookupEnabled = false;
    }
  }

  this.setWindowHeight = function()
  {
    var wh = arguments[0];
    if (wh)
    {
      var whStr = new String(wh);
      if (isNumber(whStr.trim()))
      {
        this.windowHeight = wh;
      }
    }
  }

  this.setWindowWidth = function()
  {
    var ww = arguments[0];
    if (ww)
    {
      var wwStr = new String(ww);
      if (isNumber(wwStr.trim()))
      {
        this.windowHeight = ww;
      }
    }
  }

  this.lookup = function()
  {
    if (this.lookupEnabled == true)
    {
      if (this.id && this.url)
      {
        lookup_setCurrentLookupClass(this);
        popup_openWindow(this.url,this.id,'', this.windowHeight, this.windowWidth);
      }
      else
      {
        var msg = "";
        if (this.id == null && this.url == null)
        {
          msg = " Lookup ID & URL not specified!";
        }
        else
        {
          if (this.id == null)
          {
            msg = "ID not specified for URL: " + this.url;
          }
          else
          {
            msg = this.id + " Lookup URL not specified!";
          }
        }
        alert(msg);
      }
    }
  }

  function callbackMethodNotRegistered()
  {
    alert("Callback method not registered!");
  }

  this.callbackMethod = callbackMethodNotRegistered; // Default

  this.registerCallbackMethod = function()
  {
    this.callbackMethod = arguments[0] ? arguments[0] : callbackMethodNotRegistered;
  }

  this.executeCallbackMethod = function()
  {
    //if (this != arguments.callee._oScope)
    //{
    //  return arguments.callee.apply(arguments.callee._oScope, arguments);
    //}
    var xmlData = arguments[0];
    if (xmlData)
    {
      var xml = new XML();
      xml.createDocumentFromString(xmlData);
      var hd = xml.getHashedData();
      this.callbackMethod(hd);
    }
    else
    {
      alert("No data value returned!");
    }
  }
  //this.executeCallbackMethod._oScope = this;
}
/*==============================================================================

Function: Select

Description: select object

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
01/17/2005 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
function Select()
{
  this.id = arguments[0] ? arguments[0] : null;
  this.selObj = document.getElementById(this.id);

  this.getElementCount = function()
  {
    return this.selObj.length;
  }

  this.getSelectedIndex = function()
  {
    return this.selObj.selectedIndex;
  }

  this.getSelectedValue = function()
  {
    return this.selObj[selObj.selectedIndex].value;
  }

  this.setSelectedByIndex = function(idx)
  {
    if (this.selObj.length > idx)
    {
      this.selObj.selectedIdx = idx;
    }
  }

  this.setSelectedByValue = function(value)
  {
    for(i = 0; i < this.selObj.length; i++)
    {
      if (this.selObj[i].value == value)
      {
        this.selObj.selectedIndex = i;
      }
    }
  }

  this.removeAll = function()
  {
    while(this.selObj.length > 0)
    {
      this.selObj.remove(this.selObj.length - 1);
    }
  }

  this.removeByValue = function(value)
  {
    for(i = 0; i < this.selObj.length; i++)
    {
      if (this.selObj[i].value == value)
      {
        this.selObj.remove(i);
      }
    }
  }

  this.removeByIndex = function(index)
  {
    this.selObj.remove(index);
  }

  this.add = function(code, value)
  {
    var option = document.createElement("option");
    option.value = code;
    option.text = value;
    this.selObj.add(option);
  }

}
/*==============================================================================

Function: SwapSelect

Description: Create new "select" node and swap this node with the specifed
              node.  Also, swap the original back into the document.

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
01/18/2005 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
function SwapSelect()
{

  this.callbackMethodNotRegistered = function()
  {
    alert("SwapSelct: Callback method not registered for " + this.id);
  }

  this.executeCallbackMethod = function()
  {
    if (this != arguments.callee._oScope)
    {
      return arguments.callee.apply(arguments.callee._oScope, arguments);
    }
    var obj = document.getElementById(this.id);
    this.callbackMethod(obj);
  }
  this.executeCallbackMethod._oScope = this;

  function Option(value, text)
  {
    this.value = arguments[0];
    this.text  = arguments[1];
    this.node  = document.createElement("option");
    this.attr  = document.createAttribute("value");
    this.txt   = document.createTextNode(new String(this.text));
    this.node.setAttributeNode(this.attr);
    this.node.value = this.value;
    this.node.appendChild(this.txt);

    this.getNode = function()
    {
      return this.node;
    }

    this.getValue = function()
    {
      return this.value;
    }

    this.getText = function()
    {
      return this.text;
    }
  }

  this.id = arguments[0];
  this.callbackMethod = arguments[1] ? arguments[1] : this.callbackMethodNotRegistered;
  this.style = arguments[2];
  this.oldNode = document.getElementById(this.id);
  this.newNode = document.createElement("select");
  this.attr = document.createAttribute("id");
  this.newNode.setAttributeNode(this.attr);
  this.newNode.id = this.id;
  if (this.oldNode.style.cssText)
  {
    var s = document.createAttribute("style");
    this.newNode.setAttributeNode(s);
    this.newNode.style.cssText = this.oldNode.style.cssText;
  }
  if (this.oldNode.className)
  {
    this.newNode.className = this.oldNode.className;
  }
  this.attr2 = document.createAttribute("onchange");
  this.newNode.setAttributeNode(this.attr2);
  this.newNode.onchange = this.executeCallbackMethod;

  this.options = new Array();

  this.addOption = function()
  {
    var value = arguments[0];
    var desc  = arguments[1];
    if (value && desc)
    {
      var option = new Option(value, desc);
      if (option)
      {
        this.options.push(option);
      }
    }
  }

  this.swaped = false; // initial value

  this.swap = function()
  {
    if (this.swaped == false)
    {
      this.swaped = true;
      this.oldNode.swapNode(this.newNode);
      var newNode = document.getElementById(this.id);
      for(i = 0; i < this.options.length; i++)
      {
        newNode.appendChild(this.options[i].getNode());
      }
    }
  }

  this.swapBack = function()
  {
    if (this.swaped == true)
    {
      this.swaped = false;
      var newNode = document.getElementById(this.id);
      while(newNode.childNodes.length > 0)
      {
        newNode.removeChild(newNode.firstChild);
      }
      this.newNode.swapNode(this.oldNode);
    }
  }
}
/*==============================================================================

Function:    Section

Description:

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
01/17/2005 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
function Section(id)
{
  var sectionId = id;
  var sec       = document.getElementById(sectionId);
  var top       = sec.style.top;
  var left      = sec.style.left;
  this.hide     = function()
  {
    sec.style.visibility = "hidden";
    sec.style.top = 5000;
    sec.style.left = 5000;
  }
  this.show     = function()
  {
    sec.style.visibility = "visible";
    sec.style.top = top;
    sec.style.left = left;
  }
}
/*==============================================================================

Function:    FormDataEncoder

Description:

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
01/17/2005 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
function FormDataEncoder()
{
  var params = new Hashtable();

  this.addParameter = function (name, value)
  {
    params.put(name, value);
  }

  this.getEncodedData = function()
  {
    var data = "";
    var keys = params.keys();
    for(i = 0; i < keys.length; i++)
    {
      var key = keys[i];
      var val = params.get(key);
      if (i == 0)
      {
        data = escape(key) + "=" + escape(val);
      }
      else
      {
        data = data + "&" + escape(key) + "=" + escape(val);
      }
    }
    return data;
  }
}
/*==============================================================================

Function:    HttpRequestFactory
             HttpRequest
             HttpResponse

Description: Send receive HTTP request response

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
01/18/2005 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
//
// Factory
//
function HttpRequestFactory()
{
  var MSXML_XMLHTTP_PROGIDS = new Array('MSXML2.XMLHTTP.5.0',
                                        'MSXML2.XMLHTTP.4.0',
                                        'MSXML2.XMLHTTP.3.0',
                                        'MSXML2.XMLHTTP',
                                        'Microsoft.XMLHTTP'
                                        );
  var browserType = getBrowserType();

  this.create = function()
  {
    var httpRequest = null;
    if (browserType == "Microsoft")
    {
      var success = false;
      for (var i=0;i < MSXML_XMLHTTP_PROGIDS.length && !success; i++)
      {
        try
        {
          httpRequest = new ActiveXObject(MSXML_XMLHTTP_PROGIDS[i]);
          success = true;
        }
        catch (e)
        {}
      }
    }
    else
    {
      httpRequest = new XMLHttpRequest();
    }
    return httpRequest;
  }
}
//
// Response
//
function HttpResponse()
{
  this.status       = arguments[0];
  this.statusText   = arguments[1] ? new String(arguments[1]) : new String("");
  this.responseText = arguments[2] ? new String(arguments[2]) : new String("");
  this.responseXML  = arguments[3];

  this.getStatus = function()
  {
    return this.status;
  }

  this.getStatusText = function()
  {
    return this.statusText;
  }

  this.getResponseText = function()
  {
    return this.responseText;
  }

  this.getResponseXML = function()
  {
    return this.responseXML;
  }
}
//
// Request
//
function HttpRequest()
{
  this.userName    = arguments[0] ? arguments[0] : null;
  this.password    = arguments[1] ? arguments[1] : null;
  this.httpRequest = null;
  this.async       = true; // default
  this.content     = null;

  // The following statement is needed for Netscame to access local file system
  // and domains other than the one from which this script is loaded.
  // netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");

  function callbackMethodNotRegistered()
  {
    alert("Callback method not registered!");
  }

  function onErrorCallbackMethodNotRegistered()
  {
    alert("On Error Callback method not registered!");
  }

  this.callbackMethod = callbackMethodNotRegistered; // Default
  this.onErrorCallbackMethod = onErrorCallbackMethodNotRegistered; // Default

  this.registerCallbackMethod = function()
  {
    this.callbackMethod = arguments[0] ? arguments[0] : callbackMethodNotRegistered;
  }

  this.registerOnErrorCallbackMethod = function()
  {
    this.onErrorCallbackMethod = arguments[0] ? arguments[0] : onErrorCallbackMethodNotRegistered;
  }

  this.executeCallbackMethod = function()
  {
    if (this != arguments.callee._oScope)
    {
      return arguments.callee.apply(arguments.callee._oScope, arguments);
    }
    if (this.httpRequest.readyState == 4)
    {
      var httpResponse = new HttpResponse(this.httpRequest.status,
                                          this.httpRequest.statusText,
                                          this.httpRequest.responseText,
                                          this.httpRequest.responseXML);
      //<SPECIAL CASE>
      //<Comment>
      //  Check whether Elkay.ePortal session expired
      //</Comment>
      var resTxt = new String(httpResponse.getResponseText());
      if (resTxt.indexOf("sessionExpired") >= 0)
      {
        window.location = "/Elkay.ePortal/jsp/sessionExpired.jsp";
      }
      //</SPECIAL-CASE>
      if (this.httpRequest.status == 200)
      {
        var rs = new String(httpResponse.getResponseText());
        if (rs.trim().indexOf("Error") > 0 ||
            rs.trim().length == 0)
        {
          this.onErrorCallbackMethod(httpResponse);
        }
        else
        {
          this.callbackMethod(httpResponse);
        }
      }
      else
      {
        this.onErrorCallbackMethod(httpResponse);
      }
    }
  }
  this.executeCallbackMethod._oScope = this;

  this.httpRequestFactory = new HttpRequestFactory();
  this.httpRequest = null; // this.httpRequestFactory.create();

  //this.httpRequest.onreadystatechange = this.executeCallbackMethod;

  this.abort = function()
  {
    this.httpRequest.abort();
  }

  this.getAllResponseHeaders = function()
  {
    return this.httpRequest.getAllResponseHeaders();
  }

  this.getResponseHeader = function()
  {
    return this.httpRequest.getResponseHeader(arguments[0]);
  }

  this.setRequestHeader = function()
  {
    this.httpRequest.setRequestHeader(arguments[0], arguments[1]);
  }

  this.setAsync = function()
  {
    this.async = arguments[1] ? ((arguments[1] == false) ? false : true) : true;
  }

  this.__create__ = function()
  {
    this.httpRequest = this.httpRequestFactory.create();
    this.httpRequest.onreadystatechange = this.executeCallbackMethod;
  }

  this.openForGET = function()
  {
    var url      = arguments[0];
    var userName = arguments[1];
    var password = arguments[2];
    this.content = null;
    this.__create__();
    if ((this.userName && this.password) || (userName && password))
    {
      if (this.userName && this.password)
      {
        this.httpRequest.open("GET", url, this.async, this.userName, this.password);
      }
      else
      {
        this.httpRequest.open("GET", url, this.async, userName, password);
      }
    }
    else
    {
      this.httpRequest.open("GET", url, this.async);
    }
  }

  this.openForPOST = function()
  {
    var url      = arguments[0];
    var userName = arguments[1];
    var password = arguments[2];
    this.content = null;
    this.__create__();
    if ((this.userName && this.password) || (userName && password))
    {
      if (this.userName && this.password)
      {
        this.httpRequest.open("POST", url, this.async, this.userName, this.password);
      }
      else
      {
        this.httpRequest.open("POST", url, this.async, userName, password);
      }
    }
    else
    {
      this.httpRequest.open("POST", url, this.async);
    }
  }


  this.send = function()
  {
    this.content = arguments[0] ? arguments[0] : null;
    this.httpRequest.send(this.content);
    this.content = null;
  }
}
/*==============================================================================

Function:    Date.prototype.addDays

Description: Extends Date object to include add functionality

Modified   By  Purpose
~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
02/07/2005 AEB Aldrin Edison Baroi (Creation)

==============================================================================*/
Date.prototype.addDays = function(days)
{
  return new Date(this.getTime() + (days * 24 * 60 * 60 *1000));
}
/*==============================================================================
==============================================================================*/




