var resizeEvent=false; //resize event check.
var ie,ns4,dom //mainbrowsers Internet Explorer, Netscape 4 or DOM-supported browsers
var opera,gecko,ie4,ie55 //special browsers
var pc, mac, unix //Windows, Mac and Unix compatible systems
var uA = navigator.userAgent 
gecko = (uA.indexOf("Gecko") != -1) ? true : false;
opera = (uA.indexOf("Opera") != -1) ? true : false;
dom = (document.getElementById) ? true : false;
ie = (document.all && !opera) ? true : false;
ie55 = (dom && ie && uA.indexOf("5.5")!=-1) ? true : false;
ie4 = (ie && !opera && !dom) ? true : false;
ns4 = (document.layers)? true : false;
pc = (uA.indexOf("Win") != -1) ? true: false;
mac = (uA.indexOf("Mac")!=-1)? true : false;
unix = (uA.indexOf("Unix") != -1 || uA.indexOf("Linux") != -1) ? true : false;

//preloading images
preload('smUncheckedImg','/files/images/buttons/gx_checkbox_open_b_w1.gif');
preload('smCheckedImg','/files/images/buttons/gx_checkbox_checked_b_w1.gif');

function preload(imgObj,imgSrc) {
// preloada föra tt minska antalet requests till servern
	if (document.images) {
		eval(imgObj+' = new Image()')
		eval(imgObj+'.src = "'+imgSrc+'"')
	}
}


function changeImage(layer,imgName,imgObj) {
// onmouseover script
	if (document.images) {
		if (ns4 && layer!=null) 
			eval('document.layers.container.document.'+layer+'.document.images["'+imgName+'"].src = '+imgObj+'.src');
		else{
			document.images[imgName].src = eval(imgObj+".src");
		}
	}
}

function changeProdImage(layer,imgName,imgObj) {
// onmouseover script
	if (document.images) {
		if (ns4 && layer!=null) 
			eval("document.layers.container.document."+layer+".document.images[\"" +imgName+ "\"].src = \"" + imgObj + "\"");
		else{
			document.images[imgName].src = imgObj;
		}
	}
}

var winW, winH, obj, lObj,posl,post;

function init(){
	// Hitta mitten på skärmen för alla lager
	if (ie){
		winW = document.body.offsetWidth;
		winH = document.body.offsetHeight;
		obj = document.all.container.style
		//lObj = document.all.loader.style
	} else if(ns4){
		winW = window.innerWidth;
		winH = window.innerHeight;
		obj = document.layers.container
		//lObj = document.layers.loader
		//areReady=true
	} else {
		// alla andra browsers, NS6, IE5, Opera m.m.
		winW = window.innerWidth;
		winH = window.innerHeight;
		obj = document.getElementById('container').style
		//lObj = document.getElementById('loader').style
	}
	alignWindow2();
	//if(mac && !areReady && !ie)setTimeout("init()",1000)
	return;
}

function alignWindow2(){
	if (winW < 780 || winH < 430){
	// Om man har mindre än 800x600 skall den alltid ligga till vänster-top
		obj.left = 10;
		obj.top  = 10;
		posl=10; post=10;
	} else { 
	// annars positionera mitt i fönstret
		obj.left = ((winW - 780)/2+15);
		obj.top  = ((winH - 430)/2-5);
		posl=parseInt(obj.left); post=parseInt(obj.top)
	}
	obj.visibility = ns4 ? 'show' : 'visible'
	if(setCookie){
		setCookie('left_layer_position', obj.left)
		setCookie('toppos', obj.top)
	}
	//if(lObj!=null) lObj.visibility = ns4 ? 'hide' : 'hidden'
}
function popEndorsement(url){
	popWindow=window.open(url,'popup','toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,width=691,height=405');
}

function setQuery()
{
	
	frmObj = ns4 ? document.container.document.menu.document.forms['frmSearch'] : document.frmSearch;
	if(frmObj.txtQuery!=''){
		frmObj.newQuery.value = "true"
		frmObj.submit()
	}
}

