$(document).ready(function(){
 $("#dodaci_adresa").hide();
    
  $("#ship_same").click(function(){
     var dodaci =  $(this).val();
     var test = 0;
     if (this.checked ){
        test = 11;
     } else {
        test = 22;
     }
     //alert(test);
    if (test == 11){
          $("#dodaci_adresa").slideDown(500);
       } else {
          $("#dodaci_adresa").slideUp(500);
       }
       
     });
// informace pred odeslanim objednavky
$("#obj_odeslat").click(function(){
  var chyba = 0;
  var hlaska = "Před odesláním objednávky prosím opravte následující chyby:\n\n"
  var testinput =  $("#telephone").val();
    if (testinput == '') {chyba = 1; hlaska = hlaska  + "Vyplňte prosím telefonní číslo\n";}
  testinput =  $("#email_address").val();
    if (testinput == '') {chyba = 1; hlaska = hlaska  + "Vyplňte prosím Vaši emailovou adresu\n";}
  testinput =  $("#firstname").val();
    if (testinput == '') {chyba = 1; hlaska = hlaska  + "Vyplňte prosím Vaše jméno\n";}
  testinput =  $("#lastname").val();
    if (testinput == '') {chyba = 1; hlaska = hlaska  + "Vyplňte prosím příjmení\n";}
   testinput =  $("#street_address").val();
    if (testinput == '') {chyba = 1; hlaska = hlaska  + "Vyplňte prosím ulici\n";}
  testinput =  $("#city").val();
    if (testinput == '') {chyba = 1; hlaska = hlaska  + "Vyplňte prosím město\n";}       

// kontrola fakturační adresy
 ship_hodnota =  $('input[name=ship_same]:checked').val();
   if (ship_hodnota == 'on'){
     testinput =  $("#ship_firstname").val();
        if (testinput == '') {chyba = 1; hlaska = hlaska  + "Vyplňte prosím Vaše jméno v dodací adrese\n";}
     testinput =  $("#ship_lastname").val();
        if (testinput == '') {chyba = 1; hlaska = hlaska  + "Vyplňte prosím příjmení v dodací adrese\n";}
     testinput =  $("#ship_street_address").val();
        if (testinput == '') {chyba = 1; hlaska = hlaska  + "Vyplňte prosím ulici v dodací adrese\n";}
     testinput =  $("#ship_city").val();
        if (testinput == '') {chyba = 1; hlaska = hlaska  + "Vyplňte prosím město v dodací adrese\n";}
     testinput =  $("#ship_postcode").val();
        if (testinput == '') {chyba = 1; hlaska = hlaska  + "Vyplňte prosím PSČ v dodací adrese\n";}           
      }
  var doprava = $('.shipping:checked').val();
   // alert (doprava);  
 // var obsah =  $('.paymentr:checked').val();
   switch($('.paymentr:checked').val()){
      case 'cod': var platba = "dobírka"; break;
      case 'flat': var platba = "dobírka"; break;
      case 'table': var platba = "dobírka"; break;
      case 'moneyorder': var platba = "převodem";  break;
      default: var platba = 1; chyba = 1; hlaska =  hlaska + "Vyberte prosím způsob platby.\n";
    }
    
    
    
 
   if (chyba == 1){
     alert(hlaska);
     return false;
   } else{
   
   pokracovat = confirm("Vaše objednávka bude nyní odeslána.\nPokud chcete ještě upravit nebo doplnit údaje, použijte tlačítko \"Zrušit\", pak můžete údaje upravit. ");
   if(pokracovat) 
   {
    return true;
   } else
   {
   return false;
   }
    //return false;
 }
});  
// vertikální centrovani obrazku
    $(".pl_img img").each(function(){
      var h = 0;
      h = $(this).height();
      var $newmargin = (124 - h)/2;
   	});

    
    $("#item_select").change(function(){
           var coJeVybrano = $("#item_select option:selected").val();
           $("#hodnota").text(coJeVybrano);
      });
    $("#odkaz").click(function(){
       $("#item_select").addOption("4", "item4", false);
        var $newvyrobce =  $("#novy_vyrobce").val();
        //var $newvyrobce =  $("input[@name=novy_vyrobce]").val(); ma fungovat ale nefuguje:-(
        $.get("/pecha/jquery/ajax/stranka.php",{ vyrobce: $newvyrobce}, function(vystup){
           alert("Soubor vrátil: " + vystup);
          // $("#select").html(vystup);
           //vystup;
            });
      });
      
    $("#odkaz2").click(function(){
       $("#item_select").addOption("4", "item4", false); // pouze přidá položku seznamu viz soubor select.js
      });

    $("#pridej").click(function(){
       $("#vyrobce").html("<input type=\"text\" name=\"novy_vyrobce\" id=\"novy_vyrobce\" />");
      });      
          
});

