// JavaScript Document

function OpenUserAccountPopup(e)
{
	if (user == null)
	{
		OpenIdentDiv(e);
	}
	else if (user.anonymous)
	{
		alert("Cette section est réservée aux membres");
	}
	else
	{
		var content = CreateWindow("UserAccountWindow", "Mon compte", "CloseUserAccountPopup()", null, 350, 450, "#c0c0c0");
		content.style.backgroundColor = "#c0c0c0";
		
		var table = document.createElement("table"); table.cellSpacing = 0; table.cellPadding = 0;
			table.style.width = "100%"; table.style.height = "100%";
		var tr = table.insertRow(-1);
		var td = tr.insertCell(-1); td.style.fontSize = "1px"; td.style.width = "28px"; td.vAlign = "top";
			var inTb = document.createElement("table"); inTb.cellPadding = 0; inTb.cellSpacing = 0; inTb.style.height = "100%";
			var inTr = inTb.insertRow(-1);
			var inTd = inTr.insertCell(-1); inTd.style.cursor = "pointer"; inTd.id = "general";
				inTd.enabled = true;
				inTd.onclick = function() { SelectAccountOnglet(this); }
				inTd.innerHTML = "<img src=\"img/onglets/general_on.jpg\" />";
			var inTr = inTb.insertRow(-1);
			var inTd = inTr.insertCell(-1); inTd.style.cursor = "pointer"; inTd.id = "classement";
				inTd.enabled = false;
				inTd.onclick = function() { SelectAccountOnglet(this); }
				inTd.innerHTML = "<img src=\"img/onglets/classement_off.jpg\" />";
			var inTr = inTb.insertRow(-1);
			var inTd = inTr.insertCell(-1); inTd.style.cursor = "pointer"; inTd.id = "historique";
				inTd.enabled = false;
				inTd.onclick = function() { SelectAccountOnglet(this); }
				inTd.innerHTML = "<img src=\"img/onglets/historique_off.jpg\" />";
			var inTr = inTb.insertRow(-1);
			var inTd = inTr.insertCell(-1); inTd.style.cursor = "pointer"; inTd.id = "facturation";
				inTd.enabled = false;
				inTd.onclick = function() { SelectAccountOnglet(this); }
				inTd.innerHTML = "<img src=\"img/onglets/facturation_off.jpg\" />";
			var inTr = inTb.insertRow(-1);
			var inTd = inTr.insertCell(-1); inTd.style.height = "100%";
				inTd.innerHTML = "&nbsp;";
				inTd.style.background = "url('img/onglets/pad.jpg')";
			
		td.appendChild(inTb);
		
		var td = tr.insertCell(-1); td.style.width = "100%"; td.style.backgroundColor = "#ebebeb"; td.vAlign = "top";
		var divGeneral = document.createElement("div"); divGeneral.id = "div_general"; divGeneral.style.paddingTop = "4px";
			divGeneral.style.width = "100%";
			divGeneral.style.overflow = "auto"; divGeneral.style.height = "450px";
			divGeneral.innerHTML = "Chargement";
		td.appendChild(divGeneral);
		
		var divClassement = document.createElement("div"); divClassement.id = "div_classement"; divClassement.style.paddingTop = "4px";
			divClassement.innerHTML = "divClassement"; divClassement.style.display = "none";
			divClassement.style.overflow = "auto"; divClassement.style.height = "450px";
		td.appendChild(divClassement);
		
		var divHistorique = document.createElement("div"); divHistorique.id = "div_historique"; divHistorique.style.paddingTop = "4px";
			divHistorique.innerHTML = "Chargement en cours..."; divHistorique.style.display = "none";
		td.appendChild(divHistorique);
		
		var divFacturation = document.createElement("div"); divFacturation.id = "div_facturation";
		divFacturation.style.padding = "5px";
			divFacturation.innerHTML = "Cette fonctionnalit&eacute;e n'est pas disponible pour le moment.<br><br>Celle ci vous permettra de demander la facturation de vos gains, gagn&eacute;s gr&acirc;ce &agrave; vos paris.<br><br>Le syst&egrave;me de pari sera mis en place lorsque suffisament de joueurs auront demand&eacute; le cr&eacute;dit de leur compte (section \"Mon compte\" -> \"G&eacute;n&eacute;ral\") pour nous permettre la mise en place du syst&egrave;me de paiement en ligne."; 
		divFacturation.style.display = "none";
		td.appendChild(divFacturation);
		
		content.appendChild(table);
		
		LoadGeneralAccountInformations();
	}
}

