/*
-----------------------------
source til "default.min.js"

compile meed closure: http://closure-compiler.appspot.com/home

tjek med JsLint: www.jslint.com (eller prøv denne: www.jshint.com)
(Assume a browser, Tolerate == and !=, Tolerate missing 'Use Strict', Tolerate messy white space
-----------------------------
*/

// browser check
var agt = navigator.userAgent.toLowerCase();
var is_nav = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
var is_mac = (agt.indexOf("mac")!=-1);
var is_win = (agt.indexOf("win")!=-1); 
var is_major = parseInt(navigator.appVersion,10); // the radix (numeral system) is 10 (decimal)
var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie7 = (agt.indexOf('msie 7') != -1);
var is_ie8 = (agt.indexOf('msie 8') != -1);
var is_ie9 = (agt.indexOf('msie 9') != -1);
var is_opera = ((agt.indexOf("opera") != -1) || is_ie7 || is_ie8); // korriger for IE7+8
var is_ie3 = (is_ie && (is_major < 4));
var is_ie4 = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
var is_ie5 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
var is_ie5up = (is_ie && !is_ie3 && !is_ie4);
var is_ie55up = (is_ie && !is_ie3 && !is_ie4 && !is_ie5);
var is_nav6up = (is_nav && is_major >= 5);

// 2011, nov
// http://www.bloggingdeveloper.com/post/JavaScript-QueryString-ParseGet-QueryString-with-Client-Side-JavaScript.aspx
//function getQuerystring(key, default_) { // var author_value = getQuerystring('author');
//  if (default_==null) default_="";
//  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
//  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
//  var qs = regex.exec(window.location.href);
//  if(qs == null)
//    return default_;
//  else
//    return qs[1];
//}
function hasClass(ele,cls) {
	return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}
function addClass(ele,cls) {
	if (!hasClass(ele,cls)) {ele.className += " "+cls;}
}
function removeClass(ele,cls) {
	if (hasClass(ele,cls)) {
		var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
		ele.className=ele.className.replace(reg,' ').replace(/\s+/g,' ').replace(/^\s|\s$/,'');
	}
}
// http://www.dustindiaz.com/getelementsbyclass
function getElementsByClass(node,searchClass,tag) {
	var i,j,classElements,els,elsLen,pattern;
	classElements = []; // new Array();
	els = node.getElementsByTagName(tag); // use "*" for all elements
	elsLen = els.length;
	pattern = new RegExp("\\b"+searchClass+"\\b");
	for (i = 0, j = 0; i < elsLen; i=i+1) {
	 if ( pattern.test(els[i].className) ) {
	 classElements[j] = els[i];
	 j = j+1;
	 }
}
return classElements;
}
function replaceClass(ele, oldClass, newClass){
    if(hasClass(ele, oldClass)){
        removeClass(ele, oldClass);
        addClass(ele, newClass);
    }   
    return;
}
function toggleClass(ele, cls1, cls2){
    if(hasClass(ele, cls1)){
        replaceClass(ele, cls1, cls2);
    }else if(hasClass(ele, cls2)){
        replaceClass(ele, cls2, cls1);
    }else{
        addClass(ele, cls1);
    } 
}

function insertAfter(referenceNode, newNode){
    referenceNode.parentNode.insertBefore( newNode, referenceNode.nextSibling );
}/**/

// http://onlinetools.org/articles/unobtrusivejavascript/chapter4.html
// addEvent(window, 'load', thefunction);
function addEvent(obj, evType, fn){
if(obj!=null) { // f.eks. touchstart
 if (obj.addEventListener){ 
   obj.addEventListener(evType, fn, false);
   return true; 
 } else if (obj.attachEvent){ // IE 6,7,8
   var r = obj.attachEvent("on"+evType, fn); 
   return r; 
 } else { 
   return false; 
 } 
 }
}

// pageTimer
var pageTime = 0;
function pageTimerUpdate() {
	pageTime = pageTime+1;
	if(document.getElementById("sidetid")) document.getElementById("sidetid").value = pageTime;
}
function pageTimeBegin() {
	var pageTimer = window.setInterval(pageTimerUpdate, 1000);
}
addEvent(window, 'load', pageTimeBegin);


// Cookies
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 var expires = "";
	document.cookie = name +"="+value+expires+"; path=/";
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name) {
	createCookie(name,"",-1);
}

