function slideIt(myDiv,myLink,myLink2) {     //modifiée par Yuan 28/03/2008
    var mySlide = new Fx.Slide(myDiv);
    mySlide.hide();
    $(myLink).addEvent('click', function(e){
        e = new Event(e);
        mySlide.toggle();
        if(myLink2 != ""){
            $(myLink).removeClass('title_visible');
            $(myLink).addClass ('title_hidden');
        }
        e.stop();
    });
    if (myLink2 != "") {
        $(myLink2).addEvent('click', function(e){
            e = new Event(e);
            mySlide.toggle().chain(function()   {
                $(myLink).removeClass('title_hidden');    
                   $(myLink).addClass ('title_visible');
            });
            e.stop();
        });
    }
}

var mtTable = new Class({
    initialize : function(attr) {
        this.table = "";
        this.attr = attr;
        this.checkBrowser();
        this.myTitle = new Array();
        this.myColOrder = new Array();
    },
    
    checkBrowser : function() {
         if(navigator.appName == "Microsoft Internet Explorer") {
             this.ie = true;
         } else {
             this.ie = false;
         }
    },
    
    triggerError : function(){
      obj = this;         
      $(this.attr.output).empty();
      $(this.attr.output).adopt(new Element('div',{'class':'error'}).setText(obj.attr.noresultString));
      if ($(this.attr.paginContainer) != undefined) {
        $(this.attr.paginContainer).empty();
      }
      return false;
    },
    
    draw : function(response) {
        if(response == null    )
            return this.triggerError();
        if(response[0].nb_items == 0) {
            return this.triggerError();
        }
       
        this.data         = response[0].data;
        this.title      = response[0].title;
        this.totRows     = response[0].totRows;
        this.currentPage= response[0].currentPage;
        this.nb_items   = response[0].nb_items;
        this.title = this.makeTitle();
        
        var motif     = "\{c(\\d+)\}";
        var reg        = new RegExp(motif,"g");
        //this.data = data;
        
        this.getColTitle();
        this.table = new Element('table',{
            'class' : this.attr.cssClass,
            'id'     : this.attr.id,
            'border'     : 0,
            'cellpadding'     : 0,
            'cellspacing'     : 0
        });
        thead    = new Element('thead');
        tr        = new Element('tr');
        for(var j=0;j<this.myTitle.length;j++) {
            th    = new Element('th');
            th.setHTML(this.myTitle[j]);
            tr.adopt(th);
        }
        thead.adopt(tr);
        this.table.adopt(thead);
        tbody = new Element('tbody');

        // END DRAW HEADER
 
        
        // START DRAW BODY 
        var toHide = false;
        var toHideClass = "";
        var mainId = 0;
        var odd=0;
        var img = '';
        var toHideClassRow = new Array();
        
        for(var j=0;j<this.data.length;j++) {
            var _elts = new Array();
            masterSlave_switchOffset = this.data[j].length-1; 
            tr = new Element('tr');
            tr.id = "r"+j;
            if (this.data[j][masterSlave_switchOffset] == 0) {
                toHide = true;
            } else {
                toHide = false;
                mainId = j;
            }
            
            // code yanked from the Yahoo media player.
            if (! ("console" in window) || !("firebug" in console)) {
                var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
                window.console = {};
                for (var i = 0; i < names.length; ++i) window.console[names[i]] = function() {};
            }
            //var line = '';
            for(var k=0;k<this.myColOrder.length;k++) {
            
                var str = this.myColOrder[k];
                var obj = this;
                var tmp = '';
                if (str.match(reg)) {
                    tmp = str.replace(reg,function (str,replace1) {return obj.translateIt(j,replace1);});
                    tmp = tmp.replace(reg,function (tmp,replace1) {return obj.translateIt(j,replace1);});
                } else if(toHide == false) {
                    tmp = str;
                }
            
                td = new Element('td');
                
                myClass = "";
                if(toHide == true) {
                    
                    myClass = "class='hiddenRow'";
                    td.addClass("hiddenRow");
                    img = '';
                    if(k==0) {
                        img = "<img src='/include/smarty_tpl/templates/leadium/images/triview.gif' valign='absmiddle'>";
                    }
                }
                
                _elts.push(td.setHTML(img+tmp));
            }
            tr.adopt(_elts);
  
            if (toHide == true) {
                tr.addClass("display_none");
                if(!(toHideClassRow[mainId] instanceof Array)) {
                    toHideClassRow[mainId] = new Array();
                }
                toHideClassRow[mainId].push(tr);
            } else {
                tr.setStyle('cursor', 'pointer');
                if(++odd%2 == 0) {
                    tr.addClass("odd");
                }
                
        if (response[0].ntype==4){
             this.attr.hiddenRow = false;
        }
        else if(response[0].ntype != undefined && response[0].ntype!=4){
             this.attr.hiddenRow = true;
        }

                if(this.attr.hiddenRow == true) {
                    tr.set( {'events': { 'click':function() {
                            pId = this.id.substr(1,this.id.length);
                            for(w=0;w<toHideClassRow[pId].length;w++) {
                                toHideClassRow[pId][w].toggleClass('display_none');
                                toHideClassRow[pId][w].toggleClass('display_row');
                            }}
                        }
                    });
                }
            
            }
            tbody.adopt(tr);
            
        };
        this.table.adopt(tbody);
        
        // END DRAW BODY 
        $(this.attr.output).empty();
        if (this.attr.mode=='stats') {
            if (this.attr.exportContainer != undefined)    { $(this.attr.exportContainer).empty();target = this.attr.exportContainer}    else    { target = this.attr.output }   
            if (this.title != false) {
                $(target).adopt(new Element('div',{"class":"StatsTitle"}).setText(this.title));
            }

            $(target).adopt(
                new Element('div',{"class":"statsExportData"}).adopt(
                    new Element('a',{'id':'refresh','href':'javascript:void(0)','style':'border:0;','border':'0','events':{'click':function(){$('search_go').fireEvent('click');}}}).adopt(
                        new Element('img',{'src':this.attr.refreshbtn,'alt':'rafraichir les resultats','width':'24','height':'24','border':'0','style':'border:0;'})
                    ),
                    new Element('a',{'id':'urlXml','href':'javascript:void(0)','style':'border:0;','border':'0','events':{'click':function(){getXML();}}}).adopt(
                        new Element('img',{'name':'urlXml','id':'urlXml','width':'24','height':'24','src':this.attr.xmlbtn,'alt':'Flux XML','style':'border:0;','border':'0'})
                    ),
                    new Element('a',{'id':'urlxls','href':'javascript:void(0)','style':'border:0;','border':'0','events':{'click':function(){getXLS();}}}).adopt(
                        new Element('img',{'name':'urlXls','id':'urlXls','width':'24','height':'24','src':this.attr.xlsbtn,'alt':'Fichier Excel','style':'border:0;','border':'0'})
                    )
                )
            );
        }
        
        this.makePagination();
        if(this.attr.paginContainer != undefined) {
            $(this.attr.paginContainer).empty();
            if (this.attr.pagin_pre != undefined)    {
                 $(this.attr.paginContainer).adopt(new Element('span').setText(this.attr.pagin_pre));
            }
            $(this.attr.paginContainer).adopt(this.pagin);
            if (this.attr.pagin_post != undefined)    {
                 $(this.attr.paginContainer).adopt(new Element('span').setText(this.attr.pagin_post));
            }
            obj = this;
            toggleSelector('a','showPageSelector','click','a_selected',function(elt) {
                myStats.arg["p_nPage"] = elt.id;
                if (obj.attr.dependantContent != undefined) {
                    for (i=0;i<obj.attr.dependantContent.length;i++)  {
                        $(obj.attr.dependantContent[i]).setStyle('display','none');
                    }
                }
                myStats.doRequest(myStats.arg);
            });
        }
        $(this.attr.output).appendChild(this.table);
        if (this.attr.triggerDomReady == true)  {
            window.fireEvent('domready'); 
        }
        if (this.attr.dependantContent != undefined) {
            for (i=0;i<this.attr.dependantContent.length;i++)  {
                $(this.attr.dependantContent[i]).setStyle('display','block');
            }
        }
        //this.table.destroy();
    },
    
    translateIt:function(offset,replacement)  {    
        var myString = this.data[offset][replacement];
        if(this.attr.translation) {
            eval("myTransTab = this.attr.translation.c"+replacement+";");
            if(myTransTab instanceof Array) {
                if(myTransTab.length>0) {
                    myString = myTransTab[myString];
                }
            }
            if (myTransTab instanceof Object)   {
                if (myTransTab[myString])   {
                    myString = myTransTab[myString];
                }
            }
        }
        return myString;
    },
    
    makePagination:function() {
        this.pagin = new Element("span",{'id':'showPageSelector','class':'displaySelector2','name':'p_nPage'});
        nbPage = Math.ceil(this.totRows);
        start = (this.currentPage <= 2 ? 0 : this.currentPage-3);
        if (nbPage <= 5)    {end = nbPage}  else    {
            if (this.currentPage == nbPage) { end = nbPage} else    {
                end = start + 2 > nbPage ? nbPage : start+5;
            }
        }
        if (start > 0)  {
            a = new Element("a",{'id':1,'style':'cursor:pointer'}).setHTML(1);
            span = new Element("span").setHTML(' ... ');
            this.pagin.adopt(a,span);        
        }
        for(i=start;i<end;i++) {
            var page = parseInt(i+1);
            a = new Element("a",{'id':page,'style':'cursor:pointer'}).setHTML(page);
            if(page==this.currentPage)   {
                $(a).addClass('a_selected');
            }
            this.pagin.adopt(a);
        }
        if (end < this.totRows) {
            span = new Element("span").setHTML(' ... ');
            a = new Element("a",{'id':nbPage,'style':'cursor:pointer'}).setHTML(nbPage);
            this.pagin.adopt(span,a);        
        }
    },
    
    makeTitle : function()  {
        if (this.attr.str_stats_du != undefined)    {
            var title         = this.attr.str_stats_du +" "+this.title[0]+" "+this.attr.str_au+" "+this.title[1];
            if (this.title[2] != undefined){
                title+= " "+this.attr.str_pour_prog+" ["+this.title[2]+"]";
            }
        }   else    {
            if (this.attr.str_votre_recherche != undefined)  {
                var title     = this.attr.str_votre_recherche + this.title + this.attr.str_resultats;
            }   else    {
                title=false;
            }
        }
       return title;
    },
    
    getColTitle : function() {
        var i = 0;
        for(myAttr in this.attr.cellDesc) {
            this.myTitle[i]     = myAttr;
            this.myColOrder[i++] = this.attr.cellDesc[myAttr];
        }
    }    
});

