/** skripty pro JARO-BALONY, (c) 2009 Marek Aufart, Jan Kovarik  */


$(document).ready(function(){
  $('.odkaz_cenik').click(function(){
    $(".cenikovy:visible").hide();
    $('div#' + $(this).attr('href').replace('_','')).show("slow");
    window.location.href = $(this).attr('href');
    return false;
  });
  //nacteni ceniku, pokud je v URL
  if (window.location.href.indexOf('#') != -1) {
  var cenik_url = window.location.href.split('#');
  $(".cenikovy:visible").hide();
  $("#" + cenik_url[1].replace('_','')).show("slow");
  }

$('#pocetlidi30').change(function () { $('#objednat30').attr('href','objednavka.php?let='+$(this).val()) });
$('#pocetlidi20').change(function () { $('#objednat20').attr('href','objednavka.php?let='+$(this).val()) });
  
//uprava ceny u letu z mest/mist
if ($('#lokalita-akce').length) {
	uprav_cenu_nahled($('#lokalita-akce').attr('title'));
}

$('select.#lokalita').live("change", function(){
	//window.location.href = '?let='+$('#let-cislo').val()+'&mesto='+$(this).val();
	var url = '?let='+$('#let-cislo').val()+'&mesto='+$(this).val()+" #objednavka_cena>*";
	$('#objednavka_cena').load(url, function(response, status, xhr) { //alert(url+"--"+response); 
	  if ($('#lokalita-akce').length) { uprav_cenu_nahled($('#lokalita-akce').attr('title')); }
		$('#objednavka_cena').hide();
		$('#objednavka_cena').fadeIn('slow');
	});
	return false;
});

});

function uprav_cenu_nahled(t) {
	$('#cenaletuobj').html(t+' Kč');
}

function jePrazdny(retezec) {
	for (var i=0; i<retezec.length; i++) {
	   var znak = retezec.charAt(i); 
	  if ((znak!=" ") && (znak!="\t") && (znak!="\n")) return false;
	}
	return true;
}

function isEmail(retezec) {
	reg_vyraz = /(.+)@(.+)\.(.+)/;
	return reg_vyraz.test(retezec);
}

function kontrola_vyhl() {
  var chyby = "";
  if (!isEmail(document.getElementById("email").value)) {
	 chyby += "Musíte správně vyplnit váš email\n";
	 document.getElementById("email").style.backgroundColor="#ff8888";
  } else { document.getElementById("email").style.backgroundColor="#ffffff"; }

  if (jePrazdny(document.getElementById("jmeno").value)) { 
	chyby += "Jméno nesmí být prázdné\n";
	document.getElementById("jmeno").style.backgroundColor="#ff8888";
  } else { document.getElementById("jmeno").style.backgroundColor="#ffffff"; } 

  if (jePrazdny(document.getElementById("prijmeni").value)) { 
	chyby += "Příjmení nesmí být prázdné\n";
	document.getElementById("prijmeni").style.backgroundColor="#ff8888";
  } else { document.getElementById("prijmeni").style.backgroundColor="#ffffff"; } 

  if (jePrazdny(document.getElementById("tel").value)) { 
	chyby += "Telefoní číslo nesmí být prázdné\n";
	document.getElementById("tel").style.backgroundColor="#ff8888";
  } else { document.getElementById("tel").style.backgroundColor="#ffffff"; } 

  if (jePrazdny(document.getElementById("ulice").value)) { 
	chyby += "Pole ulice nesmí být prázdné\n";
	document.getElementById("ulice").style.backgroundColor="#ff8888";
  } else { document.getElementById("ulice").style.backgroundColor="#ffffff"; } 

  if (jePrazdny(document.getElementById("mesto").value)) { 
	chyby += "Město nesmí být prázdné\n";
	document.getElementById("mesto").style.backgroundColor="#ff8888";
  } else { document.getElementById("mesto").style.backgroundColor="#ffffff"; } 

  if (jePrazdny(document.getElementById("psc").value)) { 
	chyby += "PSČ nesmí být prázdné\n";
	document.getElementById("psc").style.backgroundColor="#ff8888";
  } else { document.getElementById("psc").style.backgroundColor="#ffffff"; } 

  if (jePrazdny(document.getElementById("lokalita").value)) { 
	chyby += "Místo startu letu nesmí být prázdné\n";
	document.getElementById("lokalita").style.backgroundColor="#ff8888";
  } else { document.getElementById("lokalita").style.backgroundColor="#ffffff"; } 

  if (document.getElementById("csoucet").value!=8) { 
	chyby += "Máte napsat 8\n";
	document.getElementById("csoucet").style.backgroundColor="#ff8888";
  } else { document.getElementById("csoucet").style.backgroundColor="#ffffff"; } 

  if (!document.getElementById("vopsouhlas").checked) { 
	chyby += "Pro objednání musíte souhlasit s VOP\n";
	document.getElementById("vopsouhlas").style.backgroundColor="#ff8888";
  } else { document.getElementById("vopsouhlas").style.backgroundColor="#ffffff"; }

  if (chyby.length==0) return confirm("Opravdu provést objednání?");
  alert(chyby);
  return false;
}

