var currentPage, pageUpdate, layout = -1; var pageHandlers = ['Public','Private','Sent']; //---------------------------------------------------------------------------------------------- // LISTINGS //---------------------------------------------------------------------------------------------- function ListingColumn(title,hdSpan,tdcl,custom,dc,sa,sd) { this.title = title; this.hdSpan = hdSpan; this.colClass = tdcl; this.drawContents = (custom ? null : dc); this.drawColumn = (custom ? dc : null); this.sortAsc = sa; this.sortDesc = sd; } function Listing(element,list,varname,slabel) { this.element = element; this.list = list; this.varName = varname; this.searchLabel = slabel; this.columns = new Array(); this.lines = new Array(); this.sortBy = 0; this.sortDir = false; this.searchText = ''; this.perPage = 20; this.indices = new Array(); this.nPages = 0; this.page = 0; this.emptyText = notFound; this.notFound = notFound; this.addColumn = Listing_addColumn; this.draw = Listing_draw; this.searchFor = Listing_searchFor; this.updateDisplay = Listing_updateDisplay; this.setPage = Listing_setPage; this.setSort = Listing_setSort; this.updateIndices = Listing_updateIndices; this.makeAll = Listing_makeAll; this.makeList = Listing_makeList; this.makePage = Listing_makePage; } function Listing_addColumn(column, lIdx) { if (!this.lines[lIdx]) this.lines[lIdx] = new Array(); this.columns.push(column); this.lines[lIdx].push(this.columns.length - 1); } function Listing_draw() { this.updateIndices(); document.getElementById(this.element).innerHTML = this.makeAll(); } function Listing_searchFor(text) { if (this.searchText == text) return; this.searchText = text; this.updateDisplay(); } function Listing_updateDisplay() { var vals; eval('vals='+this.list); if (vals.length && document.getElementById('selpage_'+this.element)) { this.updateIndices(); document.getElementById('selpage_'+this.element).innerHTML = this.makePage(); document.getElementById('lstcontents_'+this.element).innerHTML = this.makeList(); } else this.draw(); } function Listing_setPage(np) { if (this.page == np) return; this.page = np; document.getElementById('lstcontents_'+this.element).innerHTML = this.makeList(); } function Listing_setSort(ns) { this.sortBy = ns; this.sortDir = !this.sortDir; this.updateDisplay(); } function Listing_updateIndices() { var i,vals; eval('vals='+this.list); this.indices = new Array(); if (this.searchText == "") for (i=0;i0?1:0); if (this.nPages > 0 && this.page >= this.nPages) this.page = this.nPages - 1; } function Listing_makeAll() { var vals,str; eval('vals='+this.list); if (vals.length) { var i; str = ''; str += ''; str += ''; str += ''; str += '
'; var s2 = ''; str += listingText[0].replace(/%1%/,s2) + ''; str += this.makePage() + '
'; str += '

' + this.makeList() + '
'; } else str = this.emptyText; return str; } function Listing_makePage() { var str; if (this.nPages == 0) str = ' '; else if (this.nPages == 1) str = listingText[1].replace(/%.%/g, '1'); else { var i,s2 = ''; str = listingText[1].replace(/%1%/,s2).replace(/%2%/,this.nPages); } return str; } function Listing_makeList() { if (this.indices.length == 0) return '

