﻿var DHTML = (document.getElementById || document.all || document.layers);
var w3c=(document.getElementById)? true: false;
var ie5=(navigator.appName=="Microsoft Internet Explorer")? true : false;
var ns6=(navigator.appName=="Netscape")? true: false;
var ope=(navigator.appName=="Opera")? true: false;
var objBackpanel, objLista;
var pocitadlo=0;

function Resolution(){ //zjistí rozlišení mapy IMG podle vel. okna
//	if (document.getElementById("full").value!='true') return document.getElementById("mapsize").value; //+fce 
//alert('objFull.value:'+objFull.value+"\n!objFull.value:"+(!objFull.value)+"\nobjFull.value=='false':"+(objFull.value=='false')+"\nobjFull.value==false:"+(objFull.value==false));
	if (typeof(objFull.value)!="undefined"){
		if (objFull.value!="true"){
			if (typeof(objMapsize.value)!="undefined") return objMapsize.value;
			else if(typeof(document.getElementById("mapsize").value)!="undefined") return document.getElementById("mapsize").value; //+fce 
		}
	}else if (typeof(document.getElementById("full").value)!="undefined"&&document.getElementById("full").value!="true"){
		if(typeof(document.getElementById("mapsize").value)!="undefined") return document.getElementById("mapsize").value; //+fce 
		else return "640 480";
	}
	var resX, resY;
	objBackpanel=document.getElementById("backpanel");	//+inicializace v map.js
	objLista=document.getElementById("lista");			//+inicializace v map.js
//	alert("objBackpanel.currentStyle.width:"+objBackpanel.currentStyle.width);	
	if(!objModul&&typeof(document.getElementById("modul").value)!="undefined"){
		var objModul=new Object();
		objModul.value=document.getElementById("modul").value;
	}
	if (ie5){ //IE počítá aktivní plochu se scrollbarem
		if (objModul&&objModul.value.toLowerCase()=="true"){
			resX=(document.body.offsetWidth-40-20-2);
			resY=(document.body.offsetHeight-85);
		}else{
			resX=(document.body.offsetWidth-parseInt(objBackpanel.currentStyle.width)-offsetX-20); //-1
			resY=(document.body.offsetHeight-parseInt(objLista.currentStyle.height)-offsetY);
		}
	}else if (ns6){
		if (objModul&&objModul.value.toLowerCase()=="true"){
			resX=(document.body.clientWidth-40-4);
			resY=(document.body.clientHeight-85);
		}else{
			resX=document.body.clientWidth-parseInt(document.defaultView.getComputedStyle(objBackpanel, '').getPropertyValue("width"))-offsetX; 
			resY=document.body.clientHeight-parseInt(document.defaultView.getComputedStyle(objLista, '').getPropertyValue("height"))-offsetY;
		}
	}else{ //Opera
		if (objModul&&objModul.value.toLowerCase()=="true"){
			resX=(document.body.clientWidth-40-2);
			resY=(document.body.clientHeight-85);
		}else{
			resX=document.body.clientWidth-parseInt(document.defaultView.getComputedStyle(objBackpanel, '').getPropertyValue("width"))-offsetX-20;
			resY=document.body.clientHeight-parseInt(document.defaultView.getComputedStyle(objLista, '').getPropertyValue("height"))-offsetY-20;
		}
	}
	if (typeof(imgWidth)!="undefined"&&typeof(imgHeight)!="undefined")
	if (Math.abs(resX-imgWidth)<3&&Math.abs(resY-imgHeight)<3){ //kdyz je zmena mensi nez 3px
		resX=imgWidth;
		resY=imgHeight;
	}else{
		if(resX<imgWidth&&ns6) resX+=15;
		if(resY<imgHeight&&ns6) resY+=15;
	}
	
	if (!resX||!resY||typeof(resX)=="undefined"||typeof(resY)=="undefined"||resX<160||resY<120){ //ošetrení chybových hodnot
		resX=160;
		resY=Relation(resX,null);
		document.getElementById('full').value=false;
		alert("Hodnota imgsize je příliš malá.\n Bude zvětšena na "+ resX +"x"+resY+" pixelů a vypnuta fce FullWindow.");
	} else if (resX>3200||resY>2400){
		reX=3200;
		resY=Relation(resX,null);
		document.getElementById('full').value=false;
		alert("Hodnota imgsize je příliš velká.\n Bude omezena na "+ resX +"x"+resY+" pixelů a vypnuta fce FullWindow.");
	}
	//alert(document.body.offsetWidth+" x "+document.body.offsetHeight+"\n Moz:"+document.body.clientWidth+" x "+document.body.clientHeight); 
	/*relation=(resY/resX); //rozlišení v poměru 3:4
	  if (relation>0.75){ 
		resY=resX*3/4;
	  }else{
		resX=resY*4/3;
	  }*/
	  /*pocitadlo=pocitadlo+1;
	  alert(resX+" "+resY+" "+pocitadlo);*/
	///outcome=((document.body.offsetWidth-parseInt(document.styleSheets[0].rules[2].style.width)-parseInt(document.styleSheets[0].rules[4].style.width)+offsetX)+" "+(document.body.offsetHeight-parseInt(document.styleSheets[0].rules[1].style.height)-parseInt(document.styleSheets[0].rules[7].style.height)+offsetY));
	//alert((document.body.offsetWidth-parseInt(document.styleSheets[0].rules[2].style.width)-parseInt(document.styleSheets[0].rules[4].style.width))+" "+(document.body.offsetHeight-parseInt(document.styleSheets[0].rules[1].style.height)-parseInt(document.styleSheets[0].rules[7].style.height)));
	//if (resize==true||globalResize==true){
	return (resX+" "+resY);
}

