// Kompenser for Opera-bug i toppmeny (http://geocities.com/csssite/opera/bug07.xhtml)
if (window.opera) {
	document.write('<style type="text/css">'
		+ '#toppmeny .toppmeny li {'
		+ 'float: left;'
		+ '}'
		+'</style>');
}

sfHover = function() {
	var sfEls = document.getElementById("toppmeny").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
			showHideSelects('hidden');
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			showHideSelects('visible');
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

showHideSelects = function (vis) {
	try {
		var arr = navigator.appVersion.split("MSIE");
		if (parseFloat(arr[1]) <= 6) {
			var sel = document.getElementsByTagName('SELECT');
			for (var i = 0; i < sel.length; i++) {
				sel[i].style.visibility = vis;
			}
		}
	} catch (e) {}
}

function tipsvindu(txtURL) {
	var x, y;
	x = (window.screen.width - 360) / 2;
  	y = (window.screen.height - 410) / 2;
	var strURL = new String(txtURL);
	tipsvindu = window.open(strURL,'Tipsvindu', 'width=360, height=410, scrollbars=0,screenx='+x+',screeny='+y+',left='+x+',top='+y+'');
	tipsvindu.focus();		
}

var defaultFontSize = 76;
var currentFontSize = defaultFontSize;
function changeFontSize(sizeDifference){
	if (sizeDifference == 0) {
		currentFontSize = defaultFontSize;
	} else {
		currentFontSize = parseInt(currentFontSize) + parseInt(sizeDifference * 10);
	}

	if(currentFontSize > 150){
		currentFontSize = 150;
	}else if(currentFontSize < 60){
		currentFontSize = 60;
	}

	setFontSize(currentFontSize);
	return false;
};
function setFontSize(fontSize){
	document.body.style.fontSize = fontSize + '%';
	createCookie('fontSize', fontSize +'%', 60);
	//alert (document.body.style.fontSize);
};
function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
};



