var ie6 = (navigator.userAgent.toLowerCase().indexOf("msie 6") != -1) ? true : false;
var mac = (navigator.userAgent.toLowerCase().indexOf("mac") != -1) ? true : false;
var pho = (navigator.userAgent.toLowerCase().indexOf("phoenix") != -1) ? true : false;
var ie = (navigator.userAgent.toLowerCase().indexOf("msie") != -1) ? true : false;
var ie55 = (ie && (navigator.userAgent.toLowerCase().indexOf("5.5") != -1)) ? true : false;
var moz = (navigator.appName == "Mozilla" || (navigator.appName == "Netscape" && navigator.appVersion.indexOf("4.") == -1)) ? true : false;	

var IE6 = ie6;	
var IE = ie;

/**
 * Støtte funktion
 */

function getLayer(id) {
	if (document.layers) {
		for (i=0;i<document.layers.length;i++) {
			if (document.layers[i].name == id) {
				return document.layers[i];
			}
		}
	} else if (document.getElementById) {
		return document.getElementById(id)
	} else if (document.all) {
		return document.all[id]
	}
}

function submitPoll(obj) {
	o = -1;
	
	for (i=0; i < obj.option.length;i++) {
		if (obj.option[i].checked) {o=i};
	}
	
	if (o == -1) {
		alert('Der er ikke valgt et svar!');
	} else {
		obj.submit();
	}
}

function alertCookie(obj) {
	if (obj.checked == true) {
		var question = confirm('Brug kun autologin ved en computer som du er enebruger af!\nVil du bruge autologin?');
		if (question == '0') {
			obj.checked = false;
		}
    }
}

img = new Image;
function changeImg(imgName, target) {
	img.src = imgName;
	document[target].src = img.src;
}

function openScaleableWin(url,win_name,popUpWidth,popUpHeight,leftPos,topPos) {
	popWidthHeight = "width=" + popUpWidth + ",height=" + popUpHeight;
	poptop = "";
	popleft = "";
	features = popWidthHeight + poptop + popleft + ",scrollbars=yes,status=yes,resizable=yes";
	window.open(url,win_name,features);
}

function openWindow(url,name,windowWidth,windowHeight) {
	
	if (document.all || document.layers) {
	   w = screen.availWidth;
	   h = screen.availHeight;
	} else {
		w = window.screen.availWidth;
		h = window.screen.availHeight;
	}
	
	var leftPos = Math.round((w-windowWidth)/2);
	var topPos = Math.round((h-windowHeight)/2);
	
	
	features = "width=" + windowWidth + ", height=" + windowHeight +', top='+ topPos + ', left=' + leftPos +', status=yes, resizable=yes';
	return window.open(url,name,features);
}

function openWin(url,win_name) {
	window.open(url,win_name);
}

function popupFileLink(fileId) {
	openWindow('/d/skolemaelk/static/view/index.php?file='+ fileId,'popup',400,600);
}

function playFlash(url,width,height) {
	tagStr = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0" width="'+ width +'" height="'+ height +'">';
	tagStr = tagStr + '	<param name="movie" value="'+ url +'">';
	tagStr = tagStr + '	<param name="quality" value="best">';
	tagStr = tagStr + '	<param name="play" value="true">';
	tagStr = tagStr + '	<embed src="'+ url +'" type="application/x-shockwave-flash" width="'+ width +'" height="'+ height +'" pluginspage="http://www.macromedia.com/go/getflashplayer" quality="best" play="true">';
	tagStr = tagStr + '</object>';
	
	document.write(tagStr);
}





function toggleClass(eId) {
	curClass = document.getElementById(eId).className;
	baseName = ""; //className uden Show eller Hide
	if (curClass.lastIndexOf("Hide") > -1) {
		arrClassName = curClass.split("Hide");
		postfix = "Show";
	} else if (curClass.lastIndexOf("Show") > -1) {
		arrClassName = curClass.split("Show");
		postfix = "Hide";
	}
	baseName = arrClassName[0];
	className =  baseName + postfix
	document.getElementById(eId).className = className;
	return className;
}





var Util = new Object();

Util.Menu = new function(){

	this.over = function(element){
		if(!element.firstChild.src.match(/_over/g)){
			if(!element.initiated){
				element.onmouseout = function(){
					Util.Menu.out(this);
				}
			}
			element.initiated = true;

			element.firstChild.src = element.firstChild.src.replace(/.png/g, "_over.png");
		}
	}
	this.out = function(element){
		element.firstChild.src = element.firstChild.src.replace(/_over/g, "");
	}

}

Util.otliam = function(name, domain){
	document.write('<a href="mailto:'+name+'@'+domain+'">'+name+'@'+domain+'</a>');
}

// create popup
Util.popUp = function(url, name, w, h, extras){
	name = (name) ? name : "POPUP_" + new Date().getHours() + "_" + new Date().getMinutes() + "_" + new Date().getMilliseconds();
	w = (w) ? w : 673;
	h = (h) ? h : 500;
	w += Util.explorer() ? 28 : 0;
	var parameters = "width=" + w + ",height=" + h;
	parameters += ",left=" + (screen.width-w)/2;
	parameters += ",top=" + ((screen.height-h)-20)/2;
	if(extras){
		parameters += "," + extras;
	}else{
		parameters += ",scrollbars";
	}
	document[name] = window.open(url, name, parameters);
}

Util.print = function(url){
	if(Util.explorer()){
		Util.popUp(url, false, 650);
	}else{
		window.print();
	}
}

/* START browser definition utilities */
Util.explorer = function(){
	if(document.all){
		return true;
	}
	return false;
}
Util.safari = function(){
	if(navigator.appVersion.indexOf("Safari") >= 0){
		return true;
	}
	return false;
}
Util.firefox = function(){
	if(navigator.userAgent.indexOf("Firefox") >= 0){
		return true;
	}
	return false;
}
/* END browser definition utilities */

function showHideSolution(argIntId)
{
	if(document.getElementById('question' + argIntId).className == "hide")
	{
		document.getElementById('question' + argIntId).className = "show";
		document.getElementById('solution' + argIntId).className = "hide";
	}
	else
	{
		document.getElementById('question' + argIntId).className = "hide";
		document.getElementById('solution' + argIntId).className = "show";
	}
}


function writeHTML(a)
{
	document.write(a)
}

