﻿// ****************************************  reroot sur index pour user non VIP ****************************************
$(document).ready(function(){
	if($("#core").hasClass("adminRewards")){
		//cas particulier interface admin des cadeaux gestion dans chaque page par webbox TpCustomerRole
	}
	else if(gTypeProfile != "VIP" && !document.getElementById("aniflash") && !document.getElementById("noreroot")){
		top.location.replace("/_pl/_pl/club-vip/index.aspx");
	}
});

// **************************************** LEFT NAV ****************************************
$(document).ready(function(){
	$('#VIPNav > li > a').click(function(e){
		if($(this).next('ul').hasClass('ssmenus')){
			var zedisplay = ($(this).next('ul').css('display') == 'block') ? 'none' : 'block';
			$('#VIPNav > li > ul').slideUp('fast');
			if(zedisplay == 'block') $(this).next('ul').slideDown('slow');
			if(zedisplay == 'none') $(this).next('ul').slideUp('slow');
			e.preventDefault();
		}
	});
	if(gUserVisible != "1"){
		//on n'affiche pas le nombre d'ami si gUserVisible != 1
		$("#perso .nbfriends").hide();
		//on n'affiche pas le menu VIP_myNetwork de la nav
		$("#menu_VIP_myNetwork").hide();
	}
	//mood focus et blur
	if(document.getElementById("user_mood")){
		var initMood = $("#user_mood").attr("value");
		$("#user_mood").focus(function(){
			if($(this).attr("value") == initMood){
				$(this).attr("value", "");
			}
		});
		$("#user_mood").blur(function(){
			if($(this).attr("value") == ""){
				$(this).attr("value", initMood);
			}
		});
	}
	$('#submit a').filter(function() {
	    return (this.className.indexOf('1_Login') > -1);
	}).click(function(e) {
	    e.preventDefault();
	    LOP.openExpandVIP();
	});
});
// **************************************** FIN LEFT NAV ****************************************


// **************************************** OUVERTURE ET FERMETURE POPIN ****************************************
//pour creer une popin identifiee par id et classe
function createPopinCib(id, classe){
	//creation div cible uniquement si n'existe pas deja...
	if(!$("#"+id).length){
		var cib = '<div id="'+id+'" class="'+classe+'"></div>';
		if(document.getElementById("main")){
			$(cib).appendTo("#main");
		}
		else if (document.getElementById("registerForm")){
			$(cib).appendTo("#registerForm");
		}
	}
}
//pour fermer une popin identifie par un ID
function closePopin(id){
	var callback = function(){
		$("#"+id).remove();
	}
	$("#"+id).fadeOut("slow", callback);
}
// **************************************** FIN OUVERTURE ET FERMETURE POPIN ****************************************


// **************************************** OUVERTURE POPIN SIGN-IN DEPUIS GALAXY FLASH ****************************************
LOP.openSignInFromFlash = function() {
    LOP.execStatCM(vipStats.signIn);
    LOP.popins.add({
        url: '#popinSignIn',
        id: 'signIn',
        processHTML: LOP.processHTMLPopins,
        refresh: false
    });
};
// **************************************** FIN OUVERTURE POPIN SIGN-IN DEPUIS GALAXY FLASH ****************************************


