// Version 1.1.0 - 10/26/2009
// 09/11/2008 - added .toGMTString() to date in setCookie() cookie string for Safari
// 12/09/2008 - added dependent listbox and logging functions.  corrected FireFix bug in popup code.
// 04/05/2009 - added serial number to ajax calls to defeat caching
// 04/17/2009 - changed innerHTML to DOM object appendChild on popUp and iframePop
// 04/17/2009 - changed logIt function to dynamically add <div> for log content
// 04/20/2009 - added Head First Ajax functions
// 07/01/2009 - added Splash Page functions
// 09/17/2009 - extended popup to display passed object instrad of just text
// 09/25/2009 - fixed global search edit on cleanUpPopupBox and added encode/decode for <&> characters
// 10/26/2009 - added post to this page and post to new window functions

//determine browser type
var isDOM = document.getElementById ? 1 : 0;
var isIE = document.all ? 1 : 0;
var isNS4 = navigator.appName == 'Netscape' && !isDOM ? 1 : 0;
var isOp = self.opera ? 1 : 0;
var isDyn = isDOM || isIE || isNS4;
var serializeURLcallId = true;

/*** Positioning ***/
/**
* returns the absolute top of any object
* @param {Object} which - an Element
* @return {Number} theTop
*/
function absoluteTop(which) {
    var theTop = 0;
    var mySelf = which;
    try {
        do {
            theTop += mySelf.offsetTop;
            mySelf = mySelf.parentElement;
        } while (mySelf.offsetTop);
    }
    catch (e) { }
    return theTop;
}

/**
* returns the absolute left of any object
* @param {Object} which - an Element
* @return {Number} theLeft
*/
function absoluteLeft(which) {
    var theLeft = 0;
    var mySelf = which;
    try {
        do {
            theLeft += mySelf.offsetLeft;
            mySelf = mySelf.parentElement;
        } while (mySelf.offsetLeft);
    }
    catch (e) { }
    return theLeft
}

/*** IFrame support ***/
//writes header to iframe
function writeframeheader(myframe) {
    document.frames(myframe).document.open();
    document.frames(myframe).document.writeln('<html>');
    document.frames(myframe).document.writeln('<head>');
    document.frames(myframe).document.writeln('<link href="stylesheets/theme.css" rel="stylesheet">');
    document.frames(myframe).document.writeln('<link href="stylesheets/color.css" rel="stylesheet">');
    document.frames(myframe).document.writeln('<script src="commonFunctions.js"></script>');
    document.frames(myframe).document.writeln('</head>');
    document.frames(myframe).document.writeln('<body class="mstheme">');
}

//writes footer to frame
function writeframefooter(myframe) {
    document.frames(myframe).document.writeln('</body>');
    document.frames(myframe).document.writeln('</html>');
    document.frames(myframe).document.close();
}

/*** Location support ***/
// return the path portion of the current URL reference
function extractCurrentPath(aPathName) {
    var x1 = aPathName.lastIndexOf("\\");
    var x2 = aPathName.lastIndexOf("/");
    if (x1 == -1 && x2 == -1) {
        return aPathName;
    }
    else {
        if (x1 > x2) {
            return aPathName.substring(0, x1 + 1);
        }
        else {
            return aPathName.substring(0, x2 + 1);
        }
    }
}

/*** Object support ***/
/**
* retrieve object by HTML id
* @param {String} id
* @return {Object} the Object
*/
function getObject(id) {
    if (document.getElementById != null) {
        return document.getElementById(id);
    }
    else if (document.all != null) {
        return document.all[id];
    } else {
        return null;
    }
}

/**
* update the innerHTML of named object with passed value
* @param {String} which - id of element
* @param {String} passed
*/
function setInnerHtml(which, passed) {
    var element = getObject(which);
    element.innerHTML = passed;
}

/**
* append to the innerHTML of named object with passed value
* @param {String} which - id of element
* @param {String} passed
*/
function addInnerHtml(which, passed) {
    var element = getObject(which);
    element.innerHTML = element.innerHTML + passed;
}

/*** Ajax Functions ***/
/**
* Set object's HTML from url (sync)
* @param {String} target - id of element
* @param {String} url
*/
function ajaxSetObject(target, url) {
    element = getObject(target);
    if (element != null) {
        element.innerHTML = ajaxGet(url);
    }
}

/**
* Append to an object's HTML from url (sync)
* @param {String} target - id of element
* @param {String} url
*/
function ajaxAddObject(target, url) {
    element = getObject(target);
    if (element != null) {
        element.innerHTML = element.innerHTML + ajaxGet(url);
    }
}

