﻿var currentpopup = "";
var currentpopupxpos = 0;
var EnableMenus = false;

function overlay_quick(curobj, subobjstr, opt_position) {
    if (EnableMenus) {
        var subobj = document.getElementById(subobjstr)

        var xpos = findPosX(curobj)
        var ypos = findPosY(curobj) + curobj.offsetHeight


        subobj.style.left = xpos + "px"
        subobj.style.top = ypos - 1 + "px"

        currentpopupxpos = xpos;

        subobj.style.display = "block"; subobj.style.height = "auto";
        subobj.style.left = xpos + "px"
        IFrame_Mask(subobjstr);
        currentpopup = subobjstr;
    }

}


function overlay_quick_static(curobj, subobjstr, opt_position, opt_yposition, multipop) {
    if (document.getElementById(currentpopup) && !multipop)
        hidepopup(currentpopup);
    if (EnableMenus) {
        var subobj = document.getElementById(subobjstr)

        var xpos = findPosX(curobj)
        var ypos = findPosY(curobj) + curobj.offsetHeight

        if (opt_yposition)
            ypos -= opt_yposition;
        if (opt_position)
            if (opt_position == 'center')
        { }
        else
            subobj.style.left = xpos + opt_position + "px"
        else
            subobj.style.left = xpos + "px"



        if (!multipop)
            currentpopupxpos = xpos;

        subobj.style.display = "block"; subobj.style.height = "auto";

        if (opt_position) {

            if (opt_position == 'center') {

                var availHeight;
                var availWidth;

                if (typeof (window.innerWidth) == 'number') {
                    availHeight = window.innerHeight;
                    availWidth = window.innerWidth;
                }
                else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {

                    availHeight = document.documentElement.clientHeight;
                    availWidth = document.documentElement.clientWidth;
                }
                else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
                    availHeight = document.body.clientHeight;
                    availWidth = document.body.clientWidth;
                }


                //var IpopTop = (document.body.clientHeight - subobj.offsetHeight) / 2;
                var IpopLeft = (document.body.clientWidth - subobj.offsetWidth) / 2;

                //subobj.style.top=IpopTop + document.body.scrollTop+'px';

                var yOffset
                if (self.pageYOffset)
                    yOffset = self.pageYOffset;
                else if (document.documentElement && document.documentElement.scrollTop)
                    yOffset = document.documentElement.scrollTop;
                else if (document.body)
                    yOffset = document.body.scrollTop;

                if (opt_yposition)
                    subobj.style.top = opt_yposition + "px";
                else
                    subobj.style.top = ((availHeight / 2) + yOffset) - (subobj.offsetHeight / 2) + document.body.scrollLeft + 'px';
                subobj.style.left = (availWidth - subobj.offsetWidth) / 2 + document.body.scrollLeft + 'px';

            }
            else {
                subobj.style.left = xpos + opt_position + "px";
                subobj.style.top = ypos - 1 + "px";
            }
        }
        else {
            subobj.style.left = xpos + "px";
            subobj.style.top = ypos - 1 + "px";
        }
        IFrame_Mask(subobjstr);
        document.getElementById(subobjstr).style.display = "block";

        //IFrame_Mask(subobjstr);
        currentpopup = subobjstr;
    }

}

var isgcheckout = 'N';
function XML_ping(url) {
    var xmlhttp
    xmlhttp = null
    // code for Mozilla, etc.
    if (window.XMLHttpRequest)
        xmlhttp = new XMLHttpRequest()
    // code for IE
    else if (window.ActiveXObject)
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")

    if (xmlhttp != null) {
        xmlhttp.open("GET", url, true)
        xmlhttp.send(null)
    }

}

function isIE() {
    version = 0;
    if (navigator.appVersion.indexOf("MSIE") != -1) {
        temp = navigator.appVersion.split("MSIE")
        version = parseFloat(temp[1])
    }
    if (version != 0)
        return version;
    else
        return false;

}

