function zjisti(odkaz) {

  var potvrzeno = window.confirm("Opravdu chcete záznam vymazat???");

  if (potvrzeno) window.location.href = odkaz;
  
}

function splatky(){

  var cena = document.getElementById('cena_highlight').innerHTML;

  cena = cena.replace(/\s/g,'');

  cena = parseInt(cena);

  window.open('http://www.mt-nabytek.cz/webkalkulacka.php?cena='+cena, '_blank', 'toolbar=0, resizable=1, status=1, width=398, height=482');

}

function ukaz(id, id_nadpis){
  if (document.getElementById(id).style.display == 'inline') {
    document.getElementById(id).style.display = 'none';  
  }
  else {document.getElementById(id).style.display = 'inline';}
}

function parseUrl(url){
  var cleanUrl = (url + " ").replace(/[^a-zA-Z0-9]+/g, "-");
  return cleanUrl.slice(0, cleanUrl.length -1).toLowerCase();
}

function alias(url, output){
  sdiak = "áäčďéěíĺľňóô öŕšťúů üýřžÁÄČĎÉĚÍĹĽŇÓÔ ÖŔŠŤÚŮ ÜÝŘŽ";
  bdiak = "aacdeeillnoo orstuu uyrzAACDEEILLNOO ORSTUU UYRZ"; 
  tx = "";
  txt = url;
  for(p = 0; p < txt.length; p++)
  {
    if (sdiak.indexOf(txt.charAt(p)) != -1)
    {
      tx += bdiak.charAt(sdiak.indexOf(txt.charAt(p)));
    }
    else tx += txt.charAt(p);
  }
  document.getElementById(output).value = parseUrl(tx);
} 

function kontrola_delky(max, input){
  if (document.getElementById(input).value.length >= max){document.getElementById(input).style.borderColor = 'red';}
  else document.getElementById(input).style.borderColor = '#CCC';
}

function kontrola(){
  var chyba = 0;
  var chyba_email = 0;
  mail = /.+@.+\..+/;
  if (document.getElementById('krjmeno').value == ''){chyba = 1;}
  if (document.getElementById('prijmeni').value == ''){chyba = 1;}
  if (mail.test(document.getElementById('mail').value) == false){chyba = 1; chyba_email = 1;}
  if (document.getElementById('telefon').value == ''){chyba = 1;}
  if (document.getElementById('ulice').value == ''){chyba = 1;}
  if (document.getElementById('mesto').value == ''){chyba = 1;}
  if (document.getElementById('psc').value == ''){chyba = 1;}
  if (chyba == 1) {if (chyba_email == 1){alert('Neplatný formát emailové adresy, pozor na mezery. (neco@neco.tld)'); return false;} else {alert('Chybí povinné položky! Vyplňte je prosím!'); return false;}} else return true;
}

function kontrola_affilate(){
  var chyba = 0;
  var chyba_email = 0;
  mail = /.+@.+\..+/;
  if (document.getElementById('jmeno').value == ''){chyba = 1;}
  if (document.getElementById('prijmeni').value == ''){chyba = 1;}
  if (mail.test(document.getElementById('adresa').value) == false){chyba = 1; chyba_email = 1;}
  if (document.getElementById('telefon').value == ''){chyba = 1;}
  if (document.getElementById('web').value == ''){chyba = 1;}
  if (document.getElementById('popis').value == ''){chyba = 1;}
  if (chyba == 1) {if (chyba_email == 1){alert('Neplatný formát emailové adresy, pozor na mezery. (neco@neco.tld)'); return false;} else {alert('Chybí povinné položky! Vyplňte je prosím!'); return false;}} else return true;
}

function kontrola_velkoobchod(){
  var chyba = 0;
  var chyba_email = 0;
  mail = /.+@.+\..+/;
  if (document.getElementById('jmeno').value == ''){chyba = 1;}
  if (document.getElementById('prijmeni').value == ''){chyba = 1;}
  if (mail.test(document.getElementById('adresa').value) == false){chyba = 1; chyba_email = 1;}
  if (document.getElementById('telefon').value == ''){chyba = 1;}
  if (document.getElementById('popis').value == ''){chyba = 1;}
  if (chyba == 1) {if (chyba_email == 1){alert('Neplatný formát emailové adresy, pozor na mezery. (neco@neco.tld)'); return false;} else {alert('Chybí povinné položky! Vyplňte je prosím!'); return false;}} else return true;
}

function kontrola_reklamace(){
  var chyba = 0;
  var chyba_email = 0;
  mail = /.+@.+\..+/;
  if (document.getElementById('jmeno').value == ''){chyba = 1;}
  if (document.getElementById('prijmeni').value == ''){chyba = 1;}
  if (document.getElementById('objednavka').value == ''){chyba = 1;}
  if (mail.test(document.getElementById('adresa').value) == false){chyba = 1; chyba_email = 1;}
  if (document.getElementById('telefon').value == ''){chyba = 1;}
  if (document.getElementById('popis').value == ''){chyba = 1;}
  if (chyba == 1) {if (chyba_email == 1){alert('Neplatný formát emailové adresy, pozor na mezery. (neco@neco.tld)'); return false;} else {alert('Chybí povinné položky! Vyplňte je prosím!'); return false;}} else return true;
}

function kontrola_email(input){

  mail = /.+@.+\..+/;
  var chyba = 0;
  if (mail.test(document.getElementById('prijemce').value) == false) chyba = 1;
  if (mail.test(document.getElementById('adresat').value) == false) chyba = 1;
  if (chyba == 1) {alert('Neplatný formát emailové adresy, pozor na mezery. (neco@neco.tld)'); return false;} else return true;
}

function ajax(stranka, kam)
{

    var httpRequest;
    
    if(typeof window.ActiveXObject != 'undefined')
    {
        httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else
    {  
        httpRequest = new XMLHttpRequest();
    }
    httpRequest.open("GET", stranka, true);
    httpRequest.onreadystatechange= function () 
    {
        processRequest(httpRequest, kam) 
    };
    httpRequest.send(null);
}

function processRequest(httpRequest, kam)
{
    if (httpRequest.readyState == 4)
    {
        if(httpRequest.status == 200)
        {
            if (typeof kam == 'string')
            {
                document.getElementById(kam).innerHTML = httpRequest.responseText;
            }
            if (typeof kam == 'function')
            {
                kam(httpRequest.responseText);
            }
        }
        else
        {
            document.getElementById(kam).innerHTML = '';
        }
    }
    else
    {
        if (typeof kam == 'string' && kam != '')
        {
          //document.getElementById(kam).innerHTML = '<img id="wait" src="/images/wait.gif" alt="Načítám!">';
        }
    }
}