/**
* Get the page request from a url (sync)
* @param {String} url
* @return {String} the html
*/
function ajaxGet(url) {
    var page_request = null;
    page_request = createRequest();
    if (page_request != null) {
        try {
            page_request.open('GET', serializeURL(url), false); // false = synchronously
            page_request.send(null);
            //if (window.location.href.indexOf("http") == -1 || page_request.status == 200) {
            if (page_request.status == 0 || page_request.status == 200) {
                return page_request.responseText;
            }
            return "Error:  HTTP Status: " + page_request.status;
        } catch (e) {
            if (e.toString() == "[object Error]") {
                return "Error:  This web page must be invoked from the server.";
            }
            else {
                return "Error:  No page found or server not running.  " + e.toString();
            }
        }
    }
    return "Error:  No transport found in browser.";

}

/**
* Asynchronous update/append of innerHTML using name of HTML object and url
* @param {String} target - name of target HTML element
* @param {String} url
* @param {String} method - "add" to append, anything else to overwrite
*/
function updateInnerHtmlFromUrl(target, url, method) {
    var page_request = null;
    var element = null;
    element = getObject(target);
    if (element != null) {
        page_request = createRequest();
    }
    if (page_request != null) {
        try {
            page_request.onreadystatechange = function() {
                if (page_request.readyState == 4) {
                    if (page_request.status == 0 || page_request.status == 200) {
                        if (method == "add") {
                            element.innerHTML = element.innerHTML + page_request.responseText;
                        }
                        else {
                            element.innerHTML = page_request.responseText;
                        }
                    }
                    else {
                        element.innerHTML = page_request.status;
                    }
                }
            }
            page_request.open('GET', serializeURL(url), true); // true = asynchronously
            page_request.send(null);
        } catch (e) { }
    }
}

/**
* Serialize Url
*/
function serializeURL(passed) {
    if (serializeURLcallId) {
        if (passed.indexOf("?") > -1) {
            return passed + "&serializedURLcallId=" + Math.random();
        }
        else {
            return passed + "?serializedURLcallId=" + Math.random();
        }
    }
    else {
        return passed
    }
}

/*** date time functions ***/
var thisDate;
var thisTime;
/**
* Updates the "thisDate" and "thisTime" strings
*/
function updateTime() {
    var toDay = new Date();
    var thisYear = toDay.getYear();
    if (thisYear < 1900) {
        thisYear = thisYear + 1900;
    }
    var thisMonth = toDay.getMonth() + 1;
    if (thisMonth < 10) {
        thisMonth = "0" + thisMonth;
    }
    var thisDay = toDay.getDate();
    if (thisDay < 10) {
        thisDay = "0" + thisDay;
    }
    thisDate = thisYear + "" + thisMonth + "" + thisDay;
    var thisWeekday = toDay.getDay();
    var thisHour = toDay.getHours();
    if (thisHour < 10) {
        thisHour = "0" + thisHour;
    }
    var thisMinute = toDay.getMinutes();
    if (thisMinute < 10) {
        thisMinute = "0" + thisMinute;
    }
    var thisSecond = toDay.getSeconds();
    if (thisSecond < 10) {
        thisSecond = "0" + thisSecond;
    }
    var thisMillis = toDay.getMilliseconds();
    if (thisMillis < 10) {
        thisMillis = "00" + thisMillis;
    }
    else if (thisMillis < 100) {
        thisMillis = "0" + thisMillis;
    }
    thisTime = thisHour + "" + thisMinute + "" + thisSecond + "" + thisMillis;
}

/*** Cookie functions ***/
/**
* Get a cookie
* @param {String} sName
*/
function getCookie(sName) {
    var sCookie = " " + document.cookie;
    var sSearch = " " + sName + "=";
    var sStr = null;
    var iOffset = 0;
    var iEnd = 0;
    if (sCookie.length > 0) {
        iOffset = sCookie.indexOf(sSearch);
        if (iOffset != -1) {
            iOffset += sSearch.length;
            iEnd = sCookie.indexOf(";", iOffset)
            if (iEnd == -1)
                iEnd = sCookie.length;
            sStr = unescape(sCookie.substring(iOffset, iEnd));
        }
    }
    return (sStr);
}

