function changeStyles(styleObj, mouseOn, isEvent, dateName){
	if (mouseOn){
		styleObj.backgroundColor = "#D3E3ED";
		styleObj.borderColor = "#91B7CD";		
		styleObj.cursor = "pointer";
		var affectedAnkers = document.getElementsByName(dateName);
		for (i=0; i<affectedAnkers.length; i++){
			affectedAnkers[i].style.color = "#ED014C";
		}	
	} else {
		if (isEvent){
			styleObj.backgroundColor = "#FFFFFF";
			styleObj.borderColor = "#91B7CD";		
			styleObj.cursor = "arrow";
			var affectedAnkers = document.getElementsByName(dateName);
			for (i=0; i<affectedAnkers.length; i++){
				affectedAnkers[i].style.color = "#1D6CA9";
			}	
		} else {
			styleObj.backgroundColor = "#F3F3F0";
			styleObj.borderColor = "#E1E0D9";		
			styleObj.cursor = "arrow";		
		}
	}
}
function toggleLogin(){
	var loginObj = document.getElementById('loginbox');
	if (loginObj.style.display == 'none'){
		loginObj.style.display = 'block';
	} else {
		loginObj.style.display = 'none';
	}
}

function toggleGotobox(theSelect) {
    // hide all boxes
    var a;
    var viewbox;
    viewbox = theSelect.value;
    a = document.getElementById('gototype1');
    if (a) a.style.display = 'none';
    a = document.getElementById('gototype2');
    if (a) a.style.display = 'none';
    a = document.getElementById('gototype3');
    if (a) a.style.display = 'none';
    a = document.getElementById('gototype4');
    if (a) a.style.display = 'none';
    a = document.getElementById('gototype5');
    if (a) a.style.display = 'none';
    a = document.getElementById('gototype6');
    if (a) a.style.display = 'none';
    a = document.getElementById('gototype7');
    if (a) a.style.display = 'none';
    //show the relevant box
    if (a!='') {
        a = document.getElementById(viewbox)
        if (a) a.style.display = 'block';
    }
}

function doClick(buttonName,e, f)
{
    var key;

     if(window.event)
          key = window.event.keyCode;     //IE

     else
          key = e.which;     //firefox


    if (key == 13)
    {
        eval(f);
        return true;
    }
    return false;
}

/* Functionality used by download section */
var xcoord;
var ycoord;
function getcoords(e) {
    if (!e) 
    { 
        e = window.event; 
    } 

	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	// posx and posy contain the mouse position relative to the document
	// Do something with this information
	xcoord = posx;
	ycoord = posy;
}


var linkToDownload;
function showDownloadBox(link){
	var downloadbox = document.getElementById('downloadbox');
	var elements = downloadbox.getElementsByTagName('div');
	
	/* reset box padding */
	/*elements[2].style.marginTop = '-20px';
	elements[0].style.marginLeft = '110px';*/
	/* calculate box position */
	/*if(xcoord < 350) 
	{
	    elements[0].style.marginLeft = '360px';
	}
	
	if(ycoord > 600) {
	    elements[2].style.marginTop = ycoord - 600 + 'px';
	} */
	elements[0].style.marginLeft = xcoord - 130;
	elements[2].style.marginTop = ycoord - 510;
	
	downloadbox.style.display = 'block';
	linkToDownload = link;
}

function hideDownloadBox() {
	document.getElementById('downloadbox').style.display = 'none';
}

function redirectToDownload(controlid){
	document.getElementById('downloadbox').style.display = 'none';	
	document.getElementById(controlid).value = linkToDownload;
	/*__doPostBack('dlLink', linkToDownload);*/
}

/* should be used in conjunction with asp email validator and above redirect function */
function validateEmail ( emailField ) {
 emailpat = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(\.[a-zA-Z0-9_-]+)+$/;
 if( !emailpat.test( emailField.value ) ) {
  return false;
 }
 return true;
}

