/**
 * @author	MEL
 * @revised 14/09/07
*/
var Utils = {
	_$:function(s){ return document.getElementById(s)!==null?document.getElementById(s):false; },
	$:function (o){
		if(typeof o=="string"){
			var s=o.split("|"),a=[];
			if(s.length==1) return Utils._$(s[0]);
			for(var i=0; i<s.length; i++) a.push(Utils._$(s[i]));
			o=a;
		}
		return o; 
	},
	show:function(o){
		var o=Utils.$(o),d="block";
		if(!Utils.Browser.msie){
			switch(o.nodeName){
				case "TR":
					d = "table-row";
					break;
				case "TD":
					d = "table-cell";
					break;
				case "TABLE":
					d = "table";
					break;
				case "TBODY":
					d = "table-row-group";
					break;
			}
		}
		if(o.length>1){ 
			for(var i=0; i<o.length; i++) this.setCss(o[i],{display:d}); 
			return o; 
		} else {
			this.setCss(o,{display:d}); 
		}
		return o;
	},
	hide:function(o){
		var o = Utils.$(o);
		if(o.length>1){
			for(var i=0; i<o.length; i++) this.setCss(o[i],{display:"none"}); 
			return o; 
		} else {
			this.setCss(o,{display:"none"});
		}
		return o;
	},
	fill:function(o,c){
		var o = Utils.$(o);
		o.appendChild(Utils.$(c));
		return o;
	},

	getCss:function(o,s){
		var o=Utils.$(o),r,n;
		if(o.currentStyle){ // ie
			var n = s.split("-");
			for(var i=1; i<n.length; i++) n[i] = n[i].charAt(0).toUpperCase()+n[i].substr(1);
			r=o.currentStyle[n.join("")];
		} else if(document.defaultView && document.defaultView.getComputedStyle){ // ff, saf
			r=document.defaultView.getComputedStyle(o,null).getPropertyValue(s);
		} else { // fallback
			r=o.style[s];
		}
		return r;
	},

	setCss:function(o,s){
		var o=Utils.$(o);
		for(var p in s){
			var n = p.split("-");
			for(var i=1; i<n.length; i++) n[i] = n[i].charAt(0).toUpperCase()+n[i].substr(1);
			o.style[n.join("")]=s[p];
		}
	},
	
	addClass:function(o,s){
		var o=Utils.$(o);
		Utils.removeClass(o,s);
		o.className=(o.className+" "+s).trim();
		return o;
	},

	removeClass:function(o,s){
		var o=Utils.$(o);
		o.className=o.className.replace(s,"").trim();
		return o;
	},
	
	getPageSize: function (){
		var xScroll,yScroll,scrollLeft;
		if(window.innerHeight && window.scrollMaxY){
			xScroll = document.body.scrollWidth;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if(document.body.scrollHeight>document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		var windowWidth, windowHeight;
		if (self.innerHeight) {	// all except Explorer
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
			scrollLeft = document.body.scrollLeft;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
			scrollLeft = document.documentElement.scrollLeft;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
			scrollLeft = document.body.scrollLeft;
		}	
		// for small pages with total height less then height of the viewport
		pageHeight = yScroll<windowHeight?windowHeight:yScroll;
		// for small pages with total width less then width of the viewport
		pageWidth=xScroll<windowWidth?windowWidth:xScroll;

		return [pageWidth,pageHeight,windowWidth,windowHeight,scrollLeft];
	},
	createElement:function(t,oConf){
		var o = document.createElement(t);
		for(p in oConf){
			if(p=="CSSClass"){
				o.className = oConf[p];
			} else if(p=="content"){
			    var h = typeof oConf[p]=="object"?oConf[p].innerHTML:oConf[p];
				try { o.innerHTML = h; } catch(e){}
			} else {
				o.setAttribute(p,oConf[p]);
			}
		}
		if(oConf.parent){
			var p = Utils.$(oConf.parent);
			p.appendChild(o);
		} else {
			document.body.appendChild(o);
		}
		return o;
	},
	addLoadEvent:function (f){
		var exi=window.onload;
		if(typeof window.onload!="function"){
			window.onload=f;
		} else {
			window.onload=function(){ exi(); f(); };
		}
	},
	
	/**
	 *
	*/
	addKeyPressEvent:function (o,f){
		var exi=o["onkeypress"];
		if(typeof o["onkeypress"]!="function"){
			o["onkeypress"]=f;
		} else {
			o["onkeypress"]=function(){ o["onkeypress"](); f();	};
		}
	},
	getElementsByClassName:function(p,s){
	    var p=Utils.$(p);
		if(typeof p=="object"){
			var a=p.getElementsByTagName("*"),r=[];
			if(a.length<=0) a=document.all;
			if(a.length>0){
				for(var i=0; i<a.length; i++){
					var sTmp = "#"+a[i].className+"#";
					var re = "[ |#]"+s+"[ |#]";
					if(sTmp.match(new RegExp(re))) r.push(a[i]);
				}
				return r;
			} else {
				return false;
			}
		} else {
			return false;
		}
	},
	getElementsByName_iefix:function(tag, name){
	    var elem = document.getElementsByTagName(tag);
	    var arr = new Array();
	    for(a = 0,iarr = 0; a<elem.length; a++){
	        var att = elem[a].getAttribute("name");
	        if(att == name) {
	            arr[iarr] = elem[a];
	            iarr++;
	        }
	    }
	    return arr;
	},
	disableIEBackgroundFlicker:function (){
		try { document.execCommand('BackgroundImageCache', false, true); } catch(e){}
	},

	Dimensions:{
		page:function (){
			var de = document.documentElement;
			var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
			var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
			return {w:w,h:h};
		},
		scroll:function (){
			var x,y;
			if (self.pageYOffset){ // all except Explorer
				x = self.pageXOffset;
				y = self.pageYOffset;
			} else if (document.documentElement && document.documentElement.scrollTop){ // Explorer 6 Strict
				x = document.documentElement.scrollLeft;
				y = document.documentElement.scrollTop;
			} else if (document.body){ // all other Explorers
				x = document.body.scrollLeft;
				y = document.body.scrollTop;
			}
			return {w:x,h:y};
		}
	},
	Browser:{
		safari:/webkit/.test(navigator.userAgent.toLowerCase()),
		opera:/opera/.test(navigator.userAgent.toLowerCase()),
		msie:/msie/.test(navigator.userAgent.toLowerCase()) && !/opera/.test(navigator.userAgent.toLowerCase()),
		mozilla: /mozilla/.test(navigator.userAgent.toLowerCase()) && !/(compatible|webkit)/.test(navigator.userAgent.toLowerCase())
	},
	Page:{
		
		resizeLeftMenu:function (){
			if(Utils.$("col-left-nav")){
				try { Utils.$("col-left-nav").style.height = (Utils.$("grid").offsetHeight-16) + "px"; } catch(e) {} // the -16px is the margin-top on .col {...}
			}
		}, // @Utils.Page.resizeLeftMenu
		
		setCampaignLinks:function (){
			/**
			 * Get <div>'s with class "add-link" and add custom over/out/click events to each. 
			 * Create transparent overlays to specific modules.
			*/
			 // ÆØ 3555 MIW
			var allDivAddLinks = Utils.getElementsByName_iefix("div", "divaddlink");
			for (var u = 0; u<allDivAddLinks.length; u++)
			{
			    var aCamps = Utils.getElementsByClassName(allDivAddLinks[u],"add-link");
			    //alert(aCamps.length)
			// ÆØ 3555 TODO change function to not use document
			//var aCamps = Utils.getElementsByClassName(document,"add-link");
			// \ÆØ 3555
			if(aCamps.length>0){
			for(var i=0; i<aCamps.length; i++){
				var o = aCamps[i];
				Utils.addClass(o,"link-cursor");
				
				/**
				 * 20/04/07 - MEL - Phase 2 specifies a new type of module - "banner".
				 * Look: image with transparent overlay on mouseover. To be able to do 
				 * this have to be able to switch between the two types. So a custom
				 * property ("overlayTypeIs") is set on the outer <div> as a flag.
				*/
				o.overlayTypeIs = ""; // textAndImage | onlyImage
				/**/
				
				// a new fase 2 camp specifies text-decoration on hover
				o.addUnderline = (o.className.indexOf("add-underline")!= -1 ? true:false);
				
				/**
				 * Modules with image and text
				 * Add an overlay layer to every webpart that contains a <div> with classname "trans-trumpet"
				*/
				var oTransDiv = Utils.getElementsByClassName(o,"trans-trumpet");
				if(oTransDiv[0]){
					var oTD = oTransDiv[0];
					var oOverlay = Utils.createElement("DIV",{CSSClass:"overlay",content:"&nbsp;"});
					oTD.appendChild(oOverlay);
					oOverlay.style.visibility = "visible";
					var aHeader = oTD.getElementsByTagName("H3");
					if(aHeader[0]){ aHeader[0].style.visibility = "visible"; }
					o.overlayTypeIs = "textAndImage";
					o.setAttribute("overlayTypeIs","textAndImage");
				}
				
				/**
				 * Module "banner" - image only
				 * Add an overlay layer to every webpart that contains a <div> with classname "trans-overlay"
				 * 07/08/07 Update: this behaviour is also needed in a rendering with image and headline, 
				 * but not a trumpet so the "image only" is not entirely correct
				*/
				var oTransDiv = Utils.getElementsByClassName(o,"trans-overlay");
				if(oTransDiv[0]){
					var oTD = oTransDiv[0];
					var oOverlay = Utils.createElement("DIV",{CSSClass:"overlay",content:""});
					oTD.appendChild(oOverlay);
					oOverlay.style.display = "none";
					o.overlayTypeIs = "onlyImage";
					var oArrow = Utils.createElement("DIV",{CSSClass:"arrow",content:"&nbsp;"});
					oTD.appendChild(oArrow);
				}
				
				// Get the first link in the webpart and add it's href-att. as a custom prop. to the current <div>
				var aL = o.getElementsByTagName("A");
				if(aL[0]){ var aTemp = aL[0]; o.setAttribute("href",aL[0].getAttribute("href")); o.linkref = aTemp; }
				
				// "Hardcode" inline style height value
				var aImgs = o.getElementsByTagName("IMG");
				if(aImgs[0]){
					aImgs[0].alt = "";
					aImgs[0].title = "";
					aImgs[0].wrapper = o;
					if(Utils.Browser.msie){
						if(aImgs[0].parentNode.className.indexOf("bottom")!=-1){ aImgs[0].height+=(aImgs[0].offsetHeight%2!=0?-1:0); } // CR 1121: solution for the 1px jog in IE
						o.setAttribute("oheight",aImgs[0].height + "px"); 
					} else {
						aImgs[0].onload = function (){
							this.wrapper.setAttribute("oheight",this.height + "px");
						}
					}
				}
				
				// event mouseover
				o.onmouseover = function (e){ 
					
					// Show the link address in the browsers status bar, so it looks like a regular HTML link
					try { window.status = this.getAttribute("href").replace("_blank",""); } catch(e){} 

					if(this.overlayTypeIs == "textAndImage"){
						var o = Utils.getElementsByClassName(this,"trans-trumpet"); // parent div
						if(o[0]){
							var o = o[0];
							var aOverlay = Utils.getElementsByClassName(this,"overlay");
							if(aOverlay[0] != null){
								var oOverlay = aOverlay[0];
								Utils.addClass(oOverlay,"hover");
								oOverlay.style.height = this.getAttribute("oheight"); 
							}
							
						} // 
					} else if(this.overlayTypeIs == "onlyImage"){
						var o = Utils.getElementsByClassName(this,"trans-overlay"); // parent div
						if(o[0]){
							var o = o[0];
							var aOverlay = Utils.getElementsByClassName(this,"overlay");
							if(aOverlay[0] != null){
								var oOverlay = aOverlay[0];
								oOverlay.style.display = "block";
								oOverlay.style.height = this.getAttribute("oheight");
							}
						}
					}
					
					this.oOverlayRef = oOverlay; // pass a ref to the overlay to the mouseover <div>, so it can be used in the mouseout event
					
					if(this.addUnderline){
						this.linkref.className = "force-underline";
					}
				}

				// event mouseout
				o.onmouseout = function (){ 
					try { window.status = window.defaultStatus; } catch(e){}
					if(this.overlayTypeIs == "textAndImage"){
						Utils.removeClass(this.oOverlayRef,"hover");
						try { this.oOverlayRef.style.height = "auto"; } catch(e){}
					} else if(this.overlayTypeIs == "onlyImage"){
						try { this.oOverlayRef.style.display = "none"; } catch(e){}
					}
					if(this.addUnderline){
						this.linkref.className = "clean";
					}
				}

				// event click
				o.onclick = function (){ 
				    if (this.getAttribute("href").match("_blank") != null)
				    {
				        window.open(this.getAttribute("href").replace("_blank", ""));
				    }
				    else
				    {
				        document.location.href = this.getAttribute("href"); 
				    }
				}
								
				/**
				 * Nuke all links in the campaign
				*/
				var aLinks = o.getElementsByTagName("A");
				if(aLinks.length > 0){
					for(var p=0; p<aLinks.length; p++){
						aLinks[p].removeAttribute("href");
						Utils.addClass(aLinks[p],"clean");  /** some browsers still underlines the link when mousing over, so add a class that removes the unline */
					}
				}				
			} // for()
			} // if length>0
			} // for (allDivAddLinks)
			
			/**
			 * topnews webpart
			*/
			var aCampsNews = Utils.getElementsByClassName("grid","webpart-news");
			for(var i=0; i<aCampsNews.length; i++){
				var o = aCampsNews[i];
				var aImgs = o.getElementsByTagName("IMG");
				if(aImgs[0]){
					aImgs[0].onload = function (){
						this.parentNode.style.height = this.height + "px";
						Utils.removeClass(o,"no-image");
					}
				}
			}
		}, // @Utils.Page.setCampaignLinks
		
		createAccessiblePopupLinks:function (){
		    // ÆØ 3555 MIW kun nødvendig for tools menuen
		    var toolmenu = document.getElementById("menu-tools");
		    if(toolmenu)
		    {
			    var aElms = Utils.getElementsByClassName(toolmenu,"popup");
    			
			    //var aElms = Utils.getElementsByClassName(document,"popup");
    			
			    var dims = {
				    tipafriend:{w:500,h:500},
				    def:{w:100,h:100}
			    };
			    var currentDims;
			    for(var i=0; i<aElms.length; i++){
    			    
				    var o=aElms[i];
				    if(o.nodeName == "A"){ // only apply to links <a> not other nodes with class "popup"
					    var sHref = o.getAttribute("href");
					    //alert(sHref);
					    o.setAttribute("savedHrefAtt",sHref); // save the href attribute so we can use it in the window.open()
					    o.onclick = function (){
						    if(sHref != "#" && sHref != ""){
							    if(o.className.indexOf("tipafriend") != -1){
								    currentDims = "tipafriend";
							    } else {
								    currentDims = "def";
							    }
							    try {
							        //alert(dims)
								    this.win = window.open(this.getAttribute("savedHrefAtt"),"RegionH","width="+dims[currentDims].w+",height="+dims[currentDims].h);
							    } catch(e){ }
							    return false; 
						    }
					    };
				    }
			}
			}
		}, // @Utils.Page.createAccessiblePopupLinks
		
		ModalMask:{
			create:function(c){
				var o = Utils.createElement("DIV",{id:"modalmask"});
				Utils.addClass(document.getElementsByTagName("HTML")[0],"modalenabled");
				Utils.Page.ModalMask.resize("modalmask");
				window.onresize = function (){
					Utils.Page.ModalMask.resize("modalmask");
				}
				var o = Utils.createElement("DIV",{id:"modalcontent",CSSClass:"modalcontent"});
				this.content(o,c);
			},
			destroy:function (){
				var o = Utils.$("modalmask");
				var oC = Utils.$("modalcontent");
				if(o) try { document.body.removeChild(o); document.body.removeChild(oC); } catch(e){ }
				Utils.removeClass(document.getElementsByTagName("HTML")[0],"modalenabled"); // only used to hide <select>'s in ie6.css
				window.onresize = null;
			},
			resize:function (s){
				var o = Utils.$(s);
				var d = Utils.Dimensions.page();
				o.style.height = d.h + "px";
				o.style.width = d.w + "px";
			},
			content:function (o,c){
				Utils.show(o);
				Utils.fill(o,Utils.$(c));
				Utils.setCss(o,{"marginLeft":"-"+(o.offsetWidth/2)+"px","marginTop":"-"+(o.offsetHeight/2)+"px"});
			}
		},
		Tables:{		
			zebratize:function (){
			    var allTables = Utils.getElementsByName_iefix("div", "tableWithStripes");
			    for (var u = 0; u<allTables.length; u++)
			    {
				    var oTables = Utils.getElementsByClassName(allTables[u],"stripes");
				    //var oTables = Utils.getElementsByClassName(document,"stripes");
				    for(var i=0; i<oTables.length; i++){
					    var oTbodys = oTables[i].getElementsByTagName("TBODY");
					    for(var j=0; j<oTbodys.length; j++){
						    for(var k=0; tr=oTbodys[j].getElementsByTagName("TR")[k]; k++){
							    tr.className = k%2==0?"odd":"even";
						    }
					    }
				    }
				}
			}
		}, // @Utils.Page.Tables
					
		Stylesheet:{
			FontSizes:{
				min:60,
				max:90,
				init:70,
				current:70
			},
			initialize:function (){
				this.buttons();
				if(typeof Utils.Page.Cookie.read("NCfontSize") == "string"){
					document.body.style.fontSize = Utils.Page.Cookie.read("NCfontSize")+"%";
					Utils.Page.Stylesheet.FontSizes.current = parseInt(Utils.Page.Cookie.read("NCfontSize"));
				}		
			},
			buttons:function (){
				if(Utils.$("menu-tools")) try { Utils.getElementsByClassName(Utils.$("menu-tools"),"link-text-small")[0].onclick = function (){ return Utils.Page.Stylesheet.changeTo("smaller"); } } catch(e){ }
				if(Utils.$("menu-tools")) try { Utils.getElementsByClassName(Utils.$("menu-tools"),"link-text-large")[0].onclick = function (){ return Utils.Page.Stylesheet.changeTo("larger"); } } catch(e){ }
			},
			changeTo:function(sSize){
				var size = Utils.Page.Stylesheet.FontSizes.current;
				if(sSize == "larger"){
					if(size <= Utils.Page.Stylesheet.FontSizes.max){
						document.body.style.fontSize = size+5 + "%";
						
						Utils.Page.Stylesheet.FontSizes.current += 7;
					}
				} else if(sSize == "smaller"){
					if(size >= Utils.Page.Stylesheet.FontSizes.min){
						document.body.style.fontSize = size-5 + "%";
						Utils.Page.Stylesheet.FontSizes.current -= 7;
					}
				}
				Utils.Page.Cookie.create("NCfontSize",Utils.Page.Stylesheet.FontSizes.current,365);
				
				return false; 
			}
		}, // @Utils.Page.Stylesheet
		
		Cookie:{
			create:function(name,value,days){
				if(days){
					var date = new Date();
					date.setTime(date.getTime()+(days*24*60*60*1000));
					var expires = "; expires="+date.toGMTString();
				} else {
					expires = "";
				}
				document.cookie = name+"="+value+expires+"; path=/";
			},
			read:function(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;
			}
		}, // @Utils.Page.Cookie
		
		Print:{
			active:false,
			initialize:function (){
			    if ( getUrlParameterValue( "printpage" ) == "true" )
			    {
			        this.enablePrintPreview();
			    }
				if(Utils.$("menu-tools")){
					var oThis = this;
					var btn = Utils.getElementsByClassName(Utils.$("menu-tools"),"link-print")[0];
					btn.onclick = function (){ 
					    var separator = "?";
					    if ( window.location.href.indexOf(separator) != -1 )
					    {
					        separator = "&";
					    }
					    window.open(window.location.href + separator + "printpage=true"); // æø 2935
						/*oThis.enablePrintPreview();
						oThis.active = true;*/
						return false;
					}
					if(oThis.oPrintPreview()){
						oThis.oPrintPreview().disabled = true;
					}
					// set the possibility to cancel the printpreview by pressing <ESC>
					Utils.addKeyPressEvent(document,function(e){
						var code;
						if (!e) var e = window.event;
						if(e.keyCode){
							code = e.keyCode;
						} else if(e.which){
							code = e.which;
						}
						if(code == 27 && oThis.active){
							oThis.disablePrintPreview();
						}
					});
				}
			},
			oPrintPreview:function (){ 
				return Utils.$("ss-print-preview"); 
			},
			enablePrintPreview:function (){
			    this.active = true;
				Utils.Page.Print.oPrintPreview().disabled = false;
				try { window.print(); } catch(e){}
				Utils.$("cancel-print-preview").onclick = this.disablePrintPreview;
				var links = Utils.getElementsByClassName(document,"add-link");
				try { if(navigator.userAgent.toLowerCase().indexOf("msie") != -1) window.resizeBy(1,1); } catch(e){} // fix weird IE render bug when pressing the printpreview button. -> The print logo is not visible before you resize the window manually, so try to do it automatically.
			},
			disablePrintPreview:function (){
				Utils.Page.Print.oPrintPreview().disabled = true;
				Utils.Page.Print.active = false;
				return false;
			}
		}, // @Utils.Page.Print
		
		Layout:{
			tmpScrollInt:0,
			check: function (){
				if(Utils.$("area-head")){
					var p = Utils.getPageSize();
					var checkAgainstScrollWidth = p[4];
					if(p[2] <= 977 || checkAgainstScrollWidth != Utils.Page.Layout.tmpScrollInt){
						Utils.$("area-head").style.width = p[2] +checkAgainstScrollWidth+ "px";
						Utils.Page.Layout.tmpScrollInt = p[4];
					} else {
						Utils.$("area-head").style.width = "auto";
						}
				}
			},
			positionSearchBox: function (){
				setInterval("Utils.Page.Layout.check()",1000);
			}
		},  // @Utils.Page.Layout
		
		clearSearchBoxText:function (){
			try {
			    var searchArea = document.getElementById("search"); // ÆØ 3555 MIW optimeret
				var searchTermInputs = Utils.getElementsByClassName(searchArea,"searchterm"); // ÆØ 3555
				//var searchTermInputs = Utils.getElementsByClassName(document,"searchterm");
				if(typeof searchTermInputs == "object"){
					for(var i=0; i<searchTermInputs.length; i++){
						searchTermInputs[i].onfocus = function (){
							this.value = "";
						}
					}
				}
			} catch(e){}
		}, // @Utils.Page.Layout

		/**
		 * onDOMContentLoaded, kudos jquery
		*/
		Loader:{
			readyList:[],
			add:function (func){
				Utils.Page.Loader.readyList.push(func);
			},
			run:function (){
				for(var i=0; i<Utils.Page.Loader.readyList.length; i++){
					Utils.Page.Loader.readyList[i].apply(document);
				}
			},
			prepare:function (){
				if (Utils.Browser.mozilla || Utils.Browser.opera){
					document.addEventListener( "DOMContentLoaded", Utils.Page.Loader.run, false );
				} else if(Utils.Browser.msie){	
					document.write("<scr" + "ipt id=__ie_init defer=true " + 
						"src=//:><\/script>");
					var script = document.getElementById("__ie_init");
					if ( script ) 
						script.onreadystatechange = function() {
							if ( this.readyState != "complete" ) return;
							this.parentNode.removeChild( this );
							Utils.Page.Loader.run();
						};
					script = null;
				} else if (Utils.Browser.safari){
					var safariTimer = setInterval(function(){
						if ( document.readyState == "loaded" || 
							document.readyState == "complete" ) {
							clearInterval(safariTimer);
							safariTimer = null;
							Utils.Page.Loader.run();
						}
					}, 10); 
				} else {
					Utils.addLoadEvent(Utils.Page.Loader.run);
				}
			}	
		},
		
		start:function (){

			/**
			 * Add links to all relevant campaigns
			*/
			Utils.Page.setCampaignLinks();
			
			Utils.disableIEBackgroundFlicker();
			
			/**
			 * Set focus handler on the textboxes that clears the text
			*/
			Utils.Page.clearSearchBoxText();

			/**
			 * Initializes the print button. (Set onclick handlers on the button)
			*/
			Utils.Page.Print.initialize();
			
			/**
			 * Sets the preferred stylesheet based on user cookie and 
			 * sets onclick handlers on the buttons for changing stylesheets.
			*/
			Utils.Page.Stylesheet.initialize();
			
			/**
			 * Resize the height of the left menu to stretch to 100%
			*/
			Utils.Page.resizeLeftMenu();
			
			/**
			 * Creates accessible popup-links
			*/
			// ÆØ 3555 MIW seems like this is not used
			Utils.Page.createAccessiblePopupLinks();
			
			/**
			 * Reposition the top searchbox at an interval, so the box is visible in 800x600 too
			*/
			Utils.Page.Layout.positionSearchBox();
			
			/**
			 * Add stripes to all tables that have class="stripes"
			*/
			Utils.Page.Tables.zebratize();
			
			/*jump to console if in editmode*/
			var s=window.location.href;
			if(s.indexOf("EnableGotoAchor")!=-1) window.location.href="#visning"; //ÆØ139 PKA
			
			// ÆØ 3555 MIW Only relevant in startineditmode udkommenter
			/*only relevant in editmode*/
			// RFC 3555
			//var plut=Utils.getElementsByClassName(document,'btn-calendar');
			//for(var i=0; i<plut.length; i++) plut[i].style.display = 'block';
		}, // @Utils.Page.start
		
		// if in editmode, strip out all functions that use getElementsByClassName
		startInEditMode:function (){
		    var plut=Utils.getElementsByClassName(document,'btn-calendar');
			for(var i=0; i<plut.length; i++) plut[i].style.display = 'block';
			var s=window.location.href;
			if(s.indexOf("EnableGotoAchor")!=-1 ) window.location.href="#visning"; //ÆØ139 PKA
		} // @Utils.Page.startInEditMode		
	} // @Utils.Page
} // @Utils

/**
 * Initialize the document
*/
// ÆØ 2741 MIW inkommenter efter MEL svar
var s=window.location.href;
//If user is editing or creating a new page
if(s.indexOf("AuthoringReedit") != -1 || s.indexOf("AuthoringNew" )!=-1)
{
    $(document).ready(Utils.Page.startInEditMode);
} 
else 
{
    $(document).ready(Utils.Page.start);
}
// \ ÆØ 2741
//Utils.Page.Loader.prepare();
//var s=window.location.href;
////If user is editing or creating a new page
//if(s.indexOf("AuthoringReedit") != -1 || s.indexOf("AuthoringNew" )!=-1){
//    Utils.Page.Loader.add(Utils.Page.startInEditMode);
//} else {
//    Utils.Page.Loader.add(Utils.Page.start);
//}
String.prototype.trim = function(){
	return this.replace(/^\s+|\s+$/,"");
}
if(typeof Array.prototype.push=="undefined"){
	Array.prototype.push = function (k){
		this[this.length] = k;
		return this.length;
	};
}
function clog(o){
	if(typeof window.console == "object"){
		window.console.log(o);
	} else {
		alert(o)
	}
}

/*
 * gets the value of an url parameter from the name of the parameter
*/
function getUrlParameterValue( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#$]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

//Nedenstående er JS fra RegionN
function updateExportFields(path, idFieldId, pathFieldId) {
  var idField   = document.getElementById(idFieldId);
  var pathField = document.getElementById(pathFieldId);

  if(pathField.value != "" && pathField.value.substring(0, 1) == "/") {
    path = encodeURI(pathField.value);
  }

  var result = window.showModalDialog("/RegionHovedstaden/Modules/RegNord/ExportFolder.aspx?path=" + path + "&amp;selected=" + idField.value, "", "status:no");
  var values;
  
  if(result == null || result == "") {
    return;
  }

  values = result.split(",");

  idField.value   = values[0];
  pathField.value = values[1];  

}

// Apply checked state to visibility of an object
function applyCheckedInvisible(checkBox, targetId) {

  setVisibility(targetId, !checkBox.checked);

}

function applyCheckedVisible(checkBox, targetId) {

  setVisibility(targetId, checkBox.checked);

}

// Set visibility of an object by object ID.
function setVisibility(targetId, visible) {

  var target = document.getElementById(targetId);
  
  if(visible == true) {
    target.style.display = "block";
  } else {
    target.style.display = "none";
  }
  
}

function updateMetaField(type, fieldId) {
  
  var field   = document.getElementById(fieldId);
  var content = field.value.replace("/^\s*|\s*$/g","");
  var current;

  if(content == "") {
    current = new Array();
  } else { 
    current = content.split(",");
    for(var i = 0; i < current.length; i++) {
      current[i] = current[i].replace("/^\s*|\s*$/g","");
    }
  }
  
  //alert("current: " + current.join(","));
  var result = window.showModalDialog("/RegionHovedstaden/Modules/RegNord/MetadataDialog.aspx?type=" + type + "&checked=" + field.value, "", "status:no");
  var checked;
  
  if(result == null) {
    return;
  }
  
  if(result == "") {
    checked = new Array();
  } else {
    checked = result.split(",");
  }
  
  //alert("checked: " + checked.join(","));

  for(var i = 0; i < checked.length; i++) {
    var found = false;
    for(var j = 0; j < current.length; j++) {
      if(checked[i] == current[j]) {
        found = true;
      }
    }
    if(found == false) {
      current.push(checked[i]);
    }
  }      

  //alert("combined: " + current.join(","));

  field.value = current.join(",");
  
  //End RegionN
}
