				

/* Function getPos.     */
/* Only used internally */
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.       */
/* Used in ItemListControl.ascx */
function skjulBillede(){
	 				 document.getElementById("Billedekasse").visibility="hidden";
	 				 document.getElementById("Billedekasse").innerHTML ="";
	 				 SwitchVisibility('filterControl_ItemGroupDropDownList', 'false');
	 				 SwitchVisibility('filterControl_TimeDropDownList', 'false');
	 				 SwitchVisibility('filterLinkListControl_FilterDataList', 'false');
}

/* Function VisBillede.         */
/* Used in ItemListControl.ascx */
function VisBillede(obj,sti){
					var position = getPos(obj);
					var bk = document.getElementById("Billedekasse");
					bk.style.visibility="visible";
					bk.style.position="absolute";
					bk.style.left = position.x + "px";
					bk.style.top = CalcTopPos(position.y, obj) + "px";
					document.getElementById("Billedekasse").innerHTML= " <img src=" + sti + " class=gulboks>"
}

/* Function CalcTopPos. */
/* Only used internally */
function CalcTopPos(yPos, obj){
	var availHeight = getWindowHeight();
	var imgPopHeight = getPopupHeight(obj.height, obj.width);
	var scrollY = getScrollY();
	var sum = 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;
	}
}

/* Function getPopupHeight. */
/* Only used internally.    */
function getPopupHeight(imgHeight, imgWidth){
	var rel = imgHeight / imgWidth;
	var imgPopHeight;
	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. */
/* Only used Internally      */
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. */
/* Only used Internally */
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 SwitchVisibility. */
/* Only used Internally       */
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';
		}
		
	}
}

/* Function TextSearch.                            */
/* Used in CategoryMenuControl.ascx and internally */
function TextSearch() { 
	var searchText;
	var searchTextParsed;

	searchText = document.getElementById('SearchTextBox').value;
	searchText = encodeURI(searchText);
	searchTextParsed = searchText.replace(/&/g, '%26');
	document.location.href = 'ItemList/ItemList.Aspx?STA=3&FText=' + searchTextParsed ;
} 
   
/* Function DoEnter.                */ 
/* Used in CategoryMenuControl.ascx */     
function DoEnter(event) {
    if (event && event.keyCode == 13){
        TextSearch();
    }
    return !(event && event.keyCode == 13);
}
