function changeFamille(num)
{
    document.getElementById('famille1').src = "img/picto-camping-car.png";
    document.getElementById('famille2').src = "img/picto-mobilhome.png";
    document.getElementById('famille3').src = "img/picto-caravane.png";

    $("#famille1").attr("rel","");
    $("#famille2").attr("rel","");
    $("#famille3").attr("rel","");

    ch=document.getElementById('famille'+num).src

    document.getElementById('famille'+num).src = ch.replace(/\.png/,"ON.png");
    document.getElementById('idfamille').value=num;

// $("#famille"+num).attr("rel", "encours");
// alert($("img.famillepicto[rel='encours']").attr("id"))
}
    
$(function(){

    // click sur trasnaction
    $("input[name=idtransaction][type=radio]").click(function(){
        var idtransaction=$(this).val();

        //gere l'affichage des listes en fonction du type de transaction
        if (idtransaction==1) {
            $("tr:has(td select#nomgamme)").show();
            $("tr:has(td select#nommarque)").show();
            $("tr:has(td select#idfourchetteprix)").show();
            $("tr:has(td select#idfourchettekm)").hide();
        }

        if (idtransaction==2) {
            $("tr:has(td select#idfourchetteprix)").show();
            $("tr:has(td select#idfourchettekm)").show();
            $("tr:has(td select#nomgamme)").show();
            $("tr:has(td select#nommarque)").hide();
        }
        if (idtransaction==3) {
            $("tr:has(td select#nomgamme)").hide();
            $("tr:has(td select#nommarque)").hide();
            $("tr:has(td select#idfourchetteprix)").hide();
            $("tr:has(td select#idfourchettekm)").hide();
        }
        //maj le contenu de la liste gamme
        $.getJSON("php/selectlisteajax.php",{
            idtransaction:idtransaction,
            idfamille: $("#idfamille").val(),
            ajax: 'true'
        }, function(k){
            var options = '';
            for (var i = 0; i < k.length; i++) {
                options += '<option value="' + k[i].optionValue + '" '+k[i].optionSelected+'>' + k[i].optionDisplay + '</option>';
            }
            $("select#nomgamme").html(options);
        });
        //maj le contenu de la liste marque
        $.getJSON("php/selectlisteajax.php",{
            idtransaction:idtransaction,
            idfamille: $("#idfamille").val(),
            nomgamme: "",
            ajax: 'true'
        }, function(k){
            var options = '';
            for (var i = 0; i < k.length; i++) {
                options += '<option value="' + k[i].optionValue + '" '+k[i].optionSelected+'>' + k[i].optionDisplay + '</option>';
            }
            $("select#nommarque").html(options);
        });

    });

    // click sur picto famille
    $("img.famillepicto").click(function(){
        //maj le contenu de la liste gamme
        $.getJSON("php/selectlisteajax.php",{
            idtransaction:$("input[name=idtransaction][type=radio][checked]").val(),
            idfamille: $("#idfamille").val(),
            ajax: 'true'
        }, function(k){
            var options = '';
            for (var i = 0; i < k.length; i++) {
                options += '<option value="' + k[i].optionValue + '" '+k[i].optionSelected+'>' + k[i].optionDisplay + '</option>';
            }
            $("select#nomgamme").html(options);
        });
        //maj le contenu de la liste marque
        $.getJSON("php/selectlisteajax.php",{
            idtransaction:$("input[name=idtransaction][type=radio][checked]").val(),
            idfamille: $("#idfamille").val(),
            nomgamme: "",
            ajax: 'true'
        }, function(k){
            var options = '';
            for (var i = 0; i < k.length; i++) {
                options += '<option value="' + k[i].optionValue + '" '+k[i].optionSelected+'>' + k[i].optionDisplay + '</option>';
            }
            $("select#nommarque").html(options);
        });
    })

    if ( $("select#nomgamme").length > 0 ) {
        // click sur liste gamme
        $("select#nomgamme").change(function(){
            var nomgamme=$(this).val();
            //maj le contenu de la liste marque
            $.getJSON("php/selectlisteajax.php",{
                idtransaction:$("input[name=idtransaction][type=radio][checked]").val(),
                idfamille: $("#idfamille").val(),
                nomgamme: nomgamme,
                ajax: 'true'
            }, function(k){
                var options = '';
                for (var i = 0; i < k.length; i++) {
                    options += '<option value="' + k[i].optionValue + '" '+k[i].optionSelected+'>' + k[i].optionDisplay + '</option>';
                }
                $("select#nommarque").html(options);
            });
        })
    }
  
});

///init
$(document).ready(function(){
    $("input[name=idtransaction][type=radio]:checked").click();
//$("img.famillepicto[rel='encours']").click();
//alert($("img.famillepicto[rel='encours']").attr('id'))
});

