include("ajax.js");

var Search = function(caller){
    var progressBar = "#loadingbar";
	this.ajax = new Ajax("module", "Search", progressBar, caller);
}

Search.prototype.loadSearch = function(search, mode){
    this.ajax.appendVar("mode", mode);
    this.ajax.appendVar("search", search);

	return this.ajax.request("loadSearch",
        function(response){
            if (response){
                window.location.href = "/search/";
            }
        }
    );
}

function initBindes(){
    $("#search").click(function(){
        var search = new Search(this);
        search.loadSearch($("#search_field").val(),1);
    });
    $("#search_field").keypress(function(e){
        if(e.which == 13){
            var search = new Search(this);
            search.loadSearch($("#search_field").val(),1);
        }
    });
    $("#butSearch").click(function(){
        var search = new Search(this);
        search.loadSearch($("#inpSearch").val(),1);
    });
    $("#inpSearch").keypress(function(e){
        if(e.which == 13){
            var search = new Search(this);
            search.loadSearch($("#inpSearch").val(),1);
        }
    });
}

$(document).ready(
	function(){
        initBindes();
	}
);