// **************************************** POPIN PROFILE ****************************************
function setUserAge(){
	//affiche l'age du FRIEND dans sa popin
	var laDate = $("#popinCib .birthdate").text().split(" ")[0];
	var today = new Date();
	var birth = get_Date(laDate);
	var age = tjs_age(laDate);
	//$("#popinCib .birthdate").text(laDate + ", " + age);
	$("#popinCib .birthdate").text(age);
}
function setLastVisit(){
	//affiche la date de derniere visite du FRIEND (en reperant la valeur de la EP "LastVisitedDate" ecrite dans <span class="lastvisit">)
	var lastvisit = $("#popinCib .lastvisit").text();
	var laDate_arr = lastvisit.split("-");
	var laDate = laDate_arr[2] + "/" + laDate_arr[1] + "/" + laDate_arr[0];
	var heure = laDate_arr[3] + "h" + laDate_arr[4];
	$("#popinCib .lastvisit").text(laDate + ", " + heure);
}
//ouverture popin profil
function seeProfile(id){
	var classe = "popinProfile";
	//callback apres chargement AJAH
	var callback = function(msg){
	    LOP.execStatCM(vipStats.seeProfile);
		setUserAge(); //affichage age
		setLastVisit(); //affichage date derniere visite
		$("#popinCib").attr("class", "");
		$("#popinCib").addClass(classe);
		$("#popinCib").fadeIn("slow");
		//drag
		if(!navig.IE6){
			var dragPopin = new BOX.SimpleDrag({
				'root': '#popinCib',
				'handle': '#popinTitle',
				'minX': -200,
				'minY': 78,
				'maxX': 814,
				'maxY': 350// - $("#popinCib").height()
			});
		}
	}
	//creation cible pour popin
	createPopinCib("popinCib", classe);
	//chargement page HTML dans cible via AJAH
	$("#popinCib").load(gVIPpath + "popins/profile.aspx?id="+id, callback);
	return false;
}
// **************************************** FIN POPIN PROFILE ****************************************

// **************************************** POPIN join-community ****************************************
function joinCommunity(id){
	//ouverture popin de confirmation
	var classe = "popinRemoveFriends";
	//callback apres chargement AJAH
	var zid = id;
	var callback = function(msg){
	    LOP.execStatCM(vipStats.joinCommunity);
		//action bouton YES
		$("#popinCib #yesbtn").click(function(e){
			var callback2 = function(){
				top.location.reload();
			}
			majCustomerProp(zid, "VIP_visible_profile", "1", "int", callback2);
			e.preventDefault();
		});
		$("#popinCib").attr("class", "");
		$("#popinCib").addClass(classe);
		$("#popinCib").fadeIn("slow");
		//drag
		if(!navig.IE6){
			var dragPopin = new BOX.SimpleDrag({
				'root': '#popinCib',
				'handle': '#popinTitle',
				'minX': -200,
				'minY': 78,
				'maxX': 814,
				'maxY': 350// - $("#popinCib").height()
			});
		}
	}
	//creation cible pour popin
	createPopinCib("popinCib", classe);
	//chargement page HTML dans cible via AJAH
	$("#popinCib").load(gVIPpath + "popins/join-community.aspx?id="+id, callback);
	return false;
}
// **************************************** FIN POPIN join-community ****************************************

// **************************************** POPIN MESSAGES ERREUR****************************************
function openPopinMessage(titre, texte, secondcallback){
	var popinTitle = titre;
	var popinText = texte;
	var classe = "popinMessages";
	var callback2 = secondcallback;
	//callback apres chargement AJAH
	var callback = function(msg){
		$("#popinCib #popinTitle").html(popinTitle);
		$("#popinCib .content").html(popinText);
		$("#popinCib").attr("class", "");
		$("#popinCib").addClass(classe);
		$("#popinCib").fadeIn("slow");
		if(callback2) callback2.apply();
		//drag
		if(!navig.IE6){
			var dragPopin = new BOX.SimpleDrag({
				'root': '#popinCib',
				'handle': '#popinTitle',
				'minX': -200,
				'minY': 78,
				'maxX': 814,
				'maxY': 350// - $("#popinCib").height()
			});
		}
	}
	//creation cible pour popin
	createPopinCib("popinCib", classe);
	//chargement page HTML dans cible via AJAH
	$("#popinCib").load(gVIPpath + "popins/messages.aspx", callback);
	return false;
}
// **************************************** FIN POPIN MESSAGES ERREUR****************************************

