/*
		Javascriptsfunctions
		Version: 20000107
		Author:	 Jimmy Herdberg, Spinecom AB
		
		Reference:
			Netscape Javascript 1.2:		http://developer.netscape.com/docs/manuals/communicator/jsref/index.htm
			Microsoft Jscript Reference:	http://help.activeserverpages.com/iishelp/JScript/htm/JStoc.htm
			W3C HTML 4.0 Specification:		http://www.w3.org/TR/REC-html40/
*/


// Browsercheck
ns			= (navigator.appName == "Netscape")
ie  		= !ns
pc			= (navigator.platform.indexOf("Win")!=-1) ? true : false
mac			= !pc
version = parseFloat(navigator.appVersion)


function openWin(url, width, height) {
	newWin=window.open(url,'', 'menubar=no,resizable=no,width=' + width + ',height=' + height + ',titlebar=no,alwaysRaised=yes,status=no,scrollbars=no,left='+(screen.width/2-width/2)+',top='+(screen.height/2-height/2-height/10)+',screenX=0,screenY=0');
	return newWin
}

function openScrollWin(url, width, height) {
	newWin=window.open(url,'', 'menubar=no,resizable=no,width=' + width + ',height=' + height + ',titlebar=no,alwaysRaised=yes,status=no,scrollbars=yes,left='+(screen.width/2-width/2)+',top='+(screen.height/2-height/2-height/10)+',screenX=0,screenY=0');
	return newWin
}

function popup(txt,action) {
 openWin("_inc/popup.asp?txt=" + escape(txt) + "&action=" + escape(action), 375,400)
}

function resizeFix() { if (ns && version>=4.1) top.location.reload() }

function dropFocus(obj) { if (ie) obj.blur(); }


/* Check a form
   Put following into the form tag.
	 onSubmit="return checkForm(this,'Fyll i formuläret fullständigt tack.');"
*/
function checkForm(obj, errorMessage) {
 for (i=0; i<obj.length; i++) { 
  if (obj[i].value=="" && obj[i].type!="submit") { alert(errorMessage); obj[i].focus(); return false }
 }
 return true
}


/* Cookiefunctions
   use: getCookie("name");
   use: setCookie("name", "value", daysBeforeExpire);
*/

function getCookie(name) { 
  obj=document.cookie
	if ( obj.indexOf(name + "=")==-1   ) { return false	}	else { strFrom = obj.indexOf(name + "=") + name.length + 1 }
  if ( obj.indexOf(";", strFrom)==-1 ) { strTo=obj.length; } else { strTo   = obj.indexOf(";", strFrom) }
	return unescape( obj.substring(strFrom, strTo) );
}

function setCookie(name,value,days) { 
	expire=1000 * 60 * 60 * 24 * ((days!=null)?days:365)
	datum = new Date ();
	datum.setTime(datum.getTime() + expire);
	document.cookie = name + '=' + escape(value) + ';expires=' + datum.toGMTString();
}


function showLayer(lager){
	if(ns) document.layers[lager].visibility = 'show'
	else document.all.item(lager).style.visibility = 'visible'
}
   
function hideLayer(lager){
	if(ns) document.layers[lager].visibility = 'hide'
	else document.all.item(lager).style.visibility = 'hidden'
}

 	
// Ser till att objekt tolkas samma i  N & e
function obj(objectName) {
	if (ns) { object=eval("window.document." + objectName) } else { object=eval(objectName + ".style")	}
	return object
}

// *** Image object
function oImage(imgName, normalSrc, overSrc, onSrc, url, layerName, offSrc, overOffSrc) {
	this.imageName = imgName
	this.toId

	this.normal = new Image(); this.normal.src=normalSrc
	this.over = new Image(); this.over.src=overSrc
	this.on = new Image(); this.on.src=onSrc
	this.normalOff = new Image(); this.normalOff.src=offSrc
	this.onOff = this.normalOff
  this.overOff = new Image(); this.overOff.src=overOffSrc
	this.flip=flip
	this.state=true

	this.layerName=layerName
	this.url=url
	this.go=go
}

// Change Image
function flip(state){
 if (state=='switch') { this.state=!this.state; state="on" }
 if (state==true)   { this.state=true ; state="on" }
 if (state==false)  { this.state=false; state="on" }
 if (!this.state) state=state + "Off"
 if (this.layerName) {
  if (ns) eval("document."+ this.layerName + ".document.images['" + this.imageName + "'].src=this." + state + ".src")
  else eval(this.imageName + ".src=this." + state + ".src")
 } else {
  eval("document.images['" + this.imageName + "'].src=this." + state + ".src")
 }
}

// Go to URL	
function go() {
 if (this.url.length) parent.main.location.href=this.url
}

function goTo(currentPage) {
 if (currentPage!=0) location.href="main.asp?current=" + currentPage
}


function mov(objectName, x, y) { // cObj = currentObject, cLay = currentLayer
	cObj=eval(objectName); cLay=obj(cObj.layerName)
	cTop=(ns) ? cLay.top : cLay.pixelTop;	cLeft=(ns) ? cLay.left : cLay.pixelLeft
	
	for (i=0; i<cObj.speed; i++) {
	 if (cTop!=y) { cTop = (cTop>y) ? cTop-1 : cTop+1 }
	 if (cLeft!=x) { cLeft = (cLeft>x) ? cLeft-1 : cLeft+1 }
	}
	
	if (ns) { cLay.top = cTop; cLay.left = cLeft  } else { cLay.pixelTop = cTop; cLay.pixelLeft = cLeft }
		
	if (cTop!=y || cLeft!=x) {
	clearTimeout(cObj.toId)
	cObj.toId=setTimeout("mov('" + objectName + "'," + x + "," + y +")",1)
 	}
}

