﻿// README
//
// There are two steps to adding a property:
//
// 1. Create a member variable to store your property
// 2. Add the get_ and set_ accessors for your property
//
// Remember that both are case sensitive!


/// <reference name="MicrosoftAjaxTimer.debug.js" />
/// <reference name="MicrosoftAjaxWebForms.debug.js" />
/// <reference name="AjaxControlToolkit.ExtenderBase.BaseScripts.js" assembly="AjaxControlToolkit" />


Type.registerNamespace('WIS.Web.AjaxControls.Extenders');

WIS.Web.AjaxControls.Extenders.SiteSearchBehavior = function(element) {
    WIS.Web.AjaxControls.Extenders.SiteSearchBehavior.initializeBase(this, [element]);

	// Handlers
    this._clickHandler = null;
    
    // Variables
    this._searchUrl = null;
    this._searchTextID = null;
}
WIS.Web.AjaxControls.Extenders.SiteSearchBehavior.prototype = {
    initialize : function() {
        WIS.Web.AjaxControls.Extenders.SiteSearchBehavior.callBaseMethod(this, 'initialize');

        this._clickHandler = Function.createDelegate(this, this._onClick);
        $addHandler(this.get_element(), "click", this._clickHandler);
    },

    dispose : function() {
        if (this._clickHandler) {
			$removeHandler(this.get_element(), "click", this._clickHandler);
        }

        WIS.Web.AjaxControls.Extenders.SiteSearchBehavior.callBaseMethod(this, 'dispose');
    },
    
    ProcessUserKeyPress : function(e) {
        var keycode;
        if (window.event) {
            keycode = window.event.keyCode;
        }
        else if (e) {
            keycode = e.which;
        }
        if (keycode == 13) {
            this._onClick();
            return false;
        }
        return true;
    },
    
    _onClick : function() {
		window.location.href = this._searchUrl + "?q=" + $get(this._searchTextID).value;
    },
    
    get_SearchTextID : function() {
		return this._searchTextID;
    },
    set_SearchTextID : function(value) {
		this._searchTextID = value;
    },
    
    get_SearchUrl : function() {
		return this._searchUrl;
    },
    set_SearchUrl : function(value) {
		this._searchUrl = value;
    }
}
WIS.Web.AjaxControls.Extenders.SiteSearchBehavior.registerClass('WIS.Web.AjaxControls.Extenders.SiteSearchBehavior', AjaxControlToolkit.BehaviorBase);

if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();