function CloseUserAccountPopup()
{
	var popup = document.getElementById("UserAccountWindow");
	if (popup)
	{
		document.body.removeChild(popup);	
	}
}

function SelectAccountOnglet(td)
{
	if (td.enabled == true) return;
	
	//First select onglet
	td.enabled = true;
	td.innerHTML = "<img src=\"img/onglets/" + td.id + "_on.jpg\" />";
	var div = document.getElementById("div_" + td.id); div.style.display = "";
	
	//Deselect others
	if (td.id != "general")
	{
		var atd = document.getElementById("general"); atd.enabled = false; atd.style.cursor = "pointer";
		atd.innerHTML = "<img src=\"img/onglets/general_off.jpg\" />";
		var adiv = document.getElementById("div_general"); adiv.style.display = "none";
	}
	
	if (td.id != "classement")
	{
		var atd = document.getElementById("classement"); atd.enabled = false; atd.style.cursor = "pointer";
		atd.innerHTML = "<img src=\"img/onglets/classement_off.jpg\" />";
		var adiv = document.getElementById("div_classement"); adiv.style.display = "none";
	}
	else
	{
		AccountClassementConstruct();	
	}
	
	if (td.id != "historique")
	{
		var atd = document.getElementById("historique"); atd.enabled = false; atd.style.cursor = "pointer";
		atd.innerHTML = "<img src=\"img/onglets/historique_off.jpg\" />";
		var adiv = document.getElementById("div_historique"); adiv.style.display = "none";
	}
	else
	{
		AccountHistoryConstruct();	
	}
	
	if (td.id != "facturation")
	{
		var atd = document.getElementById("facturation"); atd.enabled = false; atd.style.cursor = "pointer";
		atd.innerHTML = "<img src=\"img/onglets/facturation_off.jpg\" />";
		var adiv = document.getElementById("div_facturation"); adiv.style.display = "none";
	}
}

function LoadGeneralAccountInformations()
{
	var params = new Array();
    params.push(new WSParams("login", user.userName));
	
    AjaxRequest("sawale_ws.php", OnLoadGeneralAccountInformations, "GetUserInformations", params, "robatmac/Awale");
}

