function initialize() {
  linksExternos();
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function visskjul(id) {
  if(document.getElementById(id).style.display == 'none')
    document.getElementById(id).style.display = 'block';
  else
    document.getElementById(id).style.display = 'none';
}

function emptyValue(theelement,defaultvalue) {
  if(theelement.value==defaultvalue)
    theelement.value="";
  return;
}
 
function fillValue(theelement,defaultvalue) {
  if(theelement.value=="")
    theelement.value=defaultvalue;
  return;
} 

function resizeContentArea(topdiv,bottomdiv,contdiv,minsize) {
  contentTopDiv = document.getElementById(topdiv)
	contentBotDiv = document.getElementById(bottomdiv)
	contentTop = getPixelsFromTop(contentTopDiv);
	contentBottom = getPixelsFromTop(contentBotDiv);
	contentHeight = contentBottom - contentTop;
	if(contentHeight < minsize) {
    contentDiv=document.getElementById(contdiv);
    contentDiv.style.height=minsize + 'px';
  }
}

function equalheightcols() {
  maxheight=0;
  minsize=equalheightcols.arguments[0];
  for(x=1;x<equalheightcols.arguments.length;x++) {
    theelement=equalheightcols.arguments[x];
    contentTopDiv = document.getElementById(theelement+'_top');
  	contentBotDiv = document.getElementById(theelement+'_bottom');
  	contentTop = getPixelsFromTop(contentTopDiv);
  	contentBottom = getPixelsFromTop(contentBotDiv);
  	contentHeight = contentBottom - contentTop;
  	if(contentHeight>maxheight) { maxheight=contentHeight; }
  }
  if(maxheight<minsize) { maxheight=minsize; }
  for(x=1;x<equalheightcols.arguments.length;x++) {
    theelement=equalheightcols.arguments[x];
    contentDiv=document.getElementById(theelement);
    contentDiv.style.height=maxheight + 'px';
  }
}



function getPixelsFromTop(obj){
	objFromTop = obj.offsetTop;
	while(obj.offsetParent!=null) {
		objParent = obj.offsetParent;
		objFromTop += objParent.offsetTop;
		obj = objParent;
	}
	return objFromTop;
}

function placeFocus() {
  if (document.forms.length > 0) {
    var field = document.forms[0];
    for (i = 0; i < field.length; i++) {
      if ((field.elements[i].type == "text") || (field.elements[i].type == "textarea") || (field.elements[i].type.toString().charAt(0) == "s")) {
        document.forms[0].elements[i].focus();
        break;
      }
    }
  }
}

function linksExternos() {
  if (!document.getElementsByTagName) return;
  var anchors = document.getElementsByTagName("a");
  for (var i=0; i<anchors.length; i++) {
    var anchor = anchors[i];
    anchor.tabindex = i;
    if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
      anchor.target = "_blank";
  }
}

function confirmWithUrl(theText, theUrl) {
  if (confirm(theText))
    location.href=theUrl;
}

function MM_openBrWindow(theURL,winName,features) {
  win=window.open(theURL,winName,features);
  win.focus();
}

function changeImages() {
	if (document.images) {
		for (var i=0; i < changeImages.arguments.length; i+=2) {
			document.getElementById(changeImages.arguments[i]).src = changeImages.arguments[i+1];
		}
	}
}

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);
}

function getWindowHeight() {
   var windowHeight = 0;
   if (typeof(window.innerHeight) == 'number') {
     windowHeight = window.innerHeight;
   }
   else {
     if (document.documentElement && document.documentElement.clientHeight) {
       windowHeight = document.documentElement.clientHeight;
     }
     else {
       if (document.body && document.body.clientHeight) {
         windowHeight = document.body.clientHeight;
       }
     }
   }
   return windowHeight;
 }
 