/* Used by software product list to show old products */
function showAllVersions() {
		productlist = document.getElementById('listofproducts');
	elements = productlist.getElementsByTagName('div');

	for(var d=0;d < elements.length;d+=1){
	  if(elements[d].id.substring(7,0) == 'product'){
		elements[d].style.display = 'inline';
	  }
	}	
	document.getElementById('allproductversions').style.display = 'none';
	document.getElementById('newestproductversions').style.display = 'inline';
}

/* Used by software product list to show old products */
function hideOldVersions() {
		productlist = document.getElementById('listofproducts');
	elements = productlist.getElementsByTagName('div');

	for(var d=0;d < elements.length;d+=1){
	  if(elements[d].id.substring(10,0) == 'productold'){
		elements[d].style.display = 'none';
	  }
	}
	document.getElementById('allproductversions').style.display = 'inline';
	document.getElementById('newestproductversions').style.display = 'none';
}

/*  External Magnus Søg section */
function redirect() {
	var background = document.getElementById('backgroundcolor').value;
	var border = document.getElementById('bordercolor').value;
	var text = document.getElementById('textcolor').value;

			background = background.replace('#', '');
			border = border.replace('#', '');
			text = text.replace('#', '');


	var url = window.location.href + '?param1=' + background + '&param2=' + border + '&param3=' + text;

	window.location = url;
	return false;
}
function redirectsats() {
	var background = document.getElementById('backgroundcolorsats').value;
	var border = document.getElementById('bordercolorsats').value;
	var text = document.getElementById('textcolorsats').value;

			background = background.replace('#', '');
			border = border.replace('#', '');
			text = text.replace('#', '');


	var url = window.location.href + '?param1=' + background + '&param2=' + border + '&param3=' + text;

	window.location = url;
	return false;
}
function hideDesigner() 
{
	document.getElementById('designer').style.display = 'none';
	return false;
}
function toggleDiv(element) 
{
	var div = document.getElementById(element);
	if(div.style.display == 'none')
		div.style.display = 'block';
	else if(div.style.display == 'block')
		div.style.display = 'none';
}
function changeStyles() 
{
	var newBoxWidth = document.getElementById('searchboxwidth').value;
	var newBackgroundColor;
	var newBorderColor;
	var newTextColor;
	
	if(document.getElementById('backgroundcolor').value.match('#'))
		newBackgroundColor = document.getElementById('backgroundcolor').value;
	else newBackgroundColor = '#' + document.getElementById('backgroundcolor').value;
		
	if(document.getElementById('bordercolor').value.match('#'))
		newBorderColor = document.getElementById('bordercolor').value;
	 else newBorderColor = '#' + document.getElementById('bordercolor').value;
		
	if(document.getElementById('textcolor').value.match('#'))
		newTextColor = document.getElementById('textcolor').value;
	else newTextColor = '#' + document.getElementById('textcolor').value;
	
	var magnussearchboxlimiter = document.getElementById('magnussearchboxlimiter');
	magnussearchboxlimiter.style.width = newBoxWidth;
	
				
	var magnusContainer = document.getElementById('magnuscontainer');
	if(magnusContainer == null){
	    magnusContainer = document.getElementById('magnuscontainersats');
	}
	if(magnusContainer == null){
	    magnusContainer = document.getElementById('magnuscontainerblanketter');
	}
	magnusContainer.style.backgroundColor = newBackgroundColor;
	
	
	var magnusContent = document.getElementById('magnuscontent');
	if(magnusContent == null) {
	    magnusContent = document.getElementById('magnuscontentsats');
	}
	if(magnusContent == null) {
	    magnusContent = document.getElementById('magnuscontentblanketter');
	}
	magnusContent.style.borderColor = newBorderColor;
	
	
	var magnusText = document.getElementById('magnustext');	
	if(magnusText == null) {
	    magnusText = document.getElementById('magnustextsats');	
	}
	if(magnusText == null) {
	    magnusText = document.getElementById('magnustextblanketter');	
	}
	magnusText.style.color = newTextColor;
	
	return false;
}
function changeStylesSats() 
{
	var newBoxWidth = document.getElementById('searchboxwidth').value;
	var newBackgroundColor;
	var newBorderColor;
	var newTextColor;	
	
	if(document.getElementById('backgroundcolor').value.match('#'))
		newBackgroundColor = document.getElementById('backgroundcolor').value;
	else newBackgroundColor = '#' + document.getElementById('backgroundcolor').value;
	
	if(document.getElementById('bordercolor').value.match('#'))
		newBorderColor = document.getElementById('bordercolor').value;
	 else newBorderColor = '#' + document.getElementById('bordercolor').value;
		
	if(document.getElementById('textcolor').value.match('#'))
		newTextColor = document.getElementById('textcolor').value;
	else newTextColor = '#' + document.getElementById('textcolor').value;
	
	
	var magnussearchboxlimiter = document.getElementById('magnussearchboxlimiter');
	magnussearchboxlimiter.style.width = newBoxWidth;
				
	var magnusContainer = document.getElementById('magnuscontainersats');
	magnusContainer.style.backgroundColor = newBackgroundColor;
	
	var magnusContent = document.getElementById('magnuscontentsats');
	magnusContent.style.borderColor = newBorderColor;
	
	var magnusText = document.getElementById('magnustextsats');	
	magnusText.style.color = newTextColor;
	
	return false;
}