// iframe kommunikation (ikke IE7)
function dataRequest(evt) {
	var arrIframePairs = evt.data.split("&");
	for(var i = 0; i < arrIframePairs.length; i++) { 
	  var pos = arrIframePairs[i].indexOf('=');
	  if (pos == -1) continue;
	  var argname = arrIframePairs[i].substring(0,pos); 
	  var value = arrIframePairs[i].substring(pos+1);
	  switch(argname) {
	  	  case 'location_hash':
		  	if(value=='toppen') {
			scroll(0,0);
			} else {
			location.hash = '#' + value; // #toppen
		    }
		  break;
		  case 'wh': // window height
		    var strContentHeight = parseInt(document.getElementById("content").offsetHeight);
			if(document.getElementById("stamkort")) {
			  var strIframeHeight = parseInt(document.getElementById("stamkort").offsetHeight);
			  strContentHeight = strContentHeight - strIframeHeight;
			  var strStamkortHeight = parseInt(value) + 120;
			  var intContentTotalHeight = strContentHeight + strStamkortHeight;
			  document.getElementById("stamkort").style.height = strStamkortHeight + 'px';
			  document.getElementById("content").style.height = intContentTotalHeight + 'px';
			  // scrollTo top of #stamkort
			  var viewportScroll = (window.pageYOffset || document.documentElement.scrollTop)  - (document.documentElement.clientTop || 0);
			  var viewportOffset_stamkort = document.getElementById("stamkort").getBoundingClientRect();
			  var stamkortScrollTo = parseInt(viewportScroll) + parseInt(viewportOffset_stamkort.top);
			  //window.scrollTo(0, stamkortScrollTo);
			} else {
			  document.getElementById("content").style.height = strContentHeight + parseInt(value) + 'px';
			}
		   
		  break;
		  case 'sendmessage': // send location til iframe (kun til mobil, virker ikke i IE7)
		  // if (evt.origin == 'https://www.stamkort.dk') { // The message came from an origin that
		  evt.source.postMessage(document.location.href, evt.origin);
		  break;
	   }
	}
}
addEvent(window,'message',dataRequest);


function trc(url) {
	if(document.images){
	  if(url.childNodes) { // 2011: encodeURI() i stedet for escape()
	    new Image().src = "admin/trc.asp?url="+encodeURI(url)+"&linkname="+encodeURI(url.childNodes[0].nodeValue);
	  } else {
	    new Image().src = "admin/trc.asp?url="+encodeURI(url);
	  }
	}
	return true;
}

function openWin(billed_id,billednavn) {
	var newwin;
	if (is_ie7) {
	newwin = window.open('admin/inc/billede.asp?billedid='+billed_id+'&bnavn='+billednavn,'_blank','menubar=yes,resizable=yes,width=591,height=532');
	} else if (is_opera || is_nav6up) {
	newwin = window.open('admin/inc/billede.asp?billedid='+billed_id+'&bnavn='+billednavn,'_blank','menubar=yes,width=591,height=512');
	} else {
	newwin = window.open('admin/inc/billede.asp?billedid='+billed_id+'&bnavn='+billednavn,'_blank','menubar=yes,width=591,height=493');
	}
	return false;
}


function encodemail(country,domain,name,linktekst,strclass,strtabindex) {
	var strEncodedMail = '<a ';
		if(strtabindex!='') strEncodedMail = strEncodedMail + strtabindex + ' ';
		if(strclass != "") {strEncodedMail = strEncodedMail + 'class="'+strclass+'" ';}
	strEncodedMail = strEncodedMail + 'href="&#109;&#97;&#105;&#108;'
		+ '&#116;&#111;&#58;'+name+'&#064;'+domain+'&#46;'+country+'">';
		if(linktekst != "") {strEncodedMail = strEncodedMail + linktekst;}
		else {strEncodedMail = strEncodedMail + linktekst + name+'&#064;'+domain+'&#46;'+country;}
	strEncodedMail = strEncodedMail + '</a>';
	document.write(strEncodedMail);
}

// show/hide visibility
function aliaShow(targetId){
  if (document.getElementById){
    var target = document.getElementById(targetId);
	target.style.display = "block";
  }
}
function aliaHide(targetId){
  if (document.getElementById){
    var target = document.getElementById(targetId);
	target.style.display = "none";
  }
}
// toggle visibility
function toggle(targetId){
  if (document.getElementById){
    var target = document.getElementById(targetId);
	if (target.style.display == "none"){
	  target.style.display = "";
	} else {
	  target.style.display = "none";
	}
  }
}

