/*
	check browser
*/
IE55 = (navigator.userAgent.indexOf("MSIE 5.5") != -1) ? true : false;
IE6 = (navigator.userAgent.indexOf("MSIE 6.0") != -1) ? true : false;
SAFARI = (navigator.userAgent.indexOf("Safari") != -1) ? true : false;
NS6 = (navigator.userAgent.indexOf("Netscape6") != -1) ? true : false;

/*
	Control the bottom background-color
*/
function expandableChange(elm){
	var cn = elm.parentNode.parentNode.childNodes;
	closeArticles(elm);
	//closeSections(elm);

	for(var i=0; i < cn.length; i++){
		var child = cn[i];
	
		if(child.nodeType == 1){
			if(child.className == "expandableContent"){
				if(child.style.display == "none" && child != document["opened"]){
					child.style.display = "block";
					document["opened"] = child;
					elm.parentNode.parentNode.className += " expandableItemOpen";
				}else{
					child.style.display = "none";
					document["opened"] = null;
					elm.parentNode.parentNode.className = "expandableItem";
				}
			}
		}
	}
	initLayers();
}
			
function closeArticles(newelm){
	var rootNode = newelm.parentNode;
	while(rootNode.className != 'expandablePanel')
		rootNode = rootNode.parentNode;
	closeArticlesRek(rootNode);
}
function closeArticlesRek(elm){
		if(elm.className == "expandableItem expandableItemOpen"){
			elm.className = "expandableItem";
			var x = elm.childNodes;
			for(var y = 0; y < x.length; y++){
				if(x[y].className == "expandableContent")
					x[y].style.display = "none";
			}
		}
		var cn = elm.childNodes;
		for(var i = 0; i < cn.length; i++){
			try{
				if(cn[i].nodeType == 1){
					if(cn[i].nodeName == "DIV"){
						closeArticlesRek(cn[i]);
						}
				}
			}catch(e){}
		}
}

function expandableSectionChange(elm){
	//closeArticles(elm);
	closeSections(elm);
	
	
	var cn = elm.parentNode.parentNode.childNodes;
	
	for(var i=0; i < cn.length; i++){
		var child = cn[i];
		if(child.nodeType == 1){
			if(child.className == "expandableSectionContent"){
				if(child.style.display == "none" && child != document["opened"]){
					child.style.display = "block";
					document["opened"] = child;
					elm.parentNode.parentNode.className += " expandableSectionItemOpen";
				}
				else{
					
					child.style.display = "none";
					document["opened"] = null;
					elm.parentNode.parentNode.className = "expandableSectionItem";
				}
			}
		}
	}
	initLayers();
}


function closeSections(newelm){
	var rootNode = newelm.parentNode;	
	var thisSection;
	
	while(rootNode.className != 'expandablePanel'){
		rootNode = rootNode.parentNode;
		if(thisSection == null && rootNode.className == 'expandableSectionItem'){
			thisSection = rootNode;
		}
	}
	closeSectionsRek(rootNode, thisSection);
}
function closeSectionsRek(elm, thisSection){
		var current = elm;
		var closeSection = true;
		//alert("this: " + thisSection.id + " current: " + current.id );
		//alert("current: " + current.className);
		
		while(current.className != 'expandablePanel'){
			if(current === thisSection){
				closeSection = false;
				//alert(current.id);
			}
			current = current.parentNode;
			
		}
		
		//if(elm.className.indexOf('Section') > 0)
		//	alert(elm.className.indexOf('Section') + " " + elm.className);
		if(closeSection){	
			if(elm.className == "expandableSectionItem expandableSectionItemOpen"){
				elm.className = "expandableSectionItem";
				var x = elm.childNodes;
				for(var y = 0; y < x.length; y++){
					if(x[y].className == "expandableSectionContent")
						x[y].style.display = "none";
				}
			}
		}
		var cn = elm.childNodes;
		for(var i = 0; i < cn.length; i++){
			
			try{
				if(cn[i].nodeType == 1){
					if(cn[i].nodeName == "DIV"){
						closeSectionsRek(cn[i], thisSection);
						}
				}
			}catch(e){}
		}
}

