
function objednavka_forward(zmeny, url, zprava) {
  if (zmeny && confirm(zprava)) {
    window.location.href=url;
  }
  
  if (!zmeny) {
    window.location.href=url;
  }
}

function zmena() {
  document.getElementById('potvrdit_zmeny').style.border = '1px solid red';
  return 1;
}

function vlozDatum(textarea) {
  datum = new Date();
  with(datum){
    hod = getHours();
    min = getMinutes();
    
    den = getDate();
    mes = getMonth()+1;
    if (document.all) {
      rok = getYear();
    }
    else {
      rok = getYear() + 1900;
    }
  }
  textarea.value += "\n" + den + "." + mes + "." + rok + " (" + hod + ":" + min + ")" + "\n";
}










function omezitDodani(anone, cena_gpp_cz, cena_gpp_sk) {
  
  
  if (anone) {
    for (t = 0; t < document.formZakaznik.dodani.length; t++) {
      if (document.formZakaznik.dodani[t].value == 'gpp') {
        document.formZakaznik.dodani[t].checked = true;
        document.getElementById('dodani_gpp').innerHTML = cena_gpp_sk;
    
    // alert(anone);

      }
      else {
        //if (document.formZakaznik.dodani[t].value != 'ool' && document.formZakaznik.dodani[t].value != 'oop')
        if (document.formZakaznik.dodani[t].value != 'ool')
        document.formZakaznik.dodani[t].disabled = true;

      }
    }
  } 

  else {
    for (t = 0; t < document.formZakaznik.dodani.length; t++) {
      document.formZakaznik.dodani[t].disabled = false;
     
      // ja .. vypnout gpp u CR
     // if (document.formZakaznik.dodani[t].value == 'gpp')
     // document.formZakaznik.dodani[t].disabled = true;
     
    // alert(anone);
    
    }
    
    document.getElementById('dodani_gpp').innerHTML = cena_gpp_cz;
  }

}









function minusAplus(id, url) {
  document.getElementById('img_' + id).src = document.getElementById(id).style.display == 'none' ? url+'/minus.gif' : url+'/plus.gif';
  document.getElementById(id).style.display = document.getElementById(id).style.display == 'none' ? 'block' : 'none';
  
  return false;
}

function addFile(name) {
  var root=document.getElementById('foto').getElementsByTagName('tr')[0].parentNode; 
  var oR = cE('tr');
  var oC = cE('td');
  var oI = cE('input'); 
  var oS = cE('span'); 
  cA(oI,'type','file');
  cA(oI,'name', name + '[]');
  
  oS.style.cursor = 'pointer';
  oS.onclick = function() {
    this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode);
    //document.getElementById('foto_dalsi').style.display = 'inline';
    
  }
  oS.appendChild(document.createTextNode(' Zrušit')); 
  oC.appendChild(oI);
  oC.appendChild(oS);
  oR.appendChild(oC);
  root.appendChild(oR);
  /*
  if (count == 9) {
    document.getElementById('foto_dalsi').style.display = 'none';
  }
  */
  //return count;
}

function cE(el) {
  this.obj = document.createElement(el); 
  return this.obj; 
} 

function cA(obj,att,val) {
  obj.setAttribute(att,val); 
return ;
} 

/*
function addFoto(count) {
  count++;
  if (count < 10) {
    // zaloha puvodnich hodnot
    for (t = 1; t < count; t++) {
      hodnoty[t] = document.getElementById('foto_' + t).value;
      document.getElementById('pokus').innerHTML += hodnoty[t] + '<br />';
    }
    // ' + count + ' ... myslim, ze pole bude lepsi
    var fakeFileUpload = document.createElement('div');
        fakeFileUpload.className = 'fakefile';
        fakeFileUpload.appendChild(document.createElement('input'));
    document.getElementById('foto').appendChild(document.createElement('input'));
    
    '<input type="file" name="foto[]" /><br />';
    
    // obnova puvodnich hodnot
    for (t = 1; t < count; t++) {
      document.getElementById('foto_' + t).value = hodnoty[t];
    }
    
    if (count == 9) {
      document.getElementById('foto_dalsi').style.display = 'none';
    }
  }
  
  return count;
}
*/

function checkni(prefix, ids) {
  for (t=1; t < checkni.arguments.length; t++) {
    if (document.getElementById(prefix + '_' + checkni.arguments[t]).checked) {
      document.getElementById(prefix + '_' + checkni.arguments[t]).checked = false;
    }
    else {
      document.getElementById(prefix + '_' + checkni.arguments[t]).checked = true;
    }
  }
}

function kontrola(formular) {
  var status = 0;
  var globStatus = 0;
  
  for (t=1; t < kontrola.arguments.length; t++) {
    status = 0;
    // osetreni checkboxu
    if (eval('formular.' + kontrola.arguments[t] + '.type') == 'checkbox') {
      if (!eval('formular.' + kontrola.arguments[t] + '.checked')) {
        status = 1;
      }
    }
    else {
      // zbyle elementy (text, textarea, password)
      var hodnota = eval('formular.' + kontrola.arguments[t] + '.value');
      
      switch (eval('formular.' + kontrola.arguments[t] + '.type')) {
      case 'text':
        if (isBlank(hodnota)) {
          status = 2;
        }
        else {
          switch (kontrola.arguments[t]) {
          case 'email':
            if (!isEmail(hodnota)) {
              status = 21;
            }
            break;
            case 'telefon':
            //todo
            break;
          }
        }
        break;
      case 'textarea':
        if (isBlank(hodnota)) {
          status = 3;
        }
        break;
      case 'password':
        if (hodnota == '') {
          status = 4;
        }
        break;
      }
    }
    if (status) {
      eval('formular.'+ kontrola.arguments[t] + '.style').border = '1px solid red';
      globStatus = 1;
    }
    else {
      eval('formular.'+ kontrola.arguments[t] + '.style').border = '1px solid green';
    }
  }
  
  if (globStatus) {
    //alert('Formulář je chybně vyplněný!');
    alert('Některé informace chybí nebo jsou chybně vyplněny!');
    return false;
  }
  
  return true;
}

 
function isBlank(val) {
  if(val == null) {
    return true;
  }
  
  for (var i=0; i < val.length; i++) {
    if ((val.charAt(i) != ' ') && (val.charAt(i) != "\t") && (val.charAt(i) != "\n") && (val.charAt(i) != "\r")) {
      return false;
    }
  }
   
  return true;
}

function isEmail(val) {
  var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; 
  return filter.test(val); 
} 