// **************************************** POPIN FRIEND REQUEST ****************************************
//ouverture popin profil
function openPopinRequest(id){
	//callback apres chargement AJAH
	var classe = "popinRequest";
	var callback = function(msg){
	    LOP.execStatCM(vipStats.requestFriendship);
		setUserAge(); //affichage age
		$("#popinCib").attr("class", "");
		$("#popinCib").addClass(classe);
		$("#popinCib").fadeIn("slow");
		var initMessage = $("#message").text();
		$("#message").focus(function(){
			if($(this).text() == initMessage){
				$(this).text("");
			}
		});
		$("#message").blur(function(){
			if($(this).text() == ""){
				$(this).text(initMessage);
			}
		});
		//drag
		if(!navig.IE6){
			var dragPopin = new BOX.SimpleDrag({
				'root': '#popinCib',
				'handle': '#popinTitle',
				'minX': -200,
				'minY': 78,
				'maxX': 814,
				'maxY': 350
			});
		}
	}
	//creation cible pour popin
	createPopinCib("popinCib", classe);
	//chargement page HTML dans cible via AJAH
	$("#popinCib").load(gVIPpath + "popins/request-friendship.aspx?id="+id, callback);
	return false;
}
// **************************************** FIN POPIN FRIEND REQUEST ****************************************


// **************************************** POPIN ANSWER MESSAGE****************************************
//ouverture popin profil
function openAnswer(id){
	//callback apres chargement AJAH
	var classe = "popinRequest";
	var callback = function(msg){
	    LOP.execStatCM(vipStats.answerPost);
		setUserAge(); //affichage age
		$("#popinCib").attr("class", "");
		$("#popinCib").addClass(classe);
		$("#popinCib").fadeIn("slow");
		var initMessage = $("#message").text();
		$("#message").focus(function(){
			if($(this).text() == initMessage){
				$(this).text("");
			}
		});
		$("#message").blur(function(){
			if($(this).text() == ""){
				$(this).text(initMessage);
			}
		});
		//drag
		if(!navig.IE6){
			var dragPopin = new BOX.SimpleDrag({
				'root': '#popinCib',
				'handle': '#popinTitle',
				'minX': -200,
				'minY': 78,
				'maxX': 814,
				'maxY': 350
			});
		}
	}
	//creation cible pour popin
	createPopinCib("popinCib", classe);
	//chargement page HTML dans cible via AJAH
	$("#popinCib").load(gVIPpath + "popins/answer-message.aspx?id="+id, callback);
	return false;
}
// **************************************** FIN POPIN FRIEND REQUEST ****************************************

// **************************************** COMBOBOX ****************************************
$(document).ready(function(){	
	var D = this.document;
    var combobox = $('.combobox');
    var comboboxList = $('ul', combobox);
    //comboboxList.css("bottom", 17);
    var open = function() {
        comboboxList.removeClass('off');
        $(D).bind('mousedown.pagination', function(e) {
            var t = e.target;
            while (t != combobox[0] && (t = t.parentNode));
            if (t != combobox[0]) {
                close();
            }
        });
    };   
    var close = function() {
        comboboxList.addClass('off');
        $(D).unbind('mousedown.pagination');
    };   
    var manageClick = function(e) {
        var t = e.target;
        if (t.nodeName.toLowerCase() == 'span') {
            if (comboboxList.hasClass('off')) {
                open();
            } else {
                close();
            }
        }
    };
    combobox.click(manageClick);
});
// **************************************** FIN COMBOBOX ****************************************


// **************************************** cases a cocher ****************************************
var gSelectedPosts = new Array();
//gSelectedPost va contenir les IDs des posts selectionnes par les cases a cocher.
var gSelectedFriendsPosts = new Array();
//gSelectedFriendsPosts va contenir les IDs des posts des friends selectionnes par les cases a cocher...
//utilise pour creation d'une paire d'amis et pour le send-message a plusieurs amis
function checkSelect(postId, that){
	var ozerID = $(that).attr("id").split("_")[1];
	if($(that).hasClass("off")){
		if(postId != null) gSelectedPosts.push(postId);
		if(ozerID) gSelectedFriendsPosts.push(ozerID);
		$(that).removeClass("off");
		$(that).addClass("on");
	}
	else{
		if(postId != null) {
			var poz = jQuery.inArray(postId, gSelectedPosts);
			gSelectedPosts.splice(poz, 1);
		}
		if(ozerID){
			var poz = jQuery.inArray(ozerID, gSelectedFriendsPosts);
			gSelectedFriendsPosts.splice(poz, 1);
		}
		$(that).removeClass("on");
		$(that).addClass("off");
	}
}
// **************************************** FIN cases a cocher ****************************************


