﻿berryAlloc.SearchBox = function (selectorSuffix) {
	this.selectorSuffix = selectorSuffix;
	this.BindEvents();
	this.Initialize();
};

berryAlloc.SearchBox.prototype = {
    BindEvents: function () {
        var me = this;
        j("#SearchBoxButton" + me.selectorSuffix).click(function () { me.DoSearch() });
        j("#SearchBoxInput" + me.selectorSuffix).keypress(function (e) { if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) { me.DoSearch(); return false; } });
    },
    Initialize: function () {
        var me = this;
        //j("#SearchBoxInput" + me.selectorSuffix).focus();
    },
    DoSearch: function () {
        var me = this;
        var url = j("#SearchUrl" + me.selectorSuffix).val();
        var searchString = j("#SearchBoxInput" + me.selectorSuffix).val();
        url = url + '?qs=' + encodeURIComponent(searchString);
        window.location.href = url;
    }
};

