function ToggleDisplay(id){id=document.getElementById(id);id.style.display=!id.style.display?"none":""}
function appendEvent(a,b,c){if(a.attachEvent)a.attachEvent("on"+b,c);else if(a.addEventListener)a.addEventListener(b,c,false);else a["on"+b]=c}
function popup(url,name,width,height){iLeft=(screen.width/2)-(width/2);iTop=(screen.height/2)-(height/2);window.open(url,name,"width="+width+",height="+height+",top="+iTop+",left="+iLeft+",scrollbars=yes")}
function InputClear(o){o.value=o.style.color="";o.onfocus=function(){}}
function FormValidate(a){var sPassword;for(i=0;i<a.elements.length;i++){switch(a.elements[i].getAttribute("title")){case "Password":sPassword=a.elements[i].value;if(!a.elements[i].value){alert("Du mangler at udfylde noget.");a.elements[i].focus();return false};break;case "Gentag password":if(a.elements[i].value!=sPassword){alert("De to passwords er ikke ens.");a.elements[i].focus();return false}break;case "Påkrævet":if(!a.elements[i].value){alert("Du mangler at udfylde noget.");a.elements[i].focus();return false}break;case "Email":if(!a.elements[i].value.match(/^.*@\w[\w\.-]*\.[a-z]{2,6}$/)){alert("Du har ikke udfyldt en gyldig email-adresse.");a.elements[i].focus();return false}break;case "Dato":if(!a.elements[i].value.match(/^(3[01]|[012]\d)[\-\/\.](1[012]|0\d)[\-\/\.]\d{1,4}$/gi)){alert("Du har ikke indtastet en gyldig dato! Den bør være i formatet dd-mm-åååå.");a.elements[i].focus();return false}break;return true}}}
function OnlyNumbers(e){var charCode=e.which?e.which:event.keyCode;if(charCode>31&&(charCode<48||charCode>57))return false;return true}
function Center(id,width,height){id=document.getElementById(id);id.style.left=(screen.width/2)-width+"px";id.style.top=(screen.height/2)-height+"px"}
var req=false;function AjaxConn(){req=false;if(window.XMLHttpRequest){req=new XMLHttpRequest()}else if(window.ActiveXObject){try{req=new ActiveXObject("Msxml2.XMLHTTP")}catch(e){try{req=new ActiveXObject("Microsoft.XMLHTTP")}catch (e){}}}if(!req){alert("AJAX understøttes ikke! Kontakt webmasteren, hvis problemet fortsætter.");return false}}
function AjaxSend(url,param){req.open("post",url,true);req.setRequestHeader("Content-type","application/x-www-form-urlencoded");req.setRequestHeader("Content-length",param.length);req.setRequestHeader("Connection","close");req.send(param)}
function LoginClick(o){InputClear(o);if(document.getElementById("loginusername").style.color+document.getElementById("loginpassword").style.color==""){document.getElementById("loginsubmit").removeAttribute("disabled","")}}
function Login(o,username,password){o.setAttribute("disabled",true);AjaxConn();req.onreadystatechange=function(){if(req.readyState==4&&req.status==200){var json=eval("("+req.responseText+")");if(json.message!="")alert(json.message);if(json.status)window.location.reload(true);else o.removeAttribute("disabled")};};AjaxSend("/json/login.asp","username="+URLEncode(username)+"&password="+URLEncode(password))}
function UsernameExists(o){document.getElementById("usernamevacant").style.display=document.getElementById("usernameexists").style.display="none";document.getElementById("submit").removeAttribute("disabled");if(o.value.length){AjaxConn();document.getElementById("usernameloading").style.display="inline";req.onreadystatechange=function(){if(req.readyState==4&&req.status==200){document.getElementById("usernameloading").style.display="none";var json=eval("("+req.responseText+")");if(json.exists){document.getElementById("submit").setAttribute("disabled",true);document.getElementById("usernameexists").style.display="inline"}else{document.getElementById("usernamevacant").style.display="inline"};};};AjaxSend("/json/usernameexists.asp","username="+URLEncode(o.value))}}
function ZeroInt(i){i=String(i);if(i.length==1)i=0+i;return i}
function DateTime(){if(document.getElementById("time")){var now=new Date();document.getElementById("time").firstChild.nodeValue=ZeroInt(now.getDate())+"-"+ZeroInt((parseInt(now.getMonth())+1))+"-"+now.getFullYear()+" "+ZeroInt(now.getHours())+":"+ZeroInt(now.getMinutes())+":"+ZeroInt(now.getSeconds());setTimeout("DateTime()",1001)}}appendEvent(window,"load",function(){DateTime()})
function insertFlash(src,width,height,flashvars){document.write("<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" width=\""+width+"\" height=\""+height+"\"><param name=\"allowScriptAccess\" value=\"sameDomain\"><param name=\"movie\" value=\""+src+"\"><param name=\"quality\" value=\"high\"><param name=\"flashvars\" value=\""+flashvars+"\"><param name=\"menu\" value=\"false\"><embed src=\""+src+"\" quality=\"high\" name=\"logo1\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" menu=\"false\" width=\""+width+"\" height=\""+height+"\" flashvars=\""+flashvars+"\"></object>")}
function URLEncode(clearString){var output="";var x=0;clearString=clearString.toString();var regex=/(^[a-zA-Z0-9_.]*)/;while(x<clearString.length){var match=regex.exec(clearString.substr(x));if(match!=null&&match.length>1&&match[1]!=""){output+=match[1];x+=match[1].length}else{if(clearString[x]==" ")output+="+";else{var charCode=clearString.charCodeAt(x);var hexVal=charCode.toString(16);output+="%"+(hexVal.length<2?"0":"")+hexVal.toUpperCase()}x++};};return output}