var alPages = new Array('Main', 'Vote', 'MList', 'PList', 'MStat', 'Pending', 'FAdmin', 'RAdmin');
var alColours = new Array(null, null, null, null, null, null, null, null);
var alCheckPriv = new Array(
new Function('return true'),
new Function('return lockedAlliances || isDemocracy'),
new Function('return (alPrivileges[0] > 0)'),
new Function('return (alPrivileges[0] > 1)'),
new Function('return (alPrivileges[1] == 1)'),
new Function('return (alPrivileges[4] == 1) && !lockedAlliances'),
new Function('return (alPrivileges[5] == 1)'),
new Function('return (alPrivileges[8] == 1)')
);
var lockedAlliances;
var plAlliance;
var inAlliance;
var alTag;
var alName;
var hasFocus = -1;
var alPubInfo = false;
var gdTimer;
var puTimer;
var amPage;
var myPubInfo = false;
var alPrivileges;
var successor;
var isDemocracy;
var asSuccessor;
var asDemocracy;
var techTrade;
var asTechTrade;
var asButtons = false;
var leCandidates;
var leSelected;
var leNewSel = false;
var leCanSel;
var leCanApply;
var leCanCancel;
var leCanTake;
var leInAction = false;
var leSort = 0;
var leSortDir = false;
var lsMode = false;
var lsPlanets = new Array();
var lsPPerPage = 10;
var lsPPage = 0;
var lsPSearchType = 0;
var lsPSearchText = "";
var lsPIndices;
var lsPSort = 1;
var lsPSortDir = false;
var lsMembers = new Array();
var lsMPerPage = 10;
var lsMPage = 0;
var lsMRanks;
var lsMChange;
var lsMKick;
var lsMSearchText = "";
var lsMIndices;
var lsMSort = 0;
var lsMSortDir = false;
var lsMNewRank = false;
var lsAttacks = new Array();
var lsAPerPage = 10;
var lsAPage = 0;
var lsAIndices;
var lsASort = 1;
var lsASortDir = false;
var lsASearchText = "";
var lsASearchType = 0;
var pRequests = new Array();
var faForums;
var faEditing = false;
var faOriginal;
var faOriACL;
var faNewPos;
var faAccess;
var raRanks = new Array();
var raForums;
var raEditing = false;
var raOriginal;
var raDeleting = 0;
var raDemote;
var alltt;
function emptyCB(data) {}
function PubAlliance(id, tag, name, leader, rank, points, nplanets, cx, cy, vicCond)
{
this.id = id;
this.tag = tag;
this.name = name;
this.leader = leader;
this.points = points;
this.rank = rank;
this.points = points;
this.nplanets = nplanets;
this.cx = cx;
this.cy = cy;
this.victory = vicCond;
}
function initAlliancePage()
{
var data = document.getElementById('allinit').innerHTML;
if (data.indexOf('\n') != -1)
generalDataReceived(data);
else // IE really sucks
x_getGeneralData(generalDataReceived);
}
function generalDataReceived(data)
{
var a = data.split('\n');
var b = a[0].split('#');
plAlliance = b[0];
if (plAlliance == "")
{
inAlliance = false;
drawPageNoAlliance();
}
else if (a.length == 3)
{
inAlliance = false;
alTag = a[1];
alName = a[2];
drawPageNoAlliance();
}
else
{
if (!inAlliance)
drawAllianceMemberLayout();
lockedAlliances = (b[2] == 1);
b = a[3].split('#');
myPubInfo = new PubAlliance(b[0], a[1], a[2], a[4], b[5], b[6], b[1], b[2], b[3], b[8]);
successor = a[5];
isDemocracy = (b[4] == "1");
techTrade = b[7];
alPrivileges = a[6].split('#');
alColours[4] = (alPrivileges[1] == 1 && a[8] != '0') ? "red" : null;
alTag = a[1];
alName = a[2];
inAlliance = true;
if (a[7] == 'List') {
a[7] = 'Main';
}
if (amPage != a[7])
eval('switchTo'+a[7]+'Page()');
else if (amPage == 'Main')
{
drawAllianceMenu();
drawMainPage();
}
else
drawAllianceMenu();
}
gdTimer = setTimeout('x_getGeneralData(generalDataReceived)', 30000);
}
function clearUpdate()
{
if (puTimer)
clearTimeout(puTimer);
puTimer = false;
}
//--------------------------------------------------
// ALLIANCE INFORMATION
//--------------------------------------------------
function getAllianceInfo()
{
var v = document.getElementById('alinfo').value;
if (v == "")
{
alertAllianceInfo(0);
return;
}
x_getTagInformation(v, tagInformationReceived);
}
function tagInformationReceived(data)
{
if (data.indexOf('ERR') == 0)
{
var a = data.split('#');
alPubInfo = false;
alertAllianceInfo(parseInt(a[1], 10));
}
else
{
var a = data.split('\n');
var b = a[0].split('#');
alPubInfo = new PubAlliance(b[0], a[1], a[2], a[3], b[4], b[5], b[1], b[2], b[3], b[6]);
}
drawPubAllianceInfo();
}
//--------------------------------------------------
// ALLIANCE CREATION / REQUEST
//--------------------------------------------------
function createAlliance()
{
var t, n;
t = document.getElementById('actag').value;
if (t == "")
{
alertCreate(2);
return;
}
n = document.getElementById('acname').value;
if (n == "")
{
alertCreate(3);
return;
}
x_createAlliance(t, n, allianceCreated);
}
function allianceCreated(data)
{
if (data.indexOf('ERR') == 0)
{
var a = data.split('#');
alertCreate(parseInt(a[1], 10));
}
else
{
updateHeader();
clearTimeout(gdTimer);
generalDataReceived(data);
}
}
function sendJoinRequest()
{
var t;
t = document.getElementById('aljoin').value;
if (t == "")
{
alertJoin(0);
return;
}
x_sendRequest(t, requestSent);
}
function requestSent(data) {
if (data.indexOf('ERR') == 0) {
var a = data.split('#');
alertJoin(parseInt(a[1], 10));
} else {
clearTimeout(gdTimer);
generalDataReceived(data);
}
}
//--------------------------------------------------
// ALLIANCE MEMBER PAGE
//--------------------------------------------------
function drawAllianceMemberLayout() {
document.getElementById('allpage').innerHTML = '
';
}
function drawAllianceMenu() {
var i, j, str = "";
for (i = 0, j = 0; i < alPages.length; i ++) {
if (!alCheckPriv[i]()) {
continue;
}
if (j > 0) {
str += (j == 5 ? " " : " - ");
}
j ++;
var colour = alColours[i] ? (" style='color: " + alColours[i] + "' ") : "";
var t = (amPage == alPages[i]);
str += (t ? ('')
: ('')
) + alPgTitles[i] + (t ? '' : '');
}
document.getElementById('alpmenu').innerHTML = str;
}
// Main page (current alliance + alliance information)
function switchToMainPage()
{
clearUpdate();
x_mainPage(emptyCB);
amPage = "Main";
asButtons = (asDemocracy != isDemocracy)
|| (asSuccessor.toLowerCase() != successor.toLowerCase())
|| (asTechTrade != techTrade);
hasFocus = -1;
drawAllianceMenu();
drawMainPage();
}
function updateASControls() {
var nst = (asDemocracy != isDemocracy)
|| (asSuccessor.toLowerCase() != successor.toLowerCase())
|| (asTechTrade != techTrade);
if (nst == asButtons) {
return;
}
asButtons = nst;
if (asButtons) {
drawASButtons();
} else {
document.getElementById('lasbut').innerHTML = ' ';
}
}
function resetAllianceSettings() {
asSuccessor = successor;
asDemocracy = isDemocracy;
asTechTrade = techTrade;
drawMainPage();
}
function modifyAllianceSettings()
{
document.getElementById('lasbut').innerHTML = ' ';
x_modifySettings(asDemocracy ? 1 : 0, asTechTrade, asSuccessor, aSettingsModified);
}
function aSettingsModified(data) {
if (data.indexOf('ERR') == 0) {
var a = data.split('#');
alertASettings(parseInt(a[1], 10));
drawASButtons();
} else {
asDemocracy = -1;
clearTimeout(gdTimer);
generalDataReceived(data);
}
}
function asFocus() {
if (hasFocus == 0 && alPrivileges[8] == 1) {
document.getElementById('lassucc').focus();
} else if (hasFocus == 3) {
document.getElementById('alinfo').focus();
}
}
function leaderStepDown()
{
if (!confirmLSD())
return;
x_leaderStepDown(aSettingsModified);
}
function leaveAlliance()
{
var b;
if (alPrivileges[8] == 0)
b = confirmLeave(0);
else if (successor != "")
b = confirmLeave(1);
else
b = confirmLeave(isDemocracy ? 2 : 3);
if (!b)
return;
x_leaveAlliance(aSettingsModified);
}
// Leader election
function switchToVotePage()
{
clearUpdate();
if (!alCheckPriv[1]()) {
switchToMainPage();
return;
}
amPage = 'Vote';
drawAllianceMenu();
drawLoadingText();
x_getCandidates(candidatesReceived);
}
function Candidate(id,nVotes,name)
{
this.id = id;
this.nVotes = nVotes;
this.name = name;
}
function candidatesReceived(data)
{
leInAction = false;
if (amPage != "Vote")
return;
if (data == "") {
switchToMainPage();
return;
} else if (data.indexOf('ERR#') == 0) {
var a = data.split('#');
alertElection(parseInt(a[1],10));
} else {
var a = data.split('\n');
var ll = a.shift().split('#');
leCanSel = (ll[0] == '1');
leCanApply = (ll[1] == '1');
leCanCancel = (ll[2] == '1');
leCanTake = (ll[3] == '1');
leSelected = ll[4];
if (leNewSel == false && leCanSel)
leNewSel = leSelected;
var i;
leCandidates = new Array();
for (i=0;i getRawRankText(y).toLowerCase() ? 1 : -1;
});
}
function getRank(m) {
if (m.rankText == "") {
m.rankText = getRankText(m.getRawRank());
}
return m.rankText;
}
function getRawRankText(r) {
for (var i = 0; i < lsMRanks.length && lsMRanks[i].id != r; i ++) {
// Empty loop
}
return getRankText(i);
}
function getCookedRankText(r) {
for (var i = 0; i < lsMRanks.length && lsMRanks[i].id != r; i ++) {
// Empty loop
}
return getRankText((i == lsMRanks.length || lsMRanks[i].name == '-') ? '-' : i);
}
function removeMember(id) {
var k;
for (k=0;k ';
}
for (i = 0; i < 4; i ++) {
str += '