var banStatsTable = mtTable.extend({
  draw : function(response) {
    if(response == null    ) return this.triggerError();
        if(response[0].nb_items == 0) return this.triggerError();
        
        this.data         = response[0].data;
        this.title      = response[0].title;
        this.totRows     = response[0].totRows;
        this.currentPage= response[0].currentPage;      
        this.title = this.makeTitle();

        var motif     = "\{c(\\d+)\}";
        var reg        = new RegExp(motif,"g");    
        //this.data = data;
        /** START DRAW<br /> HEADER **/
        this.getColTitle();
        this.table = new Element('table',{
            'class' : this.attr.cssClass,
            'id'     : this.attr.id,
            'border'     : 0,
            'cellpadding'     : 0,
            'cellspacing'     : 0
        });
        thead    = new Element('thead');
        tr        = new Element('tr');
        for(var j=0;j<this.myTitle.length;j++) {
            th    = new Element('th');
            th.setHTML(this.myTitle[j]);
            tr.adopt(th);
        }
        thead.adopt(tr);
        this.table.adopt(thead);
        /** END DRAW HEADER **/

        
        /** START DRAW BODY **/
    tbody = new Element('tbody');
        var toHide = false;
        var toHideClass = "";
        var mainId = 0;
        var odd=0;
        var img = '';
        var toHideClassRow = new Array();
    for(var j=0;j<this.data.length;j++) {
            if(this.data[j][0] == 'total'){
                var total_line = j;
                continue;
            }
            masterSlave_switchOffset = this.data[j].length-1;
            tr = new Element('tr');
            tr.id = "r"+j;
            if (this.data[j][masterSlave_switchOffset] == 0) {
                toHide = true;
            } else {
                toHide = false;
                mainId = j;
            }
            
            // code yanked from the Yahoo media player.
            if (! ("console" in window) || !("firebug" in console)) {
                var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
                window.console = {};
                for (var i = 0; i < names.length; ++i) window.console[names[i]] = function() {};
            }
            
            for(var k=0;k<this.myColOrder.length;k++) {
                var str = this.myColOrder[k];
                
                    var obj = this;
                tmp = str.replace(reg,function (str,replace1) {return obj.translateIt(j,replace1);});
                tmp = tmp.replace(reg,function (tmp,replace1) {return obj.translateIt(j,replace1);});
                td = new Element('td');
                if(toHide == true) {
                    td.addClass("hiddenRow");
                  img = '';
                  if(k==0) {
                 img = "<img src='/include/smarty_tpl/templates/leadium/images/triview.gif' valign='absmiddle'>";
              }
                }
                td.setHTML(img+tmp);
                    tr.adopt(td);
            }
            
            if (toHide == true) {
                tr.addClass("display_none");
                if(!(toHideClassRow[mainId] instanceof Array)) toHideClassRow[mainId] = new Array();
                toHideClassRow[mainId].push(tr);
            } else {
                tr.setStyle('cursor', 'pointer');
                if(++odd%2 == 0) {
                    tr.addClass("odd");
                }
                if(this.attr.hiddenRow == true) {
                    tr.set( {'events': { 'click':function() {
            pId = this.id.substr(1,this.id.length);
                        for(w=0;w<toHideClassRow[pId].length;w++) {
                          toHideClassRow[pId][w].toggleClass('display_row');
                        }
          }}});
                }
            }
            tbody.adopt(tr);
        }

        //create 'total' line
        tr = new Element('tr');
        for(var k=0;k<this.myColOrder.length;k++) {
            var str = this.myColOrder[k];
            var obj = this;
            tmp = str.replace(reg,function (str,replace1) {return obj.translateIt(total_line,replace1);});
            tmp = tmp.replace(reg,function (tmp,replace1) {return obj.translateIt(total_line,replace1);});
            td = new Element('td');
            td.setHTML( (k == 0 ? 'total' : tmp));
            tr.adopt(td);
        }
        tbody.adopt(tr);
        
    this.table.adopt(tbody);
        /** END DRAW BODY **/
        
    $(this.attr.output).empty();
    if (this.attr.mode=='stats') {
        
        if (this.title != false) {
            $(this.attr.output).adopt(new Element('div',{"class":"StatsTitle"}).setText(this.title));
        }
        if (this.attr.exportContainer != undefined)    { $(this.attr.exportContainer).empty();target = this.attr.exportContainer}    else    { target = this.attr.output }
        $(target).adopt(
            new Element('div',{"class":"statsExportData"}).adopt(
                new Element('a',{'id':'refresh','href':'javascript:void(0)','style':'border:0;','border':'0','events':{'click':function(){$('search_go').fireEvent('click');}}}).adopt(
                    new Element('img',{'src':this.attr.refreshbtn,'alt':'rafraichir les resultats','width':'24','height':'24','border':'0','style':'border:0;'})
                ),
                new Element('a',{'id':'urlXml','href':'javascript:void(0)','style':'border:0;','border':'0','events':{'click':function(){getXML();}}}).adopt(
                    new Element('img',{'name':'urlXml','id':'urlXml','width':'24','height':'24','src':this.attr.xmlbtn,'alt':'Flux XML','style':'border:0;','border':'0'})
                ),
                new Element('a',{'id':'urlxls','href':'javascript:void(0)','style':'border:0;','border':'0','events':{'click':function(){getXLS();}}}).adopt(
                    new Element('img',{'name':'urlXls','id':'urlXls','width':'24','height':'24','src':this.attr.xlsbtn,'alt':'Fichier Excel','style':'border:0;','border':'0'})
                )
            )
        );
    }
    
    this.makePagination();
        
    if(this.attr.paginContainer != undefined) {
        $(this.attr.paginContainer).empty();
        if (this.attr.pagin_pre != undefined) {
            $(this.attr.paginContainer).adopt(new Element('span').setText(this.attr.pagin_pre));
        }
        $(this.attr.paginContainer).adopt(this.pagin);
      if (this.attr.pagin_post != undefined)    {
        $(this.attr.paginContainer).adopt(new Element('span').setText(this.attr.pagin_post));
      }
            toggleSelector('a','showPageSelector','click','a_selected',function(elt) {myStats.arg["p_nPage"] = elt.id;myStats.doRequest(myStats.arg);});
        }
        $(this.attr.output).appendChild(this.table);
        if (this.attr.triggerDomReady == true)  window.fireEvent('domready');
        if (this.attr.dependantContent != undefined) {
            for (i=0;i<this.attr.dependantContent.length;i++)  {
                $(this.attr.dependantContent[i]).setStyle('display','block');
            }
        }
    }
});

var myAjax = Ajax.extend({
    initialize : function(properties)   {
        this.arg = new Object();
        this.properties= properties;
        this.parent(this.properties.url, {
                   method: this.properties.method,
                   onComplete:this.doComplete});
    },

    doRequest : function(displayLoading)    {
        
        if (displayLoading==undefined){
            $(this.properties.output).innerHTML = this.properties.loadingMessage;
        }
        
        this.request(this.arg);
        
    },
    
    doComplete : function(result) {
        if(result == "false") {
            alert("Votre session a expirée");
            top.document.location.href="http://www.leadium.com";
        } else {
            r = eval(result);
            this.properties.render.draw(r);
        }
    }
});

var myAjaxStats = myAjax.extend({
    doComplete:function(response){
        r = eval(response);
        this.properties.render.draw(r);
        window.fireEvent('domready');
    }
});

var MyMenu = Ajax.extend({
    initialize : function(properties)   {
        this.properties= properties;
        this.parent(this.properties.url, {
                   method: this.properties.method,
                   onComplete:this.doComplete});
    },

    doRequest : function(add,urlOverride)    {
        var options ='';
        if (urlOverride != null)    {
            if (document.location.href.indexOf('?')==-1)    {
                url = document.location.href;
            }   else    {
                url = document.location.href.substr(0,document.location.href.indexOf('?'));
            }                                                                              
            url = url+'?'+Object.toQueryString(urlOverride);
        }   else    {
            url = document.location.href;
        }
        if (add==true)  {
            var tagName = window.prompt(this.properties.promptStr);
            if (tagName != null)   {
                options = {"method":"add","tag":escape(tagName),"url":escape(url)};
            }
        }
        $(this.properties.container).style.display = 'none';
        this.request(options);
    },
    
    doComplete : function(response) {
        r = eval(response);
        if (r!=null)    {
            $(this.properties.container).style.display='block';
            var len = r[0].length;
            var str = '';
            for(i=0;i<r.length;i++) {
                str+= '<a href="'+r[i][2]+'">'+r[i][1]+'</a> | ';
            }
            $(this.properties.links).innerHTML = str;
        }
    }             
});

function toggleSelector(tagName,ctnrName,evtType,className,callBackFunc) {
    $ES(tagName,ctnrName).addEvent(evtType,function(e) {
         $ES(tagName+'.'+className,ctnrName).removeClass(className);
         this.addClass(className);
         callBackFunc(this);
    });
}


var progTable = mtTable.extend({
   initialize : function(properties)    {
        this.properties = properties;
   },
   
   draw : function(data)  {
        obj=this;
        this.data = data[0].data;
        if (data[0].nb_items  < 1) {
            return this.triggerError();   
        }
        this.nbPage = data[0].nbPage;
        this.currentPage = data[0].currentPage;
        var motif     = "\{(.*?)\}";
        var reg        = new RegExp(motif,"g");
        var regprice = new RegExp("^{(.*?)(price)}$", "g"); 
        var table = new Element('table',{
            'class' : this.properties.class_name,
            'cellspacing' : '0',
            'cellpadding' : '0'
        });              
        var thead = new Element('thead');
        var tr = new Element('tr');
        var i=0;
        for (headerTitle in this.properties.cellDesc)  {   
            var options = null;
            if (i>0 && i<6)  {options = {'style':'width:45px;'};};
            if (i==1 || i==3 || i==5)  {options = {'class':'background','style':'width:45px;'};};
            if (i==0)  { options = {'class':'emphasize leftText', 'width':'170'};  };
            if (i>5 && i<10)  { options = {'style':'width:52px;'};  };
            if (i==10)  { options = {'style':'width:58px;'};  };
            tr.adopt(new Element('th',options).setText(headerTitle));
            i++;
        }
        thead.adopt(tr);
        var tbody = new Element('tbody');
        for (i=0;i<this.data.length;i++)  {
            var tr = new Element('tr');
            tr.programme = new Prog(this.data[i],this.properties);
            var j=0;
            
            for (headerTitle in this.properties.cellDesc)  {
                var options = null;
                if (j==1 || j==3 || j==5)  {options = {'class':'background'};};
                var td = new Element('td',options);
                str = this.properties.cellDesc[headerTitle];
                if (regprice.test(str))  {
                    regprice.test(str);
                    tmp = str.replace(reg,function (str,replace1) {return obj.data[i][replace1];});
                    
                    if (tmp>0) {
                        if(str == '{leadprice}') {
                            if (this.properties.str_currency_pos=='left'){
                                tmp = this.properties.str_currency+tmp;
                            } else {
                                tmp = tmp+this.properties.str_currency;
                            }
                        }
                        if(str == '{saleprice}') {
                            if (obj.data[i]['salecurrency'] == 1)   {
                                tmp = tmp/1+"%";
                            }   else    {
                                if (this.properties.str_currency_pos=='left'){
                                    tmp = this.properties.str_currency+tmp;
                                } else {
                                    tmp = tmp+this.properties.str_currency;
                                }
                            }
                        }
                        tmp = '<div class="price">'+tmp+'</div>';
                    } else {
                        tmp = '';
                    }
                }   else    {
                    tmp = str.replace(reg,function (str,replace1) {return obj.data[i][replace1];});
                }
                td.innerHTML = tmp;
                tr.adopt(td);
                j++;
            }
            tbody.adopt(tr);
        }        
        table.adopt(thead);
        table.adopt(tbody);
        $(this.properties.output).empty().adopt(table);
        $(this.properties.paginContainer).empty();
        this.makePagination();
        if (this.properties.pagin_pre != undefined)    {
             $(this.properties.paginContainer).adopt(new Element('span').setText(this.properties.pagin_pre));
        }
        $(this.properties.paginContainer).adopt(this.pagin);
        if (this.properties.pagin_post != undefined)    {
             $(this.properties.paginContainer).adopt(new Element('span').setText(this.properties.pagin_post));
        }
        toggleSelector('a','showPageSelector','click','a_selected',function(elt) {args.p_nPage = elt.id.substr(5);myProgList.doRequest(args);});
    },
    
    makePagination:function() {                    
        this.pagin = new Element("span",{'id':'showPageSelector','class':'displaySelector2'});
        for(i=0;i<this.nbPage;i++) {
            a = new Element("a",{'id':'page_'+parseInt(i+1),'style':'cursor:pointer'}).setHTML(parseInt(i+1));
            if(parseInt(i+1)==this.currentPage)   {
                $(a).addClass('a_selected');
            }
            this.pagin.adopt(a);
        }
        return this.pagin;
    },

   triggerError : function()    {
      obj = this;
      $(this.properties.output).empty();
      $(this.properties.output).adopt(new Element('div',{'class':'error'}).setText(obj.properties.msg_noResult));
      if ($(this.properties.paginContainer) != undefined) {
        $(this.properties.paginContainer).empty();
      }
      return false;
   }
});

