//*************************************************************************
//***	DOM LIBRARY
//*************************************************************************

//*** GLOBAL VARIABEL
	var blnDOM = false;
	
//*** FUNCTIONS
	// Do stuff on onload
	function fjsDoStuffOnOnload() {
		/** Aktiver flasher ***
		var objects = document.getElementsByTagName("object");

		for (var i = 0; i < objects.length; i++){
		    objects[i].outerHTML = objects[i].outerHTML;
		}
		*/ 
		
		//*** Set høyrekolonne høy nok ***
		if (document.getElementById("RightCol")) { 
			if (document.getElementById("RightCol").clientHeight < 315) {
				document.getElementById("RightCol").style.height = 315+'px';
			}
		}

	}


	//Advanced dthml check
	if (document.getElementById && document.createElement){
		blnDOM = true;
	}		
	
	//default image switch
	function fjsImgSwitch(id, imgsrc){
		if (blnDOM == true){		
			if (document.getElementById(item)){		
				//Switch image	
				document.getElementById(item).src = imgsrc;			
			}
		}
	}
	
	//Tool, strips away all path info
	function fjsGetFileName(varName) {
		var re = /^.*\/(\S*\.\S*)$/;
		var tmp = new String(varName);
		tmp = tmp.match(re)[1];
			
		return tmp;
	}
	
	//Swap classes for any item
	function fjsSwapClass(strId, class1, class2){
		if (blnDOM == true){			
			//Check if element exists
			if (document.getElementById(strId)){
				//Switch class
				if (document.getElementById(strId).className == class1){
					document.getElementById(strId).className = class2;
				}
				else if(document.getElementById(strId).className == class2){
					document.getElementById(strId).className = class1;
				}
			}
		}
	}
		
	//Change class for any item
	function fjsChangeClass(strId, class1){
		if (blnDOM == true){
			//Check if element exists
			if (document.getElementById(strId)){
				//Change class
				document.getElementById(strId).className = class1;
			}
		}
	}
	
	//Clear input boxes for default data 
	function fjsClearBox(e){			
		e.value = "";
		e.focus();			
	}	
	
	//When IE creates a new element it gives the new element about 84 attributes inherited from IE's default DTD. Oh what fun.
	//And when you try to change an attribute like "class", it actually creates a new attribute so you end up with 2 "class" attributes.
	//So, this function checks your node for a given attribute, if it exists then it changes the attribute value with the one given.
	//If the attribute doesnt exist, it creates a new one and sets its value.
	function fjsToolBox_setAttribute(oNode, strAttribute, strValue) 
	{
		if (oNode.getAttributeNode(strAttribute)) 
		{
			for (var i = 0; i < oNode.attributes.length; i++) {
				var attrName = oNode.attributes[i].name.toUpperCase();
				if (attrName == strAttribute.toUpperCase()) 
				{
					oNode.attributes[i].value = strValue;
				}
			}				
		}
		else {
			//create a new attribute 
			oNode.setAttribute(strAttribute, strValue);
		}
	}

	
	//retrieves content from text nodes
	function fjsToolBox_GetTextNodeContent(n) 
	{			
		var s = '';
		var children = n.childNodes;
		for(var i = 0; i < children.length; i++) 
		{
			var child = children[i];
			if (child.nodeType == 3 /*Node.TEXT_NODE*/) 
			{
				s += child.data;
			}
			else{ 
				s += getTextContent(child);
			}
		}
		return s;
	}
	
	
	// NAVO HOVER EVENTS STUFF:
	function showHoverEvent(strTheDate, theText)	
	{
		if (document.getElementById("todaysEvents"))
		{
			document.getElementById("todaysEvents").style.display ="none";
		}
		if (document.getElementById("hoverCalendarEvents"))
		{
			var theParent = document.getElementById("hoverCalendarEvents");
			theParent.style.display = "block";
			if(theParent.childNodes.length>0)
			{
				for(i=0; i<theParent.childNodes.length; i++)
				{
					var dill = theParent.removeChild(theParent.childNodes[i]);
				}
			}
			//theParent.childNodes = null;
			var heading = document.createElement("div");
			heading.style.fontWeight = "bold";
			var headingText = document.createTextNode("Hendelser " +strTheDate +":");
			heading.appendChild(headingText);
			theParent.appendChild(heading);
			var arrEvents = new Array();
			arrEvents = theText.split('$');
			for(i=0; i<arrEvents.length; i++)
			{
				var theEvent = document.createElement("p");
				theEvent.id = "eventId"+ i;
				var theTextNode = document.createTextNode(arrEvents[i]);
				theEvent.appendChild(theTextNode);
				theParent.appendChild(theEvent);
			}
			document.getElementById("eventVisualContainer").style.height = (theParent.clientHeight + 8) + "px";

			if(theParent.clientHeight>120)
				document.getElementById("eventContainer").style.height = (theParent.clientHeight + 8) + "px";
			else
				document.getElementById("eventContainer").style.height = "120px";
		}
	}
	function hideHoverEvents()
	{
		if (document.getElementById("hoverCalendarEvents"))
		{
			var theParent = document.getElementById("hoverCalendarEvents");
			if(theParent.childNodes.length>0)
			{
				for(i=0; i<theParent.childNodes.length; i++)
				{
					var dill = theParent.removeChild(theParent.childNodes[i]);
				}
			}
			theParent.style.display = "none";
			theParent.innerHTML = "";
		}
		if (document.getElementById("todaysEvents"))
		{
			document.getElementById("todaysEvents").style.display ="block";
			var todaysHeight = document.getElementById("todaysEvents").clientHeight;
			document.getElementById("eventVisualContainer").style.height = (todaysHeight + 8) +"px";

			if(document.getElementById("todaysEvents").clientHeight>120)
				document.getElementById("eventContainer").style.height = (todaysHeight + 8) + "px";
			else
				document.getElementById("eventContainer").style.height = "120px";
		}else
		{
			//Dagens events eksisterer ikke, sett den visuelle grå bakgrunnen til 0
			document.getElementById("eventVisualContainer").style.height = "0px";
			//
			document.getElementById("eventContainer").style.height = "120px";
		}
	}
	function addLoadEvent(func) {
		var oldonload = window.onload;
		if (typeof window.onload != 'function') {
			window.onload = func;
		} else {
			window.onload = function() {
				if (oldonload) {
					oldonload();
				}
			func();
			}
		}
	}

	// Used for frame-resizing
	function fjsResizeHeight(iHeight,strElementId) {
		var iThisHeight = iHeight;
	//	alert("iThisHeight="+iThisHeight+", strElementId="+strElementId);
	//	document.getElementById("ifrPdc").height = iThisHeight +'px';
		document.getElementById("ifrPdc").style.height = iThisHeight +'px';
	}
	
	// call function on onload
	window.onload = fjsDoStuffOnOnload;