function getPageSize(){ // getSize()
	var xScroll,yScroll,windowWidth,windowHeight,myScroll; // myWidth, myHeight
	if (window.innerHeight && window.scrollMaxY) {
	 xScroll = document.body.scrollWidth;
	 yScroll = window.innerHeight + window.scrollMaxY;
	 } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
	 xScroll = document.body.scrollWidth;
	 yScroll = document.body.scrollHeight;
	 } else if (document.documentElement && document.documentElement.scrollHeight > document.documentElement.offsetHeight){ // Explorer 6 strictmode
	 xScroll = document.documentElement.scrollWidth;
	 yScroll = document.documentElement.scrollHeight;
	 } else { // Explorer Mac...would also work in Mozilla and Safari
	 xScroll = document.body.offsetWidth;
	 yScroll = document.body.offsetHeight;
	 }
	 if (self.innerHeight) { // all except Explorer
	 windowWidth = self.innerWidth;
	 windowHeight = self.innerHeight;
	 myScroll = window.pageYOffset;
	 } else if (document.documentElement && document.documentElement.clientHeight) { // IE6 Strict
	 windowWidth = document.documentElement.clientWidth;
	 windowHeight = document.documentElement.clientHeight;
	 myScroll = document.documentElement.scrollTop;
	 } else if (document.body) { // other IE, IE7 etc.
	 windowWidth = document.body.clientWidth;
	 windowHeight = document.body.clientHeight;
	 myScroll = document.body.scrollTop;
	 }
	 // for small pages with total height less then height of the viewport
	 if(yScroll < windowHeight){
	 pageHeight = windowHeight;
	 } else {
	 pageHeight = yScroll;
	 }
	 // for small pages with total width less then width of the viewport
	 if(xScroll < windowWidth){
	 pageWidth = windowWidth;
	 } else {
	 pageWidth = xScroll;
	 }
	 arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight,myScroll)
	 return arrayPageSize;
}

// AJAX
function doAjaxResponse(http_request,response_type,error_function) {
	if (http_request.readyState == 4) { 
		if (http_request.status == 200) {
			if(response_type=='xml') return (http_request.responseXML);
			else return (http_request.responseText);
			/*
			text: simple text using the responseText
			xml: you can traverse its DOM, performing functions on the elements, attributes, and text nodes.
			*/	
		} else {
			if(error_function != '') { window[error_function]('status: ' + http_request.status);} // return eval(error_function+"('status: ' + http_request.status)");
		 }
	} else {
		// if(error_function != '') eval(error_function+"('readyState: ' + http_request.readyState)");
	 }
}

//function handleDivTag(divtag) { //   var divtag; //   return divtag; //} 
function AJAX(send_method,send_url,postvars,response_type,targetid,run_function,error_function) {
	var ajaxresponse;
	// run_function og error_function er VALGFRI
	if (window.XMLHttpRequest) { // IE 7, Mozilla, Safari, ...//
    var http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {http_request.overrideMimeType('text/xml');}
	}
	else if (window.ActiveXObject) { // IE 6
	  	try {var http_request = new ActiveXObject("Msxml2.XMLHTTP");}
			catch (err1) {
			     try {var http_request = new ActiveXObject("Microsoft.XMLHTTP");}
				 catch (err2) {}
            }
	}
	if (!http_request) return false; // alert('Giving up :( Cannot create an XMLHTTP instance');
	//Create the Divtag Handler -- Mainly an IE 6 Fix // var divhandler = new handleDivTag(null);
	http_request.onreadystatechange = function(){
		if(doAjaxResponse(http_request,response_type,error_function)) { // 2x doAjaxResponse
		  ajaxresponse = doAjaxResponse(http_request,response_type,'');
			if(run_function != '') {
				window[run_function](ajaxresponse); // eval(run_function+"(ajaxresponse)");
			 } // speciel ok-funktion
			// http://www.quirksmode.org/dom/innerhtml.html
			else if(ajaxresponse != null) {
			  if(document.getElementById(targetid)) document.getElementById(targetid).innerHTML = ajaxresponse; // default
			}
		}
	}
	http_request.open(send_method,send_url,true); // If TRUE, the execution will continue while the response of the server has not yet arrived
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=iso-8859-1"); 
	http_request.send(postvars); //  null, name=value&anothername=othervalue&so=on
}