function kontrola_rekl() {
  var chyby = "";
  if (!isEmail(document.getElementById("email").value)) {
	 chyby += "Musíte správně vyplnit váš email\n";
	 document.getElementById("email").style.backgroundColor="#ff8888";
  } else { document.getElementById("email").style.backgroundColor="#ffffff"; }

  if (jePrazdny(document.getElementById("firma").value)) { 
	chyby += "Pole firma nesmí být prázdné\n";
	document.getElementById("firma").style.backgroundColor="#ff8888";
  } else { document.getElementById("firma").style.backgroundColor="#ffffff"; } 

  if (jePrazdny(document.getElementById("ic").value)) { 
	chyby += "IČ nesmí být prázdné\n";
	document.getElementById("ic").style.backgroundColor="#ff8888";
  } else { document.getElementById("ic").style.backgroundColor="#ffffff"; } 

  if (jePrazdny(document.getElementById("dic").value)) { 
	chyby += "DIČ nesmí být prázdné\n";
	document.getElementById("dic").style.backgroundColor="#ff8888";
  } else { document.getElementById("dic").style.backgroundColor="#ffffff"; } 

  if (jePrazdny(document.getElementById("tel").value)) { 
	chyby += "Telefoní číslo nesmí být prázdné\n";
	document.getElementById("tel").style.backgroundColor="#ff8888";
  } else { document.getElementById("tel").style.backgroundColor="#ffffff"; } 

  if (jePrazdny(document.getElementById("ulice").value)) { 
	chyby += "Pole ulice nesmí být prázdné\n";
	document.getElementById("ulice").style.backgroundColor="#ff8888";
  } else { document.getElementById("ulice").style.backgroundColor="#ffffff"; } 

  if (jePrazdny(document.getElementById("mesto").value)) { 
	chyby += "Město nesmí být prázdné\n";
	document.getElementById("mesto").style.backgroundColor="#ff8888";
  } else { document.getElementById("mesto").style.backgroundColor="#ffffff"; } 

  if (jePrazdny(document.getElementById("kontaktni_osoba").value)) { 
	chyby += "Pole kontaktní osoba nesmí být prázdné\n";
	document.getElementById("kontaktni_osoba").style.backgroundColor="#ff8888";
  } else { document.getElementById("kontaktni_osoba").style.backgroundColor="#ffffff"; } 

  if (jePrazdny(document.getElementById("psc").value)) { 
	chyby += "PSČ nesmí být prázdné\n";
	document.getElementById("psc").style.backgroundColor="#ff8888";
  } else { document.getElementById("psc").style.backgroundColor="#ffffff"; } 

  if (jePrazdny(document.getElementById("lokalita").value)) { 
	chyby += "Místo startu letu nesmí být prázdné\n";
	document.getElementById("lokalita").style.backgroundColor="#ff8888";
  } else { document.getElementById("lokalita").style.backgroundColor="#ffffff"; } 

  if (document.getElementById("csoucet").value!=8) { 
	chyby += "Máte napsat 8\n";
	document.getElementById("csoucet").style.backgroundColor="#ff8888";
  } else { document.getElementById("csoucet").style.backgroundColor="#ffffff"; } 

  if (!document.getElementById("vopsouhlas").checked) { 
	chyby += "Pro objednání musíte souhlasit s VOP\n";
	document.getElementById("vopsouhlas").style.backgroundColor="#ff8888";
  } else { document.getElementById("vopsouhlas").style.backgroundColor="#ffffff"; }

  if (chyby.length==0) return confirm("Opravdu provést objednání?");
  alert(chyby);
  return false;
}

function kontrola_rez() {
    var chyby = "";
    
    if (jePrazdny(document.getElementById("rez_cislo").value)) {
        chyby += "Číslo letenky nesmí být prázdné\n";
        document.getElementById("rez_cislo").style.backgroundColor="#ff8888";
    } else { document.getElementById("rez_cislo").style.backgroundColor="#ffffff"; }
    
    if (jePrazdny(document.getElementById("rez_jmeno").value)) {
        chyby += "Vaše jméno nesmí být prázdné\n";
        document.getElementById("rez_jmeno").style.backgroundColor="#ff8888";
    } else { document.getElementById("rez_jmeno").style.backgroundColor="#ffffff"; }

    if (jePrazdny(document.getElementById("rez_tel").value)) {
        chyby += "Telefon nesmí být prázdný\n";
        document.getElementById("rez_tel").style.backgroundColor="#ff8888";
    } else { document.getElementById("rez_tel").style.backgroundColor="#ffffff"; }
    
    if (jePrazdny(document.getElementById("rez_vaha").value)) {
        chyby += "Prosím, vyplňte i Vaši přibližnou váhu\n";
        document.getElementById("rez_vaha").style.backgroundColor="#ff8888";
    } else { document.getElementById("rez_vaha").style.backgroundColor="#ffffff"; }
    
    if (chyby.length==0) return true;
    alert(chyby);
    return false;
}

