if(document.all){
	var xMax = screen.width;
	var yMax = screen.height;
}
else{
	if(document.layers){
		var xMax = window.outerWidth;
		var yMax = window.outerHeight;
	}
	else{
		var xMax = 800;
		var yMax = 600;
	}
}
var imgHeight = '';
var imgWidth = '';
var img = '';
function openPicViewer(iSrc,katID){
	img = new Image();
	img.src = iSrc;
	img.onload = function theRest(){
	var imgWidth = img.width;
	
	if(imgWidth>800){
		var imgHeight = Math.round(img.height/(imgWidth/800))+40;
		imgWidth = 800;
	}
	else{
		var imgHeight = img.height+40;
	}
	
	var xOffset = (xMax/2) - (imgWidth/2);
	var yOffset = (yMax/2) - (imgHeight/2);
	var iKategori = getQuery(iSrc,"kategori");
	var iLopenr = getQuery(iSrc,"lopenr");
	var iDato = getQuery(iSrc,"dato");
	var iRef = getQuery(iSrc,"ref");
	var urlString = "misc?URL=/mal/bestillbildeForside.pbs&nocache=1&Kategori=" + iKategori + "&Lopenr=" + iLopenr + "&Dato=" + iDato + "&Ref=" + iRef;
//	alert(urlString);
		if(imgHeight != 0){
		window.open(urlString,'tb','width=' + imgWidth + ',height=' + imgHeight + ',fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,directories=no,location=no,screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+'');
		}
		else{
			alert("Det har oppstått en liten feil. Prøv igjen!");
		}
	}
}
function getQuery(string,query){
	string = string.toLowerCase();
	var i = 1;
	var nextLetter = '';
	while(nextLetter!='&'){
		i += 1;
		nextLetter = string.substring(string.indexOf(query)+query.length+i,string.indexOf(query)+query.length+i+1);
	}
	i = i-1;
	var a = string.indexOf(query)+query.length+1;
	var b = string.indexOf(query)+query.length+1+i;
	query = string.substring(a,b);
	return query;
}