var Prog = new Class({
    initialize : function(options,option) {
        for(property in option)    {
            this[property] = option[property];
        }
        for(property in options)    {
            this[property] = options[property];
        }
    },

    toggleDisplay : function(parent)   {
        this.parent = parent;
        if (this.isDisplayed == true)   {    
            $('details_'+this.id).toggleClass('hidden');
        }   else    {
            this.drawDetails().injectAfter(this.parent);
            this.isDisplayed = true;
        }
    },
    
    drawDetails : function()  {
        obj = this;
    var info = '<a href="javascript:void(0)" class="infobulle">';
        var tr = new Element('tr',{'class':'progList_progDetails','id':'details_'+obj.id});
        var td = new Element('td',{'colspan':'11'});
        var div= new Element('div',{'class':'progDetails'});
        
        div.adopt(new Element('div',{'class':'imageContainer'}).adopt(
            new Element('center').adopt(
                new Element('img',{'src':'http://'+screenshot_path+obj.id+'.jpg'}))
            )
        );
        
        var divdetail = new Element('div',{'class':'detailsContainer'});
        sdesc = (obj.shortdesc == "HTML" ? obj.msg_progHtml : obj.shortdesc); 
        var cat = (obj.cat[obj.progcat1].length > 33 ? obj.cat[obj.progcat1].substr(0,30)+'...' : obj.cat[obj.progcat1]);
        divdetail.adopt(
            new Element('div',{'class':'categoryName'}).adopt(
                new Element('strong').setText(obj.catstring),
                new Element('span').setText(cat+".")
            )
        );
        divdetail.adopt(new Element('textarea').setText(sdesc));


        divdetail.adopt(new Element('table',{'class':'table_progAuth'}).adopt(new Element('tbody').adopt(
                            new Element('tr').adopt(                                                                                                 
                                new Element('td').setHTML(obj.str_kw+'<br /><img src="'+template_string+'images/ico_keyword_'+obj.keyword+'.gif"/>'),
                                new Element('td').setHTML(info + obj.str_flux + '<em>'+obj.xml_info+'</em></a><br /><img src="'+template_string+'images/ico_xml_'+obj.xml+'.gif"/>'),
                                new Element('td').setHTML(obj.str_txt+'<br /><img src="'+template_string+'images/ico_lientexte_'+obj.text+'.gif"/>'),
                                new Element('td').setHTML(obj.str_cook+'<br /><img src="'+template_string+'images/ico_cookie_'+obj.cookie+'.gif"/><br />'+obj.cookies+' '+obj.str_jours),
                                new Element('td').setHTML(info + obj.str_incentive+'<em>'+obj.incentive_info+'</em></a><br /><img src="'+template_string+'images/ico_incentive_'+obj.incentive+'.gif"/>'),
                                new Element('td',{'class':'last'}).setHTML(obj.str_postview+'<br /><img src="'+template_string+'images/ico_postview_'+obj.postview+'.gif"/>')
                            )
                        )
                    ));
        return tr.adopt(td.adopt(div.adopt(divdetail)));           
    }
}); 
var resumeTable = new Class({
    initialize:function(options)    {
        var motif     = "\{c(\\d+)\}";
        this.reg      = new RegExp(motif,"g");    
        for(property in options)    {
            this[property] = options[property];
        }
    },
    
    draw: function(data)    {
        if (data[0].nb_items == 0) { 
           return this.triggerError();
        }
        obj = this;
        this.data = data[0].data;
        
        var table = new Element('table',{'class':this.class_name});
        var thead = new Element('thead');
        var tbody = new Element('tbody');
        tr =new Element('tr');
        for(k=0;k<this.rowDesc[0].length;k++)  {
            tr.adopt(new Element('th').setText(this.rowDesc[0][k]));    
        }
        thead.adopt(tr);
        var field;
        var j;
        for (i=1;i<this.rowDesc.length;i++) {
            tr =new Element('tr');          
            for (j=0;j<this.rowDesc[0].length;j++)  {                                              
                str = obj.rowDesc[i][j];
                str = str.replace(this.reg,function (str,replace1) {
                    return myString = obj.data[(obj.data.length)-1][replace1];
                })
                td = new Element('td').setHTML(str);
                tr.adopt(td); 
               if (j==obj.rowDesc[0].length)  { td.addClass('last');  }     
            }                                                          
            tbody.adopt(tr);
        }
        $(this.output).empty();
        table.adopt(thead,tbody);
        $(this.output).adopt(table);
    },
    
    triggerError : function()   {
        var obj = this;
        $(this.output).empty().adopt(new Element('div',{'class':'error'}).setText(obj.msg_noResult));
        return false;
    }
});  
  
var banTable = mtTable.extend({
    initialize : function(properties) {
       this.properties = properties;
       this.attr = properties; 
       this.rxps = new Array();
       for(needle in this.properties.translations)  {
            this.rxps[this.rxps.length] ={
                "str_replace" : this.properties.translations[needle],
                "regexp" :  new RegExp("(\{"+needle+"\})","g")
            };
       }
    },
                                        
    drawListingTable : function()   {
        var i=0;
        obj = this;
        $(this.properties.output).empty();    
        for (ban in this.data)  {
           if (this.data[ban].banlock != 1) {
                if (this.data[ban].isResized == true)   {

                    //flash preview patch
                    if (obj.data[ban].bantype=="flash"){
                        var subpos = obj.data[ban].sizelabel.indexOf('x');
                        
                        if (subpos>0){
                            var picWidth = obj.data[ban].sizelabel.substr(0,subpos);
                            var picHeight = obj.data[ban].sizelabel.substr(subpos+1,obj.data[ban].sizelabel.length-picWidth.length);
                            var add = "["+picWidth+" "+picHeight+"]";
                        } else {
                            var add = "[550 410]";
                        }
                    } else {
                        var add = "[550 410]";
                    }
                    
                    if (obj.data[ban].bantype=="siteunder"){
                        strResize = "";
                    } else {
                        //[550 410]
                        strResize = "<span class='redim_visuel'><a href='"+obj.data[ban].banurl+"' rel='lightbox"+add+"'  caption='"+obj.data[ban].sizelabel+"' class='"+obj.data[ban].sizelabel+"'>"+obj.properties.str_Resize+" : ( "+obj.data[ban].sizelabel+" )</a></span><br />";  
                    }
                }   else    {
                    strResize = '';
                }
                
               var image = (obj.data[ban].image == null ? '' : obj.data[ban].image);
               var tabs =  (obj.data[ban].tabs == null ? '' : obj.data[ban].tabs);
               tabs = this.translateIt(tabs);
               $(this.properties.output).adopt(new Element('table',{'width':'100%'}).adopt(new Element('tbody').adopt(new Element('tr').adopt(
                    new Element('td',{'width':'260','valign':'top','style':'padding:5px','class':'row'+((i%2)+1)}).setHTML(
                        this.properties.strings.str_programme + " : <strong>"+obj.data[ban].prognom+"</strong> <br/> "+this.properties.strings.str_idvisuel+" : <strong>"+obj.data[ban].banid+"</strong> <br/> "+((obj.data[ban].bantype=='siteunder')?'':this.properties.strings.str_size+" : <strong>"+obj.data[ban].sizelabel+"</strong><br/>") + this.properties.strings.str_type+" : <strong> "+obj.properties.bantypes[obj.data[ban].bantype]+"</strong><br/>"+
                        (((obj.data[ban].bantype=='emailhtml') || (obj.data[ban].bantype=='html'))?
                            ''
                        :
                            this.properties.strings.str_restricted+' : <strong>'+(((obj.data[ban].geoallowed==undefined) || (obj.data[ban].geoallowed=='[]'))?this.properties.strings.str_aucune:this.properties.strings.str_oui+' <a style="cursor:pointer;" onclick="javascript:window.open(\'/aff/aff_geoloc.php?banid='+obj.data[ban].banid+'\',\'GeolocAff\',\'toolbar=no, location=no, directories=no, status=yes,scrollbars=yes, resizable=no, copyhistory=no, width=540, height=440, left=200, top=100\');" style="color:#999999;" class="genLink" target="_blank"><b>['+this.properties.strings.str_voir+']</b></a>')+'</strong>'
                        )+
                        
                        "<br /><br />" +strResize +image
                    ), 
                    new Element('td',{'valign':'top','width':'469','class':'row'+((i%2)+1)}).setHTML(
                    
                        tabs +  this.properties.strings.str_ajoute+" : "+obj.data[ban].dateadd+" - "+this.properties.strings.str_maj+" : "+obj.data[ban].datemaj    )
               ))));       
               i++;
           }   
        }
       tabberAutomatic();
    },
    
    translateIt : function(str) {
        for(i=0;i<this.rxps.length;i++)  {               
            str = str.replace(this.rxps[i].regexp,this.rxps[i].str_replace);
        }
        return str;                     
    },
    
    draw : function(data)   {
        this.dataBrut = data;
        if (data[0].nb_items == 0)  {
            return this.triggerError();
        }
        this.data = data[0].data;
        this.drawListingTable();     
        window.fireEvent('domready');
    }   
});


