var productsPrices = [];

$(document).ready(function(){
  // selectboxy
  $("select[name=yearOfBirth]").selectbox();

  // checkboxy
  $(".sex-group input[type=radio]").custCheckBox({wrapperclass: 'sex-group'});
  $(".tests-group input[type=checkbox]").custCheckBox({wrapperclass: 'tests-group'});
  
  // editace mesta
  $("input.yearOfBirth, input.city").focus(function(){
      var input = $(this);
      
      if (input.hasClass("default")){
        input.val("");
        input.removeClass("default");
      }  
  });
  
  $("input.yearOfBirth, input.city").blur(function(){
      var input = $(this);
      
      if (input.val() == "") {
        input.addClass("default");
        input.val(input.attr("title"));
      }
      
  });
  
  // bubliny chybove a validace
 
  $("form.tests").submit(function(e){
    var form = e.target;
    
    // POHLAVI
    if ($("input[name=sex]:checked", form).length == 0) {
      var el = $($("input[name=sex]", form).get(0));
      errorTip(el.prev(), el.prev(), "Neuvedli jste své pohlaví", "bottomLeft", "topRight");
      return false;
    }
    
    // ROK NAROZENI
    if ($("select[name=yearOfBirth]", form).val() == "") {
      var el = $($("select[name=yearOfBirth]", form).get(0));
      errorTip(el.prev().prev(), el.prev().prev(), "Neuvedli jste rok narození", "bottomLeft", "topLeft");
      return false;
    }
    
    // MESTO
    if ($("input[name=city]", form).length > 0 &&
        ($.trim($("input[name=city]", form).val()) == "" ||
        $("input[name=city]", form).hasClass("default"))) {
      var el = $($("input[name=city]", form).get(0));
      errorTip(el, el, "Neuvedli jste město", "bottomLeft", "topLeft");
      return false;
    }
    
  });
  function isdefined( variable)
{
    return (typeof(window[variable]) == "undefined")?  false: true;
}

  // pocitani ceny
  $(".extended-profiles .test-online-calaculate").bind("onChange", function(e, d){
   
    var price = 0; // zakladni profil
    try {
      var disc = discount;
    } catch(e) {
      var disc = 0;
    }
    
    for(var id in productsPrices) {
    	if ($("#product" + id).is(":checked")) price += productsPrices[id];
    }
    
    $(".extended-profiles .total-price").text(price);
    $(".extended-profiles .total-price-discount").text(price - disc);
  });
  
});
