// 22.6.2003 Jan Pokorny
function check_all_checkboxes(strForm, strPrefix, bOn)
{
	var arrChk, i;
	arrChk = eval('self.document.'+strForm).elements;
	for (i = 0; i < arrChk.length; i++)
	{
		if(arrChk[i].name.substr(0, strPrefix.length) == strPrefix) arrChk[i].checked = bOn;
	}
};

// 9.6.2003 Jan Pokorny
function checkMe(tf,pars)
{
	pole=pars.split(',');
	for(i=0;i<pole.length;i+=2)
	{
		if(eval('typeof  tf.'+pole[i])!='undefined'){
			if(eval('tf.'+pole[i]+'.value')=='')
			{
				alert(pole[(i+1)]+' je povinná poloka.');
				eval('tf.'+pole[i]+'.focus()');
				return false;
			}
		}
	}
	return true;
}

// 17.2.2003 Jan Pokorny
function OpenPicture(filename, title, width, height)
{
	wi = Math.floor(Math.random() * 1000) + 1000
	ImageWindow = window.open('', wi.toString(), 'status=no,width='+width.toString()+',height='+height.toString()+',resizable=no,menubar=no,scrollbars=no,toolbar=no')
	ImageWindow.document.write('<html><head><title>'+title+'</title></head><body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0>')
	ImageWindow.document.write('<img src="'+filename+'" width='+width.toString()+' height='+height.toString()+'><br>')
	ImageWindow.document.write('</body></html>')
}

// 16.1.2003 Jan Pokorny
function file_show(strFile)
{
	var wndShow;
	wi = Math.floor(Math.random() * 1000) + 1000
	wndShow = window.open(strFile, wi.toString(), 'left=410,top=210,width=350,height=450,toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes');
	wndShow.focus();
}
// 27.5.2002 - Vojtech Braun - modified 17.7.2006 Tichy (add param. webID)
function open_file_select(strField, figID, nWebID)
{
	var wndFileSel, sURL;
	wi = Math.floor(Math.random() * 1000) + 1000
	sURL = '../fileman/list.asp?viewSend=1&viewSendWhat=file';
	sURL += ((strField != "" && strField != 'undefined')	? '&viewSendValue='+ strField	: '');
	sURL += ((figID != "" && figID != 'undefined')			? '&fig_id='+ figID				: '');
	sURL += ((nWebID != "" && nWebID != 'undefined')		? '&webId='+ nWebID				: '');
	wndFileSel = window.open(sURL, wi.toString(), 'left=100,top=100,height=500,width=900,status=yes,resizable=yes,toolbar=no,menubar=no,location=no,scrollbars=yes');
	wndFileSel.focus();
}

// 09.07.2002 - Vojtech Braun
function file_clear(strFormName, strFieldName)
{
	document.forms[strFormName].elements[strFieldName+'_id'].value = '';
	document.forms[strFormName].elements[strFieldName+'_name'].value = '';
	document.forms[strFormName].elements[strFieldName+'_file'].value = '';
}

//--------------------------------------------------------------------------------------
// 18.12.2003 - Jan Pokorny
// Smaze input v zadanem formulari a policku
//--------------------------------------------------------------------------------------
function input_clear(strFormName, strFieldName)
{
	document.forms[strFormName].elements[strFieldName].value = '';
}
//--------------------------------------------------------------------------------------
// 18.12.2003 - Jan Pokorny
// Otevre dokument v nvem okne (pouziva file_show)
//--------------------------------------------------------------------------------------
function document_show(docID,path){
	if(docID!='') file_show(path+docID);
}

