window.onload=windowLoad;

function windowLoad() {
	focusFirstField();
}

function autoResizeWindow(win,minWidth,minHeight) {
// Automaticky zvetsi okno podle velikosti obsahu. pouze IE
	if(win.document.readyState=='loading') win.setTimeout("autoResizeWindow(window)",200,minWidth,minHeight);
	else if(win.document.documentElement.clientWidth<win.document.documentElement.scrollWidth || win.document.documentElement.clientHeight<win.document.documentElement.scrollHeight) {
		setWidth = win.document.body.offsetWidth+35;
		setHeight = win.document.body.offsetHeight+60;
		if(minWidth && setWidth<minWidth) setWidth = minWidth;
		if(minHeight && setWidth<minHeight) setHeight = minHeight;
		win.resizeTo(setWidth,setHeight);
	}
}

function focusFirstField() {
// da focus prvnimu textovemu poli na strance. pozor na pripady, kdy je vic frames - focus se udela na posledni z nich!
// v takovem pripade umistit nekam do dokumentu, ktery chceme vynechat prazdny span s id = noFocusOnLoad
	if (document.getElementById('noFocusOnLoad')==null && document.forms.length > 0) {
		var TForm = document.forms[0];
		for (i=0;i<TForm.length;i++) {
			if ((TForm.elements[i].type=="text")||(TForm.elements[i].type=="textarea")) {
				try {
					document.forms[0].elements[i].focus();
				} catch(exc) {
					continue;
				}
				break;
			}
		}
	}
}

function noEnter(e) {
// ignoruje stisk klavesy enter. typicke volani jako form onkeypress="return noEnter(event);"
	return !(e && e.keyCode == 13);
}

function setAction(newaction) {
// nastavi hidden field "action"
	var obj = document.getElementById('action');
	if(obj==null) {
		alert('Cannot set action');
		return false;
	//} else if ((obj.value) && (obj.value!=newaction)) {
	//	//value jiz nastavena a je jina
	//	return false;
	} else {
		obj.value=newaction;
		return true;
	}
}
function unsetAction(){
	//kvuli moznosti zruseni nastavene action
	var obj = document.getElementById('action');
	if(obj==null) {
		alert('Cannot unset action');
		return false;
	} else {
		obj.value='';
		return true;
	}
}

function addEvent(obj, evType, fn) {
// jako attachEvent pdo MSIE, funguje i pod FF
  if (obj.addEventListener)
  {
    obj.addEventListener(evType, fn, false);
    return true;
  }
  else if (obj.attachEvent)
  {
  var r = obj.attachEvent("on"+evType, fn);
    return r;
  }
  else
  {
    return false;
  }
}

function textDivMouseOver(obj) {
// pokud ma div mensi sirku nez je sirka obsahu (ctlfield->width), zobrazi pri mouseover tooltip
	if(obj.clientWidth > 0 && obj.scrollWidth > obj.clientWidth ||
			obj.clientHeight > 0 && obj.scrollHeight > obj.clientHeight) {
		if(obj.innerText) var text = new String(obj.innerText);
		else var text = new String(obj.innerHTML);
		text = text.replace('&lt;','<');
		text = text.replace('&gt;','>');
		text = text.replace('<BR>',' ');
		text = text.replace('<br>',' ');
		text = text.replace('<br />',' ');
		obj.title = text;
	}
}

// ********************
// CtlCheckbox
// ********************