/*  Calendar, new feature */
function toggleEvent(elementToToggle) 
{
    if(document.getElementById('foldtext' + elementToToggle).style.display == 'none') {
        document.getElementById('foldtext' + elementToToggle).style.display = 'block';
        document.getElementById('icon' + elementToToggle).src = '/img/linkminus.gif';
        document.getElementById('imgclass' + elementToToggle).className = 'plusimg';
    }
    else 
    {
        document.getElementById('foldtext' + elementToToggle).style.display = 'none';
        document.getElementById('icon' + elementToToggle).src = '/img/linkplus.gif';
        document.getElementById('imgclass' + elementToToggle).className = 'plusimg';
    }
    return false;
}

function toggleLink(elementTotoggle, imgElementTotoggle) 
{
    var element = document.getElementById(elementTotoggle);
    var imgelement = document.getElementById(imgElementTotoggle);

    if(element.style.display == 'none') 
    {
        element.style.display = 'block';
        imgelement.src = '/img/linkminus.gif';
    }
    else 
    {
        element.style.display = 'none';
        imgelement.src = '/img/linkplus.gif';
    }
}

/* Used by satser */
function ChangeTabs(direction)
{
    /* display:block is NOT USED ON PURPOSE. Chrome and firefox looks like shit with display:block */

    var tables = document.getElementsByTagName('table');
    for(var i = 0; i < tables.length; i += 1) 
    {
        if(tables[i].id.substring(15,0) == 'satsoverskrift_')
        {
        
        /* find synlige kolonner og max og min */        
            var highestVisibleYear = 0;
            var lowestVisibleYear = 3000;
            var highestYear = 0;
            var lowestYear = 3000;
        
            var th_elements = tables[i].getElementsByTagName('th');
            for(var d = 0; d < th_elements.length; d += 1)
            {
                if(th_elements[d].id.substring(9,0) == 'columntop')
                {
                    var column = th_elements[d].id.substring(11,10);
                    if(column > highestVisibleYear) 
                    {
                        if(th_elements[d].style.display == '') { highestVisibleYear = column; }               
                    }
                    
                    if(column < lowestVisibleYear) 
                    {
                        if(th_elements[d].style.display == '') { lowestVisibleYear = column; }               
                    }
                    
                    if(column > highestYear) { highestYear = column; }
                    
                    if(column < lowestYear) { lowestYear = column; }
                }
            }        
            /* alert('highestVisibleYear:' + highestVisibleYear + ' lowestVisibleYear:' + lowestVisibleYear + ' highestYear:' + highestYear + ' lowestYear:' + lowestYear + ' tables:' + tables.length);  */
        
            if(direction == '1') 
            {
                var yearToHide;
                var yearToShow;
                
                if((highestVisibleYear + 1) <= highestYear) 
                {
                    yearToHide = lowestVisibleYear;
                    yearToShow = parseInt(highestVisibleYear) + 1;
                    
                    /* Toggles th elements */
                    var thelements = tables[i].getElementsByTagName('th');
                    for(var d = 0; d < thelements.length; d += 1)
                    {
	                      if(thelements[d].id.substring(10,11) == yearToHide) { thelements[d].style.display = 'none'; }
                          if(thelements[d].id.substring(10,11) == yearToShow) { thelements[d].style.display = ''; }
                    }
                    
                    /* Toggles td elements */
                    var tdelements = tables[i].getElementsByTagName('td');
                    for(var d = 0; d < tdelements.length; d += 1)
                    {
	                      if(tdelements[d].id.substring(7,8) == yearToHide) { tdelements[d].style.display = 'none'; }
                          if(tdelements[d].id.substring(7,8) == yearToShow) { tdelements[d].style.display = ''; }
                    }
                }
            }
        
            if(direction == '-1') 
            {
                var yearToHide;
                var yearToShow;
                
                if((lowestVisibleYear - 1) >= lowestYear) 
                {
                    yearToHide = highestVisibleYear;
                    yearToShow = parseInt(lowestVisibleYear) - 1;
                    
                    /* Toggles th elements */
                    var thelements = tables[i].getElementsByTagName('th');
                    for(var d = 0; d < thelements.length; d += 1)
                    {
	                      if(thelements[d].id.substring(10,11) == yearToHide) { thelements[d].style.display = 'none'; }
                          if(thelements[d].id.substring(10,11) == yearToShow) { thelements[d].style.display = ''; }
                    }
                    
                    /* Toggles td elements */
                    var tdelements = tables[i].getElementsByTagName('td');
                    for(var d = 0; d < tdelements.length; d += 1)
                    {
	                      if(tdelements[d].id.substring(7,8) == yearToHide) { tdelements[d].style.display = 'none'; }
                          if(tdelements[d].id.substring(7,8) == yearToShow) { tdelements[d].style.display = ''; }
                    }
                }       
            }
        }       
    }
}