//--------------------------------------------------------------------------------------
// 18.12.2003 - Jan Pokorny
// Otevre v novem okne formular pro zadani dokumentu
//--------------------------------------------------------------------------------------
function open_document_select(script,strField,docID,itmName,itmFrom,itmTo, nAppID, nWebID)
{
	var wndFileSel, sUrl;
	sUrl = '../document/' + script	;
	sUrl += '?doIt=insert'			;
	sUrl += '&appId='	+ nAppID	;
	sUrl += '&webId='	+ nWebID	;
	sUrl += '&field='	+ strField	;
	sUrl += '&id='		+ docID		;
	sUrl += '&docName=' + itmName	;
	sUrl += '&docFrom=' + itmFrom	;
	sUrl += '&docTo='	+ itmTo		;
	wndFileSel = window.open(sUrl, 'wndFileSel', 'left=100,top=100,height=400,width=850,status=yes,resizable=yes,toolbar=no,menubar=no,location=no,scrollbars=yes');
	wndFileSel.focus();
}

//--------------------------------------------------------------------------------------
// 6.1.2004 - Krystof Nemec
// Otevre v novem okne formular pro zadani odkazu
//--------------------------------------------------------------------------------------
function open_link_select(script, sourceThemaID, strFieldThema, strFieldItem, themaID, itmID)
{
	var wndFileSel;
	wndFileSel = window.open(script+'?doIt=insert&temID='+sourceThemaID+'&id='+themaID+'&itmID='+itmID +'&fieldthema='+strFieldThema +'&fielditem='+strFieldItem, 'wndLinkSel', 'left=100,top=100,height=400,width=700,status=yes,resizable=yes,toolbar=no,menubar=no,location=no,scrollbars=yes');
	wndFileSel.focus();
}

function Validate(theForm, arr)
{
    for(var i = 0; i < theForm.length; i++)
    {
        if(arr[i])
        {
            if(!arr[i].Validate(theForm.elements[i]))
                return false
        }
    }
    return true;
}

function MeText(strName, fAllowEmpty)
{
    this.strName = strName
    this.fAllowEmpty = fAllowEmpty
    this.Validate = function(field)
    {
        if ((!this.fAllowEmpty) && (field.value == ""))
        {
            alert('Vlote prosím text do pole "' + this.strName + '".')
            field.focus()
            return false
        }
        return true
    }
}

function link(left1, main1)
{
	if (left1!='') 	parent.left.location.href = left1;
	if (main1!='') 	parent.main.location.href = main1;
}

function link1(main1, left1)
{
	if (main1!='') 	parent.main.location.href = main1;
	if (left1!='') 	parent.left.location.href = left1;
	return false;
}

function newWindow(url)
{
	window.open(url);
}
function new_window(url)
{
	newWindow(url);
}
function makeWindow(url)
{
	window.open(url, '', "toolbar=no,status=no,scrollbars=no,resizable=yes,width=700,height=400");
}

function makeWindowScrollable(url)
{
	window.open(url, '', "menubar=yes,toolbar=no,status=no,scrollbars=yes,resizable=yes,width=700,height=400");
}

function previewWindow(url, title)
{
	window.open(url, title, "toolbar=no,status=no,scrollbars=yes,resizable=yes,width=800,height=600");
}

function change_color()
{
	document.aa.style.textColor = '#00FF00';
}

function VRWindow(url, title)
{
	window.open(url, title, "toolbar=no,status=no,scrollbars=yes,resizable=yes,width=780,height=450");
}
function hop(ts,adr,what){
	if(ts.options[ts.selectedIndex].value=='0' || ts.options[ts.selectedIndex].value=='') return false;
	else document.location = adr+'?'+what+'='+ts.options[ts.selectedIndex].value;
}

function volbyBanner(url, title)
{
	window.open(url, title, "toolbar=no,status=no,scrollbars=yes,resizable=yes,width=400,height=60");
}