function checkboxClick(obj,allownullentry) {
	var objCheckboxValue = document.getElementById(obj.id.slice(0,obj.id.length-4));
	var objCheckboxImg = document.getElementById(objCheckboxValue.id+'_img');
	if(allownullentry==true) {
		// pri vychozi null hodnote a klikani to jde postupne - NULL,1,0,NULL..
	        if((obj.checked)&&(objCheckboxImg.style.visibility=='visible')) {
				objCheckboxImg.style.visibility='hidden';
				objCheckboxImg.style.display = 'none';
				obj.style.display = 'inline';
				obj.checked = true;
				objCheckboxValue.value='1';
				return;
	        }
	        if((!obj.checked)&&(objCheckboxImg.style.visibility=='hidden')) {
				obj.checked = false;
				objCheckboxValue.value='0';
				return;
			}
	        if((obj.checked)&&(objCheckboxImg.style.visibility=='hidden')) {
				// here is third state beeing set ('' = NULL)
				obj.checked = false;
				objCheckboxImg.style.visibility='visible';
				objCheckboxImg.style.display = 'inline';
				obj.style.display = 'none';
				objCheckboxValue.value='';
			return;
		}
	} else {
		objCheckboxImg.style.visibility='hidden';
		if(obj.checked)
			objCheckboxValue.value='1';
		else
			objCheckboxValue.value='0';
	}
}
function defaultCheckboxClick(element){
	var objCheckboxValue = document.getElementById(element.id.slice(0,element.id.length-4));
	var objCheckbox = document.getElementById(element.id.slice(0,element.id.length-4)+'_chk');
	var objCheckboxImg = document.getElementById(objCheckboxValue.id+'_img');
	objCheckboxImg.style.display='none';
	objCheckboxImg.style.visibility='hidden';
	objCheckbox.checked='checked';
	objCheckboxValue.value='1';
	objCheckbox.style.display = 'inline';
	//if (objCheckbox.onclick) objCheckbox.onclick();
//	element.style.visibility='hidden';
}
// ********************
// Funkce pro TrTag, RowCheckbox
// ********************
var trmousedown = false;
var tablemouseover = false;
var trmousedown_checkboxid = '';
//pro zmeny smeru budeme prehazovat i posledni v puvodnim
var trmousedown_checkboxid_before = '';
var trmousedown_checkboxid_before_before = '';
var trclickopen_enabled=true;
var checkboxmouseover = false;
function trMouseOver(obj,text,trmousedown,checkboxid,doublerowmode) {
	var back=obj.style.backgroundColor;
	// doublerowmode se pouzije jen pokud jsou v browse dve spojene radky pod sebou
	// potom je bud 1 nebo 2. Prvni radek zarizuje highlighting i pro nasledujici, naopak druhy radek nedela nic
	if(doublerowmode==1) var obj2 = getNextSibling(obj);
	else if(doublerowmode==2) var obj2 = getPreviousSibling(obj);
	str=new String(back);
	if(back == '') {
		obj.style.backgroundColor = '#bfdffe';
		if(obj2) obj2.style.backgroundColor = '#bfdffe';
	} else if(back == '#eaeaea' || back == 'rgb(234, 234, 234)') {
		obj.style.backgroundColor  = '#bfdfff';
		if(obj2) obj2.style.backgroundColor  = '#bfdfff';
	}
	window.top.status=text;
	if (typeof(checkboxid)!='undefined' && typeof(trmousedown!='undefined')){
		if (trmousedown && document.getElementById(checkboxid)){
			if (checkboxid!=trmousedown_checkboxid){
				document.getElementById(checkboxid).checked = !document.getElementById(checkboxid).checked;
				if (document.getElementById(checkboxid).onclick) document.getElementById(checkboxid).onclick(window.event);
				if (trmousedown_checkboxid_before){
					if (trmousedown_checkboxid_before==checkboxid){
						document.getElementById(trmousedown_checkboxid).checked=!document.getElementById(trmousedown_checkboxid).checked;
						if (document.getElementById(trmousedown_checkboxid).onclick) document.getElementById(trmousedown_checkboxid).onclick(window.event);
					}
				}
				if (trmousedown_checkboxid_before)
					trmousedown_checkboxid_before_before = trmousedown_checkboxid_before;
				if (trmousedown_checkboxid)
					trmousedown_checkboxid_before = trmousedown_checkboxid;
				trmousedown_checkboxid = checkboxid;
			}
		}
	}
}

function trMouseOut(obj,doublerowmode) {
	var back=obj.style.backgroundColor;
	// doublerowmode se pouzije jen pokud jsou v browse dve spojene radky pod sebou
	// potom je bud 1 nebo 2. Prvni radek zarizuje highlighting i pro nasledujici, naopak druhy radek nedela nic
	if(doublerowmode==1) var obj2 = getNextSibling(obj);
	else if(doublerowmode==2) var obj2 = getPreviousSibling(obj);
	if(back == '#bfdffe' || back == 'rgb(191, 223, 254)') {
		obj.style.backgroundColor = '';
		if(obj2) obj2.style.backgroundColor = '';
	} else if(back == '#bfdfff' || back == 'rgb(191, 223, 255)') {
		obj.style.backgroundColor  = '#eaeaea';
		if(obj2) obj2.style.backgroundColor  = '#eaeaea';
	}
	window.top.status='';
}

function getNextSibling(startBrother){
// IE&firefox fungujici funkce, narozdil od obj.nextSibling
  endBrother=startBrother.nextSibling;
  while(endBrother.nodeType!=1){
    endBrother = endBrother.nextSibling;
  }
  return endBrother;
}

function getPreviousSibling(startBrother){
  endBrother=startBrother.previousSibling;
  while(endBrother.nodeType!=1){
    endBrother = endBrother.previousSibling;
  }
  return endBrother;
}

//promenna pro dblclick, nastavuje se na true, aby se neprovedl onclick
var trDblClicked = false;
function trClickOpen(obj,href,target,win_features) {
	if(!document.all) { window.open(href,target); return true; } // mozilla
	if(target=='_blank' || event.ctrlKey || event.shiftKey) {
		window.open(href,'_blank',win_features);
	} else window.open(href,target);
}

