function omniture_process_preliste(ajax){
    for (var i = 0; i < omniture_action.length; i++){  
        omniture_action[i](s);
    }   

 if(omniture_action.length != 0){   
    var s_code=s.t();          
    if(s_code)document.write(s_code)  
 }      
  
     if(!ajax){
     omniture_action = [];  
     s.products='';
     s.events='';
     s.prop13='';
     s.prop14='';  
     s.prop15='';
     s.prop17=''; 
     s.prop18='';
     s.prop19='';
     s.prop20='';
     s.prop21='';
     s.prop22='';
     s.prop23='';  
     s.prop24='';
     s.prop25='';
     s.prop26='';
     s.prop27='';
     s.prop31='';
     s.prop33='';  
     s.prop34='';  
     s.eVar26='';
     s.eVar35='';
     s.eVar36='';
     s.eVar38='';
     s.eVar41='';
     s.eVar42='';
     s.eVar43='';
     s.eVar44='';
     s.eVar46='';
     s.eVar49='';
     s.eVar17='';
    }
}
        
function omniture_process_preliste_ajax(){
 omniture_action = [];  
 s.products='';
 s.events='';
 s.prop13='';
 s.prop14='';  
 s.prop15='';
 s.prop17=''; 
 s.prop18='';
 s.prop19='';
 s.prop20='';
 s.prop21='';
 s.prop22='';
 s.prop23='';  
 s.prop24='';
 s.prop25='';
 s.prop26='';
 s.prop27='';
 s.prop31='';
 s.prop33='';  
 s.prop34='';  
 s.eVar26='';
 s.eVar35='';
 s.eVar36='';
 s.eVar38='';
 s.eVar41='';
 s.eVar42='';
 s.eVar43='';
 s.eVar44='';
 s.eVar46='';
 s.eVar49='';
 s.eVar17='';   
    $j(".tracking_omniture_bcl script").each( function () {
          eval($j(this).html());          
    }); 
    omniture_process_preliste(true);
} 
var recharge = 0;
function Refine()
{
    this.ajaxQuery = null;
    this.ajaxLocQuery = null;
    this.textBlockPub = '';
    this.type = 'habiter';
    var oldQuery = new SearchQuery(document.location.search);
    this.lastRnd = { rnd1: oldQuery.GetFirstValueOrDefault("rnd1"), 
                     rnd2: oldQuery.GetFirstValueOrDefault("rnd2") };
    
    this.types = ['habiter', 'investir', 'terrains'];
    this.$frLocPanel = $j('#france_localisation');
    this.$listContainer = $j('#container_resultats');
    
    this.$btPrev = $j('.nav_back_on, .nav_back_off');
    this.$btNext = $j('.nav_forward_on, .nav_forward_off');
    
    this.refinePaging = new RefinePaging(
        this,
        $j('#resultats_top_nombre'),
        $j('#rech_nav1 > .nav_pages'),
        $j('.nav_back_on, .nav_back_off'),
        $j('.nav_forward_on, .nav_forward_off'),
        $j('#rech_nav2 td')
    );
    
    this.breadcrumbInfo = $j('h2').text();
    
    var currentRefine = this;
    if (typeof($j.History) != 'undefined') {
        $j.History.bind(function(hash){
            var query = currentRefine.hashToQuery(hash);
            if (query == null || query.length == 0)
                query = document.location.search.substr(1);
            // do not execute request if the url has #expiree in it
            if (document.location.hash.indexOf('expiree') == -1) {
            currentRefine.executeRequest(query);
            }
        });
    }
    // if there is a hash on first arrive, we change the url of the page
    // also check that there is no "expiree" after the hash
    if ((document.location.hash != null && document.location.hash.length > 0) && (document.location.hash.indexOf('expiree') == -1))
        document.location = 'http://' + document.location.host + document.location.pathname + '?' + this.hashToQuery(document.location.hash.substr(1));

    $j.browser.msie8 = $j.browser.msie && /MSIE 8\.0/i.test(window.navigator.userAgent);
        
    this.initRefine();
    if(recharge === 0 ){
        $j('.refiner_add_ville').live('click', function(e){ currentRefine.AddUITown(); e.preventDefault(); });
        $j('.refiner_del_ville').live('click', function(e){ currentRefine.DelUITown($j(this)); currentRefine.launchRequest(); e.preventDefault(); });
       recharge ++;
    }
}