function OnLoadGeneralAccountInformations(obj)
{
	if (obj == null)
	{
		alert("Erreur de chargement");
		return;
	}
	
	var divGeneral = document.getElementById("div_general");
	
	var html = new Array();
	html.push("<table style=\"width:99%\" cellpadding=1 cellspacing=1 bgcolor=\"#666666\">");
	html.push("<tr><td class=Title1 style=\"height:20px\">Vos coordonn&eacute;es</td></tr>");
	html.push("<tr><td><table style=\"width:100%\" cellpadding=0 cellspacing=1 style=\"table-layout:fixed\" bgcolor=\"#ebebeb\">");
	html.push("<colgroup><col style=\"width:85px\" /><col style=\"width:66px\" /><col /></colgroup>");
	html.push("<tr><td colspan=2 class=Title3 valign=bottom>Nom</td><td class=Title3 valign=bottom>Pr&eacute;nom</td></tr><tr><td colspan=2><input type=text id=\"AccountFirstName\" class=InputAccount value='");
		if (obj.FirstName != "undefined") html.push(InnerEnc(obj.FirstName));
		
	html.push("'></td><td><input type=text class=InputAccount id=\"AccountLastName\" value='");
		if (obj.LastName != "undefined") html.push(InnerEnc(obj.LastName)); html.push("'></td></tr>");
	html.push("<tr><td colspan=3 class=Title3 valign=bottom>Adresse</td></tr><tr><td colspan=2><input type=text id=\"AccountAdresse1\" class=InputAccount value='");
		if (obj.Adresse1 != "undefined") html.push(InnerEnc(obj.Adresse1));
	html.push("'></td><td><input type=text class=InputAccount id=\"AccountAdresse2\" value='");
		if (obj.Adresse2 != "undefined") html.push(InnerEnc(obj.Adresse2));
	html.push("'></td></tr>");
	html.push("<tr><td class=Title3 valign=bottom>Code postal</td><td colspan=2 class=Title3 valign=bottom>Ville</td></tr><tr><td><input type=text class=InputAccount id=\"AccountZipCode\" value=\"");
		if (obj.ZipCode != "undefined") html.push(InnerEnc(obj.ZipCode));
	html.push("\"></td><td colspan=2><input type=text class=InputAccount style=\"width:93%\" id=\"AccountTown\" value='");
		if (obj.Town != "undefined") html.push(InnerEnc(obj.Town));
	html.push("'></td></tr>");
	html.push("<tr><td class=Title3 valign=bottom colspan=3>Pays</td></tr><tr><td colspan=3><select id=\"AccountCountry\" class=InputAccount><option value=\"France\" ");
		if (obj.Country == "France") html.push("selected");
	html.push(">France</option></select></td></tr>");
	html.push("<tr><td colspan=3>&nbsp;</td></tr>");
	html.push("<tr><td colspan=3 align=center><button id=\"BtAccountInfos\" onclick=\"SaveUserAccountInfos(this);\">Enregistrer</button></td></tr>");
	
	
	html.push("</table></td></tr>");
	html.push("<tr><td class=Title1 style=\"height:20px\">Identification</td></tr>");
	html.push("<tr><td><table style=\"width:100%\" cellpadding=0 cellspacing=1 style=\"table-layout:fixed\" bgcolor=\"#ebebeb\">");
	html.push("<colgroup><col style=\"width:60px\" /><col style=\"width:60px\" /><col style=\"width:80px\" /><col  /></colgroup>");
	html.push("<tr><td colspan=4 class=Title3 valign=bottom>Pseudo</td></tr><tr><td colspan=4><input type=text class=InputAccount disabled value='");
		html.push(InnerEnc(user.userName));
	html.push("'></td></tr>");
	html.push("<tr><td colspan=4 class=Title3 valign=bottom>Mot de passe</td></tr><tr><td colspan=4><input type=password class=InputAccount id='AccountNewPassword'></td></tr>");
	html.push("<tr><td colspan=4 class=InfoBlack valign=bottom>6 caract&egrave;res minimum - Laisser vide pour ne pas modifier</td></tr>");
	html.push("<tr><td colspan=4 class=Title3 valign=bottom>Adresse e-mail</td></tr><tr><td colspan=4><input type=text id='AccountEmail' class=InputAccount value='");
		if (obj.Mail != "undefined") html.push(obj.Mail);
	html.push("'></td></tr>");
	
	var bornDay = ((obj.BornDate != "undefined") && (obj.BornDate != null)) ? obj.BornDate : "";
	
	var tab = bornDay.split("-");
	var day = (tab[2] != null) ? parseInt(tab[2], 10) : 0;
	var month = (tab[1] != null) ? parseInt(tab[1], 10) : 0;
	var year = (tab[0] != null) ? parseInt(tab[0], 10) : "";
	if (isNaN(year)) year = "";
	
	html.push("<tr><td colspan=4 class=Title3 valign=bottom>Date de naissance</td></tr><tr><td><select class=\"InputAccount\" id=\"AccountBornDay\">");
	for (var i = 1; i <= 31; i++)
	{
		html.push("<option value=" + i + " "); 
		if (i == day) html.push("selected");
		html.push(">" + VerifDigits(i, 2) + "</option>");
	}
	html.push("</select></td><td><select class=\"InputAccount\" id=\"AccountBornMonth\">");
	for (var i = 1; i <= 12; i++)
	{
		html.push("<option value=" + i + " ");
		if (i == month) html.push("selected");
		html.push(">" + VerifDigits(i, 2) + "</option>");
	}
	html.push("</td><td class=Title3 align=right>Ann&eacute;e</td><td><input type=text class=InputAccount id='AccountBornYear' style=\"width:60px\" value='");
	html.push(year);
	html.push("'></td></tr>");
	html.push("<tr><td colspan=4>&nbsp;</td></tr>");
	html.push("<tr><td colspan=4 align=center><button onclick=\"SaveUserAccountIdent();\" id=\"BtAccountIdent\">Enregistrer</button></td></tr>");
	html.push("</table></tr></td>");
	html.push("<tr><td class=Title1 style=\"height:20px\">Cr&eacute;dit</td></tr>");
	html.push("<tr><td><table style=\"width:100%\" cellpadding=0 cellspacing=1 style=\"table-layout:fixed\" bgcolor=\"#ebebeb\">");
	html.push("<tr><td class=Title3 valign=bottom>Solde</td><td class=Title3 valign=bottom>Cr&eacute;diter de</td></tr></td><tr><td><input type=text class=InputAccount disabled value='");
		if (obj.Credit != "undefined") html.push(obj.Credit);
	html.push("'></td><td><input type=text class=InputAccount id=\"AccountCreditRequest\"></td></tr>");
	html.push("<tr><td colspan=2>&nbsp;</td></td>");
	html.push("<tr><td align=center colspan=2><button onclick=\"CreditAddRequest()\">Enregistrer</button></td></tr>");
	html.push("</table></tr></td>");
	html.push("</table>");
	divGeneral.innerHTML = html.join("");
}