function rowCheckboxClick(obj,val,listfield_id,evt) {
	var e = (window.event) ? window.event : evt;
	if (e) e.cancelBubble = true;
	rowCheckboxChange(obj.checked,val,listfield_id);
}
function rowCheckboxChange(state, val, listfield_id){
	//univerzalnejsi metoda pro explicitni check v radku, neni treba volat primo na checkboxu
	var listfield = document.getElementById(listfield_id);
	var str = new String(','+listfield.value); // na zacatek se prida carka kvuli hledani
	if (str.length>1) str = str.concat(','); //Bugfix: i na konec
	var found = str.search(','+val+',');
	if((state==true) && (found == -1)) {
		//if(str.length>1) str = str.concat(','); // pokud nejde o prvni hodnotu, prida se carka
		str = str.concat(val+','); // za carku se prida hodnota
	}
	if((state==false) && (found != -1)) {
		str = str.replace(','+val+',',',');
	}
	if (str == ',') str = '';
	else
	str = str.substring(1,str.length-1); // carka pridana na zacatek (bugfix: i na konec) se odstrani
	listfield.value = str;
}
function rowCheckboxInit(checkbox_id, val, listfield_id){
	//nastaveni checkboxu dle hidden fieldu v zahlavi
	var listfield = document.getElementById(listfield_id);
	var str = new String(','+listfield.value); // na zacatek se prida carka kvuli hledani
	if (str.length>1) str = str.concat(','); //Bugfix: i na konec
	var found = str.search(','+val+',');
	var obj = document.getElementById(checkbox_id);
	if(found == -1)
		obj.checked = false;
	else
		obj.checked = true;
}
function getSelectedMultiple(selObjId, txtSelectedValuesObjId){
	return getSelectedMultipleObj(document.getElementById(selObjId), document.getElementById(txtSelectedValuesObjId));
}
function getSelectedMultipleObj(selObj, txtSelectedValuesObj)
{
  var selectedArray = new Array();
  var i;
  var count = 0;
  for (i=0; i<selObj.options.length; i++) {
    if (selObj.options[i].selected) {
      selectedArray[count] = selObj.options[i].value;
      count++;
    }
  }
  txtSelectedValuesObj.value = selectedArray;
}

// ********************
// Funkce ovladacich prvku DateField, DateTimeField
// ********************

function DateFieldBlur(obj,dateFormat,currentDateString) {
	// Doplneni castecne napsaneho datumu
	if(dateFormat=='d.m.Y' || dateFormat=='d.m.Y H:i:s') {
		var withTime = false;
		if(dateFormat=='d.m.Y H:i:s') withTime = true;
		var str = new String(obj.value);
		var str2 = new String(currentDateString);
		var strDay = str2.slice(0,2);
		var strMonth = str2.slice(3,5);
		var strYear = str2.slice(6,10);
		if(withTime) {
			var strHour = str2.slice(11,13);
			var strMinute = str2.slice(14,16);
			var strSecond = str2.slice(17,19);
			var str_space = str.indexOf(' ');
			var str_time = '';
			if(str_space>0) {
				str_time = str.slice(str_space);
				str = str.slice(0,str_space); // pokud je obsahem cas a ma se doplnovat, cas se nepouzije
			}
		}
		var lastCharDot = 0;
		var numDots = 0;
		var i = 0;
		while(i!=-1 && numDots<20) {
			i = str.indexOf('.',i);
			if(i!=-1) {
				numDots++;
				i++;
			}
		}
		if(str.slice(-1)=='.') lastCharDot = 1;
		if( (str.length-numDots==1) || ((str.length-numDots==2) && (numDots-lastCharDot==0)) ) {
			obj.value = str.concat('.',strMonth,'.',strYear); // pouze den, prida se mesic a rok
			if(obj.onchange!=null) obj.onchange();
		} else if( ((str.length-numDots==2) && (numDots-lastCharDot==1)) || (str.length-numDots==3) || (str.length-numDots==4) ) {
			obj.value = str.concat('.',strYear); // den a mesic, prida se rok
			if(obj.onchange!=null) obj.onchange();
		}
		if ( (numDots==2) && (lastCharDot==0) ) {
			var pomYear = '';
			i = str.lastIndexOf('.')+1;
			pomYear=str.slice(i);
			pomYearNo = new Number(pomYear);
			if( ((pomYear.length==2) || (pomYear.length==1)) && (pomYearNo<99) && (pomYearNo>=0) ) {
				var strPom = str.slice(0,i);
				strPom = strPom.concat('20');
				strPom = strPom.concat(pomYear);
				obj.value = strPom; // naformatovani roku jako '20xx'
			}
		}
	}
}

// ********************
// Funkce ovladaciho prvku TimeField
// ********************

function TimeFieldBlur(obj,timeFormat,currentTimeString) {
	// Doplneni castecne napsaneho casu
	var str = new String(obj.value);
	if(str.length==3 || str.length==4 || str.length==5) {
		obj.value = str.concat(':00');
		if(obj.onchange!=null) obj.onchange();
	} else if (str.length==1 || str.length==2) {
		obj.value = str.concat(':00:00');
		if(obj.onchange!=null) obj.onchange();
	}
}