/**
* Set a cookie
* @param {String} sName
* @param {String} sVal
* @param {Number} iDays
* @param {String} sPath
* @param {String} sDomain
* @param {Boolean} bSecure
*/
function setCookie(sName, sVal, iDays, sPath, sDomain, bSecure) {
    var sExpires = new Date();
    if (iDays) {
        sExpires.setTime(sExpires.getTime() + (iDays * 24 * 60 * 60 * 1000));
    }
    else {
        sExpires.setTime(sExpires.getTime() + 1);
    }
    var workString = sName + "=" + escape(sVal) + ((sExpires) ? "; expires=" + sExpires.toGMTString() : "") +
		((sPath) ? "; path=" + sPath : "") + ((sDomain) ? "; domain=" + sDomain : "") + ((bSecure) ? "; secure" : "");

    alert(workString);

    document.cookie = workString;

    if (document.cookie.length > 0)
        return true;
    return false;
}

/**
* Get the pixels the user has the window scrolled right
*/
function getScrollLeft() {
    return (window.pageXOffset ? window.pageXOffset : (document.documentElement ? (document.documentElement.scrollLeft) : 0));
}

/**
* Get the pixels the user has the window scrolled down
*/
function getScrollTop() {
    return (window.pageYOffset ? window.pageYOffset : (document.documentElement ? (document.documentElement.scrollTop) : 0));
}
/**
* Get the visible window width
*/
function getWindowWidth() {
    //		return document.body && (typeof(document.body.clientWidth) != "undefined") ? document.body.clientWidth : (typeof(window.innerWidth) != "undefined") ? window.innerWidth : document.body ? (document.body.clientWidth || 0) : 0;
    var myWidth = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth;
    } else if (document.documentElement && (document.documentElement.clientWidth)) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
    } else if (document.body && (document.body.clientWidth)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
    }
    return myWidth;
}
/**
* Get the visible window height
*/
function getWindowHeight() {
    //		return document.body && (typeof(document.body.clientHeight) != "undefined") ? document.body.clientHeight : (typeof(window.innerHeight) != "undefined") ? window.innerHeight : document.body ? (document.body.clientHeight || 0) : 0;
    var myHeight = 0;
    if (typeof (window.innerHeight) == 'number') {
        //Non-IE
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientHeight)) {
        //IE 4 compatible
        myHeight = document.body.clientHeight;
    }
    return myHeight;
}

/*** popup functions ***/
/*
* Put this commented stuff in your target HTML...
*/
/*
<style type="text/css">
p.myPopUpObject {
border-style: dashed;
border-width: 1px;
background-color: #EEFFFF;
padding: 3px;
color: #4444FF;
}
</style> 
*/

var myPopUpObject;
var myPopUpTimer;
var myPopUpDebug = false;
var myPopUpLastText;
var myPopUpLastObjectName;
var myPopUpLastEventClientX;
var myPopUpLastEventClientY;
var myPopUpLastLeftOffset;
var myPopUpLastTopOffset;
var myPopUpDelay = 500;

/**
* Create a new popup.  Invoke from the "onmouseover" event
* @param {String} theText
* @param {String} theObjectName
* @param {Event} theEvent
*/
function showPopUp(theText, theObjectName, theEvent) {
    showPopUp(theText, theObjectName, theEvent, 0);
}

/**
* Create a new popup.  Invoke from the "onmouseover" event
* @param {String} theText
* @param {String} theObjectName
* @param {Event} theEvent
* @param {Number} theLeftOffset
*/
function showPopUp(theText, theObjectName, theEvent, theLeftOffset) {
    showPopUp(theText, theObjectName, theEvent, theLeftOffset, 0);
}

/**
* Create a new popup.  Invoke from the "onmouseover" event
* @param {String} theText
* @param {String} theObjectName
* @param {Event} theEvent
* @param {Number} theLeftOffset
* @param {Number} theTopOffset
*/
function showPopUp(theText, theObjectName, theEvent, theLeftOffset, theTopOffset) {
    showPopUp(theText, theObjectName, theEvent, theLeftOffset, theTopOffset, myPopUpDelay);
}

