/**
Copyright (C) 2001 by Michael Petersen.
Beskyttet ved Dansk lov om ophavsret.
Coded by Michael Petersen - 2000-2002
Vers. 1.0 - first released 18-09-2001
last edited: 12-01-2002
*/
//IE4=(document.all)
//NS4=(document.layers)
//NS6=document.getElementById
//Mac=(navigator.appVersion.indexOf("Mac")!=-1)



var isNS4 = false;
var isNS6 = false;
var isIE = false;
var isOpera = false;

browserCheck();
//I tilfælde af at enkelte browsere ikke understøttes kan der her linkes videre til "beklager"-side	
//if (isIE) location = 'beklager.html';
if (isNS4) location = '../javascript/beklager.html';
//if (isNS6) location = 'beklager.html';
//if (isOpera) location = 'beklager.html';


function browserCheck(){
	if (parseInt(navigator.appVersion) >= 4) {
		if (navigator.appName == 'Netscape') {
			if (navigator.userAgent.indexOf('Opera') > -1){
				isOpera = true;
			}
			if (parseInt(navigator.appVersion) >= 5)
				isNS6 = true;
			else
				isNS4 = true;
		}
		else if (navigator.appName == 'Opera'){
			isOpera = true;
		}
		else{
			if (navigator.userAgent.indexOf('Opera') > -1){
				isOpera = true;
			}
			else
				isIE = true;
		}
	}
}


function checkLayer(layerStr, name){
	var obj = eval(layerStr + '.' + name);
	if (obj){
		return obj;
	}
	else {
		var myLayer = eval(layerStr + '.layers');
		var len = 0;
		if (myLayer) len = myLayer.length;

		if (len > 0)
		{
			for (var i = 0; i < len; i++){
				var newLayerStr = layerStr + '.layers[' + i + '].document';
				myLayer = eval(newLayerStr);	
				if (myLayer)
				{
					var foundObj = checkLayer(newLayerStr, name);
					if (foundObj){
						return foundObj;
					}
				}
			}
		}
		else{
			var myForm = eval(layerStr + '.forms');
			var len = 0;
			if (myForm) len = myForm.length;

			if (len > 0){
				for (var i = 0; i < len; i++){
					var newFormStr = layerStr + '.forms[' + i + '].' + name;
					myFormElement = eval(newFormStr);	
					if (myFormElement)
						return myFormElement;
					
				}
			}
		}
	}
}


function getObj(idStr){
	if (isNS4){
		return checkLayer('document', idStr);
	}	
	else if (isNS6){
		var obj = document.getElementById(idStr);
		
		if (obj) return obj
		else return checkLayer('document', idStr);
	}
	else{
		return eval('document.all.' + idStr);
	}
}


function showObj(idStr){
	var obj = getObj(idStr);

	if (isOpera){
		obj.style.visibility = "visible";
	}
	else if (isIE){
		obj.style.visibility = "visible";
	}
	else if (isNS6){
		obj.style.visibility = "visible";
	}
	else if (isNS4){
		obj.visibility = "visible";
	}
	return obj;
}

function hideObj(idStr){
	var obj = getObj(idStr);

	if (isOpera){
		obj.style.visibility = "hidden";
	}
	else if (isIE){
		obj.style.visibility = "hidden";
	}
	else if (isNS6){
		obj.style.visibility = "hidden";
	}
	else if (isNS4){
		obj.visibility = "hidden";
	}
	return obj;
}


function setObjClip(idStr, clipLeft, clipTop, clipBottom, clipRight){
var obj = getObj(idStr);
var clipst = 'rect(' + clipTop + ', ' + clipRight + ', ' + clipBottom + ', ' + clipLeft + ')';

if (isNS6){
	oldRect = 'rect(' + obj.offsetTop + ', ' + obj.offsetWidth + ', ' + obj.offsetHeight + ', ' + obj.offsetLeft + ')';
	obj.style.clip = clipst;
}
else if (isNS4)
	with (obj.clip){
		top = clipTop;
		right = clipRight;
		bottom = clipBottom;
		left = clipLeft ;
}
else if (isIE){
	oldRect = 'rect(' + obj.offsetTop + ', ' + obj.offsetWidth + ', ' + obj.offsetHeight + ', ' + obj.offsetLeft + ')';
	obj.style.clip=clipst ;
}
else return null;
}



function getObjPosX(idStr, stopAtID){
	var obj = getObj(idStr);

	if (isOpera){
		temp = obj;
		tempX = 0;
		if (stopAtID != null){
			while (temp.id != stopAtID){
                   tempX += temp.offsetLeft;
                   temp = temp.parentElement;
			}
		
		}
		else{
			while (temp.tagName != 'HTML'){
                   tempX += temp.offsetLeft;
                   temp = temp.parentElement;
			}
		}
		return tempX;
		
	}
	else if (isIE){
		return obj.offsetLeft;
	}
	else if (isNS6){
		return obj.offsetLeft;
	}
	else if (isNS4){
		return obj.left;
	}
	else return null;
}


function getObjPosY(idStr, stopAtID){
	var obj = getObj(idStr);

	if (isOpera){
		temp = obj;
		tempY = 0;
		if (stopAtID != null){
			while (temp.id != stopAtID){
                   tempY += temp.offsetTop;
                   temp = temp.parentElement;
			}
		
		}
		else{
			while (temp.tagName != 'HTML'){
                   tempY += temp.offsetTop;
                   temp = temp.parentElement;
			}
		}
		return tempY;
	}
	else if (isIE){
		return obj.offsetTop;
	}
	else if (isNS6){
		return obj.offsetTop;
	}
	else if (isNS4){
		return obj.top;
	}
	else return null;
}


