function persoMonCompte() {
    var prenom = document.getElementById('prenom').value;
    var nom = document.getElementById('nom').value;
    var gsm = document.getElementById('gsm').value;
    var tel = document.getElementById('tel').value;
    var fax = document.getElementById('fax').value;

    var nreply = '';
    var ifChecked = document.getElementById('nreply').checked;
    if (ifChecked) var nreply = document.getElementById('nreply').value;

    var url = 'async.php?generic=persoMonCompte' + '&prenom=' + escape(prenom) + '&nom=' + escape(nom) + '&gsm=' + escape(gsm) + '&tel=' + escape(tel) + '&fax=' + escape(fax) + '&nreply=' + nreply;
    loadMulti(url + "|div_status");
}



function abuse(id) {
    var abuse_commentaire = document.getElementById('abuse_commentaire').value;
    var abuse_id_annonce = document.getElementById('abuse_id_annonce').value;
    var url = 'async_annonces.php?generic=signalement_annonce' + '&id_annonce=' + escape(abuse_id_annonce) + '&abuse_commentaire=' + escape(abuse_commentaire) + '&id_motif=' + escape(id);
    loadMulti(url + "|div_status");
    closeBox_Color();

}

function show_photos_up(id, type_photo) {
    var url = 'async.php?generic=show_photos_up&id_up=' + id + '&type_photo=' + type_photo
    loadMulti(url + "|output_pj");
}

function majNbrPhotos(id_annonce, type_photo) {
    var url = 'async.php?generic=majNbrPhotos&id_annonce=' + id_annonce + '&type_photo=' + type_photo;
    loadMulti(url + "|div_status");
}

function majCommentaireAjoutPhotos(id_annonce) {
    var countPhotos = document.getElementById('countPhoto_ajout_new_annonce').value;
    alert('off - ' + countPhotos);
}

function majCommentaireUploadPhotos(id_auto, commentaire, type_photo) {
    var url = 'async.php?generic=majCommentaireUploadPhotos&id_auto=' + escape(id_auto) + '&commentaire=' + escape(commentaire) + '&type_photo=' + type_photo;
    loadMulti(url + "|div_status");
}

function moteur_recherche(event, closeBox) {

    if (closeBox == 1) {
        (parent.window['jQueryACB'] || parent.window['jQuery']).colorbox.close();
    }
    var src_moteur_recherche = document.getElementById('src_moteur_recherche').value;
    if (src_moteur_recherche == '') return false;
    if (src_moteur_recherche.length <= 1) {
        return false
    }
    var url = 'async_annonces.php?generic=cat&recherche=' + escape(src_moteur_recherche);
    if (event != 'noEvent') {
        if (event.keyCode == 13) loadMulti(url + "|div_centre_0");
    } else {
        loadMulti(url + "|div_centre_0");
    }
}