/**
* Create a new popup.  Invoke from the "onmouseover" event
* @param {String} theText
* @param {String} theObjectName
* @param {Event} theEvent
* @param {Number} theLeftOffset
* @param {Number} theTopOffset
* @param {Number} theDelay
*/
function showPopUp(theText, theObjectName, theEvent, theLeftOffset, theTopOffset, theDelay) {
    if (!myPopUpObject) {
        // document.body.innerHTML += "<div id=\"myPopUpObject\" onmouseover=\"inPopUp();\" onmouseout=\"hidePopUp();\"></div>";
        myPopUpObject = document.createElement("div");
        myPopUpObject.id = "myPopUpObject";
        myPopUpObject.onmouseover = inPopUp;
        myPopUpObject.onmouseout = hidePopUp;
        document.body.appendChild(myPopUpObject);
        myPopUpObject.style.zIndex = 999;
        myPopUpObject.style.display = "none";
        myPopUpObject.style.position = "absolute";
    }
    else {
        myPopUpObject = getObject("myPopUpObject");
    }
    clearTimeout(myPopUpTimer);
    myPopUpLastText = theText;
    myPopUpLastObjectName = theObjectName;
    myPopUpLastEventClientX = theEvent.clientX;
    myPopUpLastEventClientY = theEvent.clientY;
    myPopUpLastLeftOffset = theLeftOffset;
    myPopUpLastTopOffset = theTopOffset;
    // set delay for popup
    myPopUpTimer = setTimeout("showPopUpNow();", theDelay);
}

// show popup
function showPopUpNow() {
    try {
        window.clearTimeout(myPopUpTimer);
        // var theBody;
        // try {
        //     theBody = document.documentElement || document.body || (document.getElementsByTagName ? document.getElementsByTagName("body")[0] : null);
        // } catch (e) {}
        var windowWidth;
        try {
            // windowWidth = document.body && (typeof(document.body.clientWidth) != "undefined") ? document.body.clientWidth : (typeof(window.innerWidth) != "undefined") ? window.innerWidth : document.body ? (document.body.clientWidth || 0) : 0
            windowWidth = getWindowWidth();
        }
        catch (e) {
        }
        var popUpWidth = 200;
        var scrollLeft = getScrollLeft();
        var scrollTop = getScrollTop();
        var theObject = getObject(myPopUpLastObjectName);
        // var theLeft = absoluteLeft(theObject);
        var theLeft = myPopUpLastEventClientX + scrollLeft;
        // var theTop = absoluteTop(theObject);
        var theTop = myPopUpLastEventClientY + scrollTop;
        var leftOffset = 20;
        var topOffset = 20;
        if (myPopUpLastLeftOffset) {
            leftOffset = myPopUpLastLeftOffset;
        }
        if (myPopUpLastTopOffset) {
            topOffset = myPopUpLastTopOffset;
        }
        // if (isDOM && !isIE) {
        topOffset = topOffset - 15;
        // }
        try {
            myPopUpObject.style.left = (theLeft + leftOffset) + "px";
            popUpWidth = windowWidth - (myPopUpLastEventClientX + leftOffset) - 10;
            if (popUpWidth > 640) {
                popUpWidth = 640;
            }
        }
        catch (e) {
        }
        try {
            myPopUpObject.style.top = (theTop + topOffset) + "px";
        }
        catch (e) {
        }
        var comments = "";
        // comments for debugging...
        if (myPopUpDebug) {
            comments = "<br><br>Left=" + theLeft + " &nbsp;&nbsp; Top=" + theTop + " &nbsp;&nbsp; LeftOffset=" + leftOffset + " &nbsp;&nbsp; TopOffset=" + topOffset;
            try {
                comments = comments + "<br>" + navigator.appName;
            }
            catch (e) {
            }
            comments = comments + "<br>" + "aX=" + absoluteLeft(theObject) + ", aY=" + absoluteTop(theObject);
            comments = comments + "<br>" + "cbX=" + (myPopUpLastEventClientX + scrollLeft) + ", cbY=" + (myPopUpLastEventClientY + scrollTop);
            comments = comments + "<br>" + "cX=" + myPopUpLastEventClientX + ", cY=" + myPopUpLastEventClientY;
            comments = comments + "<br>" + "bdX=" + scrollLeft + ", bdY=" + scrollTop;
            comments = comments + "<br>" + "pme=" + popUpWidth + ", wme=" + windowWidth;
            comments = comments + "<br>" + "wX1=" + document.body.clientWidth + ", wY1=" + document.body.clientHeight;
            comments = comments + "<br>" + "wX2=" + document.body.scrollWidth + ", wY1=" + document.body.scrollHeight;
        }
        var tempResult = "";
        try {
            if (!myPopUpLastText.id) {
                // use this one without a style sheet
                // tempResult = "<p style=\"border-style: dashed; border-width: 1px; background-color: #EEFFFF; padding: 3px; color: #4444FF; width: " + popUpWidth + "px\">" + cleanUpPopUpField(myPopUpLastText) + comments + "</p>";
                // use this one with a style sheet
                tempResult = "<p class=\"myPopUpObject\" style=\"width: " + popUpWidth + "px\">" + cleanUpPopUpField(myPopUpLastText) + comments + "</p>";
                // alert(tempResult);
                myPopUpObject.innerHTML = tempResult;
            }
            else {
                myPopUpLastText.style.display = "";
                myPopUpObject.appendChild(myPopUpLastText);
            }
            myPopUpObject.style.display = "block";
        }
        catch (e) { }
    }
    catch (e) {
        alert(e);
    }
}