function videoPopup(path, text){
		var firstwin = window.open("/video/mediaplayer/realdaniavideo.html?text=" + text + "&path=" + path ,'', "top="+((screen.height/2)-(390/2))+",left="+((screen.width/2)-(435/2))+",channelmode=no, resizable=no,height=452,width=433,status=1,toolbar=0,menubar=0,location=0");
	}
function initLayers() {
	defHeight = 0;
	document.getElementById("gx").innerHTML = "";
	
	if (SAFARI) {
		cH = 10;
		defHeight = document.body.scrollHeight;
	} else if (NS6) {
		cH = window.innerHeight;
		defHeight = document.documentElement.offsetHeight;
	} else if (IE55 || IE6) {
		cH = (IE55) ? document.body.clientHeight : document.documentElement.clientHeight;
		defHeight = ieScrollHeight();
	} else {
		cH = document.documentElement.clientHeight;
		if (defHeight == 0) {
			defHeight = document.documentElement.scrollHeight;
		}
	}
	sH = defHeight+20;
	h = (cH > sH) ? cH : sH;
	document.getElementById("gx").innerHTML = '<img src="/img/dot_tr.gif" width="1" height="'+(h-100)+'">';

	if (IE55 || IE6) {
		browserWidth = document.body.clientWidth;
	} else {
		browserWidth = document.documentElement.offsetWidth;
	}
	pos = (browserWidth-920)/2;
	pos = (pos<0) ? 0 : pos;
	document.getElementById("content").style.left = pos+"px";
}

// get scrollheight by checking top-position + height on all layers
function ieScrollHeight() {
	maxH = 0;
	d = document.getElementsByTagName('DIV');
	for (t=0; t<d.length; t++) {
		curH = 0;
		curLay = d[t];
		curH = d[t].offsetHeight;

		while (curLay.offsetParent) {
			curH += curLay.offsetTop;
			curLay = curLay.offsetParent;
		}
		maxH = (maxH > curH) ? maxH : curH;
	}
	return maxH;
}


/*
	Adjusting height and width for IE5.5, by adding paddings and borders.
*/

function IE55Fix() {
	if (IE55)	{		
		
		d = document.getElementsByTagName('DIV');
		for (var i=0;i<d.length;i++) {
			var paddingLeft = parseInt(d[i].currentStyle.paddingLeft);		
			if(!paddingLeft)
				paddingLeft = 0;
								
			var paddingRight = parseInt(d[i].currentStyle.paddingRight);	
			if(!paddingRight)
				paddingRight = 0;	
						
			var borderLeftWidth = parseInt(d[i].currentStyle.borderLeftWidth);	
			if(!borderLeftWidth)
				borderLeftWidth = 0;	
							
			var borderRightWidth = parseInt(d[i].currentStyle.borderRightWidth);	
			if(!borderRightWidth)
				borderRightWidth = 0;	
				
			var width = parseInt(d[i].currentStyle.width);
			width = width + paddingLeft + paddingRight + borderLeftWidth + borderRightWidth;
			
			if(width)
				d[i].style.width = width+"px";
				
				
			var paddingTop = parseInt(d[i].currentStyle.paddingTop);	
			if(!paddingTop)
				paddingTop = 0;	
								
			var paddingBottom = parseInt(d[i].currentStyle.paddingBottom);	
			if(!paddingBottom)
				paddingBottom = 0;	
							
			var borderTopWidth = parseInt(d[i].currentStyle.borderTopWidth);	
			if(!borderTopWidth)
				borderTopWidth = 0;	
							
			var borderBottomWidth = parseInt(d[i].currentStyle.borderBottomWidth);	
			if(!borderBottomWidth)
				borderBottomWidth = 0;	
				
			var height = parseInt(d[i].currentStyle.height);
			height = height + paddingTop + paddingBottom + borderTopWidth + borderBottomWidth;
			if(height)
				d[i].style.height = height+"px";
		}
	
	}	
}


/*
	MouseOver help-boxes functions
*/

