
/* set up our namespace */
if (typeof(window.gsf) === 'undefined') var gsf = {};

gsf.order = {
    _instructionsBound: false,
    _instructionsTextArea: null,

    instructionsBound: function() {
        return this._instructionsBound;
    },

    instructionsBoundIs: function(val) {
        if (val == this._instructionsBound) return;
        if (!val) return; /* cannot go from bound to unbound */
        this._instructionsTextArea.addClass('hasFocused');
        if (!this.formBound()) this._instructionsTextArea.val('');
        this._instructionsBound = val;
    },

    formBound: function() {
        return gsf.settings.orderFormBound;
    },

    formOnSubmit: function(evt) {
        if (!this.instructionsBound()) {
            this._instructionsTextArea.val('');
        }
    },

    textareaOnFocus: function(evt) {
        this.instructionsBoundIs(true);
    },

    bodyOnLoad: function(evt) {
        this._instructionsTextArea = $('#id_instructions');
        if (this.formBound()) this.instructionsBoundIs(true);
        else {
            var evt_this = this;
            $('form[name="orderForm"]').submit(
                function(evt) { evt_this.formOnSubmit(); });
            this._instructionsTextArea.focus(
                function(evt) { evt_this.textareaOnFocus(); });
        }
    },
};

