function clickHandler(object, type) {
	parent.frames[1].document.location.href = type;
}

function openWindow(sUrl, sWidth, sHeight){
	window.open(sUrl,'filedialog','height=' + sHeight + ',width=' + sWidth + ',top=300,left=200,resizable=yes,scrollbars=no,status=no,toolbar=no,location=no,menubar=no');
}


function deleteAll(sUrl,sWidth, sHeight)
{
	//alert(delform.deleteallver.checked);
	if(delform.deleteallver.checked)
	{
	  openWindow(sUrl, sWidth, sHeight);			
	}


}


function submitForm(oForm){
var submitDocument = window.opener.document;
var lDelay;
var sTmp;
with(oForm){

if (formaction.value == 'deleteall')
{
	//alert("smdoc_delete_ver.asp?fileid=" + fileid.value + "&deleteall=1&version=" + version.value);
	document.location.href = "smdoc_delete_ver.asp?fileid=" + fileid.value + "&deleteall=1";
	//window.opener.parent.frames.hiddenFrame.document.location.href = "smdoc_lock.asp?sid=" + fileid.value + "&lock=0";
	lDelay=500;
	//window.opener.document.location.href = sTmp
	window.opener.setTimeout("document.location.href='/default.asp?sid=" + sid.value + "'",lDelay);
	window.close();
	return true;	
}

if (formaction.value == 'deletever')
{
	document.location.href = "smdoc_delete_ver.asp?fileid=" + fileid.value + "&version=" + version.value;
	//window.opener.parent.frames.hiddenFrame.document.location.href = "smdoc_lock.asp?sid=" + fileid.value + "&lock=0";
	lDelay=500;
	//window.opener.document.location.href = sTmp
	window.opener.setTimeout("document.location.reload(true)",lDelay);
	window.close();
	return true;	
}
else
{
for(var i=0; !formaction[i].checked;i++){
}

lDelay = 2000;
	switch(formaction[i].value){
		case("upload"):
					window.resizeTo(514,182);
					document.location.href = "smdoc_uploadframe.asp?filelist=1&newversion=1&versionfolder=" + fileid.value;
					break;
		case("lock"):
					
					document.location.href = "smdoc_lock.asp?sid=" + fileid.value + "&lock=1";
					//window.opener.parent.frames.hiddenFrame.document.location.href = "smdoc_lock.asp?sid=" + fileid.value + "&lock=1";
					lDelay=500;
					//window.opener.document.location.href = sTmp
					window.opener.setTimeout("document.location.reload(true)",lDelay);
					window.close();	
					break;
		case("unlock"):
					document.location.href = "smdoc_lock.asp?sid=" + fileid.value + "&lock=0";
					//window.opener.parent.frames.hiddenFrame.document.location.href = "smdoc_lock.asp?sid=" + fileid.value + "&lock=0";
					lDelay=500;
					//window.opener.document.location.href = sTmp
					window.opener.setTimeout("document.location.reload(true)",lDelay);
					window.close();	
					break;

		case("download"):
					window.open("smdoc_download.asp?sid=" + fileid.value + "&activever=1&lock=0");
					window.close();	
					break;
		case("downloadlock"):
					window.open("smdoc_download.asp?sid=" + fileid.value + "&activever=1&lock=1");
					window.opener.setTimeout("document.location.reload(true)",lDelay);
					window.close();	
					break;
		case("fileproperties"):
					submitDocument.location.href = "/default.asp?fileid=" + fileid.value + "&sid=" + sid.value + "&action=fileproperties&versionfolder=" + parentsid.value;
					//window.opener.parent.frames.inputFrame.document.location.href = "blank.asp";
					window.close();	
					break;
		case("delete"):
					submitDocument.location.href = "/default.asp?fileid=" + fileid.value + "&sid=" + sid.value + "&action=fileproperties&delete=1&versionfolder=" + parentsid.value;
					//window.opener.parent.frames.inputFrame.document.location.href = "blank.asp";
					window.close();	
					break;




	}	

return(false);
}
}
}

