﻿document.onkeypress = checkENTER;

function checkENTER(e){
	if(!e){
		if(event.keyCode && event.keyCode == 13){
			if(event.srcElement.name == "fcatsearch"){
				//enter MS
				document.location='/default.aspx?server=1&section=4&catalog=1&catsrfield=17&catsrtext=' + encodeURI(document.forms[0].elements['fcatsearch'].value);
				event.cancelBubble = false;
				return false;

			}
			if(event.srcElement.name == "txtSearch"){
				//enter MS
				document.location='/default.aspx?searchtext='+encodeURI(document.forms[0].txtSearch.value);
				event.cancelBubble = false;
				return false;
			}			
		}
	}else{
		if(e.which && e.which == 13){
			if(e.target.name == "fcatsearch"){
				//enter OTHER
				document.location='/default.aspx?server=1&section=4&catalog=1&catsrfield=17&catsrtext=' + encodeURI(document.forms[0].elements['fcatsearch'].value);
				e.cancelBubble = false;
				return false

			}
			if(event.srcElement.name == "txtSearch"){
				//enter OTHER
				document.location='/default.aspx?searchtext='+encodeURI(document.forms[0].txtSearch.value);
				e.cancelBubble = false;
				return false
			}						
		}
	}
	return true
}


function gObject(oName){
	return document.getElementById(oName);
}

function reposLayout(){
	var oTopBar 	= gObject("topbar");
	var oTopBarDiv 	= gObject("topbardivider");
	var oPage 	= gObject("pageclip");
	var oClip 	= gObject("dataclip");

	var oColLeft	= gObject("lcolumn");
	var oColMid	= gObject("mcolumn");
	var oColRight	= gObject("rcolumn");
	
	
	if(!oColLeft) return;	

	var mHeight 	= Math.max(oColLeft.offsetHeight, oColMid.offsetHeight);
	    mHeight	= Math.max(oColRight.offsetHeight, mHeight);
	oColRight.style.height	= mHeight + "px";
	oColMid.style.height	= mHeight + "px";
	oColLeft.style.height	= mHeight + "px";

	reposFlashNews(oColMid.offsetWidth);
	hackTelecom();
	hackFlash();
}

function reposFlashNews(oWidth){
	var oHClip 	= gObject("hprotator");
	var oFClip 	= gObject("flashrotator");
	var oNClip 	= gObject("shortnews");

	if(oHClip){
		oNClip.style.width	= (oWidth-oFClip.offsetWidth-10) + "px";
		if(oNClip.offsetHeight>oFClip.offsetHeight){
			oHClip.style.height = (oNClip.offsetHeight+10) + "px";
		}
	}
}

function hackTelecom(){
	var oColLeft	= gObject("telhack");
	var oColMid	= gObject("telhackclip");
	oColMid.style.height = oColLeft.offsetHeight + "px";
	
};

function buildGraphInfo(oPar1, oPar2, oPar3, oPar4, oPar5){
	var oVlh = new Array("sucho", "střední vlhkost", "vysoká vlhkost");
	var oSln = new Array("plné slunce", "plné slunce až polostín", "polostín", "polostín až stín", "stín");
	if(oPar5[1]!=="" || oPar5[2]!==""){
		document.write("<span id='grinfo'>\n");
		document.write("<b>" + oPar5[0] + "</b><br />\n");
		if(oPar5[1]!==""){
			document.write("<span class='svvlh'><img alt='" + oSln[oPar5[1]-1] + "' title='" + oSln[oPar5[1]-1] + "' border='0' src='/Client.Images/Svetlo/" + oPar5[1] + ".gif' hspace='0' vspace='2' width='147' height='47'></span>\n");
		}
		if(oPar5[2]!==""){
			document.write("<span class='svvlh'><img alt='" + oVlh[oPar5[2]-1] + "' title='" + oVlh[oPar5[2]-1] + "' border='0' src='/Client.Images/Vlhko/" + oPar5[2] + ".gif' hspace='0' vspace='2' width='147' height='47'></span>\n");
		}
		document.write("</span>\n");
	}

	document.write("<span id='grcalinfo'>\n<br />\n");
	document.write(buildGraphCalInfo(oPar1, false));
	document.write(buildGraphCalInfo(oPar2, false));
	document.write(buildGraphCalInfo(oPar3, true));
	document.write(buildGraphCalInfo(oPar4, true));
	document.write("</span>\n");
}

