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 strtoupper( 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+'').toUpperCase();
}
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()
{

    chactioninit=document.formsearch.action
    //if ((document.formsearch.ville.options.length>0)) {
if ((document.formsearch.ville.options[0].text)=="Indifférent") { //si francais

        numsupport=document.formsearch.idsupport.options.selectedIndex
        numtype=document.formsearch.idtype.options.selectedIndex
        numville=document.formsearch.ville.options.selectedIndex
        numbudget=document.formsearch.idbudget.options.selectedIndex
        numpieces=document.formsearch.pieces.options.selectedIndex
        reference=document.formsearch.reference

        ch="annonces-immobilieres-";

        if (document.formsearch.idsupport[numsupport].value=='V')
        {


            ch=ch+"vente-";
            if (numtype>0)
                ch=ch+slugify(document.formsearch.idtype.options[numtype].text);
            ch=ch+"-"
            ch=ch+'alpes-maritimes-';

        }
        else
        {
            ch=ch+"location-";
            if (numtype>0)
                ch=ch+slugify(document.formsearch.idtype.options[numtype].text);
            ch=ch+"-"
            ch=ch+'alpes-maritimes-cote-azur-';

        }


        if (numville>0)
            ch=ch+slugify(document.formsearch.ville.options[numville].text);
        ch=ch+","
        if (numbudget>0)
            ch=ch+document.formsearch.idbudget.options[numbudget].value;
        ch=ch+","
        if (numpieces>0)
            ch=ch+document.formsearch.pieces.options[numpieces].value;
        ch=ch+","
        ch=ch+strtoupper(slugify(document.formsearch.reference.value));


        ch=ch+",0.php";


       // alert(ch)

        if (document.formsearch.isnouveautes.value==1) {
          
            if (document.formsearch.idsupport[numsupport].value=='V')
                document.location.href='annonces-immobilieres-vente-06-nouveaute.php'
            else
                document.location.href='annonces-immobilieres-location-06-nouveaute.php'
        }
        else {

            document.formsearch.action=ch;
           document.formsearch.submit()
        }
    }
    else {
        document.formsearch.method='get';
        document.formsearch.submit()

    }


}





