
 $(document).ready(function(){
 
  $("a[name='szczegoly']").toggle(
  
    function(){
       
	   index = $(this).attr("id").replace("szczegoly","");
	   
      $("table[class='detTable']:eq("+index+")").css("display","block");
  
    },
	
	function(){
	
	 $("table[class='detTable']:eq("+index+")").css("display","none");
	
	}
  
  );
  
 
 $("li[name='pagelink'] a").click(function(){
 
   $("li[name='pagelink'] a").each(function(){
   
    $(this).parent().attr("class","back");
   
   });
   
    $("div[name='page']").each(function(){
   
    $(this).css("display","none");
   
   });

  $(this).parent().attr("class","front");
  
  var name = $(this).attr("name");
  
  $("#"+name).css("display","block");
 
 });

 //ZAPYTANIE
 
  zapytanie_o = "";
  
  $("div[name='zapytanie_div']").mouseenter(function(){
  
   $("a",this).css("display","block");
   $("a:eq(0)",this).css("display","none");
  
  });
  
  $("div[name='zapytanie_div']").mouseleave(function(){
  
   $("a",this).css("display","none");
   $("a:eq(0)",this).css("display","block");
  
  });
 
 $("a[name='zapytanieDni']").click(function(){
 

   $(".ui-widget-content[required='true']").each(function(){
					 
	if($(this).val() == ""){
					  
	  $(this).parent().next("div").css("display","none");
					   
					   
	}
					 
   }); 

 
  $( "#zapytanie_box1" ).dialog( "open" );
 
  zapytanie_o = $(this).attr("id");
 
 });

 
		$( "#zapytanie_box1" ).dialog({
			autoOpen: false,
			height: 350,
			width: 400,
			modal: true,
			buttons: {
				"Zapisz": function() {
					var bValid = true;
					
					 $(".ui-widget-content[required='true']").each(function(){
					 
					  if($(this).val() == ""){
					  
					    $(this).parent().next("div").css("display","block");
					   
					   bValid = false;
					   
					  }
					 
					 });
					 

					if ( bValid ) {
					
					    $( "#zapytanie_box1" ).dialog("close");
						$( "#dialogajax" ).dialog({modal: true});
						
						var zapytanie = $("#tresc_zapytanie").val();
						var email = $("#email_zapytanie").val();
						var tel = $("#telefon_zapytanie").val();
  
						link = document.location.toString();
						$.post("/ajax/zapytanie",{z:zapytanie,e:email,t:tel,o:zapytanie_o,l:link},function(html,stat){
                        
						 if(stat == "success"){
						 
						 $( "#dialogajax" ).dialog("close");
						 
		                  $( "#dialog" ).dialog({
			               modal: true,
			               buttons: {
				            Ok: function() {
					       $(this).dialog( "close" );
				           }
			              }
		                 });
						 
						 }
  
						});
  	
						
					}
				},
				"Anuluj": function() {
					$( this ).dialog( "close" );
				}
			},
			close: function() {
				//allFields.val( "" ).removeClass( "ui-state-error" );
			}
		});
 
 });
 
 function zmiana_parametru(kraj,wylot,hotel,wyzywienie,pokoj,dni,typ,id){
 
   if(typ == ""){
   
    typ = "/typ/2";
   
   }else{
   
    typ = "/typ/"+typ;
   
   }

   if(kraj == ""){
   
    kraj = "null";
   
   }
   //alert(window.location.hostname);
   
   if(id == 1){
 
  document.location.href = "/booking/stepone/id/1/kraj/"+kraj+"/wylot/"+wylot+"/hotel/"+hotel+"/wyzywienie/"+wyzywienie+"/pokoj/"+encodeURIComponent(pokoj)+"/dni/"+dni+typ;
  
   }else{
   
  document.location.href = "/booking/stepone/id/2/kraj/"+kraj+"/wylot/"+wylot+"/hotel/"+hotel+"/wyzywienie/"+wyzywienie+"/pokoj/"+encodeURIComponent(pokoj)+typ;
   
   }
  
 }

 function zmiana_parametru_pokoju_v1(kraj,wylot,hotel,wyzywienie,pokoj,dni,typ,id){

   
    typ = "/typ/2";


   if(kraj == ""){
   
    kraj = "null";
   
   }

   
   if(id == 1){
 
  document.location.href = "/booking/stepone/id/1/kraj/"+kraj+"/wylot/"+wylot+"/hotel/"+hotel+"/wyzywienie/"+wyzywienie+"/pokoj/"+encodeURIComponent(pokoj)+"/dni/"+dni+typ;
  
   }else{
   
  document.location.href = "/booking/stepone/id/2/kraj/"+kraj+"/wylot/"+wylot+"/hotel/"+hotel+"/wyzywienie/"+wyzywienie+"/pokoj/"+encodeURIComponent(pokoj)+typ;
   
   }
  
 }


 function zmiana_parametru_pokoju(kraj,wylot,hotel,wyzywienie,pokoj,dni,typ,id){

   
    typ = "/typ/2";


   if(kraj == ""){
   
    kraj = "null";
   
   }

   $.post("/ajax/sprawdz_konfiguracje.php",{k:kraj,w:wylot,h:hotel,wz:wyzywienie,p:pokoj,action:1},function(html,stat){
   
     if(html == 0){
       $.post("/ajax/sprawdz_konfiguracje.php",{k:kraj,w:wylot,h:hotel,wz:wyzywienie,p:pokoj,action:2},function(html,stat){
        split_w = html.split(";");
		wylot = split_w[1];
		wyzywienie = split_w[0];
		przeslij_link_stepone(kraj,wylot,hotel,wyzywienie,pokoj,dni,typ,id);
       });
     }else{
	    przeslij_link_stepone(kraj,wylot,hotel,wyzywienie,pokoj,dni,typ,id)
	 }

  });
  
 }
 
function przeslij_link_stepone(kraj,wylot,hotel,wyzywienie,pokoj,dni,typ,id){

     if(id == 1){
 
      document.location.href = "/booking/stepone/id/1/kraj/"+kraj+"/wylot/"+wylot+"/hotel/"+hotel+"/wyzywienie/"+wyzywienie+"/pokoj/"+encodeURIComponent(pokoj)+"/dni/"+dni+typ;
  
     }else{
   
      document.location.href = "/booking/stepone/id/2/kraj/"+kraj+"/wylot/"+wylot+"/hotel/"+hotel+"/wyzywienie/"+wyzywienie+"/pokoj/"+encodeURIComponent(pokoj)+typ;
   
     }

}
