
//login espace membres
function doLogin() {
	if (statut)
		return false;
	
	$("font[id=idPopup_result]").slideDown("fast");
	
	$.ajax({
		type: "GET",
		url: chemin + "/scripts/ajax/identification.php?JS_pseudo="+esc( $("input[name=id_pseudo]").val() )+"&JS_password="+esc( $("input[name=id_password]").val() ), 
		success: function(string){
			if (string != "0") {
				err = "Identification impossible.";
				if (string == "actif") err = "Vous êtes déjà connecté.";
				if (string == "banni") err = "Ce compte est désactivé.";
				if (string == "faux") err = "Mauvais identifiants.";
				$("font[id=idPopup_result]").html(err);
				$("font[id=idPopup_result]").slideDown("slow");
			} else {
				statut = true;
				$("font[id=idPopup_result]").html("Bienvenue ! Redirection en cours...");
				$("font[id=idPopup_result]").slideDown("slow");
				setTimeout(function() {
					actualiser();
				}, 2000);
			}
		}
	});
	
	return false;
}

//gestion des commentaires dynamiques des profils
function cDyn() {
	if ($("#postComm").val() == "Commentaire" || $("#postComm").val() == "") {
		alert("Merci de saisir un commentaire.");
		$("#postComm")[0].focus();
		return false;
	}
	$.ajax({
		type: "GET",
		url: chemin + "/scripts/ajax/cDyn.php",
		data: "js=1&commentaire=" + esc($("#postComm").val()) + "&type=" + esc($("#postComm_type").val()) + "&item=" + esc($("#postComm_item").val()) ,
		success: function(string){
			ret = "";
			
			if (string == "0")
				ret = "Impossible de poster votre commentaire.";
			else if (string == "1")
				ret = "Vous devez être connecté en tant que Membre pour poster un commentaire.";
			else if (string == "2")
				ret = "Votre commentaire est trop court (3 caractères min.).";
			else if (string == "3")
				ret = "Votre commentaire est trop long.";
			else if (string == "4")
				ret = "Erreur.";
			else {
				//ajout du commentaire
				ret = string;
			}
			
			if (string.length < 2)
				alert(ret);
			else {
				if ($("#postComm_form input[type=submit]").val() == "Poster") {
					now = new Date();
					j = now.getDate();
					if (j < 10)
						j = "0" + j;
					m = now.getMonth()+1;
					if (m < 10)
						m = "0" + m;
					a = now.getFullYear().toString().substring(2,4);
					today = j + "/" + m + "/" + a;
					p = "<a href='"+chemin+"/espace/profil/"+myid+"/' style='text-decoration:none'><b>"+pseudo+"</b></a>";
					ret = "<table width=100% cellpadding=0 cellspacing=2 border=0 class=cell_alt style='border:none'><tr><td style='line-height:15px;' class=petit width=25%>"+p+"<br><font color='#999999'>"+today+"</font></td><td class=petit width=75% id='postComm_bloc'>"+ret+"</td></tr></table>\n";
					$("#noComm").html(ret);
					
					autoH = ( 1+ 1*$("#nbComms").val() ) * 30;
					if (autoH <= 0){
						autoH = 30;
					} else if (autoH > 1*$("#hauteurComm").val()) {
						autoH = 1*$("#hauteurComm").val();
					}
					$("#commDyn_mainFrame").css("height", autoH + "px");
					
				} else {
					//éditer
					$("#postComm_bloc").html(ret);
				}
				alert("Votre commentaire a été " + ( ($("#postComm_form input[type=submit]").val() == "Poster") ? "posté" : "édité" ) + ".");
				$("#postComm_form input[type=submit]").val("Editer");
			}
		}
	});
	
	return false;
}

//votes des musiques
function voter (id, note) {
	$.ajax({
		type: "POST",
		url: chemin + "/scripts/ajax/vote.php",
		data: { id:id, note:note } ,
		dataType: "text",
		success: function(string){
			if (string != "OK") {
				alert("Erreur : " + string);
				return ;
			}
			alert("Merci d'avoir voté !");
			$('#modalWindow').jqmHide();
		}
	});
}

//supprimer un mp
function del_mp(id) {
	$("input[name='but_supprimer']").attr("disabled", "disabled").val("Patientez...");
	$.ajax({
		type: "GET",
		url: chemin + "/scripts/ajax/del_mp.php",
		data: "check_del=" + esc(id) ,
		success: function(string){
			if (string != "1") {
				alert("Erreur : " + string);
				return false;
			}
			//masquer la ligne dans l'inbox...
			$("a[href^='javascript:popMP(\""+id+"\",']").parent().parent().hide();
			closeBscreen();
		}
	});
}

//supprimer un ami depuis profil
function del_friend(str, lnk) {
	$(lnk).parent().parent().hide();
	$.ajax({
		type: "GET",
		url: chemin + "/scripts/ajax/del_friend.php",
		data: "s=" + esc(str) ,
		success: function(string){
			if (string.length < 3) {
				alert("Une erreur s'est produite.");
				return false;
			}
		}
	});
}

//ajouter un ami depuis MP
function add_friend(id, lnk) {
	$.ajax({
		type: "GET",
		url: chemin + "/scripts/ajax/add_friend.php",
		data: "id=" + esc(id) ,
		success: function(string){
			if (string == "Une erreur s'est produite.") {
				alert(string);
				return false;
			} else {
				alert(string);
				$(lnk).hide();
				JQpopup_Reload();
			}
		}
	});
}

//ajouter un favoris
function fav_add() {
	if (!statut) {
		return false;
	}

	$.ajax({
		type: "GET",
		url: chemin + "/scripts/ajax/favoris.php",
		data: "action=add&titreFav="+esc(titre_cours)  + "&pageFav="+esc(page_cours) ,
		success: function(string){
			if (string == "1") {
				JQpopup_Reload();
			} else {
				alert("Erreur : " + string);
			}
		}
	});
}

//supprimer un favoris
function del_fav(id) {
	if (!statut) {
		return false;
	}
	$.ajax({
		type: "GET",
		url: chemin + "/scripts/ajax/favoris.php",
		data: "action=del&idFav="+esc( id ) ,
		success: function(string){
			if (string == "1") {
				JQpopup_Reload();
			} else {
				alert("Erreur");
			}
		}
	});
}
