// Adjust footer according to the container height
function ach() {
    var container = window.document.getElementById('main');
    var hContainer = container.offsetHeight;
    var maxHeight = hContainer;
    var hContLeft = window.document.getElementById('contentLeft').offsetHeight;
    var hContRight = window.document.getElementById('contentRight').offsetHeight;
    var maxContentHeight = Math.max(hContLeft, hContRight);
    window.document.getElementById('footer').style.marginTop = 0 + 'px';
    window.document.getElementById('footer').style.top = maxHeight + 'px';
    window.document.getElementById('content').style.height = maxContentHeight + 'px';
    if (window.document.getElementById('ctl00_pnlLeaderBoard') != null) {
        window.document.getElementById('goesToTop').style.top = '98px';
        if (window.document.getElementById('ctl00_BannerLeaderBoard_pnlBannerImage') == null && window.document.getElementById('ctl00_BannerLeaderBoard_pnlBannerFls') == null) {
            window.document.getElementById('ctl00_pnlLeaderBoard').style.display = 'none';
            window.document.getElementById('goesToTop').style.top = '4px';
        }
        
    }
    if (window.document.getElementById('cCRt') == null) {
        window.document.getElementById('container').style.background = 'url(App_themes/General/Layout/contentBg.png)';
    }
}
// if this is the only one script file, uncomment the following line!
//window.onload = function(){ AdjustColumnsHeight();}
function hssc() {

    if (window.document.getElementById('ctl00_btnShoppingCart') != null)
    { window.document.getElementById('ctl00_pnlEShop').style.display = 'block'; }
    else
    { window.document.getElementById('ctl00_pnlEShop').style.display = 'none'; }
}

window.onload = function() {
 
    //ach();
}

window.onresize = function() {
    ach();
}