var flashRes = new Class({
  initialize : function(flashSrc,options)   {
    this.options = options;
    this.flashSrc = flashSrc;
  },
  draw :function(response)  {
    if (response[0].nb_items == 0)   {
        this.triggerError();
        return false;
    }
    obj = this;
    data = response[0].data;
    data+= "&str_prints="+ this.options.str_cpm;
    data+= "&str_clics=" + this.options.str_clics;
    data+= "&str_leads=" + this.options.str_leads;
    data+= "&str_sales=" + this.options.str_sales;
    data+= "&str_dates=" + this.options.str_dates;
    data+= "&str_loading=" + this.options.str_loading;
    data+= "&mode=" + this.options.act_Mode;
    
    data+= "&str_Error_1=" + this.options.str_Error_1;
    data+= "&str_Error_2=" + this.options.str_Error_2;
    data+= "&str_Error_3=" + this.options.str_Error_3;

        
    var teste = document.createElement('embed');
    teste.setAttribute('src', obj.flashSrc);
    teste.setAttribute('quality', 'high');
    teste.setAttribute('bgcolor', '#ffffff');
    teste.setAttribute('width', '700');
    teste.setAttribute('height', '350');
    teste.setAttribute('name', 'newGraphe');
    teste.setAttribute('flashvars', data);
    teste.setAttribute('align', 'middle');
    teste.setAttribute('wmode', 'transparent');
    teste.setAttribute('allowScriptAccess', 'sameDomain');
    teste.setAttribute('type', 'application/x-shockwave-flash');
    teste.setAttribute('pluginspage', 'http://www.macromedia.com/go/getflashplayer');
    $(this.options.output).empty();
    document.getElementById(this.options.output).appendChild(teste);
    


  },
  
  triggerError : function()    {
      obj = this;
      $(this.options.output).empty();
      $(this.options.output).adopt(new Element('div',{'class':'error'}).setText(obj.options.msg_noResult));
      return false;
   }

});  

var AffListHandler = new Class({
  initialize : function(options)   {
    this.options = options;
  },
  
  draw :function(response)  {
    obj         = this;
    
    if (response[0]['error']==0){
    
    
    var aff_in      = response[0]['data']['aff_in'];
    var aff_out     = response[0]['data']['aff_out'];
    $(obj.options.output_in).empty();
    $(obj.options.output_out).empty();
    var myTableIn = new Element('table',{'style':'padding:0 5px 0 5px','id':'mer_manage_group_list_in','class':'mer_style'});    
    var myTableOut = new Element('table',{'style':'padding:0 5px 0 5px','id':'mer_manage_group_list_out','class':'mer_style'});
    myTableIn.adopt(
        new Element('thead').adopt(
            new Element('tr').adopt(
                new Element('td',{'style':'padding:0 5px 0 5px'}).setHTML(obj.options.str_aff_site),
                new Element('td',{'style':'padding:0 5px 0 5px'}).setHTML(obj.options.str_aff_type),
                new Element('td',{'style':'padding:0 5px 0 5px'}).setHTML(obj.options.str_retirer)
            )
        )
    )
    myTableOut.adopt(
        new Element('thead').adopt(
            new Element('tr').adopt(
                new Element('td',{'style':'padding:0 5px 0 5px'}).setHTML(obj.options.str_aff_site),
                new Element('td',{'style':'padding:0 5px 0 5px'}).setHTML(obj.options.str_aff_type),
                new Element('td',{'style':'padding:0 5px 0 5px'}).setHTML(obj.options.str_ajouter)
            )
        )
    )

    $(obj.options.output_in).adopt(
        myTableIn
    )        

    $(obj.options.output_out).adopt(
        myTableOut
    )        
    
    var mybody = new Element('tbody');
    myTableIn.adopt(
        mybody
    )
    
    var counter = 0
    if (aff_in != null)    {
        $each(aff_in,function(value,key){
            className = (counter%2==0 ? 'row1' : 'row2');
            counter+=1;

            retirerBtn = new Element('button',{'class':'small','id':'remove_affsite', 'name':'remove_affsite', 'affsiteid':key+';'+aff_in[key].affid, 'alt':obj.options.str_retirer+' '+obj.options.gplabel}).adopt(
                new Element('span').setText(obj.options.btn_retirer)
            )


            mybody.adopt(
                new Element('tr',{'class':className}).adopt(
                    new Element('td',{'style':'padding:0 5px 0 5px'}).setHTML(value.affsitenom),
                    new Element('td',{'style':'padding:0 5px 0 5px'}).setHTML(value.grp),
                    new Element('td',{'style':'padding:0 5px 0 5px'}).adopt(
                        new Element('center').adopt(
                            retirerBtn        
                        )
                    )
                )       
            )
            
            
            
        })
    }       

    var mybody = new Element('tbody');
    myTableOut.adopt(
        mybody
    )

    var counter = 0
    if (aff_out != null)    {
        $each(aff_out,function(value,key){
            className = (counter%2==0 ? 'row1' : 'row2');
            
            ajouterBtn = new Element('button',{'class':'small','id':'add_affsite', 'name':'add_affsite', 'affsiteid':key+';'+aff_out[key].affid, 'alt':obj.options.str_ajouter+' '+obj.options.gplabel}).adopt(
                new Element('span').setText(obj.options.btn_ajouter)
            )

            
            
            counter+=1;
            mybody.adopt(
                new Element('tr',{'class':className}).adopt(
                    new Element('td',{'style':'padding:0 5px 0 5px'}).setHTML(value.affsitenom),
                    new Element('td',{'style':'padding:0 5px 0 5px'}).setHTML(value.grp),
                    new Element('td',{'style':'padding:0 5px 0 5px'}).adopt(
                        new Element('center').adopt(
                            ajouterBtn
                        )
                    )
                )       
            )
        })
    }       
    this.triggerClicks();    
    } else {
        if (response[0]['error']==1){
            alert(this.options['str_error_1']);
        }
    }
  },
  
  triggerClicks:function()  {
      window.fireEvent('addFunctions'); //the addEvents are in the tpl now
    /*if($('add_affsite')){
      $('add_affsite').addEvent('click',function()   {
        myAffs.arg = args;
        myAffs.arg.add = this.getProperty('affsiteid');
        myAffs.doRequest();
        delete myAffs.arg.add;
      });
    }*/
    /*if($('remove_affsite')){
      $('remove_affsite').addEvent('click',function()   {
        myAffs.arg = args;
        myAffs.arg.del = this.getProperty('affsiteid');
        myAffs.doRequest();
        delete myAffs.arg.del;
      });
    }*/
  }
});  


var siteHandler = new Class({
   initialize : function(strings,traf_button,act_button,container,siteid,isBase,thousand_sep,unit_sep) {
     this.traf_state    = 0;
     this.act_state     = 0;
     this.strings       = strings;
     this.traf_button   = traf_button;
     this.act_button    = act_button;
     this.siteid        = siteid;
     this.container     = container;
     this.isBase        = isBase;
     this.thousand_sep  = thousand_sep;
     this.unit_sep      = unit_sep;
   },
   
   traf_listen : function() {
        var obj_sh = this;
        $(this.traf_button).addEvent('click',function() {
            if (obj_sh.traf_state == 0)    {
                obj_sh.traf_edit();
            }   else    {
                obj_sh.traf_update();   
            }
        });
   },
   
   act_listen : function()  {
        var obj_sh = this;
        $(this.act_button).addEvent('click',function() {
            if (obj_sh.act_state == 0)    {
                obj_sh.act_edit();
            }   else    {        
                obj_sh.act_update();   
            }
        });       
   },
   
   traf_edit : function()   {
        elts = $ES('div[name=traf]',$(this.container));
        for(i=0;i<elts.length;i++)   {
            obj = elts[i];
            id = obj.getAttribute('newid');
            value= obj.getAttribute('newvalue');
            if (id == 'poph' || id == 'popf')    {
                obj.replaceWith(new Element('div',{'name':'traf','newid':id}).adopt(
                    new Element('div').adopt(
                        new Element('select',{'style':'width:90px','id':id}).adopt(
                            new Element('option',{'value':1}).setText(this.strings.oui_str), 
                            new Element('option',{'value':0}).setText(this.strings.non_str) 
                          )
                       )
                    )                            
                )
            }
            else    {
                if (id=='pourch' || id.substr(0,3) == 'csp')    {
                    obj.replaceWith(new Element('div',{'name':'traf','newid':id}).adopt(
                        new Element('input',{'type':'text','style':'width:40px','size':'5','id':id,'value':value})
                    ).appendText(' '+this.strings.pourcentage));
                }   else    {
                    obj.replaceWith(new Element('div',{'name':'traf','newid':id}).adopt(
                        new Element('input',{'type':'text','style':'width:90px','id':id,'value':value})
                    ));
                }
            }
        }                 
        this.traf_state = 1;
        $(this.traf_button).setText(this.strings.valider_str);
   },
   
   traf_update : function() {
        ajx = new Ajax('/include/lib/aff_lib_site_actions.php');
        options = new Object();
        if (this.isBase == 1) {
            options['volumeoptin']    = $(this.container).getElement('input[id=volumeoptin]').value;      
            options['pourch']         = $(this.container).getElement('input[id=pourch]').value;  
        }   else    {
            options['affsitevu']      = $(this.container).getElement('input[id=affsitevu]').value;      
            options['affsitetraff']   = $(this.container).getElement('input[id=affsitetraff]').value;  
            options['pourch']         = $(this.container).getElement('input[id=pourch]').value;  
        }            
        options['cspp']               = $(this.container).getElement('input[id=cspp]').value;
        options['csp']                = $(this.container).getElement('input[id=csp]').value;
        options['cspm']               = $(this.container).getElement('input[id=cspm]').value;
        options['siteid']             = this.siteid; 
        options['traffic']            = 'traffic';
        ajx.request(options);
        elts = $ES('div[name=traf]',$(this.container));
        for(i=0;i<elts.length;i++)   {
            isImage = false;
            obj = elts[i];
            name = obj.getAttribute('name');
            id = obj.getAttribute('newid');
            if (id=='poph')  {                  
                value = options['poph'];
                isImage = true;                               
                valueTxt = (value == 1 ? this.strings.oui_str : this.strings.non_str);
                valueImg = new Element('img',{'src':(value == 1 ? this.strings.oui_img : this.strings.non_img),'alt':valueTxt});
            }
            else if (id=='popf')  {                                                    
                value = options['popf'];
                isImage = true;
                valueTxt = (value == 1 ? this.strings.oui_str : this.strings.non_str);
                valueImg = new Element('img',{'src':(value == 1 ? this.strings.oui_img : this.strings.non_img),'alt':valueTxt});
            }
            else if (id=='pourch')    {
                value = options['pourch'];
                valueTxt = options['pourch'];
                valueTxt = Number(valueTxt);
                valueTxt = valueTxt.nombreFormate(2,this.unit_sep,this.thousand_sep)+this.strings.pourcentage; 
            }
            else {                  
                value = options[obj.getAttribute('newid')];
                valueTxt = options[obj.getAttribute('newid')];
                valueTxt = Number(valueTxt);       
                if (id.substr(0,3) == 'csp')    { 
                    valueTxt = valueTxt.nombreFormate(2,this.unit_sep,this.thousand_sep);
                    valueTxt+='%';
                }   else    {
                    valueTxt = valueTxt.nombreFormate(0,this.unit_sep,this.thousand_sep);
                }
            }
            if (isImage ==true) { 
                obj.replaceWith(
                    new Element('div',{
                        'name':name,
                        'newid':id,
                        'newvalue':value}).adopt(valueImg).appendText(' '+valueTxt)
                );    
            }   else    {
                obj.replaceWith(
                    new Element('div',{
                        'name':name,
                        'newid':id,
                        'newvalue':value}).appendText(valueTxt)
                );
            }
        }
        
        this.traf_state = 0;
        $(this.traf_button).setText(this.strings.modifier_str);           
   },
   
   act_edit :   function()  {
    elts = $ES('div[name=actions]',$(this.container));
    for(i=0;i<elts.length;i++)   {
    obj = elts[i];
    id = obj.getAttribute('newid');
    value= obj.getAttribute('cvalue');
    value = (value == '' ? 0 : 1);          
    obj.replaceWith(
        new Element('div').adopt(
            new Element('select',{'style':'width:90px','id':id}).adopt(
                new Element('option',{'value':1}).setText(this.strings.oui_str), 
                new Element('option',{'value':0}).setText(this.strings.non_str) 
              )
           )
        )
        for (j=0;j<$(id).options.length;j++)   {
            if ($(id).options[j].value == value )  {
                $(id).options[j].selected = 'selected';
                break;
            }
        }                 
    }
    $(this.act_button).setText(this.strings.valider_str);
    this.act_state = 1;
   },
   
   act_update : function()  {
       ajx = new Ajax('/include/lib/aff_lib_site_actions.php');
       act_str = '';
       for(i=1;i<=5;i++)    {
          if ($(this.container).getElement('select[id=act_'+i+']').get('value') == 1)  {
            act_str +=i+'|';
          }
       }
       if(act_str.length > 1)   {
        act_str = act_str.substr(0,act_str.length-1);
       }
       ajx.request({'affaction':act_str,'siteid':this.siteid});
       for(i=1;i<=5;i++)    {
           if($(this.container).getElement('select[id=act_'+i+']').get('value') == 1)  {
            img = this.strings.oui_img;
            str = this.strings.oui_str;
            cvalue = (i-1)*2;
           }    else    {
            img = this.strings.non_img;
            str = this.strings.non_str;
            cvalue = '';
           }
           $(this.container).getElement('select[id=act_'+i+']').parentNode.replaceWith(
                new Element('div',{'name':'actions', 'newid':'act_'+i,'id':'12', 'cvalue':cvalue}).adopt(
                   new Element('img',{'src':img,'alt':str})                   
                ).appendText(' '+str)
            )
       }
       $(this.act_button).setText(this.strings.modifier_str);
       this.act_state = 0;
   }
});    