function repondre_message_messagerie(divDest, avec_photo) {
    var msg_to = 'msg_to_' + divDest;
    var msg_from = 'msg_from_' + divDest;
    var msg_sujet = 'msg_sujet_' + divDest;
    var msg_msg = 'msg_msg_' + divDest;
    var msg_id_annonce = 'msg_id_annonce_' + divDest;
    var msg_id_website = 'msg_id_website_' + divDest;
    var msg_id_message = 'msg_id_message_' + divDest;
    var source_table = 'source_table_' + divDest;

    var msg_to = document.getElementById(msg_to).value;
    var msg_from = document.getElementById(msg_from).value;
    var msg_sujet = document.getElementById(msg_sujet).value;
    var msg_msg = document.getElementById(msg_msg).value;
    var msg_id_annonce = document.getElementById(msg_id_annonce).value;
    var msg_id_website = document.getElementById(msg_id_website).value;
    var msg_id_message = document.getElementById(msg_id_message).value;
    var source_table = document.getElementById(source_table).value;

    msg_msg = msg_msg.replace(/\+/g, "__plus__");

    if (msg_msg == '') {
        alert('Votre message est vide !!');
        return false;
    }
    var url = 'msg_id_annonce=' + escape(msg_id_annonce) + '&msg_id_website=' + escape(msg_id_website) + '&msg_id_message=' + escape(msg_id_message) + '&msg_divDest=' + escape(divDest) + '&msg_to=' + escape(msg_to) + '&msg_from=' + escape(msg_from) + '&msg_sujet=' + escape(msg_sujet) + '&msg_repondre_message_id=' + divDest + '&avec_photo=' + avec_photo + '&msg_msg=' + escape(msg_msg) + '&source_table=' + source_table;
    $.ajax({
        type: "POST",
        cache: false,
        url: "async_messageries.php?generic=repondre_message_messagerie",
        data: url,
        success: function (data) {
            $(document).ready(function () {

                if (source_table == 'wan_messages_archive') {
                    alert("Votre conversation a \351t\351 d\351plac\351 dans votre boite de r\351ception");
                    loadMulti('async_messageries.php?generic=show_message&table=en_cours|div_centre_0');
                }
                //alert('ok');
                var xhr_msg = "async_messageries.php?generic=detail_message&noAnimDiv=1&id_annonce=" + msg_id_annonce + +"&msg_to=" + msg_to + "&msg_from=" + msg_from + "&id_message=" + msg_id_message + "&divDest=" + divDest + "&close=1&type=|" + divDest;

                loadMulti(xhr_msg);

                if (avec_photo == 1) {
                    call_cbox("pj_mail.php?type_photo=2&generic=detail_message&id_annonce=" + msg_id_annonce + "&msg_from=" + msg_from + "&msg_to=" + msg_to + "&id_message=" + msg_id_message + "&divDest=" + divDest + "&close=1&noAnimDiv=1&type=", 'Ajouts de photos', 720, 760);
                } else {
                    animatedGoTo('footer_' + divDest);
                }
            });
        },
        dataType: "json"
    });
}

function repondre_annonce() {

    var id_annonce = document.getElementById('repondre_annonce_id_annonce').value;
    var msg = document.getElementById('repondre_annonce_msg').value;

    if (msg != '') {
	    var url_data = 'id_annonce=' + escape(id_annonce) + '&msg=' + escape(msg);
	    $.ajax({
	        type: "POST",
	        cache: false,
	        url: 'async.php?generic=repondre_annonce',
	        data: url_data,
	        error: function () {
	        	alert("Un probl\350me a \351t\351 detect\351 durant l'envoi de votre message, merci de rafraichir votre navigateur (CTRL + F5)");
	        },
	        success: function () {
	            $(document).ready(function () {
				 closeBox_Color();
				alert("Votre message a bien \351t\351 envoy\351");
	            });
	        },
	        dataType: "json"
	    });
    }
}

