﻿// ApplicationFunctions JavaScript

/*
#########################################################################################
## Global Section - All variables and/or constants                                     ##
#########################################################################################
*/

//Global Constants
var COMBOBOX_SWITCH_POST_PAGE = "Includes/ComboBoxProcess.aspx";
var HIDDEN_FRAME_NAME = "fraHiddenFrame";
var SERVER_PING_TIME = 600000;
var SERVER_LOAD_PAGE = "Ping.aspx";
var IFRAME_ERROR_PAGE = "IFrameError";

//Global Variables
var m_bIsIE;
var m_iAnimationTimer;
var m_sRoot;
var m_sImageRoot;
var xMousePos = 0; // Horizontal position of the mouse on the screen
var yMousePos = 0; // Vertical position of the mouse on the screen
var xMousePosMax = 0; // Width of the page
var yMousePosMax = 0; // Height of the page
var m_iAcceptDialogIndicator; // if multiple pages are using the function indicates which logic to run
var m_iAcceptDialogIndicatorURL; // directs where to redirect the page 

// Global Functions

// Set Netscape up to run the "captureMousePosition" function whenever
// the mouse is moved. For Internet Explorer and Netscape 6, you can capture
// the movement a little easier.
if (document.layers) { // Netscape
    document.captureEvents(Event.MOUSEMOVE);
    document.onmousemove = captureMousePosition;
}
else if (document.all) { // Internet Explorer
    document.onmousemove = captureMousePosition;
}
else if (document.getElementById) { // Netcsape 6
    document.onmousemove = captureMousePosition;
}

// captureMousePosition
// captures the Mouse Position
// 
// @author	dspolarich - 3/08/06
// @edit	-
// @param	none
// @return	none
function captureMousePosition(e) {
    if (document.layers) {
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth + window.pageXOffset;
        yMousePosMax = window.innerHeight + window.pageYOffset;
    }
    else if (document.all) {
        if (window.event != null && document.body != null) {
            xMousePos = window.event.x + document.body.scrollLeft;
            yMousePos = window.event.y + document.body.scrollTop;
            xMousePosMax = document.body.clientWidth + document.body.scrollLeft;
            yMousePosMax = document.body.clientHeight + document.body.scrollTop;
        }
    }
    else if (document.getElementById) {
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth + window.pageXOffset;
        yMousePosMax = window.innerHeight + window.pageYOffset;
    }
    //FOR TESTING PURPOSES ONLY
    //window.status = "xMousePos=" + xMousePos + ", yMousePos=" + yMousePos + ", xMousePosMax=" + xMousePosMax + ", yMousePosMax=" + yMousePosMax;
}

// initialize
// sets up page with all required data
// 
// @author	kgrove - 3/08/06
// @edit	tom.cole - 05/07/2006:  Set the pingServer to execute after a timeout not on initial load
// @param	none
// @return	none
function initialize() {
    setBrowserType();
    window.setTimeout("pingServer();", SERVER_PING_TIME);
}


// sizeWindowLock
// sizes the window lock when the window is resized
// 
// @author	kgrove - 4/17/06
// @edit	-
// @param	none
// @return	none
function sizeWindowLock() {
    var oWindowLock = document.getElementById("fraWindowLock");
    var iFrame = false;

    //check for IFRAME
    if (oWindowLock == null) {
        oWindowLock = parent.document.getElementById("fraWindowLock");
        iFrame = true;
    }

    if (m_bIsIE) {
        oWindowLock.style.filter = "alpha(opacity=50)";
    }
    else {
        oWindowLock.style.opacity = .5;
    }

    if (iFrame == true) {
        oWindowLock.style.width = parent.document.documentElement.clientWidth + "px";
        oWindowLock.style.height = parseInt(parent.document.documentElement.scrollHeight) + "px";
    }
    else {
        oWindowLock.style.width = document.documentElement.clientWidth + "px";
        oWindowLock.style.height = parseInt(document.documentElement.scrollHeight) + "px";
    }

}


// centerDHTMLWindows
// centers all of the DHTML windows
// 
// @author	kgrove - 4/18/06
// @edit	-
// @param	none
// @return	none
function centerDHTMLWindows() {
    var sDHTMLWindows = "tblAcceptDialog,tblOkActionDialog,tblOkDialog,tblSentQuoteDialog,tblMembershipPromptDialog,tblProgressDialog";
    var oArray = sDHTMLWindows.split(",");
    var iFrame = false;

    for (i = 0; i < oArray.length; i++) {
        try {

            var oDHTMLWindow = document.getElementById(oArray[i]);

            //check for IFRAME
            if (oDHTMLWindow == null) {
                oDHTMLWindow = parent.document.getElementById(oArray[i]);
                iFrame = true;
            }

            var iHeight = oDHTMLWindow.clientHeight;
            var iScreenHeight; 

            //check for IFRAME
            if (iFrame == true) {
                iScreenHeight = parent.document.documentElement.offsetHeight;
            }
            else {
                iScreenHeight = document.documentElement.offsetHeight;
            }

            // If the window is already being displayed don't move its position.
            if (oDHTMLWindow.style.display == "") {
                continue;
            }
            //if(m_bIsIE != true AND m_bIsIE != false )
            {
                setBrowserType();
            }
            if (iHeight <= 0) {
                iHeight = 400;
            }
            if (!m_bIsIE) {
                iScreenHeight = window.innerHeight;
            }
            var iTop;
            var iLeft;

            //check for IFRAME
            if (iFrame == true) {
                iTop = ((iScreenHeight - iHeight) / 2) + parent.document.documentElement.scrollTop;
                iLeft = parseInt((parseInt(parent.document.documentElement.clientWidth) - parseInt(oDHTMLWindow.style.width)) / 2);
            }
            else {
                iTop = ((iScreenHeight - iHeight) / 2) + document.documentElement.scrollTop;
                iLeft = parseInt((parseInt(document.documentElement.clientWidth) - parseInt(oDHTMLWindow.style.width)) / 2);
            }


            if (iLeft < 0) {
                var newWidth = WindowWidth();
                iLeft = (newWidth - parseInt(oDHTMLWindow.style.width)) / 2
            }


            oDHTMLWindow.style.top = iTop + "px";
            oDHTMLWindow.style.left = iLeft + "px";
        }
        catch (e) {
            alert(e);
        }
    }
}

function WindowWidth() {
    var myWidth = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth;

    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
    }
    return myWidth;
}

