/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function validategalerieForm(form) {
  var pocet = form.obrazku.value;
  for(i=1;i<=pocet;i++) {
      var item = form["obrazek"+i];
      empty = true;
      if(item.value!="") {
        pole  = item.value.split(".");
        if(pole.length<2) {
          alert("V názvu souboru chybí přípona");
          item.focus();
          return false;
        }
        polelast = pole[pole.length-1];
        if(polelast.toUpperCase() != "JPG") {
          alert("Vyberte soubor typu .jpg");
          item.focus();
          return false;
        }
      }
      if(!empty && item.value=="") {
        alert("Není uveden soubor s obrázkem.");
        item.focus();
        return false;
      }
  }  
  return true;
}



function addRow()
{
  var tbl = document.getElementById('obrazky');
  var lastRow = tbl.rows.length;
  // if there's no header row in the table, then iteration = lastRow + 1
  document.galerieForm.obrazku.value++;
  var iteration = document.galerieForm.obrazku.value;  
  var row = tbl.insertRow(lastRow);
  // left cell
  var cellLeft = row.insertCell(0);
  var textNode = document.createTextNode('Foto '+ iteration+" :");
  cellLeft.appendChild(textNode);
  // right cell
  var cellRight = row.insertCell(1);
  var el = document.createElement('input');
  el.type = 'file';
  el.name = 'obrazek' + iteration;  
  cellRight.appendChild(el);
  lastRow = tbl.rows.length;
  row = tbl.insertRow(lastRow);
  cellLeft = row.insertCell(0);
  textNode = document.createTextNode('Popis '+ iteration+" :");
  cellLeft.appendChild(textNode);
  // right cell
  cellRight = row.insertCell(1);
  el = document.createElement('input');
  el.type = 'text';
  el.name = 'popis' + iteration;  
  cellRight.appendChild(el);


}