function SaveUserAccountIdent()
{
	this.disabled = true;
	
	var errorStr = "";
	
	var newPass = document.getElementById("AccountNewPassword");
	if ((newPass.value.length != 0) && (newPass.value.length < 6))
	{
		errorStr +=	"La longeur du mot de passe doit être de 6 caracteres au minimum\n";
		newPass.style.backgroundColor = "red";
	}
	else
	{
		newPass.style.backgroundColor = "#666666";	
	}
	
	
	//Second : veridy email
	var email = document.getElementById("AccountEmail");
	var mail_pattern = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
	if (email.value == "")
	{
		email.style.backgroundColor = "red";
		errorStr += "L'email n'est pas valide\n";
	}
	else if (!email.value.match(mail_pattern))
	{
		email.style.backgroundColor = "red";
		errorStr += "Le format de l'adresse email n'est pas valide\n";
	}
	else
	{
		email.style.backgroundColor = "#666666";
	}
	
	//Third : verify born year
	var born = document.getElementById("AccountBornYear");
	if (born.value.length != 0)
	{
		if (born.value.length != 4)
		{
			born.style.backgroundColor = "red";
			errorStr += "L'annee doit etre sur quatres chiffres. Pour ne pas specifier de date, laissez le champs vide\n";
		}
		else
		{
			var dt = parseInt(born.value, 10);
			if ((dt < 1900) || (dt > 2008))
			{
				errorStr += "L'annee saisie n'est pas valide. Pour ne pas specifier de date, laissez le champs vide\n";
				born.style.backgroundColor = "red";
			}
			else
			{
				born.style.backgroundColor = "#666666";	
			}
		}
	}
	else
	{
		born.style.backgroundColor = "#666666";	
	}
	
	if (errorStr != "")
	{
		this.disabled = false;
		alert(errorStr);
		return;
	}
	
	//If here : send informations
	var params = new Array();
    params.push(new WSParams("login", user.userName));
	params.push(new WSParams("token", user.token));
	params.push(new WSParams("newPassword", newPass.value));
	params.push(new WSParams("email", email.value));
	
	var birthDate = "";
	if (born.value != "")
	{
		birthDate = born.value + "-" + document.getElementById("AccountBornMonth").value + "-" + document.getElementById("AccountBornDay").value;	
	}
	
	params.push(new WSParams("birthDate", birthDate));
	
    AjaxRequest("sawale_ws.php", OnSaveUserAccountIdent, "SaveUserAccountIdent", params, "robatmac/Awale");
}

function OnSaveUserAccountIdent(res)
{
	res = parseInt(res, 10);
	if (res == -1)
	{
		alert("Votre identification n'est pas valide. Aucune information enregistree");	
	}
	else if (res == -2)
	{
		alert("Erreur d'enregistrement lors de la modification de vos donnees. Veuillez reessayer plus tard");	
	}
	else
	{
		alert("Vos donnees ont bien ete enregistrees");	
	}
	
	document.getElementById("BtAccountIdent").disabled = false;
}

