﻿function addLoadEvent(func) {   
    var oldonload = window.onload;   
    if (typeof window.onload != 'function') {   
        window.onload = func;   
    } else {   
        window.onload = function() {   
            if (oldonload) {   
                oldonload();   
            }   
            func();   
        }   
    }   
}  


function setSize() {
    // calculate available height
    if(typeof(window.innerWidth) == 'number') {
        //not ie
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        // ie 6+ 
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        // ie 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    } 
    
    var bb = document.getElementById("content-barebody");
    var dh = document.getElementById("content-barebody-domainhome");
    var h = dh.style.height;
    var w = dh.style.width;
    
    bb.style.height = myHeight + 'px';
    dh.style.top = (myHeight/2) - 80 + 'px';
}

function redirect(ddl) {
    var idx  = ddl.selectedIndex;
    var value = ddl.options[idx].value;
    if(value != "0") top.location.href = "/" + value.toLowerCase();
}

addLoadEvent(setSize);
window.onresize = setSize;

function onLoadBG() {
    if (($(window).height() < $(document).height())) {
        if (($(document).height() > $("div#content-barebody").height())) {
            $("body").height($(window).height());
        }
        else {
            $("body").height($(document).height());
        }
    } else {
        $("body").height($(window).height());
    }
}

function onResizeBG() {
    if (!($(window).height() < $(document).height())) {
        if (($(document).height() > $("div#content-barebody").height())) {
            $("body").height($(window).height());
        }
        else {
            $("body").height($(document).height());
        }
    } else {
        $("body").height($(window).height());
    }
}

$(window).load(function() {
    onLoadBG();
});


$(window).resize(function() {
    onResizeBG();
});
