﻿/*************************************************************
* The woms array holds all of the functions you wish to run
* when the page loads.
*************************************************************/
var woms = new Array();

/*************************************************************
* Window Onload Manager (WOM) v1.0
*
* Description:
* The WOM library of functions allows you to easily call
* multiple javascript functions when your page loads.
*
* Usage:
* Add functions to WOM using the womAdd() function. Pass the
* name of your functions (with or without parameters) into
* womAdd(). Then call womOn() like this:
*     womAdd('hideDiv()');
*     womAdd('changeBg("menuopts","#CCCCCC")');
*     womOn();
* WOM will now run when your page loads and run all of the
* functions you have added using womAdd()
*************************************************************/
/*************************************************************
* The womOn() function will set the window.onload function to
* be womGo() which will run all of your window.onload
* functions.
*************************************************************/
function womOn(){
  window.onload = womGo;
}
/*************************************************************
* The womGo() function loops through the woms array and
* runs each function in the array.
*************************************************************/
function womGo(){
  for(var i = 0;i < woms.length;i++)
    eval(woms[i]);
}
/*************************************************************
* The womAdd() function will add another function to the woms
* array to be run when the page loads.
*************************************************************/
function womAdd(func){
  woms[woms.length] = func;
}

//******************************************************************************************
// This function sets a client-side cookie as above. Only first 2 parameters are required
// Rest of the parameters are optional. If no szExpires value is set, cookie is a session cookie.
//
// Prototype : SetCookie(szName, szValue [,szExpires] [,szPath] [,szDomain] [,bSecure])
//******************************************************************************************
function SetCookie(szName, szValue, szExpires, szPath, szDomain, bSecure) 
{
    var szCookieText = escape(szName) + '=' + escape(szValue);
    szCookieText += ((szExpires) ? ";expires=" + szExpires.toGMTString() : "");
    szCookieText += ((szPath) ? ";path=" + szPath : "");
    szCookieText += ((szDomain) ? ";domain=" + szDomain : "");
    szCookieText +=((bSecure) ? ";secure" : "");

    document.cookie = szCookieText;
}

function CreateCookie(cookieName, cookieValue) 
{
    var expires = 30;
    var today = new Date();
    today.setTime(today.getTime());
    // if the expires variable is set, make the correct expires time, the 
    // current script below will set it for x number of days, to make it 
    // for hours, delete * 24, for minutes, delete * 60 * 24             
    if (expires) {
        //expires = expires * 1000 * 60 * 60 * 24;
        expires = expires * 1000 * 60;
    }
    var expires_date = new Date(today.getTime() + (expires));

    DeleteCookie(cookieName); 
    SetCookie(cookieName, cookieValue, expires_date, '/');

}
//******************************************************************************************//
// This functions reads & returns the cookie value of the specified cookie (by cookie name)
//
// Prototype : getCookie(szName)
//******************************************************************************************//

function GetCookie(szName) 
{
    var szValue = null;
    if (document.cookie) //only if exists
    {
        var arr = document.cookie.split((escape(szName) + '='));
        if (2 <= arr.length) {
            var arr2 = arr[1].split(';');
            szValue = unescape(arr2[0]);
        }
    }
    return szValue;
}

//******************************************************************************************
// To delete a cookie, pass name of the cookie to be deleted
//
// Prototype : deleteCookie(szName)
//******************************************************************************************
function DeleteCookie(szName)
{
    var tmp = GetCookie(szName);
    if (tmp) {
        SetCookie(szName, tmp, (new Date(1)));
    }
}

//******************************************************************************************
// To scrool the cursor to the top of the page
//
// Prototype : ScrollToTop()
//******************************************************************************************
 
function ScrollToTop()
{
   scroll(0,0);
}

//******************************************************************************************
// Auto jump to the next textbox  after the finish the given digits input
//
// Prototype : InputKeyUp(CurrentTextbox, NextTextBox, the number of digit being input)
//******************************************************************************************
 
function InputKeyUp(thisFieldId, nextFieldId, numberOfDigit)
{
    var thisField=document.getElementById(thisFieldId);            
    var nextField=document.getElementById(nextFieldId);
    if (thisField != null && nextField != null)
    {
        if (thisField.value != null && thisField.value.length == numberOfDigit)
        {
            nextField.focus();
        }
    }
}  
