﻿// JScript File


/* Global Interface Variables */

var gKSEVisible = false;	// whether the full KSE environment is visible

// global browser test variables
var gBrowserIE = /MSIE/.test(navigator.userAgent);
var gBrowserSafari = /Safari/.test(navigator.userAgent);
var gBrowserMozilla = !gBrowserIE && !gBrowserSafari && navigator.product == "Gecko";


if (gBrowserMozilla) {
	/* create replacement for outerHTML for Mozilla browsers */
	HTMLElement.prototype.__defineSetter__("outerHTML", function (sHTML) {
	   var r = this.ownerDocument.createRange();
	   r.setStartBefore(this);
	   var df = r.createContextualFragment(sHTML);
	   this.parentNode.replaceChild(df, this);
	
	   return sHTML;
	});
}

function toggle_display(tid) {
    if(document.getElementById(tid).style.display == "none") {
        document.getElementById(tid).style.display = "";
        img = document.getElementById(tid + "_expander");
        img.src = img.src.replace('expand', 'collapse');
    }
    else {
        document.getElementById(tid).style.display = "none";
        img = document.getElementById(tid + "_expander");
        img.src = img.src.replace('collapse', 'expand');
    }
}


function HelpAlert()
{
    alert("Hjelp er ikke tilgjengelig");
}

function toggleVisible(object)
{
 if(document.getElementById(object).style.visibility == 'hidden') {
    document.getElementById(object).style.visibility = 'visible';
 }
 else {
    document.getElementById(object).style.visibility = 'hidden';
 }
  
}

function showMap()
{
	showModalWindow();
};

/* modal dialog window display and handling */

function showModalWindow()
{
	
	// instantiate the modal window template
	
	
	

	// position the modal window centered on the page
	var wh = getWindowHeight();
	var ww = getWindowWidth();
	var mwTop = Math.round((wh - document.getElementById('_mw').offsetHeight)/2);
	var mwLeft = Math.round((ww - document.getElementById('_mw').offsetWidth)/2);
	document.getElementById('_mw').style.top = mwTop + 'px';
	//document.getElementById('_mw').style.top = '10px';
	document.getElementById('_mw').style.left = mwLeft + 'px';
	
	// show the window
	document.getElementById('_mw_clickfilter').style.visibility = 'visible';
	document.getElementById('_mw').style.visibility = 'visible';
		
};

function getWindowHeight()
{
	// try this version first, as it is a better value
	// when both are present in case the body is smaller
	// than the window frame
	if (window.innerHeight && window.innerHeight > 0) {
		// netscape
		return window.innerHeight;
	}
	
	if (document.body.offsetHeight && document.body.offsetHeight > 0) {
		// DOM
		return document.body.offsetHeight;
	}
	
	return null;
};

/* gets the window width in cross platform form */
function getWindowWidth()
{
	// try this version first, as it is a better value
	// when both are present in case the body is smaller
	// than the window frame
	if (window.innerWidth && window.innerWidth > 0) {
		// netscape
		return window.innerWidth;
	}
	
	if (document.body.offsetWidth && document.body.offsetWidth > 0) {
		// DOM
		return document.body.offsetWidth;
	}
	
	return null;
};

