﻿function Toggle(node) {
    // Unfold the branch if it isn't visible
    var nodeDiv = node.parentNode.childNodes[3];
    if (nodeDiv.style.display == 'none') {
        // Change the image (if there is an image)
        if (node.childNodes.length > 0) {
            if (node.childNodes.item(0).nodeName == "IMG") {
                node.childNodes.item(0).src = "../images/minus.gif";
            }
        }

        nodeDiv.style.display = 'block';
    }
    // Collapse the branch if it IS visible
    else {
        // Change the image (if there is an image)
        if (node.childNodes.length > 0) {
            if (node.childNodes.item(0).nodeName == "IMG") {
                node.childNodes.item(0).src = "../images/plus.gif";
            }
        }

        nodeDiv.style.display = 'none';
    }

}

function no_evt() {
}

function overControl(ctrl) {
    ctrl.style.cursor = 'pointer';    
}

function outControl(ctrl) {
    ctrl.style.cursor = 'default';
}
// load language

function load_language(lang_name) {
    showLightbox(1);
    var qry = "lang=" + lang_name;
    var submitTo = '../proc/load_language.aspx';
    http('POST', submitTo, load_language_callback, qry);
}

function load_language_callback(res) {
    if (res != '') {
        var jsonObj = new json_parse(res);
        load_language_to_control(jsonObj);        
    }    
    setTimeout("hideLightbox()", 100);
    
}

function load_language_to_control(jsonObj) {
    var i;
    var ctrl;
    for (i = 0; i < jsonObj.length; i++) {
        ctrl = document.getElementById(jsonObj[i].id);
        if (ctrl) {
            switch (ctrl.tagName.toLowerCase()) {
                case "span":
                    ctrl.innerHTML = StringJSON4Display(jsonObj[i].value);
                    break;
                case "img":
                    ctrl.src = StringJSON4Display(jsonObj[i].value);
                    break;
                case "a":
                    ctrl.innerHTML = StringJSON4Display(jsonObj[i].value);
                    break;
                case "input":
                    break;
            }

        }
    }
}

//  Login ---------------------------------------
function checkLogin() {
    var qry = "txt1=" + document.getElementById('txt1').value + "&txt2=" + document.getElementById('txt2').value;
    var submitTo = '../proc/check_login.aspx';
    http('POST', submitTo, checkLogin_callback, qry);
}

// ----------------------------------------------

function checkLogin_callback(res) {
    switch (res) {
        case "0":
            document.getElementById('divShowMsg').innerHTML = "Brugernavn eller password er ikke korrekt.";
            document.getElementById('divShowMsg').style.display = '';
            setTimeout("hidedivShowMsg( )", 2500);
            setFocus('frm1', 'txt1');
            break;
        case "1":
            location.href = "Home.aspx";
            break;
    }
}

//  Change Password ---------------------------------------
function changePass() {
    var a1 = document.getElementById('txt2').value;
    var a2 = document.getElementById('txt3').value;
    if (a1 != a2) {
        document.getElementById('divShowMsg').innerHTML = "Password og godkendt password er ikke den samme.";
        document.getElementById('divShowMsg').style.display = '';
        setTimeout("hidedivShowMsg( )", 2500);
        setFocus('aspnetForm', 'txt2');
    }
    else {
        var qry = "txt1=" + document.getElementById('txt1').value + "&txt2=" + document.getElementById('txt2').value;
        var submitTo = '../proc/change_pass.aspx';
        http('POST', submitTo, changePass_callback, qry);
    }
}

//  ---------------------------------------
function changePass_callback(res) {
    switch (res) {
        case "0":
            document.getElementById('divShowMsg').innerHTML = 'Change Password failed!';
            document.getElementById('divShowMsg').style.display = '';
            setTimeout("hidedivShowMsg( )", 2500);
            setFocus('aspnetForm', 'txt1');
            break;
        case "1":
            document.getElementById('divShowMsg').innerHTML = 'Change Password successfully.';
            document.getElementById('divShowMsg').style.display = '';
            setTimeout("hidedivShowMsg( )", 2500);
            setFocus('aspnetForm', 'txt1');
            break;
    }
}

// Bottom Slide of Products --------------------------------------------------------------------------------------------------
function initSlide() {
    $(".slide img").click(function() {
        // show small image to larger image
        $(".image_product .mid img").attr("src", $(this).attr("src"));
        // click ingame tranfer siteid
        // $(".mid a").attr("href", "BillBoard,View," + $.trim($(this).attr("alt")) + ".bb");
    }
   )
    $(".image_product .Contentslide").jCarouselLite(
    {
        speed: 1500,
        visible: 5,
        auto: 10,
        easing: "backout"
    }
   )
    // set img when page load
    $(".image_product .mid img").attr("src", $(".slide img").eq(0).attr("src"));
}
// Common -------------------------------------------------------------------------------------------------
function setFocus(formInst, elementInst) {
    if (document.forms.length > 0) {
        document.forms[formInst].elements[elementInst].focus();
    }
}

