function toggleDisplay(elementId)
{
    if (document.getElementById)
    {
        object = document.getElementById(elementId);
        if (object.style.display == "none") { object.style.display = ""; }
        else { object.style.display = "none"; }
    }
}

function isAjaxRequestOk(httpRequest)
{
    if (httpRequest.readyState == 4)
    {
        if (httpRequest.status == 200)
        {
            return true;
        }
    }

    return false;
}

function getAjaxRequest()
{
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        httpRequest = new XMLHttpRequest();
        if (httpRequest.overrideMimeType) {
            httpRequest.overrideMimeType('text/xml');
        }
    } else if (window.ActiveXObject) { // IE
        try {
            httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }

    return httpRequest;
}

function encode(uri)
{
    if (encodeURIComponent) { return encodeURIComponent(uri); }
    if (escape) { return escape(uri); }
}

function textFadeOut(id)
{
    textFadeOut2(id, 0);
}

function textFadeOut2(id, hex)
{
    if (document.getElementById(id))
    {
        if (hex < 255)
        {
            hex += 5;
            document.getElementById(id).style.color = "rgb("+hex+","+hex+","+hex+")";
            setTimeout("textFadeOut2('"+id+"', "+hex+")", 20);
        }
    }
}

// http://www.brainerror.net/scripts_js_blendtrans.php
function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

// http://www.brainerror.net/scripts_js_blendtrans.php
//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}