// **************************************** VIP Card addPoints ****************************************
function addPoints(action, val, what){
	//action=TellAfriend, Join, Buy, Diag... (ou plusieurs actions separees par ;)
	//val: prix d'un reward quand action:Buy
	//what: nom du reward (Container_Topic.Name du Topic reward correspondant)
	var acted = action;
	var prix = parseInt(val, 10);
	var reward = what;
	var callback = function(msg, textStatus, XMLHttpRequest){
		var msg = (typeof selector == "string") ? msg : msg.toString();//on transforme le msg en string 
		if(acted == "Buy"){
			if(msg.indexOf("status=TRUE")>=0){
				//popin message OK
				LOP.execStatCM(vipStats.confirmReward);
				openPopinMessage(gLabels.confirmation, gLabels.rewardBought.replace("XXXrewardXXX", reward));
				//maj boutons "buy"
				gUserPoints = parseInt(gUserPoints, 10) - prix;
				var prices_arr = $("#segmentedItems .item .button a");
				for(var i=0; i<prices_arr.length; i++){
					var price = $(prices_arr[i]).attr("id").split("_")[1];
					//on cache les boutons "buy" des cadeaux dont le prix est superieur aux points du user
					if(parseInt(price, 10) > parseInt(gUserPoints, 10) || gUserPoints == "" || !gUserPoints){
						$(prices_arr[i]).parent().fadeOut();
					}
				}
				//maj points navgauche
				$("#VIPcard .myPoints").html(gUserPoints);
				//envoi du mail de confirmation
				sendMailReward(gUserPoints, reward, prix);
			}
			else{
				openPopinMessage(gLabels.error, gLabels.rewardError);
			}
		}
		else{
			//maj des points dans la navgauche
			var param_arr = msg.split("&");
			var zobj = new Object();
			for(var i=0; i<param_arr.length; i++){
				var param = param_arr[i].split("=");
				zobj[param[0]] = param[1];
			}
			if(zobj.addedPoints){
				var addedPoints = parseInt(zobj.addedPoints, 10);
				gUserPoints = parseInt(gUserPoints, 10) + addedPoints;
				$("#VIPcard .myPoints").html(gUserPoints);
			}
		}
	}
	$.ajax({
		type: "GET",
		url: gVIPpath + "webboxtools/add-points.aspx",
		data: "rules="+action+"&price="+val,
		success: callback
	});
}

// **************************************** fin VIP Card addPoints****************************************
// **************************************** VIP CARD POPIN HOW TO EARN****************************************
function openHowToEarn(){
	var classe = "popinEarn";
	//callback apres chargement AJAH
	var callback = function(msg){
	    LOP.execStatCM(vipStats.howToEarnPoints);
		$("#popinCib").attr("class", "");
		$("#popinCib").addClass(classe);
		$("#popinCib").fadeIn("slow");
		//drag
		if(!navig.IE6){
			var dragPopin = new BOX.SimpleDrag({
				'root': '#popinCib',
				'handle': '#popinTitle',
				'minX': -200,
				'minY': 78,
				'maxX': 814,
				'maxY': 520 - $("#popinCib").height()
			});
		}
	}
	//creation cible pour popin
	createPopinCib("popinCib", classe);
	//chargement page HTML dans cible via AJAH
	$("#popinCib").load(gVIPpath + "popins/vip-card-how-to-earn.aspx", callback);
	return false;
}
// **************************************** FIN VIP CARD POPIN HOW TO EARN****************************************

// **************************************** ADD TO FAVORITES ****************************************
function addToFavorites(typ, that){
	var code =  $(that).attr("id").split("#")[1];
	var callback = function(msg, textStatus, XMLHttpRequest){
		var msg = (typeof selector == "string") ? msg : msg.toString();//on transforme le msg en string 
		openPopinMessage(gLabels.confirmation, gLabels.favoriteAdded);
	}
	$.ajax({
		type: "GET",
		url: "/_pl/_pl/tools/add-to-favorites.aspx",
		data: "type=product&code="+code,
		success: callback
	});
}
// **************************************** FIN ADD TO FAVORITES ****************************************