var banMerTable = banTable.extend({

    initialize: function(properties)  {
        obj=this;
       this.properties = properties;
       this.attr = properties;
       this.rxps = new Array();        
       this.affids_select = new Object;
       this.groupes_select = new Object;
       this.gpban_select = new Object;
       
       for(needle in this.properties.translations)  {
            this.rxps[this.rxps.length] ={
                "str_replace" : this.properties.translations[needle],
                "regexp" :  new RegExp("(\{"+needle+"\})","g")
            };
       }

       
       
       // <!-- selects 
        this.formats_select = new Element("select",{"name":"bansize"});
        this.formats_select.adopt(new Element("option",{"value":"0","label":this.properties.str_choix}).setText(this.properties.str_choix));
        for(sizeid in this.properties.sizes)    {
             this.formats_select.adopt(new Element("option",{"value":sizeid,"label":this.properties.sizes[sizeid]}).setText(this.properties.sizes[sizeid]));
        }
        for(progid in this.properties.affs)   {
            this.affids_select[progid]  = new Element("select",{"name":"affid"});
            var affids = this.properties.affs[progid];
            this.affids_select[progid].adopt(new Element("option",{"value":"0","label":this.properties.str_choix}).setText(this.properties.str_choix));
            for(affid in affids)    {
                 this.affids_select[progid].adopt(new Element("option",{"value":affid,"label":affids[affid]}).setText(affids[affid]));
            }
            this.groupes_select[progid] = new Element("select",{"name":"gpid"});
            var gpids = this.properties.groupes[progid];
            this.groupes_select[progid].adopt(new Element("option",{"value":"0","label":this.properties.str_choix}).setText(this.properties.str_choix));
            for(gpid in gpids)    {
                 this.groupes_select[progid].adopt(new Element("option",{"value":gpid,"label":gpids[gpid]}).setText(gpids[gpid]));
            }
            this.gpban_select[progid] = new Element("select",{"name":"gpban"});
            var gpids = this.properties.gpban[progid];
            this.gpban_select[progid].adopt(new Element("option",{"value":"0","label":this.properties.str_choix}).setText(this.properties.str_choix));
            for(gpid in gpids)    {
                 this.gpban_select[progid].adopt(new Element("option",{"value":gpid,"label":gpids[gpid].gpbanlabel}).setText(gpids[gpid].gpbanlabel));
            }
        }
        // -->  
    },
    editMode : function(element,styleID,ban){
        var formats = this.formats_select.clone();
        var select_affid = this.affids_select[ban.progid].clone();
        var select_gp = this.groupes_select[ban.progid].clone();
        var select_gpban = this.gpban_select[ban.progid].clone();       
        var leftFormat = new Element('div');
        var i;
        for(i=0;i<formats.options.length;i++)  {
            if (formats.options[i].value == ban.bansize)  {
               formats.options[i].selected = 'selected'; 
            }
        }
        if (ban.affid != '' && ban.affid >0)    {
            for(i=0;i<select_affid.options.length;i++)  {
                if (select_affid.options[i].value == ban.affid)  {
                   select_affid.options[i].selected = 'selected'; 
                }
            }
        }
        if (ban.gpid != '' && ban.gpid >0)    {
            for(i=0;i<select_gp.options.length;i++)  {
                if (select_gp.options[i].value == ban.gpid)  {
                   select_gp.options[i].selected = 'selected'; 
                }
            }
        }
        if (ban.gpbanid != '' && ban.gpbanid >0)    {
            for(i=0;i<select_gpban.options.length;i++)  {
                if (select_gpban.options[i].value == ban.gpbanid)  {
                   select_gpban.options[i].selected = 'selected'; 
                }
            }
        }
        
        
        
        
        
        var leftBanPriv = new Element('div').adopt(
            new Element('span').set('html',obj.properties.str_banpriv+' : '),
            new Element('strong').set('html',(ban.banpriv == 0 ? obj.properties.str_non : (obj.properties.str_oui+' : '+obj.properties.str_types[ban.privtype]+' '+(ban.privtype == 1 ? obj.properties.affs[ban.progid][ban.privid] : obj.properties.groupes[ban.progid][ban.privid]))))
        );
        var leftBanGrp = new Element('div').adopt(
            new Element('span').set('html',obj.properties.str_groupe+' : '),
            new Element('strong').set('html',(ban.gpname == null ? obj.properties.str_aucun : ban.gpname))
        )
        
        var capping = 
            new Element('div',{'class':'littleMargin'}).appendText(obj.properties.str_display_freq+' : ').adopt(//appendText(obj.properties.str_display_freq+" : ")
                new Element('input',{'type':'text','name':'capfrequency','id':'capfrequency','style':'width:30px','value':ban.capfrequency})
            ).appendText(" "+obj.properties.str_every+" ").adopt(
                new Element('input',{'type':'text','name':'captime','id':'captime','style':'width:30px','value':ban.captime})
            ).appendText(' ').adopt(
                new Element('select',{'name':'capunit','style':'width:auto;'}).adopt(
                    new Element('option',{'value':'1','selected':((ban.capunit==1)?'selected':'')}).set('html',obj.properties.str_days),
                    new Element('option',{'value':'2','selected':((ban.capunit==2)?'selected':'')}).set('html',obj.properties.str_hours)
                )
            );
        
        switch(ban.bantype){
            case 'gif':    
                var leftFormat = new Element('div').adopt(new Element('span').set('html',obj.properties.str_format+' : '),formats);
                leftSideContent = new Element("div",{"text-align":"left"}).adopt(
                    new Element('div',{'class':'littleMargin'}).appendText(obj.properties.str_visuelurl).adopt(new Element("input",{"name":"banurl","type":"text","value":ban.banurl,"size":"35","style":"margin-left:5px;"})),
                    new Element('div',{'class':'littleMargin'}).appendText(obj.properties.str_visuelredir).adopt(new Element("input",{"name":"bandestinurl","type":"text","value":ban.bandestinurl,"size":"35","style":"margin-left:5px;"}))
                );
                leftSideContent.adopt(
                    capping
                )
            break;
            case 'html':    
                leftSideContent = new Element("div",{"text-align":"left"}).appendText(obj.properties.str_visuelhtml).adopt(
                new Element('br'),
                new Element("textarea",{"name":"banhtml","type":"text","disabled":"disabled","value":ban.banhtml,"cols":"35","rows":"10","style":"margin-left:5px;"})).adopt(
                new Element("br"));
            break;
            case 'flash':    
                var leftFormat = new Element('div').adopt(new Element('span').set('html',obj.properties.str_format+' : '),formats);
                leftSideContent = 
                    new Element("div",{"text-align":"left"}).appendText(obj.properties.str_flashurl).adopt(
                        new Element("input",{"name":"banurl","type":"text","value":ban.banurl,"size":"35","style":"margin-left:5px;"})
                    ).adopt(
                        new Element("br")
                    ).appendText(obj.properties.str_visuelredir).adopt(
                        new Element("input",{"name":"bandestinurl","type":"text","value":ban.bandestinurl,"size":"35","style":"margin-left:5px;"})
                    ).adopt(
                        new Element("br")
                    ).appendText(obj.properties.str_clickTag).adopt(
                        new Element('input',{'type':'text','name':'custom_clicktag_var','value':((ban.custom_clicktag_var==undefined)?'clickTag':ban.custom_clicktag_var)})
                    );
                leftSideContent.adopt(
                    capping
                )
            break;
            case 'text':    
                leftSideContent = new Element("div",{"text-align":"left"}).appendText(obj.properties.str_txtwinname).adopt(new Element("input",{"name":"bandescription","type":"text","value":ban.bandescription,"size":"35","style":"margin-left:5px;"})).adopt(
                new Element("br")).appendText(obj.properties.str_txtlink).adopt(new Element("input",{"name":"bantext","type":"text","value":ban.bantext,"size":"35","style":"margin-left:5px;"})).adopt(
                new Element("br")).appendText(obj.properties.str_visuelredir).adopt(new Element("input",{"name":"bandestinurl","type":"text","value":ban.bandestinurl,"size":"35","style":"margin-left:5px;"})).adopt(
                new Element("br"));
            break;
            case 'emailhtml':    
                leftSideContent = new Element("div",{"text-align":"left"}).appendText(obj.properties.str_visuelhtml).adopt(
                new Element('br'),
                new Element("textarea",{"name":"banhtml","type":"text","disabled":"disabled","value":ban.banhtml,"cols":"35","rows":"10","style":"margin-left:5px;"})).adopt(
                new Element("br"))
                /*.appendText(obj.properties.str_mailkiturl).adopt(new Element("input",{"name":"urlmail","type":"text","value":obj.data[banid].banurl,"size":"35","style":"margin-left:5px;"})).adopt(
                new Element("br"))*/;
            break;
            case 'popup':    
                var leftFormat = 
                    new Element('div').adopt(
                        new Element('span').set('html',obj.properties.str_format+' : '),formats
                    );
                leftSideContent = 
                    new Element("div",{"text-align":"left"}).appendText(obj.properties.str_titrewin).adopt(
                        new Element("input",{"name":"bantext","type":"text","value":ban.bantext,"size":"35","style":"margin-left:5px;"})
                    ).adopt(
                new Element("br")).appendText(obj.properties.str_visuelurl).adopt(new Element("input",{"name":"banurl","type":"text","value":ban.banurl,"size":"35","style":"margin-left:5px;"})).adopt(
                new Element("br")).appendText(obj.properties.str_redirwin).adopt(new Element("input",{"name":"bandestinurl","type":"text","value":ban.bandestinurl,"size":"35","style":"margin-left:5px;"})).adopt(
                new Element("br"));
                leftSideContent.adopt(
                    capping
                )
            break;
            case 'popunder':    
                varleftFormat = new Element('div').adopt(new Element('span').set('html',obj.properties.str_format+' : '),formats);
                leftSideContent = new Element("div",{"text-align":"left"}).appendText(obj.properties.str_popunder).adopt(new Element("input",{"name":"bantext","type":"text","value":ban.bantext,"size":"35","style":"margin-left:5px;"})).adopt(
                new Element("br")).appendText(obj.properties.str_visuelurl).adopt(new Element("input",{"name":"banurl","type":"text","value":ban.banurl,"size":"35","style":"margin-left:5px;"})).adopt(
                new Element("br")).appendText(obj.properties.str_redirwin).adopt(new Element("input",{"name":"bandestinurl","type":"text","value":ban.bandestinurl,"size":"35","style":"margin-left:5px;"})).adopt(
                new Element("br"));
                leftSideContent.adopt(
                    capping
                )
            break;
            case 'siteunder':    
                leftSideContent = new Element("div",{"text-align":"left"}).appendText(obj.properties.str_siteunder).adopt(new Element("input",{"name":"bantext","type":"text","value":ban.bantext,"size":"35","style":"margin-left:5px;"})).adopt(
                new Element("br")).appendText(obj.properties.str_redirwin).adopt(new Element("input",{"name":"bandestinurl","type":"text","value":ban.bandestinurl,"size":"35","style":"margin-left:5px;"})).adopt(
                new Element("br"));
                leftSideContent.adopt(
                    capping
                )
            break;
        }
        
        
        
        
        var validBtns = new Array(
            new Element('button',{'class':((this.properties.afilio)?'button':'big'),'events':{'click':function(){
                obj.doUpdate(element,ban,styleID);
            }}}).adopt(
                new Element('span').set('html',obj.properties.str_modifier)
            ),
            new Element('button',{'class':((this.properties.afilio)?'button':'big'),'events':{'click':function(){
                element = obj.displayMode(element,styleID,ban);    
            }}}).adopt(
                new Element('span').set('html',obj.properties.str_back)
            )
        );
        
        element.empty().adopt(
            new Element('td',{'class':'banResults left_row row'+styleID,'valign':'top','style':'width:178px;'}).adopt(
                new Element('div').adopt(//ok don't change
                    new Element('span').set('html',obj.properties.str_prog+' : '),
                    new Element('strong').set('html',ban.prognom)
                ),
                new Element('div').adopt(//ok don't change
                    new Element('span').set('html',obj.properties.str_type+' : '),
                    new Element('strong').set('html',obj.properties.bantypes[ban.bantype])
                ),
                new Element('div').adopt(//ok don't change
                    new Element('span').set('html',obj.properties.str_datemaj+' : '),
                    new Element('strong').set('html',ban.datemaj)
                ),
                new Element('div').adopt(//ok don't change
                    new Element('span').set('html',obj.properties.str_banid+' : '),
                    new Element('strong').set('html',ban.banid)
                ),
                leftFormat.clone(),
                
                new Element('div').adopt(
                    new Element('span').set('html',obj.properties.str_visuel_aff+' : '),
                    new Element('br'),
                    select_affid
                ),
                new Element('div').adopt(
                    new Element('span').set('html',obj.properties.str_visuel_grp+' : '),
                    new Element('br'),
                    select_gp
                ),
                new Element('div').adopt(
                    new Element('span').set('html',obj.properties.str_visuel_gpban+' : '),
                    new Element('br'),
                    select_gpban
                )
                
            ),
            new Element('td',{'class':'banResults right_row row'+styleID,'valign':'top','style':'text-align: left; width: 525px;'}).adopt(
                new Element('div',{'name':'error_'+ban.banid,'style':'text-align:center;color:#EE3333;font-weight:700;'}),
                new Element('br'),
                leftSideContent,
                new Element('div',{'style':'text-align: right; margin-top: 10px; margin-left: 20px;'}).adopt(
                    validBtns                    
                )
            )
        )
        
        
        
        return element;
    },
    displayMode : function(element,styleID,ban){
        var cappingBtn = new Element('input',{'type':'button','value':'capping','events':{'click':function(){
            //element = obj.displayMode(element,styleID,ban,true);
        }}});
        
        
        if(obj.properties.afilio){
            var editBtn = new Element('button', {'class':'small', 'events':{"click":function(){
                element = obj.editMode(element,styleID,ban);
            }}}).adopt(
                new Element('span').setText(obj.properties.str_modifier)
            );
            var statusBtn = new Element('button', {'class':'small', "events":{"click":obj.activateBan.bind(obj,[ban])}}).adopt(
                new Element('span', {'id':'activer_span_'+ban.banid}).setText((ban.banlock == 0 ? obj.properties.str_supprimer : obj.properties.str_activer))
            );

            if ((ban.bantype=='gif') || (ban.bantype=='flash')  ){
                geoBtn = new Element('button', {'class':'small', 'events':{"click":function(){
                    window.open("/mer/mer_ban_geo.php?banid="+ban.banid,"Geoloc","toolbar=no, location=no, directories=no, status=yes,scrollbars=yes, resizable=no, copyhistory=no, width=975, height=470, left=200, top=100");        
                }}}).adopt(
                    new Element('span').setText(obj.properties.str_geotarg)
                );
            } else {
                geoBtn = new Element("div");
            }
        } else {
            var editBtn = new Element("img",{"name":"modifier_img","src":imageDir+"btn_s_modif.gif","alt":obj.properties.str_modifier,"style":"padding-right:10px;cursor:pointer;","events":{"click":function(){
                element = obj.editMode(element,styleID,ban);
            }}});    
            var statusBtn = new Element("img",{"name":"activer_img","src":(ban.banlock == 0 ? imageDir+"btn_desactiver.gif" :  imageDir+"btn_activer.gif"),"alt":(ban.banlock == 0 ? obj.properties.str_supprimer : obj.properties.str_activer),"style":"padding-right:10px;cursor:pointer;","events":{"click":obj.activateBan.bind(this,[ban])}});
            if ((ban.bantype=='gif') || (ban.bantype=='flash')){
                var geoBtn = new Element("img",{"name":"modifier_img","src":imageDir+"btn_geotrgt.gif","alt":obj.properties.str_modifier,"style":"padding-right:10px;cursor:pointer;","events":{"click":function(){
                    window.open("/mer/mer_ban_geo.php?banid="+ban.banid,"Geoloc","toolbar=no, location=no, directories=no, status=yes,scrollbars=yes, resizable=no, copyhistory=no, width=975, height=470, left=200, top=100");        
                }}});
            } else {
                var geoBtn = new Element("div");
            }
        }
        ban.image = this.translateIt(ban.image);
        var rightSide =     
            new Element('td',{'class':'banResults right_row row'+styleID,'valign':'top','style':'text-align: left; width: 525px;'}).adopt(
                editBtn,statusBtn,geoBtn
                ,new Element("div",{"style":"text-align:left"}).setHTML(ban.image)
                //new Element("div",{"style":"text-align:right"}).adopt(strResize)
            );
        
        
        element.empty().adopt(
            new Element('td',{'class':'banResults left_row row'+styleID,'valign':'top','style':'width:178px;'}).adopt(
                new Element('div').adopt(
                    new Element('span').set('html',obj.properties.str_prog+' : '),
                    new Element('strong').set('html',ban.prognom)
                ),
                new Element('div').adopt(
                    new Element('span').set('html',obj.properties.str_type+' : '),
                    new Element('strong').set('html',obj.properties.bantypes[ban.bantype])
                ),
                new Element('div').adopt(
                    new Element('span').set('html',obj.properties.str_datemaj+' : '),
                    new Element('strong').set('html',ban.datemaj)
                ),
                new Element('div').adopt(
                    new Element('span').set('html',obj.properties.str_banid+' : '),
                    new Element('strong').set('html',ban.banid)
                ),
                new Element('div').adopt(
                    new Element('span').set('html',obj.properties.str_format+' : '),
                    new Element('strong').set('html',ban.sizelabel)
                ),
                new Element('div').adopt(
                    new Element('span').set('html',obj.properties.str_banpriv+' : '),
                    new Element('strong').set('html',(ban.banpriv == 0 ? obj.properties.str_non : (obj.properties.str_oui+' : '+obj.properties.str_types[ban.privtype]+' '+(ban.privtype == 1 ? obj.properties.affs[ban.progid][ban.privid] : obj.properties.groupes[ban.progid][ban.privid]))))
                ),
                new Element('div').adopt(
                    new Element('span').set('html',obj.properties.str_groupe+' : '),
                    new Element('strong').set('html',(ban.gpname == null ? obj.properties.str_aucun : ban.gpname))
                ),
                new Element('div').adopt(
                    new Element('span').set('html',obj.properties.str_display_freq+' : '),
                    new Element('strong').set('html',((ban.captime>0)?obj.properties.str_oui:obj.properties.str_non))
                )
            ),
            rightSide
        );
        
        return element;
    },
   drawListingTable : function() {
       
       
       
       
       if (obj.UpdatebanEl==null){
       
            obj.tmpdata = obj.data;
            
           var myTbody = new Element('tbody');
            $(this.properties.output).empty().adopt(
                new Element('table').adopt(
                    myTbody
                )
            )
            var x = 0;
            $each(this.data,function(ban,banid){
                myTbody.adopt(
                    obj.displayMode(new Element("tr",{"id":"ban_"+ban.banid}),(x+1),ban)
                )
                x=1-x;
            })
       } else {
           
           
           $each(obj.data,function(data,key){
               obj.tmpdata[key] = obj.data[key];
               obj.data = obj.tmpdata;
           })

           
           element = obj.displayMode(obj.UpdatebanEl,obj.UpdateStyle,obj.data[obj.UpdateBanID]);
           obj.UpdatebanEl=null;
           
       }
       
    },
    openGeoLoc:function(banid){
        window.open("/mer/mer_ban_geo.php?banid="+banid,"Geoloc","toolbar=no, location=no, directories=no, status=yes,scrollbars=yes, resizable=no, copyhistory=no, width=975, height=470, left=200, top=100");        
    },
    doUpdate : function(element,ban,styleID)   {
        
        var params = new Object;
        params["progid"] =ban.progid; 
        params["banid"] = ban.banid;
        params["bantype"]= ban.bantype;
        inputs = $ES("input",$('ban_'+ban.banid));
        for(j=0;j<inputs.length;j++)    {
            params[inputs[j].getAttribute("name")] = inputs[j].value;
            eval('obj.data[ban.banid].' + inputs[j].getAttribute("name") + ' = inputs[j].value;');
        }
        params["gpbanid"]   = ($("ban_"+ban.banid).getElement('select[name=gpban]').value);
        params["affid"]   = $('ban_'+ban.banid).getElement('select[name=affid]').value;
        params["gpid"]    = $('ban_'+ban.banid).getElement('select[name=gpid]').value;
        textarea = $ES("textarea",$('ban_'+ban.banid));
        for(j=0;j<textarea.length;j++)    {                                          
            params[textarea[j].getAttribute("name")] = textarea[j].value;
            eval('obj.data[ban.banid].' + textarea[j].getAttribute("name") + ' = textarea[j].value;');
        }
        select = $ES("select",$('ban_'+ban.banid));
        for(j=0;j<select.length;j++)    {
            params[select[j].getAttribute("name")] = select[j].value;
            eval('obj.data[ban.banid].' + select[j].getAttribute("name") + ' = select[j].value;');
        }                               
        params["bansize"] = ((isNaN(params["bansize"]) || params["bansize"]==0) ? ban.bansize : params["bansize"]);
        
        var afilio = (this.properties.afilio ? true : false);
        
        new Ajax( "../include/lib/mer_lib_ban_update.php",{method:"post",onComplete : function(response)   {
            $("err_mess").empty();
            $$('div[name=error_'+ban.banid+']').empty();
            
            if (!isNaN(eval(response)) && eval(response)!=null) {
                args = new Object();
                args.banid = eval(response); 
                myBanList.arg = args;

                // a little tip for update only this element o_O
                obj.UpdatebanEl = element;
                obj.UpdateBanID = args.banid;
                obj.UpdateStyle = styleID; 
                myBanList.doRequest('this text don t clear search result while loading! plz dont remove');
            }   else    {
                var haveLocalError = false;
                $$('div[name=error_'+ban.banid+']').each(function(el){
                    haveLocalError = true;
                    el.set('html',errors[eval(response)]);
                })
                if (!haveLocalError){
                    $("err_mess").adopt(new Element("div",{"class":"msg_postule"}).setText(errors[eval(response)]));
                }
            }
            
        }}).request(params);
        
        
        
    },
    
    editBan : function(banid)    {
        var i;
        obj = this;
        ban = banid;
        classes = $("ban_"+banid).firstChild.getProperty("class");
        leftSideFormat = new Element('span').setHTML( obj.properties.str_format+" : <strong>"+obj.data[ban].sizelabel+"</strong>");
        switch(obj.data[banid].bantype)    {
            case "gif":
                var formats = this.formats_select.clone();
                for(i=0;i<formats.options.length;i++)  {
                    if (formats.options[i].value == obj.data[ban].bansize)  {
                       formats.options[i].selected = 'selected'; 
                    }
                }
                leftSideFormat = new Element('span').setText(obj.properties.str_format+" :" ).adopt(formats);
                leftSideContent = new Element("div",{"text-align":"left"}).appendText(obj.properties.str_visuelurl).adopt(new Element("input",{"name":"banurl","type":"text","value":obj.data[banid].banurl,"size":"35","style":"margin-left:5px;"})).adopt(
                new Element("br")).appendText(obj.properties.str_visuelredir).adopt(new Element("input",{"name":"bandestinurl","type":"text","value":obj.data[banid].bandestinurl,"size":"35","style":"margin-left:5px;"})).adopt(
                new Element("br"));
               break;
            case "html":
                leftSideContent = new Element("div",{"text-align":"left"}).appendText(obj.properties.str_visuelhtml).adopt(new Element("textarea",{"name":"banhtml","type":"text","disabled":"disabled","value":obj.data[banid].banhtml,"cols":"35","rows":"10","style":"margin-left:5px;"})).adopt(
                new Element("br"));
                break;     
            case "flash":
                var formats = this.formats_select.clone();
                for(i=0;i<formats.options.length;i++)  {
                    if (formats.options[i].value == obj.data[ban].bansize)  {
                       formats.options[i].selected = 'selected'; 
                    }
                }
                leftSideFormat = new Element('span').setText(obj.properties.str_format+" :" ).adopt(formats);
                leftSideContent = 
                    new Element("div",{"text-align":"left"}).appendText(obj.properties.str_flashurl).adopt(
                        new Element("input",{"name":"banurl","type":"text","value":obj.data[banid].banurl,"size":"35","style":"margin-left:5px;"})
                    ).adopt(
                        new Element("br")
                    ).appendText(obj.properties.str_visuelredir).adopt(
                        new Element("input",{"name":"bandestinurl","type":"text","value":obj.data[banid].bandestinurl,"size":"35","style":"margin-left:5px;"})
                    ).adopt(
                        new Element("br")
                    ).appendText(obj.properties.str_clickTag).adopt(
                        new Element('input',{'type':'text','name':'custom_clicktag_var','value':((obj.data[banid].custom_clicktag_var==undefined)?'clickTag':obj.data[banid].custom_clicktag_var)})
                    );
                break;         
            case "text":
                leftSideContent = new Element("div",{"text-align":"left"}).appendText(obj.properties.str_txtwinname).adopt(new Element("input",{"name":"bandescription","type":"text","value":obj.data[banid].bandescription,"size":"35","style":"margin-left:5px;"})).adopt(
                new Element("br")).appendText(obj.properties.str_txtlink).adopt(new Element("input",{"name":"bantext","type":"text","value":obj.data[banid].bantext,"size":"35","style":"margin-left:5px;"})).adopt(
                new Element("br")).appendText(obj.properties.str_visuelredir).adopt(new Element("input",{"name":"bandestinurl","type":"text","value":obj.data[banid].bandestinurl,"size":"35","style":"margin-left:5px;"})).adopt(
                new Element("br"));
                break;     
                     
            case "emailhtml":
                leftSideContent = new Element("div",{"text-align":"left"}).appendText(obj.properties.str_visuelhtml).adopt(new Element("textarea",{"name":"banhtml","type":"text","disabled":"disabled","value":obj.data[banid].banhtml,"cols":"35","rows":"10","style":"margin-left:5px;"})).adopt(
                new Element("br"))
                /*.appendText(obj.properties.str_mailkiturl).adopt(new Element("input",{"name":"urlmail","type":"text","value":obj.data[banid].banurl,"size":"35","style":"margin-left:5px;"})).adopt(
                new Element("br"))*/;
                break;  
                    
            case "popup":
                var formats = this.formats_select.clone();
                for(i=0;i<formats.options.length;i++)  {
                    if (formats.options[i].value == obj.data[ban].bansize)  {
                       formats.options[i].selected = 'selected'; 
                    }
                }
                leftSideFormat = new Element('span').setText(obj.properties.str_format+" :" ).adopt(formats);
                leftSideContent = new Element("div",{"text-align":"left"}).appendText(obj.properties.str_titrewin).adopt(new Element("input",{"name":"bantext","type":"text","value":obj.data[banid].bantext,"size":"35","style":"margin-left:5px;"})).adopt(
                new Element("br")).appendText(obj.properties.str_visuelurl).adopt(new Element("input",{"name":"banurl","type":"text","value":obj.data[banid].banurl,"size":"35","style":"margin-left:5px;"})).adopt(
                new Element("br")).appendText(obj.properties.str_redirwin).adopt(new Element("input",{"name":"bandestinurl","type":"text","value":obj.data[banid].bandestinurl,"size":"35","style":"margin-left:5px;"})).adopt(
                new Element("br"));
                break;         
            case "popunder":
                var formats = this.formats_select.clone();
                for(i=0;i<formats.options.length;i++)  {
                    if (formats.options[i].value == obj.data[ban].bansize)  {
                       formats.options[i].selected = 'selected'; 
                    }
                }
                leftSideFormat = new Element('span').setText(obj.properties.str_format+" :" ).adopt(formats);
                leftSideContent = new Element("div",{"text-align":"left"}).appendText(obj.properties.str_popunder).adopt(new Element("input",{"name":"bantext","type":"text","value":obj.data[banid].bantext,"size":"35","style":"margin-left:5px;"})).adopt(
                new Element("br")).appendText(obj.properties.str_visuelurl).adopt(new Element("input",{"name":"banurl","type":"text","value":obj.data[banid].banurl,"size":"35","style":"margin-left:5px;"})).adopt(
                new Element("br")).appendText(obj.properties.str_redirwin).adopt(new Element("input",{"name":"bandestinurl","type":"text","value":obj.data[banid].bandestinurl,"size":"35","style":"margin-left:5px;"})).adopt(
                new Element("br"));
                break;       
            case "siteunder":
                leftSideContent = new Element("div",{"text-align":"left"}).appendText(obj.properties.str_siteunder).adopt(new Element("input",{"name":"bantext","type":"text","value":obj.data[banid].bantext,"size":"35","style":"margin-left:5px;"})).adopt(
                new Element("br")).appendText(obj.properties.str_redirwin).adopt(new Element("input",{"name":"bandestinurl","type":"text","value":obj.data[banid].bandestinurl,"size":"35","style":"margin-left:5px;"})).adopt(
                new Element("br"));
               break;                                                      
        }
        if(this.properties.afilio){
            //<button id="ban_edit_go" class="big" ><span>{l}Modifier{/l}</span></button>
            validBtn = new Element('button', {'class':'button', "events":{"click":this.doUpdate.bind(this,[banid])}}).adopt(
            new Element('span').setText(obj.properties.str_modifier)
          );
          
          
        }else{
          //validBtn = new Element("img",{"src":imageDir+"btn_valider.gif","alt":obj.properties.str_modifier,"style":"cursor:pointer;","events":{"click":this.doUpdate.bind(this,[banid])}}); 
          validBtn = new Element('button', {'class':'big', "events":{"click":this.doUpdate.bind(this,[banid])}}).adopt(
            new Element('span').setText(obj.properties.str_modifier)
          );

        }
        leftSideValidation = new Element("div",{"style":"text-align:right;margin-top:10px;margin-left:20px;"}).adopt(
          validBtn
        );
        
        select_affid = this.affids_select[obj.data[ban].progid].clone();
        select_gp = this.groupes_select[obj.data[ban].progid].clone();
        select_gpban = this.gpban_select[obj.data[ban].progid].clone();       
        
        var i;
        if (obj.data[ban].affid != '' && obj.data[ban].affid >0)    {
            for(i=0;i<select_affid.options.length;i++)  {
                if (select_affid.options[i].value == obj.data[ban].affid)  {
                   select_affid.options[i].selected = 'selected'; 
                }
            }
        }
        if (obj.data[ban].gpid != '' && obj.data[ban].gpid >0)    {
            for(i=0;i<select_gp.options.length;i++)  {
                if (select_gp.options[i].value == obj.data[ban].gpid)  {
                   select_gp.options[i].selected = 'selected'; 
                }
            }
        }
        if (obj.data[ban].gpbanid != '' && obj.data[ban].gpbanid >0)    {
            for(i=0;i<select_gpban.options.length;i++)  {
                if (select_gpban.options[i].value == obj.data[ban].gpbanid)  {
                   select_gpban.options[i].selected = 'selected'; 
                }
            }
        }
        
        //$("ban_"+banid).empty().adopt(
        $("ban_"+banid).deleteCell(0);$("ban_"+banid).deleteCell(0);
        $("ban_"+banid).adopt(
            new Element("td",{"style":"width:178px","valign":"top","class":classes}).setHTML(
                obj.properties.str_prog+" : <strong>"+obj.data[ban].prognom+"</strong><br /><br />"+
                obj.properties.str_type+" : "+obj.properties.bantypes[obj.data[ban].bantype]+"<br />"+
                obj.properties.str_datemaj+" : <strong>"+obj.data[ban].datemaj+"</strong><br />"+
                obj.properties.str_banid+" : <strong>"+obj.data[ban].banid+"</strong><br />"
                
                ).adopt(leftSideFormat).adopt( 
                
                    new Element("br")).appendText(obj.properties.str_visuel_aff+" :").adopt(new Element("br")).adopt(select_affid).adopt(
                    new Element("br")).appendText(obj.properties.str_visuel_grp+" :").adopt(new Element("br")).adopt(select_gp).adopt(
                    new Element("br")).appendText(obj.properties.str_visuel_gpban+" :").adopt(new Element("br")).adopt(select_gpban)
                , 
            new Element("td",{"valign":"top","style":"text-align:left; width:525px","class":classes}).adopt(
                leftSideContent,
                leftSideValidation
            )
       );
       // -->
    },
    
    activateBan : function(ban)   { //obj.properties.str_supprimer : obj.properties.str_activer
        banid=ban.banid;
      if(obj.properties.afilio){
        ban = $("activer_span_"+banid);
        label = ban.innerHTML;
        if(label == obj.properties.str_supprimer)
          lock=1;
        else
          lock=0;
        new Ajax( "../include/lib/mer_lib_ban_activate.php",{method:"post",onComplete : function(response){
          if(response==1)
            ban.setText((lock == 1 ? obj.properties.str_activer : obj.properties.str_supprimer));
        }}).request({"banid":banid,"lock":lock});
      }else{
          
        img = $ES("img[name=activer_img]",$("ban_"+banid));
        src = img[0].getAttribute("src"); 
        if (src.substring(src.lastIndexOf("_")+1) == "desactiver.gif")  {
            ban.banlock=1;
            newsrc=imageDir+"btn_activer.gif";lock=1;
        }   else    {
            ban.banlock=0;
            newsrc=imageDir+"btn_desactiver.gif";lock=0;
        }    
           
        new_elt = img[0].clone();                                             
        new_elt.cloneEvents(img[0]);
        new_elt.setAttribute("src",newsrc); 
        
        new Ajax( "../include/lib/mer_lib_ban_activate.php",{method:"post",onComplete : function(response)   {
            if (response == 1)   {          
                img[0].replaceWith(new_elt);
            }        
        }}).request({"banid":banid,"lock":lock});
      }
    }
});