function buildGraphCalInfo(oPar, secPair){
	var avMin = parseInt(oPar[1]);
	var avMax = parseInt(oPar[2]);

	if(avMin==0 && oPar[1].indexOf("0")==0){
		avMin = parseInt(oPar[1].substring(1,2));
	}

	if(avMax==0 && (oPar[2]).indexOf("0")==0){
		avMax = parseInt(oPar[2].substring(1,2));
	}
	if(isNaN(avMin) || isNaN(avMax) || (avMin==0 && avMax==0)){
		return ""
	}
	if(avMin>avMax){
		avMax = avMin;
		avMin = parseInt(oPar[2]);
	}
	var av1Min = avMin;
	var av1Max = avMax;

	if(secPair && oPar.length==5){
		if(!isNaN(parseInt(oPar[3]))){
			av1Min = parseInt(oPar[3]);
		}		
		if(!isNaN(parseInt(oPar[4]))){
			av1Max = parseInt(oPar[4]);
		}


		if(av1Min==0 && oPar[3].indexOf("0")==0){
			av1Min = parseInt(oPar[3].substring(1,2));
		}
	
		if(av1Max==0 && (oPar[4]).indexOf("0")==0){
			av1Max = parseInt(oPar[4].substring(1,2));
		}


		if(av1Min>av1Max){
			av1Max = av1Min;
			av1Min = !isNaN(parseInt(oPar[4])) ? parseInt(oPar[4]) : avMax;
		}
	}
	var rString = new String();

	rString += ("<span class='grcalcinfo_text'>" + oPar[0] + "</span>\n");
	var oMonth = new Array("Leden", "Únor", "Březen", "Duben", "Květen", "Červen", "Červenec", "Srpen", "Září", "Říjen", "Listopad", "Prosinec");
	for(var j=1; j<13; j++){
	 	rString += "<span class='grcalcinfo'><img alt='" + oMonth[j-1] + "' title='" + oMonth[j-1] + "' border='0' src='/Client.Images/Month/" + (j + (((j>=avMin && j<=avMax) || (j>=av1Min && j<=av1Max)) ? "on" : "")) + ".gif' hspace='0' vspace='0' width='19' height='17'></span>\n"
	}
	return rString + "<br /><br />\n";
}

function displayfilter(which){
	var oObj = gObject("sfilter" + which);
	if(oObj){
		if(oObj.style.display=="block"){
			oObj.style.display = "none";
		}else{
			oObj.style.display ="block";
		}
	}
}

function showFullThumbNail(which){
	var wa = window.open("/ShowFullThumbNail.aspx?id_file=" + which, "tmb", "status=1, tollbar=0");
}

function preparePrint(idarticle){
	var wa = window.open("/default.aspx?prnwin=1&article=" + idarticle, "prn", "width=600, height=400, status=1, scrollbars=1, tollbar=0, resizable=1");
}

function InsSm(which){
	var oObj = gObject("Editor");
	if(oObj){
		oObj.value += which;
	}
}

function runMailClient(mMail){
	if(!mMail) return;
	var eAdd = new String("") + mMail.replace(" zavinac ", "@");
	eAdd = eAdd.replace(/\$/igm, ".");
	document.location = "mailto:" + eAdd;
	
}

function hackFlash(){
	if(document.getElementsByTagName){
		var objects = document.getElementsByTagName('embed'); 
		for (var i=0; i<objects.length; i++) { 
			objects[i].outerHTML = objects[i].outerHTML; 
		} 
	}
}

//**************************************************
function showppp(){
	var wa = window.open("/adolozka.htm", "adol", "width=300, height=360, status=1, scrollbars=0, tollbar=0, resizable=0");
}
//**************************************************
// ETARGET
//**************************************************
function show_link(a){
	window.status=a;return true;
}
function hide_link(){
	window.status=' ';
}