function lib_bwcheck(){
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.opera5=this.agent.indexOf("Opera 5")>-1
	this.opera6=this.agent.indexOf("Opera 6")>-1
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6
	this.mac=this.agent.indexOf("Mac")>-1
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
	return this
}
var bw=new lib_bwcheck()

function calcPosition(){
	if (bw.ns4 || bw.ns6) {
		doc_width = self.innerWidth;
	} 
	else if (bw.ie4 || bw.ie5 || bw.ie6) {
		doc_width = document.body.clientWidth;
	}
	var pos = (doc_width/2) - 375;
	if(bw.ie4 || bw.ie5 || bw.ie6 || bw.opera5 || bw.opera6){
		document.all.submenu1.style.left = pos + 160;
		document.all.submenu2.style.left = pos + 278;
		document.all.submenu3.style.left = pos + 396;
		document.all.submenu4.style.left = pos + 514;
		document.all.submenu5.style.left = pos + 632;
	}
	if (bw.ns6){
		document.getElementById("submenu1").style.left = pos + 160;
		document.getElementById("submenu2").style.left = pos + 278;
		document.getElementById("submenu3").style.left = pos + 396;
		document.getElementById("submenu4").style.left = pos + 514;
		document.getElementById("submenu5").style.left = pos + 632;
	}
		
	if(bw.ns4){
		document.layers[0].left = pos + document.layers[0].left;
		document.layers[0].top = document.layers[0].top - 7;
		document.layers[1].left = pos + document.layers[1].left;
		document.layers[1].top = document.layers[1].top - 7;
		document.layers[2].left = pos + document.layers[2].left;
		document.layers[2].top = document.layers[2].top - 7;
		document.layers[3].left = pos + document.layers[3].left;
		document.layers[3].top = document.layers[3].top - 7;
		document.layers[4].left = pos + document.layers[4].left;
		document.layers[4].top = document.layers[4].top - 7;
	}
}