function SaveUserAccountInfos(bt)
{
	bt.disabled = true;
	var errorStr = "";
	
	//Verify that firstname and lastname are not empty
	var nom = document.getElementById("AccountFirstName");
	if (nom.value.length == 0)
	{
		errorStr += "Vous devez renseigner votre nom\n";
		nom.style.backgroundColor = "red";
	}
	else
	{
		nom.style.backgroundColor = "#666666";	
	}
	
	var prenom = document.getElementById("AccountLastName");
	if (prenom.value.length == 0)
	{
		errorStr += "Vous devez renseigner votre prenom";
		prenom.style.backgroundColor = "red";
	}
	else
	{
		prenom.style.backgroundColor = "#666666";	
	}
	
	if (errorStr != "")
	{
		alert(errorStr);
		bt.disabled = false;
		return;
	}
	
	//If here : send informations
	var params = new Array();
    params.push(new WSParams("login", user.userName));
	params.push(new WSParams("token", user.token));
	params.push(new WSParams("nom", nom.value));
	params.push(new WSParams("prenom", prenom.value));
	params.push(new WSParams("adr1", document.getElementById("AccountAdresse1").value));
	params.push(new WSParams("adr2", document.getElementById("AccountAdresse2").value));
	params.push(new WSParams("cp", document.getElementById("AccountZipCode").value));
	params.push(new WSParams("town", document.getElementById("AccountTown").value));
	params.push(new WSParams("country", document.getElementById("AccountCountry").value));
	
    AjaxRequest("sawale_ws.php", OnSaveUserAccountInfos, "SaveUserAccountInfos", params, "robatmac/Awale");
}

function OnSaveUserAccountInfos(res)
{
	res = parseInt(res, 10);
	if (res == -1)
	{
		alert("Votre identification n'est pas valide. Aucune information enregistree");	
	}
	else if (res == -2)
	{
		alert("Vous devez renseigner votre nom et prenom");
	}
	else if (res == -3)
	{
		alert("Erreur d'enregistrement lors de la modification de vos donnees. Veuillez reessayer plus tard");	
	}
	else
	{
		alert("Vos donnees ont bien ete enregistrees");	
	}
	
	document.getElementById("BtAccountInfos").disabled = false;
}

function CreditAddRequest()
{
	var amount = parseFloat(document.getElementById("AccountCreditRequest").value);
	if (isNaN(amount)) amount = 0;
	
	var params = new Array();
    params.push(new WSParams("login", user.userName));
	params.push(new WSParams("amount", amount));
	
    AjaxRequest("sawale_ws.php", function() {}, "CreditAddRequest", params, "robatmac/Awale");
	
	alert("Cette fonctionalite n'est pas encore disponible. Elle le sera mise en place des que le nombre de demande sera suffisant pour nous permettre de mettre en place le systeme bancaire de paiement.\nMerci de nous excuser");
}

var accountHistoryCurrentDate = new Date();

function AccountHistoryConstruct()
{
	var str = Month[accountHistoryCurrentDate.getMonth()];
	var year = accountHistoryCurrentDate.getFullYear();
	str += " " + year;
	
	var html = new Array();
	html.push("<table style=\"width:100%\"><tr><td>");
		html.push("<table cellpadding=0 cellspacing=0 style=\"border:1px solid #CECECE;width:100%\"><tr>");
		html.push("<td style=\"cursor:pointer\" onmouseover=\"this.firstChild.src='img/arrow_left_on.png';\" onmouseout=\"this.firstChild.src='img/arrow_left.png';\" onclick=\"ChangeAccountHistoryDate(-1);\"><img src=\"img/arrow_left.png\"></td>");
		html.push("<td style=\"width:100%\" align=center id=\"TD_TITLE_ACCOUNT_HISTORY\">"); html.push(str); html.push("</td>");
		html.push("<td style=\"cursor:pointer\" onmouseover=\"this.firstChild.src='img/arrow_right_on.png';\" onmouseout=\"this.firstChild.src='img/arrow_right.png';\" onclick=\"ChangeAccountHistoryDate(1);\"><img src=\"img/arrow_right.png\" ></td>");
		html.push("</tr></table>");
	html.push("</td></tr>");
	html.push("<tr><td><div style=\"width:100%;height:400px;overflow-y:auto\"><table width=\"100%\" cellSpacing=1 id=\"UserAccountHistoryTb\" class=\"UserHistory\"><tr>");
	html.push("<td class=\"PlayerListHeader\">Date</td><td class=\"PlayerListHeader\">Jeu</td><td class=\"PlayerListHeader\">Adversaire</td><td class=\"PlayerListHeader\">R&eacute;sultat</td><td class=\"PlayerListHeader\">Gain</td></tr>");
	
	html.push("</table>");
	
	document.getElementById("div_historique").innerHTML = html.join("");
	
	LoadHistoryTable();
}