function checkMDP() {
    //<input onkeyup="this.value=this.value.replace(/[^a-zA-Z0-9]/ig, '');checkMDP()" class="field1" id="insc_mdp2" name="insc_mdp2" value="<?PHP echo $mdp; ?>" maxlength="32" size="30" type="text" />
    var mdp = document.getElementById('insc_mdp').value;
    var mdp2 = document.getElementById('insc_mdp2').value;
    //this.value = this.value.replace(/[^a-zA-Z0-9]/ig, '');
    var reg = /[^a-zA-Z0-9]/ig;
    if (reg.test(mdp)) {
        document.getElementById('insc_mdp').style.backgroundColor = '#FF9900'
        document.getElementById("btnValidation").className = "tumevoispas"
        document.getElementById("checkMDP_msg").className = "tumevois"
        document.getElementById('checkMDP_msg').innerHTML = "Les symboles ne sont pas autoris\351s";
        return false;
    } else {
        document.getElementById('insc_mdp').style.backgroundColor = '#FFFFFF'
        document.getElementById("checkMDP_msg").className = "tumevoispas"
    }
    if (reg.test(mdp2)) {
        document.getElementById('insc_mdp2').style.backgroundColor = '#FF9900'
        document.getElementById("btnValidation").className = "tumevoispas"
        document.getElementById("checkMDP_msg2").className = "tumevois"
        document.getElementById('checkMDP_msg2').innerHTML = "Les symboles ne sont pas autoris\351s";
        return false;
    } else {
        document.getElementById('insc_mdp2').style.backgroundColor = '#FFFFFF'
        document.getElementById("checkMDP_msg").className = "tumevoispas"
    }
/*
    var exp = new RegExp(mdp, /[^a-zA-Z0-9]/ig);
    if (exp)
    {

		alert("MDP");
    }
    */
    if (mdp == '' || mdp.length < 5) {
        document.getElementById('insc_mdp').style.backgroundColor = '#FF9900'
        document.getElementById("btnValidation").className = "tumevoispas"
        document.getElementById("checkMDP_msg").className = "tumevois"
        document.getElementById('checkMDP_msg').innerHTML = "5 caract\350res minimum";
    } else {
        document.getElementById('insc_mdp').style.backgroundColor = '#FFFFFF'
        document.getElementById("checkMDP_msg").className = "tumevoispas"
    }
    if (mdp2 == '' || mdp.length < 5 || mdp != mdp2) {
        document.getElementById('insc_mdp2').style.backgroundColor = '#FF9900'
        document.getElementById("btnValidation").className = "tumevoispas"
        document.getElementById("checkMDP_msg2").className = "tumevois"
        document.getElementById('checkMDP_msg2').innerHTML = "5 caractères minimum";
    } else {
        document.getElementById('insc_mdp2').style.backgroundColor = '#FFFFFF'
        document.getElementById("btnValidation").className = "tumevois"
        document.getElementById("checkMDP_msg2").className = "tumevoispas"
    }
    if (mdp2 != mdp) {
        document.getElementById('insc_mdp2').style.backgroundColor = '#FF9900'
        document.getElementById("btnValidation").className = "tumevoispas"
        document.getElementById("checkMDP_msg2").className = "tumevois"
        document.getElementById('checkMDP_msg2').innerHTML = "Votre mot de passe est diff\351rent de votre mot de passe (confirmation).";
    } else {
        document.getElementById('insc_mdp2').style.backgroundColor = '#FFFFFF'
        document.getElementById("btnValidation").className = "tumevois"
        document.getElementById("checkMDP_msg2").className = "tumevoispas"
    }
}

function checkEmailInscription() {
    var email = document.getElementById('insc_email').value;
    if (email == '' || !verifEmail(email)) {
        //alert("L'adresse E-mail est invalide");
        document.getElementById('insc_email').style.backgroundColor = '#FF9900'
        document.getElementById("btnValidation").className = "tumevoispas"
        document.getElementById("champMDP").className = "tumevoispas"
        document.getElementById("champMDP2").className = "tumevoispas"
        //document.getElementById("btnValidation").className="tumevoispas"
        document.getElementById("cgvWAM").className = "tumevoispas"
        document.getElementById("divCheckEmail").className = "tumevois"
        document.getElementById('divCheckEmail').innerHTML = "votre e-mail semble ne pas \352tre saisie correctement.";
        document.getElementById('insc_mdp').value = '';
        document.getElementById('insc_mdp2').value = '';
        return false;
    } else {
        //alert(email);
        document.getElementById('insc_email').style.backgroundColor = '#FFFFFF'
        document.getElementById("divCheckEmail").className = "tumevoispas"
        var url = 'async.php?generic=checkEmailInscription' + '&email=' + escape(email);
        loadMulti(url + "|checkEmail_status");
    }
}

function inscription() {
    var typeInscription = document.getElementById('typeInscription').value;
    var email = document.getElementById('insc_email').value;
    var mdp = document.getElementById('insc_mdp').value;
    switch (typeInscription) {
    case 'preInscription':
        var mdp2 = document.getElementById('insc_mdp2').value;
        if (mdp == '') {
            alert("Mot de passe requis");
            return false;
        }
        if (mdp2 == '') {
            alert("Confirmation du mot de passe requis");
            return false;
        }
        var ifChecked = document.getElementById('check_condition').checked;
        if (!ifChecked) {
            alert("Vous devez accepter les conditions g\351n\351rales d'utilisation du site");
            return false;
        }
        if (email == '' || !verifEmail(email)) {
            alert("L'adresse E-mail est invalide");
            return false;
        }
        if (mdp != mdp2) {
            alert("Votre mot de passe est diff\351rent de votre mot de passe (confirmation).");
            return false;
        }
        if (mdp.length < 5) {
            alert("Veuillez choisir un mot de passe d'un minimum de 5 caract\350res");
            return false;
        }
        if (mdp2.length < 5) {
            alert("Veuillez choisir un mot de passe d'un minimum de 5 caract\350res");
            return false;
        }
        var url = 'validation_inscription.php' + '?email=' + escape(email) + '&mdp=' + escape(mdp);
        call_cbox(url, "Confirmation de l'inscription");
        break;
    case 'ConfirmInscription':
        var url = 'async.php?generic=confirmInscription' + '&email=' + escape(email) + '&mdp=' + escape(mdp);
        loadMulti(url + "|div_status");
        break;
    }
}

