var pageMode; var pageModes = new Array('Topics', 'Laws', 'Attributions', 'Diplomacy'); var puTimer; var onGetComplete; var rtGetData = new Array(); // Research topics for which data must be requested var rtTitles = new Array(); // Research topics titles var rtDescriptions = new Array(); // Research topics descriptions var rtCosts = new Array(); // Research topics implementation cost var rtTypes = new Array(); // Research topics types var rtExpanded = new Array(); // Topics for which the description is being displayed var rtAll; // All research topics or laws var rtCompleted; // Completed researches var rtImplemented; // Implemted technologies var rtForeseen; // Foreseen breakthroughs var rtForeseenP; // Foreseen breakthroughs completion percentages var lEnacted; // Enacted laws var lTimeRevoke; // Time left before a law can be revoked var lAvailable; // Available laws var lTimeEnact; // Time left before a law can be enacted again var rbPoints; // Research points / day var rbPercentage; // Percentage going to each research type var rbOriPercentage; // Percentage going to each research type before player modification var rbCatPoints; // Points going to each category var rbLocks; // Locked categories var rdDiplomacyDelay; var rdSentOffer; // Offer sent by the player, false if none var rdRecOffers; // List of received offers var rdHistory; // List of past offers var rdAvailTech; // List of available technologies var rdRecPage = 0; // Current page for the received offers list var rdHistPage = 0; // Current page for the history var rdfType = 0; var rdfTech = 0; var rdfTarget = ""; var rdfPrice = ""; var rett; function initResearchPage(data) { setPage(data); } function showDescription(id) { rtExpanded.push(id); if (pageMode == 'Topics') topicsDisplayOk(); else if (pageMode == 'Laws') lawsDisplayOk(); } function hideDescription(id) { var t = rtExpanded, i; rtExpanded = new Array(); for (i=0;i tb ? 1 : -1); } function descriptionsReceived(data) { if (data != "") { var i, l, a = data.split("\n"); l = a.length / 4; for (i=0;i'; else str += ''; str += pageTitles[i]; if (pageModes[i] != pageMode) str += ''; else str += ''; } document.getElementById('respsel').innerHTML = str; } function buildTopicsDisplay(data) { var all = data.split('!'); var t, i; rtCompleted = (all[1] == "" ? new Array() : all[1].split('#')); rtAll = rtCompleted; rtImplemented = (all[0] == "" ? new Array() : all[0].split('#')); rtAll = rtAll.concat(rtImplemented); t = all[2].split('#'); rtForeseen = new Array(); rtForeseenP = new Array(); for (i=0;all[2] != "" && i 0) { onGetComplete = 'topicsDisplayOk();'; x_getDescriptions(rtGetData.join('#'), descriptionsReceived); } else topicsDisplayOk(); puTimer = setTimeout('x_getTopicsData(buildTopicsDisplay)', 900000); } function topicsDisplayOk() { rtCompleted.sort(sortResearch); rtImplemented.sort(sortResearch); rtForeseen.sort(sortResearch); document.getElementById('respage').innerHTML = getTopicsPage(); } function implementResult(data) { if (data == "OK") { updateHeader(); setPage('Topics'); } else { var a = data.split('#'); implError(parseInt(a[1], 10)); } } function implementTechnology(id) { if (!confirmTech(id)) return; x_implementTechnology(id, implementResult); } function buildLawsDisplay(data) { var t, i; t = data.split('#'); lEnacted = new Array(); lTimeRevoke = new Array(); lAvailable = new Array(); lTimeEnact = new Array(); for (i=0;data != "" && i 0) { onGetComplete = 'lawsDisplayOk();'; x_getDescriptions(rtGetData.join('#'), descriptionsReceived); } else lawsDisplayOk(); puTimer = setTimeout('x_getLawsData(buildLawsDisplay)', 900000); } function lawsDisplayOk() { lEnacted.sort(sortResearch); lAvailable.sort(sortResearch); document.getElementById('respage').innerHTML = getLawsPage(); } function switchLawResult(data) { if (data == "OK") { updateHeader(); setPage('Laws'); } else { var a = data.split('#'); slawError(parseInt(a[1], 10)); } } function revokeLaw(id) { if (!confirmRevoke(id)) return; x_switchLaw(id, switchLawResult); } function enactLaw(id) { if (!confirmEnact(id)) return; x_switchLaw(id, switchLawResult); } function buildAttributionsDisplay(data) { var a = data.split('#'), i; rbPoints = a[0]; rbOriPercentage = new Array(); for (i=0;i'; else if (l) t = ' '; else t = '[U]'; document.getElementById('rblock'+i).innerHTML = t; d = d || (rbPercentage[i] != rbOriPercentage[i]); } if (d) drawBudgetControls(); else { document.getElementById('rbcl').innerHTML = ' '; document.getElementById('rbcr').innerHTML = ' '; } } function switchLock(l) { var i, a, s = '!' + rbLocks.join('!') + '!'; if (s.indexOf('!' + l + '!') == -1) rbLocks.push(l); else { a = new Array(); for (i=0;i 100) rv = 100 - rbPercentage[a]; else rv = v; if (rv == 0) return; mv = mv.concat(rbPercentage); mv.sort(new Function('a', 'b', 'return a - b')); m = ''; for (i=0;i 100) continue; rbPercentage[a] += rs; rbPercentage[j] -= rs; rv -= rs; orv = 0; } computeCatPoints(); updateAttributionsValues(); } function resetBudget() { rbPercentage = (new Array()).concat(rbOriPercentage); rbLocks = new Array(); computeCatPoints(); updateAttributionsValues(); } function validateBudget() { var s = rbPercentage.join('#'); x_validateBudget(s, budgetValidated); } function budgetValidated(data) { if (data == "OK") { rbOriPercentage = (new Array()).concat(rbPercentage); computeCatPoints(); updateAttributionsValues(); } else { var a = data.split('#'); budgetError(parseInt(a[1], 10)); } } function ResearchOffer(id,type,status,status2,price,tech,time,player) { this.id = id; this.type = type; this.status = status; this.status2 = status2; this.price = price; this.tech = tech; this.time = parseInt(time, 10); this.player = player; var d = new Date(); var t = d.getTime(); t = (t - (t % 1000)) / 1000; this.today = (t - this.time <= rdDiplomacyDelay); } function buildDiplomacyDisplay(data) { if (data.indexOf('\n') == -1) drawDiplomacyRestrained(data); else { var i, o, a = data.split('\n'), tl; rdDiplomacyDelay = parseInt(a.shift(), 10); tl = a.shift().split('#'); rdAvailTech = new Array(); rtGetData = new Array(); for (i=0;i 1) { for (i=0;i 0) { onGetComplete = 'drawDiplomacyPage();'; x_getDescriptions(rtGetData.join('#'), descriptionsReceived); } else drawDiplomacyPage(); } puTimer = setTimeout('x_getDiplomacyData(buildDiplomacyDisplay)', 900000); } function drawDiplomacyLayout() { var str = '
'; str += ''; str += '
 
 
  
'; document.getElementById('respage').innerHTML = str; } function drawDiplomacyPage() { if (typeof rdSentOffer == "object") drawRDSentAlready(); else { rdAvailTech.sort(sortResearch); drawRDSendForm(); } drawRDPending(); drawRDHistory(); } function sendOffer() { if (rdfType == 1 && rdfTech == 0) { rdOfferError(1); return; } if (rdfTarget == "") { rdOfferError(2); return; } var p; if (rdfPrice != "") { p = parseInt(rdfPrice, 10); if (rdfPrice != p.toString() || p < 0) { rdOfferError(3); return; } } else p = 0; if (!confirmSendOffer(rdfType, rdfTech, rdfTarget, p)) return; x_sendOffer(rdfType, rdfTech, rdfTarget, p, offerSent); } function offerSent(data) { if (data.indexOf('ERR#') == 0) { var a = data.split("#"); a[1] = parseInt(a[1], 10); rdOfferError(a[1]); } else buildDiplomacyDisplay(data); } function acceptOffer(oid) { var i; for (i=0;i