Refine.prototype.onLaunchRequest = null;

Refine.prototype.onSuccessRequest = null;

Refine.prototype.onErrorRequest = null;

Refine.prototype.SetCurrentType = function(type)
{
    var checked = $j("#criteria_type_bien input:checked:visible").length > 0;
    if (type != this.type)
    {
        switch (type)
        {
            case "habiter":
            case "investir":
                if (!checked)
                    $j("#refiner_programme").attr("checked", "checked");
                break;
            case "terrains":
                if (!checked)
                    $j("#refiner_terrains_programme").attr("checked", "checked");
                break;
        }
    }
    this.type = type;
}

Refine.prototype.getCurrentCountryElement = function()
{
    return $j('#refiner_pays');
}

Refine.prototype.getCountry = function()
{
    return this.getCurrentCountryElement().val();
}

Refine.prototype.getCountryText = function()
{
    var elem = this.getCurrentCountryElement();
    if (elem.is(":visible"))
        return elem.find("option:selected").text();
    return null;
}

Refine.prototype.getCurrentRegionElement = function()
{
    return $j('#refiner_region');
}

Refine.prototype.getRegion = function()
{
    return this.getCurrentRegionElement().val();
}

Refine.prototype.getRegionText = function()
{
    var elem = this.getCurrentRegionElement();
    if (elem.is(":visible"))
        return elem.find("option:selected").text();
    return null;
}

Refine.prototype.getCurrentDepartementElement = function()
{
    return $j('#refiner_departement');
}

Refine.prototype.getDepartementText = function()
{
    var elem = this.getCurrentDepartementElement();
    if (elem.is(":visible"))
        return elem.find("option:selected").text();
    return null;
}

Refine.prototype.getDepartement = function()
{
    return this.getCurrentDepartementElement().val();
}

Refine.prototype.getCurrentTownElement = function()
{
    return $j('#france_localisation select[name="ci"]');
}

Refine.prototype.getTown = function()
{
    var vals = [];
    this.getCurrentTownElement().each(function()
        { 
            var $this = $j(this);
            if ($this.is(":visible"))
            {
                var val = $this.val();
                if (val != null && val.length > 0) vals.push(val); 
            }
        });
    return vals;
}

Refine.prototype.getTownTexts = function()
{
    var vals = [];
    this.getCurrentTownElement().each(function()
        { 
            var $this = $j(this);
            if ($this.is(":visible"))
            {
                if ($this.val() == "")
                    return;
                var val = $this.find("option:selected").text();
                if (val != null && val.length > 0) vals.push(val); 
            }
        });
    return vals;
}

Refine.prototype.getBreadcrumbInfo = function()
{
    return this.breadcrumbInfo;
}

Refine.prototype.hideDetailLoc = function()
{
    this.$frLocPanel.hide();
}

Refine.prototype.showDetailLoc = function()
{
    this.$frLocPanel.show();
}

