///<reference path="../TESCO.js" />
///<reference path="../event.js" />
///<reference path="../eventManager.js" />
///<reference path="../exception.js" />
///<reference path="../node.js" />
///<reference path="inputs.js" />
///<reference path="dialogue.js" />

TESCO.UI.SearchWidget = (function() {

    var NODE = TESCO.system.DOM.node;

    //  constructor
    function _constructor() {
        var LOCALE = TESCO.locale;

        var _form = document.getElementById("fSearch");
        var _input = NODE.getDescendantsByAttributeRegExp(_form, "input", "id", new RegExp('^searchBox-'))[0];

        TESCO.system.event.attach(_form, "submit",
		    function(e) {
		        if ((_input.value.trim() === "") || (_input.value === LOCALE.searchWidget.searchText)) {
		            e.stopEvent();
		            TESCO.UI.Dialogue.Static.show(LOCALE.dialogue.searchError());
		        }
		    }
		);
        TESCO.system.event.attach(_input, "focus",
		    function() {
                NODE.addClassName(_input, "focus");
		    }
		);
		TESCO.system.event.attach(_input, "blur",
		    function() {
		        NODE.removeClassName(_input, "focus");
		    }
		);
        if (LOCALE.search.searchText) {
        new TESCO.UI.inputs.saveDefaults("searchBox", LOCALE.search.searchText);
        return this;
        }
    }

    _constructor.prototype.NAME = "TESCO.UI.SearchWidget";

    return _constructor;
})();
