//Skilt ut main og sub vindu
//self.name="dnbnormain";

// Med segmenterings-kode, fra dnb.no
function openWin(wURL,wName,wProps){
	if (wURL.substring(0,1) == "index.html") {
		win = window.open(getJunctionPath() + wURL,wName,wProps);
	}
	else {
	 	win = window.open(wURL,wName,wProps);
	}
}
// For segmentering, ny utgave som fikser webseal 5.1 
function getJunctionPath() {
	var name = "IV_JCT";
	cookie = getCookieValue(name);

	if (cookie == null || cookie == "") {
		return "";
	}

	cookie = cookie.replace("%2F", "index.html");
	
	if (cookie == "index.html") {
		return "";
	}
	else {
		return cookie;
	}
}

// Fjerner space fra start av en streng
function ltrim(string) {
	var t = string;
	while (t.charAt(0)==' ') { 
		t = t.substring(1, t.length);
	}
	
	return t;
}

// Setter fokus på gitt felt, dersom de to første tallene som kommer inn er like 
// brukes slik på feltet foran man vil ha fokus på: onKeyUp="checkLength(this.value.length,4,document.login.otpassword)"
function checkLength(currlength, maxlength, focuselement) {
	if ( currlength==maxlength ) {
		focuselement.focus();
	}
}


// Nekter å gå ut av dette feltet før det er fylt ut med dette antall felt
function lockToField(len, unlocklen, focuselement){
	if(len!=unlocklen){
		focuselement.focus();
	}
}

// Henter verdien av en navngitt cookie, eller null hvis cookien ikke finnes
function getCookieValue(name) {
	var nameEQ = name + "=";
	
	if (document.cookie == null) {
		return null;
	}
	
	var cookies = document.cookie.split(';');
	
	for(var i=0; i < cookies.length; i++) {
		var cookie = ltrim(cookies[i]);
		
		if (cookie.indexOf(nameEQ) == 0) {
			return cookie.substring(nameEQ.length, cookie.length);
		}
	}

	return null;
}

// Div. Javascript-sjekking

// Variabel som benyttes for å være sikker på at javascript-funksjonen under finnes
var scriptCheckPresent = true;

// Henter en side fra Dynamo -- på dynamo setter vi skritping til aktivt og returnerer
// en 1x1 pxl gif. Samtidig setter vi cookien "js" slik at siden/bildet ikke må hentes flere ganger
function setScriptingEnabled() {
	var javaScriptCookieName = "js";

	// Bare hent bilde/siden fra dynamo når cookie ikke er satt
	if (getCookieValue(javaScriptCookieName) == null) {
		var url = getJunctionPath() + "/portal/utils/jsimage.jhtml";
		document.writeln("<img src=\"" + url + "\" border=\"0\"/>");
	}
}

function addInitFunction(func) {
	initFuncs[initFuncs.length] = func;
}

var initFuncs = new Array();

function init(){
	for (var i = 0; i < initFuncs.length; i++) eval(initFuncs[i]);
	isLoaded = true;
}

window.onload = init;


//Resize browser - IE fiks
/*function controlWidth(minWidth, maxWidth, divId){

	idToSize = document.getElementById(divId);

	if ((idToSize.style.pixelWidth <= minWidth) && (minWidth != 0) && (!idToSize.style.minWidth)){
		idToSize.style.pixelWidth = minWidth;
	} else if ((idToSize.style.pixelWidth > maxWidth) && (maxWidth != 0) && (!idToSize.style.maxWidth)){
		idToSize.style.pixelWidth = maxWidth;
	} 
	return false;
}

function widthEventHandler(){
	minWidth = 749; // Min width could be set here, but now use image to control minwidth
	maxWidth = 980;
	divId = 'aa';
	controlWidth(minWidth,maxWidth,divId);
	return false;
}

window.onresize = widthEventHandler;
window.onload = widthEventHandler;
*/
//End of resize browser
