﻿/* BEGIN Global variables */

var gPopupLevel = 0;
var gPinned = false;
var gCustomPinned = false;
var gSearchSession = "";
var gServerObject = "";

var reWhitespace = /^\s+$/

/* END Global variables!!! */

function centerDisplay(pObjectName) {
    if (document.getElementById) {
        var lTop = 100;
        var lLeft = 250;

        var lObject = document.getElementById(pObjectName);

        if (lObject != null) {
            var lWidth = lObject.offsetWidth;
            var lHeight = lObject.offsetHeight;

            var lVertMiddle = 334; // middle of 1024 x 768 by default
            var lHorizMiddle = 512;

            if (typeof (window.innerWidth) == 'number') {
                // non-IE
                lVertMiddle = window.innerHeight / 2;
                // lHorizMiddle = window.innerWidth / 2;
            } else if (document.documentElement
                && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
                // IE 6+ in 'standards compliant mode'
                lVertMiddle = document.documentElement.clientHeight / 2;
                lHorizMiddle = document.documentElement.clientWidth / 2;
            } else if (document.body && (document.body.clientWidth || document.body.clienthHeight)) {
                // IE 4 compatible
                lVertMiddle = document.body.clientHeight / 2;
                lHorizMiddle = document.body.clientWidth / 2;
            }

            lTop = document.documentElement.scrollTop + lVertMiddle - lHeight / 2;
            lLeft = lHorizMiddle - lWidth / 2;

            if (lTop < 0) {
                // don't let tall items be position off the top of the page
                lTop = 10;
            }
            lObject.style.top = lTop + "px";
            lObject.style.left = lLeft + "px";
        }
    }
}

function centerDisplayHorizontal(pObjectName) {
    if (document.getElementById) {
        var lLeft = 250;

        var lObject = document.getElementById(pObjectName);

        if (lObject != null) {
            var lWidth = lObject.offsetWidth;

            var lHorizMiddle = 512;

            if (typeof (window.innerWidth) == 'number') {
                // non-IE
                lHorizMiddle = window.innerWidth / 2;
            } else if (document.documentElement
                && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
                // IE 6+ in 'standards compliant mode'
                lHorizMiddle = document.documentElement.clientWidth / 2;
            } else if (document.body && (document.body.clientWidth || document.body.clienthHeight)) {
                // IE 4 compatible
                lHorizMiddle = document.body.clientWidth / 2;
            }

            lLeft = lHorizMiddle - lWidth / 2;

            lObject.style.left = lLeft + "px";
        }
    }
}

function centerDisplayVertical(pObjectName) {
    if (document.getElementById) {
        var lTop = 100;

        var lObject = document.getElementById(pObjectName);

        if (lObject != null) {
            var lHeight = lObject.offsetHeight;

            var lVertMiddle = 334; // middle of 1024 x 768 by default

            if (typeof (window.innerWidth) == 'number') {
                // non-IE
                lVertMiddle = window.innerHeight / 2;
            } else if (document.documentElement
                && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
                // IE 6+ in 'standards compliant mode'
                lVertMiddle = document.documentElement.clientHeight / 2;
            } else if (document.body && (document.body.clientWidth || document.body.clienthHeight)) {
                // IE 4 compatible
                lVertMiddle = document.body.clientHeight / 2;
            }

            lTop = document.documentElement.scrollTop + lVertMiddle - lHeight / 2;

            if (lTop < 0) {
                // don't let tall items be position off the top of the page
                lTop = 10;
            }
            lObject.style.top = lTop + "px";
        }
    }
}


function centerDisplayServer() {
    if (document.getElementById) {
        var lTop = 100;
        var lLeft = 250;

        var lObject = document.getElementById(gServerObject);

        if (lObject != null) {
            var lWidth = lObject.offsetWidth;
            var lHeight = lObject.offsetHeight;

            var lVertMiddle = 334; // middle of 1024 x 768 by default
            var lHorizMiddle = 512;

            if (typeof (window.innerWidth) == 'number') {
                // non-IE
                lVertMiddle = window.innerHeight / 2;
                // lHorizMiddle = window.innerWidth / 2;
            } else if (document.documentElement
                && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
                // IE 6+ in 'standards compliant mode'
                lVertMiddle = document.documentElement.clientHeight / 2;
                lHorizMiddle = document.documentElement.clientWidth / 2;
            } else if (document.body && (document.body.clientWidth || document.body.clienthHeight)) {
                // IE 4 compatible
                lVertMiddle = document.body.clientHeight / 2;
                lHorizMiddle = document.body.clientWidth / 2;
            }

            lTop = document.documentElement.scrollTop + lVertMiddle - lHeight / 2;
            lLeft = lHorizMiddle - lWidth / 2;

            if (lTop < 0) {
                // don't let tall items be position off the top of the page
                lTop = 10;
            }
            lObject.style.top = lTop + "px";
            lObject.style.left = lLeft + "px";
        }
    }
}