Refine.prototype.launchUpdateDetailLoc = function(name)
{
    if(this.ajaxLocQuery != null){
        this.ajaxLocQuery.abort();
    }

    var myQuery = new SearchQuery("");
    // depending on what change we give the right param to the query
    switch (name)
    {
        case "country":
            myQuery.SetParameter('idpays', this.getCountry());
            break;
        case "region":
            myQuery.SetParameter('div', this.getRegion());
            break;
        case "dep":
            myQuery.SetParameter('sdiv', this.getDepartement());
            break;
        case "town":
            myQuery.SetParameter('ci', this.getTown().join(','));
            break;
        default:
            var townVal = this.getTown();
            if (townVal != null && townVal.length > 0)
            {
                myQuery.SetParameter('ci', townVal.join(','));
            }
            else
            {
                var depVal = this.getDepartement();
                if (depVal != null && depVal.length > 0)
                {
                    myQuery.SetParameter('sdiv', depVal);
                }
                else
                {
                    return;
                }
            }
            break;
    }
    var dynParams = this.getParameters('', $j('#refiner_criteria .criteria_' + this.type + ' input[type="checkbox"]:checked:visible' +
                                ',#refiner_criteria  .criteria_' + this.type + ' input[type="radio"]:checked:visible' +
                                ',#refiner_criteria  .criteria_' + this.type + ' select:visible option:selected' +
                                ',#refiner_criteria  .criteria_' + this.type + ' input[type="text"]:visible'));
    
    for (var i = 0; i < dynParams.length; i++)
    {
        var currentDynParam = dynParams[i];
        // dynparam may contain localisation param, we skip it
        if (currentDynParam.name == "ci" || currentDynParam.name == "sdiv" ||
            currentDynParam.name == "div" || currentDynParam.name == "idpays")
            continue;
        myQuery.AddValue(currentDynParam.name, currentDynParam.values);
    }
    var currentRefine = this;
    this.ajaxLocQuery = $j.ajax(
    {
        url:'/update_localisation_json.htm',
        data:myQuery.toString(),
        timeout:15000,
        success:function(data)
        {
            $j("#current_recherche").val(myQuery.toString());
            currentRefine.updateDetailLoc(eval(data)[0]);
            initDetailClicks();
        } 
    });
}

Refine.prototype.updateDetailLoc = function(data)
{
    this.getCurrentRegionElement().html(this.createOptions(data.region));
    this.getCurrentDepartementElement().html(this.createOptions(data.departement));
    var selected = [];
    for (var j = 0; j < data.town.length; j++) {
        if (data.town[j].selected) selected.push(j);
        data.town[j].selected = false;
    }
    var options = this.createOptions(data.town);
    var selects = this.getCurrentTownElement();
    for (var i = 0; i < selects.length; i++) {
        $j(selects[i]).html(options);
        if (selected.length > 0) {
            $j(selects[i]).children(':eq(' + selected.pop() + ')')
                .attr("selected", "selected");
        }
    };
}


Refine.prototype.createOptions = function(values)
{
    var options = [];
    var name ="";
    for (var i = 0; i < values.length; i++)
    {
        name = values[i].label.split('(');
        options.push('<option value="', values[i].value,
            '" ', (values[i].selected ? 'selected' : ''),'>', 
           name[0], "</option>");
        // code below for type d'investissements
        if (values[i].selected && values[i].article_id) {
            var infos = $j('#CNTUNAME_' + values[i].article_id).html().split('|');
            $j('#lien_investir_type').attr('href', '/' + infos[0] + '/' + infos[1] + '/article.htm').attr("title","Plus d'infos pour investir en " + infos[2]);
        }
    }
    return options.join('');
}

Refine.prototype.createInputs = function(type, name, values, wrapTag)
{
    var options = [];
    
    for (var i = 0; i < values.length; i++)
    {
        if (wrapTag != undefined)
            options.push('<', wrapTag, '>');
        options.push('<input value="', values[i].value,
            '" ', (values[i].selected ? 'checked' : ''),
            ' ', (values[i].disabled ? 'disabled' : ''),
            ' name="', name, '" id="', name, '-', values[i].value,
            '" type="', type, '" /><label for="', name, '-', values[i].value, 
            '">', values[i].label, "</label>");
        if (wrapTag != undefined)
            options.push('</', wrapTag, '>');
    }
    return options.join('');
}

Refine.prototype.getParamInElement = function(element, rmStr)
{
    return element.id.substr(rmStr.length).split('|');
}

Refine.prototype.addParamValue = function(values, key, value)
{
    if (values[key] == null)
        values[key] = [];
    
    // check if val already exists (useful for quartier+location)
    var curValues = values[key];
    for (var k = 0; k < curValues.length; k++)
    {
        if (curValues[k] == value)
            break;
    }
    if (k == curValues.length)
        values[key].push(value);
}