// **************************************** TELL A FRIEND ****************************************
var gTellAFriendXMLString = '<Loreal_Reference_IN_TellAFriend>';
gTellAFriendXMLString += '<SessionID><![CDATA['+gUserId+']]></SessionID>';
gTellAFriendXMLString += '<Customer>';
gTellAFriendXMLString += '<FirstName><![CDATA['+gUserFirstName+']]></FirstName>';
gTellAFriendXMLString += '<LastName><![CDATA['+gUserLastName+']]></LastName>';
gTellAFriendXMLString += '<Email><![CDATA['+gUserEmail+']]></Email>';
gTellAFriendXMLString += '</Customer>';
gTellAFriendXMLString += '<Friend>';
gTellAFriendXMLString += '<FirstName><![CDATA[XXXfriendFirstNameXXX]]></FirstName>';
gTellAFriendXMLString += '<Email><![CDATA[XXXfriendEmailXXX]]></Email>';
gTellAFriendXMLString += '</Friend>';
gTellAFriendXMLString += '<TemplateName><![CDATA[XXXmailXMLXXX]]></TemplateName>';
gTellAFriendXMLString += '<Customs>';
gTellAFriendXMLString += '<Message><![CDATA[XXXmessageXXX]]></Message>';
gTellAFriendXMLString += '<PostId><![CDATA[XXXPostIdXXX]]></PostId>';
gTellAFriendXMLString += '<Points><![CDATA[XXXPointsXXX]]></Points>';
gTellAFriendXMLString += '<Reward><![CDATA[XXXRewardXXX]]></Reward>';
gTellAFriendXMLString += '<Price><![CDATA[XXXPriceXXX]]></Price>';
gTellAFriendXMLString += '<Path><![CDATA['+gServerURL+']]></Path>';
gTellAFriendXMLString += '</Customs>';
gTellAFriendXMLString += '</Loreal_Reference_IN_TellAFriend>';
// **************************************** FIN TELL A FRIEND ****************************************