function collapseExtraContactInfo(pDiv, pLinkDiv) {
    if (document.images) {
        document.getElementById(pDiv).style.display = "none";
        document.getElementById(pLinkDiv).innerHTML =
                      " <table border='0' cellpadding='1' cellspacing='0' style='margin: 0px;'>\n"
            	    + " <tr>\n"
                    + " <td>\n"
                    + "     <img src=\"images/buttons/plus.gif\" \n"
            	    + "     onclick=\"expandExtraContactInfo('" + pDiv + "', '" + pLinkDiv + "');\" />\n"
            	    + " </td>"
            	    + " <td style='color:#597DFA;' onclick=\"expandExtraContactInfo('" + pDiv + "', '" + pLinkDiv + "');\">\n"
            	    + "     View Additional Contact Information\n"
            	    + " </td>\n"
            	    + " </tr>\n"
            	    + " </table>\n"
            	;
    }
}

function copyDivContents(pFromDiv, pToDiv) {
    var lFromObj = null, lToObj = null;
    if (document.getElementById) {
        lFromObj = document.getElementById(pFromDiv);
        lToObj = document.getElementById(pToDiv);
    } else {
        lFromObj = document.all.pFromDiv;
        lToObj = document.all.pToDiv;
    }
    if (lFromObj != null && lToObj != null) {
        lToObj.innerHTML = lFromObj.innerHTML;
    }
}
//////////////////////////////////////////////////////////////
////////////   Drag and Drop Script   ////////////////////////
//////////////////////////////////////////////////////////////