Refine.prototype.getParameters = function(rmStr, elements)
{
    var len = elements.length;
    
    var values = new Object();
    var keys = [];
    var params = [];
    for (var i = 0; i < len; i++)
    {
        var elemNamer = elements[i].tagName.toLowerCase() == "option" ? elements[i].parentNode : elements[i];
        var name = elemNamer.name;
        if (name == undefined)
            name = elements[i].id;
        var names = name.split('|');
        var values = elements[i].value.split('|');
        for (var j = 0; j < names.length; j++)
        {
            params.push({name:names[j], values:values[j].split(',')});
        }
    }
    return params;
}

Refine.prototype.createQuery = function(page)
{   
    var myQuery = new SearchQuery("");
        
    var rnd;
    if (page == undefined) {
        // if no page set, then it's a new request and not
        // a pagination request (in this case we regenerate rnd)
        page = 1;
        rnd = this.genParamTri();

    }
    else {
        rnd = this.lastRnd;
    }
    var dynParams = this.getParameters('', $j('#refiner_criteria .criteria_' + this.type + ' input[type="checkbox"]:checked:visible' +
                                ',#refiner_criteria  .criteria_' + this.type + ' input[type="radio"]:checked:visible' +
                                ',#refiner_criteria  .criteria_' + this.type + ' select:visible option:selected' +
                                ',#refiner_criteria  .criteria_' + this.type + ' input[type="text"]:visible' +
                                ', #resultats_top_tri select:visible option:selected'));

    for (var i = 0; i < dynParams.length; i++)
    {
        var currentDynParam = dynParams[i];
        // handle dom-tom as country
        if (currentDynParam.name == "idpays" && currentDynParam.values[0] == "97")
        {
            currentDynParam.values[0] = "250";
            myQuery.AddValue("cp", "97");
        }
        myQuery.AddValue(currentDynParam.name, currentDynParam.values);
    }
    
    if (myQuery.GetFirstValueOrDefault("ci")) {
        myQuery.RmParameter("sdiv");
        myQuery.RmParameter("div");
        myQuery.RmParameter("idpays");
    } else if (myQuery.GetFirstValueOrDefault("sdiv")) {
        myQuery.RmParameter("div");
        myQuery.RmParameter("idpays");
    }
    
    if (page != undefined) {
        myQuery.SetParameter("ANN_NEUFpg", page);
    }
    myQuery.SetParameter("rnd1", rnd.rnd1);
    myQuery.SetParameter("rnd2", rnd.rnd2);
    
    this.lastRnd = rnd;
    return myQuery;
    
}

Refine.prototype.executeRequest = function(query)
{
   
    if (this.onLaunchRequest != null)
        this.onLaunchRequest();

    if(this.ajaxQuery != null){
        this.ajaxQuery.abort();
    }

    var currentRefine = this;
            //alert(query);
    this.ajaxQuery = $j.ajax(
    {  
        url:'/recherche_ajax.htm',
        data:query,
        timeout:15000,
        success:function(data)
        {
            $j("#current_recherche").val(query);
            searchQuery = new SearchQuery(query);
            currentRefine.successRequest(data);
            currentRefine.updateAltContent(query);
            initDetailClicks();
        },
        error:function()
        {
            if (currentRefine.onErrorRequest != null)
                currentRefine.onErrorRequest();
                
        }
    });
}

