var userToken = undefined;
var ajaxWaitCounter = 0;
var ajaxResponse = '';
// -------------------------------------------------------------- //
function queryInterface(ajaxAction, fieldid, additional, method, lbaction, giveBack, wait) {
if (! additional) additional = '';
if (! method) method = 'get';
ajaxResponse = false;
if (method == 'get') {
var url = 'ajax_interface.php?ajax_action=' + ajaxAction + additional + '&userToken=' + userToken;
new Ajax.Request(url, {
method: 'get',
onSuccess: function(transport) {
ajaxResponse = transport.responseText;
},
onFailure: function(failure) {
alert("error");
}
});
} else if (method == 'post') {
var url = 'ajax_interface.php?ajax_action=' + ajaxAction + '&userToken=' + userToken;
new Ajax.Request(url, {
method: 'post',
parameters: additional,
asynchronous: ! giveBack,
onSuccess: function(transport) {
ajaxResponse = transport.responseText;
},
onFailure: function(failure) {
alert("error");
}
});
}
if (fieldid && wait) {
waitForAjaxhandler('reload', fieldid, lbaction);
} else {
if (fieldid && ! wait) {
if (giveBack) return ajaxResponse;
else if (lbaction) loadLightbox(fieldid, lbaction);
} else if (wait) {
waitForAjaxhandler('',fieldid);
}
}
return ajaxResponse;
}
// ---------------------------------------------------------------- //
function cancelTransport(transport_id, fieldid) {
queryInterface('cancelJob', fieldid, '&jobNr=' + transport_id + '&jobType=marketTransport');
}
// ---------------------------------------------------------------- //
function cancelTroupAction(ta_id) {
queryInterface('cancelJob', false, '&jobNr=' + ta_id + '&jobType=action');
waitForAjaxhandler('');
}
// --------------------------------------------------------------- //
function hideAllTooltips() {
//var tooltips = document.getElementsByClassName('prototip');
for (var i = 0; i < Tips.tips.length; i++) {
Tips.tips[i].hide();
}
}
// ---------------------------------------------------------------- //
function hideServerMessage() {
for (i = 0; i < Tips.tips.length; i++) {
if (Tips.tips[i].element && Tips.tips[i].element.id == 'servermessage') {
Tips.tips[i].hide();
}
}
}
// ---------------------------------------------------------------- //
function sendStuff(fieldid) {
var amountWood = parseInt($('mWood').value);
var amountBrick = parseInt($('mBrick').value);
var amountOre = parseInt($('mOre').value);
var amountFood = parseInt($('mFood').value);
if (isNaN(amountWood)) amountWood = 0;
if (isNaN(amountBrick)) amountBrick = 0;
if (isNaN(amountOre)) amountOre = 0;
if (isNaN(amountFood)) amountFood = 0;
if (amountWood + amountBrick + amountFood + amountOre == 0) {
alert(LANG_NO_RES_INSERTED);
return false;
}
var max = $('max').value.split("|");
if (amountWood > max[0] || amountBrick > max[1] || amountOre > max[2] || amountFood > max[3]) {
alert(LANG_NOT_ENOUGH_RES);
return false;
}
if (amountWood + amountBrick + amountOre + amountFood > max[4]) {
alert(LANG_NOT_ENOUGH_MERCHANTS);
return false;
}
var targetX = parseInt($('marketX').value);
var targetY = parseInt($('marketY').value);
if (isNaN(targetX) || isNaN(targetY)) {
alert(LANG_BAD_COORDS);
return false;
}
var param = '&amountWood=' + amountWood + '&amountBrick=' + amountBrick + '&amountOre=' + amountOre + '&amountFood=' + amountFood + '&targetX=' + targetX + '&targetY=' + targetY;
queryInterface('requestMarketTransport', fieldid, param, 'get', '', false, true);
}
// ----------------------------------------------------------------------------------------------------------------- //
function paySettler(fieldid) {
// Siedler-Anzahlungen
//var amount = $('stockAmount').value;
//alert(amount + " mal einlagern");
$('paySettlerButton').update("
");
queryInterface('stockIn');
waitForAjaxhandler('reload', fieldid);
}
// ----------------------------------------------------------------------------------------------------------------- //
function deleteAlly(fieldid) {
if (window.confirm(LANG_REALLY_CLOSE_ALLY)) {
queryInterface('deleteAlly', fieldid, '', 'get', 'building', false, true);
}
}
// ----------------------------------------------------------------------------------------------------------------- //
function setNewFounder(fieldid) {
if (window.confirm(LANG_REALLY_GIVE_LEADERSHIP)) {
var newFounder = $('newfounder').value;
queryInterface('setNewFounder', fieldid, '&newFounder=' + newFounder);
}
}
// ----------------------------------------------------------------------------------------------------------------- //
function showEmbassy() {
$('buildcontainer_0').toggle();
$('embassyContent').toggle();
}
// ----------------------------------------------------------------------------------------------------------------- //
function leaveAlly(fieldid) {
queryInterface('leaveAlly', fieldid, false, false, 'invitations');
}
// ----------------------------------------------------------------------------------------------------------------- //
function setAllyProfile(fieldid) {
var profileForm = Form.serialize($('editAllyProfile'));
queryInterface('setAllyProfile', fieldid, profileForm, 'post', 'options&lboption=profile');
}
// ----------------------------------------------------------------------------------------------------------------- //
function setEmbassyRights(fieldid) {
var formdata = Form.serialize($('memberRights'));
var responseCheck = queryInterface('setEmbassyRights', fieldid, formdata, 'post', 'options', true);
if (responseCheck == 'right A missing') alert(LANG_YOU_CANNOT_TAKE_THIS_RIGHT);
else loadLightbox(fieldid, 'options');
}
// ----------------------------------------------------------------------------------------------------------------- //
function acceptMarketOffer(offerid, fieldid) {
queryInterface('acceptMarketOffer', fieldid, '&offerid=' + offerid, 'get', '', false, true);
}
// ----------------------------------------------------------------------------------------------------------------- //
function createAllyTopic(fieldid) {
var data = $('newThread').serialize(true);
queryInterface('newThread', fieldid, data, 'post', 'forum');
}
// ----------------------------------------------------------------------------------------------------------------- //
function answerToThread(fieldid) {
var data = $('answerThread').serialize(true);
var thread_id = $('threadId').value;
queryInterface('answerToThread', fieldid, data, 'post', 'forum&forumaction=showThread&thread=' + thread_id);
}
// ----------------------------------------------------------------------------------------------------------------- //
function deletePosting(fieldid, postingid) {
if (window.confirm(LANG_REALLY_DELETE_POSTING)) {
queryInterface('deletePosting', fieldid, '&postingId=' + postingid, 'get', 'forum');
}
}
// ----------------------------------------------------------------------------------------------------------------- //
function deleteTopic(fieldid, topicid) {
if (window.confirm(LANG_REALLY_DELETE_TOPIC)) {
queryInterface('deleteTopic', fieldid, '&topicId=' + topicid, 'get', 'forum');
}
}
// ----------------------------------------------------------------------------------------------------------------- //
function newDiplomacy(fieldid) {
var allyshort = document.getElementById('markupShort').value;
var dipltype = document.getElementById('markupType').value;
var check = queryInterface('newDiplomacy', fieldid, '&markupShort=' + encodeURIComponent(allyshort) + '&diplType=' + dipltype, 'get',
'options&lboption=diplomacy', true);
if (check == 'nnf') alert(LANG_NO_ALLY_FOUND);
else {
loadLightbox(fieldid, 'options&lboption=diplomacy');
}
}
// ----------------------------------------------------------------------------------------------------------------- //
function deleteNews(fieldid) {
queryInterface('deleteNews', fieldid, '', 'get', 'news');
}
// ----------------------------------------------------------------------------------------------------------------- //
function cancelDiplomacy(fieldid, diplid) {
queryInterface('cancelDiplomacy', fieldid, '&markupId=' + diplid, 'get', 'options&lboption=diplomacy');
}
// ----------------------------------------------------------------------------------------------------------------- //
function fireFromAlly(userId, fieldid, username) {
if (window.confirm(sprintf(LANG_REALLY_FIRE_FROM_ALLY, username))) {
queryInterface('fireFromAlly', fieldid, '&memberid=' + userId, 'get', 'options');
}
}
// ----------------------------------------------------------------------------------------------------------------- //
function trim(s) {
while (s.substring(0,1) == ' ') {
s = s.substring(1,s.length);
}
while (s.substring(s.length-1,s.length) == ' ') {
s = s.substring(0,s.length-1);
}
return s;
}
// ----------------------------------------------------------------------------------------------------------------- //
function acceptAllyInvitation(fieldid, invId) {
queryInterface('acceptAllyInvitation', fieldid, '&invId=' + invId, 'get', '', false, true);
}
// ----------------------------------------------------------------------------------------------------------------- //
function deleteInv(invId, fieldid) {
queryInterface('deleteInvitation', fieldid, '&invId=' + invId, 'get', 'options&lboption=invitations');
}
// ----------------------------------------------------------------------------------------------------------------- //
function allyInvite(fieldid) {
name = $('newInvName').value;
if (trim(name) != '') {
test = queryInterface('inviteToAlly', fieldid, 'name=' + encodeURIComponent(name), 'post','' , true);
}
if (test == 'n/a') alert(LANG_NO_PLAYER_FOUND);
else if(test == 'double') alert(LANG_PLAYER_ALREADY_INVITED);
else if (test == 'inthere') alert(LANG_PLAYER_ALREADY_IN_ALLY);
loadLightbox(fieldid, 'options&lboption=invitations');
}
// ----------------------------------------------------------------------------------------------------------------- //
function createAlly(fieldid) {
var name = trim($('allyName').value);
var allyShort = trim($('allyShort').value);
if (name.length >= 3 && name.length <= 50 && allyShort.length <= 6 && allyShort.length >= 3) {
var url = 'ajax_interface.php?ajax_action=makeNewAlly&userToken=' + userToken + '&allyName=' + encodeURIComponent(name) + '&allyShort=' + encodeURIComponent(allyShort);
new Ajax.Request(url, {
method: 'get',
onSuccess: function(transport) {
if (transport.responseText == 'done') {
loadLightbox(fieldid, 'overview');
} else if (transport.responseText == 'doubleNameError') alert(LANG_ALLY_NAME_EXISTING);
},
onFailure: function(failure) {
alert("error");
}
});
} else {
alert(LANG_FOUND_ALLY_NAME_ERROR);
}
}
// ----------------------------------------------------------------------------------------------------------------- //
function placeMarketOffer(fieldid) {
var maxAmount = 1000 * 50;
for(var i = 0; i < $('newOffer').offeringType.length; i++) {
if ($('newOffer').offeringType[i].checked) var offeringType = $('newOffer').offeringType[i].value;
}
var offeringAmount = parseInt($('offeringAmount').value, 10);
for (var i = 0; i < $('newOffer').wantingType.length; i++) {
if ($('newOffer').wantingType[i].checked) var wantingType = $('newOffer').wantingType[i].value;
}
var wantingAmount = parseInt($('wantingAmount').value, 10);
/*
if (wantingAmount > maxAmount) {
alert(LANG_MARKET_MAX_ERROR);
return false;
}
*/
var ratio = offeringAmount / wantingAmount;
if (ratio > 3 || ratio < 0.333) {
alert(LANG_MARKET_RATIO_ERROR);
return false;
}
if (! isNaN(offeringAmount) && ! isNaN(wantingAmount)) {
if (offeringType == wantingType) {
alert(LANG_OFFER_SEARCH_ERROR);
} else {
if (offeringType == 'wood' || offeringType == 'brick' || offeringType == 'ore' || offeringType == 'food') {
var runtime = parseInt($('runtimeValue').value);
if (isNaN(runtime) || runtime > 24) runtime = 12;
// Check ob genügend vorhanden
var max = $('max').value.split("|");
var maxMerchantCapacity = max[4];
if (offeringType == 'wood') max = max[0];
else if (offeringType == 'brick') max = max[1];
else if (offeringType == 'ore') max = max[2];
else if (offeringType == 'food') max = max[3];
if (offeringAmount > max) {
alert(LANG_NOT_ENOUGH_RES);
} else {
var url = 'ajax_interface.php?ajax_action=newMarketOffer&userToken=' + userToken + '&offeringType=' + offeringType + '&offeringAmount=' + offeringAmount + '&wantingType=' + wantingType + '&wantingAmount=' + wantingAmount + '&runtime=' + runtime;
if (offeringAmount > maxMerchantCapacity) {
alert(sprintf(LANG_MARKET_FREE_MERCHANTS_ERROR, Math.ceil(offeringAmount / 1000)));
return false;
}
new Ajax.Request(url, {
method: 'get',
onSuccess: function(transport) {
loadLightbox(fieldid, 'myoffers');
},
onFailure: function(failure) {
alert("error");
}
});
}
}
}
} else {
alert(LANG_BAD_ENTRY);
}
}
// --------------------------------------------------------- //
function deleteMarketOffer(offerid, fieldid) {
if (! isNaN(offerid)) {
$('deletecell_' + offerid).update('
');
var url = 'ajax_interface.php?ajax_action=cancelJob&userToken=' + userToken + '&jobType=marketOffer&jobNr=' + offerid;
new Ajax.Request(url, {
method: 'get',
onSuccess: function(transport) {
loadLightbox(fieldid, 'myoffers');
},
onFailure: function(failure) {
alert("error");
}
});
} else {
alert(LANG_BAD_ENTRY);
}
}
// --------------------------------------------------------- //
function groupMilitary(fieldid, type, level) {
$('groupMilitaryCell_' + type + '_Lvl_' + level).innerHTML = '
';
var additional = '&mType=' + type + '&level=' + level;
queryInterface('groupMilitary', fieldid, additional, 'get', '', false, true);
}
// --------------------------------------------------------- //
function ungroupMilitary(fieldid, groupid) {
$('ungroupMilitaryCell_' + groupid).innerHTML = '
';
var additional = '&groupId=' + groupid;
queryInterface('ungroupMilitary', fieldid, additional, 'get', '', false, true);
}
// --------------------------------------------------------- //
function sendBackTroupsFromGoldmine(supportId, isGroup, gmMapId, fieldid, otherparams) {
var add = '&supportId=' + supportId + '&gmMapId=' + gmMapId;
if (isGroup) add += '&isGroup=1';
//queryInterface('sendBackGoldmineTroops', fieldid, add, 'get', 'goldmines', false, true);
var url = 'ajax_interface.php?ajax_action=sendBackGoldmineTroops' + add + '&userToken=' + userToken;
new Ajax.Request(url, {
method: 'get',
onSuccess: function(transport) {
loadLightbox(fieldid, false, otherparams);
},
onFailure: function(failure) {
alert("error");
}
});
}
// --------------------------------------------------------- //
function transcribeGoldmine(ownerId, goldmineMapId) {
add = '&ownerId=' + ownerId + '&goldmineMapId=' + goldmineMapId;
queryInterface('changeGoldmineOwner', 0, add);
var sleepd = new Date();
var until = sleepd.getTime() + 200;
while (sleepd.getTime() < until) {
sleepd = new Date();
}
loadContentLightbox('lb_main.php?action=goldmine&mapID=' + goldmineMapId, false, true);
}
// --------------------------------------------------------- //
function sendBackSupporta(supportId, fieldid, isGroup) {
$('sendback_' + supportId).update('
');
var add = '&supportId=' + supportId
if (isGroup) add = add + '&isGroup=1';
var url = 'ajax_interface.php?ajax_action=sendBackSupport' + add + '&userToken=' + userToken;
new Ajax.Request(url, {
method: 'get',
onSuccess: function(transport) {
loadLightbox(fieldid, false, '&placeaction=troups');
},
onFailure: function(failure) {
alert("error");
}
});
}
// --------------------------------------------------------- //
function sendBackSupport(fieldId, whosetroops, villageId, isGoldmine) {
$('sendback_all_' + whosetroops).update('
');
var sendstring = '&sendunitsType=back';
var formValues = document.getElementsByClassName('toJs ' + villageId);
for(i = 0; i < formValues.length; i++) {
if (formValues[i].value && (formValues[i].type != 'checkbox' || formValues[i].checked)) {
sendstring = sendstring + '&' + formValues[i].name + '=' + formValues[i].value;
}
}
//alert("sendstring: "+sendstring);
//alert("huhu?" + isGoldmine);
var url = 'ajax_interface.php?ajax_action=sendBackSupport&whosetroops=' + whosetroops + sendstring + '&isgoldmine=' + isGoldmine + '&userToken=' + userToken;
new Ajax.Request(url, {
method: 'get',
onSuccess: function(transport) {
loadLightbox(fieldId, false, '&placeaction=troups&whosetroops=' + whosetroops);
},
onFailure: function(failure) {
alert("error");
}
});
}
// --------------------------------------------------------- //
function sendBackAllSupport(fieldId, whosetroops) {
$('allSupportBackBox').update('
');
var url = 'ajax_interface.php?ajax_action=sendBackAllSupport&whosetroops=' + whosetroops + '&userToken=' + userToken;
new Ajax.Request(url, {
method: 'get',
onSuccess: function(transport) {
loadLightbox(fieldId, false, '&placeaction=troups&whosetroops=' + whosetroops);
},
onFailure: function(failure) {
alert("error");
}
});
}
// --------------------------------------------------------- //
function changeGMName(fieldid, gmMapId) {
var newName = $('newGMName').value;
add = '&newGMName=' + encodeURIComponent(newName) + '&gmMapId=' + gmMapId;
queryInterface('changeGMName', fieldid, add, 'get', 'goldmines', false, true);
}
// --------------------------------------------------------- //
function delKB(fieldid) {
// Goldminenkbs Löschen
var cb = document.getElementsByClassName('delKB');
var kbstring = '';
for (var i = 0; i < cb.length; i++) {
if (cb[i].checked && ! isNaN(parseInt(cb[i].value))) {
var additional = '&kbId=' + parseInt(cb[i].value);
queryInterface('delGMKb', fieldid, additional);
}
}
waitForAjaxhandler('reload', fieldid, 'goldmines&gmOption=gmReports');
}
// --------------------------------------------------------- //
function request_research(researchunit, researchtype, fieldid) {
$(researchtype + "_" + researchunit).update('
');
queryInterface('requestResearchStart', fieldid, '&researchtype=' + researchtype + '&researchunit=' + researchunit,
'', '', '', true);
}
// --------------------------------------------------------- //
function cancel_research(research_id, fieldid) {
$('cancelResearch').update('
');
queryInterface('cancelJob', fieldid, '&jobType=research&jobNr=' + research_id,
'', '', '', true);
}
// --------------------------------------------------------- //
function clearTooltips() {
// Alle tooltips entfernen
var spans = document.getElementsByTagName('span');
var buttons = document.getElementsByTagName('button');
for (var i = 0; i < spans.length; i++) {
var s = $(spans[i]);
Tips.remove(s);
}
}
// --------------------------------------------------------- //
function requestMilitaryAction(field_id, attackType) {
var url = 'ajax_interface.php?ajax_action=requestTroupactionStart&userToken=' + userToken;
troupInfo = $('troupactionInfo').serialize(true);
$('unitsendSubmit').innerHTML = '
';
new Ajax.Request(url, {
method: 'post',
parameters:
troupInfo,
onSuccess: function(transport) {
if (attackType == 'explore' && transport.responseText == 'n/a') {
alert(LANG_TRYING_SEND_FEW_EXPL);
$('unitsendSubmit').innerHTML = '';
} else {
var pseudoLink = document.createElement('a');
lb = new lightbox(pseudoLink);
lb.close();
if (! isNaN(parseInt(transport.responseText))) {
// Event-ID eingetragen
checkAttackInserted(parseInt(transport.responseText));
}
}
},
onFailure:
function(failure) {
alert("error");
}
});
}
// --------------------------------------------------------- //
function requestInstantSettle(field_id, map_x, map_y) {
var url = 'ajax_interface.php?ajax_action=requestInstantSettle&userToken=' + userToken;
troupInfo = $('troupactionInfo').serialize(true);
$('instantSettleSubmit').innerHTML = '
';
new Ajax.Request(url, {
method: 'post',
parameters:
troupInfo,
onSuccess: function(transport) {
loadLightbox(field_id, false, '&action=viewarea&mapX='+map_x+'&mapY='+map_y);
},
onFailure: function(failure) {
alert("error");
}
});
}
// --------------------------------------------------------- //
function updateLightbox(fieldid) {
if ($('nu_remain')) $('nu_remain').innerHTML = '
';
resUpdateOnce();
loadLightbox(fieldid);
}
// ---------------------------------------------------------------- //
function insertFav(fieldid, input, reportid) {
if ($('favCoords_' + input)) var input = $('favCoords_' + input).value.split('|');
else var input = input.split('|');
if (! isNaN(parseInt(input[0])) && ! isNaN(parseInt(input[1]))) {
queryInterface('insertFavTarget', fieldid, '&x=' + input[0] + '&y=' + input[1]);
} else {
alert(LANG_INSERT_COORDS_LIKE_THIS);
}
if (reportid > 0) {
return;
}
if (! fieldid) {
loadContentLightbox('lb_main.php?action=viewarea&mapX=' + input[0] + '&mapY=' + input[1], false, true);
} else {
loadLightbox(fieldid, false, '&placeaction=favtargets');
}
}
// ---------------------------------------------------------------- //
function deleteFav(fieldid, favid) {
if (favid && ! isNaN(favid)) {
queryInterface("deleteFavTarget", fieldid, '&favid=' + favid);
loadLightbox(fieldid, false, '&placeaction=favtargets');
}
}
// ---------------------------------------------------------------- //
function loadContentLightbox(location, update, reload) {
var location = 'lightbox_content/' + location;
var pseudoLink = document.createElement('a');
pseudoLink.href = location;
lb = new lightbox(pseudoLink);
if (reload) lb.loadContent(location);
else lb.activate(update);
}
// ---------------------------------------------------------------- //
function loadLightbox(fieldid, lbaction, otherparams) {
var pseudoLink = document.createElement('a');
lb = new lightbox(pseudoLink);
var location = 'lightbox_content/lb_main.php?action=build&field_build=' + fieldid;
if (lbaction) location = location + '&lbaction=' + lbaction;
if (otherparams) location = location + otherparams;
lb.loadContent(location);
hideAllTooltips();
}
// ----------------------------------------------------------------- //
function goHome() {
window.location.href = 'user.php';
}
// ----------------------------------------------------------------- //
function requestFillAsManyGroupsAsPossible(unitType, fieldid) {
$('formcell_fillAllGroups').innerHTML = '
';
var url = 'ajax_interface.php?ajax_action=requestFillAsManyGroupsAsPossible&unit_type=' + unitType + '&userToken=' + userToken;
new Ajax.Request(url, {
method: 'get',
onSuccess: function(transport) {
loadLightbox(fieldid);
},
onFailure: function(failure) {
alert("error");
}
});
}
// ----------------------------------------------------------------- //
function requestMilitary(form, fieldid) {
var type = parseInt($('formid_' + form).unitID.value);
if ($('formid_' + form).unitCount) var count = parseInt($('formid_' + form).unitCount.value);
else count = 0;
if ($('formid_' + form).groupID) var group = parseInt($('formid_' + form).groupID.value);
else group = 0;
if (! isNaN(type) && ! isNaN(count)) {
$('formcell_' + form).innerHTML = '
';
var url = 'ajax_interface.php?ajax_action=requestMilitary&count=' + count +'&type=' + type + '&group=' + group + '&userToken=' + userToken;
new Ajax.Request(url, {
method: 'get',
onSuccess: function(transport) {
loadLightbox(fieldid);
},
onFailure: function(failure) {
alert("error");
}
});
} else {
//alert(type + " " + count + " form:" + form);
}
}
// -------------------------------------------------------------- //
function setVacationMode() {
$('vacCell').innerHTML = '
';
var url = 'ajax_interface.php?ajax_action=setVacMode&userToken=' + userToken;
new Ajax.Request(url, {
method: 'get',
onSuccess: function(transport) {
if (transport.responseText == 'done') {
window.location = 'index.php';
}
},
onFailure: function(failure) {
alert("error");
}
});
}
// ----------------------------------------------------------------- //
function requestBuilding(key, teardown) {
var fieldid = parseInt($('buildform_' + key).field_construct.value);
var buildid = parseInt($('buildform_' + key).build_construct.value);
if (fieldid && buildid && ! isNaN(fieldid) && ! isNaN(buildid)) {
if (teardown) var action = 'requestTeardown';
else var action = 'requestBuilding';
$('buildcontainer_' + key).innerHTML = '
';
var url = 'ajax_interface.php?ajax_action=' + action + '&field=' + fieldid +'&building=' + buildid + '&userToken=' + userToken;
new Ajax.Request(url, {
method: 'get',
onSuccess: function(transport) {
waitForAjaxhandler('buildingRequest');
},
onFailure: function(failure) {
alert("error");
}
});
}
}
// ----------------------------------------------------------------- //
function requestPremFeature(feature, duration) {
$('button_f_' + feature + '_d_' + duration).disabled=true;
var url = 'ajax_interface.php?ajax_action=requestPremFeature&userToken=' + userToken + '&feature=' + feature + '&duration=' + duration;
new Ajax.Request(url, {
method: 'get',
onSuccess: function(transport) {
if (transport.responseText.isJSON()) {
var answer = transport.responseText.evalJSON();
var buttons = document.getElementsByClassName('premiumButtons');
for (var i = 0; i < buttons.length; i++) {
if (answer.disableButtons[buttons[i].id]){
buttons[i].style.display = 'none';
$(buttons[i].id.split('button').join('link')).style.display = 'inline-block';
}
}
$('ressourceNugget').innerHTML = answer.nuggets;
$(answer.feature + 'Left').innerHTML = answer.duration;
}
$('button_f_' + feature + '_d_' + duration).disabled=false;
//window.location = 'user.php?action=home';
},
onFailure: function(failure) {
alert("error");
}
});
}
// ---------------------------------------------------------------- //
function requestPremMerch() {
var diffWood = parseInt($('diffWood').innerHTML.split('+').join(''));
var diffBrick = parseInt($('diffBrick').innerHTML.split('+').join(''));
var diffOre = parseInt($('diffOre').innerHTML.split('+').join(''));
var diffFood = parseInt($('diffFood').innerHTML.split('+').join(''));
var sum = parseInt($('sum').innerHTML);
if (sum != 0) {
alert(LANG_PREMMERCH_NO_MATCH);
return false;
}
if (diffWood == 0 && diffBrick == 0 && diffOre == 0 && diffFood == 0) {
alert(LANG_PREMMERCH_NOT_SET);
return false;
}
var nuggetCost = parseInt($('premNuggetCost').innerHTML);
var nuggetRessource = parseInt($('ressourceNugget').innerHTML);
if (nuggetCost > nuggetRessource) {
alert(LANG_NOT_ENOUGH_NUGGETS);
return false;
}
var url = 'ajax_interface.php?ajax_action=requestPremMerch&userToken=' + userToken + '&w=' + diffWood + '&b=' + diffBrick + '&o=' + diffOre + '&f=' + diffFood;
new Ajax.Request(url, {
method: 'get',
onSuccess: function(transport) {
window.location = 'user.php?action=home';
},
onFailure: function(failure) {
alert("error");
}
});
}
// --------------------------------------------------------------- //
//merchantFeature
function calculateMerchantsCapacity() {
if(parseInt($('mWood').value, 10) > (parseInt($('mmWood').innerHTML, 10) + parseInt($('invisHelperWood').value, 10))) {var intInputWood = (parseInt($('mmWood').innerHTML, 10) + parseInt($('invisHelperWood').value, 10));} else if(parseInt($('mWood').value, 10) > $('invisMaxWood').value) {var intInputWood = parseInt($('invisMaxWood').value);} else if(parseInt($('mWood').value, 10) > 0) {var intInputWood = parseInt($('mWood').value, 10);} else {var intInputWood = 0;}
if(parseInt($('mBrick').value, 10) > (parseInt($('mmBrick').innerHTML, 10) + parseInt($('invisHelperBrick').value, 10))) {var intInputBrick = (parseInt($('mmBrick').innerHTML, 10) + parseInt($('invisHelperBrick').value, 10));} else if(parseInt($('mBrick').value, 10) > $('invisMaxBrick').value) {var intInputBrick = $('invisMaxBrick').value;} else if(parseInt($('mBrick').value, 10) > 0) {var intInputBrick = parseInt($('mBrick').value, 10);} else {var intInputBrick = 0;}
if(parseInt($('mOre').value, 10) > (parseInt($('mmOre').innerHTML, 10) + parseInt($('invisHelperOre').value, 10))) {var intInputOre = (parseInt($('mmOre').innerHTML, 10) + parseInt($('invisHelperOre').value, 10));} else if(parseInt($('mOre').value, 10) > $('invisMaxOre').value) {var intInputOre = $('invisMaxOre').value;} else if(parseInt($('mOre').value, 10) > 0) {var intInputOre = parseInt($('mOre').value, 10);} else {var intInputOre = 0;}
if(parseInt($('mFood').value, 10) > (parseInt($('mmFood').innerHTML, 10) + parseInt($('invisHelperFood').value, 10))) {var intInputFood = (parseInt($('mmFood').innerHTML, 10) + parseInt($('invisHelperFood').value, 10));} else if(parseInt($('mFood').value, 10) > $('invisMaxFood').value) {var intInputFood = $('invisMaxFood').value;} else if(parseInt($('mFood').value, 10) > 0) {var intInputFood = parseInt($('mFood').value, 10);} else {var intInputFood = 0;}
$('mWood').value = intInputWood;
$('mBrick').value = intInputBrick;
$('mOre').value = intInputOre;
$('mFood').value = intInputFood;
$('invisHelperWood').value = intInputWood;
$('invisHelperBrick').value = intInputBrick;
$('invisHelperOre').value = intInputOre;
$('invisHelperFood').value = intInputFood;
var onMerchants = intInputWood + intInputBrick + intInputOre + intInputFood;
//alert('on merchants: ' + onMerchants);
var canCapacity = $('invisMaxCapacity').value - onMerchants;
var canWood = $('invisMaxWood').value - $('mWood').value;
var canBrick = $('invisMaxBrick').value - $('mBrick').value;
var canOre = $('invisMaxOre').value - $('mOre').value;
var canFood = $('invisMaxFood').value - $('mFood').value;
if(canCapacity < canWood) {canWood = canCapacity;}
if(canCapacity < canBrick) {canBrick = canCapacity;}
if(canCapacity < canOre) {canOre = canCapacity;}
if(canCapacity < canFood) {canFood = canCapacity;}
if(canWood > 0) {$('mmWood').innerHTML = canWood;} else {$('mmWood').innerHTML = '0';}
if(canBrick > 0) {$('mmBrick').innerHTML = canBrick;} else {$('mmBrick').innerHTML = 0;}
if(canOre > 0) {$('mmOre').innerHTML = canOre;} else {$('mmOre').innerHTML = 0;}
if(canFood > 0) {$('mmFood').innerHTML = canFood;} else {$('mmFood').innerHTML = 0;}
}
// --------------------------------------------------------------- //
function checkAttackInserted(eventId) {
var url = 'ajax_interface.php?ajax_action=checkAttackInserted&eventId=' + eventId + '&userToken=' + userToken;
new Ajax.Request(url, {
method: 'get',
onSuccess: function(transport) {
if (transport.responseText.isJSON()) {
var answer = transport.responseText.evalJSON();
$('attackStartedMessage').innerHTML = '