// JavaScript Document

/************************************************************************************
* AUTHOR: www.bluelinedesign.se - info@bluelinedesign.se

* NOTICE: This code may *NOT* be used for any purpose, commercial, private, 
* re-distribution or download without any further permission from the author. 
************************************************************************************/


/************************************************************************************
* displayContent - © Blueline Design 2005 (www.bluelinedesign.se)
* Visar eller döljer information som finns mellan <div> och </div>
* Fungerar i IE5+ och NS6+, i äldre läsare visas innehållet alltid som synligt.
* Testat på IE6 och Fire Fox 1.0.3

* displaytype 
* none | ytan är dold | displayContent('id_on_div_tag','none')
* block | ytan är synlig | displayContent('id_on_div_tag','block')
* toggle | växla mellan synlig och dold | displayContent('id_on_div_tag','toggle')
************************************************************************************/




function displayContent(obj, displaytype) { //

	var el = new getObj(obj); 

	
	if (el.style) { // Hittades objektet?
		
		// växla (toggle)
		if (displaytype == "toggle" && el.style.display != "block") {
			el.style.display = "block";
		} else {
			el.style.display = "none";
		}
		// displaytype none eller block
		if (displaytype != "toggle") {
			el.style.display = displaytype;
		}

	} // end if el	
	
	return;
}


function showMenu(topMenuNo, subMenuNo) {
	
	if (!document.getElementById) { return; }
	
	if (topMenuNo > 0) {
		var mn_root = document.getElementById("leftnav");
		var mn_ul = mn_root.getElementsByTagName("UL");
		
		// Is there a menu to open? If third argument are set to false don't open menu!
		if (mn_ul[topMenuNo] && arguments[2] != false) { 
			mn_ul[topMenuNo].style.display = "block"; 
		}
		
		// Remove empty nodes from topmenu
		for (i=0; i < mn_ul[0].childNodes.length; i++) { // Remove empty text nodes in FF
			var childNode = mn_ul[0].childNodes[i];
			if (childNode.nodeType == 3) { 
				mn_ul[0].removeChild(childNode); 
			}
		}
		
		// Format topmenu items...
		var topItem = mn_ul[0].childNodes[topMenuNo-1].childNodes[0];
		topItem.style.backgroundColor = "#809195";
		topItem.style.fontWeight = "bold";
		topItem.style.color = "#FFF";
	}
	
	// Is there a sub-menu font to format
	if (subMenuNo > 0)  { 
		var mn_a = mn_ul[topMenuNo].getElementsByTagName("A");
		mn_a[subMenuNo-1].style.fontWeight = "bold"; 
	}




}


function showItem(menuNo) { 
	
	if (!document.getElementById) { return; }

	var mn_root = document.getElementById("leftnav");
	var mn_ul = mn_root.getElementsByTagName("ul");
	
	// *** Remove empty text nodes in FF
	for (i=0; i < mn_ul[0].childNodes.length; i++) { 
		var childNode = mn_ul[0].childNodes[i];
		if (childNode.nodeType == 3) { 
			mn_ul[0].removeChild(childNode); 
		}
	}


	// *** Format topmenu items...
	var topItem = mn_ul[0].childNodes[menuNo-1].childNodes[0];
	topItem.style.backgroundColor = "#809195";
	topItem.style.fontWeight = "bold";
	topItem.style.color = "#FFF";
	
	
	// *** Is there a menu item to highlight in the right nav menu?
	var mn_root_right = document.getElementById("rightnav");
	
	if (mn_root_right) {
	
		var links = mn_root_right.getElementsByTagName("A");
		
		for (i=0; i < links.length; i++) {
			var url_current = new String(document.URL);
			var url_link = new String(links[i]); 
			
			if (url_link.indexOf(url_current) == 0) {
				links[i].style.fontWeight = "bold"; 
				break;
			}
		}
	}
		

}


/************************************************************************************
* Växla bild
************************************************************************************/
function setImage(obj){ // Set the down state image in menu.

	var el = new getObj(obj);

	if (el.obj) {
		the_filename = el.obj.src;
		the_pos = the_filename.lastIndexOf("_");
		the_curr_image = the_filename.substring(the_pos);
		if (the_curr_image == "_down.gif") {
			el.obj.src = the_filename.substring(0,the_pos) + "_up.gif";
		} else {
			el.obj.src = the_filename.substring(0,the_pos) + "_down.gif";
		}
	}

	return;
}

/************************************************************************************
* getObj - © Blueline Design 2005 (www.bluelinedesign.se)
* Crossbrowser Object referencing 

* .obj, giving access to the actual HTML element. You have to use this property to read 
* out or set anything else than styles. 
* .style, giving access to the styles of the HTML element. You have to use this property 
* to read out or set the styles of the element. 

* Ex. var elem = new getObj('menu'); 
* if (elem.obj) { alert(elem.obj.id); }
* if (elem.style) { elem.style.backgroundColor = "#ffcc00"; }
************************************************************************************/
function getObj(id) {
	
	if (document.getElementById) {
		var el = document.getElementById(id);
		if (el) { // hittades elementet?
			this.obj = el;
			this.style = el.style;
		}
	} else if (document.all) {
		var el = document.all[id];
		if (el) { // hittades elementet?
			this.obj = el;
			this.style = el.style;
		}
	} else if (document.layers) {	
		var el = document.layers[id];
		if (el) { // hittades elementet?
			this.obj = el ;
			this.style = el;
		}
	} // end if

	return;

} // end function


