﻿/// <reference name="MicrosoftAjax.js"/>
if (typeof (Sys) != 'undefined') {
    Type.registerNamespace("WIY");
    (function (w, s) {
        WIY._Arama = function () {
            this.A_Metni = w.ARA_METNI ? w.ARA_METNI : 'Site içi arama';
            this.IDler = [];

        }
        WIY._Arama.prototype.KeyDown = function (a) {
            if (a.keyCode) {
                if (a.keyCode == 13) {
                    a.preventDefault();
                    a.stopPropagation();
                    if (a.target && a.target.id)
                        this.Yap(a.target.id);
                }
            }
        }
        WIY._Arama.prototype.Blur = function (a) {
            if (a) {
                if (a.target)
                    if (a.target.value == '')
                        a.target.value = this.A_Metni;
            }
        }
        WIY._Arama.prototype.Focus = function (a) {
            if (a) {
                if (a.target)
                    if (a.target.value != '' && a.target.value == this.A_Metni)
                        a.target.value = '';
            }
        }
        WIY._Arama.prototype.KutuEkle = function (id) {
            if (id) {
                if (typeof (id) != 'string' && id.id)
                    id = id.id;
                if (Array.indexOf(this.IDler, id) == -1)
                    Array.add(this.IDler, id);
            }
        }
        WIY._Arama.prototype._UnBindHandlers = function () {
            for (var i = 0; i < this.IDler.length; i++) {
                var dom = $get(this.IDler[i]);
                if (dom) $clearHandlers(dom);
            }
        }
        WIY._Arama.prototype._BindHandlers = function () {
            for (var i = 0; i < this.IDler.length; i++) {
                var dom = $get(this.IDler[i]);
                if (dom) {
                    $addHandler(dom, 'keydown', Function.createDelegate(this, this.KeyDown));
                    $addHandler(dom, 'focus', Function.createDelegate(this, this.Focus));
                    $addHandler(dom, 'blur', Function.createDelegate(this, this.Blur));
                    dom.value = this.A_Metni;
                }
            }
        }
        WIY._Arama.prototype.Yap = function (id) {
            if (!id) id = '';
            if (Array.indexOf(this.IDler, id) == -1 && this.IDler.length > 0)
                id = this.IDler[0];
            var dom = $get(id);
            if (dom) {
                if (dom.value != '' && dom.value != this.A_Metni) {
                    var url = typeof (w._siteRoot) == 'undefined' ? '../../' : w._siteRoot + '/';
                    url += 'arama/' + (typeof (w._pageDil) == 'undefined' ? '0-/' : (w._pageDil + '-/')) + 'arama.html?';
                    url += '1,1,1,0,0,';
                    url += ((typeof (window.encodeURIComponent) != 'undefined') ? encodeURIComponent(dom.value) : escape(dom.value));
                    w.location.href = url;
                }
            }
        }
        WIY._Arama.registerClass('WIY._Arama', Sys.Component);
        //-----------------------------------------------------
        WIY.Arama = w.Arama = new WIY._Arama();
        Sys.Application.add_load(function () {
            window.setTimeout('WIY.Arama._BindHandlers();', 500);
        });

    } (window, Sys));
    Sys.Application.notifyScriptLoaded();
}
