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("loading"); 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('loading...'); 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 = 'loading...'; var additional = '&mType=' + type + '&level=' + level; queryInterface('groupMilitary', fieldid, additional, 'get', '', false, true); } // --------------------------------------------------------- // function ungroupMilitary(fieldid, groupid) { $('ungroupMilitaryCell_' + groupid).innerHTML = 'loading...'; 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('loading...'); 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('loading...'); 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('loading...'); 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('loading...'); queryInterface('requestResearchStart', fieldid, '&researchtype=' + researchtype + '&researchunit=' + researchunit, '', '', '', true); } // --------------------------------------------------------- // function cancel_research(research_id, fieldid) { $('cancelResearch').update('loading...'); 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 = 'loading...'; 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 = 'loading...'; 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 = 'loading...'; 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 = 'loading...'; 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 = 'loading...'; 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 = 'loading...'; 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 = 'loading...'; 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 = '
'; $('attackStartedMessage').innerHTML += '
'; $('attackStartedMessage').innerHTML += '
'; $('attackStartedMessage').innerHTML += '
'; $('attackStartedMessage').innerHTML += '
'; $('attackStartedMessage').innerHTML += '
'; $('attackStartedMessage').innerHTML += '
'; $('attackStartedMessage').innerHTML += '
'; $('attackStartedMessage').innerHTML += answer.attacktype + '
'; $('attackStartedMessage').innerHTML += answer.target + '
'; $('attackStartedMessage').innerHTML += answer.ta_arrive + '
'; $('attackStartedMessage').show(); window.setTimeout('hideAttackMessage()', 2000); } } }); } // ---------------------------------------------------------------- // function hideAttackMessage() { $('attackStartedMessage').hide(); } // ---------------------------------------------------------------- // /****************************************************************************/ /******************************* Winning Ally List **************************/ /****************************************************************************/ // --------// function maximizeAllyWinningCountdown() { $('allyWinningCountdownMinimized').hide(); $('allyWinningCountdownMaximized').show(); } // --------// function minimizeAllyWinningCountdown() { $('allyWinningCountdownMaximized').hide(); $('allyWinningCountdownMinimized').show(); } /****************************************************************************/ /******************************* Winning Ally List ENDE *********************/ /****************************************************************************/ // ---------------------------------------------------------------- / function waitForAjaxhandler(eventType, fieldid, lbaction) { var url = 'ajax_interface.php?ajax_action=waitForEventhandler&userToken=' + userToken; new Ajax.Request(url, { method: 'get', onSuccess: function(transport) { if (transport.responseText == 'done') { if (eventType == 'militaryRequest' || eventType == 'reload') { loadLightbox(fieldid, lbaction); } else if (eventType == 'artefacts') { window.location = 'user.php?action=artefacts'; } else if (eventType == 'actionRequest') { // } else { goHome(); } } }, onFailure: function(failure) { alert("error"); } }); } // --------------------------------------------------------- // function cancelJob(jobNr, jobType, fieldId) { jobNr = parseInt(jobNr); if (! isNaN(jobNr) && (jobType == 'barracks' || jobType == 'building')) { if (jobType == 'barracks') { $('cancelCell_' + jobNr).update("loading..."); } var url = 'ajax_interface.php?ajax_action=cancelJob&jobNr=' + jobNr + '&jobType=' + jobType + '&userToken=' + userToken; new Ajax.Request(url, { method: 'get', onSuccess: function(transport) { if (jobType == 'barracks') { loadLightbox(fieldId); } else { goHome(); } }, onFailure: function(failure) { alert("error"); } }); } } // --------------------------------------------------------- // function insertMaxUnits(field, count) { $('unitCount_' + field ).value = count; } // --------------------------------------------------------- // function decreaseCount() { $('unitCount').innerHTML = parseInt($('unitCount').innerHTML) - 1; } // --------------------------------------------------------- // function changeFarmerPrio(field_id, value) { queryInterface('changeFarmerPrio', field_id, '&newPrio=' + value, 'get', false, true); $('changePrioSubmit').innerHTML = 'loading...'; waitForAjaxhandler('reload', field_id); } // --------------------------------------------------------- // updateResView = function (request) { if (request.responseText.isJSON()) { //alert("fooo! " + request.responseText); var res = request.responseText.evalJSON(); $('ressourceWood').update(res.res.wood); $('ressourceBrick').update(res.res.brick); $('ressourceOre').update(res.res.ore); $('ressourceFood').update(res.res.food); if (res.ofl.wood) $('ressourceWood').className = 'overflow'; else $('ressourceWood').className = ''; if (res.ofl.brick) $('ressourceBrick').className = 'overflow'; else $('ressourceBrick').className = ''; if (res.ofl.ore) $('ressourceOre').className = 'overflow'; else $('ressourceOre').className = ''; if (res.ofl.food) $('ressourceFood').className = 'overflow'; else $('ressourceFood').className = ''; return; /* $('militaryScrollable').update(''); rows = 0; res.mil.each(function(military, index) { //alert (military.name + ' ' + military.count + ' ' + military.image); var row = $('militaryInVillage').insertRow(rows); var td1 = document.createElement('td'); td1.innerHTML = '' + military.name + ''; var td2 = document.createElement('td'); td2.appendChild(document.createTextNode(military.count)); var td3 = document.createElement('td'); td3.appendChild(document.createTextNode(military.name)); if (military.inBuild) { var buildSpan = document.createElement('span'); var inBuild = document.createTextNode(' ' + LANG_GROUP_IN_BUILDLOOP); buildSpan.appendChild(inBuild); buildSpan.style.fontStyle = 'italic'; td3.appendChild(buildSpan); } var td4 = document.createElement('td'); if (military.level != undefined) { gImg = document.createElement('img'); gImg.src = 'images/icons/star_' + military.level + '.gif'; td4.appendChild(gImg); } row.appendChild(td1); row.appendChild(td2); row.appendChild(td3); row.appendChild(td4); //$('militaryInVillage').appendChild(row); rows ++; } $('militaryTable').innerHTML = table; */ } else { //alert(request.responseText); if (request.responseText.substring(0,14) == ''); } var url = 'ajax_interface.php?ajax_action=requestInstantBuild&userToken=' + userToken; new Ajax.Request(url, { method: 'get', onSuccess: function(transport) { ajaxResponse = transport.responseText; window.location = 'user.php?action=home' }, onFailure: function(failure) { alert("error"); } }); } // -------------------------------------------------------------- // function sprintf() { if( sprintf.arguments.length < 2 ) { return; } var data = sprintf.arguments[ 0 ]; for( var k=1; k < sprintf.arguments.length; ++k ) { switch( typeof( sprintf.arguments[ k ] ) ) { case 'string': data = data.replace( /%s/, sprintf.arguments[ k ] ); break; case 'number': data = data.replace( /%d/, sprintf.arguments[ k ] ); break; case 'boolean': data = data.replace( /%b/, sprintf.arguments[ k ] ? 'true' : 'false' ); break; default: /// function | object | undefined break; } } return( data ); } /* -------------------------------- Village Select ------------------------------- */ var oldclass = 'vselectNormal'; function hoverVselect(element) { oldclass = element.className; element.className = 'vselectHover'; } function hoverOutVselect(element) { element.className = oldclass; } function toggleVselect() { if ($('vSelectList').style.display == 'none') showVselect(); else hideVselect(); } function showVselect() { Effect.BlindDown('vSelectList', {duration:0.2}); } function hideVselect() { Effect.BlindUp('vSelectList', {duration:0.2}); } /* --------------------------------- */ function toggleGroupView() { var table = $('groupTable'); if (table.style.display == 'none') { Effect.Appear('groupTable', {duration:0.3}); $('showGroups').hide(); $('hideGroups').show(); $('copyright').style.zIndex = -1; } else { Effect.Fade('groupTable', {duration:0.3}); $('showGroups').show(); $('hideGroups').hide(); $('copyright').style.zIndex = 1; } } function gamepay_item() { lbstyle='large'; loadContentLightbox('lb_main.php?action=payment¬ShowRes=1'); } function gamepay_item_lb() { //var new_win = window.open(url,'Gamepay','resizable=yes,scrollbars=yes,menubar=no,toolbar=no,status=yes,width=820,height=800,top=0,left=0'); new_win.focus(); lbstyle='large'; loadContentLightbox('lb_main.php?action=payment¬ShowRes=1', false, true); } var buildloopUpdateId = 0; var buildTimeRemain = 0; var buildTimeTotal = 0; var buildTimerStarted = 0; var titleTimeRemain = 0; var titleTimeRemainSetTime = 0; var titleLbTimeRemain = 0; var titleLbTimeRemainSetTime = 0; var titleOriginalString = ''; var titleIntervalId = null; /* * Returns true, if a ligthbox is currently displayed. */ function isLightboxOpen() { if ($('lbContent')) { return true; } return false; } function startBuildloopUpdate(buildingfieldId, timeRemain, timeTotal) { if (! $('constrBar_' + buildingfieldId)) { return false; } buildloopUpdateId = buildingfieldId; buildTimeRemain = timeRemain; buildTimeTotal = timeTotal; var date = new Date(); buildTimerStarted = date.getTime(); updateBuildPercent(); window.setInterval('updateBuildPercent()', 1000); } /** * Sets the title countdown for the lightbox. Passing null resets the title countdown. * This overrides the title countdown of the main page while a lightbox is shown. */ function setTitleLbOverrideTimeRemain(timeRemain) { titleLbTimeRemain = timeRemain; var date = new Date(); titleLbTimeRemainSetTime = date.getTime(); startTitleCountdown(); } /** * Sets the title countdown for the main page. Passing null resets the title countdown. */ function setTitleTimeRemain(timeRemain) { titleTimeRemain = timeRemain; var date = new Date(); titleTimeRemainSetTime = date.getTime(); startTitleCountdown(); } /* * Helper function, use setTitleTimeRemain() and setTitleLbOverrideTimeRemain() instead. */ function startTitleCountdown() { updateTitle(); if (titleIntervalId) { // already running return false; } titleIntervalId = window.setInterval('updateTitle()', 1000); } /* * Updates the title depending on wether or not a lightbox is shown. */ function updateTitle() { var date = new Date(); if (titleOriginalString == '') { titleOriginalString = document.title; } var timeRemaining = 0; if (!isLightboxOpen() && titleTimeRemain) { timeRemaining = titleTimeRemain - ((date.getTime() - titleTimeRemainSetTime) / 1000); } if (isLightboxOpen() && titleLbTimeRemain) { timeRemaining = titleLbTimeRemain - ((date.getTime() - titleLbTimeRemainSetTime) / 1000); } if (!timeRemaining) { document.title = titleOriginalString; if (titleIntervalId) { window.clearInterval(titleIntervalId); titleIntervalId = null; } return; } var timeRemainingStr = seconds_to_abs(Math.round(timeRemaining)); // remove 0: in front for 0 hours if (timeRemainingStr.substring(0,2) == '0:') { timeRemainingStr = timeRemainingStr.substring(2); } // remove 0 in front for single digit minutes if (timeRemainingStr.substring(0,1) == '0') { timeRemainingStr = timeRemainingStr.substring(1); } document.title = timeRemainingStr + ' - ' + titleOriginalString; } function startInstantBuildButtonTimer() { instantBuildButtonTimerID = window.setInterval("updateInstantBuildButtonTimer()", 1000); } function updateInstantBuildButtonTimer() { var minutes = parseInt(instantBuildSeconds / 60); instantBuildNuggetCost = parseInt(Math.round(Math.max(1, Math.min(25, Math.pow(5 * minutes, 0.45) - 2)))); var button = $('instantBuildButton'); button.innerHTML = LANG_INSTANTBUILD_BUTTON.replace('%d', instantBuildNuggetCost); if (instantBuildNuggetCost <= parseInt($('ressourceNugget').innerHTML)) { button.className = 'inputSubmitBig buildloopButton'; } instantBuildSeconds = instantBuildSeconds - 1; if (instantBuildSeconds <= 0) { window.clearInterval(InstantBuildButtonTimerID); } } function updateBuildPercent() { var date = new Date; var percent = 100 * (1 - (buildTimeRemain - ((date.getTime() - buildTimerStarted) / 1000)) / buildTimeTotal); if (percent > 100) percent = 100; $('constrBar_' + buildloopUpdateId).style.width= Math.round(percent) + '%'; } function updateTutorialImage(nation) { if ($('tutorialAlertPic')) { $('tutorialAlertPic').style.display = 'none'; } } function trim(str, chars) { return ltrim(rtrim(str, chars), chars); } function ltrim(str, chars) { chars = chars || "\\s"; return str.replace(new RegExp("^[" + chars + "]+", "g"), ""); } function rtrim(str, chars) { chars = chars || "\\s"; return str.replace(new RegExp("[" + chars + "]+$", "g"), ""); } /* ---------------------------- Slider ----------------------- */ /*******************************************************************/ /*******************************************************************/ /******** *********/ /******** S C R O L L B A R *********/ /******** *********/ /*******************************************************************/ /*******************************************************************/ /* Scrollbar-Skript und Funktionen */ var elementIds = new Array; var sliderObjects = new Array; var lbScrollbarsInitialized = false; function initLB() { if (! lbScrollbarsInitialized) { var scrollbarDiv = new Element('div', { 'class' : 'lightboxScrollbar', 'style' : 'position:absolute; right:85px; top:110px;' }); var scrollbarTrack = new Element('div', { 'class' : 'scrollbarBack', 'style' : 'height:410px' }); var scrollbarElement = new Element('div', { 'class' : 'scrollbar', 'style' : 'height:335px' }); var scrollbarHandle = new Element('div', { 'class' : 'scrollbarHandle', 'style' : 'height:44px;'} ); scrollbarElement.insert(scrollbarHandle); scrollbarDiv.insert(scrollbarTrack); scrollbarDiv.insert(scrollbarElement); $('lightbox').insert(scrollbarDiv); } var scrollbarBackgrounds = document.getElementsByClassName('scrollbarBack'); var scrollbarTracks = document.getElementsByClassName('scrollbar'); var scrollbarHandle = document.getElementsByClassName('scrollbarHandle'); for (var i = 0; i < scrollbarBackgrounds.length; i++) { scrollbarBackgrounds[i].id = 'scrollbarBackground_' + i; scrollbarTracks[i].id = 'scrollbar_' + i; scrollbarHandle[i].id = 'handle_' + i; } } // ---------------------------------------------------------------------------- // function scrollVertical(value, element, slider) { element.scrollTop = (element.scrollHeight - element.offsetHeight) * value; } // ---------------------------------------------------------------------------- // function wheel(event) { var delta = 0; var direction = 0; if (!event) event = window.event; //IE var data = $A(arguments); data.shift(); /***************** Scrollrichtung und Scrollstufe berechnen ********/ if (event.wheelDelta) { /** IE/Opera. */ // event.wheelDelta = 120 // Safari 360 ... if(event.wheelDelta > 0) { direction = 1; } else if(event.wheelDelta < 0) { direction = -1; } else { direction = 0; } delta = direction/(($(elementIds[data[0]]).scrollHeight-$(elementIds[data[0]]).offsetHeight)/40); } else if (event.detail) { /** Mozilla case. */ // event.detail = 3 if(event.detail > 0) { direction = -1; // FF läuft hier andersrum } else if(event.detail < 0) { direction = 1; // FF läuft hier andersrum } else { direction = 0; } delta = direction/(($(elementIds[data[0]]).scrollHeight-$(elementIds[data[0]]).offsetHeight)/40); } /***************** Scrollrichtung und Scrollstufe berechnen Ende********/ if (delta) { handleSlider(delta, data[0]); } if (event.preventDefault) event.preventDefault(); event.returnValue = false; } // ---------------------------------------------------------------------------- // function handleSlider(delta, sliderId) { sliderObjects[sliderId].setValueBy(-delta); } // ---------------------------------------------------------------------------- // function initScrollbar(type) { if (type == 'military') { elementId = 'militaryScrollable'; } else if (type == 'artefacts') { elementId = 'artefactScrollable'; } else if (type == 'artefactsSecond') { elementId = 'artefactSecondScrollable'; } else if (type == 'troupActions') { elementId = 'troupMovementScrollable'; } else if (type == 'igm') { elementId = 'igmScrollable'; } else if (type == 'lightbox') { elementId = 'lightbox_content'; } else if (type == 'mailReports') { elementId = 'mailReportsScrollable'; } else if (type == 'overview') { elementId = 'overviewScrollable'; } else if (type == 'notepad') { elementId = 'notepadScrollable'; } else if (type == 'simulator') { elementId = 'simulatorScrollable'; } else if (type == 'allyWonAnnouncement') { elementId = 'allyWonAnnouncementScrollable'; } else if (type == 'faq') { elementId = 'faqScrollable'; } else if (type == 'halloffame') { elementId = 'halloffameScrollable'; } else { return false; } scrollbarId = elementIds.length; if (type == 'lightbox' && lbScrollbarsInitialized) { delete elementIds[scrollbarId - 1]; delete sliderObjects[scrollbarId - 1] elementIds.pop(); sliderObjects.pop(); } scrollbarId = elementIds.length; elementIds[scrollbarId] = elementId; sliderObject = new Control.Slider('handle_' + scrollbarId, 'scrollbar_' + scrollbarId, { axis:'vertical', onSlide: function(value) { var data = $A(arguments); data.shift(); scrollVertical(value, $(elementIds[data[0]]), sliderObject) }.bindAsEventListener('', scrollbarId) , onChange: function(value) { var data = $A(arguments); data.shift(); scrollVertical(value, $(elementIds[data[0]]), sliderObject) }.bindAsEventListener('', scrollbarId) } ); sliderObjects[scrollbarId] = sliderObject; //if (! $(elementId)) alert("element >" + elementId + "< for scrolling missing"); /** Safari interpretiert als einziger Browser das escapte 'a' konjugiert mit dem escapten '.' als * negatives Proton! In konjugierter Addition mit der imaginären variable __proto__ ergibt sich * nach e=mc² negative masse! der energiehaushalt geht also auf 0!fakultät / 1 * entsprechend ergibt sich (unter berücksichtigung der kolodziej'schen normalenform 3ten grades) * im safari zufriedenstellenderweise das ergebnis '---------o><' was == dem escapten (nichts) konjugiert * mit dem escapten (nichts) als char betrachtet und wird deshalb vom safari logischerweise * und richtigerweise also boolsches true interpretiert. die andern browser schalten da ab ... * * * dass ich das ja nicht vergesse ... Oo wer grammatik fehler findet darf sie behalten */ if (window.opera || document.all || (/a/.__proto__=='//')) { Event.observe(elementId, 'mousewheel', wheel.bindAsEventListener('', scrollbarId)); } else { Event.observe(elementId, 'DOMMouseScroll', wheel.bindAsEventListener('', scrollbarId)); } // disable vertical scrolling if text doesn't overflow the div if ($(elementId).scrollHeight <= $(elementId).offsetHeight) { sliderObjects[scrollbarId].setDisabled(); $('scrollbarBackground_' + scrollbarId).hide(); $('scrollbar_' + scrollbarId).hide(); $('handle_' + scrollbarId).hide(); } else { sliderObjects[scrollbarId].setEnabled(); sliderObjects[scrollbarId].disabled = false; $('scrollbarBackground_' + scrollbarId).show(); $('scrollbar_' + scrollbarId).show(); $('handle_' + scrollbarId).show(); } if (type == 'lightbox') lbScrollbarsInitialized = true; } /*******************************************************************/ /*******************************************************************/ /******** *********/ /******** S C R O L L B A R *********/ /******** ENDE *********/ /******** *********/ /*******************************************************************/ /*******************************************************************/ // ---------------------------------------------------------------------- // function insertTextTags(aTag, eTag) { var input = document.getElementById('textcontent'); input.focus(); /* für Internet Explorer */ if(typeof document.selection != 'undefined') { /* Einfügen des Formatierungscodes */ var range = document.selection.createRange(); var insText = range.text; range.text = aTag + insText + eTag; /* Anpassen der Cursorposition */ range = document.selection.createRange(); if (insText.length == 0) { range.move('character', -eTag.length); } else { range.moveStart('character', aTag.length + insText.length + eTag.length); } range.select(); } /* für neuere auf Gecko basierende Browser */ else if(typeof input.selectionStart != 'undefined') { /* Einfügen des Formatierungscodes */ var start = input.selectionStart; var end = input.selectionEnd; var insText = input.value.substring(start, end); input.value = input.value.substr(0, start) + aTag + insText + eTag + input.value.substr(end); /* Anpassen der Cursorposition */ var pos; if (insText.length == 0) { pos = start + aTag.length; } else { pos = start + aTag.length + insText.length + eTag.length; } input.selectionStart = pos; input.selectionEnd = pos; } /* für die übrigen Browser */ else { /* Abfrage der Einfügeposition */ var pos; var re = new RegExp('^[0-9]{0,3}$'); while(!re.test(pos)) { pos = prompt("Einfügen an Position (0.." + input.value.length + "):", "0"); } if(pos > input.value.length) { pos = input.value.length; } /* Einfügen des Formatierungscodes */ var insText = prompt("Bitte geben Sie den zu formatierenden Text ein:"); input.value = input.value.substr(0, pos) + aTag + insText + eTag + input.value.substr(pos); } } // ----------------------------------------------------------------------------------------------------------------- // function buddyInviteByName() { var name = $('buddyInvitationName').value; var text = $('buddyInvitationNameText').value; if (trim(name) != '') { test = queryInterface('inviteBuddyByName', false, '&name=' + encodeURIComponent(name) + '&text=' + encodeURIComponent(text), 'post','' , true); } if (test == 'n/a') alert(LANG_NO_PLAYER_FOUND); else if(test == 'double') alert(LANG_PLAYER_ALREADY_INVITED); else if(test == 'friend') alert(LANG_PLAYER_ALREADY_FRIEND); else if (test == 'self') alert(LANG_PLAYER_YOURSELF); loadContentLightbox('lb_main.php?action=buddylist&lbaction=buddyinvitation', false, true); } // ----------------------------------------------------------------------------------------------------------------- // function buddyInviteByMail() { var email = $('buddyInvitationEmail').value; var text = $('buddyInvitationEmailText').value; if (trim(email) != '') { test = queryInterface('inviteBuddyByEmail', false, '&email=' + encodeURIComponent(email) + '&text=' + encodeURIComponent(text), 'post','' , true); } if (test == 'double') alert(LANG_EMAIL_EXISTS); else if (test == 'invalid') alert(LANG_INVALID_EMAIL); loadContentLightbox('lb_main.php?action=buddylist&lbaction=buddyinvitation', false, true); } // ----------------------------------------------------------------------------------------------------------------- // function acceptBuddyInvitation(binvId) { var url = 'ajax_interface.php?ajax_action=acceptBuddyInvitation&binvId=' + binvId + '&userToken=' + userToken; new Ajax.Request(url, { method: 'get', onSuccess: function(transport) { if (transport.responseText == 'done') { loadContentLightbox('lb_main.php?action=buddylist&lbaction=buddyinvitation', false, true); } }, onFailure: function(failure) { alert("error"); } }); } // ----------------------------------------------------------------------------------------------------------------- // function deleteBuddyInvitation(binvId) { var url = 'ajax_interface.php?ajax_action=deleteBuddyInvitation&binvId=' + binvId + '&userToken=' + userToken; new Ajax.Request(url, { method: 'get', onSuccess: function(transport) { if (transport.responseText == 'done') { loadContentLightbox('lb_main.php?action=buddylist&lbaction=buddyinvitation', false, true); } }, onFailure: function(failure) { alert("error"); } }); } // ----------------------------------------------------------------------------------------------------------------- // function deleteBuddy(bId, user, buddy) { if (window.confirm(LANG_REALLY_DELETE_BUDDY)) { var url = 'ajax_interface.php?ajax_action=deleteBuddy&bId=' + bId + '&user=' + user + '&buddy=' + buddy + '&userToken=' + userToken; new Ajax.Request(url, { method: 'get', onSuccess: function(transport) { if (transport.responseText == 'done') { loadContentLightbox('lb_main.php?action=buddylist&lbaction=buddyinvitation', false, true); } }, onFailure: function(failure) { alert("error"); } }); } } // ----------------------------------------------------------------------------------------------------------------- // function saveVillageTemplate() { var sendstring = ''; var buildingFields = document.getElementsByClassName('villageTemplateGround'); var buildingIds = new Array; for(i = 0; i < buildingFields.length; i++) { if (buildingFields[i].value == 0) { var check = 'empty'; break; } else if (in_array(buildingFields[i].value, buildingIds)) { var check = 'double'; break; } else { buildingIds.push(buildingFields[i].value); sendstring = sendstring + '&' + buildingFields[i].name + '=' + buildingFields[i].value; } } if(check == 'empty') alert(LANG_TEMPLATE_SAVE_EMPTY); else if(check == 'double') alert(LANG_TEMPLATE_SAVE_DOUBLE); else { if (window.confirm(LANG_TEMPLATE_REALLY_SAVE)) { $('villageTemplateUseButton').innerHTML = 'loading...'; var url = 'ajax_interface.php?ajax_action=saveVillageTemplate' + sendstring + '&userToken=' + userToken; new Ajax.Request(url, { method: 'get', onSuccess: function(transport) { waitForAjaxhandler('buildingRequest'); }, onFailure: function(failure) { alert("error"); } }); } } } // ----------------------------------------------------------------------------------------------------------------- // function useVillageTemplate() { if (window.confirm(LANG_TEMPLATE_REALLY_USE)) { $('villageTemplateUseButton').innerHTML = 'loading...'; var url = 'ajax_interface.php?ajax_action=useVillageTemplate&userToken=' + userToken; new Ajax.Request(url, { method: 'get', onSuccess: function(transport) { waitForAjaxhandler('buildingRequest'); }, onFailure: function(failure) { alert("error"); } }); } } function toggleMarkupPixel(mode, type) { var pixel = document.getElementsByClassName(type); for(i = 0; i < pixel.length; i++) { if (mode == 'on') { pixel[i].show(); } else if (mode == 'off') { pixel[i].hide(); } else break; } } function updateVillageTemplateDropdowns() { // ALLE options erstmal sichtbar machen var allOptions = document.getElementsByClassName('bO'); for(var i = 0; i < allOptions.length; i++) { allOptions[i].show(); } // alle gebäude finden, die ausgewählt sind, und die entsprechenden options verstecken var selectedBuildings = document.getElementsByClassName('villageTemplateGround'); for(i = 0; i < selectedBuildings.length; i++) { var buildingOptions = document.getElementsByClassName('buildingOption_'+selectedBuildings[i].value); for(var j = 0; j < buildingOptions.length; j++) { buildingOptions[j].hide(); } } } // ----------------------------------------------------------------------------------------------------------------- // // ----------------------------------------------------------------------------------------------------------------- // // helper // function in_array(item,arr) { for(p=0;p < arr.length;p++) if (item == arr[p]) return true; return false; } // ----------------------------------------------------------------------------------------------------------------- // function pad(num, size) { var s = num+""; while (s.length < size) s = "0" + s; return s; }