/**
* Hides the recently created popup.  Invoke from the "onmouseout" event.
*/
function hidePopUp() {
    hidePopUp(myPopUpDelay);
}

function hidePopUp(theDelay) {
    try {
        if (theDelay.type) {
            var theDelay = myPopUpDelay;
        }
    } catch (e) { }
    window.clearTimeout(myPopUpTimer);
    // set delay for hide
    myPopUpTimer = window.setTimeout("outPopUp();", theDelay);
}

// keep popup
function inPopUp() {
    window.clearTimeout(myPopUpTimer);
}

// remove popup
function outPopUp() {
    myPopUpObject.style.display = "none";
    try {
        if (!myPopUpLastText.id) {
            myPopUpObject.innerHTML = "";
        }
        else {
            myPopUpLastText.style.display = "none";
        }
    } catch (e) { }
    try {
        myPopUpObject.removeChild(myPopUpObject.firstChild);
    } catch (e) { }
}

// clean up data
function cleanUpPopUpField(passed) {
    return passed.replace(/&/g, "&amp;").replace(/>/g, "&gt;").replace(/</g, "&lt;");
}

// test encode special characters
function encodeData(passed) {
    return passed.replace(/&/g, "&amp;").replace(/>/g, "&gt;").replace(/</g, "&lt;");
}
// test decode special characters
function decodeData(passed) {
    return passed.replace(/&amp;/g, "&").replace(/&gt;/g, ">").replace(/&lt;/g, "<");
}

/*** dependent listbox functions ***/
/**
* Create a new Dependent List Box Handler
* To use this handler, create the list box TEXT field with three columns, you choose
* the delimiter.  The columns are (1) Text, (2) Parent Key, and (3) Child Key.  The
* parent key of the child listbox must match the child key of the parent list box.
* @param {String} mainName - name of main listbox
* @param {String} mainDelim - delimiter for keys on the main listbox option text field
* @param {String} childName - name of child list box
* @param {String} childDelim - delimiter for keys on the child listbox option text field
* @param {dependentListBoxHandler} childHandler - if the child list box has a dependent listbox, that handler
*/
function dependentListBoxHandler(mainName, mainDelim, childName, childDelim, childHandler) {
    this.mainKeys = new Array();
    this.mainParentKeys = new Array();
    this.mainTexts = new Array();
    this.mainValues = new Array();
    this.mainName = mainName;
    this.mainDelim = mainDelim;
    this.childKeys = new Array();
    this.childTexts = new Array();
    this.childValues = new Array();
    this.childName = childName;
    this.childDelim = childDelim;
    this.Load = dependentListBoxHandlerLoad;
    this.Change = dependentListBoxHandlerChange;
    try {
        this.childHandler = childHandler;
    } catch (e) { }
}

/**
* Invoke to load a new Dependent List Box Handler
*/
function dependentListBoxHandlerLoad() {
    var aHandler = this;
    var theListBox;

    // edit and load main list box
    theListBox = document.getElementById(aHandler.mainName);
    for (var x = 0; x < theListBox.options.length; x++) {
        var theText = theListBox.options[x].text;
        aHandler.mainParentKeys[x] = theText.substring(theText.indexOf(aHandler.mainDelim) + aHandler.mainDelim.length, theText.lastIndexOf(aHandler.mainDelim));
        aHandler.mainKeys[x] = theText.substring(theText.lastIndexOf(aHandler.mainDelim) + aHandler.mainDelim.length);
        aHandler.mainTexts[x] = theText.substring(0, theText.indexOf(aHandler.mainDelim));
        aHandler.mainValues[x] = theListBox.options[x].value;
    }
    var saveIndex = theListBox.selectedIndex;
    for (var x = theListBox.options.length - 1; x > -1; x--) {
        theListBox.remove(x);
    }
    for (var x = 0; x < aHandler.mainKeys.length; x++) {
        var theOption = document.createElement('option');
        theOption.text = aHandler.mainTexts[x];
        theOption.value = aHandler.mainValues[x];
        try {
            theListBox.add(theOption, null);
        }
        catch (e) {
            theListBox.add(theOption);
        }
    }
    theListBox.selectedIndex = saveIndex;

    theListBox = document.getElementById(aHandler.childName);
    if (aHandler.childHandler) {
        // load arrays from child
        aHandler.childKeys = aHandler.childHandler.mainParentKeys;
        aHandler.childTexts = aHandler.childHandler.mainTexts;
        aHandler.childValues = aHandler.childHandler.mainValues;
        for (var x = 0; x < aHandler.childKeys.length; x++) {
        }
    }
    else {
        // edit and reload child list box
        for (var x = 0; x < theListBox.options.length; x++) {
            var theText = theListBox.options[x].text;
            aHandler.childKeys[x] = theText.substring(theText.indexOf(aHandler.childDelim) + aHandler.childDelim.length, theText.lastIndexOf(aHandler.childDelim));
            aHandler.childTexts[x] = theText.substring(0, theText.indexOf(aHandler.childDelim));
            aHandler.childValues[x] = theListBox.options[x].value;
        }
    }
    aHandler.Change(true);
}

