host = "/";

function removeThickBoxEvents() {
        $('.thickbox').each(function(i) {
            $(this).unbind('click');
        });
    }

function bindThickBoxEvents() {
        removeThickBoxEvents();
        tb_init('a.thickbox, area.thickbox, input.thickbox');
}


function display_show(id) {
  jQuery("#"+id).show();  
}

function display_hide(id) {
  jQuery("#"+id).hide();  
}

function hide_accom_filter() {
    jQuery("#accom_navigation").hide();
    jQuery("#accom_filter_link_hide").hide();
    jQuery("#accom_filter_link_show").show();
    
}

function show_accom_filter() {
    jQuery("#accom_navigation").show();
    jQuery("#accom_filter_link_hide").show();
    jQuery("#accom_filter_link_show").hide();
    
}

function reservationControl() {


  var name = jQuery("#name").val();
  var ret = true;
  if(name.length < 2) {
    jQuery("#name").addClass("input_error");
    ret = false;
  }else{
    jQuery("#name").removeClass("input_error");
  }
  
  var adults = jQuery("#adults").val();

  if(parseInt(adults) > 0 && parseInt(adults)< 100) {
   jQuery("#adults").removeClass("input_error");
  }else{
    jQuery("#adults").addClass("input_error");
    ret = false;
  }
  
  var email = jQuery("#email").val();
  if (window.RegExp)
    {
        znaky=new RegExp("^[^.]+(\.[^.]+)*@([^.]+[.])+[a-z]{2,3}$");
        if (!znaky.test(email))
        {
            jQuery("#email").addClass("input_error");
            ret = false;
        }else{
            jQuery("#email").removeClass("input_error");
        }
    } 
  
  return ret;
}

function prevPicture(id, div_id) {
  
  var act_value = jQuery("#"+div_id+"_button").attr('value');
  var new_value = parseInt(act_value) - 1;
  var new_value_to_next = act_value;
  var val_to_send = act_value - 1;
  send = "id="+id+"&function=1&img_from="+val_to_send;
  $.ajax({
    url: host+"wp-content/plugins/accommodation/ajax.php",
    data: send,
    dataType: 'script',
    success: function(data){
      el = document.getElementById("picture_next_"+id);
      el.innerHTML = data;
      
      jQuery("#picture_next_"+id).html(data);
      bindThickBoxEvents();
    }
  });
  //alert("#"+div_id+"_button");
  jQuery("#picture_next_"+id+"_button").attr('value', new_value_to_next);
  jQuery("#picture_next_"+id+"_button").show();
  if(new_value == 1) {
    jQuery("#"+div_id+"_button").hide();
    jQuery("#"+div_id+"_button").attr('value', new_value);
  }else{
    jQuery("#"+div_id+"_button").attr('value', new_value);
    jQuery("#"+div_id+"_button").show();
  }
  
}

function nextPicture(id, div_id, max_number) {

  var act_value = jQuery("#"+div_id+"_button").attr('value');
  var new_value = parseInt(act_value) + 1;
  var new_value_prev = new_value - 1;

  send = "id="+id+"&function=1&img_from="+act_value;
  $.ajax({
    url: host+"wp-content/plugins/accommodation/ajax.php",
    data: send,
    dataType: 'script',
    success: function(data){
      el = document.getElementById(div_id);
      el.innerHTML = data;
      jQuery("#"+div_id).html(data);
      bindThickBoxEvents();
    }
  });
  
  if( parseInt(max_number) < ( parseInt(act_value) + 3)) {
    jQuery("#picture_next_"+id+"_button").hide();
  }
  
  jQuery("#picture_prev_"+id+"_button").show();

  jQuery("#picture_prev_"+id+"_button").attr('value', new_value_prev);
  jQuery("#"+div_id+"_button").attr('value', new_value);

}

function menu_item(id) {
  var menu = new Array("description", "services", "pricelist", "reservation", "contact", "map");
  for(i=0 ; i < menu.length ; i++) {
    jQuery("#"+menu[i]).hide();
    jQuery("#"+menu[i]+"_menu").removeClass("menu_item_selected");
    jQuery("#"+menu[i]+"_menu").addClass("menu_item");
  }
  jQuery("#"+id+"_menu").addClass("menu_item_selected");
  jQuery("#"+id).show();
}


function getPricelist(id, cur) {
  
  send = "id="+id+"&function=2&currency="+cur;
  $.ajax({
    url: host+"wp-content/plugins/accommodation/ajax.php",
    data: send,
    dataType: 'script',
    success: function(data){
      jQuery("#pricelist_div").html(data);
      jQuery("#pricelist_title_currency").html(cur);

    }
  });
  
  jQuery(".currency_link").show();
  jQuery("#curr_"+cur).hide();
  
}


function countyChanged() {
  jQuery("search-county").val();
}

function searchWidget() {

 var send = "function=3"; 
      jQuery("select").each(function () { 
            var cla = jQuery(this).attr('class');
            var claa = "aa"+cla;
            var index_pos = claa.indexOf('search-select-widget');
            if(index_pos > 0) {
              var nam = jQuery(this).attr('name');
              var nam_array = nam.split('[');
              nam = nam_array[1].replace(']','');
              var val = jQuery(this).val();
              send +=  "&"+nam+"="+val;
            }
         
      });
      
      var price_from = jQuery("#price-from-widget").attr('value');
      var price_to = jQuery("#price-to-widget").attr('value');
      if(price_from > 0) {
        send +=  "&price_from="+price_from;
      }
      if(price_to > 0) {
        send +=  "&price_to="+price_to;
      }
      //alert(send);
      
       jQuery.ajax({
        url: host+"wp-content/plugins/accommodation/ajax.php",
        data: send,
        dataType: 'script',
        success: function(data){
          var text = data+" accommodation found";
          $("#search-widget-number-accom").html(text);
        }
      });

}

jQuery(document).ready(function(){

  jQuery(".checkbox-county").click(function() {
    
    var id = jQuery(this).attr('id');
    var id_array = id.split('_');
    var id_number = id_array[1];
    
    var checked = jQuery(this).attr('checked');
    if(checked == true) {
      jQuery("#towns-county_"+id_number).show();
    }else{
      jQuery("#towns-county_"+id_number).hide();
      jQuery(".checkbox-town-county_"+id_number).removeAttr("checked");
    }
    
    
    
  });
  
  
  jQuery(".search-select-widget").change(function() {
    
      
    searchWidget();

    
  });

  searchWidget();
    
});





