var scriptloaded = false;

function loadscript(src){
	if (scriptloaded == false){
		var script = document.createElement("script");
		script.src = "http://slikleksikon.org/" + src;
		script.type = "text/javascript";
		var head = document.getElementsByTagName("head").item(0);
		head.appendChild(script);
	}
}

function login(elm){
	if (document.getElementById('loginbox')){
		document.getElementById('loginbox').parentNode.removeChild(document.getElementById('loginbox'));
	}else{
		if (document.getElementById('loginpil')){
			document.getElementById('loginpil').parentNode.removeChild(document.getElementById('loginpil'));
		}
		var newdiv;
		newdiv = document.createElement('div');
		newdiv.className = 'logindiv';
		newdiv.id = 'loginbox';
		newdiv.innerHTML = '<form action="http://slikleksikon.org/static/login/" method="POST" name="loginf" onsubmit="this.pass.value = crypt(this.pass.value);"><table border="0" cellpadding="2" cellspacing="0" width="140"><tr><td colspan="2"><input type="text" name="nick" value="Brugernavn" onfocus="if (this.value==\'Brugernavn\'){this.value=\'\';};" class="login" style="width:140px;"></td></tr><tr><td colspan="2"><input type="text" name="dummy" value="Password" onfocus="this.style.display=\'none\';document.loginf.pass.style.display=\'block\';document.loginf.pass.focus();" class="login" style="width:140px;"><input type="password" name="pass" class="login" style="width:100%;display:none;"></td></tr><tr><td width="20"><input type="checkbox" name="auto"></td><td class="login" width="140">Auto login</td></tr><tr><td colspan="2" align="right"><input type="submit" value="Login" class="login"> <input type="button" value="Annuller" onclick="login(this);" class="login"></td></tr></table></form>';
		elm.parentNode.appendChild(newdiv);

		//loadscript("js/crypt.js");
	}
}

function popup(url, width, height){
	var pw = Math.round((screen.availWidth/2)-(width/2));
	var ph = Math.round((screen.availHeight/2)-(height/2));
	var popup = window.open(url, 'POPUPEN', 'width=' + width + ', height=' + height + ', left=' + pw + ', top=' + ph + ',resizable=yes,scrollbars=yes');
}

var toggledlast = null;

function toggletr(obj, collapslast){
	if (obj.style.display == "none"){
		if (toggledlast != null && collapslast){
			toggledlast.style.display = "none";
		}
		
		obj.style.display = "table-row";
		
		if (collapslast){
			toggledlast = obj;
		}
	}else{
		obj.style.display = "none";
	}
}