$(document).ready( function () {
  function doPriceSearch(event)
  {
    var from = $("#price_from").val();
        to   = $("#price_to").val();
    if ( from.match(/^[1-9][0-9]*$/) ) {
      wv.prototype.price.from = from;
    } else {
      wv.prototype.price.from = "";
      $("#price_from").val( "" );
    }
    if ( to.match(/^[1-9][0-9]*$/) ) {
      wv.prototype.price.to   = to;
    } else {
      wv.prototype.price.to   = "";
      $("#price_to").val( "" );
    }
    if ( wv.prototype.mode == "similar" ) {
      is.doSearch( is.param.query, "priceSearch" );
    } else {
      cs.doSearch( cs.param.query, "priceSearch" );
    }
  };
  
  $("#price_from").bind( "keyup", function (event) {
    var key = event.keyCode;
    if ( key == 13
         || key == 8
         || key == 46
         || key == 48
         || key == 49
         || key == 50
         || key == 51
         || key == 52
         || key == 53
         || key == 54
         || key == 55
         || key == 56
         || key == 57
         || key == 96
         || key == 97
         || key == 98
         || key == 99
         || key == 100
         || key == 101
         || key == 102
         || key == 103
         || key == 104
         || key == 105
         ) {
         var currentPrice = $("#price_from").val();
         var timerId = setInterval(function () {
                if ( currentPrice == $("#price_from").val()) {
                  doPriceSearch(event);
                }
                clearInterval(timerId);
         }, 1300);
    }
  } );
  $("#price_to").bind( "keyup", function (event) {
    var key = event.keyCode;
    if ( key == 13
         || key == 8
         || key == 46
         || key == 48
         || key == 49
         || key == 50
         || key == 51
         || key == 52
         || key == 53
         || key == 54
         || key == 55
         || key == 56
         || key == 57
         || key == 96
         || key == 97
         || key == 98
         || key == 99
         || key == 100
         || key == 101
         || key == 102
         || key == 103
         || key == 104
         || key == 105
         ) {
         var currentPrice = $("#price_to").val();
         var timerId = setInterval(function () {
                if ( currentPrice == $("#price_to").val()) {
                  doPriceSearch(event);
                }
                clearInterval(timerId);
	 }, 1300);
    }
  } );
  $(".priceSearchBtn").bind( "click", doPriceSearch );
  $(".priceClearBtn").bind( "click", function() {
                                       $("#price_from").val( "" );
                                       $("#price_to").val( "" );
                                       doPriceSearch();
                                     });
                                       
});