/***********************************************
* Drag and Drop Script: © Dynamic Drive (http://www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

var dragobject = {
    z: 0, x: 0, y: 0, offsetx: null, offsety: null, targetobj: null, dragapproved: 0,
    initialize: function() {
        document.onmousedown = this.drag
        document.onmouseup = function() { this.dragapproved = 0 }
    },
    drag: function(e) {
        var evtobj = window.event ? window.event : e
        this.targetobj = window.event ? event.srcElement : e.target
        if (this.targetobj.className == "drag"
    || this.targetobj.className == "popup"
    || this.targetobj.className == "details_drag"
    || this.targetobj.className == "details") {
            this.dragapproved = 1
            if (isNaN(parseInt(this.targetobj.style.left))) { this.targetobj.style.left = 0 }
            if (isNaN(parseInt(this.targetobj.style.top))) { this.targetobj.style.top = 0 }
            this.offsetx = parseInt(this.targetobj.style.left)
            this.offsety = parseInt(this.targetobj.style.top)
            this.x = evtobj.clientX
            this.y = evtobj.clientY
            if (evtobj.preventDefault)
                evtobj.preventDefault()
            document.onmousemove = dragobject.moveit
        }
    },
    moveit: function(e) {
        var evtobj = window.event ? window.event : e
        if (this.dragapproved == 1) {
            this.targetobj.style.left = this.offsetx + evtobj.clientX - this.x + "px"
            this.targetobj.style.top = this.offsety + evtobj.clientY - this.y + "px"
            return false
        }
    }
}

dragobject.initialize()

function expandExtraContactInfo(pDiv, pLinkDiv) {
    if (document.images) {
        document.getElementById(pDiv).style.display = "block";
        document.getElementById(pLinkDiv).innerHTML =
                      " <table border='0' cellpadding='1' cellspacing='0' style='margin: 0px;'>\n"
            	    + " <tr>\n"
                    + " <td>\n"
                    + "     <img src=\"images/buttons/minus.gif\" \n"
            	    + "     onclick=\"collapseExtraContactInfo('" + pDiv + "', '" + pLinkDiv + "');\" />\n"
            	    + " </td>"
            	    + " <td style='color:#597DFA;' onclick=\"collapseExtraContactInfo('" + pDiv + "', '" + pLinkDiv + "');\">\n"
            	    + "     Hide Additional Contact Information\n"
            	    + " </td>\n"
            	    + " </tr>\n"
            	    + " </table>\n"
            	;
    }
}

function filterClearAll(pCheckbox, pGridViewClientID) {
    if (pCheckbox.checked) {
        // checked the "All" box, which will clear out all the other checkboxes
        alert("filterSelectAll[" + pGridViewClientID + "]");
        var lGrid = document.getElementById(pGridViewClientID);
        var lCell;
        if (lGrid != null) {
            if (lGrid.rows != null) {
                if (lGrid.rows.length > 0) {
                    for (i = 1; i < lGrid.rows.length; ++i) {
                        lCell = lGrid.rows[i].cells[0];

                        if (lCell != null) {
                            for (j = 0; j < lCell.childNodes.length; ++j) {
                                if (lCell.childNodes[j].className == "FilterActualCheckbox") {
                                    for (k = 0; k < lCell.childNodes[j].childNodes.length; ++k) {
                                        var lDeepestObject = lCell.childNodes[j].childNodes[k];
                                        if (lDeepestObject.type == "checkbox") {
                                            lDeepestObject.checked = false;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            } // if (lGrid.rows != null
        }
    }
}

function filterSelectOne(pCheckbox, pGridViewClientID) {
    if (pCheckbox.checked) {
        // one of the specific boxes checked, so uncheck the "All" box
        alert("filterSelectOne["+pGridViewClientID + "]");
        var lGrid = document.getElementById(pGridViewClientID);
        var lCell;

        if (lGrid != null) {
            if (lGrid.rows != null) {
                if (lGrid.rows.length > 0) {
                    lCell = lGrid.rows[0].cells[0];

                    for (j = 0; j < lCell.childNodes.length; ++j) {
                        for (k = 0; k < lCell.childNodes[j].childNodes.length; ++k) {
                            var lDeepestObject = lCell.childNodes[j].childNodes[k];
                            if (lDeepestObject.type == "checkbox") {
                                lDeepestObject.checked = false;
                            }
                        }
                    }
                }
            }
        }
    }
}

function findPosX(obj) {
    var curleft = 0;
    if (obj.offsetParent)
        while (1) {
        curleft += obj.offsetLeft;
        if (!obj.offsetParent)
            break;
        obj = obj.offsetParent;
    }
    else if (obj.x)
        curleft += obj.x;
    return curleft;
}

function findPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent) {
        while (obj.offsetParent) {
            curtop += obj.offsetTop - obj.scrollTop
            obj = obj.offsetParent;
        }
    } else if (obj.y) {
        curtop += obj.y;
    }
    return curtop;
}

function getCheckboxValue(pCheckbox) {
    if (pCheckbox.checked)
        return (true);
    else
        return (false);
}

function getDivContents(pDiv) {
    if (document.getElementById) {
        var lObject = document.getElementById(pDiv);
        if (lObject != null) {
            return (lObject.innerHTML);
        }
    }
    return ("");
}

function getListValue(pSelectObj) {
    if (pSelectObj == null)
        return("");
    else
        return(pSelectObj.options[pSelectObj.selectedIndex].value);
}

function getRadioValue(radioObj) {
    if (!radioObj)
        return "";
    var radioLength = radioObj.length;
    if (radioLength == undefined)
        if (radioObj.checked)
        return radioObj.value;
    else
        return "";
    for (var i = 0; i < radioLength; i++) {
        if (radioObj[i].checked) {
            return radioObj[i].value;
        }
    }
    return "";
}

// allow list value to also be returned by referring to it as a "select", which
// is what it REALLY is anyway
function getSelectValue(pSelectObj) {
    return (getListValue(pSelectObj));
}

// Custom Functions: used for mouseovers when additional button information is required.
function hideCustomDisplay(pDiv, pOverRide) {
    if (!gCustomPinned || pOverRide == "yes") {
        var lTitleObj = pDiv + "Title";
        var lBodyObj = pDiv + "Body";

        setVisible(pDiv, false);
        setDivContents(lTitleObj, "");
        
        setVisible(lBodyObj, false);
        setDivContents(lBodyObj, "");
    }
}

function hideBusy() {
    document.body.style.cursor = "default";
    setVisible("working", false);
}

function hideDetailDisplay() {
    if (!gPinned) {
        setVisible("detailDisplay", false);
        setDivContents("detailDisplayTitle", "");
        setVisible("detailDisplayTitle", false);
        setDivContents("detailDisplayBody", "");
        setVisible("detailDisplayBody", false);
    }
}

function hidePopup(pName) {
    --gPopupLevel;
    if (gPopupLevel == 1) {
        // level 2 popup - nested popups

        // reset the z-index to the default in case the pop-up is used in more than one location
        var lObject = document.getElementById(pName);
        lObject.style.zIndex = 10;

        //setVisible('blankout_deeper', false);
        setBlankOut("blankout_deeper", false);
        setVisible(pName, false);
    } else {
        // level 1 popup - normal popup
        //setVisible('blankout', false);
        setBlankOut("blankout", false);
        setVisible(pName, false);
    }
}

function highlightCustom(pObj, pColor) {
    pObj.style.background = pColor;
}

function highlightOn(pObj) {
    if (!gPinned) {
        // pObj.style.background = gMouseoverRowColor;
        pObj.className = "MouseOverRow";
    }
}

function highlightAltOff(pObj) {
    if (!gPinned) {
        // pObj.style.background = gMouseOutAltRowColor;
        pObj.className = "AlternateRow";
    }
}

function highlightCellOn(pObj) {
    pObj.style.background = "#F9EECE";
}

function highlightOff(pObj) {
    if (!gPinned) {
        pObj.className = "Row";
        // pObj.style.background = gMouseOutRowColor;
    }
}

function highlightCellOff(pObj, pColor) {
    pObj.style.background = pColor;
}

function iconButtonOver(pButton) {
    pButton.className = 'iconButtonHot';
}

function iconButtonOut(pButton) {
    pButton.className = 'iconButton';
}

function isEmpty(s) {
    return ((s == null) || (s.length == 0))
}

function isWhitespace(s) {   // Is s empty?
    return (isEmpty(s) || reWhitespace.test(s));
}

function leftDisplay(pObjectName) {
    if (document.getElementById) {
        var lObject = document.getElementById(pObjectName);
        var lContentObjectLeft = document.getElementById("wrap"); // find the starting left position

        lObject.style.left = lContentObjectLeft.offsetLeft + "px";
    }
}

function noClientAction() {
    // function to be used from buttons where no client side action is performed, but a call to SOME
    // javascript routine is necessary to add the button to the popup
}

// included in body tag to track when the user has closed the browser
function onPageUnload() {
    var lX = 0;
    var lY = 0;

    if (window.event) {
        if (window.event.pageX || window.event.pageY) {
            lX = window.event.pageX;
            lY = window.event.pageY;
        } else if (window.event.clientX || window.event.clientY) {
            lX = window.event.clientX;
            lY = window.event.clientY;
        }
    }

    if (lY < 0 && lX < 0) {
        trackBrowserClose();
    }
}

function pinCustomDisplay(pObjectName, pOverRide) {
    if (pOverRide != "yes")
        gCustomPinned = true;

    var lMainDiv = document.getElementById(pObjectName);
    
    var lTitle = pObjectName + "Title";
    var lBody = pObjectName + "Body";
    var lButtons = pObjectName + "Buttons";

    lTitle = document.getElementById(lTitle);
    lBody = document.getElementById(lBody);
    lButtons = document.getElementById(lButtons);

    var lTopCorner1 = pObjectName + "TopCorner1";
    var lTopCorner2 = pObjectName + "TopCorner2";
    var lTopCorner3 = pObjectName + "TopCorner3";
    var lTopCorner4 = pObjectName + "TopCorner4";

    lTopCorner1 = document.getElementById(lTopCorner1);
    lTopCorner2 = document.getElementById(lTopCorner2);
    lTopCorner3 = document.getElementById(lTopCorner3);
    lTopCorner4 = document.getElementById(lTopCorner4);

    var lBottomCorner1 = pObjectName + "BottomCorner1";
    var lBottomCorner2 = pObjectName + "BottomCorner2";
    var lBottomCorner3 = pObjectName + "BottomCorner3";
    var lBottomCorner4 = pObjectName + "BottomCorner4";

    lBottomCorner1 = document.getElementById(lBottomCorner1);
    lBottomCorner2 = document.getElementById(lBottomCorner2);
    lBottomCorner3 = document.getElementById(lBottomCorner3);
    lBottomCorner4 = document.getElementById(lBottomCorner4);

    lMainDiv.className = "popup";
    lTitle.className = "popup_title";
    lBody.className = "popup_content";

    lTopCorner2.style.background = "#0073A6";
    lTopCorner3.style.background = "#0073A6";
    lTopCorner4.style.background = "#0073A6";

    lBottomCorner1.style.background = "#ffffff";
    lBottomCorner2.style.background = "#ffffff";
    lBottomCorner3.style.background = "#ffffff";

    lButtons.style.display = 'block';

    //setVisible('blankout', true);
    setBlankOut("blankout", true);
}

function pinDetailDisplay() {
    //ruru
    gPinned = true;
    
    var lDetailDisplay = document.getElementById("detailDisplay");
    var lDetailDisplayTitle = document.getElementById("detailDisplayTitle");
    var lDetailDisplayBody = document.getElementById("detailDisplayBody");
    var lDetailDisplayButtons = document.getElementById("detailDisplayButtons");

    var lDetailTopCorner1 = document.getElementById("detailTopCorner1");
    var lDetailTopCorner2 = document.getElementById("detailTopCorner2");
    var lDetailTopCorner3 = document.getElementById("detailTopCorner3");
    var lDetailTopCorner4 = document.getElementById("detailTopCorner4");

    var lDetailBottomCorner1 = document.getElementById("detailBottomCorner1");
    var lDetailBottomCorner2 = document.getElementById("detailBottomCorner2");
    var lDetailBottomCorner3 = document.getElementById("detailBottomCorner3");
    var lDetailBottomCorner4 = document.getElementById("detailBottomCorner4");

    lDetailDisplay.className = "popup";
    lDetailDisplayTitle.className = "popup_title";
    lDetailDisplayBody.className = "popup_content";

    lDetailTopCorner2.style.background = "#0073A6";
    lDetailTopCorner3.style.background = "#0073A6";
    lDetailTopCorner4.style.background = "#0073A6";

    lDetailBottomCorner1.style.background = "#ffffff";
    lDetailBottomCorner2.style.background = "#ffffff";
    lDetailBottomCorner3.style.background = "#ffffff";

    lDetailDisplayButtons.style.display = 'block';

    //setVisible('blankout', true);
    setBlankOut("blankout", true);

}

function rightDisplay(pObjectName) {
    if (document.getElementById) {
        var lObject = document.getElementById(pObjectName);
        var lContentObjectRight = document.getElementById("wrap"); // find the starting left position
        lObject.style.left = (lContentObjectRight.offsetLeft + 996 - lObject.offsetWidth) + "px";
    }
}

function searchHighlightOn(pRow) {
    pRow.className = "SearchMouseoverRow";
}

function searchHighlightOff(pRow) {
    pRow.className = "SearchRow";
}

function setCheckboxValue(pCheckbox, pValue) {
    if (pValue == "TRUE"
        || pValue == "true"
        || pValue == "Y"
        || pValue == "y"
        || pValue == "YES"
        || pValue == "yes"
        || pValue == "ON"
        || pValue == "on"
        || pValue == "CHECKED"
        || pValue == "checked"
        || pValue == "1"
        )
        pCheckbox.checked = true;
    else
        pCheckbox.checked = false;
}

function setDetailTitle(pValue) {
    setDivContents("detailDisplayTitle", pValue);
}

function setDisplay(szDivID, iState) {
    if (document.layers) {  //NN4+
        document.layers[szDivID].display = iState ? "block" : "none";
    } else if (document.getElementById) {    //gecko(NN6) + IE 5+
        var obj = document.getElementById(szDivID);
        if (obj != null) {
            obj.style.display = iState ? "block" : "none";
        }
    } else if (document.all) { // IE 4
        if (document.all[szDivID] != null) {
            document.all[szDivID].style.display = iState ? "block" : "none";
        }
    }
}

function setDisplayX(pObjectName, pX) {
    // put object at specific location within display area
    if (document.getElementById) {
        var lLeft = 250;

        var lObject = document.getElementById(pObjectName);
        var lContents = document.getElementById("wrap");

        if (lObject != null) {
            // Get the left edge of the "contents" div, which
            // reflects the left side of the RAPID page, no matter
            // how wide the window is.
            lLeft = findPosX(lContents) + pX;

            lObject.style.left = lLeft + "px";
        }
    }
}

function setDisplayY(pObjectName, pY) {
    // center the object horizontally, but leave it at a specific Y position
    if (document.getElementById) {
        var lTop = document.documentElement.scrollTop + pY;
        var lLeft = 250;

        var lObject = document.getElementById(pObjectName);

        if (lObject != null) {
            var lWidth = lObject.offsetWidth;

            var lHorizMiddle = 512;

            if (document.documentElement
                && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
                // IE 6+ in 'standards compliant mode'
                lHorizMiddle = document.documentElement.clientWidth / 2;
            } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
                // IE 4 compatible
                lHorizMiddle = document.body.clientWidth / 2;
            }

            lLeft = lHorizMiddle - lWidth / 2;

            lObject.style.top = lTop + "px";
            lObject.style.left = lLeft + "px";
        }
    }
}

function setDisplayXY(pObjectName, pX, pY) {
    // put object at specific location within display area
    if (document.getElementById) {
        var lTop = document.documentElement.scrollTop + pY;
        var lLeft = 250;

        var lObject = document.getElementById(pObjectName);
        var lContents = document.getElementById("wrap");

        if (lObject != null) {
            // Get the left edge of the "contents" div, which
            // reflects the left side of the RAPID page, no matter
            // how wide the window is.
            lLeft = findPosX(lContents) + pX;

            lObject.style.top = lTop + "px";
            lObject.style.left = lLeft + "px";
        }
    }
}

function setDivContents(pObjName, pValue) {
    var lObject = null;
    if (document.getElementById) {
        lObject = document.getElementById(pObjName);
    } else {
        lObject = document.all[pObjName];
    }
    if (lObject != null) {
        lObject.innerHTML = pValue;
    }
}


function setRadioValue(radioObj, newValue) {
    if (!radioObj)
        return;
    var radioLength = radioObj.length;
    if (radioLength == undefined) {
        radioObj.checked = (radioObj.value == newValue.toString());
        return;
    }
    for (var i = 0; i < radioLength; i++) {
        radioObj[i].checked = false;
        if (radioObj[i].value == newValue.toString()) {
            radioObj[i].checked = true;
        }
    }
}

function setSelected(pTextBox) {
    pTextBox.select();
}
        
function setVisible(szDivID, iState) {
    if (document.layers) {  //NN4+
        document.layers[szDivID].visibility = iState ? "show" : "hide";
    } else if (document.getElementById) {    //gecko(NN6) + IE 5+
        var obj = document.getElementById(szDivID);
        if (obj != null) {
            obj.style.visibility = iState ? "visible" : "hidden";
        }
    } else if (document.all) { // IE 4
        if (document.all[szDivID] != null) {
            document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
        }
    }
}

function setVisibleCenter(pDiv, pState) {
    setVisible(pDiv, pState);
    centerDisplay(pDiv);
}

function setVisibleLeft(pDiv, pState) {
    // center the object first then left justify its position!
    centerDisplay(pDiv);
    leftDisplay(pDiv);
    setVisible(pDiv, pState);
}

function setVisibleRight(pDiv, pState) {
    // center the object first then right justify its position!
    centerDisplay(pDiv);
    rightDisplay(pDiv);
    setVisible(pDiv, pState);
}

function showBusy() {
    document.body.style.cursor = "wait";
    setVisibleCenter("working", true);
}

// Show Custom Functions: used for mouseovers when additional button information is required.
function showCustomDisplay(pDiv) {
    setVisibleCenter(pDiv, true);

    var displayTitle = pDiv + "Title";
    setVisible(pDiv, true);
}

function showCustomDisplayXY(pDiv, pOffsetX, pY) {
    setDisplayXY(pDiv, pOffsetX, pY);
    setVisible(pDiv, true);
}

function showCustomDisplayX(pDiv,pX) {
    setDisplayX(pDiv, pX);
    setVisible(pDiv, true);
}



function showDetailDisplay() {
    setVisibleCenter("detailDisplay", true);
    setVisible("detailDisplayTitle", true);
}

function showDetailDisplayY(pY) {
    setDisplayY("detailDisplay", pY);
    setVisible("detailDisplay", true);
    setVisible("detailDisplayTitle", true);
}

function showDetailDisplayXY(pOffsetX, pY) {
    setDisplayXY("detailDisplay", pOffsetX, pY);
    setVisible("detailDisplay", true);
    setVisible("detailDisplayTitle", true);
}

function showDetailDisplayLeft() {
    setVisibleLeft("detailDisplay", true);
}

function showDetailDisplayRight() {
    setVisibleRight("detailDisplay", true);
}

function showPopup(pName) {
    ++gPopupLevel;
    if (gPopupLevel > 2) {
        --gPopupLevel;    // back it back to the acceptable level
        alert("Message to developers: We only currently support nesting pop-ups two levels deep.  Try another approach.");
    } else if (gPopupLevel > 1) {
        // level 2 popup - nested popups
    
        // bump up the z-index for the nested popup so that it is above everything else
        var lObject = document.getElementById(pName);
        lObject.style.zIndex = 25;

        //setVisible('blankout_deeper', true);
        setBlankOut("blankout_deeper", true);
        setVisibleCenter(pName, true);
    } else {
    // level 1 popup - normal popup
        var lObject = document.getElementById(pName);
        lObject.style.zIndex = 20;
        setBlankOut("blankout", true);
        setVisibleCenter(pName, true);
    }
}

function showPopupSafe(pName) {
    // Returning to basics.  The original showPopup() looked something like this (note: the zIndex manipulation).
    // Somewhere along the way, that changed.  Returning showPopup() to its original state breaks too many
    // things at this late date, so we need a "safe" version that minimizes the impact on the rest of the
    // website.  It hurts, but it's safe.
    ++gPopupLevel;
    if (gPopupLevel > 2) {
        --gPopupLevel;    // back it back to the acceptable level
        alert("Message to developers: We only currently support nesting pop-ups two levels deep.  Try another approach.");
    } else if (gPopupLevel > 1) {
        // level 2 popup - nested popups

        // bump up the z-index for the nested popup so that it is above everything else
        var lObject = document.getElementById(pName);
        lObject.style.zIndex = 20;

        setBlankOut("blankout_deeper", true);
        setVisibleCenter(pName, true);
    } else {
        // level 1 popup - normal popup
        var lObject = document.getElementById(pName);
        setBlankOut("blankout", true);
        setVisibleCenter(pName, true);
    }
}

function showSuccessServer() {
    document.getElementById(gServerObject).style.visibility = "visible";
    document.getElementById(gServerObject).style.zIndex = 30;
    document.getElementById(gServerObject).style.width = "300px";
    centerDisplayServer();
}

function trackBrowserClose() {
    // browser close functionality not working, but left it here in case we re-incorporate it
    submitBatchBackground('Track.aspx?action=browser_close');
}

function trackClick() {
    callAjaxBatch('Track.aspx?action=click');
}

function trackAction(pAction, pComment) {
    callAjaxBatch('Track.aspx?action='+pAction+'&comment_text='+encodeURI(pComment));
}


function unpinCustomDisplay(pObjectName, pOverRide) {
    if (pOverRide != "yes")
        gCustomPinned = false;
    
    var lMainDiv = document.getElementById(pObjectName);

    var lTitle = pObjectName + "Title";
    var lBody = pObjectName + "Body";
    var lButtons = pObjectName + "Buttons";

    lTitle = document.getElementById(lTitle);
    lBody = document.getElementById(lBody);
    lButtons = document.getElementById(lButtons);

    var lTopCorner1 = pObjectName + "TopCorner1";
    var lTopCorner2 = pObjectName + "TopCorner2";
    var lTopCorner3 = pObjectName + "TopCorner3";
    var lTopCorner4 = pObjectName + "TopCorner4";

    lTopCorner1 = document.getElementById(lTopCorner1);
    lTopCorner2 = document.getElementById(lTopCorner2);
    lTopCorner3 = document.getElementById(lTopCorner3);
    lTopCorner4 = document.getElementById(lTopCorner4);

    var lBottomCorner1 = pObjectName + "BottomCorner1";
    var lBottomCorner2 = pObjectName + "BottomCorner2";
    var lBottomCorner3 = pObjectName + "BottomCorner3";
    var lBottomCorner4 = pObjectName + "BottomCorner4";

    lBottomCorner1 = document.getElementById(lBottomCorner1);
    lBottomCorner2 = document.getElementById(lBottomCorner2);
    lBottomCorner3 = document.getElementById(lBottomCorner3);
    lBottomCorner4 = document.getElementById(lBottomCorner4);

    lMainDiv.className = "Details";
    lTitle.className = "DetailsTitle";
    lBody.className = "DetailsBody";

    lTopCorner2.style.background = "#F9EECE";
    lTopCorner3.style.background = "#F9EECE";
    lTopCorner4.style.background = "#F9EECE";

    lBottomCorner1.style.background = "#F9EECE";
    lBottomCorner2.style.background = "#F9EECE";
    lBottomCorner3.style.background = "#F9EECE";

    lButtons.style.display = 'none';
   
    if (pOverRide != "yes") {
        //setVisible('blankout', false);
        setBlankOut("blankout", false);
        hideCustomDisplay(pObjectName);
    }
}

function unpinDetailDisplay() {
    gPinned = false;

    var lDetailDisplay = document.getElementById("detailDisplay");
    var lDetailDisplayTitle = document.getElementById("detailDisplayTitle");
    var lDetailDisplayBody = document.getElementById("detailDisplayBody");
    var lDetailDisplayButtons = document.getElementById("detailDisplayButtons");

    var lDetailTopCorner1 = document.getElementById("detailTopCorner1");
    var lDetailTopCorner2 = document.getElementById("detailTopCorner2");
    var lDetailTopCorner3 = document.getElementById("detailTopCorner3");
    var lDetailTopCorner4 = document.getElementById("detailTopCorner4");

    var lDetailBottomCorner1 = document.getElementById("detailBottomCorner1");
    var lDetailBottomCorner2 = document.getElementById("detailBottomCorner2");
    var lDetailBottomCorner3 = document.getElementById("detailBottomCorner3");
    var lDetailBottomCorner4 = document.getElementById("detailBottomCorner4");

    lDetailDisplay.className = "Details";
    lDetailDisplayTitle.className = "DetailsTitle";
    lDetailDisplayBody.className = "DetailsBody";

    lDetailTopCorner2.style.background = "#F9EECE";
    lDetailTopCorner3.style.background = "#F9EECE";
    lDetailTopCorner4.style.background = "#F9EECE";

    lDetailBottomCorner1.style.background = "#F9EECE";
    lDetailBottomCorner2.style.background = "#F9EECE";
    lDetailBottomCorner3.style.background = "#F9EECE";

    lDetailDisplayButtons.style.display = 'none';

    setVisible('blankout', false);
    hideDetailDisplay();

}

function setBlankOut(pDiv, pValue) {
    if (pValue) {
        if (document.getElementById) {
            var lBlank = document.getElementById(pDiv);
            var lFooter = document.getElementById('footer');

            if (lBlank != null && lFooter != null) {
                lBlank.style.height = (findPosY(lFooter) + lFooter.offsetHeight) + "px";
            }
        }
        setVisible(pDiv, true);
    } else {
        setVisible(pDiv, false);
    }
}

function newExternalWindow(pUrl) {
    var lUrl = escape(pUrl);
    window.open(pUrl, null, "width=1024,height=600,scrollbars=yes,toolbar=yes,status=yes,menubar=yes,location=yes,resizable=yes", null);
}


function showCustDetails(pCustDbId, pName) {
    // set the title for the mouseover
    setDivContents("custDetailsTitle", pName);

    callAjax('ContactDetailsDisplay.aspx?cust_db_id=' + pCustDbId, 'custDetailsBody');
    showCustomDisplayX("custDetails", 10);
}

function pinCustDetails(pInviDbId, pEzBuyFlag) {
    pinCustomDisplay('custDetails', 'no');
    ++gPopupLevel;
}

function unpinCustDetails() {
    unpinCustomDisplay('custDetails', 'no');
    --gPopupLevel;
}

function showHint(pObj, pDiv) {
    var status = getDivContents(pDiv + '_status');

    if (status != "SEEN") {
        // only display the hint if the user hasn't already seen it
        putHintClose(pObj, pDiv);
        setVisible(pDiv, true);
    }
    // showCustomDisplayXY("Hint",pX,pY);
}

function hideHint(pDiv) {
    setVisible(pDiv, false);
    callAjaxBatch('UtilPage.aspx?mode=hint&name=' + pDiv);
}

function putHintClose(pObj, pDiv) {
    var lDivObj = document.getElementById(pDiv);
    if (pObj != null && lDivObj != null) {
        var lX = findPosX(pObj) - 150;
        var lY = findPosY(pObj) + pObj.offsetHeight;

        // var lWrap = document.getElementById("wrap");

        lDivObj.style.left = lX + "px";
        lDivObj.style.top = lY + "px";
    }
}

 