function objects(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=objects(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}
// vars for layers
var openLayer= new Array();
openLayer[0] = "0";
subLayer = "";
var timer;
var mousePosition;
function controlLayers() {
  var i,p,v,obj,args=controlLayers.arguments;
if(openLayer[0] != 0 && args[1] == ""){
	recursiveClose();
	}
  openLayer[0] = args[0];
  
  if (objects(openLayer[0]) != null){ // finns objektet
	if(bw.ie4 || bw.ie5 || bw.ie6 || bw.opera5 || bw.opera6)
		document.all[openLayer[0]].style.left = mousePosition-25;
	if (bw.ns6)
		document.getElementById(openLayer[0]).style.left = mousePosition-25;
  }
	
	
  for (i=0; i<(args.length-2); i+=3) if ((obj=objects(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}
function closeLayer() {
  var i,p,v,obj,args=closeLayer.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=objects(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}
function recursiveClose(){ //om man använder flera nivåer, vilket vi inte gör
	for(i=0; i< openLayer.length; i++){
		if(openLayer[i] != null)
		 closeLayer(openLayer[i],'','hide');
	}
}
function countdown(){
timer = setTimeout("recursiveClose()", 1000);
}
function clearTheTimer(){
	clearTimeout(timer);
}

//Scroll functions ###################################################################################################################
var timer;
var speed;

function makeObj(obj,nest){
    nest=(!nest) ? "":'document.'+nest+'.'
	this.el=bw.dom?document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval(nest+'document.'+obj):0;
  	this.css=bw.dom?document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?eval(nest+'document.'+obj):0;
	this.scrollHeight=bw.ns4?this.css.document.height:this.el.offsetHeight
	this.clipHeight=bw.ns4?this.css.clip.height:this.el.offsetHeight
	this.up=goUp;this.down=goDown;
	this.moveIt=moveIt; this.x=0; this.y=0;
    this.obj = obj + "Object"
    eval(this.obj + "=this")
    return this
}

// A unit of measure that will be added when setting the position of a layer.
var px = bw.ns4||window.opera?"":"px";

function moveIt(x,y){
	this.x = x
	this.y = y
	this.css.left = this.x+px
	this.css.top = this.y+px
}

//Makes the object go up
function goDown(move){
	if (this.y>-this.scrollHeight+oCont.clipHeight){
		this.moveIt(0,this.y-move)
			if (loop) setTimeout(this.obj+".down("+move+")",speed)
	}
}

//Makes the object go down
function goUp(move){
	if (this.y<0){
		this.moveIt(0,this.y-move)
		if (loop) setTimeout(this.obj+".up("+move+")",speed)
	}
}

//Calls the scrolling functions. Also checks whether the page is loaded or not.
function scroll(speed){
	if (scrolltextLoaded){
		loop = true;
		if (speed>0) oScroll.down(speed)
		else oScroll.up(speed)
	}
}

//Stops the scrolling (called on mouseout)
function noScroll(){
	loop = false
	if (timer) clearTimeout(timer)
}

//Makes the object
var scrolltextLoaded = false
function scrolltextInit(){
	oCont = new makeObj('news')
	oScroll = new makeObj('newsText','news')
	oScroll.moveIt(0,0)
	oCont.css.visibility = "visible"
	scrolltextLoaded = true
	
}

//Start scrolling after stopped (called on mouseout)
function newScroll(speed){
	loop = false
	if (timer) clearTimeout(timer)
}


//Misc. functions ###################################################################################################################

function openWin(url, name,spec){
window.open(url, name, spec)
}

function printNews(){
	window.print();
	window.close();
}

function language(id){
document.images["language"].src= "images/system/language" + id + ".gif";
}
function mPos(position){
mousePosition = position;
}
function movemenu(){
	mPos(event.clientX);
	if (objects(openLayer[0]) != null){ // finns objektet
	if(bw.ie4 || bw.ie5 || bw.ie6 || bw.opera5 || bw.opera6)
		document.all[openLayer[0]].style.left = mousePosition-25;
	if (bw.ns6)
		document.getElementById(openLayer[0]).style.left = mousePosition-25;
  }
}


function fnSetActive(newActiveObject){
	with(document){
		if(typeof(activeImg) != "undefined"){
			document.images[activeImg].src=document.images[activeImg].src.replace(/\-active\./,".");
			activeImg = undefined;
		}
	}

	if(typeof(currentActiveObject) != "undefined"){
		currentActiveObject.className = currentActiveObject.className.replace(/\-active/,"");
	}
	else{
		var re;
		re = /\-active/;
		for(lCount = 0; lCount<document.all.length; lCount++){
			if(re.test(document.all[lCount].className)){
				currentActiveObject = document.all[lCount];
				currentActiveObject.className = currentActiveObject.className.replace(/\-active/,"");
				break;
			}
		}
	}


	newActiveObject.className = newActiveObject.className.replace(/\-active/,"") + "-active";					
	currentActiveObject = newActiveObject;
}

var activeImg;

function fnActivateImg(imgName, stable){
	with(document.images[imgName]){		
		if(!/\-active\./.test(src)){
			src=src.replace(/\.gif/,"-active.gif");
		}
		
		if(stable && activeImg != imgName){
			if(typeof(document.images[activeImg]) != "undefined") document.images[activeImg].src = document.images[activeImg].src.replace(/\-active\./,".");
			
			activeImg = imgName;
			if(typeof(document.currentActiveObject) != "undefined"){
				document.currentActiveObject.className=document.currentActiveObject.className.replace(/\-active/,"");
			}
			else{
				with(document){
				var re;
				re = /\-active/;
				for(lCount = 0; lCount<document.all.length; lCount++){
					if(re.test(document.all[lCount].className)){
						currentActiveObject = document.all[lCount];
						currentActiveObject.className = currentActiveObject.className.replace(/\-active/,"");
						break;
					}
				}
				}
			}
		}
	}	
}

function fnDeactivateImg(imgName){
	with(document.images[imgName]){
		if(/\-active\./.test(src) && activeImg != imgName){
			src=src.replace(/\-active\./,".");
		}
	}	
}
