function changeDisplay(sName, sForce) {

    var oName = document.getElementById(sName);
    if (oName == undefined) return false;

    if (sForce == undefined) {
        if ((oName.style.display == "block" && oName.style.visibility == "visible") || (oName.style.display == "" && oName.style.visibility == "")) {
            sForce = "hide";
        }
        else {
            sForce = "show";
        }
    }

    if (sForce == "hide") {
        oName.style.display = "none";
        oName.style.visibility = "hidden";
    }
    else if (sForce == "show") {
        oName.style.display = "block";
        oName.style.visibility = "visible";
    }
}

// alerts support - see browserWarning.jsp for example

function setCookie(name, value) {
    document.cookie = name + '=' + value + ';path=/';
}

function getCookie(c_name) {
    if (document.cookie.length>0)
    {
        var c_start=document.cookie.indexOf(c_name + "=");
        if (c_start!=-1)
        {
            c_start=c_start + c_name.length+1;
            var c_end=document.cookie.indexOf(";",c_start);
            if (c_end==-1) c_end=document.cookie.length;
            return unescape(document.cookie.substring(c_start,c_end));
        }
    }
    return "";
}

function hideAlert(divId) {
    jQuery("#"+divId).slideUp("slow");
    document.cookie = divId+"_closed=true;path=/";
}

function showAlertForSeconds(divId, seconds, showSlowly) {
    if (showSlowly) {
        jQuery("#"+divId).slideDown("slow");
    } else {
        jQuery("#"+divId).show();
    }
    setTimeout("hideAlert('"+divId+"')", seconds * 1000);
}

function keepAlertDisplayedForSeconds(divId, seconds) {
    var timeShownCookieName = divId+"_time";
    var closedCookieName = divId+"_closed";

    var currentTimeSeconds = (new Date().getTime() / 1000);
    var timeShown = getCookie(timeShownCookieName);
    if (timeShown == "") {
        document.cookie = timeShownCookieName+"="+currentTimeSeconds+";path=/;";
        jQuery().ready(function(){
            showAlertForSeconds(divId, seconds, true);
        });
    } else if (getCookie(closedCookieName) == "") {
        var timeShownSeconds = parseInt(timeShown);
        if (currentTimeSeconds < timeShownSeconds + seconds) {
            showAlertForSeconds(divId, seconds - (currentTimeSeconds - timeShownSeconds), false);
        }
    }
}

function resetAlert(divId) {
    var d = new Date();
    d.setTime(0);
    document.cookie = divId+"_time=0;expires=" + d.toUTCString()+";path=/;";
    document.cookie = divId+"_closed=0;expires=" + d.toUTCString()+";path=/;";
}

var IE6 = (navigator.userAgent.toLowerCase().indexOf('msie 6') != -1) && (navigator.userAgent.toLowerCase().indexOf('msie 7') == -1);

function loadingMessage(divId) {
    var addTodiv = document.getElementById(divId);
    addTodiv.style.display = "none";
    addTodiv.style.visibility = "hidden";
    var loadingDiv = document.getElementById(divId + "_loading");
    loadingDiv.style.display = "block";
    loadingDiv.style.visibility = "visible";
}

function endLoadingMessage(divId) {
    var addTodiv = document.getElementById(divId);
    addTodiv.style.display = "block";
    addTodiv.style.visibility = "visible";
    var loadDiv = document.getElementById(divId + "_loading");
    loadDiv.style.display = "none";
    loadDiv.style.visibility = "hidden";
}

function getPressedKey(e) {
    if (window.event) {
        return window.event.keyCode;
    } else if (e) {
        return e.which;
    }
    return null;
    
}

var _rrPageValues;

function appendPageValuesToQuery(query) {
    for (var key in _rrPageValues) {
        query[key] = _rrPageValues[key];
    }
}

function setPageValue(name, value) {
    _rrPageValues[name] = value;
}

function appendPageValuesToURL(url, escapeAmpersand) {
    if (escapeAmpersand == undefined) {
        escapeAmpersand = false;
    }
    var ampersand = escapeAmpersand ? '%26' : '&';
    var params = '';
    for (var key in _rrPageValues) {
        if (params.length > 0) {
            params += ampersand;
        }
        params += key + '=' + _rrPageValues[key];
    }
    if (url.indexOf('?') != -1 || url.indexOf('%3F') != -1 || url.indexOf('%3f') != -1) {
        if (url.lastIndexOf('&') == url.length - 1  || url.lastIndexOf('%26') == url.length - 3) {
            url += params;
        } else {
            url += ampersand + params;
        }
    } else {
        url += '?' + params;
    }
    return url;
}

function appendPageValuesToLink(link) {
    link.href = appendPageValuesToURL(link.href);
}

function storePageValuesInCookies() {
    for (var key in _rrPageValues) {
        setCookie('rrPageValue' + key, _rrPageValues[key]);
    }
}