function Relation(relX,relY){ //test, případně návrat jedné hodnoty v relaci
	var relation=0.75; //relace y:x (3:4)
	if (relX&&relY)
		if (relY/relX==relation) return true;
		else return false;
	else if (relX) return (relX*relation);
	else return (relY/relation);
}
 
function Resize(){ //spustí timer a nastavuje histTime
	if (objFull.value!='true') return objMapsize.value; //+ fce Resolution();
	var d;
	if (histTime==60) TestTime(); //start
	if (histTime!=-1){
	d = new Date();
	histTime=d.getSeconds();
	}}
	
	function TestTime(){ //timer testuje prodlevu události onResize
	var currTime, d, interval; 
	d = new Date();
	interval=2; //minimální doba mezi dvěma událostmi resize pro reload (v sec)
	currTime=d.getSeconds();
	if (histTime>=0&&((currTime-histTime)>=interval)){
		histTime=-1; //ukonči testování
		//objMapsize.value=Resolution();
		objMapsize.value=Resolution();
//		alert(objMapsize.value+" \n"+imgWidth+" "+imgHeight);
		if (objMapsize.value==imgWidth+" "+imgHeight){
			histTime=60;
			return;
		}
		Refreshmap(true);
		return;
	}else {
		setTimeout("TestTime()",100);
	}
}

function Loading(){ //ini layeru loading
	var objLoad=document.getElementById("wait-text");
	var strLoad="Čekejte prosím...";
	/*if (ie5) document.getElementById("wait_op").style.filter="alpha(opacity=70)";
	else document.getElementById("wait_op").style.MozOpacity=.7;*/
	if ((strLoad.length)!=0){
				for (i=0; i<strLoad.length; i++){
					var tag="<span>"+strLoad.charAt(i)+"</span>";
					objLoad.innerHTML=objLoad.innerHTML+tag;
				}
	Coloring(0);
	}
}

function Coloring(n){ //vybarvuj
	var speed=200;
	var objLoad=document.getElementById("wait-text");
	var basecolor="black";
	var textcolor="red";
	if (n==0) //nastavení na výchozí barvu
		for (m=0;m<objLoad.childNodes.length;m++)
			objLoad.childNodes[m].style.color=basecolor;
	objLoad.childNodes[n].style.color=textcolor;
	n++;
	
	if (n==objLoad.childNodes.length) {n=0;}
	setTimeout("Coloring("+n+")",200);
}

function ViewMenu(id){ //menu
	if (id!=null){
		var obj=document.getElementById(id);
		if (obj!=null&&obj.hasChildNodes()) show(obj.childNodes[0].id,0,obj);
	}
}

var remember = new Array();
var remember2 = new Array();
var checkIt, checkRun; //flagy timeru
 
