var W118000Registry;

if(W118000Registry == undefined){

    W118000Registry = {
        _registry : new Array(),
        
        set : function (uid,widget){
            this._registry[uid] = widget;
        },
        
        get : function (uid){
            return this._registry[uid];
        }
    }
    
    W118000Cookie = {
        set : function (c_name,value,expiredays){
            var exdate=new Date();
            exdate.setDate(exdate.getDate()+expiredays);
            document.cookie=c_name+ "=" +escape(value)+
            ((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+
            "; path=/";
        },
        get : function getCookie(c_name){
            if (document.cookie.length>0){
                c_start=document.cookie.indexOf(c_name + "=");
                if (c_start!=-1){
                    c_start=c_start + c_name.length+1;
                    c_end=document.cookie.indexOf(";",c_start);
                    if (c_end==-1) c_end=document.cookie.length;
                    return unescape(document.cookie.substring(c_start,c_end));
                }
            }
            return "0";
        },
        get_capping : function(){
            cook_val = parseInt(this.get("w118000_widget_capping"));
            displayed_times = parseInt(cook_val==NaN || cook_val=="NaN" ? "0" : cook_val);
            return displayed_times;
        },

        increment_capping : function(){
            displayed_times++;
            W118000Cookie.set("w118000_widget_capping",displayed_times,1);
        }
    }
    
    W118000Callback = function(calling_id,data){
        var _calling_widget = W118000Registry.get(calling_id);
        switch(data._jkbc){
            case "display_vid":
                //_calling_widget.display_vid(data._jkbp);
                _calling_widget.display_ad(data._jkbp);
                break;
            case "display_result":
                _calling_widget.display_result(_calling_widget,data._jkbp);
                break;
            default:
                throw("Error in method name : " + data._jkbc);
        }
    }
    
    
    Widget118000 = function(target_div,options){
        
        this._options = this.settings(options);
        
        this._target_div = target_div;
        this._baseurl = "http://118000.digiteka.net/distribution/js/";
        this._prefix = "w118000wdgt";
        this._uid = Math.round(Math.random()*100000);
        
        this._registry_key = this._prefix+"_"+this._uid;
        
        this._transmit_div = this._prefix+"_transmit_"+this._uid;
        this._queryform = this._prefix+"_queryform_"+this._uid;
        this._queryform_searchtype = this._prefix+"_searchtype_"+this._uid;
        this._contentdiv = this._prefix+"_content_"+this._uid;
        this._infodiv = this._prefix+"_info_"+this._uid;
        this._previousdiv = this._prefix+"_previous_"+this._uid;
        this._frontaddiv = this._prefix+"_frontad_"+this._uid;
        this._searchchoicesul = this._prefix+"_searchul_"+this._uid;
        
        this._history = {history: Array(), position: -1};
        
        this._last_qs = "";
        this._last_dv = "";
        this._last_ot = "";
        
        this.draw();
        this.historysave();
        this.getAvailableSearch(this);
        //this.addActions(this,"search_action");
        
        
        W118000Registry.set(this._registry_key,this);
    }
    
    Widget118000.prototype.settings = function(options){
        var opts = {};
        
        if(options.s_id == undefined){
            throw "s_id parameter is mandatory";
        }else{
            opts.s_id = options.s_id;
        }
            
        switch(options.format){
            case "300X600":
                opts.widgetheight            = "600px";
                opts.contentdiv_small_height = "518px";
                opts.contentdiv_large_height = "544px";
                opts.maxResult = 20;
                opts.format                  = "300X600";
                break;
            default:
            case "300X300":
                opts.widgetheight            = "300px";
                opts.contentdiv_small_height = "218px";
                opts.contentdiv_large_height = "244px";
                opts.maxResult = 10;
                opts.format                  = "300X300";
                break;
        }
        
        return opts;
    }
    
    Widget118000.prototype.template = function(which,data){
        var template = "";
        if(which == "form_search_type"){
            template = "<form style='margin-left: 7px; width: 293px;'>"
                     +  "<table><tr>"
                     +  "<td>Je recherche : </td>"
                     +  "<td><ul  id='"+this._searchchoicesul+"'>"
                     +  "</ul></td>"
                     +  "</tr></table>"
                     +  "</form>";
        }
        if(which == "form_search_ul"){
            data = data || {"inverse" : true};
                              
            template =  "    <li><input type='radio' name='search_type' checked "
                     +  "           onclick='W118000Registry.get(\""+this._registry_key+"\").toggleSearchType(\"pro\")'"
                     +  "        > Un professionel </li>"
                     +  "    <li><input type='radio' name='search_type' "
                     +  "           onclick='W118000Registry.get(\""+this._registry_key+"\").toggleSearchType(\"perso\")'"
                     +  "        > Un particulier </li>";
            if(data.inverse){
                template += "    <li><input type='radio' name='search_type' "
                         +  "           onclick='W118000Registry.get(\""+this._registry_key+"\").toggleSearchType(\"inverse\")'"
                         +  "        > Annuaire inversé </li>";
             }
        }
        if(which == "form_search_what"){
            data = data || {ot:"111100"}
            template = "<form action='#' id='"+this._queryform+"' title='"+this._registry_key+"' style='margin:0;padding:0;'>"
                     +  "<table  style='margin-left: 7px;'>"
                     +  "<tr><td>Qui ? Quoi ? </td><td><input type='text' name='qs'> </td></tr>"
                     +  "<tr><td>Où </td><td><input type='text' name='dv' > </td></tr>"
                     +  "<input type='hidden' name='ot' value='"+data.ot+"'>"
                     +  "<input type='hidden' name='tr' value='1'>"
                     +  "</table>"
//                     +  this.template("form_search_filter")
                     +  "<div style='text-align: center;padding-top: 5px;'><input type='submit' value='Rechercher'></div>";
            if(this._options.format == "300X600"){  
                template += "<div id='"+this._frontaddiv+"' class='w118000frontad' style='margin-top: 30px;'></div>";
            }
             template+=  this.template("form_search_button")
                     +  "</form>";
        
        }
        
        if(which == "form_search_inverse"){
            data = data || {}
            template = "<form action='#' id='"+this._queryform+"' title='"+this._registry_key+"'>"
                     +  "<table>"
                     +  "<tr><td>A qui est ce numéro</td><td><input type='text' name='qs'></td></tr>"
                     +  "<input type='hidden' name='tr' value='9'>"
                     +  "<tr style='font-size:9px;'><td>&nbsp;</td><td>Ex: 0425511452 ou 04.25.51.14.52</td></tr>"
                     +  "</table>"
//                     +  this.template("form_search_filter")
                     +  "<div style='text-align: center;padding-top: 15px;'><input type='submit' value='Rechercher'></div>";
            if(this._options.format == "300X600"){  
                template += "<div id='"+this._frontaddiv+"' class='w118000frontad' style='margin-top: 30px;'></div>";
            }
            template+=  this.template("form_search_button")
                     +  "</form>";
        
        }
        
        if(which == "form_search_filter"){
            template =  "<table><tr>"
                     +  "<td>Afficher<td>"
                     +  "<td><ul>"
                     +  "   <li><input type='checkbox' disabled checked> Nom (obligatoire) </li>"
                     +  "   <li><input type='checkbox' checked> Numéro de Téléphone </li>"
                     +  "   <li><input type='checkbox' checked> Adresse </li>"
                     +  "</ul></td>"
                     +  "</tr></table>";
        }
        
        if(which == "form_result_filter"){
            template = "<form action='#' id='"+this._queryform+"' title='"+this._registry_key+"'>"
                     + "   Afficher : "
                     + "   <input type='checkbox' checked> Numéro de Téléphone"
                     + "   <input type='checkbox' checked> Adresse "
                     + "</form>";
        }
        
        if(which == "form_search_button"){
            template = "<div class='w118000form_search_button'>"

                     +  "</div>";
        
        }
        
        if(which == "content_search_default"){
            template = this.template("form_search_type");
            template += "<div id='"+this._queryform_searchtype+"' class='formulaire_champs'>"
                     +  this.template("form_search_what")
                     +  "</div>";
        
        }
        
        if(which == "content_result_default"){
        
            data = data || {resultnum:0};
            template = "";
                     
            template +="<table>";      
            if(data.resultnum > 0){
                for(x in data.data){
                    resline = data.data[x];
                    resline.pagenum = data.pagenum;
                    template += this.template("result_singleresult",resline);
                }
                
            }else{
                template += "<li style='text-align: center'>"
                         + "Nous n'avons trouvé aucun résultat correspondant à votre recherche"
                         + "</li>"
                         + "<li style='text-align: center; margin-top: 15px;'>"
                         + "<a href='javascript:;' "
                         + "onclick='W118000Registry.get(\""+this._registry_key+"\").historyback(W118000Registry.get(\""+this._registry_key+"\"))'"
                         +"'>Effectuer une nouvelle recherche</a>"
                         + "</li>"
                         + "<li style='text-align: center; margin-top: 15px;'>"
                         + "<a href='http://118000.fr/' target='_blank'>Aller sur l'annuaire 118000</a>"
                         + "</li>"
                         + "<li>";
            }
            if(data.resultnum > 0){
                template += "<tr>"
                         +  "<td colspan='3' style='text-align:center'>"
                var npages = Math.min(10,Math.ceil(data.resultnum/this._options.maxResult));
                var currentpage = data.pagenum/this._options.maxResult+1;
                for(var p = 1; p <= npages; p++){
                    var qs = "qs="+encodeURI(this._last_qs)
                           +"&dv="+encodeURI(this._last_dv)
                           +"&ot="+encodeURI(this._last_ot)
                           +"&be="+encodeURI((p-1)*this._options.maxResult);
                    if(currentpage == p){
                        template += "<strong>";
                    }
                    template += "<a style='color: #333;' href='javascript:;' onclick='"
                             +  "W118000Registry.get(\""+this._registry_key+"\").jscall(\"displayResults\",\""+qs+"\");"
                             +  "'>"+p+"</a>";
                             
                    if(currentpage == p){
                        template += "</strong>";
                    }
                    
                    if(p != npages){
                        template += " - ";
                    }
                }
                    
                template +=  "</td>"
            }
            template +="</table>"


            template += "<table style='margin-left: 20px; width: 250px;'><tr>"
                     + "<td>"
                     + this.template("small_ad",data.pub.emplacements.mini[0])
                     + "</td>"
                     + "<td>"
                     + this.template("small_ad",data.pub.emplacements.mini[1])
                     + "</td>"
                     + "</tr>"
                     + "<tr>"
                     + "<td>"
                     + this.template("small_ad",data.pub.emplacements.mini[2])
                     + "</td>"
                     + "<td>"
                     + this.template("small_ad",data.pub.emplacements.mini[3])
                     + "</td>"
                     + "</tr></table>";
            
        
        }
        
        if(which == "small_ad"){
            data = data || {};
            /*
            url = "http://ads.118000.fr/www/delivery/avw.php?zoneid=28&cb=6345098&sc=veterinaire&c=maison-jardin&d=59&n=a58f9a49";
            template = "<img src='"+url+"'>";
            */
            url="http://118000.digiteka.net/distribution/ad/?s_id="+this._options.s_id+"&c_id="+data.campaigns[0];
            for(x in data.vars){
                url+="&"+x+"="+data.vars[x];
            }
            width = data.size[0];
            height= data.size[1];
            template = "<iframe frameborder='0' style='border: none;' scrolling='no' src='"+url+"' width='"+width+"' height='"+height+"'></iframe>";
        }
        
        if(which == "frontad"){
            data = data || {};
            /*
            url = "http://ads.118000.fr/www/delivery/avw.php?zoneid=28&cb=6345098&sc=veterinaire&c=maison-jardin&d=59&n=a58f9a49";
            template = "<img src='"+url+"'>";
            */
            var url = "";
            url="http://118000.digiteka.net/distribution/ad/?s_id="+this._options.s_id+"&c_id="+data.campaigns[0];
            
            for(x in data.vars){
                url+="&"+x+"="+data.vars[x];
            }
            width = data.size[0];
            height= data.size[1];
            template = "<iframe frameborder='0' style='border: none;' scrolling='no' src='"+url+"' width='"+width+"' height='"+height+"'></iframe>";
        }
        
        if(which == "result_singleresult"){
            data = data || {};
            parity = (data.position % 2 == 0) ? "even" : "odd" ;
            var position = data.position + data.pagenum;
            if(data.special){
                classname = "w118000resultposition prio";
            }else{
                classname = "w118000resultposition";
            }
            template = "<tr class='w118000singleresult "+parity+"'>"
                     + "<td><span class='"+classname+"'>"+position+"</span></td>"
                     + "<td style='width:210px;'>"
                     + "<span class='w118000resultname'>"+data.name+"</span><br>"
                     + "<span class='w118000resultaddres'>"+data.address+"</span><br>"
                     + "<span class='w118000resultcity'>"+data.city+"</span><br>"
                     + "<span class='w118000resulttel'>Tèl : "+data.phone[0].number+"</span>"
            if(data.special){
                template += "<br><span class='w118000resultmoreprio'><input type='button' onclick='"
                         +  "   W118000Registry.get(\""+this._registry_key+"\").jscall(\"displayDetail\",\""+data.detailquery+"\");"
                         +  "' value='Infos pratiques, horaires ...'>";
            }
                     
            template +="</td>"
                     + "<td>"
                     + "<a class='w118000resultmore' href='javascript:" 
                     + "       W118000Registry.get(\""+this._registry_key+"\").jscall(\"displayDetail\",\""+data.detailquery+"\");"
                     + "' title='details'></a>"
                     + "</td>"
                     + "</tr>";
        }
        
        if(which == "error_location"){
            data = data || {};
            template = "<ul>";
            for(x in data.data){
                resline = data.data[x];
                template += "<li class='w118000suggestion' onclick='"
                         + "W118000Registry.get(\""+this._registry_key+"\").jscall(\"displayResults\",\""+resline.newquery+"\");"
                         +"'>"
                         + resline.city
                         + " ("+resline.dep+")"
                         + "</li>" 
            }
            template += "</ul>";
        }
        
        if(which == "content_detail"){
            data = data || {};
            if(data.special){
                template = "<div>"
                         + "    <div class='w118000detail_address'>"
                         + "        <span class='w118000resultname'>"+data.name+"</span><br>"
                         + "        <span class='w118000resultaddres'>"+data.address+"</span><br>"
                         + "        <span class='w118000resultcity'>"+data.city+"</span><br>"
                         + "    </div>"
                         + "    <div class='w118000detail_picture'>"
                         + "        <img src='"+data.img+"'>"
                         + "    </div>"
                         + "<div class='w118000detail_numbers'><ul>";
                for(tn in data.phone){
                    line = data.phone[tn];
                    switch(line.type){
                        case "f":
                            typeclassname = "fax";
                            break;
                        case "m":
                            typeclassname = "cell";
                            break;
                        case "t":
                        case "v":
                        default:
                            typeclassname = "land";
                            break;
                    }
                    template +="<li class='w118000detail_numbers_"+typeclassname+"'>"+line.number+"</li>"
                }
                
                template +="</ul></div>"
                         + "<div class='w118000detail_activity'>"
                         + "<strong>Activité</strong> : " + data.category
                         + "</div>"
                         /*
                         $res['description'] = (string)$value->des;
                            $res['pay'] = (string)$value->pay;
                            $res['hour'] = (string)$value->hour; w118000detail_description w118000detail_hour w118000detail_pay w118000detail_email
                            $res['email'] = (string)$value->em;
                         */
                 if(data.description != undefined && data.description !=""){
                    template +="<div class='w118000detail_description'>"
                             + "    <strong>Description</strong> : " + data.description
                             + "</div>";
                 }
                 if(data.hour != undefined && data.hour !=""){
                    template +="<div class='w118000detail_hour'>"
                             + "    <strong>Heures d'ouverture</strong> : " + data.hour
                             + "</div>";
                 }
                 if(data.pay != undefined && data.pay !=""){
                    template +="<div class='w118000detail_pay'>"
                             + "    <strong>Paiments acceptés</strong> : " + data.pay
                             + "</div>";
                 }
                 if(data.email != undefined && data.email !=""){
                    template +="<div class='w118000detail_email'>"
                             + "    <strong>Email</strong> : " + data.email
                             + "</div>";
                 }
                 
                 if(data.url != undefined && data.url !=""){
                    template +="<div class='w118000detail_email'>"
                             + "    <strong>Site</strong> : "
                             + "    <a href='"+data.url+"' target='_blank'>Visiter</a>"
                             + "</div>";
                 }
                 
                 template+="    <div class='w118000detail_footer'>"
                         + "        <a href='"+data.linkmap+"' target='_blank' class='w118000detail_proximity'>Afficher le plan et la recherche à proximité</a><br>"
                         + "        <a href='"+data.linkemail+"' target='_blank' class='w118000detail_sharemail'>Partager par mail</a>"
                         + "    </div>"
                         + "</div>";
                         
            }else{
                template = "<div>"
                         + "    <div class='w118000detail_address'>"
                         + "        <span class='w118000resultname'>"+data.name+"</span><br>"
                         + "        <span class='w118000resultaddres'>"+data.address+"</span><br>"
                         + "        <span class='w118000resultcity'>"+data.city+"</span><br>"
                         + "    </div>"
                         + "<div class='w118000detail_numbers'><ul>";
                for(tn in data.phone){
                    line = data.phone[tn];
                    switch(line.type){
                        case "f":
                            typeclassname = "fax";
                            break;
                        case "m":
                            typeclassname = "cell";
                            break;
                        case "t":
                        case "v":
                        default:
                            typeclassname = "land";
                            break;
                    }
                    template +="<li class='w118000detail_numbers_"+typeclassname+"'>"+line.number+"</li>"
                }
                
                template +="</ul></div>";
                if(data.category != undefined){
                    template +="<div class='w118000detail_activity'>"
                             + "    <strong>Activité</strong> : " + data.category
                             + "</div>";
                }
                template +="    <div class='w118000detail_footer'>"
                         + "        <a href='"+data.linkmap+"' target='_blank' class='w118000detail_proximity'>Afficher le plan et la recherche à proximité</a><br>"
                         + "        <a href='"+data.linkemail+"' target='_blank' class='w118000detail_sharemail'>Partager par mail</a>"
                         + "    </div>"
                         + "</div>";
            }
        }
    
        return template;
    }
    
    Widget118000.prototype.toggleSearchType = function(which){
    
        this._last_qs = document.getElementById(this._queryform).qs.value;
        if(document.getElementById(this._queryform).dv){
            this._last_dv = document.getElementById(this._queryform).dv.value;
        }
        
        switch(which){
            case "perso":
                document.getElementById(this._queryform_searchtype).innerHTML = this.template("form_search_what",{ot:"000011"});
                break;
            case "inverse":
                document.getElementById(this._queryform_searchtype).innerHTML = this.template("form_search_inverse");
                break;
            case "pro":
            default:
                document.getElementById(this._queryform_searchtype).innerHTML = this.template("form_search_what",{ot:"111100"});
                break;
        } 
        this.addActions(this,"search_action");
        if(this._options.format == "300X600"){
            this.getFrontAd(this);
        }
    }
    
    Widget118000.prototype.showInfo = function(action,text,classname){
        if(action == "hide"){
            document.getElementById(this._contentdiv).className = "w118000Content large";
            document.getElementById(this._contentdiv).style.height = this._options.contentdiv_large_height;
            document.getElementById(this._infodiv).style.display = "none";
            return;
        }
        if(action == "show"){
            classname = " "+classname || "";
            document.getElementById(this._contentdiv).className = "w118000Content small";
            document.getElementById(this._contentdiv).style.height = this._options.contentdiv_small_height;
            document.getElementById(this._infodiv).style.display = "block";
            document.getElementById(this._infodiv).className = "w118000Info"+classname;
            document.getElementById(this._infodiv).innerHTML = text;
        }
    }
    
    
    Widget118000.prototype.draw = function(){
        //wrapper
        var divwrapper            = document.createElement('div');
            divwrapper.className  = "w118000Wrapper";
            divwrapper.style.height=this._options.widgetheight;
            
        var divtransmit           = document.createElement('div');
            divtransmit.id        = this._transmit_div;
        
        var csslink               = document.createElement('link');
            csslink.href          = "http://118000.digiteka.net/css/distribution/widget.css";
            csslink.media         = "screen";
            csslink.type          = "text/css";
            csslink.rel           = "stylesheet";

        
        var divheader             = document.createElement('div');
            divheader.className   = "w118000Header";
            
        var divprevious           = document.createElement('div');
            divprevious.className   = "w118000Previous";
            divprevious.id        = this._previousdiv;
            
            _f1 = this.historyback;
            _w1 = this;
            
            divprevious.onclick   = function(){_f1(_w1)};
            divprevious.style.display = "none";
        
        var divinfo               = document.createElement('div');
            divinfo.className     = "w118000Info";
            divinfo.id            = this._infodiv;
            divinfo.innerHTML     = "le 118000 c'est trop cool";
            divinfo.style.display = "none";
        
        var divcontent            = document.createElement('div');
            divcontent.className  = "w118000Content large";
            divcontent.id         = this._contentdiv;
            divcontent.innerHTML  = this.template("content_search_default");
            divcontent.style.height = this._options.contentdiv_large_height;

        divheader.appendChild(divprevious);
        
        divwrapper.appendChild(divheader);
        divwrapper.appendChild(divinfo);
        divwrapper.appendChild(divcontent);

        document.getElementById(this._target_div).innerHTML = '';
        document.getElementById(this._target_div).appendChild(divwrapper);
        document.getElementById(this._target_div).appendChild(divtransmit);
        document.getElementById(this._target_div).appendChild(csslink);
    }
    
    Widget118000.prototype.addActions = function(self,which){
        if(which == "search_action"){
            
            document.getElementById(self._queryform).qs.value = self._last_qs;
            if(document.getElementById(self._queryform).dv){
                document.getElementById(self._queryform).dv.value = self._last_dv;
            }
            
            document.getElementById(self._queryform).onsubmit = function(){
                                            if(this.tr.value == 1){
                                                qs = "qs="+encodeURI(this.qs.value)
                                                   +"&dv="+encodeURI(this.dv.value)
                                                   +"&ot="+encodeURI(this.ot.value);
                                                self._last_qs = this.qs.value;
                                                self._last_dv = this.dv.value;
                                                self._last_ot = this.ot.value;
                                            }else if(this.tr.value == 9){
                                                this.qs.value = this.qs.value.replace(" ","");
                                                this.qs.value = this.qs.value.replace(".","");
                                                qs = "qs="+encodeURI(this.qs.value)
                                                   +"&tr=9";
                                                self._last_qs = this.qs.value;
                                                self._last_dv = "";
                                            }else{
                                                qs = "";
                                            }
                                            W118000Registry.get(self._registry_key).jscall("displayResults",
                                                                                    qs
                                                                                   );
                                            
                                            return false;
                                        }
        }
    }
    
    Widget118000.prototype.getFrontAd = function(self){
        var url = this._baseurl+"frontad";
        self.jscall("drawFrontAd","",url);
    }
    
    Widget118000.prototype.drawFrontAd = function(data){
        document.getElementById(this._frontaddiv).innerHTML = this.template("frontad",data);
    }
    
    Widget118000.prototype.getAvailableSearch = function(self){
        var url = this._baseurl+"allowedsearch";
        self.jscall("drawAvailableSearch","",url);
    }
    
    Widget118000.prototype.drawAvailableSearch = function(data){
        document.getElementById(this._searchchoicesul).innerHTML = this.template("form_search_ul",data);
        this.addActions(this,"search_action");
        
        if(this._options.format == "300X600"){
            this.getFrontAd(this);
        }
    }
    
    Widget118000.prototype.jscall = function(callback,querystring,url){
        callfunc = "W118000Registry.get('"+this._registry_key+"')."+callback;
        
        host = document.location.host || "localhost";
        
        url = url || this._baseurl;
        
        call_url = url+"?host="+host+"&s_id="+this._options.s_id+"&callback="+callfunc+"&mr="+this._options.maxResult+"&"+querystring;
        document.getElementById(this._transmit_div).innerHTML = '';
        var scr  = document.createElement("script");
        scr.type = "text/javascript";
        scr.src  = call_url;
        document.getElementById(this._transmit_div).appendChild(scr);
        this._last_qstring = querystring;
    }
    
    Widget118000.prototype.historyback = function(self){
        //self = W118000Registry.get(self._registry_key);
        self._history.position = Math.max(self._history.position-1,0);
        
        if(self._history.position > 0){
            document.getElementById(self._previousdiv).style.display = "block";
            discardlast = self._history.history.pop();
            historyitem = self._history.history[self._history.history.length-1];
        }else{
            document.getElementById(self._previousdiv).style.display = "none";
            historyitem = self._history.history[0];
        }
        
        document.getElementById(self._infodiv).style.display = historyitem.info.display;
        document.getElementById(self._infodiv).className     = historyitem.info.className;
        document.getElementById(self._infodiv).innerHTML    = historyitem.info.innerHTML;
        
        document.getElementById(self._contentdiv).className = historyitem.content.className;
        document.getElementById(self._contentdiv).innerHTML = historyitem.content.innerHTML;
        document.getElementById(self._contentdiv).style.height = historyitem.content.height;

        if(self._history.position == 0){
            self.getAvailableSearch(self);
            /*self.getFrontAd(self);*/
        }
        return false;
    }
    
    Widget118000.prototype.historysave = function(){
        var historyitem = { info:{
                                    display: document.getElementById(this._infodiv).style.display,
                                    className: document.getElementById(this._infodiv).className,
                                    innerHTML: document.getElementById(this._infodiv).innerHTML
                                  },
                            content:{
                                    className: document.getElementById(this._contentdiv).className,
                                    innerHTML: document.getElementById(this._contentdiv).innerHTML,
                                    height   : document.getElementById(this._contentdiv).style.height
                                  }
                            };
        this._history.history.push(historyitem);
        this._history.position ++;
        if(this._history.position > 0){
            document.getElementById(this._previousdiv).style.display = "block";
        }
    }
    
    Widget118000.prototype.displayResults = function(data){
        
        switch(data.status){
            case "OK":
            case "OKGEX":
                document.getElementById(this._contentdiv).innerHTML = this.template("content_result_default",data);
                this.showInfo("show","Votre recherche : "+this._last_qs+" "+this._last_dv,"w118000infogreen");
                break;
            case "OKDV":
                document.getElementById(this._contentdiv).innerHTML = this.template("error_location",data);
                this.showInfo("show","Plusieurs localité correspondantes : ","w118000infogreen");
                break;
            case "NOKDV":
                document.getElementById(this._contentdiv).innerHTML = this.template("content_result_default",{"resultnum":0});
                this.showInfo("show","Votre recherche : "+this._last_qs+" "+this._last_dv,"w118000infogreen");
                break;
            default:
                document.getElementById(this._contentdiv).innerHTML = data.status;
        }
        this.historysave();
    }
    
    
    Widget118000.prototype.displayDetail = function(data){
        this.showInfo("hide");
        for(x in data.data){
            resline = data.data[x];
            document.getElementById(this._contentdiv).innerHTML = this.template("content_detail",resline);
        }
        this.historysave();
    }
    
}
