﻿// JScript File

function CheckAllInColumn(el)
{
    var column = el.parentNode;
    var table = column.parentNode.parentNode;
    for (var i = 0; i < table.rows.length; i++)
    {
        var chBox = table.rows[i].cells[column.cellIndex].getElementsByTagName('input')[0];
        if (typeof(chBox) != "undefined" && chBox.type == "checkbox" && chBox.disabled == false)
        {
            chBox.checked = el.checked;
        }
    }
}



function CheckColumn(el)
{
    var column = el.parentNode;
    var table = column.parentNode.parentNode;
    var allChecked = true;
    var cbAll;
    for (var i = 0; i < table.rows.length; i++)
    {
        var chBox = table.rows[i].cells[column.cellIndex].getElementsByTagName('input')[0];
        if (typeof(chBox) != "undefined" && chBox.type == "checkbox" && chBox.disabled == false)
        {
            if (chBox.id == "pdf_all" || chBox.id == "cd_all" || chBox.id == "paper_all")
            {
                cbAll = chBox;
            }
            else if (!chBox.checked)
            {
                allChecked = false;
                break;
            }
        }
    }
    cbAll.checked = allChecked;
}

/**
 * Sets cookie
 * @param cookieName  Name of cookie
 * @param cookieValue  Value of cookie
 * @param [time]
 * @param [typeOfTime]  Type of time as string (e.g. "day", "hour"). default considered as "sec"
 * @param [path]  Path where the cookie is valid (default: path of calling document)
 * @param [domain]  Domain where the cookie is valid (default: domain of calling document)
 * @param [secure]  Boolean value indicating if the cookie transmission requires a secure transmission
*/
function setCookie(cookieName, cookieValue, time, typeOfTime, path, domain, secure)
{
    if (time)
    {
        var today = new Date();
        var expire = new Date();
        var add = 0;
        switch(typeOfTime)
        {
            case "day":
            case "days" :
                add = 3600000*24*time; break;
            case "hour":
            case "hours":
                add = 3600000*time; break;
            default : // seconds
                add = 1000*time;
        }
        expire.setTime(today.getTime() + add);
    }
    document.cookie = cookieName + "=" + escape(cookieValue) + 
        ((expire) ? "; expires=" + expire.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");     
}


/**
 * Gets the value of the specified cookie.
 * @param name  Name of the desired cookie.
 * @return a string containing value of specified cookie, or null if cookie does not exist.
 */
function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}


/**
 * Deletes the specified cookie.
 * @param name      name of the cookie
 * @param [path]    path of the cookie (must be same as path used to create cookie)
 * @param [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

function bookmark(url, description)
{
    netscape="Netscape User's hit CTRL+D to add a bookmark to this site."
    if (navigator.appName=='Microsoft Internet Explorer')
    {
        window.external.AddFavorite(url, description);
    }
    else if (navigator.appName=='Netscape')
    {
        alert(netscape);
    }
}

function changeOpac(opacity, elID)
{
    var el = document.getElementById(elID);
    if (!el) return;
    if (el.style.filter != undefined)
        el.style.filter = "alpha(opacity=" + opacity + ")";
    if (el.style.opacity != undefined)
        el.style.opacity = (opacity / 100);
    if (el.style.MozOpacity != undefined)
        el.style.MozOpacity = (opacity / 100);
    if (el.style.KhtmlOpacity != undefined)
        el.style.KhtmlOpacity = (opacity / 100);
}