/**
* Dependent List Box Change Handler
* @param {Boolean} skip
*/
function dependentListBoxHandlerChange(skip) {
    var aHandler = this;
    var theListBox;
    theListBox = document.getElementById(aHandler.childName);
    var saveText = theListBox.options[theListBox.selectedIndex].text;
    var saveValue = theListBox.options[theListBox.selectedIndex].value;
    for (var x = theListBox.options.length - 1; x > -1; x--) {
        theListBox.remove(x);
    }
    var lookText = document.getElementById(aHandler.mainName).options[document.getElementById(aHandler.mainName).selectedIndex].text;
    var lookValue = document.getElementById(aHandler.mainName).options[document.getElementById(aHandler.mainName).selectedIndex].value;
    var theKey = "This is a string that I do not expect to ever find...";
    for (var x = 0; x < aHandler.mainKeys.length; x++) {
        if (aHandler.mainTexts[x] == lookText && aHandler.mainValues[x] == lookValue) {
            theKey = aHandler.mainKeys[x];
        }
    }
    for (var x = 0; x < aHandler.childKeys.length; x++) {
        if (theKey == aHandler.childKeys[x]) {
            var theOption = document.createElement('option');
            theOption.text = aHandler.childTexts[x];
            theOption.value = aHandler.childValues[x];
            try {
                theListBox.add(theOption, null);
            }
            catch (e) {
                theListBox.add(theOption);
            }
        }
    }
    theListBox.selectedIndex = 0;
    for (var x = 0; x < theListBox.options.length; x++) {
        theOption = theListBox.options[x];
        if (theOption.text == saveText && theOption.value == saveValue) {
            theListBox.selectedIndex = x;
        }
    }
    try {
        if (!skip) {
            aHandler.childHandler.Change(skip);
        }
    } catch (e) { }
}

/**
* Return the index into an array of a value/object
* @param {Array} array
* @param {Object} value
* @return {Number}
*/
function getArrayIndexForValue(array, value) {
    for (var x = 0; x < array.length; x++) {
        if (value == array[x]) {
            return x;
        }
    }
    return -1;
}

/**
* Return the index of the listbox option with certain value
* @param {ListBox} listBox
* @param {String} value
* @return {Number}
*/
function getListBoxIndexForValue(listBox, value) {
    for (var x = 0; x < listBox.options.length; x++) {
        theOptions = listBox.options[x];
        if (value == theOptions.value) {
            return x;
        }
    }
    return -1;
}

/**
* Return the index of the listbox option with certain text
* @param {ListBox} listBox
* @param {String} text
* @return {Number}
*/
function getListBoxIndexForText(listBox, text) {
    for (var x = 0; x < listBox.options.length; x++) {
        theOptions = listBox.options[x];
        if (text == theOptions.text) {
            return x;
        }
    }
    return -1;
}

/**
* Return the listbox as a string
* @param {ListBox} passed
* @return {String}
*/
function dumpListBox(passed) {
    var content = "<br>";
    for (var x = 0; x < passed.options.length; x++) {
        theOptions = passed.options[x];
        content = content + "&nbsp;&nbsp;&nbsp;t:" + theOptions.text + " v:" + theOptions.value + " s:" + theOptions.selected + "<br>";
    }
    return content + "&nbsp;&nbsp;&nbsp;sv:" + passed.value + " si:" + passed.selectedIndex + " ol:" + passed.options.length;
}

/*** log functions ***/
var logItDivObject;