' + this.notFound + '
'; var i,j,str = ''; if (this.lines.length > 1) str += ''; var vals,k,f = this.page * this.perPage; var l = Math.min(f + this.perPage, this.indices.length); eval('vals='+this.list); for (i=f;i 1) str += ''; } str += '
'; for (j=0;j' : '') + title; if (this.sortBy == idx) { str += '';
				str += (this.sortDir ? '; } str += ''; }} str += ''; } if (this.lines.length > 1) str += '
'; for (k=0;k 1) str += '
'; return str; } //------------------------------------------------------------------------ // PUBLIC OFFERS OBJECTS //------------------------------------------------------------------------ var mapCType, mapX, mapY, mapDist, mapParm; var myPlanets, sysType, sysProt, sysPlanets; var pOffers, fOffers, sellers; function SysPlanet(id,status,own,ally,name) { this.id = id; this.status = status; this.ownership = own ? 2 : (ally ? 1 : 0); this.name = name; } function Seller(id,isMe,quit,name) { this.id = id; this.isMe = isMe; this.quit = quit; this.name = name; } function PublicPlanetOffer(offer,expires,id,seller,x,y,orbit,price,auction,pop,tur,fact,name) { this.offer = offer; this.expires = expires; this.id = id; this.seller = seller; this.x = x; this.y = y; this.orbit = orbit; this.price = price; this.auction = auction; this.population = pop; this.turrets = tur; this.fact = fact; this.name = name; this.fleet = null; } function PublicFleetOffer(offer,expires,id,seller,x,y,orbit,plId,price,auction,sg,sf,sc,sb,name) { this.offer = offer; this.expires = expires; this.id = id; this.seller = seller; this.x = x; this.y = y; this.orbit = orbit; this.plId = plId; this.price = price; this.auction = auction; this.plName = name; this.fleet = [sg, sf, sc, sb]; this.match = PublicFleetOffer_match; } function PublicFleetOffer_match(t) { return this.plName.toLowerCase().indexOf(t.toLowerCase()) != -1; } //------------------------------------------------------------------------ // PAGE INIT. & AUTO-UPDATE //------------------------------------------------------------------------ function lockUpdate(p) { if (!pageUpdate || p!=currentPage) return false; var p = pageUpdate; pageUpdate = null; clearTimeout(p); return true; } function startUpdate() { if (pageUpdate) return; pageUpdate = setTimeout('updateData()', 60000); } function drawMenu() { var i,str = ''; for (i=0;i' : (''); str += menuText[i] + (i == currentPage ? '' : ''); } document.getElementById('mkppsel').innerHTML = str; } function dataReceived(data) { var s = pageHandlers[currentPage]; eval('parse' + s + 'Offers(data)'); if (layout != currentPage) { drawMenu(); eval('draw' + s + 'Layout()'); layout = currentPage; } eval('draw' + s + 'Page()'); startUpdate(); } function updateData() { if (!lockUpdate(currentPage)) { setTimeout('updateData()', 500); return; } var s = 'x_get' + pageHandlers[currentPage] + 'Offers(dataReceived)'; eval(s); } function initMarket() { var e = document.getElementById('mkpfpage'); if (!e) return; currentPage = parseInt(e.innerHTML, 10); // Public offers, Planets pfsListing = new Listing('plsale', 'pOffers','pfsListing',searchText[0]); pfsListing.addColumn(new ListingColumn(psHeaders[0], 2, 'pname', true, drawPSName, sortPSNameAsc, sortPSNameDesc), 0); pfsListing.addColumn(new ListingColumn(psHeaders[1], 1, 'coords', false, drawCoords, sortPSCrdAsc, sortPSCrdDesc), 0); pfsListing.addColumn(new ListingColumn(psHeaders[2], 1, 'pdat', false, drawPSPop, sortPSPopAsc, sortPSPopDesc), 0); pfsListing.addColumn(new ListingColumn(psHeaders[3], 1, 'pdat', false, drawPSTurrets, sortPSTurAsc, sortPSTurDesc), 0); pfsListing.addColumn(new ListingColumn(psHeaders[4], 1, 'pdat', false, drawPSFactories, sortPSFacAsc, sortPSFacDesc), 0); pfsListing.addColumn(new ListingColumn(psHeaders[5], 1, 'pflt', false, drawPSFleets, sortPSFltAsc, sortPSFltDesc), 0); pfsListing.addColumn(new ListingColumn(' ', 1, 'lspc', false, function () { return ' ' }, null, null), 1); pfsListing.addColumn(new ListingColumn(psHeaders[6], 1, 'seller', false, drawSeller, sortPSSelAsc, sortPSSelDesc), 1); pfsListing.addColumn(new ListingColumn(psHeaders[7], 2, 'sexp', false, drawExpire, sortPSExpAsc, sortPSExpDesc), 1); pfsListing.addColumn(new ListingColumn(psHeaders[8], 2, 'price', false, drawPrice, sortPSPriAsc, sortPSPriDesc), 1); pfsListing.addColumn(new ListingColumn(psHeaders[9], 1, 'action', false, drawPSAction, sortPSActAsc, sortPSActDesc), 1); pfsListing.emptyText = noPSales; pfsListing.notFound = noPSalesFound; // Public offers, Fleets ffsListing = new Listing('flsale','fOffers','ffsListing',searchText[1]); ffsListing.addColumn(new ListingColumn(fsHeaders[0], 3, 'pname', true, drawFSLocation, sortFSLocAsc, sortFSLocDesc), 0); ffsListing.addColumn(new ListingColumn(fsHeaders[1], 1, 'coords', false, drawCoords, sortFSCrdAsc, sortFSCrdDesc), 0); ffsListing.addColumn(new ListingColumn(fsHeaders[2], 1, 'ships', false, drawFSGAShips, sortFSGASAsc, sortFSGASDesc), 0); ffsListing.addColumn(new ListingColumn(fsHeaders[3], 1, 'ships', false, drawFSFighters, sortFSFgtAsc, sortFSFgtDesc), 0); ffsListing.addColumn(new ListingColumn(fsHeaders[4], 1, 'ships', false, drawFSCruisers, sortFSCruAsc, sortFSCruDesc), 0); ffsListing.addColumn(new ListingColumn(fsHeaders[5], 1, 'ships', false, drawFSBCruisers, sortFSBCrAsc, sortFSBCrDesc), 0); ffsListing.addColumn(new ListingColumn(' ', 1, 'lspc', false, function () { return ' ' }, null, null), 1); ffsListing.addColumn(new ListingColumn(fsHeaders[6], 1, 'seller', false, drawSeller, sortFSSelAsc, sortFSSelDesc), 1); ffsListing.addColumn(new ListingColumn(fsHeaders[7], 2, 'sexp', false, drawExpire, sortFSExpAsc, sortFSExpDesc), 1); ffsListing.addColumn(new ListingColumn(fsHeaders[8], 2, 'price', false, drawPrice, sortFSPriAsc, sortFSPriDesc), 1); ffsListing.addColumn(new ListingColumn(fsHeaders[9], 2, 'action', false, drawFSAction, sortFSActAsc, sortFSActDesc), 1); ffsListing.emptyText = noFSales; ffsListing.notFound = noFSalesFound; // Pending private offers proListing = new Listing('prpending', 'prOffers', 'proListing', searchText[0]); proListing.addColumn(new ListingColumn(proHeaders[0], 1, 'rdate', false, drawPRReceived, sortPRRecAsc, sortPRRecDesc), 0); proListing.addColumn(new ListingColumn(proHeaders[1], 1, 'seller', false, drawSeller, sortPRSelAsc, sortPRSelDesc), 0); proListing.addColumn(new ListingColumn(proHeaders[2], 1, 'price', false, drawPRPrice, sortPRPriAsc, sortPRPriDesc), 0); proListing.addColumn(new ListingColumn(proHeaders[3], 1, 'sexp', false, drawExpire, sortPRExpAsc, sortPRExpDesc), 0); proListing.addColumn(new ListingColumn(' ', 1, 'lspc', false, function () { return ' ' }, null, null), 1); proListing.addColumn(new ListingColumn(proHeaders[4], 3, 'details', false, drawPRDetails, null, null), 1); proListing.emptyText = noPOffers; proListing.notFound = noPOffersFound; proListing.perPage = 5; proListing.sortDir = true; // Private offers history prhListing = new Listing('prhistory', 'prHistory', 'prhListing', searchText[0]); prhListing.addColumn(new ListingColumn(prhHeaders[3], 1, 'rdate', false, drawPHActionDate, sortPHADtAsc, sortPHADtDesc), 0); prhListing.addColumn(new ListingColumn(prhHeaders[0], 1, 'rdate', false, drawPRReceived, sortPHRecAsc, sortPHRecDesc), 0); prhListing.addColumn(new ListingColumn(prhHeaders[4], 1, 'hstat', false, drawPHStatus, sortPHStaAsc, sortPHStaDesc), 0); prhListing.addColumn(new ListingColumn(prhHeaders[1], 1, 'seller', false, drawSeller, sortPHSelAsc, sortPHSelDesc), 0); prhListing.addColumn(new ListingColumn(prhHeaders[2], 1, 'price', false, drawPRPrice, sortPHPriAsc, sortPHPriDesc), 0); prhListing.addColumn(new ListingColumn(' ', 1, 'lspc', false, function () { return ' ' }, null, null), 1); prhListing.addColumn(new ListingColumn(prhHeaders[5], 4, 'details', false, drawPRDetails, null, null), 1); prhListing.emptyText = noPHist; prhListing.notFound = noPHistFound; prhListing.perPage = 5; prhListing.sortDir = true; // Pending sent offers sopListing = new Listing('sopending', 'soPending', 'sopListing', searchText[0]); sopListing.addColumn(new ListingColumn(sopHeaders[0], 1, 'rdate', false, drawPRReceived, sortSOSntAsc, sortSOSntDesc), 0); sopListing.addColumn(new ListingColumn(sopHeaders[1], 1, 'otype', false, drawSentMode, sortSOModAsc, sortSOModDesc), 0); sopListing.addColumn(new ListingColumn(sopHeaders[2], 1, 'price', false, drawSentPrice, sortSOPriAsc, sortSOPriDesc), 0); sopListing.addColumn(new ListingColumn(sopHeaders[3], 1, 'sexp', false, drawExpire, sortSOExpAsc, sortSOExpDesc), 0); sopListing.addColumn(new ListingColumn(sopHeaders[4], 1, 'buyer', false, drawSentBuyer, sortSOBuyAsc, sortSOBuyDesc), 0); sopListing.addColumn(new ListingColumn(' ', 1, 'lspc', false, function () { return ' ' }, null, null), 1); sopListing.addColumn(new ListingColumn(sopHeaders[5], 4, 'details', false, drawPRDetails, null, null), 1); sopListing.emptyText = noSOffers; sopListing.notFound = noSOffersFound; sopListing.perPage = 5; sopListing.sortDir = true; // Sent offers, history sohListing = new Listing('sohistory', 'soHistory', 'sohListing', searchText[0]); sohListing.addColumn(new ListingColumn(sohHeaders[0], 1, 'rdate', false, drawPHActionDate, sortSHADtAsc, sortSHADtDesc), 0); sohListing.addColumn(new ListingColumn(sohHeaders[1], 1, 'hstat', false, drawPHStatus, sortSHStaAsc, sortSHStaDesc), 0); sohListing.addColumn(new ListingColumn(sohHeaders[2], 1, 'rdate', false, drawPRReceived, sortSHSntAsc, sortSHSntDesc), 0); sohListing.addColumn(new ListingColumn(sohHeaders[3], 1, 'otype', false, drawSentMode, sortSHModAsc, sortSHModDesc), 0); sohListing.addColumn(new ListingColumn(sohHeaders[4], 1, 'price', false, drawSentPrice, sortSHPriAsc, sortSHPriDesc), 0); sohListing.addColumn(new ListingColumn(sohHeaders[5], 1, 'buyer', false, drawSentBuyer, sortSHBuyAsc, sortSHBuyDesc), 0); sohListing.addColumn(new ListingColumn(' ', 1, 'lspc', false, function () { return ' ' }, null, null), 1); sohListing.addColumn(new ListingColumn(sohHeaders[6], 5, 'details', false, drawPRDetails, null, null), 1); sohListing.emptyText = noSHist; sohListing.notFound = noSHistFound; sohListing.perPage = 5; sohListing.sortDir = true; e = document.getElementById('mkpinit').innerHTML; if (e.indexOf('\n') == -1 && e.split('#').length > 2) { var s = 'x_get' + pageHandlers[currentPage] + 'Offers(dataReceived)'; eval(s); } else dataReceived(e); } function selectPage(nb) { if (!lockUpdate(currentPage)) return; currentPage = nb; var s = 'x_get' + pageHandlers[currentPage] + 'Offers(dataReceived)'; eval(s); } //------------------------------------------------------------------------ // PUBLIC OFFERS DATA & ACTIONS //------------------------------------------------------------------------ function parsePublicOffers(data) { var l = data.split('\n'); var a = l.shift().split('#'); // Get map parameters mapCType = parseInt(a.shift(), 10); mapX = parseInt(a.shift(), 10); mapY = parseInt(a.shift(), 10); mapDist = parseInt(a.shift(), 10); mapParm = (mapCType > 0) ? a.join('#') : ''; // Get own planet list var i, np = parseInt(l.shift(),10); myPlanets = new Hashtable(); for (i=0;i -1) { sysPlanets = new Array(); for (i=0;i<6;i++) { a = l.shift().split("#"); sysPlanets.push(new SysPlanet(a.shift(),a.shift(),(a.shift()=='1'),(a.shift()=='1'),a.join('#'))); } } // Read offers pOffers = new Array(); fOffers = new Array(); sellers = new Hashtable(); a = l.shift().split('#'); var s='',nop=parseInt(a[0],10),nof=parseInt(a[1],10); if (nop+nof == 0) return; np = 0; // Planet offers for (i=0;i'; else str += 'prem_s.png" alt="[P]" />'; str += '' + name + ''; }} } else { for (i=0;i<6;i++) {with(sysPlanets[i]){ str += '' + name + ''; }} } str += ''; document.getElementById('mapcnt').innerHTML = str; } function drawPublicPage() { drawSystemMap(); pfsListing.updateDisplay(); ffsListing.updateDisplay(); } function updateMapControls() { var i; for (i=0;i<3;i++) document.getElementById('mct'+i).checked = (i==mapCType); document.getElementById('cx').value = mapX; document.getElementById('cy').value = mapY; var e = document.getElementById('mcpo'); for (i=0;i' + v.x + ',' + v.y + ','+v.orbit+')'; } function drawSeller(v) { var s = sellers.get(v.seller); return (s.isMe||s.quit ? '' : ('')) + s.name + (s.isMe||s.quit ? '' : ''); } function drawPrice(v) { return '€' + formatNumber(v.price); } // Planet sales listing functions function drawPSName(v) { var str = '[P]'; str += ''+v.name+''; return str; } function sortPSNameAsc(a,b) { var ra = pOffers[a].name.toLowerCase(), rb = pOffers[b].name.toLowerCase(); return (ra > rb) ? 1 : -1; } function sortPSNameDesc(a,b) { var ra = pOffers[a].name.toLowerCase(), rb = pOffers[b].name.toLowerCase(); return (ra > rb) ? -1 : 1; } function sortPSCrdAsc(a,b) { var va = pOffers[a]; var vb = pOffers[b]; return (va.x>vb.x)?1:(va.xvb.y?1:(va.yvb.orbit?1:-1)))); } function sortPSCrdDesc(a,b) { var va = pOffers[a]; var vb = pOffers[b]; return (va.x>vb.x)?-1:(va.xvb.y?-1:(va.yvb.orbit?-1:1)))); } function drawPSPop(v) { return formatNumber(v.population); } function sortPSPopAsc(a,b) { var ra=parseInt(pOffers[a].population,10),rb=parseInt(pOffers[b].population,10); return (ra>rb)?1:(rarb)?-1:(rarb)?1:(rarb)?-1:(rarb)?1:(rarb)?-1:(rarb)?1:(rarb)?-1:(rarb)?1:(rarb)?-1:(rarb)?1:(rarb)?-1:(rarb)?1:(rarb)?-1:(ra'; str += ''+v.plName+''; return str; } function sortFSLocAsc(a,b) { var ra = fOffers[a].plName.toLowerCase(), rb = fOffers[b].plName.toLowerCase(); return (ra>rb)?1:(rarb)?-1:(ravb.x)?1:(va.xvb.y?1:(va.yvb.orbit?1:(va.orbitvb.x)?-1:(va.xvb.y?-1:(va.yvb.orbit?-1:(va.orbitrb)?1:(rarb)?-1:(rarb)?1:(rarb)?-1:(rarb)?1:(rarb)?-1:(rarb)?1:(rarb)?-1:(rarb)?1:(rarb)?-1:(rarb)?1:(rarb)?-1:(rarb)?1:(rarb)?-1:(rarb)?1:-1; } function sortFSIdDesc(a,b) { var ra=parseInt(fOffers[a].id,10),rb=parseInt(fOffers[b].id,10); return (ra>rb)?-1:1; } //------------------------------------------------------------------------ // PRIVATE OFFERS DATA & ACTIONS //------------------------------------------------------------------------ var prOffers, prHistory; var proListing, prhListing; function PrivateOffer(id, seller, price, x, y, orbit, planet, fleet, started, expires, pName) { this.id = id; this.seller = seller; this.price = price; this.x = x; this.y = y; this.orbit = orbit; this.started = started; this.expires = expires; this.pName = pName; this.planet = [planet, 0, 0, 0]; this.fleet = [fleet, 0, 0, 0, 0]; this.match = PrivateOffer_match; } function PrivateHistory(seller, price, x, y, orbit, isPlanet, hasFleet, started, action, aDate, pName) { this.seller = seller; this.price = price; this.x = x; this.y = y; this.orbit = orbit; this.planet = [isPlanet, 0, 0, 0]; this.fleet = [hasFleet, 0, 0, 0, 0]; this.started = started; this.action = action; this.aDate = aDate; this.pName = pName; this.match = PrivateOffer_match; } function PrivateOffer_match(t) { return this.pName.toLowerCase().indexOf(t.toLowerCase()) != -1; } function parsePrivateOffers(data) { var l = data.split('\n'); var i, a = l.shift().split('#'); var nOffers = a[0], nHistory = a[1]; var s='',ns=0; // Read offers data prOffers = new Array(); for (i=0;irb)?1:(rarb)?-1:(rarb)?1:(rarb)?-1:(rarb)?1:(rarb)?-1:(rarb)?1:(rarb)?-1:(rarb)?1:(rarb)?-1:(rarb)?1:(rarb)?-1:(rarb)?1:(rarb)?-1:(rarb)?1:(rarb)?-1:(rarb)?1:(rarb)?-1:(rarb)?1:(rarb)?-1:(rarb)?1:(rarb)?-1:(rarb)?1:(rarb)?-1:(rarb)?1:(rarb)?-1:(rarb)?1:(rarb)?-1:(rarb)?1:(rarb)?-1:(rarb)?1:(rarb)?-1:(rarb)?1:(rarb)?-1:(rarb)?1:(rarb)?-1:(rarb)?1:(rarb)?-1:(rarb)?1:(rarb)?-1:(ra