﻿jQuery(document).ready(function(){

// poczatek

				// Tabs
				$('#tabs').tabs();
	

$('#show_all_arr').click(function(){

var show_all_arr=$("#all_arr").val();
if (show_all_arr=='0') 
{
var kr_prz=$("#arr_combo").val();


$.ajax({
   type: "GET",
   url: "m_arr_all_coutries.php",
   data: "all="+show_all_arr,
    error: function(){
        alert('Blad polaczenia z baza danych');
    },success: function(msg){
$("#arr_combo").html(msg);}
});

$("#all_arr").val("1");
show_all_arr=$("#all_arr").val();
$.ajax({
   type: "GET",
   url: "m_apt_list2.php",
   data: "all="+show_all_arr+"&country="+kr_prz+"&language=<?echo($language);?>",
    error: function(){
        alert('Blad polaczenia z baza danych');
    },success: function(msg2){
$("#arr_apt_list").html(msg2);
$("#arr_combo").selectOptions(kr_prz);
$("#show_all_arr").text("Pokaż tylko popularne");

}
});
} // koniec petli show_all_arr==0
else
{
var kr_prz=$("#arr_combo").val();


$.ajax({
   type: "GET",
   url: "m_arr_all_coutries.php",
   data: "all="+show_all_arr,
    error: function(){
        alert('Blad polaczenia z baza danych');
    },success: function(msg){
$("#arr_combo").html(msg);}
});
$("#all_arr").val("0");
show_all_arr=$("#all_arr").val();

$.ajax({
   type: "GET",
   url: "m_apt_list2.php",
   data: "all="+show_all_arr+"&country="+kr_prz+"&language=<?echo($language);?>",
    error: function(){
        alert('Blad polaczenia z baza danych');
    },success: function(msg2){
$("#arr_apt_list").html(msg2);
$("#show_all_arr").text("Więcej krajów i miast");
$("#arr_combo").selectOptions(kr_prz);
}

});


} // koniec else 




});


//koniec


$('#show_all_dep').click(function(){


var show_all_dep=$("#all_dep").val();

if (show_all_dep=='0') 
{
var kr_wyl=$("#dep_combo").val();

$.ajax({
   type: "GET",
   url: "m_dep_all_coutries.php",
   data: "all="+show_all_dep,
    error: function(){
        alert('Blad polaczenia z baza danych');
    },success: function(msg){
$("#dep_combo").html(msg);}
});


//$("#dep_combo").val(str);

$("#show_all_dep").text("Pokaż tylko popularne");
$("#all_dep").val("1");
show_all_dep=$("#all_dep").val();

$.ajax({
   type: "GET",
   url: "m_apt_list1.php",
   data: "all="+show_all_dep+"&country="+kr_wyl+"&language=<?echo($language);?>",
    error: function(){
        alert('Blad polaczenia z baza danych');
    },success: function(msg2){
$("#dep_apt_list").html(msg2);
$("#dep_combo").selectOptions(kr_wyl);

}
});
//



} // koniec petli show_all_dep==0

else

{
var kr_wyl=$("#dep_combo").val();

$.ajax({
   type: "GET",
   url: "m_dep_all_coutries.php",
   data: "all="+show_all_dep,
    error: function(){
        alert('Blad polaczenia z baza danych');
    },success: function(msg){
$("#dep_combo").html(msg);}
});

$("#show_all_dep").text("Więcej krajów i miast");
$("#all_dep").val("0");
show_all_dep=$("#all_dep").val();

$.ajax({
   type: "GET",
   url: "m_apt_list1.php",
   data: "all="+show_all_dep+"&country="+kr_wyl+"&language=<?echo($language);?>",
    error: function(){
        alert('Blad polaczenia z baza danych');
    },success: function(msg2){
$("#dep_apt_list").html(msg2);
$("#dep_combo").selectOptions(kr_wyl);
}

});


} // koniec else 


});

$('#advanced').hide();

$('#show_adv').click(function() {
$('#advanced').toggle();
});

   var msg="";
    $("form").submit(function() {
      if ($("#departure_port").val() == "") {
        msg="Wybierz lub wpisz port wylotu!\n";
      }
      
      if ($("#arrival_port").val() == "") {
        msg=msg+"Wybierz lub wpisz port docelowy!\n";
      }
if ($("#dep_date").val() == "") {
        msg=msg+"Podaj datę wylotu!\n";
      }

if ($("#arr_date").val() == "") {
        msg=msg+"Podaj datę powrotu!\n";
      }


if (msg!="") {
alert(msg);
msg="";
return false;      
      }
      
      return true;
    });



$('#oneway').click(function() {

    $('#arr_date').attr("disabled", true);
    $('#arr_date').hide();
       }); 

  $('#return').click(function() {
$('#arr_date').removeAttr("disabled");
$('#arr_date').show();
       }); 


  $('#copy_flights').click(function() {

var city=$('#arrival_port').val();


$('#city').val(city.substr(0,strpos(city, '[', 0)-1));


$('#checkin').val($('#dep_date').val());
$('#checkout').val($('#arr_date').val());
       }); 



$('#departure_port').click(function() {
$('#departure_port').val("");
});

$('#arrival_port').click(function() {
$('#arrival_port').val("");
});

$('#arrival_port_2').click(function() {
$('#arrival_port_2').val("");
});

$("span.apt").live("click", function(){
  $("#departure_port").val($(this).text() );
  $('#dep_port').dialog("close");
$("#adt_count").show();
$("#child_count").show();
$("#inf_count").show();
$("#flex_date").show();
$("#specific_airline1").show();

});


$("span.apt2").live("click", function(){
  $("#arrival_port").val($(this).text() );
  $('#arr_port').dialog("close");
$("#modal").hide();
$("#adt_count").show();
$("#child_count").show();
$("#inf_count").show();
$("#flex_date").show();
$("#specific_airline1").show();

});

$("span.apt3").live("click", function(){
  $("#arrival_port_2").val($(this).text() );
  $('#arr_port_2').dialog("close");
$("#modal").hide();
$("#adt_count").show();
$("#child_count").show();
$("#inf_count").show();
$("#flex_date").show();
$("#specific_airline1").show();


});



$("#departure_port").autocomplete(dep_apt_table);
$("#arrival_port").autocomplete(dep_apt_table);

$("#departure_port2").autocomplete(dep_apt_table);
$("#arrival_port2").autocomplete(dep_apt_table);

$("#departure_port3").autocomplete(dep_apt_table);
$("#arrival_port3").autocomplete(dep_apt_table);

$("#departure_port4").autocomplete(dep_apt_table);
$("#arrival_port4").autocomplete(dep_apt_table);

$("#departure_port5").autocomplete(dep_apt_table);
$("#arrival_port5").autocomplete(dep_apt_table);

$("#departure_port6").autocomplete(dep_apt_table);
$("#arrival_port6").autocomplete(dep_apt_table);


$("#arrival_port_2").autocomplete(dep_apt_table);

$("#multi_dep_1").autocomplete(dep_apt_table);
$("#multi_dep_2").autocomplete(dep_apt_table);
$("#multi_dep_3").autocomplete(dep_apt_table);

$("#multi_arr_1").autocomplete(dep_apt_table);
$("#multi_arr_2").autocomplete(dep_apt_table);
$("#multi_arr_3").autocomplete(dep_apt_table);




$(function() {
		$("#dep_date2").datepicker({dateFormat: 'yy-mm-dd' ,
    maxDate:'+12m',minDate:'0d',
     rangeSelect: false, numberOfMonths: 2, 
    showOn: 'focus',
    showAnim: 'slideDown',speed:'fast'
    });
	});

$(function() {
		$("#dep_date3").datepicker({dateFormat: 'yy-mm-dd' ,
    maxDate:'+12m',minDate:'0d',
     rangeSelect: false, numberOfMonths: 2, 
    showOn: 'focus',
    showAnim: 'slideDown',speed:'fast'
    });
	});

$(function() {
		$("#dep_date4").datepicker({dateFormat: 'yy-mm-dd' ,
    maxDate:'+12m',minDate:'0d',
     rangeSelect: false, numberOfMonths: 2, 
    showOn: 'focus',
    showAnim: 'slideDown',speed:'fast'
    });
	});

$(function() {
		$("#dep_date5").datepicker({dateFormat: 'yy-mm-dd' ,
    maxDate:'+12m',minDate:'0d',
     rangeSelect: false, numberOfMonths: 2, 
    showOn: 'focus',
    showAnim: 'slideDown',speed:'fast'
    });
	});

$(function() {
		$("#dep_date6").datepicker({dateFormat: 'yy-mm-dd' ,
    maxDate:'+12m',minDate:'0d',
     rangeSelect: false, numberOfMonths: 2, 
    showOn: 'focus',
    showAnim: 'slideDown',speed:'fast'
    });
	});


$(function() {
		$("#dep_date").datepicker({dateFormat: 'yy-mm-dd' ,
    maxDate:'+12m',minDate:'0d',
     rangeSelect: false, numberOfMonths: 2, 
    showOn: 'focus',
    showAnim: 'slideDown',speed:'fast',
    onClose: function(date) { 
    if ($('#arr_date').val()<date) $('#arr_date').val(date);
    var data=date.split("-"); 
    $('#arr_date').datepicker('option', 'minDate', new Date(data[0],data[1]-1,data[2]));
    }
    });
	});


$(function() {
		$("#checkin").datepicker({dateFormat: 'yy-mm-dd' ,
    maxDate:'+12m',minDate:'0d',
     rangeSelect: false, numberOfMonths: 2, 
    showOn: 'focus',
    showAnim: 'slideDown',speed:'fast',
    onClose: function(date) { 
    if ($('#checkout').val()<date) $('#checkout').val(date);
    var data=date.split("-"); 
    $('#h_arr_date').datepicker('option', 'minDate', new Date(data[0],data[1]-1,data[2]));
    }
    });
	});


$(function() {
		$("#d_birth_chd1").datepicker({dateFormat: 'yy-mm-dd' ,
    maxDate:'0d',minDate:'-144m',
     rangeSelect: false, numberOfMonths: 2, 
    showOn: 'focus',
    showAnim: 'slideDown',speed:'fast',
    onClose: function(date) { 
    }
    });
	});


$(function() {
		$("#checkout").datepicker({dateFormat: 'yy-mm-dd' ,
    maxDate:'+12m',minDate:'0d',rangeSelect: false, numberOfMonths: 2, 
    showOn: 'focus',
    showAnim:'slideDown',speed:'fast'});
});



$(function() {
		$("#arr_date").datepicker({dateFormat: 'yy-mm-dd' ,
    maxDate:'+12m',minDate:'0d',rangeSelect: false, numberOfMonths: 2, 
    showOn: 'focus',
    showAnim:'slideDown',speed:'fast'});
});



function strpos( haystack, needle, offset){
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Onno Marsman    
    // +   bugfixed by: Daniel Esteban
    // *     example 1: strpos('Kevin van Zonneveld', 'e', 5);
    // *     returns 1: 14
 
    var i = (haystack+'').indexOf(needle, (offset ? offset : 0));
    return i === -1 ? false : i;
}


$('#dep_port').dialog({
autoOpen: false,
width: 500,height:450,
close: function() { 
$("#modal").hide();
$("#adt_count").show();
$("#child_count").show();
$("#inf_count").show();
$("#flex_date").show();
$("#specific_airline1").show();

} 
});



$('#arr_port').dialog({
autoOpen: false,
width: 500,height:450 
,close: function() { $("#modal").hide(); 
$("#adt_count").show();
$("#child_count").show();
$("#inf_count").show();
$("#flex_date").show();
$("#specific_airline1").show();

}
});

$('#arr_port_2').dialog({
autoOpen: false,
width: 500,height:450 
,close: function() { $("#modal").hide(); 
$("#adt_count").show();
$("#child_count").show();
$("#inf_count").show();
$("#flex_date").show();
$("#specific_airline1").show();

}
});


    $("#dep_combo").change(function () {
          var str = "";
          $("#dep_combo option:selected").each(function () {
                str += $(this).val();
			//var kr_wyl= $(this).val();
				});

var show_all_dep=$("#all_dep").val();
$.ajax({
   type: "GET",
   url: "m_apt_list1.php",
   data: "all="+show_all_dep+"&country="+str+"&language=<?echo($language);?>",
    error: function(){
        alert('Blad polaczenia z baza danych');
    },success: function(msg){
$("#dep_apt_list").html(msg);}
});
        });;


    $("#arr_combo").change(function () {
          var str = "";
          $("#arr_combo option:selected").each(function () {
                str += $(this).val();
				//var kr_prz= $(this).val();
              });
var show_all_arr=$("#all_arr").val();
$.ajax({
   type: "GET",
   url: "m_apt_list2.php",
   data: "all="+show_all_arr+"&country="+str+"&language=<?echo($language);?>",
    error: function(){
        alert('Blad polaczenia z baza danych');
    },success: function(msg){
$("#arr_apt_list").html(msg);}
});
        });


    $("#arr_combo_2").change(function () {
          var str = "";
          $("#arr_combo_2 option:selected").each(function () {
                str += $(this).val();
              });

$.ajax({
   type: "GET",
   url: "m_apt_list3.php",
   data: "country="+str+"&language=<?echo($language);?>",
    error: function(){
        alert('Blad polaczenia z baza danych');
    },success: function(msg){
$("#arr_apt_list_2").html(msg);}
});
        });


$('#last_search_win').dialog({
autoOpen: false,
width: 500,height:450,
buttons: {
"Ok": function() {
 $(this).dialog("close"); 
 $("#modal").hide();
 $("#adt_count").show();
$("#child_count").show();
$("#inf_count").show();
 $("#flex_date").show();
$("#specific_airline1").show();

 }
},

close: function() { 
$("#modal").hide();
$("#adt_count").show();
$("#child_count").show();
$("#inf_count").show();
$("#flex_date").show();
$("#specific_airline1").show();

} 
});

$('#last_search').click(function() {
$("#modal").show();
$("#adt_count").hide();
$("#child_count").hide();
$("#inf_count").hide();
$("#flex_date").hide();
$("#specific_airline1").hide();
$('#last_search_win').dialog('open');
});



$('#dep_list').click(function() {
$("#modal").show();
$("#adt_count").hide();
$("#child_count").hide();
$("#inf_count").hide();
$("#flex_date").hide();
$("#specific_airline1").hide();

$('#dep_port').dialog('open');
});


$('#arr_list').click(function() {
$("#modal").show();
$("#adt_count").hide();
$("#child_count").hide();
$("#inf_count").hide();
$("#flex_date").hide();
$("#specific_airline1").hide();

$('#arr_port').dialog('open');
});

$('#arr_list_2').click(function() {
$("#modal").show();
$("#adt_count").hide();
$("#child_count").hide();
$("#inf_count").hide();
$("#flex_date").hide();
$("#specific_airline1").hide();

$('#arr_port_2').dialog('open');
});


});