/* Used by search boxes providing the same functionality as zeteo-search on the front page */
function clearzeteosearchbox(element) 
{
	var textboxtext = element.value;
	if(textboxtext.substring(0,7) == 'Indtast')
		element.value = '';
		
	return false;
}

function searchzeteo(element, perspective, newbrowser) 
{
	var url = "/Soegeresultat.aspx?a=a&searchaction=search&searchvalue=" + encodeURI(element.value) + "&extSource=True";
	if(perspective != 'false') 
	{
	    url = url + "&searchfilter=" + perspective;
	}
	if(newbrowser == 'true')
	{
	    window.location.href(url);	
	}
	if(newbrowser == 'false')
	{
	    window.open(url);
	}
	return false;
}

/* NEW TO SIGNFORM */
function doButtonClick(buttonName,e){
//the purpose of this function is to allow the enter key to 
//point to the correct button to click.
    var key;
        
    if(window.event)
        key = window.event.keyCode;     //IE

    else
        key = e.keyCode;     //firefox
    
    if (key == 13)
    {
        //Get the button the user wants to have clicked
        var btn = document.getElementById(buttonName);
        if (btn != null && typeof (btn.click) == 'function')
        { //If we find the button click it                
            btn.click(buttonName);
        }
        else {
            window.location = btn.href;
        }
    }
}

function fold(divid){
	if (document.getElementById(divid).className=='folded'){
		document.getElementById(divid).className='unfolded';
	} else {
		document.getElementById(divid).className='folded';
	}
	resetChildElementsInFolder(divid);
}