//checkes input value for search
var checkedImg = "";
function selRadioButton(elName,imgName,boxValue) {
	if(ns4)
		var formElements = document.container.document.menu.document.forms['frmSearch'].elements;
	else
		var formElements = document.forms['frmSearch'].elements;
		
	if(checkedImg == "" && imgName != "prodimg"){
		changeImage('menu','prodimg','smUncheckedImg');	
	}
	
	if (checkedImg != imgName && checkedImg != ""){
		changeImage('menu',checkedImg,'smUncheckedImg');
		}
		
	formElements[elName].value = boxValue; //puts the new checked checkbox value to the input value

	changeImage('menu',imgName,'smCheckedImg');
		 //and changes the checkbox to checked 
	checkedImg = imgName; //checked checkbox is placed in the variabel
}

winCnt = new Array()
function popUp(popNode,parameterName,parameterValue,url, w, h,op,opv){
	var a=arguments
	if(a[6]!=null) o_para = a[6];
	if(a[7]!=null) o_para_value = a[7];
	var l;
	var t;
	if(ns4 || gecko) {
		//Values 5 and 24 are hardcoded values that represent the border and statusbar on netscape
		l = (window.screenX+5) + ((window.innerWidth/2) - (w/2))-5
		if(ns4){ t = (window.screenY + ((window.outerHeight-24) - window.innerHeight)) + (window.innerHeight/2)-(h/2)}
		else if(gecko) { t = (window.screenY + (window.outerHeight-window.innerHeight) - 36) + ((window.innerHeight-18)/2)-(h/2)}
	} else if(mac && ie) {
		l = event.screenX - event.clientX+10; //macie5 only
		t = event.screenY - event.clientY+10; //macie5 only
	} else {
		l = window.screenLeft + (document.body.offsetWidth/2) - w/2
		t = window.screenTop + (document.body.offsetHeight/2) - h/2
	}
	winName = "popup" + winCnt.length
	winProps = "toolbar=no,location=topleft,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=" + w + ",height=" + h + ",left=" + l + ",top=" + t + "screenX=" + l + "screenY=" + t
	if(a[6]!=null) winCnt[winCnt.length] = window.open(popNode + "?url=" + url + "&parameterName=" + parameterName + "&parameterValue=" + parameterValue+"&op="+o_para+"&opv="+o_para_value, winName, winProps)
	else winCnt[winCnt.length] = window.open(popNode + "?url=" + url + "&parameterName=" + parameterName + "&parameterValue=" + parameterValue, winName, winProps)
}

function setPosCookie(){
   if (!resizeEvent) {
		if(ns4){
			leftP = document.layers.container.left
			topP = document.layers.container.top
		}else if(ie&&!dom){
			leftP = parseInt(document.all.container.style.left)
			topP = parseInt(document.all.container.style.top)
		}else if (dom){
			leftP = parseInt(document.getElementById('container').style.left)
			topP = parseInt(document.getElementById('container').style.top)
		}
		var today = new Date();
		var expires = new Date();
		expires.setTime(today.getTime() + 10000);
		setCookie('left_layer_position', leftP, expires)
		setCookie('toppos', topP, expires)
	}
}

function setCookie(name, value, expires, path, domain, secure){
	document.cookie=name + "=" + escape(value) +
	((expires) ? "; expires=" + expires.toGMTString() : "")+
	((path)? "; path=" + path : "") +
	((domain)? "; domain=" + domain : "") +
	((secure)? "; secure" : "");
}

function ns_check(){
	resizeEvent = true;

	if(ns4){
		document.container.visibility='hide'
		leftP=window.innerWidth/2-750/2
		topP=window.innerHeight/2-400/2
		setCookie('left_layer_position', leftP)
		setCookie('toppos', topP)
		setTimeout("top.location.reload()",100)
	}
	else{
		init()
	}
}