function checkEnter() {
    nn = (document.layers) ? true : false;
    ie = (document.all) ? true : false;
    document.onkeyup = keyUp;
    if (nn) document.captureEvents(Event.KEYUP);
}

function keyUp(e) {
    var evt = (e) ? e : (window.event) ? window.event : null;
    if (evt) {
        var key = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
        if (key == "13")
            checkLogin();
    }
}

function hidedivShowMsg() {
    document.getElementById('divShowMsg').style.display = 'none';
}

// ----------------------------------------------------------------------------------------------------

function getPageScroll() {

    var yScroll;

    if (self.pageYOffset) {
        yScroll = self.pageYOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
        yScroll = document.documentElement.scrollTop;
    } else if (document.body) {// all other Explorers
        yScroll = document.body.scrollTop;
    }

    arrayPageScroll = new Array('', yScroll)
    return arrayPageScroll;
}

function getPageSize() {

    var xScroll, yScroll;

    if (window.innerHeight && window.scrollMaxY) {
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }

    var windowWidth, windowHeight;
    if (self.innerHeight) {	// all except Explorer
        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;
    }

    // for small pages with total height less then height of the viewport
    if (yScroll < windowHeight) {
        pageHeight = windowHeight;
    } else {
        pageHeight = yScroll;
    }

    // for small pages with total width less then width of the viewport
    if (xScroll < windowWidth) {
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }

    arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight)
    return arrayPageSize;
}

function hideLightbox() {
    // get objects
    objOverlay = document.getElementById('overlay');
    // hide lightbox and overlay
    objOverlay.style.display = 'none';
}

function showLightbox() {
    var objOverlay = document.getElementById('overlay');
    var objLoadingImage = document.getElementById('loadingImage');

    var arrayPageSize = getPageSize();
    var arrayPageScroll = getPageScroll();

    // set height of Overlay to take up whole page and show
    objOverlay.style.height = (arrayPageSize[1] + 'px');
    objOverlay.style.display = 'block';

    // center loadingImage if it exists
    if (objLoadingImage) {
        objLoadingImage.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - objLoadingImage.height) / 2) + 'px');
        objLoadingImage.style.left = (((arrayPageSize[0] - 20 - objLoadingImage.width) / 2) + 'px');
        objLoadingImage.style.display = 'block';
    }
}

function pause(numberMillis) {
    var now = new Date();
    var exitTime = now.getTime() + numberMillis;
    while (true) {
        now = new Date();
        if (now.getTime() > exitTime)
            return;
    }
}

function hideLightboxCart() {
    // get objects
    objOverlay = document.getElementById('overlay');
    // hide lightbox and overlay
    objOverlay.style.display = 'none';
}

function showLightbox(type) {
    var objOverlay = document.getElementById('overlay');
    var objLoadingImage = document.getElementById('loadingImage');
    var objCart = document.getElementById('frmCart');
    var objInvoice = document.getElementById('frmInvoice');
   
    
    
    var arrayPageSize = getPageSize();
    var arrayPageScroll = getPageScroll();

    // set height of Overlay to take up whole page and show
    objOverlay.style.height = (arrayPageSize[1] + 'px');
    objOverlay.style.display = 'block';

    // center loadingImage if it exists
    if (type == 1) {
        if (objLoadingImage) {
            objLoadingImage.style.display = '';
            objLoadingImage.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - objLoadingImage.height) / 2) + 'px');
            objLoadingImage.style.left = (((arrayPageSize[0] - 20 - objLoadingImage.width) / 2) + 'px');
            objLoadingImage.style.display = 'block';
        }       
    }
    else {
        if (type == 2) {
            if (objCart) {
                objLoadingImage.style.display = 'none';
                objCart.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - objCart.style.height) / 10) + 'px');
                objCart.style.left = (((arrayPageSize[0] - 20 - parseInt(objCart.style.width)) / 7) + 'px');
                objCart.style.display = 'block';                
            }            
        }        
        else {
            if (type == 3) {
                if (objInvoice) {
                    objLoadingImage.style.display = 'none';
                    objCart.style.display = 'none';
                    objInvoice.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - objInvoice.style.height) / 10) + 'px');
                    objInvoice.style.left = (((arrayPageSize[0] - 20 - parseInt(objInvoice.style.width)) / 7) + 'px');
                    objInvoice.style.display = 'block';
                }                
            }
        }
    }
}

function StringJSON4Display(str) {
    var searchStr = "'";
    var replaceStr = '"';
    var re = new RegExp(searchStr, "g");
    var result = str.replace(re, replaceStr);
    return result;
}

openWindow('','500','400');

function openWindow(vLink, vWidth, vHeight) {
    if (vLink == '') {
        return false;
    }

    hasScrollBar = "no";

    winDef = 'status=no,resizable=yes,scrollbars=no,toolbar=no,location=no,fullscreen=no,titlebar=no,height=' + vHeight + 'px, width=' + vWidth + 'px,';
    winDef = winDef.concat('top=').concat((screen.height - vHeight) / 2).concat(',');
    winDef = winDef.concat('left=').concat((screen.width - vWidth) / 2);
    newwin = window.open(vLink, '_blank', winDef);
}