var customTagList = mtTable.extend({
    initialize : function(properties) {
       this.attr=properties;
       this.properties = properties;
       
    },
                                        
    drawListingTable : function()   {
            
        var i=0;
        obj = this;
        $(this.properties.output).empty();
        $(this.properties.output).className = 'cadreUp';
        var ban = '';
        for (ban in this.data)  {
           if (this.data[ban].banlock != 1) {
               var banprogid = this.data[ban].progid;
               /*if (this.data[ban].bantype == 'gif')   {
                var bannerImage = new Element('img',{'src':this.data[ban].banurl,'width':nWidth,'height':nHeight});
               }   else if (this.data[ban].bantype == 'flash') {
                var bannerImage = new Element('object').adopt(
                  new Element('embed',{'src':this.data[ban].banurl,'width':nWidth,'height':nHeight})
                );
               }*/
               if(this.data[ban].bantype == 'gif'){
                   var bannerImage = document.createElement('img');
                   bannerImage.setAttribute('src', this.data[ban].banurl);
                   bannerImage.setAttribute('width', nWidth);
                   bannerImage.setAttribute('height', nHeight);
               }else if(this.data[ban].bantype == 'flash'){
                   var bannerImage = document.createElement('embed');
                   bannerImage.setAttribute('rel', 'lightbox['+nWidth+' '+nHeight+']');
                   bannerImage.setAttribute('src', this.data[ban].banurl);
                   bannerImage.setAttribute('width', nWidth);
                   bannerImage.setAttribute('height', nHeight);
                   bannerImage.setAttribute('quality', 'high');
                   bannerImage.setAttribute('type', 'application/x-shockwave-flash');
                   bannerImage.setAttribute('pluginspage', 'http://www.macromedia.com/go/getflashplayer');
               }
               var image = (obj.data[ban].image == null ? '' : obj.data[ban].image);
               if(this.properties.afilio){
                 addToMyListBtn = new Element('button', {'class':'small','id':'ban'+this.data[ban].banid,'type':this.data[ban].bantype,'name':'addToMyList'}).adopt(
                    new Element('span').setText(this.properties.str_ajouter)
                 );
               } else {
                 addToMyListBtn = new Element('button', {'class':'small','id':'ban'+this.data[ban].banid,'type':this.data[ban].bantype,'name':'addToMyList'}).adopt(
                    new Element('span').setText(this.properties.str_ajouter)
                 )
               }
                var subpos = this.data[ban].bansize_lbl.indexOf('x');
                
                if (subpos>0){
                    var picWidth = this.data[ban].bansize_lbl.substr(0,subpos);
                    var picHeight = this.data[ban].bansize_lbl.substr(subpos+1,this.data[ban].bansize_lbl.length-picWidth.length);
                    var add = "["+picWidth+" "+picHeight+"]";
                } else {
                    var add = "[550 410]";
                }
               
               
               $(this.properties.output).adopt(
                   new Element('table',{'width':'100%','class':'ban_rot_table'}).adopt(new Element('tbody').adopt(new Element('tr').adopt(
                        new Element('td',{'class':'banrot_td1'}).adopt(addToMyListBtn),
                        //new Element('td',{'class':'banrot_td2'}).adopt(bannerImage),
                        //new Element('td',{'class':'banrot_td2'}).appendChild(bannerImage),
                        new Element('td',{'class':'banrot_td2', 'id':'td2_'+this.data[ban].banid}),
                        new Element('td',{'class':'banrot_td3'}).adopt(
                            new Element('div').adopt(new Element('img',{'src':imageDir+'pic_view.gif','alt':altAgr}),new Element('a',{'href':this.data[ban].banurl,'rel':'lightbox'+add,'class': this.properties.bansize + ' viewsize'}).setText(txtAgr)),    
                            new Element('br'), 
                            new Element('span',{'class':'xs bold'}).setText(progNoms[banprogid]),
                            new Element('br'),
                            new Element('span',{'class':'xs'}).setText(categories[banprogid]),
                            new Element('br'),
                            new Element('span',{'class':'xs'}).setHTML(tarifs[banprogid])
                        )
               ))));
               document.getElementById('td2_'+this.data[ban].banid).appendChild(bannerImage);
               i++;
           }
        }
        if(this.properties.afilio || this.properties.globalAdd){
            $(this.properties.output).adopt(
                new Element('div').adopt(
                    new Element('button', {'class':'button', 'id':'ajouterAllBan'}).adopt(
                        new Element('span').setText(this.properties.str_ajouterAll)
                    )
                )
            );
        }
    },
    
    triggerError : function()    {
      obj = this;         
      //$(this.attr.output).setStyles('border:none;');
      $(this.attr.output).className = 'cadreUp-error';
      $(this.attr.output).empty();
      $(this.attr.output).adopt(new Element('div',{'class':'error'}).setText(obj.attr.noresultString));
      if ($(this.attr.paginContainer) != undefined) {
        $(this.attr.paginContainer).empty();
      }
      return false;
    },
        
    draw : function(data)   {
        this.dataBrut = data;
        if (data[0].nb_items == 0)  {
            return this.triggerError();
        }
        this.data = data[0].data;
        this.drawListingTable();     
        
        window.fireEvent('domready');
    }   
});
var customTagContent = mtTable.extend({
    initialize : function(properties) {
       this.attr=properties;
       this.properties = properties;
    },
                                        
    drawListingTable : function()   {
        var i=0;
        obj = this;
        $(this.properties.output).empty();
        $(this.properties.output).className = 'cadreUp'; //changed the styles by a class
        var strSrc ='';
        for (ban in this.data)  {
           if (this.data[ban].banlock != 1) {        
               var banprogid = this.data[ban].progid;                                
               var image = (obj.data[ban].image == null ? '#' : obj.data[ban].image);
               strSrc+= (obj.data[ban].image == null ? '' : obj.data[ban].image+',');
               
                if (this.properties.bansize!=undefined){
                    var subpos = this.properties.bansize.indexOf('x');
                    if (subpos>0){
                        var picWidth = this.properties.bansize.substr(0,subpos);
                        var picHeight = this.properties.bansize.substr(subpos+1,this.properties.bansize.length-picWidth.length);
                        var add = "["+picWidth+" "+picHeight+"]";
                    } else {
                        var add = "[550 410]";
                    }
                }
               
               $(this.properties.output).adopt(
                   new Element('table',{'width':'100%','class':'ctContent','cellPadding':'8'}).adopt(new Element('tbody').adopt(new Element('tr').adopt(
                        new Element('td',{'class':'firstCell'}).adopt(
                            new Element('span',{'class':'xs bold'}).setText(progNoms[banprogid]),
                            new Element('br'),
                            new Element('span',{'class':'xs'}).setHTML(tarifs[banprogid])
                        ),
                        new Element('td',{'class':'secondCell'}).adopt(
                            new Element('a',{'id':'ban'+this.data[ban].banid,'href':image,'rel':'lightbox'+add,'class': this.properties.bansize + ' showban'}).adopt(
                                new Element('span').setText(viewBanner)
                            )
                        ),
                        new Element('td',{'class':'thirdCell'}).adopt(
                            new Element('a',{'id':'ban'+this.data[ban].banid,'href':'javascript:void(0)','name':'removeBanner'}).adopt(
                                 new Element('img',{'src':imageDir+'delete.gif','alt':altSupr,'border':'0'})
                            )
                        )
               ))));       
               i++;
           }   
        }
        if(this.properties.afilio || this.properties.globalRemove){
            $(this.properties.output).adopt(
                new Element('div').adopt(
                    new Element('button', {'class':'button', 'id':'removeAllBan'}).adopt(
                        new Element('span').setText(this.properties.str_removeAll)
                    )
                )
            );
        }

        strSrc = strSrc.substr(0,strSrc.length-1);
        var htmlcol = $ES('object','viewer_top');
        flashMovie = htmlcol[0];
        flashMovie.SetVariable("src",""+strSrc+"");
        flashMovie.SetVariable("newSrc","true");
    },
    
    triggerError : function()    {
      obj = this;
      $(this.attr.output).className = 'cadreUp-error';    
      $(this.attr.output).empty();
      $(this.attr.output).adopt(new Element('div',{'class':'error'}).setText(obj.attr.noresultString));
      if ($(this.attr.paginContainer) != undefined) {
        $(this.attr.paginContainer).empty();
      }
      return false;
    },
        
    draw : function(data)   {
        this.dataBrut = data;
        if (data[0].nb_items == 0)  {
            return this.triggerError();
        }
        this.data = data[0].data;
        this.drawListingTable();      
        window.fireEvent('domready');
    }   
});