//--------------------------------------------------------------------------------------
// Meni style.display u divu s divID na opacny
// 1.12.2003 Jan Pokorny
//--------------------------------------------------------------------------------------
function divSwapDisplay(divName){
	var myDiv=document.getElementById(divName);
	var myStyle=myDiv.style.display;
	if(myStyle==''){
		myDiv.style.display='none';
	}else{
		myDiv.style.display='';
	}
	return true;
}
//--------------------------------------------------------------------------------------
// Zavola zmenu zobrazeni divu a vytvori obrazek ... jenz nahraje do session stav mapy
// 2.2.2004 Jan Pokorny
//--------------------------------------------------------------------------------------
function divSwapMap(divName,temID) {
	divSwapDisplay(divName);
	var myDiv=document.getElementById(divName);
	var myStyle=myDiv.style.display;
	if(document.images){
		//alert("showHideMap.asp?thema="+temID+"&display="+myStyle);
		(new Image()).src="showHideMap.asp?thema="+temID+"&display="+myStyle;
	}
	return true;
}

//--------------------------------------------------------------------------------------
// U telefoniho seznamu provede odeslani formure pro jeho spraven serazeni
// 1.12.2003 Krystof Nemec
//--------------------------------------------------------------------------------------
function order_by(strForm, strElement, strValue){
	var searchInput=document.getElementById(strElement);
	var searchForm=document.getElementById(strForm);
	searchInput.value=strValue;
	searchForm.submit();
	//alert('document.' +strForm +'.' +strElement);
	//eval('document.' +strForm +'.' +strElement).value = strValue;
	//eval('document.' +strForm).submit();
}

//--------------------------------------------------------------------------------------
// Prepina mezi _map1.gif a map2.gif
// 16.1.2004 Jan Pokorny
//--------------------------------------------------------------------------------------
function swapMap(){
	var myDiv=document.getElementById('mapPicture');	
	var imgSrc=myDiv.src;
	var ImgName
	var tmp=myDiv.src;
	imgName=imgSrc.substr(imgSrc.lastIndexOf('/')+1,imgSrc.length-(imgSrc.lastIndexOf('/')+1));
	
	if(imgName=='_map1.gif') {
		window.setTimeout('document.getElementById(\'mapPicture\').src=\''+ imgSrc.replace(imgName, '_map2.gif') +'\'');
	}else{
	    window.setTimeout('document.getElementById(\'mapPicture\').src=\''+ imgSrc.replace(imgName, '_map1.gif') +'\'');
	}
}



function blinkelement(id, barva, cas, barva2, cas2)
{
    if (document.getElementById)
    {
        document.getElementById(id).style.color = barva;
        setTimeout('blinkelement("' + id + '","' + barva2 + '",' + cas2 + ',"' + barva + '",' + cas + ')', cas);
    }
    else if (document.all)
    {
        document.all[id].style.color = barva;
        setTimeout('blinkelement("' + id + '","' + barva2 + '",' + cas2 + ',"' + barva + '",' + cas + ')', cas);
    }
}


// ------------------------------
// Okno na vybirani ZIPu a mesta - Pro registrovane uzivatele
// ------------------------------
function validateZipField (eRef) {
	if (!eRef.value) {
		alert ('Prosím zadejte alespoň 3 číslice do pole PSČ.')
		eRef.focus();
		return false;

	}
	return true;
}

function validateZip(zipCode, zipAddress) {
	var zipE = document.getElementById(zipCode);
	if (!validateZipField (zipE)) {
		return false;
	}

	window.zipCode = zipCode;
	window.zipAddress = zipAddress;

	if (window.showModalDialog) {
		showModalDialog ("zip.asp?search=yes&zip=" +zipE.value, window, "dialogheight=270px;dialogwidth=300px;status=no;toolbar=no;menubar=no;location=no;resizable=yes;scroll:yes")
	} else {
		window.open("zip.asp?search=yes&zip=" +zipE.value, 'zipWindow', 'width=300,height=270,status=no,toolbar=no,menubar=no,location=no,resizable=yes,scroll=yes,')
	}

}

// vraci hodnotu z popup okna zpet do formulara
function backToForm(formID, elName, newId, newName){
	var opnr=window.opener;
	var desForm=opnr.document.getElementById(formID);
	opnr.document.getElementById(elName+'_fk').value=newId;
	opnr.document.getElementById(elName+'_name').innerHTML=newName;
	window.setTimeout('window.close()',10);
}