// ********************
// Funkce ovladaciho prvku Checkbox
// ********************

/*function CheckboxClick(obj,allownullentry) {
	var objCheckboxValue = document.getElementById(obj.id.slice(0,obj.id.length-4));
	var objCheckboxImg = document.getElementById(objCheckboxValue.id+'_img');
	if(allownullentry) {
		// pri vychozi null hodnote a klikani to jde postupne - NULL,1,0,NULL..
	        if((obj.checked)&&(objCheckboxImg.style.visibility=='visible')) {
			objCheckboxImg.style.visibility='hidden';
			obj.checked = true;
			objCheckboxValue.value='1';
			return;
	        }
	        if((!obj.checked)&&(objCheckboxImg.style.visibility=='hidden')) {
			obj.checked = false;
			objCheckboxValue.value='0';
			return;
		}
	        if((obj.checked)&&(objCheckboxImg.style.visibility=='hidden')) {
			// here is third state beeing set ('NULL')
			obj.checked = false;
			objCheckboxImg.style.visibility='visible';
			objCheckboxValue.value='NULL';
			return;
		}
	} else {
		objCheckboxImg.style.visibility='hidden';
		if(obj.checked)
			objCheckboxValue.value='1';
		else
			objCheckboxValue.value='0';
	}
}*/
/*
Funkce ctlCheckAllNone veme vsechny checkboxy vytvorene pomoci CtlCheckbox (s hidden fieldy a img na null, na samotne checkboxy pouzit CheckAllNone() )
ve formulari zacinajici na startname a da jim hodnotu stejnou jako ma checkbox allnonename.
pouziti: onclick="ctlCheckAllNone(this,'check');"
*/
function ctlCheckAllNone(allnonename, startname) {
  var field = allnonename.form;
  for (var i=0;i<field.elements.length;i++)
	{
		var elem=field.elements[i];
		if (elem.type=="checkbox" && elem.name!=allnonename.name && (elem.name.indexOf(startname) == 0) && (elem.name.length>3) && (elem.name.indexOf("_box")==(elem.name.length-4))) {
    	  		elem.checked = allnonename.checked;
    	 		var hidden = elem.name.substr(0, elem.name.length-4);
     	document.getElementById(hidden).value=(allnonename.checked)?1:0;
     	var objCheckboxImg = hidden+"_img";
     	document.getElementById(objCheckboxImg).style.visibility="hidden";
    		}
	}
}
//metoda pouze na checkboxy, neresi hidden pole a img - pouzivano v rowchecku
function CheckAllNone(allnonename, startname){
	var field = allnonename.form;
	  for (var i=0;i<field.elements.length;i++)
		{
			var elem=field.elements[i];
			if (elem.type=="checkbox" && elem.name!=allnonename.name && (elem.name.indexOf(startname) == 0) && (elem.name.length>3)) {
					if (elem.checked != allnonename.checked) {
						elem.checked = allnonename.checked;
						elem.onclick();
					}
	    		}
		}
}

// ********************
// Funkce ovladaciho prvku FloatField
// ********************

function FloatFieldBlur(obj,decimalpoints,thousandSeparator,decimalPointSymbol) {
// Position kontroluje obsah Floatfieldu, prevadi spatne desetinne oddelovace na spravne a pripadne oddeluje tisice
	var str,n,i,badnumber=0,pointcount=0,pointlocation,isminus=0;
	// Nahradime spatne oddelovace spravnymi
	var badDecimalPointSymbol='';
	if(decimalPointSymbol==',') badDecimalPointSymbol='.';
	if(decimalPointSymbol=='.') badDecimalPointSymbol=',';
	if(badDecimalPointSymbol!='') {
		str=obj.value;
		obj.value=str.replace(badDecimalPointSymbol,decimalPointSymbol);
	}
	// Zkontrolujeme, zda je v poli korektni hodnota
	//if (checkFloat(obj.name,"")!="") return;
	var str2=""; // do str2 se postupne nacte cislo bez formatovacich znaku
	str=obj.value;
	if (str=="") return;
	n=str.length;
	for(i=0;i<n;i++){
		if (str.charAt(i)!=decimalPointSymbol && str.charAt(i)!=badDecimalPointSymbol && str.charAt(i)!=thousandSeparator && str.charAt(i)!="-") str2=str2+str.charAt(i);
		// Odstranujeme z retezce formatovaci znaky, aby bylo s nim bylo v js mozne pracovat jako s cislem
		if (str.charAt(i)==decimalPointSymbol) str2=str2+".";
		if (str.charAt(i)=="-") isminus=1;
	}
	str=str2; // str nyni obsahuje cislo bez formatovacich znaku
	afterpoint =( (str.slice(str.indexOf(".")+1,str.length)) ); // znaky za desetinnou teckou
	if (str.indexOf(".")!=-1) { // nalezena desetinna tecka - neni cele cislo
		if(decimalpoints!=='') {
			if (afterpoint.length>decimalpoints) afterpoint=afterpoint.slice(0,decimalpoints); // Desetinnych mist je vice nez ma byt - jsou oriznuta
			if (afterpoint.length<decimalpoints) afterpoint=afterpoint+multiplyString(decimalpoints-afterpoint.length,"0"); // Desetinnych mist je mene nez ma byt - jsou doplnena nulami
		}
		// zavolame SeparateThousands. Pozn. desetinna tecka se kontroluje na tecku, nikoliv na decimalPointSymbol (kontroluje se str, to uz je upravene)
		obj.value=SeparateThousands(str.slice(0,str.indexOf('.')),thousandSeparator,decimalPointSymbol)+decimalPointSymbol+afterpoint;
		if (isminus) obj.value="-"+obj.value;
		return;
	} else { // cele cislo - neni desetinna tecka
		if (str=="" || str==0) str="0";
		obj.value=SeparateThousands(str,thousandSeparator,decimalPointSymbol);
		if (isminus) obj.value="-"+obj.value;
		return;
	}
}

