function monAjax(url, data, dest) {
    $.ajax({
        type: 'POST',
        url: url,
        data: data,
        success: function(msg)
        {
            $(dest).html(msg);
        }
    });
}

// retourne un objet xmlHttpRequest.
// méthode compatible entre tous les navigateurs (IE/Firefox/Opera)
function getXMLHTTP()
{
    var xhr = null;
    if(window.XMLHttpRequest)
    { // Firefox et autres
        xhr = new XMLHttpRequest();
    }
    else if(window.ActiveXObject)
    { // Internet Explorer
        try
        {
            xhr = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(e)
        {
            try
            {
                xhr = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch(e1)
            {
                xhr = null;
            }
        }
    }
    else
    { // XMLHttpRequest non supporté par le navigateur
        alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
    }

    return xhr;
}



// INSCRIPTION
// Vérification Javascript
function verif_pseudo (a, mini, maxi) {
    if (longueur(a, mini, maxi, 'l'+a.id))
        monAjax('http://www.plancul.fr/ajax/pseudo.php?valeur='+a.value,$("#label-pseudo :input").serialize(),'#label-pseudo');
    else
        fermer('label-pseudo');
}

function verif_mail (a) {
    if (is_mail(a, 'l'+a.id))
        monAjax('http://www.plancul.fr/ajax/mail.php?valeur='+a.value,$("#label-mail :input").serialize(),'#label-mail');
    else
        fermer('label-mail');
}

function ecrire_ville (a) {
    if (longueur(a, 5, 5, 'lpostal'))
        monAjax('http://www.plancul.fr/ajax/ville.php?valeur='+a.value,$("#ville :input").serialize(),'#ville');
    else {
        document.form.ville.options.length = 0;
        document.form.ville.options[0]=new Option('...', 0);
    }
}

function confirmation_psw(a, b, l, mini, maxi) {
    if (longueur(a, mini, maxi, l)) {
        psw = document.getElementById(b);
        if (psw.value != a.value) {
            rouge(a);
            rouge(document.getElementById(l));
        } else {
            noir(a);
            gris(document.getElementById(l));
        }
    } else {
        rouge(a);
        rouge(document.getElementById(l));
    }
}

// Fonctions
function longueur(a, mini, maxi, b) {
    if(a.value.lastIndexOf(" ") != -1 || a.value.length < mini || a.value.length > maxi) {
        rouge(a);
        rouge(document.getElementById(b));
        return false;
    } else {
        noir(a);
        gris(document.getElementById(b));
        return true;
    }
}

function vider(a, txt) {
    if (a.value == txt)
        a.value = "";
}

function remplir(a, txt) {
    if (a.value == "")
        a.value = txt;
}

function is_numeric(a) {
    num = a.value.replace('.',',');
    if(isNaN(num)) {
        rouge(a);
    } else {
        noir(a);
    }
}

function is_mail(a, b) {
    if (a.value.lastIndexOf(" ") != -1 || a.value.indexOf('@') == -1 || a.value.indexOf('.') == -1) {
        rouge(a);
        rouge(document.getElementById(b));
        return false;
    } else {
        noir(a);
        gris(document.getElementById(b));
        return true;
    }
}

// Changement de couleur de l'élément
function rouge(a) {
    a.style.color = '#FF0000';
    a.style.fontStyle = 'normal';
}

function noir(a) {
    a.style.color = '#444444';
    a.style.fontStyle = 'normal';
}

function gris(a) {
    a.style.color = '#444444';
    a.style.fontStyle = 'normal';
}

// Mise a jour d'une liste déroulante
function modif_jour(a) {
    if (a.value == 2) {
        document.form.jour.options.length = 30;
    } else {
        if (a.value == 4 || a.value == 6 || a.value == 9 || a.value == 11) {
            j = 31;
        } else {
            j = 32;
        }
        i=document.form.jour.options.length;
        document.form.jour.options.length = j;
        while (i<j) {
            document.form.jour.options[i]=new Option(i, i);
            i++;
        }
    }
}

function postal(a) {
    if (a.value.length == 5)
        ecrire_ville(a);
}

function confirmer(){
    mail = document.getElementById('mail').value;
    if(mail == "")
        return true;
    texte = 'Attention, un e-mail de confirmation va vous être envoyé à l\'adresse "'+mail+'"\n\rMerci de la valider ou de la corriger';
    return confirm(texte);
}

function ouvre_popup(page) {
    window.open(page,"cgu","menubar=no, status=no, scrollbars=yes, menubar=no, width=500, height=500");
}


function mailing_journalier(){
    $("#div-modification").load('http://www.plancul.fr/ajax/batches/mailing_journalier.php');
}

function batches(){
    $("#gauche").load("http://www.plancul.fr/batches/email.php");
}

function debloquer(profil, pseudo, source){
    $("#div-infos").load('http://www.plancul.fr/ajax/actions/debloquer.php?profil='+profil+'&pseudo='+pseudo+'&source='+source);
}

function envoyer_message(limit, id, pseudo, form) {
    switch(form){
        case "form_chat_profil":
            form = "form_chat_profil";
            div = "form_chat_profil";
            source = "profil_moyen";
            break;
            
        default:
            form = "form-chat";
            div = "div-chat";
            source = "site";
            break;
    }
    monAjax('http://www.plancul.fr/ajax/chat/messages.php?limit='+limit+'&profil='+id+'&pseudo='+pseudo+'&source='+source, $("#"+form+" :input").serialize(), '#'+div);
}

function fermer(div){
    switch(div){
        case "div-profil":
            if(isset('sTProfil')){
                clearTimeout(sTProfil);
            }
            document.getElementById('body').style.overflow = 'auto';
            break;
    }
    document.getElementById(div).innerHTML = "";
}

function page_href(){
    if(document.getElementById('div-chats').innerHTML != ''){
        document.location.href = "#div-centre";
    }
}

function filtre_copie() {
    document.getElementById('limit_mg').value = "0_0";
    document.getElementById('search_charge').style.display = 'block';
    monAjax('http://www.plancul.fr/ajax/menu/gauche.php',$("#div-filtre :input").serialize(),'#div-mg');
}

function filtre(min, max) {
	if(!isset(min)){
		min = 0;
	}
	if(!isset(max)){
		max = 0;
	}
    document.getElementById('limit_mg').value = min+"_"+max;
    document.getElementById('search_charge').style.display = 'block';
    monAjax('http://www.plancul.fr/ajax/menu/gauche.php',$("#div-filtre :input").serialize(),'#div-mg');
}

//Objet XMLHTTPRequest
var XHR = null;

function filtre_age() {
	if(XHR && XHR.readyState != 0){
		XHR.abort();
		delete XHR;
	}
	XHR = getXMLHTTP();
	if(!XHR){
		return false;
	}
	age_mini = document.getElementById('age_mini').options[document.getElementById('age_mini').selectedIndex].value;
	age_maxi = document.getElementById('age_maxi').options[document.getElementById('age_maxi').selectedIndex].value;
	XHR.open("POST", "../ajax/actions/enregistre_recherche.php?id_membre=&age_mini="+age_mini+"&age_maxi="+age_maxi, true);
	XHR.send(null);
	
    document.getElementById('limit_mg').value = "0_0";
    monAjax('http://www.plancul.fr/ajax/menu/gauche.php',$("#div-filtre :input").serialize(),'#div-mg');
}

function supprimer_chat(id, messages){
    $("#div-chat").load('http://www.plancul.fr/ajax/chat/messages.php?supprimer&limit&profil='+id+'&id_message='+messages);
}

function preference_messages_envoyes(rep){
    masquer_envoye = '?masquer_envoye=';
    switch(rep){
        case "afficher":
            masquer_envoye += '0';
            break

        case "masquer":
            masquer_envoye += '1';
            break

        default:
            masquer_envoye = '';
            break
    }
    $("#p-chats").load('http://www.plancul.fr/ajax/menu/mes_chats.php'+masquer_envoye);
}

function age_mini_mg() {
    age_mini = document.getElementById('age_mini');
    age_maxi = document.getElementById('age_maxi');

    i = age_mini.length;
    age_mini.length = age_maxi.value-17;
    j = age_mini.length;
    while (i<=j) {
        age_mini.options[i]=new Option(17+i, 17+i);
        i++;
    }
    if (age_mini.length==45)
        age_mini.length=44;
}

function age_maxi_mg() {
    age_mini = document.getElementById('age_mini');
    age_maxi = document.getElementById('age_maxi');
    ok = false;
    i=0;
    if (age_maxi.length>(62-age_mini.value)) {
        while (!ok) {
            if (age_maxi.options[i].value < age_mini.value) {
                age_maxi.options[i] = null;
                i--;
            }
            i++;
            ok = (i==age_maxi.length);
        }
    }
    else if (age_maxi.length<(62-age_mini.value)) {
        sel = age_maxi.value;
        age_maxi.length = 0;
        for (i=0; i<61-age_mini.value; i++) {
            val = parseInt(age_mini.value) + parseInt(i);
            age_maxi.options[i]=new Option(val, val);
            if (sel == age_maxi.options[i].value)
                age_maxi.options[i].selected = true;
        }
        age_maxi.options[i]=new Option("+ 60", 61);
        if (sel == age_maxi.options[i].value)
            age_maxi.options[i].selected = true;
    }
}

function page_recherche(rubrique){
    $("#div-centre").load('http://www.plancul.fr/ajax/centre/recherche/recherche.php?ajax=1&rubrique='+rubrique);
    page_href();
}

function page_dernier_inscrit(){
    $("#div-centre").load('http://www.plancul.fr/ajax/centre/derniers_inscrits.php?ajax=1');
}

function page_contacts(rubrique){
    $("#div-centre").load('http://www.plancul.fr/ajax/centre/contacts/contacts.php?rubrique='+rubrique);
    page_href();
}

function page_messagerie(rubrique, type){
    mailbox(type, '');
    page_href();
}

function page_agenda(rubrique){
    $("#div-centre").load('http://www.plancul.fr/ajax/centre/agenda/agenda.php?rubrique='+rubrique);
    page_href();
}

function page_videos(rubrique){
    //$("#div-centre").load('http://www.plancul.fr/ajax/videos.php');
    page_href();
}

function page_sexe(rubrique, type){
    switch(rubrique){
        case "histoires":
            $("#div-centre").load('http://www.plancul.fr/ajax/centre/histoires/histoires.php?rubrique='+type);
            break;
    }
    page_href();
}

function page_consultation(rubrique){
    $("#div-centre").load('http://www.plancul.fr/ajax/centre/consultations.php');
}

function page_compte(rubrique){
    $("#div-centre").load('http://www.plancul.fr/ajax/centre/compte/compte.php?rubrique='+rubrique);
    page_href();
}

function page_preference(rubrique){
    //$("#div-centre").load('http://www.plancul.fr/ajax/preferences.php?rubrique='+rubrique);
}

function page_faq(rubrique){
    $("#div-centre").load('http://www.plancul.fr/ajax/centre/forum/forum.php?rubrique='+rubrique);
    page_href();
}

function page_plans_cul(rubrique, sous_rubrique){
    $("#div-centre").load('http://www.plancul.fr/ajax/centre/plancul/plancul.php?rubrique='+rubrique+'&sous_rubrique='+sous_rubrique);
    page_href();
}

function page_parrainage(rubrique){
    $("#div-centre").load('http://www.plancul.fr/ajax/centre/parrainage/parrainage.php?rubrique='+rubrique);
    page_href();
}

function page_video(){
    $("#div-centre").load('http://www.plancul.fr/ajax/centre/video.php');
    page_href();
}



function etoile_over(nb, id) {

    for(i=1; i<=nb; i++) {
        nom = 'E'+i+'_'+id;
        change_image_name(nom, 'etoile.png');
    }
    for(i=3; i>nb; i--) {
        nom = 'E'+i+'_'+id;
        change_image_name(nom, 'etoile_off.png');
    }
}

function classe_send(note, profil, pseudo, mobile, complet) {
    if( mobile != 0 ){
        mobile = "false";
    }
    vote = document.getElementById('l-votes_'+pseudo).innerHTML;
    ancien = document.getElementById('defaut_etoile_'+profil).value;

    if (note==ancien){
        val = parseInt(vote)-parseInt(note);
    } else {
        val = parseInt(vote)+parseInt(note)-parseInt(ancien);
    }
    document.getElementById('l-votes_'+pseudo).innerHTML = val;
    etoile_click(note, profil, pseudo, ancien, mobile, complet);
}

function classe_send2(x, y, z, complet) {
    ancien = document.getElementById('defaut_etoile_'+y).value;
    etoile_click2(x, y, z, ancien, '0', complet);
}

function etoile_click(nb, profil, pseudo, ancien, mobile, complet) {
    if( mobile != 0 ){
        mobile = "false";
    }
    if (document.getElementById('defaut_etoile_'+profil).value == nb) {
        nb = 0;
    }
    etoile_over(nb);
    document.getElementById('defaut_etoile_'+profil).value = nb;
    var ele = $('.etoile'+profil);
    if( complet == 1 ){
    	if(ele.css('display') == "none") {
    		ele.css('display','block');
  		}	
        $(".etoile"+profil).load('http://moi.plancul.fr/ajax/reponses/classe.php?bMobile='+mobile+'&profil='+profil+'&classe='+nb+'&pseudo='+pseudo+'&ancien='+ancien+'&bComplet='+complet);
    } else {
    	if(ele.css('display') == "none") {
    		ele.css('display','block');
  		}
        $(".etoile"+profil).load('http://www.plancul.fr/ajax/reponses/classe.php?bMobile='+mobile+'&profil='+profil+'&classe='+nb+'&pseudo='+pseudo+'&ancien='+ancien+'&bComplet='+complet);
    }

    ele.css('display','block');
}

function etoile_click2(nb, profil, pseudo, ancien) {
    if (document.getElementById('defaut_etoile_'+profil).value == nb) {
        etoile_over2(0, profil);
        document.getElementById('defaut_etoile_'+profil).value = 0;
        $("#div-news").load('http://www.plancul.fr/ajax/reponses/classe.php?profil='+profil+'&classe=0&pseudo='+pseudo+'&ancien='+ancien);
    } else {
        etoile_over2(nb, profil);
        document.getElementById('defaut_etoile_'+profil).value = nb;
        $("#div-news").load('http://www.plancul.fr/ajax/reponses/classe.php?profil='+profil+'&classe='+nb+'&pseudo='+pseudo+'&ancien='+ancien);
    }
}

function change_image_name(nom, img){
    aEtoiles = document.getElementsByName(nom);
    iEtoiles = aEtoiles.length;

    for(ind=0; ind<iEtoiles; ind++){
        aEtoiles[ind].src = "http://www.plancul.fr/pictures/"+img;
    }
}

function etoile_over2(nb, id) {
    for(i=1; i<=nb; i++) {
        nom = 'E_'+id+'_'+i;
        change_image_name(nom, 'etoile.png');
    }
    for(i=3; i>nb; i--) {
        nom = 'E_'+id+'_'+i;
        change_image_name(nom, 'etoile_off.png');
    }
}

function etoile_out2(id) {
    etoile_over2(document.getElementById('defaut_etoile_'+id).value, id);
}
function etoile_out(id) {
    etoile_over(document.getElementById('defaut_etoile_'+id).value, id);
}
function chatter(id, complet) {
    switch(complet){
        case true:
        case 1:
            $("#div-chats").load('http://www.plancul.fr/ajax/chat/chat.php?complet=true&profil='+id);
            break;

        default:
            $("#div-chats").load('http://www.plancul.fr/ajax/chat/chat.php?profil='+id);
            break;
    }
}
function chatter2(id, div) {
    $("#"+div).load('http://www.plancul.fr/ajax/mailbox_chat.php?profil='+id);
}





function affiche_favori_ajout(profil, pseudo){
    $("#div-infos").load('http://www.plancul.fr/ajax/actions/ajout_favoris.php?profil='+profil+'&pseudo='+pseudo+'&news=1');
}






function affiche_profil_restreint(profil, demande, tab){
	lien="";
	switch(typeof(tab)){
        case "undefined":
            break;
        default:
            lien += "&tab="+tab;
            break;
    }
    switch(typeof(demande)){
        case "undefined":
            $("#div-profil").load('http://www.plancul.fr/ajax/profil_moyen/display.php?profil='+profil+lien);
            break;
        default:
            $("#div-profil").load('http://www.plancul.fr/ajax/profil_moyen/display.php?profil='+profil+'&demande='+demande+lien);
            break;
    }
}
function afficheValidationCommentaire(x){
    $("#div-centre").load('http://www.plancul.fr/ajax/actions/commentaire.php?id_com='+x);
}
function body_longueur(element, maxi, mini) {
    if(element.value == "") {
        element.style.color = '#000000';
        document.getElementById('nb_car_area').innerHTML = maxi+" caractères maximum";
        document.getElementById('nb_car_area').style.color = '#444444';
    } else {
        if(element.value.length > maxi) {
            texte = element.value.length-maxi;
            if(element.value.length-maxi > 1)
                texte += " caractères de trop";
            else
                texte += " caractère de trop";

            element.style.color = '#FF0000';
            document.getElementById('nb_car_area').innerHTML = texte;
            document.getElementById('nb_car_area').style.color = '#FF0000';
        } else {
            texte = maxi-element.value.length;
            if(maxi-element.value.length > 1)
                texte += " caractères restants";
            else
                texte += " caractère restant";

            element.style.color = '#000000';
            document.getElementById('nb_car_area').innerHTML = texte;
            document.getElementById('nb_car_area').style.color = '#444444';
        }
    }
}
function news() {
    $("#div-infos").load('http://www.plancul.fr/ajax/news.php');
}
function news2(x) {
    monAjax('http://www.plancul.fr/ajax/news.php?id_news='+x,$("#div-infos :input").serialize(),'#div-infos');
}
function fermer_nous_contacter() {
    document.getElementById('div-contacter').innerHTML = "";
}

function ajout_pc(id, pseudo, express, mobile, complet) {
    if( mobile != 1 ){
        mobile = "false";
    }
    if(isset('sT')){
        clearTimeout(sT);
    }
    
    document.getElementById('div-demande').style.display = 'block';

    if( complet == 1 ){
        $("#div-demande").load('http://moi.plancul.fr/ajax/actions/ajout_plancul.php?bMobile='+mobile+'&profil='+id+'&pseudo='+pseudo+'&express='+express+'&bComplet='+complet);
    } else {
        $("#div-demande").load('http://www.plancul.fr/ajax/actions/ajout_plancul.php?bMobile='+mobile+'&profil='+id+'&pseudo='+pseudo+'&express='+express+'&bComplet='+complet);
    }

}
function envoyer_mail(id, pseudo, discussion){
    if (discussion == 0)
        $("#div-centre").load('http://www.plancul.fr/ajax/message_envoi.php?pseudo='+pseudo);
    else if (id != 0)
        $("#div-centre").load('http://www.plancul.fr/ajax/mail_display.php?profil='+id);
    else
        $("#div-centre").load('http://www.plancul.fr/ajax/mail_display.php?discussion='+discussion);
}
function mailbox(type, pseudo) {
    switch(type){
        case "tous":
        case "envoyes":
        case "ecrire":
            post = type;
            break;
        default:
            post = 'recus';
            break;
    }
    if(pseudo != "") {
        post += "&pseudo="+pseudo;
    }
    $("#div-centre").load('http://www.plancul.fr/ajax/centre/messages/messages.php?rubrique='+post);
}
function ajout_amis(id, pseudo, mobile, complet) {
    if( mobile != 1 ){
        mobile = "false";
    }
    if(isset('sT')){
        clearTimeout(sT);
    }
    lien_amis('ok', id, pseudo, mobile, complet);
    document.getElementById('div-demande').style.display = 'block';
    if(complet == 1){
        $("#div-demande").load('http://moi.plancul.fr/ajax/actions/ajout_ami.php?bMobile='+mobile+'&profil='+id+'&pseudo='+pseudo+'&bComplet='+complet);
    } else {
        $("#div-demande").load('http://www.plancul.fr/ajax/actions/ajout_ami.php?bMobile='+mobile+'&profil='+id+'&pseudo='+pseudo+'&bComplet='+complet);
    }
}
function retirer_amis(id, pseudo, mobile, complet) {
    if( mobile != 1 ){
        mobile = "false";
    }
    if(isset('sT')){
        clearTimeout(sT);
    }
    lien_amis('annul', id, pseudo, mobile, complet);
    document.getElementById('div-demande').style.display = 'block';
    if(complet == 1){
        $("#div-demande").load('http://moi.plancul.fr/ajax/actions/ajout_ami.php?bMobile='+mobile+'&profil='+id+'&pseudo='+pseudo+'&bComplet='+complet+'&type=annul');
    } else {
        $("#div-demande").load('http://www.plancul.fr/ajax/actions/ajout_ami.php?bMobile='+mobile+'&profil='+id+'&pseudo='+pseudo+'&bComplet='+complet+'&type=annul');
    }
}

function lien_amis(type, id, pseudo, mobile, complet){

	image_ajout_amis = '<a onclick="ajout_amis('+id+', \''+pseudo+'\', \''+mobile+'\', \''+complet+'\')" href="javascript:;" title="Lui demander de faire partie de vos Amis !"><img title="Lui demander de faire partie de vos Amis !" alt="Lui demander de faire partie de vos Amis !" src="http://www.plancul.fr/pictures/amis.png"></a>';
	lien_ajout_amis = '<a onclick="ajout_amis('+id+', \''+pseudo+'\', \''+mobile+'\', \''+complet+'\')" href="javascript:;" title="Lui demander de faire partie de vos Amis !">Ajouter à mes amis</a>';
	
	image_retire_amis = '<a onclick="retirer_amis('+id+', \''+pseudo+'\', \''+mobile+'\', \''+complet+'\')" href="javascript:;" title="Le retirer de ma liste d\'amis !"><img title="Le retirer de ma liste d\'amis !" alt="Le retirer de ma liste d\'amis !" src="http://www.plancul.fr/pictures/non_amis.png"></a>';
	lien_retire_amis = '<a onclick="retirer_amis('+id+', \''+pseudo+'\', \''+mobile+'\', \''+complet+'\')" href="javascript:;" title="Le retirer de ma liste d\'amis !">Retirer de mes amis</a>';
	if(type == 'annul'){
			$('td#pm_amis_membre_img').html('');
			$('td#pm_amis_membre').html('');
			$('td#pm_amis_membre_img').html(image_ajout_amis);
			$('td#pm_amis_membre').html(lien_ajout_amis);
	}else if(type == 'ok'){
			$('td#pm_amis_membre_img').html('');
			$('td#pm_amis_membre').html('');
			$('td#pm_amis_membre_img').html(image_retire_amis);
			$('td#pm_amis_membre').html(lien_retire_amis);
	}
}

function autoriser_album_prive(id, pseudo, mobile, complet) {
	if( confirm("Etes vous certain de vouloir autoriser "+pseudo+" à voir votre album privé?") ){
		lien_album('ok', id, pseudo, mobile, complet);
		if( mobile != 1 ){
			mobile = "false";
			if( isset('sT') ){
				clearTimeout(sT);
			}
		}
		if( complet == 1 ){
			$("#div-demande").load('http://moi.plancul.fr/ajax/actions/autoriser_album_prive.php?bMobile='+mobile+'&profil='+id+'&pseudo='+pseudo+'&bComplet='+complet);
		} else {
			$("#div-demande").load('http://www.plancul.fr/ajax/actions/autoriser_album_prive.php?bMobile='+mobile+'&profil='+id+'&pseudo='+pseudo+'&bComplet='+complet);
		}
    }
}
function annuler_album_prive(id, pseudo, mobile, complet) {
	if( confirm("Etes vous certain de vouloir annuler l'autorisation de "+pseudo+" à voir votre album privé?") ){
		lien_album('annul', id, pseudo, mobile, complet);
		if( mobile != 1 ){
			mobile = "false";
			if( isset('sT') ){
				clearTimeout(sT);
			}
		}
		if( complet == 1 ){
			$("#div-demande").load('http://moi.plancul.fr/ajax/actions/autoriser_album_prive.php?bMobile='+mobile+'&profil='+id+'&pseudo='+pseudo+'&bComplet='+complet+'&type=annul');
		} else {
			$("#div-demande").load('http://www.plancul.fr/ajax/actions/autoriser_album_prive.php?bMobile='+mobile+'&profil='+id+'&pseudo='+pseudo+'&bComplet='+complet+'&type=annul');
		}
    }
}

function lien_album(type, id, pseudo, mobile, complet){

	image_autorise = '<a onclick="autoriser_album_prive('+id+', \''+pseudo+'\', \''+mobile+'\', \''+complet+'\')" href="javascript:;" title="Autoriser ce membre à accéder à votre album privé"><img title="Autoriser ce membre à accéder à votre album privé" alt="Autoriser ce membre à accéder à votre album privé" src="http://www.plancul.fr/pictures/icone_autoriser_albumprive.jpg"></a>';
	lien_autorise = '<a onclick="autoriser_album_prive('+id+', \''+pseudo+'\', \''+mobile+'\', \''+complet+'\')" href="javascript:;" title="Autoriser ce membre à accéder à votre album privé">Autorisation</a>';
	
	image_desautorise = '<a onclick="annuler_album_prive('+id+', \''+pseudo+'\', \''+mobile+'\', \''+complet+'\')" href="javascript:;" title="Annuler l\'autorisation ce membre à accéder à votre album privé"><img title="Annuler l\'autorisation de ce membre à accéder à votre album privé" alt="Annuler l\'autorisation de ce membre à accéder à votre album privé" src="http://www.plancul.fr/pictures/icone_desautoriser_albumprive.jpg"></a>';
	lien_desautorise = '<a onclick="annuler_album_prive('+id+', \''+pseudo+'\', \''+mobile+'\', \''+complet+'\')" href="javascript:;" title="Annuler l\'autorisation de ce membre à accéder à votre album privé">Retirer l\'autorisation</a>';
	if(type == 'annul'){
			$('td#pm-autorisation_membre_img').html('');
			$('td#pm-autorisation_membre').html('');
			$('td#pm-autorisation_membre_img').html(image_autorise);
			$('td#pm-autorisation_membre').html(lien_autorise);
	}else if(type == 'ok'){
			$('td#pm-autorisation_membre_img').html('');
			$('td#pm-autorisation_membre').html('');
			$('td#pm-autorisation_membre_img').html(image_desautorise);
			$('td#pm-autorisation_membre').html(lien_desautorise);
	}
}

function signaler(id, pseudo) {
    $("#div-profil").load('http://www.plancul.fr/ajax/actions/signaler.php?iIdMembre='+id+'&sPseudo='+pseudo);
    return true;
    $("#div-chats").load('http://www.plancul.fr/ajax/actions/signaler.php?iIdMembre='+id+'&sPseudo='+pseudo);
}
//Fonction appelée à l'envoi du formulaire de signalement
function signaler_envoi() {
	//Elsa : Ajout d'un condition sur la longueur du champs.
	valeur = $(".message_obligatoire").val();
	longueur = $(".message_obligatoire").attr('value').length;
	if((valeur!='')&&(longueur>15)){
		$(".error").html('');
		$(".error").css('display','none');
		monAjax('http://www.plancul.fr/ajax/actions/signaler.php', $("#div-profil :input").serialize(),"#div-profil");
    	return true;
    	monAjax('http://www.plancul.fr/ajax/actions/signaler.php', $("#div-chats :input").serialize(),"#div-chats");
	}else{
		$(".message_obligatoire").css('border','1px solid red');
		$(".error").css({'display':'block', 'float':'left','margin-left':'145px','width':'398px','padding':'5px','color':'red'});
		$(".error").html('Veuillez nous expliquer la raison de ce signalement.(Minimum 15 caractères)');
	}
}

function affiche_relation(id, complet){
    if( complet == "1" ){
        $("#div-demande").load('http://moi.plancul.fr/ajax/relations.php?id='+id);
    } else {
        $("#div-demande").load('http://www.plancul.fr/ajax/relations.php?id='+id);
    }
}

function bannir(id, pseudo, mobile, rep, complet) {
	a = document.getElementById('pm-bannis_membre');
    b = document.getElementById('pm-bannis_membre_img');
    switch(rep){
        case 0:
            var nRep = 1;
            
            var src = 'icone_bannir.png';
            var txt = 'Bannir ce membre';
            var title = "Bannir ce membre pour qu'il ne puisse plus me contacter";
            
            var confirmation = "Etes vous certain de vouloir debloquer "+pseudo+"?";
            var type = 'annul';
            break;
            
        case 1:
        default:
            var nRep = 0;
            
            var src = 'warning.png';
            var txt = 'Débloquer ce membre';
            var title = "Débloquer ce membre";
            var confirmation = "Etes vous certain de vouloir bloquer "+pseudo+"?";
            
            var type = '';
            break;
    }
    if( confirm(confirmation) ){
        if( mobile != 1 ){
            mobile = "false";
            if( isset('sT') ){
                clearTimeout(sT);
            }
        }
        var lien = '<a href="javascript:;" onclick="bannir(\''+id+'\', \''+pseudo+'\',\'\', '+nRep+')" title="'+title+'">';
   	 	b.innerHTML = lien+'<img id="pm-bannis_membre_img" src="http://www.plancul.fr/pictures/'+src+'" alt="'+title+'" title="'+title+'" /></a>';
    	a.innerHTML = lien+txt+'</a>';
    	
        if( complet == 1 ){
            $("#div-demande").load('http://moi.plancul.fr/ajax/actions/bannir.php?bMobile='+mobile+'&profil='+id+'&pseudo='+pseudo+'&bComplet='+complet+'&type='+type);
        } else {
            $("#div-demande").load('http://www.plancul.fr/ajax/actions/bannir.php?bMobile='+mobile+'&profil='+id+'&pseudo='+pseudo+'&bComplet='+complet+'&type='+type);
        }
    }
}

function alerteConnection(id, pseudo, sexe, rep, complet){
    a = document.getElementById('pm-alerte_membre');
    b = document.getElementById('pm-alerte_membre_img');
    switch(rep){
        case 0:
            var nRep = 1;
            var src = 'icone_alertes.png';
            var txt = 'Alerte e-mail inactive';
            var title = "Vous ne recevez pas d'e-mail quand cette personne se connecte. Cliquez pour activer l'alerte";
            break;
        case 1:
        default:
            var nRep = 0;
            var src = 'warning.png';
            var txt = 'Alerte e-mail activée';
            var title = "Vous recevez un e-mail quand cette personne se connecte. Cliquez pour désactiver l'alerte";
            break;
    }
    var lien = '<a href="javascript:;" onclick="alerteConnection(\''+id+'\', \''+pseudo+'\', \''+sexe+'\', '+nRep+')" title="'+title+'">';
    b.innerHTML = lien+'<img id="pm-alerte_membre_img" src="http://www.plancul.fr/pictures/'+src+'" alt="'+title+'" title="'+title+'" /></a>';
    a.innerHTML = lien+txt+'</a>';
    if(complet == 1){
        $("#div-demande").load('http://moi.plancul.fr/ajax/actions/alerte_connexion.php?profil='+id+'&pseudo='+pseudo+'&rep='+rep+'&sexe='+sexe+'&bComplet='+complet);
    } else {
        $("#div-demande").load('http://www.plancul.fr/ajax/actions/alerte_connexion.php?profil='+id+'&pseudo='+pseudo+'&rep='+rep+'&sexe='+sexe+'&bComplet='+complet);
    }
}
function afficher_photo(nom, photo, conteneur, num_photo) {
    document.getElementById('photo_actuelle').value = num_photo;
    change_source_image(photo, 'http://www.plancul.fr/photos/normal/'+nom);
    document.getElementById(conteneur).style.display = 'block';
}

function change_source_image(photo, source){
    document.images[photo].src = source;
}


function affiche_photo_compte(img, conteneur, nom){
    contenu  = '<div class="profil_moyen_grande_photo_action"><img onclick="fermer(\''+conteneur+'\')" src="http://www.plancul.fr/pictures/x_fonce.png" /></div>';
    contenu += '<img src="http://www.plancul.fr/photos/normal/'+nom+'" />';
    document.getElementById(conteneur).innerHTML = contenu;
}


function afficher_photo_precedent(){
    actuelle = document.getElementById('photo_actuelle').value;
    type_photo = document.getElementById('type_photos').value;
    tmp = document.getElementById(type_photo).value;
    photos = tmp.split('#');
    nb_photos = photos.length;
    if (actuelle == 0)
        actuelle = nb_photos - 1;
    else
        actuelle--;
    afficher_photo(photos[actuelle], 'photo_profil_moyen', 'profil_moyen_grande_photo', actuelle);
}

function afficher_photo_suivant(){
    actuelle = document.getElementById('photo_actuelle').value;
    type_photo = document.getElementById('type_photos').value;
    tmp = document.getElementById(type_photo).value;
    photos = tmp.split('#');
    nb_photos = photos.length;
    if (actuelle == (nb_photos - 1))
        actuelle = 0;
    else
        actuelle++;
    afficher_photo(photos[actuelle], 'photo_profil_moyen', 'profil_moyen_grande_photo', actuelle);
}





function fermer_photo(conteneur) {
    document.images["photo_profil_moyen"].src = '';
    document.getElementById(conteneur).style.display = 'none';
}
function invitation_partouze(id, pseudo, membre){
    if(isset('sT')){
        clearTimeout(sT);
    }
    $("#div-infos").load('http://www.plancul.fr/ajax/centre/invitation_partouze.php?pseudo='+pseudo+'&partouze='+id+'&membre='+membre);
}
function mes_partouzes(id, pseudo){
    $("#div-centre").load('http://www.plancul.fr/ajax/centre/partouzes.php?rubrique=organise&profil='+id+'&pseudo='+pseudo);
}
function mes_annonces(id, pseudo){
    $("#div-centre").load('http://www.plancul.fr/ajax/centre/annonces.php?rubrique=organise&profil='+id+'&pseudo='+pseudo);
}
function mes_commentaires(id, pseudo){
    $("#div-centre").load('http://www.plancul.fr/ajax/centre/commentaires.php?rubrique=organise&profil='+id+'&pseudo='+pseudo);
}
function affiche_partouze(partouze){
    $("#div-centre").load('http://www.plancul.fr/ajax/partouze.php?rubrique='+partouze);
}
function isset(variable){
    if(typeof(window[variable]) != "undefined"){
        return true;
    } else {
        return false;
    }
}

function afficherFormComm(id, pseudo, sexe, sexualite){
    if(isset('sT')){
        clearTimeout(sT);
    }
    document.getElementById("div-commentaires_"+id).innerHTML = '';
    $("#div-commentaire_"+id).load('http://www.plancul.fr/ajax/forms.php?form=commentaire&id='+id+'&pseudo='+pseudo+'&sexe='+sexe+'&sexualite='+sexualite);
}

function annulerCommentaire(id){
    $("#div-commentaires_"+id).load('http://www.plancul.fr/ajax/actions/afficher_commentaire.php?iId='+id);
}
function retirerTxt(area, txt){
    if(area.value == txt){
        area.value = '';
    }
}
function mettreTxt(area, txt){
    if(area.value == ''){
        area.value = txt;
    }
}
function validerCommentaire(id, pseudo){
    monAjax('http://www.plancul.fr/ajax/actions/ajout_commentaire.php?id='+id, $("#form_commentaire_"+id+" :input").serialize(),"#ajout_commentaire_"+id);
}

function changer_message_invitation(x, y, z){
    document.getElementById('invitation_'+x+'_'+z).style.display = 'none';
    document.getElementById('label_'+x+'_'+z).style.display = 'inline';
    $("#div-infos").load('http://www.plancul.fr/ajax/actions/invitation_partouze.php?partouze='+x+'&pseudo='+y+'&membre='+z);
}
function changer_message_invitation_reponse(x, y, z, r){
    switch(r){
        case 1:
            txt = 'style="color: green; ">Participation acceptée';
            break;
        case 2:
            txt = 'style="color: red; ">Participation refusée';
            break;
    }
    document.getElementById('span_'+x+'_'+z).innerHTML = '<label id="label_'+x+'_'+z+'" '+txt+'</label>';
    $("#div-demande").load('http://www.plancul.fr/ajax/contacts_partouzes_reponse.php?partouze='+x+'&pseudo='+y+'&membre='+z+'&choix='+r);
}
function fermerDiscussion(profil){
    $("#div-infos").load('http://www.plancul.fr/ajax/chat/fermer_discussion.php?profil='+profil);
}
function modifier_partouze(partouze){
    $("#div-mp").load('http://www.plancul.fr/ajax/modifier_partouze.php?partouze='+partouze);
}
function envoyer_ami(type, id){
    switch(type){
        case "annonce":
            $("#e_a-annonce_"+id).load('http://www.plancul.fr/ajax/centre/agenda/envoyer_amis.php?annonce='+id);
            break;

        case "partouze":
            $("#e_a-partouze_"+id).load('http://www.plancul.fr/ajax/centre/agenda/envoyer_amis.php?partouze='+id);
            break;
    }

    document.getElementById('s_e_a-'+type+'_'+id).innerHTML = '<a href="javascript:;" onclick="fermer_ea(\''+type+'\', '+id+')">fermer</a>';
}
function fermer_ea(type, id){
    fermer('e_a-'+type+'_'+id);
    document.getElementById('s_e_a-'+type+'_'+id).innerHTML = '<a href="javascript:;" onclick="envoyer_ami(\''+type+'\', '+id+')">envoyer à un ami</a>';
}
function ea_change_color(sElement, sStyle){
    document.getElementById(sElement).style.color = sStyle;
}



function getMap(LatLong, zoom, cont){
    var myOptions = {
        zoom: zoom,
        center: LatLong,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    return new google.maps.Map(document.getElementById(cont), myOptions);
}
function getLatLng(lat, lon){
    return new google.maps.LatLng(lat, lon);
}
function setMarker(map, LatLong, titre){
    return new google.maps.Marker({
        position: LatLong,
        map: map,
        title: titre
    });
}
function zoomClick(marker, zoom, LatLong){
    google.maps.event.addListener(marker, 'click', function() {
        map.setZoom(zoom);
        centrer(LatLong, map);
    });
}
function centrer(LatLong, map){
    map.setCenter(LatLong);
}
function googleMap(param){
    LatLong = getLatLng(param['latitude'], param['longitude']);
    map = getMap(LatLong, param['zoom'], param['conteneur']);

    for(x in param['options']){
        LatLong = getLatLng(param['options'][x]['latitude'], param['options'][x]['longitude']);
        marker = setMarker(map, LatLong, param['options'][x]['titre']);
        zoomClick(marker, param['options'][x]['zoom'], LatLong);
    }
    return map;
}
function change_trajet(mode){
    document.getElementById('mode').value = mode;
    switch(mode){
        case "WALKING":
            document.images['DRIVING'].src = 'http://www.plancul.fr/pictures/google_voiture_passif.jpg';
            document.images['WALKING'].src = 'http://www.plancul.fr/pictures/google_pied_actif.jpg';
            break;
        case "DRIVING":
        default:
            document.images['DRIVING'].src = 'http://www.plancul.fr/pictures/google_voiture_actif.jpg';
            document.images['WALKING'].src = 'http://www.plancul.fr/pictures/google_pied_passif.jpg';
            break;
    }
    trajet();
}
function trajet() {
    var selectedMode = document.getElementById("mode").value;
    var directionsService = new google.maps.DirectionsService();
    /**
    if(LatLongDest2 != null){ // adresse temporaire
        var request = {
            origin: LatLongOrig,
            destination: LatLongDest2,
            travelMode: google.maps.DirectionsTravelMode[selectedMode]
        };

        directionsService.route(request, function(response, status) {
            if (status == google.maps.DirectionsStatus.OK) {
                directionsDisplay2.setDirections(response);

                //var distance = response.routes[0].legs[0].distance.text;
                //document.getElementById('label-distance').innerHTML = distance;
            }
        });
    }
    /**/

    var request = { // adresse principale
        origin: LatLongOrig,
        destination: LatLongDest,
        travelMode: google.maps.DirectionsTravelMode[selectedMode]
    };

    directionsService.route(request, function(response, status) {
        if (status == google.maps.DirectionsStatus.OK) {
            directionsDisplay.setDirections(response);

            var distance = response.routes[0].legs[0].distance.text;
            document.getElementById('label-distance').innerHTML = distance;
        }
    });
}
function setDirectionsDisplay(){
    dd = new google.maps.DirectionsRenderer({
        suppressBicyclingLayer: false,
        suppressInfoWindows: true,
        suppressMarkers: true,
        suppressPolylines: false
    });
    return dd;
}
function maPosition(lat, long, autre){
    lat = parseFloat(lat);
    long = parseFloat(long);

    lat2 = parseFloat(autre[0]['latitude']);
    long2 = parseFloat(autre[0]['longitude']);

    /**
    lat3 = parseFloat(autre[1]['latitude']);
    long3 = parseFloat(autre[1]['longitude']);
    /**/
    var bMaPosition = false;
    var bSaPosition = false;
    var bSaPositionTemp = false;
    var ok = false;

    param = new Array();
    param['options'] = new Array();
    param['zoom'] = 12;
    param['conteneur'] = "map_canvas";

    i = 0;

    if(!(isNaN(lat) || isNaN(long))){
        param['latitude'] = lat;
        param['longitude'] = long;

        param['options'][i] = new Array();
        param['options'][i]['type'] = 'marker';
        param['options'][i]['latitude'] = param['latitude'];
        param['options'][i]['longitude'] = param['longitude'];
        param['options'][i]['zoom'] = 16;
        param['options'][i]['titre'] = "Chez moi";
        i++;
        bMaPosition = true;
    }

    if(!(isNaN(lat2) || isNaN(long2))){
        param['options'][i] = new Array();
        param['options'][i]['type'] = 'marker';
        param['options'][i]['latitude'] = lat2;
        param['options'][i]['longitude'] = long2;
        param['options'][i]['zoom'] = 16;
        param['options'][i]['titre'] = "Chez lui";
        i++;
        bSaPosition = true;
    }
    /**
    if(!(isNaN(lat3) || isNaN(long3))){
        param['options'][i] = new Array();
        param['options'][i]['type'] = 'marker';
        param['options'][i]['latitude'] = lat3;
        param['options'][i]['longitude'] = long3;
        param['options'][i]['zoom'] = 16;
        param['options'][i]['titre'] = "Chez lui temp";
        i++;
        bSaPositionTemp = true;
    }
    /**/
    if(bMaPosition == true){
        map = googleMap(param);
        LatLongOrig = getLatLng(lat, long);

        if(bSaPosition == true){
            directionsDisplay = setDirectionsDisplay();
            directionsDisplay.setMap(map);

            LatLongDest = getLatLng(lat2, long2);
            ok = true;
        }
        /**
        if(bSaPositionTemp == true){
            directionsDisplay2 = setDirectionsDisplay();
            directionsDisplay2.setMap(map);

            LatLongDest2 = getLatLng(lat3, long3);
            ok = true;
        }
        /**/
        if(ok == true){
            trajet();
        }
    }
}

function detecterMaPosition(param){

    browserSupportFlag = false;

    if(navigator.geolocation) {
        browserSupportFlag = true;
        navigator.geolocation.getCurrentPosition(function(position) {
            maLatitude = position.coords.latitude;
            maLongitude = position.coords.longitude;
            maPosition(maLatitude, maLongitude, param);
        }, function() {
            handleNoGeolocation(browserSupportFlag);
        });
    } else if(google.gears) {
        browserSupportFlag = true;
        var geo = google.gears.factory.create('beta.geolocation');
        geo.getCurrentPosition(function(position) {
            maLatitude = position.latitude;
            maLongitude = position.longitude;
            maPosition(maLatitude, maLongitude, param);
        }, function() {
            handleNoGeoLocation(browserSupportFlag);
        });
    } else {
        browserSupportFlag = false;
        handleNoGeolocation(browserSupportFlag);
    }

}
function handleNoGeolocation(errorFlag) {
    if (errorFlag == true) {
        alert("Geolocation service failed.");
        initialLocation = newyork;
    } else {
        alert("Your browser doesn't support geolocation. We've placed you in Siberia.");
        initialLocation = siberia;
    }
    map.setCenter(initialLocation);
}

function var_dump(obj) {
    if(typeof obj == "object") {
        return "Type: "+typeof(obj)+((obj.constructor) ? "\nConstructor: "+obj.constructor : "")+"\nValue: " + obj;
    } else {
        return "Type: "+typeof(obj)+"\nValue: "+obj;
    }
}
function fermer_profil_map(){
    document.getElementById('div-map2').style.display = 'none';
    document.getElementById('div-map3').style.display = 'block';
}
function ouvrir_profil_map(){
    document.getElementById('div-map3').style.display = 'none';
    document.getElementById('div-map2').style.display = 'block';
}
tab_principale = new Array();
tab_principale[0] = new Array();
tab_principale[1] = new Array();

tab_provisoire = new Array();
tab_provisoire[0] = new Array();
tab_provisoire[1] = new Array();



function fermer_profil_contacts(){
    document.getElementById('pm-contacts2').style.display = 'none';
    document.getElementById('pm-contacts3').style.display = 'block';

    document.getElementById('contacts-amis').className='onglet_passif';
    document.getElementById('contacts-favoris').className='onglet_passif';
    document.getElementById('contacts-plancul').className='onglet_passif';
    document.getElementById('contacts-commentaires').className='onglet_passif';

    fermer('pm-contacts');
}
function hover_on(x){
    x.style.cursor = 'pointer';
}
function activites(x){
    switch(x){
        case "messages":
            $("#div-centre").load('http://www.plancul.fr/ajax/mailbox.php');
            break;

        case "demandes":
            $("#div-centre").load('http://www.plancul.fr/ajax/demandes.php');
            break;

        case "plancul":
            $("#div-centre").load('http://www.plancul.fr/ajax/contacts.php?post=plancul');
            break;
    }
}

function mes_activites() {
    mon_activites("messages");
    mon_activites("demandes");
    mon_activites("plancul");
}

function mon_activites(activite){
    switch(activite){
        case "messages":
            $("#p-chats").load('http://www.plancul.fr/ajax/menu/mes_chats.php');
            break;

        case "demandes":
            $("#p-demandes").load('http://www.plancul.fr/ajax/menu/demandes.php');
            break;

        case "plancul":
            $("#p-plan_cul").load('http://www.plancul.fr/ajax/menu/plan_cul.php');
            break;
    }
}

function consulte_mon_profil(){
    $("#div-visite_profil").load('http://www.plancul.fr/ajax/menu/consulte_profil.php');
}

function plancul(div, choix, id, pseudo, page, moyen){
    $("#"+div).load('http://www.plancul.fr/ajax/reponses/plancul.php?choix='+choix+'&id='+id+'&pseudo='+pseudo+'&page='+page+'&moyen='+moyen);
}

function amis(div, choix, id, pseudo, page, moyen){
    $("#"+div).load('http://www.plancul.fr/ajax/reponses/amis.php?choix='+choix+'&profil='+id+'&pseudo='+pseudo+'&page='+page+'&moyen='+moyen);
}

function partouze(div, choix, id, pseudo, page, moyen, id_partouze){
    $("#"+div).load('http://www.plancul.fr/ajax/reponses/partouze.php?choix='+choix+'&profil='+id+'&id_partouze='+id_partouze+'&page='+page+'&moyen='+moyen+'&pseudo='+pseudo);
}

function album_prive(choix, id, pseudo){
    $("#div-demande").load('http://www.plancul.fr/ajax/reponses/album_prive.php?choix='+choix+'&profil='+id+'&pseudo='+pseudo);
}

function video(choix, id, pseudo){
    $("#div-demande").load('http://www.plancul.fr/ajax/reponses/video_perso.php?choix='+choix+'&profil='+id+'&pseudo='+pseudo);
}

function couple(choix, id, pseudo){
    $("#div-demande").load('http://www.plancul.fr/ajax/reponses/couple.php?choix='+choix+'&profil='+id+'&pseudo='+pseudo);
}

function confirmation_mail() {
    $("#div-modif").load('http://www.plancul.fr/ajax/mail_confirmation.php');
}


function envie( element ){
    if (document.getElementById(element).style.display == 'none') {
        affiche_mon_envie( element );
    } else  {
        cache_mon_envie( element );
    }
}
function cache_mon_envie( element ) {
    document.getElementById(element).style.display='none';
}
function affiche_mon_envie( element ) {
    document.getElementById(element).style.display='block';
}

function supprimerCompte(){
    txt = "Vous êtes sur le point de supprimer votre compte.\n\nConfirmez vous la suppression de votre compte ?\n(OK => supprimer mon compte, Annuler => revenir sur le site)";
    if(confirm(txt)){
        $("#div-supprimer_compte").load('http://www.plancul.fr/ajax/actions/supprimer_compte.php');
    }
}

function recherche() {
    monAjax('http://www.plancul.fr/ajax/centre/recherche/resultat.php',$("#div-recherche :input").serialize(),'#div-resultat_recherche');
}

function histoires_valider(form, div){
    monAjax('http://www.plancul.fr/ajax/centre/histoires/ajouter.php', $("#"+form+" :input").serialize(), "#"+div);
}

function affiche_histoire( div, id_histoire ){
    $("#"+div).load('http://www.plancul.fr/ajax/centre/histoires/unique.php?iIdHistoire='+id_histoire);
}

function modifier_histoire(div, id_histoire){
    $("#"+div).load('http://www.plancul.fr/ajax/centre/histoires/modification.php?iIdHistoire='+id_histoire);
}

function supprimer_histoire(div, id_histoire){
    $("#div-infos").load('http://www.plancul.fr/ajax/centre/histoires/suppression.php?iIdHistoire='+id_histoire);
}

function ajout_ligne(ind){
    sup = ind + 1;
    if(!(document.getElementById('contact-'+sup))){
        obj = document.getElementById('contact-'+ind);
        obj.innerHTML += '<label class="titre_champ_parrainage">E-mail :</label> ';
        obj.innerHTML += '<input type="text" name="contact[]" onfocus="ajout_ligne('+sup+')" />';
        obj.innerHTML += '<div id="contact-'+sup+'"></div>';
    }
}

$(document).ready(function() { 
	$(document).keyup(function(event) {
		code = event.keyCode;
		if(code == 18){
			$(location).attr('href','http://www.google.fr');
		}
	}); 
});

function anim_chargement(){
	if($('#img_file').val() != ''){
		$('#image_loader').css('display', 'block');
	}
}


function DF_ObjetDefilant(id,id_dim,mode,sens,vit,pos,b_esp,pause)
{
	this.DF_ObjetParam = typeof this.DF_ObjetParam == 'undefined' ? new Array() : this.DF_ObjetParam;	
	this.DF_ObjetParam[id] = typeof this.DF_ObjetParam[id] == 'undefined' ? new Array() : this.DF_ObjetParam[id];	
			
	if(typeof this.DF_ObjetParam[id]['id_defile'] == 'undefined') {Set_param (id,id_dim,mode,sens,vit,pos,b_esp,pause);}
	else
	if (this.DF_ObjetParam[id]['dim_defilant'] > 0)
	{
		if (this.DF_ObjetParam[id]['mode'] == 'r') {Boucle_ar(id);} else {Boucle_cont(id);}
	 
		this.DF_ObjetParam[id]['Timer'] = setTimeout(function(){DF_ObjetDefilant(id)},this.DF_ObjetParam[id]['delaicrnt']);	
	}
	


	function Set_param (id,id_dim,mode,sens,vit,pos,b_esp,pause) 
	{	
		var id_d = null;
		var id_c = null;
		var id_cc = null;
		
		
		if(!(id_d = document.getElementById(id))) {id_d = null;} else if(!(id_c = id_d.parentNode)) {id_c = null;}
		else if(!(id_cc = id_c.parentNode)) {id_cc = null;};
		
		if(id_c != null && id_cc != null && id_d != null)
		{
		function is_all_ws ( nod )
			{
			  // Use ECMA-262 Edition 3 String and RegExp features
			  return !(/[^\t\n\r ]/.test(nod.data));
			}
			
			
		function is_ignorable ( nod )
			{
			  return (nod.nodeType == 8) || // A comment node
					 ( (nod.nodeType == 3) && is_all_ws(nod) ); // a text node, all ws
			}


		function trim_debut (myString)
			{
				return myString.replace(/^\s+/g,'')
			} 
		
		
		function trim_fin (myString)
			{
				return myString.replace(/\s+$/g,'')
			} 
		
											
		// Nettoyage mise en page html Mozilla Chrome...
		if (id_d != null) 
			{
				while (id_d.hasChildNodes() && is_ignorable(id_d.lastChild)) {id_d.removeChild(id_d.lastChild);}
				while (id_d.hasChildNodes() && is_ignorable(id_d.firstChild)) {id_d.removeChild(id_d.firstChild);}
			}	
		}
		
		if(id_c != null && id_cc != null && id_d != null && id_d.hasChildNodes())
			{
				this.DF_ObjetParam[id]['instance'] = typeof this.DF_ObjetParam[id]['instance'] == 'undefined' ? function () {DF_ObjetDefilant(id,id_dim,mode,sens,vit,pos,b_esp,pause);} : this.DF_ObjetParam[id]['instance'];
				
				this.DF_ObjetParam[id]['sens_ini'] = typeof sens != 'undefined' && (sens == 'g' || sens == 'd' || sens == 'h' || sens == 'b') ? sens : 'g';
	
				this.DF_ObjetParam[id]['sens_horizontal'] = this.DF_ObjetParam[id]['sens_ini'] == 'g' || this.DF_ObjetParam[id]['sens_ini'] == 'd' ? true : false;	
				
				id_cc.style.overflow = "hidden";
				
				id_c.style.visibility = "hidden";
				id_c.style.position = "relative";
				id_c.style.overflow = "hidden";
				
							
				id_d.style.position = "absolute";
				id_d.style.width = "auto";
				id_d.style.height = "auto";
				
				
				// Nettoyage espaces vides en d�but de d�filant pour le mode horizontal
				var elem = id_d.firstChild;	
				
				if (elem.nodeType == 3 && this.DF_ObjetParam[id]['sens_horizontal']) 
					{
						var noeud_debut = document.createTextNode(trim_debut(elem.nodeValue)); 
						id_d.replaceChild(noeud_debut, id_d.firstChild);
					}
		 
				// Nettoyage espaces vides en fin de d�filant
				elem = id_d.lastChild;	
				
				if (elem.nodeType == 3) 
					{
						var noeud_fin = document.createTextNode(trim_fin(elem.nodeValue)); 
						id_d.replaceChild(noeud_fin, id_d.lastChild);
					}
				
				
				var div_defile = id_d.cloneNode(true);
				
				var espace_insecable = document.createTextNode("\u00a0"); 
				
				// Ajoute un espace ins�cable "\u00a0" si 'BR' est en fin de d�filant pour le mode vertical (pour ie)
				if(!this.DF_ObjetParam[id]['sens_horizontal'] && div_defile.lastChild.nodeName == 'BR') 
				{
					div_defile.appendChild(espace_insecable);
				}
	
				
				var c = document.createElement("div");
				c.style.height = "100%";
				
				var nb_noeud = id_c.childNodes.length;
				
				
				// Dimensions du cadre
				for (var i = 0; i < nb_noeud ; i++) {id_c.removeChild(id_c.firstChild);}
				id_c.appendChild(c);
				
				this.DF_ObjetParam[id]['hauteur_cadre'] = c.offsetHeight;
				this.DF_ObjetParam[id]['largeur_cadre'] = c.offsetWidth;
				id_c.removeChild(id_c.firstChild);
				id_c.appendChild(div_defile);			
					
				this.DF_ObjetParam[id]['id_defile'] = document.getElementById(id);
				
				
				// Dimensions du d�filant	
				var id_dim = typeof id_dim == 'undefined' || trim_debut(id_dim) == '' || id_dim == 'auto' ? 'auto' :  parseInt(id_dim);
				
				if(this.DF_ObjetParam[id]['sens_horizontal']) 
					{
						this.DF_ObjetParam[id]['id_defile'].style.height = this.DF_ObjetParam[id]['hauteur_cadre']+'px';
												
						this.DF_ObjetParam[id]['largeur_def'] = id_dim == 'auto' ? undefined : id_dim;
						
						if (typeof this.DF_ObjetParam[id]['largeur_def'] == 'undefined')
						{
							id_c.style.width = '1000000px';//largeur maxi de calcul
							
							this.DF_ObjetParam[id]['largeur_def'] = this.DF_ObjetParam[id]['id_defile'].offsetWidth;
							
							id_c.style.width = 'auto';
						}
						
						this.DF_ObjetParam[id]['id_defile'].style.width = this.DF_ObjetParam[id]['largeur_def']+'px';
						
					}
					else 
					{
						this.DF_ObjetParam[id]['id_defile'].style.width = this.DF_ObjetParam[id]['largeur_cadre']+'px';
						
						this.DF_ObjetParam[id]['hauteur_def'] = id_dim == 'auto' ? this.DF_ObjetParam[id]['id_defile'].offsetHeight : id_dim;
						
						this.DF_ObjetParam[id]['id_defile'].style.height = this.DF_ObjetParam[id]['hauteur_def']+'px';
					}



				this.DF_ObjetParam[id]['dim_cadre'] = this.DF_ObjetParam[id]['sens_horizontal'] ? this.DF_ObjetParam[id]['largeur_cadre'] : this.DF_ObjetParam[id]['hauteur_cadre'];
				
				this.DF_ObjetParam[id]['dim_defilant'] = this.DF_ObjetParam[id]['sens_horizontal'] ? this.DF_ObjetParam[id]['largeur_def'] : this.DF_ObjetParam[id]['hauteur_def'];
				
	
				this.DF_ObjetParam[id]['mode'] = typeof mode != 'undefined' && (mode == 'r' || mode == 'b') ? mode : 'b';
							
				this.DF_ObjetParam[id]['vitesse'] = typeof vit != 'undefined' && parseInt(vit) > 0 ? parseInt(vit) : 20;
			
				this.DF_ObjetParam[id]['psinit'] = typeof pos != 'undefined' && parseFloat(pos) > 0 ? parseFloat(pos) : 0;
				
				this.DF_ObjetParam[id]['b_esp'] = typeof b_esp != 'undefined' && parseFloat(b_esp) > 0 ? parseFloat(b_esp) : 0;		
				
				this.DF_ObjetParam[id]['pause'] = typeof pause != 'undefined' && parseInt(pause) > 0 ? parseInt(pause) : 0;
							
		
				this.DF_ObjetParam[id]['b_esp'] = this.DF_ObjetParam[id]['b_esp'] < 0  || this.DF_ObjetParam[id]['b_esp'] > 100 || this.DF_ObjetParam[id]['mode'] == 'r' ? 0 : Math.ceil(this.DF_ObjetParam[id]['b_esp'] * this.DF_ObjetParam[id]['dim_cadre']/100);
				
			
				this.DF_ObjetParam[id]['psinit'] = this.DF_ObjetParam[id]['psinit'] == 100 || this.DF_ObjetParam[id]['psinit'] < 0 || this.DF_ObjetParam[id]['psinit'] > 100 ? this.DF_ObjetParam[id]['dim_cadre'] : Math.ceil(this.DF_ObjetParam[id]['psinit']*this.DF_ObjetParam[id]['dim_cadre']/100);		
				
				
				this.DF_ObjetParam[id]['psinit'] = (this.DF_ObjetParam[id]['dim_cadre'] > this.DF_ObjetParam[id]['dim_defilant'] &&  this.DF_ObjetParam[id]['psinit'] == 0 ) ? this.DF_ObjetParam[id]['dim_cadre'] - this.DF_ObjetParam[id]['dim_defilant'] : this.DF_ObjetParam[id]['psinit'];
				
				
				this.DF_ObjetParam[id]['pscrnt'] = this.DF_ObjetParam[id]['psinit'];
				
				this.DF_ObjetParam[id]['sens'] = 1;
			
				this.DF_ObjetParam[id]['p_retour'] = this.DF_ObjetParam[id]['dim_defilant'] >= this.DF_ObjetParam[id]['dim_cadre'] ? this.DF_ObjetParam[id]['dim_defilant'] - this.DF_ObjetParam[id]['dim_cadre'] : 0;
				
				this.DF_ObjetParam[id]['dim_defilant'] += this.DF_ObjetParam[id]['b_esp'];														
			
				this.DF_ObjetParam[id]['p_retour'] = this.DF_ObjetParam[id]['mode'] == 'b' ? this.DF_ObjetParam[id]['dim_defilant'] : this.DF_ObjetParam[id]['p_retour'];
				
			
				if (this.DF_ObjetParam[id]['mode'] == 'r' && this.DF_ObjetParam[id]['dim_defilant'] == this.DF_ObjetParam[id]['dim_cadre'] && this.DF_ObjetParam[id]['psinit'] == 0) {this.DF_ObjetParam[id]['dim_defilant'] = 0;}
			
				if (this.DF_ObjetParam[id]['dim_defilant'] > 0 && this.DF_ObjetParam[id]['mode'] == 'b') {Ajout_clone(id);}
				
				
				id_cc.style.overflow = "visible";
				id_c.style.visibility = "visible";	
				
			
				this.DF_ObjetParam[id]['instance']();	
		}
	}


	
	function Ajout_clone(id) 
	{	   	
		var div_contenu = document.createElement("div");
		
		var nb_noeud = this.DF_ObjetParam[id]['id_defile'].childNodes.length;
		
		for (var i = 0; i < nb_noeud ; i++) 
			{				   
				div_contenu.appendChild(this.DF_ObjetParam[id]['id_defile'].firstChild.cloneNode(true));
				this.DF_ObjetParam[id]['id_defile'].removeChild(this.DF_ObjetParam[id]['id_defile'].firstChild);
			}
			
		if (this.DF_ObjetParam[id]['b_esp'] > 0)
		{
			if (this.DF_ObjetParam[id]['sens_horizontal'])
				{
					this.DF_ObjetParam[id]['sens_ini'] == 'g' ? div_contenu.style.marginRight = this.DF_ObjetParam[id]['b_esp']+'px' : div_contenu.style.marginLeft = this.DF_ObjetParam[id]['b_esp']+'px';		
				}
				else 
				{
					this.DF_ObjetParam[id]['sens_ini'] == 'h' ? div_contenu.style.marginBottom = this.DF_ObjetParam[id]['b_esp']+'px' : div_contenu.style.marginTop = this.DF_ObjetParam[id]['b_esp']+'px';					
				}
		}
		
		if (this.DF_ObjetParam[id]['sens_horizontal']) {div_contenu.style.display = "inline";};					
			   
		this.DF_ObjetParam[id]['id_defile'].appendChild(div_contenu.cloneNode(true));
				
		var nb_clone = Math.ceil(this.DF_ObjetParam[id]['dim_cadre']/(this.DF_ObjetParam[id]['dim_defilant']));
		
		if (this.DF_ObjetParam[id]['sens_horizontal']) 
			{
			   this.DF_ObjetParam[id]['id_defile'].style.width = ((nb_clone+1) * this.DF_ObjetParam[id]['dim_defilant'])+'px';
			}
			else
			{
			   this.DF_ObjetParam[id]['id_defile'].style.height = ((nb_clone+1) * this.DF_ObjetParam[id]['dim_defilant'])+'px';
			}
			
		for (var j = 0; j < nb_clone ; j++)
			{
				this.DF_ObjetParam[id]['id_defile'].appendChild(this.DF_ObjetParam[id]['id_defile'].firstChild.cloneNode(true));    
			}
	}



	function Boucle_cont(id)
	{
		this.DF_ObjetParam[id]['delaicrnt'] = this.DF_ObjetParam[id]['vitesse'];
		this.DF_ObjetParam[id]['inverse'] = 1;
	
		if(this.DF_ObjetParam[id]['pscrnt'] == - this.DF_ObjetParam[id]['p_retour'])	
				{					
					this.DF_ObjetParam[id]['id_defile'].appendChild(this.DF_ObjetParam[id]['id_defile'].firstChild.cloneNode(true));  
					this.DF_ObjetParam[id]['id_defile'].removeChild(this.DF_ObjetParam[id]['id_defile'].firstChild); 
					 
					this.DF_ObjetParam[id]['inverse'] = -1;		
					this.DF_ObjetParam[id]['pscrnt'] = 0;
					this.DF_ObjetParam[id]['sens'] = -1;		
				}		
				else
				{
					if(this.DF_ObjetParam[id]['pscrnt'] == this.DF_ObjetParam[id]['psinit'])
						{
							this.DF_ObjetParam[id]['sens'] *= -1;
							this.DF_ObjetParam[id]['delaicrnt'] = this.DF_ObjetParam[id]['pause']; 
						}
				}
				
			if (this.DF_ObjetParam[id]['sens_horizontal'])
				{
					this.DF_ObjetParam[id]['sens_ini'] == 'g' ? this.DF_ObjetParam[id]['id_defile'].style.left = this.DF_ObjetParam[id]['pscrnt']+"px" : this.DF_ObjetParam[id]['id_defile'].style.right = this.DF_ObjetParam[id]['pscrnt']+"px" ;
				}
				else
				{
					this.DF_ObjetParam[id]['sens_ini'] == 'h' ? this.DF_ObjetParam[id]['id_defile'].style.top = this.DF_ObjetParam[id]['pscrnt']+"px" : this.DF_ObjetParam[id]['id_defile'].style.bottom = this.DF_ObjetParam[id]['pscrnt']+"px" ;
				}
			 
			this.DF_ObjetParam[id]['pscrnt'] += this.DF_ObjetParam[id]['sens']; 
	}
	
	
	
	function Boucle_ar (id) 
	{
		this.DF_ObjetParam[id]['delaicrnt'] = this.DF_ObjetParam[id]['vitesse'];
		this.DF_ObjetParam[id]['inverse'] = 1;
		
		if(this.DF_ObjetParam[id]['pscrnt']  == - this.DF_ObjetParam[id]['p_retour'] || this.DF_ObjetParam[id]['pscrnt'] == this.DF_ObjetParam[id]['psinit'])
			{
				this.DF_ObjetParam[id]['inverse'] = -1;
				this.DF_ObjetParam[id]['delaicrnt'] = this.DF_ObjetParam[id]['pause']; 
				this.DF_ObjetParam[id]['sens'] *= -1;
			}
			
		if (this.DF_ObjetParam[id]['sens_horizontal'])
			{		
				this.DF_ObjetParam[id]['sens_ini'] == 'g' ? this.DF_ObjetParam[id]['id_defile'].style.left = this.DF_ObjetParam[id]['pscrnt']+"px" : this.DF_ObjetParam[id]['id_defile'].style.right = this.DF_ObjetParam[id]['pscrnt']+"px" ;
			}
			else
			{
				this.DF_ObjetParam[id]['sens_ini'] == 'h' ? this.DF_ObjetParam[id]['id_defile'].style.top = this.DF_ObjetParam[id]['pscrnt']+"px" : this.DF_ObjetParam[id]['id_defile'].style.bottom = this.DF_ObjetParam[id]['pscrnt']+"px" ;

			}
		
		this.DF_ObjetParam[id]['pscrnt'] += this.DF_ObjetParam[id]['sens']; 
	}

}



function DF_ObjetNavigMous(id,etat,nb) 
{
	var nb = typeof nb == 'undefined'? 0 :  nb + 1;
	
	if(typeof this.DF_ObjetParam != 'undefined' && typeof this.DF_ObjetParam[id] != 'undefined' && this.DF_ObjetParam[id]['id_defile'] != null && typeof this.DF_ObjetParam[id]['instance'] != 'undefined' && typeof this.DF_ObjetParam[id]['Timer'] == 'number') 
		{
			clearTimeout(this.DF_ObjetParam[id]['Timer']);
			this.DF_ObjetParam[id]['Timer'] = 0;
			if (etat == 'out') this.DF_ObjetParam[id]['instance']();
		}
		else if (nb < 30)//pour ancien navigateur avec chargement onload de DF_ObjetDefilant_Off(id)
		{
			setTimeout(function(){DF_ObjetNavigMous(id,etat,nb)},15);
		}
}



function DF_ObjetSensInverse (id) 
{
	if(typeof this.DF_ObjetParam != 'undefined' && typeof this.DF_ObjetParam[id] != 'undefined' && this.DF_ObjetParam[id]['id_defile'] != null && typeof this.DF_ObjetParam[id]['Timer'] == 'number' && this.DF_ObjetParam[id]['inverse'] == 1 && !(this.DF_ObjetParam[id]['pscrnt']  == - this.DF_ObjetParam[id]['p_retour'] || this.DF_ObjetParam[id]['pscrnt'] == this.DF_ObjetParam[id]['psinit'])) 
		{
			this.DF_ObjetParam[id]['sens'] *= -1;
		}
}



function DF_ObjetDefilant_On (id)
{
	if(typeof this.DF_ObjetParam[id]['id_defile'] == 'undefined' && typeof this.DF_ObjetParam[id]['instance'] != 'undefined') 
		{
			this.DF_ObjetParam[id]['instance']();	
		}
		else
		{
			DF_ObjetNavigMous(id,'out');
		}
}



function DF_ObjetDefilant_Off (id)
{
	DF_ObjetNavigMous(id,'over');
}



function DF_ObjetDefilant_On_Off (id)
{
	if(typeof this.DF_ObjetParam[id]['id_defile'] == 'undefined' || (typeof this.DF_ObjetParam[id]['Timer'] == 'number' && this.DF_ObjetParam[id]['Timer'] == 0))
		{
			DF_ObjetDefilant_On (id);
		}
		else
		{
			DF_ObjetNavigMous(id,'over');
		}
}



function DF_ObjetDefilant_On_Inverse (id)
{
	if(typeof this.DF_ObjetParam[id]['id_defile'] == 'undefined' || (typeof this.DF_ObjetParam[id]['Timer'] == 'number' && this.DF_ObjetParam[id]['Timer'] == 0))
		{
			DF_ObjetDefilant_On (id);
		}
		else
		{
			DF_ObjetSensInverse (id);
		}
}



function DF_ObjetDefilant_Inverse (id)
{
	if(typeof this.DF_ObjetParam[id]['Timer'] == 'number' && this.DF_ObjetParam[id]['Timer'] > 0)
		{
			DF_ObjetSensInverse (id);
		}
}



function addLoad_DF_ObjetDefilant(func) 
{
	if (window.addEventListener)
		{
			window.addEventListener("load", func, false);
		}
	else if (document.addEventListener)
		{
			document.addEventListener("load", func, false);
		}
	else if (window.attachEvent)
		{
			window.attachEvent("onload", func);
		}
}
