/*______________________________________________search_______________________________*/
function GlobalFooterSearch(options) {
    this.options = options;
    this.searchTextBox = options.searchTextBox;
    this.searchButton = options.searchButton;
    this.formName = options.formName;
    this.searchDefaultText = options.searchDefaultText;
    this.searchTextBox.value = this.searchDefaultText;
    this.keyPresssed = false;
    this.attachSearchTextEvents();
    this.attachSearchActions();
};   
GlobalFooterSearch.prototype = {   
    constructor : GlobalFooterSearch,
    bind : function(fnMethod){
        var objSelf = this;
        return(
            function(){
                return(fnMethod.apply(objSelf, arguments));
            }
        );
    },   
   
    crossBrowserEvnt : function (e) {
		if (!e) {var e = window.event;}
    	if (e.target) {targ = e.target;}
   	 	else if (e.srcElement) {targ = e.srcElement;}
    	if (targ.nodeType == 3) {targ = targ.parentNode;}        
		return targ;
	},
    attachSearchTextEvents : function(){
         this.searchTextBox.onclick = this.bind(function(e){
            if(this.keyPresssed != true){
				this.searchTextBox.value = "";
            }
         });
         this.searchTextBox.onblur = this.bind(function(e){
             if(this.searchTextBox.value == ""){
				this.searchTextBox.value = this.searchDefaultText;
				this.keyPresssed = false;
            }
        });
        this.searchTextBox.onkeypress = this.bind(function(e){
			this.keyPresssed = true;
         });
    },      
    attachSearchActions : function () {
        this.searchButton.onclick = this.bind(function(e){        
			if(this.keyPresssed == true){		
				this.searchQuery = this.searchTextBox.value;          
				this.formName.onsubmit();
	            }
        });         
        this.formName.onsubmit = this.bind(function(e){              
           
			if (!e) {			
				e = window.event;
			}
            if (e.preventDefault) {			    
				e.preventDefault();
            }
            else if (window.event && window.event.returnValue) {
				window.eventReturnValue = false;
            } else { e.returnValue = false;}            
           
		   if(this.keyPresssed == true && this.searchTextBox.value != ""){           
            this.searchQuery = this.searchTextBox.value;
			document.location.href = this.doSearch();}
		   
        });
    }, 
    doSearch : function () {
        var searchQuery = this.searchQuery.toLowerCase();
        var searchUrl = "/search/?q=" + encodeURIComponent(this.searchQuery);
        return searchUrl;
    }
};