//--- Logikk for venstremeny
// Underliggjande menypunkt vert skjult kun viss brukaren har JS
// Torstein Hnsi @ Fylkesmannen i Sogn og Fjordane, 2007
/*document.write("<style type='text/css'>"
	+ "#venstreside #venstremeny li ul { display:none }"
	+ "</style>");
var uls, icons = new Array;

function jsVenstremeny() {
	if (!document.getElementById("mcVenstremenyID")) return;
	// finn overskrifter og separatorar
	var lis = document.getElementById("mcVenstremenyID").getElementsByTagName("LI");
	for (var i=0; i<lis.length; i++) {
		if (!lis[i].innerHTML.match(/\<ul\>/)) {
			// Overskrifter
			if (lis[i].innerHTML.match(/\.\.\.\.\.\s/)) {
				var c = lis[i].childNodes[0];
				while (c.nextSibling) {
					if (c.tagName && c.tagName.match(/A/)) break;
					c = c.nextSibling;
				}
				lis[i].innerHTML = c.innerHTML.replace(/\.\.\.\.\.\s/, ' ');
				lis[i].className += " menyoverskrift";
			}
			// Meny-separatorar
			else if (lis[i].innerHTML.match(/\.\.\.\.\./)) {
				var hasUlChild = 0;
				for (var j = 0; j < lis[i].childNodes.length; j++) { // ikkje sep viss underpunkt
					if (lis[i].childNodes[j].tagName == 'UL') {
						hasUlChild = 1;
						break;
					}
				}
				if (!hasUlChild) {
					lis[i].innerHTML = '<div class="menysep"></div>';
				}
			}
			// Vanlege menypkt
			else {
				lis[i].className += " single";
			}
		}
		// Korriger sistenode der det er berre ein node
		if (lis[i].className.match('mcVenstremenyFirst')) {
			var hasSibling = false, nextLi = lis[i];
			while (nextLi = nextLi.nextSibling) {
				if (nextLi.tagName && nextLi.tagName.match(/LI/)) {
					hasSibling = true;
					break;
				}
				if (!nextLi.nextSibling) break;
			}
			if (!hasSibling) lis[i].className += ' mcVenstremenyLast';
		}
			
	}
	
	// finn li-nodar med nesta ul
	uls = document.getElementById("mcVenstremenyID").getElementsByTagName("UL");
	for (var i=0; i<uls.length; i++) {
		if (uls[i].parentNode.tagName.match(/LI/)) { // is sublevel
			icons[i] = document.createElement('a');
			icons[i].className = 'plus';
			icons[i].href = 'javascript:toggleChild('+ i +',1)';
			icons[i].title = 'Utvid';
			//icons[i].innerHTML = '<img src="/gfx/plus.png"/>';
			uls[i].parentNode.insertBefore(icons[i], uls[i].parentNode.firstChild);
		}
	}
	
	// Marker aktiv side
	var q, m, activeEl;
	try {
		q = window.document.location.toString();
		m = q.replace(/^.*?[\?&]m=([0-9]+)(&.*?)?$/, '$1');
		var as = document.getElementById("mcVenstremenyID").getElementsByTagName("A");
		for (var i=0; i<as.length; i++) {
			if (as[i].href && as[i].href.match("m="+ m)) {
				as[i].className = "aktiv";
				activeEl = as[i];
				break;
			}
		}
	} catch (e) {}
	
	// Nødløysing for rettsråd tho 2007-12-11
	document.body.className += " m-"+m;
	
	if (activeEl) {
		var el = activeEl;
		// Ekspander overliggjande nodar
		while (el.parentNode && el.parentNode.id != "mcVenstremenyID") {
			el = el.parentNode;
			if (el.tagName && el.tagName.match(/UL/)) {
				
				el.className = "expanded";
				var icon = el.parentNode.firstChild;
				icon.className = "minus";
				icon.title = "Trekk sammen";
				icon.href = icon.href.replace(',1', ',0');
				//icon.innerHTML = '<img src="/gfx/minus.png"/>';
			}
		}
		// Ekspander direkte underliggjande node
		el = activeEl
		while (el.nextSibling) {
			el = el.nextSibling;
			if (el.tagName && el.tagName.match(/UL/)) {
				el.className = "expanded";
				var icon = el.parentNode.firstChild;
				icon.className = "minus";
				icon.title = "Trekk sammen"
				icon.href = icon.href.replace(',1', ',0');
				//icon.innerHTML = '<img src="/gfx/minus.png"/>';
			}
		}
	}
}*/
function toggleChild(i, show) {
	if (show) {
		uls[i].className = 'expanded';
		icons[i].className = 'minus';
		icons[i].title = 'Trekk sammen';
	} else {
		uls[i].className = null;
		icons[i].className = 'plus';
		icons[i].title = 'Utvid';
	}
	var toggle = show ? 0 : 1;
	icons[i].href = 'javascript:toggleChild('+ i +','+ toggle +')';
	adjustLayoutHeight();
}

// Marker aktiv side i toppmenyen
function jsToppmeny() {
	var q = document.getElementById("brodsmular").getElementsByTagName("A")[0].href;
	var m = q.replace(/^.*?[\?&]m=([0-9]+)(&.*?)?$/, '$1');
	var as = document.getElementById("toppmenyID").getElementsByTagName("A");
	for (var i=0; i<as.length; i++) {
		if (as[i].href && as[i].href.match("m="+ m)) {
			as[i].parentNode.className += " aktiv"; // li
			break;
		}
	}
}

