﻿
gPageBottom = 0;
gCartItemMultiplier = 0;

function deleteCartItem(cartItemId) {
    document.getElementById("__EVENTTARGET").value = "DeleteCartItem";
    document.getElementById("__EVENTARGUMENT").value = cartItemId;
    theForm.submit();
}

function getReportWithEmail(website, email) {
    if (email == "" || email.indexOf("@") == -1)
    { alert("Please enter an email address so we can send you this report immediately."); }
    else
    { document.location.href = "/processaction.aspx?website=" + website + "&action=get&dataElement=report&email=" + email; }
}

function goToPageTop() {
    pageTopLocation = document.location.href.replace("#globalPageTop", "");
    document.location.href = pageTopLocation + "#globalPageTop";
}

function hideLightbox()
{ showHideLightbox('hide'); }


function hideLightboxPopup() {
    document.getElementById('lightboxPopupMenu').style.display = 'none';
    document.getElementById('lightboxIFrame').style.display = 'none';
    document.getElementById('lightboxPopupContainer').style.display = 'none';
    document.getElementById('lightboxBackground').style.display = 'none';
}

function setInnerHTML(element, html, count) {
    element.innerHTML = html;
    if (!count) count = 1;
    if (html != '' && element.innerHTML == '' && count < 5)
    { ++count; setTimeout(function() { setInnerHTML(element, html, count); }, 50); }
}

function showHideLightbox(showHide) {
    if (showHide == "show") {
        document.getElementById('lightboxMenu').style.display = 'block';
        document.getElementById('lightboxContainer').style.display = 'block';

        showLightboxBackground();

        if ((gCartItemMultiplier * 1) < 1) {
            document.getElementById('lightboxContainer').style.height = '450px';
            document.getElementById('lightboxFooter').style.display = 'none';
        }
        else {
            document.getElementById('lightboxFooter').style.display = 'block';
            if ((gCartItemMultiplier * 1) > 2)
            { gCartItemMultiplier = 2; }
            lightboxHeight = ((gCartItemMultiplier * 1) * 85) + 70;
            document.getElementById('lightboxContainer').style.height = lightboxHeight + 'px';

            lightboxFooterTop = ((lightboxHeight * 1) + 70);
            document.getElementById("lightboxFooter").style.top = lightboxFooterTop + 'px';

            userAgent = navigator.userAgent.toLowerCase();
            if (userAgent.indexOf("safari") != -1) {
                setInnerHTML(document.getElementById("lightboxFooter"), document.getElementById("divHiddenMiniCartFooter").innerHTML, 1);
            }
            else {
                document.getElementById("lightboxFooter").innerHTML = document.getElementById("divHiddenMiniCartFooter").innerHTML;
            }
        }

        goToPageTop();
    }
    else {
        document.getElementById('lightboxMenu').style.display = 'none';
        document.getElementById('lightboxContainer').style.display = 'none';
        document.getElementById('lightboxFooter').style.display = 'none';
        document.getElementById('lightboxBackground').style.display = 'none';
    }
}

function showLightbox()
{ showHideLightbox('show'); }

function showLightboxBackground() {
    document.getElementById('lightboxBackground').style.display = 'block';
    if (gPageBottom > 0) {
        document.getElementById("lightboxBackground").style.height = ((gPageBottom * 1) + 20) + "px";
    }
}

function showLightboxPopup(width, height, url) {
    showLightboxBackground();
    document.getElementById('lightboxPopupMenu').style.display = 'block';
    document.getElementById('lightboxPopupMenu').style.width = ((width*1) + 10) + 'px';
    document.getElementById('lightboxPopupContainer').style.display = 'block';
    document.getElementById('lightboxPopupContainer').style.width = ((width * 1) + 10) + 'px';
    document.getElementById('lightboxIFrame').style.display = 'block';
    document.getElementById('lightboxIFrame').style.height = height + 'px';
    document.getElementById('lightboxIFrame').style.width = width + 'px';
    document.getElementById('lightboxIFrame').src = url;
    goToPageTop();
}

function updateCartItem(controlId) {
    if ((document.getElementById(controlId).value * 1) < 1)
    { alert("Please specify a valid amount for quantity"); }
    else {
        document.getElementById("__EVENTTARGET").value = "UpdateCart";
        document.getElementById("__EVENTARGUMENT").value = "";
        theForm.submit();
    }
}