$(document).ready(function(){
    $("#kpokladne").html("<img src=\"templates/zahradnik/buttons/czech/button_checkout.gif\" />");
    $("#schovany").hide();
    $("#shipping_adress_skryvany").hide();
    $("#acountboxyes").hide();
    $("#new_adress").hide();
    
      $("#kpokladne").click(function(){
          $("#schovany").show();
          return false;
      });
      
      
      // zobrazi a skryje tabulku pro zadani jine dodaci adresy
      $("#row").click(function(){
          //$("#create_account3_loginbox").toggle(500);
          $("#shipping_adress_skryvany").toggle();
      });
      // zobrazi a skryje pole pro zadání hesla     
      $("#createaccount").click(function(){      
          $("#acountboxyes").toggle();
      }); 
      
       $("#prazdny").click(function(){
          //$("#create_account3_loginbox").toggle(500);
          $("#new_adress").toggle();
          $("#adresar").toggle();
      });     
     
    
    if ( $("input[name=shipping]:checked").val() == "flat_flat") {
    //alert("Soubor vrátil: " + $str);
    $("#cod").hide();
    $("#moneyorder").hide();
    $("#cop").show();
    $("#radcop").attr("checked", "checked"); 

    }
    
        if ( $("input[name=shipping]:checked").val() == "table_table") {
        $("#cod").show();
        $("#moneyorder").show();
        $("#cop").hide();
        $("#radcod").attr("checked", "checked"); 
    }

  $(".shipping").click(function(){
    $str = $("input[name=shipping]:checked").val();
   
    
    if ( $("input[name=shipping]:checked").val() == "flat_flat") {
    //alert("Soubor vrátil: " + $str);
    $("#cod").hide();
    $("#moneyorder").hide();
    $("#cop").show();
    $("#radcop").attr("checked", "checked"); 

    }
    
    if ( $("input[name=shipping]:checked").val() == "table_table") {
        $("#cod").show();
        $("#moneyorder").show();
        $("#cop").hide();
        $("#radcod").attr("checked", "checked"); 
    }
        
  });
  
   $(".pl-vypis").each(function(){
		var height = 0;			
		$(".pl-name", this).each(function(){
			$(this).css("height", "auto");
			height = this.offsetHeight > height ? this.offsetHeight : height;			
		}).each(function(){
			$(this).css("height", height + "px");
		
		});		
	}); 

   $(".pl-vypis").each(function(){
		var height = 0;			
		$(".pl-img", this).each(function(){
			$(this).css("height", "auto");
			height = this.offsetHeight > height ? this.offsetHeight : height;			
		}).each(function(){
			$(this).css("height", height + "px");
		
		});		
	}); 

   $(".pl-vypis").each(function(){
		var height = 0;			
		$(".pl_li", this).each(function(){
			$(this).css("height", "auto");
			height = this.offsetHeight > height ? this.offsetHeight : height;			
		}).each(function(){
			$(this).css("height", height + "px");
		
		});
	}); 	

    $(".pl-vypis").each(function(){
		var height = 0;			
		$(".sp_produkt", this).each(function(){
			$(this).css("height", "auto");
			height = this.offsetHeight > height ? this.offsetHeight : height;			
		}).each(function(){
			$(this).css("height", height + "px");
		
		});
	}); 		

});

function remember(selector){
    $(selector).each(
    	function(){
    	
    		//if this item has been cookied, restore it
    		var name = $(this).attr('name');
    		if( $.cookie( name ) ){
    			if( $(this).is(':checkbox') ){
    				$(this).attr('checked',$.cookie( name ));
    			}else{
    				$(this).val( $.cookie(name) );
    			}
    										
    		}
    		
    		//assign a change function to the item to cookie it
    		$(this).change(
    			function(){
    				if( $(this).is(':checkbox') ){
    					$.cookie(name, $(this).attr('checked'), { path: '/', expires: 365 });
    				}else{
    					$.cookie(name, $(this).val(), { path: '/', expires: 365 });
    				}
    			}
    		);
    	}
    );
}


