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,pictureId) {
    openImageWindowFromHref(link.href,picutreId)
}

function openRecomendationWindow(articleId) {
     window.open("/content/recommend.jsf?articleId="+articleId, "recommend", "width=1, height=1, menubar=false, status=false, toolbar=false,scrollbars=false");
}

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

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

function openFlashWindowNoVote(link, width, height, pictureId) {
    openFlashWindowFromHref(link.href, width, height, pictureId, false)
}

function openFlashWindowEx(link, width, height, pictureId) {
    openFlashWindowFromHref(link, width, height, pictureId)
}

function openFlashWindowFromHref(href, width, height, pictureId,showVote) {
	var windowHeight = height+20;
	if(showVote){
		windowHeight += 50;
	}
	var browser = detectBrowser();
	if(browser.browser == 'Internet Explorer' && browser.version == 7){
		windowHeight += 20;
	} else if (browser.browser == 'Safari'){
		windowHeight +=20;
		width += 5;
	}
    window.open("/content/showFlash.jsf?path="+href+"&width="+width+"&height="+height+"&pictureId="+pictureId+"&showVote="+showVote, "image", 
    		"width="+(width+22)+", height="+windowHeight+ ",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 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";
            }
        }
    }
}

		function linkActive() {
		    var content = document.getElementById("td-refs-content");
		    function content_display(cond) {
		        content.style.display = "block";
		    }
		    toggle_class_by_id("td-refs", 'content-inside-open', 'content-inside-open', content_display);
		
		    return true;
		}

function openPrintWindow(type,id){
	window.open("/content/print_article.jsf?type="+type+"&id="+id,"Print_Article","width=600,height=800,scrollbars=1");
	return false;
}
            
//writeStyleLink(styles);  
 
