﻿function GotoPrimaryLayout() {
  var s=location.href;
  s=s.split ("?") [0]+"?"+s.split ("&") [1];
  location.href=s;
}

function ShowScrewsByGroupCategory(PageId,FilterId,Caption) {
  document.cookie='screwcaption='+Caption;
  location.href='/page'+PageId+'.aspx?check1='+FilterId;
}

function AddTargetToLinks()
{
var links = document.getElementsByTagName("a");

 for(var i = 0;i<links.length;i++)
 {
   if(links[i].className.toLowerCase() != "pageposition") links[i].target = "_top";
 }
}


function TipAFriend(pageid,formpageid){

	page_url = escape (window.location.toString());
	page_title = escape (window.document.title);
	window.location.href = "page" + formpageid + ".aspx?page_title="+page_title+"&page_url="+page_url;

}






function bytes2human(bytesize){   
		
		var returnString = "0 Kb";
		
		// Tester om bytesize er 0, ellers er det ligefedt
	  if (bytesize == 0){return returnString;}


	  // Hvis bytesize er kortere end 4 tal, må formatet være bytes
	  if (bytesize < 1000){	 
	  	returnString = bytesize + " bytes";   
	  }
		    // Bytesize er altså længere end 3 tal, men hvis den er
		    // kortere end 7 tal, må formatet være kilobytes
		    else if (bytesize < 1000000){
					var kbsize = bytesize/1024;
					kbsize = parseInt(kbsize);//Ikke ønsker at have komma-tal i kb
					//kbsize = parseInt((kbsize * 10) + 0.5) / 10;
					returnString = kbsize + " Kb";
		    }
				 
				// Bytesize er altså længere end 5 tal, men hvis den er
				// kortere end 10 tal, må formatet være megabytes
				else if (bytesize < 1000000000){
							var mbsize = (bytesize/1024)/1024;
							mbsize = parseInt((mbsize * 10) + 0.5) / 10;
							returnString = mbsize + " Mb";
				}
				// Bytesize er altså længere end 9 tal, men hvis den er
				// kortere end 13 tal, må formatet være gigabytes
					  else if (bytesize < 100000000000){
									var gbsize = ((bytesize/1024)/1024)/1024;
									gbsize = parseInt((gbsize * 10) + 0.5) / 10;
									returnString = gbsize + " Gb";
					  }
					  // Bytesize er altså længere end 12 tal, men hvis den er
					  // kortere end 16 tal, må formatet være terabytes
						    else if (bytesize < 1000000000000000){
											var tbsize = (((bytesize/1024)/1024)/1024)/1024;
											tbsize = parseInt((tbsize * 10) + 0.5) / 10;
											returnString = tbsize + " Tb";
						    }
		    
	  //Returnerer værdi og målenhed som sat i den rigtige return variabel
	  return (returnString);
}






/*----- JS for rolo-img -----*/
function getPos(elm) {
    for(var zx=zy=0;elm!=null;zx+=elm.offsetLeft,zy+=elm.offsetTop,elm=elm.offsetParent);
    return {x:zx,y:zy}
	}
function skjulBillede(){
	document.getElementById("imgbox").visibility="hidden";
	document.getElementById("imgbox").innerHTML ="";
	SwitchVisibility('filterControl_itemGroupDropDownList', 'false');
	SwitchVisibility('filterControl_timeDropDownList', 'false');
	SwitchVisibility('filterLinkListControl_filterDataList', 'false');
}
function VisBillede(obj,sti,myWidth,myHeight){
	var position = getPos(obj);
	var ib = document.getElementById("imgbox");
	ib.style.visibility="visible";
	ib.style.position="absolute";
	ib.style.left = position.x + "px";
	ib.style.top = CalcTopPos(position.y, obj, myWidth, myHeight) + "px";
	ib.innerHTML= " <img src=" + sti + " class='roloimg' width='"+myWidth+"' height='"+myHeight+"' />";
}
function CalcTopPos(yPos, obj, myWidth, myHeight){
	var availHeight = getWindowHeight();
	//var imgPopHeight = getPopupHeight(obj.height, obj.width, myWidth);
	var imgPopHeight = myHeight;
	var scrollY = getScrollY();
	var sum = yPos + obj.height + imgPopHeight - scrollY;
	//alert('yPos + obj.height + imgPopHeight - scrollY\n'+ yPos +' '+ obj.height +' '+ imgPopHeight +' '+ scrollY);
	if (sum > availHeight) {
		//hide filterboxes if popup image covers them 
		if (document.getElementById('filterControl_itemGroupDropDownList') != null) {
			var filterBox = document.getElementById('filterControl_itemGroupDropDownList');
			var posFilterBox = getPos(filterBox);
			if ((yPos - imgPopHeight) < posFilterBox.y) {
				SwitchVisibility('filterControl_itemGroupDropDownList', 'true');
				SwitchVisibility('filterControl_timeDropDownList', 'true');
			}
		}
		return yPos - imgPopHeight;
	}
	else {
		//hide myLists if they are visible and lowest popup image covers it
		if (document.getElementById('filterLinkListControl_filterDataList') != null) {
			var myListBox = document.getElementById('filterLinkListControl_filterDataList');
			var posMyListBox = getPos(myListBox);
			if ((yPos + obj.height + imgPopHeight) > posMyListBox.y) {
				SwitchVisibility('filterLinkListControl_filterDataList', 'true');
			}
		}
		return yPos + obj.height;//136 GKW!!
	}
}
function getPopupHeight(imgHeight, imgWidth, myMaxBottleneck){
	var rel = imgHeight / imgWidth;
	var imgPopHeight;
	
	var imgPopWidth;
	if(imgWidth > imgHeight){
		imgPopWidth = myMaxBottleneck;
		imgPopHeight = (imgPopWidth / imgWidth)*imgHeight;
	}else{
		imgPopHeight = myMaxBottleneck;
		imgPopWidth = (imgPopHeight / imgHeight)*imgWidth;
	}
	/*
	if (imgWidth == 60) {
		imgPopHeight = rel * 160;
	}
	else if (imgWidth == 160) {
		imgPopHeight = rel * 300;
	}
	else {
		//do nothing as its an illegal height
		imgPopHeight = 0;
	}
	*/
	return imgPopHeight;
}
function getWindowHeight() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} 
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} 
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	return myHeight;
}
function getScrollY() {
	var scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
	} 
	else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
	}
	else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
	    //IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
	}
	return scrOfY;
}
function isObject(a) {
    return (a && typeof a == 'object') || isFunction(a);
}
function SwitchVisibility(element, hide) {
	if (document.getElementById(element) != null) {
		if (hide == 'true') {
			document.getElementById(element).style.visibility = 'hidden';
		}
		else {
			document.getElementById(element).style.visibility = 'visible';
		}
		
	}
}
/*-----\JS for rolo-img\-----*/




function openClose( el , opener ){
	
	opener = opener || false;//default value for open-indicator
	
	if( opener )
		var open_obj = document.getElementById(opener);
	
	var obj = document.getElementById(el);
	
	if( !obj ) return;
	
	if( obj.style.display == 'none' ){
		obj.style.display = 'block';
		if( opener )
			open_obj.innerHTML = '-'
	}else{
		obj.style.display = 'none';
		if( opener )
			open_obj.innerHTML = '+'
	}
		
}






function getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return pair[1];
		}
	}
	return false;
}