// vraci hodnotu z popup okna zpet do formulara
function backToFormThema(formID, elName, newId, newName, themaPath){
	var opnr=window.opener;
	var desForm=opnr.document.getElementById(formID);
	opnr.document.getElementById(elName+'_fk').value=newId;
	opnr.document.getElementById(elName+'_name').innerHTML=newName;
	opnr.document.getElementById(elName+'_path').innerHTML=themaPath;
	window.setTimeout('window.close()',10);
}

// smaza hodnoty z formulare u tematu
function deleteThemaForm(name){
	document.getElementById(name+'_fk').value='';
	document.getElementById(name+'_name').innerHTML='';
}


// DT.2007/03/01 - Zvyraznovani radku v tabulce seznamu 
// Vysviti vsechny radky v tabulkach s class="seznam hightlight" krome prvniho a th
// Funguje jenom pro IE (attachEvent) a je to urcene pouze pro manage
function highlightListTables(){
	var i, tables, table, r, rows, row, c, cols;
	tables = document.getElementsByTagName('table');
	for(i = 0; i < tables.length; i++){
		table = tables[i];
		if(table.className == 'seznam highlight'){
			rows = table.getElementsByTagName('tr');
			for(r = 0; r < rows.length; r++){
				row = rows[r];
				if(r > 0 && row.getElementsByTagName('td').length > 0){
					row.attachEvent("onmouseover", highlightOn);	//priradi udalost vysviceni pri mouseover
					row.attachEvent("onmouseout", highlightOff);	//priradi udalost zhasnuti pri mouseout
					
					// Pokud narazi na 'zvyraznene' bunky tak zvyrazni tr a s td odstrani zvyrazneni
					// cols = row.getElementsByTagName('td')
					// if(cols[0].className == "zvyrazni"){
					// 	row.style.backgroundColor = "#D5D5D5";
					// 	for(c = 0; c < cols.length; c++){
					// 		cols[c].className = "";
					// 	}
					// }
				}
			}
		}
	}
}

// DT.2007/03/01 - Vysviceni radku - pro higlightTableSeznam 
// Funguje jenom pro IE (event.srcElement) a je to urcene pouze pro manage
function highlightOn(){
	var obj = event.srcElement;
	var row = getParentElementByTagName(obj, 'tr');
	if(row != null){
		// do atributu alt ulozim puvodni barvu pozadi
		row.setAttribute("alt", row.style.backgroundColor);
		row.style.backgroundColor = "#CDCDCD";
	}
}

// DT.2007/03/01 - Zhasnuti radku -  pro higlightTableSeznam
// Funguje jenom pro IE (event.srcElement) a je to urcene pouze pro manage
function highlightOff(){
	var obj = event.srcElement;
	var row = getParentElementByTagName(obj, 'tr');
	if(row != null){
		// nastavim zpet barvu kterou jsem si ulozil do atributu alt
		row.style.backgroundColor = row.getAttribute("alt");
	}
}

// DT.2007/03/01 - Nalezeni nadrazeneho tagu
function getParentElementByTagName(elm, tag){
	var _elm = elm;
	if (_elm.tagName.toLowerCase() == tag.toLowerCase())
		return _elm;
	do {
		if (_elm.tagName.toLowerCase() == tag.toLowerCase())
			return _elm;
	} while ((_elm = _elm.parentElement) != null);
	return null;
}

// MM 2007/03/21
function confirmBotDefender(sElementBaseName, sCode, nTimeStamp) {
    document.getElementById(sElementBaseName +'_code_hidden').value = sCode;
    document.getElementById(sElementBaseName +'_stamp_hidden').value = nTimeStamp;
}


function statusText(sText){
	window.status = sText;
	return true;
}

function statusTextClear(){
	window.status = "";
	return true;
}

function thisPageDoPrint(){
	self.window.print();
}

function thisPageAddFavorite(sTitle){
	self.window.external.AddFavorite(document.location.href, sTitle);	
}
