/**
 * Otevre nove okno a zadanych rozmerech.
 * Nastavenim width a height na 0 se otevre okno na plnou obrazovku.
 *
 * @param name Nazev noveho okna
 * @param url Adresa okna
 * @param width Sirka okna
 * @param height Vyska okna
 * @param tools Zobrazeni nastrojove listy
 */
function openWin(name, url, width, height, tools)
{
  var parameters = "";

  var max_width  = screen.availWidth;
  var max_height = screen.availHeight;

  var top  = (screen.height - height) / 2;
  var left = (screen.width - width) / 2;

  if (width <= 0 || height <= 0 || width == null || height == null ||
      width > max_width || height > max_height)
  {
    width  = max_width;
    height = max_height;

    top  = 0;
    left = 0;
  }

  parameters += "width="+width+"px, height="+height+"px, ";
  parameters += "top="+top+"px, left="+left+"px, "

  if (!tools)
  {
    parameters += "toolbar=yes, menubar=yes, location=yes, directories=yes, ";
  }
  else
  {
    parameters += "toolbar=no, menubar=no, location=no, directories=no, ";
  }

  parameters += "status=yes, scrollbars=yes, resizable=yes";

  var win = window.open(url, name, parameters);

  win.moveTo(left, top);
  win.resizeTo(width, height);
  win.focus();
} // openWin()


/**
 * Otevre novy dialog a zadanych rozmerech.
 * Nastavenim width a height na 0 se otevre okno na plnou obrazovku.
 *
 * @param name Nazev noveho okna
 * @param url Adresa okna
 * @param width Sirka okna
 * @param height Vyska okna
 */
function openDialog(name, url, width, height)
{
  var parameters = "";

  var max_width  = screen.availWidth;
  var max_height = screen.availHeight;

  var top  = (screen.height - height) / 2;
  var left = (screen.width - width) / 2;

  if (width <= 0 || height <= 0 || width == null || height == null ||
      width > max_width || height > max_height)
  {
    width  = max_width;
    height = max_height;

    top  = 0;
    left = 0;
  }

  parameters += "width="+width+"px, height="+height+"px, ";
  parameters += "top="+top+"px, left="+left+"px, "
  parameters += "toolbar=no, menubar=no, location=no, directories=no, ";
  parameters += "status=no, scrollbars=no, resizable=no";

  var win = window.open(url, name, parameters);

  win.moveTo(left, top);
  win.resizeTo(width, height);
  win.focus();
} // openDialog()


/**
 * Zavre aktualni okno a preda fokus rodici.
 *
 */
function closeWin()
{
  var parent = window.opener;
  parent.focus();
  window.close();
} // closeWin()




var classname; // globalni uloziste predesleho nazvu tridy


/**
 * Nastavi tridu danemu elementu.
 *
 * @param object Ukazatel na element
 * @param newclassname Nove jmeno tridy
 */
function setClass(object, newclassname)
{
  classname = object.className;

  object.className = newclassname;
} // setClass()


/**
 * Zrusi nastaveni tridy a vrati zpet starou.
 *
 * @param object Ukazatel na element
 */
function resetClass(object)
{
  object.className = classname;
} // resetClass()




/**
 * Ziska ukazatel na nejblizsiho rodice se zadanym tagem.
 *
 * @param parent Ukazatel na aktualni objekt
 * @param tag Nazev tagu
 */
function get_parent_tag(parent, tag)
{
  do
  {
	  parent = parent.parentNode;
  }
  while (parent.tagName != tag);

  return parent;
} // get_parent_tag()



/**
 * Zobrazi skryty element.
 *
 * @param id Identifikator elementu
 */
function show(id)
{
  var elem = document.getElementById(id);

  elem.className = 'shown';
} // show()


/**
 * Skryje zobrazeny element.
 *
 * @param id Identifikator elementu
 */
function hide(id)
{
  var elem = document.getElementById(id);

  elem.className = 'hidden';
} // hide()


/**
 * Zobrazi skryty element a obracene.
 *
 * @param id Identifikator elementu
 */
function show_hide(id)
{
  var elem = document.getElementById(id);

  if (elem.className == 'shown')
  {
    elem.className = 'hidden';
  }
  else
  {
    elem.className = 'shown';
  }
} // show_hide()