function getObjHeight(idStr){
	var obj = getObj(idStr);

	if (isOpera){
		//return obj.pixelHeight;
		return obj.style.height;
	}
	else if (isIE){
		return obj.offsetHeight;
	}
	else if (isNS6){
		return obj.offsetHeight;
	}
	else if (isNS4){
		return obj.clip.height;
	}
	else return null;
}


function getObjWidth(idStr){
	var obj = getObj(idStr);

	if (isOpera){
		//return obj.pixelWidth;
		return obj.style.width;
	}
	else if (isIE){
		return obj.offsetWidth;
	}
	else if (isNS6){
		return obj.offsetWidth;
	}
	else if (isNS4){
		return obj.clip.width;
	}
	else return null;
}


function moveObjXY(idStr, x, y){
	var obj = getObj(idStr);

	if (isOpera){
		obj.style.pixelLeft = x;
		obj.style.pixelTop = y;
	}
	else if (isIE){
		obj.style.pixelLeft = x;
		obj.style.pixelTop = y;
	}
	else if (isNS6){
		obj.style.left = x;
		obj.style.top = y;
	}
	else if (isNS4){
		obj.left = x;
		obj.top = y;
	}
	return obj;
}


function moveObjX(idStr, x){
	var obj = getObj(idStr);

	if (isOpera){
		obj.style.pixelLeft = x;
	}
	else if (isIE){
		obj.style.pixelLeft = x;
	}
	else if (isNS6){
		obj.style.left = x;
	}
	else if (isNS4){
		obj.left = x;
	}
	return obj;
}


function moveObjY(idStr, y){
	var obj = getObj(idStr);

	if (isOpera){
		obj.style.pixelTop = y;
	}
	else if (isIE){
		obj.style.pixelTop = y;
	}
	else if (isNS6){
		obj.style.top = y;
	}
	else if (isNS4){
		obj.top = y;
	}
	return obj;
}


function getAvailScreenWidth(){
	if (isIE){
		return document.body.clientWidth;
	}
	else if (isNS6){
		return window.innerWidth;
	}
	else if (isNS4){
		return window.innerWidth;
	}
	else return null;
}

function getAvailScreenHeight(){
	if (isIE){
		return document.body.clientHeight;
	}
	else if (isNS6){
		return window.innerHeight;
	}
	else if (isNS4){
		return window.innerHeight;
	}
	else return null;
}


function getObjZIndex(idStr){
	var obj = getObj(idStr);

	if (isOpera){
		return obj.style.zIndex;
	}
	else if (isIE){
		return obj.style.zIndex;
	}
	else if (isNS6){
		return obj.style.zIndex;
	}
	else if (isNS4){
		return obj.zIndex;
	}
	return obj;
}

function setObjZIndex(idStr, zIndex){
	var obj = getObj(idStr);

	if (isOpera){
		obj.style.zIndex = zIndex;
	}
	else if (isIE){
		obj.style.zIndex = zIndex;
	}
	else if (isNS6){
		obj.style.zIndex = zIndex;
	}
	else if (isNS4){
		obj.zIndex = zIndex;
	}
	return obj;
}

function setObjWidth(idStr, width){
	var obj = getObj(idStr);

	if (isOpera){
		obj.style.pixelWidth = width;
		//obj.width = width;
	}
	else if (isIE){
		obj.style.width = width;
	}
	else if (isNS6){
		obj.style.width = width;
	}
	else if (isNS4){
		obj.width = width;
	}
	return obj;
}

function setObjHeight(idStr, height){
	var obj = getObj(idStr);

	if (isIE){
		obj.style.height = height;
	}
	else if (isNS6){
		obj.style.height = height;
	}
	else if (isNS4){
		obj.height = height;
	}
	if (isOpera){
		obj.style.pixelHeight = height;
	}
	return obj;
}

function docWrite(msg){
	document.open()
	document.write(msg);
	document.close();
}

function getCookieVal (offset) {
   var endstr = document.cookie.indexOf (";", offset);
   if (endstr == -1)
      endstr = document.cookie.length;
   return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
        var arg = name + "=";
        var alen = arg.length;
        var clen = document.cookie.length;
        var i = 0;
        while (i < clen) {
                var j = i + alen;
                if (document.cookie.substring(i, j) == arg)
                        return getCookieVal (j);
                i = document.cookie.indexOf(" ", i) + 1;
                        if (i == 0)
                                break;
                }
   return null;
}
function SetCookie (name, value) {
        var argv = SetCookie.arguments;
        var argc = SetCookie.arguments.length;
        var expires = (argc > 2) ? argv[2] : null;
        var path = (argc > 3) ? argv[3] : null;
        var domain = (argc > 4) ? argv[4] : null;
        var secure = (argc > 5) ? argv[5] : false;
        document.cookie = name + "=" + escape (value) +
                ((expires == null) ? "" : ("; expires=" +
expires.toGMTString())) +
                ((path == null) ? "" : ("; path=" + path)) +
                ((domain == null) ? "" : ("; domain=" + domain)) +
                ((secure == true) ? "; secure" : "");
}

