/*************** SYSTEME DE PARTENAIRE *********************/
//AJOUT DE PARTENAIRE
function add_partenaire_contact(id_contact,path_plugins)
{
	$.get(
		path_plugins+"annuaire/ajax_partenaire.php",
		{ id_partner: id_contact, action:'ajout'},
		function(data){
			try{
				tab = data.split(";;");
				$("#ajout_partenaire_"+id_contact).fadeOut("normal");
				$("#liste_contacts_user").prepend("<li id='my_profile_partenaire_"+id_contact+"'>" +
						tab[1]+" " +
						"<a href='#' onclick='del_partenaire_contact(\""+tab[0]+"\",\""+path_plugins+"\")'>SUPPR</a>" +
					"</li>");
				curNombre = parseInt($("#my_profile_nb_contact").html()) >= 0 ? parseInt($("#my_profile_nb_contact").html()) : 0;
				$("#my_profile_nb_contact").html(curNombre+1);
				if((curNombre+1)>1)
					$("#contact_pluriel").fadeIn("normal");
				else
					$("#contact_pluriel").fadeOut("normal");
				
				$("#msg_add_"+id_contact).fadeIn("normal");
				
			}catch(e){}
		}
	)
}

function del_partenaire_contact(id_contact,path_plugins)
{
	$.get(
		path_plugins+"annuaire/ajax_partenaire.php",
		{ id_partner: id_contact, action:'suppr'},
		function(data){
			$("#my_profile_partenaire_"+id_contact).fadeOut("normal");
			curNombre = parseInt($("#my_profile_nb_contact").html()) >= 0 ? parseInt($("#my_profile_nb_contact").html()) : 0;
			$("#my_profile_nb_contact").html( (curNombre-1)==0 ? "0" : curNombre-1);
			if((curNombre-1)>1)
					$("#contact_pluriel").fadeIn("normal");
				else
					$("#contact_pluriel").fadeOut("normal");
		}
	)
}
/*************** SYSTEME DE PARTENAIRE *********************/
//AJOUT D'EVENEMENT
function add_evenement_agenda(id_eve,path_plugins)
{
	$.get(
		path_plugins+"evenement/ajax_evenement.php",
		{ id_events: id_eve, action:'ajout'},
		function(data){
			try{
				$("#agenda_"+id_eve).fadeOut("normal");
				$("#agenda_"+id_eve).html("<a href='#' onclick='del_evenement_agenda(\""+id_eve+"\",\""+path_plugins+"\")'>Supprimer de l'agenda</a>");
				$("#agenda_"+id_eve).fadeIn("normal");
			}catch(e){}
		}
	)
}

function del_evenement_agenda(id_eve,path_plugins)
{
	$.get(
		path_plugins+"evenement/ajax_evenement.php",
		{ id_events: id_eve, action:'suppr'},
		function(data){
			try{
				$("#agenda_"+id_eve).fadeOut("normal");
				$("#agenda_"+id_eve).html("<a href='#' onclick='add_evenement_agenda(\""+id_eve+"\",\""+path_plugins+"\")'>Ajouter &agrave; l'agenda</a>");
				$("#agenda_"+id_eve).fadeIn("normal");
			}catch(e){}
		}
	)
}
/************* SYSTEME D'INVITATION **********************/
function invit_step_one(id_eve,path_plugins)
{
	$.get(
		path_plugins+"evenement/ajax_evenement.php",
		{ id_events: id_eve, action:'invit'},
		function(data){
			try{
				$("#invit_"+id_eve).html(data);
				$("#invit_"+id_eve).fadeIn("normal");
			}catch(e){}
		}
	)
}

function commentaire_invitation(id_event)
{$("#commentaire_"+id_event).html($("#message_invitation_"+id_event).val())}

function postInvitation(id_event,path_plugins)
{
	//RECUPERATION DES VARIABLES
	var obj = encodeURI($("#objet_invitation_"+id_event).val());
	var mai = encodeURI($("#message_complet_invitation_"+id_event).html());
	var con = "";
	var tabCheck = $("input:checked");
	
	for(i=0;i<tabCheck.length;i++)
	{
		con+=tabCheck[i].value+",";
	}
	con = con.substr(0,con.length-1);
	if ( con != "" )
	{
		$.post(
			path_plugins+"evenement/ajax_evenement.php?id_events="+id_event+"&action=invit_mail",
			{ 'objet': obj, 'mail': mai, 'contacts': con},
			function(data)
			{
				$("#invit_"+id_event).html(data);
				//alert("DONNEE : "+data);
			}
		);
	}
	else
	{
		alert("Veuillez sélectionner un contact");
	}
	
}
function etat(num)
{
    switch(num)
    {
        case '0': return "En attente";
        case '1': return "Favorable";
        case '2': return "Defavorable";
    }
}
function modifEtat(id_invit,e,path_plugins)
{
	$("#etat_invit_"+id_invit).html(etat(e));
    $.post(
		path_plugins+"evenement/ajax_evenement.php?id_invit="+id_invit+"&action=etat_invitation",
		{ 'etat': e });
}

function reponseInvitation(id_invit,e,path_plugins)
{
    $.post(
		path_plugins+"evenement/ajax_evenement.php?id_invit="+id_invit+"&action=reponse_invitation",
		{ 'etat': e },
        function(data){$("#invitation_etat_0").html(data)}
    );
}

function getPageInvitation(page,path_plugins)
{
	$.get(
		path_plugins+"evenement/ajax_evenement.php",
		{ panu: page, action:'invit_page'},
		function(data){$("#invitation_etat_0").html(data)}
	)
}

function switchTab(laquelle) {
	/* Reinit */
	document.getElementById("tab_entreprise").style.display='none';
	document.getElementById("tab_contact").style.display='none';
	document.getElementById("tab_direction").style.display='none';
	
	document.getElementById("nav_tab_entreprise").className='non_actif';
	document.getElementById("nav_tab_contact").className='non_actif';
	document.getElementById("nav_tab_direction").className='non_actif';
	
	document.getElementById("tab_entreprise").style.display='none';
	
	document.getElementById(laquelle).style.display='block';
	document.getElementById("nav_"+laquelle).className='actif';
	/*
	tab_entreprise
	tab_contact
	tab_direction*/
}

// Cache les msg d'erreur
function hide_error () {
	div  = (document.layers) ? document.layers['errorPad'] : document.getElementById('errorPad');
	div2  = (document.layers) ? document.layers['erlogPad'] : document.getElementById('erlogPad');
	div.style.display = "none";
	div2.style.display = "none";
}

/*$(document).ready(function() {
	alert("OK");
	if ( $$('.highlight_1') != "" ) {
		$$('.highlight_1').each(function(toggler, i) {
			toggler.onmouseover = function() {
				this.addClass('sfhover');
				if ( (deployed != undefined) && (deployed != "") && (activated != this.id) && (activated != "")  ) {
					$(deployed).style.display = 'none';
				}
			}
			toggler.onmouseout = function() {
				this.toggleClass('sfhover');
				if ( (deployed != undefined) && (deployed != "") && (activated != this.id) && (activated != "")  ) {
					$(deployed).style.display = 'block';
				}
			}
		});
	}
}*/