';
}
function escapeHtml(text) {
return text
.replace(/&/g, "&")
.replace(//g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
}
function isLocalhost() {
var url = window.location.href; // Get the current URL
if (url.includes("localhost")) {
return true;
} else {
return false;
}
}
function getLanguageFromUrl() {
var url = window.location.href; // Get the current URL
var language = ""; // Variable to store the language
// Check if the URL has at least two segments
if (url.includes("/")) {
var segments = url.split("/"); // Split the URL by '/'
// alert (segments[3]);
// Check if the second segment exists and is not empty
if (segments.length > 2 && segments[3] !== "") {
language = segments[3]; // Set the language to the second segment
}
}
return language;
}
function waitForPlayersToJoin(whichdiff,mode,gameid)
{
showSearchWindow(whichdiff,mode,gameid);
multimode=mode;
// alert('multimode='+multimode);
lobbyWaitForMatchTimer(thisuser);
}
function initLobbyAjax(mode)
{
globalmode=mode;
if (window.XMLHttpRequest){regxmlhttp=new XMLHttpRequest();}else {regxmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
regxmlhttp.onreadystatechange=function()
{
if (regxmlhttp.readyState==4 && regxmlhttp.status==200)
{
var answer = regxmlhttp.responseText;
// alert('answer 222='+answer+" answer.substring(0,2)="+answer.substring(0,2));
if (answer.substring(0,2) == "0~")
{
gameid=answer.substring(2);
waitForPlayersToJoin(difflevel,mode,gameid);
}
else
if (answer.substring(0,2) == "1~")
{
lobbyStartRobotMatch(answer.substring(2,3)); // get the robot number from the answer
}
else
{
lobbyaskforapprove(answer);
}
}
}
if (document.getElementById("lobbydiff1").checked) { difflevel = 1;}
else
if (document.getElementById("lobbydiff2").checked) { difflevel = 2;}
else
if (document.getElementById("lobbydiff3").checked) { difflevel = 3;}
else
if (document.getElementById("lobbydiff4").checked) { difflevel = 4;}
else
{difflevel = 1;}
initlobbyurl = "ilobbyuserid="+thisuser+"&idifflevel="+difflevel+"&imode="+mode+"&" + Math.random();
regxmlhttp.open("POST",'/lobbyinit.php',true);
regxmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
regxmlhttp.send(initlobbyurl);
}
function lobbyWaitForMatchAjax()
{
if (window.XMLHttpRequest){regxmlhttp=new XMLHttpRequest();}else {regxmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
regxmlhttp.onreadystatechange=function()
{
if (regxmlhttp.readyState==4 && regxmlhttp.status==200)
{
var answer = regxmlhttp.responseText;
if (answer == "0")
{
lobbyWaitForMatchCounter = lobbyWaitForMatchCounter + 1;
if ((lobbyWaitForMatchCounter == 1) || (lobbyWaitForMatchCounter == 2))
{
var waitmatchtext = nep("j130");
}
else
if ((lobbyWaitForMatchCounter == 3) || (lobbyWaitForMatchCounter == 4))
{
var waitmatchtext = nep("j131");
}
else
{
var waitmatchtext = nep("j132");
}
document.getElementById("matchwin3").innerHTML= '
'+waitmatchtext+' '+nep("j103")+'
';
}
else
{
lobbyStopWaitForMatchTimer();
lobbyaskforapprove(answer);
}
}
}
quertylobbyurl = "&rti=" + Math.random();
// check if already waiting for specific game
// alert(multimode);
if (multimode.substring(0,7) == "invite-")
{
regxmlhttp.open("POST",baseurl+'lobbycheckmatch.php?multimode='+multimode,true);
}
else
{
regxmlhttp.open("POST",baseurl+'lobbycheckmatch.php',true);
}
regxmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
regxmlhttp.send(quertylobbyurl);
}
function lobbyaskforapprove(rtndata)
{
var rtnarray = rtndata.split("~");
pendingagainstwho = rtnarray[0];
otherPlayerName = rtnarray[1];
document.getElementById("matchwin1").innerHTML= ' '+nep("j110")+' '+rtnarray[1]+'