﻿/// <reference name="MicrosoftAjax.js"/>
var ressources_path="/lib/v3.1/";
var ressources={
    btnOkOver:ressources_path+"img/search/btn_ok_o.gif",
    btnOkOut:ressources_path+"img/search/btn_ok.gif",
    btnOkClick:ressources_path+"img/search/btn_ok_click.gif",
    btnRechercherOver:ressources_path+"img/search/recherche_over.png",
    btnRechercherOut:ressources_path+"img/search/recherche_out.png",
    btnRechercherClick:ressources_path+"img/search/recherche_click.png",
    checkBoxOff:ressources_path+"img/search/checkBox_off.gif",
    checkBoxOn:ressources_path+"img/search/checkBox_on.gif"
};
var Recherche = new Class({
    initialize: function(_panelContainer, _sName) {
        this.log("Initialize()");
        //this.selectedCheckBox = 0;
        this.aSelectFilter = [0, 0];
        this.aFilterText = new Array();
        this.filter = 0;
        this.ohParent = $(_panelContainer);
        //this.name=$("entete").className=_sName;
        this.searchControl = new YAHOO.widget.TabView("searchTop");
        this.searchControl.addListener("activeTabChange", handleActiveTabChange);
        this.searchControl.set('activeIndex', ongletActive);
        //this.afficheControl= new YAHOO.widget.TabView("afficheSortVert");
        this.initEvent();
    },
    log: function(_sMessage, _sType) {
        _sType = $defined(_sType) ? _sType : "info";
        new YAHOO.widget.LogWriter("Recherche").log(_sMessage, _sType);
    },
    initEvent: function() {
        this.log("initEvent()");
        // Buttons
        $$("#btnOk a").each(function(_ohBtn, i) {
            _ohBtn.addEvent('mouseover', function(e) {
                new YAHOO.widget.LogWriter("Recherche").log("bouton mouseover :" + 0, "info");
                new Event(e).stop();
                this.src = "transparent url(" + ressources.btnOkOver + ") no-repeat scroll 0 0 ";
            });
            _ohBtn.addEvent('mouseout', function(e) {
                new YAHOO.widget.LogWriter("Recherche").log("bouton mouseout :" + 0, "info");
                new Event(e).stop();
                this.src = "transparent url(" + ressources.btnOkOut + ") no-repeat scroll 0 0 ";
            });
            _ohBtn.addEvent('mousepress', function(e) {
                new YAHOO.widget.LogWriter("Recherche").log("bouton mousepress :" + 0, "info");
                new Event(e).stop();
                this.src = "transparent url(" + ressources.btnOkOut + ") no-repeat scroll 0 0 ";
            });
        });
        //CheckBox
        $$("#search .searchFilter img").each(function(_ohCheckbox, i) {
            _ohCheckbox.src = i != 0 ? ressources.checkBoxOff : ressources.checkBoxOn;
            _ohCheckbox.addEvent('click', function(e) {
                new YAHOO.widget.LogWriter("Recherche").log("select click :" + i, "info");
                new Event(e).stop();
                oRecherche.setCheckBox(i);
                //eval($("entete").className).setCheckBox(i);
                //new Fx.Style(this, 'borderColor').set(endColor);
            });
        });
    },
    onSortVert: function(UpdatePanelID, ohElem, nOnglet) {
        $$("#search .yuiNavSort li  a").each(function(_ohSelect, i) { _ohSelect.className = ""; });
        ohElem.className = "selected";
        oRecherche.filter = nOnglet;
        this.log("vignettes/liste click :" + nOnglet, "info");
        this.doSearch(UpdatePanelID);
    },
    setCheckBox: function(_sCheckBox) {
        this.log("setCheckBox(" + _sCheckBox + ")");
        if (!isNaN(_sCheckBox))
            this.selectedCheckBox = Number(_sCheckBox);
        else {
            switch (_sCheckBox.toLowerCase()) {
                case "tous":
                    this.selectedCheckBox = 0;
                    break;
                case "audio":
                    this.selectedCheckBox = 1;
                    break;
                case "video":
                    this.selectedCheckBox = 2;
                    break;
                default:
                    this.selectedCheckBox = 0;
                    this.log("Wrong param in setCheckBox(" + _sCheckBox + ")", "error");
            };
        }
        setCheckIntern(this.selectedCheckBox);
        function setCheckIntern(_nCheckBox) {
            new YAHOO.widget.LogWriter("Recherche").log("setCheckIntern(" + _nCheckBox + ")");
            $$("#search .searchFilter img").each(function(_ohCheckbox, i) {
                //_ohCheckbox.src=eval($("entete").className).selectedCheckBox==i?ressources.checkBoxOn:ressources.checkBoxOff;
                _ohCheckbox.src = oRecherche.selectedCheckBox == i ? ressources.checkBoxOn : ressources.checkBoxOff;
            });
        }
    },
    setSelectFilter: function() {
        this.log("setSelectFilter()");
        $$("#ongletTout select").each(function(_ohSelect, i) {
            //_ohSelect.selectedIndex=eval($("entete").className).aSelectFilter[i];
            _ohSelect.selectedIndex = oRecherche.aSelectFilter[i];
            //eval($("entete").className).aFilterText[i]=_ohSelect.value;
            oRecherche.aFilterText[i] = _ohSelect.value;
        });
    },
    setGenre: function(_sGenre) {
        this.log("setGenre(" + _sGenre + ")");
        this.setFilter(_sGenre, 0);
    },
    setEvenement: function(_sEvenement) {
        this.log("setEvenement(" + _sEvenement + ")");
        this.setFilter(_sEvenement, 1);
    },
    setFilter: function(_s, _nSelect) {
        this.log("setFilter(" + _s + "," + _nSelect + ")");
        this.currentFilter = _nSelect;
        this.currentValue = _s;
        $$("#ongletTout select").each(function(_ohSelect, i) {
            //var _obj=eval($("entete").className);
            var _obj = oRecherche;
            if (i == _obj.currentFilter) {
                for (var _option = 0; _option < _ohSelect.options.length; _option++) {
                    if (_ohSelect.options[_option].value == _obj.currentValue) {
                        _ohSelect.selectedIndex = _option;
                        _obj.aSelectFilter[_obj.currentFilter] = _option;
                        _obj.aFilterText[_obj.currentFilter] = _ohSelect.value;
                        return;
                    }
                };
                new YAHOO.widget.LogWriter("Recherche").log("Element not found setFilter(" + _s + ")", "warn");
            }
        });
    },
    changeOnglet: function(UpdatePanelID, nOnglet) {
        __doPostBack(UpdatePanelID, "onglet," + nOnglet);
    },
    doSearch: function(UpdatePanelID, txtId) {
        //document.body.style.cursor = "wait";
        var ind = this.searchControl.get('activeTab') == this.searchControl.getTab(0);
        this.log("doSearch(" + (ind ? "ouglo" : "google") + "/" + this.filter + ")");
        var r = $("lstGenre");
        if (ind) {
            var _eventArgumrent = [$$("#ongletTout select")[1].value,
                                    $$("#ongletTout select")[0].value.replace("aucun", " "),
                                     this.selectedCheckBox,
                                     this.filter];
            /* call method to search data with ok button*/
            Sys.Debug.trace("Ouglo search with param: ");
            Sys.Debug.trace("- AudioVideo --> " + this.selectedCheckBox);
            Sys.Debug.trace("- Genre --> " + $$("#ongletTout select")[0].value);
            Sys.Debug.trace("- Evenement --> " + $$("#ongletTout select")[1].value);
            Sys.Debug.trace("- Type affichage --> " + ((this.filter == 0) ? "Vignettes" : "Liste"));
            //            __doPostBack('<%=UpdatePanel2.ClientID %>', 'somevalue');
            //__doPostBack("<%= btnOk_Click.ClientID %>","");
            __doPostBack(UpdatePanelID, _eventArgumrent.join(","));
        } else {
            /* call method to search data with Recherche button */
            Sys.Debug.trace("Google search with param: ");
            //        __doPostBack('<%=UpdatePanel2.ClientID %>', 'somevalue');
            //var obj = document.getElementById("<%= text.ClientID %>");
            //obj.value=value;
            this.setHistorie($$("#ongletTout select")[0].value);
            __doPostBack(UpdatePanelID, $(txtId).value);
        }

    },
    setHistorie: function(historie) {
        //var location = document.location.href;

    }

});
function handleActiveTabChange(e) {
    if (oRecherche!=null) {
        var ind = e.newValue == oRecherche.searchControl.getTab(0);
        if ($("afficheSortBleu") != null)
            $("afficheSortBleu").style.display = ind ? "block" : "none";
        if ($("afficheSortVert") != null)
            $("afficheSortVert").style.display = ind ? "block" : "none";
    }
    /*
    //var rt=e.newValue.toString();
    new YAHOO.widget.LogWriter("Recherche").log("handleActiveTabChange("+e.newValue+")","info"); 
    //var ind=e.newValue==oRecherche.searchControl.getTab(0);
    if (oRecherche.searchControl.get('activeIndex')) {
    $$("#search .containerTableCheckBox .searchFilter").each(function (_ohSelect,i){
    _ohSelect.style.display="block";
    });
    $("afficheSortVert").style.display="block";
    }else{
    $$("#search .containerTableCheckBox .searchFilter").each(function (_ohSelect,i){
    _ohSelect.style.display="none";
    });
    $("afficheSortVert").style.display="none";
    
    }
    */
}

if (typeof(Sys) !== "undefined" ) Sys.Application.notifyScriptLoaded();