var infoboks_w, infoboks_h
function showInfoBoks(pagetoload,getvars,postvars,boks_w,boks_h) {
var info_content, info_function, info_errorfunction;
getPageSize() // arrayPageSize[pageWidth,pageHeight,windowWidth,windowHeight,myScroll]
if (getvars != '') getvars = '?' + getvars;
if (!postvars != '') postvars = null;
pagetoload = pagetoload + getvars;
infoboks_w = parseInt(boks_w,10); // the radix (numeral system) is 10 (decimal)
infoboks_h = parseInt(boks_h,10); // the radix (numeral system) is 10 (decimal)
console.log('w:' + infoboks_w + ', h: ' + infoboks_h);
// send_method,send_url,postvars,response_type,run_function,error_function
AJAX('GET',pagetoload,postvars,'text','infoboks_container','showInfoBoksContent','showInfoBoksError');
}

function showInfoBoksContent(ajax_response) {
	if(ajax_response != null) {
	document.getElementById('infoboks_container').innerHTML = ajax_response;
	document.getElementById('infoboks_baggrund').style.height = arrayPageSize[1] + "px";
	document.getElementById('infoboks_baggrund').style.width = arrayPageSize[2] + "px";
	document.getElementById('infoboks_front').style.top = arrayPageSize[4] + (arrayPageSize[3]/6) + "px";
	document.getElementById('infoboks_front').style.width = '80%';
	if(!isNaN(infoboks_w)) document.getElementById('infoboks_front').style.maxWidth = infoboks_w + "px";
	if(!isNaN(infoboks_h)) document.getElementById('infoboks_front').style.height = infoboks_h + "px";
	document.getElementById('infoboks_front').style.display='block';
	document.getElementById('infoboks_baggrund').style.display='block';
	}
}
function showInfoBoksError(fejlbesked) {
  alert(fejlbesked + '\nDer opstod en fejl.\nDet vil hjælpe os meget, hvis du sender os en e-mail.\nSkriv gerne navnet på siden og beskriv kort hvordan fejlen opstod.\n\nPå forhånd tak!')
}
function hideInfoBoks() {
document.getElementById('infoboks_baggrund').style.display='none';
document.getElementById('infoboks_front').style.display='none';
}

function aliaFlash(flashdata,flashwidth,flashheight,htmlcontent) {
	htmlcontent = htmlcontent.replace(/&lt;/g,"<");
	htmlcontent = htmlcontent.replace(/&gt;/g,">");
	strFlash = '<object type="application/x-shockwave-flash" data="'+flashdata+'" width="'+flashwidth+'" height="'+flashheight+'">\n'
		+ '<param name="movie" value="'+flashdata+'" />'
		+ htmlcontent
		+ '</object>'
	document.write(strFlash);
}

function aliaFLV(flashdata,flashwidth,flashheight,autostart,startimage) {
	hmtlcontent = '<a class="nohover" href="http://www.adobe.com/go/getflashplayer" onclick="this.target=\'_blank\'"><img src="admin/inc/hent_flash.gif" border="0" width="202" height="92" alt="Hent Flash" /></a>';
	hmtlcontent = hmtlcontent.replace(/&lt;/g,"<");
	hmtlcontent = hmtlcontent.replace(/&gt;/g,">");
	flashdata = escape(flashdata);
	//if (startimage !='') {flashdata = "flvplayer.swf?autostart="+autostart+"&file="+flashdata+"&image=pics%2Fbilleder%2F"+startimage;}
	if (startimage !='') {flashdata = "flvplayer.swf?autostart="+autostart+"&file="+flashdata+"&image=pics%2F"+startimage;}
	else flashdata = "flvplayer.swf?autostart="+autostart+"&file="+flashdata;
	strFlash = '<object type="application/x-shockwave-flash" data="'+flashdata+'" width="'+flashwidth+'" height="'+flashheight+'">\n'
		+ '<param name="movie" value="'+flashdata+'" />'
		+ hmtlcontent
		+ '</object><br />';
	document.write(strFlash);
}

function aliaNoFLV(flashdata,flashwidth,flashheight,autostart,startimage) {
	hmtlcontent = '<div style="height:'+flashheight+'px;"><a class="nohover" href="http://www.adobe.com/go/getflashplayer" onclick="this.target=\'_blank\'"><img src="admin/inc/hent_flash.gif" border="0" width="202" height="92" alt="Hent Flash" /></a></div>';
	hmtlcontent = hmtlcontent.replace(/&lt;/g,"<");
	hmtlcontent = hmtlcontent.replace(/&gt;/g,">");
	document.write(hmtlcontent);
}