function getWindowWidth() {
   var windowWidth = 0;
   if (typeof(window.innerWidth) == 'number') {
     windowWidth = window.innerWidth;
   }
   else {
     if (document.documentElement && document.documentElement.clientWidth) {
       windowWidth = document.documentElement.clientWidth;
     }
     else {
       if (document.body && document.body.clientWidth) {
         windowWidth = document.body.clientWidth;
       }
     }
   }
   return windowWidth;
 }
 
 centeredElementName=new Array();
 
 function arrValueExists(arr,value) {
   foundflag=false;
   for(x=0;x<arr.length;x++) {
     if(arr[x]=value) foundflag=true;
   }
   return foundflag;
 }
 
 function centerElement(elementname) {
   if(!arrValueExists(window.centeredElementName,elementname)) window.centeredElementName[window.centeredElementName.length]=elementname;
   var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body;
   var dsocleft=document.all? iebody.scrollLeft : pageXOffset;
   var dsoctop=document.all? iebody.scrollTop : pageYOffset;
   if (document.getElementById) {
     var windowHeight = getWindowHeight();
     var windowWidth = getWindowWidth();
     if (windowHeight > 0) {
       var contentElement = document.getElementById(elementname);
       contentElement.style.height='auto';
       //var contentHeight = contentElement.offsetHeight;
       //var contentWidth = contentElement.offsetWidth;
       //var contentHeight = 500;
       var contentWidth=getWidth(contentElement,1,1);
       var contentHeight=getHeight(contentElement,1,1);
       
       if (windowHeight - contentHeight > 0) {
         contentElement.style.position = 'absolute';
         contentElement.style.top = Math.round((windowHeight / 2) - (contentHeight / 2) + dsoctop) + 'px';
         contentElement.style.left = ((windowWidth / 2) - (contentWidth / 2)) + 'px';
         contentElement.style.zIndex="1000"; 
       }
       else {
         contentElement.style.position = 'static';
       }
     }
   }
 }
 
 function centerElementAndShowHide(elementname) {
   visskjul(elementname);
   centerElement(elementname);
 }
 
 function vistipenven() {
   element=document.getElementById('centeredContent');
   element.style.display='block';
   element=document.getElementById('tipenvenform_ven_1_navn');
   element.focus();
 }
 
 window.onresize=function() {
   for(x=0;x<window.centeredElementName.length;x++) {
     centerElement(window.centeredElementName[x]); }
 }
 
 window.onscroll=function() {
   for(x=0;x<window.centeredElementName.length;x++) {
     centerElement(window.centeredElementName[x]); }
 }
 
 var getWidth = function (/* Object */ el, /* boolean */ includePadding, /* boolean */ includeBorder) {
    var width;
    el = (typeof(el) === "string") ? document.getElementById(el) : el;  
    
    if (document.defaultView && window.getComputedStyle) { /* FF, Safari, Opera and others */
        var style = document.defaultView.getComputedStyle(el, null);
        if (style.getPropertyValue("display") === "none")
            return 0;
        width = parseInt(style.getPropertyValue("width"));
        
        if (window.opera && !document.getElementsByClassName) {
            /* Opera 9.25 includes the padding and border when reporting the width/height - subtract that out */
            width -= parseInt(style.getPropertyValue("padding-left"));
            width -= parseInt(style.getPropertyValue("padding-right"));
            width -= parseInt(style.getPropertyValue("border-left-width"));
            width -= parseInt(style.getPropertyValue("border-right-width"));
        }
        
        if (includePadding) {
            width += parseInt(style.getPropertyValue("padding-left"));
            width += parseInt(style.getPropertyValue("padding-right"));
        }
        
        if (includeBorder) {
            width += parseInt(style.getPropertyValue("border-left-width"));
            width += parseInt(style.getPropertyValue("border-right-width"));
        }
    } else if (el.currentStyle) { /* IE and others */
        if (el.currentStyle["display"] === "none")
            return 0;
        var bRegex = /thin|medium|thick/; /* Regex for css border width keywords */
        width = el.offsetWidth; /* Currently the width including padding + border */
        
        if (!includeBorder) {
            var borderLeftCSS = el.currentStyle["borderLeftWidth"];
            var borderRightCSS = el.currentStyle["borderRightWidth"];
            var temp = document.createElement("DIV");
            if (el.offsetWidth > el.clientWidth && el.currentStyle["borderLeftStyle"] !== "none") {
                if (!bRegex.test(borderLeftCSS)) {
                    temp.style.width = borderLeftCSS;
                    el.parentNode.appendChild(temp);
                    width -= temp.offsetWidth;
                    el.parentNode.removeChild(temp);
                } else if (bRegex.test(borderLeftCSS)) {
                    temp.style.width = "10px";
                    temp.style.border = borderLeftCSS + " " + el.currentStyle["borderLeftStyle"] + " #000000";
                    el.parentNode.appendChild(temp);
                    width -= Math.round((temp.offsetWidth-10)/2);
                    el.parentNode.removeChild(temp);
                }
            }
            if (el.offsetWidth > el.clientWidth && el.currentStyle["borderRightStyle"] !== "none") {
                if (!bRegex.test(borderRightCSS)) {
                    temp.style.width = borderRightCSS;
                    el.parentNode.appendChild(temp);
                    width -= temp.offsetWidth;
                    el.parentNode.removeChild(temp);
                } else if (bRegex.test(borderRightCSS)) {
                    temp.style.width = "10px";
                    temp.style.border = borderRightCSS + " " + el.currentStyle["borderRightStyle"] + " #000000";
                    el.parentNode.appendChild(temp);
                    width -= Math.round((temp.offsetWidth-10)/2);
                    el.parentNode.removeChild(temp);
                }
            }
        }
        
        if (!includePadding) {
            var paddingLeftCSS = el.currentStyle["paddingLeft"];
            var paddingRightCSS = el.currentStyle["paddingRight"];
            var temp = document.createElement("DIV");
            temp.style.width = paddingLeftCSS;
            el.parentNode.appendChild(temp);
            width -= temp.offsetWidth;
            temp.style.width = paddingRightCSS;
            width -= temp.offsetWidth;
            el.parentNode.removeChild(temp);
        }
    }
    
    return width;
}

