//binding sort form selectors
bind_selectors('search_country', 'search_city', '/utils/span_cities_options?allowed=1', jQuery('#search_city').text());

//binding sort form selectors

jQuery(document).ready(function(){
  //apply block toggler


  if(jQuery.isFunction(jQuery.fn.toggleElements))
    jQuery('div.toggler-c').toggleElements({ fxAnimation:'slide', fxSpeed:'normal', className:'toggler' } );

  //search text
  /*if(jQuery('#inp1').val() == '') jQuery('#inp1').val('e.g. old automobile');
  jQuery('#search_form').submit(function(){
     if(jQuery('#inp1').val() == 'e.g. old automobile')
       jQuery('#inp1').val('');
  });
  jQuery('#inp1').click(function(){jQuery(this).val('');}); */

    var uri = window.location.href;  
    if ( parseInt(uri.indexOf("/my_club")) <= 0 ) {
        $("#inp1").focus();
    }

    $("#inp1").keypress(function(e) {
		$(this).next().css("display", "none");
		return true;
	});

	$("#inp1").click(function(e) {
		$(this).next().css("display", "none");
		return true;
    });

	$("#inp1").blur(function() {
		if( $(this).val() == "" ) {
			$(this).next().css("display", "block");
		}
		return true;
	});

	window.setInterval(function() {
		if( $("#inp1").val() != "" && $("#inp1").focus() ) {
			$("#label_search_query").css("display", "none");
		}
	}, 150);



  //go to form
  jQuery('#goto_button').click(function(){

    var page_number = jQuery('#page_number').val();
    if(page_number > total_pages || page_number <= 0)
    {
      alert(wrong_page_number_text);
      return false;
    }
    else
    {
      var url = window.location.href;
      var new_url = addUrlQueryItem(url, 'page_top_pager', page_number);
      window.location.href = new_url;
    }
  });

  //order selector
  select_bind_event('sort_by', change_order);

  //items per page selector
  select_bind_event('items', change_items_per_page);
  //left right direction selector
  jQuery('#left').click(function() {

       // $(this).attr("src","/images/left_active.jpg");
       // $('#right').attr("src","/images/left_non_active.jpg");
      var url = window.location.href;
      var new_url = addUrlQueryItem(url, 'order_direction', 'ASC');
      new_url = addUrlQueryItem(new_url, "page_top_pager", "1");
      window.location.href = new_url;
  });
  jQuery('#right').click(function() {

        //$(this).attr("src","/images/right_active.jpg");
        //$('#left').attr("src","/images/right_non_active.jpg");
          var url = window.location.href;
      var new_url = addUrlQueryItem(url, 'order_direction', 'DESC');
      new_url = addUrlQueryItem(new_url, "page_top_pager", "1");
      window.location.href = new_url;

  });
  jQuery('#cancel').click(function() {
  	var url = '/my_club/offers';
     window.location.href = url;
  });

  //search 'offer type' selector
  var offer_type = jQuery('#offer_type').val();
  if(offer_type >= 0)
  {
    var e = jQuery('.formsearch > .out > div').get(offer_type);
    jQuery(e).addClass('all').append('<div class="alleft"></div><div class="allright"></div>');
  }
  jQuery('.formsearch > .out > div').click(function() {
        jQuery('.formsearch > .out > div').removeClass('all');
        jQuery('.formsearch > .out > div div').remove();
        jQuery('#offer_type').val( getIndexByString(jQuery(this).attr('id')) );
        jQuery(this).addClass('all').append('<div class="alleft"></div><div class="allright"></div>');
  });


	// Dlya formy bystrogo vhoda --START
	$("form.headerLoginForm > div > input").focus(function() {
		if( ( $(this).val() == "" && $(this).attr("id") == "login1" ) || ( $(this).val() == "" && $(this).attr("id") == "password1" ) ) {
			$(this).next().css("display", "none");
		}
		return true;
	});

	$("form.headerLoginForm > div > input").blur(function() {
		if( ( $(this).val() == "" && $(this).attr("id") == "login1" ) || ( $(this).val() == "" && $(this).attr("id") == "password1" ) ) {
			$(this).next().css("display", "block");
		}
		return true;
	});

	window.setInterval(function() {
		if( $("#login1").val() != "" ) {
			$("#labelLogin").css("display", "none");
		}
		if( $("#password1").val() != "" ) {
			$("#labelPassword").css("display", "none");
		}
	}, 150);
	// --END

});

// Print page
function printPage(page, id)
{
	window.open("/" + page + "/print/" + id);
}