﻿function toggleDisplay(thisObject) {
    // v3.1 05/11/2007 - Jay Hayman
    var isHidden = document.getElementById(thisObject).style.display;

    switch (isHidden) {
        case "none":
            document.getElementById(thisObject).style.display = "block";
            break;
        case "block":
            document.getElementById(thisObject).style.display = "none";
            break;
    }
}

function toggleProgress(thisHide, thisShow) {
    document.getElementById(thisHide).style.display = "none";
    document.getElementById(thisShow).style.display = "block";
}

function toggleProgressNoHide(thisShow) {
    document.getElementById(thisShow).style.display = "block";
}

function clearTextBox(thisObject) {
    // v1.0 06/11/2007 - Jay Hayman
    document.getElementById(thisObject).value = "";
}

function CheckAll(checkAllBox, thisObject) {
    // v1.0 08/02/2008 - Jay Hayman
    // Toggle all checkboxes (.net object).

    var frm = document.forms[0]
    var actVar = checkAllBox.checked;
    for (i = 0; i < frm.length; i++) {
        e = frm.elements[i];
        if (e.type == 'checkbox' && e.name.indexOf(thisObject) != -1)
            e.checked = actVar;
    }
}

// preload the images 
function preload() {
    var tmp = null;
    
    try {
        for (var j = 0; j < imgs.length; j++) {
            tmp = imgs[j];
            imgs[j] = new Image();
            imgs[j].src = tmp;
        }
    } catch (e) {
        // nothing 
    }
}
void (preload());

// swap images 
function imgSwap(img, swap) {
    img.src = imgs[swap].src;
}

function popupImage(strImage, strTitle) {
    myWindow = window.open("/wiscmsToolkit/functions/popupresize.aspx?image=" + strImage + '&title=' + strTitle, "popupImage", 'alwaysRaised=yes,innerHeight=496,innerWidth=656,location=no,menubar=no,resizable=yes,status=no,titlebar=no')
}

// Font AAA Resizer
function changeFont(fontClass) {
    var element = document.getElementById(fontElementId);
    element.className = fontClass;
    setCookie("fontSize", fontClass, 5, "/", "", "");
}

/* Module Set Default Font Size (void) */
function setDefaultFontSize() {
    var fontSize = getCookie("fontSize")
    if (fontSize) {
        var element = document.getElementById(fontElementId);
        element.className = fontSize;
    }
}

function setCookie(name, value, expires, path, domain, secure) {
    var today = new Date();
    today.setTime(today.getTime());
    
    if (expires) {
        expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date(today.getTime() + (expires));

    document.cookie = name + "=" + escape(value) +
        ((expires) ? ";expires=" + expires_date.toGMTString() : "") +
        ((path) ? ";path=" + path : "") +
        ((domain) ? ";domain=" + domain : "") +
        ((secure) ? ";secure" : "");
}

function getCookie(check_name) {
    var a_all_cookies = document.cookie.split(';');
    var a_temp_cookie = '';
    var cookie_name = '';
    var cookie_value = '';
    var b_cookie_found = false;

    for (i = 0; i < a_all_cookies.length; i++) {
        a_temp_cookie = a_all_cookies[i].split('=');

        cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

        if (cookie_name == check_name) {
            b_cookie_found = true;
            if (a_temp_cookie.length > 1) {
                cookie_value = unescape(a_temp_cookie[1].replace(/^\s+|\s+$/g, ''));
            }
            return cookie_value;
            break;
        }
        a_temp_cookie = null;
        cookie_name = '';
    }
    if (!b_cookie_found) {
        return null;
    }
}

// Read ASP.NET set cookie pairs (useful for AJAX/Mash-ups).
function readCookie(sCookieName, sCookiePairedName) {
    var nameEQ = sCookieName + "=";
    var ca = document.cookie.split(';');
    var sCookieValueSplit;
    var sCookiePairedValues;

    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) {
            sCookiePairedValues = c.substring(nameEQ.length, c.length).split('&');
            for (x = 0; x < sCookiePairedValues.length; x++) {
                sCookieValueSplit = sCookiePairedValues[x].split("=");
                if (sCookieValueSplit[0] == sCookiePairedName) {
                    return sCookieValueSplit[1];
                }
            }
            return null; // cookie value match not found!
        }
    }
    return null; // cookie probably not defined!
}

// Set a div's height based on the content of another div. Ideal for abosulute positioned
// divs floating over a background that needs to expand to the size of content.
function setDivHeight(content, placeholder, yoffset) {
    var divContent = document.getElementById(content)
    var divPlaceholder = document.getElementById(placeholder)

    // IE6 marlarky again.
    isIE6 = /msie|MSIE 6/.test(navigator.userAgent);
    if (isIE6) { yoffset += yoffset }
    
    divPlaceholder.style.height = divContent.offsetHeight - yoffset + "px";
}