// DHTMLWindowsAtHeightForGallery
// centers all of the DHTML windows at a height
// 
// @author	JRoberts - 11/23/07
// @edit	-
// @param	oHeight - what height to set the window at
// @return	none
function DHTMLWindowsAtHeightForGallery(oHeight) {
    var sDHTMLWindows = "tblAcceptDialog,tblOkActionDialog,tblImgViewer";
    var oArray = sDHTMLWindows.split(",");

    try {
        for (i = 0; i < oArray.length; i++) {
            var oDHTMLWindow = document.getElementById(oArray[i]);
            var iHeight = oHeight;
            var iScreenHeight = document.documentElement.offsetHeight;

            //check for IFRAME
            if (oDHTMLWindow == null) {
                oDHTMLWindow = parent.document.getElementById(oArray[i]);
            }

            // If the window is already being displayed don't move its position.
            if (oDHTMLWindow.style.display == "") {
                continue;
            }
            //if(m_bIsIE != true AND m_bIsIE != false )
            {
                setBrowserType();
            }

            //var iTop = ((iScreenHeight - iHeight) / 2) + document.documentElement.scrollTop;   
            var iLeft = parseInt((parseInt(document.documentElement.clientWidth) - parseInt(oDHTMLWindow.style.width)) / 2);
            iLeft = iLeft - 43;
            //oDHTMLWindow.style.top = iTop + "px";
            oDHTMLWindow.style.top = oHeight + "px";
            oDHTMLWindow.style.left = iLeft + "px";
        }
    }
    catch (e) {
    }
}

// pingServer
// pings the server every x minutes to keep the session alive
// 
// @author	kgrove - 04/13/06
// @edit	-
// @param	none
// @return	none
function pingServer() {
    xmlPost(m_sRoot + SERVER_LOAD_PAGE);
    window.setTimeout("pingServer();", SERVER_PING_TIME);
}


