/**
 * 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()




/**
 * Zjisti jestli hodnota polozky je cislo.
 *
 * @param item Polozka
 * @return Vraci true pri uspechu
 */
function is_numeric(item)
{
  if (item.value != "")
  { // neni prazdna
  	re = new RegExp("^[0-9]+$");

  	if  (!re.test(item.value))
  	{
  	  return false;
  	}
  }

  return true;
} // is_numeric()


/**
 * 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()


/**
 * Prida novy vstup pro vlozeni obrazku.
 */
function pridat()
{
  var obj = document.getElementById('fotky');

  newDIV = document.createElement('div');

  newINPUT = document.createElement('input');
  newINPUT.setAttribute('name', 'images[]');
  newINPUT.setAttribute('type', 'file');
  newINPUT.setAttribute('size', '80');
  //newINPUT.setAttribute('class', 'file');

  newA = document.createElement('a');
  newA.onclick = new Function('odebrat(this); return false;');
  newA.setAttribute('title', 'Odebrat tento radek');
  newA.setAttribute('href', '#');
  newTextA = document.createTextNode(' odebrat');

  newDIV.appendChild(newINPUT);
  newA.appendChild(newTextA);
  newDIV.appendChild(newA);

  obj.appendChild(newDIV);

  //alert('ahoj');
} // pridat()


/**
 * Odebere novy vstup pro vlozeni obrazku.
 */
function odebrat(obj)
{
  var parent = obj.parentNode;

  while (parent.hasChildNodes()) {
	  parent.removeChild(parent.childNodes[0]);
  }

  parent.parentNode.removeChild(parent);
} // odebrat()

