// Check browser:
var nn4 = (document.layers)? true:false;
var ie4 = (document.all)? true:false;
var dom = (document.getElementById)? true:false;
var ns6 = (document.getElementById && !document.all)? true:false;
// functions for popUp-windows
var logWin;

function popUp(url,name,w,h,extra) {
	popUp2(url,name,w,h,extra)
}

function popUp2(url,name,w,h,extra){
	if(ns6 && w<364)
		w=363;
	if (dom && !ie4) { h = parseInt(h)+0; }
	str="height="+h+",width="+w+","+extra;
	if(parseInt(navigator.appVersion)>3) {
		str+=",left="+(screen.width-w)/2+",top="+parseInt((screen.height -h)/2);
		logWin=window.open(url,name,str);
		logWin.focus();
	}
}
function popUpScroll(filename,windowname,w,h) {
		browserName = navigator.appName;
		browserVer = parseInt(navigator.appVersion);
		ver = "0";
		
		if (browserName == "Netscape") ver = "ns";
		if (browserName == "Microsoft Internet Explorer") ver = "ie";
		
		if( (ver == "ns") & (browserVer < 4) ) {
			w += 30;
			h += 30;
		}

         popupwindow=open(filename, windowname,'scrollbars=yes,status=no,menubar=no,directories=no,resize=no,width=' +w +',height=' + h);
	 popupwindow.focus();
}
function reLoc(top,bot) {
	parent.frTop.location = top;
	if (bot) { parent.frBot.location = bot; }
}
function goAndClose(parenturl) {
top.opener.location.href=parenturl;
top.close();
}
function openPrint(url) {
if(navigator.appVersion.indexOf("Mac") != -1)
		popUp2(url,'Print',570,350,'toolbar=yes');
	else if(ns6)
		popUp2(url,'Print',571,350);
	else
		popUp2(url,'Print',570,350);
}
function getTopFrame(url) {
parent.frTop.location=url;
}
function getBottomFrame(url) {
parent.frBot.location=url;
}
function goAndRefresh(url,var1) {
top.opener.location.href=url+var1;
top.close();
}
function setFocus(streng) {
eval (streng+'.focus()');
}
//function that accepts a formname, a startdate and an enddate. Collects the startdate- and enddate values into two dateobjects and compares them. If startdate is not
//bigger or equal to the enddate, the function submits the received form.
function checkDate(formname, fperiod, tperiod) {
	startdate = new Date();
	enddate = new Date();
	if(document.layers) {
		startdate=eval('document.layers.contentClip.document.layers.content.document.'+formname+'.'+fperiod+'.options[document.layers.contentClip.document.layers.content.document.'+formname+'.'+fperiod+'.selectedIndex].value');
		enddate=eval('document.layers.contentClip.document.layers.content.document.'+formname+'.'+tperiod+'.options[document.layers.contentClip.document.layers.content.document.'+formname+'.'+tperiod+'.selectedIndex].value');
	}
	else {
		startdate=eval('document.'+formname+'.'+fperiod+'.options[document.'+formname+'.'+fperiod+'.selectedIndex].value');
		enddate=eval('document.'+formname+'.'+tperiod+'.options[document.'+formname+'.'+tperiod+'.selectedIndex].value');
	}
	if(startdate>=enddate) {
		alert('Fraperiode som er: '+startdate+' er større end eller lig med tilperiode som er: '+enddate);
		return;
	}
	else {
		alert(startdate);
		alert(enddate);
		if(ie4) {
			eval('document.all.content.document.'+formname+'.submit()');
		}
		else if(nn4) {
			eval('document.contentClip.document.content.document.'+formname+'.submit()');
		}
		else if(dom) {
			eval('document.'+formname+'.submit()');
		}
	}
}
function loopForms(){		
		for(i=0;i<document.forms.length;i++){
			for(j=0;j<document.forms[i].elements.length;j++){
				if(document.forms[i].elements[j].type == "text" || document.forms[i].elements[j].type == "password"){
					document.forms[i].elements[j].onfocus = whatForm;
					document.forms[i].elements[j].onkeypress = submitForm;
				}
			}
		}
	}
	
	var selForm;
	function whatForm(){
		selForm = this.form;
	}
	
	function submitForm(e){	
		var theEvent;
		if(document.all)
			theEvent = event.keyCode;
		else if(document.getElementById) {
			theEvent = e.which;
			alert('event er'+theEvent);
			}
		if(theEvent == 13) {
			alert('Der er trykket på enter');
			selForm.submit();
			}
	}

function popUpExt(filename,windowname,w,h) {


		browserName = navigator.appName;
		browserVer = parseInt(navigator.appVersion);
		ver = "0";
		
		if (browserName == "Netscape") ver = "ns";
		if (browserName == "Microsoft Internet Explorer") ver = "ie";
		
		if( (ver == "ns") & (browserVer < 4) ) {
			w += 30;
			h += 30;
		}

         popupwindow=open(filename, windowname,'scrollbars=yes,status=yes,menubar=yes,directories=yes,resize=yes,toolbar=yes,width=' +w +',height=' + h);
	 popupwindow.focus();
}