function qOver(what) {
	document.getElementById(what).src = q_over.src;
}
function qOut(what) {
	document.getElementById(what).src = q_out.src;
}
function showInfo(what) {
	document.getElementById(what).style.display = "block";
}
function hideInfo(what) {
	document.getElementById(what).style.display = "none";
}
function preloadHelpIcons() {
	q_over = new Image(); q_over.src = "/img/bn_help_over.gif";
	q_out = new Image(); q_out.src = "/img/bn_help_out.gif";
}

function clearField(origin, field) {
	if(origin == field.value)
		field.value = '';
}

/*
	New window pop-up function
*/

function popUp(url,nam,w,h,extra) {		
	str='height='+h+',width='+w+','+extra;
	if(parseInt(navigator.appVersion)>3)
		str+=',left='+(screen.width -w)/2+',top='+parseInt((screen.height -h)/3);	
	win=window.open(url,nam,str);
}
function flashPopUp(url,w,h) {		
	str='height='+h+',width='+w;
	if(parseInt(navigator.appVersion)>3)
		str+=',left='+(screen.width -w)/2+',top='+parseInt((screen.height -h)/3);	
	win=window.open(url,'flashPopup',str);
}

/*
	DHTML pop-up errorbox function
*/

function showError(headline,text) {
		document.getElementById("errorHeadline").innerHTML = headline;
		document.getElementById("errorText").innerHTML = text;
		scroll(0,0);
		document.getElementById("errorWrapper").style.visibility = "visible";
}

/*
	imageWrapper functions
*/
function showImage(what,closeIcon,copyright,hd,txt) {
	document.getElementById("imageHolder").innerHTML = '';
	if (IE55 || IE6 || SAFARI) {
		yPos = (IE55 || SAFARI) ? document.body.scrollTop : document.documentElement.scrollTop;
	} else if (NS6) {
		yPos = window.pageYOffset;
	} else {
		yPos = document.documentElement.scrollTop;
	}

	if (hd != "" && hd != null) { hd = "<b>"+hd+"</b>"; } else { hd = "" };
	if (txt != "" && txt != null) { txt = "<br>"+txt; } else { txt = "" };
	ySpace = 100;
	if (yPos > 100) { ySpace = 60; }
	
	var imgWrap = document.getElementById("imageWrapper");
	var imgHolder = document.getElementById("imageHolder");
	
	imgHolder.innerHTML = "<table width='1' cellpadding='19' cellspacing='0' border='0' bgcolor='#FFFFFF' style='border:solid;border-width:1px;border-color:#666666;'>\
															<tr>\
																<td align='right'>\
																	<a href='javascript:closeIt()'>\
																		<img src='"+ closeIcon +"' border='0'></a><br>\
																	<a href='javascript:closeIt()'>\
																		<img src='"+ what +"' border='0'></a>\
																	<div align='right'>"+ copyright +"<br></div>\
																	<div align='left'>"+ hd + txt +"</div>\
																</td>\
															</tr>\
														</table>";
																	
	imgWrap.style.visibility = "visible";
	imgWrap.style.display = "block";
	imgWrap.style.top = (ySpace+yPos)+"px";
	imgWrap.style.left = "40px";
	//initLayers();
	//setTimeout("initLayers();",500);
	
	
}
function closeIt() {
	document.getElementById("imageWrapper").style.visibility = "hidden";
	document.getElementById("imageWrapper").style.display = "none";
	initLayers();
}
function paneOver(what) {
	document.getElementById(what).src = eval(what+"_over.src");
}
function paneOut(what) {
	document.getElementById(what).src = eval(what+"_out.src");
}


/*
	what to do on load
*/
function init() {
	IE55Fix();
	initLayers();
	document.getElementById("content").style.visibility = "visible";
	if (document.getElementById('leftMenu') != null)
		document.getElementById("leftMenu").style.visibility = "visible";	
	
	window.onresize = initLayers;
	if (typeof(init2) != "undefined") {
		init2();
	}
	checkBoxSize();
}

// make content-area minimum-height
function checkBoxSize() {
	if (document.getElementById("tekstBoxSizer")) {
		if (parseInt(document.getElementById("tekstBoxSizer").offsetHeight) < 300) {
			document.getElementById("tekstBoxSizer").style.height = "300px";
		}
	}
}

function printPage() {
	popUp('/extranet/print.html','',480,550,'scrollbars=1');
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}