$(document).ready(function() {
  $(".fotogalerie a").lightBox();

  //$("a:not([@href^=http://www.profi-kancelar.cz])").not("[href^=#]").not("[href^=mailto:]")
  //.addClass("out-link")
  //.attr({
  //  title:"Odkaz do nového okna"
  //})
  //.attr({
  //  target: "_blank"
  //});

  $(".popup")
  .addClass("out-link")
  .attr({
    title:"Odkaz do nového okna"
  })
  .attr({
    target: "_blank"
  });

  // napiste nam
  var $input1 = "#jmeno";
  var $textik1 = "Vaše jméno...";

  if (!$($input1).attr("value")) {
    $($input1).attr("value", $textik1);
  }

  $($input1).blur(function () {
    if (!$(this).attr("value")) {
      $(this).attr("value", $textik1);
    }
  })
  $($input1).focus(function () {
    if ($(this).attr("value") == $textik1) {
      $(this).attr("value", "");
    }
  })

  var $input2 = "#email";
  var $textik2 = "Váš e-mail...";

  if (!$($input2).attr("value")) {
    $($input2).attr("value", $textik2);
  }

  $($input2).blur(function () {
    if (!$(this).attr("value")) {
      $(this).attr("value", $textik2);
    }
  })
  $($input2).focus(function () {
    if ($(this).attr("value") == $textik2) {
      $(this).attr("value", "");
    }
  })

  var $input3 = "#text";
  var $textik3 = "Text zprávy...";

  if (!$($input3).attr("value")) {
    $($input3).attr("value", $textik3);
  }

  $($input3).blur(function () {
    if (!$(this).attr("value")) {
      $(this).attr("value", $textik3);
    }
  })
  $($input3).focus(function () {
    if ($(this).attr("value") == $textik3) {
      $(this).attr("value", "");
    }
  })

var $input4 = "#telefon";
  var $textik4 = "Váš telefon...";

  if (!$($input4).attr("value")) {
    $($input4).attr("value", $textik4);
  }

  $($input4).blur(function () {
    if (!$(this).attr("value")) {
      $(this).attr("value", $textik4);
    }
  })
  $($input4).focus(function () {
    if ($(this).attr("value") == $textik4) {
      $(this).attr("value", "");
    }
  })

  // produkt - prepocitani ceny Ajax
  $("#form-moje #odeslat").click(function() {
    if (isValidEmail($("#email").val()) == false) {
      alert('Neplatná nebo nezadaná emailová adresa.');
      return false;
    }
    return true;
  });

  $("#form-moje .prepocitat").click(function() {
    prepocitat();
  });

  $("#form-moje .polozka span").click(function() {
    
    polozka = $(this).parent().children('input');
    
    if (polozka.attr('checked')) {
      //if (polozka.attr('type') == 'checkbox') {
      polozka.attr('checked', false);
    //alert('odskrtnout');
    //}
    } else {
      polozka.attr('checked', true);
    }

    prepocitat();
  });


});

function isValidEmail(str) {
  return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

function prepocitat() {
  // vstupni hodnoty z formu
  var cesta = $("input[name='path']").val();
  var $form_fields = $('#form-moje').serialize();

  // zavolani php skriptu a zmena ceny
  $.post(cesta + "tags/mojeprofi/prepocitani-ceny-ajax.php",
    $form_fields,
    function(cena){
      $("#cena").html(cena);
    });
}