function show(name,lvl,obj){
	if (!DHTML) return;
	checkUserInput(5000);
	if (remember[lvl] && remember[lvl] == name) return;
	if (remember[lvl])
	{
		closeAll(lvl);
	}
	if (name)
	{
//		var x = getObj(name);
		if (typeof(document.getElementById(name))=="object"&&typeof(document.getElementById(name).style)=="object"){ //problem Maxton
			var objX=document.getElementById(name);
			var sign = true;
			objX.style.visibility = 'visible';
			//x.borderTop = "1px solid black";
			//objX=document.getElementById(name);
			if (objX&&objX.hasChildNodes()){
				objX.childNodes[0].style.borderTop = "1px solid black";
			}
	/*if (ie5){
		x.top=TraceDistY(obj)-52;
		//alert("name="+name+"\n currentTop:"+obj.currentStyle.top+"\n offsetTop:"+obj.offsetTop+"\n TraceDistY:"+TraceDistY(obj)+"\n x.top:"+(TraceDistY(obj)));
	}else{*/
	//alert(document.getElementById("divdfdfdInfo"));
			if(objDivInfo&&objDivInfo.hasChildNodes()){
				if (name==objDivInfo.childNodes[0].id) sign=false;
			}
			if (objDivLoc&&objDivLoc.hasChildNodes()){
				if(name==objDivLoc.childNodes[0].id) sign=false;
			}
			if (sign==true){
				var top;
				if (lvl>0)	top=(TraceDistY(obj)-52-obj.offsetTop-1);
				else  		top=(TraceDistY(obj)-52-obj.offsetTop);
				if (top<0) top=0; //kvuli prvnímu řádku
				 objX.style.top = top;
	/*			var intWidth; ie delal problemy
				if (ie5){ //IE počítá aktivní plochu se scrollbarem!
					intWidth=parseInt(objX.currentStyle.width)-1; //-1 kvůli right border
				}else{
					intWidth=parseInt(document.defaultView.getComputedStyle(objX, '').getPropertyValue("width"))+1; //+1 mozilla nepočítá border do šířky
				}*/
				//document.getElementById("Input1").value=objX.id+" "+objX.currentStyle+" "+objX.currentStyle.width+" "+objX.currentStyle.fontSize+" "+objX.className;//intWidth+" "+objX;
				if (ie5) objX.style.left=(160*lvl)-1;
				else objX.style.left=(160*lvl);
			}	
		}
	}
	//}
	remember[lvl] = name;
	if (obj.parentNode) y = obj.parentNode;
	else if (obj.parentElement) y = obj.parentElement;
	else return;
	if (y.className) return;
	y.className = 'over';
	if (remember2[lvl]) remember2[lvl].className = '';
	remember2[lvl] = y;
}

function closeAll(lvl){
	for (i=remember.length-1;i>=lvl;i--)
	{
		if (remember[i]) //IE4 Mac
		{
//			var x = getObj(remember[i]);
			if (typeof(document.getElementById(remember[i]))=="object"&&typeof(document.getElementById(remember[i]).style)=="object"){ //problem Maxton
			var objX = document.getElementById(remember[i]);
			objX.style.visibility = 'hidden';
			}
		}
		remember[i] = null;
		if (remember2[i])
		{
			remember2[i].className = '';
			remember2[i] = null;
		}
	}
	checkRun=false;
}

function checkUserInput(time){
	if (checkIt) clearTimeout(checkIt);
	checkIt = setTimeout('closeAll(0)',time);
}

function ShowLayer(){
if (opener&&opener.name=='Main') opener.Waitserv(true);
}

function SubmitForm(obj){
if (obj){
	obj.submit();
	window.close();
}
}

function SetObjSizes(){ //nastav tagum styly
	if (objModul.value.toLowerCase()=="true"){
		if (ie5) document.getElementById("main").style.width=document.getElementById("overlay").style.width=(imgWidth+32)+"px";
		else document.getElementById("main").style.width=document.getElementById("overlay").style.width=(imgWidth+34)+"px";
		document.getElementById("main").style.height=document.getElementById("overlay").style.height=(imgHeight+70)+"px";
		document.getElementById("mapaback").style.top="5px";
		document.getElementById("mapaback").style.left="5px";
		document.getElementById("mapaback").style.right="5px";
		document.getElementById("mapaback").style.bottom="5px";
		document.getElementById("mapaback").style.width="100%";
		document.getElementById("mapaback").style.height="100%";		
		document.getElementById("lista").style.display="none";
		document.getElementById("backpanel").style.display="none";		
	}else{
		document.getElementById("main").style.width=document.getElementById("overlay").style.width=(imgWidth+179+offsetX)+"px"; //183
		document.getElementById("main").style.height=document.getElementById("overlay").style.height=(imgHeight+45+offsetY)+"px";
		if (ie5) document.getElementById("mapaback").style.width=(imgWidth+32)+"px";
		else document.getElementById("mapaback").style.width=(imgWidth+34)+"px";
		document.getElementById("mapaback").style.height=(imgHeight+68)+"px";
		document.getElementById("lista").style.visibility="visible";
	}
	objImg.style.width=imgWidth+"px";
	objImg.style.height=imgHeight+"px";
	objMapa.style.width=imgWidth+"px";
	objMapa.style.height=imgHeight+"px";
	document.getElementById("D3mapa").style.width=(imgWidth+22)+"px";
	document.getElementById("D3mapa").style.height=(imgHeight+22)+"px";
	document.getElementById("layers_back").style.height=(imgHeight-90)+"px";
	document.getElementById("D6-layers").style.height=(imgHeight-112)+"px";
	//document.getElementById("tool").style.bottom="5px";
}

function getObj(name){
 if (document.getElementById&&typeof(document.getElementById(name).style)!="undefined")
  {
    return document.getElementById(name).style;
  }
  else if (document.all)
  {
    return document.all[name].style;
  }
  else if (document.layers)
  {
    return document.layers[name];
  }
  else return false;
}