function IFrame_Mask(divtomask) {
    if (isIE() != false) {
        var subobj = document.getElementById(divtomask);
        if (!document.getElementById(divtomask + '_mask')) {
            var objBody = document.getElementsByTagName("body").item(0);
            var objOverlay = document.createElement("Iframe");
            objOverlay.setAttribute('id', divtomask + '_mask');
            objOverlay.setAttribute('frameborder', '0');
            objOverlay.setAttribute('scrolling', 'no');
            objOverlay.setAttribute('marginwidth', '0');
            objOverlay.setAttribute('src', 'javascript: false;');
            objOverlay.setAttribute('marginheight', '0');
            objOverlay.style.display = 'none';
            objOverlay.style.position = 'absolute';
            objOverlay.style.zindex = '1';
            objOverlay.style.border = '0';

            objOverlay.style.left = subobj.style.left;
            objOverlay.style.top = subobj.style.top;
            objOverlay.style.height = subobj.offsetHeight;
            objOverlay.style.width = subobj.offsetWidth;
            objOverlay.style.display = "inline";

            objBody.appendChild(objOverlay);
        }
        else {
            document.getElementById(divtomask + '_mask').style.left = subobj.style.left;
            document.getElementById(divtomask + '_mask').style.top = subobj.style.top;
            document.getElementById(divtomask + '_mask').style.height = subobj.offsetHeight;
            document.getElementById(divtomask + '_mask').style.width = subobj.offsetWidth;
            document.getElementById(divtomask + '_mask').style.display = "inline";

        }
    }

}

function IFrame_UnMask(divtomask) {
    //document.getElementById("FXframe").style.display = "none";

    if (document.getElementById(divtomask + '_mask')) {
        var objBody = document.getElementsByTagName("body").item(0);
        objBody.removeChild(document.getElementById(divtomask + '_mask'));
    }
}








function forceclose5_quick(e, targetdiv) {
    if (!document.getElementById(targetdiv))
        return;
    if (document.getElementById(targetdiv).style.display == "none")
        return;
    if (!e)
        var e = window.event;

    var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
    //reltg.style.border = "5px solid black";

    if (reltg.getAttribute('id') == targetdiv)
        return;

    while (reltg.nodeName != 'BODY') {
        reltg = reltg.parentNode;
        if (reltg.getAttribute('id') == targetdiv) return;
    }

    document.getElementById(targetdiv).style.display = "none";
    IFrame_UnMask(targetdiv);
    currentpopup = "";
    closeoperationinprogress = false;
}



function forceclose_quick() {

    if (currentpopup != "" && document.getElementById(currentpopup)) {
        document.getElementById(currentpopup).style.display = "none";
        IFrame_UnMask(currentpopup);
        currentpopup = "";
    }
    //closeoperationinprogress = false;
}




function showpopup(tt) {
    document.getElementById(tt).style.display = "block";
    document.getElementById(tt).style.left = findPosX(document.getElementById('termsdiv')) + (document.getElementById('termsdiv').offsetWidth / 2) - (document.getElementById(tt).offsetWidth / 2) + "px";
    scroll(0, 0);
    IFrame_Mask(tt);
    IFrame_Mask(tt);

}

function hidepopup(tt) {
    document.getElementById(tt).style.display = "none";
    IFrame_UnMask(tt);
    smoke_screen(false);
}

function show_div(tt) { document.getElementById(tt).style.display = "block"; }
function hide_div(tt) { document.getElementById(tt).style.display = "none"; }

function loadXML_content(url, tt, load_function) {
    var currentTime = new Date();
    var vTicks = currentTime.valueOf();
    var xmlhttp
    xmlhttp = null
    // code for Mozilla, etc.
    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest()
    }
    // code for IE
    else if (window.ActiveXObject) {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
    }
    if (xmlhttp != null) {
        xmlhttp.open("GET", url + '&r=' + vTicks, true)
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4) {
                // if "OK"
                if (xmlhttp.status == 200) {
                    if (tt != "")
                        document.getElementById(tt).innerHTML = xmlhttp.responseText;
                    
                    if (typeof load_function != "undefined") {
                        //	load_function.call('cart_popup');
                        //     if (load_function != "")
                        eval(load_function + '(tt)');
                    }
                    else {
                        IFrame_Mask(tt);
                    }

                }
                else {
                    alert("Problem retrieving data:" + xmlhttp.statusText)
                }
            }

        }

        xmlhttp.send(null)
    }
    else {
        alert("Your browser does not support XMLHTTP.")
    }
}



function load_PopUp(url, container) {
    loadXML_content(url, container);
    xb.addEvent(container, 'mouseleave', leave, false);
}


function refresh_iframe(container) {
    IFrame_Mask(container);

}

function showAllByTag(tagName, dispType) {
    var elements = document.getElementsByTagName(tagName);
    var i = 0;
    if (dispType == "") {
        dispType = inline;
    }
    while (i < elements.length) {
        elements[i].style.display = dispType;
        i++;
    }
}
function hideAllByTag(tagName) {
    var elements = document.getElementsByTagName(tagName);
    var i = 0;
    while (i < elements.length) {
        elements[i].style.display = "none";
        i++;
    }
}




