/* (C) Copyright 2006 Caderra Zofia Kornecka, Wszystkie Prawa Zastrzezone (All Rights Reserved).   */
/*                                                                                                 */
/* Ten program komputerowy jest chroniony prawem autorskim. Jakiekolwiek uzytkowanie, kopiowanie   */
/* badz rozpowszechnianie tego programu lub jakiejkolwiek jego czesci bez pisemnego upowaznienia   */
/* jest zabronione i moze spowodowac pociagniecie do odpowiedzialnosci cywilnej i karnej           */
/* w maksymalnym zakresie dopuszczalnym przez prawo.                                               */

function detectBrowser() {
    var detect = navigator.userAgent.toLowerCase();
    var OS,browser,version,total,thestring;

    if (checkIt('konqueror'))
    {
        browser = "Konqueror";
        OS = "Linux";
    }
    else if (checkIt('safari')) browser = "Safari"
    else if (checkIt('omniweb')) browser = "OmniWeb"
    else if (checkIt('opera')) browser = "Opera"
    else if (checkIt('webtv')) browser = "WebTV";
    else if (checkIt('icab')) browser = "iCab"
    else if (checkIt('msie')) browser = "Internet Explorer"
    else if (!checkIt('compatible'))
    {
        browser = "Netscape Navigator"
        version = detect.charAt(8);
    }
    else browser = "An unknown browser";

    if (!version) version = detect.charAt(place + thestring.length);

    if (!OS)
    {
        if (checkIt('linux')) OS = "Linux";
        else if (checkIt('x11')) OS = "Unix";
        else if (checkIt('mac')) OS = "Mac"
        else if (checkIt('win')) OS = "Windows"
        else OS = "an unknown operating system";
    }

    function checkIt(string)
    {
        place = detect.indexOf(string) + 1;
        thestring = string;
        return place;
    }
    return {"browser" : browser, "version" : version, "os" : OS};
}

function writeStyleLink(params) {
    if (params.other == null) {
        params.other = params.ie
    }
    var browserData = detectBrowser();
    if (browserData["browser"] == "Opera") {
        var version = browserData["version"] - 0;
        if (version >= 9) {
            document.write('<link rel="stylesheet" href="' + params.opera9 + '">');
        }
        else {
            document.write('<link rel="stylesheet" href="' + params.opera + '">');
        }
    } else if (browserData["browser"] == "Netscape Navigator") {
        document.write('<link rel="stylesheet" href="' + params.firefox + '">');
    } else if (browserData["browser"] == "Internet Explorer") {
        document.write('<link rel="stylesheet" href="' + params.ie + '">');
    } else {
        document.write('<link rel="stylesheet" href="' + params.other + '">');
    }
}

function disableLink(link) {
    document.getElementById("content").style.display = "none";
    document.getElementById("content2").style.display = "block";
    return true;
}

function openImageWindow(link) {
    openImageWindowFromHref(link.href)
}

function openImageWindowFromHref(href) {
    window.open("/content/showImage.jsf?path="+href, "image", "width=1, height=1, menubar=false, status=false, toolbar=false");
}

function openFlashWindow(link, width, height) {
    openFlashWindowFromHref(link.href, width, height)
}

function openFlashWindowFromHref(href, width, height) {
    window.open("/content/showFlash.jsf?path="+href+"&width="+width+"&height="+height, "image", "width="+width+", height="+height+", menubar=false, status=false, toolbar=false");
}

function showFaq(faqId) {
    window.location = "?resource=Faq&id=" + faqId;
}

//function showFaqSet(faqSetId) {
//    window.location = "?resource=FaqSet&id=" + faqSetId;
//}

function showFaqSet(faqSetId) {
    window.open("/content/faqset.jsf?resource=FaqSet&id=" + faqSetId, null, "width=800,height=600");
}

function switchFaqSet(faqSetId) {
    var id = "display:faqSetList:"+faqSetId+":faqset"
    r = RegExp("display:faqSetList:(\\d+):faqset")
    var faqSet = document.getElementById(id)
    var children = faqSet.parentNode.childNodes
    for(var i = 0; i < children.length; i++) {
        var child = children[i]
        if (child.id != null && child.id.match(r)) {
            if(child.id.match(r)[1] == faqSetId) {
                child.style.display = "block";
            } else {
                child.style.display = "none";
            }
        }
    }
}