/**
* Add log entry
* @param {String} textToLog
*/
function logIt(textToLog) {
    if (!logItDivObject) {
        logItDivObject = document.createElement("div");
        logItDivObject.id = "logItDivObject";
        logItDivObject.style.textAlign = "left";
        document.body.appendChild(logItDivObject);
        logItDivObject.innerHTML = "<h3>Log</h3>" + textToLog;
    }
    else {
        logItDivObject.innerHTML = logItDivObject.innerHTML + "<br>" + textToLog;
    }
}

/*** popup iframe ***/
var iframePopUp;
function iframeDisplayURL(url, left, top, width, height) {
    if (!iframePopUp) {
        // document.body.innerHTML += "<iframe id=\"iframePopUp\" style=\"z-Index: 998; display: none; position: absolute;\" src=\"" + url + "\"></iframe>";
        iframePopUp = document.createElement("iframe");
        iframePopUp.id = "iframePopUp";
        iframePopUp.src = url;
        iframePopUp.style.display = "none";
        iframePopUp.style.position = "absolute";
        iframePopUp.style.zIndex = "998";
        document.body.appendChild(iframePopUp);
    }
    else {
        iframePopUp = getObject("iframePopUp");
    }
    iframePopUp.style.display = "";
    iframePopUp.style.left = left + "px";
    iframePopUp.style.top = top + "px";
    iframePopUp.style.width = width + "px";
    iframePopUp.style.height = height + "px";
}
function iframeReturnValue(passed) {
    iframePopUp = getObject("iframePopUp");
    iframePopUp.style.display = "none";
    alert(passed);
}