function trim (str, charlist) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: mdsjack (http://www.mdsjack.bo.it)
    // +   improved by: Alexander Ermolaev (http://snippets.dzone.com/user/AlexanderErmolaev)
    // +      input by: Erkekjetter
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: DxGx
    // +   improved by: Steven Levithan (http://blog.stevenlevithan.com)
    // +    tweaked by: Jack
    // +   bugfixed by: Onno Marsman
    // *     example 1: trim('    Kevin van Zonneveld    ');
    // *     returns 1: 'Kevin van Zonneveld'
    // *     example 2: trim('Hello World', 'Hdle');
    // *     returns 2: 'o Wor'
    // *     example 3: trim(16, 1);
    // *     returns 3: 6

    var whitespace, l = 0, i = 0;
    str += '';

    if (!charlist) {
        // default list
        whitespace = " \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000";
    } else {
        // preg_quote custom list
        charlist += '';
        whitespace = charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '\$1');
    }

    l = str.length;
    for (i = 0; i < l; i++) {
        if (whitespace.indexOf(str.charAt(i)) === -1) {
            str = str.substring(i);
            break;
        }
    }

    l = str.length;
    for (i = l - 1; i >= 0; i--) {
        if (whitespace.indexOf(str.charAt(i)) === -1) {
            str = str.substring(0, i + 1);
            break;
        }
    }

    return whitespace.indexOf(str.charAt(0)) === -1 ? str : '';
}
function strtolower( str ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Onno Marsman
    // *     example 1: strtolower('Kevin van Zonneveld');
    // *     returns 1: 'kevin van zonneveld'

    return (str+'').toLowerCase();
}
function str_replace(search, replace, subject) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Gabriel Paderni
    // +   improved by: Philip Peterson
    // +   improved by: Simon Willison (http://simonwillison.net)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   bugfixed by: Anton Ongson
    // +      input by: Onno Marsman
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +    tweaked by: Onno Marsman
    // +      input by: Brett Zamir (http://brettz9.blogspot.com)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: str_replace(' ', '.', 'Kevin van Zonneveld');
    // *     returns 1: 'Kevin.van.Zonneveld'
    // *     example 2: str_replace(['{name}', 'l'], ['hello', 'm'], '{name}, lars');
    // *     returns 2: 'hemmo, mars'

    var s = subject;
    var ra = r instanceof Array, sa = s instanceof Array;
    var f = [].concat(search);
    var r = [].concat(replace);
    var i = (s = [].concat(s)).length;

    var j = 0;

    while (j = 0, i--) {
        if (s[i]) {

            while (s[i] = (s[i]+'').split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f){};
        }
    }

    return sa ? s : s[0];
}

function slugify(text)
{
    var voyelleaccent   = new Array(".","€","Â", "à", "â", "ä", "É", "é", "È", "è", "Ê", "ê", "ë", "ï", "î", "ô", "ö", "û", "ü", "ù", "ç");
    var voyellessaccent = new Array("","euros","A", "a", "a", "a", "E", "e", "E", "e", "E", "e", "e", "i", "i", "o", "o", "u", "u", "u", "c");

    for(i=0;i<voyelleaccent.length;i++)
    {
        text = str_replace(voyelleaccent[i], voyellessaccent[i],text);
    }


    //text = str_replace(voyelleaccent, voyellessaccent,text);

    // replace all non letters or digits by -

    text=text.replace(/\W+/g,"-")
    //text = preg_replace('/\W+/', '-', text);

    // trim and lowercase
    text = strtolower(trim(text, '-'));

    return text;
}

function testerRadio(radio) {
    theone=-1;
    for (var i=0; i<radio.length;i++) {
      
        if (radio[i].checked) {
            theone=i
        }
    }
    return theone
}

function actionRechercheSimple()
{
    if ($("#idfourchetteprix").val()=="")
        chprix="-"
    else
        chprix="-"+tabfourchetteprix[$("#idfourchetteprix").val()];

    var idtransaction=$("input[name=idtransaction][type=radio]:checked").val()
    switch (idtransaction)
    {
        case "1":
            chtransaction="vente";
            chtype="-neuf"
            chmarque="-"+$("select#nommarque").val()
            break;
        case "2":
            chtransaction="vente";
            chtype="-occasion"
            chmarque="-"+$("select#nommarque").val()
            break;
        case "3":
            chtransaction="location";
            chtype="";
            chprix=""
            chmarque=""
            break;
    }

    chfamille="-"+tabfamille[$("#idfamille").val()];

    if ($("#idnbvoyageur").val()=="")
        chplace="-"
    else
        chplace="-"+tabnbvoyageur[$("#idnbvoyageur").val()];

    chnumpage=",0";


    if (($("#idnbvoyageur").val()=="")&&($("select#nomgamme").val()=="")&&($("select#nommarque").val()=="")&&($("#idtypedecouchage").val()=="")&&($("#idfourchettekm").val()=="")&&($("idfourchetteprix").val()==""))
    ch=chtransaction+chfamille+chtype+'.html';
else
    ch=chtransaction+chfamille+chtype+chmarque+chplace+chprix+chnumpage+'.html';

    //ch="index.inc.php?page=liste";
    document.recherche.action=ch;
    document.recherche.submit()
}