// **************************************** INVITE A FRIEND ****************************************
function inviteFromSearch(){
var classe = "popinFromGalaxy";
	//callback apres chargement AJAH
	var callback = function(msg){
        LOP.execStatCM(vipStats.inviteAFriend);
		//on masque le bas de la popin
		$("#searchVIP").remove();
		//fin masquage
		$("#popinInvite").attr("class", "");
		$("#popinInvite").addClass(classe);
		$("#popinInvite").fadeIn("slow");
		var initMessage = $("#invite_message").text();
		$("#invite_message").focus(function(){
			if($(this).text() == initMessage){
				$(this).text("");
			}
		});
		
		$("#invite_message").blur(function(){
			if($(this).text() == ""){
				$(this).text(initMessage);
			}
		});
		//drag
		if(!navig.IE6){
			var dragPopin = new BOX.SimpleDrag({
				'root': '#popinInvite',
				'handle': '#popinInviteTitle',
				'minX': -200,
				'minY': 78,
				'maxX': 814,
				'maxY': 520 - $("#popinInvite").height()
			});
		}
	}
	//creation cible pour popin
	createPopinCib("popinInvite", classe);
	//chargement page HTML dans cible via AJAH
	$("#popinInvite").load(gVIPpath + "popins/invite-a-friend.aspx", callback);
}
function inviteFromGalaxy(){
	var classe = "popinFromGalaxy";
	//callback apres chargement AJAH
	var callback = function(msg){
        LOP.execStatCM(vipStats.inviteAFriend);
		$("#popinInvite").attr("class", "");
		$("#popinInvite").addClass(classe);
		$("#popinInvite").fadeIn("slow");
		var initMessage = $("#invite_message").text();
		$("#invite_message").focus(function(){
			if($(this).text() == initMessage){
				$(this).text("");
			}
		});
		$("#invite_message").blur(function(){
			if($(this).text() == ""){
				$(this).text(initMessage);
			}
		});
		//drag
		if(!navig.IE6){
			var dragPopin = new BOX.SimpleDrag({
				'root': '#popinInvite',
				'handle': '#popinInviteTitle',
				'minX': -200,
				'minY': 78,
				'maxX': 814,
				'maxY': 520 - $("#popinInvite").height()
			});
		}
	}
	//creation cible pour popin
	createPopinCib("popinInvite", classe);
	//chargement page HTML dans cible via AJAH
	$("#popinInvite").load(gVIPpath + "popins/invite-a-friend.aspx", callback);
}
function sendInvitation(){
	//test saisies
	var valid = true;
	var alertText = "";
	if(document.getElementById("invite_firstname").value == ""){
		valid = false;
		alertText = gLabels.noFirstName;
	}
	if(document.getElementById("invite_mail").value == ""){
		valid = false;
		alertText += (alertText == "") ? gLabels.noMail : "<br/>" + gLabels.noMail;
	}
	else if(!isEmail(document.getElementById("invite_mail").value)){
		valid = false;
		alertText += (alertText == "") ? gLabels.incorrectMail : "<br/>" + gLabels.incorrectMail;
	}
	if(valid){
		sendMailInvitation();
	}
	else{
		openPopinMessage(gLabels.error, alertText);
	}
}
function sendMailInvitation(){
	//appel WS tellAFriend
	var message = document.getElementById("invite_message").value;
	var leStringXML = gTellAFriendXMLString.replace("XXXfriendFirstNameXXX", document.getElementById("invite_firstname").value).replace("XXXfriendEmailXXX", document.getElementById("invite_mail").value).replace("XXXmailXMLXXX", gInviteAFriendXSL).replace("XXXmessageXXX", message);
	var inputDataText = leStringXML;
	var inputData = XML.parse(inputDataText);
	var callback = function(msg){
		var xmldata = msg; // le msg retourne par les WS est deja un objet XML
		if(xmldata.getElementsByTagName("Loreal_Reference_OUT_OK")[0]){
			openPopinMessage(gLabels.confirmation, gLabels.messageSent)
			//on efface les textes saisis dans la popin d'invitation
			document.getElementById("invite_firstname").value = "";
			document.getElementById("invite_mail").value = "";
			document.getElementById("invite_message").value = "";
			$("#invite_message").blur();
		}
		else{
			//erreur WS
			var error = xmldata.getElementsByTagName("Message")[0].firstChild.data;
			openPopinMessage(gLabels.error, error);
		}
	}
	$.ajax({
		type: "POST",
		url: "../../../ws/Customer.asmx/TellAFriend",
		data: "inputData="+inputDataText,
		success: callback
	});
	return false;
}
function inviteAFriend(){
	inviteFromGalaxy();
}
// **************************************** FIN INVITE A FRIEND ****************************************


// [[[[[[[[[[[[[[[[[[[[[[[ **************************************** ONDOMLOAD **************************************** ]]]]]]]]]]]]]]]]]]]]]]]]]]]
// **************************************** FAVORIS ****************************************
$(document).ready(function(){
	if($("#core").hasClass("favorites")){
		if(gUserVisible == "1"){
			if(parseInt(gMyFriendsNb, 10) > 0){
				$("#core .btnReco").show();
				$("#core .btnReco").fadeIn();
			}
		}
	}
	//scrolls
	XLprepareFavoritesScroll();
});
// scroll specific execution
var XLscrollFavoritesActions = {
	favoritesProductsList: function(el, id) {
	       LOP.scrollActions.horizontal({
	           'node': el,
	           'id': id,
	           'scrollTarget': '#products',
           		'scrollOffsetTarget': 'h2',
	           'itemWidth': 240,
	           'totalWidth': 720,
	           'scrollMargin': 10,
	           'visibleOnLine': 4
	       });
	   },
	   favoritesMediasList: function(el, id) {
	       LOP.scrollActions.horizontal({
	           'node': el,
	           'id': id,
	           'scrollTarget': '#medias',
           		'scrollOffsetTarget': 'h2',
	           'itemWidth': 240,
	           'totalWidth': 720,
	           'scrollMargin': 10
	       });
	   }
};
// prepare and create scroll
var XLprepareFavoritesScroll = function() {
	var id, forceScroll;
	$('body .scroll').each(function() {
		var id = BOX.getStoreId(this);
		if (XLscrollFavoritesActions[id]) {
			XLscrollFavoritesActions[id](this, id);
		}
	});
};

// **************************************** FIN FAVORIS ****************************************