// Ekspanderande tabell som aktkal og tilsyn
ExpandingTable = function(id) {
	this.id = id;
	this.wrapper = document.getElementById(id +'-wrapper');
	this.controlWrapper = document.getElementById(id +'-control');
	for (var i = 0; i < this.wrapper.childNodes.length; i++) {
		try {
			if (this.wrapper.childNodes[i].tagName.match(/TABLE/)) {
				this.table = this.wrapper.childNodes[i];
				break;
			}
		} catch (e) {}
	}
	
	if (this.table && this.table.offsetWidth > this.wrapper.offsetWidth) {
		this.control = document.createElement('a');
		this.control.href = 'javascript:void(0)';
		this.control.innerHTML = 'Utvid tabellen';
		this.control.className = 'expand';
		var pThis = this;
		this.control.onclick = function() {
			pThis.doExpand();
		};
		this.table.onclick = function() {
			pThis.doExpand();
		};
		this.table.style.cursor = 
		this.controlWrapper.appendChild(this.control);
		this.wrapper.style.height = this.wrapper.offsetHeight +'px';
		
	}
}
ExpandingTable.prototype.doExpand = function () {
	this.wrapper.className += ' table-wrapper-expanded';
	this.control.innerHTML = 'Trekk sammen tabellen';
	this.control.className = 'contract';
	var pThis = this;
	this.control.onclick = function() {
		pThis.doContract();
	}
}
ExpandingTable.prototype.doContract = function () {
	this.wrapper.className = this.wrapper.className.replace(/ table-wrapper-expanded/, '');
	this.control.innerHTML = 'Utvid tabellen';
	this.control.className = 'expand';
	var pThis = this;
	this.control.onclick = function() {
		pThis.doExpand();
	}
}

/* Juster høgde for trekolonnelayout */
function adjustLayoutHeight() {
	try {
		var venstreside = document.getElementById('venstreside');
		var height = venstreside.offsetHeight + 100;
		var hovudfelt = document.getElementById('hovudfelt');
		if (notisar = getElementsByClass('notisar', hovudfelt, 'div')) {
			try {
				if (notisar[0].offsetHeight + 50 > height) height = notisar[0].offsetHeight + 50;
			} catch (e) {}
		}
		if (height > hovudfelt.offsetHeight) {
			// standards compliant
			hovudfelt.style.minHeight = height +'px';
			
			// IE <= 6 double check
			if (height > hovudfelt.offsetHeight) {
				hovudfelt.style.height = height +'px';
			}
			
		}
	} catch (e) {}
}
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )	node = document;
	if ( tag == null ) tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

/* Søk i telefonkatalogen */
function doTelefonSok(e) {
	if (!e) e = window.event;
	if (!e.target) e.target = e.srcElement; // ie
	
	if (e.target.id == 'txtTelSok') {
		if (e.keyCode == 13) {
			submitTelefonSok();
			return false;
		}
	} else if (e.target.id == 'submitTelSok') {
		submitTelefonSok();
		return false;
	}
	return true;
}
function submitTelefonSok() {
	var s = document.getElementById('txtTelSok').value;
	if (s) {

		var url = "http://online.telefonkatalogen.no/katalog/katalog.php4?streng="+
			s.replace(/æ/i,'%E6').replace(/ø/i,'%F8').replace(/å/i,'%E5');
		
		window.location.href = url;
	}
}


//For bruk i disk.forum-mal

function setNewPostInfo(hash)
{
	try {
		getElementByDM50HiddenVariable("ParentID").value = hash.ParentID;
		getElementByDM50HiddenVariable("Category").value = hash.Category;
		getElementByDM50HiddenVariable("PostDate").value = hash.PostDate;
		getElementByDM50HiddenVariable("QuoteID").value = hash.QuoteID;
		getElementByDM50HiddenVariable("SiteID").value = hash.SiteID;
	} catch (e) {}
}
function getElementByDM50HiddenVariable(varName)
{
	var inputElems = document.getElementsByTagName("input");
	
	for (var i = 0; i < inputElems.length; i++)
	{
		if (inputElems[i].type != null)
		{
			if(inputElems[i].type == 'hidden')
			{			
				if (inputElems[i].getAttribute("DM50HiddenVariable") == varName)
					return inputElems[i];
			}
		}
	}
}


