﻿var Find = new Class({
    
    initialize: function(imgFindID, graphicsPath, txtQueryID, url,ddlSearchEntityID)
    {
        var classRef = this;
        this.txtQuery = $(txtQueryID);
        this.graphicsPath = graphicsPath;
        this.imgFind = $(imgFindID);
        this.url = url;
        this.ddlSearchEntity = $(ddlSearchEntityID); 
       
        this.handleEvent = function(e){                      
          
          if (e.keyCode==13 && classRef.txtQuery.value.trim()!="")
          {
            location.href = classRef.url + escape(classRef.txtQuery.value) + classRef.ddlSearchEntity.value;
          }
        }        
        
        //bindWithEvent automatically passes mootools Event Class to the handleEvent function.        
        this.txtQuery.onkeyup = this.handleEvent.bindWithEvent();
        
        this.imgFind.addEvent('click', function(e){
	        e = new Event(e);
	        if (classRef.txtQuery.value.trim()!="")
                location.href = classRef.url + escape(classRef.txtQuery.value) + classRef.ddlSearchEntity.value;
	        e.stop();	        
        });
        
        this.imgFind.addEvent('mouseover', function(e){
	        e = new Event(e);
	        classRef.imgFind.src = graphicsPath + "Header/find_over.gif";
	        e.stop();	        
        });
        this.imgFind.addEvent('mouseout', function(e){
	        e = new Event(e);
	        classRef.imgFind.src = graphicsPath + "Header/find.gif";
	        e.stop();	        
        });
        this.imgFind.addEvent('mousedown', function(e){
	        e = new Event(e);
	        classRef.imgFind.src = graphicsPath + "Header/find_over.gif";
	        e.stop();	        
        });
        this.imgFind.addEvent('mouseup', function(e){
	        e = new Event(e);
	        classRef.imgFind.src = graphicsPath + "Header/find.gif";
	        e.stop();	        
        });        
    }       
});