///////////////////////////////////////////////////////////////////////////////////////////////////
// USED FOR GETTING THE COMPUTED HEIGHT OF AN ELEMENT IN PIXELS
///////////////////////////////////////////////////////////////////////////////////////////////////
var getHeight = function (/* Object */ el, /* boolean */ includePadding, /* boolean */ includeBorder) {
    var height;
    el = (typeof(el) === "string") ? document.getElementById(el) : el;
    
    if (document.defaultView && window.getComputedStyle) { /* FF, Safari, Opera and others */
        var style = document.defaultView.getComputedStyle(el, null);
        if (style.getPropertyValue("display") === "none")
            return 0;
        height = parseInt(style.getPropertyValue("height"));
        
        if (window.opera && !document.getElementsByClassName) {
            /* Opera 9.25 includes the padding and border when reporting the width/height - subtract that out */
            height -= parseInt(style.getPropertyValue("padding-top"));
            height -= parseInt(style.getPropertyValue("padding-bottom"));
            height -= parseInt(style.getPropertyValue("border-top-width"));
            height -= parseInt(style.getPropertyValue("border-bottom-width"));
        }
        
        if (includePadding) {
            height += parseInt(style.getPropertyValue("padding-top"));
            height += parseInt(style.getPropertyValue("padding-bottom"));
        }
        
        if (includeBorder) {
            height += parseInt(style.getPropertyValue("border-top-width"));
            height += parseInt(style.getPropertyValue("border-bottom-width"));
        }
    } else if (el.currentStyle) { /* IE and others */
        if (el.currentStyle["display"] === "none")
            return 0;
        var bRegex = /thin|medium|thick/; /* Regex for css border width keywords */
        height = el.offsetHeight; /* Currently the height including padding + border */
    
        if (!includeBorder) {
            var borderTopCSS = el.currentStyle["borderTopWidth"];
            var borderBottomCSS = el.currentStyle["borderBottomWidth"];
            var temp = document.createElement("DIV");
            if (el.offsetHeight > el.clientHeight && el.currentStyle["borderTopStyle"] !== "none") {
                if (!bRegex.test(borderTopCSS)) {
                    temp.style.width = borderTopCSS;
                    el.parentNode.appendChild(temp);
                    height -= temp.offsetWidth;
                    el.parentNode.removeChild(temp);
                } else if (bRegex.test(borderTopCSS)) {
                    temp.style.width = "10px";
                    temp.style.border = borderTopCSS + " " + el.currentStyle["borderTopStyle"] + " #000000";
                    el.parentNode.appendChild(temp);
                    height -= Math.round((temp.offsetWidth-10)/2);
                    el.parentNode.removeChild(temp);
                }
            }
            if (el.offsetHeight > el.clientHeight && el.currentStyle["borderBottomStyle"] !== "none") {
                if (!bRegex.test(borderBottomCSS)) {
                    temp.style.width = borderBottomCSS;
                    el.parentNode.appendChild(temp);
                    height -= temp.offsetWidth;
                    el.parentNode.removeChild(temp);
                } else if (bRegex.test(borderBottomCSS)) {
                    temp.style.width = "10px";
                    temp.style.border = borderBottomCSS + " " + el.currentStyle["borderBottomStyle"] + " #000000";
                    el.parentNode.appendChild(temp);
                    height -= Math.round((temp.offsetWidth-10)/2);
                    el.parentNode.removeChild(temp);
                }
            }
        }
    
        if (!includePadding) {
            var paddingTopCSS = el.currentStyle["paddingTop"];
            var paddingBottomCSS = el.currentStyle["paddingBottom"];
            var temp = document.createElement("DIV");
            temp.style.width = paddingTopCSS;
            el.parentNode.appendChild(temp);
            height -= temp.offsetWidth;
            temp.style.width = paddingBottomCSS;
            height -= temp.offsetWidth;
            el.parentNode.removeChild(temp);
        }
    }
    
    return height;
}
 