function ChangeAccountHistoryDate(facteur)
{
	var cYear = parseInt(accountHistoryCurrentDate.getFullYear(), 10);
	var cMonth = parseInt(accountHistoryCurrentDate.getMonth(), 10);
	
	cMonth = cMonth + facteur;
	
	if (cMonth < 0)
	{
		cMonth = 11;
		cYear--;
	}
	if (cMonth > 11)
	{
		cMonth = 0;
		cYear++;
	}
	
	accountHistoryCurrentDate.setYear(cYear);
	accountHistoryCurrentDate.setMonth(cMonth);
	
	var str = Month[accountHistoryCurrentDate.getMonth()];
	var year = accountHistoryCurrentDate.getFullYear();
	str += " " + year;
	
	document.getElementById("TD_TITLE_ACCOUNT_HISTORY").innerHTML = str;
	
	LoadHistoryTable();
}

function LoadHistoryTable()
{
	var tb = document.getElementById("UserAccountHistoryTb");
	
	//First remove rows
	for (var i = tb.rows.length - 1; i > 0; i--)
	{
		tb.deleteRow(i);	
	}
	
	//Load rows
	var params = new Array();
    params.push(new WSParams("login", user.userName));
	params.push(new WSParams("year", accountHistoryCurrentDate.getFullYear()));
	params.push(new WSParams("month", accountHistoryCurrentDate.getMonth() + 1));
	
    AjaxRequest("sawale_ws.php", OnLoadHistoryTable, "GetUserHistory", params, "robatmac/Awale");
}

function OnLoadHistoryTable(res)
{
	var tb = document.getElementById("UserAccountHistoryTb");
	
	if ((res == null) || (res.length == 0))
	{
		var tr = tb.insertRow(-1);
		var td = tr.insertCell(-1); td.colSpan = 5;
		td.innerHTML = "Aucune partie jou&eacute;e";
		td.className = "UserHistoryCell";
	}
	else
	{
		for (var i = 0; i < res.length; i++)
		{
			var tr = tb.insertRow(-1);
			
			var dtStart = ((res[i]["DateStart"] != null) && (typeof(res[i]["DateStart"]) != "undefined")) ? res[i]["DateStart"] : "";
			if (dtStart != "")
			{
				var tab = dtStart.split(" ");
				var day = tab[0].split("-");
				var hour = tab[1].split(":");
				dtStart = day[2] + "-" + day[1] + "<br>" + hour[0] + ":" + hour[1];
			}
			
			var dtEnd = ((res[i]["DateEnd"] != null) && (typeof(res[i]["DateEnd"]) != "undefined")) ? res[i]["DateEnd"] : "";
			if (dtEnd != "")
			{
				var tab = dtEnd.split(" ");
				var hour = tab[1].split(":");
				dtEnd = hour[0] + ":" + hour[1];
				dtStart += " &agrave; " + dtEnd;
			}
			
			var td = tr.insertCell(-1); td.innerHTML = dtStart; td.className = "UserHistoryCell";
			var td = tr.insertCell(-1); td.innerHTML = gameFlash[parseInt(res[i]["GameId"], 10)].name; 
			td.className = "UserHistoryCell";
			var td = tr.insertCell(-1); td.className = "UserHistoryCell";
				var names = res[i]["Opponent"].split(";");
				for (var j = 0; j < names.length; j++)
				{
					td.innerHTML += names[j];
					if (j == names.length - 1) td.innerHTML += "<br>";
				}
			var td = tr.insertCell(-1); td.className = "UserHistoryCell";
				var resultat = "En cours";
				var resInt = parseInt(res[i]["EndReason"], 10);
				if (resInt == 3) resultat = "Abandon";
				else if (resInt == 2) resultat = "Perdu";
				else if (resInt == 1) resultat = "Gagn&eacute;";
			td.innerHTML = resultat;
			
			var td = tr.insertCell(-1); td.innerHTML = res[i]["Gain"]; td.className = "UserHistoryCell";
		}
	}
}