function resendMdp(go) {
    var email = document.getElementById('rsendMdp_mail').value;
    if (email == '' || !verifEmail(email)) {
        //alert(email)
        //alert("L'adresse E-mail est invalide");
        document.getElementById('rsendMdp_mail').style.backgroundColor = '#FF9900'
    } else {
        document.getElementById('rsendMdp_mail').style.backgroundColor = '#FFFFFF'
    }
    if (email != '' && go == 1) {
        var url = 'async.php?generic=rsendMdp_mail' + '&email=' + escape(email);
        loadMulti(url + "|id_resendMdp");
    }
}

function connexion() {
    var login = document.getElementById('login').value;
    var password = document.getElementById('password').value;
    var err = 0;

    if (login == '') {
        document.getElementById('div_login_status_email').style.color = '#FF0000';
        var err = 1;
    }

    if (password == '') {
        document.getElementById('div_login_status_password').style.color = '#FF0000';
        var err = 1;
    }

    if (err != 0) return false;

    var destination = document.getElementById('destinationAfterConnexion').value;
    var ifChecked = document.getElementById('rememberme').checked;
    if (!ifChecked) {
        var rememberme = 0;
    } else {
        var rememberme = 1;
    }
    if (password != '' && login != '') {
        var url = 'async.php?generic=connexion' + '&login=' + escape(login) + '&password=' + escape(password) + '&rememberme=' + escape(rememberme) + '&destination=' + escape(destination)
        loadMulti(url + "|div_status");
    }
}

function getXhr() {
    if (window.XMLHttpRequest) xhr = new XMLHttpRequest();
    else if (window.ActiveXObject) {
        try {
            xhr = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            xhr = new ActiveXObject("Microsoft.XMLHTTP");
        }
    } else {
        alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest, veuillez le mettre à jour");
        xhr = false;
    }
}