// **************************************** INBOX ****************************************
$(document).ready(function(){
	//remplacer les sauts de ligne par des <br/>
	if($("#core").hasClass("myInbox") && $("#core").hasClass("message")){
		var text = $("#inboxList .messageText").text();
		//sauts de lignes "\r\n"
		var htmlText = text.replace(/(\r\n|[\r\n])/g, "<br/>");
		//sauts de lignes string escaped
		var reg = new RegExp("%0A", "g");
		htmlText = htmlText.replace(reg, "<br/>");
		//sauts de lignes ruse de chacal pour friend-request
		var reg = new RegExp("XOXOXO", "g");
		htmlText = htmlText.replace(reg, "<br/>");
		htmlText = unescape(htmlText);
		$("#inboxList .messageText").html(htmlText);
		//Et encoder le href du bouton retour pour éviter les bugs lors du traitement des filtres presents dans l'URL
		//en effet, les filtres contiennent des signes "=" et font foirer la boucle javascript de recuperation des params d'URL...
		var hurle = $("#backbtn").attr("href");
		var indice = hurle.indexOf("filtres=")+8;
		var reg = new RegExp("=", "g");//%3D : signe égal = 
		var filtres = hurle.substring(indice, hurle.length).replace(reg, "%3D");
		var niouhurle = hurle.substring(0, indice) + filtres;
		$("#backbtn").attr("href", niouhurle);
		
		if(document.getElementById("accepted")){
			var req_friend = $(".accept").attr("id").split("_")[1];
			var regalMatch = false;
			for(var u=0; u<gMyFriends.length; u++){
				if(req_friend == gMyFriends[u]){
					$("#req_" + req_friend).hide();
					regalMatch = true;
					break;
				}
			}
			if(!regalMatch){
				
			}
		}
		//gestion ancien ami qui n'est plus un ami (ou demande qui n'est pas encore acceptee) et  friend-request en double
		var rep_friend = $(".answer").attr("id").split("_")[1];
		var regaloebMatch = false;
		for(var u=0; u<gMyFriends.length; u++){
			if(rep_friend == gMyFriends[u]){
				regaloebMatch = true;
				//gestion friend-request en double, on cache le bouton "accepter" qd sender est un deja ami
				if(document.getElementById("accepted")){
					$("#req_" + rep_friend).hide();
				}
				break;
			}
		}
		if(!regaloebMatch){
			$("#rep_" + rep_friend).parent().hide();//on cache le bouton "repondre"
			$("#accepted").hide();//on cache le bouton "demande acceptee"
		}
	}
	else if($("#core").hasClass("myInbox")){
		$("#inboxList .message a").each(function(){
			var text = $(this).text();
			var htmlText = text.replace(/(\r\n|[\r\n])/g, "<br/>");
			var reg = new RegExp("%0A", "g");
			htmlText = htmlText.replace(reg, "<br/>");
			var reg = new RegExp("XOXOXO", "g");
			htmlText = htmlText.replace(reg, "<br/>");
			htmlText = unescape(htmlText);
			$(this).html(htmlText);
		});
	}
});
// **************************************** FIN INBOX ****************************************


// **************************************** onDomLoad pages segmented pour gestion affichage boutons "recommend"  ****************************************
$(document).ready(function(){
	if(document.getElementById("segmentedItems")) {
		//gMyFriends: Array contenant tous les amis du user (initialise dans js/personalDatas.html)
		if(gMyFriends.length != 0 && gUserVisible == "1"){
			$("#segmentedItems .recobtn").fadeIn();
		}
	}
});
// **************************************** fin onDomLoad pages segmented ****************************************



// **************************************** GESTION DES POINTS POUR RECO  ****************************************
$(document).ready(function(){
	if(document.getElementById("recommendation")) {
		var param_arr = top.location.search.substr(1).split("&");
		var zobj = new Object();
		for(var i=0; i<param_arr.length; i++){
			var param = param_arr[i].split("=");
			zobj[param[0]] = param[1];
		}
		if(zobj.backFromProcess == "1"){
			addPoints("TELLAFRIEND");
		}
	}
});
// **************************************** FIN GESTION DES POINTS POUR RECO  ****************************************
