// JavaScript Document

function VerifDigits(num, nb)
{
	var num = num + "";
	if (num.length < nb)
	{
		var dif = nb - num.length;
		for (var i = 1; i < nb; i++)
		{
			num = "0" + num;	
		}
	}
	
	return num;
}

function InnerEnc(str)
{
	if (typeof(str) == "undefined") return "";
	return str.replace(/\"/gi, '\"');	
}


/***** COOKIE *********/
function setCookie(name, valeur, jours) 
{
    var expDate = new Date()
	expDate.setTime(expDate.getTime() + (jours * 24 * 3600 * 1000))
    document.cookie = name + "=" + escape(valeur) + ";expires=" + expDate.toGMTString()
}

function getCookie(name) 
{
	var deb = document.cookie.indexOf(name + "=")
	if (deb >= 0) 
	{
		deb += name.length + 1
		fin = document.cookie.indexOf(";",deb)
		if (fin < 0) fin = document.cookie.length
		return unescape(document.cookie.substring(deb,fin))
	}
	
	return ""
}

var Month = new Object();
Month[0] = "Janvier"; Month[1] = "F&eacute;vrier"; Month[2] = "Mars"; Month[3]= "Avril"; Month[4] = "Mai"; Month[5] = "Juin";
Month[6] = "Juillet"; Month[7] = "Ao&ucirc;t"; Month[8] = "Septembre"; Month[9] = "Octobre"; Month[10] = "Novembre"; Month[11] = "D&eacute;cembre";

function ObjLocalize()
{
	this.trads = new Object();
	this.title = new Object();
}

var traductions = new Object();
var images_localise = new Object();

var t1 = new ObjLocalize();
t1.trads["fr"] = "Jouer"; t1.trads["en"] = "Play";
traductions["AccueilTxtPlay"] = t1;

var t2 = new ObjLocalize();
t2.trads["fr"] = "Impossible de se connecter au serveur de jeu"; t2.trads["en"] = "Unable to connect to game server";
traductions["ErrorCx1"] = t2;

var t3 = new ObjLocalize();
t3.trads["fr"] = "Nous ne supportons pas la connexion via un serveur proxy"; t3.trads["en"] = "We does not support connection through a proxy server";
traductions["ErrorCx2"] = t3;

var t4 = new ObjLocalize();
t4.trads["fr"] = "Nom d'utilisateur inconnu"; t4.trads["en"] = "Unknow user name";
traductions["ErrorCx3"] = t4;

var t5 = new ObjLocalize();
t5.trads["fr"] = "Ce pseudonyme est déjà pris"; t5.trads["en"] = "This nickname is already in use";
traductions["ErrorCx4"] = t5;

var t6 = new ObjLocalize();
t6.trads["fr"] = "Cet utilisateur est déjà connecté"; t6.trads["en"] = "This user is already log in";
traductions["ErrorCx5"] = t6;

var t7 = new ObjLocalize();
t7.trads["fr"] = "Des parties sont en cours. Souhaitez vous réellement quitter ?"; t7.trads["en"] = "Some games are running. Are you sure you want to leave ?";
traductions["ConfirmQuit"] = t7;

var t8 = new ObjLocalize();
t8.trads["fr"] = "La connexion au serveur de jeu a été perdue.\nVeuillez vous reconnecter."; t8.trads["en"] = "The connection to the game server has been lost.\nPlease reconnect you.";
traductions["ErrorDisconnect"] = t8;

var t = new ObjLocalize();
t.trads["fr"] = "Awale"; t.trads["en"] = "Awale";
traductions["Game0"] = t;

var t = new ObjLocalize();
t.trads["fr"] = "Jeu royal d'ur"; t.trads["en"] = "Royal game of ur";
traductions["Game1"] = t;

var t = new ObjLocalize();
t.trads["fr"] = "Kukuli"; t.trads["en"] = "Kukuli";
traductions["Game2"] = t;

var t = new ObjLocalize();
t.trads["fr"] = "Backgammon"; t.trads["en"] = "Backgammon";
traductions["Game3"] = t;

var t = new ObjLocalize();
t.trads["fr"] = "Jeu de tables"; t.trads["en"] = "Tables";
traductions["Game4"] = t;

var t = new ObjLocalize();
t.trads["fr"] = "Plakoto"; t.trads["en"] = "Plakoto";
traductions["Game5"] = t;

var t = new ObjLocalize();
t.trads["fr"] = "DouShouQi"; t.trads["en"] = "DouShouQi";
traductions["Game6"] = t;

var t = new ObjLocalize();
t.trads["fr"] = "Liens"; t.trads["en"] = "Links";
traductions["AccueilTxtLinks"] = t;

var t = new ObjLocalize();
t.trads["fr"] = "Connexion"; t.trads["en"] = "Connection";
t.title["fr"] = "en construction..."; t.title["en"] = "in progress...";
traductions["AccueilTxtConnection"] = t;

var t = new ObjLocalize();
t.trads["fr"] = "Cr&eacute;er un compte"; t.trads["en"] = "Create an account";
t.title["fr"] = "en construction..."; t.title["en"] = "in progress...";
traductions["AccueilTxtCreateAccount"] = t;

var t = new ObjLocalize();
t.trads["fr"] = "Classements"; t.trads["en"] = "Ranking";
t.title["fr"] = "en construction..."; t.title["en"] = "in progress...";
traductions["AccueilTxtClassement"] = t;

var t = new ObjLocalize();
t.trads["fr"] = "Forum"; t.trads["en"] = "Forum";
t.title["fr"] = "en construction..."; t.title["en"] = "in progress...";
traductions["AccueilTxtForum"] = t;

var t = new ObjLocalize();
t.trads["fr"] = "Tournois"; t.trads["en"] = "Tournaments";
t.title["fr"] = "en construction..."; t.title["en"] = "in progress...";
traductions["AccueilTxtTournois"] = t;

var i1 = new ObjLocalize();
i1.trads["fr"] = "img/game_home_fr_1440.png";
i1.trads["en"] = "img/game_home_en_1440.png";
images_localise["Game_Img_Home"] = i1;


var i2 = new ObjLocalize();
i2.trads["fr"] = "img/ur_fr.png";
i2.trads["en"] = "img/ur_en.png";
images_localise["Game_Img_Ur"] = i2;

var i3 = new ObjLocalize();
i3.trads["fr"] = "img/game_title_fr.png";
i3.trads["en"] = "img/game_title_en.png";
images_localise["Game_Title_img"] = i3;

var i4 = new ObjLocalize();
i4.trads["fr"] = "img/logsc_fr.gif";
i4.trads["en"] = "img/logsc_en.gif";
images_localise["Copyright_img"] = i4;

var i5 = new ObjLocalize();
i5.trads["fr"] = "img/tables_fr.png";
i5.trads["en"] = "img/tables_en.png";
images_localise["Game_Img_Tables"] = i5;

function GameObject(fl, w, h, n, l, nb)
{
	this.flash = fl;
	this.width = w;
	this.height = h;
	this.name = n;
	this.localisable = l;
	this.nbPlayers = nb;
}


function SupervisorMessage(msg)
{
	alert("Message from site administrator:\n" + msg.replace(/\[BACKSLASH\]/gi, "\n"));	
}

function SetLangage(lng)
{
	if (culture != lng)
	{
        if (document.getElementById("News_div_Text_" + culture).style.display != "none") {
            document.getElementById("News_div_Text_" + culture).style.display = "none";
            document.getElementById("News_div_Text_" + lng).style.display = "";
        }
        
        if (document.getElementById("Links_div_Text_" + culture).style.display != "none") {
            document.getElementById("Links_div_Text_" + culture).style.display = "none";
            document.getElementById("Links_div_Text_" + lng).style.display = "";
        }
        
        if (document.getElementById("LinksInternal_div_Text_" + culture).style.display != "none") {
            document.getElementById("LinksInternal_div_Text_" + culture).style.display = "none";
            document.getElementById("LinksInternal_div_Text_" + lng).style.display = "";
        }
        
        if (document.getElementById("Links_div_Title_" + culture).style.display != "none") {
            document.getElementById("Links_div_Title_" + culture).style.display = "none";
            document.getElementById("Links_div_Title_" + lng).style.display = "";
        }
    
		culture = lng;
	
		for (var k in traductions)
		{
			var ob = document.getElementById(k);
			if (!ob) continue;
			ob.innerHTML = traductions[k].trads[lng];
			
			if (traductions[k].title[lng] != null) {
				ob.title = traductions[k].title[lng];
			}
		}
		
		for (var k in images_localise)
		{
			var img = document.getElementById(k);
			if (!img) continue;
			img.src = images_localise[k].trads[lng];
		}
	}
}

function AlertError(msg, isLogin)
{
	var found = false;
	
	for (var i = 0; i < listeningGames.length; i++)
	{	
		try {
			if (listeningGames[i].popup.hasFocus == true)
			{
				listeningGames[i].popup.alert(msg);
				if (isLogin)
				{
					listeningGames[i].popup.EnableLogin();
				}
				found = true;
			}
		}
		catch(e) { }
	}
	
	if (!found) alert(msg);	
}

function RoomObject(id, popup)
{
	this.gameId = id;
	this.popup = popup;
}