function ajout_annonce_check(etape) {
/*
if (empty($nom)) $nom = 'Nom';
if (empty($prenom)) $prenom = "Pr&eacute;nom";
if (empty($tel)) $tel = "T&eacute;l&eacute;phone Fixe";
if (empty($email)) $email = "Email";
if (empty($gsm)) $gsm = "GSM / Mobilis";

*/
    var msg_profil = '\n\r Votre profil : \n\r---------------------\n\r';
    var nom = '';
    var prenom = '';
    var tel = '';
    var gsm = '';
    var email = '';
    var cb_nom = document.getElementById('cb_nom').checked;
    if (cb_nom) var nom = document.getElementById('nom').value;

	if (nom == 'Nom') {
        var nom = '';
        msg_profil = msg_profil + '- Nom \n\r';
    }
    var cb_prenom = document.getElementById('cb_prenom').checked;
    if (cb_prenom) var prenom = document.getElementById('prenom').value;
    if (prenom == 'Prénom') {
        var prenom = '';
        msg_profil = msg_profil + '- Prénom \n\r';
    }
    var cb_tel = document.getElementById('cb_tel').checked;
    if (cb_tel) var tel = document.getElementById('tel').value;
    if (tel == 'Téléphone Fixe') {
        var tel = '';
        msg_profil = msg_profil + '- Téléphone Fixe \n\r';
    }
    var cb_gsm = document.getElementById('cb_gsm').checked;
    if (cb_gsm) var gsm = document.getElementById('gsm').value;
    if (gsm == 'GSM / Mobilis') {
        var gsm = '';
        msg_profil = msg_profil + '- GSM / Mobilis \n\r';
    }
    var cb_email = document.getElementById('cb_email').checked;
    if (cb_email) var email = document.getElementById('email').value;
    if (email == 'Email') {
        var email = '';
        msg_profil = msg_profil + '- Email \n\r';
    }
    ajout_annonce_texte = $('#ajout_annonce_texte').val();
    ajout_annonce_texte = strip_tags(ajout_annonce_texte);

    var id_annonce_modif = document.getElementById('id_annonce_modif').value;
    var source_annonce = document.getElementById('source').value;
    var ajout_annonce_prix = document.getElementById('ajout_annonce_prix').value;
    //var ajout_annonce_texte = document.getElementById('ajout_annonce_texte').value;
    //var ajout_annonce_texte = rawurlencode(ajout_annonce_texte);
    var ajout_annonce_titre = document.getElementById('ajout_annonce_titre').value;
    var ajout_annonce_type_annonces = document.getElementById('ajout_annonce_type_annonces').value;
    var ajout_annonce_categorie = document.getElementById('ajout_annonce_categorie').value;

    var msg = 'Veuillez d\351finir : \n\r---------------------\n\r';
    if (ajout_annonce_categorie == '') msg = msg + '- Une cat\351gorie \n\r';
    if (ajout_annonce_titre == '') msg = msg + '- Un titre \n\r';
    if (ajout_annonce_type_annonces == 0) msg = msg + '- Un type (Offre,Demande, ...) \n\r';
    if (ajout_annonce_texte == '') msg = msg + '- Un texte pour votre annonce \n\r';
    if (!form_input_is_numeric(ajout_annonce_prix)) msg = msg + '\r\n Le prix doit \352tre numérique, saisissez uniquement des chiffres \n\r';
    if (msg_profil == '\n\r Votre profil : \n\r---------------------\n\r') {
        msg_profil = '';
    } else {
        msg = msg + msg_profil;
    }
    if (msg != 'Veuillez d\351finir : \n\r---------------------\n\r') {
        alert(msg);
        return false;
    }

    var divDest = "header_annonce_" + id_annonce_modif;

    var url = 'async_annonces.php?generic=ajout_annonce&viaPost=1&' + '&id_annonce=' + escape(id_annonce_modif) + '&source=' + source_annonce + '&id_categorie=' + escape(ajout_annonce_categorie) + '&id_type_annonces=' + escape(ajout_annonce_type_annonces) + '&titre=' + escape(ajout_annonce_titre) + '&prix=' + escape(ajout_annonce_prix) + '&nom=' + escape(nom) + '&prenom=' + escape(prenom) + '&gsm=' + escape(gsm) + '&tel=' + escape(tel) + '&etape=' + escape(etape) + '&email=' + escape(email) + '&texte=' + escape(ajout_annonce_texte);
    //lienXHR(url,divDest);
/*
xhr.onreadystatechange = function () {
    if (xhr.readyState == 4 && xhr.status == 200) {
        //document.getElementById(url).innerHTML = xhr.responseText;
        lienXHR("async_annonces.php?generic=detail_annonce&id=" + id_annonce_modif + "&id_cat=" + ajout_annonce_categorie, divDest);
    }
}

xhr.open("POST", 'async_annonces.php?generic=ajout_annonce', true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.send(url)
*/

/*
switch (etape) {
case 'etape_3':
    var url = "ajout_annonce_etape_3.php?id_annonce=" + id_annonce_modif;
    call_cbox(url, 'ETAPE 3', 620, 512, false)
    break;
}*/
}

function getF() {
    s = $(contact).serialize();
    $.ajax({
        type: "POST",
        data: s,
        url: $(this).attr("action"),
        success: function (retour) {
            $("#recipient").empty().append(retour);
        }
    });
    return false;
}

function del_idAnnonce_selection_annonce() {
    var url = 'async_annonces.php?generic=del_idAnnonce_selection_annonce' + '&id=' + escape(id);
    loadMulti(url + "|div_status");
}

function show_annonce_parPage(lien) {
    $(document).ready(function () {
        var form_par_page = document.getElementById('form_par_page').value;
        url = lien + '&form_par_page=' + form_par_page;
        //alert(url);
        lienXHR(url, 'div_centre_0');
    });
}