/*** Head First Ajax functions ***/
/**
* Create request object
*/
function createRequest() {
    try {
        request = new XMLHttpRequest();
    } catch (tryMS) {
        try {
            request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (otherMS) {
            try {
                request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (failed) {
                request = null;
            }
        }
    }
    return request;
}

/**
* returns the event object
* @param {Object} e
*/
function getEvent(e) {
    var obj;
    if (!e) {
        // early version of IE
        obj = window.event;
    } else {
        // other browser
        obj = e;
    }
    return obj;
}

/**
* get object event handler fired upon
* @param {Object} e
*/
function getActivatedObject(e) {
    var obj;
    if (!e) {
        // early version of IE
        obj = window.event.srcElement;
    } else if (e.srcElement) {
        // IE 7 or later
        obj = e.srcElement;
    } else {
        // DOM Level 2 browser
        obj = e.target;
    }
    return obj;
}

/**
* Define Event Handler
* @param {Object} obj
* @param {Object} eventName
* @param {Object} handler
*/
function addEventHandler(obj, eventName, handler) {
    if (document.attachEvent) {
        obj.attachEvent("on" + eventName, handler);
    }
    else if (document.addEventListener) {
        obj.addEventListener(eventName, handler, false);
    }
}

/**
* Returns true if passed object is an array
* @param {Object} arg
*/
function isArray(arg) {
    if (typeof arg == 'object') {
        try {
            var criteria = arg.constructor.toString().match(/array/i);
            return (criteria != null);
        } catch (e) {
            return false;
        }
    }
    return false;
}

/*** Display Splash/Loading Page/Message ***/
// Add this line immediately after <body>
// <div id="myLoadingObject" style="display:none; position:absolute; z-index:999; border-style: dashed; border-width: 1px; filter:alpha(opacity=75); opacity: .75;"></div>
// Execute showSplashMessage in body script before loading anything else
// Execute hideSplashMessage as last thing in body.onload
function showSplashMessage(message) {
    var windowWidth = 1024;
    var windowHeight = 768;
    var top = 256;
    var left = 192;
    var height = 512;
    var width = 384;
    var topOffset = 0;
    var leftOffset = 0;
    try {
        windowWidth = getWindowWidth();
        windowHeight = getWindowHeight();
        top = Math.round(windowHeight / 4);
        // if (top < 256) top = 256;
        left = Math.round(windowWidth / 4);
        height = Math.round(windowHeight / 2);
        // if (height < 512) height = 512;
        // height = 50;
        width = Math.round(windowWidth / 2);
        leftOffset = getScrollLeft();
        topOffset = getScrollTop();
    } catch (e) { }
    top = top + topOffset;
    left = left + leftOffset;
    // var fieldContent = "<div style=\"position: absolute; width: 100%; left: 0px; top:" + Math.round((height / 2) - (isIE ? 32 : 46)) + "px\"><p style=\"filter:alpha(opacity=75); opacity: .75; font-family: arial, sans-serif; font-weight: bold; font-size: 12pt; padding: 3px; background-color: #d0d8e0; color: #002040; text-align: center;\"><br />" + message + "</p></div>";
    var fieldContent = "<div style=\"position: absolute; width: 100%; left: 0px; top:" + Math.round((height / 2) - (isIE ? 32 : 46)) + "px\"><p style=\"font-family: arial, sans-serif; font-weight: bold; font-size: 12pt; padding: 3px; background-color: #d0d8e0; color: #002040; text-align: center;\"><br />" + message + "</p></div>";
    var htmlDivObject = document.getElementById("myLoadingObject");
    htmlDivObject.style.backgroundColor = "#d0d8e0";
    htmlDivObject.innerHTML = fieldContent;
    htmlDivObject.style.top = top + "px";
    htmlDivObject.style.left = left + "px";
    htmlDivObject.style.width = width + "px";
    htmlDivObject.style.height = height + "px";
    htmlDivObject.style.display = "block";
}
function hideSplashMessage(delay) {
    if (delay && delay > 0) {
        window.setTimeout("hideSplashMessage(0)", delay);
    }
    else {
        document.getElementById("myLoadingObject").style.display = "none";
    }
}

/*** set a div, p, and img elements to screen size ***/
function setSplashSize(theDiv, thePar, theImg, topManualOffset, leftManualOffset) {
    var windowWidth = 1024;
    var windowHeight = 768;
    var top = 256;
    var left = 192;
    var height = 512;
    var width = 384;
    var topOffset = topManualOffset;
    var leftOffset = leftManualOffset;
    try {
        windowWidth = getWindowWidth();
        windowHeight = getWindowHeight();
        top = Math.round(windowHeight / 4);
        // if (top < 256) top = 256;
        left = Math.round(windowWidth / 4);
        height = Math.round(windowHeight / 2);
        // if (height < 512) height = 512;
        // height = 50;
        width = Math.round(windowWidth / 2);
    } catch (e) { }
    try {
        leftOffset = getScrollLeft() + leftManualOffset;
        topOffset = getScrollTop() + topManualOffset;
    } catch (e) { }
    top = top + topOffset;
    left = left + leftOffset;
    var htmlImgObject = document.getElementById(theImg);
    htmlImgObject.style.top = Math.round((height / 2) + (isIE ? 0 : 16)) + "px";
    htmlImgObject.style.left = Math.round((width / 2) - 36) + "px";
    var htmlParObject = document.getElementById(thePar);
    htmlParObject.style.width = "100%";
    htmlParObject.style.top = Math.round((height / 2) - 32) + "px";
    htmlParObject.style.left = "0px";
    var htmlDivObject = document.getElementById(theDiv);
    htmlDivObject.style.top = top + "px";
    htmlDivObject.style.left = left + "px";
    htmlDivObject.style.width = width + "px";
    htmlDivObject.style.height = height + "px";
    htmlDivObject.style.display = "block";
}

/*** Post values to a new page ***/
var postPage;
function postCreatePage(url) {
    postPage = document.createElement("form");
    postPage.setAttribute("method", "POST");
    postPage.setAttribute("action", url);
}
function postAddVariable(key, value) {
    var hiddenField = document.createElement("input");
    hiddenField.setAttribute("type", "hidden");
    hiddenField.setAttribute("name", key);
    hiddenField.setAttribute("value", value);
    postPage.appendChild(hiddenField);
}
function postPageExecute() {
    document.body.appendChild(postPage);
    postPage.submit();
}
function postCreatePageWindow(theWindow, url) {
    try {
        theWindow.document.write("<html>\r\n<head></head>\r\n<body>\r\n");
        theWindow.document.write("<form id='subform' method='post' action='" + url + "'>\r\n");
    } catch (e) { }
}
function postAddVariableWindow(theWindow, key, value) {
    try {
        theWindow.document.write("<input type='hidden' name='" + key + "' value='" + value + "' />\r\n");
    } catch (e) { }
}
function postPageExecuteWindow(theWindow) {
    try {
        theWindow.document.write("</form>\r\n<script>\r\ndocument.getElementById('subform').submit();\r\n</script>\r\n</body>\r\n</html>");
    } catch (e) { }
}

/*** Return the numeric portion of a string ***/
function getNumberValue(aString) {
    var goodChars = "0123456789.";
    var work = "";
    for (var x = 0; x < aString.length; x++) {
        var chr = aString.substr(x, 1);
        if (goodChars.indexOf(chr) > -1) {
            work = work + "" + chr;
        }
    }
    if (work.length == 0) {
        work = "0";
    }
    return work;
}