// xmlPost
// post to url
// 
// @author	kgrove - 04/18/06
// @edit	-
// @param	p_sURL - url to post to
//          p_sPostData - data to send to the page
// @return	request object
function xmlPost(p_sURL, p_sPostData) {
    var e;
    try {
        xmlRequestObj = new XMLHttpRequest();
    }
    catch (e) {
        try {
            xmlRequestObj = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (e) { }
    }
    xmlRequestObj.open("POST", p_sURL, true);
    xmlRequestObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlRequestObj.send(p_sPostData);
    return xmlRequestObj;
}


// AjaxRequest
// ???
// 
// @author	tcole - ??/??/??
// @edit	-
// @param	url - ???
//          postData - ???
//          callback - ???
// @return	none
function AjaxRequest(url, postData, callback) {
    var e;
    try {
        xmlRequestObj = new XMLHttpRequest();
    }
    catch (e) {
        try {
            xmlRequestObj = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (e) { }
    }
    xmlRequestObj.onreadystatechange = callback;
    xmlRequestObj.open("POST", url, true);
    xmlRequestObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlRequestObj.send(postData);
    return xmlRequestObj;
}


// setBrowserType
// determines browser type and set global m_bIsIE variable
// 
// @author	kgrove - 03/08/06
// @edit	-
// @param	none
// @return	none
function setBrowserType() {
    var sBrowserType = navigator.appName;

    sBrowserType = sBrowserType.toLowerCase();
    m_bIsIE = false;
    if (sBrowserType == "microsoft internet explorer") {
        m_bIsIE = true;
        return true;
    }
    return false;
}


// switchComboBoxPost
// posts required data to the combobox processing page used for combobox loading
// 
// @author	kgrove - 03/08/06
// @edit	-
// @param	p_oElement - element which is calling for the switch
//          p_sStoredProcedure - name of stored procedure combobox is linked to
//          p_sDataValueField - name of database column to associate combobox's value with
//          p_sDataTextField - name of database column to associate combobox's text with
//          p_sDestinationId - id of combobox which is being loaded
// @return	none
function switchComboBoxPost(p_oElement, p_sStoredProcedure, p_sDataValueField,
                            p_sDataTextField, p_sDestinationId, p_sDestinationName,
                            p_sSelectText, p_sSelectedValue) {
    var oFrame = document.getElementById(HIDDEN_FRAME_NAME);
    var sParams = buildParamValueString(p_oElement);

    window.frames[HIDDEN_FRAME_NAME].location.replace(m_sRoot + COMBOBOX_SWITCH_POST_PAGE + "?sParams=" + sParams + "&sStoredProcedure=" + p_sStoredProcedure
            + "&sDataValueField=" + p_sDataValueField + "&sDataTextField=" + p_sDataTextField
            + "&sDestinationId=" + p_sDestinationId + "&sDestinationName=" + p_sDestinationName
            + "&sSelectText=" + p_sSelectText + "&sSelectedValue=" + p_sSelectedValue);

    _removeOption(p_oElement, "0");
}


// buildParamValueString
// builds the Param/Value string for posting
// 
// @author	kgrove - 03/09/06
// @edit	-
// @param	p_oElement - element which the string is to be built for
// @return	retuns the param/value list
function buildParamValueString(p_oElement) {
    var sParams = p_oElement.getAttribute("Params");
    var sValues = p_oElement.getAttribute("Values");
    var aParams = new Array();
    var aValues = new Array();
    var aParams = sParams.split(",");
    var aValues = sValues.split(",");
    var sParamValues = "";
    var sComma = "";
    var iValue = "";

    for (i = 0; i < aParams.length; i++) {
        iValue = eval("document.getElementById('" + aValues[i] + "').value;");
        sParamValues += aParams[i] + "|" + iValue;
        sComma = ",";
        if (i == (aParams.length - 1)) {
            sComma = "";
        }
        sParamValues += sComma;
    }

    return sParamValues;
}


// swapComboBox
// swaps the HTML from one combobox (source) to another combobox (destination)
// 
// @author	kgrove - 03/08/06
// @edit	-
// @param	p_sComboBoxId - the id of the element
//          p_bIsParent - indicates if source is the parent to the destination element
// @return	none
function swapComboBox(p_sComboBoxId, p_bIsParent) {
    var oSource = document.getElementById(p_sComboBoxId);
    var oDocument = document;
    if (p_bIsParent) {
        oDocument = parent.document;
    }
    var oDestination = oDocument.getElementById(p_sComboBoxId);

    if (m_bIsIE) {
        var onchangeEvent = oDestination.getAttribute("onchange_event");
        var sParams = oDestination.getAttribute("Params");
        var sValues = oDestination.getAttribute("Values");

        oSource.style.position = oDestination.style.position;
        oSource.style.width = oDestination.style.width;
        oSource.style.left = oDestination.style.left;
        oSource.style.top = oDestination.style.top;
        oSource.style.height = oDestination.style.height;

        oSource.setAttribute("onchange_event", onchangeEvent);
        oSource.setAttribute("Params", sParams);
        oSource.setAttribute("Values", sValues);
        if (onchangeEvent != null) {
            oSource.onchange = onchangeEvent;
        }
    }
    replaceHTML(oDestination, oSource);
}


// getOuterHTML
// gets the outerHTML of an element
// 
// @author	kgrove - 03/08/06
// @edit	-
// @param	p_oElement - object which outerHTML is to be returned for
// @return	the outer HTML of the element
function getOuterHTML(p_oElement) {
    var sElement = "";

    switch (p_oElement.nodeType) {
        case 1: // ELEMENT_NODE
            sElement += "<" + p_oElement.nodeName;
            for (var i = 0; i < p_oElement.attributes.length; i++) {
                if (p_oElement.attributes.item(i).nodeValue != null) {
                    sElement += " "
                    sElement += p_oElement.attributes.item(i).nodeName;
                    sElement += "=\"";
                    sElement += p_oElement.attributes.item(i).nodeValue;
                    sElement += "\"";
                }
            }

            if (p_oElement.childNodes.length == 0 && leafElems[p_oElement.nodeName])
                sElement += ">";
            else {
                sElement += ">";
                sElement += p_oElement.innerHTML;
                sElement += "<" + p_oElement.nodeName + ">"
            }
            break;

        case 3:   //TEXT_NODE
            sElement += p_oElement.nodeValue;
            break;

        case 4: // CDATA_SECTION_NODE
            sElement += "<![CDATA[" + p_oElement.nodeValue + "]]>";
            break;

        case 5: // ENTITY_REFERENCE_NODE
            sElement += "&" + p_oElement.nodeName + ";"
            break;

        case 8: // COMMENT_NODE
            sElement += "<!--" + p_oElement.nodeValue + "-->"
            break;
    }

    return sElement;
}


// replaceHTML
// replaces the outerHTML of the destination element with the outerHTML of the source element
// 
// @author	kgrove - 03/08/06
// @edit	-
// @param	p_oDestination - destination object
//          p_oSource - source object
// @return	none    
function replaceHTML(p_oDestination, p_oSource) {
    if (m_bIsIE) {
        p_oDestination.outerHTML = p_oSource.outerHTML;
        return true;
    }
    else {
        p_oDestination.innerHTML = p_oSource.innerHTML;
        p_oDestination.disabled = false;
        return true;
    }
}


// replaceOuterHTMlFireFox
// replaces the outerHTML of the destination element with the outerHTML of the source element (FireFox)
// 
// @author	kgrove - 03/08/06
// @edit	-
// @param	p_oDestination - destination object
//          p_oSource - source object
// @return	none 
function replaceOuterHTMlFireFox(p_oSource, p_oDestination) {
    var sSourceOuterHTML = getOuterHTML(p_oSource);
    var innerHTML = '';
    var sEndTagName = sSourceOuterHTML.indexOf(' ');
    var sTag = sSourceOuterHTML.substr(1, (sEndTagName - 1));
    var oNewNode = document.createElement(sTag);
    var sFirstCloseTag = sSourceOuterHTML.indexOf('>');
    var sParse = sSourceOuterHTML.substr(sEndTagName + 1, sFirstCloseTag - (sEndTagName + 1));

    p_oDestination.parentNode.replaceChild(oNewNode, p_oDestination);
    while (sParse.length > 0) {
        if (sParse.substr(0, 1) == ' ') {
            sParse = sParse.substr(1, sParse.length);
        }
        else {
            var iStart = sParse.indexOf('="');
            var sAttributeName = sParse.substr(0, iStart);
            var iEnd = (sParse.indexOf('"', (iStart + 2))) - (iStart + 2);
            var sAttributeValue = sParse.substr(iStart + 2, iEnd);
            oNewNode.setAttribute(sAttributeName, sAttributeValue);
            sParse = sParse.substr(iStart + iEnd + 4, sParse.length);
        }
    }

    if (sSourceOuterHTML.substr(sFirstCloseTag - 1, 1) == '/') {
        innerHTML = sSourceOuterHTML.substr(sFirstCloseTag + 1, sSourceOuterHTML.length);
    }
    else {
        var i = sSourceOuterHTML.length - 2;
        var sStartClose = '';
        while (sStartClose != "<" && i > 0) {
            sStartClose = sSourceOuterHTML.substr(i, 1);
            i--;
        }
        innerHTML = sSourceOuterHTML.substr(sFirstCloseTag + 1, i - sFirstCloseTag);
    }
    oNewNode.innerHTML = innerHTML;
}


// _removeOption
// removes the specified option from a select combo box
//
// @author	kgrove - 3/10/06
// @param	p_0Element - the combo box element
//			p_iValue - value of the item to be removed
// @return	true - if item was found and removed
function _removeOption(p_oElement, p_iValue) {
    for (var i = 0; i < p_oElement.length; i++) {
        if (p_oElement[i].value == p_iValue) {
            p_oElement.remove(i);
            return true;
        }
    }
}


// _addOption
// adds an option to the combo box specified
//
// @author	kgrove - 3/10/06
// @param	p_oElement - the combo box element
//			p_sOptionName - name to be put inbetween the option tags
//			p_sOptionName - value to be given for the option
// @return	index of the created option
function _addOption(p_oElement, p_sOptionName, p_iOptionValue) {
    var iNextOption = p_oElement.options.length;
    p_oElement.options[iNextOption] = new Option(p_sOptionName, p_iOptionValue);
    //sortOptions(p_oElement);
    for (var i = 0; i < p_oElement.length; i++) {
        if (p_oElement[i].value == p_iOptionValue) {
            return i;
        }
    }
    return iNextOption;
}


// sortOptions
// Sorts the given select based on the text.
// 
// @author	kgrove - 03/10/06
// @edit	-
// @param	p_oSelect - Select containing items to sort
// @return	none
function sortOptions(p_oSelect) {
    var iItems = p_oSelect.options.length;
    var aTempArray = new Array(iItems);

    for (i = 0; i < iItems; i++) {
        aTempArray[i] = copyOption(p_oSelect.options[i]);
    }
    aTempArray.sort(compareOptionText);
    for (i = 0; i < iItems; i++) {
        p_oSelect.options[i] = copyOption(aTempArray[i]);
    }
}


// copyOption
// Builds a new options and copies any custom attributes to from the source.
// 
// @author	kgrove - 03/10/06
// @edit	-
// @param	p_oSourceOption - Source option to copy
// @return	none
function copyOption(p_oSourceOption) {
    var oOption = new Option(p_oSourceOption.text, p_oSourceOption.value);
    var iAttributes = p_oSourceOption.attributes.length;
    var iLoop;

    for (iLoop = iAttributes - 1; iLoop > 0; iLoop--) {
        if (p_oSourceOption.attributes[iLoop].name == "value"
			|| p_oSourceOption.attributes[iLoop].name == "selected") {
            break;
        }
        oOption.setAttribute(
			p_oSourceOption.attributes[iLoop].name,
			p_oSourceOption.attributes[iLoop].value);
    }
    return oOption;
}


// stripDollar
// removes all formating from the string
//
// @author	kgrove - 3/14/2006
// @param	p_sValue - value to be stripped
// @return	none
function stripDollar(p_sValue) {
    p_sValue = p_sValue.replace("$", "");
    p_sValue = p_sValue.replace("(", "-");
    p_sValue = p_sValue.replace(")", "");
    for (i = 0; i <= p_sValue.length; i++) {
        if (p_sValue.charAt(i) == ",") {
            p_sValue = p_sValue.replace(",", "");
        }
    }
    return p_sValue;
}


// formatCurrency
// formats the string to a currency format
//
// @author	kgrove - 3/14/2006
// @param	p_sValue - value to be formatted
// @return	none
function formatCurrency(p_sValue) {
    var bIsBoolean = false;
    if (p_sValue.length == 0) {
        return;
    }
    //if the first character is a decimal point, format it and exit
    if (p_sValue.charAt(0) == ".") {
        p_sValue = "$0" + p_sValue;
        return;
    }
    //if the first character is a negative sign and the second character is a decimal point, format it and exit
    if ((p_sValue.charAt(0) == "-") && (p_sValue.charAt(1) == ".")) {
        p_sValue = "($0" + p_sValue.substring(1, p_sValue.length) + ")";
        return
    }
    //Determine if the field is negative
    if (p_sValue.indexOf("-") != -1) {
        bIsBoolean = true;
        p_sValue = p_sValue.replace("-", "");
    }
    //format the dollar amount
    if (bIsBoolean == true) {
        //add negative formatting
        p_sValue = "($" + formatDollar(p_sValue) + ")";
    }
    else {
        //format positive dollar amount
        p_sValue = "$" + formatDollar(p_sValue);
    }
    return p_sValue;
}


// formatCurrency
// formats the string to a dollar format
//
// @author	kgrove - 3/14/2006
// @param	p_sValue - value to be formatted
// @return	none
function formatDollar(p_sValue) {
    var iValue = parseFloat(p_sValue);

    if (!iValue && iValue != 0) return "";
    iValue = (Math.round(iValue * 100)) / 100;
    iValue = Math.abs(iValue);
    p_sValue = iValue.toString();
    p_sValue = formatNumber(p_sValue, 0);
    return p_sValue;
}


// formatNumber
// 
//
// @author	kgrove - 3/14/2006
// @param	p_sValue
//          p_iPercision
// @return	none
function formatNumber(p_sValue, p_iPercision) {
    var iValue = parseFloat(p_sValue);
    if (!iValue && iValue != 0) return 0;

    iValue = Math.abs(iValue);
    p_sValue = iValue.toString();
    var sDecimal = "";
    var sNumber = p_sValue;
    if (p_sValue.indexOf(".") > 0) {
        sDecimal = p_sValue.substring(p_sValue.indexOf(".") + 1);
        sNumber = p_sValue.substring(0, p_sValue.indexOf("."));
        p_sValue = "." + padPrecision(sDecimal, p_iPercision);
    }
    else if (p_iPercision) {
        p_sValue = "." + padPrecision("0", p_iPercision);
    }
    else {
        p_sValue = "";
    }

    var iCommas = parseInt(sNumber.length / 3);
    var iLength = sNumber.length;
    var iStart;
    var iEnd;

    for (var i = 0; i <= iCommas; i++) {
        iEnd = iLength - (i * 3);
        iStart = iEnd - 3;
        if (iStart <= 0) {
            iStart = 0;
            p_sValue = sNumber.substring(iStart, iEnd) + p_sValue;
        }
        else {
            p_sValue = "," + sNumber.substring(iStart, iEnd) + p_sValue;
        }
    }
    return p_sValue;
}


// padPrecision
// 
//
// @author	kgrove - 3/14/2006
// @param	p_iNumber
//          p_iPadding
// @return	none
function padPrecision(p_iNumber, p_iPadding) {
    for (var i = 0; i < p_iPadding; i++) {
        if (p_iNumber.toString().length < p_iPadding) {
            p_iNumber = p_iNumber.toString() + "0";
        }
    }
    return p_iNumber;
}


// hideElement
// hides the element
// 
// @author	kgrove - 03/14/06
// @edit	-
// @param	p_sElement - element to hide
// @return	
function hideElement(p_sElement) {
    var thing = document.getElementById(p_sElement);

    //check for IFRAME
    if (thing == null) {
        thing = parent.document.getElementById(p_sElement);
    }

    thing.style.display = 'none';

}


// hideWebDialog
// hides the dialog window and window lock
// 
// @author	kgrove - 04/17/06
// @edit	-
// @param	p_sElement - element to hide
// @return	
function hideWebDialog(p_sElement) {
    hideElement(p_sElement);
    hideElement("fraWindowLock");
}


// showWebDialog
// hides the dialog window and window lock
// 
// @author	kgrove - 04/17/06
// @edit	-
// @param	p_sElement - element to hide
//          p_bCenter - indicates if the dialog should be centered on the screen
// @return	
function showWebDialog(p_sElement, p_bCenter) {
    if (p_bCenter) {
        centerDHTMLWindows();
    }
    sizeWindowLock();
    showElement(p_sElement);
    showElement("fraWindowLock");
}



// showWebDialogAtHeight
// hides the dialog window and window lock
// 
// @author	JoshRoberts - 11/24/07
// @edit	-
// @param	p_sElement - element to hide
//          p_bCenter - indicates if the dialog should be centered on the screen
//          oHeight - indicates how high up we want the window            
// @return	
function showWebDialogAtHeight(p_sElement, p_bCenter, oHeight) {
    if (p_bCenter) {
        DHTMLWindowsAtHeightForGallery(oHeight);
    }
    sizeWindowLock();
    showElement(p_sElement);
    showElement("fraWindowLock");
}

// disableElement
// disables the element
// 
// @author	kgrove - 03/16/06
// @edit	-
// @param	p_sElement - element to disable
// @return	
function disableElement(p_sElement) {

    var thing = document.getElementById(p_sElement);

    //check for IFRAME
    if (thing == null) {
        thing = parent.document.getElementById(p_sElement);
    }

    thing.disable = true;
}


// enableElement
// enables the element
// 
// @author	kgrove - 03/16/06
// @edit	-
// @param	p_sElement - element to enables
// @return	
function enableElement(p_sElement) {
    
    var thing = document.getElementById(p_sElement);

    //check for IFRAME
    if (thing == null) {
        thing = parent.document.getElementById(p_sElement);
    }

    thing.disable = false;
}


// showElement
// shows the element
// 
// @author	kgrove - 03/14/06
// @edit	-
// @param	p_sElement - element to show
// @return	
function showElement(p_sElement) {

    var thing = document.getElementById(p_sElement);

    //check for IFRAME
    if (thing == null) {
        thing = parent.document.getElementById(p_sElement);
    }

    thing.style.display = '';
}


// setElementFocus
// sets the focus to the element passed in
// 
// @author	kgrove - 03/15/06
// @edit	-
// @param	p_sElement - element to set focus on
// @return	
function setElementFocus(p_sElement) {
    
    var thing = document.getElementById(p_sElement);

    //check for IFRAME
    if (thing == null) {
        thing = parent.document.getElementById(p_sElement);
    }

    thing.focus();
}


// selectElementText
// select element text
// 
// @author	kgrove - 03/29/06
// @edit	-
// @param	p_sElement - element to set focus on
// @return	
function selectElementText(p_sElement) {
    
    var thing = document.getElementById(p_sElement);

    //check for IFRAME
    if (thing == null) {
        thing = parent.document.getElementById(p_sElement);
    }

    thing.select();
}


// isInteger
// determines if string is an integer
// 
// @author	kgrove - 03/15/06
// @edit	-
// @param	p_sValue - string to evaluate
// @return
function isInteger(p_sValue) {
    var i;
    for (i = 0; i < p_sValue.length; i++) {
        var c = p_sValue.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }

    return true;
}
// doubleOnly
// only allows control to have numeric values with a period(requires onKeyPress="numericOnly(event);") 
// 
// @author	kgrove - 03/15/06
// @edit	- gmercado 07/07/06
// @param	p_oEvent - event object
// @return
function doubleOnly(p_oEvent) {
    var sKey = "";

    if (window.event) {
        sKey = p_oEvent.keyCode;
    }
    else {
        sKey = p_oEvent.which
    }

    if (sKey == 0 || sKey == 8 || sKey == 13 || sKey == 46 || sKey == 44) {  //Allow Delete, Arrows, BackSpace, Enter,46=period,44 = comma
        return true;
    }
    return isInteger(String.fromCharCode(sKey));
}


// numericOnly
// only allows control to have numeric values (requires onKeyPress="numericOnly(event);") 
// 
// @author	kgrove - 03/15/06
// @edit	-
// @param	p_oEvent - event object
// @return
function numericOnly(p_oEvent) {
    var sKey = "";

    if (window.event) {
        sKey = p_oEvent.keyCode;
    }
    else {
        sKey = p_oEvent.which
    }

    if (sKey == 0 || sKey == 8 || sKey == 13) {  //Allow Delete, Arrows, BackSpace, Enter
        return true;
    }
    return isInteger(String.fromCharCode(sKey));
}


// currencyOnly
// only allows control to have currency values (requires onKeyPress="currencyOnly(event);") 
// 
// @author	kgrove - 03/15/06
// @edit	-
// @param	p_oElement - element object
//          p_oEvent - event object
// @return
function currencyOnly(p_oElement, p_oEvent) {
    var sKey = "";
    var sAllowedCharacters = "0,8,13,46";

    if (window.event) {
        sKey = p_oEvent.keyCode;
    }
    else {
        sKey = p_oEvent.which
    }

    // Only Allow 1 Period
    if (sKey == 46 && p_oElement.value.indexOf(".") > 0) {
        return false;
    }

    if (sAllowedCharacters.indexOf(sKey) > 0) {
        return true;
    }
    return isInteger(String.fromCharCode(sKey));
}


// addOkDialogMessage
// adds a message to the OK Dialog box
// 
// @author	kgrove - 3/16/06
// @edit	-
// @param	p_sMessage - the message to be added
//          p_sTitle - title for the dialog box
// @return	none
function addOkDialogMessage(p_sMessage, p_sTitle) {
    var oDialogTitle = document.getElementById("tdOkDialogTitle");
    var oDialogMessage = document.getElementById("tdOkDialogMsg");

    //check to see if we are in an IFRAME
    if (oDialogTitle == null) {
        oDialogTitle = parent.document.getElementById("tdOkDialogTitle");
        oDialogMessage = parent.document.getElementById("tdOkDialogMsg");
    }

    oDialogTitle.innerHTML = p_sTitle;
    oDialogMessage.innerHTML = p_sMessage;


}


// addOkActionDialogMessage
// adds a message to the OK Action Dialog box
// 
// @author	kgrove - 3/16/06
// @edit	-
// @param	p_sMessage - the message to be added
//          p_sTitle - title for the dialog box
// @return	none
function addOkActionDialogMessage(p_sMessage, p_sTitle) {
    var oDialogTitle = document.getElementById("tdOkActionDialogTitle");
    var oDialogMessage = document.getElementById("tdOkActionDialogMsg");

    //check to see if we are in an IFRAME
    if (oDialogTitle == null) {
        oDialogTitle = parent.document.getElementById("tdOkActionDialogTitle");
        oDialogMessage = parent.document.getElementById("tdOkActionDialogMsg");
    }

    oDialogTitle.innerHTML = p_sTitle;
    oDialogMessage.innerHTML = p_sMessage;
}


// addModelDialogMessage
// adds a message to the model Dialog box
// 
// @author	kgrove - 3/16/06
// @edit	-
// @param	p_sMessage - the message to be added
//          p_sTitle - title for the dialog box
// @return	none
function addModelDialogMessage(p_sMessage, p_sTitle) {
    var oDialogTitle = document.getElementById("tdModelDialogTitle");
    var oDialogMessage = document.getElementById("tdModelDialogMsg");

    //check to see if we are in an IFRAME
    if (oDialogTitle == null) {
        oDialogTitle = parent.document.getElementById("tdModelDialogTitle");
        oDialogMessage = parent.document.getElementById("tdModelDialogMsg");
    }

    oDialogTitle.innerHTML = p_sTitle;
    oDialogMessage.innerHTML = p_sMessage;
}


// addAcceptDialogMessage
// adds a message to the accept Dialog box
// 
// @author	kgrove - 3/17/06
// @edit	-
// @param	p_sMessage - the message to be added
//          p_sTitle - title for the dialog box
// @return	none
function addAcceptDialogMessage(p_sMessage, p_sTitle) {
    var oDialogTitle = document.getElementById("tdAcceptDialogTitle");
    var oDialogMessage = document.getElementById("tdAcceptDialogMsg");

    //check to see if we are in an IFRAME
    if (oDialogTitle == null) {
        oDialogTitle = parent.document.getElementById("tdAcceptDialogTitle");
        oDialogMessage = parent.document.getElementById("tdAcceptDialogMsg");
    }

    oDialogTitle.innerHTML = p_sTitle;
    oDialogMessage.innerHTML = p_sMessage;
}


// addImgViewer
// adds a message to the image viewer box
// 
// @author	JRoberts - 11/26/07
// @edit	-
// @param	p_sMessage - the message to be added
//          p_sTitle - title for the dialog box
// @return	none
function addImgViewer(p_sMessage, p_sTitle) {
    var oDialogTitle = document.getElementById("tdImgTitle");
    var oDialogMessage = document.getElementById("tdImg");

    //check to see if we are in an IFRAME
    if (oDialogTitle == null) {
        oDialogTitle = parent.document.getElementById("tdImgTitle");
        oDialogMessage = parent.document.getElementById("tdImg");
    }

    oDialogTitle.innerHTML = p_sTitle;
    oDialogMessage.innerHTML = p_sMessage;
}

// fixFrameHeight
// fix frame height based on the contents
// 
// @author	kgrove - 3/20/06
// @edit	-Gmercado 8/16/2006
// adds tdSpacer
// @param	p_sFrameId - the frame which will have its height adjusted
//          p_sHeightElementId - the element to evaluate the height on
//          p_iBuffer - buffer to be added to the height
// @return	none
function fixFrameHeightVehicleSummary(p_sFrameId, p_sHeightElementId, p_iBuffer) {

    var oIFrame = parent.document.getElementById(p_sFrameId);
    var oHeightElement = document.getElementById(p_sHeightElementId);
    var otdSpacer = parent.document.getElementById("tdSpacer");
    var oMainContentTD = parent.document.getElementById("mainContent_TR");
    var iHeight = 0;
    if (oHeightElement) {
        iHeight = parseInt(oHeightElement.clientHeight) + parseInt(p_iBuffer);
    }
    else {
        iHeight = p_iBuffer;
    }

    if (oIFrame) {

        oIFrame.style.height = iHeight + "px";
        if (otdSpacer) {
            otdSpacer.style.height = iHeight + "px";
        }
        if (oMainContentTD) {
            oMainContentTD.style.height = iHeight + "px";
        }
    }
}

// fixFrameHeight
// fix frame height based on the contents
// 
// @author	kgrove - 3/20/06
// @edit	-
// @param	p_sFrameId - the frame which will have its height adjusted
//          p_sHeightElementId - the element to evaluate the height on
//          p_iBuffer - buffer to be added to the height
// @return	none
function fixFrameHeight(p_sFrameId, p_sHeightElementId, p_iBuffer) {

    var oIFrame = parent.document.getElementById(p_sFrameId);
    var oHeightElement = document.getElementById(p_sHeightElementId);
    var iHeight = 0;

    if (oHeightElement) {
        iHeight = parseInt(oHeightElement.clientHeight) + parseInt(p_iBuffer);
    }
    else {
        iHeight = p_iBuffer;
    }

    if (oIFrame) {
        oIFrame.style.height = iHeight + "px";
        var otdSpacer = parent.document.getElementById("tdSpacer");
        if (otdSpacer) {
            otdSpacer.style.height = iHeight + "px";
        }
    }
}


// fixFrameHeightErrorPage
// fix frame height and width when the error page is displayed in it
// 
// @author	kgrove - 4/21/06
// @edit	-
// @param	none
// @return	none
function fixFrameHeightErrorPage() {
    var oIFrames = parent.document.getElementsByTagName("iframe");
    var oFrames = parent.frames;
    var oElementId = document.getElementById("tblErrorBody");

    for (var i = 0; i < oFrames.length; i++) {
        if (oFrames[i].location.href.indexOf(IFRAME_ERROR_PAGE) > 0) {
            fixFrameHeight(oIFrames[i].id, oElementId.id, 0);
            oElementId.style.width = oIFrames[i].clientWidth + "px";
        }
    }
}


// displayTMV
// pop up the TMV Explanation page
// 
// @author	kgrove - 3/28/06
// @edit	-
// @param	none
// @return	none
function displayTMV() {
    var sFeatures = "height=550px,location=no,menubar=no,status=no,width=650px,scrollbars=yes";
    window.open(m_sRoot + "Common/TMVExplanation.aspx", "winTMVExplanation", sFeatures);
}


// toggleCollapse
// toggles collapsable item based on the direction passed in
// 
// @author	kgrove - 3/30/06
// @edit	-
// @param	p_iDirection - direction to toggle (0 = expand, 1 = collapse)
//          p_sElementId - id of the element to be collapsed/expanded
//          p_iIdentifier - id of the identifier for the element and images
// @return	none
function toggleCollapse(p_iDirection, p_sElementId, p_iIdentifier) {
    if (p_iDirection == 0) {
        showElement(p_sElementId + p_iIdentifier);
        showElement("imgMinimize" + p_iIdentifier);
        hideElement("imgMaximize" + p_iIdentifier);
    }
    else {
        hideElement(p_sElementId + p_iIdentifier);
        hideElement("imgMinimize" + p_iIdentifier);
        showElement("imgMaximize" + p_iIdentifier);
    }
}


// animateMenuOut
// the animateMenuOut function fades the specified dhtml table out of the screen
// 
// @author	kgrove - 4/3/06
// @edit	none
// @param	p_sElement - element to fade out
//          p_iTimer - the value of the security category
//			p_iPercent - the value of the configuration category
// @return	none
function animateMenuOut(p_sElement, p_iPercent) {
    var oElement = document.getElementById(p_sElement);
    if (p_iPercent >= 5) {
        oElement.style.filter = "Alpha(Opacity=" + p_iPercent + ")"

        p_iPercent -= 5;
        m_iAnimationTimer = setTimeout("animateMenuOut('" + p_sElement + "', " + p_iPercent + ")",
					10);
    }
    else {
        clearTimeout(m_iAnimationTimer);
        p_iPercent = 100;
        oElement.style.filter = "Alpha(Opacity=" + p_iPercent + ")"
        oElement.style.display = "none";
    }
}


// getSelectedRadioIndex
// returns the array index of the selected radio button or -1 if no button is selected
//
// @author	kgrove - 4/6/06
// @param	p_oGroup - array of radio buttons to be checked
// @return	integer - selected radio button index
function getSelectedRadioIndex(p_oGroup) {
    if (p_oGroup[0]) {
        for (var i = 0; i < p_oGroup.length; i++) {
            if (p_oGroup[i].checked) {
                return i;
            }
        }
    }
    else if (p_oGroup.checked) {
        return 0;
    }
    else {
        return -1;
    }
}


// getSelectedRadio
// returns the selected radio button or an empty string if no button is selected
//
// @author	kgrove - 4/6/06
// @param	p_oGroup - array of radio buttons to be checked
// @return	object - selected radio button
function getSelectedRadio(p_oGroup) {
    var iSelected = getSelectedRadioIndex(p_oGroup);

    if (iSelected == -1) {
        return "";
    }
    else {
        if (p_oGroup[iSelected]) {
            return p_oGroup[iSelected];
        }
        else {
            return p_oGroup;
        }
    }
}


// getDropdownboxValue
// gets the value of the selected item in the dropdownlist and populate it in the provided textbox
// 
// @author	kle - 3/30/06
// @edit	-
// @param	dropdownboxId - client id of the dropdownlist
//          textboxId - client id of the textbox
// @return	none
function getDropdownboxValue(dropdownboxId, textboxId) {
    var textbox = document.getElementById(textboxId);
    var dropdownbox = document.getElementById(dropdownboxId);
    //var selValue;
    if ((textbox != null) && (dropdownbox != null)) {
        //selValue = dropdownbox[dropdownbox.selectedIndex].value; Went another Way
        //selValue = selValue.substring(1,selValue.length);
        textbox.value = dropdownbox[dropdownbox.selectedIndex].value;
    }
}


// disableControl
// disable or enable a control
// 
// @author	kle - 3/30/06
// @edit	-
// @param	disable - true=disable, false=enable
//          controlId - client id of the control to disable/enable
// @return	none
function disableControl(disable, controlId) {

    //disable
    var control = document.getElementById(controlId);
    if (control != null) {
        control.disabled = disable;
        if (disable) {
            if ((control.type == "text") || (control.type == "textarea"))
                control.value = "";
            else if (control.type == "select-one")
                control.selectedIndex = 0;
            else if (control.type == "radio") {
                control.checked = false;
            }
        }
    }
}


// hideControl
// show or hide a control
// 
// @author	kle - 3/30/06
// @edit	-
// @param	hide - true= hide, false=show
//          controlId - client id of the control to show/hide
// @return	none
function hideControl(hide, controlId) {

    var control = document.getElementById(controlId);
    if (control != null) {
        if (hide) {
            control.style.visibility = "hidden";
        }
        else {
            control.style.visibility = "";
        }
    }
}


// diableValidator
// enable or disable a validator
// 
// @author	kle - 03/30/06
// @edit	-
// @param	disable - true=disable, false=enable
//          validatorControlId - client id of the validator to disable/enable
// @return	none
function diableValidator(disable, validatorControlId) {

    var validatorControl = document.getElementById(validatorControlId);
    ValidatorEnable(validatorControl, !disable);
}


// getCookie
// get value of the cookie
// 
// @author	kgrove - 04/07/06
// @edit	-
// @param	p_sName - name of the cookie
// @return	string - the value associated with the name
function getCookie(p_sName) {
    var start = document.cookie.indexOf(p_sName + "=");
    var len = start + p_sName.length + 1;

    if ((!start) && (p_sName != document.cookie.substring(0, p_sName.length))) {
        return null;
    }
    if (start == -1) {
        return null;
    }
    var end = document.cookie.indexOf(";", len);

    if (end == -1) {
        end = document.cookie.length;
    }

    return unescape(document.cookie.substring(len, end));
}


// setCookie
// sets the value of a cookie
// 
// @author	kgrove - 04/07/06
// @edit	-
// @param	p_sName - name associated with the value
//          p_sValue - value to be set in the cookie
// @return	none
function setCookie(p_sName, p_sValue) {
    var cookieString = p_sName + "=" + escape(p_sValue);

    document.cookie = cookieString;
}

// Checks for an Enter key
// triggers an onclick event to the form's button when an enter key is pressed.
// 
// @author	Greg Mercado - 04/07/06
// @edit	-
// @param	e - event
//          buttonId - Button Id identification.
function checkEnterKey(e, buttonId) {
    var bt = document.getElementById(buttonId);
    var key;
    if (window.event)
        key = window.event.keyCode;     //IE
    else
        key = e.which;     //firefox

    if (key == 13) {
        bt.click();
        return false;
    }
    else
        return true;
}

// Checks for an Enter key and numeric value
// triggers an onclick event to the form's button when an enter key is pressed.
// 
// @author	Greg Mercado - 04/07/06
// @edit	-
// @param	e - event
// @param	buttonId - button to be click
// @param	sourceId - source to be evaluated.

function checkEnterKeyZip(e, buttonId, sourceId) {
    var bt = document.getElementById(buttonId);
    var source = document.getElementById(sourceId);
    var key;

    //if(window.event)
    if (m_bIsIE)
        key = window.event.keyCode;     //IE
    else
        key = e.which;     //firefox

    if (key == 13) {
        if (source.type == 'text') {
            bt.click();
            return false;
        }
        else {
            if (source.selectedIndex > 0);
            {
                bt.click();
                return false;
            }
        }
    }
    else {
        if (key == 0 || key == 8) {  //Allow Delete, Arrows, BackSpace, Enter
            return true;
        }
        return isInteger(String.fromCharCode(key)); // make sure its numeric
    }
}

// cancelEnterKeyPressed
// if the event was fired by the 'ENTER' key pressed, stop the event from bubbling up and return false
// 
// @author	kle - 06/01/06
// @edit	-
// @param	p_oEvent - the current event
// @return	none
function cancelEnterKeyPressed(p_oEvent) {
    if (window.event) { //IE
        sKey = p_oEvent.keyCode;
    }
    else { //Firefox
        sKey = p_oEvent.which;
    }

    if (sKey == 13) {
        cancelEventBubble(p_oEvent);
        if (m_bIsIE) {
            p_oEvent.returnValue = false;
        }
        else if (p_oEvent.stopPropagation) {
            p_oEvent.preventDefault();
        }
    }
}

// cancelEventBubble
// stop the current event from bubbling up the hierarchy of event handlers
// 
// @author	kle - 06/01/06
// @edit	-
// @param	p_oEvent - the current event
// @return	none
function cancelEventBubble(p_oEvent) {
    //http://support.microsoft.com/kb/q298498/
    //http://www.openjs.com/articles/prevent_default_action/
    //e.cancelBubble is supported by IE - this will kill the bubbling process.
    if (m_bIsIE) {
        p_oEvent.cancelBubble = true;
    }
    else if (p_oEvent.stopPropagation) {
        //e.stopPropagation works only in Firefox.
        p_oEvent.stopPropagation();
    }
}

// addSentQuoteDialogMessage
// adds a message to the Sent Quote Dialog box
// 
// @author	achow - 2/18/09
// @edit	-
// @param	p_sMessage - the message to be added
//          p_sTitle - title for the dialog box
// @return	none
function addSentQuoteDialogMessage(p_sMessage, p_sTitle) {
    var oDialogTitle = document.getElementById("tdSentQuoteDialogTitle");
    var oDialogMessage = document.getElementById("tdSentQuoteDialogMsg");

    oDialogTitle.innerHTML = p_sTitle;
    oDialogMessage.innerHTML = p_sMessage;
}

// addMembershipPromptMessage
// adds a message to the membership prompt box
// 
// @author	achow - 4/3/09
// @edit	-
// @param	p_sMessage - the message to be added
//          p_sTitle - title for the dialog box
// @return	none
function addMembershipPromptMessage(p_sMessage, p_sTitle) {
    var oDialogTitle = document.getElementById("tdMembershipPromptDialogTitle");
    var oDialogMessage = document.getElementById("tdMembershipPromptDialogMsg");

    oDialogTitle.innerHTML = p_sTitle;
    oDialogMessage.innerHTML = p_sMessage;
}

// AddProgressDialogTitle
// Change title for Progress Dialog pop up
// 
// @author	achow - 10/12/09
// @edit	-
// @param	p_sTitle - title for the dialog box
// @return	none
function AddProgressDialogTitle(p_sTitle) {
    var oDialogTitle = document.getElementById("progressDialog_header");
    oDialogTitle.innerHTML = p_sTitle;
}

/* QTip function here */
// The following are all the possible positions
//   'topRight', 'topLeft', 'topMiddle',
//   'bottomLeft', 'bottomRight', 'bottomMiddle',
//   'rightMiddle', 'rightBottom', 'rightTop',
//   'leftMiddle', 'leftTop', 'leftBottom'];

function ShowTipOnClick() {
    $('.qTipSec a')
    .click(function() { ShowTip($(this),false); });
}

function ShowTipOnMouseOver() {
    $('.qTipSec a')
    .mouseover(function() { ShowTip($(this),true); });
}

function ShowTip(linkObject, hideOnMouseOut) {
  // Destroy all tooltips is present
    $('.qTipSec a').each(
        function() {
            if ($(this).data("qtip")) 
                    $(this).qtip("destroy");
        }
    );

  // Get the content to show
    var detailContent = $(linkObject).parent().find('div').html();

  // Get Title
  var title = $(linkObject).attr('CustomTitle');
  if (title == null || title == '')
      title = '';
      
  // Get the positon
  var position = $(linkObject).attr('CustomPosition');
  // Default to topMiddle if not available
  if (position == null || position == '')
      position = "topMiddle";

  // Get the width
  var size = $(linkObject).attr('CustomSize');
  // Default to 250 if not available
  if (size == null || size == '')
      size = 250
  else
      size = parseInt(size);

  // Get text color
  var titleTextColor = $(linkObject).attr('CustomTitleTextColor');
  if (titleTextColor == null || titleTextColor == '')
      titleTextColor = "white";

  // Get background color
  var BorderBGColor = $(linkObject).attr('CustomBorderBGColor');
  if (BorderBGColor == null || BorderBGColor == '')
      BorderBGColor = "#2759AD";

  var xPositionAdj = $(linkObject).attr('CustomXPositionAdjustment');
  if (xPositionAdj == null || xPositionAdj =='')
    xPositionAdj = 0;
  else
    xPositionAdj = parseInt(xPositionAdj);
  
  var yPositionAdj = $(linkObject).attr('CustomYPositionAdjustment');
  if (yPositionAdj == null || yPositionAdj =='')
    yPositionAdj = 0;
  else
    yPositionAdj = parseInt(yPositionAdj);

  $(linkObject) // Set the links HTML to the current opposite corner
    .qtip({
        //content: corners[i], // Set the tooltip content to the current corner
        content: {
            text: detailContent,
            title:
                {
                    text: title == '' ? false : title,
                    button: 'Close'
                }
        },
        position: {
            corner: {
                tooltip: position, // Use the corner...
                target: "bottomMiddle" // ...and opposite corner
            },

            adjust:
            {
                x: xPositionAdj, y: yPositionAdj,
                resize: true,
                scroll: false
            }
        },
        show: {
            when: false, // Don't specify a show event
            ready: true // Show the tooltip when ready
        },
        hide: hideOnMouseOut==true ? 'mouseout': false, // Don't specify a hide event
        style: {
            border: {
                width: 5,
                radius: 10,
                color: BorderBGColor
            },
            
            title:
            {
                background: BorderBGColor,
                color: titleTextColor
            },

            background: '#ffffff',
            color: 'black',
            /*padding: 10,*/
            textAlign: 'left',
            tip: true, // Give it a speech bubble tip with automatic corner detection
            name: 'green', // Style it according to the preset 'cream' style
            width: size // Set a high max width so the text doesn't wrap
        }
    });
}

// Fast javascript function to clear all the options in an HTML select element
// Provide the id of the select element
// References to the old <select> object will become invalidated!
// This function returns a reference to the new select object.
function ClearOptionsFast(selectObj) {
    // var selectObj = document.getElementById(id);
    var selectParentNode = selectObj.parentNode;
    var newSelectObj = selectObj.cloneNode(false); // Make a shallow copy
    selectParentNode.replaceChild(newSelectObj, selectObj);
    return newSelectObj;
}