// LazyLoad
LazyLoad=function(k){function p(b,a){var g=k.createElement(b),c;for(c in a)a.hasOwnProperty(c)&&g.setAttribute(c,a[c]);return g}function l(b){var a=m[b],c,f;if(a)c=a.callback,f=a.urls,f.shift(),h=0,f.length||(c&&c.call(a.context,a.obj),m[b]=null,n[b].length&&j(b))}function w(){var b=navigator.userAgent;c={async:k.createElement("script").async===!0};(c.webkit=/AppleWebKit\//.test(b))||(c.ie=/MSIE/.test(b))||(c.opera=/Opera/.test(b))||(c.gecko=/Gecko\//.test(b))||(c.unknown=!0)}function j(b,a,g,f,h){var j=
function(){l(b)},o=b==="css",q=[],d,i,e,r;c||w();if(a)if(a=typeof a==="string"?[a]:a.concat(),o||c.async||c.gecko||c.opera)n[b].push({urls:a,callback:g,obj:f,context:h});else{d=0;for(i=a.length;d<i;++d)n[b].push({urls:[a[d]],callback:d===i-1?g:null,obj:f,context:h})}if(!m[b]&&(r=m[b]=n[b].shift())){s||(s=k.head||k.getElementsByTagName("head")[0]);a=r.urls;d=0;for(i=a.length;d<i;++d)g=a[d],o?e=c.gecko?p("style"):p("link",{href:g,rel:"stylesheet"}):(e=p("script",{src:g}),e.async=!1),e.className="lazyload",
e.setAttribute("charset","utf-8"),c.ie&&!o?e.onreadystatechange=function(){if(/loaded|complete/.test(e.readyState))e.onreadystatechange=null,j()}:o&&(c.gecko||c.webkit)?c.webkit?(r.urls[d]=e.href,t()):(e.innerHTML='@import "'+g+'";',u(e)):e.onload=e.onerror=j,q.push(e);d=0;for(i=q.length;d<i;++d)s.appendChild(q[d])}}function u(b){var a;try{a=!!b.sheet.cssRules}catch(c){h+=1;h<200?setTimeout(function(){u(b)},50):a&&l("css");return}l("css")}function t(){var b=m.css,a;if(b){for(a=v.length;--a>=0;)if(v[a].href===
b.urls[0]){l("css");break}h+=1;b&&(h<200?setTimeout(t,50):l("css"))}}var c,s,m={},h=0,n={css:[],js:[]},v=k.styleSheets;return{css:function(b,a,c,f){j("css",b,a,c,f)},js:function(b,a,c,f){j("js",b,a,c,f)}}}(this.document);		

function eventFire(el, etype){
   if (el.fireEvent) {
     (el.fireEvent('on' + etype));
   } else {
     var evObj = document.createEvent('Events');
     evObj.initEvent(etype, true, false);
     el.dispatchEvent(evObj);
   }
}

// fra http://www.adobe.com/devnet/flash/articles/fp8_detection.html //
//var jsVersion = 1.0; // The version of JavaScript supported
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
function JSGetSwfVer(i){
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
      		var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			descArray = flashDescription.split(" ");
			tempArrayMajor = descArray[2].split(".");
			versionMajor = tempArrayMajor[0];
			versionMinor = tempArrayMajor[1];
			if ( descArray[3] != "" ) {
				tempArrayMinor = descArray[3].split("r");
			} else {
				tempArrayMinor = descArray[4].split("r");
			}
      		versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
            flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
      	} else {
			flashVer = -1;
		}
	}
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	else {
		flashVer = -1;
	}
	return flashVer;
} 
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision) 
{
	var i;
 	reqVer = parseFloat(reqMajorVer + "." + reqRevision);
	for (i=25;i>0;i--) {	
		if (isIE && isWin && !isOpera) {
			//versionStr = VBGetSwfVer(i);
		} else {
			versionStr = JSGetSwfVer(i);		
		}
		if (versionStr == -1 ) { 
			return false;
		} else if (versionStr != 0) {
			if(isIE && isWin && !isOpera) {
				tempArray = versionStr.split(" ");
				tempString = tempArray[1];
				versionArray = tempString .split(",");				
			} else {
				versionArray = versionStr.split(".");
			}
			versionMajor = versionArray[0];
			versionMinor = versionArray[1];
			versionRevision = versionArray[2];
			versionString = versionMajor + "." + versionRevision;
			versionNum = parseFloat(versionString);
			if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) {
				//alert(versionNum)
				return true;
			} else {
				//alert(versionNum)
				return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );
			}
		}
	}	
	//return (reqVer ? false : 0.0);
	return true;
}