
$(document).ready(function(){

/*
  $("#combo_country").change(function() {
    e = $('#combo_region').get(0);

    e.options.length = 0;
    e.disabled = true;

    e = $('#combo_locality').get(0);
    e.options.length = 0;
    e.disabled = true;

    country_id = $('#combo_country').val();

    if (country_id > 0) {
      $.ajax({
        type: "POST",
        url: "index.php",
        data: ({
          presenter: "SummitTour::TourSearchResultList",
          request: "requestGetRegionLocalityList",
          country_id: country_id
        }),
        dataType: "json",
        error: function(XMLHttpRequest, status, error) {
          alert('status: ' + status + ',\nerror=' + error + '\n');
        },
        success: function(data) {
          e = $('#combo_region').get(0);
          e.options.length = 0;
          for (key in data.region_list) {
            text = data.region_list[key].title;
            value = data.region_list[key].region_id;
            e.options[e.options.length] = new Option(text, value);
          }
          e.disabled = false;

          e = $('#combo_locality').get(0);
          e.options.length = 0;
          for (key in data.locality_list) {
            text = data.locality_list[key].title;
            value = data.locality_list[key].locality_id;
            e.options[e.options.length] = new Option(text, value);
          }
          e.disabled = false;
        }
      });
    }
  });



  $("#combo_region").change(function() {

    e = $('#combo_locality').get(0);
    e.options.length = 0;
    e.disabled = true;

    country_id = $('#combo_country').val();
    region_id = $('#combo_region').val();

    if (country_id > 0 || region_id > 0) {
      $.ajax({
        type: "POST",
        url: "index.php",
        data: ({
          presenter: "SummitTour::TourSearchResultList",
          request: "requestGetLocalityList",
          country_id: country_id,
          region_id: region_id
        }),
        dataType: "json",
        error: function(XMLHttpRequest, status, error) {
          alert('status: ' + status + ',\nerror=' + error + '\n');
        },
        success: function(data) {
          e = $('#combo_locality').get(0);
          e.options.length = 0;
          for (key in data.locality_list) {
            text = data.locality_list[key].title;
            value = data.locality_list[key].locality_id;
            e.options[e.options.length] = new Option(text, value);
          }
          e.disabled = false;
        }
      });
    }
  });
/**/

  function setDatePickerBind(o) {
    $('div input', o).change(function() {
      day = $('div input:eq(0)', o).val();
      month = $('div input:eq(1)', o).val();
      year = $('div input:eq(2)', o).val();
      $('input:eq(3)', o).val(year + '-' + month + '-' + day);
    });
  }

  setDatePickerBind($("#date_picker_term").parent());
  setDatePickerBind($("#date_picker_date_from").parent());
  setDatePickerBind($("#date_picker_date_to").parent());

  $('.paginator a').removeAttr('href');
  $('.paginator a').click(function() { /* page switch patch */
    p = $(".tour_search input[name='page']");
    t = $(this).text();

    if (t.substr(2, 1) == 'p') {
      p.val(parseInt(p.val()) - 1);
    }
    else if (t.substr(0, 1) == 'd') {
      p.val(parseInt(p.val()) + 1);
    }
    else {
      p.val(t);
    }
    $('.tour_search form').get(0).submit();
    return false;
  });

/*
  val = $("#combo_country").val();
  if (val > 0) {
    $("#combo_country").change();
  };
*/
});