function SeparateThousands(str,thousandSeparator,decimalPointSymbol) {
// Position vytvori v str stringu (cislo) oddelovace tisicu
	var str2="",n,m;
	if(thousandSeparator=='') return str;
	n=str.length;
	for(i=0;i<n;i++) if (str.charAt(i)!=thousandSeparator) str2=str2+str.charAt(i);
	str=str2;
	str2="";
	n=str.length;
	m=n;
	for(i=0;i<n;i++) {
		if ((str.charAt(i)!=".") && (m%3==0 && i!=0) ) str2=str2+thousandSeparator;
		str2=str2+str.charAt(i);
		m--;
	}
	return str2;
}

// ********************
// Funkce ovladaciho prvku IntegerField
// ********************

function IntFieldBlur(obj) {
// Position zkontroluje obsah pole. Pokud je to cislo a obsahuje desetinna mista, odrizne je. Nahradi spatne oddelovace spravnymi
	var str,n,i,badnumber=0,pointcount=0,pointlocation,isminus=0
	// Nahradime spatne oddelovace spravnymi
	var decimalPointSymbol=REG_DECIMALPOINTSYMBOL;
	var badDecimalPointSymbol='';
	if(decimalPointSymbol==',') badDecimalPointSymbol='.';
	if(decimalPointSymbol=='.') badDecimalPointSymbol=',';
	if(badDecimalPointSymbol!='') {
		str=obj.value;
		obj.value=str.replace(badDecimalPointSymbol,decimalPointSymbol);
	}
	if (checkFloat(obj.name,"")!="") return;
	else {
		var str2="";
		str=obj.value;
		if (str=="") return;
		n=str.length;
		for(i=0;i<n;i++) {
			if (str.charAt(i)!="," && str.charAt(i)!="-") str2=str2+str.charAt(i);
			if (str.charAt(i)==",") str2=str2+".";
			if (str.charAt(i)=="-") isminus=1;
		}
		if (str2.indexOf(".")!=-1) str2 = str2.slice(0,str2.indexOf("."));
		if (isminus) str2="-" + str2;
		if (str2==0) str2="0";
		obj.value = str2;
		return;
	}
}

// ********************
// Obecne funkce
// ********************

function trimOnPaste(obj) {
// orizne text vkladany do prvku
	event.returnValue = false;
	var newText = trim(window.clipboardData.getData('Text'));
	var targetObj = obj.document.selection.createRange();
	targetObj.text = newText;
}

function trim(str) {
// orizne text..
   return str.replace(/^\s*|\s*$/g,"");
}

function multiplyString(n,string) {
// vraci retezec v podobe (n*string)
	returnstring="";
	for(i=0;i<n;i++)
		returnstring=returnstring+string;
	return returnstring;
}

function toRgb(color){
	var r,g,b,tmp,i
	r = (((color.charCodeAt(1) - '0') <= 9)?(color.charCodeAt(1) - '0')*16:(color.charCodeAt(1) - 'a'.charCodeAt(0) + 10)*16)+(((color.charCodeAt(2) - '0') <= 9)?(color.charCodeAt(2) - '0'):(color.charCodeAt(2) - 'a'.charCodeAt(0) + 10));
	g = (((color.charCodeAt(3) - '0') <= 9)?(color.charCodeAt(3) - '0')*16:(color.charCodeAt(3) - 'a'.charCodeAt(0) + 10)*16)+(((color.charCodeAt(4) - '0') <= 9)?(color.charCodeAt(4) - '0'):(color.charCodeAt(4) - 'a'.charCodeAt(0) + 10));
	b = (((color.charCodeAt(5) - '0') <= 9)?(color.charCodeAt(5) - '0')*16:(color.charCodeAt(5) - 'a'.charCodeAt(0) + 10)*16)+(((color.charCodeAt(6) - '0') <= 9)?(color.charCodeAt(6) - '0'):(color.charCodeAt(6) - 'a'.charCodeAt(0) + 10));
	return ("rgb("+r+", "+g+", "+b+")");
}