function AccountClassementConstruct()
{
	document.getElementById("div_classement").innerHTML = "Chargement en cours...";
	
	//Load rows
	var params = new Array();
    params.push(new WSParams("login", user.userName));
    AjaxRequest("sawale_ws.php", OnAccountClassementConstruct, "GetUserClassement", params, "robatmac/Awale");
}

function OnAccountClassementConstruct(res)
{
	var div = document.getElementById("div_classement");
	
	var html = new Array();
	
	if ((res == null) || (res.length == 0))
	{
		html.push("Vous n'avez particip&eacute; &agrave; aucun jeu : aucun classement<br>");
	}
	else
	{
			
		for (var i = 0; i < res.length; i++)
		{
			html.push("<table style=\"width:99%;\" cellpadding=1 cellspacing=1 bgcolor=\"#666666\">");
			html.push("<tr><td class=Title1 style=\"height:20px\">"); html.push(gameFlash[parseInt(res[i]["GameId"], 10)].name); html.push("</td></tr>");
			html.push("<tr bgcolor=\"#ebebeb\"><td class=Title3 align=center>Classement : "); html.push(res[i]["classement"]); html.push("</td>");
			html.push("<td class=Title3 align=center>Points : "); html.push(res[i]["nbPoints"]); html.push("</td>");
			html.push("<td class=Title3 align=center>Position : "); html.push(res[i]["position"]); html.push("/"); html.push(res[i]["nbPlayer"]);  html.push("</td></tr>");
			html.push("</table></br>");
		}
	}
	
	html.push("<table style=\"width:99%;\" cellpadding=1 cellspacing=1 bgcolor=\"#666666\">");
	html.push("<tr><td class=Title1 style=\"height:20px;\">Explications</td></tr>");
	html.push("<tr bgcolor=\"#ebebeb\"><td class=Title3 align=left style=\"padding:5px\">");
	html.push("<p style=\"text-align:justify\">Les classements vont de 0 &agrave; 20, 20 &eacute;tant le classement le plus &eacute;lev&eacute;.</p>");
	html.push("<p style=\"text-align:justify\">Les classements sont calcul&eacute;s tous les premiers du mois à minuit, en suivant les r&egrave;les suivantes :</p>");
	html.push("<li style=\"padding:5px\">Victoire sur un joueur de classement +2 (ou&nbsp;plus)&nbsp;: 150 pts</li>");
	html.push("<li style=\"padding:5px\">Victoire sur un joueur de classement +1 : 100 pts</li>");
	html.push("<li style=\"padding:5px\">Victoire sur un joueur de classement &eacute;gal : 50 pts</li>");
	html.push("<li style=\"padding:5px\">Victoire sur un joueur de classement -1 : 30 pts</li>");
	html.push("<li style=\"padding:5px\">Victoire sur un joueur de classement -2 : 20 pts</li>");
	html.push("<li style=\"padding:5px\">Victoire sur un joueur de classement -3 : 10 pts</li>");
	html.push("<li style=\"padding:5px\">D&eacute;faite sur un joueur de classement -2 (ou&nbsp;moins)&nbsp;: -10 pts</li><br>");
	html.push("<p style=\"text-align:justify\">Afin de monter vous devez comptabiliser 450 points &agrave; l'issu de la p&eacute;riode. Vous descendrez si vous n'avez pas un minimum de 250 points. Pour monter vous devez &eacute;galement comptabiliser un minimum de 250 points dans le nouveau classement.<br><br>Il est possible de monter de plusieurs classement en une fois, par contre vous ne pouvez descendre que d'une cat&eacute;gorie.<br><br>Apr&egrave;s calcul du classement les points de chaque joueurs sont remis &agrave; z&eacute;ro.</p>");
	
	html.push("</td></tr></table>");
	
	div.innerHTML = html.join("");
}