// show/hide the share article div
function showTagger(obj) {
    var el = window.document.getElementById(obj);
    if (el != "") {
        if (el.style.display == "none") {
            el.style.display = "block";
        } else {
            el.style.display = "none";
        }
    } ach();
}
// show/hide modal popus for logging
function ShowLoginPopup() {
    $find(
"openLogin").show();
    HideRegisterPopup();
    HidePasswordRecoveryPopup();
}
function HideLoginPopup() {
    $find(
"openLogin").hide();
}
function ShowRegisterPopup() {
    $find(
"openRegister").show();
    HideLoginPopup();
    HidePasswordRecoveryPopup();
}
function HideRegisterPopup() {
    $find(
"openRegister").hide();
}
function ShowPasswordRecoveryPopup() {
    $find(
"openPasswordRecovery").show();
    HideLoginPopup();
    HideRegisterPopup();
}
function HidePasswordRecoveryPopup() {
    $find(
"openPasswordRecovery").hide();
}
function popUp(URL) {
    day = new Date();
    id = day.getTime();
    eval("pageI" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=600,height=400,left = 200,top = 200');");
}
function GetImage(ImageUrl, ret) {

    var currentImgId = ImageUrl;
    $get('popImage').innerHTML = ImageUrl;
    var setimg = new Array();

    function preloading() {
        for (x = 0; x < preloading.arguments.length; x++) {
            setimg[x] = new Image();
            setimg[x].src = preloading.arguments[x];
            setimg[x].alt = preloading.arguments[x];
            //window.document.getElementById('ctl00_pnlImageUrlPopup').style.top = 0;
            //window.document.getElementById('ctl00_upImagePopup').style.top = 0;
        }
    }
    preloading(ImageUrl);
    window.document.getElementById('popImage').innerHTML = "<img src=\"" + setimg[0].alt + "\" alt=\"" + setimg[0].alt + "\" />";
    ShowImageUrlPopup();
}
function ShowImageUrlPopup() {
    $find(
"openImageUrl").show();
}
function HideImageUrlPopup() {
    $find(
"openImageUrl").hide();
}


// Accordion script, v. 0.2 Ryan Vannin
//
//
var w = window.document;
var tab = new Array();
var te = new Array();
var th = new Array();
var spta = 0;
var sptb = 0;
var st, ht;

function tabs() {
    if (w.getElementById("tab0") != null) {
        var tabs = getElementsByClassName(document, "div", "tabs");
        for (var i = 0; i < tabs.length; i++) {
            te[i] = tabs[i];
            th[i] = parseInt(tabs[i].offsetHeight);
            tabs[i].style.display = 'none';
            tabs[i].style.zIndex = i;
        }
        var x = readCookie("accCookie");
        if (x) {
            w.getElementById('tab' + x).style.display = 'block';
            tab[x] = w.getElementById('tab' + x);
            accordion(x);
        } else {
            w.getElementById('tab0').style.display = 'block';
            tab[0] = w.getElementById('tab0');
            accordion(0);
        }
        ach();
    }
}

//
// Tab function
//
function accordion(index) {
    clearInterval(ht);
    clearInterval(st);
    var tabs = getElementsByClassName(document, "div", "tabs");
    for (var i = 0; i < tabs.length; i++) {
        if (i != index) {
            w.getElementById("accdn" + i).className = "accdn";
            w.getElementById("haccdn" + i).className = "accdn";
            w.getElementById("aaccdn" + i).className = "accdn";
            if (tabs[i].style.display == 'block') {
                tab[0] = w.getElementById("tab" + i);
                ht = setInterval("fht(" + i + ")", 1);
            }
        } else {

        }
    }
    createCookie("accCookie", index, 1);
    w.getElementById("accdn" + index).className = "accdnopen";
    w.getElementById("haccdn" + index).className = "accdnopen";
    w.getElementById("aaccdn" + index).className = "accdnopen";
    st = setInterval("fst(" + index + ")", 1);
    ach();
}

var ob = 100;
var oa = 0;

function fht(index) {
    var el = tab[0];
    var b = th[index];
    sptb = sptb + 10;
    ob = ob - sptb;
    b = Math.round(b - sptb * (th[index] / 100));
    el.style.height = b + 'px';
    el.style.filter = 'alpha(opacity=' + ob + ');';
    el.style.opacity = ob;
    el.style.MozOpacity = ob;
    if (ob <= 0) {
        el.style.filter = 'alpha(opacity=0);';
        el.style.opacity = 0;
        el.style.MozOpacity = 0;
    }
    if (b <= 0) {
        clearInterval(ht);
        sptb = 0;
        ob = 100;
        el.style.height = '0px';
        el.style.display = 'none';
        ach();
    }
}

function fst(index) {
    var el = te[index];
    var a = 0;
    if (el.offsetHeight < th[index]) {
        spta = spta + 10;
        oa = oa + spta;
        a = Math.round(1 + spta * (th[index] / 100));
        el.style.display = 'block';
        el.style.height = a + 'px';
        el.style.filter = 'alpha(opacity=' + oa + ');';
        el.style.opacity = oa;
        el.style.MozOpacity = oa;
        if (oa >= 100) {
            el.style.filter = 'alpha(opacity=100);';
            el.style.opacity = 100;
            el.style.MozOpacity = 100;
        }
    }
    if (a >= th[index]) {
        el.style.height = th[index] + 'px';
        clearInterval(st);
        spta = 0;
        oa = 0;
        ach();
    }
}

//
// Slider script, v. 0.2 Ryan Vannin
//
var slide = new Array();
var sp = new Array();
var spsa = 0;
var spsb = 0;
var fms;
var ms;
var sw = 300;

function slides() {
    var sliders = getElementsByClassName(document, "table", "sliders");
    for (var i = 0; i < sliders.length; i++) {
        var slider = w.getElementById("slider" + i + "");
        slider.style.left = '0px';
        var slides = getElementsByClassName(slider, "div", "slides");
        sp[i] = new Array();
        if (slides.length > 0) {
            for (var j = 0; j < slides.length; j++) {
                sp[i][j] = -(j * sw);
            }
        }
    }
    slideNext(0, 0);
}


//
// Slider function
//
function slideNext(index, next) {
    clearInterval(ms);
    var slider = w.getElementById("slider" + index + "");
    var slides = getElementsByClassName(slider, "div", "slides");
    slide[0] = slider;
    //w.getElementById("test").innerHTML += index + " " + next + " ";
    ms = setInterval("fms(" + index + ", " + next + ")", 1);
}

function fms(index, next) {
    var el = slide[0];
    var p = Math.abs(parseInt(el.style.left));
    var n = Math.abs(sp[index][next]);
    var d = p - n;
    var a = 0;
    if (d <= 0) {
        spsa = spsa + 1;
        a = Math.floor(p + spsa);
        el.style.left = (-a) + 'px';
        if (a >= n) {
            spsa = 0;
            clearInterval(ms);
            el.style.left = (-n) + 'px';
        }
    } else {
        spsb = spsb - 1;
        a = Math.floor(p + spsb);
        el.style.left = (-a) + 'px';
        if (a <= n) {
            spsb = 0;
            clearInterval(ms);
            el.style.left = (-n) + 'px';
        }
    }
}

/*
the getElementsByClassName function I pilfered from this guy. It's
a useful function that'll return any/all tags with a specific css class.
Written by Jonathan Snook, http://www.snook.ca/jonathan
Add-ons by Robert Nyman, http://www.robertnyman.com
*/
function getElementsByClassName(oElm, strTagName, strClassName) {
    // first it gets all of the specified tags
    var arrElements = (strTagName == "*" && document.all) ? document.all : oElm.getElementsByTagName(strTagName);
    // then it sets up an array that'll hold the results
    var arrReturnElements = new Array();
    // some regex stuff you don't need to worry about
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    // now it iterates through the elements it grabbed above
    for (var i = 0; i < arrElements.length; i++) {
        oElement = arrElements[i];
        // if the class matches what we're looking for it ads to the results array
        if (oRegExp.test(oElement.className)) {
            arrReturnElements.push(oElement);
        }
    }
    // then it kicks the results back to us
    return (arrReturnElements)
}

function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name, "", -1);
}

var state = 'hidden';
function showhide(layer_ref) {
    if (state == 'visible') {
        state = 'hidden';
    }
    else {
        state = 'visible';
    }
    if (document.all) { //IS IE 4 or 5 (or 6 beta)
        eval("document.all." + layer_ref + ".style.visibility = state");
    }
    if (document.layers) { //IS NETSCAPE 4 or below
        document.layers[layer_ref].visibility = state;
    }
    if (document.getElementById && !document.all) {
        maxwell_smart = document.getElementById(layer_ref);
        maxwell_smart.style.visibility = state;
    }
}

if (document.all && /MSIE (5\.5|6)/.test(navigator.userAgent) &&
  document.styleSheets && document.styleSheets[0] && document.styleSheets[0].addRule) {
    //document.styleSheets[0].addRule('*', 'behavior: url(App_Themes/General/iepngfix.htc)');
    // Feel free to add rules for specific elements only, as above.
    // You have to call this once for each selector, like so:
    document.styleSheets[0].addRule('img', 'behavior: url(App_Themes/General/iepngfix.htc)');
    //document.styleSheets[0].addRule('div', 'behavior: url(App_Themes/General/iepngfix.htc)');
}