Refine.prototype.queryToHash = function(query)
{
    return query.replace(/\//g,';').replace(/&/g,'/').replace(/=/g,':');
}

Refine.prototype.hashToQuery = function(hash)
{
    if (hash == null)
        return null;
    return hash.replace(/\//g,'&').replace(/:/g,'=').replace(/;/g,'/');
}

Refine.prototype.launchRequest = function(page)
{   
    var searchQuery = this.createQuery(page).toString();

    // use history to launch request
 /*   
        if (typeof($j.History) != 'undefined')
            $j.History.setHash(this.queryToHash(searchQuery));
        else 
 */
            this.executeRequest(searchQuery);
    /*} else {
        this.executeRequest(searchQuery);
    }*/
    if(document.getElementById("refiner_ville_1").value === "" ){
        $j('#elargissement').hide();
    }else{
        $j('#elargissement').show();
    }
}
// function delSelect, Remove Selected whose value is null 
Refine.prototype.delSelect = function (){
    var eq = 1;
    var numList = 2;
    for(i=1; i<3; i++){
        var select = document.getElementById("refiner_ville_"+numList+"");
        if(select){
            if(select.value === ''){
                $j(".refiner_ville_container:eq("+eq+")").remove();
                this.refreshTownOptions();
            }else{
                var eq = 2;
            }
            numList += 1;
        }
    }
}

Refine.prototype.successRequest = function(data)
{
    var currentRefine = this;

    this.$listContainer.fadeTo('fast', 0.5);
    this.$listContainer[0].innerHTML = data;
    
    var refineData = eval($j('#search_refine_json').val())[0];
    
    this.updateRefine(refineData.refine);

    this.textBlockPub = refineData.textepub;
    
    this.updateDetailLoc(refineData.place);
    
    this.refinePaging.Update(
        refineData.paging.nbResults,
        refineData.paging.currentPage,
        refineData.paging.totalPages);
        
    this.$listContainer.fadeTo('fast', 1);
    if (this.onSuccessRequest != null)
        this.onSuccessRequest();
    $j("#layer_over").hide();
    $j("#refiner_loading").hide();
}

Refine.prototype.updateAltContent = function(query) {

    /* Checking for idtt and idtypebiens within the query */
    var queryArray = query.split('&');
    var idtt;
    var idtb;
    var tmp;
    var new_query = '';
    for (var i = 0; i < queryArray.length; i++) {
        if (queryArray[i].indexOf('idtt') > -1) {
            tmp = queryArray[i].split('=');
            if (tmp[1]) {
                idtt = tmp[1];
                /* Retravail de la query */
                tmp[1] = '9';
                queryArray[i] = tmp.join('=');
            }
        }
        if (queryArray[i].indexOf('idtypebien') > -1) {
            tmp = queryArray[i].split('=');
            idtb = tmp[1].split(',');
            /* Retravail de la query */
            tmp[1] = '15';
            queryArray[i] = tmp.join('=');
        }
    }

    /* Build new query for link */
    new_query = queryArray.join('&');
    
    if (idtt == '2') {
        var test_idtb = false;
        var idtb_text = "Découvrez les programmes neufs contenant l'ensemble des logements<br />se rapportant à cette recherche";
        var idtb_text2 = "Découvrez les programmes neufs contenant l'ensemble des logements se rapportant à cette recherche";
        for (var j = 0; j < idtb.length; j++) {
            if (idtb[j] == 1 || idtb[j] == 2 || idtb[j] == 4) {
                test_idtb = true;
                if (idtb[j] == 4) {
                    idtb_text = "Découvrez les lotissements contenant l’ensemble des terrains<br />se rapportant à cette recherche";
                    idtb_text2 = "Découvrez les lotissements contenant l’ensemble des terrains se rapportant à cette recherche";
                    new_query += "&si_terrain=1";
                }
            }
        }
        if (test_idtb) {
            /* Mise à jour du contenu du block */
            var new_link = '<a href="recherche.htm?' + new_query + '" title="' + idtb_text2 + '" class="button_vers_prog"><!-- --></a>'

            $j("#container_resultats_vers_prog").html('<p>' + idtb_text + ' : <span>' + this.textBlockPub + '</span></p>' + new_link);
            $j("#container_resultats_vers_prog_top").html('<p>' + idtb_text2 + ' : <br /><span>' + this.textBlockPub + '</span></p>' + new_link);

            $j("#container_resultats_vers_prog,#container_resultats_vers_prog_top").show();
            $j("#container_resultats_vers_prog_top").parents("div").show();
        } else {
            $j("#container_resultats_vers_prog,#container_resultats_vers_prog_top").hide();
        }
    } else {
        $j("#container_resultats_vers_prog,#container_resultats_vers_prog_top").hide();
    }

    var domain = $j("#current_domain").val();
    $j("#pub_300_Right_iframe").attr('src', domain + '/recherche,frame_300_250.htm?' + query);
    $j("#pub_728_90_iframe").attr('src', domain + '/recherche,frame_728_90.htm?' + query);
    $j("#pub_300_600_iframe").attr('src', domain + '/recherche,frame_300_600.htm?' + query);
    $j("#pub_300_600_2_iframe").attr('src', domain + '/recherche,frame_300_600_2.htm?' + query);
    $j("#pub_300_encart_iframe").attr('src', domain + '/recherche,frame_300_encart.htm?' + query);
    $j("#blocAlerte_refine_top,#blocAlerte_refine_bottom_1,#blocAlerte_refine_bottom_2").attr('href', domain + '/recherche,alerte,creation.htm?' + query);
    $j("#rss_recherche_refine").attr('href', domain + '/rss,recherche.xml?' + query);
        //console.info($j("#rss_recherche_refine").attr('href'));
}

Refine.prototype.updateTypeBienItem = function(id, count, selected)
{

    var input = $j('#' + id);
    input.next('label').children('.refiner_count').text('(' + count + ')');
    if (count == 0) 
        input.attr('disabled', 'disabled');
    else
        input.removeAttr('disabled');
    if (selected)
        input.attr('checked', 'checked');
    else
        input.removeAttr('checked');
}

Refine.prototype.updateTypeBien = function(refineInfo)
{
    var nbapp = 0;
    var nbmaison = 0;
    var nbprog = 0;
    var nbterrains = 0;
    var selapp = false;
    var selmaison = false;
    var selprog = false;
    var selterrains = false;
    for (var i = 0; i < refineInfo.values.length; i++) {
        switch (refineInfo.values[i].value) {
            case '1':
                nbapp = refineInfo.values[i].count;
                selapp = refineInfo.values[i].selected;
                break;
            case '2':
                nbmaison = refineInfo.values[i].count;
                selmaison = refineInfo.values[i].selected;
                break;
            case '15':
                nbprog = refineInfo.values[i].count;
                selprog = refineInfo.values[i].selected;
                if (selprog) 
                {
                    $j("#resultats_top_tri_selection_prg").show();
                    $j("#resultats_top_tri_selection").hide();
                }
                else
                {
                    $j("#resultats_top_tri_selection_prg").hide();
                    $j("#resultats_top_tri_selection").show();
                }
                break;
            case '4':
                nbterrains = refineInfo.values[i].count;
                selterrains = refineInfo.values[i].selected;
                break;
        }
    }
    this.updateTypeBienItem('refiner_logement', nbapp + nbmaison, selapp | selmaison);
    this.updateTypeBienItem('refiner_appartement', nbapp, selapp);
    this.updateTypeBienItem('refiner_maison', nbmaison, selmaison);
    this.updateTypeBienItem('refiner_programme', nbprog, selprog);
    this.updateTypeBienItem('refiner_terrains_logement', nbterrains, selterrains);
    this.updateTypeBienItem('refiner_terrains_programme', nbprog, selprog);
}

Refine.prototype.updateRefine = function(refineData)
{
    for (var i = 0; i < refineData.length; i++)
    {
        var refineInfo = refineData[i];
        if (refineInfo.name == 'idtypebien')
        {    
            if (jQuery.inArray(this.type, refineInfo.types) >= 0)
                this.updateTypeBien(refineInfo);
            continue;
        }
        var $container = $j('#' + refineInfo.name + '_container');
        switch (refineInfo.type)
        {
            case 'select':
                $container = $container.find('select');
                $container.html(this.createOptions(refineInfo.values));
                break;
            case 'checkbox':
            case 'radio':
                $container[0].innerHTML = this.createInputs(refineInfo.type, refineInfo.name, refineInfo.values, 'p');
                break;
        }
    }
}

Refine.prototype.countryChange = function()
{
    if (this.getCountry() != "250")
    {
        this.hideDetailLoc();
        this.launchRequest();
        return;
    }
    this.launchUpdateDetailLoc('country');
    this.showDetailLoc();
}

Refine.prototype.AddUITown = function()
{   
    this.$frLocPanel = $j('#france_localisation');
    var selects = this.$frLocPanel.find("select[name='ci']");
    var count = selects.length;
    if (count >= 3) return;
    var $lastTownElem = this.$frLocPanel.find(".refiner_ville_container:last");
    $lastTownElem.clone().insertAfter($lastTownElem).find("select").val("");
    $j('.refiner_ville_container:eq(0) select').attr("id","refiner_ville_1");
    $j('.refiner_ville_container:eq(1) select').attr("id","refiner_ville_2");
    $j('.refiner_ville_container:eq(2) select').attr("id","refiner_ville_3");
    this.refreshTownOptions();
    var currentRefine = this;
    this.$frLocPanel.find('.refiner_ville_container select')
        .unbind('change')
        .change(function() { currentRefine.launchRequest(); });
}

Refine.prototype.DelUITown = function($element)
{
    $element.parents(".refiner_ville_container").remove();
    $j('.refiner_ville_container:eq(0) select').attr("id","refiner_ville_1");
    $j('.refiner_ville_container:eq(1) select').attr("id","refiner_ville_2");
    $j('.refiner_ville_container:eq(2) select').attr("id","refiner_ville_3");
    this.refreshTownOptions();
}

Refine.prototype.clearTown = function()
{
    this.$frLocPanel.find(".refiner_ville_container").not(":eq(0)").remove();
    this.$frLocPanel.find(".refiner_ville_container option:eq(0)").attr("selected", "selected");
    this.refreshTownOptions();
}

Refine.prototype.refreshTownOptions = function()
{
    var currentRefine = this;
    var addOption = this.$frLocPanel.find(".refiner_add_ville").hide();
    if (addOption.length != 3) addOption.filter(":last").show();
    var delOption = this.$frLocPanel.find(".refiner_del_ville");
    delOption.css("visibility", delOption.length == 1 ? "hidden" : "visible");
}

Refine.prototype.setTypeBien = function($elem)
{
    if ($elem.attr("type") == "radio")
    {
        $elem.parent().parent().find('input[type="checkbox"]').removeAttr('checked');
        $elem.parent().nextAll(".refiner_block_criteres_indent").find('input').attr('checked', 'checked');
    }
    else
    {
        $elem.parent().parent().find('input[type="radio"]').removeAttr('checked');
        $elem.parent().parent().find('input:eq(0)').attr('checked', 'checked');
        if (!$elem.is(":checked")) // if elem is going unchecked
        {
            if ($elem.parent().parent().find('input[type="checkbox"]:checked').not($elem).length == 0)
            {
                $elem.attr('checked', 'checked');
            }
        }
    }
}

Refine.prototype.genParamTri = function()
{
    rnd1 = 10000 * Math.random() | 0;
    rnd2 = 10000 * Math.random() | 0;
    
    while(rnd1 % rnd2 == 0 || rnd2 % rnd1 == 0) {
        rnd1++;
    }
    return { rnd1: rnd1, rnd2: rnd2 };
}

Refine.prototype.initRefine = function()
{
    var currentRefine = this;
    $j('#refiner_pays').change(function(){ currentRefine.countryChange(); });
    $j('#refiner_region').change(function(){ currentRefine.launchUpdateDetailLoc('region'); });
    // if departement change we must set town to empty
    $j('#refiner_departement').change(function(){ currentRefine.clearTown(); });
    // if type bien change, there is some logic to do
    $j("#criteria_type_bien input").change(
        function(e) {
            currentRefine.setTypeBien($j(this));
            currentRefine.launchRequest();
        });
    // if departement or town change we launch the request
    $j('#refiner_criteria select').not('#refiner_pays, #refiner_region')
        .change(function() { currentRefine.launchRequest(); });

    // if any checkbox or radio change in column 3 or 4 we launch request
    // and we do some nasty stuff to know if there is some UI manip to do
    $j('#refiner_col_3 , #refiner_col_4')
        .delegate('input[type="radio"], input[type="checkbox"]', 'change', function()
        { 
            var el = $j(this);

            if (el.attr("type") == "checkbox")
            {
                var sel;
                if (el.val() == "all" ||  el.val() == "0") { 
                    sel = el.parent().parent().find('input').not(el);
                } else { 
                    sel = el.parent().parent().find('input:first'); 
                }
                sel.removeAttr("checked");
            }
            currentRefine.launchRequest(); 
        });

    $j('#resultats_top_tri select').change(function(){ currentRefine.launchRequest(); });
    $j('.refiner_block_criteres input[type="image"]').click(function() {
        currentRefine.launchRequest();
    });
}
