﻿
Entegris.Navigation.GlobalSearch = function(FormGETUrl, IsBlueBox){

    this.input = Ext.get('GlobalSearchTerm');
    this.button = Ext.get('GlobalSearchSubmit');
    this.error = Ext.get('GlobalSearchError');
    this.error.setVisibilityMode(Ext.Element.DISPLAY);
    this.error.setVisible(false);
            
            
    this.term = new Ext.form.TextField({    el: this.input,
                                            allowBlank: true,
                                            selectOnFocus: true
                                        });
    this.term.applyTo(this.input);
    
    
    submit = function() {
        if (this.term.getValue() == '') {
            this.error.setVisible(true);
            this.term.focus();
        } else {
            var url = FormGETUrl;
            
            var myForm = document.createElement("form");
            myForm.method="post";
            myForm.action = url;
            
            var myInput = document.createElement("input") ;
            myInput.setAttribute("name", "term");
            myInput.setAttribute("value", this.term.getValue());
            myForm.appendChild(myInput);

            
            document.body.appendChild(myForm) ;
            myForm.submit() ;
            document.body.removeChild(myForm) ;
        }
    };
    
    onSpecialKey = function(field, e) {
        if(e.getKey() == e.ENTER){
            submit();
        }
    };
    
    onBlur = function(field, e) {
        this.error.setVisible(false);
    };
    
    this.term.on('specialkey', onSpecialKey, this);
    this.term.on('blur', onBlur, this);
    this.button.on('click', submit, this);
    
    
    this.term.setValue(C4.Utility.QueryString.get('term', ''));
         
};