function debugobj(inobj) {
// v novem okne otevre vypis daneho objektu
	op = window.open();
	op.document.open('text/plain');
	for (objprop in inobj) {
		op.document.write(objprop + ' => ' + inobj[objprop] + '\n');
	}
	op.document.close();
}

//************************************
// Obecne funkce pro IFRAME Popup
//************************************

function fadeIn(id,lastopacity,increment,timeout) {
	var obj = document.getElementById(id);
	var opacity = lastopacity+increment;
	obj.style.filter = 'progid:DXImageTransform.Microsoft.Alpha( Opacity='+opacity+', FinishOpacity=0, Style=0, StartX=0,  FinishX=100, StartY=0, FinishY=100)';
	if(opacity<100) window.setTimeout('fadeIn("'+id+'",'+opacity+','+increment+')',timeout);
	else obj.style.filter = '';
}
function openPopupFrame(name, url, width, height, relativeobjid, direction, offsetx, offsety){
	var relativeobj = document.getElementById(relativeobjid);
	return openPopupFrameObj(name,url,width,height,relativeobj,direction,offsetx,offsety);
}
function openPopupFrameObj(name,url,width,height,relativeobj,direction,offsetx,offsety) {
// funkce pro otevreni (vytvoreni) popupu
// direction udava, jestli ma byt frame zobrazen pod objektem ('bottom') nebo napravo('right')
	if(direction == 'bottom') {
		var oy;
		if (document.getElementById(relativeobj.id+'_overflow_box')){
			oy = getElementTopObj(document.getElementById(relativeobj.id+'_overflow_box'))+document.getElementById(relativeobj.id+'_overflow_box').offsetHeight+2;
		}
		var x = getElementLeftObj(relativeobj);
		var y = getElementTopObj(relativeobj)+relativeobj.offsetHeight+2;
		if (oy)
			if (oy<y) y=oy;
	} else if(direction == 'right') {
		var x = getElementLeftObj(relativeobj)+relativeobj.offsetWidth+2;
		var y = getElementTopObj(relativeobj);
	} else if(direction == 'submenu') {
		var x = getElementLeftObj(relativeobj);
		var y = getElementTopObj(relativeobj)+relativeobj.offsetHeight;
	} else {
		alert('Unsupported direction in showPopupFrame');
		return true;
	}
	if(offsetx) x = x + offsetx;
	if(offsety) y = y + offsety;
	if (x<0) x=0;
	if (y<0) y=0;
	var s=document.getElementById(name);
	if(s){
		ifrm=s;
	} else {
		ifrm = document.createElement("iframe");
	}
	ifrm.frameBorder='0';
	ifrm.name=name;
	ifrm.id=name;
	//ifrm.setAttribute("scrolling", 'no');
	ifrm.setAttribute("src", url);
	ifrm.className = 'clsPopupFrame';
	ifrm.style.backgroundColor = 'white';
	ifrm.style.position = 'absolute';
	ifrm.style.left = x + 'px';
	ifrm.style.top = y + 'px';
	ifrm.style.width = width+'px';
	ifrm.style.height = height+'px';
	ifrm.style.display = 'block';
	ifrm.style.zIndex = 990;
	ifrm.style.filter = 'progid:DXImageTransform.Microsoft.Alpha( Opacity=30, FinishOpacity=0, Style=0, StartX=0,  FinishX=100, StartY=0, FinishY=100)';
	document.body.appendChild(ifrm);
	window.focus();
	window.setTimeout('fadeIn("'+ifrm.id+'",30,5)',10);
	//ifrm.onblur = new Function("closePopupFrame('"+name+"');");
	//ifrm.contentWindow.focus();
	//ifrm.contentWindow.onblur = new Function("closePopupFrame('"+name+"');");
	ifrm.opener = self;
	//mozno pak volat idcko pres self.name
	ifrm.contentWindow.name=name;
	//ifrm.contentWindow.document.write('<body onblur="var i = window.parent.document.getElementById(window.name); i.style.display=\'none\';">');
	//ifrm.contentWindow.document.close();
	return ifrm;
}
function getElementLeft(elementid){
	var obj=document.getElementById(elementid);
	return getElementLeftObj(obj);
}
function getElementLeftObj(obj) {
// vrati skutecnou left pozici elementu (kterou lze nastavit styl left)
	var left=obj.offsetLeft;
	var parent=obj.offsetParent;
	var realParent = false;
	while(parent != null) {
		if (realParent) {
	        while (realParent != parent) {
	            left -= realParent.scrollLeft || 0;
	            realParent = realParent.parentNode;
	        }
        }
		left=left+parent.offsetLeft;
        left -= parent.scrollLeft || 0;
		realParent = parent.parentNode;
		parent=parent.offsetParent;
	}
	return left;
}
function getElementTop(elementid){
	var obj=document.getElementById(elementid);
	return getElementTopObj(obj);
}
function getElementTopObj(obj) {
// vrati skutecnou top pozici elementu (kterou lze nastavit styl top)
	var top=obj.offsetTop;
	var parent=obj.offsetParent;
	var realParent = false;
	while(parent != null) {
		if (realParent) {
	        while (realParent != parent) {
	            top -= realParent.scrollTop  || 0;
	            realParent = realParent.parentNode;
	        }
        }
		top=top+parent.offsetTop;
		top -= parent.scrollTop  || 0;
		realParent = parent.parentNode;
		parent=parent.offsetParent;
	}
	return top;
}
function closePopupFrame(name) {
// uzavreni popupu (vola se primarne pri Storno)
// na onblur se vola hide, aby nezmizely upravy provedene v Iframu
	if(window.document.getElementById(name)!=null) { // volano z parent frame
		doc = window.frames[name].document;
		if(doc==null){
			docwnd=document.getElementById(name);
			if(docwnd) doc=docwnd.contentDocument;
			else doc=null;
		}
		docParent = document;
	} else return false;
	// else { // volano primo z daneho frame
	//	doc = document;
	//	docParent = window.parent.document;
	//}
	if(doc!=null) { // odstrani objekty (deti) v popupframe
		while (doc.childNodes.length > 0) {
	        doc.removeChild(doc.childNodes[0]);
	   	}
	}
   	var obj = docParent.getElementById(name); // odstrani vlastni popupframe(iframe)
	if (obj!=null) {
		if (obj.contentWindow.parent){
			w = obj.contentWindow.parent.document;
			if (!w.history_skip)
				w.history_skip = 0;
			w.history_skip = w.history_skip + (window.history.length-obj.init_history_length);
		}
		obj.parentNode.removeChild(obj);
	}
	//	hideStatus(true);
}
function closeThisPopupFrame(){
	//zavreni tohoto popup framu a prehozeni onclick na danou kontrolku.
	//Predpoklada definovani pozadovanych zaviracich funkci ve skriptu
	eval("window.parent.closePopupFrame_"+self.name+"();");
	return false;
}
function hideThisPopupFrame(){
	//hide tohoto popup framu a prehozeni onclick na danou kontrolku.
	//Predpoklada definovani pozadovanych zaviracich funkci ve skriptu
	eval("window.parent.hidePopupFrame_"+self.name+"();");
	return false;
}
function hidePopupFrame(name){
	// hide popupu (vola se primarne pri onblur)
	if(window.document.getElementById(name)!=null) { // volano z parent frame
		window.document.getElementById(name).style.display='none';
	} else { // volano primo z daneho frame
		//neotestovano
		//self.style.display = 'none';
	}
}
function setParentField(value,name){
	if (!window.parent) return false;
	if (!window.parent.document) return false;
	if (name==null){
		if (!window.name) return false;
		wname = new String(window.name);
		//odstranujeme Iframe_
		name = wname.substring(7);
	}
	if (!window.parent.document.getElementById(name)) return false;
	if (window.parent.document.getElementById(name).tagName=='INPUT'){
		prev_value = window.parent.document.getElementById(name).value;
		window.parent.document.getElementById(name).value=value;
		if (prev_value!=value && window.parent.document.getElementById(name).onchange)
			window.parent.document.getElementById(name).onchange();
	} else
		window.parent.document.getElementById(name).innerHTML=value;
	return true;
}
function setFromParentField(fieldname,parentfieldname){
	if (!document.getElementById(fieldname)) return false;
	if (!window.parent) return false;
	if (!window.parent.document) return false;
	if (parentfieldname==null){
		if (!window.name) return false;
		wname = new String(window.name);
		//odstranujeme Iframe_
		parentfieldname = wname.substring(7);
	}
	if (!window.parent.document.getElementById(parentfieldname)) return false;
	document.getElementById(fieldname).value = window.parent.document.getElementById(parentfieldname).value;
	return true;
}
function setParentFields(){
	fields = document.getElementsByTagName('INPUT');
	for(i=0;i<fields.length;i++){
		if (fields[i].onblur) fields[i].onblur();
	}
	fields = document.getElementsByTagName('SELECT');
	for(i=0;i<fields.length;i++){
		if (fields[i].onblur) fields[i].onblur();
	}
	fields = document.getElementsByTagName('TEXTAREA');
	for(i=0;i<fields.length;i++){
		if (fields[i].onblur) fields[i].onblur();
	}
	return false;
}
function setParentFieldMultiple(val, name, displayed_name, displayed_val){
	if (!window.parent) return false;
	if (!window.parent.document) return false;
	if (name==null){
		if (!window.name) return false;
		wname = new String(window.name);
		//odstranujeme Iframe_
		name = wname.substring(7);
	}
	if (!window.parent.document.getElementById(name)) return false;

	if (displayed_name==null){
		if (!window.name) return false;
		wname = new String(window.name);
		//odstranujeme Iframe_
		displayed_name = wname.substring(7);
	}
	if (!window.parent.document.getElementById(displayed_name)) return false;
	return setFieldMultipleObj(val,window.parent.document.getElementById(name), window.parent.document.getElementById(displayed_name), displayed_val);
}
function unsetFieldMultiple(val, name, displayed_name, displayed_val, unsetobj){
	return setFieldMultipleObj(val,document.getElementById(name),document.getElementById(displayed_name),displayed_val, unsetobj);
}
function setFieldMultipleObj(val, listfield, displayed_span, displayed_val, unsetobj){
	var str = new String(','+listfield.value); // na zacatek se prida carka kvuli hledani
	if (str.length>1) str = str.concat(','); //Bugfix: i na konec
	var found = str.search(','+val+',');
	if((found == -1)) {
		//if(str.length>1) str = str.concat(','); // pokud nejde o prvni hodnotu, prida se carka
		str = str.concat(val+','); // za carku se prida hodnota
	}
	if((found != -1)) {
		str = str.replace(','+val+',',',');
	}
	if (str == ',') str = '';
	else
	str = str.substring(1,str.length-1); // carka pridana na zacatek (bugfix: i na konec) se odstrani
	/*if (unsetobj==null){
		if (window.parent.document.getElementById(listfield.id+'_value_box'))
			window.parent.document.getElementById(listfield.id+'_value_box').innerHTML = str;
	} else {
		if (document.getElementById(listfield.id+'_value_box'))
			document.getElementById(listfield.id+'_value_box').innerHTML = str;
	}*/
	listfield.value = str;
	listfield.setAttribute("value",str);
	if((found == -1)){
		setParentSpan(displayed_span.id, val, displayed_val, listfield.name);
	} else {
		if (unsetobj==null)
			unsetobj = window.parent.document.getElementById(displayed_span.id+'_'+val);
		unsetobj.parentNode.removeChild(unsetobj);
		if (listfield.value==''){
			displayed_span.innerHTML='<table><tr><td></td><td>--nezadáno--</td></tr></table>';
		}
	}
	return true;







}
function setParentSpan(name, val, displayed_val, pkname){
	if (!window.parent) return false;
	if (!window.parent.document) return false;
	if (name==null){
		if (!window.name) return false;
		wname = new String(window.name);
		//odstranujeme Iframe_
		name = wname.substring(7);
	}
	if (!window.parent.document.getElementById(name)) return false;

	var listfield = window.parent.document.getElementById(name);
	var string = new String(listfield.innerHTML);
	if (window.parent.document.getElementById(pkname).value==val)
		string = new String('<table><tbody>');
	else{
		string = string.substr(0,string.length-16);
	}
	//string=string.concat('<a href="#" id="'+name+'_'+val+'" onclick="unsetFieldMultiple('+"'"+val+"','"+pkname+"','"+name+"','"+val+"',this"+');return false;">'+displayed_val+'<br /></a>');
	string=string.concat(displayed_val+'</tbody></table>');
	listfield.innerHTML=string;
	return true;
}
function getIframeHistorySkip(){
	//preskakovani historie zpusobene iframy
	if (typeof document.history_skip == 'undefined')
		document.history_skip=0;
	var history_iframes = document.getElementsByTagName('IFRAME');
	for (i=0;i<history_iframes.length;i=i+1){
		if (history_iframes[i].init_history_length)
			document.history_skip = document.history_skip + (window.history.length - history_iframes[i].init_history_length);
	}
	history_skip = document.history_skip;
	document.history_skip = null;
	return history_skip;
}
function FrameToWindow(){
	//vyskoceni z framu do celeho okna
	if (top!=self) top.location=self.location;
}
function WindowToFrame(toplocation){
	if (top==self) top.location=toplocation;
}
function searchComboChange(e,ctlboxid,secboxid){
	if (secboxid){
		if (e.value=='bt')
			document.getElementById(secboxid).style.display='';
		else
			document.getElementById(secboxid).style.display='none';
	}
	if ((e.value=='empty') || (e.value=='entered'))
		document.getElementById(ctlboxid).style.display='none';
	else
		document.getElementById(ctlboxid).style.display='';

}
// Create the AJAX request
function createRequestObject(){
	if(window.XMLHttpRequest){
		req = new XMLHttpRequest();
		if(req.overrideMimeType){ req.overrideMimeType('text/xml'); }
	}
	else if(window.ActiveXObject){
		try{ req = new ActiveXObject("Msxml2.XMLHTTP"); }
		catch(e){
			try{ req = new ActiveXObject("Microsoft.XMLHTTP"); }
			catch(e){}
		}
	}
	
	if(!req)
		return false;
	else
		return req;
}