function changeLanguage() {
	
	var menu = document.getElementById("mn_select_language");
	
	if (!menu.style.visibility) { 
		menu.style.display = "none";
		menu.style.visibility = "hidden"; 
		if (menu.filters) { // Make in pretty in IE :)
			menu.style.filter = "progid:DXImageTransform.Microsoft.Fade(Duration=.4)";
		} 
	}
	
	if (menu.style.visibility == "hidden") {
		
		if (menu.filters) { // IE
			menu.filters[0].apply();
			menu.style.visibility = "visible";
			menu.filters[0].play();
		} else { // Others
			menu.style.visibility = "visible";
		}
	
		menu.style.display = "block";
	
	} else {
		
		if (menu.filters) { // IE
			menu.filters[0].apply();
			menu.style.visibility = "hidden";
			menu.filters[0].play();
		} else { // Others
			menu.style.visibility = "hidden";
			
		}
	
		menu.style.display = "none";
	
	}

}	


function confirmURL(msg, url) {
	if (confirm(msg)) {
		window.location.href = url;
		//window.open(url,'_blank'); 
	}
}




// **********************************************************************************************************
// HTML popup
// **********************************************************************************************************

function displayWindow(theURL,winName,width,height,features) { 
    var window_width = width;
    var window_height = height;
    var newfeatures= features;
    var window_top = (screen.height-window_height)/2;
    var window_left = (screen.width-window_width)/2;
    newWindow=window.open(''+ theURL + '',''+ winName + '','width=' + window_width + ',height=' + window_height + ',top=' + window_top + ',left=' + window_left + ',features=' + newfeatures + '');
    newWindow.focus();
}

// **********************************************************************************************************
// DIV popup to confirm urls 
// **********************************************************************************************************
function cfurl(caption,yestxt,yesurl,notxt,nourl,target) {

	if (!document.createElement && !document.body.clientWidth && !document.createTextNode) { 
		if (confirm(caption)) { window.open(yesurl,'_blank'); }
		return false; 
		
	}
	
	
	var popup = document.getElementById("bd-cfurl");
 	
	if (popup) { popup.parentNode.removeChild(popup); }
	
	
	var left = (document.body.clientWidth) / (2) - (450/2); // IE 6 win | FF 1.0.6 win
	var top = document.documentElement.scrollTop + 200; // IE 6 win | FF 1.0.6 win

	var container = document.createElement("div");
	container.id = "bd-cfurl";
	container.style.position = "absolute";
	container.style.width = "450px";
	container.style.left = left +"px";
	container.style.top = top + "px";
	
	var title = document.createElement("div");
	title.id = "bd-cfurl-title";
	title.style.width = "100%";
	title.style.marginBottom = "10px";
	
	//var titletxt = document.createTextNode(caption);
	//title.appendChild(titletxt);
	title.innerHTML = caption;
	container.appendChild(title);

	var cfYes = document.createElement('a');
	cfYesTxt = document.createTextNode(yestxt);
	cfYes.href = "#";
	cfYes.onclick = Function("cfurlgo('" + yesurl + "','" + target + "');");
	cfYes.appendChild(cfYesTxt);
	container.appendChild(cfYes);
	
	
	var cfBr = document.createElement('br');
	//var cfSpace = document.createTextNode("\u00a0\u00a0\u00a0");
	container.appendChild(cfBr);
	
	var cfNo = document.createElement('a');
	cfNoTxt = document.createTextNode(notxt);
	cfNo.href = "#";
	cfNo.onclick =  Function("cfurlgo('" + nourl + "','" + target + "');");
	cfNo.appendChild(cfNoTxt);
	container.appendChild(cfNo);
	
	document.body.appendChild(container);		
}

function cfurlgo(url, target) {
	
	var popup = document.getElementById("bd-cfurl");
 	
	if (popup) { 
		popup.parentNode.removeChild(popup);
	}
	
	if (url != "") {
		window.open(url, target); 
		//location.href = url;
	}
}

// **********************************************************************************************************
// Turn specific formatted span tags into mailto links. 
// Ex. <span class="bd-safe" >info [at] foretaget [dot] se</span>
// **********************************************************************************************************
function BDSpamSafe() { //v1.0, Blueline Design
	
	var scan = document.getElementsByTagName("span");

	if (scan) { // scan successful?
		
		for (i=0; i < scan.length; i++) {
			
			if (scan[i].className == "bd-safe") { // our magic tag is found	:)
				
				var span = scan[i]; 
				var text = scan[i].firstChild;
	
				// Get address from current text node
				address = text.nodeValue;
				address = address.replace(/\[dot\]/g,".");
				address = address.replace(/\[at\]/g,"@");
				address = address.replace(/\s+/g,"");
				
				// Remove current text node
				span.removeChild(text);
				
				// Create a new next node and a link node, add it to our span
				var alinktext = document.createTextNode(address);
				var alink = document.createElement("a");
				alink.setAttribute("href", "mailto:" + address);
				alink.appendChild(alinktext);
				span.appendChild(alink);
			
			}
		}
	}
}



// **********************************************************************************************************
// Function for faq/ask.asp
// **********************************************************************************************************
function doCategory() {
	category = document.forms[0].categoryID;
	category  = category.options[category.selectedIndex].text;
	document.forms[0].faq_category.value = category;
}