function XML_POST(url, params, tt, load_function) {

    var xmlhttp
    xmlhttp = null
    // code for Mozilla, etc.
    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest()
    }
    // code for IE
    else if (window.ActiveXObject) {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
    }
    if (xmlhttp != null) {
        xmlhttp.open("POST", url, true)
        xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlhttp.setRequestHeader("Content-length", params.length);
        xmlhttp.setRequestHeader("Connection", "close");

        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4) {
                // if "OK"
                if (xmlhttp.status == 200) {
                    if (tt != "")
                        document.getElementById(tt).innerHTML = xmlhttp.responseText;

                    if (typeof load_function != "undefined") {
                 //       //	load_function.call('cart_popup');
                        eval(load_function + '(tt)');
                    }
                    else {
                        IFrame_Mask(tt);
                    }
                }
                else {
                    alert("Problem retrieving data:" + xmlhttp.statusText)
                }
            }

        }

        xmlhttp.send(params)
    }
    else {
        alert("Your browser does not support XMLHTTP.")
    }
}



function LoadJS(tt) {
    var elements = document.getElementById(tt).getElementsByTagName('script');
    var i = 0;
    while (i < elements.length) {
        eval(elements[i].innerHTML);
        i++;
    }
}

//Find X Coord
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;
}

//Find Y Coord
function findPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent)
        while (1) {
        curtop += obj.offsetTop;
        if (!obj.offsetParent)
            break;
        obj = obj.offsetParent;
    }
    else if (obj.y)
        curtop += obj.y;
    return curtop;
}




function getCheckedValue(radioGroupName) {
    radioObj = document.getElementsByName(radioGroupName);
    if (!radioObj)
        return "";

    if (radioObj[0] && radioObj[0].type == "select-one") {
        return document.getElementById(radioGroupName).options[document.getElementById(radioGroupName).selectedIndex].value;
    }
    else {
        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 "";
    }
}


function show_masked_popup(tt) {
    if (tt.id)
        tt = tt.id;
    document.getElementById(tt).style.display = "block";
    document.getElementById(tt).style.left = findPosX(document.getElementById('termsdiv')) + (document.getElementById('termsdiv').offsetWidth / 2) - (document.getElementById(tt).offsetWidth / 2) + "px";
    IFrame_Mask(tt);
    scroll(0, 0);
    smoke_screen(true);

}

function lines_busy(tt) {
    loadXML_content('/lines_are_busy{if empty($live_server)}_dev{/if}.php', 'generic_pop', 'show_masked_popup');
    show_masked_popup(document.getElementById('generic_pop'));

}



function GetBrowserSize() {

    var xDimension, yDimension;

    if (window.innerHeight && window.scrollMaxY) {
        xDimension = window.innerWidth + window.scrollMaxX;
        yDimension = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
        xDimension = document.body.scrollWidth;
        yDimension = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xDimension = document.body.offsetWidth;
        yDimension = document.body.offsetHeight;
    }

    var windowWidth, windowHeight;

    if (self.innerHeight) {	// all except Explorer
        if (document.documentElement.clientWidth) {
            windowWidth = document.documentElement.clientWidth;
        } else {
            windowWidth = self.innerWidth;
        }
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }

    if (yDimension < windowHeight) {
        pageHeight = windowHeight;
    } else {
        pageHeight = yDimension;
    }

    if (xDimension < windowWidth) {
        pageWidth = xDimension;
    } else {
        pageWidth = windowWidth;
    }

    return [pageWidth, pageHeight];
}

function smoke_screen(display_toggle) {
    //GRAB BROWSER VERSOPM
    var version = 0;
    if (navigator.appVersion.indexOf("MSIE") != -1) { temp = navigator.appVersion.split("MSIE"); version = parseFloat(temp[1]); }
    //IF NEWER THAN IE 5.5 (most visitors should be)
    if (version >= 5.5 || version == 0) //NON IE browser will return 0
    {
        if (display_toggle) {
            var arrayPageSize = GetBrowserSize();
            if (!document.getElementById('SmokeScreen')) {
                var objBody = document.getElementsByTagName("body").item(0);
                var objOverlay = document.createElement("div");
                objOverlay.setAttribute('id', 'SmokeScreen');
                objOverlay.style.display = 'none';
                objOverlay.style.height = '1876px';
                objOverlay.style.width = '1264px';
                objBody.appendChild(objOverlay);
            }

            var smokeScreenObj = document.getElementById('SmokeScreen');
            smokeScreenObj.style.width = arrayPageSize[0] + 'px';
            smokeScreenObj.style.height = arrayPageSize[1] + 'px';
            smokeScreenObj.style.display = "block";
        }
        else if (document.getElementById('SmokeScreen'))
            document.getElementById('SmokeScreen').style.display = "none";
    }

}

