/* Some Javascript-functions */

/* Open eg. links with rel="external" in new windows, taken from http://www.sitepoint.com/article/standards-compliant-world/ */
function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href")){
			if(anchor.getAttribute("rel") == "external"){
				anchor.target = "_blank";
			}else{
				if(anchor.getAttribute("rel") == "content"){
					anchor.target = "_content";
				}else{
					if(anchor.getAttribute("rel") == "self"){
						anchor.target = "_self";
					}
				}
			}
		}
	}
	addform = document.getElementById("addform");
	if(addform){
		addform.target = "_content";
	}
}

/* Jump to field with id "firstfield", if that does not exist, jump to field with id "searchform" */
function firstField(){
	firstinput = document.getElementById("firstfield");
	if(firstinput){
		firstinput.focus();
	}/*else{
		searchform = document.getElementById("searchform");
		if(searchform){
			searchform.str.focus();
		}
	}*/
}

/* Functioncalls which should be executed after loading the page */
function onloadCalls(){
	externalLinks();
	firstField();
}

/* Add the mozilla-sidebar */
function addmozbar(url) { 
	if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) { 
		window.sidebar.addPanel ("LinkLib3 - Sidebar", url, ""); 
    } else  { 
		var rv = window.confirm ("The Mozilla Sidebar works with Mozilla-based Browsers or NS6. " + "Do you want to upgrade?"); 
		if (rv){ 
			document.location.href = "http://www.mozilla.org/releases/";
		}
	} 
}

/* Go to the selected category */
function go(sel){
	if (sel != ""){
		var basis = "?category=";
		selelem = document.getElementById(sel);
		where = selelem.options[selelem.selectedIndex].value;
		location.href = basis + where;
	}
}

/* Set Onload-Handler */
window.onload = onloadCalls;
