/// <reference name="MicrosoftAjax.js"/>
if (typeof (Sys) != 'undefined') {
    Type.registerNamespace("WIY"); Type.registerNamespace("WIY._Arama");
    (function (w, s) {
        WIY._Arama = function () {
            this.A_Metni = w.ARA_METNI ? w.ARA_METNI : 'Site içi arama';
            this.IDler = [];
            this._Div = null;
        }
        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.DugmeEkle = function (bid, tid) {
            if (typeof (bid) != 'undefined') {
                if (!tid) tid = '';
                var btn = $get(bid);
                if (btn) {
                    if (Array.indexOf(this.IDler, tid) == -1 && this.IDler.length > 0)
                        tid = this.IDler[0];
                    var t = $get(tid);
                    if (t) {
                        var f = function (e) {
                            e.preventDefault();
                            e.stopPropagation();
                            this.Yap(tid);
                        }
                        $addHandler(btn, 'click', Function.createDelegate(this, f));
                    }
                }
            }
        }
        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 + '-'+w._pageAnah)) + '/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);
        });
        //---------------------------------------------------------------------------------------------------------------------
        WIY.Arama.Grid = function (a) {
            WIY.Arama.Grid.initializeBase(this, [a]);
            this._Items = [];
            this._Dil = -1;
            this._Aktif = -1;
            this.onDelegate = null;
            this._Div = null;
            this.onSuccessDelegate = Function.createDelegate(this, this.IcerikGeldi);
            this.onFailureDelegate = Function.createDelegate(this, this.IcerikGelmedi);
        }
        WIY.Arama.Grid.prototype.IcerikGeldi = function (r, uc, m) {
            window.jQuery(uc).data('icerik', r);
            this.IcerikGoster(r, uc);
        }
        WIY.Arama.Grid.prototype.IcerikGelmedi = function (a) {
            window.status = a.get_message();
            this.IcerikGizle();
        }

        WIY.Arama.Grid.prototype.HandleMouseOver = function (e) {
            if (e) {
                var ref = (typeof (e.srcElement) != 'undefined') ? e.srcElement : e.target;
                if (ref) {
                    var jq = window.jQuery(ref);
                    this._Aktif = jq.data('anah');
                    if (this._Aktif && jq.data('icerik') == null)
                        Sys.Net.WebServiceProxy.invoke('../../Servisler/IcerikServisi.asmx', 'BelgeIcerik', false, { argBBA: this._Aktif, dil: this._Dil }, this.onSuccessDelegate, this.onFailureDelegate, e);
                    else
                        this.IcerikGoster(jq.data('icerik'), e);
                }
            }
        }
        WIY.Arama.Grid.prototype.IcerikGizle = function () {
            if (this._Div)
                window.jQuery(this._Div).animate({ opacity: 0 }, 500, 'linear', function () { window.jQuery(this._Div).css({ height: 0, width: 0 }); });
        }
        WIY.Arama.Grid.prototype.IcerikGoster = function (data, e) {
            var jq = window.jQuery(this._Div);
            if (jq) {
                jq.hide();
                if (data) {
                    if (data != '') {
                        jq.html(data);
                        jq.css({ zIndex: '1009', backgroundColor: 'white', position: 'fixed', left: (e.screenX - 150), top: (e.screenY - 105), overflow: 'auto', height: 1, width: 1, opacity: 1 }).animate({ width: 300, height: 100 }, 300, 'linear');
                    }
                }
            }
        }
        WIY.Arama.Grid.prototype.initialize = function () {
            WIY.Arama.Grid.callBaseMethod(this, 'initialize');
            this.onDelegate = Function.createDelegate(this, this.HandleMouseOver);
            for (var i = 0; i < this._Items.length; i++) {
                var dom = $get(this._Items[i].id);
                var l = window.jQuery(dom).find('a');
                if (l.length == 1) {
                    l.data('anah', this._Items[i].anah);
                    l.mouseover(this.onDelegate);
                }
            }
        }
        WIY.Arama.Grid.prototype.dispose = function () {
            WIY.Arama.Grid.callBaseMethod(this, 'dispose');
        }
        WIY.Arama.Grid.prototype.get_Items = function () { return this._Items; }
        WIY.Arama.Grid.prototype.set_Items = function (d) { this._Items = d; }
        WIY.Arama.Grid.prototype.get_Dil = function () { return this._Dil; }
        WIY.Arama.Grid.prototype.set_Dil = function (d) { this._Dil = d; }
        WIY.Arama.Grid.prototype.get_DivID = function () { return ""; }
        WIY.Arama.Grid.prototype.set_DivID = function (d) {
            this._Div = $get(d);
            if (this._Div)
                $addHandler(this._Div, 'mouseout', function () { window.jQuery('#' + d).hide(); });
        }
        WIY.Arama.Grid.registerClass('WIY.Arama.Grid', Sys.UI.Control);
    } (window, Sys));
    Sys.Application.notifyScriptLoaded();
}