function resetChildElementsInFolder(elementId) 
{
	var el = document.getElementById(elementId);
	var grandfather = el.parentNode.parentNode;
	var siblings = grandfather.childNodes;
	
	for(i = 0; i < siblings.length; i++) 
	{
		if(siblings[i].className == 'fold_documents')
		{
			for(ii = 0; ii < siblings[i].childNodes.length; ii++) 
			{
				for(iii = 0; iii < siblings[i].childNodes[ii].childNodes.length; iii++) 
				{
					if(siblings[i].childNodes[ii].childNodes[iii].className == 'hidelayer') 
					{
						/* Silly solution but it works. In some browsers the div wont return to its correct position unless something inside changes styles. Like a mouse over on a link. This takes care of the bug automatically */
						var originalBorder = siblings[i].childNodes[ii].childNodes[iii].style.border;
						siblings[i].childNodes[ii].childNodes[iii].style.border ='3px solid red';
						siblings[i].childNodes[ii].childNodes[iii].style.border = originalBorder;
					}
			
				}				
			}
		}
	
	}
}

/* used by the document lock popup */
function toggleShow(divid, showid) {
    var ie7 = false;
    if ( $.browser.msie ) {
        if(parseInt($.browser.version) == '7')
        {
            ie7 = true;
        }
    }
    
    if(ie7)
    {
        document.getElementById(divid).style.display = 'none';
    }
    else 
    {
        if (document.getElementById(divid).innerHTML == "") {
        document.getElementById(divid).innerHTML = document.getElementById(showid).innerHTML;
        } else {
            document.getElementById(divid).innerHTML = "";
        }
    }  
}

function movePopupForIE7(lockicondiv) {
	if(navigator.appVersion.indexOf('MSIE 7') > -1) {
		// Get your element and move it to where you want it.
		var lockpos = findPos(lockicondiv);
		/*alert(lockpos);*/
		var popup = document.getElementById('lockhtmlabsolute');
		document.body.appendChild(popup);
		popup.style.left = lockpos[0] - 225;
		popup.style.top = lockpos[1] - 30;
		popup.style.zIndex = '110';
	}
}

/* finds the position of the given element. Used by lock popup */
function findPos(obj) {
var curleft = curtop = 0;
if (obj.offsetParent) 
	do 
	{
		curleft += obj.offsetLeft;
		curtop += obj.offsetTop;
	} 
	while (obj = obj.offsetParent);
	return [curleft,curtop];
}

function toggle_submenu(thisitem){
	if (document.getElementById(thisitem+"_sub").style.display=="none" || document.getElementById(thisitem+"_sub").style.display==""){
		document.getElementById(thisitem+"_sub").style.display='block';
		if (document.getElementById(thisitem).className=='menu_item last_item'){
			document.getElementById(thisitem).className='menu_item last_item active';
		} else {
			document.getElementById(thisitem).className='menu_item active';
		}
	} else {
		document.getElementById(thisitem+"_sub").style.display='none';
		if (document.getElementById(thisitem).className=='menu_item last_item active'){
			document.getElementById(thisitem).className='menu_item last_item';
		} else {
			document.getElementById(thisitem).className='menu_item';
		}
	}
}

function toggleShowById(id) {
    if (document.getElementById(id).style.display == 'block') {
        document.getElementById(id).style.display = 'none';
    } 
    else {
        document.getElementById(id).style.display = 'block';
    }
}

/* Used by OSATreeNavigation to add or remove bottom margin when the menu is hidden/shown by a folder */
function togglemenufoldermargin(divid)
{
    if (document.getElementById(divid).className == 'rightsidefold rightsidefold_nobottommargin'){
        document.getElementById(divid).className = 'rightsidefold rightsidefold_bottommargin';
    } else {
        document.getElementById(divid).className = 'rightsidefold rightsidefold_nobottommargin';
    }
}


var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();


 function ChangeIFrameSize() 
 {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) 
	{
		myWidth = window.innerWidth; 
		myHeight = window.innerHeight;
		if(BrowserDetect.browser == 'Chrome') 
		{
			myHeight = myHeight - 23;
		}
		if(BrowserDetect.browser == 'Firefox') 
		{
			myHeight = myHeight - 59;
		}
		/*ff, chrome */
	} 
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
	{
		myWidth = document.documentElement.clientWidth; 
		myHeight = document.documentElement.clientHeight;
		/* explorer*/
	} 
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
	{
		myWidth = document.body.clientWidth; 
		myHeight = document.body.clientHeight;
	}
	document.getElementById('mainZeteo').height = (myHeight - 177) ;
};
