﻿function toggleTopLinks(forceHide) {
	if (document.getElementById("topLinksDiv")) {
		if (document.getElementById("topLinksDiv").style.visibility == "visible" || forceHide) {
			document.getElementById("topLinksDiv").style.visibility = "hidden"
		} else {
			document.getElementById("topLinksDiv").style.visibility = "visible"
		}
	}
}
var topLinksTimer
function hideTopLinks() {
	if (typeof (topLinksTimer) != "undefined")
		clearTimeout(topLinksTimer)
	topLinksTimer = setTimeout("toggleTopLinks(true)", 2000)
}
function clearTopLinksTimer() {
	clearTimeout(topLinksTimer)
}

function doSearch() {
	if (document.getElementById("topSearch")) {
		if (document.getElementById("topSearch").value != "Søg..." && document.getElementById("topSearch").value != "") {
			location.href = "default.aspx?i=950&m=2&soegform=vis&soegeord=" + escape(document.getElementById("topSearch").value)
		} else {
			alert("Du skal angive et søgeord først")
		}
	}
}

function checkMitTREFORLogin() {
	if (document.getElementById("loginform")) {
		var kundenr = document.getElementById("kundenummer").value
		var pinkode = document.getElementById("pinkode").value
		if (kundenr != "" && kundenr != "Kundenummer" && pinkode != "" && pinkode != "PIN-kode") {
			document.getElementById("loginform").submit()
		} else {
			alert("Angiv venligst kundenummer og pin-kode\ninden du klikker på Log ind")
		}
	}
}

function keycodeSearch(e) {
	if (e.keyCode == 13)
		doSearch()
}

var currentPostlist = 0
function selectPostlist(num) {
	if (document.getElementById("postlistDiv" + currentPostlist)) {
		document.getElementById("postlistDiv" + currentPostlist).style.display = "none"
		document.getElementById("postlistImg" + currentPostlist).src = "custom/design/tab_pl" + currentPostlist + "_n.png"
	}
	if (document.getElementById("postlistDiv" + num)) {
		document.getElementById("postlistDiv" + num).style.display = "block"
		document.getElementById("postlistImg" + num).src = "custom/design/tab_pl" + num + "_a.png"
		currentPostlist = num
	}
}

function setFaqIcons() {
	var url = location.href
	
	if (url.indexOf("faq=1") > -1) {
		if (document.getElementById('headingLeftTd')) {
			document.getElementById('headingLeftTd').innerHTML = '<img src="custom/design/trefor_faq1.gif" border="0" alt="">&nbsp;&nbsp;'
			document.getElementById('headingLeftTd').style.textAlign = 'right'
		}
		
		if (document.getElementById('paragraphgLeftTd1')) {
			document.getElementById('paragraphgLeftTd1').innerHTML = '<img src="custom/design/trefor_faq2.gif" border="0" alt="">&nbsp;&nbsp;'
			document.getElementById('paragraphgLeftTd1').style.textAlign = 'right'
		}
		
		if (document.getElementById('faqBackLink')) {
			document.getElementById('faqBackLink').style.display = 'block'
		}
	}
}

