function postback(udalost, frm)
{
   if(udalost == null) udalost = "";
   if(frm == null) frm = getE("form1");
   frm.udalost.value = udalost;
   frm.submit()
}

function MyWindowOpen(url,win_id,width,height,resizeable,scrollable)
{   
   xpos = (screen.width - width)/2;
   ypos = (screen.height - height)/2;       
   myWin = self.open(url,win_id,'top=' + ypos + ',left=' + xpos +',width='+width+',height='+height+',scrollbars='+scrollable+',resizable='+resizeable+',status=yes')
   myWin.focus();
   return myWin;
}

function AutoResize(width, height)
{
	var pridavok = 20
	var tbl1 = document.getElementById("limit")
	if (tbl1 == null) return

	if(!width || width == null) width = tbl1.offsetWidth + tbl1.offsetLeft * 2
	if(!height || height == null) height = tbl1.offsetHeight + tbl1.offsetTop * 2

	if(width == document.body.clientWidth && height == document.body.clientHeight) return

	widthavail = screen.availWidth
	heightavail = screen.availHeight
	if(width > widthavail) width = widthavail
	if(height > heightavail) height = heightavail
	var rezervaX = widthavail - width
	var rezervaY = heightavail - height
	if(pridavok > rezervaY) pridavok = rezervaY
	sur_x=(widthavail - width)/2;
	sur_y=(heightavail - height)/2;
	window.moveTo(sur_x, sur_y)

	var rozdielX = 0
	window.resizeTo(width, height + pridavok);
	rozdielX = width - document.body.clientWidth
	if(rozdielX > rezervaX) rozdielX = rezervaX

	var rozdielY = height - document.body.clientHeight
	if(rozdielY > rezervaY) rozdielY = rezervaY
	window.resizeBy(rozdielX, rozdielY)	
    window.moveBy(-rozdielX/2, -rozdielY/2)
}

function addStartEvent(func)
{
  var oldonload = window.onload;
  if (typeof window.onload != 'function') { window.onload = func; }
  else
  {
    window.onload = function()
    {
      if (oldonload) { oldonload(); }
      func();
    }
  }
}

function setMenuPos()
{
	DM.fromLeft=getHeadPos();
}

function getHeadPos()
{
	var pozice = findElement('head');
	return pozice.x;
}

function getE(id)
{
	return document.getElementById(id)
}

function getRadioValue(obj)
{
	for (var i = 0; i < obj.length; i++)
		if (obj[i].checked) return obj[i].value
	return ""
}

function setCookie(name, value, exp, path, domain, secure)
{
	if(name=='') return;
	var cookie=name+'='+escape(value);
	if(value=='')
	{
		cookie+='; expires='+new Date((new Date()).getTime()-1).toGMTString();//zmaz cookie
	}
	else
	{
		if(exp) cookie+='; expires='+new Date((new Date()).getTime()+exp*(1000*60*60)).toGMTString();//hod na milisec
		else cookie+='; expires='+new Date((new Date()).getTime()+(1000*60*60*24*365)).toGMTString();//rok na milisec
		if(path) cookie+='; path='+path;
		if(domain) cookie+='; domain='+domain;
		if(secure) cookie+='; secure';
	}
	document.cookie=cookie;
}

function getCookie(name, def)
{
	var cookies=document.cookie;
	if(cookies=='') return def;
	var from=cookies.indexOf(name+'=');
	if(from<0) return def;
	var to=cookies.indexOf(';',from);
	if(to<0) to=cookies.length;
	return unescape(cookies.substring(from+name.length+1,to));
}