function automateRightColumn() {
	if (document.getElementById("postlistTD5"))
		selectPostlist(5)
	else if (document.getElementById("postlistTD19"))
		selectPostlist(19)
	else if (document.getElementById("postlistTD21"))
		selectPostlist(21)
	
	if (document.getElementById("hboks1")) {
		if (!webeditoreditmode && (document.getElementById("hboks1").innerHTML == " " || document.getElementById("hboks1").innerHTML == "&nbsp;")) {
			document.getElementById("hboks1").style.display = "none"
			document.getElementById("hboks1Headline").style.display = "none"
		}
	}
	if (document.getElementById("aboks1")) {
		if (!webeditoreditmode && document.getElementById("aboks1").innerHTML == "") {
			document.getElementById("aboks1").style.display = "none"
		}
	}
	if (document.getElementById("postlistDiv5")) {
		var plTemp1 = document.getElementById("postlistDiv5").innerHTML.toUpperCase().replace(/\"/g, '')
		var plTemp2 = document.getElementById("postlistDiv2").innerHTML.toUpperCase().replace(/\"/g, '')
		if (plTemp1 == '<DIV CLASS=POSTLIST></DIV>' && plTemp2 == '<DIV CLASS=POSTLIST></DIV>') {
			document.getElementById("supPostList").style.display = "none"
		}
	}
}

//*** Ajax for getting dynamic images ***
var xmlhttp1 = null
var xmlhttp2 = null
var bredbaandTemplate = false
var waooTemplate = false
function checkRCBanners() {
	if (document.getElementById("hboks1") && !webeditoreditmode) {
		if (document.getElementById("hboks1").innerHTML == "") {
			var ponly = ""
			if (location.href.indexOf("ponly=true") > 1)
				ponly = "?ponly=true"
			if (bredbaandTemplate)
				ponly == "" ? ponly = "?bredbaand=true" : ponly += "&bredbaand=true";
			if (waooTemplate)
				ponly == "" ? ponly = "?waoo=true" : ponly += "&waoo=true";
			loadXMLDoc1('custom/frontPageBanners.aspx' + ponly)
		}
	}
}

function findTopParImage() {
	if (document.getElementById("bboks1")) {
		var bbox = document.getElementById("bboks1").innerHTML
		var f = ""
		if (bbox.length <= 1) { //load random image from default folder
			f = ""
		} else if (bbox.indexOf("<") >= 1 || bbox.length >= 50) { //already contains an image or other text
			f = "stop"
		} else { //contains foldername
			f = bbox
		}
		if (f != "stop") {
			loadXMLDoc2('custom/randomTopBanner.aspx?f=' + f)
		}
	}	
}

function loadXMLDoc1(url) {
	if (url != "") {
		xmlhttp1 = null
		xmlhttp1 = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (xmlhttp1 != null) {
			xmlhttp1.onreadystatechange = onXmlResponse1
			xmlhttp1.open("GET", url, true)
			xmlhttp1.send(null)
		} else {
			//alert("Din browser understøtter ikke XML over HTTP!")
		}
	}
}
function loadXMLDoc2(url, mode) {
	if (url != "") {
		xmlhttp2 = null
		xmlhttp2 = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (xmlhttp2 != null) {
			xmlhttp2.onreadystatechange = onXmlResponse2
			xmlhttp2.open("GET", url, true)
			xmlhttp2.send(null)
		} else {
			//alert("Din browser understøtter ikke XML over HTTP!")
		}
	}
}
function checkXmlReadyState(obj) {
	var out = false
	if (obj != null) {
		if (obj.readyState == 4) {
			if (obj.status == 200) {
				out = true
			}
		}
	}
	return out
}
function onXmlResponse1() {
	var loaded = checkXmlReadyState(xmlhttp1)

	if (loaded) {
		var response = xmlhttp1.responseXML.documentElement;
		if (response != null) {
			var txt = ''
			var x = response.getElementsByTagName("result")
			try {
				txt = x[0].firstChild.data
			}
			catch (er) {
				txt += 'Fejl ved udlæsning af bannere<br />' + er
			}
			//alert(txt)
			xmlhttp1 = null
			document.getElementById("hboks1").innerHTML = txt
			if (txt != "") {
				document.getElementById("hboks1Headline").style.display = "block"
				if (typeof (autosize) == "function") {
					autosize('ifrm_content')
				}
			}
		}
	}
}
function onXmlResponse2() {
	var loaded = checkXmlReadyState(xmlhttp2)

	if (loaded) {
		var response = xmlhttp2.responseXML.documentElement;
		if (response != null) {
			var txt = ''
			var x = response.getElementsByTagName("result")
			try {
				txt = x[0].firstChild.data
			}
			catch (er) {
				txt += 'Fejl ved udlæsning af bannere<br />' + er
			}

			xmlhttp2 = null
			var topTD = txt
			if (webeditoreditmode)
				topTD += document.getElementById("topParImageTD").innerHTML
			document.getElementById("topParImageTD").innerHTML = topTD

			if (typeof (autosize) == "function") {
				setTimeout("autosize('ifrm_content')", 500)
			}
		}
	}
}
//*** End *** Ajax for getting dynamic images ***

