DoA Power Tools Plus IV (update by TLC)

Power Tools for Dragons of Atlantis

// ==UserScript==
// @name        	DoA Power Tools Plus IV (update by TLC)
// @description		Power Tools for Dragons of Atlantis
// @grant			GM_xmlhttpRequest
// @grant			GM_info
// @grant			GM_setValue
// @grant			GM_getValue
// @match         *://apps.facebook.com/dragonsofatlantis/*
// @match         *://*.castle.wonderhill.com/platforms/*/game*
// @match         *://www.kabam.com/dragons-of-atlantis/play
// @match         *://www.kabam.com/*/dragons-of-atlantis/*
// @match         *://www.kongregate.com/games/kabam/dragons-of-atlantis
// @match         *://www.kongregate.com/games/kabam/dragons-of-atlantis*
// @match         *://www.agame.com/game/dragons-of-atlantis*
// @match         *://www.agame.com/plinga/gadget/spil/Atlantis*
// @match         *://*.yahoo.com/game/dragons-of-atlantis*
// @match         *://*.yahooapis.com/*
// @match         *://apps.yahoo.com/-iframe/mDuFjS4e/*
// @match         *://*.yahoo.com/*
// @include       *://www.kongregate.com/games/kabam/dragons-of-atlantis*
// @include       *://www.agame.com/game/dragons-of-atlantis*
// @include       *://www.agame.com/plinga/gadget/spil/Atlantis*
// @include       *://www.kabam.com/dragons-of-atlantis/play
// @include       *://www.kabam.com/*/dragons-of-atlantis/*
// @include       *://apps.facebook.com/dragonsofatlantis/*
// @include       *://*.castle.wonderhill.com/platforms/*/game*
// @include       *://*.yahoo.com/game/dragons-of-atlantis*
// @include       *://*.yahooapis.com/*
// @include       *://apps.yahoo.com/-iframe/mDuFjS4e/*
// @include       *://*.yahoo.com/*
// @exclude       *://apps.facebook.com/dragonsofatlantis/rubies
// @exclude       *://apps.facebook.com/ai.php*
// @exclude       *://www.facebook.com/plugins/like.php*
// @exclude       *://kabam1-a.akamaihd.net/pixelkabam/*
// @exclude       *://*.akamaihd.net/pixelkabam/*
// @exclude       *://plus.google.com/_/apps-static/*
// @exclude       *://plus.google.com/u/0/_/gadgets/contactPicker*
// @exclude       *://accounts.google.com/*
// @exclude       *://talkgadget.google.com/*
// @exclude       *://www.googleapis.com/static*
// @exclude		  *://realmtheraindoa.altervista.org/*
// @version			2014.05.19
// @changeLog		View description
// @namespace https://greasyfork.org/users/1829
// ==/UserScript==

/*
	===== TO DO EVERYTIME WHEN PACKAGING CHROME EXTENSION =====
	!! Change CHROME_EXT here and version in manifest.json before packing !!
*/

(function() {

var CHROME_EXT = false;
var scriptVersion = '2014.05.19';
var scriptId	  = '18016';

var LAST_CHANGES = '';
var LAST_CHANGES_FR = '';

var chrome_extensions = 'chrome://chrome/extensions/';
var userscripts_src  = 'http://userscripts.org/scripts/source/'+scriptId+'.user.js'; 

var REMOVE_HD = false;

if ((/dragons-of-atlantis\/play/.test(window.location.href)) && window.location.href.indexOf("kabam.com") !== -1)
	setTimeout(function(){document.getElementById('promo-sidebar').style.display = 'none';
		var to_remove = document.getElementById('promo-sidebar').parentNode;
		to_remove.parentNode.removeChild(to_remove);
	},7000);

if (/(pixelkabam|akamaihd|plugins|ai\.php|talkgadget|notifications|contactPicker|accounts|googleapis\.com\/static)/.test(window.location.href)) return;

if ( !( (/apps\.facebook\.com\/dragonsofatlantis/.test(window.location.href) && /rubies/.test(window.location.pathname) == false) ||
 		/castle\.wonderhill\.com\/platforms\/.+\/game/.test(window.location.href) ||
 		/plus\.google\.com.*\/games.*\/659749063556/.test(window.location.href)         || 
 		/plus\.google\.com.*\/games\/play\/659749063556/.test(window.location.href)         || 
 		/googleusercontent\.com\/gadgets\/.*\/659749063556/.test(window.location.href)  || 
 		/kabam.com\/dragons-of-atlantis\/play/.test(window.location.href)	||
 		/kongregate.com\/games\/kabam\/dragons-of-atlantis/.test(window.location.href)	||
 		(/realmtheraindoa.altervista.org\/*/.test(window.location.href)	&& !/realmtheraindoa.altervista.org\/Jeux\/*/.test(window.location.href)) ||
 		/wackoscripts.com\/realm*/.test(window.location.href)
 	)){
 		return;
}
var REALM_URL = '';

function bf (data) {
	if (window.console && console.log) console.log(data);
}
function fa(body, game_container) {
	if (body.childNodes) {
		var child_elements = body.childNodes;
		for (var c=0; c<child_elements.length; c++) {
			var child = child_elements[c];
			if (child.id && child.id == game_container) {
				child.style.width = '100%';
				child.style.margin = '0';
				child.style.border = '0';
				child.style.background = '#888 url(http://www.heberger-image.fr/data/images/11663_dragonsd_dragons_fire_people_and_monsters_1382215.jpg)';
			} else {
				var depend = gF(child);
				if (!depend) {
					if (child.tagName == 'DIV' || child.tagName == 'IFRAME' || child.tagName == 'TABLE') {
						child.style.width = '0%';
						child.style.display = 'none';
					} else fa (child, game_container);
				} else {
					if (child.tagName == 'DIV' || child.tagName == 'IFRAME' || child.tagName == 'TABLE' || child.tagName == 'TD') {
						child.style.padding = '0px';
						child.style.width = '100%';
						child.style.margin = '0';
						child.style.border = '0';
						child.style.background = '#888 url(http://www.heberger-image.fr/data/images/11663_dragonsd_dragons_fire_people_and_monsters_1382215.jpg)';
					}
					fa (child, game_container);
				}
			}
		}
		function gF (tag) {
			if (!tag.childNodes) return (false);
			var child_list = tag.childNodes;
			var found = false;
			for (var x=0; x<child_list.length && !found; x++) {
				if (child_list[x].id && child_list[x].id == game_container) found = true;
				else found = gF (child_list[x]);
			}
			return found;
		}
	}
}
function gp (bA) {
	if (bA.parentNode) {
		var parent_element = bA.parentNode;
		gp (parent_element);
		if (parent_element.tagName == 'DIV' || parent_element.tagName == 'IFRAME' || parent_element.tagName == 'TABLE' || parent_element.tagName == 'TD') {
			parent_element.style.width = '100%';
			parent_element.style.background = '#888 url(http://www.heberger-image.fr/data/images/11663_dragonsd_dragons_fire_people_and_monsters_1382215.jpg)';
		}
	}
}
function gX(frame,width) {
	var maxWidth = (width ? width : (document.body.offsetWidth - 50)+'px');
	if (frame) {
		if (frame.width) frame.width = maxWidth;
		else if (frame.style.width) frame.style.width = maxWidth;
		else frame.setAttribute("style", "width: "+maxWidth+";");
	}
}
if (window.top === window.self) {
	function hv() {
		if ( window.location.href.indexOf('facebook') !== -1 ) {
			iframe	 = document.getElementById('iframe_canvas');
			platform = 'facebook';
		}
		else if ( window.location.href.indexOf("google") !== -1 ) {
			game_frame = 'oz-gadgets-canvas-iframe-659749063556';
			iframe	 = document.getElementById('oz-gadgets-canvas-iframe-659749063556');
			platform = 'google';
		}
		else if ( window.location.href.indexOf("kongregate.com") !== -1 ) {
			game_frame = 'gameiframe';
			iframe	 = document.getElementById('gameiframe');
			platform = 'kongregate';
		}
		else if ( window.location.href.indexOf("kabam.com") !== -1 ) {
			iframe	 = document.getElementById('game_frame');
			platform = 'kabam';
		}
		else if ( window.location.href.indexOf("altervista.org") !== -1 || window.location.href.indexOf("wackoscripts.com/realm") !== -1 ) {
			iframe = 'none';
			platform = 'altervista';
		}
		if (!iframe || iframe.length < 1) {
			setTimeout (hv, 1000);
			return;
		}
		var background_118446 = localStorage.getItem( '118446_background' );
		var USE_BACKGROUND = (background_118446 && background_118446 != undefined && background_118446 != null) ? eval(background_118446) : true;
		switch (platform) {
			case 'facebook' :
				while ((iframe = iframe.parentNode) != null) {
					if (iframe.tagName == 'DIV')
						iframe.style.width = '100%';
				}
				document.getElementById('rightCol').style.display = 'none';
				document.getElementById('rightCol').style.display = 'none';
				document.getElementById('blueBarHolder').style.display = 'none';
				document.getElementById('blueBar').style.display = 'none';
				document.getElementById('pageHead').style.display = 'none';
				document.getElementById('jewelContainer').style.display = 'none';
				document.getElementById('headNav').style.display = 'none';
				document.getElementById('contentCol').style.margin = '0px';
				document.getElementById('contentCol').style.background = '#888 url(http://www.heberger-image.fr/data/images/11663_dragonsd_dragons_fire_people_and_monsters_1382215.jpg)';
				var contentColChild = document.getElementById('contentCol').childNodes;
				for (var i=0; i<contentColChild.length; i++)
					if (contentColChild[i].tagName == 'DIV')
						contentColChild[i].style.margin = '0px';
				document.scrollTop = '42px';
				if (USE_BACKGROUND) {
					var body_elements = document.getElementsByTagName ('body');
					for (var el=0; el < body_elements.length; el++)
						body_elements[el].style.background = '#888 url(http://www.heberger-image.fr/data/images/11663_dragonsd_dragons_fire_people_and_monsters_1382215.jpg)';
				}
				break;
			case 'kabam' :
				iframe.style.width = '100%';
				iframe.style.margin = '0';
				iframe.style.border = '0';
				if (USE_BACKGROUND)
					iframe.style.backgroundColor = 'transparent';
				else
					iframe.style.backgroundColor = 'white';
				while ((iframe = iframe.parentNode) != null) {
					if (iframe.tagName == 'DIV') {
						iframe.style.width = '100%';
						iframe.style.margin = '0';
						iframe.style.border = '0';
						iframe.style.background = '#888 url(http://www.heberger-image.fr/data/images/11663_dragonsd_dragons_fire_people_and_monsters_1382215.jpg)';
					}
				}
				break;
			case 'altervista' :
				if (!document.getElementsByTagName('head')) {
					var header = document.createElement ('head');
					var html_elements = document.getElementsByTagName ('html');
					html_elements[0].appendChild(header);
				}
				if (document.getElementsByTagName('link').length <= 0) {
					var ss = document.createElement("link"); 
					ss.type = "text/css"; 
					ss.rel = "stylesheet"; 
					ss.media = "screen"; 
					ss.href = "https://kabam1-a.akamaihd.net/castle/stylesheets/chomped/common_258783ec84eaa8c2ad74bf6168ec24317be52dab.css"; 
					document.getElementsByTagName('head')[0].appendChild(ss); 
					var ss = document.createElement("link"); 
					ss.type = "text/css"; 
					ss.rel = "stylesheet"; 
					ss.media = "screen"; 
					ss.href = "https://kabam1-a.akamaihd.net/castle/stylesheets/chomped/facebook_37fbd906939be51243d0becafcb7aca6edbc3a8f.css"; 
					document.getElementsByTagName('head')[0].appendChild(ss); 
				}
				var centers = document.getElementsByTagName ('center');
				for (var el=0; el < centers.length; el++) {
					var old_elem = centers[el];
					var new_elem = document.createElement ('div');
					new_elem.id = 'altervista_div'+el;
					old_elem.parentNode.appendChild(new_elem);
					while (old_elem.hasChildNodes())
						new_elem.appendChild(old_elem.removeChild(old_elem.firstChild));
				}
				var object = document.getElementsByTagName('object');
				if (object) gM(object);
				break;
			default :
				if (platform == 'kongregate') setTimeout (function(){gX(document.getElementById('gameiframe'),undefined)}, 10000);
				var top_body = document.getElementsByTagName ('body');
				for (var el=0; el < top_body.length; el++) {
					if (top_body[el].id) bf ('top_body['+el+'].id = '+top_body[el].id);
					fa (top_body[el], game_frame);
				}
				var frame = document.getElementById(game_frame);
				if (frame) {
					if (frame.width) frame.width = '100%';
					frame.style.width = '100%';
					frame.setAttribute("style", "width: 100%;");
				}
				break;
		}
	}
	hv();
} else {
	platform = document.body.className.split(' ');
	if (platform && platform[0]){
		platform = platform[0].replace(/(platforms_|_game)/g,'');
	} else {
		platform = 'google';
	}
	var errors = 0;
	function gC() {
		clearTimeout;
		if (document.getElementById('game_frame')) setTimeout (function(){gX(document.getElementById('game_frame'),'100%')}, 10000);
		var object = document.getElementsByTagName('object');
		if (object.length < 1) {
			if ( ++errors > 6 ){
				errors = 0;
				window.location =  window.location.href;
			}
			setTimeout (gC, 1000);
			return;
		}
		var background_118446 = localStorage.getItem( '118446_background' );
		var USE_BACKGROUND = (background_118446 && background_118446 != undefined && background_118446 != null) ? eval(background_118446) : true;
		switch (platform) {
			case 'facebook' :
				REALM_URL = 'http://apps.facebook.com/dragonsofatlantis/realm/';
				for (var i=0; i<object.length; i++) {
					switch (object[i].parentNode.id) {
						case 'hd' :
							object[i].style.display = 'none'; 
							break;
						default :
							object[i].parentNode.style.margin = '0px';
					}
				}
				document.getElementById('hd').parentNode.style.width = '760px';
				var hdChild = document.getElementById('hd').childNodes;
				for (var i=0; i<hdChild.length; i++) {
					if (hdChild[i].tagName == 'DIV') hdChild[i].style.display = 'none';
					if (hdChild[i].tagName == 'IFRAME') hdChild[i].style.display = 'none';
				}
				document.getElementById('ft').style.display = 'none';
				document.scrollTop = '42px';
				if (REMOVE_HD) document.getElementById('hd').style.display = 'none';
				if (USE_BACKGROUND) {
					var body_elements = document.getElementsByTagName ('body');
					for (var el=0; el < body_elements.length; el++)
						body_elements[el].style.background = '#888 url(http://www.heberger-image.fr/data/images/11663_dragonsd_dragons_fire_people_and_monsters_1382215.jpg)';
					var html_elements = document.getElementsByTagName ('html');
					for (var el=0; el < html_elements.length; el++)
						html_elements[el].style.background = '#888 url(http://www.heberger-image.fr/data/images/11663_dragonsd_dragons_fire_people_and_monsters_1382215.jpg)';
				}
				break;
			case 'google' :
				document.getElementById('pane_hd').style.display = 'none';
				if (USE_BACKGROUND) {
					var body_elements = document.getElementsByTagName ('body');
					for (var el=0; el < body_elements.length; el++) {
						body_elements[el].style.background = '#888 url(http://www.heberger-image.fr/data/images/11663_dragonsd_dragons_fire_people_and_monsters_1382215.jpg)';
						body_elements[el].style.background = '#888 url(http://www.heberger-image.fr/data/images/11663_dragonsd_dragons_fire_people_and_monsters_1382215.jpg)';
					}
				}
				break;
			case 'kabam' :
				var html_elements = document.getElementsByTagName ('html');
				for (var el=0; el < html_elements.length; el++) {
					html_elements[el].style.overflow = 'hidden'
					html_elements[el].style.background = '#888 url(http://www.heberger-image.fr/data/images/11663_dragonsd_dragons_fire_people_and_monsters_1382215.jpg)';
				}
				if (!USE_BACKGROUND) document.body.style.background = '#888 url(http://www.heberger-image.fr/data/images/11663_dragonsd_dragons_fire_people_and_monsters_1382215.jpg)';
				document.getElementById('cn').style.textAlign = 'left';
				if (document.getElementById('castlemania_swf')) gp(document.getElementById('castlemania_swf'));
				break;
		}
		gM(object);
	}
	gC();
}



function gM (SWF_OBJECT) {
var UID = {};
var UIDN = {};

    function gn(len){
        var len = ( len != undefined ? len : 20);
        var chars = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','u','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','U','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9','_'];
    	var uid = chars[Math.floor(Math.random()*54)];
    	for(var i = 0; i < len; i++)
    	{
    		uid += chars[Math.floor(Math.random()*64)];
    	}
    	return uid;
    }
    function jU(name){
    	return UID[name] != undefined ? UID[name] : name;
    }
    function bS(name){
    	var uid = gn();
    	while(UIDN[uid] != undefined){
    		uid = gn();
    	}
    	UIDN[uid] = 1;
    	UID[name] = uid;
    	return uid;
    }
    function kJ(str){
        var obj = {};
    	var pattern = /\s*(.*?)\s*=\s*('|")(.*?)\2/gi;
    	var match;
    	while ((match = pattern.exec(str)) != null){
    		obj[match[1]] = match[3];
    	}
    	return obj;
    }
    function iz (swf){
    	var params = swf.innerHTML;
    	var pattern = /\<\s*param\s*(.*?)\>/gi;
    	var attrs={};
    	var args, match, p;
    	while ((match = pattern.exec(params)) != null){
    		var p = kJ(match[1]);
    		if (p.name && p.name == 'flashvars'){
    			args = jE(p.value).split('&');
    			for (var i=0; i < args.length; i++)	{
    				var av = args[i].split('=');
    				attrs[av[0].cT()] = av[1].cT();
    			}
    			break;
    		}
    	}
    	aU.attrs.apiServer	= attrs.api_server;
    	aU.attrs.sessionId	= attrs.session_id;
    	aU.attrs.dragonHeart = attrs.dragon_heart;
    	aU.attrs.userId		= attrs.user_id;
    	aU.attrs.locale		= attrs.locale;
    	USER_ID		 		= attrs.user_id;
    	S3_SERVER	 		= attrs.s3_server;
    	S3_SWF_PREFIX		= attrs.s3_swf_prefix;
    	PUB_SERVER	 		= attrs.pub_server;
    	PUB_PORT			= attrs.pub_port;
    	MAP_BIN_CACHEBREAKER = attrs.map_bin_cachebreaker;
    	SERVER_ID	 		= ( /realm(\d+)\./.exec( attrs.api_server ) || ['',''] )[1];
    	url_versions		= aU.attrs.apiServer;
    	if (url_versions.indexOf('/api') > 0)
    		url_versions = url_versions.substring(0,url_versions.indexOf('/api'));
    }

var api_version = 'overarch', scriptName = 'Doa Power Tools IV', mainAuthor = 'TLC';
var urlBackgroundImage = '', urlBackgroundLogo  = 'http://imageshack.com/a/img836/9333/8dxw.png';
var styleList = [ 'btn_blue', 'blue', 'btn_cyan', 'btn_green', 'btn_on', 'btn_off', 'btn_red', 'btn_purple', 'btn_red', 'btn_yellow', 'bold_red', 'compact_table',
 'content', 'content_table', 'defending', 'hiding', 'popup_bar', 'popup_close', 'popup_main', 'popup_outer', 'popup_top', 'row_headers', 'row_style', 'row_top_headers',
 'row_headers_left', 'scrollable', 'status_feedback', 'status_report', 'status_ticker', 'subtitle', 'support_link', 'table', 'table_console', 'table_headers', 'table_targets',
 'table_wrap', 'title', 'red', 'green', 'btn_disabled', 'title_main', 'info_protect', 'info_alerts', 'info_boosts' ];

var INFO_TAB_ORDER = 1,
    JOBS_TAB_ORDER = 2,
    ALLIANCE_TAB_ORDER = 3,
    WAVE_TAB_ORDER = 4,
    ATTACK_TAB_ORDER = 5,
    SINGLE_TAB_ORDER = 6,
    SEARCH_TAB_ORDER = 10,
    TOWER_TAB_ORDER = 11,
    WALL_TAB_ORDER = 12,
    OPTIONS_TAB_ORDER = 20,
    WHEEL_TAB_ORDER = 21,
    BOOKMARK_TAB_ORDER = 30,
    MULTI_TAB_ORDER = 31,
    SPY_TAB_ORDER = 32,
    INBOX_TAB_ORDER = 50,
    LOG_TAB_ORDER = 99;

var ALLIANCE_TAB_ENABLE = true,
    ATTACK_TAB_ENABLE = true,
    BOOKMARK_TAB_ENABLE = true,
    INBOX_TAB_ENABLE = true,
    INFO_TAB_ENABLE = true,
    JOBS_TAB_ENABLE = true,
    LOG_TAB_ENABLE = true,
    MULTI_TAB_ENABLE = true,
    OPTIONS_TAB_ENABLE = true,
    WHEEL_TAB_ENABLE = true,
    SEARCH_TAB_ENABLE = true,
    SINGLE_TAB_ENABLE = true,
    SPY_TAB_ENABLE = true,
    TOWER_TAB_ENABLE = true,
    WALL_TAB_ENABLE = true,
    WAVE_TAB_ENABLE = true;

var DEBUG_TRACE_AJAX = 2,
    DEBUG_MARCHES = false,
    E429_TIMER = 0,
    E429_DELAY = 3600,
    TILE_DELAY = 2250,
    MAP_DELAY = 1250,
    MIN_DELAY = 20,
    EMULATE_NET_ERROR = 0,
    MIN_DELAY_BETWEEN_WAVE = 20;

var BUTTON_BGCOLOR = '#436',
    JOB_BUTTON_BGCOLOR = '#436';

var MESSAGES_ALL = 0,
    MESSAGES_ONLY = 1,
    REPORTS_ONLY = 2,
    MAX_READ = 120,
    MAX_DELETE = 30;

var CAPITAL = {id:0, type:'capital', name:'', dragon_name:'CityGreatDragon'},
    SPECTRAL_OUTPOST = {id:1, type:'spectral', name:'SpectralDragonOutpost', dragon_name:''},
    ICE_OUTPOST = {id:2, type:'ice', name:'IceDragonOutpost', dragon_name:'IceDragon'},
    SWAMP_OUTPOST = {id:3, type:'swamp', name:'SwampDragonOutpost', dragon_name:'SwampDragon'},
    FOREST_OUTPOST = {id:4, type:'forest', name:'ForestDragonOutpost', dragon_name:'ForestDragon'},
    DESERT_OUTPOST = {id:5, type:'desert', name:'DesertDragonOutpost', dragon_name:'DesertDragon'},
    WATER_OUTPOST = {id:6, type:'water', name:'WaterDragonOutpost', dragon_name:'WaterDragon'},
    STONE_OUTPOST = {id:7, type:'stone', name:'StoneDragonOutpost', dragon_name:'StoneDragon'},
    FIRE_OUTPOST = {id:8, type:'fire', name:'FireDragonOutpost', dragon_name:'FireDragon'},
    WIND_OUTPOST = {id:9, type:'wind', name:'WindDragonOutpost', dragon_name:'WindDragon'},
    CHRONO_OUTPOST = {id:10, type:'chrono', name:'ChronoDragonOutpost', dragon_name:'ChronoDragon'},
    SKY_OUTPOST = {id:11, type:'skythrone', name:'SkythroneOutpost', dragon_name:'KaiserDragon'},
    CAVE_OUTPOST = {id:12, type:'cave', name:'CaveDragonOutpost', dragon_name:'CaveDragon'},
	LUNA_OUTPOST = {id:13, type:'luna', name:'LunaDragonOutpost', dragon_name:'LunaDragon'};

var IsChrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;

var kFatalSeedTitle	= 'ERROR WHILST FETCHING DATA FROM SERVER',
    kFatalSeedMsg = 'Please disable the script and see if you are able to play the game manually. If normal play is possible then enable the script and try again. If the error persists please read the following post before submitting a report. If normal play is not possible then wait until it is and try again.',
    kFatalSWF = '"<B>Error initializing:</b><BR><BR>Unable to find SWF element"',
    kStartupErr = '"Unable to start "'+ scriptName +'"<BR>"',
    kInitErr = '"<B>Error initializing:</b><BR><BR>"';

var marchErrorTexts = [
		{ vb : 'delayed due to', fb : ''},
		{ vb : 'delayed due to pending march request', fb : 'Another march request is pending'},
		{ vb : 'has-too-many-marches', fb : 'has-too-many-marches'},
		{ vb : 'delayed due to no available generals', fb : 'No Generals Available'},
		{ vb : 'No Troops Defined', fb : 'No Troops Defined'},
		{ vb : 'delayed due to no available Great Dragon', fb : 'No Great Dragon available'},
		{ vb : '<b>Rate Limit Exceeded</b>, too many requests!', fb : 'Rate Limit Exceeded because there were too many requests'},
		{ vb : 'Requirements Unmet', fb : 'Requirements Unmet'},
		{ vb : 'no resources to transport', fb : 'no resources to transport'}
	];

var sanctuaryDragonRank = new Array('common','lesser','heightened','royal','exalted','omniscient','legendary');
var all_dragon_list		 = ['GreatDragon', 'WaterDragon', 'StoneDragon', 'FireDragon', 'WindDragon', 'IceDragon', 'SwampDragon', 'ForestDragon', 'DesertDragon', 'ChronoDragon', 'SpectralDragon', 'KaiserDragon', 'CaveDragon','LunaDragon',];
var all_unit_types		 = [ 'Porter', 'Conscript', 'Spy', 'Halberdsman', 'Minotaur', 'Longbowman', 'SwiftStrikeDragon', 'BattleDragon', 'ArmoredTransport', 'Giant', 'FireMirror', 'PackDragon', 'DarkSlayer', 'DimensionalRuiner', 'LightningCannon', 'ChargeTroop', 'VengeWyrm', 'AquaTroop', 'StoneTroop', 'FireTroop', 'WindTroop', 'IceTroop', 'SwampTroop', 'FrostGiant', 'ForestTroop', 'DesertTroop', 'ArcticLeviathan', 'Harrier', 'Defendo', 'ShadowStalker', 'Shaman','WarScarab','VoltRanger'];
var attack_unit_types	 = [ 'Porter', 'Conscript', 'Spy', 'Halberdsman', 'Minotaur', 'Longbowman', 'SwiftStrikeDragon', 'BattleDragon', 'ArmoredTransport', 'PackDragon', 'Giant', 'FireMirror', 'DarkSlayer', 'DimensionalRuiner', 'LightningCannon', 'ChargeTroop', 'VengeWyrm', 'AquaTroop', 'StoneTroop', 'FireTroop', 'WindTroop', 'IceTroop', 'SwampTroop', 'FrostGiant', 'ForestTroop', 'DesertTroop', 'ArcticLeviathan', 'Harrier', 'Defendo', 'ShadowStalker', 'Shaman','WarScarab','VoltRanger'];
var wave_unit_types		 = [ 'Porter', 'Conscript', 'Spy', 'Halberdsman', 'Minotaur', 'Longbowman', 'ArmoredTransport', 'PackDragon', 'SwiftStrikeDragon', 'BattleDragon', 'Giant', 'FireMirror', 'DarkSlayer', 'DimensionalRuiner', 'LightningCannon', 'ChargeTroop', 'VengeWyrm', 'AquaTroop', 'StoneTroop', 'FireTroop', 'WindTroop', 'IceTroop', 'SwampTroop', 'FrostGiant', 'ForestTroop', 'DesertTroop', 'ArcticLeviathan', 'Harrier', 'Defendo', 'ShadowStalker', 'Shaman','WarScarab','VoltRanger'];
var spy_unit_types		 = [ 'Spy' ];
var transport_unit_types = [ 'Porter', 'ATrans', 'PackDrg' ];
var all_resource_types				= [	'gold', 'food', 'wood', 'ore', 'stone', 'blue_energy','lunar_energy', 'enchanting'];
var transportable_resource_types	= [	'gold', 'food', 'wood', 'ore', 'stone', 'enchanting'];
var capital_buildings	= [	'Home', 'Garrison', 'ScienceCenter', 'Metalsmith', 'OfficerQuarter', 'MusterPoint', 'Rookery', 'StorageVault', 'Theater', 'Sentinel', 'Factory', 'Fortress', 'DragonKeep', 'Wall','DefensiveTower'];
var outpost_buildings	= [	'TrainingCamp', 'Home', 'Silo', 'MusterPoint', 'DragonKeep', 'Wall'];
var field_buildings		= [	'Mine', 'Farm', 'Lumbermill', 'Quarry'];
var spectral_buildings	= [	'DarkPortal', 'Mausoleum', 'SpectralDragonKeep'];
var spectral_fields		= [	'EnergyCollector'];
var skythrone_buildings	= [	'KaiserDragonKeep', 'Cathedral', 'Forge', 'Greenhouse', 'Library', 'Workshop'];
var cave_buildings		= [ 'CaveDragonKeep', 'CaveCathedral', 'CaveDepot', 'CaveForge', 'CaveGreenhouse', 'CaveLibrary', 'CaveTrainingCamp', 'CaveWorkshop']; 
var luna_buildings		= [ 'DragonKeep','LunaCathedral','LunaDepot','LunaForge','LunaGreenhouse','LunaLibrary','LunaShrine','LunaWorkshop']; 						
var time_item_list = [	{ name:'Blink',					text:'1m',		type:'JMTR',	confirmation:false},
						{ name:'Hop',					text:'5m',		type:'JMTR',	confirmation:false},
						{ name:'Skip',					text:'15m',		type:'JMTR',	confirmation:false},
						{ name:'Jump',					text:'1h', 	type:'JMTR',	confirmation:false},
						{ name:'Leap',					text:'2h30', 	type:'JMTR',	confirmation:false},
						{ name:'Bounce',				text:'8h', 	type:'JMTR',	confirmation:false},
						{ name:'Bore',					text:'15h',	type:'JMTR',	confirmation:false},
						{ name:'Bolt',					text:'24h',	type:'JMTR',	confirmation:true},
						{ name:'Blast',					text:'60h',	type:'JMTR',	confirmation:true},
						{ name:'Blitz',					text:'96h',	type:'JMTR',	confirmation:true},
						{ name:'ForcedMarchDrops', 		text:'25%',		type:'M',	confirmation:false},
						{ name:'TranceMarchDrops', 		text:'50%',		type:'M',	confirmation:false},
						{ name:'TestroniusPowder', 		text:'30%',		type:'JMTR',	confirmation:false},
						{ name:'DarkTestroniusPowder', 	text:'30%',		type:'JMTR',	confirmation:false},
						{ name:'TestroniusDeluxe', 		text:'50%',		type:'JMTR',	confirmation:false},
						{ name:'DarkTestroniusDeluxe', 	text:'50%',		type:'JMTR',	confirmation:false},
						{ name:'TestroniusInfusion', 	text:'99%',		type:'JMTR',		confirmation:true},
						{ name:'DarkTestroniusInfusion',text:'99%',		type:'JMTR',		confirmation:true}];


var LANG_CODE = navigator.language.substring(0,2).toLowerCase();
var IS_NOT_NATIVE_LANG = (LANG_CODE !== 'en');
var TRANSLATION_ARRAY = {};

var div_player_attack	= bS('div_SwfPlyr_attack');
var div_player_spy	 	= bS('div_SwfPlyr_spy');
var div_player_building = bS('div_SwfPlyr_building');
var div_player_units	= bS('div_SwfPlyr_units');
var div_player_research = bS('div_SwfPlyr_research');
var div_player_fortuna  = bS('div_SwfPlyr_fortuna');
var short_alerts = bS('short_alerts');
var TIMER_COLOR = '#2B4988';

var Tabs = {};
var progressBarPop;
var updaterPop;
var mainPop;
var header_2lines = false;
var swf_object;
var SWF_CONTAINER;
var SWF_CONTAINER_INNERHTML;
var gAttScrollPos = 0;
var gMapScrollPos = 0;
var aU = {};
var gFormatTime = ':';
var gFormatDate = '/';
var kForumLink 		 = 'Forum';
var kWikiLink		 = 'Wiki DoA';
var scriptTitle		 = '';
var scriptSite		 = '';
var scriptTimeout	 = null;
var scriptLoaded	 = false;
var startupCount = 0;
var initTimeout	 = null;
var STARTUP_TIMER;
var citySteps;

styleList.forEach(
    function (bA, index, array)
    {
        bS(bA);
    });
et();
aU.attrs = {};

function dU() {
	var i;
	progressBar.hideshow(false);
	clearTimeout(scriptTimeout);

	if (scriptLoaded){
		return;
	}

	if (++startupCount > 20) {
		dw (kFatalSWF);
		return;
	}

	try {  
		var swf = null;
		var object = document.getElementsByTagName ('object');
		if (object.length < 1) {
			scriptTimeout = setTimeout(dU, 1000);
			return;
		}
		for (i=0; i < object.length; i++) {
			if (object[i].type && object[i].type=='application/x-shockwave-flash') {
				swf = object[i];
				iz(swf);
				if (aU.attrs.apiServer){
					var maxWidth = document.body.offsetWidth - 570;
					if (maxWidth < 760) maxWidth = 760;
					if (window.location.href.indexOf("facebook") !== -1)
						document.getElementById('hd').parentNode.style.width = maxWidth+'px';
					if (swf.id == 'castlemania_swf') swf.style.width = maxWidth+'px';
					swf_object = swf;
					SWF_CONTAINER = swf.parentNode;
					SWF_CONTAINER_INNERHTML = SWF_CONTAINER.innerHTML;
					setTimeout (function(){bI('Mute sound'); swf.musicMute();}, 30000);
					break;
				}
			}
		}
		if (!aU.attrs.apiServer) {
			scriptTimeout = setTimeout(dU, 1000);
			return;
		}  
	} catch (e) {
		bf ('scriptStartup : Error = '+e);
		scriptTimeout = setTimeout(dU, 1000);
		return;
	}

	scriptLoaded = true;

	try {
		AutoUpdater.check();
		var retry = 0;
		var startupDelay = Math.randRange(10000, 15000);
		progressBar.start({ steps:21, delay:startupDelay, title:translate('Initializing...'), stepText:translate('Loading basic data') });

		Data.init({
			log		: [ [], [] ],
			options	: {
				popUp	: {
					open : true,
					drag : true,
					x	 : 0,
					y	 : 0
				},
				background			: true,
				currentTab			: false,
				forumUrl			: 'https://www.facebook.com/groups/DoAscripts/',
				wikiUrl				: 'https://www.facebook.com/doa.wiki.page',
				disable_wave		: !WAVE_TAB_ENABLE,
				disable_multi		: MULTI_TAB_ENABLE,
				disable_bookmark	: !BOOKMARK_TAB_ENABLE,
				disable_spies		: SPY_TAB_ENABLE,
				disable_inbox		: !INBOX_TAB_ENABLE,
				disable_search		: !SEARCH_TAB_ENABLE,
				disable_alliance	: !ALLIANCE_TAB_ENABLE,
				disable_wall		: !WALL_TAB_ENABLE,
				disable_single		: !SINGLE_TAB_ENABLE,
				disable_wheel		: !WHEEL_TAB_ENABLE,
				disable_log			: !LOG_TAB_ENABLE,
                enable_notifications_fortuna : false,
				enable_notifications_spy : false,
				enable_notifications_attack : false,
                messages_notification : [],
				speedups_enabled	: false,
				jobs_speedups_enabled : false,
				use_speedup_confirmation: false,
				jobs_cancel_confirmation : false,
				utc_time			: false,
				user_language		: LANG_CODE,

				alliance	: {
					last_update		: '',
					alliance_update	: '',
					activity_update	: '',
					current_tab		: 0,
					transport_id	: 0,
					reinforce_id	: 0,
					auto_id			: 0,
					sort_list		: '0',
					sort_alliance	: '0',
					sort_activity	: '0',
					sort_applicants : '0',
					data		 : {
						transports	: {},
						resources	: {},
						units		: {}
					},
					auto		 : {
						enabled		: false,
						recall 		: false,
						max_load	: false,
						delay_min	: 30,
						delay_max	: 45,
						max_marches	: null,
						transports	: {},
						resources	: {}
					},
					recall		 :false
				},

                sanctuaryAbilities : { },

				autoCollect	: {
					enabled		: true,
					last_time	: 0,
					delay		: 60,
					unit		: 60
				},

				autoRefresh	: {
					enabled	: false,
					delay	: 1,
					unit	: 3600
				},
				flashRefresh	: {
					enabled	: false,
					delay	: 30,
					unit	: 60
				},

				info	: {	current_tab	: 0, troop_sub_tab : 0, consumption_sel : 0	},
				jobs	: {	current_tab	: 0	},
				building	: {
					enabled		 : false,
					hide_fields  : false,
					level_enable : [{},{},{},{},{},{},{},{},{},{},{},{},{}], 
					level_cap	 : [{},{},{},{},{},{},{},{},{},{},{},{},{}]  
				},
				research	: {
					enabled		: false,
					res_enable	: [{},{},{},{},{},{}],
					res_cap		: [{},{},{},{},{},{}]
				},
				training	: {
					enabled		: false,
					current_tab	: 0,
					city		: [ 
						{ enabled : true, units : [], cap : [] }, 
						{ enabled : true, units : [], cap : [] }, 
						{ enabled : true, units : [], cap : [] }, 
						{ enabled : true, units : [], cap : [] }, 
						{ enabled : true, units : [], cap : [] }, 
						{ enabled : true, units : [], cap : [] }, 
						{ enabled : true, units : [], cap : [] }, 
						{ enabled : true, units : [], cap : [] }, 
						{ enabled : true, units : [], cap : [] }, 
						{ enabled : true, units : [], cap : [] }, 
						{ enabled : true, units : [], cap : [] }, 
						{ enabled : true, units : [], cap : [] },  
						{ enabled : true, units : [], cap : [] }, 
						{ enabled : true, units : [], cap : [] }  
						
					],
					mode		: 'min_resource'
				},
				resurrect	: {
					enabled		: false,
					res_enable	: [{},{},{},{},{},{}],
					res_max		: [{},{},{},{},{},{}]
				},
				sanctuary	: {
					enabled		: false,
					current_tab	: 0,
					male_id		: 0,
					female_id	: 0,
					feeding		: {}
				},

				collapsed: {
							quests: [],
							train: [],
							build: []
				},
				inbox	: {
					current_tab		: 0
				},
				map	: {
					radius		: 16,
					radius_fast	: 32,
					x			: 0,
					y			: 0
				},
				messages	: {
					last_read	: 0,
					missing		: 0
				},
				messages_tower	: [],
				messages_delete: {
							type: 0,
							msgGame: true,
							msgPlayer: true,
							msgSentinel: true,
							msgAlliance: true,
							rptAnthropus: true,
							rptTransport: true,
							rptSpy: true,
							rptBattle: true,
							rptReinforcement: true,
							rptCurse: true,
							rptTrading: true,
							rptBreeding: true,
							rptExceptMyAttacks: true,
							rptExceptYourAttacks: true,
							dateAll: true
						},
						search: {
							enabled: false,
							current_tab: 0,
							sort_list: '0',
							last_update: '',
							target: {
								enabled: false,
								alliance: null,
								player: null,
								distance: 14,
								x: 999,
								y: 999,
								type: '',
								level: 0
							},
							grassland: true,
							lake: true,
							hill: true,
							mountain: true,
							forest: true,
							nuage: true,
							plain: true,
							swamp: true,
							min_level: 1,
							max_level: 10,
							unowned: false
						},
				sound : {
					enable_jobs		: false,
					enable_fortuna  : false,
					enable_sentinel : false,
					repeat_attack	: false,
					attack_rdelay	: 2,
					repeat_spy		: false,
					spy_rdelay		: 2,
					URL_player		: SoundPlayer.SWF_PLAYER_URL,
					URL_attack		: SoundPlayer.DEFAULT_SOUND_URL.attack,
					URL_spy			: SoundPlayer.DEFAULT_SOUND_URL.spy,
					URL_building	: SoundPlayer.DEFAULT_SOUND_URL.building,
					URL_units		: SoundPlayer.DEFAULT_SOUND_URL.units,
					URL_research	: SoundPlayer.DEFAULT_SOUND_URL.research,
					URL_fortuna		: SoundPlayer.DEFAULT_SOUND_URL.fortuna
				},
				aZ	: { enabled : false },

				tower: {
							enabled: true,
							current_tab: 0,
							nospy: false,
							delay: 2,
							unit: 60,
							delete_report: true,
							delete_delay: 1,
							delete_unit: 3600,
							preset: '',
							send_message: false,
							msg_subject: 'I\'m under attack !! (automatic message)',
							msg_body: '%1 at %2 is leading an attack on me...\n' + 'Ennemy forces are composed with :\n' + '%3\n\n' + 'The attack should arrive at %4.\n' + 'Could you please reinforce me ASAP (%6 at %7) ?\n' + 'Thanks\n\n' + '%5'
						},

						attacks: {
							enabled: false,
							current_tab: 0,
							choice: 'AnthropusCamp',
							delay_min: 30,
							delay_max: 60,
							delete_reports: true,
							stop_on_loss: true,
							log_attacks: true,
							max_marches: null,
							level_enable: ['', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
							level_distance: ['', 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16],
							units: ['', {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}],
							include_great_dragon: ['', false, false, false, false, false, false, false, false, false, false, false],
							except_great_dragon: ['', {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}],
							clear_all_targets: false,
							send_without_dragon: false
						},
						bookmarks: {
							enabled: false,
							current_tab: 0,
							choice: 3,
							sort: 0,
							delay_min: 30,
							delay_max: 45,
							max_marches: null,
							stop_on_loss: true,
							delete_reports: true,
							targets: [],
							new_bookmark: {
								x: 0,
								y: 0,
								sequence: '',
								type: '',
								level: 0,
								units: {},
								dragons: {},
								include_great_dragon: false,
								comment: ''
							}
						},
						multiple: {
							enabled: false,
							current_tab: 0,
							delay_min: 30,
							delay_max: 45,
							delay_b4_secondary: 20,
							delay_min2: 10,
							delay_max2: 15,
							max_marches: null,
							max_secondary: null,
							stop_on_loss: true,
							delete_reports: true,
							target: {
								x: 0,
								y: 0,
								type: '',
								level: 0,
								ai: 0,
								primary_units: {},
								dragons_1: {},
								include_gd_1: false,
								saved_units_1: {},
								secondary_units: {},
								dragons_2: {},
								include_gd_2: false,
								saved_units_2: {},
								comment: ''
							}
						},
						single: {
							current_tab: 0,
							current_preset: '',
							presets: [],
							preset: {
								name: '',
								units: {}
							},
							target: {
								x: 0,
								y: 0,
								type: '',
								level: 0,
								ai: 0,
								units: {},
								dragons: {},
								saved_units: {},
								include_great_dragon: false,
								comment: ''
							},
							history: []
						},
						spies: {
							enabled: false,
							current_tab: 0,
							delay_min: 30,
							delay_max: 45,
							max_marches: null,
							stop_on_loss: true,
							delete_reports: false,
							target: {
								x: 0,
								y: 0,
								type: '',
								level: 0,
								ai: 0,
								units: {},
								comment: ''
							},
							history: []
						},
						wall: {
							current_tab: 0,
							current_preset: '',
							presets: [],
							preset: {
								name: '',
								units: {},
								scales: '',
								armor: ''
								}
							},
							waves: {
							enabled: false,
							current_tab: 0,
							delay_min: 30,
							delay_max: 45,
							max_marches: null,
							stop_on_loss: true,
							delete_reports: true,
							send_without_dragon: false,
							target: {
								x: 0,
								y: 0,
								type: '',
								level: 0,
								ai: 0,
								units: {},
								dragons: {},
								saved_units: {},
								include_great_dragon: false,
								comment: ''
							},
							history: []
						},
				wheel	: {
					current_tab	 : 0,
					type		 : 'regular',
					auto_refresh : true,
					auto_play	 : true,
					delay		 : 3,
					unit		 : 1,
					number		 : 1,
					max_auto	 : 1,
					mandatory	 : [['CompletionGrant', 'null'],
									['AncestralSeal', 'TestroniusInfusion']],
					optional	 : [['null', 'null', 'null', 'null'],
									['null', 'null', 'null', 'null']]
				}
			},
			stats	: {
				attacks	: {
					start_at		: 0,
					run_time		: 0,
					total_attacks	: 0,
					loss			: {},
					items			: {},
					resources		: {},
					by_level		: [ '',
						{total_attacks:0, items:{}, resources:{}},
						{total_attacks:0, items:{}, resources:{}},
						{total_attacks:0, items:{}, resources:{}},
						{total_attacks:0, items:{}, resources:{}},
						{total_attacks:0, items:{}, resources:{}},
						{total_attacks:0, items:{}, resources:{}},
						{total_attacks:0, items:{}, resources:{}},
						{total_attacks:0, items:{}, resources:{}},
						{total_attacks:0, items:{}, resources:{}},
						{total_attacks:0, items:{}, resources:{}},
						{total_attacks:0, items:{}, resources:{}}
					]
				},
				bookmarks	: {
					start_at		: 0,
					run_time		: 0,
					total_attacks	: 0,
					loss			: {},
					items			: {},
					resources		: {}
				},
				leaderboards	: {
					alliance	: {
						offensive_kills : [ {}, {}, {} ],
						defensive_kills	: [ {}, {}, {} ],
						power_taken		: [ {}, {}, {} ],
						power_gained	: [ {}, {}, {} ]
					},
					player	: {
						offensive_kills : [ [ {}, {}, {} ], [ {}, {}, {} ] ],
						defensive_kills	: [ [ {}, {}, {} ], [ {}, {}, {} ] ],
						power_taken		: [ [ {}, {}, {} ], [ {}, {}, {} ] ]
					},
					last_refresh : ''
				},
				multiple : {
					start_at		: 0,
					run_time		: 0,
					total_attacks	: 0,
					loss			: {},
					items			: {},
					resources		: {}
				},
				requests : {
					start_at	: 0,
					run_time	: 0,
					last_block	: 0,
					count_block	: 0,
					ajax_type	: {
						binary		 : {time:[], error:[]},
						versions	 : {time:[], error:[]},
						locales		 : {time:[], error:[]},
						cookie		 : {time:[], error:[]},
						manifest     : {time:[], error:[]},
						player		 : {time:[], error:[]},
						cities		 : {time:[], error:[]},
						jobs		 : {time:[], error:[]},
						dragons		 : {time:[], error:[]},
						alliances	 : {time:[], error:[]},
						membership	 : {time:[], error:[]},
						activity	 : {time:[], error:[]},
						map			 : {time:[], error:[]},
						tile_at		 : {time:[], error:[]},
						building	 : {time:[], error:[]},
						research	 : {time:[], error:[]},
						training	 : {time:[], error:[]},
						resurrect	 : {time:[], error:[]},
						canceljob	 : {time:[], error:[]},
						marches		 : {time:[], error:[]},
						cancelmarch	 : {time:[], error:[]},
						reports		 : {time:[], error:[]},
						reports_del  : {time:[], error:[]},
						reports_read : {time:[], error:[]},
						message		 : {time:[], error:[]},
						minigame	 : {time:[], error:[]},
						save_minigame: {time:[], error:[]},
						leaderboards : {time:[], error:[]},
						aI		 : {time:[], error:[]},
						claim		 : {time:[], error:[]},
						defended	 : {time:[], error:[]},
						defense		 : {time:[], error:[]},
						items		 : {time:[], error:[]},
						breeding	 : {time:[], error:[]},
						feeding	 	 : {time:[], error:[]},
						dragonHandle : {time:[], error:[]},
                        customization: {time:[], error:[]}
					}
				},
				spies	: {
					start_at		: 0,
					run_time		: 0,
					total_attacks	: 0,
					loss			: {}
				},
				total	: {
					start_at		: 0,
					total_attacks	: 0,
					loss			: {},
					items			: {},
					resources		: {}
				},
				waves	: {
					start_at		: 0,
					run_time		: 0,
					total_attacks	: 0,
					loss			: {},
					items			: {},
					resources		: {}
				},
				wheel	: {
					type		 : 'regular',
					total_grids	 : [0, 0],
					total_played : [0, 0],
					items		 : [{}, {}],
					last_won	 : [[], []]
				}
			},
			dynamic	: {
				recall_marches	: [],
				players	: {
					memberships				: [],
					memberships_evolution	: [],
					alliances				: [],
					friends					: [],
					foes					: [],
					alliances_evolution		: [],
					activity				: [],
					applicants				: []
				}
			},
			map	: {
				terrains	: {},
				players		: {},
				evolution	: {},
				alliance	: {},
				coords		: {}
			},
			marches	: {
				start_at	: 0,
				attacks		: {},
				bookmark	: {},
				waves		: {},
				spies		: {},
				transport	: {},
				multiple	: {},
				count_limit	: 1,
				ressources	: {}
			}
		});

		aZ ('Session parameters : '+bC (aU, 6, 1));
		

		if ( Data.options.user_language != undefined && Data.options.user_language != null && Data.options.user_language != LANG_CODE) {
			et(Data.options.user_language);
		}
		function eP (current_step) {
			var wait_time = Math.randRange(2500, 4500);
			var error_code;
			var error_msg;
            var progress_title;
			progressBar.resume ();

			function bx (message, waitTime, currentStep) {
				aZ ( message );
				bf ( message );
				STARTUP_TIMER = setTimeout(eP, waitTime, currentStep);
			}

			function onError (errorCode, errorMsg, message, waitTime, currentStep) {
				error_code = errorCode;
				switch (errorCode) {
					case 400 :	error_msg = translate('<b>Bad request!</b>');
								progressBar.stop;
								progressBar.hideshow(false);
								retry = 400;
								dw('<b>' + kFatalSeedTitle + '</b><br><br>\
											<font color="#BF0000"><b> ' + errorMsg + '</b></font>\
											<br><br><div align=left>\
											' + kFatalSeedMsg + '<br><br></div>\
											<a id="' + UID['support_link'] + '" href="" target="_blank">Bugs and Known Issues</a><br>');
								return;
								break;
					case 403 :	error_msg = translate('<b>Forbidden!</b>');
								retry = 403;
								return;
								break;
					case 429 :	error_msg = '<b>API </b>'+translate('<b>Rate Limit Exceeded</b>, too many requests!');
								waitTime = E429_DELAY;
								progressBar.update ({ step:currentStep, title:progress_title, stepText:translate('Fetching') + ' ' + message +'<br>'+ error_msg + ' - ' + translate('Retry in') + ' ' + waitTime });
								progressBar.pause ();
								aZ(error_msg + ' - ' + translate('Retry in :') + waitTime);
								STARTUP_TIMER = setTimeout( eP, waitTime * 1000, currentStep );
								return;
								break;
					case 509 :	error_msg = translate('<b>Rate Limit Exceeded</b>, too many requests!');
								waitTime = 600;
								progressBar.update ({ step:currentStep, title:progress_title, stepText:translate('Fetching') + ' ' + message +'<br>'+ error_msg + ' - ' + translate('Retry in') + ' ' + waitTime });
								progressBar.pause ();
								aZ(error_msg + ' - ' + translate('Retry in :') + waitTime);
								STARTUP_TIMER = setTimeout( eP, waitTime * 1000, currentStep );
								return;
								break;
					default : break;
				}
				error_msg = errorMsg;
				bf('stepStarting: '+message+', Error '+errorCode+', '+error_msg+'. Retry ' + retry);
				STARTUP_TIMER = setTimeout( eP, waitTime, currentStep, ++retry);
			}

			if (retry <= 20) {
			switch ( current_step ) {
				case 1: 
					function ia (bO) {
						var params = {};
						new aB ('versions', url_versions + '/supported_versions', params, function (res) {
							if (res.ok && res.dat) {
								var list = '';
								if (res.dat.length) {
									api_version = res.dat[res.dat.length-1];
									for (var av=0; av<res.dat.length; av++) list = list+((av==0) ? '':', ')+res.dat[av];
								} else {
									api_version = res.dat;
									list = res.dat;
								}
								aZ ( 'List of supported API version : '+list );
								bf ( 'List of supported API version : '+list );
							}
							if (bO) bO(res);
						}, false);
					}
					progress_title = translate('Getting API version...');
					progressBar.update ({ step:current_step, title:progress_title, stepText:translate('Checking API version') });
					ia(function (res) {
						if (res.ok) {
							bx (translate('API version Successfully initialized')+' : '+api_version, wait_time, current_step + 1);
						} else {
							bf('stepStarting: '+translate('Checking API version')+', Error '+res.status+', '+res.errmsg+'.');
							bx (translate('API version not available. Using default')+' : '+api_version, wait_time, current_step + 1);
						}
					});
					break;
				case 2: 
					progress_title = translate('Getting map data...');
					progressBar.update ({ step:current_step, title:progress_title, stepText:translate('Charging Map binairy file') });
					Map.initMapData(function (res) {
						if (res.ok) {
							bx (translate('Map Bin Successfully initialized'), wait_time, current_step + 1);
						} else {
							onError (res.status, res.errmsg, translate('Map Bin'), wait_time, current_step);
						}
					});
					break;
				case 3: 
					progress_title = translate('Getting basic data...');
					progressBar.update ({ step:current_step, title:progress_title, stepText:translate('Fetching Translation matrix') });
					Translation.init(function (res) {
						if (res.ok) {
							bx (translate('Translation Matrix Successfully initialized'), wait_time, current_step + 1);
						} else {
							onError (res.status, res.errmsg, translate('Translation matrix'), wait_time, current_step);
						}
					});
					break;
				case 4: 
					progress_title = translate('Getting game data...');
					progressBar.update ({ step:current_step, title:progress_title, stepText:translate('Fetching Manifest') });
					Manifest.init(function (res) {
						if (res.ok) {
							bx (translate('Manifest Successfully initialized'), wait_time, current_step + 1);
						} else {
							onError (res.status, res.errmsg, translate('Manifest'), wait_time, current_step);
						}
					});
					break;
				case 5: 
					progress_title = translate('Getting game data...');
					progressBar.update ({ step:current_step, title:progress_title, stepText:translate('Fetching Seed') });
					Seed.init(function (res) {
						if (res.ok) {
							bx (translate('Seed Successfully initialized'), wait_time, current_step + 1);
						} else {
							onError (res.status, res.errmsg, translate('Seed'), wait_time, current_step);
						}
					});
					break;
				case 6: 
					progress_title = translate('Getting dragons data...');
					progressBar.update ({ step:current_step, title:progress_title, stepText:translate('Fetching Dragons data') });
					Seed.fetchDragons (function(res) {
						if (res.ok) {
							bx (translate('Dragons data successfully fetched'), wait_time, current_step + 1);
						} else {
							onError (res.status, res.errmsg, translate('Dragons'), wait_time, current_step);
						}
					});
					break;
				case 7: 
					progress_title = translate('Getting cities data...');
					var cityIdx;
					for (var i=0; i < Seed.cityInit.length; i++) {
						if (Seed.cityInit[i].type == 'capital') {
							cityIdx = Seed.cityInit[i].id;
						}
					}
					citySteps = Math.floor(14 / (Seed.cityInit.length-1));
					progressBar.update ({ step:current_step, title:progress_title, stepText:translate('Fetching Capital data') });
					Seed.fetchCity (cityIdx, function(res) {
						if (res.ok) {
							wait_time = Math.randRange(2500,6000);
							bx (translate('Capital data successfully fetched'), wait_time, current_step + 1);
						} else {
							onError (res.status, res.errmsg, translate('Capital data'), wait_time, current_step);
						}
					});
					break;
				case 8: 
					progress_title = translate('Getting cities data...');
					for (var i=0; i < Seed.cityInit.length; i++) {
						if (Seed.cityInit[i].loaded) {
							continue;
						}
						progressBar.update ({ step:current_step+(citySteps*i), title:progress_title, stepText:translate('Fetching Outpost n°')+(i+1) });
						if (Seed.cityInit[i].timer) {
							clearTimeout (Seed.cityInit[i].timer);
						}
						var current_index = i;
						var cityIdx = Seed.cityInit[i].id;
						Seed.fetchCity (cityIdx, function(res) {
							if (res.ok) {
								wait_time = Math.randRange(2500,6000);
								if (current_index == Seed.cityInit.length - 1) {
									wait_time = 2500;
								}
								bx (translate('Outpost')+' #'+(i+1)+' '+translate('data successfully fetched'), wait_time, current_step);
							} else {
								onError (res.status, res.errmsg, translate('Outpost')+' #'+(i+1), wait_time, current_step);
							}
						});
						return;
					}
					iI();
					return;
					break;
				}
			} else {
				clearTimeout( STARTUP_TIMER );
				progressBar.stop;
				progressBar.hideshow(false);
				if (retry < 400) { 
					dw('<b>' + kFatalSeedTitle + '</b><br><br>\
								<font color="#BF0000"><b> ' + (error_code || retry) + ' - ' + error_msg + '</b></font>\
								<br><br><div align=left>\
								' + kFatalSeedMsg + '<br><br></div>\
								<a id="' + UID['support_link'] + '" href="" target="_blank">Bugs and Known Issues</a><br>');
				}
				return;
			}
		}
		
		aX('<B>' + scriptVersion + ' ' +translate('Loading...') + '</B>');
		dk('<B>' + scriptVersion + ' ' +translate('Loading...') + '</B>');
		eP( 1 );

		function iI() {

			if (updaterPop)	setTimeout (function(){updaterPop.destroy()}, 100);

			progressBar.update ({ step:19, title:translate('Completing...'), stepText:translate('Initializing map, auto-collect, ...') });
			Names.init ();
			Map.init ();
			Marches.init ();
			AutoCollect.init ();
			AutoRefresh.init ();
			Messages.init ();

			progressBar.stop;
			progressBar.hideshow(false);
			progressBarPop.destroy();

			if (Data.options.popUp==null || Data.options.popUp.x==null || Data.options.popUp.x=='' || isNaN(Data.options.popUp.x)){
				var maxWidth = document.body.offsetWidth - 570;
				if (maxWidth < 760) maxWidth = 760;
				Data.options.popUp.x = maxWidth+2;
				Data.options.popUp.y = 1;
			}
			var popupWidth = 550;
			var popupHeight = 800;

			km();

			mainPop = new cO ('main', Data.options.popUp.x, Data.options.popUp.y, popupWidth, popupHeight, Data.options.popUp.drag, function () { tabManager.hideTab(); }); 

			Map.checkOurCoords();

			tabManager.init(mainPop.aG());

			Data.options.popUp.open = true;
			if (Data.options.popUp.open) {
				mainPop.show(true);
				tabManager.showTab();
			}

			Data.setDefaultValues ('options');
			RecallMarch.init ();
			SoundPlayer.init ();
			WackoScript.init ();
            dptp4Notifications.init ();
			window.addEventListener('unload', Data.onUnload, false);

			iL();

			aX('<B>' + scriptVersion + ' ' +translate('Loaded') + '</B>');
			dk('<B>' + scriptVersion + ' ' +translate('Loaded') + '</B>');
			if (Data.stats.requests) Data.stats.requests.start_at = be();
			fZ();
			REALM_NAME = '';
			bI(REALM_NAME);
		}
	} catch (e) {
		dw(kInitErr + e);
		bI(bC (e, 8, 1));				
	}
}
var dptp4Notifications={init:function(){var e=dptp4Notifications;Messages.addAlarmReportListener(e.gotAlarmReport);aZ("dptp4Notifications init successfully")},showFortunaWin:function(e){var t=dptp4Notifications;if(Data.options.enable_notifications_fortuna){t.showNotification(REALM_NAME+" : FORTUNA",e,SERVER_ID+"fortuna"+be(),"https://wackoscripts.com/images/Fortunas_Ticket.jpg")}},showNotification:function(e,t,n,r){try{aZ("IsChrome = "+IsChrome);if(!IsChrome){Notification.requestPermission(function(i){aZ("perm = "+i);if(i=="granted"){return new Notification(e,{body:t,tag:n,icon:r})}})}else{aZ("checkPermission = "+window.webkitNotifications.checkPermission());if(window.webkitNotifications.checkPermission()==0){return new Notification(e,{body:t,tag:n,icon:r})}else{window.webkitNotifications.requestPermission()}}}catch(i){aZ("Error Notification = "+bC(i,8,1))}},showAlertNotification:function(e){if(Data.options.enable_notifications_spy&&e.type==1||Data.options.enable_notifications_attack&&e.type==0){dptp4Notificationss.showNotification(REALM_NAME+"-"+translate(e.type==1?"Spy":"Attack")+"-"+translate("Arrival time")+": "+(new Date(e.arrive_at)).formatDate()+" "+(new Date(e.arrive_at)).formatTime(),e.x+","+e.y+" : "+e.alliance+"/"+e.troups,SERVER_ID+(e.type==1?"Spy":"Attack")+e.x+e.y+be(),e.type==1?"https://wackoscripts.com/images/Spy.jpg":"https://wackoscripts.com/images/Attacks.jpg")}},gotAlarmReport:function(e,t){var n=dptp4Notifications;var r=0;var i={id:t,type:0,arrive_at:0,alliance:"",x:0,y:0,units:{},troups:"",general:0,op:0};if(!e){return}if(e.report.warnings){var s=e.report.warnings;if(s.attacker_name){i.alliance=s.attacker_name}if(s.attacker_title&&s.attacker_title.alliance){if(i.alliance){i.alliance=i.alliance+" / "+s.attacker_title.alliance}else{i.alliance=s.attacker_title.alliance}}if(s.attacker_coords){i.x=s.attacker_coords.x;i.y=s.attacker_coords.y}if(s.march_type&&s.march_type=="SpyMarch"){i.type=1}if(s.attacker_units){var o=[];for(var u in s.attacker_units){var a=bD(s.attacker_units[u]," ")+" "+translate(u);o.push(a);if(i.type==1&&u=="Spy"){r=s.attacker_units[u]}}if(o.length>0){i.troups=o.join(", ")}i.units=aA(s.attacker_units)}if(s.march_arrival_time){i.arrive_at=n.getTimeAlarm(s.march_arrival_time)}}var f=false;for(var l=0;l<Data.options.messages_notification.length&&!f;l++){if(Data.options.messages_notification[l].id==t){f=true}}if(!f){Data.options.messages_notification.push(i);n.showAlertNotification(i)}},getTimeAlarm:function(e){var t=0;if(e.length>=19){var n=bV(e.substr(0,4));var r=bV(e.substr(5,2));if(r==0){r=bV(e.substr(6,1))}var i=bV(e.substr(8,2));if(i==0){i=bV(e.substr(9,1))}var s=bV(e.substr(11,2));if(s==0){s=bV(e.substr(12,1))}var o=bV(e.substr(14,2));if(o==0){o=bV(e.substr(15,1))}var u=bV(e.substr(17,2));if(u==0){u=bV(e.substr(18,1))}t=new Date(Date.UTC(n,r-1,i,s,o,u))}return t}}
var MyAjax = { addMainParams: function() { var t = MyAjax; var p = {}; p['user_id'] = aU.attrs.userId; p['dragon_heart'] = aU.attrs.dragonHeart; p['_session_id'] = aU.attrs.sessionId; p['version'] = api_version; p['timestamp'] = bV(be()); return p; }, sanctuaryAbilities: function(bO) { var t = MyAjax; var p = {}; p = t.addMainParams(); new aB('dragonHandle', 'sanctuary_abilities', p, by, false); function by(rslt) { if (rslt.ok) { Data.options.sanctuaryAbilities = rslt.dat.sanctuary_abilities; if (bO) { bO(true); } } else { aZ('Ajax.sanctuaryAbilities ' + translate('was returned with a status of') + ' ' + rslt.ok + ' - ' + rslt.errmsg); if (bO) { bO(false); } } } }, battleReport: function(report_id, player_id, bO) { var t = MyAjax; var p = {}; p = t.addMainParams(); new aB('reports_read', 'reports/battle/' + report_id + '/player/' + player_id + '.json', p, by, false); function by(rslt) { if (rslt.ok) { var msg = rslt.dat.result.report_notification; var rpt = { id: msg.id, created_at: msg.created_at, summary: msg.summary, type: msg.report_type, from: msg.from, unread: (as(msg.read_at) ? true : false), report: (rslt.dat.result.report ? rslt.dat.result.report : null) }; if (Messages.activity[report_id]) Messages.activity[report_id].mergeWith(rpt); else Messages.activity[report_id] = aA(rpt); if (bO) { bO(rpt); return; } } else aZ('Ajax.battleReport ' + translate('was returned with a status of') + ' ' + rslt.ok + ' - ' + rslt.errmsg); if (bO) bO(null); return; } }, setCustomization: function(unitName, armor, scales, bO) { var t = MyAjax; var p = {}; p = t.addMainParams(); p['unit_name'] = unitName; if (armor) { p['customizations'] = scales + ',' + armor; } else { p['customizations'] = scales; } new aB('customization', 'player_unit_customization/update.json', p, by, true); function by(rslt) { if(rslt.dat) { if (rslt.dat.result) { if (rslt.dat.result.success) { var dragon_name = rslt.dat.result.unit_type.substring(rslt.dat.result.unit_type.indexOf('::') + 2); Seed.dragons[dragon_name].slots = rslt.dat.result.slots; if (Seed.dragons[dragon_name].slots.scales == undefined) Seed.dragons[dragon_name].slots.scales = "GreenScales"; if (Seed.dragons[dragon_name].slots.armor == undefined) Seed.dragons[dragon_name].slots.armor = "GreenArmor"; } } else { aZ('Ajax.setCustomization ' + translate('was returned with a status of') + ' ' + rslt.ok + ' - ' + rslt.errmsg); } } else { aZ('Ajax.setCustomization ' + translate('was returned with a status of') + ' ' + rslt.ok + ' - ' + rslt.errmsg); } if (bO) bO(rslt); return; } }, buildingUpgrade: function(cityId, buildingId, bO) { var t = MyAjax; var p = {}; p = t.addMainParams(); p['_method'] = 'put'; new aB('building', 'cities/' + cityId + '/buildings/' + buildingId + '.json', p, by, true); function by(rslt) { if (rslt.ok) { if (rslt.dat.result.success) { Seed.checkAddJob(rslt.dat.result.job); } } else aZ('Ajax.buildingUpgrade ' + translate('was returned with a status of') + ' ' + rslt.ok + ' - ' + rslt.errmsg); if (bO) bO(rslt); return; } }, cancelTraining: function(jobId, bO) { var t = MyAjax; var p = {}; p = t.addMainParams(); p['job_id'] = jobId; p['_method'] = 'delete'; new aB('canceljob', 'jobs/' + jobId + '.json', p, by, true); function by(rslt) { if (rslt.ok) { if (rslt.dat.result.success) { delete(Seed.jobs[rslt.dat.result.job.city_id][rslt.dat.result.job.id]); Seed.updateCity(rslt.dat.result.city); } } else aZ('Ajax.cancelTraining ' + translate('was returned with a status of') + ' ' + rslt.ok + ' - ' + rslt.errmsg); if (bO) bO(rslt); return; } }, claimQuest: function(questName, bO) { var t = MyAjax; var p = {}; p = t.addMainParams(); p['quest_name'] = questName; p['_method'] = 'put'; new aB('claim', 'player_quests/claim.json', p, by, true); function by(rslt) { if (rslt.ok) { try { if (rslt.dat.quests.claimed) Seed.player.quests.claimed = aA(rslt.dat.quests.claimed); if (rslt.dat.result.items) Seed.player.items = aA(rslt.dat.result.items); } catch (e) { aZ(translate('could-not-claim') + ': ' + e.name + ' - ' + e.message); } } else aZ(translate('could-not-claim') + ': ' + rslt.errmsg); if (bO) bO(rslt); return; } }, collectResources: function(cityId, bO) { var t = MyAjax; var p = {}; p = t.addMainParams(); new aB('collect', 'cities/' + cityId + '/move_resources.json', p, by, true); function by(rslt) { if (rslt.ok) Seed.updateCity(rslt.dat.city); else aZ(translate('Auto-Collect Error') + ': ' + rslt.errmsg); if (bO) bO(rslt.ok); return; } }, dragonBreeding: function(male_id, female_id, bO) { var t = MyAjax; var p = {}; p = t.addMainParams(); p['_method'] = 'put'; p['male_id'] = male_id; p['female_id'] = female_id; new aB('breeding', 'dragons', p, by, true); function by(rslt) { if (rslt.ok) { if (rslt.dat.result.success) Seed.checkAddJob(rslt.dat.result.breeding_job); } else aZ('Ajax.dragonBreeding ' + translate('was returned with a status of') + ' ' + rslt.ok + ' - ' + rslt.errmsg); if (bO) bO(rslt); return; } }, dragonHandle: function(options, bO) {  if (!options.dragon_id) return; var t = MyAjax; var p = {}; p = t.addMainParams(); p['_method'] = (options.method || 'put'); if (options && options.building_id) p['building_id'] = options.building_id; new aB('dragonHandle', 'dragons/' + options.dragon_id, p, by, true);

				function by(rslt) {
					if (rslt.ok) {
						if (rslt.dat.result.success) {
							if (options.method == 'delete') {
								delete(Seed.sanctuary_dragons[options.dragon_id]);
								if (Data.options.sanctuary.feeding[options.dragon_id]) delete(Data.options.sanctuary.feeding[options.dragon_id]);
							} else {
								Seed.player.boosts = aA(rslt.dat.boosts);
								try {
									for (var i in rslt.dat.result.dragon) {
										var dragon = aA(rslt.dat.result.dragon[i]);
										var dragon_name = dragon.type.substring(dragon.type.indexOf('::') + 2);
										dragon_name = (dragon_name == 'CityGreatDragon') ? 'GreatDragon' : dragon_name;
										dragon.name = dragon_name;
										var dragon_rank = sanctuaryDragonRank[dragon.rank];
										dragon.type = dragon.gender + '-' + dragon_rank;
										dragon.subtype = ((i == 'city_great_dragon') ? 'great_dragon' : i).replace(/ |_/g, '-');
										Seed.sanctuary_dragons[dragon.id] = aA(dragon);
									}
								} catch (e) {
									rslt.ok = false;
									rslt.errmsg = 'Exception - ' + e.toString();
									aZ('Ajax.dragonHandle ' + translate('was returned with a status of') + ' ' + rslt.ok + ' - ' + rslt.errmsg)
								}
							}
						}
					} else aZ('Ajax.dragonHandle ' + translate('was returned with a status of') + ' ' + rslt.ok + ' - ' + rslt.errmsg);
					if (bO) bO(rslt);
					return;
				}
			},
			dragonFeeding: function(dragon_id, bO) {
				var t = MyAjax;
				var p = {};
				p = t.addMainParams();
				new aB('feeding', 'dragons/' + dragon_id + '/feed', p, by, true);

				function by(rslt) {
					if (rslt.ok) {
						if (rslt.dat.result.success)
							Seed.checkAddJob(rslt.dat.result.feeding_job);
					} else aZ('Ajax.dragonFeeding ' + translate('was returned with a status of') + ' ' + rslt.ok + ' - ' + rslt.errmsg);
					if (bO) bO(rslt);
					return;
				}
			},
			getMinigame: function(type, bO) {
				var t = MyAjax;
				var p = {};
				p = t.addMainParams();
				p['ticket_type'] = type;
				new aB('minigame', 'minigames/index.json', p, by, false);

				function by(rslt) {
					if (rslt.ok) {
						if (bO) {
							bO({
								ok: rslt.ok,
								list: rslt.dat.result.prize_list,
								id: rslt.dat.result.minigame_timestamp,
								ticket: rslt.dat.result.has_free_ticket,
								golden: rslt.dat.result.has_free_golden_ticket
							});
							return;
						}
					} else aZ('Ajax.getMinigame ' + translate('was returned with a status of') + ' ' + rslt.ok + ' - ' + rslt.errmsg);
					if (bO) bO(null);
					return;
				}
			},
			marchRecall: function(cityId, marchId, bO) {
				var t = MyAjax;
				var p = {};
				p = t.addMainParams();
				p['_method'] = 'delete';
				new aB('cancelmarch', 'cities/' + cityId + '/marches/' + marchId + '.json', p, by, true);

				function by(rslt) {
					if (rslt.ok) {
						if (rslt.dat.result.success)
							Seed.updateCity(rslt.dat.result.city);
					} else aZ('Ajax.marchRecall ' + translate('was returned with a status of') + ' ' + rslt.ok + ' - ' + rslt.errmsg);
					if (bO) bO(rslt);
					return;
				}
			},
			marchBusy: false,
			marchSend: function(cityId, x, y, generalId, units, ownerId, bO) {
				var t = MyAjax;

				t.marchBusy = true;
				var dragon_type = null;
				var found_in_list = false;
				var u = {}
				var mt = false;
				var sendTroops = "{";
				for (var pu in units) {
					if (units[pu] > 0) {
						for (var gd = 0; gd < Seed.dragonList.length && !found_in_list; gd++) {
							if (Seed.dragonList[gd].type == units[pu]) {
								found_in_list = true;
								dragon_type = units[pu];
							}
						}
						u[pu] = units[pu];
						if (mt == true) {
							sendTroops += ',';
						}
						sendTroops += '"' + pu + '":' + units[pu];
						mt = true;
					}
				}
				sendTroops += "}";

				var p = {};
				p = t.addMainParams();
				p['march[x]'] = x;
				p['march[y]'] = y;
				p['_method'] = 'post';
				p['march[units]'] = sendTroops;
				p['march[general_id]'] = generalId;
				p['march[march_type]'] = 'attack'; 
				new aB('marches', 'cities/' + cityId + '/marches.json', p, by, true);

				function by(rslt) {
					t.marchBusy = false;
					if (rslt.ok) {
						try {
							rslt.dat.result.job.ownerId = ownerId;
							if (rslt.dat.result.city.marches) {
								for (var i = 0; i < rslt.dat.result.city.marches.length; i++) {
									if (rslt.dat.result.city.marches[i].id == rslt.dat.result.job.march_id)
										rslt.dat.result.city.marches[i].ownerId = ownerId;
								}
							}
							Seed.updateCity(rslt.dat.result.city);
							if (dragon_type !== null && Seed.dragons[dragon_type])
								Seed.dragons[dragon_type].is_in_city = false;
						} catch (e) {
							bf('***********' + e);
						}
					} else aZ('Ajax.marchSend ' + translate('was returned with a status of') + ' ' + rslt.ok + ' - ' + rslt.errmsg);
					if (bO) bO(rslt);
					return;
				}
			},
			marchSpy: function(cityId, x, y, units, ownerId, bO) {
				var t = MyAjax;

				t.marchBusy = true;
				var u = {}
				var mt = false;
				var sendTroops = "{";
				for (var pu in units) {
					if (units[pu] > 0) {
						u[pu] = units[pu];
						if (mt == true) {
							sendTroops += ',';
						}
						sendTroops += '"' + pu + '":' + units[pu];
						mt = true;
					}
				}
				sendTroops += "}";

				var p = {};
				p = t.addMainParams();
				p['march[march_type]'] = 'spy';
				p['march[y]'] = y;
				p['march[units]'] = sendTroops;
				p['_method'] = 'post';
				p['march[x]'] = x;
				new aB('marches', 'cities/' + cityId + '/marches.json', p, by, true);

				function by(rslt) {
					t.marchBusy = false;
					if (rslt.ok) {
						try {
							rslt.dat.result.job.ownerId = ownerId;
							if (rslt.dat.result.city.marches) {
								for (var i = 0; i < rslt.dat.result.city.marches.length; i++) {
									if (rslt.dat.result.city.marches[i].id == rslt.dat.result.job.march_id)
										rslt.dat.result.city.marches[i].ownerId = ownerId;
								}
							}
							Seed.updateCity(rslt.dat.result.city);
						} catch (e) {
							bf('***********' + e);
						}
					} else aZ('Ajax.marchSpy ' + translate('was returned with a status of') + ' ' + rslt.ok + ' - ' + rslt.errmsg);
					if (bO) bO(rslt);
					return;
				}
			},
			membership: function(alliance_id, id, method, bO) {
				var t = MyAjax;
				var p = {}, json = 'alliances/' + alliance_id + '/memberships';
				p = t.addMainParams();
				if (method == 'put')
					p['alliance_membership[approved]'] = 'true';
				if (method == 'invite')
					p['alliance_membership[player_id]'] = id;
				else {
					json += '/' + id;
					p['_method'] = method;
				}
				new aB('membership', json, p, by, true);

				function by(rslt) {
					if (!rslt.ok) aZ('Ajax.membership ' + translate('was returned with a status of') + ' ' + rslt.ok + ' - ' + rslt.errmsg);
					if (bO) {
						
						bO(rslt);
					}
					return;
				}
			},
			messageDetail: function(id, bO) {
				var t = MyAjax;
				var p = {};
				p = t.addMainParams();
				new aB('reports_read', 'reports/' + id + '.json', p, by, false);

				function by(rslt) {
					if (rslt.ok) {
						var msg = rslt.dat.result.report_notification;
						var d = {
							id: msg.id,
							created_at: msg.created_at,
							summary: msg.summary,
							type: msg.report_type,
							from: msg.from,
							unread: (as(msg.read_at) ? true : false),
							report: (rslt.dat.result.report ? rslt.dat.result.report : null)
						};
						if (Messages.details[msg.id])
							Messages.details[msg.id].mergeWith(d);
						else Messages.details[msg.id] = aA(d);
						Messages.updateUnreadCount();
						if (bO) {
							bO(rslt.dat.result);
							return;
						}
					} else aZ('Ajax.messageDetail ' + translate('was returned with a status of') + ' ' + rslt.ok + ' - ' + rslt.errmsg);
					if (bO) bO(null);
					return;
				}
			},
			messageDelete: function(ids, bO) {
				var t = MyAjax;
				var p = {};
				p = t.addMainParams();
				p['_method'] = 'delete';
				p['ids'] = ids.join('|');
				new aB('reports_del', 'reports/bulk_delete.json', p, by, true);

				function by(rslt) {
					if (rslt.ok) {
						for (var i = 0; i < ids.length; i++) {
							if (Messages.details[ids[i]]) delete(Messages.details[ids[i]]);
						}
						Messages.updateUnreadCount();
					} else aZ('Ajax.messageDelete ' + translate('was returned with a status of') + ' ' + rslt.ok + ' - ' + rslt.errmsg);
					if (bO) bO(rslt.ok);
					return;
				}
			},
			messageList: function(cat, numpage, count, bO) {
				var t = MyAjax;
				if (!cat) {
					cat = 'all';
				}
				var npage = (numpage == -1 ? 1 : numpage);
				var p = {};
				p = t.addMainParams();
				p['count'] = count;
				p['category'] = cat;
				p['page'] = npage;
				new aB('reports', 'reports.json', p, by, false);

				function by(rslt) { if (rslt.ok) { Messages.total_count = rslt.dat.result.total; if (rslt.dat.result.report_notifications) { var msgs = rslt.dat.result.report_notifications; for (var i = 0; i < msgs.length; i++) { var d = { id: msgs[i].id, created_at: msgs[i].created_at, summary: msgs[i].summary, type: msgs[i].report_type, from: msgs[i].from, unread: (as(msgs[i].read_at) ? true : false) }; if (Messages.details[msgs[i].id]) Messages.details[msgs[i].id].mergeWith(d); else Messages.details[msgs[i].id] = aA(d); } Messages.updateUnreadCount(); } if (bO) bO(rslt.dat.result); return; } else aZ('Ajax.messageList ' + translate('was returned with a status of') + ' ' + rslt.ok + ' - ' + rslt.errmsg); if (bO) bO(null); return; } }, messageSend: function(subject, body, id, to_player, bO) { var t = MyAjax; var p = {}; p = t.addMainParams(); if (to_player) p['player_id'] = id; else p['alliance_id'] = id; p['message[subject]'] = subject; p['message[message]'] = body; new aB('message', 'messages.json', p, by, true); function by(rslt) { if (rslt.ok) { if (bO) { bO(rslt.dat.result); return; } } else aZ('Ajax.messageSend ' + translate('was returned with a status of') + ' ' + rslt.ok + ' - ' + rslt.errmsg); if (bO) bO(null); } }, pollingList: function(bO) { var t = MyAjax; var p = {}; new aB('reports', 'poll.json', p, by, false); function by(rslt) { if (rslt.ok) { if (bO) { bO(rslt.dat.result);  return; } } else aZ('Ajax.pollingList ' + translate('was returned with a status of') + ' ' + rslt.ok + ' - ' + rslt.errmsg); if (bO) bO(null); return; } }, researchStart: function(cityId, researchType, bO) { var t = MyAjax; var p = {}; p = t.addMainParams(); p['_method'] = 'post'; p['research[research_type]'] = researchType; new aB('research', 'cities/' + cityId + '/researches.json', p, by, true); function by(rslt) { if (rslt.ok) { Seed.updateCity(rslt.dat.result.city); Seed.checkAddJob(rslt.dat.result.job); } else aZ('Ajax.researchStart ' + translate('was returned with a status of') + ' ' + rslt.ok + ' - ' + rslt.errmsg); if (bO) bO(rslt); return; } }, save_sound: function(bO) { var t = MyAjax; var p = {}; p = t.addMainParams(); p['cookie'] = '{"DoALocalSoundKey":{"sound":0,"music":0}}'; new aB('cookie', 'cookie/save.json', p, by, true); function by(rslt) { if (!rslt.ok) aZ('Ajax.save_sound ' + translate('was returned with a status of') + ' ' + rslt.ok + ' - ' + rslt.errmsg); if (bO) bO(rslt.ok); return; } }, saveMinigame: function(id, type, bO) { var t = MyAjax; var p = {}; p = t.addMainParams(); p['ticket_type'] = type; p['minigame_timestamp'] = id; new aB('save_minigame', 'minigames/save_result.json', p, by, true); function by(rslt) { if (rslt.ok) { try { if (rslt.dat.result.items) Seed.player.items = aA(rslt.dat.result.items); Seed.player.tickets.gold_club = rslt.dat.result.tickets.fortunas_chance; Seed.player.tickets.fortunas_chance = rslt.dat.result.tickets.gold_club; if (bO) { bO({ ok: rslt.ok, item: rslt.dat.result.item_won }); return; } } catch (e) { rslt.ok = false; rslt.errmsg = e.name + ' - ' + e.message; aZ(translate('Save minigame Error') + ': ' + e.name + ' - ' + e.message); } } else aZ(translate('Save minigame Error') + ': ' + rslt.errmsg); if (bO) bO(rslt); return; } }, setDefenseForce: function(cityId, units, bO) { var t = MyAjax; var u = {}; var mt = false; var defenseForce = "{"; for (var pu in units) { if (units[pu] > 0) { u[pu] = units[pu]; if (mt == true) { defenseForce += ','; } defenseForce += '"' + pu + '":' + units[pu]; mt = true; } } defenseForce += "}"; var p = {}; p = t.addMainParams(); p['_method'] = 'put'; p['defense_force[units]'] = defenseForce; new aB('defense', 'cities/' + cityId + '/defense_force.json', p, by, true); function by(rslt) { if (rslt.ok) { try { Seed.updateCity(rslt.dat.result.city); } catch (e) { bf('***********' + e); } } else aZ('Ajax.setDefenseForce ' + translate('was returned with a status of') + ' ' + rslt.ok + ' - ' + rslt.errmsg); if (bO) bO(rslt); return; } }, dr: function(cityId, onOff, bO) { var t = MyAjax; var p = {}; p = t.addMainParams(); p['callback'] = 'function Function() {}'; p['_method'] = 'put'; p['defended'] = onOff ? '0' : '1'; new aB('defended', 'cities/' + cityId + '.json', p, by, true); function by(rslt) { if (rslt.ok) { aZ(translate('switchDefense OK')); Seed.updateCity(rslt.dat.city); } else aZ(translate('switchDefense Error') + ': ' + rslt.errmsg); if (bO) bO(rslt); return; } }, TransportMarch: function(cityId, x, y, units, resources, ownerId, bO) { var t = MyAjax; t.marchBusy = true; var r = {}; var trs = false; var sendResources = "{"; for (var pr in resources) { if (resources[pr] > 0) { r[pr] = resources[pr]; if (trs == true) { sendResources += ','; } sendResources += '"' + pr + '":' + resources[pr]; trs = true; } } sendResources += "}"; var u = {}; var mt = false; var sendTroops = "{"; for (var pu in units) { if (units[pu] > 0) { u[pu] = units[pu]; if (mt == true) { sendTroops += ','; } sendTroops += '"' + pu + '":' + units[pu]; mt = true; } } sendTroops += "}"; var p = {}; p = t.addMainParams(); p['march[type]'] = 'TransportMarch'; p['march[y]'] = y; p['march[resources]'] = sendResources; p['march[units]'] = sendTroops; p['_method'] = 'post'; p['march[x]'] = x; new aB('marches', 'cities/' + cityId + '/marches.json', p, by, true); function by(rslt) { t.marchBusy = false; if (rslt.ok) { try { rslt.dat.result.job.ownerId = ownerId; if (rslt.dat.result.city.marches) { for (var i = 0; i < rslt.dat.result.city.marches.length; i++) { if (rslt.dat.result.city.marches[i].id == rslt.dat.result.job.march_id) rslt.dat.result.city.marches[i].ownerId = ownerId; } } Seed.updateCity(rslt.dat.result.city); Data.marches.ressources[rslt.dat.result.job.march_id] = aA(resources); } catch (e) { bf('***********' + e); } } else aZ('Ajax.marchSend ' + translate('was returned with a status of') + ' ' + rslt.ok + ' - ' + rslt.errmsg); if (bO) bO(rslt); return; } }, troopTraining: function(troopType, troopQty, cityId, bO) { var t = MyAjax; var p = {}; p = t.addMainParams(); p['_method'] = 'post'; p['units[quantity]'] = troopQty; p['units[unit_type]'] = troopType; new aB('training', 'cities/' + cityId + '/units.json', p, by, true); function by(rslt) { if (rslt.ok) { Seed.updateCity(rslt.dat.result.city); Seed.checkAddJob(rslt.dat.result.job); } else aZ('Ajax.troopTraining ' + translate('was returned with a status of') + ' ' + rslt.ok + ' - ' + rslt.errmsg); if (bO) bO(rslt); return; } }, troopReviving: function(troopType, troopQty, cityId, bO) { var t = MyAjax; var p = {}; p = t.addMainParams(); p['units[quantity]'] = troopQty; p['_method'] = 'post'; p['units[unit_type]'] = troopType; new aB('resurrect', 'cities/' + cityId + '/units/resurrect.json', p, by, true); function by(rslt) { if (rslt.ok) Seed.checkAddJob(rslt.dat.result.job); else aZ('Ajax.troopReviving ' + translate('was returned with a status of') + ' ' + rslt.ok + ' - ' + rslt.errmsg); if (bO) bO(rslt); return; } }, useItem: function(cityId, url, jobId, bO) { var t = MyAjax; var p = {}; p = t.addMainParams(); p['job_id'] = jobId; p['_method'] = 'delete'; new aB('items', 'player_items/' + url + '.json', p, by, true); function by(rslt) { if (rslt.ok) { try { if (rslt.dat.result.items) Seed.player.items = aA(rslt.dat.result.items); } catch (e) { rslt.ok = false; rslt.errmsg = e.name + ' - ' + e.message; aZ(translate('March speedup Error') + ': ' + e.name + ' - ' + e.message); } } else aZ(translate('March speedup Error') + ': ' + rslt.errmsg); if (bO) bO(rslt); return; } }, dZ: function(url, bO) { var t = MyAjax; var p = {}; p = t.addMainParams(); p['_method'] = 'delete'; p['quantity'] = 1; new aB('items', 'player_items/' + url + '.json', p, by, true); function by(rslt) { if (rslt.ok) { try { if (rslt.dat.result.items) { var tabIt = []; for(var it in rslt.dat.result.items) { if(rslt.dat.result.items[it] != Seed.player.items[it]) { aZ('Push : ' + translate(it)); tabIt.push(it); } } rslt.diff = tabIt; Seed.player.items = aA(rslt.dat.result.items); } } catch (e) { rslt.ok = false; rslt.errmsg = e.name + ' - ' + e.message; aZ(translate('Single item usage Error') + ': ' + e.name + ' - ' + e.message); } } else aZ(translate('Single item usage Error') + ': ' + rslt.errmsg); if (bO) bO(rslt); return; } }, fe: function(url, nb, bO) { var t = MyAjax; var p = {}; p = t.addMainParams(); p['_method'] = 'delete'; p['quantity'] = nb; new aB('items', 'player_items/' + url + '.json', p, by, true); function by(rslt) { if (rslt.ok) { try { if (rslt.dat.result.items) { var tabIt = []; for(var it in rslt.dat.result.items) { if(rslt.dat.result.items[it] != Seed.player.items[it]) { aZ('Push : ' + translate(it)); tabIt.push(it); } } rslt.diff = tabIt; Seed.player.items = aA(rslt.dat.result.items); } } catch (e) { rslt.ok = false; rslt.errmsg = e.name + ' - ' + e.message; aZ(translate('More item usage Error') + ': ' + e.name + ' - ' + e.message); } } else aZ(translate('More item usage Error') + ': ' + rslt.errmsg); if (bO) bO(rslt); return; } } };
				
var AutoCollect = { init : function (){ var t = AutoCollect; t.aM (Data.options.autoCollect.enabled); }, aM : function (onOff){ var t = AutoCollect; clearTimeout (t.timer); Data.options.autoCollect.enabled = onOff; if (onOff){ var time = (Data.options.autoCollect.delay*Data.options.autoCollect.unit) - be() + Data.options.autoCollect.last_time; if (time <= 0){ t.aJ (); } else { t.timer = setTimeout (t.aJ, time*1000); } } }, aJ : function (){ var t = AutoCollect, offset = 0; Data.options.autoCollect.last_time = be(); if (Seed.player.boosts && Seed.player.boosts.collect_resources) {  aX (translate('Collected resources at outpost')+ ' : '+ translate('pause').initCap() +' ('+ translate('boost-collect-week') +')'); } else { for (var out=2; out<Seed.cities.length; ++out){  if (Seed.cities[out] && Seed.cities[out].id && Buildings.getCount (out, 'Silo') > 0) {  ++offset; aI (out, offset*Math.randRange(5000,10000)); } } } var delay_time = ((Data.options.autoCollect.delay * Data.options.autoCollect.unit) + (Math.random()*120))*1000; t.timer = setTimeout (t.aJ, delay_time); function aI (cityIdx, delay){ setTimeout (function(){ MyAjax.collectResources (Seed.cities[cityIdx].id); aX (translate('Collected resources at outpost')+ ' <B>#'+ cityIdx +'</B>'); }, delay); } } };
var AutoRefresh = { timer : null, current_mouse : [0,0], last_mouse : [0,0], last_time : 0, init : function () { var t = AutoRefresh; t.aM (Data.options.flashRefresh.enabled); }, aM : function (onOff) { var t = AutoRefresh; Data.options.flashRefresh.enabled = onOff; if (Data.options.flashRefresh.enabled){ t.last_time = bV(be()); window.addEventListener('mousemove', t.onMouseMove, false); t.onTimeout(); } else { window.removeEventListener('mousemove', t.onMouseMove, false); } }, onMouseMove : function (event) { AutoRefresh.current_mouse = [event.clientX, event.clientY]; }, onTimeout : function () { var t = AutoRefresh; clearTimeout(t.timer); if (t.current_mouse.join() !== t.last_mouse.join()) { t.last_time = bV(be()); t.last_mouse = [].concat(t.current_mouse); } if (bV(be()) - t.last_time > Data.options.flashRefresh.delay*Data.options.flashRefresh.unit) { t.last_time = bV(be()); aZ ('Flash refresh'); setTimeout(dX,500); setTimeout(dX,5000); } if (Data.options.flashRefresh.enabled) { t.timer = setTimeout(t.onTimeout, 30000); } } }
var Buildings = { getCount : function (cityIdx, type) { var nb = 0; for (var i=0; i < Seed.cities[cityIdx].buildings.length; i++) { if (Seed.cities[cityIdx].buildings[i].type === type) nb++; } return nb; }, getList : function (cityIdx, type) { var ret = []; for (var i=0; i < Seed.cities[cityIdx].buildings.length; i++) { if (Seed.cities[cityIdx].buildings[i].type === type) ret.push (Seed.cities[cityIdx].buildings[i]); } return ret; }, getLevel : function (cityIdx, type){ var build_list = Buildings.getList(cityIdx, type ); if (build_list.length < 1) return {min:0, max:0}; build_list.sort(function(a,b){return a.level - b.level;}); return {min:build_list[0].level, max:build_list[build_list.length-1].level}; }, getById : function (cityIdx, bid){ for (var i=0; i < Seed.cities[cityIdx].buildings.length; i++){ if (Seed.cities[cityIdx].buildings[i].id == bid) return (Seed.cities[cityIdx].buildings[i]); } return null; }, setLevel : function (city_id, bid, level){ var cityIdx = Seed.cityIdx[city_id]; for (var i=0; i < Seed.cities[cityIdx].buildings.length; i++){ if (Seed.cities[cityIdx].buildings[i].id == bid) Seed.cities[cityIdx].buildings[i].level = level; } Tabs.Jobs.buildRefreshLvl = false; return null; } };
var Data = { log: [ [], [] ], defaults: {}, saveTimer: 0, init: function(obj) { try {  Data.defaults.mergeWith(obj || {}); for (var item_name in obj) {  if (typeof(Data[item_name]) == 'undefined') {  Data[item_name] = typeof(obj[item_name]) != 'undefined' ? aA(obj[item_name]) : {}; }  var stored_object = Data.getObject(item_name);  if (stored_object != null && typeof(stored_object) == 'object') { aZ('Clean Removed Vars from : [ ' + name + ' ]'); stored_object.cleanRemoved(Data[item_name], 1); }  if (Data[item_name] !== null && typeof(Data[item_name]) == 'object') {  Data[item_name].mergeWith(stored_object); } else { Data[item_name] = stored_object; } } Data.cleanRequestsStats(); if (!Data.saveTimer) Data.saveTimer = setInterval(Data.save, 600000); } catch (e) { alert('This browser does not support LocalStorage\n\n' + e); return false; } }, clearStorage: function(keep_map) { if (keep_map) { var temp_storage = {}; var keys = cr(Data.defaults); for (var i = 0; i < keys.length; i++) { if (/(map|dynamic)/i.test(keys[i])) { var item_name = keys[i]; temp_storage[item_name] = aA(Data[item_name]); } } } localStorage.clear(); for (var item_name in Data.defaults) { Data[item_name] = aA(Data.defaults[item_name]); } if (keep_map) { var keys = cr(temp_storage); for (var i = 0; i < keys.length; i++) { var item_name = keys[i]; Data[item_name] = aA(temp_storage[item_name]); Data.setObject(item_name, Data[item_name]); } } dk('localStorage Deleted!'); }, getObject: function(key) { var item = localStorage.getItem([SERVER_ID, USER_ID, key].join('_'));  return (item || '').charAt(0) === '{' ? JSON.parse(item || '{}') : eval(item); }, setObject: function(key, value) { if (key == 'log') return; try {  localStorage.setItem([SERVER_ID, USER_ID, key].join('_'), JSON.stringify(value)); } catch (e) { if (e === QUOTA_EXCEEDED_ERR || (e.code === 22 && e.name === 'QUOTA_EXCEEDED_ERR')) { aZ('Error save localstorage , ' + name + '=' + value + ', error=' + bC(e, 8, 1)); bI(translate('LocalStorage') + ' : ' + translate('Quota exceeded') + '! ' + translate('Please, delete the cache and persistent data in your browser')); } } }, onUnload: function() { if (Data.saveTimer) clearInterval(Data.saveTimer); Data.save(); }, save: function() { aZ('Save Data in localStorage'); Data.cleanRequestsStats(); var keys = cr(Data.defaults); for (var i = 0; i < keys.length; i++) { var item_name = keys[i]; Data.setObject(item_name, Data[item_name]); } }, cleanRequestsStats: function() { if (!Data.stats.requests.ajax_type) return; for (var req_type in Data.stats.requests.ajax_type) { for (var i = 0; i < Data.stats.requests.ajax_type[req_type].time.length; i++) if (bV(be()) - Data.stats.requests.ajax_type[req_type].time[i] >= 3600) Data.stats.requests.ajax_type[req_type].time.splice(i, 1); for (var i = 0; i < Data.stats.requests.ajax_type[req_type].error.length; i++) if (bV(be()) - Data.stats.requests.ajax_type[req_type].error[i] >= 3600) Data.stats.requests.ajax_type[req_type].error.splice(i, 1); } }, setDefaultValues: function(tab) { switch (tab) { case 'alliance': gl(); break; case 'attacks': gc(); break; case 'bookmark': hs(); break; case 'jobs': gj(); break; case 'multiple': gw(); break; case 'options': hc(); break; case 'search': gI(); break; case 'spies': hm(); break; case 'waves': he(); break; case 'wheel': gz(); break; case 'all': gl(); gc(); hs(); gj(); gw(); hc(); gI(); hm(); he(); gz(); break; default: break; }

				function gl() {
					if (Seed.cities[CAPITAL.id].figures.marches.maximum && as(Data.options.alliance.auto.max_marches))
						Data.options.alliance.auto.max_marches = bV(Seed.cities[CAPITAL.id].figures.marches.maximum);
				}

				function gc() {
					for (var x = 1; x <= 11; x++) {
						if (!Data.options.attacks.units[x])
							Data.options.attacks.units[x] = {};
						var exists = false;
						for (var j = 0; j < attack_unit_types.length && !exists; j++) {
							if (Data.options.attacks.units[x][attack_unit_types[j]] && Data.options.attacks.units[x][attack_unit_types[j]] > 0)
								exists = true;
						}
						if (!exists) {
							for (var j = 0; j < attack_unit_types.length; j++) {
								var num = 0
								switch (x) {
									case 1:
										switch (attack_unit_types[j]) {
											case 'Longbowman':
												num = 110;
												break;
											case 'ArmoredTransport':
												num = 25;
												break;
											default:
												num = 0;
												break;
										}
										break;
									case 2:
										switch (attack_unit_types[j]) {
											case 'Longbowman':
												num = 550;
												break;
											case 'ArmoredTransport':
												num = 50;
												break;
											default:
												num = 0;
												break;
										}
										break;
									case 3:
										switch (attack_unit_types[j]) {
											case 'Longbowman':
												num = 1050;
												break;
											case 'ArmoredTransport':
												num = 80;
												break;
											default:
												num = 0;
												break;
										}
										break;
									case 4:
										switch (attack_unit_types[j]) {
											case 'Longbowman':
												num = 2100;
												break;
											case 'ArmoredTransport':
												num = 100;
												break;
											default:
												num = 0;
												break;
										}
										break;
									case 5:
										switch (attack_unit_types[j]) {
											case 'Longbowman':
												num = 5500;
												break;
											case 'ArmoredTransport':
												num = 130;
												break;
											default:
												num = 0;
												break;
										}
										break;
									case 6:
										switch (attack_unit_types[j]) {
											case 'Longbowman':
												num = 11000;
												break;
											case 'ArmoredTransport':
												num = 150;
												break;
											default:
												num = 0;
												break;
										}
										break;
									case 7:
										switch (attack_unit_types[j]) {
											case 'Longbowman':
												num = 30000;
												break;
											case 'ArmoredTransport':
												num = 1000;
												break;
											default:
												num = 0;
												break;
										}
										break;
									case 8:
										switch (attack_unit_types[j]) {
											case 'FireTroop':
												num = 2500;
												break;
											case 'ArmoredTransport':
												num = 1000;
												break;
											default:
												num = 0;
												break;
										}
										break;
									case 9:
										switch (attack_unit_types[j]) {
											case 'FireTroop':
												num = 3000;
												break;
											case 'ArmoredTransport':
												num = 1000;
												break;
											default:
												num = 0;
												break;
										}
										break;
									case 10:
										switch (attack_unit_types[j]) {
											case 'FireTroop':
												num = 4000;
												break;
											case 'ArmoredTransport':
												num = 1000;
												break;
											default:
												num = 0;
												break;
										}
										break;
									case 11:
										switch (attack_unit_types[j]) {
											case 'FireTroop':
												num = 50000;
												break;
											case 'ArmoredTransport':
												num = 5000;
												break;
											default:
												num = 0;
												break;
										}
										break;
									default:
										num = 0;
										break;
								}
								if (num > 0) Data.options.attacks.units[x][attack_unit_types[j]] = num;
							}
						}
					}
					for (var x = 1; x <= 11; x++) {
						if (!Data.options.attacks.except_great_dragon[x])
							Data.options.attacks.except_great_dragon[x] = {};
						if (as(Data.options.attacks.except_great_dragon[x])) {
							for (var j = 0; j < Seed.dragonList.length; j++) {
								var dragon = Seed.dragonList[j];
								Data.options.attacks.except_great_dragon[x][dragon.type] = false;
							}
						}
					}
					if (Seed.cities[CAPITAL.id].figures.marches.maximum && as(Data.options.attacks.max_marches)) {
						Data.options.attacks.max_marches = Seed.cities[CAPITAL.id].figures.marches.maximum;
					}
				}

				function hs() {
					if (!Data.options.bookmarks.new_bookmark.dragons)
						Data.options.bookmarks.new_bookmark.dragons = {};
					if (as(Data.options.bookmarks.new_bookmark.dragons)) {
						for (var j = 0; j < Seed.dragonList.length; j++) {
							var dragon = Seed.dragonList[j];
							Data.options.bookmarks.new_bookmark.dragons[dragon.type] = false;
						}
					}
					if (Seed.cities[CAPITAL.id].figures.marches.maximum && as(Data.options.bookmarks.max_marches))
						Data.options.bookmarks.max_marches = bV(Seed.cities[CAPITAL.id].figures.marches.maximum);
				}

				function gj() {  var initDefault_units = all_unit_types; for (var cityIdx = 0; cityIdx < Seed.cities.length; ++cityIdx) { if (cityIdx != SPECTRAL_OUTPOST.id && cityIdx != SKY_OUTPOST.id) { if (!Data.options.training.city[cityIdx]) Data.options.training.city[cityIdx] = {}; if (!Data.options.training.city[cityIdx].units) Data.options.training.city[cityIdx].units = []; var exists = false; for (var tt = 0; tt < initDefault_units.length && !exists; tt++) { if (Data.options.training.city[cityIdx].units[tt] && Data.options.training.city[cityIdx].units[tt] > 0) exists = true; } if (!exists) { for (var tt = 0; tt < initDefault_units.length; tt++) { Data.options.training.city[cityIdx].units[tt] = 0;    } } if (!Data.options.training.city[cityIdx].cap) Data.options.training.city[cityIdx].cap = []; var exists = false; for (var tt = 0; tt < all_unit_types.length && !exists; tt++) { if (Data.options.training.city[cityIdx].cap[tt] && Data.options.training.city[cityIdx].cap[tt] > 0) exists = true; } if (!exists) { for (var tt = 0; tt < all_unit_types.length; tt++) { Data.options.training.city[cityIdx].cap[tt] = 0;     } } } }  for (var cityIdx = 0; cityIdx < Seed.cities.length; ++cityIdx) { if (!Data.options.building.level_enable[cityIdx]) Data.options.building.level_enable[cityIdx] = {}; if (!Data.options.building.level_cap[cityIdx]) Data.options.building.level_cap[cityIdx] = {}; }  for (var cityIdx = 0; cityIdx < Seed.cities.length; ++cityIdx) { if (!Data.options.research.res_enable[cityIdx]) Data.options.research.res_enable[cityIdx] = {}; if (!Data.options.research.res_cap[cityIdx]) Data.options.research.res_cap[cityIdx] = {}; }  for (var cityIdx = 0; cityIdx < Seed.cities.length; ++cityIdx) { if (!Data.options.resurrect.res_enable[cityIdx]) Data.options.resurrect.res_enable[cityIdx] = {}; if (!Data.options.resurrect.res_max[cityIdx]) Data.options.resurrect.res_max[cityIdx] = {}; for (tt = 0; tt < all_unit_types.length; tt++) { if (!Data.options.resurrect.res_max[cityIdx][all_unit_types[tt]]) { Data.options.resurrect.res_max[cityIdx][all_unit_types[tt]] = 0; } } }  if (!Data.options.sanctuary.feeding) Data.options.sanctuary.feeding = {}; for (var i in Seed.sanctuary_dragons) if (!Data.options.sanctuary.feeding[i]) Data.options.sanctuary.feeding[i] = { enable: false, cap: 9 }; } function gw() { if (!Data.options.multiple.target.dragons_1) Data.options.multiple.target.dragons_1 = {}; if (!Data.options.multiple.target.dragons_2) Data.options.multiple.target.dragons_2 = {}; if (as(Data.options.multiple.target.dragons_1)) { for (var j = 0; j < Seed.dragonList.length; j++) { var dragon = Seed.dragonList[j]; Data.options.multiple.target.dragons_1[dragon.type] = false; } } if (as(Data.options.multiple.target.dragons_2)) { for (var j = 0; j < Seed.dragonList.length; j++) { var dragon = Seed.dragonList[j]; Data.options.multiple.target.dragons_2[dragon.type] = false; } } if (Seed.cities[CAPITAL.id].figures.marches.maximum) { if (as(Data.options.multiple.max_marches)) Data.options.multiple.max_marches = bV(Seed.cities[CAPITAL.id].figures.marches.maximum); if (as(Data.options.multiple.max_secondary)) Data.options.multiple.max_secondary = bV(Seed.cities[CAPITAL.id].figures.marches.maximum); } } function hc() { fZ(); } function gI() { if (!Data.options.search.target.x || Data.options.search.target.x == 999) { Data.options.search.target.x = Seed.cities[CAPITAL.id].x; Data.options.search.target.y = Seed.cities[CAPITAL.id].y; } if (as(Data.options.search.target.alliance)) Data.options.search.target.alliance = '*'; if (as(Data.options.search.target.player)) Data.options.search.target.player = '*'; if (as(Data.options.search.target.distance)) Data.options.search.target.distance = 14; if (as(Data.options.search.sort_list)) Data.options.search.sort_list = '0'; if (as(Data.options.search.min_level)) Data.options.search.min_level = 1; if (as(Data.options.search.max_level)) Data.options.search.max_level = 10; } function hm() { if (Seed.cities[CAPITAL.id].figures.marches.maximum && as(Data.options.spies.max_marches)) Data.options.spies.max_marches = bV(Seed.cities[CAPITAL.id].figures.marches.maximum); } function he() { if (!Data.options.waves.target.dragons) Data.options.waves.target.dragons = {}; if (as(Data.options.waves.target.dragons)) { for (var j = 0; j < Seed.dragonList.length; j++) { var dragon = Seed.dragonList[j]; Data.options.waves.target.dragons[dragon.type] = false; } } if (Seed.cities[CAPITAL.id].figures.marches.maximum && as(Data.options.waves.max_marches)) Data.options.waves.max_marches = Seed.cities[CAPITAL.id].figures.marches.maximum; } function gz() {} } };

var Jobs={deleteJob:function(e,t){var n=Seed.cities[e].id;var r=Seed.jobs[n];for(var i in r){if(r[i]==t)delete r[i]}},getBuildingJob:function(e){var t=Seed.cities[e].id;for(var n in Seed.jobs[t]){var r=Seed.jobs[t][n];if(r.queue=="building")return{job:r,building:Buildings.getById(e,r.city_building_id)}}return null},getDefenseTowerHealing:function(e){var t=Seed.cities[e].id;for(var n in Seed.jobs[t]){var r=Seed.jobs[t][n];if(r.queue=="tower_healing")return{job:r,building:Buildings.getById(e,r.city_building_id)}}return null},getDefenseTowerJob:function(e){var t=Seed.cities[e].id;for(var n in Seed.jobs[t]){var r=Seed.jobs[t][n];if(r.queue=="build_tower")return{job:r,building:Buildings.getById(e,r.city_building_id)}}return null},getJobs:function(e,t,n){var r=[],i=n||CAPITAL.id;if(i>=0&&Seed.cities[i]){var s=Seed.cities[i].id;if(s){for(var o in Seed.jobs[s]){var u=Seed.jobs[s][o];if(u.queue==e){r.push(u);if(t)return r}}}}else if(i==-1){for(var a=0;a<Seed.cities.length;a++){if(!Data.options.Rcheat_enabled&&a!=CAPITAL.id&&e=="research")continue;if(Seed.cities[a]&&a!=undefined&&!isNaN(a)&&a>=0&&a<Seed.cities.length&&(a!=SPECTRAL_OUTPOST.id&&a!=SKY_OUTPOST.id&&a!=CAVE_OUTPOST.id&&a!=LUNA_OUTPOST.id&&e=="research"||e!="research")){var s=Seed.cities[a].id;if(s){for(var o in Seed.jobs[s]){var u=Seed.jobs[s][o];if(u.queue==e){r.push(u);if(t)return r}}}}}}return r},addSingleButton:function(e,t,n,r,i){if(!Data.options.jobs_speedups_enabled)return;n.innerHTML="";n.title=translate(time_item_list[e].name)+" x"+i;var s=bV(Seed.player.items[time_item_list[e].name]);var o=document.createElement("input");o.type="button";o.setAttribute("ref",time_item_list[e].name+"_"+r);o.value=time_item_list[e].text;if(s>0){o.disabled=false;o.className=UID["btn_green"]+" thin";o.addEventListener("click",function(e){var t=e.target;t.disabled=true;t.className=UID["btn_disabled"]+" thin";bI(""+t.getAttribute("ref"));var n=t.getAttribute("ref").split("_");var r=false;var i=false;var s=Seed.cities[n[1]].jobs;for(var u=0;u<s.length&&!r;u++)if(s[u].id==n[2])r=true;if(!r)return;for(var a=0;a<time_item_list.length;a++){if(time_item_list[a].name==n[0]){i=time_item_list[a].confirmation;break}}if(i&&Data.options.use_speedup_confirmation){dO(translate("Do you want to use [0] on this job").replace("[0]",translate(n[0]))+" ?",function(){MyAjax.useItem(Seed.cities[n[1]].id,n[0],n[2],function(e){if(e.ok&&e.dat.result.success){if(e.dat.result.item_response){itmResp=e.dat.result.item_response;if(/(units|building|build_tower|research|breeding|hatching|feeding|resurrection)/.test(itmResp.queue)){var t=false;var r=Seed.cities[n[1]].jobs;for(var i=0;i<r.length&&!t;i++){if(r[i].id==itmResp.id){t=true;r[i].run_at=itmResp.run_at;r[i].duration=itmResp.duration}}var s=Seed.jobs[Seed.cities[n[1]].id][n[2]];if(s){s.run_at=itmResp.run_at;s.duration=itmResp.duration}}var u=bV(Seed.player.items[n[0]]);if(u>0){o.disabled=false;o.className=UID["btn_green"]+" thin"}}}})},function(){},true)}else{MyAjax.useItem(Seed.cities[n[1]].id,n[0],n[2],function(e){if(e.ok&&e.dat.result.success){if(e.dat.result.item_response){itmResp=e.dat.result.item_response;if(/(units|building|build_tower|research|breeding|hatching|feeding|resurrection)/.test(itmResp.queue)){var t=false;var r=Seed.cities[n[1]].jobs;for(var i=0;i<r.length&&!t;i++){if(r[i].id==itmResp.id){t=true;r[i].run_at=itmResp.run_at;r[i].duration=itmResp.duration}}var s=Seed.jobs[Seed.cities[n[1]].id][n[2]];if(s){s.run_at=itmResp.run_at;s.duration=itmResp.duration}}var u=bV(Seed.player.items[n[0]]);if(u>0){o.disabled=false;o.className=UID["btn_green"]+" thin"}}}})}},false)}else{o.disabled=true;o.className=UID["btn_disabled"]+" thin"}n.appendChild(o)},addSpeedUpButtons:function(e,t,n,r){var i=0;var s=UID["row_marchMine"];for(var o=0;o<time_item_list.length;o++)i+=bV(Seed.player.items[time_item_list[o].name]);if(i>0){iRow=e.insertRow(-1);iRow.className=s;iCell=iRow.insertCell(-1);iCell.style.textAlign="left";iCell.style.width="100%";iCell.setAttribute("colspan","4");iCell.innerHTML="<table id="+bS(t)+" class="+UID["table"]+"></table>";var u,a;u=document.getElementById(UID[t]).insertRow(-1);u.className=s;for(var o=0;o<time_item_list.length;o++){var f=bV(Seed.player.items[time_item_list[o].name]);if(f>0&&Jobs.checkItemType(o,n)){a=u.insertCell(-1);a.style.textAlign="right";a.innerHTML="&nbsp;";var l="N";if(n=="jobs"&&time_item_list[o].type.indexOf("J")==-1||n=="units"&&time_item_list[o].type.indexOf("T")==-1||n=="resurrection"&&time_item_list[o].type.indexOf("R")==-1)l="C";Jobs.addSingleButton(o,l,a,r,f)}}}},checkItemType:function(e,t){var n=time_item_list[e].type;if(n.indexOf("T")>=0&&t=="units"||n.indexOf("R")>=0&&t=="resurrection"||n.indexOf("J")>=0&&t=="jobs")return true;else return false},updateBuildTable:function(e){var t=bV(be()),n=[];var r=UID["row_marchMine"];for(var i=0;i<e.rows.length;i++){e.deleteRow(i);i--}for(var s=0;s<Seed.cities.length;++s){if(Seed.cities[s]){var o={noPlayer:true,cities:[]};var u=Seed.cities[s];var a=Jobs.getJobs("building",true,s);var f=Jobs.getJobs("build_tower",true,s);if(a.length==0&&f.length==0)n.push(s);else{if(a.length!=0){var l,c;l=e.insertRow(-1);l.className=r;c=l.insertCell(-1);c.style.textAlign="left";c.style.width="20%";c.innerHTML="<b>"+(s==CAPITAL.id?u.name:translate(u.name))+"</b>";var h=a[0].run_at-be()>0?bE(a[0].run_at-be()):0;if(h==0){c=l.insertCell(-1);c.setAttribute("colspan","3");c.innerHTML=translate("Awaiting task completion notification")+"...";Jobs.deleteJob(s,a[0]);if(Tabs.Jobs.buildStatFetch==false){if(s!=0)o.cities.push(Seed.cities[CAPITAL.id].id);o.cities.push(u.id);Seed.fetchPlayer(o);Tabs.Jobs.buildStatFetch=true}}else{l.setAttribute("ref",s+"_"+a[0].id);c=l.insertCell(-1);c.style.textAlign="left";c.style.width="35%";c.innerHTML="<b>"+translate("Building")+":</b> &nbsp;&nbsp;"+translate(a[0].city_building_type)+"  ("+a[0].level+")";c=l.insertCell(-1);c.style.width="10%";var p=document.createElement("input");p.type="button";p.setAttribute("ref",s+"_"+a[0].id);p.value="X";if(a[0].cancelled){p.disabled=true;p.className=UID["btn_disabled"]+" thin"}else{p.className=UID["btn_red"]+" thin";p.addEventListener("click",function(e){var t=e.target;t.disabled=true;t.className=UID["btn_disabled"]+" thin";var n=t.getAttribute("ref").split("_");var r=Seed.jobs[Seed.cities[n[0]].id][n[1]];if(r){r.cancelled=true;var i=translate(r.city_building_type)+" "+r.level;MyAjax.cancelTraining(n[1],function(e){if(e.ok&&e.dat.result.success){aZ(translate("Building job cancelled")+" ("+i+")")}})}},false)}c.appendChild(p);c=l.insertCell(-1);c.style.textAlign="left";c.style.width="25%";c.innerHTML="<font color="+TIMER_COLOR+">"+h+"</font>";if(!a[0].cancelled&&Data.options.jobs_speedups_enabled)Jobs.addSpeedUpButtons(e,"tabJobsBuild_speedups_0","jobs",s+"_"+a[0].id);Tabs.Jobs.buildStatFetch=false;try{document.getElementById(UID["tabJobBuild_FB_"+s+"_"+a[0].city_building_type]).innerHTML="<font color=#000>"+translate("Building")+": "+translate(a[0].city_building_type)+" "+translate("Level").toLowerCase()+" "+a[0].level+"</font>"}catch(d){}}l=e.insertRow(-1);c=l.insertCell(-1);c.style.textAlign="left";c.style.width="20%";c.innerHTML="&nbsp;"}if(f.length!=0){var l,c;l=e.insertRow(-1);l.className=r;c=l.insertCell(-1);c.style.textAlign="left";c.style.width="20%";c.innerHTML="<b>"+(s==CAPITAL.id?u.name:translate(u.name))+"</b>";var h=f[0].run_at-be()>0?bE(f[0].run_at-be()):0;if(h==0){c=l.insertCell(-1);c.setAttribute("colspan","3");c.innerHTML=translate("Awaiting task completion notification")+"...";Jobs.deleteJob(s,f[0]);if(Tabs.Jobs.buildStatFetch==false){if(s!=0)o.cities.push(Seed.cities[CAPITAL.id].id);o.cities.push(u.id);Seed.fetchPlayer(o);Tabs.Jobs.buildStatFetch=true}}else{l.setAttribute("ref",s+"_"+f[0].id);c=l.insertCell(-1);c.style.textAlign="left";c.style.width="35%";c.innerHTML="<b>"+translate("Building")+":</b> &nbsp;&nbsp;"+translate(f[0].city_building_type)+"  ("+f[0].level+")";c=l.insertCell(-1);c.style.width="10%";var p=document.createElement("input");p.type="button";p.setAttribute("ref",s+"_"+f[0].id);p.value="X";if(f[0].cancelled){p.disabled=true;p.className=UID["btn_disabled"]+" thin"}else{p.className=UID["btn_red"]+" thin";p.addEventListener("click",function(e){var t=e.target;t.disabled=true;t.className=UID["btn_disabled"]+" thin";var n=t.getAttribute("ref").split("_");var r=Seed.jobs[Seed.cities[n[0]].id][n[1]];if(r){r.cancelled=true;var i=translate(r.city_building_type)+" "+r.level;MyAjax.cancelTraining(n[1],function(e){if(e.ok&&e.dat.result.success){aZ(translate("Building job cancelled")+" ("+i+")")}})}},false)}c.appendChild(p);c=l.insertCell(-1);c.style.textAlign="left";c.style.width="25%";c.innerHTML="<font color="+TIMER_COLOR+">"+h+"</font>";if(!f[0].cancelled&&Data.options.jobs_speedups_enabled)Jobs.addSpeedUpButtons(e,"tabJobsBuild_speedups_0","jobs",s+"_"+f[0].id);Tabs.Jobs.buildStatFetch=false;try{document.getElementById(UID["tabJobBuild_FB_"+s+"_"+f[0].city_building_type]).innerHTML="<font color=#000>"+translate("Building")+": "+translate(f[0].city_building_type)+" "+translate("Level").toLowerCase()+" "+f[0].level+"</font>"}catch(d){}}l=e.insertRow(-1);c=l.insertCell(-1);c.style.textAlign="left";c.style.width="20%";c.innerHTML="&nbsp;"}}}}for(var s=0;s<n.length;++s){if(Seed.cities[n[s]]){var u=Seed.cities[n[s]];var l,c;l=e.insertRow(-1);l.className=r;c=l.insertCell(-1);c.style.textAlign="left";c.style.width="20%";c.innerHTML="<b>"+(s==CAPITAL.id?u.name:translate(u.name))+"</b>";c=l.insertCell(-1);c.innerHTML=translate("Idle")}}},updateResearchTable:function(e){var t=bV(be());var n=UID["row_marchMine"];for(var r=0;r<e.rows.length;r++){e.deleteRow(r);r--}for(var i=0;i<Seed.cities.length;++i){if(!Data.options.Rcheat_enabled&&i!=CAPITAL.id)continue;if(Seed.cities[i]&&i>=0&&i<Seed.cities.length&&i!=SPECTRAL_OUTPOST.id&&i!=SKY_OUTPOST.id&&i!=CAVE_OUTPOST.id&&i!=LUNA_OUTPOST.id&&Seed.cities[i].figures.queue_lengths&&Seed.cities[i].figures.queue_lengths["research"]){var s=Seed.cities[i];var o=Jobs.getJobs("research",true,i);var u,a;u=e.insertRow(-1);u.className=n;a=u.insertCell(-1);a.style.textAlign="left";a.style.width="20%";a.innerHTML="<b>"+(i==CAPITAL.id?s.name:translate(s.name))+"</b>";if(o.length==0){a=u.insertCell(-1);a.innerHTML=translate("Idle")}else{var f=o[0].run_at-be()>0?bE(o[0].run_at-be()):0;if(f==0){a=u.insertCell(-1);a.setAttribute("colspan","3");a.innerHTML=translate("Awaiting task completion notification")+"...";Jobs.deleteJob(i,o[0]);if(Tabs.Jobs.resStatFetch==false){if(i!=0)options.cities.push(Seed.cities[CAPITAL.id].id);options.cities.push(s.id);Seed.fetchPlayer(options);Tabs.Jobs.resStatFetch=true}}else{u.setAttribute("ref",i+"_"+o[0].id);a=u.insertCell(-1);a.style.textAlign="left";a.style.width="35%";a.innerHTML="<b>"+translate("Researching")+":</b> &nbsp;&nbsp;"+translate(Tabs.Jobs.resUITranslate(o[0].research_type))+"  ("+o[0].level+")";a=u.insertCell(-1);a.style.width="10%";var l=document.createElement("input");l.type="button";l.setAttribute("ref",i+"_"+o[0].id);l.value="X";if(o[0].cancelled){l.disabled=true;l.className=UID["btn_disabled"]+" thin"}else{l.className=UID["btn_red"]+" thin";l.addEventListener("click",function(e){var t=e.target;t.disabled=true;t.className=UID["btn_disabled"]+" thin";var n=t.getAttribute("ref").split("_");var r=Seed.jobs[Seed.cities[n[0]].id][n[1]];if(r){r.cancelled=true;var i=translate(Tabs.Jobs.resUITranslate(r.research_type))+" "+r.level;MyAjax.cancelTraining(n[1],function(e){if(e.ok&&e.dat.result.success){aZ(translate("Research job cancelled")+" ("+i+")")}})}},false)}a.appendChild(l);a=u.insertCell(-1);a.style.textAlign="left";a.style.width="25%";a.innerHTML="<font color="+TIMER_COLOR+">"+f+"</font>";if(!o[0].cancelled&&Data.options.jobs_speedups_enabled)Jobs.addSpeedUpButtons(e,"tabJobsResearch_speedups_0","jobs",i+"_"+o[0].id);Tabs.Jobs.resStatFetch=false;try{document.getElementById(UID["tabJobResearch_FB_"+o[0].research_type]).innerHTML="<font color=#000>"+translate("Researching")+": "+translate(Tabs.Jobs.resUITranslate(job[0].research_type))+" "+translate("Level").toLowerCase()+" "+o[0].level+"</font>"}catch(c){}}u=e.insertRow(-1);a=u.insertCell(-1);a.style.textAlign="left";a.style.width="20%";a.innerHTML="&nbsp;"}}}},updateSanctuaryTable:function(e){function r(t){var r=be();var i=[];var s=[];if(t=="breeding"){for(var o=0;o<Seed.cities.length;++o){var u=Seed.cities[o]?Seed.cities[o].jobs:[];for(var a=0;a<u.length;a++){if(u[a].queue=="breeding"&&u[a].male_id&&u[a].female_id&&u[a].run_at>r){i.push(u[a]);s.push(o)}}}}else{var o=CAPITAL.id;var u=Seed.cities[o].jobs;for(var a=0;a<u.length;a++){if(t=="hatching"&&u[a].queue=="hatching"&&u[a].egg_id&&u[a].run_at>r)i.push(u[a]);if(t=="feeding"&&u[a].queue=="feeding"&&u[a].dragon_id&&u[a].run_at>r)i.push(u[a])}}var f,l;f=e.insertRow(-1);f.className=n;l=f.insertCell(-1);l.style.textAlign="left";l.style.width="20%";if(t=="breeding")l.innerHTML="<b>"+translate("breeding-dragon")+"</b>";else if(t=="hatching")l.innerHTML="<b>"+translate("hatching-egg")+"</b>";else if(t=="feeding")l.innerHTML="<b>"+translate("upgrading-dragon")+"</b>";else l.innerHTML="<b>"+translate("Unknown")+"</b>";if(i.length==0){l=f.insertCell(-1);l.innerHTML=translate("Idle")}else{i.sort(function(e,t){return e.run_at-t.run_at});var c=0;for(var a=0;a<i.length;a++){var h;if(t=="hatching"){c+=i[a].run_at-r>0?i[a].run_at-r:0}else{h=a==0?i[a].run_at-r>0?i[a].run_at-r:0:i[a].duration}var p="";if(a!=0){f=e.insertRow(-1);f.className=n;l=f.insertCell(-1);l.style.textAlign="left";l.style.width="20%";l.innerHTML="&nbsp;"}f.setAttribute("ref",o+"_"+i[a].id);l=f.insertCell(-1);l.style.textAlign="left";l.style.width="35%";if(t=="breeding"){var d="",v="";if(!Seed.sanctuary_dragons[i[a].male_id]){aZ("Error: Inexisting dragon "+i[a].male_id);d=i[a].male_id}else{d=bo(Seed.sanctuary_dragons[i[a].male_id].subtype,"rank-"+Seed.sanctuary_dragons[i[a].male_id].type,"dragons")}if(!Seed.sanctuary_dragons[i[a].female_id]){aZ("Error: Inexisting dragon "+i[a].female_id);v=i[a].female_id}else{v=bo(Seed.sanctuary_dragons[i[a].female_id].subtype,"rank-"+Seed.sanctuary_dragons[i[a].female_id].type,"dragons")}l.innerHTML=d+" + "+v}else if(t=="hatching"){var m="";if(!Seed.sanctuary_dragons[i[a].egg_id]){aZ("Error: Inexisting dragon "+i[a].egg_id);m=i[a].egg_id}else{m=bo(Seed.sanctuary_dragons[i[a].egg_id].subtype,"rank-"+Seed.sanctuary_dragons[i[a].egg_id].type,"dragons")}l.innerHTML=m}else if(t=="feeding"){var g="";if(!Seed.sanctuary_dragons[i[a].dragon_id]){aZ("Error: Inexisting dragon "+i[a].dragon_id);g=i[a].dragon_id}else{g=bo(Seed.sanctuary_dragons[i[a].dragon_id].subtype,"rank-"+Seed.sanctuary_dragons[i[a].dragon_id].type,"dragons")+"&nbsp;("+(Seed.sanctuary_dragons[i[a].dragon_id].level+1)+")"}l.innerHTML=g}l=f.insertCell(-1);l.style.width="10%";var y=document.createElement("input");y.type="button";if(t=="breeding")y.setAttribute("ref",s[a]+"_"+i[a].id);else y.setAttribute("ref",o+"_"+i[a].id);y.value="X";if(i[a].cancelled){y.disabled=true;y.className=UID["btn_disabled"]+" thin"}else{y.className=UID["btn_red"]+" thin";y.addEventListener("click",function(e){var t=e.target;t.disabled=true;t.className=UID["btn_disabled"]+" thin";var n=t.getAttribute("ref").split("_");var r=false;var i=Seed.cities[n[0]].jobs;for(var s=0;s<i.length&&!r;s++){if(i[s].id==n[1]){r=true;i[s].cancelled=true;var o=translate("breeding-cancel-complete");MyAjax.cancelTraining(n[1],function(e){if(e.ok&&e.dat.result.success){aZ(o);Seed.fetchPlayer({noPlayer:true,cities:[],jobs:true,dragons:true})}})}}},false)}l.appendChild(y);l=f.insertCell(-1);l.style.textAlign="left";l.style.width="35%";l.innerHTML="<font color="+TIMER_COLOR+">"+bE(t=="hatching"?c:h,true)+"</font>";r=i[a].run_at;if(a==0&&!i[a].cancelled&&Data.options.jobs_speedups_enabled){if(t=="breeding")Jobs.addSpeedUpButtons(e,"tabJobsSanct_speedups_"+a,"jobs",s[a]+"_"+i[a].id);else Jobs.addSpeedUpButtons(e,"tabJobsSanct_speedups_"+a,"jobs",o+"_"+i[a].id)}}}f=e.insertRow(-1);l=f.insertCell(-1);l.style.textAlign="left";l.style.width="20%";l.innerHTML="&nbsp;"}var t=bV(be());var n=UID["row_marchMine"];for(var i=0;i<e.rows.length;i++){e.deleteRow(i);i--}r("breeding");r("hatching");r("feeding")},updateTrainTable:function(e,t,n){var r=bV(be());var i=UID["row_marchMine"];for(var s=0;s<e.rows.length;s++){e.deleteRow(s);s--}for(var o=0;o<Seed.cities.length;++o){if(Seed.cities[o]&&Seed.cities[o].jobs&&o!=SKY_OUTPOST.id&&(o!=SPECTRAL_OUTPOST.id&&!n||o==SPECTRAL_OUTPOST.id&&n)){var u=Seed.cities[o].jobs;var a=be();var f=[];for(var l=0;l<u.length;l++){if(t=="units"&&u[l].queue=="units"&&u[l].unit_type&&u[l].run_at>a&&!n)f.push(u[l]);if(t=="resurrection"&&u[l].queue=="resurrection"&&u[l].unit_type&&u[l].run_at>a&&n)f.push(u[l])}var c,h;c=e.insertRow(-1);c.className=i;h=c.insertCell(-1);h.style.textAlign="left";h.style.width="20%";h.innerHTML="<b>"+(o==CAPITAL.id?Seed.cities[o].name:translate(Seed.cities[o].name))+"</b>";if(f.length==0){h=c.insertCell(-1);h.innerHTML=translate("Idle")}else{f.sort(function(e,t){return e.run_at-t.run_at});var p=0;for(var l=0;l<f.length;l++){var d=l==0?f[l].run_at-a>0?f[l].run_at-a:0:f[l].duration;p=p+d;var v="";if(l!=0){c=e.insertRow(-1);c.className=i;h=c.insertCell(-1);h.style.textAlign="left";h.style.width="20%";h.innerHTML="&nbsp;";if(l==f.length-1)v=" &nbsp <B>("+bz(f[l].run_at-be()>0?f[l].run_at-be():0)+")</b>"}c.setAttribute("ref",o+"_"+f[l].id);h=c.insertCell(-1);h.style.textAlign="left";h.style.width="35%";h.innerHTML=bD(f[l].quantity," ")+" "+translate(f[l].unit_type);h=c.insertCell(-1);h.style.width="10%";var m=document.createElement("input");m.type="button";m.setAttribute("ref",o+"_"+f[l].id);m.value="X";if(f[l].cancelled){m.disabled=true;m.className=UID["btn_disabled"]+" thin"}else{m.className=UID["btn_red"]+" thin";m.addEventListener("click",function(e){if(Data.options.jobs_cancel_confirmation){var t=n?translate("Do you want to cancel this resurrection"):translate("Do you want to cancel this training");dO(t+" ?",function(){var t=e.target;t.disabled=true;t.className=UID["btn_disabled"]+" thin";var n=t.getAttribute("ref").split("_");var r=false;var i=Seed.cities[n[0]].jobs;for(var s=0;s<i.length&&!r;s++){if(i[s].id==n[1]){r=true;i[s].cancelled=true;var o=bD(i[s].quantity," ")+" "+translate(i[s].unit_type);MyAjax.cancelTraining(n[1],function(e){if(e.ok&&e.dat.result.success){aZ(translate("Training job cancelled")+" ("+o+")")}})}}},function(){},true)}else{var r=e.target;r.disabled=true;r.className=UID["btn_disabled"]+" thin";var i=r.getAttribute("ref").split("_");var s=false;var o=Seed.cities[i[0]].jobs;for(var u=0;u<o.length&&!s;u++){if(o[u].id==i[1]){s=true;o[u].cancelled=true;var a=bD(o[u].quantity," ")+" "+translate(o[u].unit_type);MyAjax.cancelTraining(i[1],function(e){if(e.ok&&e.dat.result.success){aZ(translate("Training job cancelled")+" ("+a+")")}})}}}},false)}h.appendChild(m);h=c.insertCell(-1);h.style.textAlign="left";h.style.width="35%";h.innerHTML="<font color="+TIMER_COLOR+">"+bE(d,true)+"</font>"+v;a=f[l].run_at;if(l==0&&!f[l].cancelled&&Data.options.jobs_speedups_enabled)Jobs.addSpeedUpButtons(e,"tabJobsTrain_speedups_"+l,t,o+"_"+f[l].id)}}}}}};var Manifest={data:{},init:function(e){Manifest.fetchManifest(function(t){if(t.ok)aZ(translate("Manifest was Successfully requested from the server"));else aZ("fetchManifest "+translate("was returned with a status of")+" "+t.ok+" - "+t.errmsg);if(e)e(t)})},fetchManifest:function(e){var t=(new Date).getTime()/1e3;var n={};n=MyAjax.addMainParams();new aB("manifest","manifest.json",n,function(t){if(t.ok){Manifest.data=t.dat;try{Manifest.updateManifest()}catch(n){t.ok=false;t.errmsg="fetchManifest when calling updateManifest returned this error: "+n.toString()}}if(e)e(t)},false)},buildings:{byCityType:function(e,t,n){var r=Manifest.data.buildings;var i,s,o=[];if(!t)t="all";if(!e)e="all";if(r.length>0){for(i=0;i<r.length;i=i+1){if(r[i].buildable===t||t.toLowerCase()==="all"){if(r[i].city_type.length>0){for(s=0;s<r[i].city_type.length;s=s+1){if(r[i].city_type[s]===e.toLowerCase()||e.toLowerCase()==="all"){o[o.length]=r[i];break}}}}}}if(n)o=Manifest.buildings.ct(o,n);return o},byLocation:function(e,t,n){var r=Manifest.data.buildings;var i,s=[];if(!t)t="all";if(!e)cityType="all";if(r.length>0){for(i=0;i<r.length;i=i+1){if(r[i].buildable===t||t.toLowerCase()==="all"){if(r[i].location===e.toLowerCase()||e.toLowerCase()==="all"){s[s.length]=r[i]}}}}if(n)s=Manifest.buildings.ct(s,n);return s},ct:function(e,t){function r(t){if(t.toLowerCase()==="asc"){e.sort(function(e,t){var n=e.type.toLowerCase(),r=t.type.toLowerCase();if(n<r){return-1}if(n>r){return 1}return 0})}else if(t.toLowerCase()==="desc"){e.sort(function(e,t){var n=e.type.toLowerCase(),r=t.type.toLowerCase();if(n>r){return-1}if(n<r){return 1}return 0})}}function i(t){if(t===true){e.sort(function(e,t){var n=e.buildable,r=t.buildable;if(n<r){return-1}if(n>r){return 1}return 0})}else if(t===false){e.sort(function(e,t){var n=e.buildable,r=t.buildable;if(n>r){return-1}if(n<r){return 1}return 0})}}function s(t){if(t.toLowerCase()==="city"){e.sort(function(e,t){var n=e.location.toLowerCase(),r=t.location.toLowerCase();if(n<r){return-1}if(n>r){return 1}return 0})}else if(t.toLowerCase()==="field"){e.sort(function(e,t){var n=e.location.toLowerCase(),r=t.location.toLowerCase();if(n>r){return-1}if(n<r){return 1}return 0})}}var n;if(!t)t={alphabetical:"asc"};for(n in t){switch(n){case"alphabetical":r(t[n]);break;case"buildable":i(t[n]);break;case"location":s(t[n]);break}}return e}},building:function(e){bf("Manifest.building");var t;if(e){for(t=0;t<Manifest.data.buildings.length;t=t+1){}}else{}},updateManifest:function(){var e,t,n;e=Manifest.data.buildings;for(t=0;t<e.length;t++){if(!Seed.requirements.building[e[t].type])Seed.requirements.building[e[t].type]={};if(!Seed.requirements.building[e[t].type].level)Seed.requirements.building[e[t].type].level=[];if(!Seed.stats.building[e[t].type])Seed.stats.building[e[t].type]={};if(!Seed.stats.building[e[t].type].level)Seed.stats.building[e[t].type].level=[];for(n=0;n<e[t].levels.length;n++){Seed.requirements.building[e[t].type].level[e[t].levels[n].level]=e[t].levels[n].requirements;Seed.stats.building[e[t].type].level[e[t].levels[n].level]={};Seed.stats.building[e[t].type].level[e[t].levels[n].level].time=e[t].levels[n].time}if(!as(e[t].capacity)){for(var r in e[t].capacity){if(r!="lignore me!"){var i=r.substring(1);Seed.stats.building[e[t].type].level[i].capacity=e[t].capacity[r]}}}}e=Manifest.data.research;Seed.research=[];for(t=0;t<e.length;t++){Seed.research[t]=e[t].type;if(!Seed.requirements.research[e[t].type])Seed.requirements.research[e[t].type]={};if(!Seed.requirements.research[e[t].type].level)Seed.requirements.research[e[t].type].level=[];if(!Seed.stats.research[e[t].type])Seed.stats.research[e[t].type]={};if(!Seed.stats.research[e[t].type].level)Seed.stats.research[e[t].type].level=[];for(n=0;n<e[t].levels.length;n++){Seed.requirements.research[e[t].type].level[e[t].levels[n].level]=e[t].levels[n].requirements;Seed.stats.research[e[t].type].level[e[t].levels[n].level]={time:e[t].levels[n].time}}}e=Manifest.data.city.capital.units;for(t=0;t<e.length;t++){if(!Seed.requirements.unit[e[t].type])Seed.requirements.unit[e[t].type]=[];Seed.requirements.unit[e[t].type]=e[t].requirements;if(!Seed.stats.unit[e[t].type])Seed.stats.unit[e[t].type]={};Seed.stats.unit[e[t].type]=e[t].stats;Seed.stats.unit[e[t].type].time=e[t].time;Seed.stats.unit[e[t].type].upkeep=e[t].upkeep;Seed.stats.unit[e[t].type].trainable=[]}e=Manifest.data.city;for(var s in e){units=e[s].units;for(t=0;t<units.length;t++){if(units[t].trainable)Seed.stats.unit[units[t].type].trainable.push(s)}}e=Manifest.data.city.spectral.units;for(t=0;t<e.length;t++){if(!Seed.requirements.resurrect[e[t].type])Seed.requirements.resurrect[e[t].type]=[];Seed.requirements.resurrect[e[t].type]=e[t].requirements;if(!Seed.stats.resurrect[e[t].type])Seed.stats.resurrect[e[t].type]={};Seed.stats.resurrect[e[t].type]=e[t].stats;Seed.stats.resurrect[e[t].type].time=e[t].time;Seed.stats.resurrect[e[t].type].upkeep=e[t].upkeep}e=Manifest.data.dragon_levels;for(t=0;t<e.length;t++){if(!Seed.requirements.dragon.feeding)Seed.requirements.dragon.feeding={};if(!Seed.requirements.dragon.feeding.level)Seed.requirements.dragon.feeding.level=[];if(!Seed.requirements.dragon.feeding.level[e[t].level])Seed.requirements.dragon.feeding.level[e[t].level]=e[t].requirements;if(!Seed.stats.dragon.feeding)Seed.stats.dragon.feeding={};if(!Seed.stats.dragon.feeding.level)Seed.stats.dragon.feeding.level=[];if(!Seed.stats.dragon.feeding.level[e[t].level])Seed.stats.dragon.feeding.level[e[t].level]={time:e[t].time}}e=Manifest.data.quests;for(t=0;t<e.length;t++){if(!Seed.quests.category[t])Seed.quests.category[t]=[];Seed.quests.category[t]=e[t][0];for(n=0;n<e[t][1].length;n++){if(!Seed.quests.list[e[t][0]])Seed.quests.list[e[t][0]]=[];var o={name:e[t][1][n].name,recommended:e[t][1][n].recommended,reward:e[t][1][n].reward};Seed.quests.list[e[t][0]].push(o)}}e=Manifest.data.store;for(var t in e){if(!Seed.items[t])Seed.items[t]=[];for(n=0;n<e[t].length;n++){Seed.items[t].push({type:e[t][n].type,price:e[t][n].price?e[t][n].price:0,usable:e[t][n].usable})}}e=Manifest.data.armors;for(var t in e){Seed.armors.push(e[t].head[0]);Seed.armors.push(e[t].body[0]);Seed.armors.push(e[t].claws[0]);Seed.armors.push(e[t].tail[0])}Seed.armors.push("SpectralDragonHead");Seed.armors.push("SpectralDragonTalons");Seed.armors.push("SpectralDragonTail");Seed.armors.push("SpectralDragonBody");Seed.armors.push("KaiserDragonTailGuard");Seed.armors.push("KaiserDragonClawGuards");Seed.armors.push("KaiserDragonHelmet");Seed.armors.push("KaiserDragonBodyArmor");var u=Manifest.data.great_dragon_levels;var a=Manifest.data.water_dragon_levels;var f=Manifest.data.stone_dragon_levels;var l=Manifest.data.fire_dragon_levels;var c=Manifest.data.wind_dragon_levels;var h=Manifest.data.ice_dragon_levels;var p=Manifest.data.swamp_dragon_levels;var d=Manifest.data.forest_dragon_levels;var v=Manifest.data.desert_dragon_levels;var m=Manifest.data.chrono_dragon_levels;var g=Manifest.data.kaiser_dragon_levels;var y=Manifest.data.spectral_dragon_levels;var b=Manifest.data.luna_dragon_levels;var w=Manifest.data.cave_dragon_levels;for(var E=1;E<20;E++){if(u[E]){if(!Seed.greatDragons.GreatDragon[E])Seed.greatDragons.GreatDragon[E]=[];Seed.greatDragons.GreatDragon[E]=u[E]}if(a[E]){if(!Seed.greatDragons.WaterDragon[E])Seed.greatDragons.WaterDragon[E]=[];Seed.greatDragons.WaterDragon[E]=a[E]}if(f[E]){if(!Seed.greatDragons.StoneDragon[E])Seed.greatDragons.StoneDragon[E]=[];Seed.greatDragons.StoneDragon[E]=f[E]}if(l[E]){if(!Seed.greatDragons.FireDragon[E])Seed.greatDragons.FireDragon[E]=[];Seed.greatDragons.FireDragon[E]=l[E]}if(c[E]){if(!Seed.greatDragons.WindDragon[E])Seed.greatDragons.WindDragon[E]=[];Seed.greatDragons.WindDragon[E]=c[E]}if(h[E]){if(!Seed.greatDragons.IceDragon[E])Seed.greatDragons.IceDragon[E]=[];Seed.greatDragons.IceDragon[E]=h[E]}if(p[E]){if(!Seed.greatDragons.SwampDragon[E])Seed.greatDragons.SwampDragon[E]=[];Seed.greatDragons.SwampDragon[E]=p[E]}if(d[E]){if(!Seed.greatDragons.ForestDragon[E])Seed.greatDragons.ForestDragon[E]=[];Seed.greatDragons.ForestDragon[E]=d[E]}if(v[E]){if(!Seed.greatDragons.DesertDragon[E])Seed.greatDragons.DesertDragon[E]=[];Seed.greatDragons.DesertDragon[E]=v[E]}if(m[E]){if(!Seed.greatDragons.ChronoDragon[E])Seed.greatDragons.ChronoDragon[E]=[];Seed.greatDragons.ChronoDragon[E]=m[E]}if(g[E]){if(!Seed.greatDragons.KaiserDragon[E])Seed.greatDragons.KaiserDragon[E]=[];Seed.greatDragons.KaiserDragon[E]=g[E]}if(y[E]){if(!Seed.greatDragons.SpectralDragon[E])Seed.greatDragons.SpectralDragon[E]=[];Seed.greatDragons.SpectralDragon[E]=y[E]}if(w[E]){if(!Seed.greatDragons.CaveDragon[E])Seed.greatDragons.CaveDragon[E]=[];Seed.greatDragons.CaveDragon[E]=w[E]}if(b[E]){if(!Seed.greatDragons.LunaDragon[E])Seed.greatDragons.LunaDragon[E]=[];Seed.greatDragons.LunaDragon[E]=b[E]}}}};var Map={map_bin:null,is_refreshing:false,x:0,y:0,names:{type:{0:"bog",1:"plain",2:"mountain",3:"forest",4:"hill",5:"grassland",6:"lake",7:"City",8:"AnthropusCamp",9:"Clouds",10:"Spectral",11:"Water",12:"Stone",13:"Fire",14:"Wind",15:"Ice",16:"Swamp",17:"Forest",18:"Desert",19:"Chrono",20:"Sky",21:"Cave",22:"Luna",bog:0,plain:1,mountain:2,forest:3,hill:4,grassland:5,lake:6,City:7,AnthropusCamp:8,Clouds:9,Spectral:10,Water:11,Stone:12,Fire:13,Wind:14,Ice:15,Swamp:16,Forest:17,Desert:18,Chrono:19,Sky:20,Cave:21,Luna:22}},targets:{AnthropusCamp:[],forest:[],grassland:[],hill:[],lake:[],mountain:[],plain:[],City:[],Outpost:[]},to_refresh:{forest:[],grassland:[],hill:[],lake:[],mountain:[],plain:[],City:[]},to_avoid:["45,651","45,652","45,653","45,654","45,655","46,651","46,652","46,653","46,654","46,655","47,651","47,652","47,653","47,654","47,655","48,651","48,652","48,653","48,654","48,655","49,651","49,652","49,653","49,654","49,655","134,189","134,190","134,191","134,192","134,193","135,189","135,190","135,191","135,192","135,193","136,189","136,190","136,191","136,192","136,193","137,189","137,190","137,191","137,192","137,193","138,189","138,190","138,191","138,192","138,193","141,235","141,236","141,237","141,238","141,239","142,235","142,236","142,237","142,238","142,239","143,235","143,236","143,237","143,238","143,239","144,235","144,236","144,237","144,238","144,239","145,235","145,236","145,237","145,238","145,239","158,632","158,633","158,634","158,635","158,636","159,632","159,633","159,634","159,635","159,636","160,632","160,633","160,634","160,635","160,636","161,632","161,633","161,634","161,635","161,636","162,632","162,633","162,634","162,635","162,636","196,183","196,184","196,185","196,186","196,187","197,183","197,184","197,185","197,186","197,187","198,183","198,184","198,185","198,186","198,187","199,183","199,184","199,185","199,186","199,187","200,183","200,184","200,185","200,186","200,187","206,240","206,241","206,242","206,243","206,244","207,240","207,241","207,242","207,243","207,244","208,240","208,241","208,242","208,243","208,244","209,240","209,241","209,242","209,243","209,244","210,240","210,241","210,242","210,243","210,244","319,341","319,342","319,343","319,344","319,345","320,341","320,342","320,343","320,344","320,345","321,341","321,342","321,343","321,344","321,345","322,341","322,342","322,343","322,344","322,345","323,341","323,342","323,343","323,344","323,345","343,676","343,677","343,678","343,679","343,680","344,676","344,677","344,678","344,679","344,680","345,676","345,677","345,678","345,679","345,680","346,676","346,677","346,678","346,679","346,680","347,676","347,677","347,678","347,679","347,680","423,510","423,511","423,512","423,513","423,514","424,510","424,511","424,512","424,513","424,514","425,510","425,511","425,512","425,513","425,514","426,510","426,511","426,512","426,513","426,514","427,510","427,511","427,512","427,513","427,514","451,46","451,47","451,48","451,49","451,50","452,46","452,47","452,48","452,49","452,50","453,46","453,47","453,48","453,49","453,50","454,46","454,47","454,48","454,49","454,50","455,46","455,47","455,48","455,49","455,50","459,284","459,285","459,286","459,287","459,288","460,284","460,285","460,286","460,287","460,288","461,284","461,285","461,286","461,287","461,288","462,284","462,285","462,286","462,287","462,288","463,284","463,285","463,286","463,287","463,288","636,669","636,670","636,671","636,672","636,673","637,669","637,670","637,671","637,672","637,673","638,669","638,670","638,671","638,672","638,673","639,669","639,670","639,671","639,672","639,673","640,669","640,670","640,671","640,672","640,673","660,445","660,446","660,447","660,448","660,449","661,445","661,446","661,447","661,448","661,449","662,445","662,446","662,447","662,448","662,449","663,445","663,446","663,447","663,448","663,449","664,445","664,446","664,447","664,448","664,449","684,483","684,484","684,485","684,486","684,487","685,483","685,484","685,485","685,486","685,487","686,483","686,484","686,485","686,486","686,487","687,483","687,484","687,485","687,486","687,487","688,483","688,484","688,485","688,486","688,487","701,384","701,385","701,386","701,387","701,388","702,384","702,385","702,386","702,387","702,388","703,384","703,385","703,386","703,387","703,388","704,384","704,385","704,386","704,387","704,388","705,384","705,385","705,386","705,387","705,388","712,87","712,88","712,89","712,90","712,91","713,87","713,88","713,89","713,90","713,91","714,87","714,88","714,89","714,90","714,91","715,87","715,88","715,89","715,90","715,91","716,87","716,88","716,89","716,90","716,91","730,551","730,552","730,553","730,554","730,555","731,551","731,552","731,553","731,554","731,555","732,551","732,552","732,553","732,554","732,555","733,551","733,552","733,553","733,554","733,555","734,551","734,552","734,553","734,554","734,555","738,712","738,713","738,714","738,715","738,716","739,712","739,713","739,714","739,715","739,716","740,712","740,713","740,714","740,715","740,716","741,712","741,713","741,714","741,715","741,716","742,712","742,713","742,714","742,715","742,716"],coords_to_avoid:{},to_check:[],initMapData:function(e){Map.fetchMap(function(t){if(t.ok){aZ(translate("Map was Successfully requested from the server"))}else{aZ("fetchMap "+translate("was returned with a status of")+" "+t.ok+" - "+t.errmsg)}if(e){e(t)}})},fetchMap:function(e){var t=(new Date).getTime()/1e3;var n={};n["b"]=MAP_BIN_CACHEBREAKER;new aB("map",S3_SERVER+S3_SWF_PREFIX+"/map.bin",n,function(t){if(t.errors){t.ok=false;t.errmsg=t.errors}else if(t.dat){try{Map.map_bin=new jDataView(t.dat)}catch(n){t.ok=false;t.errmsg="fetchMap when decoding map.bin returned this error: "+n}}if(e)e(t)},false,true)},init:function(){var e=Map;e.x=Seed.cities[CAPITAL.id].x||0;e.y=Seed.cities[CAPITAL.id].y||0;Data.init({map:{terrains:{},players:{},evolution:{},alliance:{},coords:{}}});for(var t=0;t<e.to_avoid.length;t++)e.coords_to_avoid[e.to_avoid[t]]={x:0};e.checkOurCoords();e.setOurselves()},setOurselves:function(){var e=Map;for(var t=0;t<Seed.player.player_wildernesses.length;t++){var n=Seed.player.player_wildernesses[t];var r=n.x+","+n.y;Data.map.terrains[r]=[Seed.player.id,Seed.player.name,e.checkType(n.type),n.level];Data.map.coords[r]={A:0,la:0}}var i=Seed.player.alliance&&Seed.player.alliance.id?Seed.player.alliance.id:0;Data.map.players[Seed.player.id]=[Seed.player.name,Seed.player.level,Seed.player.might,i,1];if(i)Data.map.alliance[i]=Seed.player.alliance.name},getCities:function(e){var t=Map;var n=[];var r=e.radius||16;var i=e.x;var s=e.y;if(isNaN(i))i=t.x;if(isNaN(s))s=t.y;for(var o=i-r;o<i+r;o++){for(var u=s-r;u<s+r;u++){var a=t.normalize(o);var f=t.normalize(u);var l=t.map_bin.getUint8(f+a*750+2);var c=l>>4&15;var h=l&15;if(!l)continue;var p=a+","+f;var d=t.coords_to_avoid[p]?true:false;if(d)continue;if(!c||c!=0&&c!=7&&c<=9)continue;var v=c;var m=Data.map.terrains[p];if(m){v=t.checkType(m[2]);if(v==7||v>9)n.push({x:a,y:f})}}}return n},getTargets:function(e){var t=Map;var n={AnthropusCamp:[],forest:[],grassland:[],hill:[],lake:[],mountain:[],plain:[],City:[],Outpost:[]};var r=e.radius||16;var i=e.x;var s=e.y;if(isNaN(i))i=t.x;if(isNaN(s))s=t.y;var o=e.map_type||"all";for(var u=i-r;u<i+r;u++){for(var a=s-r;a<s+r;a++){var f=t.normalize(u);var l=t.normalize(a);var c=t.map_bin.getUint8(l+f*750+2);var h=c>>4&15;var p=c&15;if(!c)continue;var d=f+","+l;var v=t.coords_to_avoid[d]?true:false;if(v)continue;if(!h||h==9||o!="all"&&o=="C"&&h!=7&&h<=9&&o=="W"&&(h==0||h>=7)){continue}if(!Data.map.coords[d])Data.map.coords[d]={A:1,la:0};var m={x:f,y:l,t:h,l:p,A:Data.map.coords[d].A==0?false:true,la:Data.map.coords[d].la};var g=Data.map.terrains[d];if(g){m.id=g[0]||0;m.cn=g[1];m.t=t.checkType(g[2]);m.l=g[3]||m.l;if(m.id){var y=Data.map.players[m.id];if(y){m.n=y[0];m.pl=y[1];m.m=y[2];m.ai=y[3];m.a=Data.map.alliance[y[3]]||y[3];var b=Data.map.coords[d].A==0?false:true;m.A=b=m.a?false:true;m.bk=y[4]}}}else{if(h==7)m.l=1}m.d=bu(i,s,f,l);var w=t.names.type[h];if(m.t>9)w="Outpost";if(m.t==7&&as(m.n)&&as(m.cn))continue;n[w].push(m)}}Map.targets=n;return n},tileAt:function(e,t){function p(e){if(e.ok){if(e.dat.map_player&&e.dat.map_player!=null&&e.dat.map_player.id){var n=0;var r=0;var i=e.dat.map_terrain.x+","+e.dat.map_terrain.y;if(e.dat.map_player.alliance){n=e.dat.map_player.alliance.id;Data.map.alliance[n]=e.dat.map_player.alliance.name;f.A=Data.map.coords[i].A=0;if(Seed.player.alliance&&e.dat.map_player.alliance.id===Seed.player.alliance.id){r=1}}Data.map.players[e.dat.map_player.id]=[e.dat.map_player.name,e.dat.map_player.level,e.dat.map_player.might,n,r];f.n=e.dat.map_player.name;f.pl=e.dat.map_player.level;f.m=e.dat.map_player.might;f.ai=n;f.a=Data.map.alliance[n]||n;f.bk=r;var s=e.dat.map_terrain.type?Map.names.type[e.dat.map_terrain.type]:o;var a=e.dat.map_terrain.name;Data.map.terrains[i]=[e.dat.map_terrain.map_player_id,a,Map.checkType(s),e.dat.map_terrain.level||f.l];f.id=e.dat.map_terrain.map_player_id;f.cn=a;f.t=Map.checkType(s);f.l=Data.map.terrains[i][3]}else{if(e.dat.map_terrain){f.t=Map.checkType(e.dat.map_terrain.type?Map.names.type[e.dat.map_terrain.type]:o);f.l=e.dat.map_terrain.level}else{f.t=Map.checkType(o);f.l=u}f.id=null;f.cn=null;f.n=null;f.pl=null;f.m=null;f.ai=null;f.a=null;f.bk=null;var i=e.dat.x+","+e.dat.y;Data.map.terrains[i]=[null,0,f.t,f.l]}f.ok=true;if(t)t(f);return}else{aZ("Map tileAt "+translate("was returned with a status of")+" "+e.ok+" - "+e.errmsg);if(t)t(e);return}}var n=Map,r,i;if(!isNaN(e.x))r=n.normalize(e.x);else r=n.normalize(n.x);if(!isNaN(e.y))i=n.normalize(e.y);else i=n.normalize(n.y);var s=n.map_bin.getUint8(i+r*750+2);var o=s>>4&15;var u=s&15;if(!s)return null;var a=r+","+i;if(!Data.map.coords[a])Data.map.coords[a]={A:1,la:0};var f={x:r,y:i,t:o,l:u,A:Data.map.coords[a].A,la:Data.map.coords[a].la};if(o==8){f.ok=true;t(f);return}if(Data.map.terrains[a]&&Data.map.terrains[a][0]){var l=Data.map.terrains[a];f.id=l[0];f.cn=l[1];f.t=n.checkType(l[2]);f.l=l[3];if(Data.map.players[f.id]&&Data.map.players[f.id][0]){var c=Data.map.players[f.id];f.n=c[0];f.pl=c[1];f.m=c[2];f.ai=c[3];f.a=Data.map.alliance[f.ai]||f.ai;f.bk=c[4];if(!e.force_request&&(!e.wild_detail||e.wild_detail&&f.l<7)){f.ok=true;if(t)t(f);return}}}if(f.n&&!e.force_request){f.ok=true;if(t)t(f);return}var h={};h=MyAjax.addMainParams();h["x"]=r;h["y"]=i;new aB("tile_at","map/tile_at.json",h,p,true)},scanMap:function(e,t){var n=Map;n.bO=t;n.radius=!e.radius||e.radius<8?8:e.radius;n.pos_x=n.normalize(e.x-n.radius+4);n.pos_y=n.normalize(e.y-n.radius+8);n.step_x=n.step_y=0;n.steps_x=Math.ceil(n.radius*2/8);n.steps_y=Math.ceil(n.radius*2/16);n.steps=bV(n.steps_x*n.steps_y)+1;n.step=0;n.percent=bV(n.step*100/n.steps);n.tile_count=0;n.total_tiles=0;n.old_percent=0;n.tile_percent=bV(n.tile_count*100/(n.total_tiles==0?1:n.total_tiles));n.forwards=true;n.city_detail=e.city_detail||false;n.wild_detail=e.wild_detail||false;n.force_request=e.force_request||false;n.options=e;n.to_check=aA(n.getCities({x:e.x,y:e.y,radius:n.radius}));var r={};r=MyAjax.addMainParams();r["x"]=n.pos_x;r["y"]=n.pos_y;r["width"]=8;r["height"]=16;new aB("map","map.json",r,n.gotMapCities,true)},gotMapCities:function(e){var t=Map;var n=Data.map;t.tile_count=0;t.total_tiles=0;if(!e.ok){if(t.bO)t.bO(null);return}var r={forest:[],grassland:[],hill:[],lake:[],mountain:[],plain:[],City:[]};for(var i=0;i<e.dat.map_cities.length;i++){var s=e.dat.map_cities[i];var o=0;var u=0;if(s.alliance_name){o=s.alliance_name;if(Seed.player.alliance&&s.alliance_name===Seed.player.alliance.name){u=1}}if(!Data.map.players[s.map_player_id]){Data.map.players[s.map_player_id]=[0,0,s.might,o,u]}else{if(!Data.map.players[s.map_player_id][3])Data.map.players[s.map_player_id][3]=o}var a=s.x+","+s.y;Data.map.terrains[a]=[s.map_player_id,s.name||0,t.checkType(s.type),s.level||0];var f=false;for(var l=0;l<t.to_check.length&&!f;l++){if(t.to_check[l].x==s.x&&t.to_check[l].y==s.y){f=true;t.to_check.splice(l,1)}}if(!Data.map.coords[a])Data.map.coords[a]={A:1,la:0};Data.map.coords[a].A=o?0:1;if(Seed.player.id===s.map_player_id)Data.map.coords[a].A=0;if(t.city_detail){var c={x:s.x,y:s.y};r.City.push(c)}}if(t.wild_detail){var h=t.pos_x;var p=t.pos_y;for(var d=h-t.radius;d<h+t.radius;d++){for(var v=p-t.radius;v<p+t.radius;v++){var m=t.normalize(d);var g=t.normalize(v);var y=t.map_bin.getUint8(g+m*750+2);var b=y>>4&15;var w=y&15;if(y){var a=m+","+g;var E=t.coords_to_avoid[a]?true:false;if(b>0&&b<7&&w>=7&&!E){var S=t.names.type[b];r[S].push({x:m,y:g})}}}}}if(t.city_detail||t.wild_detail){for(var x in r){if(r[x].length>0){r[x].shuffle()}}Map.to_refresh=r;Map.is_refreshing=true;for(var x in Map.to_refresh){t.total_tiles+=Map.to_refresh[x].length||0}t.getDetails()}t.callNext()},scanWilds:function(e,t){var n=Map;var r=Data.map;n.bO=t;n.radius=!e.radius||e.radius<8?8:e.radius;var i=e.x;var s=e.y;if(isNaN(i))i=n.x;if(isNaN(s))s=n.y;n.steps=1;n.step=0;n.percent=bV(n.step*100/n.steps);n.tile_count=0;n.total_tiles=0;n.old_percent=0;n.tile_percent=bV(n.tile_count*100/(n.total_tiles==0?1:n.total_tiles));n.options=e;var o={forest:[],grassland:[],hill:[],lake:[],mountain:[],plain:[],City:[]};for(var u=i-n.radius;u<i+n.radius;u++){for(var a=s-n.radius;a<s+n.radius;a++){var f=n.normalize(u);var l=n.normalize(a);var c=n.map_bin.getUint8(l+f*750+2);var h=c>>4&15;var p=c&15;if(c){var d=f+","+l;var v=n.coords_to_avoid[d]?true:false;if(h>0&&h<7&&p>=7&&!v&&(h==1&&Data.options.search.plain||h==2&&Data.options.search.mountain||h==3&&Data.options.search.forest||h==4&&Data.options.search.hill||h==5&&Data.options.search.grassland||h==6&&Data.options.search.lake)){var m=n.names.type[h];o[m].push({x:f,y:l})}}}}for(var g in o){if(o[g].length>0){o[g].shuffle()}}Map.to_refresh=o;Map.is_refreshing=true;for(var g in Map.to_refresh){n.total_tiles+=Map.to_refresh[g].length||0}n.getDetails();n.callNextWilds()},checkOurCoords:function(){var e=Map;if(Data.options.map.x!=Seed.cities[CAPITAL.id].x||Data.options.map.y!=Seed.cities[CAPITAL.id].y){Data.options.map.x=Seed.cities[CAPITAL.id].x;Data.options.map.y=Seed.cities[CAPITAL.id].y}},normalize:function(e){if(e==0)return 0;if(e>749)return e-750;if(e<0)return e+750;return e},checkType:function(e){var t=e;if(e>=0&&e<=20)t=e;else t=Map.names.type[e]||e;return t},callNext:function(){var e=Map;if(e.is_refreshing){setTimeout(e.callNext,1e3)}else{e.step=e.step+1;e.percent=bV(e.step*100/e.steps);progressBar.update({step:e.percent});if(e.forwards){++e.step_x;if(e.step_x>=e.steps_x){++e.step_y;e.forwards=false;--e.step_x}}else{--e.step_x;if(e.step_x<0){++e.step_y;e.forwards=true;++e.step_x}}if(e.step_y>=e.steps_y){if(e.to_check.length>0){e.is_refreshing=true;e.tile_count=0;e.total_tiles=e.to_check.length+1;e.old_percent=0;e.tile_percent=bV(e.tile_count*100/(e.total_tiles==0?1:e.total_tiles));e.checkOldCities(function(e){Map.is_refreshing=false});setTimeout(e.callNext,1e3)}else{if(e.bO){e.bO({done:true,terrains:e.terrains});return}}}e.bO({done:false});setTimeout(function(){var n={};n=MyAjax.addMainParams();n["x"]=e.normalize(e.pos_x+e.step_x*8);n["y"]=e.normalize(e.pos_y+e.step_y*16);n["width"]=8;n["height"]=16;new aB("map","map.json",n,e.gotMapCities,true)},TILE_DELAY*Math.floor(Math.random()*-1+2))}},callNextWilds:function(){var e=Map;if(e.is_refreshing){setTimeout(e.callNextWilds,1e3)}else{if(e.bO){e.bO({done:true,terrains:e.terrains});return}}},checkOldCities:function(e){var t=Map;if(t.to_check.length>0){var n=t.to_check[0].x;var r=t.to_check[0].y;Map.tileAt({x:n,y:r,force_request:true},function(e){if(e&&e.ok){t.to_check.splice(0,1);t.tile_count++;t.tile_percent=Math.floor(t.tile_count*100/(t.total_tiles==0?1:t.total_tiles));t.percent=bV(t.step*100/t.steps);t.percent=t.percent+t.tile_percent/t.steps;if(t.percent!=t.old_percent){progressBar.update({step:t.percent,stepText:translate("Please wait...")+"<br>"+translate("Step")+" "+(t.step+1)+"/"+t.steps+" : "+translate("Got")+" "+t.tile_count+"/"+t.total_tiles+" ("+translate("Checking old city coords")+")"});t.old_percent=t.percent}setTimeout(t.checkOldCities,TILE_DELAY*Math.floor(Math.random()*-1+2))}else{aZ("Map tileAt "+translate("was returned with a status of")+" "+e.ok+" - "+e.errmsg);var n=e.errmsg;var r=600;switch(e.status){case 400:n=translate("<b>Bad request!</b>");r=0;break;case 403:n=translate("<b>Forbidden!</b>");r=0;break;case 429:n="<b>API </b>"+translate("<b>Rate Limit Exceeded</b>, too many requests!");r=E429_DELAY;break;case 509:n=translate("<b>Rate Limit Exceeded</b>, too many requests!");r=300;break}if(r>0){progressBar.update({stepText:n+" - "+translate("Retry in")+" "+r});setTimeout(t.checkOldCities,r*1e3)}else{progressBar.update({stepText:n});t.to_check.splice(0,1);setTimeout(t.checkOldCities,TILE_DELAY*Math.floor(Math.random()*-1+2))}}})}if(t.to_check.length==0)Map.is_refreshing=false;if(e&&t.to_check.length==0)e({done:true})},getDetails:function(){var e=Map;for(var t in e.to_refresh){if(e.to_refresh[t].length>0){var n=e.to_refresh[t][0].x;var r=e.to_refresh[t][0].y;var i=t;Map.tileAt({x:n,y:r},function(t){if(t&&t.ok){e.to_refresh[i].splice(0,1);e.tile_count++;e.tile_percent=Math.floor(e.tile_count*100/(e.total_tiles==0?1:e.total_tiles));e.percent=bV(e.step*100/e.steps);e.percent=e.percent+e.tile_percent/e.steps;if(e.percent!=e.old_percent){progressBar.update({step:e.percent,stepText:translate("Please wait...")+"<br>"+translate("Step")+" "+(e.step+1)+"/"+e.steps+" : "+translate("Got")+" "+e.tile_count+"/"+e.total_tiles+" ("+translate(i)+")"});e.old_percent=e.percent}setTimeout(e.getDetails,TILE_DELAY*Math.floor(Math.random()*-1+2))}else{aZ("Map tileAt "+translate("was returned with a status of")+" "+t.ok+" - "+t.errmsg);var n=t.errmsg;var r=600;switch(t.status){case 400:n=translate("<b>Bad request!</b>");r=0;break;case 403:n=translate("<b>Forbidden!</b>");r=0;break;case 429:n="<b>API </b>"+translate("<b>Rate Limit Exceeded</b>, too many requests!");r=E429_DELAY;break;case 509:n=translate("<b>Rate Limit Exceeded</b>, too many requests!");r=300;break}if(r>0){progressBar.update({stepText:n+" - "+translate("Retry in")+" "+r});setTimeout(e.getDetails,r*1e3)}else{progressBar.update({stepText:n});e.to_refresh[i].splice(0,1);setTimeout(e.getDetails,TILE_DELAY*Math.floor(Math.random()*-1+2))}}});break}}var s=true;for(var t in e.to_refresh){if(e.to_refresh[t].length>0)s=false}if(s)Map.is_refreshing=false}};var Marches={table_output:{attacks:{},bookmark:{},waves:{},spies:{},transport:{},multiple:{}},count:{attacks:0,bookmark:0,waves:0,spies:0,transport:0,multiple:0},init:function(){var e=Marches;Data.init({marches:{start_at:0,attacks:{},bookmark:{},waves:{},spies:{},transport:{},multiple:{},count_limit:1,ressources:{}}})},add:function(e,t){var n=Marches;if(as(t)){if(Data.marches.attacks[e.id]===undefined&&Data.marches.bookmark[e.id]===undefined&&Data.marches.waves[e.id]===undefined&&Data.marches.spies[e.id]===undefined&&Data.marches.transport[e.id]===undefined&&Data.marches.multiple[e.id]===undefined){if(!as(e.ownerId))t=e.ownerId;else{switch(e.march_type){case"TransportMarch":t="transport";break;default:t="attacks";break}}}}Data.marches[t][e.id]=aA(e);Data.marches[t][e.id].has_report=t=="transport"?true:false},remove:function(e,t){var n=Marches;if(e)if(as(t)){for(var t in Data.marches){if(!/(attacks|waves|spies|multiple|bookmark|transport)/.test(t))continue;if(Data.marches[t][e]){delete Data.marches[t][e]}if(Data.marches.ressources[e])delete Data.marches.ressources[e]}}else{delete Data.marches[t][e]}},update:function(e){var t=Marches;var n=false;for(var r in Data.marches){if(!/(attacks|waves|spies|multiple|bookmark|transport)/.test(r))continue;var i=Data.marches[r][e.id];if(i){i.mergeWith(e);if(as(i.real_run_at)&&i.run_at&&i.duration&&i.status=="marching")i.real_run_at=i.run_at+bV(i.duration)}}},find:function(e){var t=Marches;var n=false;for(var r in Data.marches){if(!/(attacks|waves|spies|multiple|bookmark|transport)/.test(r))continue;for(var i in Data.marches[r]){var s=Data.marches[r][i];if(s.id==e){n=true;return s}}}if(!n)return null},purge:function(){var e=Marches,t=bV(be());for(var n in Data.marches){if(!/(attacks|waves|spies|multiple|bookmark|transport)/.test(n))continue;for(var r in Data.marches[n]){var i=Data.marches[n][r];if(i&&!e.findInSeed(r)&&(i.real_run_at&&t>i.real_run_at||!i.realrun_at))e.remove(r,n)}}},findInSeed:function(e){var t=false;for(var n in Seed.cities[CAPITAL.id].marches){var r=Seed.cities[CAPITAL.id].marches[n];if(r.id==e){t=true}}return t},checkTimer:null,check:function(){var e=Marches;var t=bV(be());clearTimeout(e.checkTimer);for(var n in Data.marches){if(!/(attacks|waves|spies|multiple|bookmark|transport)/.test(n)){continue}var r=Data.marches[n];for(var i in r){if(r[i].run_at<t-60&&!r[i].has_report){if(r[i].retry&&r[i].run_at<t-300){++Data.options.messages.missing;if(DEBUG_MARCHES)bf("March report never received! (now="+t+")\n"+bC(r[i],6,1));r[i].has_report=true}else{r[i].retry=true;Messages.checkMessages({category:"reports"})}}}}e.checkTimer=setTimeout(e.check,Math.randRange(3e4,7e4))},updateCounters:function(){var e=Marches;for(var t in Data.marches){if(!/(attacks|waves|spies|multiple|bookmark|transport)/.test(t))continue;Marches.count[t]=0;for(var n in Data.marches[t]){Marches.count[t]++}}},trace:function(e,t){var n=[];var r=Marches;for(var i in Data.marches){if(!/(attacks|waves|spies|multiple|bookmark|transport)/.test(i))continue;for(var s in Data.marches[i]){var o=Data.marches[i][s];if(o.status=="encamped")continue;if(t){if(t==s)n.push({march:"id="+s+", ownerId="+(o.ownerId?o.ownerId:"")+", job_id="+(o.job_id?o.job_id:"")+", status="+o.status+", inSeed="+r.findInSeed(o.id)+", has_report="+(o.has_report?o.has_report:""),times:"now="+cc(bV(be()))+", run_at="+(o.run_at?cc(o.run_at):"")+", duration="+(o.duration?o.duration:"")+", real_run_at="+(o.real_run_at?cc(o.real_run_at):"")})}else n.push({march:"id="+s+", ownerId="+(o.ownerId?o.ownerId:"")+", job_id="+(o.job_id?o.job_id:"")+", status="+o.status+", inSeed="+r.findInSeed(o.id)+", has_report="+(o.has_report?o.has_report:""),times:"now="+cc(bV(be()))+", run_at="+(o.run_at?cc(o.run_at):"")+", duration="+(o.duration?o.duration:"")+", real_run_at="+(o.real_run_at?cc(o.real_run_at):"")})}}if(n&&n.length>0)bI(e+" : "+bC(n,8,1))},updateTable:function(e,t){var n=Marches;var r=bV(be());if(!/(attacks|waves|spies|multiple|bookmark|transport)/.test(t))return;var i=n.table_output[t];var s=0;for(var o=0;o<e.rows.length;o++){var u=e.rows[o].getAttribute("ref");var a=Data.marches[t][u];if(!a||!n.findInSeed(u)&&(a.real_run_at&&r>a.real_run_at||!a.realrun_at)){s++;e.deleteRow(o);delete i[u];o--;if(a)n.remove(u,t);continue}else if(s>0)i[u].row-=s}n.count[t]=0;for(var u in Data.marches[t]){if(n.findInSeed(u))n.count[t]++}Marches.updateCounters(t);for(var u in Data.marches[t]){var f,l;var a=Data.marches[t][u];var c=a.status==="retreating";var h=a.run_at-r;if(!h||h<0)h=(a.real_run_at?a.real_run_at:a.run_at)-r;var p;if(h<0&&a.status!=="encamped"){p="..."}else if(isNaN(h)||h<0&&a.status==="encamped"){p="---"}else{p=bE(h,true)}var d="";for(var v in a.units)d+=" "+translate(v)+": "+bD(a.units[v]," ")+" +";d=d.substr(1,d.length-2);var m="";if(Data.marches.ressources[u]){m=" +"+translate("Resources")+": +";for(var g in Data.marches.ressources[u]){if(Data.marches.ressources[u][g]>0)m+=" "+translate(g)+": "+bD(Data.marches.ressources[u][g]," ")+" +"}m=m.substr(1,m.length-2)}if(i[u]===undefined&&(h||a.status==="encamped"||!h&&a.real_run_at-r>0)){f=e.insertRow(0);i[u]={};f.setAttribute("ref",u);f.title=["("+(a.general&&a.general.name?a.general.name:"----")+")",a.target_name,a.terrain_level,"["+a.x+"/"+a.y+"]\n",d.replace(/\+/g,"\n"),m.replace(/\+/g,"\n")].join(" ");if(c){i[u].row_status=2;l=f.insertCell(-1);l.innerHTML="<b>"+translate("Returning")+":</b>";l=f.insertCell(-1);l.className="wrap";l.innerHTML=a.target_name.nowrap();l=f.insertCell(-1);l.style.textAlign="right";l.innerHTML="&nbsp;<b>&lt;</b>&nbsp;";l=f.insertCell(-1);l.innerHTML=p;l=f.insertCell(-1);l.style.textAlign="right";l.innerHTML="&nbsp;";for(var y=0;y<time_item_list.length;y++){if(time_item_list[y].type.indexOf("M")>=0&&bV(Seed.player.items[time_item_list[y].name])>0){l=f.insertCell(-1);l.style.textAlign="right";l.innerHTML="&nbsp;";n.addSpeedUpButton(y,l,f.cells[3],u)}}}else{i[u].row_status=1;l=f.insertCell(-1);switch(a.march_type){case"TransportMarch":l.innerHTML="<b>"+(RecallMarch.exists(u)?translate("Yoyo"):translate("Transport")).capitalize()+":</b>";break;case"SpyMarch":l.innerHTML="<b>"+translate("Spy").capitalize()+":</b>";break;default:l.innerHTML="<b>"+translate(a.status).capitalize()+":</b>";break}l=f.insertCell(-1);l.className="wrap";l.innerHTML=a.target_name.nowrap()+"&nbsp;"+a.terrain_level+"&nbsp;";l=f.insertCell(-1);l.style.textAlign="right";l.innerHTML="<span class=jewel> ["+a.x+"/"+a.y+"]</span>&nbsp;<b>&gt;</b>&nbsp;";l=f.insertCell(-1);l.style.textAlign="right";l.innerHTML=p;l=f.insertCell(-1);var b=document.createElement("input");b.type="button";b.setAttribute("ref",u);if(a.status==="encamped"){b.className="thin";b.value="X"}else{b.className=UID["btn_red"]+" thin";b.value="X"}b.addEventListener("click",function(e){var n=e.target;n.disabled=true;n.style.display="none";var r=n.getAttribute("ref");if(Data.marches[t][r]){var i=Data.marches[t][r].city_id;MyAjax.marchRecall(i,r,function(e){if(e.ok&&e.dat.result.success){Data.marches[t][r].status="retreating"}})}},false);l.appendChild(b);for(var y=0;y<time_item_list.length;y++){if(time_item_list[y].type.indexOf("M")>=0&&bV(Seed.player.items[time_item_list[y].name])>0){l=f.insertCell(-1);l.style.textAlign="right";l.innerHTML="&nbsp;";if(a.status!="encamped")n.addSpeedUpButton(y,l,f.cells[3],u)}}}}else{if(i[u]===undefined)continue;for(var o=0;o<e.rows.length;o++){if(e.rows[o].getAttribute("ref")==u){f=e.rows[o];break}}if(f===undefined){delete i[u];continue}switch(i[u].row_status){case 0:if(c&&h>0){i[u].row_status=2;f.cells[4].innerHTML="";var w=0;for(var y=0;y<time_item_list.length;y++){if(time_item_list[y].type.indexOf("M")>=0){f.cells[5+w].innerHTML="";w++}}continue}f.style.display="none";i[u].row_status=-1;continue;break;case 1:case 2:if(c){i[u].row_status=3;var E="";E+="<b>"+translate("Returning")+":</b>";f.cells[0].innerHTML=E;f.cells[1].innerHTML=a.target_name.nowrap();f.cells[2].innerHTML="&nbsp;<b>&lt;</b>&nbsp;";f.cells[4].innerHTML="";var w=0;for(var y=0;y<time_item_list.length;y++){if(time_item_list[y].type.indexOf("M")>=0&&bV(Seed.player.items[time_item_list[y].name])>0){f.cells[5+w].innerHTML="";n.addSpeedUpButton(y,f.cells[5+w],f.cells[3],u);w++}}}else if((isNaN(h)||h<0)&&(i[u].row_status===1||i[u].row_status===2)){if(a.terrain_type&&!/(Anthropus|City|Outpost|Bog)/.test(a.terrain_type)){if(a.status==="marching"){i[u].row_status=2}else if(a.status==="encamped"){i[u].row_status=4;var E="";E+="<b>"+translate(a.status).capitalize()+":</b>";f.cells[0].innerHTML=E;f.cells[4].innerHTML="";var b=document.createElement("input");b.type="button";b.setAttribute("ref",u);b.className="thin";b.value="X";b.addEventListener("click",function(e){var n=e.target;n.disabled=true;n.style.display="none";var r=n.getAttribute("ref");if(Data.marches[t][r]){var i=Data.marches[t][r].city_id;MyAjax.marchRecall(i,r,function(e){if(e.ok&&e.dat.result.success){Data.marches[t][r].status="retreating"}})}},false);f.cells[4].appendChild(b);var w=0;for(var y=0;y<time_item_list.length;y++){if(time_item_list[y].type.indexOf("M")>=0){if(f.cells[5+w])f.cells[5+w].innerHTML="";w++}}}}}break;case 3:if(isNaN(h)||h<0){i[u].row_status=0}break;case 4:if(c){i[u].row_status=3;f.cells[0].innerHTML="<b>"+translate("Retreating")+":</b>";f.cells[1].innerHTML=a.target_name.nowrap();f.cells[2].innerHTML="&nbsp;<b>&lt;</b>&nbsp;";f.cells[4].innerHTML="";var w=0;for(var y=0;y<time_item_list.length;y++){if(time_item_list[y].type.indexOf("M")>=0&&bV(Seed.player.items[time_item_list[y].name])>0){f.cells[5+w].innerHTML="";n.addSpeedUpButton(y,f.cells[5+w],f.cells[3],u);w++}}}break}f.cells[3].innerHTML=p}}},addSpeedUpButton:function(e,t,n,r){if(!Data.options.speedups_enabled)return;var i=Marches;t.innerHTML="";var s=bV(Seed.player.items[time_item_list[e].name]);var o=document.createElement("input");o.type="button";o.setAttribute("ref",time_item_list[e].name+"_"+r);o.value=time_item_list[e].text;if(s>0){o.disabled=false;o.className=UID["btn_green"]+" thin";o.addEventListener("click",function(t){var r=t.target;var i=r.getAttribute("ref").split("_");var s=Marches.find(i[1]);if(s!=null){var u=s.city_id;if(time_item_list[e].confirmation&&Data.options.use_speedup_confirmation){dO(translate("Do you want to use [0] on this march").replace("[0]",translate(time_item_list[e].name))+" ?",function(){r.disabled=true;r.className=UID["btn_disabled"]+" thin";MyAjax.useItem(u,i[0],s.job_id,function(e){if(e.ok&&e.dat.result.success){if(e.dat.result.item_response){itmResp=e.dat.result.item_response;marchResp=Marches.find(itmResp.march_id);var t=aA(itmResp);delete t.type;Seed.checkAddJob(t);if(itmResp.queue=="march"&&marchResp){marchResp.run_at=itmResp.run_at;marchResp.duration=itmResp.duration;var r=marchResp.run_at-bV(be());var s;if(r<0){s="..."}else if(isNaN(r)){s="---"}else{s=bE(r,true)}n.innerHTML=s}}var u=bV(Seed.player.items[i[0]]);if(u>0){o.disabled=false;o.className=UID["btn_green"]+" thin"}}})},function(){},true)}else{r.disabled=true;r.className=UID["btn_disabled"]+" thin";MyAjax.useItem(u,i[0],s.job_id,function(e){if(e.ok&&e.dat.result.success){if(e.dat.result.item_response){itmResp=e.dat.result.item_response;marchResp=Marches.find(itmResp.march_id);var t=aA(itmResp);delete t.type;Seed.checkAddJob(t);if(itmResp.queue=="march"&&marchResp){marchResp.run_at=itmResp.run_at;marchResp.duration=itmResp.duration;var r=marchResp.run_at-bV(be());var s;if(r<0){s="..."}else if(isNaN(r)){s="---"}else{s=bE(r,true)}n.innerHTML=s}}var u=bV(Seed.player.items[i[0]]);if(u>0){o.disabled=false;o.className=UID["btn_green"]+" thin"}}})}}},false)}else{o.disabled=true;o.className=UID["btn_disabled"]+" thin"}t.appendChild(o)}};var MemberShips={fetchMembership:function(e,t,n){var r=MemberShips;r.bO=t;r.doDetail=n;if(e){var i={};i=MyAjax.addMainParams();i["count"]=120;i["approved"]=1;var s="alliances/"+e+"/memberships";new aB("membership",s,i,r.updateMemberships,false)}},updateMemberships:function(e){var t=MemberShips;if(!e.ok){t.bO(e);return}var n=e.dat.alliance_memberships;var r={member:[]};for(var i=0;i<n.length;i++){var s={player:n[i].player.name,id:n[i].player.id,role:n[i].role,might:n[i].player.might,joined:n[i].created_at_i*1e3,city:n[i].player.city.name,x:n[i].player.city.x,y:n[i].player.city.y,dragon:n[i].player.city.dragon_slots,req_id:n[i].id,dist:bu(Seed.cities[CAPITAL.id].x,Seed.cities[CAPITAL.id].y,n[i].player.city.x,n[i].player.city.y)};r.member.push(s)}r.done=true;t.bO(r);return},fetchApplicants:function(e,t,n){var r=MemberShips;r.bO=t;r.doDetail=n;if(e){var i={};i=MyAjax.addMainParams();i["page"]=1;i["count"]=30;i["approved"]=0;i["sort"]="might";var s="alliances/"+e+"/memberships";new aB("membership",s,i,r.updateApplicants,false)}},updateApplicants:function(e){var t=MemberShips;if(!e.ok){t.bO(e);return}var n=e.dat.alliance_memberships;var r={member:[]};for(var i=0;i<n.length;i++){var s={player:n[i].player.name,id:n[i].player.id,role:"applicant",might:n[i].player.might,joined:n[i].created_at_i*1e3,city:n[i].player.city.name,x:n[i].player.city.x,y:n[i].player.city.y,dragon:n[i].player.city.dragon_slots,req_id:n[i].id,dist:bu(Seed.cities[CAPITAL.id].x,Seed.cities[CAPITAL.id].y,n[i].player.city.x,n[i].player.city.y)};r.member.push(s)}r.done=true;t.bO(r);return},fetchAlliances:function(e){var t=MemberShips;t.results={alliance:[],friends:[],foes:[]};t.bO=e;t.steps=5;t.step=1;t.percent=bV(t.step*100/t.steps);progressBar.update({step:t.percent});var n={};n=MyAjax.addMainParams();n["q"]="";n["sort"]="might";n["count"]=20;n["page"]=t.step;new aB("alliances","alliances",n,t.updateAlliances,false)},updateAlliances:function(e){var t=MemberShips;var n=e.dat.alliances;if(!e.ok){if(t.bO)t.bO(e);return}if(n){for(var r=0;r<n.length;r++){var i={name:n[r].name,id:n[r].id,count:n[r].member_count,rank:n[r].rank,might:n[r].might,lord:n[r].overlord.name,lord_id:n[r].overlord.id,desc:n[r].description};t.results.alliance.push(i)}if(e.dat.friend_ids){for(var s=0;s<e.dat.friend_ids.length;s++)t.results.friends.push(e.dat.friend_ids[s])}if(e.dat.foe_ids){for(var s=0;s<e.dat.foe_ids.length;s++)t.results.foes.push(e.dat.foe_ids[s])}}t.callNextPage()},callNextPage:function(){var e=MemberShips;e.step++;e.percent=bV(e.step*100/e.steps);progressBar.update({step:e.percent});if(e.step>e.steps){if(e.bO){e.results.done=true;e.bO(e.results)}return}setTimeout(function(){var n={};n=MyAjax.addMainParams();n["q"]="";n["sort"]="might";n["count"]=20;n["page"]=e.step;new aB("alliances","alliances",n,e.updateAlliances,false)},MAP_DELAY*Math.floor(Math.random()*-1+2))},fetchActivity:function(e,t){var n=MemberShips;n.results={battle:[]};n.bO=t;n.steps=10;n.step=0;n.id=e;n.percent=bV(n.step*100/n.steps);progressBar.update({step:n.percent});if(e){var r={};r=MyAjax.addMainParams();r["offset"]=0;r["approved"]=0;r["limit"]=20;r["sort"]="might";var i="alliances/"+e+"/activity";new aB("activity",i,r,n.updateActivity,false)}},updateActivity:function(e){var t=MemberShips;var n=e.dat.activity;if(!e.ok||e.errmsg){t.bO(e);return}if(n){for(var r=0;r<n.length;r++){var i={won:n[r].alliance_member_won,id:n[r].battle_report_id,def:n[r].alliance_member_attacked,time:n[r].battle_time_i,aid:n[r].alliance_player.id,aname:n[r].alliance_player.name,amight:n[r].alliance_player.might,ax:n[r].alliance_player.capital_x,ay:n[r].alliance_player.capital_y,pname:n[r].non_alliance_player.name,pmight:n[r].non_alliance_player.might,px:n[r].non_alliance_player.capital_x,py:n[r].non_alliance_player.capital_y,palli:n[r].non_alliance_player.alliance.name};t.results.battle.push(i)}}t.callNextActivity()},callNextActivity:function(){var e=MemberShips;e.step++;e.percent=bV(e.step*100/e.steps);progressBar.update({step:e.percent});if(e.step>e.steps){if(e.bO){e.results.done=true;e.bO(e.results)}return}setTimeout(function(){var n={};n=MyAjax.addMainParams();n["offset"]=bV(e.step)*20;n["approved"]=0;n["limit"]=20;n["sort"]="might";var r="alliances/"+e.id+"/activity";new aB("activity",r,n,e.updateActivity,false)},MAP_DELAY*Math.floor(Math.random()*-1+2))}};var Messages={readList:[],fetchTimer:null,mainTimer:0,lastQueued:0,unread_count:0,total_count:0,known_count:0,checkBusy:false,battleReportListeners:[],alarmReportListeners:[],spyReportListeners:[],delete_queue:[],details:{},activity:{},messageDeletion:false,readPagesTimer:null,pagesMessages:0,pageReading:0,toRead:[],idsToDelete:[],init:function(){var e=Messages;e.checkMessages({wait:1e3});window.addEventListener("unload",e.onUnload,false);e.mainTimer=setTimeout(e.messageTick,1e3)},messageTick:function(){var e=Messages;var t=false;for(var n in Data.marches){if(!/(attacks|waves|spies|multiple|bookmark|transport)/.test(n))continue;for(var r in Data.marches[n]){var i=Data.marches[n][r];if(i.status=="retreating"&&!i.has_report)t=true}}clearTimeout(e.mainTimer);if(t&&!e.messageDeletion){e.checkMessages({category:Data.options.disable_inbox?"reports":"all",wait:Math.randRange(2e3,3e3),bypass:false});e.mainTimer=setTimeout(e.messageTick,5e3)}else{if((Data.options.tower.enabled||!Data.options.disable_inbox)&&!e.messageDeletion){var s=Data.options.disable_inbox?6e5:6e4;var o=Data.options.tower.delay*Data.options.tower.unit*1e3;var u=hW()*1e3;if(o<u)o=u;if(Data.options.tower.enabled)s=o>s?s:o;e.checkMessages({category:Data.options.disable_inbox?"reports":"all",wait:s,bypass:true})}e.mainTimer=setTimeout(e.messageTick,1e3)}},deleteMessage:function(e){function n(){var e=Messages;MyAjax.messageDelete(e.delete_queue,function(e){var t=Messages;t.delete_queue=[]})}var t=Messages;t.delete_queue.push(e);if(t.delete_queue.length>=Math.randRange(5,12))n()},onUnload:function(){var e=Messages;if(e.delete_queue.length>0)MyAjax.messageDelete(e.delete_queue)},newWarning:function(e){bI("Messages.newWarning --- Start");var t=Messages;t.checkMessages({category:Data.options.disable_inbox?"reports":"all",wait:1,bypass:true});bI("Messages.newWarning --- End")},checkMessages:function(e){function i(e){MyAjax.messageList(e,1,12,function(e){var t=Messages;if(e==null)return;var n=e.report_notifications;if(n==null)return;for(var r=n.length-1;r>=0;r--){if(n[r].report_type==="BattleReport"&&!n[r].read_at&&t.battleReportListeners.length!=0){if(t.readList.indexOf(n[r].id)<0){t.readList.push(n[r].id)}}if(n[r].report_type==="SpyReport"&&!n[r].read_at&&t.spyReportListeners.length!=0){if(t.readList.indexOf(n[r].id)<0){t.readList.push(n[r].id)}}if(n[r].report_type==="SentinelWarning"&&(!n[r].read_at||Tabs.Tower.startup)&&t.alarmReportListeners.length!=0){var i=false;for(var s=0;s<Data.options.messages_tower.length;s++){if(Data.options.messages_tower[s].id==n[r].id){i=true;break}}if(!i)t.readList.push(n[r].id)}}clearTimeout(t.fetchTimer);if(t.readList.length>0)t.fetchTimer=setTimeout(t.fetchNext,Math.randRange(2e3,4e3))})}var t=Messages;if(t.battleReportListeners.length==0&&t.alarmReportListeners.length==0&&t.spyReportListeners.length==0&&Data.options.disable_inbox)return;var n=(e.category||"all").toLowerCase();var r=e.wait||2e4;if(!RequestQueue.isPending("checkMessages",r))RequestQueue.add("checkMessages",function(){i(n)},r,e.bypass)},fetchNext:function(){var e=Messages;var t=e.readList[0];if(!t||t==null){aZ("Messages.fetchNext BAD MESSAGE ID:\n"+bC(e.readList,8,1));return}clearTimeout(e.fetchTimer);MyAjax.messageDetail(t,function(e){var n=Messages;n.readList.shift();if(e&&e.report_notification&&e.report_notification.report_type==="BattleReport")n.gotReport("battle",e);if(e&&e.report_notification&&e.report_notification.report_type==="SpyReport")n.gotReport("spy",e);if(e&&e.report_notification&&e.report_notification.report_type==="SentinelWarning")n.gotReport("alarm",e,t);if(n.readList.length>0)n.fetchTimer=setTimeout(n.fetchNext,Math.randRange(2e3,4e3))})},gotReport:function(e,t,n){var r=Messages,i=null;if(!t||!t.report)return;switch(e){case"battle":i=r.battleReportListeners;break;case"spy":i=r.spyReportListeners;break;default:i=r.alarmReportListeners;break}for(var s=0;s<i.length;s++){if(n)i[s](t,n);else i[s](t)}},removeReportListener:function(e,t){var n=Messages,r=null,i=0;switch(e){case"attacks":case"waves":case"multiple":case"bookmark":r=n.battleReportListeners;i=Marches.count[e];break;case"spies":r=n.spyReportListeners;i=Marches.count[e];break;default:r=n.alarmReportListeners;break}var s=r.indexOf(t);if(s>=0){if(i==0)r.splice(s,1);else setTimeout(n.removeReportListener,1e3,e,t)}},addAlarmReportListener:function(e){var t=Messages.alarmReportListeners.indexOf(e);if(t<=0)Messages.alarmReportListeners.push(e)},addBattleReportListener:function(e){var t=Messages.battleReportListeners.indexOf(e);if(t<=0)Messages.battleReportListeners.push(e)},addSpyReportListener:function(e){var t=Messages.spyReportListeners.indexOf(e);if(t<=0)Messages.spyReportListeners.push(e)},deleteSingleMsg:function(e,t){var n=Messages,r=[];r.push(e);MyAjax.messageDelete(r,function(e){var n=Messages;if(t)t(true)})},displayBattleReport:function(e,t){var n=e.report;var r=n.attacker;var i=n.defender;var s=n.boost_logger;var o="";var u="";var a=false;if(r.name==(t||Seed.player.name)){if(n.winner=="attacker"){o="victory";switch(n.location.terrain){case"City":u="attack-city-win";break;case"Outpost":u="attack-outpost-win";break;case"AnthropusCamp":u="attack-camp-win";break;default:u="attack-wild-win";break}}else{o="defeat";switch(n.location.terrain){case"City":u="attack-city-lose";break;case"Outpost":u="attack-outpost-lose";break;case"AnthropusCamp":u="attack-camp-lose";break;default:u="attack-wild-lose";break}}}else{a=true;if(n.winner=="defender"){o="victory";switch(n.location.terrain){case"City":u="defend-city-win";break;case"Outpost":u="defend-outpost-win";break;default:u="defend-wild-win";break}}else{o="defeat";switch(n.location.terrain){case"City":u="defend-city-lose";break;case"Outpost":u="defend-outpost-lose";break;default:u="defend-wild-lose";break}}}var f='<table style="margin-top:3px" width=98%>'+"	<tr valign=top align=center>"+"		<td width=100%><br><b><span class="+UID["red"]+"><b>"+translate(o).toUpperCase()+"</b></span></b> - <b>"+translate(u)+"</b></td>"+"	</tr></table><br>"+'<table style="margin-top:3px" width=98%>'+"	<tr valign=top align=left>"+"		<td width=49%>"+"			<label>"+translate("report-no")+" :</label><b>"+e.id+"</b><br>"+"			<label>"+(new Date(e.created_at*1e3)).myString()+"</label><br><br>"+"			<label>"+translate(n.location.terrain)+" "+translate("level")+" "+n.location.level+"</label><br>";var l=n.location.terrain=="Outpost"?translate(n.location.title):n.location.terrain=="City"?n.location.title:"";if(l!=""){f+="			<table width=100%><tr>"+"				<td width=5%><label>"+translate("location")+" : </td><td width=95%><b>"+l+"</b></td></tr>"+"			<tr><td></td><td><label><b>"+n.location.x+", "+n.location.y+"</b></label></td></tr>"+"			</table><br>"}else{f+="			<label>"+translate("location")+" : <b>"+n.location.x+", "+n.location.y+"</b></label><br>"}if(i.great_dragon){var c=i.great_dragon.starting_life-i.great_dragon.ending_life;var h=(c/i.great_dragon.starting_life*100).toFixed(2);var p="",d="";var v="",m="";if(i.buffs&&i.buffs[0]){p=i.buffs?translate(i.buffs[0].name):"";for(var g in i.buffs[0].stats){if(i.buffs[0].stats[g]>0)d+=translate(g)+" +"+bD(i.buffs[0].stats[g]," ")+", "}d=d.substr(0,d.length-2)}if(i.buffs&&i.buffs[1]){v=i.buffs?translate(i.buffs[1].name):"";for(var g in i.buffs[1].stats){if(i.buffs[1].stats[g]>0)m+=translate(g)+" +"+bD(i.buffs[0].stats[g]," ")+", "}m=m.substr(0,m.length-2)}f+="		<table width=100%><tr>"+"			<td width=20%>"+translate("GreatDragon")+" "+i.great_dragon.level+" : </td>"+"			<td width=80%><b>"+bD(c," ")+"</b>"+translate(" damages taken")+"</td></tr>"+"		<tr><td></td><td><b>"+h+"%</b> "+translate("life lost")+"</td></tr>";if(p!="")f+='<tr><td colspan=2 style="white-space:normal;"><b>'+p+"</b>&nbsp;&nbsp;("+d+")</td></tr>";if(v!="")f+='<tr><td colspan=2 style="white-space:normal;"><b>'+v+"</b>&nbsp;&nbsp;("+m+")</td></tr>";f+="		</table><br>"}f+="		</td>"+"		<td width=2%>&nbsp</td>"+"		<td width=49%>"+"			<table class="+UID["row_style"]+" width=100%>"+"			<tr class="+UID["row_headers"]+"><td colspan=2 class=left>"+translate("Resources")+"</td></tr>";var y=n.spoils.resources;for(var b=0;b<transportable_resource_types.length;b++){var w=transportable_resource_types[b];var E=false;if(y){for(var S in y){if(S==transportable_resource_types[b]){var x=bV(y[S])>0?"<b>"+bD(a?bV(y[S])*-1:bV(y[S]))+"</b>":0;f+="		<tr><td class=left width=50%>"+translate(w)+"</td><td align=right width=50%>"+x+"</td></tr>";E=true}}}if(!E&&w!="blue_energy"&&w!="lunar_energy"&&w!="enchanting"){f+="		<tr><td class=left width=50%>"+translate(w)+"</td><td align=right width=50%>0</td></tr>"}}var T=n.spoils.kill_items;if(T){for(var S in T)f+="		<tr><td class=left width=50%>"+translate(S)+"</td><td align=right width=50%>"+bD(bV(T[S])," ")+"</td></tr>"}var N=n.spoils.items;if(N&&N.length>0){for(var C=0;C<N.length;C++)f+="		<tr><td class=left colspan=2>"+translate(N[C])+"</td></tr>"}else{f+="		<tr><td class=left colspan=2>"+translate("battle-report-no-items")+"</td></tr>"}f+="			</table>"+"		</td>"+"	</tr>"+"</table><br>"+'<div style="height:350px; max-height:350px; overflow-y:auto; white-space:pre-wrap;" width=98%>';if(r.location)att_loc=r.location.x+", "+r.location.y;else att_loc=n.location.x+", "+n.location.y;if(i.location)def_loc=i.location.x+", "+i.location.y;else def_loc=n.location.x+", "+n.location.y;f+='<table style="margin-top:1px" width=98%>'+"	<tr valign=top align=center>"+"		<td width=49%>"+"			<table class="+UID["row_style"]+" width=100%>"+"				<tr>"+"					<td valign=middle colspan=3><b>"+r.name+"</b> ("+att_loc+")&nbsp;<span class="+UID["red"]+">"+(n.winner=="attacker"?translate("victorious"):translate("defeated"))+"</span></td>"+"				</tr><tr class="+UID["row_headers"]+">"+"					<td valign=middle width=40%><b>"+translate("Troops")+"</b></td>"+"					<td valign=middle width=20%><b>"+translate("Fought")+"</b></td>"+"					<td valign=middle width=20%><b>"+translate("lost")+"</b></td>"+"					<td valign=middle width=20%><b>"+translate("Might")+"</b></td>"+"				</tr>";if(r.units){var k=0;for(var S in r.units){if(S&&r.units[S]){var L=r.units[S][0]!=r.units[S][1]?r.units[S][0]-r.units[S][1]:0;var A=r.units[S][0]!=r.units[S][1]?"<span class="+UID["red"]+"><b>"+bD(r.units[S][0]-r.units[S][1])+"</b></span>":0;var O=0;for(var M=0;M<all_unit_types.length;M++){if(all_unit_types[M]==S){O=L*Seed.stats.unit[all_unit_types[M]].power;k+=O;break}}f+="			<tr>"+"				<td class=left>"+translate(S)+"</td>"+"				<td align=right>"+bD(r.units[S][0])+"</td>"+"				<td align=right>"+A+"</td>"+"				<td align=right>"+bD(O)+"</td>"+"			</tr>"}}f+="	<tr>"+"		<td class=left><b>"+translate("Total lost")+"</b></td>"+"		<td align=right colspan=3><span class="+UID["green"]+"><b>"+bD(k)+"</b></span></td>"+"	</tr>"}f+="			</table>"+"		</td>"+"		<td width=2%>&nbsp</td>"+"		<td width=49%>"+"			<table class="+UID["row_style"]+" width=100%>"+"				<tr>"+"					<td valign=middle colspan=3><b>"+i.name+"</b> ("+def_loc+")&nbsp;<span class="+UID["red"]+">"+(n.winner!="attacker"?translate("victorious"):translate("defeated"))+"</span></td>"+"				</tr><tr class="+UID["row_headers"]+">"+"					<td valign=middle width=40%><b>"+translate("Troops")+"</b></td>"+"					<td valign=middle width=20%><b>"+translate("Fought")+"</b></td>"+"					<td valign=middle width=20%><b>"+translate("lost")+"</b></td>"+"					<td valign=middle width=20%><b>"+translate("Might")+"</b></td>"+"				</tr>";if(i.units){var k=0;for(var S in i.units){if(S&&i.units[S]){var _=translate(S),D=1;if(i.anthropus){switch(S){case"Porter":_="Brats";D=3;break;case"Conscript":_="Cannibals";break;case"Spy":_="Stench";break;case"Halberdsman":_="She-Devils";D=2;break;case"Minotaur":_="Clubbers";D=2;break;case"Longbowman":_="Hurlers";D=3;break;case"SwiftStrikeDragon":_="Shredders";D=4;break;case"BattleDragon":_="Chieftan";D=4;break;case"ArmoredTransport":_="Shaggies";D=5;break;case"Giant":_="Bloods";D=5;break;case"FireMirror":_="Ragers";D=10;break;case"AquaTroop":_="Smash";D=5;break;case"StoneTroop":_="Launchers";D=5;break;case"FireTroop":_="Gnashers";D=5;break;case"WindTroop":_="Divers";D=5;break;default:_=translate(S);break}}var P=i.units[S][0]*D;var H=i.units[S][1]*D;var L=P!=H?P-H:0;var A=P!=H?"<span class="+UID["red"]+"><b>"+bD(P-H)+"</b></span>":0;var O=0;for(var M=0;M<all_unit_types.length;M++){if(all_unit_types[M]==S){O=L*Seed.stats.unit[all_unit_types[M]].power;k+=O;break}}f+="			<tr>"+"				<td class=left>"+_+"</td>"+"				<td align=right>"+bD(P)+"</td>"+"				<td align=right>"+A+"</td>"+"				<td align=right>"+bD(O)+"</td>"+"			</tr>"}}f+="	<tr>"+"		<td class=left><b>"+translate("Total lost")+"</b></td>"+"		<td align=right colspan=3><span class="+UID["green"]+"><b>"+bD(k)+"</b></span></td>"+"	</tr>"}f+="			</table>"+"		</td>"+"	</tr>"+"</table>";if(s||s.march||s.target){f+='<table style="margin-top:1px" width=98%>'+"	<tr valign=top align=center>"+"		<td width=49%>"+"			<table class="+UID["row_style"]+" width=100%>"+"				<tr class="+UID["row_headers"]+"><td colspan=3 class=left>"+translate("boost-combat")+"</td></tr>";if(s.march){for(var C in s.march){var B=s.march[C]<5?bD(Math.round(s.march[C]*100))+"%":bD(s.march[C]);var _=bo("name",C.replace(/ |_/g,"-"),"boosts").replace(":","");if(_.indexOf("n%")<=0&&_.indexOf("%boost%")<=0)f+="			<tr><td align=left colspan=2>"+_+"</td><td><b>"+B+"</b></td></tr>";else{if(_.indexOf("n%")>0)_=_.replace("n%",B);if(_.indexOf("%boost%")>0)_=_.replace("%boost%",B);f+="			<tr><td align=left colspan=3>"+_+"</td></tr>"}}}f+="			</table>"+"		</td>"+"		<td width=2%>&nbsp</td>"+"		<td width=49%>"+"			<table class="+UID["row_style"]+" width=100%>"+"				<tr class="+UID["row_headers"]+"><td colspan=3 class=left>"+translate("boost-combat")+"</td></tr>";if(s.target){for(var C in s.target){var B=s.target[C]<5?bD(Math.round(s.target[C]*100))+"%":bD(s.target[C]);var _=bo("name",C.replace(/ |_/g,"-"),"boosts").replace(":","");if(_.indexOf("n%")<=0&&_.indexOf("%boost%")<=0)f+="			<tr><td align=left colspan=2>"+_+"</td><td><b>"+B+"</b></td></tr>";else{if(_.indexOf("n%")>0)_=_.replace("n%",B);if(_.indexOf("%boost%")>0)_=_.replace("%boost%",B);f+="			<tr><td align=left colspan=3>"+_+"</td></tr>"}}}f+="			</table>"+"		</td>"+"	</tr>"+"</table>"}if(r.items&&r.items.length>0||i.items&&i.items.length>0){f+='<table style="margin-top:1px" width=98%>'+"	<tr valign=top align=center>"+"		<td width=49%>"+"			<table class="+UID["row_style"]+" width=100%>"+"				<tr class="+UID["row_headers"]+"><td colspan=3 class=left>"+translate("bonus-items")+"</td></tr>";if(r.items&&r.items.length>0){for(var C=0;C<r.items.length;C++)f+="			<tr><td align=left colspan=3>"+translate(r.items[C])+"</td></tr>"}f+="			</table>"+"		</td>"+"		<td width=2%>&nbsp</td>"+"		<td width=49%>"+"			<table class="+UID["row_style"]+" width=100%>"+"				<tr class="+UID["row_headers"]+"><td colspan=3 class=left>"+translate("bonus-items")+"</td></tr>";if(i.items&&i.items.length>0){for(var C=0;C<i.items.length;C++)f+="			<tr><td align=left colspan=3>"+translate(i.items[C])+"</td></tr>"}f+="			</table>"+"		</td>"+"	</tr>"+"</table>"}if(r.souls||i.souls){f+='<table style="margin-top:1px" width=98%>'+"	<tr valign=top align=center>"+"		<td width=49%>"+"			<table class="+UID["row_style"]+" width=100%>"+"				<tr class="+UID["row_headers"]+">"+"					<td valign=middle width=70%><b>"+translate("Troops")+"</b></td>"+"					<td valign=middle width=30%><b>"+translate("Souls")+"</b></td>"+"				</tr>";if(r.souls){var j=false;if(r.souls.soul_capacity==true){j=true;delete r.souls.soul_capacity}for(var S in r.souls){if(S&&!isNaN(r.souls[S])&&r.souls[S]>0){f+="			<tr>"+"				<td class=left>"+translate(S)+"</td>"+"				<td align=right>"+bD(r.souls[S])+"</td>"+"			</tr>"}}if(j){f+="	<tr>"+"		<td class=left colspan=2><span class="+UID["red"]+"><b>"+translate("mausoleums-full")+"</b></span></td>"+"	</tr>"}}f+="			</table>"+"		</td>"+"		<td width=2%>&nbsp</td>"+"		<td width=49%>"+"			<table class="+UID["row_style"]+" width=100%>"+"				<tr class="+UID["row_headers"]+">"+"					<td valign=middle width=60%><b>"+translate("Troops")+"</b></td>"+"					<td valign=middle width=20%><b>"+translate("Souls")+"</b></td>"+"					<td valign=middle width=20%><b>"+translate("Reaped")+"</b></td>"+"				</tr>";if(i.souls){var j=false;if(i.souls.soul_capacity==true){j=true;delete i.souls.soul_capacity}for(var S in i.souls){if(S&&!isNaN(i.souls[S])&&i.souls[S]>0){var F=i.souls[S];var I=0;if(i.souls.reaped_souls&&i.souls.reaped_souls[S]&&!isNaN(i.souls.reaped_souls[S])&&i.souls.reaped_souls[S]>0){I=i.souls.reaped_souls[S];F-=i.souls.reaped_souls[S];if(F<0)F=0}f+="			<tr>"+"				<td class=left>"+translate(S)+"</td>"+"				<td align=right>"+bD(F)+"</td>"+"				<td align=right>"+bD(I)+"</td>"+"			</tr>"}}if(j){f+="	<tr>"+"		<td class=left colspan=3><span class="+UID["red"]+"><b>"+translate("mausoleums-full")+"</b></span></td>"+"	</tr>"}}f+="			</table>"+"		</td>"+"	</tr>"+"</table>"}f+="</div>";return f},displayBreedingReport:function(e){var t=e.report;var n='<table style="margin-top:3px" width=100%>'+"	<tr valign=top align=center>"+"		<td width=100%><br><span class="+UID["red"]+"><b>"+translate("breeding-report").toUpperCase()+"</b></span></td>"+"	</tr></table><br>"+'<table style="margin-top:3px" width=100%>'+"	<tr valign=top align=left>"+"		<td width=70%>"+"			<label><b>"+translate("breeding-report-description")+"</b></label></td>"+"		<td width=30%>"+"			<label>"+translate("report-no")+" :</label><b>"+e.id+"</b><br>"+"			<label>"+(new Date(e.created_at*1e3)).myString()+"</label></td>"+"	</tr>"+"</table><br><br>"+'<div style="height:360px; max-height:360px; overflow-y:auto; white-space:pre-wrap;" width=100%>';var r=t.egg;for(var i in r){var s=r[i].type.substring(r[i].type.indexOf("::")+2);s=s=="CityGreatDragon"?"GreatDragon":s;var o=sanctuaryDragonRank[r[i].rank];dragon_type=r[i].gender+"-"+o;dragon_subtype=(i=="city_great_dragon"?"great_dragon":i).replace(/ |_/g,"-");n+='<center><table style="margin-top:3px" width=100%>'+"	<tr valign=top>"+"		<td width=100% align=center>"+"			<table class="+UID["row_style"]+" width=92%>"+"				<tr class="+UID["row_headers"]+">"+"					<td valign=middle width=100% colspan=2><b>"+bo(dragon_subtype,"rank-"+dragon_type,"dragons")+"</b></td>"+'				</tr><tr style="border-bottom: 1px solid #898989;">'+"					<td colspan=2>"+translate(r[i].gender)+" "+translate("level")+" "+r[i].level+"</td>"+"				</tr>";if(r[i].abilities||obj.length>0){var u=r[i].abilities;for(var a=0;a<u.length;a++){var f=bo("name",u[a].name.replace(/ |_/g,"-"),"boosts")+" "+u[a].level;var l=bo("description",u[a].name.replace(/ |_/g,"-"),"boosts");var c=u[a].rate<1?bD(u[a].rate*100)+"%":bD(u[a].rate);if(l.indexOf("n%")>0)l=l.replace("n%",c);if(l.indexOf("%boost%")>0)l=l.replace("%boost%",c);n+="<tr><td width=40%><b>"+f+"</b></td><td width=60%><span class=jewel>"+l+"</span></td></tr>"}}n+="			</table>"+"		</td>"+"	</tr>"+"</table></center>"}n+="</div>";return n},displayCurseReport:function(e){var t=Messages;var n=e.report;var r=translate("curse-report-received-body");if(typeof r=="object")r=r["from-non-alliance"];var i='<table style="margin-top:3px" width=100%>'+"	<tr valign=top align=center>"+"		<td width=100%><br><span class="+UID["red"]+"><b>"+translate("curse-report-received").toUpperCase()+"</b></span></td>"+"	</tr></table><br>"+'<table style="margin-top:3px" width=100%>'+"	<tr valign=top align=center>"+"		<td width=100%><b>"+translate("curse-report-received-subtitle")+"</b></td>"+"	</tr><tr><td>&nbsp;</td>"+"	</tr><tr valign=top align=left>"+"		<td><label>"+translate("report-no")+" :</label><b>"+e.id+"</b></td>"+"	</tr><tr valign=top align=left>"+"		<td><label>"+(new Date(e.created_at*1e3)).myString()+"</label></td>"+"	</tr>"+"</table><br><br>"+'<center><div style="width:90%; max-width:90%; white-space:pre-wrap;" align=left>'+r.replace("$PlayerName$","<b>"+n.cursor_name+"</b>").replace("$ResourceName$","<b>"+translate(n.resource_affected)+"</b>").replace("$ResourceName$","<b>"+translate(n.resource_affected)+"</b>")+"</div></center>";return i},displayHatchingReport:function(e){var t=e.report;var n='<table style="margin-top:3px" width=100%>'+"	<tr valign=top align=center>"+"		<td width=100%><br><span class="+UID["red"]+"><b>"+translate("hatching-report").toUpperCase()+"</b></span></td>"+"	</tr></table><br>"+'<table style="margin-top:3px" width=100%>'+"	<tr valign=top align=left>"+"		<td width=70%>"+"			<label><b>"+translate("hatching-report-description")+"</b></label></td>"+"		<td width=30%>"+"			<label>"+translate("report-no")+" :</label><b>"+e.id+"</b><br>"+"			<label>"+(new Date(e.created_at*1e3)).myString()+"</label></td>"+"	</tr>"+"</table><br><br>"+'<div style="height:360px; max-height:360px; overflow-y:auto; white-space:pre-wrap;" width=100%>';var r=t.dragon;for(var i in r){var s=r[i].type.substring(r[i].type.indexOf("::")+2);s=s=="CityGreatDragon"?"GreatDragon":s;var o=sanctuaryDragonRank[r[i].rank];dragon_type=r[i].gender+"-"+o;dragon_subtype=(i=="city_great_dragon"?"great_dragon":i).replace(/ |_/g,"-");n+='<center><table style="margin-top:3px" width=100%>'+"	<tr valign=top>"+"		<td width=100% align=center>"+"			<table class="+UID["row_style"]+" width=92%>"+"				<tr class="+UID["row_headers"]+">"+"					<td valign=middle width=100% colspan=2><b>"+bo(dragon_subtype,"rank-"+dragon_type,"dragons")+"</b></td>"+'				</tr><tr style="border-bottom: 1px solid #898989;">'+"					<td colspan=2>"+translate(r[i].gender)+" "+translate("level")+" "+r[i].level+"</td>"+"				</tr>";if(r[i].abilities||obj.length>0){var u=r[i].abilities;for(var a=0;a<u.length;a++){var f=bo("name",u[a].name.replace(/ |_/g,"-"),"boosts")+" "+u[a].level;var l=bo("description",u[a].name.replace(/ |_/g,"-"),"boosts");var c=u[a].rate<1?bD(u[a].rate*100)+"%":bD(u[a].rate);if(l.indexOf("n%")>0)l=l.replace("n%",c);if(l.indexOf("%boost%")>0)l=l.replace("%boost%",c);n+="<tr><td width=40%><b>"+f+"</b></td><td width=60%><span class=jewel>"+l+"</span></td></tr>"}}n+="			</table>"+"		</td>"+"	</tr>"+"</table></center>"}n+="</div>";return n},fL:function(e){var t=Messages;var n=e.report;var r="<b>"+(e.from?e.from.name:translate("system-title")).toUpperCase()+"</b>"+(e.from&&e.from.alliance?" / "+e.from.alliance.name:"");var i=n.alliance?n.alliance.name:Seed.player.name;var s='<table style="margin-top:3px" width=95% align=center>'+"	<tr valign=top align=center>"+"		<td width=100%><br><b>"+r+"</b></td>"+"	</tr></table><br>"+'<table style="margin-top:3px" width="520px" align=center>'+"	<tr valign=top>"+"		<td width=70% align=left><b>"+translate("To")+" : </b>"+i+"<br>"+"		<td width=30% align=right><b>"+translate("Subject")+" : </b>"+(new Date(e.created_at*1e3)).myString()+"</td>"+"	</tr><tr valign=top>"+'		<td colspan=2 align=left style="white-space:pre-wrap"><b>'+translate("Subject")+" : </b>"+e.summary+"</td>"+"	</tr>"+"</table><br>"+"<center><div class="+UID["status_ticker"]+'	 style="height:470px; max-height:470px; width:520px; max-width:520px; overflow-y:auto; white-space:pre-wrap; background-color:white;" align=left>'+n.message+"</div></center>";return s},displayReinforcement:function(e){var t=e.report;var n=t.sender;var r=n.location;var i=t.recipient;var s=t.location;var o='<table style="margin-top:3px" width=100%>'+"	<tr valign=top align=center>"+"		<td width=100%><br><span class="+UID["red"]+"><b>"+translate("reinforcements-have-arrived").toUpperCase()+"</b></span></td>"+"	</tr></table><br>"+'<table style="margin-top:3px" width=100%>'+"	<tr valign=top align=left>"+"		<td width=70%>"+"			<label>"+translate("From")+" : </label><b>"+n.name+"</b>&nbsp;("+r.title+" "+translate("at")+" "+r.x+" / "+r.y+")</td>"+"		<td width=30%>"+"			<label>"+translate("report-no")+" :</label><b>"+e.id+"</b></td>"+"	</tr><tr valign=top align=left>"+"		<td width=70%>&nbsp;</td>"+"		<td width=30%>"+"			<label>"+(new Date(e.created_at*1e3)).myString()+"</label></td>"+"	</tr><tr valign=top align=left>"+"		<td colspan=2>"+"			<label>"+translate("To")+" : </label><b>"+i.name+"</b>&nbsp;("+(s.terrain=="Outpost"?translate(s.title):s.title)+" "+translate("at")+" "+s.x+" / "+s.y+")</td>"+"	</tr>"+"</table><br><br>"+'<div style="height:360px; max-height:360px; overflow-y:auto; white-space:pre-wrap;" width=100%>'+'<center><table style="margin-top:3px" width=60%>'+"	<tr valign=top>"+"		<td width=100%>"+"			<table class="+UID["row_style"]+" width=100%>"+"				<tr class="+UID["row_headers"]+">"+"					<td valign=middle width=60%><b>"+translate("Troops")+"</b></td>"+"					<td valign=middle width=20%><b>"+translate("Quantity")+"</b></td>"+"				</tr>";if(n.units){for(var u in n.units){if(u&&n.units[u]){o+="			<tr>"+"				<td class=left>"+translate(u)+"</td>"+"				<td align=right>"+bD(n.units[u][0])+"</td>"+"			</tr>"}}}o+="			</table>"+"		</td>"+"	</tr>"+"</table></center>"+"</div>";return o},displaySentinelReport:function(e){var t=Messages;var n=e.report;var r="<b>Dragon of Atlantis</b>";var i=Seed.player.name;var s='<table style="margin-top:3px" width=95% align=center>'+"	<tr valign=top align=center>"+"		<td width=100%><br><b>"+r+"</b></td>"+"	</tr></table><br>"+'<table style="margin-top:3px" width="520px" align=center>'+"	<tr valign=top>"+"		<td width=70% align=left><b>"+translate("To")+" : </b>"+i+"<br>"+"		<td width=30% align=right><b>"+translate("Subject")+" : </b>"+(new Date(e.created_at*1e3)).myString()+"</td>"+"	</tr><tr valign=top>"+'		<td colspan=2 align=left style="white-space:pre-wrap"><b>'+translate("Subject")+" : </b>"+e.summary+"</td>"+"	</tr>"+"</table><br>"+"<center><div class="+UID["status_ticker"]+'	 style="height:470px; max-height:470px; width:520px; max-width:520px; overflow-y:auto; white-space:pre-wrap; background-color:white;" align=left>';if(n.warnings){var o=n.warnings,u="",a="",f=Seed.cities[CAPITAL.id].name;if(o.attacker_name)u=o.attacker_name;if(o.attacker_title&&o.attacker_title.alliance){if(u)u=u+" / "+o.attacker_title.alliance;else u=o.attacker_title.alliance}if(o.march_type&&o.march_type=="SpyMarch")a=translate("sentinel-warning-verb-spy");else a=translate("sentinel-warning-verb-attack");if(o.outpost_attack){var l=false;for(var c=0;c<Seed.cities.length&&!l;++c){if(Seed.cities[c]&&Seed.cities[c].id==o.march_incoming){if(Seed.cities[c].type=="Outpost")f=translate(Seed.cities[c].outpost_type);else f=Seed.cities[c].name;l=true}}}s+="	<br>"+translate("sentinel-warning-march-incoming").replace("$CITY_NAME$","<b>"+f+"</b>")+"	<br><br>"+translate("sentinel-warning-march-type").replace("$MARCH_VERB$","<b>"+a+"</b>");if(o.march_arrival_time)s+="	<br><br>"+translate("sentinel-warning-march-arrival-time").replace("$ARRIVES_AT$","<b>"+o.march_arrival_time+"</b>");if(o.attacker_coords)s+="	<br><br>"+translate("sentinel-warning-attacker-coords").replace("$CITY_X$","<b>"+o.attacker_coords.x+"</b>&nbsp;").replace("$CITY_Y$","&nbsp;<b>"+o.attacker_coords.y+"</b>");if(o.attacker_units){var h=[],p="";for(var d in o.attacker_units){var v="- "+bD(o.attacker_units[d]," ")+" "+translate(d);h.push(v)}if(h.length>0)p=h.join("<br>");if(p)s+="	<br><br>"+translate("sentinel-warning-attacker-types").replace("$UNITS$","<br><b>"+p+"</b>")}if(!as(u))s+="<br><br>"+translate("sentinel-warning-attacker-name").replace("$ATTACKER_RACE$","<b>"+o.attacker_title.race+"</b>").replace("$ATTACKER_NAME$","<b>"+u+"</b>")}s+="<br><br>"+translate("sentinel-warning-prepare-for-battle")+"</div></center>";return s},displaySpyReport:function(e){var t=e.report;var n=t.attacker;var r=t.defender;var i="";var s="";var o=false;var u=t.location.terrain=="Outpost"?translate(t.location.title):t.location.terrain=="City"?t.location.title:"";if(u=="")u=translate(t.location.terrain)+" "+translate("level")+" "+t.location.level;var a='<table style="margin-top:3px" width=98%>'+"	<tr valign=top align=center>"+"		<td width=100%><br><b><span class="+UID["red"]+"><b>"+translate("spy-report-title").toUpperCase()+"</b></span></b></td>"+"	</tr></table><br>"+'<table style="margin-top:3px" width=98%>'+"	<tr valign=top>"+"		<td width=50% align=left><label>"+translate("report-no")+" :</label><b>"+e.id+"</b></td>"+"		<td width=50% align=right><label>"+translate("location")+" :</label><b>"+u+"</b></td>"+"	</tr><tr valign=top>"+"		<td width=50% align=left><label>"+(new Date(e.created_at*1e3)).myString()+"</label></td>"+"		<td width=50% align=right><b>"+t.location.x+" / "+t.location.y+"</b></td>"+"	</tr>"+"</table><br><br>"+'<table style="margin-top:3px" width=98%>'+"	<tr valign=top align=center>"+"		<td width=49%>"+"			<table class="+UID["row_style"]+" width=100%>"+"				<tr>"+"					<td valign=middle colspan=3><b>"+n.name+"</b>&nbsp;<span class="+UID["red"]+">"+(t.winner=="attacker"?translate("victorious"):translate("defeated"))+"</span></td>"+"				</tr><tr class="+UID["row_headers"]+">"+"					<td valign=middle width=60%><b>"+translate("Troops")+"</b></td>"+"					<td valign=middle width=20%><b>"+translate("Fought")+"</b></td>"+"					<td valign=middle width=20%><b>"+translate("lost")+"</b></td>"+"				</tr>";if(n.units){for(var f in n.units){if(f&&n.units[f]){var l=n.units[f][0]!=n.units[f][1]?"<span class="+UID["red"]+"><b>"+bD(n.units[f][0]-n.units[f][1])+"</b></span>":0;a+="			<tr>"+"				<td class=left>"+translate(f)+"</td>"+"				<td align=right>"+bD(n.units[f][0])+"</td>"+"				<td align=right>"+l+"</td>"+"			</tr>"}}}a+="			</table>"+"		</td>"+"		<td width=2%>&nbsp</td>"+"		<td width=49%>"+"			<table class="+UID["row_style"]+" width=100%>"+"				<tr>"+"					<td valign=middle colspan=3><b>"+r.name+"</b>&nbsp;<span class="+UID["red"]+">"+(t.winner!="attacker"?translate("victorious"):translate("defeated"))+"</span></td>"+"				</tr><tr class="+UID["row_headers"]+">"+"					<td valign=middle width=60%><b>"+translate("Troops")+"</b></td>"+"					<td valign=middle width=20%><b>"+translate("Fought")+"</b></td>"+"					<td valign=middle width=20%><b>"+translate("lost")+"</b></td>"+"				</tr>";if(r.units){for(var f in r.units){if(f&&r.units[f]){var c=translate(f),h=1;if(r.anthropus){switch(f){case"Porter":c="Brats";h=3;break;case"Conscript":c="Cannibals";break;case"Spy":c="Stench";break;case"Halberdsman":c="She-Devils";h=2;break;case"Minotaur":c="Clubbers";h=2;break;case"Longbowman":c="Hurlers";h=3;break;case"SwiftStrikeDragon":c="Shredders";h=4;break;case"BattleDragon":c="Chieftan";h=4;break;case"ArmoredTransport":c="Shaggies";h=5;break;case"Giant":c="Bloods";h=5;break;case"FireMirror":c="Ragers";h=10;break;case"AquaTroop":c="Smash";h=5;break;case"StoneTroop":c="Launchers";h=5;break;case"FireTroop":c="Gnashers";h=5;break;case"WindTroop":c="Divers";h=5;break;default:c=translate(f);break}}var p=r.units[f][0]*h;var d=r.units[f][1]*h;var l=p!=d?"<span class="+UID["red"]+"><b>"+bD(p-d)+"</b></span>":0;a+="			<tr>"+"				<td class=left>"+c+"</td>"+"				<td align=right>"+bD(p)+"</td>"+"				<td align=right>"+l+"</td>"+"			</tr>"}}}a+="			</table>"+"		</td>"+"	</tr>"+"</table><br><br>"+'<div style="height:380px; max-height:380px; overflow-y:auto;" width=98%>'+'<table style="margin-top:3px" width=98%>'+"	<tr valign=top align=center>"+"		<td width=49%>"+"			<table class="+UID["row_style"]+" width=100%>"+"				<tr class="+UID["row_headers"]+"><td colspan=2 class=left>"+translate("Resources")+"</td></tr>";var v=r.intel.resources;for(var m=0;m<transportable_resource_types.length;m++){var g=transportable_resource_types[m];if(g=="blue_energy")g="blueenergy250k";var y=false;if(v){for(var f in v){if(f==transportable_resource_types[m]){var b=bV(v[f])>0?"<b>"+bD(o?bV(v[f])*-1:bV(v[f]))+"</b>":0;a+="		<tr><td class=left width=50%>"+translate(g)+"</td><td align=right width=50%>"+b+"</td></tr>";y=true}}}if(!y)a+="		<tr><td class=left width=50%>"+translate(g)+"</td><td align=right width=50%>0</td></tr>"}a+="			</table><br>"+"			<table class="+UID["row_style"]+" width=100%>"+"				<tr class="+UID["row_headers"]+">"+"					<td class=left width=70%>"+translate("Research")+"</td>"+"					<td class=left width=30%>"+translate("Level")+"</td></tr>";var w=r.intel.research;if(w){for(var f in w)a+="		<tr><td class=left width=50%>"+translate(f)+"</td><td align=right width=50%>"+bV(w[f])+"</td></tr>"}a+="			</table>"+"		</td>"+"		<td width=2%>&nbsp</td>"+"		<td width=49% align=left>";if(r.intel.last_login)a+="		<label>"+translate("last-time-awake")+" :</label><b>"+(new Date(r.intel.last_login*1e3)).myString()+"</b><br><br>";a+="			<table class="+UID["row_style"]+" width=100%>"+"				<tr class="+UID["row_headers"]+">"+"					<td class=left width=50%>"+translate("Units")+"</td>"+"					<td class=left width=50%>"+translate("Qty")+"</td></tr>";var E=r.intel.defenders;if(E){for(var m=0;m<all_unit_types.length;m++){for(var f in E){if(f==all_unit_types[m]&&bV(E[f])>0)a+="		<tr><td class=left width=50%>"+translate(f)+"</td><td align=right width=50%>"+bV(E[f])+"</td></tr>"}}}a+="			</table>"+"		</td>"+"	</tr>"+"</table><br>";var S=Seed.player.research["Clairvoyance"];if(!S)S=0;else if(S>10)S=10;a+='<center><div align=left width=98% style="white-space:pre-wrap;"><label>'+translate("spy-tip-"+S)+"&nbsp;"+translate("spy-tip-prefix")+"</label></div></center><br>"+"</div>";return a},displayTournamentAwardMessage:function(e){var t=e.report,n="",r="";if(t.leaderboard)r=translate("award-tournament-description").replace("$type",translate("you-placed")).replace("$rank",t.leaderboard.rank);else r=translate("award-tournament-description").replace("$type",translate("you-placed"));var n='<table style="margin-top:3px" width=100%>'+"	<tr valign=top align=center>"+"		<td width=100%><br><span class="+UID["red"]+"><b>"+translate("award-tournament-subject").toUpperCase()+"</b></span></td>"+"	</tr></table><br>"+'<table style="margin-top:3px" width=100%>'+"	<tr valign=top align=left>"+'		<td width=70% align=left style="white-space:pre-wrap;">'+"			<label><b>"+r+"</b></label></td>"+"		<td width=30%>"+"			<label>"+translate("report-no")+" :</label><b>"+e.id+"</b><br>"+"			<label>"+(new Date(e.created_at*1e3)).myString()+"</label></td>"+"	</tr>"+"</table><br><br>"+'<div style="height:360px; max-height:360px; overflow-y:auto; white-space:pre-wrap;" width=100%>'+'<center><table style="margin-top:3px" width=70%>'+"	<tr valign=top class="+UID["row_headers"]+">"+"		<td valign=middle width=100%><b>"+translate("you-won")+"</b></td>"+"	</tr>";if(t.prize)n+="		<tr><td>"+t.prize.quantity+" "+translate(t.prize.item_type)+"</td></tr>";n+="</table></center></div>";return n},displayContestPrizeReport:function(e){var t=e.report,n="";var n='<table style="margin-top:3px" width=100%>'+"	<tr valign=top align=center>"+"		<td width=100%><br><span class="+UID["red"]+"><b>"+e.summary.toUpperCase()+"</b></span></td>"+"	</tr></table><br>"+'<table style="margin-top:3px" width=100%>'+"	<tr valign=top align=left>"+'		<td width=70% align=left style="white-space:pre-wrap;">'+"			<label><b>"+e.summary+"</b></label></td>"+"		<td width=30%>"+"			<label>"+translate("report-no")+" :</label><b>"+e.id+"</b><br>"+"			<label>"+(new Date(e.created_at*1e3)).myString()+"</label></td>"+"	</tr>"+"</table><br><br>"+'<div style="height:360px; max-height:360px; overflow-y:auto; white-space:pre-wrap;" width=100%>'+'<center><table style="margin-top:3px" width=70%>'+"	<tr valign=top class="+UID["row_headers"]+">"+"		<td valign=middle width=100%><b>"+translate("you-won")+"</b></td>"+"	</tr>";for(var r=0;r<t.prizes.length;r++)n+="		<tr><td>"+t.prizes[r].quantity+" "+translate(t.prizes[r].name)+"</td></tr>";n+="</table></center></div>";return n},displayTradingReport:function(e){var t="",n="",r,i,s,o,u="";var a=e.report;if(a.trading_report)i=a.trading_report;if(i&&i.details)s=i.details;if(s){o=s.offer;switch(s.type){case"sale":t="sale-summary";n="Buyer";r=s.purchaser;break;case"delivery":t="delivery-summary";n="Seller";r=o.seller;break;case"pillaged":t="pillaged-summary";break;case"expired":t="expired-summary";break}}else{t="unknown";n="unknown"}if(!as(r))u=translate(n)+"&nbsp;:&nbsp;<b>"+r.name.toUpperCase()+"</b>"+(r.alliance?" / "+r.alliance.name:"");var f='<table style="margin-top:3px" width=100%>'+"	<tr valign=top align=center>"+"		<td width=100%><br><span class="+UID["red"]+"><b>"+translate("trading-report").toUpperCase()+"</b></span></td>"+"	</tr></table><br>"+'<table style="margin-top:3px" width=100%>'+"	<tr valign=top align=left>"+"		<td width=70%>"+"			<label><b>"+translate(t)+"</b></label></td>"+"		<td width=30%>"+"			<label>"+translate("report-no")+" :</label><b>"+e.id+"</b></td>"+"	</tr><tr valign=top align=left>"+"		<td width=70%>&nbsp;</td>"+"		<td width=30%>"+"			<label>"+(i?jn(i.created_at).myString():(new Date(e.created_at*1e3)).myString())+"</label></td>";if(!as(r))f+="	</tr><tr valign=top align=left>"+"		<td colspan=2>"+u+"</td>";f+="	</tr>"+"</table><br><br>"+'<div style="height:360px; max-height:360px; overflow-y:auto; white-space:pre-wrap;" width=100%>'+'<center><table style="margin-top:3px" width=60%>'+"	<tr valign=top>"+"		<td width=100%>"+"			<table class="+UID["row_style"]+" width=90%>"+"				<tr class="+UID["row_headers"]+">"+"					<td valign=middle width=60%><b>"+translate("Ressource")+"</b></td>"+"					<td valign=middle width=20%><b>"+translate("Quantity")+"</b></td>"+"					<td valign=middle width=20%><b>"+translate("Price")+"</b></td>"+"				</tr>";if(o){f+="			<tr>"+"				<td>"+translate(o.product)+"</td>"+"				<td>"+bD(o.units)+"</td>"+"				<td>"+bD(o.price)+"</td>"+"			</tr>"}f+="			</table>"+"		</td>"+"	</tr>"+"</table></center>"+"</div>";return f},displayTransportReport:function(e){var t=e.report;var n=t.sender;var r=n.location;var i=t.recipient;var s=t.location;var o=t.spoils;var u='<table style="margin-top:3px" width=100%>'+"	<tr valign=top align=center>"+"		<td width=100%><br><span class="+UID["red"]+"><b>"+translate("transfer-goods").toUpperCase()+"</b></span></td>"+"	</tr></table><br>"+'<table style="margin-top:3px" width=100%>'+"	<tr valign=top align=left>"+"		<td width=70%>"+"			<label>"+translate("From")+" : </label><b>"+n.name+"</b>&nbsp;("+r.title+" "+translate("at")+" "+r.x+" / "+r.y+")</td>"+"		<td width=30%>"+"			<label>"+translate("report-no")+" :</label><b>"+e.id+"</b></td>"+"	</tr><tr valign=top align=left>"+"		<td width=70%>&nbsp;</td>"+"		<td width=30%>"+"			<label>"+(new Date(e.created_at*1e3)).myString()+"</label></td>"+"	</tr><tr valign=top align=left>"+"		<td colspan=2>"+"			<label>"+translate("To")+" : </label><b>"+i.name+"</b>&nbsp;("+(s.terrain=="Outpost"?translate(s.title):s.title)+" "+translate("at")+" "+s.x+" / "+s.y+")</td>"+"	</tr>"+"</table><br><br>"+'<div style="height:360px; max-height:360px; overflow-y:auto; white-space:pre-wrap;" width=100%>'+'<center><table style="margin-top:3px" width=60%>'+"	<tr valign=top>"+"		<td width=100%>"+"			<table class="+UID["row_style"]+" width=100%>"+"				<tr class="+UID["row_headers"]+">"+"					<td valign=middle width=60%><b>"+translate("Troops")+"</b></td>"+"					<td valign=middle width=20%><b>"+translate("Quantity")+"</b></td>"+"				</tr>";if(n.units){for(var a in n.units){if(a&&n.units[a]){u+="			<tr>"+"				<td class=left>"+translate(a)+"</td>"+"				<td align=right>"+bD(n.units[a][0])+"</td>"+"			</tr>"}}}u+="			</table>"+"		</td>"+"	</tr><tr valign=top><td>&nbsp;</td>"+"	</tr><tr valign=top>"+"		<td width=100%>"+"			<table class="+UID["row_style"]+" width=100%>"+"				<tr class="+UID["row_headers"]+">"+"					<td valign=middle width=60%><b>"+translate("Resources")+"</b></td>"+"					<td valign=middle width=20%><b>"+translate("Quantity")+"</b></td>"+"				</tr>";if(o){for(var f=0;f<transportable_resource_types.length;f++){var l=transportable_resource_types[f];if(l=="blue_energy")l="blueenergy250k";var c=false;for(var a in o){if(a==transportable_resource_types[f]){u+="		<tr><td class=left width=50%>"+translate(l)+"</td><td align=right width=50%><b>"+bD(bV(o[a]))+"</b></td></tr>";c=true}}if(!c)u+="		<tr><td class=left width=50%>"+translate(l)+"</td><td align=right width=50%>0</td></tr>"}}u+="			</table>"+"		</td>"+"	</tr>"+"</table></center>"+"</div>";return u},getFirstPage:function(e,t){var n="all";MyAjax.messageList(n,1,MAX_READ,function(e){if(t)t(Messages.details)})},updateUnreadCount:function(){var e=Messages,t=0,n=0,r="";for(var i in e.details){t++;n+=e.details[i].unread?1:0}e.unread_count=n;e.known_count=t;if(document.getElementById(UID["tabInbox_UnreadCount"])){if(Data.options.currentTab=="Inbox")r="yellow";else r="red";document.getElementById(UID["tabInbox_UnreadCount"]).innerHTML=translate("Inbox")+(e.unread_count>0?"&nbsp<font color="+r+">"+e.unread_count+"</font>":"")}},dealMessages:function(e,t,n){var r=Messages;r.mode=e;r.period=t;r.bO=n;r.messageDeletion=true;r.totMessages=0;r.pagesMessages=0;r.steps=e=="del"?3:1;r.step=0;r.percent=bV(r.step*100/r.steps);r.read_battle=0;r.total_battle=0;r.delete_count=0;r.total_to_delete=0;r.old_percent=0;r.result_count=0;progressBar.update({step:r.percent});MyAjax.messageList("all",-1,12,function(e){var t=Messages;if(e==null||e.total==null){t.messageDeletion=false;return}var t=Messages;t.totMessages=bV(e.total);if(t.totMessages==0){t.messageDeletion=false;return}else{t.pagesMessages=bV(t.totMessages/MAX_READ);if(t.totMessages%MAX_READ!=0)t.pagesMessages++;t.steps+=t.pagesMessages;t.pageReading=t.pagesMessages;clearTimeout(t.readPagesTimer);t.readPagesTimer=setTimeout(t.readPages,2e3)}});r.dA()},dP:function(e){var t=Messages;t.bO=e;t.messageDeletion=true;t.steps=1;t.step=-1;t.percent=0;t.delete_count=0;t.total_to_delete=0;t.delete_percent=0;t.old_percent=0;t.result_count=0;progressBar.update({step:t.percent});for(var n in Messages.details){if(Messages.details[n].checked)t.total_to_delete++}if(t.total_to_delete>0)t.deleteSelected();else t.messageDeletion=false;t.dA()},dA:function(){var e=Messages;if(e.messageDeletion){setTimeout(e.dA,1e3)}else{if(e.bO){e.bO({done:true,count:e.result_count});return}}},readPages:function(){var e=Messages;if(e.pageReading>0){var t=(e.pageReading-1)*MAX_READ/12+1;var n=e.pageReading*MAX_READ/12;var r=bV(e.totMessages/12)+(e.totMessages%12!=0?1:0);if(n>r)n=r;var i=translate("Read pages ")+t+" "+translate("to")+" "+n+" "+translate("of")+" "+r;clearTimeout(e.readPagesTimer);e.step++;e.percent=bV(e.step*100/e.steps);progressBar.update({step:e.percent,stepText:i});MyAjax.messageList("all",e.pageReading,MAX_READ,function(e){var t=Messages;if(e!=null&&e.report_notifications&&e.report_notifications!=null&&t.pageReading>0){t.pageReading--;t.readPagesTimer=setTimeout(t.readPages,2e3)}})}else{clearTimeout(e.readPagesTimer);if(e.mode=="del")e.readPagesTimer=setTimeout(e.selectMessages,2e3);else e.messageDeletion=false}},selectMessages:function(){var e=Messages;e.step++;e.percent=bV(e.step*100/e.steps);progressBar.update({step:e.percent,stepText:translate("Selecting messages to delete")+"..."});for(var t in Messages.details){var n=false,r=Messages.details[t];if(!as(r)){switch(r.type){case"BattleReport":if(!as(r.report)){if(Data.options.messages_delete.rptBattle&&r.report.sanctuary){n=r.report.sanctuary;if(n&&(Data.options.messages_delete.rptExceptMyAttacks&&r.report.attacker.name==Seed.player.name||Data.options.messages_delete.rptExceptYourAttacks&&r.report.attacker.name!=Seed.player.name))n=false}else if(Data.options.messages_delete.rptAnthropus&&r.report.defender.anthropus){n=r.report.defender.anthropus}}else if(Data.options.messages_delete.rptBattle||Data.options.messages_delete.rptAnthropus){e.toRead.push(t);e.total_battle++}break;case"CurseReport":n=Data.options.messages_delete.rptCurse;break;case"SentinelWarning":n=Data.options.messages_delete.msgSentinel;break;case"SpyReport":n=Data.options.messages_delete.rptSpy;break;case"ReinforcementsReport":n=Data.options.messages_delete.rptReinforcement;break;case"TradingReport":n=Data.options.messages_delete.rptTrading;break;case"TransportMarchReport":n=Data.options.messages_delete.rptTransport;break;case"PlayerMessage":n=Data.options.messages_delete.msgPlayer;break;case"AllianceMessage":n=Data.options.messages_delete.msgAlliance;break;case"SystemMessage":case"Leaderboard::TournamentAwardMessage":case"TargetedMessage":n=Data.options.messages_delete.msgGame;break;case"Messages::Breeding":case"Messages::Hatching":n=Data.options.messages_delete.rptBreeding;break;default:n=false}if(n&&!Data.options.messages_delete.dateAll)if(r.created_at<e.period[0]||r.created_at>e.period[1])n=false;if(n||r.checked){r.checked=true;e.total_to_delete++}}}clearTimeout(e.readPagesTimer);if(e.total_battle>0&&e.toRead.length>0)e.readPagesTimer=setTimeout(e.readBattles,2e3);else e.readPagesTimer=setTimeout(e.deleteSelected,2e3)},readBattles:function(){var e=Messages;clearTimeout(e.readPagesTimer);e.read_battle++;e.battle_percent=Math.floor(e.read_battle*100/(e.total_battle==0?1:e.total_battle));e.percent=bV(e.step*100/e.steps);e.percent=e.percent+e.battle_percent/e.steps;if(e.percent!=e.old_percent){progressBar.update({step:e.percent,stepText:translate("Reading battle reports")+"..."+"<br>"+e.read_battle+"/"+e.total_battle});e.old_percent=e.percent}var t=e.toRead[0];if(!t){e.toRead.shift();if(e.toRead.length>0)e.readPagesTimer=setTimeout(e.readBattles,1500);else e.readPagesTimer=setTimeout(e.deleteSelected,2e3);return}MyAjax.messageDetail(t,function(e){var t=Messages;if(e!=null&&e.report_notification&&e.report){var n=false,r=Messages.details[e.report_notification.id];if(!as(r.report)){if(Data.options.messages_delete.rptBattle&&r.report.sanctuary){n=r.report.sanctuary;if(n&&(Data.options.messages_delete.rptExceptMyAttacks&&r.report.attacker.name==Seed.player.name||Data.options.messages_delete.rptExceptYourAttacks&&r.report.attacker.name!=Seed.player.name))n=false}else if(Data.options.messages_delete.rptAnthropus&&r.report.defender.anthropus){n=r.report.defender.anthropus}}else n=true;if(n&&!Data.options.messages_delete.dateAll)if(r.created_at<t.period[0]||r.created_at>t.period[1])n=false;if(n){r.checked=n;t.total_to_delete++}}t.toRead.shift();if(t.toRead.length>0)t.readPagesTimer=setTimeout(t.readBattles,1500);else{t.readPagesTimer=setTimeout(t.deleteSelected,2e3)}})},deleteSelected:function(){var e=Messages;e.step++;e.percent=bV(e.step*100/e.steps);e.old_percent=0;for(var t in Messages.details){if(Messages.details[t].checked){e.delete_count++;e.delete_percent=Math.floor(e.delete_count*100/(e.total_to_delete==0?1:e.total_to_delete));e.percent=bV(e.step*100/e.steps);e.percent=e.percent+e.delete_percent/e.steps;if(e.percent!=e.old_percent){progressBar.update({step:e.percent,stepText:translate("Deleting messages")+"..."+"<br>"+e.delete_count+"/"+e.total_to_delete});e.old_percent=e.percent}if(e.idsToDelete.length>MAX_DELETE){MyAjax.messageDelete(e.idsToDelete);e.idsToDelete=[]}e.idsToDelete.push(t);e.result_count++}}if(e.idsToDelete.length>0){MyAjax.messageDelete(e.idsToDelete);e.idsToDelete=[]}setTimeout(e.deleteComplete,Math.randRange(2e3,5e3));return},deleteComplete:function(){var e=Messages;e.messageDeletion=false}};var Names={troops:{names:[[0,"Porter","Porter"],[1,"Conscript","Conscr"],[2,"Spy","Spy"],[3,"Halberdsman","Halbrd"],[4,"Minotaur","Mino"],[5,"Longbowman","LBM"],[6,"SwiftStrikeDragon","SSDrg"],[7,"BattleDragon","BatDrg"],[8,"ArmoredTransport","ATrans"],[9,"Giant","Giant"],[10,"FireMirror","FireM"],[11,"GreatDragon","GrtDrg"],[12,"WaterDragon","WatDrg"],[13,"StoneDragon","StnDrg"],[14,"FireDragon","FireDrg"],[15,"WindDragon","WndDrg"],[16,"IceDragon","IceDrg"],[17,"SwampDragon","SwpDrg"],[18,"SpectralDragon","SpctDrg"],[19,"AquaTroop","Fang"],[20,"StoneTroop","Ogre"],[21,"FireTroop","Magma"],[22,"WindTroop","Banshee"],[23,"IceTroop","SReaper"],[24,"SwampTroop","Venom"],[25,"PackDragon","PackDrg"],[26,"FrostGiant","FGiant"],[27,"ForestDragon","ForDrg"],[28,"ForestTroop","Titan"],[29,"DesertDragon","DesDrg"],[30,"DesertTroop","Strider"],[31,"DarkSlayer","Slayer"],[32,"LightningCannon","LCannon"],[33,"ChargeTroop","Storm"],[34,"ChronoDragon","Chrono"],[35,"VengeWyrm","Wyrm"],[36,"DimensionalRuiner","Ruiner"],[37,"KaiserDragon","Kaiser"],[38,"ArcticLeviathan","Leviathan"],[39,"Harrier","Harr."],[40,"CaveDragon","CavDrg"],[41,"Defendo","Golem"],[42,"LunaDragon","LunaDrg"],[43,"ShadowStalker","Stalker"],[44,"Shaman","Shaman"],[45,"WarScarab","War Scarab"],[46,"VoltRanger","Volt Ranger"]]},transco:{AquaTroopRespiratorStack100:["AquaTroopRespirator",100],AquaTroopRespiratorStack500:["AquaTroopRespirator",500],AquaTroopRespiratorStack1000:["AquaTroopRespirator",1e3],StoneTroopItemStack100:["StoneTroopItem",100],StoneTroopItemStack500:["StoneTroopItem",500],StoneTroopItemStack1000:["StoneTroopItem",1e3],FireTroopItemStack100:["FireTroopItem",100],FireTroopItemStack500:["FireTroopItem",500],FireTroopItemStack1000:["FireTroopItem",1e3],WindTroopItemStack100:["WindTroopItem",100],WindTroopItemStack500:["WindTroopItem",500],WindTroopItemStack1000:["WindTroopItem",1e3],IceTroopItemStack100:["IceTroopItem",100],IceTroopItemStack500:["IceTroopItem",500],IceTroopItemStack1000:["IceTroopItem",1e3],SwampTroopItemStack100:["SwampTroopItem",100],SwampTroopItemStack500:["SwampTroopItem",500],SwampTroopItemStack1000:["SwampTroopItem",1e3],FrostGiantItemStack100:["FrostGiantItem",100],FrostGiantItemStack500:["FrostGiantItem",500],FrostGiantItemStack1000:["FrostGiantItem",1e3],ForestTroopItemStack100:["ForestTroopItem",100],ForestTroopItemStack500:["ForestTroopItem",500],ForestTroopItemStack1000:["ForestTroopItem",1e3],DarkSlayerItemStack100:["DarkSlayerItem",100],DarkSlayerItemStack500:["DarkSlayerItem",500],DarkSlayerItemStack1000:["DarkSlayerItem",1e3]},init:function(){var e=Names;e.makeIdx(e.troops)},getTroopAbbr:function(e){var t=Names.troops.byName[e];if(t)return t[2];return e.substr(0,14)},makeIdx:function(e){byAbbr={};byName={};var t=e.names;for(var n=0;n<t.length;n++){byAbbr[t[n][2]]=t[n];byName[t[n][1]]=t[n]}e.byAbbr=byAbbr;e.byName=byName}};var RecallMarch={init:function(){var e=RecallMarch;if(as(Data.dynamic.recall_marches))Data.dynamic.recall_marches=[];e.timer=setTimeout(e.aJ,1e3)},aJ:function(){function r(e){var t="Recall march "+e.marchId;aZ(t+" "+translate("attempted"));new MyAjax.marchRecall(e.cityId,e.marchId,function(n){if(n.ok){delete e;aX(t);aZ(t+" "+translate("succeeded"))}else{e.recalling=false;aZ(t+" "+translate("failed and returned error")+": "+n.errmsg)}})}var e=RecallMarch;for(var t=0;t<Data.dynamic.recall_marches.length;t++){if(Data.dynamic.recall_marches[t]===undefined)Data.dynamic.recall_marches.splice(t,1);else if(Data.dynamic.recall_marches[t]!==undefined&&Marches.find(Data.dynamic.recall_marches[t].marchId)==null){bf("***** March to recall missing from seed: "+bC(Data.dynamic.recall_marches[t]));Data.dynamic.recall_marches.splice(t,1)}}for(var t=0;t<Data.dynamic.recall_marches.length;t++){if(Data.dynamic.recall_marches[t]!==undefined&&Marches.find(Data.dynamic.recall_marches[t].marchId)!==null){var n=bV(be());if(Data.dynamic.recall_marches[t].run_at-n<60&&!Data.dynamic.recall_marches[t].recalling){Data.dynamic.recall_marches[t].recalling=true;aZ("Recalling march "+Data.dynamic.recall_marches[t].marchId+" arrives at "+bE(Data.dynamic.recall_marches[t].run_at,true)+" "+", current time "+bE(n,true)+", diff "+(Data.dynamic.recall_marches[t].run_at-n)+"s");r(Data.dynamic.recall_marches[t])}}}e.timer=setTimeout(e.aJ,1e3)},exists:function(e){var t=RecallMarch;if(!Data.dynamic.recall_marches||Data.dynamic.recall_marches.length===0)return false;var n=false;for(var r=0;r<Data.dynamic.recall_marches.length&&!n;r++){if(Data.dynamic.recall_marches[r].marchId==e)n=true}return n}};var RequestQueue={que:{},add:function(e,t,n,r){function a(e){var t=RequestQueue;var n=t.que[e][0];delete t.que[e];n()}var i=RequestQueue;var s=be(),o=0;if(isNaN(n))o=1e3;else o=n;if(i.que[e]){if(s+o>=i.que[e][2])return;clearTimeout(i.que[e][1])}var u=setTimeout(function(){a(e)},o);i.que[e]=[t,u,s+o,r]},dispQ:function(e){var t=be();var n=e+" (now="+cc(t)+") :\n";for(var r in RequestQueue.que){n+=r+" : "+RequestQueue.que[r][1]+" : "+RequestQueue.que[r][2]+" ("+(RequestQueue.que[r][2]-t)+")\n"}bf(n)},isPending:function(e,t){var n=RequestQueue;if(n.que[e]&&t){var r=be();if(r+t<n.que[e][2]&&n.que[e][3])return false;else return true}else return n.que[e]?true:false}};var Seed={cities:[],cityIdx:{},cityTs:{},cityInit:[],jobs:{},numMarches:0,generals:{},requirements:{building:[],research:[],resurrect:[],unit:[],dragon:[]},stats:{building:{},dragons:{},research:{},resurrect:{},unit:{},dragon:{}},refresh_cities:[],greatDragons:{GreatDragon:[],WaterDragon:[],StoneDragon:[],FireDragon:[],WindDragon:[],IceDragon:[],SwampDragon:[],ForestDragon:[],DesertDragon:[],ChronoDragon:[],SpectralDragon:[],KaiserDragon:[],CaveDragon:[],LunaDragon:[]},dragonList:[],dragons:{},items:{},sanctuary_dragons:{},quests:{category:[],list:[]},numGenerals:0,serverTimeOffset:0,lastRefresh:0,tickTimer:0,numCities:0,updatingCity:false,research:[],armors:[],init:function(e){var t=Seed;t.fetchPlayer(function(t){if(t.ok)aZ(translate("Player data was Successfully requested from the server"));else aZ("fetchPlayer "+translate("was returned with a status of")+" "+t.ok+" - "+t.errmsg);if(e)e(t)},{noCities:true});clearInterval(t.tickTimer);t.tickTimer=setInterval(t.cf,1e3)},fetchPlayer:function(e,t){var n;if(e instanceof Function){var e=e;var t=t||{}}else{var t=e;var e=null}if(t&&t.noPlayer){if(t&&t.cities){for(var r=0;r<t.cities.length;r++){if(Seed.cityIdx[t.cities[r]]!==undefined){aZ("FetchPlayer : Call fetchCity");setTimeout(Seed.fetchCity,Math.randRange(r*1e3,r*3e3),t.cities[r],e)}}if(!t.jobs&&!t.dragons)return}if(t&&t.jobs){setTimeout(Seed.fetchJobs,Math.randRange(r*1e3,r*3e3),e);if(!t.dragons)return}if(t&&t.dragons){setTimeout(Seed.fetchDragons,Math.randRange(r*1e3,r*3e3),e);return}}var i={};i=MyAjax.addMainParams();new aB("player","player.json",i,function(r){if(r.ok){if(r.dat.timestamp){Seed.serverTimeOffset=r.dat.timestamp-(new Date).getTime()/1e3}Seed.player=r.dat;if(t&&t.cities){for(var i=0;i<t.cities.length;i++){if(Seed.cityIdx[t.cities[i]]!==undefined){aZ("FetchPlayer / player.json : Call fetchCity");setTimeout(Seed.fetchCity,Math.randRange(i*1e3,i*3e3),t.cities[i],e)}}if(!t.jobs&&!t.dragons)return}if(t&&t.jobs){setTimeout(Seed.fetchJobs,Math.randRange(i*1e3,i*3e3),e);if(!t.dragons)return}if(t&&t.dragons){setTimeout(Seed.fetchDragons,Math.randRange(i*1e3,i*3e3),e);return}var i=0;for(n in r.dat.cities){if(Seed.cityInit[i]===undefined){Seed.cityInit[i]={}}Seed.cityInit[i].id=r.dat.cities[n].id;Seed.cityInit[i].type=n;i++}if(t&&t.noCities){if(e)e(r);return}try{for(var i=0;i<Seed.cityInit.length;i++){if(Seed.cityInit[i].timer){clearTimeout(Seed.cityInit[i].timer)}aZ("FetchPlayer / all cities : Call fetchCity");Seed.cityInit[i].timer=setTimeout(Seed.fetchCity,Math.randRange(i*2e3,i*4e3),Seed.cityInit[i].id,e)}}catch(s){r.ok=false;r.errmsg=s.toString()}}if(e)e(r);return})},fetchCity:function(e,t){if(!e)return;var n=Seed;var r={};r=MyAjax.addMainParams();new aB("cities","cities/"+e+".json",r,function(r){if(r.ok){if(r.dat.timestamp){n.serverTimeOffset=r.dat.timestamp-(new Date).getTime()/1e3;if(r.dat.city.type=="Capital")n.lastRefresh=be()}try{n.updateCity(r.dat.city)}catch(i){r.ok=false;r.errmsg="Exception - "+i.toString()}}if(!r.ok)aZ("fetchCity "+translate("attempt for")+" "+e+" "+translate("was returned with a status of")+" "+r.ok+" - "+r.errmsg);var s=false;for(var o=0;o<n.refresh_cities.length&&!s;o++){if(n.refresh_cities[o].id==e){n.refresh_cities[o].isRefreshing=false;s=true}}if(t)t(r)},true)},fetchJobs:function(e){var t=Seed;var n={};n=MyAjax.addMainParams();new aB("jobs","player/jobs.json",n,function(t){if(t.ok){try{for(var n in t.dat.result.result){var r=t.dat.result.result[n];if(r&&r.length>0){for(var i=0;i<r.length;i++){Seed.checkAddJob(r[i])}}Seed.checkRemoveJobs()}}catch(s){t.ok=false;t.errmsg="Exception - "+s.toString()}}if(!t.ok)aZ("fetchJobs "+translate("attempted")+" "+translate("was returned with a status of")+" "+t.ok+" - "+t.errmsg);if(e)e(t)})},fetchDragons:function(e){var t=Seed;var n={};n=MyAjax.addMainParams();new aB("dragons","dragons/",n,function(t){if(t.ok){try{var n=aA(t.dat.result.dragons);Seed.sanctuary_dragons={};for(var r=0;r<n.length;r++){for(var i in n[r]){var s=aA(n[r][i]);var o=s.type.substring(s.type.indexOf("::")+2);o=o=="CityGreatDragon"?"GreatDragon":o;s.name=o;var u=sanctuaryDragonRank[s.rank];s.type=s.gender+"-"+u;s.subtype=(i=="city_great_dragon"?"great_dragon":i).replace(/ |_/g,"-");Seed.sanctuary_dragons[s.id]=aA(s);if(!Data.options.sanctuary.feeding[s.id])Data.options.sanctuary.feeding[s.id]={enable:false,cap:9}}}for(var a in Data.options.sanctuary.feeding){if(!Seed.sanctuary_dragons[a])delete Data.options.sanctuary.feeding[a]}Seed.sanctuary_dragons.player_slots=t.dat.result.master_rookery.player_slots}catch(f){t.ok=false;t.errmsg="Exception - "+f.toString()}}if(!t.ok)aZ("fetchDragons "+translate("attempted")+" "+translate("was returned with a status of")+" "+t.ok+" - "+t.errmsg);if(e)e(t)})},addToRefresh:function(e,t){var n=Seed;var r=false;var i=be();for(var s=0;s<n.refresh_cities.length&&!r;s++)if(n.refresh_cities[s].id==e)r=true;if(!r)n.refresh_cities.push({id:e,isRefreshing:t})},cf:function(){var e=Seed;var t=bV(be());var n=false;try{for(var r=0;r<all_resource_types.length;r++){var i=e.cities[CAPITAL.id].figures.resource_rates[all_resource_types[r]];var s=e.cities[CAPITAL.id].resources[all_resource_types[r]];if(e.player.boosts&&e.player.boosts.collect_resources&&all_resource_types[r]=="food"&&s>i.capacity)n=true;if((s<i.capacity&&i.rate>0||s>(i.vault_capacity||0)&&i.rate<0)&&!n){if(e.lastRefresh&&e.lastRefresh!=0){s=s+i.rate/3600*bV(t-e.lastRefresh);e.lastRefresh=0}else s=s+i.rate/3600;if(s>i.capactity)s=i.capacity;if(s<(i.vault_capacity||0))s=i.vault_capacity||0;if(!e.refresh_cities[CAPITAL.id])e.cities[CAPITAL.id].resources[all_resource_types[r]]=s}}}catch(o){aZ(translate("Resources stock levels update failed")+": "+bC(o,8,1));clearInterval(e.tickTimer);setTimeout(e.restartTick,3e4);return}for(var u in e.jobs){for(var a in e.jobs[u]){var f=e.jobs[u][a];if(f.done){if(t>f.run_at-1){var l=true;var c=Marches.find(f.march_id);if(c){switch(c.status){case"marching":if(t>c.run_at+10)e.addToRefresh(u,false);break;case"retreating":if(t<c.real_run_at||e.updatingCity){l=false;break}if(c.general_id){if(!e.generals[c.general_id]){e.generals[c.general_id]={};bf("ERROR in Seed.tick() : could not be found General Id: "+c.general_id+" in Seed.generals. Creating an entry to fix the problem.")}e.generals[c.general_id].busy=false;e.generals[c.general_id].x=c.x;e.generals[c.general_id].y=c.y;e.generals[c.general_id].status=c.status}var h=null;var p=false;for(var d in c.units){for(var v=0;v<Seed.dragonList.length&&!p;v++){if(Seed.dragonList[v].type==d){p=true;h=d}}}if(h!==null&&Seed.dragons[h])Seed.dragons[h].is_in_city=true;e.addToRefresh(e.cities[CAPITAL.id].id,false);if(c.units["WaterDragon"])e.addToRefresh(e.cities[WATER_OUTPOST.id].id,false);if(c.units["StoneDragon"])e.addToRefresh(e.cities[STONE_OUTPOST.id].id,false);if(c.units["FireDragon"])e.addToRefresh(e.cities[FIRE_OUTPOST.id].id,false);if(c.units["WindDragon"])e.addToRefresh(e.cities[WIND_OUTPOST.id].id,false);if(c.units["IceDragon"])e.addToRefresh(e.cities[ICE_OUTPOST.id].id,false);if(c.units["SwampDragon"])e.addToRefresh(e.cities[SWAMP_OUTPOST.id].id,false);if(c.units["ForestDragon"])e.addToRefresh(e.cities[FOREST_OUTPOST.id].id,false);if(c.units["DesertDragon"])e.addToRefresh(e.cities[DESERT_OUTPOST.id].id,false);if(c.units["ChronoDragon"])e.addToRefresh(e.cities[CHRONO_OUTPOST.id].id,false);if(c.units["KaiserDragon"])e.addToRefresh(e.cities[SKY_OUTPOST.id].id,false);if(c.units["CaveDragon"])e.addToRefresh(e.cities[CAVE_OUTPOST.id].id,false);if(c.units["LunaDragon"])e.addToRefresh(e.cities[LUNA_OUTPOST.id].id,false);Marches.remove(c.id);break}}if(l)delete e.jobs[u][a]}}else{if(t>f.run_at-1){f.done=true;switch(f.queue){case"breeding":Seed.fetchPlayer({noPlayer:true,cities:[],jobs:true,dragons:true});break;case"building":SoundPlayer.PlaySound(f.queue);Tabs.Jobs.buildRefreshLvl=true;Buildings.setLevel(u,f.city_building_id,f.level);Tabs.Jobs.buildRefreshTab=true;break;case"feeding":Seed.fetchPlayer({noPlayer:true,cities:[],jobs:true,dragons:true});break;case"hatching":Seed.fetchPlayer({noPlayer:true,cities:[],jobs:true,dragons:true});break;case"march":var c=Marches.find(f.march_id);if(c&&c.status=="marching")e.addToRefresh(u,false);break;case"research":SoundPlayer.PlaySound(f.queue);Seed.player.research[f.research_type]=f.level;break;case"units":SoundPlayer.PlaySound(f.queue);Seed.cities[CAPITAL.id].units[f.unit_type]+=f.quantity;break;default:e.addToRefresh(u,false)}}}}}e.numMarches=0;for(var m in Data.marches){if(!/(attacks|waves|spies|multiple|bookmark|transport)/.test(m))continue;for(var g in Data.marches[m])e.numMarches++}if(Data.marches)Marches.updateCounters();if(e.refresh_cities.length){for(var y=e.refresh_cities.length-1;y>=0;y--){var b=e.refresh_cities[y];if(!b.isRefreshing){b.isRefreshing=true;aZ("Seed.tick : Call fetchCity for "+b.id);e.fetchCity(b.id,function(e){if(e.ok){Seed.refresh_cities.splice(y,1)}else{var t;var n=3e4;if(e.status===429){t="<b>API Rate Limit Exceeded</b>, too many requests!";n=E429_DELAY*1e3}else if(e.status===509){t="<b>Rate Limit Exceeded</b>, too many requests!";n=18e5}else t=e.errmsg;aZ("Seed.tick : Call fetchCity returned code "+e.status+" - "+t);if(Seed.refresh_cities[y]&&Seed.refresh_cities[y].isRefreshing)Seed.refresh_cities[y].isRefreshing=false;clearInterval(Seed.tickTimer);setTimeout(Seed.restartTick,n);return}})}}}},restartTick:function(){var e=Seed;if(e.tickTimer)clearInterval(e.tickTimer);e.tickTimer=setInterval(e.cf,1e3)},updateCity:function(e){var t=Seed;if(!e)return;t.updatingCity=true;aZ(translate("Updating City values")+": "+e.name);var n=e.type=="Capital"?CAPITAL.id:e.name.charAt(e.name.length-1);if(typeof t.cityIdx[e.id]!=="undefined"&&t.cityIdx[e.id]!==null){n=t.cityIdx[e.id]}else if(e.type=="Capital"){n=CAPITAL.id}else{bI(e.outpost_type);switch(e.outpost_type){case"WaterDragonOutpost":n=WATER_OUTPOST.id;break;case"StoneDragonOutpost":n=STONE_OUTPOST.id;break;case"FireDragonOutpost":n=FIRE_OUTPOST.id;break;case"WindDragonOutpost":n=WIND_OUTPOST.id;break;case"IceDragonOutpost":n=ICE_OUTPOST.id;break;case"SwampDragonOutpost":n=SWAMP_OUTPOST.id;break;case"ForestDragonOutpost":n=FOREST_OUTPOST.id;break;case"DesertDragonOutpost":n=DESERT_OUTPOST.id;break;case"SpectralDragonOutpost":n=SPECTRAL_OUTPOST.id;break;case"ChronoDragonOutpost":n=CHRONO_OUTPOST.id;break;case"SkythroneOutpost":n=SKY_OUTPOST.id;break;case"CaveDragonOutpost":n=CAVE_OUTPOST.id;break;case"LunaDragonOutpost":n=LUNA_OUTPOST.id;break;default:n=SPECTRAL_OUTPOST.id}if(n==CAPITAL.id)n=ICE_OUTPOST.id;if(typeof t.cities[n]!=="undefined"&&t.cities[n]!==null){t.cityIdx[t.cities[n].id]=t.cities.length;t.cities[t.cities.length]=t.cities[n]}}t.cities[n]=e;t.cityIdx[e.id]=n;t.cityTs[e.id]=be();var r=null;switch(bV(n)){case CAPITAL.id:r=e.great_dragon;break;case WATER_OUTPOST.id:r=e.water_dragon;break;case STONE_OUTPOST.id:r=e.stone_dragon;break;case FIRE_OUTPOST.id:r=e.fire_dragon;break;case WIND_OUTPOST.id:r=e.wind_dragon;break;case ICE_OUTPOST.id:r=e.ice_dragon;break;case SWAMP_OUTPOST.id:r=e.swamp_dragon;break;case FOREST_OUTPOST.id:r=e.forest_dragon;break;case DESERT_OUTPOST.id:r=e.desert_dragon;break;case CHRONO_OUTPOST.id:r=e.chrono_dragon;break;case SKY_OUTPOST.id:r=e.kaiser_dragon;break;case CAVE_OUTPOST.id:r=e.cave_dragon;break;case LUNA_OUTPOST.id:r=e.luna_dragon;break;default:r=null;break}if(r!==null){var i=r.type.substring(r.type.indexOf("::")+2);i=i=="CityGreatDragon"?"GreatDragon":i;var s=Seed.player.research["AerialCombat"]?Seed.player.research["AerialCombat"]:0;t.dragons[i]=r;t.dragons[i].name=i;t.dragons[i].can_attack=t.checkArmorDragon(i)&&t.dragons[i].level>=8&&s>0&&i!="SpectralDragon";t.dragons[i].city_id=e.id;if(r.life!==r.maximum_life){t.dragons[i].cure_at=be()+(r.maximum_life-r.life)/r.recovery_rate*3600}else{t.dragons[i].cure_at=be()}var o=false;for(var u=0;u<t.dragonList.length&&!o;u++)if(t.dragonList[u].type==i)o=true;if(!o){t.dragonList.push({type:i,city:n});t.dragonList.sort(function(e,t){return e.city-t.city})}}if(n==CAPITAL.id){for(var a=0;a<e.generals.length;a++){t.generals[e.generals[a].id]=e.generals[a]}t.numGenerals=e.generals.length;Marches.purge();for(var a=0;a<e.marches.length;a++){var f=e.marches[a];if(f.general_id){if(!t.generals[f.general_id]){t.generals[f.general_id]={};bf("ERROR in updateCity() : could not be found General Id: "+f.general_id+" in Seed.generals. Creating an entry to fix the problem.")}t.generals[f.general_id].busy=true;t.generals[f.general_id].x=f.x;t.generals[f.general_id].y=f.y;t.generals[f.general_id].status=f.status}var i=null;var o=false;for(var l in f.units){for(var u=0;u<t.dragonList.length&&!o;u++){if(t.dragonList[u].type==l){o=true;i=l}}}if(i!==null&&t.dragons[i])t.dragons[i].is_in_city=false;var c=aA(f);c.target_name=c.destination_name?translate("City")+" "+c.destination_name:translate(c.terrain_type);if((cur_march=Marches.find(c.id))==null){Marches.add(c,c.ownerId?c.ownerId:null)}else{Marches.update(c)}}}for(var a=0;a<e.jobs.length;a++){t.checkAddJob(e.jobs[a])}t.checkRemoveJobs();t.updatingCity=false;for(var a=0;a<t.cityInit.length;a++){if(t.cityInit[a].id===e.id&&!t.cityInit[a].loaded){t.cityInit[a].loaded=true;var h=translate("City")+" "+e.id+" "+translate("Successfully initialized");aZ(h);bf(h)}}},checkArmorDragon:function(e){var t=Seed;var n=["BodyArmor","ClawGuards","TailGuard","Helmet"];var r=0;for(var i=0;i<n.length;i++){if(bV(Seed.player.items[e+n[i]])!==0){r++}}if(r==4)return true;else return false},checkAddJob:function(e){var t=Seed;var n=e.city_id;if(!e.run_at){bf("checkAddJob job.run_at is null:\n"+bC(e,5,1))}else{e.run_at+=1}if(!t.jobs[n]){t.jobs[n]={}}if(e.queue=="march"){if((march=Marches.find(e.march_id))==null){if(e.run_at<be()){return}bf("checkAddJob MISSING MARCH:\n"+bC(e,5,1))}else{march.run_at=e.run_at;march.duration=e.duration;march.job_id=e.id;if(march.status=="marching")march.real_run_at=e.run_at+bV(e.duration);if(march.real_run_at<march.run_at)march.real_run_at=march.run_at}}if(!t.jobs[n][e.id])t.jobs[n][e.id]=aA(e);if(e.queue=="building"){Tabs.Jobs.last_built[n]={id:e.city_building_id,level:e.level}}var r=false;for(var i=0;i<Seed.cities.length;++i){var s=Seed.cities[i];if(s&&s.id==n){for(var o=0;o<s.jobs.length&&!r;o++){if(s.jobs[o].id==e.id){s.jobs[o].mergeWith(e);r=true}}if(!r)s.jobs.push(e)}}},checkRemoveJobs:function(){var e=Seed;if(!Seed.cities||Seed.cities.length==0)return;for(var t=0;t<Seed.cities.length;t++){if(!Seed.cities[t])continue;var n=Seed.cities[t].id;var r=Seed.cities[t];for(var i in Seed.jobs[n]){var s=Seed.jobs[n][i],o=false;if(s.queue!="march"){for(var u=0;u<r.jobs.length&&!o;u++)if(i==r.jobs[u].id)o=true;if(!o){bf("checkRemoveJob delete job :\n"+bC(s,5,1));delete Seed.jobs[n][i]}}}}}};var SoundPlayer={alertString:"",shortString:"",checkInterval:null,attack_active:false,attack_repeat_timer:null,spy_active:false,spy_repeat_timer:null,SWF_PLAYER_URL:"https://wackoscripts.com/mp3/jawz.swf",SOUND_TYPES:["attack","spy","building","research","units","fortuna"],DEFAULT_SOUND_URL:{attack:"https://wackoscripts.com/mp3/tower.mp3",spy:"https://wackoscripts.com/mp3/spy.mp3",building:"https://wackoscripts.com/mp3/construction.mp3",units:"https://wackoscripts.com/mp3/training.mp3",research:"https://wackoscripts.com/mp3/research.mp3",fortuna:"https://wackoscripts.com/mp3/wheel.mp3"},init:function(){var e=SoundPlayer;e.oldAlertCount=0;e.checkInterval=setInterval(e.checkAlerts,1e3)},loadPlayer:function(e,t){var n=SoundPlayer;if(!t){if(!Data.options.sound["URL_"+e]){if(!n.DEFAULT_SOUND_URL[e])return;t=n.DEFAULT_SOUND_URL[e]}else t=Data.options.sound["URL_"+e]}var r=Data.options.sound["URL_player"]||SoundPlayer.SWF_PLAYER_URL;var i="SwfPlyr_"+e;var s="div_SwfPlyr_"+e;var o=document.getElementById(UID[s]);var u='<object class="playerpreview" id="'+i+'" type="application/x-shockwave-flash" data="'+r+'" width="50" height="0">'+'	<param name="movie" value="'+r+'">'+'	<param name="AllowScriptAccess" value="always" />'+'	<param name="FlashVars" value="mp3='+t+'&autoplay=1" />'+"</object>";if(o)try{o.innerHTML=u}catch(a){}},PlaySound:function(e,t,n,r){var i=SoundPlayer;var s="div_SwfPlyr_"+e;var o=document.getElementById(UID[s]);if(!t&&(/(building|units|research)/.test(e)&&Data.options.sound.enable_jobs||/(attack|spy)/.test(e)&&Data.options.sound.enable_sentinel||e=="fortuna"&&Data.options.sound.enable_fortuna)||t){i.loadPlayer(e);if(!t&&n&&r){if(e=="attack"){i.attack_active=true;i.attack_repeat_timer=setTimeout(function(){i.PlaySound(e,t,n,r)},r*6e4)}if(e=="spy"){i.spy_active=true;i.spy_repeat_timer=setTimeout(function(){i.PlaySound(e,t,n,r)},r*6e4)}}}},StopSound:function(e){var t=SoundPlayer;var n="div_SwfPlyr_"+e;var r=document.getElementById(UID[n]);if(r)r.innerHTML="";if(e=="attack"){t.attack_active=false;if(t.attack_repeat_timer){clearTimeout(t.attack_repeat_timer);t.attack_repeat_timer=null}}if(e=="spy"){t.spy_active=false;if(t.spy_repeat_timer){clearTimeout(t.spy_repeat_timer);t.spy_repeat_timer}}},checkAlerts:function(){var e=SoundPlayer;e.alertString="";e.shortString="";var t=0;var n=0;var r=false,i=false,s=false,o;if(Data.options.messages_tower.length!=0){for(var u=0;u<Data.options.messages_tower.length;u++){o=Date.parse(Data.options.messages_tower[u].arrive_at)/1e3;var a=bV(be());var f=a-o;if(f<0){if(!Data.options.messages_tower[u].warned){Data.options.messages_tower[u].warned=true;if(Data.options.messages_tower[u].type==0)r=true;else i=true}if(!Data.options.messages_tower[u].sent&&Data.options.tower.send_message&&Data.options.tower.msg_subject&&Data.options.tower.msg_subject!=null&&Data.options.tower.msg_body&&Data.options.tower.msg_body!=null&&Data.options.messages_tower[u].type==0){Data.options.messages_tower[u].sent=true;if(Seed.player.alliance&&Seed.player.alliance.id>0)e.send_message(u)}if(Data.options.messages_tower[u].type==0)t++;if(Data.options.messages_tower[u].type==1)n++}}}if(t==0&&e.attack_active)e.StopSound("attack");if(n==0&&e.spy_active)e.StopSound("spy");if(t+n>0){e.alertString+="<div class="+UID["info_alerts"]+">"+translate("Warning")+" : <B>";var l={};if(t==0){if(n>1){l={type:"basic",title:n+" "+translate("spies"),message:n+" "+translate("spies"),iconUrl:"/images/icon16.png"};e.alertString+=n+" "+translate("spies")+" (&incoming_spy&)";e.shortString+=n+" "+translate("spies")}else{l={type:"basic",title:"1 "+translate("spy"),message:"1 "+translate("spy"),iconUrl:"/images/icon16.png"};e.alertString+="1 "+translate("spy")+" (&incoming_spy&)";e.shortString+="1 "+translate("spy")}}else if(t>1){if(n>1){l={type:"basic",title:n+" "+translate("spies")+" & "+t+" "+translate("attacks"),message:n+" "+translate("spies")+" & "+t+" "+translate("attacks"),iconUrl:"/images/icon16.png"};e.alertString+=n+" "+translate("spies")+" (&incoming_spy&)"+translate("</B> and <B>")+t+" "+translate("attacks")+" (&incoming_attack&)";e.shortString+=n+" "+translate("spies")+" / "+t+" "+translate("attacks")}else if(n==1){l={type:"basic",title:"1 "+translate("spy")+" & "+t+" "+translate("attacks"),message:"1 "+translate("spy")+" & "+t+" "+translate("attacks"),iconUrl:"/images/icon16.png"};e.alertString+="1 "+translate("spy")+" (&incoming_spy&)"+translate("</B> and <B>")+t+" "+translate("attacks")+" (&incoming_attack&)";e.shortString+="1 "+translate("spy")+" / "+t+" "+translate("attacks")}else{l={type:"basic",title:t+" "+translate("attacks"),message:t+" "+translate("attacks"),iconUrl:"/images/icon16.png"};e.alertString+=t+" "+translate("attacks")+" (&incoming_attack&)";e.shortString+=t+" "+translate("attacks")}}else{if(n>1){l={type:"basic",title:n+" "+translate("spies")+" & "+t+" "+translate("attacks"),message:n+" "+translate("spies")+" & "+t+" "+translate("attacks"),iconUrl:"/images/icon16.png"};e.alertString+=n+" "+translate("spies")+" (&incoming_spy&)"+translate("</B> and <B>")+"1 "+translate("attack")+" (&incoming_attack&)";e.shortString+=n+" "+translate("spies")+" / 1 "+translate("attack")}else if(n==1){l={type:"basic",title:"1 "+translate("spy")+" & "+"1 "+translate("attack"),message:"1 "+translate("spy")+" & "+"1 "+translate("attacks"),iconUrl:"/images/icon16.png"};e.alertString+="1 "+translate("spy")+" (&incoming_spy&)"+translate("</B> and <B>")+"1 "+translate("attack")+" (&incoming_attack&)";e.shortString+="1 "+translate("spy")+" / 1 "+translate("attack")}else{l={type:"basic",title:"1 "+translate("attack"),message:"1 "+translate("attacks"),iconUrl:"/images/icon16.png"};e.alertString+="1 "+translate("attack")+" (&incoming_attack&)";e.shortString+="1 "+translate("attack")}}e.alertString+="</B> "+translate("in progress")+"</div>";e.shortString="<input id="+UID["short_alerts"]+" type=button class="+UID["btn_off"]+' value="'+e.shortString+'" />'}if(Data.options.tower.enabled&&Data.options.sound.enable_sentinel&&(r||i)){if(r)e.PlaySound("attack",false,!e.attack_active?Data.options.sound.repeat_attack:false,Data.options.sound.attack_rdelay);else e.PlaySound("spy",false,!e.spy_active?Data.options.sound.repeat_spy:false,Data.options.sound.spy_rdelay)}},getFirstAlert:function(){var e=SoundPlayer,t=[],n=[],r={attack:"",spy:""};if(Data.options.messages_tower.length!=0){for(var i=0;i<Data.options.messages_tower.length;i++){var s=bV(be())-Date.parse(Data.options.messages_tower[i].arrive_at)/1e3;if(s<0){if(Data.options.messages_tower[i].type==0)t.push(Data.options.messages_tower[i].arrive_at);else n.push(Data.options.messages_tower[i].arrive_at)}}}if(t.length>0){t.sort(function(e,t){return e-t});r.attack=cc(Date.parse(t[0])/1e3-bV(be()))}if(n.length>0){n.sort(function(e,t){return e-t});r.spy=cc(Date.parse(n[0])/1e3-bV(be()))}return r},send_message:function(e){var t=SoundPlayer,n=Data.options.tower.msg_body,r=Data.options.messages_tower[e],i=false,s;var o=r.arrive_at!=0?(new Date(r.arrive_at)).formatDate()+" "+(new Date(r.arrive_at)).formatTime():"";n=n.replace("%1",r.alliance);n=n.replace("%2",r.x+","+r.y);n=n.replace("%3",r.troups);n=n.replace("%4",o);n=n.replace("%5",Seed.player.name);if(bV(r.op)!=0){for(var u=0;u<Seed.cities.length&&!i;++u){if(Seed.cities[u]&&Seed.cities[u].id==bV(r.op)){s=Seed.cities[u];i=true}}}if(!i)s=Seed.cities[CAPITAL.id];n=n.replace("%6",translate(s.name));n=n.replace("%7",s.x+","+s.y);MyAjax.messageSend(Data.options.tower.msg_subject,n,Seed.player.alliance.id,false)}};var Translation={loaded:false,xml:{},available_langs:[{code:"de",desc:"German"},{code:"en",desc:"English"},{code:"es",desc:"Spanish"},{code:"fr",desc:"French"},{code:"nl",desc:"Dutch"},{code:"sv",desc:"Swedish"}],_section:["items","common","boosts","buildings","messages","dialogs","dragons","levels","troops","map","alliances","outposts","research","quests","trading","activerecord"],init:function(e){var t=Translation;t.fetchLocale(function(n){if(n.ok){aZ(translate("Locale data was Successfully requested from the sever"));t.loaded=true;t.fixResults()}else aZ("fetchLocale "+translate("was returned with a status of")+" "+n.ok+" - "+n.errmsg);if(e)e(n)})},fetchLocale:function(e){var t=Translation;new aB("locales","locales/"+aU.attrs.locale+".xml",{_swf_session_id:aU.attrs.sessionId},function(n){if(n.ok){try{t.parseXML(n.dat)}catch(r){n.ok=false;n.errmsg=r.toString()}}else if(n.errmsg.indexOf("404")!==-1){new aB("locales","locales/en.xml",{"%5Fswf%5Fsession%5Fid":aU.attrs.sessionId},function(n){if(n.ok){try{t.parseXML(n.dat)}catch(r){n.ok=false;n.errmsg=r.toString()}}if(e)e(n);return})}if(e)e(n)})},parseXML:function(e){var t=Translation;var n=parseInt(be());if(e.indexOf("<targeted-messages>")>0)e=e.substring(0,e.indexOf("<targeted-messages>"))+e.substring(e.indexOf("</targeted-messages>")+20);e=e.replace(/<[0-9]+/g,"<");e=e.replace(/<\/[0-9]+/g,"</");e=e.replace(/<>/g,"<Teamwork_"+n+">");e=e.replace(/<\/>/g,"</Teamwork_"+n+">");e=e.replace(/<[-;,\.<>]/g,"<Teamwork-");e=e.replace(/<\/[-;,\.<>]/g,"</Teamwork-");xmlTmpObj=new XML.ObjTree;var r=xmlTmpObj.parseXML(e);if(r.translations){if(r.translations.parsererror){bf("erreur parsing : "+bC(r.translations.parsererror,8,1))}for(sect in r.translations){var s=false;for(i=0;i<t._section.length&&!s;i++){if(sect===t._section[i])s=true}if(!s)delete r.translations[sect]}t.xml=r.translations}else aZ("Error in the XML file structure: <translations> element not found!")},fixResults:function(){function t(e){var t={};for(var n in e){if(typeof e[n]==="object"){for(var r in e[n]){if(typeof e[n][r]==="object"){for(var i in e[n][r]){if(i==="title"||i==="name")t[n+"-"+r]=e[n][r][i];else t[n+"-"+r+"-"+i]=e[n][r][i]}}else{if(r==="title"||r==="name")t[n]=e[n][r];else t[n+"-"+r]=e[n][r]}}}else{t[n]=e[n]}}return t}var e=Translation.xml;var n=["dialogs","messages","activerecord","dragons","alliances"];for(var r=0;r<n.length;r++){if(e[n[r]])e[n[r]]=t(e[n[r]])}var i={};for(var s in e.quests){if(typeof e.quests[s]=="object"){for(var o in e.quests[s]){switch(o){case"title":i[s]=e.quests[s][o];break;case"objectives":i[s+"-"+o]=e.quests[s][o];break;default:break}}}else{i[s]=e.quests[s]}}Translation.xml["quests"]=aA(i);try{e.common.information=e.common.info;e.common.Info=e.common.info;e.common.omit=e.common.skip;e.common["spy-on"]=e.common.spy;e.dialogs.researching=e.dialogs.research;e.common["enter-coords"]=e.dialogs["attack-screen-enter-coords"];e.common["battle-report"]=e.messages["battle-report-title"];e.common["auto-collection-of-resources"]=e.dialogs["boost-collect-day"].replace(/:/,"");e.common["has-too-many-marches"]=e.activerecord["errors-models-march"]["attributes"]["player-id"]["has-too-many-marches"];e.common["not-enough-units"]=e.activerecord["errors-models-march"]["attributes"]["city-id"]["not-enough-units"];e.common["could-not-claim"]=e.activerecord["errors-models-player-quest"]["could-not-claim"];e.common.levels=iX(e.common.level,e.messages["spy-tip-prefix"]);for(var u in e.outposts){if(u.indexOf("-outpost")){var a=u.replace("-outpost","_dragon")+"-outpost";e.outposts[a]=e.outposts[u]}}delete e.common.error;delete e.common.home;delete e.common.info;delete e.common["ranged-attack"];delete e.common.skip;delete e.common.spy;delete e.messages.date;delete e.messages.fought;delete e.messages.subject;delete e.messages.to;delete e.dialogs.research;delete e.dialogs.spy;delete e.dialogs.unavailable;delete e.dialogs.upkeep}catch(f){bf("Error whilst fixing translation matrix results :\n"+bC(f,8,1))}},fG:function(e){return(e.toString()||"").toLowerCase().replace(/ /g,"-")},getContent:function(e,t,n){t=Translation.fG(t);if(Translation.xml[e]!=undefined){if(Translation.xml[e][t]!=undefined){return n?Translation.xml[e][t][n]:Translation.xml[e][t]}}return false},alliances:function(e){return Translation.getContent("alliances",e)},buildings:function(e,t){t=t!=undefined?t:"name";return Translation.getContent("buildings",e,t)},common:function(e){return Translation.getContent("common",e)},activerecord:function(e){return Translation.getContent("activerecord",e)},items:function(e,t){t=t!=undefined?t:"name";return Translation.getContent("items",e,t)},boosts:function(e,t){t=t!=undefined?t:"name";return Translation.getContent("boosts",e,t)},dragons:function(e,t){t=t!=undefined?t:"name";return Translation.getContent("dragons",e,t)},dialogs:function(e){return Translation.getContent("dialogs",e)},levels:function(e){return Translation.getContent("levels",e,"title")},map:function(e,t){t=t!=undefined?t:"name";return Translation.getContent("map",e,t)},messages:function(e){return Translation.getContent("messages",e)},outposts:function(e,t){t=t!=undefined?t:"name";return Translation.getContent("outposts",e,t)},trading:function(e){return Translation.getContent("trading",e)},troops:function(e,t){t=t!=undefined?t:"name";return Translation.getContent("troops",e,t)},research:function(e,t){t=t!=undefined?t:"name";return Translation.getContent("research",e,t)},quests:function(e,t){t=t!=undefined?t:"name";return Translation.getContent("quests",e,t)}}
		var needTranslate = {};

		function translate(str, ignore) {
			if (TRANSLATION_ARRAY[str] != undefined) {
				return TRANSLATION_ARRAY[str];
			} else if (Translation.loaded) {
				if( str != undefined) {
					var newStr;
					for (var i = 0; i < Translation._section.length; ++i) {
						newStr = Translation[Translation._section[i]](str);
						if (newStr) return newStr;
					}
				}
				if (IS_NOT_NATIVE_LANG && needTranslate[str] == undefined) {
					needTranslate[str] = 1;
					if (Tabs.Log && !ignore) bI('( Translate ) -> "' + str + '"');
				}
			}
			return str;
		}

		function bo(str, key, section) {
			if (Translation.loaded) {
				var newStr;
				if (section) {
					if (key) newStr = Translation[section](key, str);
					else newStr = Translation[section](str);
					if (newStr) return newStr;
				}
				for (var i = 0; i < Translation._section.length; ++i) {
					if (key) newStr = Translation[Translation._section[i]](key, str);
					else newStr = Translation[Translation._section[i]](str);
					if (newStr) return newStr;
				}
			} else if (TRANSLATION_ARRAY[str] != undefined) {
				return TRANSLATION_ARRAY[str];
			}
			if (IS_NOT_NATIVE_LANG && needTranslate[str] == undefined) {
				needTranslate[str] = 1;
				if (Tabs.Log) bI('( Translate ) -> "' + str + '"');
			}
			return str;
		}
var VerboseLog = {
			init: function() {
				VerboseLog.aM(Data.options.aZ.enabled);
			},

			aM: function(onOff) {
				Data.options.aZ.enabled = onOff;
			}
		};
var WackoScript = {
	url_binary_file : [],

	init : function () {
		var t=WackoScript;
		for (var type in Data.options.sound) {
			if (/URL_/.test(type))
				t.url_binary_file.push({url : Data.options.sound[type], type : type, load_timer : null, retries : 0});
		}
		for (var i=0; i<t.url_binary_file.length; i++)
			t.url_binary_file[i].load_timer = setTimeout(t.LoadBinary,1000,t.url_binary_file[i].url,i,false);
	},
	LoadBinary : function (url, index, degraded) {
		var t=WackoScript, p = {}, method = 'GET';
		if (degraded && url.indexOf('wackoscripts') > 0) { 
			if (url.indexOf('//www.') > 0) url = url.replace('//www.','//');
			else url = url.replace('//wacko','//www.wacko');
		}
		new aB('binary', url, p, by, false, true);
		function by(rslt) {
			if (rslt.ok) {
				bI('url '+url+' loaded ==> OK');
				var type = t.url_binary_file[index].type;
				if ((/URL_/.test(type)) && Data.options.sound[type] != url) { Data.options.sound[type] = url; bI ('New url for Data.options.sound.'+type+' = '+url); }
			} else {
				clearTimeout(t.url_binary_file[index].load_timer);
				t.url_binary_file[index].retries++;
				t.url_binary_file[index].load_timer = null;
				if (t.url_binary_file[index].retries < 6) {
					bI('url '+url+' not loaded ==> Retry in 5 seconds');
					t.url_binary_file[index].load_timer = setTimeout(t.LoadBinary,5000,url,index,true);
				} else {
					bI('url '+url+' not loaded ==> This sound won\'t probably work when needed...');
				}
			}
			return;
		}
	}
};
function dJ(container, target) {
			function iW(targetObj, aD) {
				var cityId = Seed.cities[CAPITAL.id].id;
				var cityIdx = CAPITAL.id;
				var units = [];
				units['Spy'] = 1;
				var attackUnits = bb(CAPITAL.id, units);
				if (attackUnits != null) {
					aD(aW(attackUnits, 'fb'));
					return;
				}
				var targMsg = '<B>' + translate('Manual spy sent to') + '</B>: ' + targetObj.n + ' ' + translate('at') + ' ' + targetObj.x + '/' + targetObj.y;
				aZ(targMsg + ' ' + translate('attempted'));
				new MyAjax.marchSpy(cityId, targetObj.x, targetObj.y, units, 'attacks', function(rslt) {
					if (rslt.ok && rslt.dat.result.success) {
						aZ(targMsg + ' ' + translate('Successfully'));
						aX(targMsg);
						if (aD) aD('OK');
					} else {
						aZ(targMsg + ' ' + translate('failed and returned error') + ': ' + rslt.errmsg);
						if (aD) aD(translate('Error') + ': ' + rslt.errmsg);
					}
				});
			}
			var dial = new aw(container, 300, 150, '', false);
			dial.bd().innerHTML = '<div class=' + UID['title'] + '><center><b>' + scriptName + ' : ' + translate('Message') + '</b></center></div>';
			dial.getContentDiv().innerHTML = translate('Spying');
			iW(target, aD);

			function aD(rslt) {
				if (rslt != 'OK') {
					dial.getContentDiv().innerHTML = '<b>' + rslt + '</b>';
					dial.allowClose(true);
				} else {
					dial.getContentDiv().innerHTML = '<b>' + translate('OK') + '</b>';
					setTimeout(function() {
						dial.destroy()
					}, 1000);
				}
			}
		}

		function dq(tab, units, options) {
			var ex = document.getElementById(UID[tab + '_CoordsX']);
			var ey = document.getElementById(UID[tab + '_CoordsY']);
			var x = bV(ex.value);
			var y = bV(ey.value);
			ex.value = x;
			ey.value = y;

			if (!as(units)) {
				var time = ba(x, y, units);
				document.getElementById(UID[tab + '_Distance']).innerHTML = bu(Seed.cities[CAPITAL.id].x, Seed.cities[CAPITAL.id].y, x, y) + ' (' + bz(time) + ')';
			}
			document.getElementById(UID[tab + '_Tile']).innerHTML = '&nbsp;';

			if (x < 0 || x > 749) {
				if (x < 0) {
					while (x < 0) x = 750 + x;
				} else {
					while (x > 749) x = x - 750;
				}
				ex.style.backgroundColor = 'red';
				return;
			}
			if (y < 0 || y > 749) {
				if (y < 0) {
					while (y < 0) y = 750 + y;
				} else {
					while (y > 749) y = y - 750;
				}
				ey.style.backgroundColor = 'red';
				return;
			}
			options.x = x;
			options.y = y;
			ey.style.backgroundColor = '';
			ex.style.backgroundColor = '';

			Map.tileAt({
				x: x,
				y: y,
				force_request: true
			}, function(target) {
				if (target && target.ok) {
					var cfeedBack = '';
					options.level = target.l;
					if (options.ai) options.ai = target.ai;
					var attColor = target.A ? '#000' : '#C22';

					var type_name = Map.names.type[target.t] || target.t;
					var type = 'C';
					if (target.t != 7 && target.t < 10) type = 'W'; 

					var tile = '<font color=' + attColor + '>' + '<b>' + translate(type_name) + '&nbsp;' + translate('Level') + '&nbsp;' + target.l + '</b>' + '</font>';
					if (target.cn != undefined && type != 'W') {
						options.id = target.id;
						options.n = target.n;
						tile += '<br>' + translate('City') + ': <b>' + target.cn + '</b> - ' + translate('Alliance') + ': <b>' + ((target.a != undefined && target.a != 0) ? target.a : '----') + '</b>' + '<br>' + translate('Name') + ': <b>' + target.n + '</b> - ' + translate('Level') + ': <b>' + target.l + '</b> - ' + translate('Might') + ': <b>' + target.m + '</b>';
						cFeedBack = translate(type_name) + ' ' + target.n + ' (' + bD(target.m) + ')' + ((target.a != undefined && target.a != 0) ? ' / ' + target.a : '');
					} else {
						options.id = target.id;
						options.n = '';
						cFeedBack = translate(type_name) + ' ' + translate('Level') + ' ' + target.l;
					}
					options.type = cFeedBack;
					if (document.getElementById(UID[tab + '_Tile']))
						document.getElementById(UID[tab + '_Tile']).innerHTML = tile;
					else
						bI('checkCoords : UID[' + tab + '_Tile] not defined');
				}
			});
		}

		function dB(targetMsg, feedback_element, marchCount, retryDelay, count_type, max_type, generalId, checkGeneral) {
			var checkresult = 0;
			if (MyAjax.marchBusy) {
				checkresult = 1;
				bM(targetMsg, feedback_element, checkresult, false, retryDelay);
				return (checkresult);
			}
			if ((marchCount > Seed.cities[CAPITAL.id].figures.marches.maximum) || (count_type >= max_type)) {
				checkresult = 2;
				bM(targetMsg, feedback_element, checkresult, true, retryDelay);
				return (checkresult);
			}
			if (generalId === null && checkGeneral) {
				checkresult = 3;
				bM(targetMsg, feedback_element, checkresult, false, retryDelay);
				return (checkresult);
			}
			return (checkresult);
		}

		function bb(cityIdx, units) {
			var totalTroops = 0,
				unit_qty = 0,
				muster_point = bJ(cityIdx);
			for (var p in units) {
				unit_qty = bV(units[p]);
				if (unit_qty > 0) {
					totalTroops += unit_qty;
					if (Seed.cities[cityIdx].units[p] < unit_qty)
						return (translate('not-enough-units') + ' ' + translate(p));
				}
			}
			if (totalTroops <= 0) return (4);
			for (var p in units) {
				unit_qty = bV(units[p]);
				if (unit_qty > 0) {
					if (unit_qty > muster_point.max_troops) return (2);
				}
			}
			if (totalTroops > muster_point.max_troops) return (2);
			if (muster_point.slots <= 0) return (2);
			return null;
		}

		function aS(target, msg) {
			if (msg && msg != '')
				msg = new Date().toTimeString().substring(0, 8) + ' ' + msg;
			if (target && document.getElementById(target)) document.getElementById(target).innerHTML = msg;
		}

		function aF(o, name, val, transcoding) {
			var qty, item;
			if (Names.transco[name] && transcoding) {
				qty = Names.transco[name][1] * val;
				item = Names.transco[name][0];
			} else {
				qty = val;
				item = name;
			}
			if (!o[item]) o[item] = qty;
			else o[item] += qty;
		}

		function lq(cityIdx) {
			var ret = {};
			var generals = Seed.cities[cityIdx].generals;
			for (var i = 0; i < generals.length; i++) {
				ret[generals[i].id] = generals[i].name + ' (' + generals[i].rank + ')';
			}
			return ret;
		}

		function eQ(id, name) {
			var found = false;
			var ret = name;
			if (Data.dynamic.players.friends) {
				for (var x = 0; x < Data.dynamic.players.friends.length && !found; x++) {
					if (Data.dynamic.players.friends[x] == id) {
						found = true;
						ret = '<span class=' + UID['green'] + '>' + name + '</span>';
					}
				}
			}
			if (Data.dynamic.players.foes && !found) {
				for (var x = 0; x < Data.dynamic.players.foes.length && !found; x++) {
					if (Data.dynamic.players.foes[x] == id) {
						found = true;
						ret = '<span class=' + UID['red'] + '>' + name + '</span>';
					}
				}
			}
			return ret;
		}

		function cw(id) {
			var found = false;
			var ret = '0';
			if (Data.dynamic.players.friends) {
				for (var x = 0; x < Data.dynamic.players.friends.length && !found; x++) {
					if (Data.dynamic.players.friends[x] == id) {
						found = true;
						ret = '1';
					}
				}
			}
			if (Data.dynamic.players.foes && !found) {
				for (var x = 0; x < Data.dynamic.players.foes.length && !found; x++) {
					if (Data.dynamic.players.foes[x] == id) {
						found = true;
						ret = '-1';
					}
				}
			}
			return ret;
		}

		function dC(include_exclude, dragon_list) {
			var found = false;
			for (var gd = 0; gd < Seed.dragonList.length && !found; gd++) {
				var dragon = Seed.dragons[Seed.dragonList[gd].type];
				var curName = dragon.name;
				var isInCity = dragon.is_in_city;
				var canAttack = dragon.can_attack;
				var curLife = dragon.life;
				var maxLife = dragon.maximum_life;
				var is_in_list = true;
				if (dragon_list) is_in_list = dragon_list[Seed.dragonList[gd].type];
				if (((curLife / maxLife) >= 0.75) && isInCity && canAttack &&
					((include_exclude && is_in_list) || (!include_exclude && !is_in_list))) {
					found = true;
				}
			}
			if (found)
				return curName;
			else
				return null;
		}

		function bB() {
			var general = null;
			var rank = 6;
			for (var p in Seed.generals) {
				if (!Seed.generals[p].busy) {
					if (Seed.generals[p].rank < rank) {
						rank = Seed.generals[p].rank;
						general = Seed.generals[p]
					}
				}
			}
			return general;
		}

		function jl() {
			var ret = [];
			for (var i in Seed.player.boosts) {
				if (i == 'curser') continue;
				for (var j = 0; j < Seed.player.boosts[i].length; j++) {
					var id = 0,
						name = '';
					var boost = Seed.player.boosts[i][j];
					switch (i) {
						case 'safety':
							id = 0;
							name = 'Protection';
							break;
						case 'collect_resources':
							id = 2;
							name = translate('boost-collect-week');
							break;
						case 'food':
						case 'ore':
						case 'stone':
						case 'wood':
							id = 2;
							name = bo('name', ('nano-' + i).replace(/ |_/g, '-'), 'boosts');
							break;
						case 'gold':
							id = 2;
							name = bo('name', i.replace(/ |_/g, '-'), 'boosts');
							break;
						case 'food_curse':
							id = 5;
							name = translate('curselocusts');
							break;
						case 'ore_curse':
						case 'stone_curse':
						case 'wood_curse':
						case 'blue_curse':
							id = 5;
							name = translate(i.substring(0, i.indexOf('_')));
							if (boost.amount && boost.amount != null && boost.amount != '')
								name += ' (' + ((boost.amount < 1) ? bD(boost.amount * 100) + '%' : bD(boost.amount)) + ')';
							break;
						default:
							if (boost.source == 'timer') {
								id = 2;
								name = translate('boost-combat-' + i.replace(/ |_/g, '-'));
							} else if (boost.source == 'dragon') {
								id = 3;
								var rate = ((boost.amount < 1) ? bD(boost.amount * 100) + '%' : bD(boost.amount));
								name = bo('description', i.replace(/ |_/g, '-'), 'boosts');
								if (name.indexOf('n%') > 0) name = name.substring(0, name.indexOf('n%')) + rate + name.substring(name.indexOf('n%') + 2);
								if (name.indexOf('%boost%') > 0) name = name.substring(0, name.indexOf('%boost%')) + rate + name.substring(name.indexOf('%boost%') + 7);
							} else {
								id = 4;
								name = translate(i.replace(/ |_/g, '-'));
							}
							break;
					}
					ret.push({
						id: id,
						type: i,
						name: name,
						run_at: boost.expires_at
					});
				}
			}
			ret.sort(function(a, b) {
				if (a.id > b.id) return 1;
				else if (a.id < b.id) return -1;
				else {
					a = a.name.toLowerCase();
					b = b.name.toLowerCase();
					if (a > b) return 1;
					else if (a < b) return -1;
					return 0;
				}
			});
			return ret;
		}

		function dY(cityIdx, bId) {
			var b = Seed.cities[cityIdx].buildings;
			for (var i = 0; i < b.length; i++) {
				if (b[i].id == bId) return b[i].type;
			}
			return '';
		}

		function iJ(id) {
			var type = '';
			for (var cityIdx = 0; cityIdx < Seed.cities.length; ++cityIdx) {
				if (Seed.cities[cityIdx] && Seed.cities[cityIdx].id == id) {
					if (Seed.cities[cityIdx].type == 'Outpost') {
						switch (Seed.cities[cityIdx].outpost_type) {
							case 'WaterDragonOutpost':
								type = 'Water';
								break;
							case 'StoneDragonOutpost':
								type = 'Stone';
								break;
							case 'FireDragonOutpost':
								type = 'Fire';
								break;
							case 'WindDragonOutpost':
								type = 'Wind';
								break;
							case 'IceDragonOutpost':
								type = 'Ice';
								break;
							case 'SwampDragonOutpost':
								type = 'Swamp';
								break;
							case 'ForestDragonOutpost':
								type = 'Forest';
								break;
							case 'DesertDragonOutpost':
								type = 'Desert';
								break;
							case 'ChronoDragonOutpost':
								type = 'Chrono';
								break;
							case 'KaiserDragonOutpost':
								type = 'Sky';
								break;
							case 'CaveDragonOutpost':
								type = 'Cave';
								break;
							case 'LunaDragonOutpost':
								type = 'Luna';
								break;
							default:
								type = '';
						}
					}
				}
			}
			if (type != '') {
				if (Data.options.disable_alliance) type = '<br><span class=' + UID['bold_red'] + '>OP : ' + translate(type) + '</span>';
				else type = '<br><U><div id=' + bS('goto_reinforcement') + ' ref="' + id + '"><A><span class=' + UID['bold_red'] + '>OP : ' + translate(type) + '</span></A></div></U>';
			}
			return type;
		}

		function ih(cityIdx) {
			var type = '';
			switch (bV(cityIdx)) {
				case CAPITAL.id:
					type = CAPITAL.type;
					break;
				case WATER_OUTPOST.id:
					type = WATER_OUTPOST.type;
					break;
				case STONE_OUTPOST.id:
					type = STONE_OUTPOST.type;
					break;
				case FIRE_OUTPOST.id:
					type = FIRE_OUTPOST.type;
					break;
				case WIND_OUTPOST.id:
					type = WIND_OUTPOST.type;
					break;
				case ICE_OUTPOST.id:
					type = ICE_OUTPOST.type;
					break;
				case SWAMP_OUTPOST.id:
					type = SWAMP_OUTPOST.type;
					break;
				case FOREST_OUTPOST.id:
					type = FOREST_OUTPOST.type;
					break;
				case DESERT_OUTPOST.id:
					type = DESERT_OUTPOST.type;
					break;
				case CHRONO_OUTPOST.id:
					type = CHRONO_OUTPOST.type;
					break;
				case SKY_OUTPOST.id:
					type = SKY_OUTPOST.type;
					break;
				case CAVE_OUTPOST.id:
					type = CAVE_OUTPOST.type;
					break;
				case LUNA_OUTPOST.id:
					type = LUNA_OUTPOST.type;
					break;
				default:
					break;
			}
			return type;
		}

		function aW(error, type) {
			return (isNaN(error) ? error : translate(marchErrorTexts[error][type]));
		}

		function ba(x, y, units) {
			var dist = bu(Seed.cities[CAPITAL.id].x, Seed.cities[CAPITAL.id].y, x, y);
			var speed = 99999;
			for (var unit in units) {
				if (units[unit] > 0) {
					if (Seed.stats.unit[unit]) {
						if (Seed.stats.unit[unit].speed < speed) speed = Seed.stats.unit[unit].speed;
					} else speed = 100;
				}
			}
			var time = dist / ((Seed.cities[CAPITAL.id].figures.marches.speed_multiplier * speed) / 6000) + 30;
			return time;
		}

		function cK() {
			var count = 0,
				delay = 0,
				min_time = 700000,
				max_time = 0;
			for (var type in Data.marches) {
				if (!(/(attacks|waves|spies|multiple|bookmark|transport)/.test(type))) continue;
				for (var id in Data.marches[type]) {
					var march = (Data.marches[type])[id];
					++count;
					var left_time = (march.run_at - bV(be())) + (march.status == 'marching' ? march.duration : 0);
					if (left_time > 0) {
						min_time = min_time < left_time ? min_time : left_time;
						max_time = max_time > left_time ? max_time : left_time;
					}
				}
			}
			if (min_time === 700000 || max_time === 0) min_time = 3;
			delay = min_time + Math.randRange(2, 5);
			return {
				count: count,
				delay: delay
			};
		}

		function bJ(cityIdx) {
			var lvl = (Buildings.getLevel(cityIdx, 'MusterPoint')).max;
			if (as(Seed.cities[cityIdx].figures.marches.maximum_troops)) {
				if (lvl)
					if (lvl <= 10) var maxLvl = lvl * 10000;
					else var maxLvl = ((lvl - 10) * 20000) + 100000;
			} else var maxLvl = Seed.cities[cityIdx].figures.marches.maximum_troops;
			return ({
				slots: ((!lvl) ? 0 : lvl - Seed.numMarches),
				max_troops: maxLvl
			});
		}

		function hW() {
			var protection_time = 0,
				found = false;
			if (fT() && Seed.player.boosts.safety) {
				for (var i = 0; i < Seed.player.boosts.safety.length && !found; i++) {
					var time = Seed.player.boosts.safety[i].expires_at;
					protection_time = (time > be()) ? (time - be()) : 0;
					found = true;
				}
			}
			return protection_time;
		}

		function er() {
			if (Seed.cities[SPECTRAL_OUTPOST.id]) {
				var min = 0;
				if (Seed.cities[CAPITAL.id].souls) {
					for (var troop in Seed.cities[CAPITAL.id].souls)
						min += Seed.cities[CAPITAL.id].souls[troop];
				}
				return {
					min: min,
					max: Seed.cities[CAPITAL.id].figures.soul_cap
				};
			} else {
				return {
					min: 0,
					max: 0
				};
			}
		}

		function iR() {
			var now = be();
			var totalTrain = [];
			for (var cityIdx = 0; cityIdx < Seed.cities.length; ++cityIdx) {
				var time = 0;
				if (Seed.cities[cityIdx] && Seed.cities[cityIdx].jobs) {
					var jobs = Seed.cities[cityIdx].jobs;
					var trains = [];
					for (var j = 0; j < jobs.length; j++)
						if (jobs[j].queue == 'units' && jobs[j].unit_type && jobs[j].run_at > now) trains.push(jobs[j]);
					if (trains.length > 0) {
						trains.sort(function(a, b) {
							return a.run_at - b.run_at;
						});
						var time = trains[trains.length - 1].run_at - now;
					}
				}
				if (Seed.cities[cityIdx] && cityIdx != SPECTRAL_OUTPOST.id && cityIdx != SKY_OUTPOST.id) totalTrain.push({
					cityIdx: cityIdx,
					total: time
				});
			}
			totalTrain.sort(function(a, b) {
				return a.total - b.total
			});
			return totalTrain;
		}

		function aV(cityIdx, troopType) {
			var incity = 0,
				indefense = 0,
				marches = 0,
				intraining = 0,
				inresurrection = 0,
				inmosauleum = 0;
			var city = (typeof cityIdx == 'number') ? Seed.cities[cityIdx] : cityIdx;
			incity = city.units[troopType] ? city.units[troopType] : 0;
			if (city.defense_force) indefense = city.defense_force[troopType] ? city.defense_force[troopType] : 0;
			for (var type in Data.marches) {
				if (!(/(attacks|waves|spies|multiple|bookmark|transport)/.test(type))) continue;
				for (var id in Data.marches[type]) {
					var march = (Data.marches[type])[id];
					for (var name in march.units) {
						if (troopType == name)
							marches += march.units[name];
					}
				}
			}
			for (var city_idx = 0; city_idx < Seed.cities.length; city_idx++) {
				var trains = Jobs.getJobs('units', false, city_idx);
				for (var i = 0; i < trains.length; i++) {
					if (troopType === trains[i].unit_type)
						intraining += trains[i].quantity;
				}
			}
			for (var city_idx = 0; city_idx < Seed.cities.length; city_idx++) {
				var resurrect = Jobs.getJobs('resurrection', false, city_idx);
				for (var i = 0; i < resurrect.length; i++) {
					if (troopType === resurrect[i].unit_type)
						inresurrection += resurrect[i].quantity;
				}
			}
			var souls = Seed.cities[0].souls;
			if (souls && souls[troopType]) inmosauleum += souls[troopType];

			return {
				incity: incity,
				indefense: indefense,
				marches: marches,
				intraining: intraining,
				inresurrection: inresurrection,
				souls: inmosauleum,
				total: incity + marches + indefense,
				all: incity + marches + indefense + intraining + inresurrection + inmosauleum
			};
		}

		function cq(trps, sep) {
			var result = '';
			var tRes = [];
			for (var i in trps) {
				if (trps[i] > 0) tRes.push(bD(trps[i], ' ') + ' ' + translate(i));
				else if (trps[i] == -1) tRes.push('Max ' + translate(i));
			}
			if (tRes.length > 0) result = tRes.join(',' + sep);
			return result;
		}

		function da(cityIdx, unit) {
			var trainables = Seed.stats.unit[unit].trainable,
				found = false;
			var city_type = ih(cityIdx);
			for (i = 0; i < trainables.length && !found; i++) {
				if (city_type == trainables[i]) found = true;
			}
			return found;
		}

		function jo() {
			if (Seed.player.boosts.safety) return true;
			else return false;
		}

		function bF(event) {
			var ids = event.target.getAttribute('ref').split('_');
			eH(ids[1], ids[0], true);
		}

		function bM(what, bA, error, prefix, delay) {
			var prefixMsg = (prefix ? aW(0, 'vb') + ' ' : '');
			var verboseMsg = prefixMsg + aW(error, 'vb');
			var feedbackMsg = aW(error, 'fb');
			aZ(what + ' ' + verboseMsg + ': ' + translate('Retry in') + ' ' + delay + ' ' + translate('seconds'));
			aS(bA, feedbackMsg + ': ' + translate('Retry in') + ' ' + delay + ' ' + translate('seconds'));
		}

		function eo(container, aD) {
			var options = {
				cities: [],
				jobs: true,
				dragons: true
			};
			options.cities.push(Seed.cities[CAPITAL.id].id);
			var dial = new aw(container, 300, 165, '', false, null);
			dial.bd().innerHTML = '<div class=' + UID['title'] + '><center><b>' + scriptName + ' : ' + translate('Message') + '</b></center></div>';
			dial.getContentDiv().innerHTML = translate('Refreshing player and cities data');
			Seed.fetchPlayer(function(rslt) {
				if (rslt.ok) {
					aZ(translate('Player data was Successfully requested from the server'));
					try {
						dial.destroy();
					} catch (e) {}
					if (aD) aD(true);
					return;
				} else {
					try {
						dial.getContentDiv().innerHTML = translate('Error while retrieving player data') + '&nbsp;\n' + rslt.errmsg; 
						dial.allowClose(true);
					} catch (e) {}
					if (aD) aD(false);
					return;
				}
			}, options);
		}

		function dj(container, x, y, type, level, id, name, units, ai, include_great_dragon, include_exclude, great_dragons, comment) {
			if (Data.options.bookmarks.targets && Data.options.bookmarks.targets.length > 0) {
				var h = aA(Data.options.bookmarks.targets);
				for (var i = h.length - 1; i >= 0; i--) {
					if ((h[i].x == x) && (h[i].y == y))
						Data.options.bookmarks.targets.splice(i, 1);
				}
			}
			var target_desc = '',
				target_id = id,
				target_name = name;
			var target_type = 0;
			Map.tileAt({
				x: x,
				y: y,
				force_request: false
			}, function(target) {
				if (target && target.ok) {
					if (target.t == 7 || target.t >= 10) target_type = 0;
					else if (target.t == 8) target_type = 1;
					else target_type = 2;
					var type_name = Map.names.type[target.t] || target.t;
					if (target.cn != undefined && target_type == 0) {
						target_desc = translate(type_name) + ' ' + target.n + ' (' + bD(target.m) + ')' + ((target.a != undefined && target.a != 0) ? ' / ' + target.a : '');
						target_id = target.id;
						target_name = target.n;
					} else {
						target_desc = translate(type_name) + ' ' + target.l;
						target_id = '';
						target_name = '';
					}
				}
			});
			var dragon_list = {};
			if (include_great_dragon) {
				for (var gd = 0; gd < Seed.dragonList.length; gd++) {
					var dragon = Seed.dragonList[gd].type;
					var is_in_list = (include_exclude ? false : true);
					if (great_dragons)
						is_in_list = great_dragons[Seed.dragonList[gd].type];
					if ((include_exclude && is_in_list) || (!include_exclude && !is_in_list)) {
						dragon_list[dragon] = true;
					} else {
						dragon_list[dragon] = false;
					}
				}
			}

			var rec = {
				x: x,
				y: y,
				t: target_type,
				d: bu(Seed.cities[CAPITAL.id].x, Seed.cities[CAPITAL.id].y, x, y),
				ti: ba(x, y, units),
				type: target_desc,
				level: level,
				id: target_id,
				n: target_name,
				units: aA(units),
				dragons: dragon_list,
				inc: include_great_dragon,
				comment: comment
			};
			Data.options.bookmarks.targets.push(rec);
			var dial = new aw(container, 300, 150, '', false);
			dial.bd().innerHTML = '<div class=' + UID['title'] + '><center><b>' + scriptName + ' : ' + translate('Message') + '</b></center></div>';
			dial.getContentDiv().innerHTML = translate('Bookmark saved');
			setTimeout(function() {
				dial.destroy()
			}, 1000);
		}

		function bG(button, enabled, class_enabled, class_disabled) {
			if (!button) return;
			if (enabled) {
				button.disabled = false;
				Element.removeClassName(button, (class_disabled ? UID[class_disabled] : UID['btn_disabled']));
				Element.addClassName(button, (class_enabled ? UID[class_enabled] : UID['btn_blue']));
			} else {
				button.disabled = true;
				Element.removeClassName(button, (class_enabled ? UID[class_enabled] : UID['btn_blue']));
				Element.addClassName(button, (class_disabled ? UID[class_disabled] : UID['btn_disabled']));
			}
		}

		function df(container, city_id, units, aD) {
			var dial = new aw(container, 300, 165, '', false, null);
			dial.bd().innerHTML = '<div class=' + UID['title'] + '><center><b>' + scriptName + ' : ' + translate('Message') + '</b></center></div>';
			dial.getContentDiv().innerHTML = translate('wall-choose-defenders');
			MyAjax.setDefenseForce(city_id, units, bO);

			function bO(dat) {
				if (dat.ok) {
					if (aD) aD(true);
					dial.destroy();
				} else {
					dial.getContentDiv().innerHTML = translate('Error while setting defense choice');
					dial.allowClose(true);
					if (aD) aD(false);
					return;
				}
			}
		}

		function du(tab, rownum, prefix, unit_types, units, units_save, listener, multilines) {
			var row = [];
			row.push(tab.insertRow(rownum));
			row.push(tab.insertRow(rownum + 1));
			var val, r = 0,
				c = 0;
			for (var i = 0; i < unit_types.length; ++i) {
				if (c == 9) {
					r = r + 2;
					row.push(tab.insertRow(rownum + r));
					row.push(tab.insertRow(rownum + r + 1));
					c = 0;
				}
				row[r].insertCell(c).innerHTML = translate(Names.getTroopAbbr(unit_types[i]));
				var inp = document.createElement('input');
				inp.type = 'text';
				inp.size = '1';
				inp.style.width = '40px';
				inp.title = translate(unit_types[i]);
				if (i < 3) inp.style.border = '1px solid grey';
				else if (i < 6) inp.style.border = '1px solid green';
				else if (i < 12) inp.style.border = '1px solid blue';
				else inp.style.border = '1px solid red';
				inp.maxlength = '6';
				if (units[unit_types[i]] == undefined)
					units[unit_types[i]] = 0;
				val = units[unit_types[i]];
				if (!as(units_save)) {
					if (units_save[unit_types[i]] == undefined)
						units_save[unit_types[i]] = 0;
					val = units_save[unit_types[i]];
				}
				if (!val) val = 0;
				inp.value = val;
				inp.name = prefix + '_' + i;
				inp.addEventListener('change', listener, false);
				row[r + 1].insertCell(c).appendChild(inp);
				c++;
			}
			return tab;
		}

		function fT() {
			return Seed.cities[CAPITAL.id].protected
		}


Tabs.Info={tabOrder:INFO_TAB_ORDER,tabLabel:"Info",tabDisabled:!INFO_TAB_ENABLE,container:null,timer:null,contentType:0,troopsContentType:0,infoScrollPos:0,infoScrollLeft:0,lastSubTab:"tabInfoOverview",refreshPlayerBusy:false,show_fulscreen:false,dragonTimer:null,diff:null,init:function(e){function u(){try{bI("Mute sound");swf_object.musicMute()}catch(e){}MyAjax.save_sound()}function a(e){var n=document.body.offsetWidth-570;if(n<760)n=760;t.show_fulscreen=!t.show_fulscreen;e.target.className=UID[t.show_fulscreen?"btn_on":"btn_off"];swf_width=t.show_fulscreen?"99%":n+"px";document.getElementById("container").style.width=swf_width;document.getElementById("castlemania_swf").style.width=swf_width;document.getElementById("castlemania_swf_container").style.width=swf_width}var t=Tabs.Info;for(var n=0;n<Seed.quests.category.length;n++){for(var r=0;r<Seed.quests.list[Seed.quests.category[n]].length;r++){var i=Seed.quests.list[Seed.quests.category[n]][r];var s=false;if(Seed.player.quests.claimed){for(var o=0;o<Seed.player.quests.claimed.length&&!s;o++){if(name==Seed.player.quests.claimed[o])s=true}}if(s)Seed.quests.list[Seed.quests.category[n]].splice(r,1)}}t.container=e;e.innerHTML="<div class="+UID["title_main"]+' style="padding-top:3px; padding-bottom:3px;">'+"<table width=80% align=center>"+'	<tr align=center><td width="100px"><a id='+bS("tabInfo_ScriptUpdate")+' style="color:#ffffff;text-decoration:none;">'+translate("Version update")+"</a></td>"+'		<td width="100px"><a href="'+Data.options.wikiUrl+'" target="_blank" style="color:#FFFFFF;text-decoration:none;">'+kWikiLink+"</a></td>"+'		<td width="100px"><a href="'+Data.options.forumUrl+'" target="_blank" style="color:#FFFFFF;text-decoration:none;">'+kForumLink+"</a></td>"+"</tr></table></div>"+"<table width=100%><tr>"+"	<td width=20%><input id="+bS("tabInfo_Refresh")+' type=button value="'+translate("Refresh")+'"></input></td>'+"	<td width=20% align=center><input id="+bS("tabInfo_Toggle")+' type=button value="'+translate("Toggle Flash")+'"></input></td>'+"	<td width=20% align=center>"+(REALM_URL==null||REALM_URL==""||!REALM_URL?"":"<input id="+bS("tabInfo_Reload")+' type=button value="'+translate("Reload")+'"></input>')+"</td>"+'	<td width=20% align=center><input style="margin-left:5px;width:100px;" class="'+UID[t.show_fulscreen?"btn_on":"btn_off"]+'" type=button value="Fullscreen" id='+bS("Tabs.Info.fullScreen")+" /></td>"+"</tr></table>"+"<ul class=tabs>"+'	<li class="tab first"><a id='+bS("tabInfoOverview")+">"+translate("Overview")+"</a></li>"+"	<li class=tab><a id="+bS("tabInfoInventory")+">"+translate("items-panel")+"</a></li>"+"	<li class=tab><a id="+bS("tabInfoQuests")+">"+translate("Quests")+"</a></li>"+"	<li class=tab><a id="+bS("tabInfoTroops")+">"+translate("Troops")+"</a></li>"+"	<li class=tab><a id="+bS("tabInfoStats")+">"+translate("Stats")+"</a></li>"+"	<li class=tab><a id="+bS("tabInfoHelp")+">"+translate("Player infos")+"</a></li>"+"</ul>"+"<div id="+bS("tabInfo_Content")+' class="'+UID["scrollable"]+'" style="margin-top:1px !important; height:650px; max-height:650px;"></div>';document.getElementById(UID["tabInfo_Refresh"]).addEventListener("click",t.refresh,false);if(REALM_URL&&REALM_URL!=null&&REALM_URL!="")document.getElementById(UID["tabInfo_Reload"]).addEventListener("click",le,false);document.getElementById(UID["tabInfo_Toggle"]).addEventListener("click",dX,false);document.getElementById(UID["tabInfoOverview"]).addEventListener("click",t.tabInfoOverview,false);document.getElementById(UID["tabInfo_ScriptUpdate"]).addEventListener("click",AutoUpdater.manualCheck,false);document.getElementById(UID["tabInfoInventory"]).addEventListener("click",t.tabInfoInventory,false);document.getElementById(UID["tabInfoQuests"]).addEventListener("click",t.tabInfoQuests,false);document.getElementById(UID["tabInfoTroops"]).addEventListener("click",t.tabInfoTroops,false);document.getElementById(UID["tabInfoStats"]).addEventListener("click",t.tabInfoStats,false);document.getElementById(UID["tabInfoHelp"]).addEventListener("click",t.tabInfoHelp,false);document.getElementById(UID["Tabs.Info.fullScreen"]).addEventListener("click",a,false);t.contentType=Data.options.info.current_tab;t.show()},show:function(){var e=Tabs.Info;switch(bV(e.contentType)){case 0:e.tabInfoOverview();break;case 1:e.tabInfoInventory();break;case 2:e.tabInfoQuests();break;case 3:e.tabInfoHelp();break;case 4:e.tabInfoTroops();break;case 5:e.tabInfoStats();break}},hide:function(){var e=Tabs.Info;clearTimeout(e.timer)},onUnload:function(){var e=Tabs.Info;bI("===============  Tabs.Info.onUnload");Data.options.info.current_tab=e.contentType},tabInfoOverview:function(){function S(t){if(e.contentType==0){e.infoScrollPos=document.getElementById(UID["tabInfo_Content"]).scrollTop}}function x(t){if(e.contentType==0){e.infoScrollLeft=document.getElementById(UID["tabInfo_Unitsbox"]).scrollLeft}}function T(e){var t=["BodyArmor","ClawGuards","TailGuard","Helmet"],n=0,r="";for(var i=0;i<t.length;i++){if(bV(Seed.player.items[e+t[i]])!==0){n++}}if(n!=4){r=" ("+translate("Got")+" "+n+"/4)"}return r}function N(){var e="",t="",n=jl();for(var r=0;r<n.length;r++){if(fT()&&n[r].type=="safety"&&n[r].run_at){if(n[r].run_at>be()){var i=bE(n[r].run_at-be(),true);e+="<tr><td width=100% colspan=4><div class="+UID["info_protect"]+">Protection : "+i+"</div></td></tr>"}}if(n[r].type!="safety"){var s=n[r];if(n[r].run_at&&n[r].run_at>be()){var i=bE(n[r].run_at-be(),true);if(n[r].id==2){t+='<tr><td width=100%><font color="yellow">'+n[r].name+" : "+i+"</font></td></tr>"}else if(n[r].id==5){t+='<tr><td width=100%><font color="orange">'+n[r].name+" : "+i+"</font></td></tr>"}else{t+="<tr><td width=100%>"+n[r].name+" : "+i+"</td></tr>"}}else if(!n[r].run_at||n[r].run_at==null||n[r].run_at==""){t+="<tr><td width=100%>"+n[r].name+"</td></tr>"}}}if(t!=""){e+="<tr><td width=100% colspan=4><div class="+UID["info_boosts"]+"><table width=100%>"+t+"</table></div></td></tr>"}return e}function C(){var e="",t=Jobs.getJobs("breeding",false,-1);for(var n=0;n<t.length;n++){var r="",i=0,s="",o="";if(n==0){r=translate("breeding-dragon")+":";i=t[n].run_at-be()>0?t[n].run_at-be():0}else{i=t[n].duration}if(!Seed.sanctuary_dragons[t[n].male_id]){s=t[n].male_id;aZ("Error: Inexisting dragon "+t[n].male_id)}else{s=bo(Seed.sanctuary_dragons[t[n].male_id].subtype,"rank-"+Seed.sanctuary_dragons[t[n].male_id].type,"dragons")}if(!Seed.sanctuary_dragons[t[n].female_id]){aZ("Error: Inexisting dragon "+t[n].female_id);o=t[n].female_id}else{o=bo(Seed.sanctuary_dragons[t[n].female_id].subtype,"rank-"+Seed.sanctuary_dragons[t[n].female_id].type,"dragons")}e+="<tr>"+"		<td class=right width=20%>"+r+"</td>"+"		<td align=left width=50% colspan=2>"+s+" + "+o+"</td>"+"     <td width=30%><font color="+TIMER_COLOR+">"+bE(i,true)+"</font></td>"+"</tr>"}return e}function k(e){var t="<tr><td width=20% class=right>"+translate("Building")+": </td>",n=Jobs.getBuildingJob(e);if(n&&n.job.run_at>be()){t+="<td width=50% align=left colspan=2>"+translate(n.building.type)+" ("+n.job.level+") &nbsp;</td>"+"<td width=30%><font color="+TIMER_COLOR+">"+bE(n.job.run_at-be(),true)+"</font></td>"+"</tr>"}else{t+="<td align=left width=80% colspan=3><span class="+UID["bold_red"]+">"+translate("None").toUpperCase()+"</span></td></tr>"}return t}function L(e){var t="<tr><td width=20% class=right>"+translate("Building")+": </td>",n=Jobs.getDefenseTowerJob(e);if(n&&n.job.run_at>be()){t+="<td width=50% align=left colspan=2>"+translate(n.building.type)+" ("+n.job.level+") &nbsp;</td>"+"<td width=30%><font color="+TIMER_COLOR+">"+bE(n.job.run_at-be(),true)+"</font></td>"+"</tr>"}else{t+="<td align=left width=80% colspan=3><span class="+UID["bold_red"]+">"+translate("DefensiveTower")+" "+translate("None").toUpperCase()+"</span></td></tr>"}return t}function A(e){var t="<tr><td width=20% class=right>"+translate("Repairing")+": </td>",n=Jobs.getDefenseTowerHealing(e);if(n&&n.job.run_at>be()){t+="<td width=50% align=left colspan=2><span class="+UID["bold_red"]+">"+translate("DefensiveTower")+"</span> &nbsp;</td>"+"<td width=30%><font color="+TIMER_COLOR+">"+bE(n.job.run_at-be(),true)+"</font></td>"+"</tr>"}else{t+="<td align=left width=80% colspan=3><span class="+UID["bold_red"]+">"+translate("DefensiveTower")+" "+translate("None").toUpperCase()+"</span></td></tr>"}return t}function O(e){var t='<table style="margin-top:3px" width=100% class='+UID["row_style"]+">"+"	<tr class="+UID["row_headers"]+" align=center>"+"		<td width=20%>"+translate("Type")+"</td>"+"		<td width=20%>"+translate("Reserves")+"</td>"+"		<td width=15%>"+translate("Per Hour")+"</td>"+"		<td width=20%>"+translate("Consumption")+"</td>"+"		<td width=25%>"+translate("Capacity")+"</td>"+"	</tr>";for(var n=0;n<all_resource_types.length;n++){var r=false;var i=Seed.cities[e].figures.resource_rates[all_resource_types[n]];var s=bD(bV(Seed.cities[e].resources[all_resource_types[n]]));if(all_resource_types[n]=="food"&&Seed.player.boosts&&Seed.player.boosts.collect_resources&&bV(Seed.cities[e].resources[all_resource_types[n]])>i.capacity){r=true}desc=all_resource_types[n];if(all_resource_types[n]=="blue_energy"){desc="blueenergy250k"}t+="	<tr valign=top align=center>"+"		<td align=right class=jewel>"+translate(desc)+"</td>"+"		<td align=right class=jewel>"+s+"</td>"+"		<td align=right class=jewel>"+(r?"<font color=blue><b>0</b></font>":bD(bV(i.rate)))+"</td>"+"		<td align=right class=jewel>"+bD(bV(i.unit_consumption||i.general_salaries||0))+"</td>"+"		<td align=right class=jewel>"+(i.capacity===1e18?translate("Unlimited"):bD(i.capacity))+"</td>"+"	</tr>"}t+="</table>";return t}function M(e){var t=Seed.cities[e].figures.population;var n=t.current-t.laborers-t.armed_forces;n=n<0?0:n;var r='<table style="margin-top:3px" width=100%>'+"	<tr class="+UID["row_headers"]+" align=center>"+"		<td width=20%>"+translate("Population")+"</td>"+"		<td width=20%>"+translate("Laborers")+"</td>"+"		<td width=20%>"+translate("Army")+"</td>"+"		<td width=20%>"+translate("IdlePopulation").replace(translate("Population"),"")+"</td>"+"		<td width=20%>"+translate("Capacity")+"</td>"+"	</tr>"+"	<tr>"+"		<td align=right>"+bD(t.current)+"</td>"+"		<td align=right>"+bD(t.laborers)+"</td>"+"		<td align=right>"+bD(t.armed_forces)+"</td>"+"		<td align=right>"+bD(n)+"</td>"+"		<td align=right>"+bD(t.limit)+"</td>"+"	</tr>"+"</table>";return r}function _(e,t){var n="",r=Jobs.getJobs(e,false,t);for(var i=0;i<r.length;i++){var s="",o=0,u="";var a=e=="feeding"?r[i].dragon_id:r[i].egg_id;if(i==0){s=translate(e=="feeding"?"upgrading-dragon":"hatching-egg")+":";o=r[i].run_at-be()>0?r[i].run_at-be():0}else{o=r[i].duration}if(!Seed.sanctuary_dragons[a]){u=a;aZ("Error: Inexisting dragon "+a)}else{u=bo(Seed.sanctuary_dragons[a].subtype,"rank-"+Seed.sanctuary_dragons[a].type,"dragons")}n+="<tr>"+"		<td class=right width=20%>"+s+"</td>"+"		<td align=left width=50% colspan=2>"+u+"</td>"+"     <td width=30%><font color="+TIMER_COLOR+">"+bE(o,true)+"</font></td>"+"</tr>"}return n}function D(){var e="",t="";if(Marches.count.attacks>0){t=Marches.count.attacks+" At";e=" + "}if(Marches.count.waves>0){t+=e+Marches.count.waves+" Wa";e=" + "}if(Marches.count.bookmark>0){t+=e+Marches.count.bookmark+" Bo";e=" + "}if(Marches.count.transport>0){t+=e+Marches.count.transport+" Tr";e=" + "}if(Marches.count.spies>0){t+=e+Marches.count.spies+" Sp";e=" + "}if(Marches.count.multiple>0){t+=e+Marches.count.multiple+" Mu"}if(t!=""){t=" ("+t+")"}return t}function P(){var e=Tabs.Info,t="";if(E429_TIMER){if(E429_TIMER>bV(be())){var n=cc(E429_TIMER-bV(be()));t="<div class="+UID["info_alerts"]+" width=100%><br><b>API</b> "+translate("<b>Rate Limit Exceeded</b>, too many requests!")+" <b>&nbsp;&nbsp;"+n+"</b><br>&nbsp;</div>"}else{E429_TIMER=0}}return t}function H(e,t){var n="",r=Jobs.getJobs(e,true,t)[0];if(r&&r.run_at>be()){n+="<tr><td class=right width=20%>"+translate(e=="outpost"?"Repairing":"Healing")+":</td>"+"<td width=50% colspan=2><SPAN class="+UID["bold_red"]+">"+translate(e=="outpost"?"outpost-progress":"Dragon healing")+"</span></td>"+"<td width=30%><font color="+TIMER_COLOR+">"+bE(r.run_at-be(),true)+"</font></td></tr>"}return n}function B(e){var t="<tr>"+"		<td class=right width=20%>"+translate("Researching")+": </td>";var n=Jobs.getJobs("research",true,e)[0];if(n&&n.run_at>be()){t+="<td width=50% align=left colspan=2>"+translate(n.research_type)+" ("+n.level+") &nbsp;</td>"+"<td width=30%><font color="+TIMER_COLOR+">"+bE(n.run_at-be(),true)+"</font></td>"+"</tr>"}else if(e==CAPITAL.id){t+="<td align=left width=80% colspan=3><span class="+UID["bold_red"]+">"+translate("None").toUpperCase()+"</span></td></tr>"}else{t=""}return t}function j(e){var t="",n=[];for(var r=0;r<Seed.cities[e].jobs.length;r++){if(Seed.cities[e].jobs[r].queue=="resurrection"&&Seed.cities[e].jobs[r].unit_type&&Seed.cities[e].jobs[r].run_at>be()){n.push(Seed.cities[e].jobs[r])}}n.sort(function(e,t){return e.run_at-t.run_at});for(var r=0;r<n.length;r++){var i="",s="",o=0;if(r==0){i=translate("Resurrection")+":";o=n[r].run_at-be()>0?n[r].run_at-be():0}else if(r==n.length-1){o=n[r].run_at-be()>0?n[r].run_at-be():0;s="&nbsp;<b>("+bz(o)+")</b>";o=n[r].duration}else{o=n[r].duration}t+="<tr>"+"		<td class=right width=20%>"+i+"</td>"+"		<td align=left width=50% colspan=2>"+bD(n[r].quantity," ")+"&nbsp;&nbsp;"+translate(n[r].unit_type)+"&nbsp;</td>"+"     <td width=30%><font color="+TIMER_COLOR+">"+bE(o,true)+"</font>&nbsp"+s+"</td>"+"</tr>"}return t}function F(){var e="",t=er(),n="";if(t&&t.max>0){var r=t.min/t.max*1e4;if(r>9e3)n="<span class="+UID["bold_red"]+">"+bD(Math.round(r/100)," ")+"%</span>";else n="<font color="+TIMER_COLOR+">"+bD(Math.round(r/100)," ")+"%</font>";e+="<tr><td class=right width=20%>"+translate("Capacity")+":</td>"+"	<td width=50% colspan=2><font color="+TIMER_COLOR+"><b>"+bD(t.min," ")+" / "+bD(t.max," ")+"</b></span></td>"+"	<td width=30%>"+n+"</td>"+"</tr>"}return e}function I(e){var t="",n=[];for(var r=0;r<Seed.cities[e].jobs.length;r++){if(Seed.cities[e].jobs[r].queue=="units"&&Seed.cities[e].jobs[r].unit_type&&Seed.cities[e].jobs[r].run_at>be()){n.push(Seed.cities[e].jobs[r])}}n.sort(function(e,t){return e.run_at-t.run_at});for(var r=0;r<n.length;r++){var i="",s="",o=0;if(r==0){i=translate("Training")+":";o=n[r].run_at-be()>0?n[r].run_at-be():0}else if(r==n.length-1){o=n[r].run_at-be()>0?n[r].run_at-be():0;s="&nbsp;<b>("+bz(o)+")</b>";o=n[r].duration}else{o=n[r].duration}t+="<tr>"+"		<td class=right width=20%>"+i+"</td>"+"		<td align=left width=50% colspan=2>"+bD(n[r].quantity," ")+"&nbsp;&nbsp;"+translate(n[r].unit_type)+"&nbsp;</td>"+"     <td width=30%><font color="+TIMER_COLOR+">"+bE(o,true)+"</font>&nbsp"+s+"</td>"+"</tr>"}return t}function q(e){var n='<table width=100% style="margin-top:3px;">'+"	<tr valign=top>"+'		<td width="180px">'+"			<table class="+UID["row_style"]+" width=100% id="+bS("tabInfoUnits_Unit")+">"+"				<tr class="+UID["row_headers"]+" align=center>"+'					<td width="180px">'+translate("Troops")+"</td>"+"				</tr>";for(var r=0;r<all_unit_types.length;r++){var i=aV(t,all_unit_types[r]);n+="			<tr valign=top>"+"				<td class=right>"+translate(all_unit_types[r])+":</td>"+"			</tr>"}n+="			</table>"+"		</td>"+'		<td width="345px">'+"			<div id="+bS("tabInfo_Unitsbox")+' style="width:345px; max-width:345px; overflow-x:auto;">'+"			<div id="+bS("tabInfo_UnitsTable")+' style="width:560px; max-width:560px">'+"			<table class="+UID["row_style"]+" width=100% id="+bS("tabInfoUnits_Detail")+">"+"				<tr class="+UID["row_headers"]+">"+'					<td width="70px">'+translate("Army")+"</td>"+'					<td width="70px">'+translate("Defense")+"</td>"+'					<td width="70px">'+translate("In city")+"</td>"+'					<td width="70px">'+translate("In march")+"</td>"+'					<td width="80px">'+translate("Total")+"</td>"+'					<td width="70px">'+translate("Train")+"</td>"+'					<td width="70px">'+translate("Resurrect")+"</td>"+'					<td width="60px">'+translate("Souls")+"</td>"+"				</tr>";for(var r=0;r<all_unit_types.length;r++){var i=aV(t,all_unit_types[r]);n+="			<tr valign=top>"+"				<td align=right>"+bD(i.total," ")+"</td>"+"				<td align=right>"+bD(i.indefense," ")+"</td>"+"				<td align=right>"+bD(i.incity," ")+"</td>"+"				<td align=right>"+(i.marches?"&nbsp;+&nbsp;<b>"+bD(i.marches," ")+"</b>":"")+"</td>"+"				<td align=right><b>"+bD(i.all," ")+"</b></td>"+"				<td align=right>"+(i.intraining?bD(i.intraining," "):"")+"</td>"+"				<td align=right>"+(i.inresurrection?bD(i.inresurrection," "):"")+"</td>"+"				<td align=right>"+(i.souls?bD(i.souls," "):"")+"</td>"+"			</tr>"}n+="			</table>"+"			</div></div>"+"		</td>"+"	</tr>"+"</table>";return n}function R(){var e=bV(Seed.player.max_wildernesses);var t=bV(Seed.player.player_wildernesses.length);var n=t<e?"<span class="+UID["bold_red"]+">"+t+"</span>":t;n+=" / "+e;return n}function U(e){var t=Tabs.Info;var n=e.target;var r=Seed.cities[CAPITAL.id].id;var i=Seed.cities[CAPITAL.id].defended;var s=translate("Switching defense");aZ(s+" "+translate("attempted"));new MyAjax.dr(r,i,function(e){if(e.ok){aZ(s+" "+translate("Successfully"));aX(s);n.className=UID[Seed.cities[CAPITAL.id].defended?"btn_off":"btn_on"];n.value=translate(Seed.cities[CAPITAL.id].defended?"Defend":"Hiding").toUpperCase()}else{aZ(s+" "+translate("failed and returned error")+": "+e.errmsg)}});var o=Seed.cities[CAPITAL.id].defended;n.className=UID[o?"btn_off":"btn_on"];n.value=translate(o?"Defend":"Hiding").toUpperCase()}var e=Tabs.Info;var t=Seed.cities[CAPITAL.id];var n="<div class="+UID["status_ticker"]+">";var r=Seed.player.alliance?Seed.player.alliance.name:"";var i=translate(Seed.cities[CAPITAL.id].defended?"Defend":"Hiding").toUpperCase();var s="";clearTimeout(e.timer);document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabInfoOverview"]).className="selected";document.getElementById(UID["tabInfoOverview"]).style.zIndex=1;e.lastSubTab="tabInfoOverview";e.contentType=0;Data.options.info.current_tab=e.contentType;n+="<div class="+UID["subtitle"]+"><table class="+UID["table"]+">"+"<tr><td align=left width=35%>"+t.name+"</td>"+"<td align=center width=30%>"+t.x+","+t.y+"</td>"+"<td align=center width=200px><font color=yellow>"+r+"</font></td>"+"<TD width=35% align=right><input id="+bS("tabInfo_setDefense")+" type=button value="+i+" class="+UID[Seed.cities[CAPITAL.id].defended?"btn_off":"btn_on"]+"></input></td>"+"</tr></table></div>";n+=O(CAPITAL.id)+M(CAPITAL.id)+P()+SoundPlayer.alertString.replace("&incoming_spy&",SoundPlayer.getFirstAlert().spy).replace("&incoming_attack&",SoundPlayer.getFirstAlert().attack)+q(CAPITAL.id)+"<br>"+"<table class="+UID["table"]+" width=100%>"+N()+"	<tr>"+"		<td class=right width=20%>"+translate("Marching")+": </td>"+"		<td width=30%>"+Seed.numMarches+D()+"</td>"+"		<td class=right width=20%>"+translate("Wildernesses")+": </td>"+"		<td width=30%>"+R()+ +"	</tr>"+H("dragon",CAPITAL.id)+A(CAPITAL.id)+H("outpost",CAPITAL.id)+k(CAPITAL.id)+B(CAPITAL.id)+I(CAPITAL.id)+"</table>"+"</div>";if(Seed.cities.length>0){for(var o=1;o<Seed.cities.length;++o){if(Seed.cities[o]){n+="<div class="+UID["status_ticker"]+' style="margin-top:6px !important">'+e.dR(o)+"<table class="+UID["table"]+" width=100%>"+(o==SPECTRAL_OUTPOST.id?F():"")+H("dragon",o)+H("outpost",o)+k(o)+B(o)+I(o)+j(o)+"</table>"+"</div>"}}}n+="<br><div class="+UID["status_ticker"]+' style="margin-top:6px !important">'+"<div class="+UID["subtitle"]+"><table class="+UID["table"]+">"+"<tr><td align=left width=35%>"+translate("dragon-sanctuary")+"</td>"+"<td align=right width=65%>&nbsp;</td>"+"</tr></table></div>"+"<table class="+UID["table"]+" width=100%>"+C()+_("hatching",CAPITAL.id)+_("feeding",CAPITAL.id)+"</table>"+"</div>"+"<br>"+'<table style="margin-top:3px" width=100%>'+"	<tr class="+UID["row_headers"]+" align=center>"+"		<td width=50%>"+translate("Generals").toUpperCase()+"</td>"+"		<td width=50%>"+translate("Great dragons").toUpperCase()+"</td>"+"	</tr>"+"	<tr valign=top align=center>"+'		<td width=50% style="border-right: 1px solid;">';n+="		<table class="+UID["table"]+">";for(var u=0;u<t.generals.length;u++){for(var a in Data.marches){if(!/(attacks|waves|spies|multiple|bookmark|transport)/.test(a)){continue}for(var f in Data.marches[a]){var l=Data.marches[a][f];if(l.march_type!="TransportMarch"&&l.march_type!="SpyMarch"){try{if(t.generals[u].name==l.general.first_name){s=l.x+","+l.y;if(l.status=="encamped")className="bluejwl";else className="jewel"}}catch(c){aZ(translate("Error")+": "+"general first_name not available"+c.name+" "+c.message)}}}}n+="		<tr>"+'			<td width=50% align=right><font color="#000000">'+t.generals[u].name+" ("+t.generals[u].rank+")</font></td>"+"			<td width=50%>"+(t.generals[u].busy?'<span class="'+className+'">['+s+"]</span>":"")+"</td>"+"		</tr>"}n+="		</table>"+"	</td>"+'	<td width=50% style=" padding-left:7px">'+"		<table class="+UID["table"]+">";for(var h=0;h<Seed.dragonList.length;h++){var p=Seed.dragons[Seed.dragonList[h].type];var d="";var v=" ("+bD(Math.round(p.life/p.maximum_life*100)," ")+" %)";if(p.life/p.maximum_life>=.75&&p.is_in_city&&p.can_attack){d=translate("Ready")+v}else if(!p.is_in_city&&p.can_attack){d=translate("Attacking")}else if(!p.can_attack){d=translate("Not ready")+T(Seed.dragonList[h].type)}else if(p.life/p.maximum_life<.75){d=translate("Healing")+v}else{d=translate("Not ready")+T(Seed.dragonList[h].type)}n+="		<tr>"+'			<td width=50% align=right><font color="#000000">'+translate(p.name)+"</font></td>"+"			<td width=50%><span class=jewel>"+d+"</span></td>"+"		</tr>"}n+="		</table>"+"		</td>"+"	</tr>"+"</table>";document.getElementById(UID["tabInfo_Content"]).innerHTML=n;document.getElementById(UID["tabInfo_Content"]).scrollTop=e.infoScrollPos;document.getElementById(UID["tabInfo_Content"]).addEventListener("scroll",S,false);document.getElementById(UID["tabInfo_Unitsbox"]).scrollLeft=e.infoScrollLeft;document.getElementById(UID["tabInfo_Unitsbox"]).addEventListener("scroll",x,false);document.getElementById(UID["tabInfo_setDefense"]).addEventListener("click",U,false);var m=document.getElementById(UID["tabInfoUnits_Unit"]).getElementsByTagName("TR");var g=document.getElementById(UID["tabInfoUnits_Detail"]).getElementsByTagName("TR");for(var y=0;y<m.length;y++){var b=m[y].getElementsByTagName("TD")[0];var w=g[y].getElementsByTagName("TD")[0];if(b.offsetHeight!=w.offsetHeight){var E=(b.offsetHeight>w.offsetHeight?b.offsetHeight:w.offsetHeight)-2;b.setAttribute("height",E);w.setAttribute("height",E)}}var m=document.getElementById(UID["tabInfoUnits_Unit"]).getElementsByTagName("TR");var g=document.getElementById(UID["tabInfoUnits_Detail"]).getElementsByTagName("TR");for(var y=0;y<m.length;y++){var b=m[y].getElementsByTagName("TD")[0];var w=g[y].getElementsByTagName("TD")[0];if(b.offsetHeight!=w.offsetHeight){var E=(b.offsetHeight>w.offsetHeight?b.offsetHeight:w.offsetHeight)-2;b.setAttribute("height",E);w.setAttribute("height",E)}}e.timer=setTimeout(e.show,1e3)},tabInfoInventory:function(){function h(e){var t=bV(e.target.value);if(t>50){e.target.style.backgroundColor=""}else{e.target.style.backgroundColor=""}}function p(t){var n=t.target.getAttribute("ref");t.target.disabled=true;Element.removeClassName(t.target,UID["btn_green"]);Element.addClassName(t.target,UID["btn_disabled"]);new MyAjax.dZ(n,function(t){if(t.ok){aX("<B>"+translate(n)+"</B> "+translate("used")+" "+translate("Successfully"))}else{aX(translate("Single usage of")+" "+translate(n)+" "+translate("failed and returned error")+": "+t.errmsg)}e.timer=setTimeout(e.show,100)})}function d(e){var t=e.target.getAttribute("ref");var n=document.getElementById(UID["tabInfoInv_"+t+"_nb"]).value;e.target.disabled=true;Element.removeClassName(e.target,UID["btn_green"]);Element.addClassName(e.target,UID["btn_disabled"]);new MyAjax.fe(t,n,function(e){if(e.ok){aX("<B>"+n+"x "+translate(t)+"</B> "+translate("used")+" "+translate("Successfully"));Tabs.Info.diff=e.diff}else{aX(translate("More usage of")+" "+translate(t)+" "+translate("failed and returned error")+": "+e.errmsg)}Tabs.Info.diff=e.diff;Tabs.Info.timer=setTimeout(Tabs.Info.show,100);setTimeout(Tabs.Info.highLightDiff,600)})}clearTimeout(Tabs.Info.timer);var e=Tabs.Info;clearTimeout(e.timer);document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabInfoInventory"]).className="selected";document.getElementById(UID["tabInfoInventory"]).style.zIndex=1;e.lastSubTab="tabInfoInventory";e.contentType=1;Data.options.info.current_tab=e.contentType;var t="<div class="+UID["status_ticker"]+">";t+=e.dR(CAPITAL.id);t+='<table style="margin-top:3px" width=100%>';var n=Seed.cities[CAPITAL.id],r=[],i=[],s=[];for(var o in Seed.items){if(/(featured)/.test(o))continue;s.push({type:o,desc:translate(o)})}s.sort(function(e,t){e=e.desc.toLowerCase();t=t.desc.toLowerCase();if(e>t)return 1;if(e<t)return-1;return 0});for(var u=0;u<s.length;u++){var o=s[u].type,a=[];for(item=0;item<Seed.items[o].length;item++){var f=false;for(var l=0;l<Seed.armors.length&&!f;l++)if(Seed.items[o][item].type==Seed.armors[l]||Seed.items[o][item].type+"Helmet"==Seed.armors[l]||Seed.items[o][item].type+"Armor"==Seed.armors[l]||Seed.items[o][item].type+"Guard"==Seed.armors[l]||Seed.items[o][item].type+"Guards"==Seed.armors[l]){f=true}num=bV(Seed.player.items[Seed.items[o][item].type]);if(num>0&&!f)a.push({type:Seed.items[o][item].type,desc:translate(Seed.items[o][item].type),qty:num,usable:Seed.items[o][item].usable})}if(a.length>0){a.sort(function(e,t){e=e.desc.toLowerCase();t=t.desc.toLowerCase();if(e>t)return 1;if(e<t)return-1;return 0});t+="<tr class="+UID["row_headers"]+' align=center><td style="border-bottom: 1px solid; border-bottom: 1px solid;" colspan=2>'+translate(o)+"</td></tr><tr valign=top align=center>"+'<td width=50% style="border-right: 1px solid;"><table class='+UID["row_style"]+" width=100%>";for(var c=0;c<Math.ceil(a.length/2);c++){t+="<tr><td align=left width=70%><span id="+bS("tabInfoInv_"+a[c].type+"_hl")+">"+a[c].desc+"</span></td><td align=left width=20%>"+bD(a[c].qty," ")+"</td>"+"<td align=center valign=middle width=10%>";if(a[c].usable){t+="<input id="+bS("tabInfoInv_"+a[c].type)+" ref="+a[c].type+' class="Xtrasmall '+UID["btn_green"]+'" style="width:auto !important;" type=submit value="'+translate("Use")+'" />';if(/(arsenal|chest|resource)/.test(o)){t+="<input id="+bS("tabInfoInv_"+a[c].type+"_nb")+" ref="+a[c].type+' class="short" type=textbox value=1 />';i.push(a[c].type)}else{r.push(a[c].type)}}else t+="&nbsp";t+="</td></tr>"}t+="</table></td><td width=50%><table class="+UID["row_style"]+" width=100%>";for(var c=Math.ceil(a.length/2);c<a.length;c++){t+="<tr><td align=left width=70%><span id="+bS("tabInfoInv_"+a[c].type+"_hl")+">"+a[c].desc+"</span></td><td align=left width=20%>"+bD(a[c].qty," ")+"</td>"+"<td align=center valign=middle width=10%>";if(a[c].usable){t+="<input id="+bS("tabInfoInv_"+a[c].type)+" ref="+a[c].type+' class="Xtrasmall '+UID["btn_green"]+'" style="width:auto !important;" type=submit value="'+translate("Use")+'" />';if(/(arsenal|chest|resource)/.test(o)){t+="<input id="+bS("tabInfoInv_"+a[c].type+"_nb")+" ref="+a[c].type+' class="short" type=textbox value=1 />';i.push(a[c].type)}else{r.push(a[c].type)}}else t+="&nbsp";t+="</td></tr>"}t+="</table></td></tr><tr><td> &nbsp </td></tr>"}}t+="</table></div>";document.getElementById(UID["tabInfo_Content"]).innerHTML=t;for(var c=0;c<r.length;c++)document.getElementById(UID["tabInfoInv_"+r[c]]).addEventListener("click",p,false);for(var c=0;c<i.length;c++){document.getElementById(UID["tabInfoInv_"+i[c]]).addEventListener("click",d,false);document.getElementById(UID["tabInfoInv_"+i[c]+"_nb"]).addEventListener("change",h,false)}},tabInfoQuests:function(){function T(e){var t=false;if(Seed.player.quests.claimed){for(var n=0;n<Seed.player.quests.claimed.length&&!t;n++){if(e==Seed.player.quests.claimed[n])t=true}}return t}function N(e){var t=false;if(Seed.player.quests.completed){for(var n=0;n<Seed.player.quests.completed.length&&!t;n++){if(e==Seed.player.quests.completed[n])t=true}}return t}function C(e){var t="";var n=[];for(var r in e){if(e[r]>0)n.push(bD(e[r]," ")+" "+translate(r))}if(n.length>0)t=n.join(", ");return t}function k(e){if(e.target.tagName=="DIV")bA=e.target;else{var t=e.target.parentNode;while(t.tagName!="DIV"){t=t.parentNode}bA=t}var n=bA.getAttribute("ref");var r="tabInfo_questList_"+n;var i="tabInfo_accordion_"+n;var s=document.getElementById(UID[r]);if(s.style.display=="none"){s.style.display="block";document.getElementById(UID[i]).innerHTML="-&nbsp";Data.options.collapsed.quests[n]=false}else{s.style.display="none";document.getElementById(UID[i]).innerHTML="+&nbsp";Data.options.collapsed.quests[n]=true}}function L(e){var t=e.target.getAttribute("ref").split("_");var n=Seed.quests.list[Seed.quests.category[t[0]]][t[1]].name;e.target.disabled=true;Element.removeClassName(e.target,UID["btn_green"]);Element.addClassName(e.target,UID["btn_disabled"]);var r="tabInfo_QFb_"+e.target.getAttribute("ref");var i=document.getElementById(UID[r]);new MyAjax.claimQuest(n,function(e){if(e.ok){aX("<B>"+translate("Quest")+" "+n+"</B> "+translate("claimed")+" "+translate("Successfully"));i.innerHTML="<font color=#898989>"+translate("Claimed")+"</font>"}else{aX(translate("Claiming quest")+" "+n+" "+translate("failed and returned error")+": "+e.errmsg);i.innerHTML="<font color=#AA0000><B>"+translate("Error")+"</b></font>"}})}function A(e){return e.toLowerCase().replace(/_/g,"-")}var e=Tabs.Info;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabInfoQuests"]).className="selected";document.getElementById(UID["tabInfoQuests"]).style.zIndex=1;e.lastSubTab="tabInfoQuests";e.contentType=2;Data.options.info.current_tab=e.contentType;var t=Seed.cities[CAPITAL.id];var n="<div class="+UID["status_ticker"]+' stype="width:540px; max-width:540px;">';n+=e.dR(CAPITAL.id);n+='<table style="margin-top:3px" width=100%>';for(var r=0;r<Seed.quests.category.length;r++){if(Data.options.collapsed.quests[r]==undefined)Data.options.collapsed.quests[r]=false}var i=[],s=[];for(var r=0;r<Seed.quests.category.length;r++){var o="tabInfo_questList_"+r;var u="tabInfo_categ_"+r;var a="tabInfo_accordion_"+r;var f=true;for(var l=0;l<Seed.quests.list[Seed.quests.category[r]].length;l++){var c=Seed.quests.list[Seed.quests.category[r]][l];var h="tabInfo_quest_"+r+"_"+l;var p="tabInfo_QFb_"+r+"_"+l;var d=Translation.xml["quests"][A(c.name)];var v=N(c.name);var m=T(c.name);if(!m){if(f){n+="<tr class="+UID["row_headers"]+" align=center>"+'	<td style="border-bottom: 1px solid; border-bottom: 1px solid;" width=100%>'+"		<A><div id="+bS(u)+' ref="'+r+'" >'+"		<table width=100%>"+'			<tr><td align=center width=100% style="border-right:none">'+translate(Seed.quests.category[r])+"</td>"+'				<td align=right style="border-right:none"><div id='+bS(a)+' ref="'+r+'" style="font-size:16px"></div></td>'+"		</tr></table></div></A>"+"	</td>"+"</tr>"+"<tr valign=top>"+"	<td width=100%>"+"		<div id="+bS(o)+">"+"			<table class="+UID["row_style"]+">";i.push(UID[u]);f=false}var g=c.recommended&&!v?"<span class="+UID["red"]+">"+d+"</span>":d;n+='<tr valign=top><td align=left width="160px" style="padding-bottom: 3px; border-bottom: 1px solid #898989;">'+g+"</td>"+'	<td align=left width="328px" style="padding-bottom: 3px; border-bottom: 1px solid #898989;">'+Translation.xml["quests"][A(c.name+"-objectives")]+"<br>"+"		<font color="+TIMER_COLOR+">"+C(c.reward)+"</font>";if(v){n+='<td align=center valign=middle width="50px" style="padding-bottom: 3px; border-bottom: 1px solid #898989;"><div id='+bS(p)+">"+"<input id="+bS(h)+' class="'+UID["btn_green"]+' small" ref="'+r+"_"+l+'" style="width:auto !important;" type=submit value=" '+translate("Claim")+' " />'+"</div></td>"+"</tr>";s.push(UID[h])}else n+='<td width="50px" style="padding-bottom: 3px; border-bottom: 1px solid #898989;"></td></tr>'}}if(!f)n+="</table></div></td></tr>"}n+="</table></div>";document.getElementById(UID["tabInfo_Content"]).innerHTML=n;for(var y=0;y<i.length;y++){document.getElementById(i[y]).addEventListener("click",k,false);var b=document.getElementById(i[y]).getAttribute("ref");var w="tabInfo_questList_"+b;var E="tabInfo_accordion_"+b;var S=document.getElementById(UID[w]);if(Data.options.collapsed.quests[b]){S.style.display="none";document.getElementById(UID[E]).innerHTML="+&nbsp"}else{S.style.display="block";document.getElementById(UID[E]).innerHTML="-&nbsp"}}for(var x=0;x<s.length;x++)document.getElementById(s[x]).addEventListener("click",L,false)},tabInfoTroops:function(){var e=Tabs.Info;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabInfoTroops"]).className="selected";document.getElementById(UID["tabInfoTroops"]).style.zIndex=1;e.lastSubTab="tabInfoTroops";e.contentType=4;Data.options.info.current_tab=e.contentType;var t="<div class="+UID["title"]+">"+translate("Troops")+" "+translate("Overview")+"</div>"+"<div class="+UID["status_ticker"]+' style="margin-bottom: 5px !important">'+"<ul class=tabs>"+'	<li class="tab first"><a id='+bS("tabInfoTroopsMight")+">"+translate("Might")+"</a></li>"+'	<li class="tab"><a id='+bS("tabInfoTroopsFood")+">"+translate("Consumption")+"</a></li>"+'	<li class="tab"><a id='+bS("tabInfoTroopsStats")+">"+translate("Statistics")+"</a></li>"+"</ul>"+"<div id="+bS("tabInfoTroops_Content")+' style="height:560px; ; max-height:560px; overflow-y:auto">';document.getElementById(UID["tabInfo_Content"]).innerHTML=t;document.getElementById(UID["tabInfoTroopsMight"]).addEventListener("click",e.tabInfoTroopsMight,false);document.getElementById(UID["tabInfoTroopsFood"]).addEventListener("click",e.tabInfoTroopsFood,false);document.getElementById(UID["tabInfoTroopsStats"]).addEventListener("click",e.tabInfoTroopsStats,false);switch(e.troopContentType||0){case 0:e.tabInfoTroopsMight();break;case 1:e.tabInfoTroopsFood();break;case 2:e.tabInfoTroopsStats();break}},tabInfoTroopsMight:function(){var e=Tabs.Info;document.getElementById(UID["tabInfoTroopsMight"]).className="selected";document.getElementById(UID["tabInfoTroopsMight"]).style.zIndex=1;document.getElementById(UID["tabInfoTroopsFood"]).className="";document.getElementById(UID["tabInfoTroopsFood"]).style.zIndex=0;document.getElementById(UID["tabInfoTroopsStats"]).className="";document.getElementById(UID["tabInfoTroopsStats"]).style.zIndex=0;e.troopContentType=0;Data.options.info.troop_sub_tab=e.troopContentType;var t=Seed.cities[CAPITAL.id];var n=Seed.player.alliance?Seed.player.alliance.name:"";var r="<div class="+UID["status_ticker"]+' style="margin-top:10px !important">'+"<div class="+UID["subtitle"]+"><table class="+UID["table"]+">"+"<tr><td align=left width=35%>"+Seed.player.name+" / "+t.name+"</td>"+"<td align=center width=30%>"+t.x+","+t.y+"</td>"+"<td align=center width=200px><font color=yellow>"+n+"</font></td>"+"<td width=35% align=right><font color=yellow>"+bD(Seed.player.might)+"</font></td>"+"</tr></table></div>"+"<table class="+UID["row_style"]+' style="margin-top:3px" width=80%>'+"	<tr class="+UID["row_headers"]+" align=center>"+"		<td width=50%>"+translate("Troops")+"</td>"+"		<td width=20%>"+translate("Quantity")+"</td>"+"		<td width=10%>"+translate("Might")+"</td>"+"		<td width=20%>"+translate("Total")+"</td>"+"	</tr>";var i=0;for(var s=0;s<all_unit_types.length;s++){var o=aV(CAPITAL.id,all_unit_types[s]);var u=Seed.stats.unit[all_unit_types[s]].power;var a=o.total*u;i+=a;r+="	<tr valign=top>"+"		<td class=right>"+translate(all_unit_types[s])+" :</td>"+"		<td align=right>"+bD(o.total," ")+"</td>"+"		<td align=right>"+bD(u," ")+"</td>"+"		<td align=right>"+bD(a," ")+"</td>"+"	</tr>"}r+="	<tr><td colspan=4>&nbsp</td></tr>"+"	<tr><td>&nbsp</td><td colspan=3 align=center><hr></td></tr>"+"	<tr valign=top>"+"		<td class=right>"+translate("Troops")+" :</td>"+"		<td align=right></td>"+"		<td align=right></td>"+"		<td align=right><b>"+bD(i," ")+"</b></td>"+"	</tr>"+"	<tr valign=top>"+"		<td class=right>"+translate("Building")+" + "+translate("Quests")+" :</td>"+"		<td align=right></td>"+"		<td align=right></td>"+"		<td align=right><b>"+bD(Seed.player.might-i," ")+"</b></td>"+"	</tr>"+"	<tr><td>&nbsp</td><td colspan=3 align=center><hr></td></tr>"+"	<tr valign=top>"+"		<td class=right>"+translate("Total")+" :</td>"+"		<td align=right></td>"+"		<td align=right></td>"+"		<td align=right><font color=red><b>"+bD(Seed.player.might)+"</b></font></td>"+"	</tr>"+"</table></div>";document.getElementById(UID["tabInfoTroops_Content"]).innerHTML=r},tabInfoTroopsFood:function(){function m(e){var t=Tabs.Info;Data.options.info.consumption_sel=bV(e.target.value);t.tabInfoTroopsFood()}var e=Tabs.Info;document.getElementById(UID["tabInfoTroopsMight"]).className="";document.getElementById(UID["tabInfoTroopsMight"]).style.zIndex=0;document.getElementById(UID["tabInfoTroopsFood"]).className="selected";document.getElementById(UID["tabInfoTroopsFood"]).style.zIndex=1;document.getElementById(UID["tabInfoTroopsStats"]).className="";document.getElementById(UID["tabInfoTroopsStats"]).style.zIndex=0;e.troopContentType=1;Data.options.info.troop_sub_tab=e.troopContentType;var t=Seed.cities[CAPITAL.id];var n=Seed.player.alliance?Seed.player.alliance.name:"";bS("tabInfoTroopFood_Sel");var r="<div class="+UID["status_ticker"]+' style="margin-top:10px !important">'+"<div class="+UID["subtitle"]+"><table class="+UID["table"]+">"+"<tr><td align=left width=35%>"+Seed.player.name+" / "+t.name+"</td>"+"<td align=center width=30%>"+t.x+","+t.y+"</td>"+"<td align=center width=200px><font color=yellow>"+n+"</font></td>"+"<td width=35% align=right><font color=yellow>"+bD(Seed.player.might)+"</font></td>"+"</tr></table></div>"+"<table><tr>"+"	<td><label>"+translate("Troops")+"</label></td>"+"	<td><input type=radio name="+UID["tabInfoTroopFood_Sel"]+' value="0" /></td><td align=left colspan=2><label>'+translate("Total")+"</label></td>"+'	<td width="20px"></td>'+"	<td><input type=radio name="+UID["tabInfoTroopFood_Sel"]+' value="1" /></td><td align=left width=15%><label>'+translate("In city")+"</label></td>"+"	</tr>"+"</table><br>"+"<table class="+UID["row_style"]+' style="margin-top:3px" width=80%>'+"	<tr class="+UID["row_headers"]+" align=center>"+"		<td width=50%>"+translate("Troops")+"</td>"+"		<td width=20%>"+translate("Quantity")+"</td>"+"		<td width=10%>"+translate("Upkeep")+"</td>"+"		<td width=20%>"+translate("Consumption")+"</td>"+"	</tr>";var i=0;var s=0;for(var o=0;o<all_unit_types.length;o++){var u=aV(CAPITAL.id,all_unit_types[o]);var a=Seed.stats.unit[all_unit_types[o]].upkeep.food;var f=u.total*a;var l=(u.incity+u.indefense)*a;i+=f;s+=l;r+="	<tr valign=top>"+"		<td class=right>"+translate(all_unit_types[o])+" :</td>"+"		<td align=right>"+bD(Data.options.info.consumption_sel==1?u.incity+u.indefense:u.total)+"</td>"+"		<td align=right>"+bD(a," ")+"</td>"+"		<td align=right>"+bD(Data.options.info.consumption_sel==1?l:f)+"</td>"+"	</tr>"}var a=Seed.greatDragons.GreatDragon[t.great_dragon.level].upkeep.food;r+="	<tr valign=top>"+"		<td class=right>"+translate("GreatDragon")+" :</td>"+"		<td align=right></td>"+"		<td align=right>"+bD(a," ")+"</td>"+"		<td align=right>"+bD(a," ")+"</td>"+"	</tr>";i+=a;s+=a;var c=t.figures.resource_rates["food"];var h=bV(c.rate);var p=c.production+c.production*c.multipliers.wilderness+c.production*c.multipliers.boosts+c.production*c.multipliers.research;var d=p-i;r+="	<tr><td colspan=4>&nbsp</td></tr>"+"	<tr><td>&nbsp</td><td colspan=3 align=center><hr></td></tr>"+"	<tr valign=top>"+"		<td class=right>"+translate("Troops")+" :</td>"+"		<td align=right></td>"+"		<td align=right></td>"+"		<td align=right><b>"+bD(-1*(Data.options.info.consumption_sel==1?s:i))+"</b></td>"+"	</tr>"+"	<tr valign=top>"+"		<td class=right>"+translate("Production")+" ("+translate("Per Hour")+") :</td>"+"		<td align=right></td>"+"		<td align=right></td>"+"		<td align=right><b>"+bD(p)+"</b></td>"+"	</tr>"+"	<tr><td>&nbsp</td><td colspan=3 align=center><hr></td></tr>"+"	<tr valign=top>"+"		<td class=right>"+translate("Hourly rate")+" :</td>"+"		<td align=right></td>"+"		<td align=right></td>"+"		<td align=right><font color=red><b>"+bD(Data.options.info.consumption_sel==1?h:d)+"</b></font></td>"+"	</tr>"+"</table></div>";document.getElementById(UID["tabInfoTroops_Content"]).innerHTML=r;var v=document.getElementsByName(UID["tabInfoTroopFood_Sel"]);for(o=0;o<v.length;o++){v[o].addEventListener("change",m,false);v[o].checked=v[o].value==Data.options.info.consumption_sel}},tabInfoTroopsStats:function(){var e=Tabs.Info;document.getElementById(UID["tabInfoTroopsMight"]).className="";document.getElementById(UID["tabInfoTroopsMight"]).style.zIndex=0;document.getElementById(UID["tabInfoTroopsFood"]).className="";document.getElementById(UID["tabInfoTroopsFood"]).style.zIndex=0;document.getElementById(UID["tabInfoTroopsStats"]).className="selected";document.getElementById(UID["tabInfoTroopsStats"]).style.zIndex=1;e.troopContentType=2;Data.options.info.troop_sub_tab=e.troopContentType;var t=Seed.cities[CAPITAL.id];var n=Seed.player.alliance?Seed.player.alliance.name:"";var r="<div class="+UID["status_ticker"]+' style="margin-top:10px !important">'+"<div class="+UID["subtitle"]+"><table class="+UID["table"]+">"+"<tr><td align=left width=35%>"+Seed.player.name+" / "+t.name+"</td>"+"<td align=center width=30%>"+t.x+","+t.y+"</td>"+"<td align=center width=200px><font color=yellow>"+n+"</font></td>"+"<td width=35% align=right><font color=yellow>"+bD(Seed.player.might)+"</font></td>"+"</tr></table></div>"+"<table class="+UID["row_style"]+' style="margin-top:3px; overflow:auto; white-space:nowrap" width=100%>'+"	<tr class="+UID["row_headers"]+">"+"		<td valign=middle width=29%><b>"+translate("Troops")+"</b></td>"+"		<td valign=middle width=12%><b>"+translate("Melee")+"</b></td>"+"		<td valign=middle width=11%><b>"+translate("Defense")+"</b></td>"+"		<td valign=middle width=11%><b>"+translate("Speed")+"</b></td>"+"		<td valign=middle width=11%><b>"+translate("Range")+"</b></td>"+"		<td valign=middle width=12%><b>"+translate("Ranged")+"</b></td>"+"		<td valign=middle width=14%><b>"+translate("Life")+"</b></td>"+"	</tr>";var i=0;for(var s=0;s<all_unit_types.length;s++){var o=Seed.stats.unit[all_unit_types[s]];r+="	<tr valign=top>"+"		<td class=right>"+translate(all_unit_types[s])+" :</td>"+"		<td align=right>"+bD(o.melee," ")+"</td>"+"		<td align=right>"+bD(o.defense," ")+"</td>"+"		<td align=right>"+bD(o.speed," ")+"</td>"+"		<td align=right>"+bD(o.range," ")+"</td>"+"		<td align=right>"+bD(o.ranged," ")+"</td>"+"		<td align=right>"+bD(o.life," ")+"</td>"+"	</tr>"}for(var s=0;s<all_dragon_list.length;s++){var u=true;var a=0;switch(all_dragon_list[s]){case"GreatDragon":var o=Seed.greatDragons.GreatDragon[15];a=15;break;case"WaterDragon":var o=Seed.greatDragons.WaterDragon[12];a=12;break;case"StoneDragon":var o=Seed.greatDragons.StoneDragon[12];a=12;break;case"FireDragon":var o=Seed.greatDragons.FireDragon[12];a=12;break;case"WindDragon":var o=Seed.greatDragons.WindDragon[12];a=12;break;case"IceDragon":var o=Seed.greatDragons.IceDragon[12];a=12;break;case"SwampDragon":var o=Seed.greatDragons.SwampDragon[11];a=11;break;case"ForestDragon":var o=Seed.greatDragons.ForestDragon[11];a=11;break;case"DesertDragon":var o=Seed.greatDragons.DesertDragon[10];a=10;break;case"ChronoDragon":var o=Seed.greatDragons.ChronoDragon[11];a=11;break;case"KaiserDragon":var o=Seed.greatDragons.KaiserDragon[10];a=10;break;case"CaveDragon":var o=Seed.greatDragons.KaiserDragon[10];a=10;break;case"LunaDragon":var o=Seed.greatDragons.KaiserDragon[10];a=10;break;case"SpectralDragon":var o=Seed.greatDragons.SpectralDragon[10];a=10;break;default:u=false;break}if(u){r+="	<tr valign=top>"+"		<td class=right>"+translate(all_dragon_list[s])+a+" :</td>"+"		<td align=right>"+bD(o.melee," ")+"</td>"+"		<td align=right>"+bD(o.defense," ")+"</td>"+"		<td align=right>"+bD(o.speed," ")+"</td>"+"		<td align=right>"+bD(o.range," ")+"</td>"+"		<td align=right>"+bD(o.ranged," ")+"</td>"+"		<td align=right>"+bD(o.life," ")+"</td>"+"	</tr>"}}r+="</table></div>";document.getElementById(UID["tabInfoTroops_Content"]).innerHTML=r},tabInfoHelp:function(){var e=Tabs.Info;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabInfoHelp"]).className="selected";document.getElementById(UID["tabInfoHelp"]).style.zIndex=1;e.lastSubTab="tabInfoHelp";e.contentType=3;Data.options.info.current_tab=e.contentType;var t="<div id="+bS("tabInfo_Help")+">"+"	<div class="+UID["title"]+">"+translate("About "+scriptName+"")+"</div>"+"	<div class="+UID["status_ticker"]+' style="height:575px; max-height:575px; overflow-y:auto ; overflow-x:auto ; margin-top:1px !important">'+"		<table id="+bS("tabInfo_HelpTable")+" class="+UID["table_console"]+" cellspacing=1 width=100%>"+'			<tr><td><br><div align=left style="color:#000000">'+"<center><h2><B>INFORMATIONS</B><h2></center><br>"+"<b>On Facebook :</b>"+'<br>- <a href="http://www.facebook.com/groups/DoAscripts/" target="_blank">DOA Scripts</a>'+'<br>- <a href="https://www.facebook.com/groups/conseiletevolution/" target="_blank">Dictature de Doa (french group)</a>'+"<br>"+"<br>"+"<b>My Facebook:</b>"+'<br>- <a href="https://www.facebook.com/tlc.doa.5" target="_blank">Tlc doa</a>'+"<br>"+"<br>"+"<b>Link for chrome :</b>"+'<br>- <a href="https://chrome.google.com/webstore/detail/doa-power-tools-plus-iv-u/kgkjpfofcfabmfflmlknaeiihlnmnmjc" target="_blank">'+scriptName+"</a>"+"<br>"+"<b>Link for all browsers :</b>"+'<br>- <a href="https://dl.dropboxusercontent.com/u/47778769/script.user.js" target="_blank">'+scriptName+"</a>"+"<br>"+"<br><br><center><h2><B>VERSION</B><h2></center><br>"+"You use Doa Power Tools IV by TLC v.2014.05.19<br>"+"<br>"+"What's new?<br>"+"<br>"+"Add : quests tab<br>"+"Add : you can use multiple items at once (chests, arsenal and resources)<br>"+"Add : Defensive Tower repairing job in info tab<br>"+'Add : Add an option "Send even without Dragon" (if it is healing)<br>'+"Add : display maximum of troops you can send (in attacks, multi & waves tab)<br>"+"Add : realm & server in Player infos<br>"+"Fix : change taxe rate<br>"+"FIx : display of battle reports<br>"+"Fix : Fix : time remaining for some jobs<br>"+"Fix : sentinel stop the alert when the march is arrived<br>"+"Fix : display of wall tab and options tab on mozilla is OK<br>"+"Fix : optimization of the interface (script is more fast)<br>"+"<br>"+"Fixed version<br>"+"<br>"+"Fix : display researchs<br>"+"Fix : notifications<br>"+"Fix : armors & scales are not displaying in inventory now<br>"+"Fix : fortuna auto-play<br>"+"<br><B><I></I></B><br><br><center>";t+="</div></td></tr></table></div></div>";document.getElementById(UID["tabInfo_Content"]).innerHTML=t},tabInfoStats:function(){function n(){var e=Tabs.Info;var t=be();Data.stats.total={start_at:t,total_attacks:0,loss:{},items:{},resources:{}};r()}function r(){var e=Tabs.Info;var t=document.getElementById(UID["tabInfoStats_Status"]);if(t==null)return;if(!Data.stats.total.start_at||Data.stats.total.start_at==undefined||Data.stats.total.start_at==0)Data.stats.total.start_at=Data.stats.requests.start_at;var n=be()-Data.stats.total.start_at;var r=n>0?n/3600:1;var i="<table class="+UID["table"]+">"+"	<tr>"+"		<td class=right>"+translate("Start Date")+": </td>"+"		<td colspan=>"+(new Date(Data.stats.total.start_at*1e3)).myString()+"</td>"+"	</tr><tr>"+"		<td class=right>"+translate("Run Time")+": </td>"+"		<td>"+bE(n,true)+"</td>"+"	</tr><tr>"+"		<td class=right>"+translate("Attacks")+": </td>"+"		<td>"+Data.stats.total.total_attacks+"</td>"+"	<tr valign=top align=right>"+"		<td class=right>"+translate("Troops lost")+": </td>";var s=true;for(var o in Data.stats.total.loss){var u=Math.round(Data.stats.total.loss[o]/r);if(s)s=false;else i+="	<tr align=right><td></td>";i+="		<td>"+translate(o)+":</td>"+"		<td>"+bD(Data.stats.total.loss[o]," ")+"</td>"+"		<td>("+bD(u," ")+" /"+translate("h")+")</td>"+"	</tr>"}i+="</tr><tr valign=top align=right>"+"		<td class=right>"+translate("Resources")+": </td>";var s=true;for(var o in Data.stats.total.resources){var u=Math.round(Data.stats.total.resources[o]/r);if(s)s=false;else i+="	<tr align=right><td></td>";i+="			<td>"+translate(o)+":</td>"+"			<td>"+bD(Data.stats.total.resources[o]," ")+"</td>"+"			<td>("+bD(u," ")+" /"+translate("h")+")</td>"+"		</tr>"}i+="<tr valign=top align=right>"+"		<td class=right>"+translate("Items")+": </td>";var a=[];for(var o in Data.stats.total.items)a.push({desc:translate(o),qty:Data.stats.total.items[o]});if(a.length>0){a.sort(function(e,t){e=e.desc.toLowerCase();t=t.desc.toLowerCase();if(e>t)return 1;if(e<t)return-1;return 0});for(var f=0;f<a.length;f++){var u=Math.round(a[f].qty/r);if(f>0)i+="<tr align=right><td></td>";i+="		<td>"+a[f].desc+":</td>"+"		<td>"+bD(a[f].qty," ")+"</td>"+"		<td>("+bD(u," ")+" /"+translate("h")+")</td>"+"	</tr>"}}i+="</table>";t.innerHTML=i}var e=Tabs.Info;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabInfoStats"]).className="selected";document.getElementById(UID["tabInfoStats"]).style.zIndex=1;e.lastSubTab="tabInfoStats";e.contentType=5;Data.options.info.current_tab=e.contentType;var t="<div class="+UID["title"]+">"+translate("Attacks Stats")+"</div>"+"<div id="+bS("tabInfoStats_Statbox")+" class="+UID["status_ticker"]+">"+"<div id="+bS("tabInfoStats_Status")+"></div>"+"<div id="+bS("tabInfoStats_Percent")+"></div>"+"<br/>"+"<center><input id="+bS("tabInfoStats_Clear")+' type=button value="'+translate("Clear Stats")+'" /></center>'+"<br></div>";document.getElementById(UID["tabInfo_Content"]).innerHTML=t;document.getElementById(UID["tabInfoStats_Clear"]).addEventListener("click",function(){n();r()},false);r()},dR:function(e,t){var n=Tabs.Info;var r=Seed.cities[e];var i="";var s=Seed.player.alliance?Seed.player.alliance.name:"";s=r.type=="Outpost"?"":s;if(e==CAPITAL.id)i=Seed.cities[e].defended?"<font class="+UID["defending"]+">"+translate("Defend").toUpperCase()+"</font>":"<font class="+UID["hiding"]+">"+translate("Hiding").toUpperCase()+"</font>";else i=" &nbsp ";if(r.type=="Outpost"&&e!=SPECTRAL_OUTPOST.id&&e!=SKY_OUTPOST.id&&e!=CAVE_OUTPOST.id&&e!=LUNA_OUTPOST.id){var o=0;var u=0;var a=Buildings.getList(e,"Silo");for(var f=0;f<a.length;f++){o+=Seed.stats.building[a[f].type].level[a[f].level].capacity}for(var l in r.resources){u+=r.resources[l]}var c=bV(u/o*100);if(c<75)var h="white";else if(c<90)var h="yellow";else var h="#FF7F00";i="<font color="+h+">"+translate("Silo")+" "+c+" %</font>"}return"<div class="+UID["subtitle"]+"><table class="+UID["table"]+">"+"<tr><td align=left width=35%>"+(r.type=="Outpost"?translate(r.name):r.name)+"</td>"+"<td align=center width=30%>"+r.x+","+r.y+"</td>"+"<td align=center width=200px><font color=yellow>"+s+"</font></td>"+"<TD width=35% align=right>"+i+"</td>"+"</tr></table></div>"},refresh:function(){bI("fetchPlayer from Tab.Info refresh");var e=Tabs.Info;if(e.refreshPlayerBusy)return false;e.refreshPlayerBusy=true;eo(e.container,function(){bI(translate("Player data retrieved"));Tabs.Info.refreshPlayerBusy=false});e.show()}};Tabs.Alliance={tabOrder:ALLIANCE_TAB_ORDER,tabLabel:"Alliance",tabDisabled:!ALLIANCE_TAB_ENABLE,container:null,contentType:0,totalResources:0,maxResources:0,totalForces:0,recallTimer:0,lastSubTab:"tabAllianceList",own:0,my_role:"none",autoTimer:null,marchTimer:null,autoErrors:0,report_num:-1,last_report:null,checkAlliancesBusy:false,checkAlliancesError:false,init:function(e){var t=Tabs.Alliance;t.own=Seed.player.alliance?Seed.player.alliance.id:-1;t.my_role=Seed.player.alliance_membership?Seed.player.alliance_membership.role:"none";Data.setDefaultValues("alliance");if(t.new_id==0)t.new_id=Seed.player.alliance.id;t.container=e;var n="<div class="+UID["title"]+">"+translate("Alliance features")+"</div>"+"<div id="+bS("tabAlliance_Status")+' style="margin-bottom:5px !important">'+"	<table width=100%>"+"		<tr>"+'			<td align=center width=25%><input type=button value="'+translate("Refresh list")+'" id='+bS("tabAlliance_RefreshList")+" /></td>"+'			<td align=center width=25%><input type=button value="'+translate("Message alliance")+'" id='+bS("tabAlliance_MsgAll")+" /></td>"+"			<td align=center width=25%>"+(t.my_role=="vassal"||t.my_role=="none"?"&nbsp;":'<input type=button value="'+translate("Refresh applicants")+'" id='+bS("tabAlliance_RefreshApplicants")+" />")+"</td>"+'			<td align=center width=25%><input type=button value="'+translate("actions-resign").initCap()+'" id='+bS("tabAlliance_Regin")+" /></td>"+"		</tr>"+"	</table>"+"</div>"+"<ul class=tabs>"+'	<li class="tab first"><a id='+bS("tabAllianceList")+">"+translate("members")+"</a></li>"+"	<li class=tab><a id="+bS("tabAllianceActivity")+">"+translate("Activity")+"</a></li>"+"	<li class=tab><a id="+bS("tabAllianceTrans")+">"+translate("Transport")+"</a></li>"+"	<li class=tab><a id="+bS("tabAllianceReinforcement")+">"+translate("reinforcements")+"</a></li>"+"	<li class=tab><a id="+bS("tabAllianceAuto")+">L.I.T.</a></li>"+"	<li class=tab><a id="+bS("tabAlliances")+">"+translate("Alliances")+" Top 100</a></li>"+"</ul>"+"<div id="+bS("tabAlliance_Content")+' style="padding-top:0px; height:655px; ; max-height:655px; overflow-y:auto"></div>';t.container.innerHTML=n;document.getElementById(UID["tabAlliance_RefreshList"]).addEventListener("click",t.refreshList,false);document.getElementById(UID["tabAllianceList"]).addEventListener("click",t.tabAllianceList,false);document.getElementById(UID["tabAllianceActivity"]).addEventListener("click",t.tabAllianceActivity,false);document.getElementById(UID["tabAllianceTrans"]).addEventListener("click",t.tabAllianceTrans,false);document.getElementById(UID["tabAllianceReinforcement"]).addEventListener("click",t.tabAllianceReinforcement,false);document.getElementById(UID["tabAllianceAuto"]).addEventListener("click",t.tabAllianceAuto,false);document.getElementById(UID["tabAlliance_MsgAll"]).addEventListener("click",function(){eH(translate("Alliance"),Seed.player.alliance.id||0)});document.getElementById(UID["tabAlliance_Regin"]).addEventListener("click",function(){t.onClickResign(function(){t.show()})},false);document.getElementById(UID["tabAlliances"]).addEventListener("click",t.tabAlliances,false);if(document.getElementById(UID["tabAlliance_RefreshApplicants"]))document.getElementById(UID["tabAlliance_RefreshApplicants"]).addEventListener("click",t.refreshApplicants,false);window.addEventListener("unload",t.onUnload,false);t.contentType=bV(Data.options.alliance.current_tab);t.aM(false);t.show()},show:function(){var e=Tabs.Alliance;if(Seed.player.alliance&&Seed.player.alliance.id>0){bG(document.getElementById(UID["tabAlliance_RefreshList"]),true);if(document.getElementById(UID["tabAlliance_RefreshApplicants"]))bG(document.getElementById(UID["tabAlliance_RefreshApplicants"]),true);bG(document.getElementById(UID["tabAlliance_MsgAll"]),true);if(e.my_role=="overlord")bG(document.getElementById(UID["tabAlliance_Regin"]),false,"btn_off");else bG(document.getElementById(UID["tabAlliance_Regin"]),true,"btn_off")}else{bG(document.getElementById(UID["tabAlliance_RefreshList"]),false);if(document.getElementById(UID["tabAlliance_RefreshApplicants"]))bG(document.getElementById(UID["tabAlliance_RefreshApplicants"]),false);bG(document.getElementById(UID["tabAlliance_MsgAll"]),false);bG(document.getElementById(UID["tabAlliance_Regin"]),false,"btn_off")}e.marchTick();if(!e.checkMembersBusy){switch(bV(e.contentType)){case 0:e.tabAllianceList();break;case 1:e.tabAllianceTrans();break;case 2:e.tabAllianceReinforcement();break;case 3:e.tabAlliances();break;case 4:e.tabAllianceAuto();break;case 5:e.tabAllianceActivity();break}}else setTimeout(e.show,100)},onUnload:function(){var e=Tabs.Alliance;if(e.marchTimer)clearTimeout(e.marchTimer);bI("===============  Tabs.Alliance.onUnload");Data.options.alliance.current_tab=e.contentType},hide:function(){},refreshList:function(){var e=Tabs.Alliance;if(e.checkMembersBusy)return false;e.checkMembersBusy=true;e.getAllianceMembers(function(){bI(translate("Alliance members list retrieved"));Tabs.Alliance.checkMembersBusy=false;var e=be();Data.options.alliance.last_update=(new Date(e*1e3)).myString();Tabs.Alliance.show()})},getAllianceMembers:function(e){function i(t){if(!t.done){if(t.errmsg)r.getContentDiv().innerHTML=t.errmsg;else r.getContentDiv().innerHTML=translate("Error while retrieving the list of members");r.allowClose(true);if(e)e(false);return}else{Data.dynamic.players.memberships=aA(t.member);bI("*********  List retrieved ... Total members: "+Data.dynamic.players.memberships.length);function n(e,t){e=e.player.toLowerCase();t=t.player.toLowerCase();if(e>t)return 1;if(e<t)return-1;return 0}Data.dynamic.players.memberships.sort(n);Data.options.alliance.sort_list="2";setTimeout(function(){r.destroy()},1e3);if(e)e(true)}}var t=Tabs.Alliance;ret=[];if(Data.dynamic.players.memberships&&Data.dynamic.players.memberships!=undefined&&Data.dynamic.players.memberships.length>0){for(var n=0;n<Data.dynamic.players.memberships.length;n++){if(Data.dynamic.players.memberships[n].role!="applicant")ret.push({id:Data.dynamic.players.memberships[n].id,player:Data.dynamic.players.memberships[n].player,role:Data.dynamic.players.memberships[n].role,might:Data.dynamic.players.memberships[n].might,city:Data.dynamic.players.memberships[n].city,x:Data.dynamic.players.memberships[n].x,y:Data.dynamic.players.memberships[n].y,dragon:Data.dynamic.players.memberships[n].dragon,dist:Data.dynamic.players.memberships[n].dist,joined:Data.dynamic.players.memberships[n].joined})}}Data.dynamic.players.memberships_evolution=aA(ret);Data.dynamic.players.memberships={player:"",id:0,role:"",might:0,city:"",x:0,y:0,dragon:{},req_id:0,dist:0,joined:0};var r=new aw(t.container,300,165,"",false,null);r.bd().innerHTML="<div class="+UID["title"]+"><center><b>"+scriptName+" : "+translate("Message")+"</b></center></div>";r.getContentDiv().innerHTML=translate("Search for alliance members");MemberShips.fetchMembership(Seed.player.alliance.id,i,false)},refreshApplicants:function(){var e=Tabs.Alliance;if(e.checkMembersBusy)return false;e.checkMembersBusy=true;e.getApplicants(function(){bI(translate("Alliance applicants list retrieved"));Tabs.Alliance.checkMembersBusy=false;Tabs.Alliance.tabAllianceList()})},getApplicants:function(e){function r(t){if(!t.done){if(t.errmsg)n.getContentDiv().innerHTML=t.errmsg;else n.getContentDiv().innerHTML=translate("Error while retrieving the list of applicants");n.allowClose(true);if(e)e(false);return}else{Data.dynamic.players.applicants=aA(t.member);bI("*********  List retrieved ... Total applicants: "+Data.dynamic.players.applicants.length);function r(e,t){e=e.player.toLowerCase();t=t.player.toLowerCase();if(e>t)return 1;if(e<t)return-1;return 0}Data.dynamic.players.applicants.sort(r);Data.options.alliance.sort_applicants="2";setTimeout(function(){n.destroy()},1e3);if(e)e(true)}}var t=Tabs.Alliance;Data.dynamic.players.applicants={player:"",id:0,role:"",might:0,city:"",x:0,y:0,dragon:{},req_id:0,dist:0,joined:0};var n=new aw(t.container,300,165,"",false,null);n.bd().innerHTML="<div class="+UID["title"]+"><center><b>"+scriptName+" : "+translate("Message")+"</b></center></div>";n.getContentDiv().innerHTML=translate("Search for alliance applicants");MemberShips.fetchApplicants(Seed.player.alliance.id,r,false)},tabAllianceList:function(){function g(e,t,n,r,i,s){function a(e){if(e==null||!e.ok){if(e.errmsg)u.getContentDiv().innerHTML=e.errmsg;else u.getContentDiv().innerHTML=translate("Error while "+(n?"accepting":"rejecting")+" the "+(t?"member":"applicant"));u.destroy();if(s)s(false);return}if(t)Data.dynamic.players.memberships.splice(r,1);else Data.dynamic.players.applicants.splice(r,1);setTimeout(function(){u.destroy()},1e3);if(s)s(true);return}var o=Tabs.Alliance;bG(e,false,n?"btn_green":"btn_red","btn_disabled");var u=new aw(o.container,300,165,"",false,null);u.bd().innerHTML="<div class="+UID["title"]+"><center><b>"+scriptName+" : "+translate("Message")+"</b></center></div>";u.getContentDiv().innerHTML=n?translate("Accepting applicant"):t?translate("Rejecting member"):translate("Rejecting applicant");MyAjax.membership(Seed.player.alliance.id,i,n?"put":"delete",a,false);u.destroy();if(o.checkMembersBusy)return false;o.checkMembersBusy=true;o.getAllianceMembers(function(){bI(translate("Alliance members list retrieved"));Tabs.Alliance.checkMembersBusy=false;var e=be();Data.options.alliance.last_update=(new Date(e*1e3)).myString();Tabs.Alliance.show()})}function y(e){var t=Tabs.Alliance,n=e.target;var r=n.getAttribute("ref").split("_");g(n,false,true,r[0],r[1],t.show)}function b(e){var t=Tabs.Alliance,n=e.target;var r=n.getAttribute("ref").split("_");g(n,false,false,r[0],r[1],t.show)}function w(e){dO(translate("Do you want to reject this member")+" ?",function(){var t=Tabs.Alliance,n=e.target;var r=n.getAttribute("ref").split("_");g(n,true,false,r[0],r[1],t.show)},function(){},true)}function E(e){var t=Tabs.Alliance;var n=e.target.parentNode.parentNode.id;if(n==UID["tabAlliance_tal_0"]){if(Data.options.alliance.sort_list=="0"){Data.dynamic.players.memberships.sort(function(e,t){return t.dist-e.dist});Data.options.alliance.sort_list="-0"}else{Data.dynamic.players.memberships.sort(function(e,t){return e.dist-t.dist});Data.options.alliance.sort_list="0"}}else if(n==UID["tabAlliance_tal_1"]){if(Data.options.alliance.sort_list=="1"){Data.dynamic.players.memberships.sort(function(e,t){return t.x-e.x});Data.options.alliance.sort_list="-1"}else{Data.dynamic.players.memberships.sort(function(e,t){return e.x-t.x});Data.options.alliance.sort_list="1"}}else if(n==UID["tabAlliance_tal_2"]){if(Data.options.alliance.sort_list=="2"){Data.dynamic.players.memberships.sort(function(e,t){e=e.player.toLowerCase();t=t.player.toLowerCase();if(e>t)return-1;if(e<t)return 1;return 0});Data.options.alliance.sort_list="-2"}else{Data.dynamic.players.memberships.sort(function(e,t){e=e.player.toLowerCase();t=t.player.toLowerCase();if(e>t)return 1;if(e<t)return-1;return 0});Data.options.alliance.sort_list="2"}}else if(n==UID["tabAlliance_tal_3"]){if(Data.options.alliance.sort_list=="3"){Data.dynamic.players.memberships.sort(function(e,t){e=e.role.toLowerCase();t=t.role.toLowerCase();if(e>t)return-1;if(e<t)return 1;return 0});Data.options.alliance.sort_list="-3"}else{Data.dynamic.players.memberships.sort(function(e,t){e=e.role.toLowerCase();t=t.role.toLowerCase();if(e>t)return 1;if(e<t)return-1;return 0});Data.options.alliance.sort_list="3"}}else if(n==UID["tabAlliance_tal_4"]){if(Data.options.alliance.sort_list=="4"){Data.dynamic.players.memberships.sort(function(e,t){return t.might-e.might});Data.options.alliance.sort_list="-4"}else{Data.dynamic.players.memberships.sort(function(e,t){return e.might-t.might});Data.options.alliance.sort_list="4"}}else if(n==UID["tabAlliance_tal_5"]){if(Data.options.alliance.sort_list=="5"){Data.dynamic.players.memberships.sort(function(e,t){return t.joined-e.joined});Data.options.alliance.sort_list="-5"}else{Data.dynamic.players.memberships.sort(function(e,t){return e.joined-t.joined});Data.options.alliance.sort_list="5"}}t.tabAllianceList()}function S(e){var t=Tabs.Alliance;var n=e.target.parentNode.parentNode.id;if(n==UID["tabAlliance_taa_0"]){if(Data.options.alliance.sort_applicants=="0"){Data.dynamic.players.applicants.sort(function(e,t){return t.dist-e.dist});Data.options.alliance.sort_applicants="-0"}else{Data.dynamic.players.applicants.sort(function(e,t){return e.dist-t.dist});Data.options.alliance.sort_applicants="0"}}else if(n==UID["tabAlliance_taa_1"]){if(Data.options.alliance.sort_applicants=="1"){Data.dynamic.players.applicants.sort(function(e,t){return t.x-e.x});Data.options.alliance.sort_applicants="-1"}else{Data.dynamic.players.applicants.sort(function(e,t){return e.x-t.x});Data.options.alliance.sort_applicants="1"}}else if(n==UID["tabAlliance_taa_2"]){if(Data.options.alliance.sort_applicants=="2"){Data.dynamic.players.applicants.sort(function(e,t){e=e.player.toLowerCase();t=t.player.toLowerCase();if(e>t)return-1;if(e<t)return 1;return 0});Data.options.alliance.sort_applicants="-2"}else{Data.dynamic.players.applicants.sort(function(e,t){e=e.player.toLowerCase();t=t.player.toLowerCase();if(e>t)return 1;if(e<t)return-1;return 0});Data.options.alliance.sort_applicants="2"}}else if(n==UID["tabAlliance_taa_3"]){if(Data.options.alliance.sort_applicants=="3"){Data.dynamic.players.applicants.sort(function(e,t){return t.might-e.might});Data.options.alliance.sort_applicants="-3"}else{Data.dynamic.players.applicants.sort(function(e,t){return e.might-t.might});Data.options.alliance.sort_applicants="3"}}t.tabAllianceList()}var e=Tabs.Alliance;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabAllianceList"]).className="selected";document.getElementById(UID["tabAllianceList"]).style.zIndex=1;e.lastSubTab="tabAllianceList";e.contentType=0;if(as(Data.options.alliance.sort_list))Data.options.alliance.sort_list="0";if(!as(Data.options.alliance.last_update))kLastupdate=" ("+Data.options.alliance.last_update+")";else kLastupdate="";var t="<div id="+bS("tabAlliance_Results")+' style="height:640px">'+"	<div class="+UID["title"]+">"+translate("Members list ")+kLastupdate+"</div>"+"	<div id="+bS("tabAlliance_ResultList")+" class="+UID["status_ticker"]+' style="height:620px; max-height:620px; overflow:auto; white-space:nowrap; margin-top:1px !important"></div>'+"	<div id="+bS("tabAlliance_RequestHeader")+" class="+UID["title"]+">"+translate("Applicants")+"</div>"+"	<div id="+bS("tabAlliance_RequestList")+" class="+UID["status_ticker"]+' style="display:none; height:100px; max-height:100px; overflow:auto; white-space:nowrap; margin-top:1px !important"></div>'+"	</div>";document.getElementById(UID["tabAlliance_Content"]).innerHTML=t;if(e.my_role=="vassal"||e.my_role=="none"||Data.dynamic.players.applicants.length==0){document.getElementById(UID["tabAlliance_ResultList"]).style.height="620px";document.getElementById(UID["tabAlliance_RequestHeader"]).style.display="none";document.getElementById(UID["tabAlliance_RequestList"]).style.display="none"}else{document.getElementById(UID["tabAlliance_ResultList"]).style.height="490px";document.getElementById(UID["tabAlliance_RequestHeader"]).style.display="block";document.getElementById(UID["tabAlliance_RequestList"]).style.display="block"}var t="<table class="+UID["row_style"]+">"+"	<tr class="+UID["row_headers"]+">"+"		<td id="+bS("tabAlliance_tal_0")+' width="40px"><A><span>'+translate("Dist")+"</span></A></td>"+"		<td id="+bS("tabAlliance_tal_1")+' width="55px"><A><span>'+translate("Coords")+"</span></A></td>"+"		<td id="+bS("tabAlliance_tal_2")+' width="150px" style="overflow-x:auto"><A><span>'+translate("Player name")+"</span></A></td>"+"		<td id="+bS("tabAlliance_tal_3")+' width="65px" style="overflow-x:auto"><A><span>'+translate("Role")+"</span></A></td>"+"		<td id="+bS("tabAlliance_tal_4")+' width="65px" align=right><A><span>'+translate("Might")+"</span></A></td>"+'		<td width="60px" align=right>'+translate("Evol")+"</td>"+"		<td id="+bS("tabAlliance_tal_5")+' width="65px" align=right><A><span>'+translate("Joined")+"</span></A></td>"+"	</tr>";var n=[],r=[],i=bS("tabAlliance_SendMsg"),s=bS("tabAlliance_reject");for(var o=0;o<Data.dynamic.players.memberships.length;o++){t+="<tr><td>"+Data.dynamic.players.memberships[o].dist+"</td>"+"	<td align=center>"+Data.dynamic.players.memberships[o].x+","+Data.dynamic.players.memberships[o].y+"</td>";var u=bD(Data.dynamic.players.memberships[o].might," ");var a=false;var f="x";for(var l=0;l<Data.dynamic.players.memberships_evolution.length&&!a;l++){if(Data.dynamic.players.memberships_evolution[l].id==Data.dynamic.players.memberships[o].id){f=Data.dynamic.players.memberships[o].might-Data.dynamic.players.memberships_evolution[l].might;if(f<0)f="<span class="+UID["red"]+">"+bD(f," ")+"</span>";else if(f>0)f="<span class="+UID["green"]+">+"+bD(f," ")+"</span>";else f=bD(f," ");a=true}}if(Data.dynamic.players.memberships[o].role=="vassal")var c="";else var c=translate("role-"+Data.dynamic.players.memberships[o].role);var h=Data.dynamic.players.memberships[o].id+"_"+Data.dynamic.players.memberships[o].player;t+="<td align=left>"+Data.dynamic.players.memberships[o].player+"</td>"+"	<td align=left>"+c+"</td>"+"	<td align=right>"+u+"</td>"+"	<td align=right>"+f+"</td>"+"	<td align=right>"+(new Date(Data.dynamic.players.memberships[o].joined)).formatDate()+"</td>"+"	<td align=right>&nbsp;<input class=Xtrasmall id="+i+"_"+Data.dynamic.players.memberships[o].id+' ref="'+h+'" type=button  style="width:auto !important;" value="'+translate("Msg")+'" ></td>'+(e.my_role=="vassal"||e.my_role=="none"?"":'<td align=right>&nbsp;<input class="Xtrasmall '+UID["btn_red"]+'" id='+s+"_"+o+' ref="'+o+"_"+Data.dynamic.players.memberships[o].req_id+'" type=button  style="width:auto !important;" value=" X " ></td>')+"</tr>";n.push(i+"_"+Data.dynamic.players.memberships[o].id);if(e.my_role!="vassal"&&e.my_role!="none")r.push(s+"_"+o)}for(var l=0;l<Data.dynamic.players.memberships_evolution.length;l++){var a=false;for(var o=0;o<Data.dynamic.players.memberships.length&&!a;o++){if(Data.dynamic.players.memberships_evolution[l].id==Data.dynamic.players.memberships[o].id)a=true}if(!a&&Data.dynamic.players.memberships_evolution[l].player){t+="<tr><td><span class="+UID["red"]+">"+Data.dynamic.players.memberships_evolution[l].dist+"</span></td>"+"	<td align=center><span class="+UID["red"]+">"+Data.dynamic.players.memberships_evolution[l].x+","+Data.dynamic.players.memberships_evolution[l].y+"</span></td>";var u=bD(Data.dynamic.players.memberships_evolution[l].might," ");if(Data.dynamic.players.memberships_evolution[l].role=="vassal")var c="";else var c=translate("role-"+Data.dynamic.players.memberships_evolution[l].role);var h=Data.dynamic.players.memberships_evolution[l].id+"_"+Data.dynamic.players.memberships_evolution[l].player;t+="<td align=left><span class="+UID["red"]+">"+Data.dynamic.players.memberships_evolution[l].player+"</span></td>"+"	<td align=left><span class="+UID["red"]+">"+c+"</span></td>"+"	<td align=right><span class="+UID["red"]+">"+u+"</span></td>"+"	<td align=right><span class="+UID["red"]+">-</span></td>"+"	<td align=right><span class="+UID["red"]+">"+(new Date(Data.dynamic.players.memberships_evolution[l].joined)).formatDate()+"</span></td>"+"	<td align=right><input class=small id="+i+"_"+Data.dynamic.players.memberships_evolution[l].id+' ref="'+h+'" type=button  style="width:auto !important;" value="'+translate("Msg")+'" ></td>'+"</tr>";n.push(i+"_"+Data.dynamic.players.memberships_evolution[l].id)}}document.getElementById(UID["tabAlliance_ResultList"]).innerHTML=t+"</table>";for(var p=0;p<6;p++)document.getElementById(UID["tabAlliance_tal_"+p]).addEventListener("click",E,false);for(var d=0;d<n.length;d++)document.getElementById(n[d]).addEventListener("click",bF,false);for(var d=0;d<r.length;d++)document.getElementById(r[d]).addEventListener("click",w,false);if(e.my_role!="vassal"&&e.my_role!="none"||as(Data.dynamic.players.applicants)||Data.dynamic.players.applicants.length>0){var t="<table class="+UID["row_style"]+">"+"	<tr class="+UID["row_headers"]+">"+"		<td id="+bS("tabAlliance_taa_0")+' width="40px"><A><span>'+translate("Dist")+"</span></A></td>"+"		<td id="+bS("tabAlliance_taa_1")+' width="55px"><A><span>'+translate("Coords")+"</span></A></td>"+"		<td id="+bS("tabAlliance_taa_2")+' width="150px" style="overflow-x:auto"><A><span>'+translate("Player name")+"</span></A></td>"+"		<td id="+bS("tabAlliance_taa_3")+' width="65px" align=right><A><span>'+translate("Might")+"</span></A></td>"+"	</tr>";var n=[],v=[],r=[],i=bS("tabAlliance_A_SendMsg"),m=bS("tabAlliance_A_accept"),s=bS("tabAlliance_A_reject");for(var o=0;o<Data.dynamic.players.applicants.length;o++){t+="<tr><td>"+Data.dynamic.players.applicants[o].dist+"</td>"+"	<td align=center>"+Data.dynamic.players.applicants[o].x+","+Data.dynamic.players.applicants[o].y+"</td>";var u=bD(Data.dynamic.players.applicants[o].might," ");var h=Data.dynamic.players.applicants[o].id+"_"+Data.dynamic.players.applicants[o].player;t+="<td align=left>"+Data.dynamic.players.applicants[o].player+"</td>"+"	<td align=right>"+u+"</td>"+"	<td align=right>&nbsp;<input class=Xtrasmall id="+i+"_"+Data.dynamic.players.applicants[o].id+' ref="'+h+'" type=button  style="width:auto !important;" value="'+translate("Msg")+'" >&nbsp;</td>'+'	<td align=right>&nbsp;<input class="Xtrasmall '+UID["btn_green"]+'" id='+m+"_"+o+' ref="'+o+"_"+Data.dynamic.players.applicants[o].req_id+'" type=button  style="width:auto !important;" value="'+translate("Accept")+'" >&nbsp;</td>'+'	<td align=right>&nbsp;<input class="Xtrasmall '+UID["btn_red"]+'" id='+s+"_"+o+' ref="'+o+"_"+Data.dynamic.players.applicants[o].req_id+'" type=button  style="width:auto !important;" value="'+translate("Dismiss")+'" >&nbsp;</td>'+"</tr>";n.push(i+"_"+Data.dynamic.players.applicants[o].id);v.push(m+"_"+o);r.push(s+"_"+o)}document.getElementById(UID["tabAlliance_RequestList"]).innerHTML=t+"</table>";for(var p=0;p<4;p++)document.getElementById(UID["tabAlliance_taa_"+p]).addEventListener("click",S,false);for(var d=0;d<n.length;d++){document.getElementById(n[d]).addEventListener("click",bF,false);document.getElementById(v[d]).addEventListener("click",y,false);document.getElementById(r[d]).addEventListener("click",b,false)}}},tabAllianceTrans:function(){function l(e,t,n,r){var i=Tabs.Alliance;var s=[];s.push(e.insertRow(t));s.push(e.insertRow(t+1));s.push(e.insertRow(t+2));var o,u=0;for(var a=0;a<transport_unit_types.length;++a){s[0].insertCell(u).innerHTML=translate(transport_unit_types[a]);var f=document.createElement("input");f.type="text";f.size="2";f.style.width="65px";f.title=translate(transport_unit_types[a]);f.style.border="1px solid grey";f.maxlength="6";if(n=="TR"){if(Data.options.alliance.data.transports[Names.troops.byAbbr[transport_unit_types[a]][1]]==undefined)Data.options.alliance.data.transports[Names.troops.byAbbr[transport_unit_types[a]][1]]=0;o=bV(Data.options.alliance.data.transports[Names.troops.byAbbr[transport_unit_types[a]][1]])}if(!o)o=0;f.value=o;f.name=n+"_"+a;f.id=n+"_"+a;f.addEventListener("change",r,false);s[1].insertCell(u).appendChild(f);var l=s[2].insertCell(u);var c=bD(bV(Seed.cities[CAPITAL.id].units[Names.troops.byAbbr[transport_unit_types[a]][1]])," ");l.className="jewel";l.innerHTML="(&nbsp;"+c+"&nbsp;)";u=u+1}return e}function c(e){var t=Tabs.Alliance;var n=e.target.name.split("_");var r=bV(e.target.value);if(n[0]=="TR"){var i=0;var s=true;for(var o=0;o<transport_unit_types.length;++o){var u=bV($("TR_"+o).value);if(isNaN(r)||r<0){s=false;$("TR_"+o).style.backgroundColor="red"}else{i+=u;$("TR_"+o).style.backgroundColor=""}}if(i>bJ(CAPITAL.id).max_troops){for(var o=0;o<transport_unit_types.length;++o){$("TR_"+o).style.backgroundColor="red"}}else{Data.options.alliance.data.transports[Names.troops.byAbbr[transport_unit_types[n[1]]][1]]=r;var a=Data.options.alliance.data.transports;var f=Names.troops.byAbbr[transport_unit_types[n[1]]][1];a[f]=e.target.value}}t.playerCityDesc();t.ce()}function h(){var e=Tabs.Alliance;for(var t=0;t<transport_unit_types.length;t++)Data.options.alliance.data.transports[Names.troops.byAbbr[transport_unit_types[t]][1]]=0;for(var n=0;n<transportable_resource_types.length;n++){Data.options.alliance.data.resources[transportable_resource_types[n]]=0}e.tabAllianceTrans()}function p(t){var n=t.target.id.split("_");var r=bV(t.target.value);e.totalResources=0;var i=0;for(var s=0;s<transportable_resource_types.length;s++){if(transportable_resource_types[s]!="lunar_energy"&&transportable_resource_types[s]!="blue_energy"){if(s!=n[1])e.totalResources=bV(e.totalResources)+bV(Data.options.alliance.data.resources[transportable_resource_types[s]]);if(s==n[1])i=Math.round(bV(Seed.cities[CAPITAL.id].resources[transportable_resource_types[s]]));document.getElementById(UID["tabAlliance_Res"]+"_"+s).style.backgroundColor=""}}if(isNaN(r)||r<0||r+bV(e.totalResources)>bV(e.maxResources))t.target.style.backgroundColor="red";else t.target.style.backgroundColor="";t.target.value=bV(r);Data.options.alliance.data.resources[transportable_resource_types[n[1]]]=bV(r);document.getElementById(UID["tabAlliance_Rem"]+"_"+n[1]).innerHTML="( "+bD(i-bV(r)," ")+" )";e.ce()}function d(t){var n=t.target.id.split("_");var r=0;var i=bV(Seed.cities[CAPITAL.id].resources[transportable_resource_types[n[1]]]);e.totalResources=0;for(var s=0;s<transportable_resource_types.length;s++)if(s!=n[1])e.totalResources=bV(e.totalResources)+bV(Data.options.alliance.data.resources[transportable_resource_types[s]]);r=bV(e.maxResources)-bV(e.totalResources);if(r>i)r=i;Data.options.alliance.data.resources[transportable_resource_types[n[1]]]=bV(r);e.tabAllianceTrans()}function v(e){var t=Tabs.Alliance;var n=0,r=0,i=[];for(var s=0;s<transport_unit_types.length;s++){if(Names.troops.byAbbr[transport_unit_types[s]][1]=="Porter")var o=200;else if(Names.troops.byAbbr[transport_unit_types[s]][1]=="ArmoredTransport")var o=5e3;else if(Names.troops.byAbbr[transport_unit_types[s]][1]=="PackDragon")var o=6e3;else var o=0;var u=bV(Seed.cities[CAPITAL.id].units[Names.troops.byAbbr[transport_unit_types[s]][1]]);try{var o=Seed.stats.unit[Names.troops.byAbbr[transport_unit_types[s]][1]].load;var a=Seed.stats.unit[Names.troops.byAbbr[transport_unit_types[s]][1]].speed}catch(f){}i.push({type:transport_unit_types[s],load:o,speed:a,max_qty:u,max_load:bV(u)*bV(o)});n+=bV(u)*bV(o)}for(var l=0;l<transportable_resource_types.length;l++)r+=bV(Data.options.alliance.data.resources[transportable_resource_types[l]]);if(e==1)i.sort(function(e,t){e=e.type.toLowerCase();t=t.type.toLowerCase();if(e>t)return 1;if(e<t)return-1;return 0});else i.sort(function(e,t){return t.speed-e.speed});if(n>=0&&n>=r){for(var s=0;s<i.length;s++){var c=0;if(r>=0){if(i[s].max_load>r){c=Math.ceil(r/i[s].load);r-=c*i[s].load}else{c=i[s].max_qty;r-=i[s].max_load}}Data.options.alliance.data.transports[Names.troops.byAbbr[i[s].type][1]]=c}}t.tabAllianceTrans()}function m(){function n(n){if(n!="OK"){t.getContentDiv().innerHTML="<B>"+n+"</b>";t.allowClose(true)}else{t.getContentDiv().innerHTML="<B> OK </b>";setTimeout(function(){t.destroy()},1e3);e.show()}}var t=new aw(e.container,300,150,"",false);t.bd().innerHTML="<div class="+UID["title"]+"><center><b>"+scriptName+" : "+translate("Message")+"</b></center></div>";t.getContentDiv().innerHTML=translate("Sending transport");g(n)}function g(e){var t=Tabs.Alliance;var n=Seed.cities[CAPITAL.id].id;var r=CAPITAL.id;var i=t.getTarget(Data.options.alliance.transport_id);if(as(i)){e(translate("No Recipient Defined"));return}var s=Data.options.alliance.data.resources;var o=0;for(var u in s)if(s[u]>0)o+=s[u];if(o<=0){e(translate("No resources to transport defined"));return}var a=Data.options.alliance.data.transports;var f=bb(CAPITAL.id,a);if(f!=null){e(aW(f,"fb"));return}var l="<B>"+translate("Transport sent to")+"</B> : "+i.msg;aZ(l+" "+translate("attempted"));new MyAjax.TransportMarch(n,i.x,i.y,a,s,"transport",function(t){if(t.ok){aZ(l+" "+translate("Successfully"));aX(l);if(Data.options.alliance.recall){var r={cityId:n,marchId:t.dat.result.job.march_id,run_at:t.dat.result.job.run_at};Data.dynamic.recall_marches.push(r)}if(e)e("OK")}else{aZ(l+" "+translate("failed and returned error")+": "+t.errmsg);if(e)e(translate("Error")+": "+t.errmsg)}return})}var e=Tabs.Alliance;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabAllianceTrans"]).className="selected";document.getElementById(UID["tabAllianceTrans"]).style.zIndex=1;e.lastSubTab="tabAllianceTrans";e.contentType=1;var t="<div id="+bS("tabAlliance_Results")+' style="height:590px">'+"	<div class="+UID["title"]+">"+translate("Send resources")+"</div>"+"	<div id="+bS("tabAlliance_Status")+" class="+UID["status_ticker"]+' style="margin-bottom:5px !important">'+"	<table class="+UID["table"]+" width=100%>"+"		<tr class="+UID["row_headers_left"]+" align=left>"+"			<td align=left colspan=2>"+translate("Recipient")+" : </td>"+"		</tr><tr>"+"			<td><div id="+bS("tabAlliance_TransPlayerList")+"></div></td>"+"			<td><div id="+bS("tabAlliance_TransTarget")+' style="height: 17px; padding: 2px 0px;"></div></td>'+"		</tr>"+"	</table><br>"+"	<br>"+"	<table id="+bS("tabAlliance_TabYoyo")+" class="+UID["table"]+">"+"		<tr align=left class="+UID["row_headers_left"]+">"+"			<td colspan=2>"+translate("Yoyo functionality")+":&nbsp;</td>"+"		</tr>"+"		<tr align=left>"+"			<td>"+translate("Automatically recall transport 1 minute before delivery")+":&nbsp;</td>"+"			<td><input id="+bS("tabAlliance_Yoyo")+" type=checkbox "+(Data.options.alliance.recall?"CHECKED":"")+" /></td>"+"		</tr>"+"	</table><br>"+"	<table id="+bS("tabAlliance_TTroops")+" class="+UID["table"]+">"+"		<tr align=left class="+UID["row_headers_left"]+">"+"			<td colspan=4>"+translate("Troops for transport")+":&nbsp;("+translate("Max")+". "+translate("Troops")+" "+bD(bV(bJ(CAPITAL.id).max_troops)," ")+")&nbsp;</td>"+"		</tr>"+"	</table><br>"+"	<table id="+bS("tabAlliance_Resources")+" class="+UID["table"]+" width=100%>"+"		<tr align=left class="+UID["row_headers_left"]+">"+"			<td colspan=5>"+translate("Resources to transport")+":&nbsp;</td>"+"		</tr>";var n=bS("tabAlliance_Res");var r=bS("tabAlliance_Max");var s=bS("tabAlliance_Rem");for(var o=0;o<transportable_resource_types.length;o++){var u=bV(Data.options.alliance.data.resources[transportable_resource_types[o]]);var a=Math.round(bV(Seed.cities[CAPITAL.id].resources[transportable_resource_types[o]]));var f="( "+bD(a-u," ")+" )";a=bD(a);desc=transportable_resource_types[o];if(transportable_resource_types[o]=="blue_energy")desc="blueenergy250k";if(desc!="lunar_energy"&&desc!="blueenergy250k"){t+="<tr><td class=right width=70px>"+translate(desc)+" :</td>"+"	<td width=90px>"+"		<input type=text id="+n+"_"+o+' maxlength=10 style="width:70px" size=2 value="'+u+'"></td>'+"	<td width=30px>"+"		<input class=small id="+r+"_"+o+" ref="+o+' type=button style="width:auto !important;" value=" Max " ></td>'+"	<td align=right width=90px>"+a+"</td>"+"	<td align=right width=90px><span id="+s+"_"+o+" ref="+i+">"+f+"</span></td>"+"<td></td></tr>"}}t+="<tr><td align=right class=right>"+translate("Load capacity")+"&nbsp:</td>"+"		<td colspan=4 align=left><div id="+bS("tabAlliance_Total")+"></div></td>"+"	</tr>"+"</table><br>"+"<table class="+UID["table"]+' style="margin-top:3px" width=60%>'+'	<tr valign=top><td style="font-size:2px">&nbsp</td>'+"	</tr><tr valign=top align=center>"+"		<td width=25%><label><input id="+bS("tabAlliance_AdaptTrsp")+' type=button class="'+UID["btn_green"]+'" value="'+translate("Adapt Transport")+'" /></label></td>'+"		<td width=25%><label><input id="+bS("tabAlliance_AdaptTSpeed")+' type=button class="'+UID["btn_green"]+'" value="'+translate("Adapt Transp. by speed")+'" /></label></td>'+'	</tr><tr valign=top><td style="font-size:2px">&nbsp</td>'+"	</tr><tr valign=top align=center>"+"		<td width=25%><label><input id="+bS("tabAlliance_clearAll")+' type=button class="'+UID["btn_green"]+'" value="'+translate("Clear all")+'" /></label></td>'+"		<td width=25%><label><input id="+bS("tabAlliance_Launch")+' type=button value="'+translate("Send transport")+'" /></label></td>'+"	</tr>"+"</table>"+"<br></div>"+"<div id="+bS("tabAlliance_TFeedbackBox")+" class="+UID["status_ticker"]+' style="margin-top:5px; margin-bottom:5px !important">'+"	<div id="+bS("tabAlliance_TReport")+' style="margin-top:5px;height:165px; max-height:165px; width:540px; max-width:540px; overflow:auto;">'+"		<table id="+bS("tabAlliance_TMarches")+" class="+UID["table"]+">"+"		</table>"+"	</div>"+"</div></div>";document.getElementById(UID["tabAlliance_Content"]).innerHTML=t;document.getElementById(UID["tabAlliance_Yoyo"]).addEventListener("click",function(e){Data.options.alliance.recall=e.target.checked},false);document.getElementById(UID["tabAlliance_clearAll"]).addEventListener("click",h,false);document.getElementById(UID["tabAlliance_AdaptTrsp"]).addEventListener("click",function(){v(1)},false);document.getElementById(UID["tabAlliance_AdaptTSpeed"]).addEventListener("click",function(){v(2)},false);document.getElementById(UID["tabAlliance_Launch"]).addEventListener("click",m,false);l(document.getElementById(UID["tabAlliance_TTroops"]),1,"TR",c);for(i=0;i<transportable_resource_types.length;i++){if(transportable_resource_types[i]!="lunar_energy"&&transportable_resource_types[i]!="blue_energy"){document.getElementById(n+"_"+i).addEventListener("change",p,false);butMax=document.getElementById(r+"_"+i);butMax.addEventListener("click",d,false);bG(butMax,true,"btn_green")}}e.getMemberList();e.ce();clearTimeout(e.marchTimer);e.marchTick()},tabAllianceAuto:function(){function a(e){var t=bV(e.target.value);var n=bV(t*1.5);if(t<bK(MIN_DELAY_BETWEEN_WAVE,20)||t>3600){e.target.style.backgroundColor="red";return}document.getElementById(UID["tabAlliance_AutoDelayMax"]).innerHTML=n;e.target.style.backgroundColor="";Data.options.alliance.auto.delay_min=t;Data.options.alliance.auto.delay_max=n}function f(){var e=Tabs.Alliance;e.totalResources=0;e.maxResources=0;for(var t=0;t<transportable_resource_types.length;t++)e.totalResources=bV(e.totalResources)+bV(Data.options.alliance.auto.resources[transportable_resource_types[t]]);for(var n=0;n<transport_unit_types.length;n++){if(Names.troops.byAbbr[transport_unit_types[n]][1]=="Porter")var r=200;else if(Names.troops.byAbbr[transport_unit_types[n]][1]=="ArmoredTransport")var r=5e3;else if(Names.troops.byAbbr[transport_unit_types[n]][1]=="PackDragon")var r=6e3;else var r=0;var i=Data.options.alliance.auto.transports[Names.troops.byAbbr[transport_unit_types[n]][1]];try{var r=Seed.stats.unit[Names.troops.byAbbr[transport_unit_types[n]][1]].load}catch(s){aX("<B>"+translate("Troops load: ")+"</B>"+s.msg+" "+translate("Manifest not available, using defaults"))}e.maxResources=e.maxResources+bV(i)*bV(r)}var o=bD(bV(e.maxResources)-bV(e.totalResources)," ");document.getElementById(UID["tabAlliance_ATotal"]).innerHTML="<B>"+bD(bV(e.totalResources)," ")+"</B> / <B>"+bD(bV(e.maxResources)," ")+"</B> (<B>"+o+"</B> disponible)"}function l(e){var t=Tabs.Alliance;var n=e.target.name.split("_");var r=bV(e.target.value);if(n[0]=="TR"){if(isNaN(r)||r<0||r>bJ(CAPITAL.id).max_troops){e.target.style.backgroundColor="red"}else{Data.options.alliance.auto.transports[Names.troops.byAbbr[transport_unit_types[n[1]]][1]]=r;var i=Data.options.alliance.auto.transports;var s=Names.troops.byAbbr[transport_unit_types[n[1]]][1];i[s]=e.target.value;e.target.style.backgroundColor=""}}f()}function c(e){var t=bV(document.getElementById(UID["tabAlliance_AutoMaxMarches"]).value);if(t<0||t>Seed.cities[CAPITAL.id].figures.marches.maximum){e.target.style.backgroundColor="red";return}e.target.style.backgroundColor="";Data.options.alliance.auto.max_marches=t}function h(e){var t=Tabs.Alliance;var n=e.target.id.split("_");var r=bV(e.target.value);t.totalResources=0;for(var s=0;s<transportable_resource_types.length;s++)if(s!=n[1])t.totalResources=bV(t.totalResources)+bV(Data.options.alliance.auto.resources[transportable_resource_types[s]]);for(i=0;i<transportable_resource_types.length;i++)document.getElementById(UID["tabAlliance_ARes"]+"_"+i).style.backgroundColor="";if(isNaN(r)||r<0||r+bV(t.totalResources)>bV(t.maxResources))e.target.style.backgroundColor="red";else e.target.style.backgroundColor="";e.target.value=bV(r);Data.options.alliance.auto.resources[transportable_resource_types[n[1]]]=bV(r);f()}function p(t){var n=t.target.id.split("_");var r=0;var i=bV(Seed.cities[CAPITAL.id].resources[transportable_resource_types[n[1]]]);e.totalResources=0;for(var s=0;s<transportable_resource_types.length;s++)if(s!=n[1])e.totalResources=bV(e.totalResources)+bV(Data.options.alliance.auto.resources[transportable_resource_types[s]]);r=bV(e.maxResources)-bV(e.totalResources);if(r>i)r=i;Data.options.alliance.auto.resources[transportable_resource_types[n[1]]]=bV(r);e.tabAllianceAuto()}function d(e,t,n,r){var i=Tabs.Alliance;var s=[];s.push(e.insertRow(t));s.push(e.insertRow(t+1));s.push(e.insertRow(t+2));var o,u=0;var a=bS("tabAlliance_ATStk");for(var f=0;f<transport_unit_types.length;++f){s[0].insertCell(u).innerHTML=translate(transport_unit_types[f]);var l=document.createElement("input");l.type="text";l.size="2";l.style.width="65px";l.title=translate(transport_unit_types[f]);l.style.border="1px solid grey";l.maxlength="6";if(n=="TR"){if(Data.options.alliance.auto.transports[Names.troops.byAbbr[transport_unit_types[f]][1]]==undefined)Data.options.alliance.auto.transports[Names.troops.byAbbr[transport_unit_types[f]][1]]=0;o=bV(Data.options.alliance.auto.transports[Names.troops.byAbbr[transport_unit_types[f]][1]])}if(!o)o=0;l.value=o;l.name=n+"_"+f;l.addEventListener("change",r,false);s[1].insertCell(u).appendChild(l);var c=s[2].insertCell(u);var h=bD(bV(Seed.cities[CAPITAL.id].units[Names.troops.byAbbr[transport_unit_types[f]][1]])," ");c.className="jewel";c.innerHTML="<div id="+a+"_"+f+">(&nbsp;"+h+"&nbsp;)</div>";u=u+1}return e}var e=Tabs.Alliance;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabAllianceAuto"]).className="selected";document.getElementById(UID["tabAllianceAuto"]).style.zIndex=1;e.lastSubTab="tabAllianceAuto";e.contentType=4;var t="<div id="+bS("tabAlliance_Results")+">"+"	<div class="+UID["title"]+'>"Lost In Translation" (Auto-Bank / Auto-Yoyo)</div>'+"	<div id="+bS("tabAlliance_Status")+" class="+UID["status_ticker"]+' style="margin-bottom:5px !important">'+"	<table class="+UID["table"]+" width=100%>"+"		<tr class="+UID["row_headers_left"]+" align=left>"+"			<td align=left colspan=2>"+translate("Recipient")+" : </td>"+"		</tr><tr>"+"			<td><div id="+bS("tabAlliance_AutoPlayerList")+"></div></td>"+"			<td><div id="+bS("tabAlliance_AutoTarget")+' style="height: 17px; padding: 2px 0px;"></div></td>'+"		</tr>"+"	</table><br>"+"	<table id="+bS("tabAlliance_TabAutoYoyo")+" class="+UID["table"]+">"+"		<tr align=left class="+UID["row_headers_left"]+">"+"			<td colspan=2>"+translate("Yoyo functionality")+":&nbsp;</td>"+"		</tr>"+"		<tr align=left>"+"			<td>"+translate("Automatically recall transport 1 minute before delivery")+":&nbsp;</td>"+"			<td><input id="+bS("tabAlliance_AutoYoyo")+" type=checkbox "+(Data.options.alliance.auto.recall?"CHECKED":"")+" /></td>"+"		</tr>"+"	</table><br>"+"	<table id="+bS("tabAlliance_ATroops")+" class="+UID["table"]+">"+"		<tr align=left class="+UID["row_headers_left"]+">"+"			<td colspan=4>"+translate("Troops for transport")+":&nbsp;</td>"+"		</tr>"+"	</table><br>"+"	<table id="+bS("tabAlliance_AResources")+" class="+UID["table"]+" width=100%>"+"		<tr align=left class="+UID["row_headers_left"]+">"+"			<td colspan=3>"+translate("Resources to transport")+":&nbsp;</td>"+"			<td>"+translate("Reserves")+"</td>"+"		</tr>";var n=bS("tabAlliance_ARes");var r=bS("tabAlliance_AMax");var s=bS("tabAlliance_AStk");for(var o=0;o<transportable_resource_types.length;o++){var u=bD(Math.round(bV(Seed.cities[CAPITAL.id].resources[transportable_resource_types[o]])));desc=transportable_resource_types[o];if(transportable_resource_types[o]=="blue_energy")desc="blueenergy250k";t+="<tr><td class=right width=60px>"+translate(desc)+" :</td>"+"	<td width=90px>"+"		<input type=text id="+n+"_"+o+' maxlength=10 style="width:70px" size=2 value="'+bV(Data.options.alliance.auto.resources[transportable_resource_types[o]])+'"></td>'+"	<td width=30px>"+"		<input class=small id="+r+"_"+o+" ref="+o+' type=button style="width:auto !important;" value=" Max " ></td>'+"	<td align=right width=90px><div id="+s+"_"+o+">"+u+"</div></td>"+"<td></td></tr>"}t+="<tr><td align=right class=right>"+translate("Load capacity")+"&nbsp:</td>"+"		<td colspan=4 align=left><div id="+bS("tabAlliance_ATotal")+"></div></td>"+"	</tr><tr>"+"		<td colspan=3 class=right>"+translate("Maximize resource to transport according to max load")+":&nbsp;</td>"+"		<td><input id="+bS("tabAlliance_MaxLoad")+" type=checkbox "+(Data.options.alliance.auto.max_load?"CHECKED":"")+" /></td>"+"	</tr><tr>"+"		<td colspan=3 class=right>"+translate("Delay Between Transports")+":&nbsp;</td>"+"		<td><input id="+bS("tabAlliance_AutoDelayMin")+' type=text size=1 maxlength=4 value="'+Data.options.alliance.auto.delay_min+'" />'+"			 to <span id="+bS("tabAlliance_AutoDelayMax")+">"+Data.options.alliance.auto.delay_max+"</span>&nbsp;"+translate("seconds")+"		</td>"+"	</tr><tr>"+"		<td colspan=3 class=right> "+translate("Maximum simultaneous marches")+":&nbsp;</td>"+"		<td><input id="+bS("tabAlliance_AutoMaxMarches")+' type=text size=1 maxlength=2 value="'+Data.options.alliance.auto.max_marches+'" /></td>'+"	</tr>"+"</table><br><br>"+"<center><input id="+bS("tabAlliance_AOnOff")+' type=button value="OnOff" /></center>'+"<br></div>"+"<div id="+bS("tabAlliance_FeedbackBox")+" class="+UID["status_ticker"]+' style="margin-top:5px; margin-bottom:5px !important">'+"	<div id="+bS("tabAlliance_Feedback")+" class="+UID["status_feedback"]+"></div>"+"	<div id="+bS("tabAlliance_AReport")+' style="margin-top:5px;height:105px; max-height:105px; width:540px; max-width:540px; overflow:auto;">'+"		<table id="+bS("tabAlliance_AMarches")+" class="+UID["table"]+">"+"		</table>"+"	</div>"+"</div></div>";document.getElementById(UID["tabAlliance_Content"]).innerHTML=t;document.getElementById(UID["tabAlliance_AutoYoyo"]).addEventListener("click",function(e){Data.options.alliance.auto.recall=e.target.checked},false);document.getElementById(UID["tabAlliance_MaxLoad"]).addEventListener("click",function(e){Data.options.alliance.auto.max_load=e.target.checked},false);document.getElementById(UID["tabAlliance_AutoDelayMin"]).addEventListener("change",a,false);document.getElementById(UID["tabAlliance_AutoMaxMarches"]).addEventListener("change",c,false);document.getElementById(UID["tabAlliance_AOnOff"]).addEventListener("click",function(){e.aM(!Data.options.alliance.auto.enabled)},false);d(document.getElementById(UID["tabAlliance_ATroops"]),1,"TR",l);for(i=0;i<transportable_resource_types.length;i++){document.getElementById(n+"_"+i).addEventListener("change",h,false);butMax=document.getElementById(r+"_"+i);butMax.addEventListener("click",p,false);bG(butMax,true,"btn_green")}e.getMemberList();f();e.aM(Data.options.alliance.auto.enabled)},tabAllianceReinforcement:function(){function f(t){var n=t.target.id.split("_");var r=bV(t.target.value);e.totalForces=0;var i=0;for(var s=0;s<all_unit_types.length;s++){if(s!=n[1])e.totalForces=bV(e.totalForces)+bV(Data.options.alliance.data.units[all_unit_types[s]]);if(s==n[1])i=bV(Seed.cities[CAPITAL.id].units[all_unit_types[s]]);document.getElementById(UID["tabAlliance_Trp"]+"_"+s).style.backgroundColor=""}if(isNaN(r)||r<0||r+bV(e.totalForces)>bJ(CAPITAL.id).max_troops)t.target.style.backgroundColor="red";else t.target.style.backgroundColor="";t.target.value=r;Data.options.alliance.data.units[all_unit_types[n[1]]]=r;document.getElementById(UID["tabAlliance_RemT"]+"_"+n[1]).innerHTML="( "+bD(i-r," ")+" )"}function l(){var e=Tabs.Alliance;for(var t=0;t<all_unit_types.length;t++)Data.options.alliance.data.units[all_unit_types[t]]=0;e.tabAllianceReinforcement()}function c(t){var n=t.target.id.split("_");var r=0;var i=bV(Seed.cities[CAPITAL.id].units[all_unit_types[n[1]]]);e.totalForces=0;for(var s=0;s<all_unit_types.length;s++)if(s!=n[1])e.totalForces=bV(e.totalForces)+bV(Data.options.alliance.data.units[all_unit_types[s]]);r=bJ(CAPITAL.id).max_troops-bV(e.totalForces);if(r>i)r=i;Data.options.alliance.data.units[all_unit_types[n[1]]]=bV(r);e.tabAllianceReinforcement()}function h(){function n(n){if(n!="OK"){try{t.getContentDiv().innerHTML="<B>"+n+"</b>";t.allowClose(true)}catch(r){}}else{try{t.getContentDiv().innerHTML="<B> OK </b>";setTimeout(function(){t.destroy()},1e3)}catch(r){}e.show()}}var t=new aw(e.container,300,150,"",false);t.bd().innerHTML="<div class="+UID["title"]+"><center><b>"+scriptName+" : "+translate("Message")+"</b></center></div>";t.getContentDiv().innerHTML=translate("Sending reinforcement");p(Data.options.alliance.data.units,n)}function p(e,t){var n=Tabs.Alliance;var r=Seed.cities[CAPITAL.id].id;var i=CAPITAL.id;var s=n.getTarget(Data.options.alliance.reinforce_id);if(as(s)){t(translate("No Recipient Defined"));return}var o=null;var u=bb(CAPITAL.id,e);if(u!=null){t(aW(u,"fb"));return}o=bB();if(o==null){t(aW(3,"fb"));return}var a="<B>"+translate("Reinforcement sent to")+"</B> : "+s.msg;aZ(a+" "+translate("attempted"));new MyAjax.marchSend(r,s.x,s.y,o.id,e,"attacks",function(e){if(e.ok){aZ(a+" "+translate("Successfully"));aX(a);if(t)t("OK")}else{aZ(a+" "+translate("failed and returned error")+": "+e.errmsg);if(t)t(translate("Error")+": "+e.errmsg)}return})}function d(){var e=Tabs.Alliance;if(e.checkReinfBusy)return false;e.checkReinfBusy=true;v(function(){bI("****** Setting checkReinfBusy to FALSE");Tabs.Alliance.checkReinfBusy=false;Tabs.Alliance.show()})}function v(e){function e(t){if(t!="OK"){progressBarPop.getContentDiv().innerHTML="<B>"+t+"</B>";progressBarPop.allowClose(true);if(e)e(false);return}else{aX("<B>startReinforcements</B> : "+translate("complete"));progressBarPop.destroy();if(e)e(true);return}}var t=Tabs.Alliance;var n=[];var r=0;for(i=0;i<all_unit_types.length;i++){var s=false;for(var o=0;o<transport_unit_types.length&&!s;o++)if(Names.troops.byAbbr[transport_unit_types[o]][1]==all_unit_types[i])s=true;if(!s){var u=bV(Seed.cities[CAPITAL.id].units[all_unit_types[i]]);r+=u;if(u>0)n.push({type:all_unit_types[i],qty:u,upkeep:bV(Seed.stats.unit[all_unit_types[i]].upkeep.food)})}}var a=bJ(CAPITAL.id);var f=a.slots;var l=a.max_troops;if(f<=0||r==0||l<=0){e(true);return}bI("======> alliance tab initReinforcements");progressBar.init(800+Math.randRange(1,50),100,300,150,translate("Message"),200,true,t.container);progressBar.start({steps:100,delay:1,byCount:true,title:translate("Sending reinforcement")+"...",stepText:translate("Please wait...")});n.sort(function(e,t){return t.upkeep-e.upkeep});t.to_send=n;t.step=0;t.steps=Math.ceil(r/l)<=f?Math.ceil(r/l):f;m(e)}function m(e){var t=Tabs.Alliance;t.is_sending=true;t.bO=e;t.result="OK";y();g()}function g(){var e=Tabs.Alliance;if(e.is_sending){setTimeout(g,1e3)}else{if(e.bO){e.bO(e.result);return}}}function y(){var e=Tabs.Alliance,t=bJ(CAPITAL.id);var n=t.max_troops;var r=0;var i=[];for(var s=0;s<e.to_send.length&&r<n;s++){var o=e.to_send[s];if(o.qty>0){var u=o.qty>n-r?n-r:o.qty;r+=u;i[o.type]=u;o.qty-=u}}if(t.slots<=0||r==0){e.is_sending=false;return}p(i,function(t){if(t=="OK"){e.percent=bV(e.step*100/e.steps);progressBar.update({step:e.percent,stepText:translate("Please wait...")+"<br>"+translate("Step")+" "+(e.step+1)+"/"+e.steps+" : "+cq(i," ")});e.step++;setTimeout(y,Math.randRange(2e3,5e3))}else{progressBar.update({stepText:t});e.result=t;e.is_sending=false}})}var e=Tabs.Alliance;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabAllianceReinforcement"]).className="selected";document.getElementById(UID["tabAllianceReinforcement"]).style.zIndex=1;e.lastSubTab="tabAllianceReinforcement";e.contentType=2;var t="<div id="+bS("tabAlliance_Results")+' style="height:590px">'+"	<div class="+UID["title"]+">"+translate("reinforcements")+"</div>"+"	<div id="+bS("tabAlliance_Status")+" class="+UID["status_ticker"]+' style="margin-bottom:5px !important">'+"	<table class="+UID["table"]+" width=100%>"+"		<tr class="+UID["row_headers_left"]+" align=left>"+"			<td align=left colspan=2>"+translate("Recipient")+" : </td>"+"		</tr><tr>"+"			<td><div id="+bS("tabAlliance_ReinfPlayerList")+"></div></td>"+"			<td><div id="+bS("tabAlliance_ReinfTarget")+' style="height: 17px; padding: 2px 0px;"></div></td>'+"		</tr>"+"	</table><br>"+"	<br>"+"	<table id="+bS("tabAlliance_RTroops")+" class="+UID["table"]+">"+"		<tr align=left class="+UID["row_headers_left"]+">"+"			<td colspan=5>"+translate("Troops for reinforcement")+":&nbsp;</td>"+"		</tr>";var n=bS("tabAlliance_Trp");var r=bS("tabAlliance_MaxT");var s=bS("tabAlliance_RemT");for(i=0;i<all_unit_types.length;i++){var o=bV(Data.options.alliance.data.units[all_unit_types[i]]);var u=bV(Seed.cities[CAPITAL.id].units[all_unit_types[i]]);var a="( "+bD(u-o," ")+" )";u=bD(u," ");t+='<tr><td class=right width="100px">'+translate(Names.troops.byName[all_unit_types[i]][1])+":</td>"+'	<td width="75px">'+"		<input type=text id="+n+"_"+i+' maxlength=6 style="width:55px" size=2 value="'+o+'"></td>'+'	<td width="30px">'+"		<input class=small id="+r+"_"+i+" ref="+i+' type=button  style="width:auto !important;" value=" Max " ></td>'+'	<td align=right width="70px">'+u+"</td>"+'	<td align=right width="80px"><span id='+s+"_"+i+" ref="+i+">"+a+"</span></td>"+"</tr>"}t+="</table><br><br>"+"<table class="+UID["table"]+' style="margin-top:3px" width=60%>'+"	<tr valign=top align=center>"+"		<td width=25%><label><input id="+bS("tabAlliance_clearAllR")+' type=button class="'+UID["btn_green"]+'" value="'+translate("Clear all")+'" /></label></td>'+"		<td width=25%><label><input id="+bS("tabAlliance_LaunchR")+' type=button value="'+translate("Send reinforcement")+'" /></label></td>'+"		<td width=25%><label><input id="+bS("tabAlliance_LaunchAllR")+' type=button value="'+translate("Send Max in reinf")+'" /></label></td>'+"	</tr>"+"</table>"+"<br></div></div>";document.getElementById(UID["tabAlliance_Content"]).innerHTML=t;document.getElementById(UID["tabAlliance_clearAllR"]).addEventListener("click",l,false);document.getElementById(UID["tabAlliance_LaunchR"]).addEventListener("click",h,false);document.getElementById(UID["tabAlliance_LaunchAllR"]).addEventListener("click",d,false);for(i=0;i<all_unit_types.length;i++){document.getElementById(n+"_"+i).addEventListener("change",f,false);butMax=document.getElementById(r+"_"+i);butMax.addEventListener("click",c,false);bG(butMax,true,"btn_green")}if(jo()){bG(document.getElementById(UID["tabAlliance_LaunchR"]),false);bG(document.getElementById(UID["tabAlliance_LaunchAllR"]),false)}else{bG(document.getElementById(UID["tabAlliance_LaunchR"]),true);bG(document.getElementById(UID["tabAlliance_LaunchAllR"]),true)}e.getMemberList()},tabAlliances:function(){function v(e){var t=Tabs.Alliance;var n=e.target.parentNode.parentNode.id;if(n==UID["tabAlliance_taa_0"]){if(Data.options.alliance.sort_alliance=="0"){Data.dynamic.players.alliances.sort(function(e,t){return t.rank-e.rank});Data.options.alliance.sort_alliance="-0"}else{Data.dynamic.players.alliances.sort(function(e,t){return e.rank-t.rank});Data.options.alliance.sort_alliance="0"}}else if(n==UID["tabAlliance_taa_1"]){if(Data.options.alliance.sort_alliance=="1"){Data.dynamic.players.alliances.sort(function(e,t){e=e.name.toLowerCase();t=t.name.toLowerCase();if(e>t)return-1;if(e<t)return 1;return 0});Data.options.alliance.sort_alliance="-1"}else{Data.dynamic.players.alliances.sort(function(e,t){e=e.name.toLowerCase();t=t.name.toLowerCase();if(e>t)return 1;if(e<t)return-1;return 0});Data.options.alliance.sort_alliance="1"}}else if(n==UID["tabAlliance_taa_2"]){if(Data.options.alliance.sort_alliance=="2"){Data.dynamic.players.alliances.sort(function(e,t){e=e.lord.toLowerCase();t=t.lord.toLowerCase();if(e>t)return-1;if(e<t)return 1;return 0});Data.options.alliance.sort_alliance="-2"}else{Data.dynamic.players.alliances.sort(function(e,t){e=e.lord.toLowerCase();t=t.lord.toLowerCase();if(e>t)return 1;if(e<t)return-1;return 0});Data.options.alliance.sort_alliance="2"}}else if(n==UID["tabAlliance_taa_3"]){if(Data.options.alliance.sort_alliance=="3"){Data.dynamic.players.alliances.sort(function(e,t){return t.count-e.count});Data.options.alliance.sort_alliance="-3"}else{Data.dynamic.players.alliances.sort(function(e,t){return e.count-t.count});Data.options.alliance.sort_alliance="3"}}else if(n==UID["tabAlliance_taa_4"]){if(Data.options.alliance.sort_alliance=="4"){Data.dynamic.players.alliances.sort(function(e,t){return t.might-e.might});Data.options.alliance.sort_alliance="-4"}else{Data.dynamic.players.alliances.sort(function(e,t){return e.might-t.might});Data.options.alliance.sort_alliance="4"}}t.tabAlliances()}function m(){var e=Tabs.Alliance;if(e.checkAlliancesBusy)return false;e.checkAlliancesBusy=true;y(function(){bI(translate("Alliances list retrieved"));Tabs.Alliance.checkAlliancesBusy=false;var e=be();Data.options.alliance.alliance_update=(new Date(e*1e3)).myString();g()})}function g(){var e=Tabs.Alliance;if(e.checkAlliancesBusy)setTimeout(g,1e3);else e.tabAlliances()}function y(e){function r(t){if(!t.done){if(t.errmsg)progressBarPop.getContentDiv().innerHTML=t.errmsg;else progressBarPop.getContentDiv().innerHTML=translate("Error while retrieving the list of alliances");Tabs.Alliance.checkAlliancesError=true;progressBarPop.allowClose(true);if(e)e(false);return}else{Data.dynamic.players.alliances=aA(t.alliance);Data.dynamic.players.friends=aA(t.friends);Data.dynamic.players.foes=aA(t.foes);aX(translate("Search for alliance list")+" "+translate("complete"));bI("*********  List retrieved ... Total members: "+Data.dynamic.players.alliances.length);Data.dynamic.players.alliances.sort(function(e,t){return e.rank-t.rank});Data.options.alliance.sort_alliance="0";progressBarPop.destroy();if(e)e(true)}}var t=Tabs.Alliance;ret=[];if(Data.dynamic.players.alliances&&Data.dynamic.players.alliances!=undefined&&Data.dynamic.players.alliances.length>0)for(var n=0;n<Data.dynamic.players.alliances.length;n++)ret.push({id:Data.dynamic.players.alliances[n].id,might:Data.dynamic.players.alliances[n].might,count:Data.dynamic.players.alliances[n].count});Data.dynamic.players.alliances_evolution=aA(ret);Data.dynamic.players.alliances={name:"",id:0,count:0,rank:0,might:0,lord:"",lord_id:0,desc:""};progressBar.init(800+Math.randRange(1,50),100,300,150,translate("Message"),200,true,t.container);progressBar.start({steps:100,delay:1,byCount:true,title:translate("Search for alliance list")+"...",stepText:translate("Please wait...")});MemberShips.fetchAlliances(r)}function b(e){function s(e){if(e==null||!e.ok){if(e.errmsg)i.getContentDiv().innerHTML=e.errmsg;else i.getContentDiv().innerHTML=translate("Error while sending the request");i.allowClose(true);return}setTimeout(function(){i.destroy()},1e3);return}var t=Tabs.Alliance,n=e.target;var r=n.getAttribute("ref");bG(n,false);var i=new aw(t.container,300,165,"",false,null);i.bd().innerHTML="<div class="+UID["title"]+"><center><b>"+scriptName+" : "+translate("Message")+"</b></center></div>";i.getContentDiv().innerHTML=translate("actions-ask-to-join");MyAjax.membership(r,Seed.player.id,"invite",s,false)}var e=Tabs.Alliance;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabAlliances"]).className="selected";document.getElementById(UID["tabAlliances"]).style.zIndex=1;e.lastSubTab="tabAlliances";e.contentType=3;if(as(Data.options.alliance.sort_alliance))Data.options.alliance.sort_alliance="0";if(!as(Data.options.alliance.alliance_update))kLastupdate=" ("+Data.options.alliance.alliance_update+")";else kLastupdate="";var t="<div id="+bS("tabAlliance_Results")+' style="height:640px">'+"	<div class="+UID["title"]+">"+translate("Alliances")+"Top 100 "+kLastupdate+"</div>"+"	<div id="+bS("tabAlliance_ResultList")+" class="+UID["status_ticker"]+' style="height:620px; max-height:620px; overflow:auto; white-space:nowrap; margin-top:1px !important"></div>'+"	</div>";document.getElementById(UID["tabAlliance_Content"]).innerHTML=t;var t="<table class="+UID["row_style"]+">"+"	<tr><td align=left colspan=4>"+'		<input type=button value="'+translate("Refresh list")+'" id='+bS("tabAlliance_RefreshAlliances")+" />"+"	</td></tr>"+'	<tr valign=top><td style="font-size:2px">&nbsp</td>'+"	</tr>"+"	<tr class="+UID["row_headers"]+">"+"		<td id="+bS("tabAlliance_taa_0")+' width="40px" align=center><A><span>'+translate("Rank")+"</span></A></td>"+"		<td id="+bS("tabAlliance_taa_1")+' width="150px" style="overflow-x:auto"><A><span>'+translate("Alliance")+"</span></A></td>"+"		<td id="+bS("tabAlliance_taa_2")+' width="150px" style="overflow-x:auto"><A><span>'+translate("role-overlord")+"</span></A></td>"+"		<td id="+bS("tabAlliance_taa_3")+' width="45px" align=center><A><span>'+translate("members")+"</span></A></td>"+"		<td id="+bS("tabAlliance_taa_4")+' width="65px" align=right><A><span>'+translate("Might")+"</span></A></td>"+'		<td width="60px" align=right>'+translate("Evol")+"</td>"+"	</tr>";var n=[],r=[],i=bS("tabAlliances_SendMsg"),s=bS("tabAlliances_Invite");for(var o=0;o<Data.dynamic.players.alliances.length;o++){var u=bD(Data.dynamic.players.alliances[o].might," ");var a=false;var f="x",l="";for(var c=0;c<Data.dynamic.players.alliances_evolution.length&&!a;c++){if(Data.dynamic.players.alliances_evolution[c].id==Data.dynamic.players.alliances[o].id){f=Data.dynamic.players.alliances[o].might-Data.dynamic.players.alliances_evolution[c].might;l=Data.dynamic.players.alliances[o].count-(Data.dynamic.players.alliances_evolution[c].count||Data.dynamic.players.alliances[o].count);if(f<0)f="<span class="+UID["red"]+">"+bD(f," ")+"</span>";else if(f>0)f="<span class="+UID["green"]+">+"+bD(f," ")+"</span>";else f=bD(f," ");if(l<0)l=" (<span class="+UID["red"]+">"+bD(l," ")+"</span>)";else if(l>0)l=" (<span class="+UID["green"]+">+"+bD(l," ")+"</span>)";else l="";a=true}}var h=Data.dynamic.players.alliances[o].id+"_"+Data.dynamic.players.alliances[o].lord_id;t+="<tr><td align=center>"+Data.dynamic.players.alliances[o].rank+"</td>"+"	<td align=left>"+eQ(Data.dynamic.players.alliances[o].id,Data.dynamic.players.alliances[o].name)+"</td>"+"	<td align=left>"+Data.dynamic.players.alliances[o].lord+"</td>"+"	<td align=center>"+Data.dynamic.players.alliances[o].count+l+"</td>"+"	<td align=right>"+u+"</td>"+"	<td align=right>"+f+"</td>"+"	<td align=right>&nbsp;<input class=Xtrasmall id="+i+"_"+Data.dynamic.players.alliances[o].id+' ref="'+h+'" type=button  style="width:auto !important;" value="'+translate("Msg")+'" ></td>'+(Seed.player.alliance&&Seed.player.alliance.id>0?"":"<td align=right>&nbsp;<input class=Xtrasmall id="+s+"_"+o+' ref="'+Data.dynamic.players.alliances[o].id+'" type=button  style="width:auto !important;" value="'+translate("Invite")+'" ></td>')+"</tr>";n.push(i+"_"+Data.dynamic.players.alliances[o].id);if(!Seed.player.alliance||Seed.player.alliance.id==0)r.push(s+"_"+o)}document.getElementById(UID["tabAlliance_ResultList"]).innerHTML=t+"</table>";document.getElementById(UID["tabAlliance_RefreshAlliances"]).addEventListener("click",m,false);for(var p=0;p<5;p++)document.getElementById(UID["tabAlliance_taa_"+p]).addEventListener("click",v,false);for(var d=0;d<n.length;d++)document.getElementById(n[d]).addEventListener("click",bF,false);for(var d=0;d<r.length;d++)document.getElementById(r[d]).addEventListener("click",b,false)},tabAllianceActivity:function(){function c(t){e.report_num=-1;e.tabAllianceActivity()}function h(t){var n=bV(t.target.getAttribute("ref"));e.report_num=n;e.tabAllianceActivity()}function p(){var e=Tabs.Alliance;e.report_num=-1;if(e.checkAlliancesBusy)return false;e.checkAlliancesBusy=true;v(function(){bI(translate("Alliance activity retrieved"));Tabs.Alliance.checkAlliancesBusy=false;var e=be();Data.options.alliance.activity_update=(new Date(e*1e3)).myString();d()})}function d(){var e=Tabs.Alliance;if(e.checkAlliancesBusy)setTimeout(d,1e3);else e.tabAllianceActivity()}function v(e){function n(t){if(!t.done){if(t.errmsg)progressBarPop.getContentDiv().innerHTML=t.errmsg;else progressBarPop.getContentDiv().innerHTML=translate("Error while retrieving the alliance activity");Tabs.Alliance.checkAlliancesError=true;progressBarPop.allowClose(true);if(e)e(false);return}else{Data.dynamic.players.activity=aA(t.battle);aX(translate("Search for alliance activity")+" "+translate("complete"));bI("*********  List retrieved ... Total battles: "+Data.dynamic.players.activity.length);Data.dynamic.players.activity.sort(function(e,t){return t.time-e.time});Data.options.alliance.sort_activity="0";progressBarPop.destroy();if(e)e(true)}}var t=Tabs.Alliance;Data.dynamic.players.activity={won:false,id:0,def:false,time:0,aname:"",amight:0,ax:0,ay:0,pname:"",pmight:0,px:0,py:0,palli:""};progressBar.init(800+Math.randRange(1,50),100,300,150,translate("Message"),200,true,t.container);progressBar.start({steps:100,delay:1,byCount:true,title:translate("Search for alliance activity")+"...",stepText:translate("Please wait...")});MemberShips.fetchActivity(Seed.player.alliance.id,n)}function m(){var e=Tabs.Alliance;if(e.checkActivityBusy)setTimeout(m,1e3);else y()}function g(){var e=Tabs.Alliance;if((as(Messages.activity)||as(Messages.activity[Data.dynamic.players.activity[e.report_num].id])||as(Messages.activity[Data.dynamic.players.activity[e.report_num].id].report))&&!e.checkActivityBusy){e.checkActivityBusy=true;MyAjax.battleReport(Data.dynamic.players.activity[e.report_num].id,Data.dynamic.players.activity[e.report_num].aid,function(e){var t=Tabs.Alliance;t.checkActivityBusy=false;if(!e)return})}m()}function y(){var e=Tabs.Alliance,t="";t+="<center><div id="+bS("displayMsg_ReportContent")+' style="height:555px; max-height:555px; width:98%; max-width:98%; overflow-y:auto;">'+Messages.displayBattleReport(Messages.activity[Data.dynamic.players.activity[e.report_num].id],Data.dynamic.players.activity[e.report_num].aname)+"</div></center>";document.getElementById(UID["tabAlliance_ReportDetail"]).innerHTML=t}var e=Tabs.Alliance;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabAllianceActivity"]).className="selected";document.getElementById(UID["tabAllianceActivity"]).style.zIndex=1;e.lastSubTab="tabAllianceActivity";e.contentType=5;if(as(Data.options.alliance.sort_activity))Data.options.alliance.sort_activity="0";if(!as(Data.options.alliance.activity_update))kLastupdate=" ("+Data.options.alliance.activity_update+")";else kLastupdate="";var t="<div id="+bS("tabAlliance_Results")+' style="height:640px">'+"	<div class="+UID["title"]+">"+translate("Activity")+" "+kLastupdate+"</div>"+"	<div id="+bS("tabAlliance_ResultList")+" class="+UID["status_ticker"]+' style="height:9999px; max-height:620px; overflow:auto; white-space:nowrap; margin-top:1px !important"></div>'+"	<div id="+bS("tabAlliance_ReportDetail")+" class="+UID["status_ticker"]+' style="height:555px; max-height:555px; overflow:auto; white-space:nowrap; display:none; margin-top:1px !important"></div>'+"	</div>";document.getElementById(UID["tabAlliance_Content"]).innerHTML=t;var t="<table class="+UID["row_style"]+">"+"	<tr><td align=left colspan=6>"+'		<input type=button value="'+translate("Refresh")+'" id='+bS("tabAlliance_RefreshActivity")+" />"+"	</td></tr>"+'	<tr valign=top><td style="font-size:2px">&nbsp</td>'+"	</tr>"+"	<tr class="+UID["row_headers"]+">"+'		<td width="40px" align=center><A><span>'+translate("ago")+"</span></A></td>"+'		<td width="150px" style="overflow-x:auto"><A><span>'+translate("members")+"</span></A></td>"+'		<td width="20px" style="overflow-x:auto"><A><span>'+translate("Role")+"</span></A></td>"+'		<td width="150px" align=center><A><span>'+translate("Enemy")+"</span></A></td>"+'		<td width="60px" align=right><A><span>'+translate("status")+"</span></A></td>"+'		<td width="60px" align=right>'+translate("reports")+"</td>"+"	</tr>";if(e.report_num==-1){document.getElementById(UID["tabAlliance_ResultList"]).style.height="2480px";document.getElementById(UID["tabAlliance_ReportDetail"]).style.display="none";for(var n=0;n<Data.dynamic.players.activity.length;n++){var r=Data.dynamic.players.activity[n];var i=bz(bV(be())-bV(r.time));var s='<span title="'+r.aname+", "+translate("might")+" "+bD(r.amight," ")+" ("+r.ax+"/"+r.ay+')"><b>'+r.aname+"</b></span>";var o="";if(!as(r.palli))o=", "+r.palli;var u='<span title="'+r.pname+o+", "+translate("might")+" "+bD(r.pmight," ")+" ("+r.px+"/"+r.py+')"><b>'+r.pname+"</b>"+o+"</span>";t+="<tr><td align=center>"+i+"</td>"+"	<td align=left>"+s+"</td>"+"	<td align=center><b>"+(r.def?"&gt":"<span class="+UID["red"]+">&lt</span>")+"</b></td>"+"	<td align=left>"+u+"</td>"+"	<td align=left>"+(r.won?translate("won"):"<span class="+UID["red"]+">"+translate("lost")+"</span>")+"</td>"+"	<td><input id="+bS("tabAlliance_view_"+n)+" ref="+n+' class=Xtrasmall style="width:auto !important;" type=submit value="'+translate("View")+'" /></td>'+"</tr>"}}else{document.getElementById(UID["tabAlliance_ResultList"]).style.height="60px";document.getElementById(UID["tabAlliance_ReportDetail"]).style.display="block";var r=Data.dynamic.players.activity[e.report_num];var i=bz(bV(be())-bV(r.time));var s='<span title="'+r.aname+", "+translate("might")+" "+bD(r.amight," ")+" ("+r.ax+"/"+r.ay+')"><b>'+r.aname+"</b></span>";var o="";if(!as(r.palli))o=", "+r.palli;var u='<span title="'+r.pname+o+", "+translate("might")+" "+bD(r.pmight," ")+" ("+r.px+"/"+r.py+')"><b>'+r.pname+"</b>"+o+"</span>";t+="<tr><td align=center>"+i+"</td>"+"	<td align=left>"+s+"</td>"+"	<td align=center>"+(r.def?"&gt":"<span class="+UID["red"]+">&lt</span>")+"</td>"+"	<td align=left>"+u+"</td>"+"	<td align=left>"+(r.won?translate("won"):"<span class="+UID["red"]+">"+translate("lost")+"</span>")+"</td>"+"	<td><input id="+bS("tabAlliance_Hide")+' class=Xtrasmall style="width:auto !important;" type=submit value="'+translate("wall-orders-hide")+'" /></td>'+"</tr>"}document.getElementById(UID["tabAlliance_ResultList"]).innerHTML=t+"</table>";var a=document.getElementById(UID["tabAlliance_RefreshActivity"]);a.addEventListener("click",p,false);if(Seed.player.alliance&&Seed.player.alliance.id>0)bG(a,true);else bG(a,false);if(e.report_num==-1){for(var n=0;n<Data.dynamic.players.activity.length;n++){var f=document.getElementById(UID["tabAlliance_view_"+n]);f.addEventListener("click",h,false);Element.addClassName(f,UID["btn_green"])}}else{var l=document.getElementById(UID["tabAlliance_Hide"]);l.addEventListener("click",c,false);Element.addClassName(l,UID["btn_green"]);g()}},ce:function(){var e=Tabs.Alliance;e.totalResources=0;e.maxResources=0;for(var t=0;t<transportable_resource_types.length;t++)e.totalResources=bV(e.totalResources)+bV(Data.options.alliance.data.resources[transportable_resource_types[t]]);for(var n=0;n<transport_unit_types.length;n++){if(Names.troops.byAbbr[transport_unit_types[n]][1]=="Porter")var r=200;else if(Names.troops.byAbbr[transport_unit_types[n]][1]=="ArmoredTransport")var r=5e3;else if(Names.troops.byAbbr[transport_unit_types[n]][1]=="PackDragon")var r=6e3;else var r=0;var i=Data.options.alliance.data.transports[Names.troops.byAbbr[transport_unit_types[n]][1]];try{var r=Seed.stats.unit[Names.troops.byAbbr[transport_unit_types[n]][1]].load}catch(s){aX("<B>"+translate("Troops load: ")+"</B>"+s.msg+" "+translate("Manifest not available, using defaults"))}e.maxResources=e.maxResources+bV(i)*bV(r)}var o=bD(bV(e.maxResources)-bV(e.totalResources)," ");document.getElementById(UID["tabAlliance_Total"]).innerHTML="<B>"+bD(bV(e.totalResources)," ")+"</B> / <B>"+bD(bV(e.maxResources)," ")+"</B> (<B>"+o+"</B> disponible)"},autoTransportTick:function(){function v(t,n){var r=0,i=0,s=0,o=0,u=0,a=0;for(var f=0;f<transport_unit_types.length;f++){if(Names.troops.byAbbr[transport_unit_types[f]][1]=="Porter")var l=200;else if(Names.troops.byAbbr[transport_unit_types[f]][1]=="ArmoredTransport")var l=5e3;else if(Names.troops.byAbbr[transport_unit_types[f]][1]=="PackDragon")var l=6e3;else var l=0;var c=n[Names.troops.byAbbr[transport_unit_types[f]][1]];try{var l=Seed.stats.unit[Names.troops.byAbbr[transport_unit_types[f]][1]].load}catch(h){}r=r+bV(c)*bV(l)}var p=bD(bV(e.maxResources)-bV(e.totalResources)," ");for(var d=0;d<transportable_resource_types.length;d++){i=bV(t[transportable_resource_types[d]]);s=bV(s)+i;o=Math.round(bV(Seed.cities[CAPITAL.id].resources[transportable_resource_types[d]]))-i;if(o>0)a++}u=bV(r)-bV(s);if(u<=0||a==0)return t;var v=Math.round(u/a);while(u>0&&a>0&&v>0){for(var m=0;m<transportable_resource_types.length;m++){i=bV(t[transportable_resource_types[m]]);o=Math.round(bV(Seed.cities[CAPITAL.id].resources[transportable_resource_types[m]]))-i;if(o>0&&o<v)v=o}a=0;for(var m=0;m<transportable_resource_types.length;m++){i=bV(t[transportable_resource_types[m]]);o=Math.round(bV(Seed.cities[CAPITAL.id].resources[transportable_resource_types[m]]))-i;if(o>0){t[transportable_resource_types[m]]=i+v;u=u-v;o=o-v;if(o>0)a++}}v=Math.round(u/a)}return t}var e=Tabs.Alliance,t,n,r,i,s=0;var o=Seed.cities[CAPITAL.id].id;var u=CAPITAL.id;clearTimeout(e.autoTimer);if(!Data.options.alliance.auto.enabled)return;var a=e.getTarget(Data.options.alliance.auto_id);if(as(a)){aS(UID["tabAlliance_Feedback"],translate("No Recipient Defined"));e.aM(false);return}var t="<B>"+translate("Transport sent to")+"</B> : "+a.msg;var f=UID["tabAlliance_Feedback"];var l=cK();s=l.count;n=l.delay;availableGeneral=bB();var c=dB(t,f,s,n,Marches.count.transport,Data.options.alliance.auto.max_marches,null,false);if(c!=0){e.autoTimer=setTimeout(e.autoTransportTick,n*1e3);return}r=bb(CAPITAL.id,Data.options.alliance.auto.transports);if(r!==null){bM(t,f,r,true,n);e.autoTimer=setTimeout(e.autoTransportTick,n*1e3);return}var i=aA(Data.options.alliance.auto.resources);var h=0;for(var p in i){var d=Math.round(bV(Seed.cities[CAPITAL.id].resources[p]));if(i[p]>0){if(i[p]>d)i[p]=d;h+=i[p]}}if(Data.options.alliance.auto.max_load)i=v(i,Data.options.alliance.auto.transports);if(h<=0){bM(t,f,8,false,n);e.autoTimer=setTimeout(e.autoTransportTick,n*1e3);return}aZ(t+" "+translate("attempted"));new MyAjax.TransportMarch(o,a.x,a.y,Data.options.alliance.auto.transports,i,"transport",function(e){var n=Tabs.Alliance,r,i;if(e.ok&&e.dat.result.success){n.autoErrors=0;r=Math.floor(Math.random()*(Data.options.alliance.auto.delay_max-Data.options.alliance.auto.delay_min+1)+Data.options.alliance.auto.delay_min);aZ(t+" "+translate("Successfully"));aX(t);aS(UID["tabAlliance_Feedback"],t);n.autoTimer=setTimeout(n.autoTransportTick,r*1e3);if(Data.options.alliance.auto.recall){var s={cityId:o,marchId:e.dat.result.job.march_id,run_at:e.dat.result.job.run_at};Data.dynamic.recall_marches.push(s)}for(var u=0;u<transportable_resource_types.length;u++){var a=bD(Math.round(bV(Seed.cities[CAPITAL.id].resources[transportable_resource_types[u]])));var l=UID["tabAlliance_AStk"]+"_"+u;if(document.getElementById(l))document.getElementById(l).innerHTML=a}for(var c=0;c<transport_unit_types.length;++c){var h=bD(bV(Seed.cities[CAPITAL.id].units[Names.troops.byAbbr[transport_unit_types[c]][1]])," ");var p=UID["tabAlliance_ATStk"]+"_"+c;if(document.getElementById(p))document.getElementById(p).innerHTML="(&nbsp;"+h+"&nbsp;)"}}else{n.autoErrors++;i=30*n.autoErrors*n.autoErrors;aZ(t+" "+translate("failed and returned error")+": "+e.errmsg+" - "+translate("Retry in")+" "+i+" "+translate("seconds"));aX(t+" "+translate("failed"));if(e.status===429){i=E429_DELAY;bM(t+" "+translate("failed")+" - <b>API</b> ",f,6,false,i)}else if(e.status===509){i=600;bM(t+" "+translate("failed")+" - ",f,6,false,i)}else aS(UID["tabAlliance_Feedback"],t+" "+translate("failed"));n.autoTimer=setTimeout(n.autoTransportTick,i*1e3)}})},marchTick:function(){var e=Tabs.Alliance;var t;switch(e.contentType){case 4:t="tabAlliance_AMarches";break;default:t="tabAlliance_TMarches";break}clearTimeout(e.marchTimer);if(document.getElementById(UID[t]))Marches.updateTable(document.getElementById(UID[t]),"transport");e.marchTimer=setTimeout(e.marchTick,1e3)},getTarget:function(e){var t=false,n={};for(var r=1;r<Seed.cities.length&&!t;r++){if(Seed.cities[r]&&e==Seed.cities[r].id){t=true;var i=Seed.cities[r];return{x:i.x,y:i.y,msg:translate(i.name)+" "+translate("at")+" "+i.x+","+i.y}}}if(!t){for(var s=0;s<Data.dynamic.players.memberships.length&&!t;s++){if(Data.dynamic.players.memberships[s].id==e){t=true;var o=Data.dynamic.players.memberships[s];return{x:o.x,y:o.y,msg:o.player+", "+o.city+" "+translate("at")+" "+o.x+","+o.y}}}}},getMemberList:function(){var e=Tabs.Alliance;var t,n,r,i;switch(e.contentType){case 4:t="tabAlliance_AutoPlayerList";n="tabAlliance_AutoPlayer";i=Data.options.alliance.auto_id;break;case 2:t="tabAlliance_ReinfPlayerList";n="tabAlliance_ReinfPlayer";i=Data.options.alliance.reinforce_id;break;default:t="tabAlliance_TransPlayerList";n="tabAlliance_TransPlayer";i=Data.options.alliance.transport_id;break}r=bS(n);var s="<select id="+r+">";var o="";for(var u=1;u<Seed.cities.length;u++){if(Seed.cities[u]){o="";if(i==Seed.cities[u].id)o=" selected";s+='<option value="'+Seed.cities[u].id+'" '+o+">"+translate(Seed.cities[u].name)+"</option>"}}if(Seed.cities.length<2&&(!Data.dynamic.players.memberships||Data.dynamic.players.memberships.length==0))s+='<option value="">'+translate("To be refreshed")+"</option>";else{for(var a=0;a<Data.dynamic.players.memberships.length;a++){o="";if(Data.dynamic.players.memberships[a].id==i)o=" selected";s+='<option value="'+Data.dynamic.players.memberships[a].id+'" '+o+">"+Data.dynamic.players.memberships[a].player+"</option>"}}s+="</select>";document.getElementById(UID[t]).innerHTML=s;document.getElementById(UID[n]).addEventListener("change",e.playerSelChanged,false);e.playerCityDesc()},onClickResign:function(e){var t=Tabs.Alliance;bG(document.getElementById(UID["tabAlliance_Regin"]),false,"btn_off","btn_disabled");dO(translate("leave-current"),function(){try{var t=new aw(Tabs.Alliance.container,300,165,"",false,null);t.bd().innerHTML="<div class="+UID["title"]+"><center><b>"+scriptName+" : "+translate("Message")+"</b></center></div>";t.getContentDiv().innerHTML=translate("Leaving the alliance")+"...";MyAjax.membership(Seed.player.alliance.id,Seed.player.alliance_membership.id,"delete",n,false);function n(n){if(n==null||!n.ok){if(n.errmsg)t.getContentDiv().innerHTML=n.errmsg;else t.getContentDiv().innerHTML=translate("Error while leaving the alliance");t.allowClose(true);if(e)e(false);return}else{t.getContentDiv().innerHTML=translate("Refreshing player and cities data");Seed.fetchPlayer(function(n){if(n.ok){aZ(translate("Player data was Successfully requested from the server"));try{setTimeout(function(){t.destroy()},1e3)}catch(r){}if(e)e(true);return}else{try{t.getContentDiv().innerHTML=translate("Error while retrieving player data "+n.errmsg);t.allowClose(true)}catch(r){}if(e)e(false);return}},{noCities:true})}if(e)e(true);return}}catch(r){}},function(){bG(document.getElementById(UID["tabAlliance_Regin"]),true,"btn_off","btn_disabled")},true)},playerSelChanged:function(e){var t=Tabs.Alliance;var n;switch(t.contentType){case 4:n="tabAlliance_AutoPlayer";break;case 2:n="tabAlliance_ReinfPlayer";break;default:n="tabAlliance_TransPlayer";break}var r=document.getElementById(UID[n]);var i=bK(r.value,"none");r.value=i;switch(t.contentType){case 4:Data.options.alliance.auto_id=i;break;case 2:Data.options.alliance.reinforce_id=i;break;default:Data.options.alliance.transport_id=i;break}t.playerCityDesc()},playerCityDesc:function(){var e=Tabs.Alliance;var t,n;switch(e.contentType){case 4:t="tabAlliance_AutoTarget";n=Data.options.alliance.auto_id;break;case 2:t="tabAlliance_ReinfTarget";n=Data.options.alliance.reinforce_id;break;default:t="tabAlliance_TransTarget";n=Data.options.alliance.transport_id;break}var r=false;for(var i=1;i<Seed.cities.length&&!r;i++){if(Seed.cities[i]&&n==Seed.cities[i].id){r=true;document.getElementById(UID[t]).innerHTML="<B>"+translate(Seed.cities[i].name)+"</b>"+" &nbsp; ("+Seed.cities[i].x+", "+Seed.cities[i].y+") &nbsp; <B>"+translate("Distance")+": </b>"+bu(Seed.cities[CAPITAL.id].x,Seed.cities[CAPITAL.id].y,Seed.cities[i].x,Seed.cities[i].y)}}if(!r){for(var s=0;s<Data.dynamic.players.memberships.length&&!r;s++){if(Data.dynamic.players.memberships[s].id==n){r=true;document.getElementById(UID[t]).innerHTML=translate("City")+" &nbsp; <B>"+Data.dynamic.players.memberships[s].city+"</b>"+" &nbsp; ("+Data.dynamic.players.memberships[s].x+", "+Data.dynamic.players.memberships[s].y+") &nbsp; <B>"+translate("Distance")+": </b>"+Data.dynamic.players.memberships[s].dist}}}},aM:function(e){var t=Tabs.Alliance;var n=document.getElementById(UID["tabAlliance_AOnOff"]);Data.options.alliance.auto.enabled=e;if(n){if(e){n.value=translate("Enabled").toUpperCase();n.className=UID["btn_on"];if(!t.autoTimer)t.autoTransportTick()}else{if(t.autoTimer)clearTimeout(t.autoTimer);n.value=translate("Disabled").toUpperCase();n.className=UID["btn_off"]}}}};Tabs.Attacks={tabOrder:ATTACK_TAB_ORDER,tabLabel:"Attacks",tabDisabled:!ATTACK_TAB_ENABLE,lastSubTab:"tabAttackLevels",container:null,attackTimer:null,marchTimer:null,lastAttack:0,attackErrors:0,checkMapBusy:false,MAX_DISTANCE:70,curRunStart:0,contentType:0,selectedMapName:"AnthropusCamp",targetTickTimer:0,requestTimer:0,init:function(e){var t=Tabs.Attacks;t.container=e;Data.setDefaultValues("attacks");e.innerHTML=""+"<div id="+bS("tabAttack_Title")+" class="+UID["title"]+">"+translate("Attack")+" "+translate(Data.options.attacks.choice)+" </div>"+"<div class="+UID["status_ticker"]+" id="+bS("tabAttack_Status")+' style="margin-bottom:5px !important">'+'	<center><input type=button value="OnOff" id='+bS("tabAttack_OnOff")+" /></center>"+"	<div id="+bS("tabAttack_Report")+' style="margin-top:5px;height:140px; max-height:140px; width:540px; max-width:540px; overflow:auto;">'+"		<table id="+bS("tabAttack_Marches")+" class="+UID["table"]+"></table>"+"	</div>"+"	<div id="+bS("tabAttack_Feedback")+" class="+UID["status_feedback"]+"></div>"+"</div>"+"<ul class=tabs>"+'	<li class="tab first"><a id='+bS("tabAttackLevels")+">"+translate("Levels")+"</a></li>"+"	<li class=tab><a id="+bS("tabAttackTarget")+">"+translate("Targets")+"</a></li>"+"	<li class=tab><a id="+bS("tabAttackStats")+">"+translate("Statistics")+"</a></li>"+"	<li class=tab><a id="+bS("tabAttackMaps")+">"+translate("Map")+"</a></li>"+"	<li class=tab><a id="+bS("tabAttackConfig")+">"+translate("Config")+"</a></li>"+"</ul>"+"<div id="+bS("tabAttack_Content")+' style="padding-top:0px; height:440px; overflow:auto"></div>';document.getElementById(UID["tabAttack_OnOff"]).addEventListener("click",function(){t.setAttackEnable(!Data.options.attacks.enabled)},false);document.getElementById(UID["tabAttackLevels"]).addEventListener("click",t.tabAttackLevels,false);document.getElementById(UID["tabAttackConfig"]).addEventListener("click",t.tabAttackConfig,false);document.getElementById(UID["tabAttackTarget"]).addEventListener("click",t.tabAttackTarget,false);document.getElementById(UID["tabAttackStats"]).addEventListener("click",t.tabAttackStats,false);document.getElementById(UID["tabAttackMaps"]).addEventListener("click",t.tabAttackMaps,false);if(Data.stats.attacks==null)t.aY();t.contentType=bV(Data.options.attacks.current_tab);setTimeout(Marches.check,6e4);t.tabAttackLevels();window.addEventListener("unload",t.onUnload,false);t.setAttackEnable(Data.options.attacks.enabled)},firstShow:true,show:function(){var e=Tabs.Attacks;e.marchTick();Data.options.attacks.current_tab=e.contentType||Data.options.attacks.current_tab;if(e.contentType==2)document.getElementById(UID["tabAttack_Content"]).scrollTop=gAttScrollPos;switch(e.contentType){case 0:e.tabAttackLevels();break;case 1:e.tabAttackConfig();break;case 2:e.tabAttackTarget();break;case 3:e.tabAttackStats();break;case 4:e.tabAttackMaps();break}},hide:function(){var e=Tabs.Attacks;clearTimeout(e.marchTimer);clearTimeout(e.targetTickTimer)},onUnload:function(){bI("Tabs.Attacks.onUnload");var e=Tabs.Attacks;if(Data.options.attacks.enabled)Data.stats.attacks.run_time+=be()-e.curRunStart;Data.options.attacks.current_tab=e.contentType},checkMapData:function(){var e=Tabs.Attacks;if(e.checkMapBusy){return false}else{var t=Data.options.map.radius=16;var n=Map.getTargets({radius:t});if(n[Data.options.attacks.choice].length!=0||Data.options.attacks.choice=="Fog")return true}return true},gotBattleReport:function(e){var t=Tabs.Attacks,n=false;if(!e)return;var r=null;for(var i in Data.marches.attacks){var s=Data.marches.attacks[i];if(s.general.id===e.report.attacker.general.id){r=i;break}}if(r&&r!=null)t.trackStats(r,e);var o=e.report.spoils.items;if(o.length!==0)Seed.fetchPlayer({noCities:true});if(!Data.options.attacks.delete_reports&&!Data.options.attacks.stop_on_loss)return;if(Data.options.attacks.stop_on_loss&&e.report.attacker.name==Seed.player.name){for(var u in e.report.attacker.units){if(e.report.attacker.units[u][0]!=e.report.attacker.units[u][1]){n=true;var a=(new Date(e.report_notification.created_at*1e3)).myString();t.abort(translate("Troops lost")+"! ("+a+")");return}}}if(Data.options.attacks.delete_reports&&e.report.attacker.name==Seed.player.name&&!n)Messages.deleteMessage(e.report_notification.id)},setAttackEnable:function(e){var t=Tabs.Attacks;clearTimeout(t.attackTimer);var n=document.getElementById(UID["tabAttack_OnOff"]);Data.options.attacks.enabled=e;if(e){Messages.addBattleReportListener(t.gotBattleReport);n.value=translate("Attacking").toUpperCase();n.className=UID["btn_on"];t.curRunStart=be();t.autoCheckTargets()}else{Messages.removeReportListener("attacks",t.gotBattleReport);if(t.curRunStart!=0)Data.stats.attacks.run_time+=be()-t.curRunStart;n.value=translate("Disabled").toUpperCase();n.className=UID["btn_off"];aS(UID["tabAttack_Feedback"],"")}},abort:function(e){function r(e,t){var n="Recall march "+t;aZ(n+" "+translate("attempted"));new MyAjax.marchRecall(e,t,function(e){if(e.ok){aZ(n+" "+translate("succeeded"))}else{aZ(n+" "+translate("failed and returned error")+": "+e.errmsg)}})}var t=Tabs.Attacks;t.setAttackEnable(false);aS(UID["tabAttack_Feedback"],e);aX(e);for(var n in Data.marches.attacks){if(Data.marches.attacks[n].status==="marching")r(Data.marches.attacks[n].city_id,n)}},marchTick:function(){var e=Tabs.Attacks;clearTimeout(e.marchTimer);Marches.updateTable(document.getElementById(UID["tabAttack_Marches"]),"attacks");e.marchTimer=setTimeout(e.marchTick,1e3)},autoCheckTargets:function(){var e=Tabs.Attacks;var t=be();var n=CAPITAL.id;var r,i,s,o,u=0,a;clearTimeout(e.attackTimer);r="";if(!Data.options.attacks.enabled)return;if(!e.checkMapData())return;var f=translate("Attack to ")+r;var l=UID["tabAttack_Feedback"];var c=cK();u=c.count;i=c.delay;s=bB();var h=dB(f,l,u,i,Marches.count.attacks,Data.options.attacks.max_marches,s,true);if(h!=0){e.attackTimer=setTimeout(e.autoCheckTargets,i*1e3);return}var p=e.getNextAttackTarget();if(p){var d=null;if(Data.options.attacks.include_great_dragon[p.l]){if((d=dC(false,Data.options.attacks.except_great_dragon[p.l]))==null){if(!Data.options.attacks.send_without_dragon){bM(f,l,5,false,i);e.attackTimer=setTimeout(e.autoCheckTargets,i*1e3);return}}}o=bb(CAPITAL.id,Data.options.attacks.units[p.l]);if(o==null){e.sendAttack(CAPITAL.id,p,s,d,function(e){var t=Tabs.Attacks,n,r;if(e){var i=bV(Data.options.attacks.delay_min,bK(MIN_DELAY_BETWEEN_WAVE,3));var s=bV(Data.options.attacks.delay_max,bV(i*1.5));n=Math.floor(Math.random()*(s-i+1)+i);t.attackTimer=setTimeout(t.autoCheckTargets,n*1e3)}else{r=30*t.attackErrors*t.attackErrors;if(e.status===429){retry_delay=E429_DELAY;bM(f+" "+translate("failed")+" - <b>API</b> ",l,6,false,r)}else if(e.status===509){retry_delay=600;bM(f+" "+translate("failed")+" - ",l,6,false,r)}t.attackTimer=setTimeout(t.autoCheckTargets,r*1e3)}});return}else{bM(f,l,o,true,i);e.attackTimer=setTimeout(e.autoCheckTargets,i*1e3)}}else{bM(f,l,7,false,i);e.attackTimer=setTimeout(e.autoCheckTargets,i*1e3)}},sendAttack:function(e,t,n,r,i){var s=Tabs.Attacks;var o=be();if(s.attackBusy){aS(UID["tabAttack_Feedback"],translate("Error")+": "+translate("sendAttack is busy, no response from server?"));if(!s.requestTimer)s.requestTimer=setTimeout(function(){Tabs.Attacks.attackBusy=false},1e4);if(i)i(false);return}else if(s.requestTimer)clearTimeout(s.requestTimer);var u=aA(Data.options.attacks.units[t.l]);if(!as(r))u[r]=1;var a=translate("Attack sent to")+": "+translate(Data.options.attacks.choice)+" "+translate("Level")+" "+t.l+" "+translate("at")+" "+t.x+"/"+t.y;aZ(a+" "+translate("attempted"));s.attackBusy=true;s.lastAttack=o;new MyAjax.marchSend(Seed.cities[e].id,t.x,t.y,n.id,u,"attacks",function(e){s.attackBusy=false;if(e.ok&&e.dat.result.success){s.attackErrors=0;aZ(a+" "+translate("Successfully"));if(Data.options.attacks.log_attacks)aX(a);aS(UID["tabAttack_Feedback"],a);var n=t.x+","+t.y;if(!Data.map.coords[n])Data.map.coords[n]={};Data.map.coords[n].la=o;t.la=o;if(i)i(true)}else{s.attackErrors++;aZ(a+" "+translate("failed and returned error")+": "+e.errmsg);aX(a+" "+translate("failed"));aS(UID["tabAttack_Feedback"],a+" "+translate("failed"));if(i)i(false)}})},getNextAttackTarget:function(e){var t=Tabs.Attacks;var n=0;var r=null;var i=null;var s=Data.options.attacks;e=e||s.choice;var o=aA(s.level_enable);for(var u=0;u<o.length;u++){if(o[u]&&bb(CAPITAL.id,Data.options.attacks.units[u])!==null)o[u]=false}var a=t.getActiveObjectList(e,o);a.sort(function(e,t){return e.d-t.d});for(var u=0;u<a.length;u++){i=a[u];var f=Data.map.coords[i.x+","+i.y];if(f&&f.A){if(f.la===0||f.la===null){r=i;break}else if(n===0){n=f.la;r=i}else if(n>f.la){n=f.la;r=i;break}}}if(r===null)return;return r},getActiveObjectList:function(e,t){var n=Tabs.Attacks;t=t!==undefined?t:Data.options.attacks.level_enable;e=e!==undefined?e:Data.options.attacks.choice;var r=0;for(var i=0;i<Data.options.attacks.level_distance.length;i++){if(Data.options.attacks.level_distance[i]>r)r=Data.options.attacks.level_distance[i]}var s=Map.getTargets({radius:r});var o=[];if(s[e]){for(var i=0;i<s[e].length;i++){var u=s[e][i];if(u&&t[u.l]&&(Data.options.attacks.level_distance[u.l]===0||Data.options.attacks.level_distance[u.l]>=u.d)){o.push(u)}}}return o},cA:function(e,t){var n=Tabs.Attacks;var r=Seed.cities[CAPITAL.id].id;var i=CAPITAL.id;var s,o;var u=aA(Data.options.attacks.units[e.l]);o=bb(CAPITAL.id,u);if(o!=null){t(aW(o,"fb"));return}if((s=bB())==null){t(aW(3,"fb"));return}var a=null;if(Data.options.attacks.include_great_dragon[e.l]){if((a=dC(false,Data.options.attacks.except_great_dragon[e.l]))==null){if(!Data.options.attacks.send_without_dragon){t(aW(5,"fb"));return}}if(a&&a!=null)u[a]=1}var f=translate("Manual attack sent to")+": "+translate(Data.options.attacks.choice)+" "+translate("Level")+" "+e.l+" "+translate("at")+" "+e.x+"/"+e.y;aZ(f+" "+translate("attempted"));Messages.addBattleReportListener(n.gotBattleReport);new MyAjax.marchSend(r,e.x,e.y,s.id,u,"attacks",function(r){if(r.ok){aZ(f+" "+translate("Successfully"));if(Data.options.attacks.log_attacks)aX(f);aS(UID["tabAttack_Feedback"],f);var i=e.x+","+e.y;if(!Data.map.coords[i])Data.map.coords[i]={};Data.map.coords[i].la=be();e.la=be();t("OK")}else{aZ(f+" "+translate("failed and returned error")+": "+r.errmsg);aS(UID["tabAttack_Feedback"],translate("Error")+": "+r.errmsg);t(translate("Error")+": "+r.errmsg)}if(!Data.options.attacks.enabled)Messages.removeReportListener("attacks",n.gotBattleReport)})},tabAttackLevels:function(){function c(e){var t=bV(e.target.getAttribute("ref"));Data.options.attacks.level_enable[t]=e.target.checked}function h(t){var n=bV(t.target.getAttribute("ref"));var r=bV(t.target.value);if(isNaN(r)||r<0||r>e.MAX_DISTANCE){t.target.style.backgroundColor="red";eg(translate("Distance must be between")+" 0 "+translate("and")+" "+e.MAX_DISTANCE,e.container)}else{t.target.value=r;t.target.style.backgroundColor="";Data.options.attacks.level_distance[n]=r}}function p(e){var t=bV(e.target.getAttribute("ref"));Data.options.attacks.include_great_dragon[t]=e.target.checked}function d(e){var t=e.target.getAttribute("ref").split("_");Data.options.attacks.except_great_dragon[t[0]][Seed.dragonList[t[1]].type]=e.target.checked}function v(t){var n=t.target.getAttribute("ref").split("_");var r=bV(t.target.value);if(isNaN(r)||r<0||r>2e5){t.target.style.backgroundColor="red";eg(translate("Invalid number of troops",e.container))}else{t.target.value=r;Data.options.attacks.units[n[0]][attack_unit_types[n[1]]]=r;t.target.style.backgroundColor="";if(bV(t.target.value)>0)t.target.style.color="#000"}}var e=Tabs.Attacks;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabAttackLevels"]).className="selected";document.getElementById(UID["tabAttackLevels"]).style.zIndex=1;e.lastSubTab="tabAttackLevels";e.contentType=0;var t=Seed.cities[CAPITAL.id];var n='<div class="'+UID["title"]+'">'+translate("Max ")+translate("Troops")+" "+bD(bV(bJ(CAPITAL.id).max_troops)," ")+"</div>"+"<div id="+bS("tabAAttackLevels_Statbox")+" class="+UID["status_ticker"]+' style="height:410px; max-height:410px; overflow-y:auto; margin-top:1px !important">'+"	<table class="+UID["compact_table"]+" width=100%>"+"		<tr class="+UID["row_top_headers"]+">"+'			<td style="background:none !important;"></td>'+"			<td align=center colspan=11>&nbsp;"+translate("Levels")+"&nbsp;</td>"+"		</tr>"+"		<tr align=center class="+UID["row_headers"]+">"+'			<td width=12% style="background:none !important;"></td>'+"			<td width=8%>1</td>"+"			<td width=8%>2</td>"+"			<td width=8%>3</td>"+"			<td width=8%>4</td>"+"			<td width=8%>5</td>"+"			<td width=8%>6</td>"+"			<td width=8%>7</td>"+"			<td width=8%>8</td>"+"			<td width=8%>9</td>"+"			<td width=8%>10</td>"+"			<td width=8%>11</td>"+"		</tr>"+"		<tr align=center>"+"			<td class=right>"+translate("Enable")+": </td>";for(var r=1;r<12;r++){n+="		<td><label><input type=checkbox id="+bS("tabAttackLevels_LvlOnOff_"+r)+" ref="+r+" "+(Data.options.attacks.level_enable[r]?" checked":"")+" /></label></td>"}n+="		</tr><tr align=center>"+"			<td class=right>"+translate("Max")+" "+translate("Distance").dE(4,"")+": </td>";for(var r=1;r<12;r++){n+="		<td><input type=text id="+bS("tabAttackLevels_LvlDist_"+r)+" ref="+r+' maxlength=2 style="width:37px" value="'+Data.options.attacks.level_distance[r]+'" /></td>'}n+="		</tr><tr>"+"				<td><div class=short></div></td>"+"			</tr>";var i=[];for(var s=0;s<attack_unit_types.length;s++){var o="#FFF";if(s<5)o="#DDD";else if(s<8)o="#BEB";else if(s<10)o="#EEB";else if(s<12)o="#BBE";else if(s<16)o="#EBB";else o="#EBB";n+='<tr style="background-color:'+o+';">'+'		<td class=right><span title="'+translate(attack_unit_types[s])+'">'+translate(Names.getTroopAbbr(attack_unit_types[s]))+":<span></td>";for(var r=1;r<12;r++){var u=Data.options.attacks.units[r][attack_unit_types[s]];if(!u)u=0;n+="<td><input type=text id="+bS("tabAttackLevels_LvlTroops_"+r+"_"+s)+" ref="+(r+"_"+s)+' maxlength=6 size=2 style="width:38px;'+(u?"":"color:#888;")+'" value="'+u+'" title="" /></td>'}n+="</tr>";i.push(s)}n+="<tr>"+"		<td><div class=short></div></td>"+"	</tr>"+"	<tr>"+'		<td style="background:none !important;"></td>'+"		<td align=center colspan=11 align=center>"+"			<table cellpadding=1 cellspacing=1 width=90%>"+"				<tr><td width=40%><hr></td><td>&nbsp &nbsp"+translate("Great dragons")+"&nbsp &nbsp</td><td width=40%><hr></td></tr>"+"			</table></td>"+"	</tr><tr align=center>"+'		<td class=right><span title="'+translate("Include Great Dragon")+'">'+translate("Dragons")+":<span></td>";for(var r=1;r<12;r++){n+="		<td><label><input type=checkbox id="+bS("tabAttackLevels_GreatDrag_"+r)+" ref="+r+" "+(Data.options.attacks.include_great_dragon[r]?" checked":"")+" /></label></td>"}n+="</tr><tr align=center>"+'		<td class=left><span title="'+translate("Check the following great dragons to exclude them from being sent")+'">'+translate("Except")+":<span></td>";+"	</tr>";var a=[];for(var f=0;f<Seed.dragonList.length;f++){var l=Seed.dragonList[f],o="";if(f%2==1)o="#EBB";else o="#ECB";n+='<tr style="background-color:'+o+';">'+'		<td class=right><span title="'+translate(l.type)+'">'+translate(Names.getTroopAbbr(l.type))+":<span></td>";for(var r=1;r<12;r++){n+="<td align=center><input type=checkbox id="+bS("tabAttackLevels_LvlDragons_"+r+"_"+f)+' ref="'+(r+"_"+f)+'" '+(Data.options.attacks.except_great_dragon[r][l.type]?" checked":"")+" /></td>"}n+="</tr>";a.push(f)}n+="</table><div class=short></div></div>";document.getElementById(UID["tabAttack_Content"]).innerHTML=n;for(var r=1;r<12;r++){document.getElementById(UID["tabAttackLevels_LvlOnOff_"+r]).addEventListener("change",c,false);document.getElementById(UID["tabAttackLevels_LvlDist_"+r]).addEventListener("change",h,false);document.getElementById(UID["tabAttackLevels_GreatDrag_"+r]).addEventListener("change",p,false)}for(var s=0;s<i.length;++s){for(var r=1;r<12;r++){document.getElementById(UID["tabAttackLevels_LvlTroops_"+r+"_"+i[s]]).addEventListener("change",v,false)}}for(var f=0;f<a.length;++f){for(var r=1;r<12;r++){document.getElementById(UID["tabAttackLevels_LvlDragons_"+r+"_"+a[f]]).addEventListener("change",d,false)}}},tabAttackConfig:function(){function n(t){var n=bV(document.getElementById(UID["tabAttackConfig_DelayMin"]).value);var r=bV(document.getElementById(UID["tabAttackConfig_DelayMax"]).value);if(n<bK(MIN_DELAY,20)||n>3600||r-n<5){var i=new aw(e.container,300,150,"",true);i.bd().innerHTML="<div class="+UID["title"]+"><center><b>"+scriptName+" : "+translate("Error")+"</b></center></div>";i.getContentDiv().innerHTML="<b>"+translate("Invalid delays")+"</b><br><br>"+translate("First value must be between")+" "+MIN_DELAY+" "+translate("and")+" 3600. "+translate("Second value must be at least")+" 5 "+translate("above the first value");return}Data.options.attacks.delay_min=n;Data.options.attacks.delay_max=r}function r(e){var t=bV(document.getElementById(UID["tabAttackConfig_MaxMarches"]).value);if(t<0||t>Seed.cities[CAPITAL.id].figures.marches.maximum){e.target.style.backgroundColor="red";return}e.target.style.backgroundColor="";Data.options.attacks.max_marches=t}function i(){if(Data.options.attacks.clear_all_targets){for(var e in Map.targets){var t=Map.targets[e];for(var n=0;n<t.length;n++){t[n].la=0;Data.map.coords[t[n].x+","+t[n].y].la=0}}}else{var t=Map.targets[Data.options.attacks.choice];for(var n=0;n<t.length;n++){t[n].la=0;Data.map.coords[t[n].x+","+t[n].y].la=0}}}var e=Tabs.Attacks;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabAttackConfig"]).className="selected";document.getElementById(UID["tabAttackConfig"]).style.zIndex=1;e.lastSubTab="tabAttackConfig";e.contentType=1;var t="<div class="+UID["title"]+">"+translate("Attacks Configuration")+"</div>"+"<div id="+bS("tabAttackConfig_Status")+" class="+UID["status_ticker"]+' style="overflow:auto">'+"	<table class="+UID["table"]+" width=100%>"+"	<tr>"+"		<td width=50% class=right>"+translate("Delay Between Attacks")+":&nbsp;</td>"+"		<td width=50%>"+"		<input class=short id="+bS("tabAttackConfig_DelayMin")+' maxlength=4 type=text value="'+Data.options.attacks.delay_min+'" />&nbsp;'+translate("to")+"		<input class=short id="+bS("tabAttackConfig_DelayMax")+' maxlength=4 type=text value="'+Data.options.attacks.delay_max+'" />&nbsp;'+translate("seconds")+"		</td>"+"	</tr><tr>"+"		<td class=right>"+translate("Delete Battle Reports")+":&nbsp;</td>"+"		<td><input id="+bS("tabAttackConfig_DelAttacks")+" "+(Data.options.attacks.delete_reports?"CHECKED ":"")+" type=checkbox /></td>"+"	</tr><tr>"+"		<td class=right>"+translate("Stop if any troops lost")+":&nbsp;</td>"+"		<td><input id="+bS("tabAttackConfig_StopOnLoss")+" "+(Data.options.attacks.stop_on_loss?"CHECKED ":"")+" type=checkbox /></td>"+"	</tr><tr>"+"		<td class=right>"+translate("Maximum simultaneous marches")+":&nbsp;</td>"+"		<td><input id="+bS("tabAttackConfig_MaxMarches")+' class=short maxlength=2 type=text value="'+Data.options.attacks.max_marches+'" /></td>'+"	</tr><tr>"+"		<td class=right>"+translate("Activate Attacks Logs")+":&nbsp;</td>"+"		<td><input id="+bS("tabAttackConfig_LogAttack")+" "+(Data.options.attacks.log_attacks?"CHECKED ":"")+" type=checkbox /></td>"+"	</tr><tr>"+"		<td class=right>"+translate("Clear last attack on current map")+"&nbsp;</td>"+"		<td><input id="+bS("tabAttackConfig_ClearLast")+'  type=button value="'+translate("Delete")+'" /></td>'+"	</tr><tr>"+"		<td class=right>"+translate("Clear last attack on all maps")+"&nbsp;</td>"+"		<td><input id="+bS("tabAttackConfig_ClearAll")+" "+(Data.options.attacks.clear_all_targets?"CHECKED ":"")+" type=checkbox /></td>"+"	</tr><tr>"+"		<td class=right>"+translate("Send even without Dragon")+":&nbsp;</td>"+"			<td><input id="+bS("tabAttackConfig_SendWithoutDragon")+" type=checkbox "+(Data.options.attacks.send_without_dragon?"CHECKED":"")+" /></td>"+"		</tr>"+"	</tr></table>";document.getElementById(UID["tabAttack_Content"]).innerHTML=t;document.getElementById(UID["tabAttackConfig_DelAttacks"]).addEventListener("change",function(e){Data.options.attacks.delete_reports=e.target.checked},false);document.getElementById(UID["tabAttackConfig_StopOnLoss"]).addEventListener("change",function(e){Data.options.attacks.stop_on_loss=e.target.checked},false);document.getElementById(UID["tabAttackConfig_LogAttack"]).addEventListener("change",function(e){Data.options.attacks.log_attacks=e.target.checked},false);document.getElementById(UID["tabAttackConfig_ClearAll"]).addEventListener("change",function(e){Data.options.attacks.clear_all_targets=e.target.checked},false);document.getElementById(UID["tabAttackConfig_SendWithoutDragon"]).addEventListener("click",function(e){Data.options.attacks.send_without_dragon=e.target.checked},false);document.getElementById(UID["tabAttackConfig_DelayMin"]).addEventListener("change",n,false);document.getElementById(UID["tabAttackConfig_DelayMax"]).addEventListener("change",n,false);document.getElementById(UID["tabAttackConfig_MaxMarches"]).addEventListener("change",r,false);document.getElementById(UID["tabAttackConfig_ClearLast"]).addEventListener("click",i,false)},tabAttackTarget:function(){function m(t){if(e.contentType==2)gAttScrollPos=document.getElementById(UID["tabAttack_Content"]).scrollTop}function g(e){var t=Tabs.Attacks;if(Data.options.attacks.enabled){clearTimeout(t.targetTickTimer);t.setAttackEnable(false);aS(UID["tabAttack_Feedback"],translate("Safe Mode")+": "+translate("Attacks")+" "+translate("Turned Off"))}var n=e.target;Data.options.attacks.choice=Tabs.Attacks.selectedMapName=n.options[n.selectedIndex].value;t.tabAttackTarget()}function y(n){function s(e){if(e!="OK"){i.getContentDiv().innerHTML="<b>"+e+"</b>";i.allowClose(true)}else{i.getContentDiv().innerHTML="<b>"+translate("OK")+"</b>";setTimeout(function(){i.destroy()},1e3)}}var r=bV(n.target.getAttribute("ref"));var i=new aw(e.container,300,150,"",false);i.bd().innerHTML="<div class="+UID["title"]+"><center><b>"+scriptName+" : "+translate("Message")+"</b></center></div>";i.getContentDiv().innerHTML=translate("Attacking");e.cA(t[r],s)}function b(n){var r=bV(n.target.getAttribute("ref"));dJ(e.container,t[r])}function w(e){var n=bV(e.target.getAttribute("ref"));t[n].A=!t[n].A;bG(document.getElementById(UID["tabAttackTarget_AttackNow_"+n]),t[n].A,"btn_green","btn_red");bG(document.getElementById(UID["tabAttackTarget_SpyNow_"+n]),t[n].A,"btn_green","btn_red")}function E(n){var r=bV(n.target.getAttribute("ref"));var i="";if(Data.options.attacks.choice=="City"||Data.options.attacks.choice=="Outpost"||Data.options.attacks.choice=="Wildernesses"){i=translate(Map.names.type[t[r].t])+" "+t[r].n+"  ("+bD(t[r].m)+")"+(t[r].a!=undefined?" / "+t[r].a:"")}else{i=translate(Data.options.attacks.choice)+" "+translate("Level")+" "+t[r].l}dj(e.container,t[r].x,t[r].y,i,t[r].l,t[r].id,t[r].n,Data.options.attacks.units[t[r].l],t[r].ai,Data.options.attacks.include_great_dragon[t[r].l],false,Data.options.attacks.except_great_dragon[t[r].l])}function S(){var n=be();var r;clearTimeout(e.targetTickTimer);if(!document.getElementById(UID["tabAttackTarget_Tab"]))return;for(var i=0;i<t.length;i++){var s=document.getElementById(UID["tabAttackTarget_List_"+i]);if(s==undefined)continue;if(as(t[i].la))r="---";else{var o=n-t[i].la;if(o>3600)r="<font color=#550000><b>"+bE(o,false)+"</b></font>";else r=bE(o,false)}s.innerHTML=r}e.targetTickTimer=setTimeout(S,5e3)}var e=Tabs.Attacks;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabAttackTarget"]).className="selected";document.getElementById(UID["tabAttackTarget"]).style.zIndex=1;e.lastSubTab="tabAttackTarget";e.contentType=2;clearTimeout(e.targetTickTimer);e.checkMapData();var t=e.getActiveObjectList();if(t.length==0)aS(UID["tabAttack_Feedback"],translate("Use the Levels Tab to select attack areas"));t.sort(function(e,t){return e.d-t.d});document.getElementById(UID["tabAttack_Title"]).innerHTML=translate("Attack")+" "+translate(Data.options.attacks.choice);var n="<div class="+UID["title"]+">"+translate("Attacks")+"&nbsp;"+translate(Data.options.attacks.choice)+"</div>";bS("tabAttackTarget_MapChoice");n+="<div id="+bS("tabAAttackTarget_Statbox")+" class="+UID["status_ticker"]+' style="height:390px; max-height:390px">';n+="<table><tr>"+"<td align=right>"+"&nbsp;<b>"+translate("Select")+" "+translate("Targets")+"</b>"+"</td>"+"<td>"+":&nbsp;<select id="+UID["tabAttackTarget_MapChoice"]+">";for(var r in Map.targets){switch(r){case"City":case"Outpost":case"AnthropusCamp":n+='<option value="'+r+'" '+(r==Data.options.attacks.choice?"selected":"")+">"+translate(r)+"</option>";break;default:break}}n+="</select>&nbsp;"+"</td>"+"<td>"+"<span class=jewel>"+t.length+" "+translate("of")+" "+Map.targets[Data.options.attacks.choice].length+"</span>"+"</td>"+"</tr></table><br>";n+='<div class="'+UID["scrollable"]+'" style="height:350px; width:530px; max-width:530px; overflow:auto; white-space:nowrap;">'+"<table id="+bS("tabAttackTarget_Tab")+" class="+UID["row_style"]+">"+"	<tr class="+UID["row_headers"]+">"+'		<td valign=middle width="20px"><b>'+translate("Distance").substring(0,4)+"</b></td>"+'		<td valign=middle width="20px"><b>'+translate("Time")+"</b></td>"+'		<td valign=middle width="30px"><b>'+translate("Coords")+"</b></td>"+'		<td valign=middle width="15px"><b>'+translate("Level")+" </b></td>"+'		<td valign=middle width="80px"><b>'+translate("Last attack")+"</b></td>"+'		<td colspan=3 style="background:none"></td>'+"</tr>";var i=Seed.player.player_wildernesses,s=false,o=[];for(var u=0;u<t.length;u++){n+="<tr id="+bS("tabAttackTarget_TabRow_"+u);if(Data.options.attacks.choice=="City"||Data.options.attacks.choice=="Outpost"||Data.options.attacks.choice=="Wildernesses"){n+='  title="'+t[u].cn+"  ("+translate(Map.names.type[t[u].t])+") \n"+(t[u].n||"????")+" (lvl "+t[u].pl+") - Pwr: "+t[u].m+" \n"+translate("Alliance")+": "+(t[u].a||"---")+'"'}var a=ba(t[u].x,t[u].y,Data.options.attacks.units[t[u].l]);n+=">"+"<td>"+t[u].d+"</td>"+"<td>"+bz(a)+"</td>"+"<td align=center>"+t[u].x+"/"+t[u].y+"</td>"+"<td align=center>"+t[u].l+"</td>"+"<td><span id="+bS("tabAttackTarget_List_"+u)+"> --- </span></td>"+"<td>";n+="<input id="+bS("tabAttackTarget_AttackNow_"+u)+" ref="+u+' class="'+UID["btn_red"]+'" style="width:auto !important;" type=button value="  '+translate("Attack")+' !  "/>'+"&nbsp;&nbsp;<input id="+bS("tabAttackTarget_SpyNow_"+u)+" ref="+u+' class="'+UID["btn_red"]+'" style="width:auto !important;" type=button value="  '+translate("Spy")+' !  " />'+"&nbsp;&nbsp;<input id="+bS("tabAttackTarget_Bookmark_"+u)+" ref="+u+' class="'+UID["btn_blue"]+'" style="width:auto !important;" type=button value=" '+translate("Bookmark")+' " />';if(t[u].id&&t[u].id!=""&&t[u].n&&t[u].n!=""){var f=t[u].id+"_"+t[u].n;var l=bS("tabAttackTarget_Msg_"+u);n+="	&nbsp;<input id="+l+" ref="+f+' class="'+UID["btn_blue"]+'" style="width:auto !important;" type=submit value="'+translate("Msg")+'" />';o.push(l)}if(Data.options.attacks.choice=="City"||Data.options.attacks.choice=="Outpost"||Data.options.attacks.choice=="Wildernesses"){if(!t[u].bk||t[u].bk==0){n+="&nbsp;&nbsp;</td><td><input id="+bS("tabAttackTarget_SkipAttack_"+u)+" ref="+u+" type=checkbox "+(t[u].A?"CHECKED":"")+" /></td>"+"<td><b>"+(t[u].n||"????").dE(13).replace("...","<span class=jewel>...</span>")+"</b></td>"+"<td>"+(t[u].a||"---").dE(16).replace("...","<span class=jewel>...</span>")}}n+="</td></tr>"}n+="</table></div>";document.getElementById(UID["tabAttack_Content"]).innerHTML=n;document.getElementById(UID["tabAttack_Content"]).scrollTop=gAttScrollPos;for(var u=0;u<t.length;u++){for(var c=0;c<i.length;c++){if(i[c].x==t[u].x&&i[c].y==t[u].y){document.getElementById(UID["tabAttackTarget_TabRow_"+u]).className=UID["row_owned"];t[u].A=false;break}}}document.getElementById(UID["tabAttack_Content"]).addEventListener("scroll",m,false);document.getElementById(UID["tabAttackTarget_MapChoice"]).addEventListener("change",g,false);for(var u=0;u<t.length;u++){var h=document.getElementById(UID["tabAttackTarget_AttackNow_"+u]);h.addEventListener("click",y,false);var p=document.getElementById(UID["tabAttackTarget_SpyNow_"+u]);p.addEventListener("click",b,false);var d=document.getElementById(UID["tabAttackTarget_Bookmark_"+u]);d.addEventListener("click",E,false);if(e.selectedMapName=="City"||e.selectedMapName=="Outpost"||e.selectedMapName=="Wildernesses"){if(!t[u].bk||t[u].bk==0)document.getElementById(UID["tabAttackTarget_SkipAttack_"+u]).addEventListener("click",w,false)}bG(h,t[u].A,"btn_green","btn_red");bG(p,t[u].A,"btn_green","btn_red");bG(d,t[u].A)}for(var v=0;v<o.length;v++)$(o[v]).addEventListener("click",bF,false);S()},tabAttackStats:function(){var e=Tabs.Attacks;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabAttackStats"]).className="selected";document.getElementById(UID["tabAttackStats"]).style.zIndex=1;e.lastSubTab="tabAttackStats";e.contentType=3;var t="<div class="+UID["title"]+">"+translate("Attacks Stats")+"</div>"+"<div id="+bS("tabAttackStats_Statbox")+" class="+UID["status_ticker"]+">"+"<div id="+bS("tabAttackStats_Status")+"></div>"+"<div id="+bS("tabAttackStats_Percent")+"></div>"+"<br/>"+"<center><input id="+bS("tabAttackStats_Clear")+' type=button value="'+translate("Clear Stats")+'" /></center>'+"<br></div>";document.getElementById(UID["tabAttack_Content"]).innerHTML=t;document.getElementById(UID["tabAttackStats_Clear"]).addEventListener("click",function(){e.aY();e.bL()},false);e.bL()},aY:function(){var e=Tabs.Attacks;var t=be();Data.stats.attacks={start_at:t,run_time:0,total_attacks:0,loss:{},items:{},resources:{},by_level:[]};e.curRunStart=t;for(var n=0;n<12;n++){Data.stats.attacks.by_level[n]={total_attacks:0,items:{},resources:{}}}e.bL()},trackStats:function(e,t){var n=Tabs.Attacks;if(DEBUG_MARCHES)bf("Tabs.Attacks.trackStats: "+e);var r=t.report.location.level;if(r<1||r>12)r=0;if(as(Data.stats.total.total_attacks))Data.stats.total.total_attacks=0;++Data.stats.attacks.total_attacks;++Data.stats.attacks.by_level[r].total_attacks;++Data.stats.total.total_attacks;var i=t.report.spoils.resources;for(var s in i){aF(Data.stats.attacks.resources,s,bV(i[s]),false);aF(Data.stats.attacks.by_level[r].resources,s,bV(i[s]),false);aF(Data.stats.total.resources,s,bV(i[s]),false)}var o=t.report.spoils.kill_items;for(var s in o){aF(Data.stats.attacks.resources,s,bV(o[s]),false);aF(Data.stats.attacks.by_level[r].resources,s,bV(o[s]),false);aF(Data.stats.total.resources,s,bV(o[s]),false)}var u=t.report.spoils.items;for(var a=0;a<u.length;a++){aF(Data.stats.attacks.items,u[a],1,false);aF(Data.stats.attacks.by_level[r].items,u[a],1,false);aF(Data.stats.total.items,u[a],1,true)}for(var s in t.report.attacker.units){if(t.report.attacker.units[s][0]!=t.report.attacker.units[s][1]){var f=bV(t.report.attacker.units[s][0])-bV(t.report.attacker.units[s][1]);aF(Data.stats.attacks.loss,s,f,true);aF(Data.stats.total.loss,s,f,true)}}Data.marches.attacks[e].has_report=true;n.bL()},bL:function(){function c(e){var t={};for(var n=1;n<12;n++){for(var r in Data.stats.attacks.by_level[n][e]){if(!t[r]){t[r]=[];for(var i=1;i<12;i++){t[r][i]=0}}t[r][n]+=Data.stats.attacks.by_level[n][e][r]}}return t}var e=document.getElementById(UID["tabAttackStats_Status"]);var t=Tabs.Attacks;if(e==null)return;var n=Data.stats.attacks.run_time;if(Data.options.attacks.enabled)n+=be()-t.curRunStart;var r=n>0?n/3600:1;var s="<table class="+UID["table"]+">"+"	<tr>"+"		<td class=right>"+translate("Start Date")+": </td>"+"		<td>"+(new Date(Data.stats.attacks.start_at*1e3)).myString()+"</td>"+"	</tr><tr>"+"		<td class=right>"+translate("Run Time")+": </td>"+"		<td>"+bE(n,true)+"</td>"+"	</tr><tr>"+"		<td class=right>"+translate("Attacks")+": </td>"+"		<td>"+Data.stats.attacks.total_attacks+"</td>"+"	<tr valign=top align=right>"+"		<td class=right>"+translate("Troops lost")+": </td>";var o=true;for(var u in Data.stats.attacks.loss){var a=Math.round(Data.stats.attacks.loss[u]/r);if(o)o=false;else s+="	<tr align=right><td></td>";s+="		<td>"+translate(u)+":</td>"+"		<td>"+bD(Data.stats.attacks.loss[u]," ")+"</td>"+"		<td>("+bD(a," ")+" /"+translate("h")+")</td>"+"	</tr>"}s+="	</tr><tr valign=top>"+"		<td class=right>"+translate("Resources")+": </td>"+"		<td>"+"			<table class="+UID["table"]+">";for(var u in Data.stats.attacks.resources){var a=Math.round(Data.stats.attacks.resources[u]/r);s+="	<tr align=right>"+"			<td>"+translate(u)+":</td>"+"			<td>"+bD(Data.stats.attacks.resources[u]," ")+"</td>"+"			<td>("+bD(a," ")+" /"+translate("h")+")</td>"+"		</tr>"}s+="		</table>"+"		</td>"+"</tr></table>"+"<br><div class="+UID["subtitle"]+">"+translate("Statistics")+"&nbsp;"+translate("of")+"&nbsp;"+translate("Attack")+" "+translate("and")+" "+translate("Items")+"</div>"+'<div style="overflow:auto">'+"	<table class="+UID["table"]+" width=100%>"+"		<tr class="+UID["row_top_headers"]+" align=center>"+'			<td style="background:none !important;"></td>'+'			<td align=right colspan=11 width="440px">'+translate("Levels")+"</td>"+"		</tr><tr align=right class="+UID["row_headers"]+">"+'			<td style="background:none !important;"></td>';for(i=1;i<12;i++){s+='	<td width="40px">'+i+"</td>"}s+="	</tr><tr>"+"			<td colspan=12><HR class=thin></td>"+"		</tr><tr align=right>"+"			<td class=right># "+translate("Attacks")+":</td>";for(i=1;i<12;i++){s+="	<td>"+Data.stats.attacks.by_level[i].total_attacks+"</td>"}s+="	</tr><tr>"+"			<td colspan=12><HR class=thin></td>"+"		</tr>";var f=c("items");for(var l in f){s+="<tr align=right>"+'		<td class=right style="white-space:normal">'+translate(l)+":</td>";for(i=1;i<12;i++){s+="<td>"+f[l][i]+"<br>"+(Data.stats.attacks.by_level[i].total_attacks==0||f[l][i]==0?"":"("+Math.round(f[l][i]/Data.stats.attacks.by_level[i].total_attacks*100)+"%)")+"</td>"}s+="</tr><tr>"+"		<td colspan=12><HR class=thin></td>"+"	</tr>"}s+="</table></div>";e.innerHTML=s},tabAttackMaps:function(){function i(e){aX("<B>scanMap</B>: begin");var t=Tabs.Attacks;for(var n in Data.map.players){if(Data.map.players[n]&&Data.map.players[n][2]){if(!Data.map.evolution[n])Data.map.evolution[n]={};Data.map.evolution[n].m=Data.map.players[n][2]}}var r=0;iy=0;var i=Data.options.map.x;var s=Data.options.map.y;var o=Data.options.map.radius;if(!e)o=Data.options.map.radius_fast;progressBar.init(800+Math.randRange(1,50),100,300,150,translate("Message"),200,true,t.container);progressBar.start({steps:100,delay:1,byCount:true,title:translate("Scanning map")+"...",stepText:translate("Please wait...")});Map.scanMap({x:i,y:s,radius:o,city_detail:e,force_request:e},function(e){if(e==null){progressBarPop.getContentDiv().innerHTML="<B>"+translate("Bummer, there was an error while scanning the map")+".</B>";progressBarPop.allowClose(true);Tabs.Attacks.checkMapBusy=false;return}if(e.done){aX("<B>scanMap</B>: "+translate("complete"));Tabs.Attacks.checkMapBusy=false;progressBarPop.destroy()}})}var e=Tabs.Attacks;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabAttackMaps"]).className="selected";document.getElementById(UID["tabAttackMaps"]).style.zIndex=1;e.lastSubTab="tabAttackMaps";e.contentType=4;var t="<div class="+UID["subtitle"]+">"+translate("Search")+" "+translate("Location")+"</div>"+"<div id="+bS("tabAttackMaps_Statbox")+" class="+UID["status_ticker"]+' style="overflow:auto; margin-top:1px !important">'+"<b>"+translate("Search Radius")+":</b> "+"	<select id="+bS("tabAttackMaps_Radius")+">";for(var n=8;n<=40;n+=8){t+='		<option value="'+n+'" '+(Data.options.map.radius==n?"selected":"")+">"+n+"</option>"}t+="	<select> "+translate("miles")+".&nbsp;&nbsp;"+"<input id="+bS("tabAttackMaps_Search")+' type=button value="'+translate("Detailed search")+'" />'+"<br><b>"+translate("Search Radius")+":</b> "+"	<select id="+bS("tabAttackMaps_RadiusFast")+">";for(var n=8;n<=72;n+=8){t+='		<option value="'+n+'" '+(Data.options.map.radius_fast==n?"selected":"")+">"+n+"</option>"}t+="	<select> "+translate("miles")+".&nbsp;&nbsp;"+"<input id="+bS("tabAttackMaps_FastSearch")+' type=button value="'+translate("Fast search")+'" />'+"<br><br><br>"+"	<table class="+UID["table"]+">"+"		<tr align=center class="+UID["row_headers"]+">"+"			<td>"+translate("type")+"</td>"+"			<td>"+translate("total")+"</td>"+"		</tr>";for(var r in Map.targets){t+="<tr>"+"	<td>"+translate(r)+"</td>"+"	<td align=right><span class=jewel>"+Map.targets[r].length+"</span></td>"+"</tr>"}t+="</table></div>";document.getElementById(UID["tabAttack_Content"]).innerHTML=t;document.getElementById(UID["tabAttackMaps_Search"]).addEventListener("click",function(){i(true)},false);document.getElementById(UID["tabAttackMaps_FastSearch"]).addEventListener("click",function(){i(false)},false);document.getElementById(UID["tabAttackMaps_Radius"]).addEventListener("change",function(e){var t=e.target;Data.options.map.radius=bV(t.options[t.selectedIndex].value)},false);document.getElementById(UID["tabAttackMaps_RadiusFast"]).addEventListener("change",function(e){var t=e.target;Data.options.map.radius_fast=bV(t.options[t.selectedIndex].value)},false)}};Tabs.Bookmarks={tabOrder:BOOKMARK_TAB_ORDER,tabLabel:"Bookmarks",tabDisabled:!BOOKMARK_TAB_ENABLE,container:null,enabled:false,attackTimer:null,marchTimer:null,lastAttack:0,attackErrors:0,contentType:0,lastSubTab:"tabBookmarksTargets",running:{start_at:0},last_target_idx:-1,current_target_idx:-1,requestTimer:0,init:function(e){var t=Tabs.Bookmarks;Data.setDefaultValues("bookmark");t.container=e;var n=""+"<div class="+UID["title"]+">"+translate("Bookmarks")+"</div>"+"<div id="+bS("tabBookmarks_Status")+" class="+UID["status_ticker"]+' style="margin-bottom:5px !important">'+"	<center><input id="+bS("tabBookmarks_OnOff")+' type=button value="OnOff" /></center>'+"	<div id="+bS("tabBookmarks_Report")+' style="margin-top:5px;height:140px; max-height:140px; width:540px; max-width:540px; overflow:auto;">'+"		<table id="+bS("tabBookmarks_Marches")+" class="+UID["table"]+">"+"		</table>"+"	</div>"+"	<div id="+bS("tabBookmarks_Feedback")+" class="+UID["status_feedback"]+"></div>"+"</div>"+"<ul class=tabs>"+'	<li class="tab first"><a id='+bS("tabBookmarksEdit")+">"+translate("Edit")+"</a></li>"+"	<li class=tab><a id="+bS("tabBookmarksTargets")+">"+translate("Targets")+"</a></li>"+"	<li class=tab><a id="+bS("tabBookmarksStats")+">"+translate("Stats")+"</a></li>"+"	<li class=tab><a id="+bS("tabBookmarksConfig")+">"+translate("Config")+"</a></li>"+"</ul>"+"<div id="+bS("tabBookmarks_Content")+' style="padding-top:0px; height:430px; overflow-y:auto"></div>';t.container.innerHTML=n;document.getElementById(UID["tabBookmarksEdit"]).addEventListener("click",t.tabBookmarksEdit,false);document.getElementById(UID["tabBookmarksTargets"]).addEventListener("click",t.tabBookmarksTargets,false);document.getElementById(UID["tabBookmarksStats"]).addEventListener("click",t.tabBookmarksStats,false);document.getElementById(UID["tabBookmarksConfig"]).addEventListener("click",t.tabBookmarksConfig,false);document.getElementById(UID["tabBookmarks_OnOff"]).addEventListener("click",function(){t.setBookmarksEnable(!Data.options.bookmarks.enabled)},false);window.addEventListener("unload",t.onUnload,false);if(Data.stats.bookmarks==null)t.aY();t.setBookmarksEnable(false);t.contentType=bV(Data.options.bookmarks.current_tab);t.show()},tabBookmarksEdit:function(){function a(t){dJ(e.container,Data.options.bookmarks.new_bookmark)}function f(e){dq("tabBookmarks",Data.options.bookmarks.new_bookmark.units,Data.options.bookmarks.new_bookmark)}function l(e){var t=Tabs.Bookmarks;var n=e.target.name.split("_");if(n[0]=="BW"){var r=wave_unit_types[n[1]];var i=Data.options.bookmarks.new_bookmark.units;i[r]=e.target.value}}function c(){var e=Tabs.Bookmarks;dj(e.container,Data.options.bookmarks.new_bookmark.x,Data.options.bookmarks.new_bookmark.y,Data.options.bookmarks.new_bookmark.type,Data.options.bookmarks.new_bookmark.level,Data.options.bookmarks.new_bookmark.id,Data.options.bookmarks.new_bookmark.n,Data.options.bookmarks.new_bookmark.units,Data.options.bookmarks.new_bookmark.ai,Data.options.bookmarks.new_bookmark.include_great_dragon,true,Data.options.bookmarks.new_bookmark.dragons,Data.options.bookmarks.new_bookmark.comment);e.tabBookmarksTargets()}var e=Tabs.Bookmarks;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabBookmarksEdit"]).className="selected";document.getElementById(UID["tabBookmarksEdit"]).style.zIndex=1;e.lastSubTab="tabBookmarksEdit";e.contentType=0;var t='<div class="'+UID["title"]+'">'+translate("Edit bookmark")+"</div>"+"<div class="+UID["content"]+">"+"	<div>"+"		<b>"+translate("Coords")+":&nbsp;</b>&nbsp;"+"		X: <input id="+bS("tabBookmarks_CoordsX")+' size=1 maxlength=3 type=text value="'+Data.options.bookmarks.new_bookmark.x+'" /> '+"		Y: <input id="+bS("tabBookmarks_CoordsY")+' size=2 maxlength=3 type=text value="'+Data.options.bookmarks.new_bookmark.y+'" /> '+"		&nbsp <b>"+translate("Distance")+":</b> <span id="+bS("tabBookmarks_Distance")+"></span>"+"		&nbsp <input id="+bS("tabBookmarks_Spy")+' class="'+UID["btn_green"]+' small" style="width:auto !important;" type=submit value=" '+translate("Spy")+' " />'+"		&nbsp <input id="+bS("tabBookmarks_Save")+' class="'+UID["btn_green"]+' small" style="width:auto !important;" type=submit value=" '+translate("Save")+' " />';if(Data.options.bookmarks.new_bookmark.id&&Data.options.bookmarks.new_bookmark.id!=""&&Data.options.bookmarks.new_bookmark.n&&Data.options.bookmarks.new_bookmark.n!=""){var n=Data.options.bookmarks.new_bookmark.id+"_"+Data.options.bookmarks.new_bookmark.n;t+="	&nbsp <input id="+bS("tabBookmarks_Msg")+" ref="+n+' class="'+UID["btn_blue"]+' small" style="width:auto !important;" type=submit value=" '+translate("Msg")+' " />'}t+="	<br><br><label>"+translate("description")+" :</label>&nbsp"+"		<textarea id="+bS("tabBookmarks_Comment")+' cols="80" rows="2" wrap="PHYSICAL">'+Data.options.bookmarks.new_bookmark.comment+"</textarea><br>"+"		<div class="+UID["status_ticker"]+' style="height:auto !important;margin:5px 10px !important;">'+"			<center><span id="+bS("tabBookmarks_Tile")+"></span></center>"+"		</div>"+"	</div>"+"  <div>"+"	<table id="+bS("tabBookmarks_Troops")+" class="+UID["table"]+" width=100%>"+"		<tr align=center class="+UID["row_headers"]+">"+"			<td colspan=10>"+translate("Troops for Bookmarks Attack")+":&nbsp;</td>"+"		</tr>"+"	</table>"+"	</div><br>"+"  <div>"+"	<table id="+bS("tabBookmarks_Dragons")+" class="+UID["table"]+" width=100%>"+"		<tr align=center class="+UID["row_headers"]+">"+"			<td colspan=10>"+translate("Include Great Dragon")+":&nbsp;</td>";var r=[];for(var i=0;i<Seed.dragonList.length;i++){var s=Seed.dragonList[i];if(i%5==0)t+="</tr><tr>";t+='	<td class=right><span title="'+translate(s.type)+'">'+translate(Names.getTroopAbbr(s.type))+":<span></td>"+"	<td align=center><input type=checkbox id="+bS("tabBookmarks_Dragons_"+i)+" ref="+i+" "+(Data.options.bookmarks.new_bookmark.dragons[s.type]?" checked":"")+" /></td>";r.push(i)}t+="</tr>"+"	</table>"+"	</div>"+"</div>";document.getElementById(UID["tabBookmarks_Content"]).innerHTML=t;document.getElementById(UID["tabBookmarks_CoordsX"]).addEventListener("change",f,false);document.getElementById(UID["tabBookmarks_CoordsY"]).addEventListener("change",f,false);document.getElementById(UID["tabBookmarks_Comment"]).addEventListener("change",function(){Data.options.bookmarks.new_bookmark.comment=document.getElementById(UID["tabBookmarks_Comment"]).value},false);document.getElementById(UID["tabBookmarks_Save"]).addEventListener("click",c,false);if(Data.options.bookmarks.new_bookmark.id&&Data.options.bookmarks.new_bookmark.id!=""&&Data.options.bookmarks.new_bookmark.n&&Data.options.bookmarks.new_bookmark.n!="")document.getElementById(UID["tabBookmarks_Msg"]).addEventListener("click",bF,false);du(document.getElementById(UID["tabBookmarks_Troops"]),1,"BW",wave_unit_types,Data.options.bookmarks.new_bookmark.units,undefined,l,true);for(var i=0;i<r.length;++i){document.getElementById(UID["tabBookmarks_Dragons_"+r[i]]).addEventListener("change",function(e){var t=e.target.getAttribute("ref");Data.options.bookmarks.new_bookmark.dragons[Seed.dragonList[t[0]].type]=e.target.checked;var n=false;for(var r=0;r<Seed.dragonList.length&&!n;r++){var i=Seed.dragonList[r];if(Data.options.bookmarks.new_bookmark.dragons[i.type])n=true}if(n)Data.options.bookmarks.new_bookmark.include_great_dragon=true;else Data.options.bookmarks.new_bookmark.include_great_dragon=false},false)}f();var o=document.getElementById(UID["tabBookmarks_Spy"]);o.addEventListener("click",a,false);var u=Data.options.bookmarks.new_bookmark;if(!u.ai||u.ai==0||u.ai==null||u.ai!=(Seed.player.alliance?Seed.player.alliance.id:-1))bG(o,true,"btn_green","btn_disabled");else bG(o,false,"btn_green","btn_disabled")},tabBookmarksTargets:function(){function b(t){var n=bV(t.target.getAttribute("ref"));dJ(e.container,Data.options.bookmarks.targets[n])}function w(t){var n=bV(t.target.getAttribute("ref"));Data.options.bookmarks.new_bookmark.x=Data.options.bookmarks.targets[n].x;Data.options.bookmarks.new_bookmark.y=Data.options.bookmarks.targets[n].y;Data.options.bookmarks.new_bookmark.type=Data.options.bookmarks.targets[n].type;Data.options.bookmarks.new_bookmark.level=Data.options.bookmarks.targets[n].level;Data.options.bookmarks.new_bookmark.id=Data.options.bookmarks.targets[n].id;Data.options.bookmarks.new_bookmark.n=Data.options.bookmarks.targets[n].n;Data.options.bookmarks.new_bookmark.ai=Data.options.bookmarks.targets[n].ai;Data.options.bookmarks.new_bookmark.units=aA(Data.options.bookmarks.targets[n].units);Data.options.bookmarks.new_bookmark.dragons=aA(Data.options.bookmarks.targets[n].dragons);Data.options.bookmarks.new_bookmark.include_great_dragon=Data.options.bookmarks.targets[n].inc;Data.options.bookmarks.new_bookmark.comment=Data.options.bookmarks.targets[n].comment;e.tabBookmarksEdit()}function E(t){var n=bV(t.target.getAttribute("ref"));Data.options.bookmarks.targets.splice(n,1);e.tabBookmarksTargets()}function S(e){var t=e.target.getAttribute("ref");Data.options.bookmarks.targets[t].enabled=e.target.checked}function x(e){var t=Tabs.Bookmarks;t.last_target_idx=-1;if(Data.options.bookmarks.enabled){clearTimeout(t.attackTimer);t.setBookmarksEnable(false);aS(UID["tabBookmarks_Feedback"],translate("Safe Mode")+": "+translate("Attacks")+" "+translate("Turned Off"))}for(var n=0;n<Data.options.bookmarks.targets.length;n++){Data.options.bookmarks.targets[n].d=bu(Seed.cities[CAPITAL.id].x,Seed.cities[CAPITAL.id].y,Data.options.bookmarks.targets[n].x,Data.options.bookmarks.targets[n].y);Data.options.bookmarks.targets[n].ti=ba(Data.options.bookmarks.targets[n].x,Data.options.bookmarks.targets[n].y,Data.options.bookmarks.targets[n].units)}var r=e.target;Data.options.bookmarks.sort=bV(r.options[r.selectedIndex].value);switch(Data.options.bookmarks.sort){case 1:Data.options.bookmarks.targets.sort(function(e,t){return t.d-e.d});break;case 2:Data.options.bookmarks.targets.sort(function(e,t){return t.ti-e.ti});break;default:Data.options.bookmarks.targets.sort(function(e,t){return e.d-t.d});break}t.tabBookmarksTargets()}function T(e){var t=Tabs.Bookmarks;t.last_target_idx=-1;if(Data.options.bookmarks.enabled){clearTimeout(t.attackTimer);t.setBookmarksEnable(false);aS(UID["tabBookmarks_Feedback"],translate("Safe Mode")+": "+translate("Attacks")+" "+translate("Turned Off"))}var n=e.target;Data.options.bookmarks.choice=bV(n.options[n.selectedIndex].value);t.tabBookmarksTargets()}function N(){var e=be();var n;clearTimeout(t);if(!document.getElementById(UID["tabBookmarksTargets_Tab"]))return;for(var r=0;r<Data.options.bookmarks.targets.length;r++){var i=document.getElementById(UID["tabBookmarksTargets_Last_"+r]);if(i==undefined)continue;if(as(Data.options.bookmarks.targets[r].last_attack))n="---";else{var s=e-Data.options.bookmarks.targets[r].last_attack;if(s>3600)n="<font color=#550000><b>"+bE(s,false)+"</b></font>";else n=bE(s,false)}i.innerHTML=n}t=setTimeout(N,5e3)}var e=Tabs.Bookmarks;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabBookmarksTargets"]).className="selected";document.getElementById(UID["tabBookmarksTargets"]).style.zIndex=1;e.lastSubTab="tabBookmarksTargets";e.contentType=1;var t=null;var n='<div class="'+UID["title"]+'">'+translate("Targets")+"</div>"+"	<div id="+bS("tabBookmarksTargets_TargetsList")+" class="+UID["status_ticker"]+' style="height:380px; max-height:380px; width:540px; max-width:540px; overflow:auto ; margin-top:1px !important"></div>'+"	</div>";document.getElementById(UID["tabBookmarks_Content"]).innerHTML=n;bS("tabBookmarks_TypeChoice");bS("tabBookmarks_SortChoice");var n="<table><tr>"+"<td align=right>&nbsp;<b>"+translate("Select")+" "+translate("Targets")+"</b></td>"+"<td>:&nbsp;<select id="+UID["tabBookmarks_TypeChoice"]+">"+'	<option value="3" '+(Data.options.bookmarks.choice==3?"selected":"")+">"+translate("All")+"</option>"+'	<option value="1" '+(Data.options.bookmarks.choice==1?"selected":"")+">"+translate("AnthropusCamp")+"</option>"+'	<option value="0" '+(Data.options.bookmarks.choice==0?"selected":"")+">"+translate("City")+" / "+translate("Outpost")+"</option>"+'	<option value="2" '+(Data.options.bookmarks.choice==2?"selected":"")+">"+translate("Wildernesses")+"</option>"+"</select>&nbsp;"+"</td>"+"<td align=right>&nbsp;<b>"+translate("Attack")+"</b></td>"+"<td>:&nbsp;<select id="+UID["tabBookmarks_SortChoice"]+">"+'	<option value="0" '+(Data.options.bookmarks.sort==0?"selected":"")+">"+translate("By distance ascending")+"</option>"+'	<option value="1" '+(Data.options.bookmarks.sort==1?"selected":"")+">"+translate("By distance descending")+"</option>"+'	<option value="2" '+(Data.options.bookmarks.sort==2?"selected":"")+">"+translate("Back at the same time")+"</option>"+"</select>&nbsp;"+"</td>"+"</tr></table><br>";var r=[],i=[],s=[],o=0;n+="<table id="+bS("tabBookmarksTargets_Tab")+" class="+UID["row_style"]+' width=100% style="white-space:nowrap">'+"	<tr class="+UID["row_headers"]+">"+"		<td width=9%>"+translate("Enable")+"</td>"+"		<td width=7%>"+translate("Dist")+"</td>"+"		<td width=7%>"+translate("Coords")+"</td>"+'		<td width=25% style="white-space:wrap">'+translate("Target")+"</td>"+'		<td width=25% style="white-space:wrap">'+translate("Troops")+"</td>"+"		<td width=7%>"+translate("GD")+"</td>"+"		<td width=20%>"+translate("Last attack")+"</td>"+"	</tr>";for(var u=0;u<Data.options.bookmarks.targets.length;u++){if(Data.options.bookmarks.choice==3||Data.options.bookmarks.choice==Data.options.bookmarks.targets[u].t){var a=false;for(var f=0;f<Seed.dragonList.length&&!a;f++){var l=Seed.dragonList[f];if(Data.options.bookmarks.targets[u].dragons[l.type])a=true}o++;var c="";if(o%2==1)c='style="background-color:White';else c='style="background-color:rgb(239,239,224)';if(!Data.options.bookmarks.targets[u].comment||Data.options.bookmarks.targets[u].comment==null||Data.options.bookmarks.targets[u].comment=="")c=c+"; border-bottom: 1px solid #898989;";n+="<tr valign=top "+c+'">'+"	<td><input type=checkbox id="+bS("tabBookmarksTargets_CB_"+u)+" ref="+u+" "+(Data.options.bookmarks.targets[u].enabled?"checked":"")+" /></td>"+"	<td>"+Data.options.bookmarks.targets[u].d+"</td>"+"	<td align=center>"+Data.options.bookmarks.targets[u].x+","+Data.options.bookmarks.targets[u].y+"<br>("+bz(Data.options.bookmarks.targets[u].ti)+")</td>"+"	<td align=left>"+Data.options.bookmarks.targets[u].type+"</td>"+"	<td align=left>"+cq(Data.options.bookmarks.targets[u].units,"<br>")+"</td>"+"	<td align=center>"+(a?"Y":"")+"</td>"+"	<td align=left><span id="+bS("tabBookmarksTargets_Last_"+u)+"> --- </span><br>"+"	<input id="+bS("tabBookmarksTargets_Edit_"+u)+" ref="+u+' class="Xtrasmall '+UID["btn_green"]+'" style="width:auto !important;" type=submit value="'+translate("Edit")+'" />&nbsp &nbsp'+"	<input id="+bS("tabBookmarksTargets_Spy_"+u)+" ref="+u+' class="Xtrasmall '+UID["btn_green"]+'" style="width:auto !important;" type=submit value="'+translate("Spy")+'" />&nbsp &nbsp';if(Data.options.bookmarks.targets[u].id&&Data.options.bookmarks.targets[u].id!=""&&Data.options.bookmarks.targets[u].n&&Data.options.bookmarks.targets[u].n!=""){var h=Data.options.bookmarks.targets[u].id+"_"+Data.options.bookmarks.targets[u].n;var p=bS("tabBookmarksTargets_Msg_"+u);n+="	<input id="+p+" ref="+h+' class="Xtrasmall '+UID["btn_blue"]+'" style="width:auto !important;" type=submit value="'+translate("Msg")+'" />&nbsp &nbsp';s.push(p)}n+="	<input id="+bS("tabBookmarksTargets_Delete_"+u)+" ref="+u+' class="Xtrasmall '+UID["btn_red"]+'" style="width:auto !important;" type=submit value=" X " /></td>'+"</tr>";if(Data.options.bookmarks.targets[u].comment&&Data.options.bookmarks.targets[u].comment!=null&&Data.options.bookmarks.targets[u].comment!=""){n+="<tr valign=top "+c+'; border-bottom: 1px solid #898989;">'+"	<td>&nbsp</td><td colspan=5>"+Data.options.bookmarks.targets[u].comment+"</td><td>&nbsp</td></tr>"}r.push(UID["tabBookmarksTargets_CB_"+u]);i.push(u)}}document.getElementById(UID["tabBookmarksTargets_TargetsList"]).innerHTML=n+"</table>";document.getElementById(UID["tabBookmarks_TypeChoice"]).addEventListener("change",T,false);document.getElementById(UID["tabBookmarks_SortChoice"]).addEventListener("change",x,false);for(var u=0;u<r.length;u++){document.getElementById(r[u]).addEventListener("click",S,false);var d=document.getElementById(UID["tabBookmarksTargets_Edit_"+u]);var v=document.getElementById(UID["tabBookmarksTargets_Delete_"+u]);var m=document.getElementById(UID["tabBookmarksTargets_Spy_"+u]);d.addEventListener("click",w,false);v.addEventListener("click",E,false);m.addEventListener("click",b,false);var g=Data.options.bookmarks.targets[i[u]];if(!g.ai||g.ai==0||g.ai==null||g.ai!=(Seed.player.alliance?Seed.player.alliance.id:-1))bG(m,true,"btn_green","btn_disabled");else bG(m,false,"btn_green","btn_disabled")}for(var y=0;y<s.length;y++)document.getElementById(s[y]).addEventListener("click",bF,false);N()},tabBookmarksStats:function(){var e=Tabs.Bookmarks;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabBookmarksStats"]).className="selected";document.getElementById(UID["tabBookmarksStats"]).style.zIndex=1;e.lastSubTab="tabBookmarksStats";e.contentType=2;var t="<div class="+UID["title"]+">"+translate("Attacks Stats")+"</div>"+"<div id="+bS("tabBookmarksStats_Statbox")+" class="+UID["status_ticker"]+">"+"<div id="+bS("tabBookmarksStats_Status")+"></div>"+"<div id="+bS("tabBookmarksStats_Percent")+"></div>"+"<br/>"+"<center><input id="+bS("tabBookmarksStats_Clear")+' type=button value="'+translate("Clear Stats")+'" /></center>'+"<br></div>";document.getElementById(UID["tabBookmarks_Content"]).innerHTML=t;document.getElementById(UID["tabBookmarksStats_Clear"]).addEventListener("click",function(){e.aY();e.bL()},false);e.bL()},tabBookmarksConfig:function(){function n(t){var n=bV(document.getElementById(UID["tabBookmarksConfig_DelayMin"]).value);var r=bV(document.getElementById(UID["tabBookmarksConfig_DelayMax"]).value);if(n<MIN_DELAY||n>3600||r-n<3){var i=new aw(e.container,300,150,"",true);i.bd().innerHTML="<div class="+UID["title"]+"><center><b>"+scriptName+" : "+translate("Error")+"</b></center></div>";i.getContentDiv().innerHTML="<b>"+translate("Invalid delays")+"</b><br><br>"+translate("First value must be between")+" "+MIN_DELAY+" "+translate("and")+" 3600. "+translate("Second value must be at least")+" 5 "+translate("above the first value");return}Data.options.bookmarks.delay_min=n;Data.options.bookmarks.delay_max=r}function r(e){var t=bV(document.getElementById(UID["tabBookmarksConfig_MaxMarches"]).value);if(t<0||t>Seed.cities[CAPITAL.id].figures.marches.maximum){e.target.style.backgroundColor="red";return}e.target.style.backgroundColor="";Data.options.bookmarks.max_marches=t}var e=Tabs.Bookmarks;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabBookmarksConfig"]).className="selected";document.getElementById(UID["tabBookmarksConfig"]).style.zIndex=1;e.lastSubTab="tabBookmarksConfig";e.contentType=3;var t="<div class="+UID["title"]+">"+translate("Bookmarks Configuration")+"</div>"+"<div id="+bS("tabBookmarksConfig_Status")+" class="+UID["status_ticker"]+' style="overflow:auto">'+"	<table class="+UID["table"]+" width=100%>"+"	<tr>"+"		<td width=50% class=right>"+translate("Delay Between Attacks")+":&nbsp;</td>"+"		<td width=50%>"+"		<input class=short id="+bS("tabBookmarksConfig_DelayMin")+' maxlength=4 type=text value="'+Data.options.bookmarks.delay_min+'" />&nbsp;'+translate("to")+"		<input class=short id="+bS("tabBookmarksConfig_DelayMax")+' maxlength=4 type=text value="'+Data.options.bookmarks.delay_max+'" />&nbsp;'+translate("seconds")+"		</td>"+"	</tr><tr>"+"		<td class=right>"+translate("Delete Battle Reports")+":&nbsp;</td>"+"		<td><input id="+bS("tabBookmarksConfig_DelAttacks")+" "+(Data.options.bookmarks.delete_reports?"CHECKED ":"")+" type=checkbox /></td>"+"	</tr><tr>"+"		<td class=right>"+translate("Stop if any troops lost")+":&nbsp;</td>"+"		<td><input id="+bS("tabBookmarksConfig_StopOnLoss")+" "+(Data.options.bookmarks.stop_on_loss?"CHECKED ":"")+" type=checkbox /></td>"+"	</tr><tr>"+"		<td class=right>"+translate("Maximum simultaneous marches")+":&nbsp;</td>"+"		<td><input id="+bS("tabBookmarksConfig_MaxMarches")+' class=short maxlength=2 type=text value="'+Data.options.bookmarks.max_marches+'" /></td>'+"	</tr></table>";document.getElementById(UID["tabBookmarks_Content"]).innerHTML=t;document.getElementById(UID["tabBookmarksConfig_DelAttacks"]).addEventListener("change",function(e){Data.options.bookmarks.delete_reports=e.target.checked},false);document.getElementById(UID["tabBookmarksConfig_StopOnLoss"]).addEventListener("change",function(e){Data.options.bookmarks.stop_on_loss=e.target.checked},false);document.getElementById(UID["tabBookmarksConfig_DelayMin"]).addEventListener("change",n,false);document.getElementById(UID["tabBookmarksConfig_DelayMax"]).addEventListener("change",n,false);document.getElementById(UID["tabBookmarksConfig_MaxMarches"]).addEventListener("change",r,false)},autoCheckTargets:function(){var e=Tabs.Bookmarks;var t=be();var n=CAPITAL.id;var r,i,s,o,u=0,a;clearTimeout(e.attackTimer);if(!Data.options.bookmarks.enabled)return;var f=cK();u=f.count;i=f.delay;var l=e.getNextTarget();if(l){var r=l.type+" "+translate("at")+" "+l.x+"/"+l.y;var c=translate("Attack to ")+r;var h=UID["tabBookmarks_Feedback"];s=bB();var p=dB(c,h,u,i,Marches.count.bookmark,Data.options.bookmarks.max_marches,s,true);if(p!=0){e.attackTimer=setTimeout(e.autoCheckTargets,i*1e3);return}var d=null;if(l.inc){if((d=dC(true,l.dragons))==null){bM(c,h,5,false,i);e.attackTimer=setTimeout(e.autoCheckTargets,i*1e3);return}}o=bb(CAPITAL.id,l.units);if(o==null){e.sendAttack(CAPITAL.id,l,s,d,function(e){var t=Tabs.Bookmarks,n,r;if(e){t.last_target_idx=t.current_target_idx;if(Data.options.bookmarks.sort==2){var i=t.getNextTarget();if(i){n=i.st;if(n<5)n=5}else{n=Math.floor(Math.random()*(Data.options.bookmarks.delay_max-Data.options.bookmarks.delay_min+1)+Data.options.bookmarks.delay_min)}}else{n=Math.floor(Math.random()*(Data.options.bookmarks.delay_max-Data.options.bookmarks.delay_min+1)+Data.options.bookmarks.delay_min)}t.attackTimer=setTimeout(t.autoCheckTargets,n*1e3)}else{r=30*t.attackErrors*t.attackErrors;if(e.status===429){retry_delay=E429_DELAY;bM(c+" "+translate("failed")+" - <b>API</b> ",h,6,false,r)}else if(e.status===509){retry_delay=600;bM(c+" "+translate("failed")+" - ",h,6,false,r)}t.attackTimer=setTimeout(t.autoCheckTargets,r*1e3)}});return}else{bM(c,h,o,true,i);e.attackTimer=setTimeout(e.autoCheckTargets,i*1e3)}}else{e.last_target_idx=-1;clearTimeout(e.attackTimer);e.setBookmarksEnable(false);aS(h,translate("Requirements Unmet")+": "+translate("Attacks")+" "+translate("Turned Off"))}},aY:function(){var e=Tabs.Bookmarks;var t=be();Data.stats.bookmarks={start_at:t,run_time:0,total_attacks:0,loss:{},items:{},resources:{}};e.bL()},getNextTarget:function(){var e=Tabs.Bookmarks;var t=Data.options.bookmarks.targets;if(t.length==0)return;var n=bV(e.last_target_idx)+1;if(n>t.length)n=0;var r=false;var i=null;for(var s=n;s<t.length&&!r;s++){if(t[s].enabled&&(Data.options.bookmarks.choice==3||Data.options.bookmarks.choice==t[s].t)){i=t[s];e.current_target_idx=s;r=true}}if(i===null)return;return i},gotBattleReport:function(e){var t=Tabs.Bookmarks,n=false;if(!e)return;var r=null;for(var i in Data.marches.bookmark){var s=Data.marches.bookmark[i];if(s.general.id===e.report.attacker.general.id){r=i;break}}if(r&&r!=null)t.trackStats(r,e);var o=e.report.spoils.items;if(o.length!==0)Seed.fetchPlayer({noCities:true});if(!Data.options.bookmarks.delete_reports&&!Data.options.bookmarks.stop_on_loss)return;if(Data.options.bookmarks.stop_on_loss&&e.report.attacker.name==Seed.player.name){for(var u in e.report.attacker.units){if(e.report.attacker.units[u][0]!=e.report.attacker.units[u][1]){n=true;var a=(new Date(e.report_notification.created_at*1e3)).myString();t.setBookmarksEnable(false);aS(UID["tabBookmarks_Feedback"],translate("Troops lost")+"! ("+a+")");aX(translate("Troops lost")+"! ("+a+")");return}}}if(Data.options.bookmarks.delete_reports&&e.report.attacker.name==Seed.player.name&&!n)Messages.deleteMessage(e.report_notification.id)},initializeTargets:function(){var e=Tabs.Bookmarks;var t=-1;for(var n=0;n<Data.options.bookmarks.targets.length;n++){if(Data.options.bookmarks.sort==2&&Data.options.bookmarks.targets[n].enabled&&(Data.options.bookmarks.choice==3||Data.options.bookmarks.choice==Data.options.bookmarks.targets[n].t)){if(t==-1){Data.options.bookmarks.targets[n].st=0}else{var r=bV(t*2-Data.options.bookmarks.targets[n].ti*2);Data.options.bookmarks.targets[n].st=r}t=Data.options.bookmarks.targets[n].ti}else{Data.options.bookmarks.targets[n].st=0}}},marchTick:function(){var e=Tabs.Bookmarks;clearTimeout(e.marchTimer);Marches.updateTable(document.getElementById(UID["tabBookmarks_Marches"]),"bookmark");e.marchTimer=setTimeout(e.marchTick,1e3)},sendAttack:function(e,t,n,r,i){var s=Tabs.Bookmarks;var o=be();if(s.attackBusy){aS(UID["tabBookmarks_Feedback"],translate("Error")+": "+translate("sendAttack is busy, no response from server?"));if(!s.requestTimer)s.requestTimer=setTimeout(function(){Tabs.Bookmarks.attackBusy=false},1e4);if(i)i(false);return}else if(s.requestTimer)clearTimeout(s.requestTimer);var u=aA(t.units);if(!as(r))u[r]=1;var a=translate("Attack sent to")+": "+t.type+" "+translate("at")+" "+t.x+"/"+t.y;aZ(a+" "+translate("attempted"));s.attackBusy=true;s.lastAttack=o;new MyAjax.marchSend(Seed.cities[e].id,t.x,t.y,n.id,u,"bookmark",function(e){s.attackBusy=false;if(e.ok&&e.dat.result.success){s.attackErrors=0;aZ(a+" "+translate("Successfully"));aX(a);aS(UID["tabBookmarks_Feedback"],a);t.last_attack=o;if(i)i(true)}else{s.attackErrors++;aZ(a+" "+translate("failed and returned error")+": "+e.errmsg);aX(a+" "+translate("failed"));aS(UID["tabBookmarks_Feedback"],a+" "+translate("failed"));if(i)i(false)}})},setBookmarksEnable:function(e){var t=Tabs.Bookmarks;var n=document.getElementById(UID["tabBookmarks_OnOff"]);clearTimeout(t.attackTimer);Data.options.bookmarks.enabled=e;if(e){Messages.addBattleReportListener(t.gotBattleReport);n.value=translate("Attacking").toUpperCase();n.className=UID["btn_on"];t.initializeTargets();t.autoCheckTargets();t.running.start_at=be();Data.stats.bookmarks.start_at=be()}else{Messages.removeReportListener("bookmark",t.gotBattleReport);n.value=translate("Disabled").toUpperCase();n.className=UID["btn_off"];if(t.running.start_at!==0)Data.stats.bookmarks.run_time+=be()-t.running.start_at;aS(UID["tabBookmarks_Feedback"],"")}},bL:function(){var e=document.getElementById(UID["tabBookmarksStats_Status"]);var t=Tabs.Bookmarks;if(e==null)return;var n=Data.stats.bookmarks.run_time;if(Data.options.bookmarks.enabled)n+=be()-t.curRunStart;var r=n>0?n/3600:1;var i="<table class="+UID["table"]+">"+"	<tr>"+"		<td class=right>"+translate("Start Date")+": </td>"+"		<td colspan=>"+(new Date(Data.stats.bookmarks.start_at*1e3)).myString()+"</td>"+"	</tr><tr>"+"		<td class=right>"+translate("Run Time")+": </td>"+"		<td>"+bE(n,true)+"</td>"+"	</tr><tr>"+"		<td class=right>"+translate("Attacks")+": </td>"+"		<td>"+Data.stats.bookmarks.total_attacks+"</td>"+"	<tr valign=top align=right>"+"		<td class=right>"+translate("Troops lost")+": </td>";var s=true;for(var o in Data.stats.bookmarks.loss){var u=Math.round(Data.stats.bookmarks.loss[o]/r);if(s)s=false;else i+="	<tr align=right><td></td>";i+="		<td>"+translate(o)+":</td>"+"		<td>"+bD(Data.stats.bookmarks.loss[o]," ")+"</td>"+"		<td>("+bD(u," ")+" /"+translate("h")+")</td>"+"	</tr>"}i+="</tr><tr valign=top align=right>"+"		<td class=right>"+translate("Resources")+": </td>";var s=true;for(var o in Data.stats.bookmarks.resources){var u=Math.round(Data.stats.bookmarks.resources[o]/r);if(s)s=false;else i+="	<tr align=right><td></td>";i+="			<td>"+translate(o)+":</td>"+"			<td>"+bD(Data.stats.bookmarks.resources[o]," ")+"</td>"+"			<td>("+bD(u," ")+" /"+translate("h")+")</td>"+"		</tr>"}i+="<tr valign=top align=right>"+"		<td class=right>"+translate("Items")+": </td>";var a=[];for(var o in Data.stats.bookmarks.items)a.push({desc:translate(o),qty:Data.stats.bookmarks.items[o]});if(a.length>0){a.sort(function(e,t){e=e.desc.toLowerCase();t=t.desc.toLowerCase();if(e>t)return 1;if(e<t)return-1;return 0});for(var f=0;f<a.length;f++){var u=Math.round(a[f].qty/r);if(f>0)i+="<tr align=right><td></td>";i+="		<td>"+a[f].desc+":</td>"+"		<td>"+bD(a[f].qty," ")+"</td>"+"		<td>("+bD(u," ")+" /"+translate("h")+")</td>"+"	</tr>"}}i+="</table>";e.innerHTML=i},trackStats:function(e,t){var n=Tabs.Bookmarks;if(DEBUG_MARCHES)bf("Tabs.Bookmarks.trackStats: "+e);if(as(Data.stats.total.total_attacks))Data.stats.total.total_attacks=0;++Data.stats.bookmarks.total_attacks;++Data.stats.total.total_attacks;var r=t.report.spoils.resources;for(var i in r){aF(Data.stats.bookmarks.resources,i,bV(r[i]),false);aF(Data.stats.total.resources,i,bV(r[i]),false)}var s=t.report.spoils.kill_items;for(var i in s){aF(Data.stats.bookmarks.resources,i,bV(s[i]),false);aF(Data.stats.total.resources,i,bV(s[i]),false)}var o=t.report.spoils.items;for(var u=0;u<o.length;u++){aF(Data.stats.bookmarks.items,o[u],1,true);aF(Data.stats.total.items,o[u],1,true)}for(var i in t.report.attacker.units){if(t.report.attacker.units[i][0]!=t.report.attacker.units[i][1]){var a=bV(t.report.attacker.units[i][0])-bV(t.report.attacker.units[i][1]);aF(Data.stats.bookmarks.loss,i,a,true);aF(Data.stats.total.loss,i,a,true)}}Data.marches.bookmark[e].has_report=true;n.bL()},onUnload:function(){var e=Tabs.Bookmarks;if(Data.options.bookmarks.enabled&&e.running.start_at!=0)Data.stats.bookmarks.run_time+=be()-e.running.start_at;Data.options.bookmarks.current_tab=e.contentType},show:function(){var e=Tabs.Bookmarks;e.marchTick();switch(e.contentType){case 0:e.tabBookmarksEdit();break;case 1:e.tabBookmarksTargets();break;case 2:e.tabBookmarksStats();break;case 3:e.tabBookmarksConfig();break}},hide:function(){var e=Tabs.Bookmarks;clearTimeout(e.marchTimer);Data.options.bookmarks.current_tab=e.contentType}};Tabs.Inbox={tabOrder:INBOX_TAB_ORDER,tabLabel:"Inbox",tabDisabled:!INBOX_TAB_ENABLE,container:null,contentType:MESSAGES_ALL,lastSubTab:"tabInboxAll",report_num:-1,current_message:null,first_get:true,checkMessagesBusy:false,checkMessagesError:false,message_list:[],year:[],month:[],day:[],msDate:[],init:function(e){var t=Tabs.Inbox;t.container=e;var n="<div class="+UID["title"]+">"+translate("Messages")+"</div>"+"<div id="+bS("tabInbox_Status")+' style="margin-bottom:5px !important">'+"	<table width=100%>"+"		<tr>"+'			<td align=center width=25%><input type=button value="'+translate("Retrieve all")+'" id='+bS("tabInbox_Refresh")+" /></td>"+'			<td align=center width=25%><input type=button value="'+translate("Select all")+'" id='+bS("tabInbox_SelectAll")+" /></td>"+'			<td align=center width=25%><input type=button value="'+translate("Unselect all")+'" id='+bS("tabInbox_UnselectAll")+" /></td>"+'			<td align=center width=25%><input type=button value="'+translate("Delete")+'" id='+bS("tabInbox_Delete")+" /></td>"+"		</tr>"+"	</table>"+"</div>"+"<ul class=tabs>"+'	<li class="tab first"><a id='+bS("tabInboxAll")+">"+translate("All")+"</a></li>"+"	<li class=tab><a id="+bS("tabInboxMessages")+">"+translate("Messages")+"</a></li>"+"	<li class=tab><a id="+bS("tabInboxReports")+">"+translate("Reports")+"</a></li>"+"	<li class=tab><a id="+bS("tabInboxDeletion")+">"+translate("Mass deletion")+"</a></li>"+"</ul>"+"<div id="+bS("tabInbox_Content")+' style="padding-top:0px; height:655px; ; max-height:655px; overflow-y:auto"></div>';t.container.innerHTML=n;document.getElementById(UID["tabInbox_Refresh"]).addEventListener("click",t.getAllPages,false);document.getElementById(UID["tabInbox_SelectAll"]).addEventListener("click",function(){t.onSelectAll(true)},false);document.getElementById(UID["tabInbox_UnselectAll"]).addEventListener("click",function(){t.onSelectAll(false)},false);document.getElementById(UID["tabInbox_Delete"]).addEventListener("click",t.deleteSelection,false);document.getElementById(UID["tabInboxAll"]).addEventListener("click",function(){t.tabInboxList(bV(MESSAGES_ALL))},false);document.getElementById(UID["tabInboxMessages"]).addEventListener("click",function(){t.tabInboxList(bV(MESSAGES_ONLY))},false);document.getElementById(UID["tabInboxReports"]).addEventListener("click",function(){t.tabInboxList(bV(REPORTS_ONLY))},false);document.getElementById(UID["tabInboxDeletion"]).addEventListener("click",t.tabInboxDeletion,false);bG(document.getElementById(UID["tabInbox_SelectAll"]),true,"btn_green");bG(document.getElementById(UID["tabInbox_UnselectAll"]),true,"btn_green");bG(document.getElementById(UID["tabInbox_Delete"]),true,"btn_off");window.addEventListener("unload",t.onUnload,false);t.contentType=bV(Data.options.inbox.current_tab,0);t.show()},show:function(){var e=Tabs.Inbox;if(document.getElementById(UID["tabInbox_Refresh"])){if(bV(Messages.total_count)>bV(Messages.known_count))bG(document.getElementById(UID["tabInbox_Refresh"]),true);else bG(document.getElementById(UID["tabInbox_Refresh"]),false)}if(!e.checkMessagesBusy){switch(bV(e.contentType,0)){case 3:e.tabInboxDeletion();break;default:e.tabInboxList(bV(e.contentType,0));break}}else setTimeout(e.show,100)},onUnload:function(){var e=Tabs.Inbox;bI("===============  Tabs.Inbox.onUnload");Data.options.inbox.current_tab=e.contentType},hide:function(){},tabInboxList:function(e){function f(){var e=Tabs.Inbox;if(e.checkMessagesBusy)setTimeout(f,1e3);else c()}function l(e){var t=Tabs.Inbox,n;if(e.target.tagName=="DIV")n=e.target;else{var r=e.target.parentNode;while(r.tagName!="DIV")r=r.parentNode;n=r}var i=n.getAttribute("ref");t.current_message=i;if(as(Messages.details[i].report)&&!t.checkMessagesBusy){t.checkMessagesBusy=true;MyAjax.messageDetail(i,function(e){var t=Tabs.Inbox;t.checkMessagesBusy=false;if(!e)return})}f()}function c(){var e=Tabs.Inbox,t="",n="";var r=Messages.details[e.current_message];var i=r.type;switch(i){case"BattleReport":n=Messages.displayBattleReport(r);break;case"CurseReport":n=Messages.displayCurseReport(r);break;case"Leaderboard::TournamentAwardMessage":n=Messages.displayTournamentAwardMessage(r);break;case"Messages::Breeding":n=Messages.displayBreedingReport(r);break;case"Messages::Hatching":n=Messages.displayHatchingReport(r);break;case"SentinelWarning":n=Messages.displaySentinelReport(r);break;case"SpyReport":n=Messages.displaySpyReport(r);break;case"ReinforcementsReport":n=Messages.displayReinforcement(r);break;case"TradingReport":n=Messages.displayTradingReport(r);break;case"TransportMarchReport":n=Messages.displayTransportReport(r);break;case"ChallengePrizeReport":;case"ContestPrizeReport":n=Messages.displayContestPrizeReport(r);break;case"PlayerMessage":case"AllianceMessage":case"SystemMessage":case"TargetedMessage":n=Messages.fL(r);break;default:alert("Unknown message type "+i+" (message id = "+e.current_message+")")}var s="";if(r.from)s='<input type=button value="'+translate("Reply")+'" id='+bS("MsgDisp_Answer")+" />";else s="&nbsp;";t+="<center><div id="+bS("displayMsg_ReportContent")+' style="height:565px; max-height:565px; width:100%; max-width:100%; overflow-y:auto;">'+n+"</div>"+"<br><table width=90%><tr>"+'	<td align=center width=33%><input type=button value="'+translate("Close")+'" id='+bS("MsgDisp_Close")+" /></td>"+"	<td align=center width=33%>"+s+"</td>"+'	<td align=center width=33%><input type=button value="'+translate("Delete")+'" id='+bS("MsgDisp_Delete")+" /></td>"+"</tr></table></center>";document.getElementById(UID["tabInbox_List"]).innerHTML=t;bG(document.getElementById(UID["MsgDisp_Delete"]),true,"btn_off");document.getElementById(UID["MsgDisp_Close"]).addEventListener("click",function(){e.current_message=null;e.show()},false);if(document.getElementById(UID["MsgDisp_Answer"]))document.getElementById(UID["MsgDisp_Answer"]).addEventListener("click",function(){eH(r.from.name,r.from.id,true)},false);document.getElementById(UID["MsgDisp_Delete"]).addEventListener("click",function(){Messages.deleteSingleMsg(r.id,function(){e.current_message=null;e.show()})},false)}var t=Tabs.Inbox;t.contentType=e;document.getElementById(UID[t.lastSubTab]).className="";document.getElementById(UID[t.lastSubTab]).style.zIndex=0;switch(e){case MESSAGES_ONLY:document.getElementById(UID["tabInboxMessages"]).className="selected";document.getElementById(UID["tabInboxMessages"]).style.zIndex=1;t.lastSubTab="tabInboxMessages";var n=translate("Messages");t.message_list=t.getMessages("messages");break;case REPORTS_ONLY:document.getElementById(UID["tabInboxReports"]).className="selected";document.getElementById(UID["tabInboxReports"]).style.zIndex=1;t.lastSubTab="tabInboxReports";var n=translate("Reports");t.message_list=t.getMessages("reports");break;default:document.getElementById(UID["tabInboxAll"]).className="selected";document.getElementById(UID["tabInboxAll"]).style.zIndex=1;t.lastSubTab="tabInboxAll";var n=translate("All");t.message_list=t.getMessages("all");break}if(t.first_get&&!Data.options.disable_inbox){t.first_get=false;t.refreshFirstPage()}var r="<div id="+bS("tabInbox_ListContent")+' style="height:640px">'+"	<div class="+UID["title"]+">"+n+"</div>"+"	<div id="+bS("tabInbox_List")+" class="+UID["status_ticker"]+' style="height:620px; max-height:620px; overflow:auto; white-space:nowrap; margin-top:1px !important"></div>'+"	</div>";document.getElementById(UID["tabInbox_Content"]).innerHTML=r;var r="<table class="+UID["row_style"]+" width=100%>"+"	<tr class="+UID["row_headers"]+">"+"		<td width=2%>&nbsp</td>"+"		<td width=98%><table width=100%><tr>"+"			<td width=30%>"+translate("Date")+"</td>"+"			<td width=26%>"+translate("From")+"</td>"+"			<td width=44%>"+translate("Subject")+"</td>"+"		</tr></table></td>"+"	</tr>";var i=[],s=[];for(var o=0;o<t.message_list.length;o++){var u="",a="";if(t.message_list[o].unread)var u="font-weight:bold;";if(t.message_list[o].checked)var a="background-color:grey;";r+='<tr style="border-bottom: 1px solid #898989; '+u+a+'">'+"	<td>&nbsp;<input type=checkbox id="+bS("tabInbox_SelectMsg_"+o)+' ref="'+t.message_list[o].id+"_"+o+'" '+(Messages.details[t.message_list[o].id].checked?"checked":"")+" />&nbsp;</td>"+"	<td><a><div id="+bS("tabInbox_ViewMsg_"+o)+' ref="'+t.message_list[o].id+'" style="white-space:pre-wrap;"><table width=100%><tr>'+"		<td width=30%>"+(new Date(t.message_list[o].created_at*1e3)).myString()+"</td>"+"		<td width=26%>"+(t.message_list[o].from==null?"Dragons of Atlantis":t.message_list[o].from.name)+"</td>"+"		<td width=44%>"+t.message_list[o].summary+"</td>"+"	</tr></table></div></a></td>"+"</tr>";i.push(UID["tabInbox_SelectMsg_"+o]);s.push(UID["tabInbox_ViewMsg_"+o])}document.getElementById(UID["tabInbox_List"]).innerHTML=r+"</table>";for(var o=0;o<i.length;o++)document.getElementById(i[o]).addEventListener("click",function(e){var t=e.target.getAttribute("ref").split("_");Messages.details[t[0]].checked=e.target.checked;var n=e.target.parentNode;while(n.tagName!="TR")n=n.parentNode;if(t[1]%2==1)a="rgba(255, 255, 255, 0.0)";else a="rgba(255, 255, 255, 1.0)";n.style.backgroundColor=e.target.checked?"grey":a},false);for(var o=0;o<s.length;o++){document.getElementById(s[o]).addEventListener("click",l,false)}},tabInboxDeletion:function(){function s(e){var t=Tabs.Inbox;var n=document.getElementById(e.target.id);var r=bV(n.value);n.value=r;if(e.target.id==UID["tabOptions_msgType"]){Data.options.messages_delete.type=r;u(true)}else{for(var i=0;i<2;i++){if(e.target.id==UID["tabOptions_DD"+i])t.day[i]=r;else if(e.target.id==UID["tabOptions_DM"+i])t.month[i]=r;else if(e.target.id==UID["tabOptions_DY"+i])t.year[i]=r}}}function o(){for(var e=0;e<2;e++){document.getElementById(UID["tabOptions_DD"+e]).disabled=Data.options.messages_delete.dateAll;document.getElementById(UID["tabOptions_DM"+e]).disabled=Data.options.messages_delete.dateAll;document.getElementById(UID["tabOptions_DY"+e]).disabled=Data.options.messages_delete.dateAll}}function u(e){a(false);l(false);f(Data.options.messages_delete.type!=REPORTS_ONLY,e);c(Data.options.messages_delete.type!=MESSAGES_ONLY,e);if(Data.options.messages_delete.type!=MESSAGES_ALL){a(Data.options.messages_delete.type==REPORTS_ONLY);l(Data.options.messages_delete.type==MESSAGES_ONLY)}}function a(e){document.getElementById(UID["tabOptions_MsgG"]).disabled=e;document.getElementById(UID["tabOptions_MsgP"]).disabled=e;document.getElementById(UID["tabOptions_MsgS"]).disabled=e;document.getElementById(UID["tabOptions_MsgA"]).disabled=e}function f(e,t){document.getElementById(UID["tabOptions_MsgG"]).checked=e;document.getElementById(UID["tabOptions_MsgP"]).checked=e;document.getElementById(UID["tabOptions_MsgS"]).checked=e;document.getElementById(UID["tabOptions_MsgA"]).checked=e;if(t){Data.options.messages_delete.msgGame=e;Data.options.messages_delete.msgPlayer=e;Data.options.messages_delete.msgSentinel=e;Data.options.messages_delete.msgAlliance=e}}function l(e){document.getElementById(UID["tabOptions_RepA"]).disabled=e;document.getElementById(UID["tabOptions_RepT"]).disabled=e;document.getElementById(UID["tabOptions_RepS"]).disabled=e;document.getElementById(UID["tabOptions_RepB"]).disabled=e;document.getElementById(UID["tabOptions_RepF"]).disabled=e;document.getElementById(UID["tabOptions_RepC"]).disabled=e;document.getElementById(UID["tabOptions_RepTr"]).disabled=e;document.getElementById(UID["tabOptions_RepDr"]).disabled=e;document.getElementById(UID["tabOptions_ExcM"]).disabled=e;document.getElementById(UID["tabOptions_ExcY"]).disabled=e}function c(e,t){document.getElementById(UID["tabOptions_RepA"]).checked=e;document.getElementById(UID["tabOptions_RepT"]).checked=e;document.getElementById(UID["tabOptions_RepS"]).checked=e;document.getElementById(UID["tabOptions_RepB"]).checked=e;document.getElementById(UID["tabOptions_RepF"]).checked=e;document.getElementById(UID["tabOptions_RepC"]).checked=e;document.getElementById(UID["tabOptions_RepTr"]).checked=e;document.getElementById(UID["tabOptions_RepDr"]).checked=e;document.getElementById(UID["tabOptions_ExcM"]).checked=e;document.getElementById(UID["tabOptions_ExcY"]).checked=e;if(t){Data.options.messages_delete.rptAnthropus=e;Data.options.messages_delete.rptTransport=e;Data.options.messages_delete.rptSpy=e;Data.options.messages_delete.rptBattle=e;Data.options.messages_delete.rptReinforcement=e;Data.options.messages_delete.rptCurse=e;Data.options.messages_delete.rptTrading=e;Data.options.messages_delete.rptBreeding=e;Data.options.messages_delete.rptExceptMyAttacks=e;Data.options.messages_delete.rptExceptYourAttacks=e}}function h(){function s(e,t,n){var r=false;var i;if(t<8&&t%2==1||t>7&&t%2==0)i=31;else if(t!=2)i=30;else if(o(n))i=29;else i=28;if(e>0&&e<i&&t>0&&t<13)r=true;return r}function o(e){var t=false;if(e%4==0){t=true;if(e%100==0&&e%400!=0)t=false}return t}var e=Tabs.Inbox,t=Data.options.messages_delete;if(e.checkMessagesBusy)return false;var n=false;if(t.type!=REPORTS_ONLY&&(t.msgGame||t.msgPlayer||t.msgSentinel||t.msgAlliance))n=true;if(!n&&t.type!=MESSAGES_ONLY&&(t.rptAnthropus||t.rptTransport||t.rptSpy||t.rptBattle||t.rptReinforcement||t.rptCurse||t.rptTrading||t.rptBreeding))n=true;if(!n){var i=new aw(e.container,300,150,"",true);i.bd().innerHTML="<div class="+UID["title"]+"><center><b>"+scriptName+" : "+translate("Error")+"</b></center></div>";i.getContentDiv().innerHTML="<B>"+translate("Select at least one type of message or report to delete")+" !</b>";return}if(!t.dateAll){for(r=0;r<2;r++){if(!s(e.day[r],e.month[r],e.year[r])){var i=new aw(e.container,300,150,"",true);i.bd().innerHTML="<div class="+UID["title"]+"><center><b>"+scriptName+" : "+translate("Error")+"</b></center></div>";i.getContentDiv().innerHTML="<B>"+(r==0?translate("Invalid date From"):translate("Invalid date To"))+'" !</b>';return}e.msDate[r]=Date.parse(new Date(Date.UTC(e.year[r],e.month[r]-1,e.day[r],0,0,0)))/1e3}if(e.msDate[1]<e.msDate[0]){var i=new aw(e.container,300,150,"",true);i.bd().innerHTML="<div class="+UID["title"]+"><center><b>"+scriptName+" : "+translate("Error")+"</b></center></div>";i.getContentDiv().innerHTML="<B>"+translate("Invalid date range")+" !</b>";return}e.msDate[1]+=86400}Messages.messageDeletion=true;e.checkMessagesBusy=true;p(function(){bI(translate("Messages deleted"));Tabs.Inbox.checkMessagesBusy=false;Messages.messageDeletion=false;Tabs.Inbox.show()})}function p(e){function n(t){if(t==null){Tabs.Inbox.checkMessagesError=true;progressBarPop.getContentDiv().innerHTML="<B>"+translate("Error while deleting messages")+"</B>";progressBarPop.allowClose(true);if(e)e(false);return}if(t.done){aX(translate("Deletion of messages")+" "+translate("complete")+". "+t.count+" "+translate("messages deleted"));progressBarPop.getContentDiv().innerHTML="<B>"+t.count+" "+translate("messages deleted")+"</B>";progressBarPop.allowClose(true);if(e)e(true)}}var t=Tabs.Inbox;progressBar.init(800+Math.randRange(1,50),100,300,150,translate("Message"),200,true,t.container);progressBar.start({steps:100,delay:1,byCount:true,title:translate("Message(s) deletion in progress")+"...",stepText:translate("Please wait...")});Messages.dealMessages("del",t.msDate,n)}var e=Tabs.Inbox;e.contentType=3;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabInboxDeletion"]).className="selected";document.getElementById(UID["tabInboxDeletion"]).style.zIndex=1;e.lastSubTab="tabInboxDeletion";var t=new Date;e.year[0]=2010;e.month[0]=10;e.day[0]=1;e.year[1]=t.getFullYear();e.month[1]=t.getMonth()+1;e.day[1]=t.getDate();e.msDate[0]=0;e.msDate[1]=0;var n="<div id="+bS("tabInbox_DelContent")+' style="height:640px">'+"<div class="+UID["title"]+' style="margin-bottom:10px">'+translate("Mass deletion of messages")+"</div>"+"<table class="+UID["table"]+">"+"	<tr valign=top>"+"		<td><b>"+translate("Delete messages of this type")+": </b></td>"+"		<td>"+"		<select id="+bS("tabOptions_msgType")+" size=1>"+"			<option value=0 "+(Data.options.messages_delete.type==MESSAGES_ALL?"selected":"")+">"+translate("All types")+"</option>"+"			<option value=1 "+(Data.options.messages_delete.type==MESSAGES_ONLY?"selected":"")+">"+translate("Messages")+"</option>"+"			<option value=2 "+(Data.options.messages_delete.type==REPORTS_ONLY?"selected":"")+">"+translate("Reports")+"</option>"+"		</select>"+"		</td>"+"	</tr><tr valign=top>"+'		<td  style="font-size:2px">&nbsp</td>'+"	</tr><tr valign=top>"+"		<td><b><i>"+translate("Messages")+": </i></b></td>"+"	</tr><tr valign=top>"+"		<td><label><input id="+bS("tabOptions_MsgG")+" type=checkbox "+(Data.options.messages_delete.msgGame?" CHECKED ":"")+" /> "+translate("Game messages")+"</label></td>"+"		<td><label><input id="+bS("tabOptions_MsgP")+" type=checkbox "+(Data.options.messages_delete.msgPlayer?" CHECKED ":"")+" /> "+translate("Player messages")+"</label></td>"+"	</tr><tr valign=top>"+"		<td><label><input id="+bS("tabOptions_MsgS")+" type=checkbox "+(Data.options.messages_delete.msgSentinel?" CHECKED ":"")+" /> "+translate("Sentinel messages")+"</label></td>"+"		<td><label><input id="+bS("tabOptions_MsgA")+" type=checkbox "+(Data.options.messages_delete.msgAlliance?" CHECKED ":"")+" /> "+translate("Alliance messages")+"</label></td>"+"	</tr><tr valign=top>"+'		<td  style="font-size:2px">&nbsp</td>'+"	</tr><tr valign=top>"+"		<td><b><i>"+translate("Reports")+": </i></b></td>"+"	</tr><tr valign=top>"+"		<td><label><input id="+bS("tabOptions_RepA")+" type=checkbox "+(Data.options.messages_delete.rptAnthropus?" CHECKED ":"")+" /> "+translate("Camps/wilds attack reports")+"</label></td>"+"		<td><label><input id="+bS("tabOptions_RepT")+" type=checkbox "+(Data.options.messages_delete.rtpTransport?" CHECKED ":"")+" /> "+translate("Transport reports")+"</label></td>"+"	</tr><tr valign=top>"+"		<td><label><input id="+bS("tabOptions_RepS")+" type=checkbox "+(Data.options.messages_delete.rptSpy?" CHECKED ":"")+" /> "+translate("Spy reports")+"</label></td>"+"		<td><label><input id="+bS("tabOptions_RepF")+" type=checkbox "+(Data.options.messages_delete.rptReinforcement?" CHECKED ":"")+" /> "+translate("Reinforcement reports")+"</label></td>"+"	</tr><tr valign=top>"+"		<td><label><input id="+bS("tabOptions_RepB")+" type=checkbox "+(Data.options.messages_delete.rptBattle?" CHECKED ":"")+" /> "+translate("Battle notes")+"</label></td>"+"		<td><label><input id="+bS("tabOptions_RepC")+" type=checkbox "+(Data.options.messages_delete.rptCurse?" CHECKED ":"")+" /> "+translate("Curse reports")+"</label></td>"+"	</tr><tr valign=top>"+"		<td><label><input id="+bS("tabOptions_RepTr")+" type=checkbox "+(Data.options.messages_delete.rptTrading?" CHECKED ":"")+" /> "+translate("trading-report")+"</label></td>"+"		<td><label><input id="+bS("tabOptions_RepDr")+" type=checkbox "+(Data.options.messages_delete.rptBreeding?" CHECKED ":"")+" /> "+translate("Sanctuary reports")+"</label></td>"+"	</tr><tr valign=top>"+'		<td  style="font-size:2px">&nbsp</td>'+"	</tr><tr valign=top>"+"		<td><b><i>"+translate("Exception")+": </i></b></td>"+"	</tr><tr valign=top>"+"		<td colspan=2><label><input id="+bS("tabOptions_ExcM")+" type=checkbox "+(Data.options.messages_delete.rptExceptMyAttacks?" CHECKED ":"")+" /> "+translate("Keep battle reports of my attacks on other players")+"</label></td>"+"	</tr><tr valign=top>"+"		<td colspan=2><label><input id="+bS("tabOptions_ExcY")+" type=checkbox "+(Data.options.messages_delete.rptExceptYourAttacks?" CHECKED ":"")+" /> "+translate("Keep battle reports of attacks from other players")+"</label></td>"+"	</tr><tr valign=top>"+'		<td  style="font-size:2px">&nbsp</td>'+"	</tr><tr valign=top>"+"		<td colspan=2><b><i>"+translate("Date range")+": </i></b>&nbsp &nbsp<input id="+bS("tabOptions_ChkD")+" type=checkbox "+(Data.options.messages_delete.dateAll?" CHECKED ":"")+" /> "+translate("All")+"</label></td>"+"	</tr><tr valign=top>";for(var r=0;r<2;r++){n+="<td>"+(r==0?translate("From"):translate("To"))+" : ";n+="<select id="+bS("tabOptions_DD"+r)+" size=1>";for(var i=1;i<32;i++)n+="<option value="+i+(i==e.day[r]?" selected":"")+">"+(i<10?"0":"")+i+"</option>";n+="</select>";n+="<select id="+bS("tabOptions_DM"+r)+" size=1>";for(var i=1;i<13;i++)n+="<option value="+i+(i==e.month[r]?" selected":"")+">"+(i<10?"0":"")+i+"</option>";n+="</select>";n+="<select id="+bS("tabOptions_DY"+r)+" size=1>";for(var i=2010;i<e.year[1]+1;i++)n+="<option value="+i+(i==e.year[r]?" selected":"")+">"+i+"</option>";n+="</select></td>"}n+="</tr><tr valign=top>"+'		<td  style="font-size:2px">&nbsp</td>'+"	</tr><tr valign=top>"+"		<td colspan=2 align=center><br>"+"		<label><input id="+bS("tabOptions_ButDel")+' type=button value="'+translate("Delete now")+'" /></label>'+"		</td>"+"	</tr>"+"</table>"+"</div>";document.getElementById(UID["tabInbox_Content"]).innerHTML=n;document.getElementById(UID["tabOptions_msgType"]).addEventListener("change",s,false);document.getElementById(UID["tabOptions_MsgG"]).addEventListener("click",function(e){Data.options.messages_delete.msgGame=e.target.checked},false);document.getElementById(UID["tabOptions_MsgP"]).addEventListener("click",function(e){Data.options.messages_delete.msgPlayer=e.target.checked},false);document.getElementById(UID["tabOptions_MsgS"]).addEventListener("click",function(e){Data.options.messages_delete.msgSentinel=e.target.checked},false);document.getElementById(UID["tabOptions_MsgA"]).addEventListener("click",function(e){Data.options.messages_delete.msgAlliance=e.target.checked},false);document.getElementById(UID["tabOptions_RepA"]).addEventListener("click",function(e){Data.options.messages_delete.rptAnthropus=e.target.checked},false);document.getElementById(UID["tabOptions_RepT"]).addEventListener("click",function(e){Data.options.messages_delete.rptTransport=e.target.checked},false);document.getElementById(UID["tabOptions_RepS"]).addEventListener("click",function(e){Data.options.messages_delete.rptSpy=e.target.checked},false);document.getElementById(UID["tabOptions_RepB"]).addEventListener("click",function(e){Data.options.messages_delete.rptBattle=e.target.checked},false);document.getElementById(UID["tabOptions_RepF"]).addEventListener("click",function(e){Data.options.messages_delete.rptReinforcement=e.target.checked},false);document.getElementById(UID["tabOptions_RepC"]).addEventListener("click",function(e){Data.options.messages_delete.rptCurse=e.target.checked},false);document.getElementById(UID["tabOptions_RepTr"]).addEventListener("click",function(e){Data.options.messages_delete.rptTrading=e.target.checked},false);document.getElementById(UID["tabOptions_RepDr"]).addEventListener("click",function(e){Data.options.messages_delete.rptBreeding=e.target.checked},false);document.getElementById(UID["tabOptions_ExcM"]).addEventListener("click",function(e){Data.options.messages_delete.rptExceptMyAttacks=e.target.checked},false);document.getElementById(UID["tabOptions_ExcY"]).addEventListener("click",function(e){Data.options.messages_delete.rptExceptYourAttacks=e.target.checked},false);document.getElementById(UID["tabOptions_ChkD"]).addEventListener("click",function(e){Data.options.messages_delete.dateAll=e.target.checked;o()},false);document.getElementById(UID["tabOptions_MsgG"]).addEventListener("change",function(e){Data.options.messages_delete.msgGame=e.target.checked},false);document.getElementById(UID["tabOptions_MsgP"]).addEventListener("change",function(e){Data.options.messages_delete.msgPlayer=e.target.checked},false);document.getElementById(UID["tabOptions_MsgS"]).addEventListener("change",function(e){Data.options.messages_delete.msgSentinel=e.target.checked},false);document.getElementById(UID["tabOptions_MsgA"]).addEventListener("change",function(e){Data.options.messages_delete.msgAlliance=e.target.checked},false);document.getElementById(UID["tabOptions_RepA"]).addEventListener("change",function(e){Data.options.messages_delete.rptAnthropus=e.target.checked},false);document.getElementById(UID["tabOptions_RepT"]).addEventListener("change",function(e){Data.options.messages_delete.rptTransport=e.target.checked},false);document.getElementById(UID["tabOptions_RepS"]).addEventListener("change",function(e){Data.options.messages_delete.rptSpy=e.target.checked},false);document.getElementById(UID["tabOptions_RepB"]).addEventListener("change",function(e){Data.options.messages_delete.rptBattle=e.target.checked},false);document.getElementById(UID["tabOptions_RepF"]).addEventListener("change",function(e){Data.options.messages_delete.rptReinforcement=e.target.checked},false);document.getElementById(UID["tabOptions_RepC"]).addEventListener("change",function(e){Data.options.messages_delete.rptCurse=e.target.checked},false);document.getElementById(UID["tabOptions_RepTr"]).addEventListener("change",function(e){Data.options.messages_delete.rptTrading=e.target.checked},false);document.getElementById(UID["tabOptions_RepDr"]).addEventListener("change",function(e){Data.options.messages_delete.rptBreeding=e.target.checked},false);document.getElementById(UID["tabOptions_ExcM"]).addEventListener("change",function(e){Data.options.messages_delete.rptExceptMyAttacks=e.target.checked},false);document.getElementById(UID["tabOptions_ExcY"]).addEventListener("change",function(e){Data.options.messages_delete.rptExceptYourAttacks=e.target.checked},false);document.getElementById(UID["tabOptions_ChkD"]).addEventListener("change",function(e){Data.options.messages_delete.dateAll=e.target.checked;o()},false);for(var r=0;r<2;r++){document.getElementById(UID["tabOptions_DD"+r]).addEventListener("change",s,false);document.getElementById(UID["tabOptions_DM"+r]).addEventListener("change",s,false);document.getElementById(UID["tabOptions_DY"+r]).addEventListener("change",s,false);u(false);o()}document.getElementById(UID["tabOptions_ButDel"]).addEventListener("click",h,false)},deleteSelection:function(){var e=Tabs.Inbox;if(e.checkMessagesBusy||e.checkMessagesError)return false;Messages.messageDeletion=true;e.checkMessagesBusy=true;e.dP(function(){bI(translate("Messages selection deleted"));Tabs.Inbox.checkMessagesBusy=false;Messages.messageDeletion=false;Tabs.Inbox.show()})},dP:function(e){function n(t){if(t==null){Tabs.Inbox.checkMessagesError=true;progressBarPop.getContentDiv().innerHTML="<B>"+translate("Error while deleting selected messages")+"</B>";progressBarPop.allowClose(true);if(e)e(false);return}if(t.done){aX(translate("Deleting selected messages")+" "+translate("complete")+". "+t.count+" "+translate("messages deleted"));progressBarPop.getContentDiv().innerHTML="<B>"+t.count+" "+translate("Messages deleted").toLowerCase()+"</B>";progressBarPop.allowClose(true);if(e)e(true)}}var t=Tabs.Inbox;progressBar.init(800+Math.randRange(1,50),100,300,150,translate("Message"),200,true,t.container);progressBar.start({steps:100,delay:1,byCount:true,title:translate("Deleting selected messages in progress")+"...",stepText:translate("Please wait...")});Messages.dP(n)},getAllPages:function(){var e=Tabs.Inbox;if(e.checkMessagesBusy||e.checkMessagesError)return false;Messages.messageDeletion=true;e.checkMessagesBusy=true;e.getAllMessages(function(){bI(translate("All messages retrieved"));Tabs.Inbox.checkMessagesBusy=false;Messages.messageDeletion=false;Tabs.Inbox.show()})},getAllMessages:function(e){function n(t){if(t==null){Tabs.Inbox.checkMessagesError=true;progressBarPop.getContentDiv().innerHTML="<B>"+translate("Error while retrieving all messages")+"</B>";progressBarPop.allowClose(true);if(e)e(false);return}if(t.done){aX(translate("Retrieving all messages")+" "+translate("complete"));progressBarPop.destroy();if(e)e(true)}}var t=Tabs.Inbox;progressBar.init(800+Math.randRange(1,50),100,300,150,translate("Message"),200,true,t.container);progressBar.start({steps:100,delay:1,byCount:true,title:translate("Retrieving all messages in progress")+"...",stepText:translate("Please wait...")});Messages.dealMessages("get",undefined,n)},getFirstPage:function(e){function n(t){if(t==null||t.error){Tabs.Inbox.checkMessagesError=true;if(e)e(false);return}aZ(translate("Retrieving messages")+" "+translate("complete"));bf(translate("Retrieving messages")+" "+translate("complete"));if(e)e(true)}var t=Tabs.Inbox;Messages.getFirstPage(Data.options.inbox.current_tab,n)},getMessages:function(e){var t=Tabs.Inbox,n=[];for(var r in Messages.details){msg=Messages.details[r];if(!as(msg)){switch(e){case"messages":if(/(PlayerMessage|AllianceMessage|TargetedMessage)/.test(msg.type))n.push(msg);break;case"reports":if(!/(PlayerMessage|AllianceMessage|TargetedMessage)/.test(msg.type))n.push(msg);break;default:n.push(msg);break}}}n.sort(function(e,t){return t.created_at-e.created_at});return n},onSelectAll:function(e){var t=Tabs.Inbox,n=[];for(var r in Messages.details){msg=Messages.details[r];if(!as(msg)){switch(t.contentType){case MESSAGES_ONLY:if(/(PlayerMessage|AllianceMessage|TargetedMessage)/.test(msg.type))n.push(msg.id);break;case REPORTS_ONLY:if(!/(PlayerMessage|AllianceMessage|TargetedMessage)/.test(msg.type))n.push(msg.id);break;default:n.push(msg.id);break}}}for(var r=0;r<n.length;r++)Messages.details[n[r]].checked=e;t.show()},refreshFirstPage:function(){var e=Tabs.Inbox;if(e.checkMessagesBusy||e.checkMessagesError)return false;e.checkMessagesBusy=true;e.getFirstPage(function(){Tabs.Inbox.checkMessagesBusy=false});e.show()}};Tabs.Jobs={tabOrder:JOBS_TAB_ORDER,tabLabel:"Tasks",tabDisabled:!JOBS_TAB_ENABLE,lastSubTab:"tabJobInfo",container:null,timer:null,contentType:0,trainContentType:0,sanctContentType:0,buildScrollPos:0,selectedQ:"min_resource",refreshPlayerBusy:false,trainTimer:null,trainErrorCount:0,trainRetryTime:2e4,buildTimer:null,buildErrorCount:0,buildRetryTime:2e4,buildRefreshTab:false,buildRefreshLvl:false,last_built:{},researchTimer:null,resErrorCount:0,resRetryTime:2e4,resurrectTimer:null,revErrorCount:0,revRetryTime:2e4,sanctuaryTimer:null,feedErrorCount:0,feedRetryTime:2e4,init:function(e){var t=Tabs.Jobs;Data.setDefaultValues("jobs");t.container=e;var n='<ul class=tabs>			<li class="tab first"><a id='+bS("tabJobInfo")+">"+translate("Summary")+"</a></li>			<li class=tab><a id="+bS("tabJobTrain")+">"+translate("Train")+"</a></li>			<li class=tab><a id="+bS("tabJobBuild")+">"+translate("Build")+"</a></li>			<li class=tab><a id="+bS("tabJobResearch")+">"+translate("Research")+"</a></li>";if(Seed.cities[CAPITAL.id].souls&&Seed.cities[SPECTRAL_OUTPOST.id])n+="<li class=tab><a id="+bS("tabJobResurrect")+">"+translate("Resurrect")+"</a></li>";n+="<li class=tab><a id="+bS("tabJobSanctuary")+">"+translate("dragon-sanctuary")+"</a></li></ul>			<div id="+bS("tabJob_Header")+' style="height:225px; max-height:225px; margin-bottom:5px;"></div>			<div id='+bS("tabJob_Content")+' class="'+UID["scrollable"]+'" style="padding-top:5px; height:435px; max-height:700px;"></div>';e.innerHTML=n;document.getElementById(UID["tabJobInfo"]).addEventListener("click",t.tabJobInfo,false);document.getElementById(UID["tabJobTrain"]).addEventListener("click",t.tabJobTrain,false);document.getElementById(UID["tabJobBuild"]).addEventListener("click",t.tabJobBuild,false);document.getElementById(UID["tabJobResearch"]).addEventListener("click",t.tabJobResearch,false);document.getElementById(UID["tabJobSanctuary"]).addEventListener("click",t.tabJobSanctuary,false);if(Seed.cities[CAPITAL.id].souls&&Seed.cities[SPECTRAL_OUTPOST.id])document.getElementById(UID["tabJobResurrect"]).addEventListener("click",t.tabJobResurrect,false);t.contentType=Data.options.jobs.current_tab;t.trainContentType=Data.options.training.current_tab;t.sanctContentType=Data.options.sanctuary.current_tab;t.setTrainEnable(Data.options.training.enabled);t.selectedQ=Data.options.training.mode;t.setBuildEnable(Data.options.building.enabled);t.setResearchEnable(Data.options.research.enabled);if(Seed.cities[SPECTRAL_OUTPOST.id])t.setResurrectEnable(Data.options.resurrect.enabled);window.addEventListener("unload",t.onUnload,false)},show:function(){var e=Tabs.Jobs;switch(e.contentType){case 0:e.tabJobInfo();break;case 1:e.tabJobTrain();break;case 2:e.tabJobBuild();break;case 3:e.tabJobResearch();break;case 4:if(Seed.cities[SPECTRAL_OUTPOST.id])e.tabJobResurrect();else e.tabJobInfo();break;case 5:e.tabJobSanctuary();break}},hide:function(){var e=Tabs.Jobs},onUnload:function(){bI("Tabs.Jobs.onUnload");var e=Tabs.Jobs;Data.options.jobs.current_tab=e.contentType;Data.options.training.current_tab=e.trainContentType;Data.options.sanctuary.current_tab=e.sanctContentType;Data.options.training.mode=e.selectedQ},clearTimers:function(){var e=Tabs.Jobs;clearInterval(e.jobsStatTimer)},tabJobInfo:function(){function i(){var e="<div class="+UID["status_ticker"]+">"+v(CAPITAL.id)+"<table class="+UID["table"]+" width=100%>"+s(CAPITAL.id)+l("dragon",CAPITAL.id)+l("outpost",CAPITAL.id)+u(CAPITAL.id)+a(CAPITAL.id)+c(CAPITAL.id)+p(CAPITAL.id)+"	</table>"+"</div>";for(var t=0;t<Seed.cities.length;++t){if(t!=CAPITAL.id&&Seed.cities[t]){e+="<div class="+UID["status_ticker"]+' style="margin-top:6px !important">'+v(t)+"<table class="+UID["table"]+" width=100%>"+(t==SPECTRAL_OUTPOST.id?h():"")+l("dragon",t)+l("outpost",t)+u(t)+c(t)+p(t)+d(t)+"	</table>"+"</div>"}}e+="<br><div class="+UID["status_ticker"]+' style="margin-top:6px !important">'+"<div class="+UID["subtitle"]+"><table class="+UID["table"]+">"+"<tr><td align=left width=35%>"+translate("dragon-sanctuary")+"</td>"+"<td align=right width=65%>&nbsp;</td>"+"</tr></table></div>"+"<table class="+UID["table"]+" width=100%>"+o()+f("hatching",CAPITAL.id)+f("feeding",CAPITAL.id)+"</table>"+"</div>";r.innerHTML=e;r.style.height=r.offsetHeight+"px"}function s(e){var t="<tr><td class=right width=20%>"+translate("Resources")+"</td>";var n="";for(var r=0;r<all_resource_types.length;r++){var i=false;var s=Seed.cities[e].figures.resource_rates[all_resource_types[r]];var o=bD(bV(Seed.cities[e].resources[all_resource_types[r]]));if(all_resource_types[r]=="food"&&Seed.player.boosts&&Seed.player.boosts.collect_resources&&bV(Seed.cities[e].resources[all_resource_types[r]])>s.capacity)i=true;desc=all_resource_types[r];if(all_resource_types[r]=="blue_energy")desc="blueenergy250k";t+=n+"<td width =15%>"+translate(desc)+"</td><td width=1%>:</td><td align=right width=14%>"+o+"</td><td width=5%> &nbsp </td>"+"<td width=10% align=right>("+(i?"<font color=blue><b>0</b></font>":bD(s.rate))+" /"+translate("h")+")</td><td width=30%> &nbsp </td></tr>";n="<tr><td> &nbsp </td>"}var u=bV(Seed.cities[e].figures.population["current"]);var a=bV(Seed.cities[e].figures.population["laborers"]);var f=bV(Seed.cities[e].figures.population["armed_forces"]);var l=u-a-f;l=l<0?0:l;t+="<tr><td> &nbsp </td><td width =15%>"+translate("idlepopulation")+"</td><td width=1%>:</td><td align=right width=14%>"+bD(l," ")+"</td><td width=50% colspan=3> &nbsp </td></tr>";t+="</table><br><table class="+UID["table"]+" width=100%>";return t}function o(){var e="";var t=Jobs.getJobs("breeding",false,-1);for(var n=0;n<t.length;n++){var r="",i=0,s="",o="";if(n==0){r=translate("breeding-dragon")+":";i=t[n].run_at-be()>0?t[n].run_at-be():0}else{i=t[n].duration}if(!Seed.sanctuary_dragons[t[n].male_id]){aZ("Error: Inexisting dragon "+t[n].male_id);s=t[n].male_id}else{s=bo(Seed.sanctuary_dragons[t[n].male_id].subtype,"rank-"+Seed.sanctuary_dragons[t[n].male_id].type,"dragons")}if(!Seed.sanctuary_dragons[t[n].female_id]){aZ("Error: Inexisting dragon "+t[n].female_id);o=t[n].female_id}else{o=bo(Seed.sanctuary_dragons[t[n].female_id].subtype,"rank-"+Seed.sanctuary_dragons[t[n].female_id].type,"dragons")}e+="<tr>"+"		<td class=right width=20%>"+r+"</td>"+"		<td align=left width=50% colspan=2>"+s+" + "+o+"</td>"+"     <td width=30%><font color="+TIMER_COLOR+">"+bE(i,true)+"</font></td></tr>"}return e}function u(e){var t="<tr><td width=20% class=right>"+translate("Building")+": </td>";var n=Jobs.getBuildingJob(e);if(n&&n.job.run_at>be()){t+="<td width=50% align=left>"+translate(n.building.type)+" ("+n.job.level+") &nbsp;</td>"+"<td width=30%><font color="+TIMER_COLOR+">"+bE(n.job.run_at-be(),true)+"</font></td>"+"</tr>"}else{t+="<td align=left width=80% colspan=2><span class="+UID["bold_red"]+">"+translate("None").toUpperCase()+"</span></td></tr>"}return t}function a(e){var t="<tr><td width=20% class=right>"+translate("Building")+": </td>",n=Jobs.getDefenseTowerJob(e);if(n&&n.job.run_at>be()){t+="<td width=50% align=left colspan=2>"+translate(n.building.type)+" ("+n.job.level+") &nbsp;</td>"+"<td width=30%><font color="+TIMER_COLOR+">"+bE(n.job.run_at-be(),true)+"</font></td>"+"</tr>"}else{t+="<td align=left width=80% colspan=3><span class="+UID["bold_red"]+">"+translate("DefensiveTower")+" "+translate("None").toUpperCase()+"</span></td></tr>"}return t}function f(e,t){var n="";var r=Jobs.getJobs(e,false,t);for(var i=0;i<r.length;i++){var s="",o=0,u="";if(i==0){s=translate(e=="feeding"?"upgrading-dragon":"hatching-egg")+":";o=r[i].run_at-be()>0?r[i].run_at-be():0}else{o=r[i].duration}var a=e=="feeding"?r[i].dragon_id:r[i].egg_id;if(!Seed.sanctuary_dragons[a]){aZ("Error: Inexisting dragon "+a);u=a}else{u=bo(Seed.sanctuary_dragons[a].subtype,"rank-"+Seed.sanctuary_dragons[a].type,"dragons")}n+="<tr>"+"		<td class=right width=20%>"+s+"</td>"+"		<td align=left width=50% colspan=2>"+u+"</td>"+"     <td width=30%><font color="+TIMER_COLOR+">"+bE(o,true)+"</font></td></tr>"}return n}function l(e,t){var n="";var r=Jobs.getJobs(e,true,t)[0];if(r&&r.run_at>be()){n+="<tr><td class=right width=20%>"+translate(e=="outpost"?"Repairing":"Healing")+":</td>"+"<td width=50%><SPAN class="+UID["bold_red"]+">"+translate(e=="outpost"?"outpost-progress":"Dragon healing")+"</span></td><td width=30%><font color="+TIMER_COLOR+">"+bE(r.run_at-be(),true)+"</font></td></tr>"}return n}function c(e){var t="<tr><td class=right width=20%>"+translate("Researching")+": </td>";var n=Jobs.getJobs("research",true,e)[0];if(n&&n.run_at>be()){t+="<td width=50% align=left>"+translate(n.research_type)+" ("+n.level+") &nbsp;</td>"+"<td width=30%><font color="+TIMER_COLOR+">"+bE(n.run_at-be(),true)+"</font></td>"+"</tr>"}else if(e==CAPITAL.id){t+="<td align=left width=80% colspan=2><span class="+UID["bold_red"]+">"+translate("None").toUpperCase()+"</span></td></tr>"}else return"";return t}function h(){var e="",t=er(),n="";if(t&&t.max>0){var r=t.min/t.max*1e4;if(r>9e3)n="<span class="+UID["bold_red"]+">"+bD(Math.round(r/100)," ")+"%</span>";else n="<font color="+TIMER_COLOR+">"+bD(Math.round(r/100)," ")+"%</font>";e+="<tr><td class=right width=20%>"+translate("Capacity")+":</td>"+"	<td width=50% colspan=2><font color="+TIMER_COLOR+"><b>"+bD(t.min," ")+" / "+bD(t.max," ")+"</b></span></td>"+"	<td width=30%>"+n+"</td>"+"</tr>"}return e}function p(e){var t="",n=[];for(var r=0;r<Seed.cities[e].jobs.length;r++){if(Seed.cities[e].jobs[r].queue=="units"&&Seed.cities[e].jobs[r].unit_type&&Seed.cities[e].jobs[r].run_at>be()){n.push(Seed.cities[e].jobs[r])}}n.sort(function(e,t){return e.run_at-t.run_at});for(var r=0;r<n.length;r++){var i="",s="",o=0;if(r==0){o=n[r].run_at-be()>0?n[r].run_at-be():0;i=translate("Training")+":"}else if(r==n.length-1){o=n[r].run_at-be()>0?n[r].run_at-be():0;s="&nbsp;<b>("+bz(o)+")</b>";o=n[r].duration}else{o=n[r].duration}t+="<tr>"+"		<td class=right width=20%>"+i+"</td>"+"		<td align=left width=50%>"+bD(n[r].quantity," ")+"&nbsp;&nbsp;"+translate(n[r].unit_type)+"&nbsp;</td>"+"     <td width=30%><font color="+TIMER_COLOR+">"+bE(o,true)+"</font>&nbsp"+s+"</td>"+"</tr>"}return t}function d(e){var t="",n=[];for(var r=0;r<Seed.cities[e].jobs.length;r++){if(Seed.cities[e].jobs[r].queue=="resurrection"&&Seed.cities[e].jobs[r].unit_type&&Seed.cities[e].jobs[r].run_at>be()){n.push(Seed.cities[e].jobs[r])}}n.sort(function(e,t){return e.run_at-t.run_at});for(var r=0;r<n.length;r++){var i="",s="",o=0;if(r==0){o=n[r].run_at-be()>0?n[r].run_at-be():0;i=translate("Resurrection")+":"}else if(r==n.length-1){o=n[r].run_at-be()>0?n[r].run_at-be():0;s="&nbsp;<b>("+bz(o)+")</b>";o=n[r].duration}else{o=n[r].duration}t+="<tr>"+"		<td class=right width=20%>"+i+"</td>"+"		<td align=left width=50% colspan=2>"+bD(n[r].quantity," ")+"&nbsp;&nbsp;"+translate(n[r].unit_type)+"&nbsp;</td>"+"     <td width=30%><font color="+TIMER_COLOR+">"+bE(o,true)+"</font>&nbsp"+s+"</td>"+"</tr>"}return t}function v(e){var t=Seed.cities[e];var n=m(e);var r="";var i=Seed.player.alliance?Seed.player.alliance.name:"";i=t.type=="Outpost"?"":i;if(e==CAPITAL.id)r=Seed.cities[e].defended!=undefined&&Seed.cities[e].defended?"<font class="+UID["defending"]+">"+translate("Defend").toUpperCase()+"</font>":"<font class="+UID["hiding"]+">"+translate("Hiding").toUpperCase()+"</font>";else r=" &nbsp ";var s=""+"<div class="+UID[n]+">"+"	<table class="+UID["table"]+">"+"	<tr>"+"		<td align=left width=35%>"+(t.type=="Outpost"?translate(t.name):t.name)+"</td>"+"		<td align=center width=30%>"+t.x+","+t.y+"</td>"+"		<td align=center width=200px>"+"			<font color=yellow>"+i+"</font>"+"		</td>"+"		<td width=35% align=right>"+r+"</td>"+"	</tr>"+"</table></div>";return s}function m(e){var t="subtitle";switch(e){case CAPITAL.id:break;case SPECTRAL_OUTPOST.id:t="subtitle_sr";break;case SKY_OUTPOST.id:break;case CAVE_OUTPOST.id:break;case LUNA_OUTPOST.id:break;default:break}return t}function g(){bI("fetchPlayer from Tab.Jobs refresh");var e=Tabs.Jobs;if(e.refreshPlayerBusy)return false;e.refreshPlayerBusy=true;eo(e.container,function(){bI(translate("Player data retrieved"));Tabs.Jobs.refreshPlayerBusy=false});e.tabJobInfo()}var e=Tabs.Jobs;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabJobInfo"]).className="selected";document.getElementById(UID["tabJobInfo"]).style.zIndex=1;e.lastSubTab="tabJobInfo";e.contentType=0;var t=Seed.cities[CAPITAL.id];var n="<div class="+UID["title"]+">"+translate("information")+"</div>"+"	<table width=100%><tr><td><input id="+bS("tabJobInfo_Refresh")+" type=button value="+translate("Refresh")+"></input></td></tr></table>";document.getElementById(UID["tabJob_Header"]).style.height="45px";document.getElementById(UID["tabJob_Header"]).innerHTML=n;document.getElementById(UID["tabJobInfo_Refresh"]).addEventListener("click",g,false);document.getElementById(UID["tabJob_Content"]).style.height="593px";document.getElementById(UID["tabJob_Content"]).innerHTML='<div id="'+bS("tabJob_Container")+'"></div>';var r=document.getElementById(UID["tabJob_Container"]);i();e.clearTimers();e.jobsStatTimer=setInterval(i,1e3)},tabJobTrain:function(){var e=Tabs.Jobs;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabJobTrain"]).className="selected";document.getElementById(UID["tabJobTrain"]).style.zIndex=1;e.lastSubTab="tabJobTrain";e.contentType=1;var t="<div class="+UID["title"]+">"+translate("Train")+" "+translate("Automatically")+"</div>"+"<div class="+UID["status_ticker"]+' style="margin-bottom: 5px !important">'+"	<center><input id="+bS("tabJobTrain_OnOff")+" type=button /></center>"+"	<div id="+bS("tabJobTrain_Report")+" class="+UID["status_report"]+">"+"		<table id="+bS("tabJobTrain_Table")+" class="+UID["table"]+">"+"		</table>"+"	</div>"+"	<br>"+"	<div id="+bS("tabJobTrain_Feedback")+" class="+UID["status_feedback"]+"></div>"+"</div>"+"<ul class=tabs>"+'	<li class="tab first"><a id='+bS("tabJobTrain_tabTrain")+">"+translate("Train")+"</a></li>"+'	<li class="tab"><a id='+bS("tabJobTrain_tabConfig")+">"+translate("Config")+"</a></li>"+"</ul>";document.getElementById(UID["tabJob_Header"]).style.height="225px";document.getElementById(UID["tabJob_Header"]).innerHTML=t;var n="<div id="+bS("tabJobTrain_Content")+' style="height:430px; ; max-height:430px; overflow-y:auto">';document.getElementById(UID["tabJob_Content"]).style.height="430px";document.getElementById(UID["tabJob_Content"]).innerHTML=n;document.getElementById(UID["tabJobTrain_OnOff"]).addEventListener("click",function(){var e=Tabs.Jobs;e.setTrainEnable(!Data.options.training.enabled)},false);document.getElementById(UID["tabJobTrain_tabTrain"]).addEventListener("click",e.tabJobTrainSets,false);document.getElementById(UID["tabJobTrain_tabConfig"]).addEventListener("click",e.tabJobTrainConfig,false);e.refreshTrainButton(Data.options.training.enabled);switch(e.trainContentType){case 0:e.tabJobTrainSets();break;case 1:e.tabJobTrainConfig();break}e.trainStatTick();e.clearTimers();e.jobsStatTimer=setInterval(e.trainStatTick,1e3)},tabJobTrainSets:function(){function A(e){for(var t=0;t<Seed.cities.length;++t){if(t==bV(e.target.getAttribute("ref"))&&Seed.cities[t]&&t!=SPECTRAL_OUTPOST.id&&t!=SKY_OUTPOST.id){for(S=0;S<l.length;S++){var n=da(t,l[S]);if(n){document.getElementById(UID["tabTrain_Troop_"+t+"_"+S]).value=0;document.getElementById(UID["tabTrain_Troop_"+t+"_"+S]).click()}}}}}function O(t){var n=t.target.getAttribute("ref").split("_");var r=all_unit_types[n[1]];var i=e.checkRequirements({reqs_type:"unit",city_idx:bV(n[0]),unit_type:all_unit_types[n[1]],unit_quantity:1});document.getElementById(UID["tabTrain_Troop_"+n[0]+"_"+n[1]]).value=i.max_units}function M(e){var t=e.target.getAttribute("ref").split("_");document.getElementById(UID["tabTrain_Troop_"+t[0]+"_"+t[1]]).value=0}function _(t){var n=t.target.getAttribute("ref").split("_");var r=bV(t.target.value);var i=bV(n[0]);var s=all_unit_types[n[1]];var o=e.checkTrainReqs(s,r,i);if(isNaN(r)||r<0){t.target.style.backgroundColor="red";eg(translate("Invalid number of troops",e.container))}else{t.target.value=r;Data.options.training.city[n[0]].units[n[1]]=r;t.target.style.backgroundColor=""}}function D(e){var t=e.target.getAttribute("ref").split("_");Data.options.training.city[t[1]].enabled=e.target.checked}function P(t){var n=t.target.getAttribute("ref").split("_");var r=bV(n[0]);var i=all_unit_types[n[1]];var s=Data.options.training.city[r].units[n[1]];if(s>0){cap=e.getTroopCap(i,s);try{if(cap){s=0;if(e.contentType==1)e.jobFeedback(translate("Troops Capped"));document.getElementById(UID["tabTrain_Troop_"+r+"_"+E]).style.backgroundColor="red"}else if(e.contentType==1){if(document.getElementById(UID["tabTrain_Troop_"+r+"_"+E]).style.backgroundColor=="red")document.getElementById(UID["tabTrain_Troop_"+r+"_"+E]).style.backgroundColor="white"}}catch(o){}}if(s>0){var u=e.checkTrainReqs(i,s,r);if(!u.msg)e.doTrain(i,s,r)}}function H(e){if(e.target.getAttribute("ref")){var t=e.target.getAttribute("ref").split("_");if(t[0]=="Enable")return}if(e.target.tagName=="DIV")bA=e.target;else{var n=e.target.parentNode;while(n.tagName!="DIV"){n=n.parentNode}bA=n}var r=bA.getAttribute("ref");var i="tabJobTrain_cityList_"+r;var s="tabJobTrain_accordion_"+r;var o=document.getElementById(UID[i]);if(o.style.display=="none"){o.style.display="block";document.getElementById(UID[s]).innerHTML="-&nbsp";Data.options.collapsed.train[r]=false}else{o.style.display="none";document.getElementById(UID[s]).innerHTML="+&nbsp";Data.options.collapsed.train[r]=true}}var e=Tabs.Jobs;var t=[],n="",r=[],i=[],s=[],o=[],u=[],a=[],f=[],l=all_unit_types;for(var c=0;c<Seed.cities.length;c++){if(Data.options.collapsed.train[c]==undefined)Data.options.collapsed.train[c]=false}for(var c=0;c<Seed.cities.length;++c){if(Seed.cities[c]&&c!=SPECTRAL_OUTPOST.id&&c!=SKY_OUTPOST.id&&c!=LUNA_OUTPOST.id){var h=Seed.cities[c];var p="tabJobTrain_cityId_"+c;var d="tabJobTrain_cityList_"+c;var v="tabJobTrain_Enabled_"+c;var m="tabJobTrain_accordion_"+c;var g=0;var y=be();if(h.jobs){var b=h.jobs;var w=[];for(var E=0;E<b.length;E++)if(b[E].queue=="units"&&b[E].unit_type&&b[E].run_at>y)w.push(b[E]);if(w.length>0){w.sort(function(e,t){return e.run_at-t.run_at});var g=w[w.length-1].run_at-y}}n+="<div class="+UID["status_ticker"]+' style="margin-top:10px !important">'+"<A><div id="+bS(p)+" class="+UID["subtitle"]+" ref="+c+">"+"	<table class="+UID["table"]+" width=100%>"+"	<tr>"+"		<td align=left width=1%><label><input type=checkbox id="+bS(v)+' ref="Enable_'+c+'" '+(Data.options.training.city[c].enabled?"checked":"")+" /></label></td>"+"		<td align=left width=29%>&nbsp;</td>"+"		<td align=center width=40%>"+(h.type=="Outpost"?translate(h.name):h.name)+"</td>"+"		<td align=right width=30%><font color=yellow>"+bz(g)+"</font></td>"+"		<td align=right><div id="+bS(m)+' ref="'+c+'"></div></td>'+"	</tr>"+"</table></div></A>"+"<div id="+bS(d)+">"+"<table class="+UID["table"]+" width=100%>"+"	<tr class="+UID["row_headers"]+">"+"		<td></td><td>"+translate("Quantity")+"</td><td>"+translate("Total")+"</td></tr>";r.push(UID[p]);o.push(UID[v]);var S;for(var S=0;S<l.length;S++){var x=da(c,l[S]);if(x){var T=Data.options.training.city[c].units[S];if(!T||isNaN(T))T=0;n+="<tr>"+"		<td class=right width=25%>"+translate(l[S])+":</td>"+"		<td align=middle width=10%><input type=text id="+bS("tabTrain_Troop_"+c+"_"+S)+" ref="+c+"_"+S+' maxlength=7 size=2 value="'+T+'" style="width:45px;text-align:right;" /></td>'+"      <td align=middle width=15%>"+"          <input id="+bS("tabJobTrain_Max_"+c+"_"+S)+" ref="+c+"_"+S+' class="Xtrasmall '+UID["btn_blue"]+'" style="width:auto !important;" type=button value='+translate("Max")+" />"+"			<input class=small id="+bS("tabTrain_Now_"+c+"_"+S)+" ref="+c+"_"+S+' type=button  style="width:auto !important;" value="'+translate("Train")+'" >'+"          <input id="+bS("tabJobTrain_Clear_"+c+"_"+S)+" ref="+c+"_"+S+' class="Xtrasmall '+UID["btn_blue"]+'" style="width:auto !important;" type=button value=X />'+"     </td>"+"		<td align=right width=15%>&nbsp;<span class=jewel>("+bD(aV(Seed.cities[CAPITAL.id],l[S]).total," ")+")</span></td>"+"		<td align=left width=35% id="+bS("tabJobTrain_FB_"+c+"_"+l[S])+' class=jewel valign=top style="white-space:normal;"></td>'+"	</tr>";t.push(UID["tabTrain_Troop_"+c+"_"+S]);s.push(UID["tabTrain_Now_"+c+"_"+S]);a.push(UID["tabJobTrain_Max_"+c+"_"+S]);f.push(UID["tabJobTrain_Clear_"+c+"_"+S])}}n+="<tr>"+" <td></td>"+" <td><input id="+bS("tabTrain_Clear_All_"+c)+' type="button"  style="width:auto !important;" value="'+translate("Clear all")+'" ref="'+c+'" ></td>'+" <td colspan=3></td>"+"</tr>"+"</table></div></div>";u.push(UID["tabTrain_Clear_All_"+c])}}n+="</div>";document.getElementById(UID["tabJobTrain_Content"]).innerHTML=n;document.getElementById(UID["tabJobTrain_tabConfig"]).className="";document.getElementById(UID["tabJobTrain_tabConfig"]).style.zIndex=0;document.getElementById(UID["tabJobTrain_tabTrain"]).className="selected";document.getElementById(UID["tabJobTrain_tabTrain"]).style.zIndex=1;e.trainContentType=0;for(var N=0;N<r.length;N++){document.getElementById(r[N]).addEventListener("click",H,false);var c=document.getElementById(r[N]).getAttribute("ref");var C="tabJobTrain_cityList_"+c;var k="tabJobTrain_accordion_"+c;var L=document.getElementById(UID[C]);if(Data.options.collapsed.train[c]){L.style.display="none";document.getElementById(UID[k]).innerHTML="+&nbsp"}else{L.style.display="block";document.getElementById(UID[k]).innerHTML="-&nbsp"}}for(var S=0;S<t.length;S++){document.getElementById(t[S]).addEventListener("change",_,false);document.getElementById(t[S]).addEventListener("click",_,false)}for(var S=0;S<s.length;S++){document.getElementById(s[S]).addEventListener("click",P,false)}for(var S=0;S<o.length;S++){document.getElementById(o[S]).addEventListener("change",D,false);document.getElementById(o[S]).addEventListener("click",D,false)}for(var S=0;S<u.length;S++){document.getElementById(u[S]).addEventListener("click",A,false)}for(var S=0;S<a.length;S++){document.getElementById(a[S]).addEventListener("click",O,false)}for(var S=0;S<f.length;S++){document.getElementById(f[S]).addEventListener("click",M,false)}},tabJobTrainConfig:function(){function a(e){var t=e.target.value;if(isNaN(t)||t<0||t>100){e.target.style.backgroundColor="red";e.target.value=Seed.cities[CAPITAL.id].figures.tax_rate}else{e.target.style.backgroundColor="white"}}function f(e){var t=document.getElementById(UID["TabJobTrainTaxRate"]).value;var n=new aw(document.getElementById(UID["tabJobTrain_Content"]),300,165,"",false,null);n.bd().innerHTML="<div class="+UID["title"]+"><center><b>"+scriptName+" : "+translate("Message")+"</b></center></div>";n.getContentDiv().innerHTML=translate("Refreshing Tax Rate");if(isNaN(t)||t<0||t>100){document.getElementById(UID["TabJobTrainTaxRate"]).style.backgroundColor="red";document.getElementById(UID["TabJobTrainTaxRate"]).value=Seed.cities[CAPITAL.id].figures.tax_rate}else{new MyAjax.switchTaxRate(Seed.cities[CAPITAL.id].id,t,function(e){if(e.ok){aX("<B> "+translate("Successfully"))}else{aX(translate("Refreshing Tax Rate")+" : "+e.ok+". "+translate("failed and returned error")+": "+e.errmsg)}try{n.destroy()}catch(t){}})}}function l(e){var t=Tabs.Jobs;if(Data.options.training.enabled){t.setTrainEnable(false);if(t.contentType==1)t.jobFeedback(translate("Safe Mode")+" "+translate("Training")+" "+translate("Turned Off"))}t.selectedQ=e.target.value;Data.options.training.mode=e.target.value}function c(t){var n=t.target.getAttribute("ref").split("_");var r=bV(t.target.value);if(isNaN(r)||r<0){t.target.style.backgroundColor="red";eg(translate("Invalid number of troops",e.container))}else{t.target.value=r;Data.options.training.city[n[0]].cap[n[1]]=r;t.target.style.backgroundColor=""}}var e=Tabs.Jobs;document.getElementById(UID["tabJobTrain_tabTrain"]).className="";document.getElementById(UID["tabJobTrain_tabTrain"]).style.zIndex=0;document.getElementById(UID["tabJobTrain_tabConfig"]).className="selected";document.getElementById(UID["tabJobTrain_tabConfig"]).style.zIndex=1;e.trainContentType=1;bS("tabTrainConfig_QRadio");var t="<div class="+UID["status_ticker"]+' style="margin-top:6px !important">'+"<div class="+UID["subtitle"]+">"+translate("Training Configuration")+"</div>"+'	<div class="'+UID["scrollable"]+'">'+"		<table class="+UID["table"]+">"+"		<tr align=center class="+UID["row_headers"]+">"+'			<td style="background:none !important;" colspan=2></td>'+"		</tr>"+"	<tr>"+"		<td><label><input type=radio name="+UID["tabTrainConfig_QRadio"]+' value="min_housing" />'+translate("Only one training queue per city")+"</label></td>"+"	</tr>"+"	<tr>"+"		<td><label><input type=radio name="+UID["tabTrainConfig_QRadio"]+' value="min_resource" />'+translate("Maximum training queues possible per city, according to available resources")+"</label></td>"+"</table>"+"</div>"+"<br>";var n=[];var r=all_unit_types;t+="<div class="+UID["subtitle"]+' style="background-color:#0044a0;">'+translate("Maximum Troops")+" (0 = "+translate("no max")+")</div>"+"	<table class="+UID["table"]+" width=100%>"+"		<tr valign=top>"+"			<td width=33%>"+"			<table class="+UID["table"]+" width=100%>";var i;var s=Math.ceil(r.length/2);for(i=0;i<s;i++){t+="<tr>"+"	<td class=right width=70%>"+translate(r[i])+":</td>";var o=Data.options.training.city[0].cap[i];if(!o||isNaN(o))o=0;t+="<td width=30%><input type=text id="+bS("tabTrainConfig_Cap_"+0+"_"+i)+" ref="+(0+"_"+i)+' maxlength=8 size=2 value="'+o+'" style="width:60px;text-align:right;" /></td>'+"</tr>";n.push(UID["tabTrainConfig_Cap_"+0+"_"+i])}t+="</table></td>"+"	<td width=33%>"+"	<table class="+UID["table"]+" width=100%>";for(i=s;i<r.length;i++){t+="<tr>"+"	<td class=right width=70%>"+translate(r[i])+":</td>";var o=Data.options.training.city[0].cap[i];if(!o||isNaN(o))o=0;t+="<td width=30%>"+"<input type=text id="+bS("tabTrainConfig_Cap_"+0+"_"+i)+" ref="+(0+"_"+i)+' maxlength=8 size=2 value="'+o+'" style="width:60px;text-align:right;" /></td>'+"</tr>";n.push(UID["tabTrainConfig_Cap_"+0+"_"+i])}t+="			</table>"+"			</td>"+"		</tr>"+"	</table>"+"</div>"+"</div>";document.getElementById(UID["tabJobTrain_Content"]).innerHTML=t;document.getElementById(UID["TabJobTrainChangeTaxRate"]).bP("click",f);document.getElementById(UID["TabJobTrainTaxRate"]).bP("change",a);var u=document.getElementsByName(UID["tabTrainConfig_QRadio"]);for(var i=0;i<u.length;i++){u[i].addEventListener("change",l,false);u[i].checked=u[i].value==Data.options.training.mode}for(var i=0;i<n.length;i++){$(n[i]).addEventListener("change",c,false)}},tabJobBuild:function(){function C(t){Data.options.building.hide_fields=t.target.checked;if(Data.options.building.hide_fields){for(var n=0;n<Seed.cities.length;++n){var r=[];switch(n){case CAPITAL.id:r=field_buildings;break;case SPECTRAL_OUTPOST.id:r=spectral_fields;break;case SKY_OUTPOST.id:r=null;break;case CAVE_OUTPOST.id:r=null;break;case LUNA_OUTPOST.id:r=null;break;default:r=field_buildings;break}if(r)for(var i=0;i<r.length;++i)Data.options.building.level_enable[n][r[i]]=false}}setTimeout(e.tabJobBuild,1e3)}function k(t){var n=t.target.getAttribute("ref");var r=n.split("_");var i=Seed.cities[r[0]].id;Data.options.building.level_enable[r[0]][r[1]]=t.target.checked;if(Data.options.building.level_enable[r[0]][r[1]])e.checkBuildReqs(r[0],r[1]);if(Data.options.building.enabled&&t.target.checked)e.buildTick()}function L(e,t,n){var r=Seed.stats.building[n].level.length-1;var i=Buildings.getLevel(e,n).min;var s="<td>"+"	<select id="+bS("tabJobBuild_Cap_"+e+"_"+n)+" ref="+(e+"_"+t)+">"+"		<option value=0"+(i>0?' style="display:none;"':"")+">0</option>"+"		<option value=1"+(i>1?' style="display:none;"':"")+">1</option>"+"		<option value=2"+(i>2?' style="display:none;"':"")+">2</option>"+"		<option value=3"+(i>3?' style="display:none;"':"")+">3</option>"+"		<option value=4"+(i>4?' style="display:none;"':"")+">4</option>"+"		<option value=5"+(i>5?' style="display:none;"':"")+">5</option>"+"		<option value=6"+(i>6?' style="display:none;"':"")+">6</option>"+"		<option value=7"+(i>7?' style="display:none;"':"")+">7</option>"+"		<option value=8"+(i>8?' style="display:none;"':"")+">8</option>"+"		<option value=9"+(i>9?' style="display:none;"':"")+">9</option>"+"		<option value=10"+(i>10||r<10?' style="display:none;"':"")+">10</option>"+"		<option value=11"+(i>11||r<11?' style="display:none;"':"")+">11</option>"+"		<option value=12"+(i>12||r<12?' style="display:none;"':"")+">12</option>"+"		<option value=13"+(i>13||r<13?' style="display:none;"':"")+">13</option>"+"		<option value=14"+(i>14||r<14?' style="display:none;"':"")+">14</option>"+"		<option value=15"+(i>15||r<15?' style="display:none;"':"")+">15</option>"+"		<option value=16"+(i>16||r<16?' style="display:none;"':"")+">16</option>"+"		<option value=17"+(i>17||r<17?' style="display:none;"':"")+">17</option>"+"		<option value=18"+(i>18||r<18?' style="display:none;"':"")+">18</option>"+"		<option value=19"+(i>19||r<19?' style="display:none;"':"")+">19</option>"+"		<option value=20"+(i>20||r<20?' style="display:none;"':"")+">20</option>"+"	</select></td>"+"		<td id="+bS("tabJobBuild_FB_"+e+"_"+n)+' class=jewel valign=top style="width:250px;white-space:normal;"></td>';return s}function A(t){var n=t.target.getAttribute("ref");var r=n.split("_");Data.options.building.level_cap[r[0]][r[1]]=t.target[t.target.selectedIndex].value;t.target.style.backgroundColor="";if(Data.options.building.level_enable[r[0]][r[1]])e.checkBuildReqs(r[0],r[1]);if(Data.options.building.enabled)e.buildTick()}function O(t){if(e.contentType==2)e.buildScrollPos=document.getElementById(UID["tabJob_Content"]).scrollTop}function M(e){if(e.target.tagName=="DIV")bA=e.target;else{var t=e.target.parentNode;while(t.tagName!="DIV"){t=t.parentNode}bA=t}var n=bA.getAttribute("ref");var r="tabJobBuild_cityList_"+n;var i="tabJobBuild_accordion_"+n;var s=document.getElementById(UID[r]);if(s.style.display=="none"){s.style.display="block";document.getElementById(UID[i]).innerHTML="-&nbsp";Data.options.collapsed.build[n]=false}else{s.style.display="none";document.getElementById(UID[i]).innerHTML="+&nbsp";Data.options.collapsed.build[n]=true}}var e=Tabs.Jobs;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabJobBuild"]).className="selected";document.getElementById(UID["tabJobBuild"]).style.zIndex=1;var t="subtitle";e.lastSubTab="tabJobBuild";e.contentType=2;var n="<div class="+UID["title"]+">"+translate("Build")+" "+translate("Automatically")+"</div>"+"<div class="+UID["status_ticker"]+">"+"	<center><input id="+bS("tabJobBuild_OnOff")+" type=button /></center>"+"	<div id="+bS("tabJobBuild_Report")+" class="+UID["status_report"]+">"+"		<table id="+bS("tabJobBuild_Table")+" class="+UID["table"]+">"+"		</table>"+"	</div><br>"+"	<div id="+bS("tabJobBuild_Feedback")+" class="+UID["status_feedback"]+"></div>"+"</div>";document.getElementById(UID["tabJob_Header"]).style.height="205px";document.getElementById(UID["tabJob_Header"]).innerHTML=n;document.getElementById(UID["tabJob_Content"]).innerHTML="<div id="+bS("tabJobBuild_Content")+">";document.getElementById(UID["tabJob_Content"]).style.height="455px";m='<div style="margin-bottom:5px;">'+"	<table class="+UID["table"]+" width=100%>"+"		<tr valign=top>"+"			<td width=5% align=center><input id="+bS("tabJobBuild_HideFields")+" "+(Data.options.building.hide_fields?"CHECKED ":"")+" type=checkbox /></td>"+"			<td align=left>"+translate("Hide resource fields")+"</td>"+"		</tr>"+"	</table>"+"</div>";var r=[],i=[],s=[],o=[];for(var u=0;u<Seed.cities.length;u++){if(Data.options.collapsed.build[u]==undefined)Data.options.collapsed.build[u]=false}aZ(""+bC(Seed.cities,8,1));for(var u=0;u<Seed.cities.length;++u){t="subtitle";switch(u){case CAPITAL.id:i=capital_buildings;s=field_buildings;t="subtitle_pl";aZ("cityIdx : "+u+", CAPITAL.id : "+CAPITAL.id);break;case SPECTRAL_OUTPOST.id:i=spectral_buildings;s=spectral_fields;t="subtitle_pl";aZ("cityIdx : "+u+", SPECTRAL_OUTPOST.id : "+SPECTRAL_OUTPOST.id);break;case SKY_OUTPOST.id:i=skythrone_buildings;s=false;aZ("cityIdx : "+u+", SKY_OUTPOST.id : "+SKY_OUTPOST.id);break;case CAVE_OUTPOST.id:i=cave_buildings;s=false;aZ("cityIdx : "+u+", CAVE_OUTPOST.id : "+CAVE_OUTPOST.id);break;case LUNA_OUTPOST.id:i=luna_buildings;s=false;aZ("cityIdx : "+u+", LUNA_OUTPOST.id : "+LUNA_OUTPOST.id);break;default:i=outpost_buildings;s=field_buildings;aZ("cityIdx : "+u+", default ");break}if(Seed.cities[u]){var a=Seed.cities[u];var f="tabJobBuild_cityId_"+u;var l="tabJobBuild_accordion_"+u;var c="tabJobBuild_cityList_"+u;m+="<div class="+UID["content"]+' style="margin-bottom:5px;">'+"<A><div id="+bS(f)+" class="+UID[t]+' ref="'+u+'">'+"<table width=100%>"+'	<tr><td align=center width=100% style="border-right:none">'+(a.type=="Outpost"?translate(a.name):a.name)+"</td>"+'		<td align=right style="border-right:none"><div id='+bS(l)+' ref="'+u+'"></div></td>'+"</tr></table></div></A>"+"<div id="+bS(c)+">"+"<table class="+UID["table"]+">";o.push(UID[f]);if(!Data.options.building.hide_fields&&s){for(var h=0;h<s.length;++h){var p=Seed.stats.building[s[h]].level.length-1;var d=Buildings.getLevel(u,s[h]).min;if(d<p){m+="	<tr>"+"			<td>"+"			<label><input type=checkbox id="+bS("tabJobBuild_CB_"+(u+"_"+s[h]))+" ref="+(u+"_"+s[h])+" "+(Data.options.building.level_enable[u][s[h]]?"checked":"")+" /> "+translate(s[h])+"</label>"+"			</td>"+"			<td>"+"			&nbsp;<span class=jewel>"+d+"</span>"+"			</td>"+"			<td>"+L(u,i.length+h,s[h])+"</td>"+"		</tr>";r.push(UID["tabJobBuild_CB_"+(u+"_"+s[h])])}else{Data.options.building.level_enable[u][s[h]]=false}}m+="<tr><td colspan=5><hr></td></tr>"}for(var h=0;h<i.length;++h){var p=Seed.stats.building[i[h]].level.length-1;var d=Buildings.getLevel(u,i[h]).min;if(d<p){m+="	<tr>"+"			<td>"+"			<label><input type=checkbox id="+bS("tabJobBuild_CB_"+(u+"_"+i[h]))+" ref="+(u+"_"+i[h])+" "+(Data.options.building.level_enable[u][i[h]]?"checked":"")+" /> "+translate(i[h])+"</label>"+"			</td>"+"			<td>"+"			&nbsp;<span class=jewel>"+d+"</span>"+"			</td>"+"			<td>"+L(u,h,i[h])+"</td>"+"		</tr>";r.push(UID["tabJobBuild_CB_"+(u+"_"+i[h])])}else{Data.options.building.level_enable[u][i[h]]=false}}m+="</table></div></div>"}}m+="</div>";var v=document.getElementById(UID["tabJobBuild_Content"]);v.style.height=v.offsetHeight+"px";v.innerHTML=m;for(var g=0;g<o.length;g++){document.getElementById(o[g]).addEventListener("click",M,false);var u=document.getElementById(o[g]).getAttribute("ref");var y="tabJobBuild_cityList_"+u;var b="tabJobBuild_accordion_"+u;var w=document.getElementById(UID[y]);if(Data.options.collapsed.build[u]){w.style.display="none";document.getElementById(UID[b]).innerHTML="+&nbsp"}else{w.style.display="block";document.getElementById(UID[b]).innerHTML="-&nbsp"}}for(var h=0;h<r.length;h++){document.getElementById(r[h]).addEventListener("click",k,false)}for(var u=0;u<Seed.cities.length;++u){if(Seed.cities[u]){var E;if(!Data.options.building.hide_fields){switch(u){case CAPITAL.id:E=capital_buildings.concat(field_buildings);break;case SPECTRAL_OUTPOST.id:E=spectral_buildings.concat(spectral_fields);break;case SKY_OUTPOST.id:E=skythrone_buildings;break;case CAVE_OUTPOST.id:E=cave_buildings;break;case LUNA_OUTPOST.id:E=luna_buildings;break;default:E=outpost_buildings.concat(field_buildings);break}}else{switch(u){case CAPITAL.id:E=capital_buildings;break;case SPECTRAL_OUTPOST.id:E=spectral_buildings;break;case SKY_OUTPOST.id:E=skythrone_buildings;break;case CAVE_OUTPOST.id:E=cave_buildings;break;case LUNA_OUTPOST.id:E=luna_buildings;break;default:E=outpost_buildings;break}}for(var h=0;h<E.length;++h){var p=Seed.stats.building[E[h]].level.length-1;var d=Buildings.getLevel(u,E[h]).min;if(d>=p)continue;var S=document.getElementById(UID["tabJobBuild_Cap_"+u+"_"+E[h]]);try{if(!Data.options.building.level_cap[u][h]){var x=Buildings.getLevel(u,E[h]).min;var T=x<9?9:x;S.selectedIndex=T;Data.options.building.level_cap[u][h]=T}else{S.selectedIndex=Data.options.building.level_cap[u][h];S.options[Data.options.building.level_cap[u][h]].selected=true;if(Data.options.building.level_enable[u][E[h]])e.checkBuildReqs(u,E[h])}}catch(N){}S.addEventListener("change",A,false)}}}document.getElementById(UID["tabJobBuild_HideFields"]).addEventListener("click",C,false);document.getElementById(UID["tabJobBuild_OnOff"]).addEventListener("click",function(){var e=Tabs.Jobs;e.setBuildEnable(!Data.options.building.enabled)},false);e.refreshBuildButton(Data.options.building.enabled);e.buildStatTick();e.clearTimers();e.jobsStatTimer=setInterval(e.buildStatTick,1e3)},tabJobResearch:function(){function d(e){var t=Tabs.Jobs;var n=bV(e.target.getAttribute("ref"));Data.options.research.res_enable[0][Seed.research[n]]=e.target.checked;if(Data.options.research.res_enable[0][Seed.research[n]])t.checkResearchReqs(Seed.research[n]);if(Data.options.research.enabled)t.researchTick()}function v(e){var t=Tabs.Jobs;var n=bV(e.target.getAttribute("ref"));Data.options.research.res_cap[0][Seed.research[n]]=e.target[e.target.selectedIndex].value;e.target.style.backgroundColor="";if(Data.options.research.res_enable[0][Seed.research[n]])t.checkResearchReqs(Seed.research[n]);if(Data.options.research.enabled)t.researchTick()}var e=Tabs.Jobs;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabJobResearch"]).className="selected";document.getElementById(UID["tabJobResearch"]).style.zIndex=1;e.lastSubTab="tabJobResearch";e.contentType=3;var t="<div class="+UID["title"]+">"+translate("Research")+" "+translate("Automatically")+"</div>"+"<div class="+UID["status_ticker"]+">"+"	<center><input id="+bS("tabJobResearch_OnOff")+" type=button /></center>"+"	<div id="+bS("tabJobResearch_Report")+" class="+UID["status_report"]+">"+"		<table id="+bS("tabJobResearch_Table")+" class="+UID["table"]+">"+"		</table>"+"	</div><br>"+"	<div id="+bS("tabJobResearch_Feedback")+" class="+UID["status_feedback"]+"></div>"+"</div>";document.getElementById(UID["tabJob_Header"]).style.height="205px";document.getElementById(UID["tabJob_Header"]).innerHTML=t;var n="<div id="+bS("tabJobResearch_Config")+" class="+UID["content"]+">";var r=[];var i=Seed.cities[CAPITAL.id];n+="<div class="+UID["subtitle"]+">"+i.name+"</div>"+"<table class="+UID["table"]+">";var s=0;for(var o=0;o<Seed.research.length;o++){var u=Seed.research[o];var a=Seed.player.research[u]||0;n+="	<tr>"+"			<td>"+"			<label>"+"			<input type=checkbox id="+bS("tabJobResearch_CB_"+u)+" "+(Data.options.research.res_enable[0][u]?"checked":"")+" ref="+s+" /> "+translate(u)+"			</label>"+"			</td>"+"			<td>"+"				<span class=jewel><b>"+a+"</b></span>"+"			</td>"+"			<td>";var f=(Seed.stats.research[u].level.length||12)-1;if(a!=f){n+="	<td>"+"		<select id="+bS("tabJobResearch_Sel_"+u)+" ref="+s+">";for(var l=0;l<=f;l++)n+="<option value="+l+(a>l?' style="display:none;"':"")+">"+l+"</option>";n+="	</select>"+"		</td>";r.push(UID["tabJobResearch_CB_"+u])}else{n+="	<td>Max</td>"}n+="<td id="+bS("tabJobResearch_FB_"+u)+' class=jewel valign=top style="width:250px;white-space:normal;"></td></tr>';++s}n+="</table></div>";document.getElementById(UID["tabJob_Content"]).style.height="480px";document.getElementById(UID["tabJob_Content"]).innerHTML=n;for(var s=0;s<r.length;++s){$(r[s]).addEventListener("click",d,false)}for(var o=0;o<Seed.research.length;o++){var u=Seed.research[o];var c=document.getElementById(UID["tabJobResearch_Sel_"+u]);if(c){try{if(!Data.options.research.res_cap[0][u]){var h=e.getCurrentResearchLevel(u);c.selectedIndex=h;Data.options.research.res_cap[0][u]=h}else{c.selectedIndex=Data.options.research.res_cap[0][u];c.options[Data.options.research.res_cap[0][u]].selected=true;if(Data.options.research.res_enable[0][u]){e.checkResearchReqs(u)}}}catch(p){}c.addEventListener("change",v,false)}}document.getElementById(UID["tabJobResearch_OnOff"]).addEventListener("click",function(){var e=Tabs.Jobs;e.setResearchEnable(!Data.options.research.enabled)},false);e.refreshResearchButton(Data.options.research.enabled);e.researchStatTick();e.clearTimers();e.jobsStatTimer=setInterval(e.researchStatTick,1e3)},tabJobResurrect:function(){function b(e){var t=bV(e.target.getAttribute("ref"));document.getElementById(UID["tabJobResurrect_Troop_"+t]).value=Seed.cities[CAPITAL.id].souls[all_unit_types[t]]}function w(e){var t=bV(e.target.getAttribute("ref"));document.getElementById(UID["tabJobResurrect_Troop_"+t]).value=0}function E(e){var t=Tabs.Jobs;var n=bV(e.target.getAttribute("ref"));Data.options.resurrect.res_enable[SPECTRAL_OUTPOST.id][all_unit_types[n]]=e.target.checked;if(Data.options.resurrect.res_enable[SPECTRAL_OUTPOST.id][all_unit_types[n]]){var r=Seed.cities[CAPITAL.id].souls[all_unit_types[n]];if(!r||isNaN(r))r=0;var i=Data.options.resurrect.res_max[SPECTRAL_OUTPOST.id][all_unit_types[n]];var s=r>i?i:r;t.checkResurrectReqs(all_unit_types[n],s)}else{try{document.getElementById(UID["tabJobResurrect_FB_"+n]).innerHTML="";document.getElementById(UID["tabJobResurrect_Troop_"+n]).style.backgroundColor="none"}catch(o){}}if(Data.options.resurrect.enabled)t.resurrectTick()}function S(e){var t=Tabs.Jobs;var n=bV(e.target.getAttribute("ref"));Data.options.resurrect.res_max[SPECTRAL_OUTPOST.id][all_unit_types[n]]=e.target.value;e.target.style.backgroundColor="";if(Data.options.resurrect.res_enable[SPECTRAL_OUTPOST.id][all_unit_types[n]]){var r=Seed.cities[CAPITAL.id].souls[all_unit_types[n]];if(!r||isNaN(r))r=0;var i=Data.options.resurrect.res_max[SPECTRAL_OUTPOST.id][all_unit_types[n]];var s=r>i?i:r;t.checkResurrectReqs(all_unit_types[n],s)}if(Data.options.resurrect.enabled)t.resurrectTick()}var e=Tabs.Jobs;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabJobResurrect"]).className="selected";document.getElementById(UID["tabJobResurrect"]).style.zIndex=1;e.lastSubTab="tabJobResurrect";e.contentType=4;var t="<div class="+UID["title_sr"]+">"+translate("revive-troops")+"</div>"+"<div class="+UID["status_ticker"]+">"+"	<center><input id="+bS("tabJobResurrect_OnOff")+" type=button /></center>"+"	<div id="+bS("tabJobResurrect_Report")+" class="+UID["status_report"]+">"+"		<table id="+bS("tabJobResurrect_Table")+" class="+UID["table"]+">"+"		</table>"+"	</div>"+"	<br>"+"	<div id="+bS("tabJobResurrect_Feedback")+" class="+UID["status_feedback"]+"></div>"+"</div>";document.getElementById(UID["tabJob_Header"]).style.height="205px";document.getElementById(UID["tabJob_Header"]).innerHTML=t;var n="<div id="+bS("tabJobResurrect_Config")+" class="+UID["content"]+">";var r=[],i=[],s=[];var o=Seed.cities[CAPITAL.id];var u=er(),a="";if(u&&u.max>0){var f=u.min/u.max*1e4;var a=bD(u.min," ")+" / "+bD(u.max," ")+" ("+bD(Math.round(f/100)," ")+"%)"}else a="";n+="<div class="+UID["subtitle"]+">"+"	<table class="+UID["table"]+" width=100%>"+"	<tr>"+"		<td align=left width=25%>&nbsp;</td>"+"		<td align=center width=40%>"+translate(Seed.cities[SPECTRAL_OUTPOST.id].name)+"</td>"+"		<td align=right width=25%><font color=yellow>"+a+"</font></td>"+"	</tr>"+"</table></div>"+"<table class="+UID["table"]+">"+"	<tr class="+UID["row_headers"]+">"+"		<td></td><td>"+translate("Quantity")+"</td><td>"+translate("revive-troops-total-souls")+"</td><td>"+translate("Action")+"</td><td>"+translate("Total")+"</td></tr>";for(var l=0;l<all_unit_types.length;l++){var c=Data.options.resurrect.res_max[SPECTRAL_OUTPOST.id][all_unit_types[l]];if(!c||isNaN(c))c=0;var h=o.souls[all_unit_types[l]];if(!h||isNaN(h))h=0;if(/(DarkSlayer|Harrier|ShadowStalker|WarScarab|VoltRanger)/.test(all_unit_types[l])){n+="<tr>"+"		<td width=1% align=left>&nbsp</td>"+"		<td width=25%>"+"			<label>"+translate(all_unit_types[l])+"</label>"+"		</td>"+"		<td align=right width=10%><div id="+bS("tabJobResurrect_Troop_"+l)+" ref="+l+">N/A</div></td>"+"      <td></td>"+"		<td align=right width=10%>&nbsp;"+bD(h," ")+"</td>"+"		<td align=right width=10%>&nbsp;<span class=jewel>("+bD(aV(Seed.cities[CAPITAL.id],all_unit_types[l]).total," ")+")</span></td>"+"		<td id="+bS("tabJobResurrect_FB_"+l)+' class=jewel valign=top style="width:250px;white-space:normal;"></td>'+"		</tr>"}else{n+="<tr>"+"		<td width=1% align=left><label>"+"			<input type=checkbox id="+bS("tabJobResurrect_CB_"+l)+" "+(Data.options.resurrect.res_enable[SPECTRAL_OUTPOST.id][all_unit_types[l]]?"checked":"")+" ref="+l+" /> "+"		</label></td>"+"		<td width=25%>"+"			<label>"+translate(all_unit_types[l])+"</label>"+"		</td>"+"		<td align=middle width=10%><input type=text id="+bS("tabJobResurrect_Troop_"+l)+" ref="+l+' maxlength=8 size=3 value="'+c+'" style="width:60px; text-align:right;" /></td>'+"      <td align=middle width=10%>"+"          <input id="+bS("tabJobResurrect_MaxTroop_"+l)+" ref="+l+' class="Xtrasmall '+UID["btn_blue"]+'" style="width:auto !important;" type=button value='+translate("Max")+" />"+"          <input id="+bS("tabJobResurrect_ClearTroop_"+l)+" ref="+l+' class="Xtrasmall '+UID["btn_blue"]+'" style="width:auto !important;" type=button value=X />'+"      </td>"+"		<td align=right width=10%>&nbsp;"+bD(h," ")+"</td>"+"		<td align=right width=10%>&nbsp;<span class=jewel>("+bD(aV(Seed.cities[CAPITAL.id],all_unit_types[l]).total," ")+")</span></td>"+"		<td id="+bS("tabJobResurrect_FB_"+l)+' class=jewel valign=top style="width:250px;white-space:normal;"></td>'+"		</tr>";r.push(UID["tabJobResurrect_CB_"+l]);i.push(UID["tabJobResurrect_MaxTroop_"+l]);s.push(UID["tabJobResurrect_ClearTroop_"+l])}}n+="</table></div>";document.getElementById(UID["tabJob_Content"]).style.height="450px";document.getElementById(UID["tabJob_Content"]).innerHTML=n;for(var l=0;l<r.length;++l){$(r[l]).addEventListener("click",E,false)}for(var l=0;l<i.length;++l){$(i[l]).addEventListener("click",b,false)}for(var l=0;l<s.length;++l){$(s[l]).addEventListener("click",w,false)}for(var p=0;p<all_unit_types.length;p++){var d=document.getElementById(UID["tabJobResurrect_Troop_"+p]);try{var v=o.souls[all_unit_types[p]];if(!v||isNaN(v))v=0;if(!Data.options.resurrect.res_max[SPECTRAL_OUTPOST.id][all_unit_types[p]]){d.value=v;Data.options.resurrect.res_max[SPECTRAL_OUTPOST.id][all_unit_types[p]]=v}else{d.value=resurrect.res_max[SPECTRAL_OUTPOST.id][all_unit_types[p]];if(Data.options.resurrect.res_max[SPECTRAL_OUTPOST.id][all_unit_types[p]]){var m=Data.options.resurrect.res_max[SPECTRAL_OUTPOST.id][all_unit_types[p]];var g=v>m?m:v;e.checkResurrectReqs(all_unit_types[p],g)}}}catch(y){}d.addEventListener("change",S,false)}document.getElementById(UID["tabJobResurrect_OnOff"]).addEventListener("click",function(){var e=Tabs.Jobs;e.setResurrectEnable(!Data.options.resurrect.enabled)},false);e.refreshResurrectButton(Data.options.resurrect.enabled);e.resurrectStatTick();e.clearTimers();e.jobsStatTimer=setInterval(e.resurrectStatTick,1e3)},tabJobSanctuary:function(){var e=Tabs.Jobs;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabJobSanctuary"]).className="selected";document.getElementById(UID["tabJobSanctuary"]).style.zIndex=1;e.lastSubTab="tabJobSanctuary";e.contentType=5;var t="<div class="+UID["title"]+">"+translate("dragon-sanctuary")+"</div>"+"<div class="+UID["status_ticker"]+' style="margin-bottom: 5px !important">'+"	<center><input id="+bS("tabJobSanctFeeding_OnOff")+" type=button /></center>"+"	<div id="+bS("tabJobSanct_Report")+" class="+UID["status_report"]+">"+"		<table id="+bS("tabJobSanct_TableJobs")+" class="+UID["table"]+">"+"		</table>"+"	</div>"+"	<br>"+"	<div id="+bS("tabJobSanct_Feedback")+" class="+UID["status_feedback"]+"></div>"+"</div>"+"<ul class=tabs>"+'	<li class="tab first"><a id='+bS("tabJobSanct_tabDragons")+">"+translate("Dragons")+"</a></li>"+'	<li class="tab"><a id='+bS("tabJobSanct_tabBreeding")+">"+translate("breeding-dragon")+"</a></li>"+'	<li class="tab"><a id='+bS("tabJobSanct_tabFeeding")+">"+translate("upgrading-dragon")+"</a></li>"+"</ul>";document.getElementById(UID["tabJob_Header"]).style.height="225px";document.getElementById(UID["tabJob_Header"]).innerHTML=t;var n="<div id="+bS("tabJobSanct_Content")+' style="height:430px; ; max-height:430px; overflow-y:auto">';document.getElementById(UID["tabJob_Content"]).style.height="430px";document.getElementById(UID["tabJob_Content"]).innerHTML=n;document.getElementById(UID["tabJobSanct_tabDragons"]).addEventListener("click",e.tabJobSanctDragons,false);document.getElementById(UID["tabJobSanct_tabBreeding"]).addEventListener("click",e.tabJobSanctBreeding,false);document.getElementById(UID["tabJobSanct_tabFeeding"]).addEventListener("click",e.tabJobSanctFeeding,false);document.getElementById(UID["tabJobSanctFeeding_OnOff"]).addEventListener("click",function(){var e=Tabs.Jobs;e.setFeedingEnable(!Data.options.sanctuary.enabled)},false);e.refreshFeedingButton(Data.options.sanctuary.enabled);switch(e.sanctContentType){case 0:e.tabJobSanctDragons();break;case 1:e.tabJobSanctBreeding();break;case 2:e.tabJobSanctFeeding();break}e.sanctStatTick();e.clearTimers();e.jobsStatTimer=setInterval(e.sanctStatTick,1e3)},tabJobSanctDragons:function(){function c(t){var n=bV(t.target.getAttribute("ref"));var r=bo(Seed.sanctuary_dragons[n].subtype,"rank-"+Seed.sanctuary_dragons[n].type,"dragons");var i=translate("dismiss")+" "+r;if(e.contentType==5)e.jobFeedback(i);var s={dragon_id:n,method:"delete"};MyAjax.dragonHandle(s,function(t){if(t.ok){aX(i)}else{aZ(translate("Error")+" "+i+": "+t.errmsg);aX("<B>"+translate("Error")+" "+i+"</B>: "+t.errmsg);if(e.contentType==5)e.jobFeedback(translate("Error")+" "+i+": "+t.errmsg)}e.tabJobSanctDragons()})}function h(e){if(!e||e.length==0)return"&nbsp;";var t="<table width=100%>";for(var n=0;n<e.length;n++){var r=bo("name",e[n].name.replace(/ |_/g,"-"),"boosts")+" "+e[n].level;var i=bo("description",e[n].name.replace(/ |_/g,"-"),"boosts");var s=e[n].rate<1?bD(e[n].rate*100)+"%":bD(e[n].rate);if(i.indexOf("n%")>0)i=i.substring(0,i.indexOf("n%"))+s+i.substring(i.indexOf("n%")+2);if(i.indexOf("%boost%")>0)i=i.substring(0,i.indexOf("%boost%"))+s+i.substring(i.indexOf("%boost%")+7);t+='<tr title="'+i+'"><td><span class=jewel>'+r+"</span></td></tr>"}t+="</table>";return t}function p(t){var n=bV(t.target.getAttribute("ref"));var r=bo(Seed.sanctuary_dragons[n].subtype,"rank-"+Seed.sanctuary_dragons[n].type,"dragons");var i=translate("Remove dragon from roost")+" "+r;if(e.contentType==5)e.jobFeedback(i);var s={dragon_id:n,method:"put"};MyAjax.dragonHandle(s,function(t){if(t.ok){aX(i)}else{aZ(translate("Error")+" "+i+": "+t.errmsg);aX("<B>"+translate("Error")+" "+i+"</B>: "+t.errmsg);if(e.contentType==5)e.jobFeedback(translate("Error")+" "+i+": "+t.errmsg)}e.tabJobSanctDragons()})}function d(t){var n=Buildings.getList(CAPITAL.id,"Roost"),r=false,i=0;for(var s=0;s<n.length&&!r;s++){var o=false;for(var u in Seed.sanctuary_dragons){var a=Seed.sanctuary_dragons[u];if(dY(CAPITAL.id,a.building_id).toLowerCase()=="roost"&&a.building_id==n[s].id)o=true}if(!o){r=true;i=n[s].id}}if(!r||i==0||!i)return;var f=bV(t.target.getAttribute("ref"));var a=bo(Seed.sanctuary_dragons[f].subtype,"rank-"+Seed.sanctuary_dragons[f].type,"dragons");var l=translate("select-dragon")+" "+a;if(e.contentType==5)e.jobFeedback(l);var c={dragon_id:f,method:"put",building_id:i};MyAjax.dragonHandle(c,function(t){if(t.ok){aX(l)}else{aZ(translate("Error")+" "+l+": "+t.errmsg);aX("<B>"+translate("Error")+" "+l+"</B>: "+t.errmsg);if(e.contentType==5)e.jobFeedback(translate("Error")+" "+l+": "+t.errmsg)}e.tabJobSanctDragons()})}var e=Tabs.Jobs;document.getElementById(UID["tabJobSanct_tabBreeding"]).className="";document.getElementById(UID["tabJobSanct_tabBreeding"]).style.zIndex=0;document.getElementById(UID["tabJobSanct_tabFeeding"]).className="";document.getElementById(UID["tabJobSanct_tabFeeding"]).style.zIndex=0;document.getElementById(UID["tabJobSanct_tabDragons"]).className="selected";document.getElementById(UID["tabJobSanct_tabDragons"]).style.zIndex=1;e.sanctContentType=0;var t=new Array,n=new Array,r=new Array,i=new Array,s=0,o=Buildings.getCount(CAPITAL.id,"Roost");for(var u in Seed.sanctuary_dragons){var a=Seed.sanctuary_dragons[u];if(a.gender==null||!a.gender)a.gender="";if((!a.building_id||a.building_id==null)&&a.gender!=""&&as(a.abilities))t.push(a);if((!a.building_id||a.building_id==null)&&a.gender!=""&&!as(a.abilities))i.push(a);else if(dY(CAPITAL.id,a.building_id).toLowerCase()=="roost"){n.push(a);s++}else if(dY(CAPITAL.id,a.building_id).toLowerCase()=="nest")r.push(a)}var f="<div class="+UID["status_ticker"]+' style="margin-top:6px !important">'+"<div class="+UID["subtitle"]+">"+translate("dragons")+"</div>"+"	<table class="+UID["row_style"]+" width=100%>";for(var l=0;l<t.length;l++){if(t[l].level!==undefined)f+="	<tr valign=top>"+"			<td class=left width=30%>"+bo(t[l].subtype,"rank-"+t[l].type,"dragons")+"</td>"+"			<td width=10%><label>"+translate(t[l].gender)+"</label></td>"+"			<td width=5%><label>"+t[l].level+"</label></td>"+"			<td width=55%>"+h(t[l].abilities)+"</td>"+"	</tr>"}f+="</table>"+"<br><div class="+UID["subtitle"]+">"+translate("dragonroost")+"</div>"+"	<table class="+UID["row_style"]+" width=100%>";for(var l=0;l<n.length;l++){f+="	<tr valign=top>"+"			<td class=left width=30%>"+bo(n[l].subtype,"rank-"+n[l].type,"dragons")+"<br>"+"			<input id="+bS("tabJobSanct_Remove_"+n[l].id)+" ref="+n[l].id+' class="Xtrasmall '+UID["btn_blue"]+'" style="width:auto !important;" type=submit value="'+translate("unequip").initCap()+'" />&nbsp;&nbsp;'+"			<input id="+bS("tabJobSanct_Delete_"+n[l].id)+" ref="+n[l].id+' class="Xtrasmall '+UID["btn_red"]+'" style="width:auto !important;" type=submit value="'+translate("dismiss")+'" /></td>'+"			<td width=10%><label>"+translate(n[l].gender)+"</label></td>"+"			<td width=5%><label>"+n[l].level+"</label></td>"+"			<td width=55%>"+h(n[l].abilities)+"</td>"+"	</tr>"}f+="</table>"+"<br><div class="+UID["subtitle"]+">"+bo("masterrookery",undefined,"dialogs")+" - "+Seed.sanctuary_dragons.player_slots+"</div>"+"	<table class="+UID["row_style"]+" width=100%>";for(var l=0;l<i.length;l++){f+="	<tr valign=top>"+"			<td class=left width=30%>"+bo(i[l].subtype,"rank-"+i[l].type,"dragons")+"<br>"+"			<input id="+bS("tabJobSanct_Equip_"+i[l].id)+" ref="+i[l].id+' class="Xtrasmall '+UID["btn_blue"]+'" style="width:auto !important;" type=submit value="'+translate("Equip").initCap()+'" />&nbsp;&nbsp;'+"			<input id="+bS("tabJobSanct_Delete_"+i[l].id)+" ref="+i[l].id+' class="Xtrasmall '+UID["btn_red"]+'" style="width:auto !important;" type=submit value="'+translate("dismiss")+'" /></td>'+"			<td width=10%><label>"+translate(i[l].gender)+"</label></td>"+"			<td width=5%><label>"+i[l].level+"</label></td>"+"			<td width=55%>"+h(i[l].abilities)+"</td>"+"	</tr>"}f+="</table>"+"<br><div class="+UID["subtitle"]+">"+translate("dragonnest")+"</div>"+"	<table class="+UID["row_style"]+" width=100%>";for(var l=0;l<r.length;l++){f+="	<tr valign=top>"+"			<td class=left width=30%>"+bo(r[l].subtype,"rank-"+r[l].type,"dragons")+"</td>"+"			<td width=10%><label>"+translate(r[l].gender)+"</label></td>"+"			<td width=5%><label>"+r[l].level+"</label></td>"+"			<td width=55%>"+h(r[l].abilities)+"</td>"+"	</tr>"}f+="</table>"+"</div>";document.getElementById(UID["tabJobSanct_Content"]).innerHTML=f;for(var l=0;l<n.length;l++){document.getElementById(UID["tabJobSanct_Remove_"+n[l].id]).addEventListener("click",p,false);document.getElementById(UID["tabJobSanct_Delete_"+n[l].id]).addEventListener("click",c,false)}for(var l=0;l<i.length;l++){document.getElementById(UID["tabJobSanct_Delete_"+i[l].id]).addEventListener("click",c,false);document.getElementById(UID["tabJobSanct_Equip_"+i[l].id]).addEventListener("click",d,false);if(o<=s)bG(document.getElementById(UID["tabJobSanct_Equip_"+i[l].id]),false);else bG(document.getElementById(UID["tabJobSanct_Equip_"+i[l].id]),true)}},tabJobSanctBreeding:function(){function n(){var e=false,t=false,n=0;var r=Jobs.getJobs("breeding",true,-1);if(r&&r.length>0)e=true;var i=Buildings.getCount(CAPITAL.id,"Nest"),s=0;for(var o in Seed.sanctuary_dragons){var u=Seed.sanctuary_dragons[o];if(dY(CAPITAL.id,u.building_id).toLowerCase()=="nest")s++;if(u.gender!=""&&!as(u.abilities))n++}if(i-s>0&&n<Seed.sanctuary_dragons.player_slots)t=true;else t=false;if(!e&&t)return true;else return false}function r(e){var t="<table width=100%>"+"	<tr valign=top>"+"		<td width=30%><label>"+translate("Level")+"</label></td>"+"		<td width=70%><label>"+e.level+"</label></td>"+"	</tr>"+"	<tr valign=top>"+"		<td width=30%><label>"+translate("Capacity")+"</label></td>"+"		<td width=70%>";if(!e.abilities||e.abilities.length==0)t+="&nbsp;</td></tr>";else{t+="<table width=100%>";for(var n=0;n<e.abilities.length;n++){var r=bo("name",e.abilities[n].name.replace(/ |_/g,"-"),"boosts")+" "+e.abilities[n].level;var i=bo("description",e.abilities[n].name.replace(/ |_/g,"-"),"boosts");var s=e.abilities[n].rate<1?bD(e.abilities[n].rate*100)+"%":bD(e.abilities[n].rate);if(i.indexOf("n%")>0)i=i.substring(0,i.indexOf("n%"))+s+i.substring(i.indexOf("n%")+2);if(i.indexOf("%boost%")>0)i=i.substring(0,i.indexOf("%boost%"))+s+i.substring(i.indexOf("%boost%")+7);t+='<tr title="'+i+'"><td><span class=jewel>'+r+"</span></td></tr>"}t+="</table></td></tr>"}t+="</table>";return t}function i(e,t){var n=false,r=[];var i='<select id="'+bS("tabJobSanct_dragonid_"+t)+'" ref='+t+">";for(var s in Seed.sanctuary_dragons){var o=Seed.sanctuary_dragons[s];if(o.gender&&o.gender!=null&&o.gender==(t=="M"?"male":"female")&&o.level>=8)r.push(o)}for(var u=0;u<r.length;u++){var a="";if(r[u].id==e){a="selected";n=true}i+='<option value="'+r[u].id+'" '+a+">"+bo(r[u].subtype,"rank-"+r[u].type,"dragons")+"</option>"}if(!n)a="selected";else a="";i+='<option value="0" '+a+">"+translate("None")+"</option>";i+="</select>";return i}function s(e){var t=e.target.id;var n=e.target.getAttribute("ref");var i=document.getElementById(t);var s=bK(i.value,"0");i.value=s;if(n=="M"){var u=document.getElementById(UID["tabJobSanct_maleInfos"]);Data.options.sanctuary.male_id=s}else{var u=document.getElementById(UID["tabJobSanct_femaleInfos"]);Data.options.sanctuary.female_id=s}if(s=="0"){u.innerHTML="&nbsp;";bG(document.getElementById(UID["tabJobSanct_breed"]),false)}else{u.innerHTML=r(Seed.sanctuary_dragons[s]);o()}}function o(){var e=n();if(e){if(Data.options.sanctuary.male_id&&Data.options.sanctuary.male_id!="0"&&Data.options.sanctuary.female_id&&Data.options.sanctuary.female_id!="0"){bG(document.getElementById(UID["tabJobSanct_breed"]),true)}else{bG(document.getElementById(UID["tabJobSanct_breed"]),false)}}else bG(document.getElementById(UID["tabJobSanct_breed"]),false)}function u(){var e=Tabs.Jobs;var t=n();if(t&&Data.options.sanctuary.male_id&&Data.options.sanctuary.male_id!="0"&&Data.options.sanctuary.female_id&&Data.options.sanctuary.female_id!="0"){var r=bo(Seed.sanctuary_dragons[Data.options.sanctuary.male_id].subtype,"rank-"+Seed.sanctuary_dragons[Data.options.sanctuary.male_id].type,"dragons");var i=bo(Seed.sanctuary_dragons[Data.options.sanctuary.female_id].subtype,"rank-"+Seed.sanctuary_dragons[Data.options.sanctuary.female_id].type,"dragons");var s=translate("dragonden-breed-dragon")+": "+r+" + "+i;if(e.contentType==5)e.jobFeedback(s);MyAjax.dragonBreeding(Data.options.sanctuary.male_id,Data.options.sanctuary.female_id,function(t){if(t.ok){aX(s);bG(document.getElementById(UID["tabJobSanct_breed"]),false)}else{aZ(translate("Error")+" "+translate("dragonden-breed-dragon")+": "+t.errmsg);aX("<B>"+translate("Error")+" "+translate("dragonden-breed-dragon")+"</B>: "+t.errmsg);if(e.contentType==5)e.jobFeedback(translate("Error")+" "+translate("dragonden-breed-dragon")+": "+t.errmsg)}})}else{bG(document.getElementById(UID["tabJobSanct_breed"]),false);if(!t)if(e.contentType==5)e.jobFeedback(translate("No nest available for new egg"));else if(e.contentType==5)e.jobFeedback(translate("No great dragon defined"))}}var e=Tabs.Jobs;document.getElementById(UID["tabJobSanct_tabDragons"]).className="";document.getElementById(UID["tabJobSanct_tabDragons"]).style.zIndex=0;document.getElementById(UID["tabJobSanct_tabBreeding"]).className="selected";document.getElementById(UID["tabJobSanct_tabBreeding"]).style.zIndex=1;document.getElementById(UID["tabJobSanct_tabFeeding"]).className="";document.getElementById(UID["tabJobSanct_tabFeeding"]).style.zIndex=0;e.sanctContentType=1;var t="<div class="+UID["status_ticker"]+' style="margin-top:6px !important">'+"<div class="+UID["subtitle"]+">"+translate("breeding-dragon")+"</div>"+"	<table class="+UID["table"]+" width=100%>"+"		<tr class="+UID["row_headers"]+">"+"			<td valign=middle width=50%><b>"+translate("Male")+"</b></td>"+"			<td valign=middle width=50%><b>"+translate("Female")+"</b></td>"+"		</tr>"+"		<tr>"+"			<td align=center>"+i(Data.options.sanctuary.male_id,"M")+"</td>"+"			<td align=center>"+i(Data.options.sanctuary.female_id,"F")+"</td>"+"		</tr>"+"		<tr valign=top>"+"			<td align=center><div id="+bS("tabJobSanct_maleInfos")+"></div></td>"+"			<td align=center><div id="+bS("tabJobSanct_femaleInfos")+"></div></td>"+"		</tr>"+"	</table>"+'	<br><center><input type=button value="'+translate("dragonden-breed-dragon")+'" id='+bS("tabJobSanct_breed")+" /></center><br>"+"</div>";document.getElementById(UID["tabJobSanct_Content"]).innerHTML=t;document.getElementById(UID["tabJobSanct_dragonid_M"]).addEventListener("change",s,false);document.getElementById(UID["tabJobSanct_dragonid_F"]).addEventListener("change",s,false);document.getElementById(UID["tabJobSanct_breed"]).addEventListener("click",u,false);if(Data.options.sanctuary.male_id&&Data.options.sanctuary.male_id!="0")document.getElementById(UID["tabJobSanct_maleInfos"]).innerHTML=r(Seed.sanctuary_dragons[Data.options.sanctuary.male_id]);else document.getElementById(UID["tabJobSanct_maleInfos"]).innerHTML="&nbsp;";if(Data.options.sanctuary.female_id&&Data.options.sanctuary.female_id!="0")document.getElementById(UID["tabJobSanct_femaleInfos"]).innerHTML=r(Seed.sanctuary_dragons[Data.options.sanctuary.female_id]);else document.getElementById(UID["tabJobSanct_femaleInfos"]).innerHTML="&nbsp;";o()},tabJobSanctFeeding:function(){function p(e){var t=Tabs.Jobs;var n=bV(e.target.getAttribute("ref"));Data.options.sanctuary.feeding[n].cap=e.target[e.target.selectedIndex].value;e.target.style.backgroundColor="";if(Data.options.sanctuary.feeding[n].enable)t.checkFeedingReqs(n);if(Data.options.sanctuary.enabled)t.feedingTick()}function d(e){var t=Tabs.Jobs;var n=bV(e.target.getAttribute("ref"));Data.options.sanctuary.feeding[n].enable=e.target.checked;if(Data.options.sanctuary.feeding[n].enable)t.checkFeedingReqs(n);if(Data.options.sanctuary.enabled)t.feedingTick()}function v(e){if(!e||e.length==0)return"&nbsp;";var t="<table width=100%>";for(var n=0;n<e.length;n++){var r=bo("name",e[n].name.replace(/ |_/g,"-"),"boosts")+" "+e[n].level;var i=bo("description",e[n].name.replace(/ |_/g,"-"),"boosts");var s=e[n].rate<1?bD(e[n].rate*100)+"%":bD(e[n].rate);if(i.indexOf("n%")>0)i=i.substring(0,i.indexOf("n%"))+s+i.substring(i.indexOf("n%")+2);if(i.indexOf("%boost%")>0)i=i.substring(0,i.indexOf("%boost%"))+s+i.substring(i.indexOf("%boost%")+7);t+='<tr title="'+i+'"><td><span class=jewel>'+r+"</span></td></tr>"}t+="</table>";return t}var e=Tabs.Jobs;document.getElementById(UID["tabJobSanct_tabDragons"]).className="";document.getElementById(UID["tabJobSanct_tabDragons"]).style.zIndex=0;document.getElementById(UID["tabJobSanct_tabBreeding"]).className="";document.getElementById(UID["tabJobSanct_tabBreeding"]).style.zIndex=0;document.getElementById(UID["tabJobSanct_tabFeeding"]).className="selected";document.getElementById(UID["tabJobSanct_tabFeeding"]).style.zIndex=1;e.sanctContentType=2;var t="<div class="+UID["status_ticker"]+' style="margin-top:6px !important">'+"<div class="+UID["subtitle"]+">"+translate("upgrading-dragon")+"</div>"+"	<table class="+UID["row_style"]+" width=100%>";var r=[];for(var i in Data.options.sanctuary.feeding){var s=Data.options.sanctuary.feeding[i];if(!Seed.sanctuary_dragons[i]){delete Data.options.sanctuary.feeding[i];continue}var o=Seed.sanctuary_dragons[i];if(as(o.abilities)||o.level<1)continue;t+="	<tr valign=top>"+"			<td align=left width=35%><input type=checkbox id="+bS("tabJobFeeding_CB_"+i)+" "+(s.enable?"checked":"")+" ref="+i+" /> "+translate(bo(o.subtype,"rank-"+o.type,"dragons"))+"			<br><div id="+bS("tabJobFeeding_FB_"+i)+' class=jewel valign=top style="width:100%;white-space:normal;"></div>'+"			</td>"+"			<td width=10%><label>"+translate(o.gender)+"</label></td>"+"			<td width=5%><label>"+o.level+"</label></td>"+"			<td>";var u=Seed.requirements.dragon.feeding.level.length-1||10;if(o.level<u){t+="	<td with=5%>"+"		<select id="+bS("tabJobFeeding_Sel_"+i)+" ref="+i+">";for(var a=0;a<=u;a++)t+="<option value="+a+(o.level>a?' style="display:none;"':"")+">"+a+"</option>";t+="	</select>"+"		</td>";r.push(UID["tabJobFeeding_CB_"+i])}else{t+="	<td with=5%>Max</td>"}t+="		<td width=45%>"+v(o.abilities)+"</td>"}t+="</table></div></div>";document.getElementById(UID["tabJobSanct_Content"]).innerHTML=t;for(var f=0;f<r.length;++f){document.getElementById(r[f]).addEventListener("click",d,false);document.getElementById(r[f]).addEventListener("change",d,false);var i=bV(document.getElementById(r[f]).getAttribute("ref"));var l=document.getElementById(UID["tabJobFeeding_Sel_"+i]);if(l){try{if(!Data.options.sanctuary.feeding[i]){var c=Seed.sanctuary_dragons[i].level;l.selectedIndex=c;Data.options.sanctuary.feeding[i].cap=c}else{l.selectedIndex=Data.options.sanctuary.feeding[i].cap;l.options[Data.options.sanctuary.feeding[i].cap].selected=true;if(Data.options.sanctuary.feeding[n].enable)e.checkFeedingReqs(i)}}catch(h){}l.addEventListener("change",p,false)}}},setTrainEnable:function(e){var t=Tabs.Jobs;t.refreshTrainButton(e);Data.options.training.enabled=e;clearTimeout(t.trainTimer);if(e)t.trainTimer=setTimeout(t.trainTick,3e3);else t.jobFeedback("")},setBuildEnable:function(e){var t=Tabs.Jobs;t.refreshBuildButton(e);Data.options.building.enabled=e;clearTimeout(t.buildTimer);if(e){t.buildRetryTime=2e4;t.buildTimer=setTimeout(t.buildTick,3e3)}else t.jobFeedback("")},setResearchEnable:function(e){var t=Tabs.Jobs;t.refreshResearchButton(e);Data.options.research.enabled=e;clearTimeout(t.researchTimer);if(e){t.resRetryTime=2e4;t.researchTimer=setTimeout(t.researchTick,3e3)}else t.jobFeedback("")},setResurrectEnable:function(e){var t=Tabs.Jobs;t.refreshResurrectButton(e);Data.options.resurrect.enabled=e;clearTimeout(t.resurrectTimer);if(e){t.revRetryTime=2e4;t.resurrectTimer=setTimeout(t.resurrectTick,3e3)}else t.jobFeedback("")},setFeedingEnable:function(e){var t=Tabs.Jobs;t.refreshFeedingButton(e);Data.options.sanctuary.enabled=e;clearTimeout(t.sanctuaryTimer);if(e){t.feedRetryTime=2e4;t.sanctuaryTimer=setTimeout(t.feedingTick,3e3)}else t.jobFeedback("")},refreshTrainButton:function(e){var t=Tabs.Jobs;var n=document.getElementById(UID["tabJobTrain_OnOff"]);if(!n)return;if(e){n.value=translate("Training").toUpperCase();n.className=UID["btn_on"]}else{n.value=translate("Disabled").toUpperCase();n.className=UID["btn_off"]}},refreshBuildButton:function(e){var t=Tabs.Jobs;var n=document.getElementById(UID["tabJobBuild_OnOff"]);if(!n)return;if(e){n.value=translate("Building").toUpperCase();n.className=UID["btn_on"]}else{n.value=translate("Disabled").toUpperCase();n.className=UID["btn_off"]}},refreshResearchButton:function(e){var t=Tabs.Jobs;var n=document.getElementById(UID["tabJobResearch_OnOff"]);if(!n)return;if(e){n.value=translate("Researching").toUpperCase();n.className=UID["btn_on"]}else{n.value=translate("Disabled").toUpperCase();n.className=UID["btn_off"]}},refreshResurrectButton:function(e){var t=Tabs.Jobs;var n=document.getElementById(UID["tabJobResurrect_OnOff"]);if(!n)return;if(e){n.value=translate("Reviving").toUpperCase();n.className=UID["btn_on"]}else{n.value=translate("Disabled").toUpperCase();n.className=UID["btn_off"]}},refreshFeedingButton:function(e){var t=Tabs.Jobs;var n=document.getElementById(UID["tabJobSanctFeeding_OnOff"]);if(!n)return;if(e){n.value=translate("Upgrade").toUpperCase();n.className=UID["btn_on"]}else{n.value=translate("Disabled").toUpperCase();n.className=UID["btn_off"]}},trainStatTick:function(){var e=Tabs.Jobs,t=all_unit_types;var n=document.getElementById(UID["tabJobTrain_Table"]);if(n!=null)Jobs.updateTrainTable(n,"units");for(var r=0;r<Seed.cities.length;++r){if(Seed.cities[r]&&r>=0&&r<Seed.cities.length&&r!=SPECTRAL_OUTPOST.id&&r!=SKY_OUTPOST.id&&r!=LUNA_OUTPOST.id){if(e.contentType==1&&e.trainContentType==0){for(var i=0;i<t.length;i++){if(!da(r,t[i]))continue;var s=Data.options.training.city[r].units[i];var o=document.getElementById(UID["tabTrain_Now_"+r+"_"+i]);if(bV(s)>0){var u=e.checkTrainReqs(t[i],s,r);if(!u.msg)bG(o,true,"btn_green");else bG(o,false,"btn_green")}else bG(o,false,"btn_green")}}}}},resurrectStatTick:function(){var e=Tabs.Jobs;var t=document.getElementById(UID["tabJobResurrect_Table"]);if(t!=null)Jobs.updateTrainTable(t,"resurrection",true)},sanctStatTick:function(){var e=Tabs.Jobs;var t=document.getElementById(UID["tabJobSanct_TableJobs"]);if(t!=null)Jobs.updateSanctuaryTable(t);if(e.contentType==5&&e.sanctContentType==2){for(var n in Data.options.sanctuary.feeding){if(Data.options.sanctuary.feeding[n].enable)e.checkFeedingReqs(n);else try{document.getElementById(UID["tabJobFeeding_FB_"+n]).innerHTML=""}catch(r){}}}},buildStatFetch:false,buildStatTick:function(){var e=Tabs.Jobs;if(e.buildRefreshLvl)return;var t=document.getElementById(UID["tabJobBuild_Table"]);if(t!=null)Jobs.updateBuildTable(t);for(var n=0;n<Seed.cities.length;++n){if(Seed.cities[n]){if(e.contentType==2){if(e.buildRefreshTab)setTimeout(function(){e.buildRefreshTab=false;e.tabJobBuild()},1e3);else{var r;switch(n){case CAPITAL.id:r=capital_buildings.concat(field_buildings);break;case SPECTRAL_OUTPOST.id:r=spectral_buildings.concat(spectral_fields);break;case SKY_OUTPOST.id:r=skythrone_buildings;break;case CAVE_OUTPOST.id:r=cave_buildings;break;case LUNA_OUTPOST.id:r=luna_buildings;break;default:r=outpost_buildings.concat(field_buildings);break}for(var i=0;i<r.length;++i){if(Data.options.building.level_enable[n][r[i]])e.checkBuildReqs(n,r[i])}}}}}},resStatFetch:false,researchStatTick:function(){var e=Tabs.Jobs;if(e.contentType==3){for(var t=0;t<Seed.research.length;t++){var n=Seed.research[t];if(Data.options.research.res_enable[0][n])e.checkResearchReqs(n);else try{document.getElementById(UID["tabJobResearch_FB_"+n]).innerHTML=""}catch(r){}}var i=Jobs.getJobs("research",true,CAPITAL.id);if(i.length>0){try{document.getElementById(UID["tabJobResearch_FB_"+i[0].research_type]).innerHTML="<font color=#000>"+translate("Researching")+"&nbsp;"+translate("Level").toLowerCase()+"&nbsp;"+i[0].level+"</font>"}catch(r){}}}var s=document.getElementById(UID["tabJobResearch_Table"]);if(s!=null)Jobs.updateResearchTable(s)},jobFeedback:function(e){var t=Tabs.Jobs;var n="";switch(t.contentType){case 0:break;case 1:n="tabJobTrain_Feedback";break;case 2:n="tabJobBuild_Feedback";break;case 3:n="tabJobResearch_Feedback";break;case 4:n="tabJobResurrect_Feedback";break;case 5:n="tabJobSanct_Feedback";break}if(n)aS(UID[n],e)},getCurrentResearchLevel:function(e){var t=Tabs.Jobs,n=0;try{if(e=="Rapid Deployment")e="RapidDeployment";if(e=="Weapons Calibration")e="Ballistics";if(e=="Aerial Combat")e="AerialCombat";n=Seed.player.research[e]?Seed.player.research[e]:0}catch(r){}return n},getTroopCap:function(e,t){var n=Tabs.Jobs;var r=0;var i=0;var s=0;var o=0;var u=0;for(var a=0;a<all_unit_types.length;a++){if(e==all_unit_types[a]){r=Data.options.training.city[0].cap[a];break}}if(r==0)return r;i+=Seed.cities[CAPITAL.id].units[e]!=undefined?Seed.cities[CAPITAL.id].units[e]:0;if(Seed.cities[CAPITAL.id].defense_force&&Seed.cities[CAPITAL.id].defense_force[e])s+=Seed.cities[CAPITAL.id].defense_force[e]!=undefined?Seed.cities[CAPITAL.id].defense_force[e]:0;for(var f in Data.marches){if(!/(attacks|waves|spies|multiple|bookmark|transport)/.test(f))continue;for(var l in Data.marches[f]){var c=Data.marches[f][l];for(var h in c.units){if(h==e)o+=c.units[h]}}}var p=be();for(var d=0;d<Seed.cities.length;++d){if(Seed.cities[d]&&Seed.cities[d].jobs){var v=Seed.cities[d].jobs;for(var m=0;m<v.length;m++){if(v[m].queue=="units"&&v[m].unit_type==e&&v[m].run_at>p)u+=v[m].quantity}}}return i+s+o+u+t>r?i+s+o+u+t:0},getBuildingCap:function(e,t){var n=Tabs.Jobs;var r=0;var i;switch(e){case CAPITAL.id:i=capital_buildings.concat(field_buildings);break;case SPECTRAL_OUTPOST.id:i=spectral_buildings.concat(spectral_fields);break;case SKY_OUTPOST.id:i=skythrone_buildings;break;case CAVE_OUTPOST.id:i=cave_buildings;break;case LUNA_OUTPOST.id:i=luna_buildings;break;default:i=outpost_buildings.concat(field_buildings);break}for(var s=0;s<i.length;++s){if(i[s]==t){try{r=Data.options.building.level_cap[e][s]?Data.options.building.level_cap[e][s]:0;break}catch(o){}}}return r},getResearchCap:function(e){var t=Tabs.Jobs;var n=0;for(var r=0;r<Seed.research.length;r++){var i=Seed.research[r];if(e==i){try{n=Data.options.research.res_cap[0][i]?Data.options.research.res_cap[0][i]:0;break}catch(s){}}}return n},resUITranslate:function(e){var t=Tabs.Jobs;for(var n=0;n<Seed.research.length;n++){if(Seed.research[n]==e)return Seed.research[n]}return e},getBuildingLevel:function(e,t,n){var r=Seed.cities[e].buildings;var i=0;for(var s=0;s<r.length;s++){if(r[s].type==t&&r[s].level>=n){i=r[s].level;break}}return i},getRemainingQueue:function(e,t,n){var r=Seed.cities[e];var i=r.jobs;var s=n?r.figures.queue_lengths.resurrection:r.figures.queue_lengths.units;var o=0;if(isNaN(s)||!s)return 0;for(var u=0;u<i.length;u++){if(i[u].queue==t)++o}return s-o},checkRequirements:function(e){var t=Tabs.Jobs;var n={};var r=e.unit_type||e.training_type||e.building_type||e.research_type||e.sanctuary_type;var i=Seed.requirements[e.reqs_type][r];var s=Seed.stats[e.reqs_type][r];if(typeof e.level!=="undefined"){i=i.level[e.level];s=s.level[e.level]}var o=e.city_idx||CAPITAL.id;var u=Seed.cities[CAPITAL.id];if(e.unit_type||e.reqs_type=="units"){n.max_units=999999999;var a=da(e.city_idx,e.unit_type);if(!a){n.msg=translate("Unit not trainable");return n}}var f=1;var l=s.time;switch(e.reqs_type){case"unit":f=0;if(Seed.cities[o]&&o!=SPECTRAL_OUTPOST.id&&o!=SKY_OUTPOST.id&&o!=LUNA_OUTPOST.id){var c="TrainingCamp";if(o==CAVE_OUTPOST.id)c="CaveTrainingCamp";if(o==CAPITAL.id)c="Garrison";var h=0,p=0;for(var d=0;d<Seed.cities[o].buildings.length;d++){if(Seed.cities[o].buildings[d].type===c){p++;h+=Seed.cities[o].buildings[d].level}}f=p==0?0:p+(h-p)/10}if(o==CAPITAL.id&&(e.unit_type=="BattleDragon"||e.unit_type=="PackDragon"||e.unit_type=="SwiftStrikeDragon")){var v=Buildings.getLevel(CAPITAL.id,"Rookery").max;f*=1+v/100}if(o==FOREST_OUTPOST.id&&e.unit_type=="Titan")l=52e3;break;case"building":f=u.figures.building.speed_multiplier;break}n.time=bV(l/f);var m=e.unit_quantity||1;if(i.buildings){for(var g in i.buildings){var y=g;if(o==CAVE_OUTPOST.id)y="CaveTrainingCamp";else if(o!=CAPITAL.id&&g=="Garrison")y="TrainingCamp";var b=/Science|Metal|Officer|Rookery|Storage|Theater|Sentinel|Factory|Fortress|DefensiveTower/.test(y)?CAPITAL.id:o;var w=Buildings.getLevel(b,y);if(w.max<i.buildings[g]){if(!n.buildings)n.buildings={};n.buildings[y]=i.buildings[g];n.msg=(n.msg||"")+translate(y)+"("+n.buildings[y]+")"+" + "}}}if(i.items){for(var g in i.items){var E=i.items[g]*m;var S=bV(Seed.player.items[g]||0);if(S<E){if(!n.items)n.items={};n.items[g]=E-S;n.msg=(n.msg||"")+translate(g)+"("+bD(n.items[g]," ")+")"+" + "}if(n.max_units){var x=bV(S/i.items[g]);if(n.max_units>x)n.max_units=x}}}if(i.population&&i.population.idle){var E=i.population.idle*m;var S=u.figures.population.current-u.figures.population.laborers-u.figures.population.armed_forces;S=S>0?S:0;if(S<E){n.population=E-S;n.msg=(n.msg||"")+translate("Population")+":"+bD(n.population," ")+" + "}if(n.max_units){var x=bV((S+1)/i.population.idle);if(n.max_units>x)n.max_units=x}}if(i.research){for(var g in i.research){if(Seed.player.research[g]<i.research[g]){if(!n.research)n.research={};n.research[g]=i.research[g];n.msg=(n.msg||"")+translate(g)+"("+n.research[g]+")"+" + "}}}if(i.resources){for(var g in i.resources){if(i.resources[g]==0)continue;var E=i.resources[g]*m;var S=bV(u.resources[g]||0);if(S<E){if(!n.resources)n.resources={};n.resources[g]=E-S;n.msg=(n.msg||"")+translate(g)+":"+bD(n.resources[g]," ")+" + "}if(n.max_units){var x=bV((S+1)/i.resources[g]);if(n.max_units>x)n.max_units=x}}}if(i.units){for(var g in i.units){var E=i.units[g]*m;var S=bV(u.units[g]||0);if(S<E){if(!n.units)n.units={};n.units[g]=E-S;n.msg=(n.msg||"")+translate(g)+"("+bD(n.units[g]," ")+")"+" + "}if(n.max_units){var x=bV(S/i.units[g]);if(n.max_units>x)n.max_units=x}}}if(n.max_units)n.time=bV((e.unit_quantity||0)*s.time/f);if(n.msg)n.msg=n.msg.substring(0,n.msg.length-3);return n},checkTrainReqs:function(e,t,n){var r=Tabs.Jobs;var i=r.checkRequirements({reqs_type:"unit",city_idx:n,unit_type:e,unit_quantity:t});if(r.getRemainingQueue(n,"units",false)==0)i.queue=true;var s=r.getTroopCap(e,t);if(s){i.capped=s;i.msg=translate("Production limit reached")+" + "}if(r.contentType==1){if(i.msg){try{document.getElementById(UID["tabJobTrain_FB_"+n+"_"+e]).innerHTML='<font color="#C33">'+i.msg.replace(/:\+/,":").replace(/\+\s*$/,"")+"</font>";document.getElementById(UID["tabJobTrain_FB_"+n+"_"+e]).title=translate(e)+" "+i.msg.replace(/\+/g," \n");document.getElementById(UID["tabJobBuild_Cap_"+n+"_"+e]).style.color="#C33"}catch(o){}}else{try{var u=translate("Max")+" : "+bD(i.max_units," ")+" ("+bz(i.time)+")";document.getElementById(UID["tabJobTrain_FB_"+n+"_"+e]).innerHTML=u;document.getElementById(UID["tabJobTrain_FB_"+n+"_"+e]).title=translate(e)+" \n"+u}catch(o){}}}return i},checkBuildReqs:function(e,t){var n=Tabs.Jobs;var r=Buildings.getLevel(e,t).min+1;var i=n.getBuildingCap(e,t);if(r<=i){var s=n.checkRequirements({reqs_type:"building",city_idx:e,building_type:t,level:r});if(s.msg){if(n.contentType==2){try{document.getElementById(UID["tabJobBuild_FB_"+e+"_"+t]).innerHTML='<font color="#C33">'+s.msg.replace(/:\+/,":").replace(/\+\s*$/,"")+"</font>";document.getElementById(UID["tabJobBuild_FB_"+e+"_"+t]).title=translate(t)+" "+s.msg.replace(/\+/g," \n");document.getElementById(UID["tabJobBuild_Cap_"+e+"_"+t]).style.color="#C33"}catch(o){}}}else{if(n.contentType==2){try{var u=translate("Next level")+" "+translate("OK");document.getElementById(UID["tabJobBuild_FB_"+e+"_"+t]).innerHTML=u;document.getElementById(UID["tabJobBuild_FB_"+e+"_"+t]).title=translate(t)+" \n"+u}catch(o){}}}return s}else{if(n.contentType==2){try{var u=translate("Task Completed");document.getElementById(UID["tabJobBuild_FB_"+e+"_"+t]).innerHTML="<font color=#0B0>"+u+"</font>";document.getElementById(UID["tabJobBuild_FB_"+e+"_"+t]).title=translate(t)+" \n"+u;document.getElementById(UID["tabJobBuild_Cap_"+e+"_"+t]).style.color="#5B5"}catch(o){}}}return{capped:true,msg:translate("Maximum level reached")}},checkResearchReqs:function(e,t){var n=Tabs.Jobs;var r=n.getCurrentResearchLevel(e)+1;var i=n.getResearchCap(e);if(r<=i){var s=n.checkRequirements({reqs_type:"research",research_type:e,level:r,city_idx:t||CAPITAL.id});if(s.msg){if(n.contentType==3){try{document.getElementById(UID["tabJobResearch_FB_"+e]).innerHTML="<font color=#C33>"+s.msg.replace(/:\+/,":").replace(/\+\s*$/,"")+"</font>";document.getElementById(UID["tabJobResearch_FB_"+e]).title=translate(e)+" "+s.msg.replace(/\+/g," \n");document.getElementById(UID["tabJobResearch_Sel_"+e]).style.color="#C33"}catch(o){}}}else{if(n.contentType==3){try{var u=translate("Next level")+" "+translate("OK");document.getElementById(UID["tabJobResearch_FB_"+e]).innerHTML=u;document.getElementById(UID["tabJobResearch_FB_"+e]).title=translate(e)+" \n"+u}catch(o){}}}return s}else{if(n.contentType==3){try{var u=translate("Task Completed");document.getElementById(UID["tabJobResearch_FB_"+e]).innerHTML="<font color=#0B0>"+u+"</font>";document.getElementById(UID["tabJobResearch_FB_"+e]).title=translate(e)+" \n"+u;document.getElementById(UID["tabJobResearch_Sel_"+e]).style.color="#5B5"}catch(o){}}}return{capped:true,msg:translate("Maximum level reached")}},checkFeedingReqs:function(e){var t=Tabs.Jobs;var n=Seed.sanctuary_dragons[e];var r=n.level+1;var i=Data.options.sanctuary.feeding[e].cap||0;if(r<=i){var s=t.checkRequirements({reqs_type:"dragon",sanctuary_type:"feeding",level:r,city_idx:CAPITAL.id});if(s.msg){if(t.contentType==5&&t.sanctContentType==2){try{document.getElementById(UID["tabJobFeeding_FB_"+e]).innerHTML="<font color=#C33>"+s.msg.replace(/:\+/,":").replace(/\+\s*$/,"")+"</font>";document.getElementById(UID["tabJobFeeding_FB_"+e]).title=translate(bo(n.subtype,"rank-"+n.type,"dragons"))+" "+s.msg.replace(/\+/g," \n");document.getElementById(UID["tabJobFeeding_Sel_"+e]).style.color="#C33"}catch(o){}}}else{if(t.contentType==5&&t.sanctContentType==2){try{var u=translate("Next level")+" "+translate("OK");document.getElementById(UID["tabJobFeeding_FB_"+e]).innerHTML=u;document.getElementById(UID["tabJobFeeding_FB_"+e]).title=translate(bo(n.subtype,"rank-"+n.type,"dragons"))+" \n"+u}catch(o){}}}return s}else{if(t.contentType==5&&t.sanctContentType==2){try{var u=translate("Task Completed");document.getElementById(UID["tabJobFeeding_FB_"+e]).innerHTML="<font color=#0B0>"+u+"</font>";document.getElementById(UID["tabJobFeeding_FB_"+e]).title=translate(bo(n.subtype,"rank-"+n.type,"dragons"))+" \n"+u;document.getElementById(UID["tabJobFeeding_Sel_"+e]).style.color="#5B5"}catch(o){}}}return{capped:true,msg:translate("Maximum level reached")}},checkResurrectReqs:function(e,t){var n=Tabs.Jobs;if(n.contentType==3){try{document.getElementById(UID["tabJobResurrect_FB_"+p]).innerHTML="";document.getElementById(UID["tabJobResurrect_Troop_"+p]).style.backgroundColor="none"}catch(r){}}switch(e){case"Porter":per_unit=5;darkPortal=1;break;case"Conscript":per_unit=5;darkPortal=1;break;case"Spy":per_unit=5;darkPortal=2;break;case"Halberdsman":per_unit=5;darkPortal=2;break;case"Minotaur":per_unit=7;darkPortal=3;break;case"Longbowman":per_unit=7;darkPortal=4;break;case"SwiftStrikeDragon":per_unit=7;darkPortal=5;break;case"ArmoredTransport":per_unit=7;darkPortal=6;break;case"BattleDragon":per_unit=10;darkPortal=7;break;case"Giant":per_unit=10;darkPortal=8;break;case"FireMirror":per_unit=10;darkPortal=9;break;case"DarkSlayer":per_unit=15;darkPortal=10;break;case"DimensionalRuiner":per_unit=15;darkportal=12;break;case"LightningCannon":per_unit=15;darkPortal=11;break;case"ChargeTroop":per_unit=15;darkPortal=10;break;case"VengeWyrm":per_unit=15;darkPortal=11;break;case"AquaTroop":per_unit=15;darkPortal=10;break;case"StoneTroop":per_unit=15;darkPortal=10;break;case"FireTroop":per_unit=15;darkPortal=10;break;case"WindTroop":per_unit=15;darkPortal=10;break;case"IceTroop":per_unit=15;darkPortal=10;break;case"SwampTroop":per_unit=15;darkPortal=10;break;case"PackDragon":per_unit=15;darkPortal=11;break;case"FrostGiant":per_unit=15;darkPortal=10;break;case"ForestTroop":per_unit=15;darkPortal=10;break;case"DesertTroop":per_unit=15;darkPortal=10;break;case"ArcticLeviathan":per_unit=15;darkPortal=12;break;case"Harrier":per_unit=15;darkPortal=10;break;case"Defendo":per_unit=15;darkPortal=12;break;case"ShadowStalker":per_unit=15;darkPortal=12;break;case"Shaman":per_unit=25;darkPortal=12;break;case"WarScarab":per_unit=25;darkPortal=12;break;case"VoltRanger":per_unit=25;darkPortal=12;break}var i=t*per_unit;var s=darkPortal;var o=Seed.cities[CAPITAL.id];try{var u=Seed.requirements.resurrect[e];var a=Seed.stats.resurrect[e];i=t*u.resources["blue_energy"];s=u.buildings["DarkPortal"]}catch(r){aX("<B>"+translate("Training")+"</B>: "+r.msg+" "+translate("Manifest not available, using defaults"))}var f="";var l=" : ";var c={trainable:false,msg:[]};if(o.resources.blue_energy<i)f+=translate("Blue energy")+": "+(i-o.resources.blue_energy)+" + ";var h=o.souls[e];h=h>0?h:0;if(h==0)f+=translate("Souls")+" + ";if(n.getBuildingLevel(SPECTRAL_OUTPOST.id,"DarkPortal",s)==0)f+=translate("DarkPortal")+": "+s+" + ";if(n.getRemainingQueue(SPECTRAL_OUTPOST.id,"resurrection",true)==0)f+=translate("Resurrection queue")+" ";if(f.length==0){c.trainable=true;c.msg=t+" "+translate(e)}else{c.trainable=false;c.msg=l+f}var p=undefined;for(var d=0;d<all_unit_types.length&&p==undefined;d++){if(all_unit_types[d]==e)p=d}if(c.trainable==false){if(n.contentType==4){try{document.getElementById(UID["tabJobResurrect_FB_"+p]).innerHTML="<font color=#C33>"+c.msg.replace(/:\+/,":").replace(/\+\s*$/,"")+"</font>";document.getElementById(UID["tabJobResurrect_FB_"+p]).title=translate(all_unit_types[p])+" "+c.msg.replace(/\+/g," \n");document.getElementById(UID["tabJobResurrect_Troop_"+p]).style.backgroundColor="#C33"}catch(r){}}}else{var v=0;if(Seed.cities[SPECTRAL_OUTPOST.id]){for(var m=0;m<Seed.cities[SPECTRAL_OUTPOST.id].buildings.length;m++){if(Seed.cities[SPECTRAL_OUTPOST.id].buildings[m].type=="DarkPortal")v+=1+(Seed.cities[SPECTRAL_OUTPOST.id].buildings[m].level-1)/10}}var g=bV(t*a.time*(15/100)/v);if(n.contentType==4){try{var y=translate("Revival allowed")+" : "+translate("OK")+" ("+bz(g)+")";document.getElementById(UID["tabJobResurrect_FB_"+p]).innerHTML=y;document.getElementById(UID["tabJobResurrect_FB_"+p]).title=translate(all_unit_types[p])+" \n"+y}catch(r){}}}return c},trainTick:function(){var e=Tabs.Jobs;var t=true;if(!Data.options.training.enabled)return;clearTimeout(e.trainTimer);if(Seed.refresh_cities[CAPITAL.id])t=false;else t=true;var n={noPlayer:true};var r=iR();for(var i=0;i<r.length&&t;i++){var s=false;var o=r[i].cityIdx;if(o!=undefined&&!isNaN(o)&&o>=0&&o<Seed.cities.length&&o!=SPECTRAL_OUTPOST.id&&o!=SKY_OUTPOST.id&&o!=LUNA_OUTPOST.id&&Data.options.training.city[o].enabled){bI("Trying to train in "+Seed.cities[o].name);if(e.selectedQ=="min_housing"){if(Jobs.getJobs("units",true,o).length==0)s=e.attemptTrainQ(o,0,all_unit_types.length,true)}else{s=e.attemptTrainQ(o,0,all_unit_types.length,false)}if(s){t=false}else{if(!n.cities)n.cities=[];n.cities.push(Seed.cities[o].id)}}}e.trainTimer=setTimeout(e.trainTick,Math.randRange(5e3,1e4))},buildTick:function(){var e=Tabs.Jobs;if(!Data.options.building.enabled)return;clearTimeout(e.buildTimer);var t=false;var n={noPlayer:true,cities:[]};for(var r=0;r<Seed.cities.length;++r){if(Seed.cities[r]){var i=Jobs.getJobs("building",true,r);var s=Seed.cities[r];var o=s.id;if(i.length==0){var u=[];var a=[];if(e.last_built[o])Buildings.setLevel(o,e.last_built[o].id,e.last_built[o].level);for(var f in Data.options.building.level_enable[r]){if(Data.options.building.level_enable[r][f]){a=Buildings.getList(r,f);a.sort(function(e,t){return e.level-t.level});u=u.concat(a)}}u.sort(function(e,t){return e.level-t.level});var l=false;var c=false;var h=0;for(var p=0;p<u.length&&!l;p++){var d=e.checkBuildReqs(r,u[p].type);if(d){c=true;if(e.contentType==2)e.jobFeedback(d.msg);if(!d.msg){e.doBuild(u[p],s);l=true;return}else{if(e.contentType==2)e.jobFeedback(u[p].type+" "+d.msg);if(d.capped)++h}}}if(!l&&c&&u.length-h>0)t=true}else{var v=dY(r,i[0].city_building_id);var m=translate("Building")+": "+translate(v)+" "+translate("Level").toLowerCase()+" "+i[0].level+" "+translate("at")+" "+translate(s.type);if(e.contentType==2)e.jobFeedback(m)}}}if(t){e.buildRetryTime*=1.5;if(e.contentType==2)e.jobFeedback(translate("Completion errors")+": "+translate("Retry in")+" "+bE(e.buildRetryTime/1e3)+" "+translate("seconds"));e.buildTimer=setTimeout(e.buildTick,e.buildRetryTime);return}e.buildTimer=setTimeout(e.buildTick,Math.randRange(15e3,25e3))},feedingTick:function(){var e=Tabs.Jobs;if(!Data.options.sanctuary.enabled)return;clearTimeout(e.sanctuaryTimer);var t=false;var n=false;var r=Jobs.getJobs("feeding",true,CAPITAL.id);if(r.length==0){var i=0;for(var s in Data.options.sanctuary.feeding){if(Data.options.sanctuary.feeding[s].enable){var o=Seed.sanctuary_dragons[s];var u=o.level;var a=e.checkFeedingReqs(s);if(a){if(!a.msg){e.doFeeding(s,u);n=true;break}else{if(e.contentType==5)e.jobFeedback(bo(o.subtype,"rank-"+o.type,"dragons")+" "+a.msg);++i}}if(n===false&&i)t=true}}}if(t){e.sanctuaryTimer=setTimeout(e.feedingTick,e.feedRetryTime);if(e.contentType==5)e.jobFeedback(translate("Completion errors")+": "+translate("Retry in")+" "+bE(e.feedRetryTime/1e3)+" "+translate("seconds"));e.feedRetryTime*=1.5;return}e.sanctuaryTimer=setTimeout(e.feedingTick,5e3)},researchTick:function(){function t(e){var t=Jobs.getJobs("research",false,-1),n=false;for(var r=0;r<t.length&&!n;r++){if(t[r].research_type==e)n=true}return n}var e=Tabs.Jobs;if(!Data.options.research.enabled)return;clearTimeout(e.researchTimer);var n=false;var r={noPlayer:true,cities:[]};var i=false;for(var s=0;s<Seed.cities.length&&!i;++s){if(!Data.options.Rcheat_enabled&&s!=CAPITAL.id)continue;if(Seed.cities[s]&&s!=undefined&&!isNaN(s)&&s>=0&&s<Seed.cities.length&&s!=SPECTRAL_OUTPOST.id&&s!=SKY_OUTPOST.id&&s!=CAVE_OUTPOST.id&&s!=LUNA_OUTPOST.id&&Seed.cities[s].figures.queue_lengths&&Seed.cities[s].figures.queue_lengths["research"]){var o=Jobs.getJobs("research",true,s);var u=Seed.cities[s];var a=u.id;if(o.length==0){var f=0;for(var l=0;l<Seed.research.length;l++){var c=Seed.research[l];if(Data.options.research.res_enable[0][c]==undefined)continue;if(Data.options.research.res_enable[0][c]==true&&!t(c)){var h=e.getCurrentResearchLevel(c)+1;var p=e.checkResearchReqs(c,s);if(p){if(!p.msg){e.doResearch(s,c,h);i=true;break}else{if(e.contentType==3)e.jobFeedback(c+" "+p.msg);++f}}}}if(i===false&&f)n=true}}}if(n){e.researchTimer=setTimeout(e.researchTick,e.resRetryTime);if(e.contentType==3)e.jobFeedback(translate("Completion errors")+": "+translate("Retry in")+" "+bE(e.resRetryTime/1e3)+" "+translate("seconds"));e.resRetryTime*=1.5;return}e.researchTimer=setTimeout(e.researchTick,5e3)},resurrectTick:function(){var e=Tabs.Jobs;if(!Data.options.resurrect.enabled)return;clearTimeout(e.resurrectTimer);var t=false;var n=Jobs.getJobs("resurrection",true,CAPITAL.id);var r=Seed.cities[SPECTRAL_OUTPOST.id];var i=r.id;if(n.length==0){var s=0;for(var o=0;o<all_unit_types.length;o++){if(Data.options.resurrect.res_enable[SPECTRAL_OUTPOST.id][all_unit_types[o]]==undefined)continue;if(Data.options.resurrect.res_enable[SPECTRAL_OUTPOST.id][all_unit_types[o]]==true){var u=Seed.cities[CAPITAL.id].souls[all_unit_types[o]];if(!u||isNaN(u))u=0;var a=Data.options.resurrect.res_max[SPECTRAL_OUTPOST.id][all_unit_types[o]];var f=u>a?a:u;var l=e.checkResurrectReqs(all_unit_types[o],f);var c=false;if(l){if(l.trainable){e.doResurrect(all_unit_types[o],f);c=true;break}else{if(e.contentType==4)e.jobFeedback(all_unit_types[o]+" "+l.msg);++s}}}else{try{document.getElementById(UID["tabJobResurrect_FB_"+o]).innerHTML="";document.getElementById(UID["tabJobResurrect_Troop_"+o]).style.backgroundColor="none"}catch(h){}}}if(c===false&&s)t=true}if(t){Seed.fetchPlayer({cities:[i]});e.resurrectTimer=setTimeout(e.resurrectTick,e.revRetryTime);if(e.contentType==4)e.jobFeedback(translate("Completion errors")+": "+translate("Retry in")+" "+bE(e.revRetryTime/1e3)+" "+translate("seconds"));e.revRetryTime*=1.5}else{e.resurrectTimer=setTimeout(e.resurrectTick,Math.randRange(15e3,2e4))}},attemptTrainQ:function(e,t,n,r){var i=Tabs.Jobs;var s=false;if(Seed.cities[e]&&(Jobs.getJobs("units",true,e).length==0&&r||!r)){for(var o=Data.options.training.city[e].units.length-1;o>=0;o--){var u=all_unit_types[o],a=Data.options.training.city[e].units[o],f=0;if(e==SPECTRAL_OUTPOST.id||e==SKY_OUTPOST.id||e==LUNA_OUTPOST.id||!da(e,u))a=0;if(a>0){f=i.getTroopCap(u,a);try{if(f){a=0;if(i.contentType==1)i.jobFeedback(translate("Troops Capped"));document.getElementById(UID["tabTrain_Troop_"+e+"_"+o]).style.backgroundColor="red"}else if(i.contentType==1){if(document.getElementById(UID["tabTrain_Troop_"+e+"_"+o]).style.backgroundColor=="red")document.getElementById(UID["tabTrain_Troop_"+e+"_"+o]).style.backgroundColor="white"}}catch(l){}}if(a>0){var c=i.checkTrainReqs(u,a,e);if(!c.msg){if(r){bI("==> Do Short train "+u+", qty = "+a+" for "+Seed.cities[e].name);i.doTrain(u,a,e);s=true;break}else{if(i.getRemainingQueue(e,"units",false)){bI("==> Do Long train "+u+", qty = "+a+" for "+Seed.cities[e].name);i.doTrain(u,a,e);s=true;break}else{break}}}}}}return s},doTrain:function(e,t,n){var r=Tabs.Jobs;var i=Seed.cities[n];var s=translate("Training")+": ("+bD(t)+") "+translate(e)+" "+translate("at")+" "+(i.type=="Outpost"?translate(i.name):i.name);if(r.contentType==1)r.jobFeedback(s+" ("+translate("UpKeep")+" "+t*Seed.stats.unit[e].upkeep.food+" "+translate("Food")+")");MyAjax.troopTraining(e,t,i.id,function(e){if(e.ok){r.trainErrorCount=0;aX(s)}else{aZ("Error: Training: "+e.errmsg);aX("<B>"+translate("Error")+" "+translate("Training")+"</B>: "+e.errmsg);if(++r.trainErrorCount>5){if(r.contentType==1)r.jobFeedback(translate("Too many errors, disabling auto training"));r.setTrainEnable(false);r.trainErrorCount=0}else{if(r.contentType==1)r.jobFeedback(translate("Error")+" "+translate("Training")+": "+e.errmsg);r.trainRetryTime*=1.5}}Seed.updateCity(e.dat.result.city);if(e.dat.result.city.id!==Seed.cities[CAPITAL.id].id){Seed.addToRefresh(Seed.cities[CAPITAL.id].id,false)}if(r.contentType==1&&r.trainContentType==0)r.tabJobTrainSets()})},doBuild:function(e,t){var n=Tabs.Jobs;var r="<B>"+translate("Building")+"</B>: "+translate(e.type)+" "+translate("Level").toLowerCase()+" "+(e.level+1)+" "+translate("at")+" "+translate(t.type);if(n.contentType==2)n.jobFeedback(r);MyAjax.buildingUpgrade(t.id,e.id,function(i){if(i.ok){n.buildErrorCount=0;aX(r);clearTimeout(n.buildTimer);n.buildTimer=setTimeout(n.buildTick,Math.randRange(15e3,25e3));return}else{Seed.fetchPlayer({cities:[t.id]});aX(e.type+": "+i.errmsg);if(++n.buildErrorCount>3){if(n.contentType==2)n.jobFeedback(translate("Too many errors, disabling auto-build"));n.setBuildEnable(false);n.buildErrorCount=0;return}if(n.contentType==2)n.jobFeedback(e.type+": "+i.errmsg);clearTimeout(n.buildTimer);n.buildTimer=setTimeout(n.buildTick,n.buildRetryTime);return}})},doFeeding:function(e,t){var n=Tabs.Jobs;var r=Seed.sanctuary_dragons[e];var i="<b>"+translate("upgrading-dragon")+": </b> "+bo(r.subtype,"rank-"+r.type,"dragons")+" ("+t+") ";if(n.contentType==5)n.jobFeedback(i);MyAjax.dragonFeeding(e,function(e){if(e.ok){n.feedErrorCount=0;aX(i);return}else{Seed.fetchPlayer({cities:[],dragons:true,jobs:true});aX(i+" : "+e.errmsg);if(++n.feedErrorCount>5){if(n.contentType==5)n.jobFeedback(translate("Too many errors, disabling auto-feeding"));n.setFeedingEnable(false);n.feedErrorCount=0;return}if(n.contentType==5)n.jobFeedback(translate("FEEDING ERROR")+": "+e.errmsg);return}})},doResearch:function(e,t,n){var r=Tabs.Jobs;var i=Seed.cities[e];var s="<b>"+translate("Researching")+": </b> "+translate(r.resUITranslate(t))+" ("+n+") ";if(r.contentType==3)r.jobFeedback(s);aX("<B>"+translate("Research Started")+"</B>: "+translate(r.resUITranslate(t))+" ("+n+") ");MyAjax.researchStart(i.id,t,function(e){if(e.ok){r.resErrorCount=0;aX(s);return}else{Seed.fetchPlayer({cities:[],jobs:true});aX("<B>"+translate("Research Error").toUpperCase()+"</B>: "+e.errmsg);if(++r.resErrorCount>5){if(r.contentType==3)r.jobFeedback(translate("Too many errors, disabling auto-research"));r.setResearchEnable(false);r.resErrorCount=0;return}if(r.contentType==3)r.jobFeedback(translate("RESEARCH ERROR")+": "+e.errmsg);return}})},doResurrect:function(e,t){var n=Tabs.Jobs;var r=Seed.cities[SPECTRAL_OUTPOST.id];var i="<B>"+translate("Reviving")+"</B>: ("+t+") "+translate(e)+" "+translate("at")+" "+r.type;if(n.contentType==4)n.jobFeedback(i);MyAjax.troopReviving(e,t,r.id,function(r){clearTimeout(n.resurrectTimer);if(r.ok){n.revErrorCount=0;aX(i);Seed.cities[CAPITAL.id].souls[all_unit_types[e]]-=t;n.resurrectTimer=setTimeout(function(){n.resurrectTick(0)},Math.randRange(3e3,13e3));Seed.updateCity(r.dat.result.city);if(r.dat.result.city.id!==Seed.cities[CAPITAL.id].id)Seed.addToRefresh(Seed.cities[CAPITAL.id].id,false)}else{aZ("Error: Reviving: "+r.errmsg);aX("<B>"+translate("Error")+" "+translate("Reviving")+"</B>: "+r.errmsg);if(++n.revErrorCount>5){if(n.contentType==4)n.jobFeedback(translate("Too many errors, disabling auto reviving"));n.setResurrectEnable(false);n.revErrorCount=0}else{if(n.contentType==4)n.jobFeedback(translate("Error")+" "+translate("Reviving")+": "+r.errmsg);n.resurrectTimer=setTimeout(function(){n.resurrectTick(ic)},n.revRetryTime);n.revRetryTime*=1.5}}});if(n.contentType==4)setTimeout(n.tabJobResurrect,2e3)}};Tabs.Multiple={tabOrder:MULTI_TAB_ORDER,tabLabel:"Multi",tabDisabled:!MULTI_TAB_ENABLE,container:null,enabled:false,attackTimer:null,marchTimer:null,attackErrors:0,contentType:0,lastSubTab:"tabMultiConfig",running:{start_at:0},secondarySent:0,init:function(e){var t=Tabs.Multiple;Data.setDefaultValues("multiple");t.container=e;var n=""+"<div class="+UID["title"]+">"+translate("Attack One Target in Multiple waves")+"</div>"+"<div id="+bS("tabMulti_Status")+" class="+UID["status_ticker"]+' style="margin-bottom:5px !important">'+"	<center><input id="+bS("tabMulti_OnOff")+' type=button value="OnOff" /></center>'+"	<div id="+bS("tabMulti_Report")+' style="margin-top:5px;height:140px; max-height:140px; width:540px; max-width:540px; overflow:auto;">'+"		<table id="+bS("tabMulti_Marches")+" class="+UID["table"]+"></table>"+"	</div>"+"	<div id="+bS("tabMulti_Feedback")+" class="+UID["status_feedback"]+"></div>"+"</div>"+"<ul class=tabs>"+'	<li class="tab first"><a id='+bS("tabMultiConfig")+">"+translate("Config")+"</a></li>"+"	<li class=tab><a id="+bS("tabMultiStats")+">"+translate("Stats")+"</a></li>"+"</ul>"+"<div id="+bS("tabMulti_Content")+' style="padding-top:0px; height:440px; overflow-y:auto"></div>';t.container.innerHTML=n;document.getElementById(UID["tabMultiConfig"]).addEventListener("click",t.tabMultiConfig,false);document.getElementById(UID["tabMultiStats"]).addEventListener("click",t.tabMultiStats,false);document.getElementById(UID["tabMulti_OnOff"]).addEventListener("click",function(){t.setMultiEnable(!Data.options.multiple.enabled)},false);window.addEventListener("unload",t.onUnload,false);t.setMultiEnable(Data.options.multiple.enabled);t.contentType=bV(Data.options.multiple.current_tab);t.show()},tabMultiConfig:function(){function o(e){var t=bV(e.target.value);var n=bV(t*1.5);if(t<bK(MIN_DELAY_BETWEEN_WAVE,3)||t>3600){e.target.style.backgroundColor="red";return}document.getElementById(UID["tabMulti_DelayMax"]).innerHTML=n;e.target.style.backgroundColor="";Data.options.multiple.delay_min=t;Data.options.multiple.delay_max=n}function u(e){var t=bV(e.target.value);var n=bV(t*1.5);if(t<3||t>3600){e.target.style.backgroundColor="red";return}document.getElementById(UID["tabMulti_DelayMax2"]).innerHTML=n;e.target.style.backgroundColor="";Data.options.multiple.delay_min2=t;Data.options.multiple.delay_max2=n}function a(e){var t=bV(e.target.value);if(t<3||t>3600){e.target.style.backgroundColor="red";return}e.target.style.backgroundColor="";Data.options.multiple.delay_b4_secondary=t}function f(e){dq("tabMulti",Data.options.multiple.target.primary_units,Data.options.multiple.target)}function l(e){var t=e.target.name.split("_");if(t[0]=="PW"){var n=wave_unit_types[t[1]];var r=Data.options.multiple.target.primary_units;r[n]=e.target.value;var r=Data.options.multiple.target.saved_units_1;r[n]=e.target.value;var i=ba(Data.options.multiple.target.x,Data.options.multiple.target.y,Data.options.multiple.target.primary_units);document.getElementById(UID["tabMulti_Distance"]).innerHTML=bu(Seed.cities[CAPITAL.id].x,Seed.cities[CAPITAL.id].y,Data.options.multiple.target.x,Data.options.multiple.target.y)+" ("+bz(i)+")"}}function c(e){var t=e.target.name.split("_");if(t[0]=="SW"){var n=wave_unit_types[t[1]];var r=Data.options.multiple.target.secondary_units;r[n]=e.target.value;var r=Data.options.multiple.target.saved_units_2;r[n]=e.target.value}}function h(e){var t=bV(document.getElementById(UID["tabMulti_MaxMarches"]).value);if(t<0||t>Seed.cities[CAPITAL.id].figures.marches.maximum){e.target.style.backgroundColor="red";return}e.target.style.backgroundColor="";Data.options.multiple.max_marches=t}function p(e){var t=bV(document.getElementById(UID["tabMulti_MaxSecondary"]).value);if(t<0||t>Seed.cities[CAPITAL.id].figures.marches.maximum){e.target.style.backgroundColor="red";return}e.target.style.backgroundColor="";Data.options.multiple.max_secondary=t}var e=Tabs.Multiple;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabMultiConfig"]).className="selected";document.getElementById(UID["tabMultiConfig"]).style.zIndex=1;e.lastSubTab="tabMultiConfig";e.contentType=0;var t='<div class="'+UID["title"]+'">'+translate("Max ")+translate("Troops")+" "+bD(bV(bJ(CAPITAL.id).max_troops)," ")+"</div>"+"<div class="+UID["content"]+">"+"	<div>"+"		<b>"+translate("Coords")+":&nbsp;</b>&nbsp;"+"		X: <input id="+bS("tabMulti_CoordsX")+' size=1 maxlength=3 type=text value="'+Data.options.multiple.target.x+'" /> '+"		Y: <input id="+bS("tabMulti_CoordsY")+' size=2 maxlength=3 type=text value="'+Data.options.multiple.target.y+'" /> '+"		&nbsp <b>"+translate("Distance")+":</b> <span id="+bS("tabMulti_Distance")+"></span><BR>"+"		<div class="+UID["status_ticker"]+' style="height:auto !important;margin:5px 10px !important;">'+"			<center><span id="+bS("tabMulti_Tile")+"></span></center>"+"		</div>"+"	</div>"+"  <div>"+"	<table id="+bS("tabMulti_Troops")+" class="+UID["table"]+" width=100%>"+"		<tr align=center class="+UID["row_headers"]+">"+"			<td colspan=10>"+translate("Troops for Primary Attack")+":&nbsp;</td>"+"		</tr>"+"	</table>"+"	</div>"+"  <div>"+"	<table id="+bS("tabMulti_Dragons")+" class="+UID["table"]+" width=100%>"+"		<tr align=left>"+"			<td class=left colspan=10>"+translate("Include Great Dragon")+":&nbsp;</td>";var n=[];for(var r=0;r<Seed.dragonList.length;r++){var i=Seed.dragonList[r];if(r%5==0)t+="</tr><tr>";t+='	<td class=right><span title="'+translate(i.type)+'">'+translate(Names.getTroopAbbr(i.type))+":<span></td>"+"	<td align=center><input type=checkbox id="+bS("tabMulti_Dragons_"+r)+' ref="'+r+'" '+(Data.options.multiple.target.dragons_1[i.type]?" checked":"")+" /></td>";n.push(r)}t+="</tr>"+"	</table>"+"	</div><br>"+"  <div>"+"	<table id="+bS("tabMulti_Troops2")+" class="+UID["table"]+" width=100%>"+"		<tr align=center class="+UID["row_headers"]+">"+"			<td colspan=10>"+translate("Troops for Secondary Attacks")+":&nbsp;</td>"+"		</tr>"+"	</table>"+"	</div>"+"  <div>"+"	<table id="+bS("tabMulti_Dragons2")+" class="+UID["table"]+" width=100%>"+"		<tr align=left>"+"			<td class=left colspan=10>"+translate("Include Great Dragon")+":&nbsp;</td>";var s=[];for(var r=0;r<Seed.dragonList.length;r++){var i=Seed.dragonList[r];if(r%5==0)t+="</tr><tr>";t+='	<td class=right><span title="'+translate(i.type)+'">'+translate(Names.getTroopAbbr(i.type))+":<span></td>"+"	<td align=center><input type=checkbox id="+bS("tabMulti_Dragons2_"+r)+' ref="'+r+'" '+(Data.options.multiple.target.dragons_2[i.type]?" checked":"")+" /></td>";s.push(r)}t+="</tr>"+"	</table>"+"	</div><br>"+"	<table class="+UID["table"]+">"+"		<tr>"+"			<td class=right> "+translate("Delete Battle Reports")+":&nbsp;</td>"+"			<td><input id="+bS("tabMulti_DelReports")+" type=checkbox "+(Data.options.multiple.delete_reports?"CHECKED":"")+" /></td>"+"		</tr><tr>"+"			<td class=right>"+translate("Stop if any troops lost")+":&nbsp;</td>"+"			<td><input id="+bS("tabMulti_StopOnLoss")+" type=checkbox "+(Data.options.multiple.stop_on_loss?"CHECKED":"")+" /></td>"+"		</tr><tr>"+"			<td class=right>"+translate("Delay before sending Primary attack")+":&nbsp;</td>"+"			<td>"+"				<input id="+bS("tabMulti_DelayMin")+' type=text size=1 maxlength=4 value="'+Data.options.multiple.delay_min+'" />'+"				 to <span id="+bS("tabMulti_DelayMax")+">"+Data.options.multiple.delay_max+"</span>&nbsp;"+translate("seconds")+"			</td>"+"		</tr><tr>"+"			<td class=right> "+translate("Delay before first secondary attack")+":&nbsp;</td>"+"			<td><input id="+bS("tabMulti_DelayB4Secondary")+' type=text size=1 maxlength=4 value="'+Data.options.multiple.delay_b4_secondary+'" /></td>'+"		</tr><tr>"+"			<td class=right>"+translate("Delay Between Secondary Attacks")+":&nbsp;</td>"+"			<td>"+"				<input id="+bS("tabMulti_DelayMin2")+' type=text size=1 maxlength=4 value="'+Data.options.multiple.delay_min2+'" />'+"				 to <span id="+bS("tabMulti_DelayMax2")+">"+Data.options.multiple.delay_max2+"</span>&nbsp;"+translate("seconds")+"			</td>"+"		</tr><tr>"+"			<td class=right> "+translate("Maximum simultaneous marches")+":&nbsp;</td>"+"			<td><input id="+bS("tabMulti_MaxMarches")+' type=text size=1 maxlength=2 value="'+Data.options.multiple.max_marches+'" /></td>'+"		</tr><tr>"+"			<td class=right> "+translate("Maximum secondary marches before sending another primary attack")+":&nbsp;</td>"+"			<td><input id="+bS("tabMulti_MaxSecondary")+' type=text size=1 maxlength=2 value="'+Data.options.multiple.max_secondary+'" /></td>'+"		</tr>"+"	</table>"+"</div>";document.getElementById(UID["tabMulti_Content"]).innerHTML=t;document.getElementById(UID["tabMulti_CoordsX"]).addEventListener("change",f,false);document.getElementById(UID["tabMulti_CoordsY"]).addEventListener("change",f,false);document.getElementById(UID["tabMulti_DelReports"]).addEventListener("click",function(e){Data.options.multiple.delete_reports=e.target.checked},false);document.getElementById(UID["tabMulti_StopOnLoss"]).addEventListener("click",function(e){Data.options.multiple.stop_on_loss=e.target.checked},false);document.getElementById(UID["tabMulti_DelayMin"]).addEventListener("change",o,false);document.getElementById(UID["tabMulti_DelayMin2"]).addEventListener("change",u,false);document.getElementById(UID["tabMulti_DelayB4Secondary"]).addEventListener("change",a,false);document.getElementById(UID["tabMulti_MaxMarches"]).addEventListener("change",h,false);document.getElementById(UID["tabMulti_MaxSecondary"]).addEventListener("change",p,false);du(document.getElementById(UID["tabMulti_Troops"]),1,"PW",wave_unit_types,Data.options.multiple.target.primary_units,Data.options.multiple.target.saved_units_1,l,true);du(document.getElementById(UID["tabMulti_Troops2"]),1,"SW",wave_unit_types,Data.options.multiple.target.secondary_units,Data.options.multiple.target.saved_units_2,c,true);for(var r=0;r<n.length;++r){document.getElementById(UID["tabMulti_Dragons_"+n[r]]).addEventListener("change",function(e){var t=e.target.getAttribute("ref");Data.options.multiple.target.dragons_1[Seed.dragonList[t].type]=e.target.checked;var n=false;for(var r=0;r<Seed.dragonList.length&&!n;r++){var i=Seed.dragonList[r];if(Data.options.multiple.target.dragons_1[i.type])n=true}if(n)Data.options.multiple.target.include_gd_1=true;else Data.options.multiple.target.include_gd_1=false},false)}for(var r=0;r<s.length;++r){document.getElementById(UID["tabMulti_Dragons2_"+s[r]]).addEventListener("change",function(e){var t=e.target.getAttribute("ref");Data.options.multiple.target.dragons_2[Seed.dragonList[t].type]=e.target.checked;var n=false;for(var r=0;r<Seed.dragonList.length&&!n;r++){var i=Seed.dragonList[r];if(Data.options.multiple.target.dragons_2[i.type])n=true}if(n)Data.options.multiple.target.include_gd_2=true;else Data.options.multiple.target.include_gd_2=false},false)}f()},tabMultiStats:function(){function n(){var e=Tabs.Multiple;var t=be();Data.stats.multiple={start_at:t,run_time:0,total_attacks:0,loss:{},items:{},resources:{}};e.bL()}var e=Tabs.Multiple;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabMultiStats"]).className="selected";document.getElementById(UID["tabMultiStats"]).style.zIndex=1;e.lastSubTab="tabMultiStats";e.contentType=1;var t="<div class="+UID["title"]+">"+translate("Attacks Stats")+"</div>"+"<div id="+bS("tabMultiStats_Statbox")+" class="+UID["status_ticker"]+">"+"<div id="+bS("tabMultiStats_Status")+"></div>"+"<div id="+bS("tabMultiStats_Percent")+"></div>"+"<br/>"+"<center><input id="+bS("tabMultiStats_Clear")+' type=button value="'+translate("Clear Stats")+'" /></center>'+"<br></div>";document.getElementById(UID["tabMulti_Content"]).innerHTML=t;document.getElementById(UID["tabMultiStats_Clear"]).addEventListener("click",function(){n();e.bL()},false);e.bL()},gotBattleReport:function(e){function f(e,t){var n="Recall march "+t;aZ(n+" "+translate("attempted"));new MyAjax.marchRecall(e,t,function(e){if(e.ok){aZ(n+" "+translate("succeeded"))}else{aZ(n+" "+translate("failed and returned error")+": "+e.errmsg)}})}var t=Tabs.Multiple,n=false;if(!e)return;if(e.report.location.x==Data.options.multiple.target.x&&e.report.location.y==Data.options.multiple.target.y){var r=null;for(var i in Data.marches.multiple){var s=Data.marches.multiple[i];if(s.general.id===e.report.attacker.general.id){r=i;break}}if(r&&r!=null)t.trackStats(r,e);var o=e.report.spoils.items;if(o.length!==0)Seed.fetchPlayer({noCities:true});if(!Data.options.multiple.delete_reports&&!Data.options.multiple.stop_on_loss)return;if(Data.options.multiple.stop_on_loss&&e.report.attacker.name==Seed.player.name){for(var u in e.report.attacker.units){if(e.report.attacker.units[u][0]!=e.report.attacker.units[u][1]){n=true;var a=(new Date(e.report_notification.created_at*1e3)).myString();t.setMultiEnable(false);aS(UID["tabMulti_Feedback"],translate("Troops lost")+"! ("+a+")");aX(translate("Multi")+": "+translate("Troops lost")+"! ("+a+")");for(var i in Data.marches.multiple){if(Data.marches.multiple[i].status==="marching")f(Data.marches.multiple[i].city_id,i)}return}}}if(Data.options.multiple.delete_reports&&e.report.attacker.name==Seed.player.name&&!n)Messages.deleteMessage(e.report_notification.id)}},marchTick:function(){var e=Tabs.Multiple;clearTimeout(e.marchTimer);Marches.updateTable(document.getElementById(UID["tabMulti_Marches"]),"multiple");e.marchTimer=setTimeout(e.marchTick,1e3)},setMultiEnable:function(e){var t=Tabs.Multiple;var n=document.getElementById(UID["tabMulti_OnOff"]);clearTimeout(t.attackTimer);Data.options.multiple.enabled=e;if(e){Messages.addBattleReportListener(t.gotBattleReport);n.value=translate("Attacking").toUpperCase();n.className=UID["btn_on"];t.multiAttackTick();t.running.start_at=be();Data.stats.multiple.start_at=be()}else{Messages.removeReportListener("multiple",t.gotBattleReport);n.value=translate("Disabled").toUpperCase();n.className=UID["btn_off"];if(t.running.start_at!==0){Data.stats.multiple.run_time+=be()-t.running.start_at}}},bL:function(){var e=Tabs.Multiple;var t=document.getElementById(UID["tabMultiStats_Status"]);if(t==null)return;var n=Data.stats.multiple.run_time;if(Data.options.multiple.enabled)n+=be()-e.running.start_at;var r=n>0?n/3600:1;var i="<table class="+UID["table"]+">"+"	<tr>"+"		<td class=right>"+translate("Start Date")+": </td>"+"		<td colspan=>"+(new Date(Data.stats.multiple.start_at*1e3)).myString()+"</td>"+"	</tr><tr>"+"		<td class=right>"+translate("Run Time")+": </td>"+"		<td>"+bE(n,true)+"</td>"+"	</tr><tr>"+"		<td class=right>"+translate("Attacks")+": </td>"+"		<td>"+Data.stats.multiple.total_attacks+"</td>"+"	<tr valign=top align=right>"+"		<td class=right>"+translate("Troops lost")+": </td>";var s=true;for(var o in Data.stats.multiple.loss){var u=Math.round(Data.stats.multiple.loss[o]/r);if(s)s=false;else i+="	<tr align=right><td></td>";i+="		<td>"+translate(o)+":</td>"+"		<td>"+bD(Data.stats.multiple.loss[o]," ")+"</td>"+"		<td>("+bD(u," ")+" /"+translate("h")+")</td>"+"	</tr>"}i+="</tr><tr valign=top align=right>"+"		<td class=right>"+translate("Resources")+": </td>";var s=true;for(var o in Data.stats.multiple.resources){var u=Math.round(Data.stats.multiple.resources[o]/r);if(s)s=false;else i+="	<tr align=right><td></td>";i+="			<td>"+translate(o)+":</td>"+"			<td>"+bD(Data.stats.multiple.resources[o]," ")+"</td>"+"			<td>("+bD(u," ")+" /"+translate("h")+")</td>"+"		</tr>"}i+="<tr valign=top align=right>"+"		<td class=right>"+translate("Items")+": </td>";var a=[];for(var o in Data.stats.multiple.items)a.push({desc:translate(o),qty:Data.stats.multiple.items[o]});if(a.length>0){a.sort(function(e,t){e=e.desc.toLowerCase();t=t.desc.toLowerCase();if(e>t)return 1;if(e<t)return-1;return 0});for(var f=0;f<a.length;f++){var u=Math.round(a[f].qty/r);if(f>0)i+="<tr align=right><td></td>";i+="		<td>"+a[f].desc+":</td>"+"		<td>"+bD(a[f].qty," ")+"</td>"+"		<td>("+bD(u," ")+" /"+translate("h")+")</td>"+"	</tr>"}}i+="</table>";t.innerHTML=i},trackStats:function(e,t){var n=Tabs.Multiple;if(DEBUG_MARCHES)bf("Tabs.Multiple.trackStats: "+e);if(as(Data.stats.multiple.total_attacks))Data.stats.multiple.total_attacks=0;if(as(Data.stats.total.total_attacks))Data.stats.total.total_attacks=0;++Data.stats.multiple.total_attacks;++Data.stats.total.total_attacks;var r=t.report.spoils.resources;for(var i in r){aF(Data.stats.multiple.resources,i,bV(r[i]),false);aF(Data.stats.total.resources,i,bV(r[i]),false)}var s=t.report.spoils.kill_items;for(var i in s){aF(Data.stats.multiple.resources,i,bV(s[i]),false);aF(Data.stats.total.resources,i,bV(s[i]),false)}var o=t.report.spoils.items;for(var u=0;u<o.length;u++){aF(Data.stats.multiple.items,o[u],1,true);aF(Data.stats.total.items,o[u],1,true)}for(var i in t.report.attacker.units){if(t.report.attacker.units[i][0]!=t.report.attacker.units[i][1]){var a=bV(t.report.attacker.units[i][0])-bV(t.report.attacker.units[i][1]);aF(Data.stats.multiple.loss,i,a,true);aF(Data.stats.total.loss,i,a,true)}}Data.marches.multiple[e].has_report=true;n.bL()},multiAttackTick:function(){var e=Tabs.Multiple,t,n,r,i,s=0;clearTimeout(e.attackTimer);if(!Data.options.multiple.enabled)return;t=Data.options.multiple.target.type+translate(" at ")+Data.options.multiple.target.x+"/"+Data.options.multiple.target.y;var o=translate("Primary attack to ")+t;var u=UID["tabMulti_Feedback"];var a=cK();s=a.count;n=a.delay;r=bB();var f=dB(o,u,s,n,Marches.count.multiple,Data.options.multiple.max_marches,r,true);if(f!=0){e.attackTimer=setTimeout(e.multiAttackTick,n*1e3);return}Data.options.multiple.target.primary_units=aA(Data.options.multiple.target.saved_units_1);i=bb(CAPITAL.id,Data.options.multiple.target.primary_units);if(i!==null){bM(o,u,i,true,n);e.attackTimer=setTimeout(e.multiAttackTick,n*1e3);return}if(Data.options.multiple.target.include_gd_1){var l=null;if((l=dC(true,Data.options.multiple.target.dragons_1))==null){bM(o,u,5,false,n);e.attackTimer=setTimeout(e.multiAttackTick,n*1e3);return}Data.options.multiple.target.primary_units[l]=1}e.secondarySent=0;aZ(o+" "+translate("attempted"));new MyAjax.marchSend(Seed.cities[CAPITAL.id].id,Data.options.multiple.target.x,Data.options.multiple.target.y,r.id,Data.options.multiple.target.primary_units,"multiple",function(e){var t=Tabs.Multiple,n,r;if(e.ok&&e.dat.result.success){t.attackErrors=0;var i=bV(Data.options.multiple.delay_b4_secondary,3);var s=bV(i*.2);n=Math.floor(Math.random()*(s-i+1)+i);aZ(o+" "+translate("Successfully"));aX(o);aS(u,o);t.attackTimer=setTimeout(t.multiAttackTick2,(n+10)*1e3)}else{t.attackErrors++;r=30*t.attackErrors*t.attackErrors;aZ(o+" "+translate("failed and returned error")+": "+e.errmsg+" - "+translate("Retry in")+" "+r+" "+translate("seconds"));aX(o+" "+translate("failed"));if(e.status===429){r=E429_DELAY;bM(o+" "+translate("failed")+" - <b>API</b> ",u,6,false,r)}else if(e.status===509){r=600;bM(o+" "+translate("failed")+" - ",u,6,false,r)}else aS(u,o+" "+translate("failed"));t.attackTimer=setTimeout(t.multiAttackTick,r*1e3)}})},multiAttackTick2:function(){var e=Tabs.Multiple,t,n,r,i,s=0;clearTimeout(e.attackTimer);if(!Data.options.multiple.enabled)return;t=Data.options.multiple.target.type+translate(" at ")+Data.options.multiple.target.x+"/"+Data.options.multiple.target.y;var o=translate("Secondary attack to ")+t;var u=UID["tabMulti_Feedback"];var a=cK();s=a.count;var f=bV(Data.options.multiple.delay_min,bK(MIN_DELAY_BETWEEN_WAVE,a.delay));var l=bV(Data.options.multiple.delay_max,bV(f*1.5));n=Math.floor(Math.random()*(l-f+1)+f);r=bB();var c=dB(o,u,s,n,Marches.count.multiple,Data.options.multiple.max_marches,r,true);if(c!=0){e.attackTimer=setTimeout(e.multiAttackTick,n*1e3);return}Data.options.multiple.target.secondary_units=aA(Data.options.multiple.target.saved_units_2);i=bb(CAPITAL.id,Data.options.multiple.target.secondary_units);if(i!==null){bM(o,u,i,true,n);e.attackTimer=setTimeout(e.multiAttackTick,n*1e3);return}if(Data.options.multiple.target.include_gd_2){var h=null;if((h=dC(true,Data.options.multiple.target.dragons_2))==null){bM(o,u,5,false,n);e.attackTimer=setTimeout(e.multiAttackTick,n*1e3);return}Data.options.multiple.target.secondary_units[h]=1}aZ(o+" "+translate("attempted"));new MyAjax.marchSend(Seed.cities[CAPITAL.id].id,Data.options.multiple.target.x,Data.options.multiple.target.y,r.id,Data.options.multiple.target.secondary_units,"multiple",function(e){var t=Tabs.Multiple,n,r;if(e.ok&&e.dat.result.success){t.attackErrors=0;aZ(o+" "+translate("Successfully"));aX(o);aS(u,o);t.secondarySent++;if(t.secondarySent>=Data.options.multiple.max_secondary){var i=bV(Data.options.multiple.delay_min,bK(MIN_DELAY_BETWEEN_WAVE,3));var s=bV(Data.options.multiple.delay_max,bV(i*1.5));n=Math.floor(Math.random()*(s-i+1)+i);t.attackTimer=setTimeout(t.multiAttackTick,n*1e3)}else{var i=bV(Data.options.multiple.delay_min2,3);var s=bV(Data.options.multiple.delay_max2,bV(i*1.5));n=Math.floor(Math.random()*(s-i+1)+i);t.attackTimer=setTimeout(t.multiAttackTick2,n*1e3)}}else{t.attackErrors++;var i=bV(Data.options.multiple.delay_min,bK(MIN_DELAY_BETWEEN_WAVE,3));var s=bV(Data.options.multiple.delay_max,bV(i*1.5));r=Math.floor(Math.random()*(s-i+1)+i);aZ(o+" "+translate("failed and returned error")+": "+e.errmsg+" - "+translate("Retry in")+" "+r+" "+translate("seconds"));aX(o+" "+translate("failed"));if(e.status===429){r=E429_DELAY;bM(o+" "+translate("failed")+" - <b>API</b> ",u,6,false,r)}else if(e.status===509){r=600;bM(o+" "+translate("failed")+" - ",u,6,false,r)}else aS(u,o+" "+translate("failed"));t.attackTimer=setTimeout(t.multiAttackTick,r*1e3)}})},onUnload:function(){var e=Tabs.Multiple;if(Data.options.multiple.enabled&&e.running.start_at!=0)Data.stats.multiple.run_time+=be()-e.running.start_at},show:function(){var e=Tabs.Multiple;e.marchTick();switch(e.contentType||0){case 0:e.tabMultiConfig();break;case 1:e.tabMultiStats();break}},hide:function(){var e=Tabs.Multiple;clearTimeout(e.marchTimer);Data.options.multiple.current_tab=e.contentType}};Tabs.Search={tabOrder:SEARCH_TAB_ORDER,tabLabel:"Map",tabDisabled:!SEARCH_TAB_ENABLE,container:null,checkMapBusy:false,MAX_DISTANCE:75,contentType:0,lastSubTab:"tabSearchC",init:function(e){var t=Tabs.Search;Data.setDefaultValues("search");t.container=e;var n="<div class="+UID["title"]+">"+translate("Map Search")+"</div>"+"<div class="+UID["content"]+">"+"	<div>"+"		<b>"+translate("Search coords")+":&nbsp;</b>&nbsp;"+"		X: <input id="+bS("tabSearch_CoordsX")+' size=2 maxlength=3 type=text value="'+Data.options.search.target.x+'" /> '+"		Y: <input id="+bS("tabSearch_CoordsY")+' size=2 maxlength=3 type=text value="'+Data.options.search.target.y+'" /> '+"		&nbsp <b>"+translate("Search max radius")+":</b>"+"	<select id="+bS("tabSearch_MaxRadius")+">";for(var r=5;r<=100;r+=5){n+='		<option value="'+r+'" '+(Data.options.search.target.distance==r?"selected":"")+">"+r+"</option>"}n+="	</select><br>"+"		<table class="+UID["table"]+' style="margin-top:3px" width=100%>'+"			<tr valign=top align=center>"+"				<td width=33%><label><input id="+bS("tabSearch_Refresh")+' type=button value="'+translate("Refresh map data")+'" /></label></td>'+"				<td width=33%><label><input id="+bS("tabSearch_RefreshCities")+' type=button class="'+UID["btn_green"]+'" value="'+translate("Scan cities")+'" /></label></td>'+"				<td width=33%><label><input id="+bS("tabSearch_RefreshWilds")+' type=button class="'+UID["btn_green"]+'" value="'+translate("Scan wilds")+'" /></label></td>'+"			</tr>"+"		</table><br>"+"		<div class="+UID["status_ticker"]+' style="height:auto !important;margin:1px 10px 5px !important;">'+"			<center><span id="+bS("tabSearch_Tile")+"></span></center>"+"		</div>"+"	</div>"+"	<table class="+UID["table"]+" width=100%>"+"		<tr><td class=left width=50%><div id="+bS("tabSearch_Alliance")+"></div></td>"+"			<td class=left width=50%><div id="+bS("tabSearch_Players")+"></div></td>"+"		</tr>"+"	</table>"+"</div>"+"<ul class=tabs>"+'	<li class="tab first"><a id='+bS("tabSearchC")+">"+translate("Player cities")+"</a></li>"+"	<li class=tab><a id="+bS("tabSearchW")+">"+translate("Wildernesses")+"</a></li>"+"</ul>"+"<div id="+bS("tabSearch_Content")+' style="padding-top:none; height:525px; ; max-height:525px; overflow-x:auto; overflow-y:auto"></div>';t.container.innerHTML=n;document.getElementById(UID["tabSearch_CoordsX"]).addEventListener("change",t.bU,false);document.getElementById(UID["tabSearch_CoordsY"]).addEventListener("change",t.bU,false);document.getElementById(UID["tabSearch_MaxRadius"]).addEventListener("change",function(e){var n=e.target;Data.options.search.target.distance=bV(n.options[n.selectedIndex].value);t.show()},false);document.getElementById(UID["tabSearch_Refresh"]).addEventListener("click",function(){t.refreshMapData(0)},false);document.getElementById(UID["tabSearch_RefreshCities"]).addEventListener("click",function(){t.refreshMapData(1)},false);document.getElementById(UID["tabSearch_RefreshWilds"]).addEventListener("click",function(){t.refreshMapData(2)},false);document.getElementById(UID["tabSearch_Alliance"]).addEventListener("change",t.eventAlliance,false);document.getElementById(UID["tabSearch_Players"]).addEventListener("change",t.eventPlayer,false);document.getElementById(UID["tabSearchC"]).addEventListener("click",t.tabSearchC,false);document.getElementById(UID["tabSearchW"]).addEventListener("click",t.tabSearchW,false);t.bU();t.contentType=bV(Data.options.search.current_tab);t.show()},hide:function(){},show:function(){var e=Tabs.Search;if(!e.checkMapBusy){e.displayAllianceList();e.displayPlayersList();switch(bV(e.contentType)){case 0:e.tabSearchC();break;case 1:e.tabSearchW();break}}else setTimeout(e.show,100)},onUnload:function(){var e=Tabs.Search;Data.options.search.current_tab=e.contentType},bU:function(e){dq("tabSearch",null,Data.options.search.target)},eventAlliance:function(e){var t=Tabs.Search;var n=document.getElementById(UID["tabSearch_SelAlliance"]);var r=n.value;Data.options.search.target.alliance=r;if(r==null){n.style.backgroundColor="red";return}n.style.backgroundColor="";t.displayPlayersList();t.show()},eventPlayer:function(e){var t=Tabs.Search;var n=document.getElementById(UID["tabSearch_SelPlayer"]);var r=n.value;Data.options.search.target.player=r;if(r==null){n.style.backgroundColor="red";return}n.style.backgroundColor="";t.show()},displayAllianceList:function(){var e=Tabs.Search;var t=e.getAllianceList();if(t.length>0)t.sort(function(e,t){e=e.name.toLowerCase();t=t.name.toLowerCase();if(e>t)return 1;if(e<t)return-1;return 0});var n="<span class=left>"+translate("Alliance")+":&nbsp </span><select id="+bS("tabSearch_SelAlliance")+">"+'<option value="*" '+(Data.options.search.target.alliance=="*"?"selected":"")+">"+translate("actions-all-alliances").initCap()+"</option>"+'<option value="0" '+(Data.options.search.target.alliance=="0"?"selected":"")+">"+translate("Without alliance")+"</option>"+'<option value="-1" '+(Data.options.search.target.alliance=="-1"?"selected":"")+">"+translate("Foes")+"</option>"+'<option value="1" '+(Data.options.search.target.alliance=="1"?"selected":"")+">"+translate("Friends")+"</option>";for(var r=0;r<t.length;r++){var i="";if(t[r].id==Data.options.search.target.alliance)i="selected";n+='<option value="'+t[r].id+'" '+i+">"+t[r].name+"</option>"}n+="</select>";document.getElementById(UID["tabSearch_Alliance"]).innerHTML=n;e.displayPlayersList()},displayPlayersList:function(){var e=Tabs.Search;var t=e.getPlayersList();if(t.length>0)t.sort(function(e,t){e=e.name.toLowerCase();t=t.name.toLowerCase();if(e>t)return 1;if(e<t)return-1;return 0});var n="<span class=left>"+translate("Player name")+":&nbsp </span><select id="+bS("tabSearch_SelPlayer")+">"+'<option value="*" '+(Data.options.search.target.player=="*"?"selected":"")+">"+translate("All players")+"</option>";for(var r=0;r<t.length;r++){var i="";if(t[r].id==Data.options.search.target.player)i="selected";n+='<option value="'+t[r].id+'" '+i+">"+t[r].name+"</option>"}n+="</select>";document.getElementById(UID["tabSearch_Players"]).innerHTML=n},getAllianceList:function(){var e=Tabs.Search;var t=[];for(var n in Data.map.alliance){if(n!=0)t.push({id:n,name:Data.map.alliance[n]||""})}return t},getPlayersList:function(){var e=Tabs.Search;var t=[];for(var n in Data.map.players){if(Data.options.search.target.alliance=="*"||Data.options.search.target.alliance=="1"&&cw(Data.map.players[n][3])=="1"||Data.options.search.target.alliance=="-1"&&cw(Data.map.players[n][3])=="-1"||Data.options.search.target.alliance!="*"&&Data.options.search.target.alliance!="1"&&Data.options.search.target.alliance!="-1"&&(Data.map.players[n][3]==Data.options.search.target.alliance||Data.map.players[n][3]==0&&(Data.options.search.target.alliance==null||Data.options.search.target.alliance==0)))if(Data.map.players[n][0]&&Data.map.players[n][0]!=null&&Data.map.players[n][0]!="")t.push({id:n,name:Data.map.players[n][0]||""})}bI("Player count = "+t.length);return t},getCityList:function(){var e=Tabs.Search;var t=Data.options.search.target.distance||16;var n=Data.options.search.target.x;var r=Data.options.search.target.y;if(isNaN(n))n=Seed.cities[CAPITAL.id].x;if(isNaN(r))r=Seed.cities[CAPITAL.id].y;var i=Map.getTargets({x:n,y:r,radius:t,map_type:"C"});var s=[];var o=Data.options.search.target.alliance||"*";var u=Data.options.search.target.player||"*";for(var a in i){if(a=="City"||a=="Outpost"){if(i[a]){for(var f=0;f<i[a].length;f++){var l=i[a][f];if(l&&l.d<=t&&(l.ai==o||o=="*"||o=="1"&&cw(l.ai)=="1"||o=="-1"&&cw(l.ai)=="-1"||(!l.ai||l.ai==0)&&(o==null||o==0))&&(l.id==u||u=="*")){if(!l.a&&l.n)l.a="";if(!l.n){l.n="?????";l.a="?????";l.m="?"}s.push(l)}}}}}i=null;return s},getWildernessesList:function(){var e=Tabs.Search;var t=[];var n=Data.options.search.target.distance||16;var r=Data.options.search.target.x;var i=Data.options.search.target.y;if(isNaN(r))r=Seed.cities[CAPITAL.id].x;if(isNaN(i))i=Seed.cities[CAPITAL.id].y;var s=Data.options.search.target.alliance||"*";var o=Map.getTargets({x:r,y:i,radius:n,map_type:"W"});var u=[];for(var a in o){if(a=="hill"&&Data.options.search.hill||a=="grassland"&&Data.options.search.grassland||a=="lake"&&Data.options.search.lake||a=="mountain"&&Data.options.search.mountain||a=="forest"&&Data.options.search.forest||a=="plain"&&Data.options.search.plain){if(o[a]){for(var f=0;f<o[a].length;f++){var l=o[a][f];if(l&&l.d<=n&&l.l>=bV(Data.options.search.min_level)&&l.l<=bV(Data.options.search.max_level)&&(((!l.id||l.id==0)&&Data.options.search.unowned||!Data.options.search.unowned)&&(l.ai==s||s=="*"||s=="1"&&cw(l.ai)=="1"||s=="-1"&&cw(l.ai)=="-1"||(!l.ai||l.ai==0)&&s==null)&&(l.id==Data.options.search.target.player||Data.options.search.target.player=="*")&&l.l>=7||l.l<7)){if(l.l<7&&!l.n){l.n="-";l.a="-";l.m="-"}if(!l.a&&l.n)l.a="";if(!l.n){l.n="?????";l.a="?????";l.m="?"}u.push(l)}}}}}o=null;return u},tabSearchC:function(){function h(t){var r=bV(t.target.getAttribute("ref"));dJ(e.container,n[r])}function p(e){var t=Tabs.Search;var n=e.target.parentNode.parentNode.id;if(n==UID["tabSearch_tsc_0"]){if(Data.options.search.sort_list=="0")Data.options.search.sort_list="-0";else Data.options.search.sort_list="0"}else if(n==UID["tabSearch_tsc_1"]){if(Data.options.search.sort_list=="1")Data.options.search.sort_list="-1";else Data.options.search.sort_list="1"}else if(n==UID["tabSearch_tsc_2"]){if(Data.options.search.sort_list=="2")Data.options.search.sort_list="-2";else Data.options.search.sort_list="2"}else if(n==UID["tabSearch_tsc_3"]){if(Data.options.search.sort_list=="3")Data.options.search.sort_list="-3";else Data.options.search.sort_list="3"}else if(n==UID["tabSearch_tsc_4"]){if(Data.options.search.sort_list=="4")Data.options.search.sort_list="-4";else Data.options.search.sort_list="4"}else if(n==UID["tabSearch_tsc_5"]){if(Data.options.search.sort_list=="5")Data.options.search.sort_list="-5";else Data.options.search.sort_list="5"}t.tabSearchC()}function d(){var e=Tabs.Search;switch(Data.options.search.sort_list){case"-0":n.sort(function(e,t){return t.d-e.d});break;case"0":n.sort(function(e,t){return e.d-t.d});break;case"-1":n.sort(function(e,t){return t.x-e.x});break;case"1":n.sort(function(e,t){return e.x-t.x});break;case"-2":n.sort(function(e,t){e=e.a.toLowerCase();t=t.a.toLowerCase();if(e>t)return-1;if(e<t)return 1;return 0});break;case"2":n.sort(function(e,t){e=e.a.toLowerCase();t=t.a.toLowerCase();if(e>t)return 1;if(e<t)return-1;return 0});break;case"-3":n.sort(function(e,t){e=e.n.toLowerCase();t=t.n.toLowerCase();if(e>t)return-1;if(e<t)return 1;return 0});break;case"3":n.sort(function(e,t){e=e.n.toLowerCase();t=t.n.toLowerCase();if(e>t)return 1;if(e<t)return-1;return 0});break;case"-4":n.sort(function(e,t){return t.m-e.m});break;case"4":n.sort(function(e,t){return e.m-t.m});break;case"-5":n.sort(function(e,t){return t.t-e.t});break;case"5":n.sort(function(e,t){return e.t-t.t});break;default:n.sort(function(e,t){return t.d-e.d});break}}var e=Tabs.Search;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabSearchC"]).className="selected";document.getElementById(UID["tabSearchC"]).style.zIndex=1;e.lastSubTab="tabSearchC";e.contentType=0;if(!as(Data.options.search.last_update))kLastupdate=" ("+Data.options.search.last_update+")";else kLastupdate="";var t="<div id="+bS("tabSearch_Results")+' style="height:500px">'+"	<div class="+UID["title"]+">"+translate("Player cities list")+kLastupdate+"</div>"+"	<div id="+bS("tabSearch_ResultList")+" class="+UID["status_ticker"]+'	 style="height:475px; max-height:475px; width:540px; max-width:540px; overflow:auto; white-space:nowrap; margin-top:1px !important"></div>'+"	</div>";document.getElementById(UID["tabSearch_Content"]).innerHTML=t;var t="<table class="+UID["row_style"]+" width=100%>"+"	<tr class="+UID["row_headers"]+">"+"		<td id="+bS("tabSearch_tsc_0")+' width="20px"><A><span>'+translate("Dist")+"</span></A></td>"+"		<td id="+bS("tabSearch_tsc_1")+' width="40px"><A><span>'+translate("Coords")+"</span></A></td>";if(Data.options.search.target.alliance=="*"||Data.options.search.target.alliance=="-1"||Data.options.search.target.alliance=="1")t+="	<td id="+bS("tabSearch_tsc_2")+"><A><span>"+translate("Alliance")+"</span></A></td>";t+="		<td id="+bS("tabSearch_tsc_3")+' width="200px" style="overflow-x:auto"><A><span>'+translate("members")+"</span></A></td>"+"		<td id="+bS("tabSearch_tsc_4")+' width="40px" align=right><A><span>'+translate("Might")+"</span></A></td>"+'		<td width="40px" align=right>'+translate("Evol")+"</td>"+"		<td id="+bS("tabSearch_tsc_5")+"><A><span>"+translate("Type")+"</span></A></td>"+'		<td style="background:none"></td>'+"	</tr>";var n=e.getCityList(),r=[];d();for(var i=0;i<n.length;i++){t+="<tr><td>"+n[i].d+"</td><td align=center>"+n[i].x+","+n[i].y+"</td>";if(Data.options.search.target.alliance=="*"||Data.options.search.target.alliance=="-1"||Data.options.search.target.alliance=="1")t+="<td align=left>"+eQ(n[i].ai,n[i].a)+"</td>";if(n[i].m!=null&&n[i].m!="?")mightF=bD(n[i].m," ");else mightF="?";var s="x";if(Data.map.evolution[n[i].id]&&n[i].m&&n[i].m!="?"){s=n[i].m-Data.map.evolution[n[i].id].m;if(s<0)s="<span class="+UID["red"]+">"+bD(s," ")+"</span>";else if(s>0)s="<span class="+UID["green"]+">+"+bD(s," ")+"</span>";else s=bD(s," ")}t+="<td align=left>"+eQ(n[i].ai,n[i].n)+"</td>"+"<td align=right>"+mightF+"</td>"+"<td align=right>"+s+"</td>"+"<td align=center>"+(n[i].t>9?translate(Map.names.type[n[i].t]):"")+"</td>"+"<td><input id="+bS("tabSearch_Spy_"+i)+" ref="+i+' class=Xtrasmall style="width:auto !important;" type=submit value="'+translate("Spy")+'" />';if(n[i].id&&n[i].id!=""&&n[i].n&&n[i].n!=""){var o=n[i].id+"_"+n[i].n;var u=bS("tabSearch_Msg_"+i);t+="	&nbsp &nbsp<input id="+u+" ref="+o+' class="Xtrasmall '+UID["btn_blue"]+'" style="width:auto !important;" type=submit value="'+translate("Msg")+'" /></td>';r.push(u)}else{t+="</td>"}t+="</tr>"}document.getElementById(UID["tabSearch_ResultList"]).innerHTML=t+"</table>";for(var a=0;a<6;a++)if(a!=2||(Data.options.search.target.alliance=="*"||Data.options.search.target.alliance=="-1"||Data.options.search.target.alliance=="1")&&a==2)document.getElementById(UID["tabSearch_tsc_"+a]).addEventListener("click",p,false);var f=Seed.player.alliance?Seed.player.alliance.id:-1;for(var i=0;i<n.length;i++){var l=document.getElementById(UID["tabSearch_Spy_"+i]);l.addEventListener("click",h,false);if((n[i].t>9&&n[i].t!=20||n[i].t<9)&&(!n[i].ai||n[i].ai==0||n[i].ai==null||n[i].ai!=f)){l.disabled=false;Element.removeClassName(l,UID["btn_disabled"]);Element.addClassName(l,UID["btn_green"])}else{l.disabled=true;Element.removeClassName(l,UID["btn_green"]);Element.addClassName(l,UID["btn_disabled"])}}for(var c=0;c<r.length;c++)document.getElementById(r[c]).addEventListener("click",bF,false)},tabSearchW:function(){function n(e){var t=Tabs.Search;var n=e.target.id;var r=bV(e.target.value);if(isNaN(r)||r<1||r>10){e.target.style.backgroundColor="red"}else{if(n==UID["tabSearch_LvMin"])Data.options.search.min_level=r;else Data.options.search.max_level=r;e.target.value=r;var i=Data.options.search.min_level;var o=Data.options.search.max_level;if(i>o)e.target.style.backgroundColor="red";else{e.target.style.backgroundColor="";s()}}}function r(e,t){var n=bS("tabSearch_Lv"+e);var r='<select id="'+n+'">';for(var i=1;i<=10;i++)r+='<option value="'+i+'" '+(t==i?"selected":"")+">"+i+"</option>";r+="</select>";return r}function i(){var e=Tabs.Search;var t=document.getElementById(UID["tabSearch_WildG"]);var n=document.getElementById(UID["tabSearch_WildL"]);var r=document.getElementById(UID["tabSearch_WildP"]);var i=document.getElementById(UID["tabSearch_WildH"]);var o=document.getElementById(UID["tabSearch_WildM"]);var u=document.getElementById(UID["tabSearch_WildF"]);var a=document.getElementById(UID["tabSearch_Unowned"]);Data.options.search.grassland=t.checked;Data.options.search.lake=n.checked;Data.options.search.plain=r.checked;Data.options.search.hill=i.checked;Data.options.search.mountain=o.checked;Data.options.search.forest=u.checked;Data.options.search.unowned=a.checked;s()}function s(){function p(t){function s(e){if(e!="OK"){i.getContentDiv().innerHTML="<b>"+e+"</b>";i.allowClose(true)}else{i.getContentDiv().innerHTML="<B>"+translate("OK")+"</b>";setTimeout(function(){i.destroy()},1e3)}}var r=bV(t.target.getAttribute("ref"));var i=new aw(e.container,300,150,"",false);i.bd().innerHTML="<div class="+UID["title"]+"><center><b>"+scriptName+" : "+translate("Message")+"</b></center></div>";i.getContentDiv().innerHTML=translate("Attacking");d(n[r],s)}function d(e,t){var n=Tabs.Search;var r=Seed.cities[CAPITAL.id].id;var i=CAPITAL.id;var s=null;var o=[];o["Spy"]=1;attackUnits=bb(CAPITAL.id,o);if(attackUnits!=null){t(aW(attackUnits,"fb"));return}s=bB();if(s==null){t(aW(3,"fb"));return}var u="<B>"+translate("Manual attack sent to")+"</B>: "+e.n+" "+translate("at")+" "+e.x+"/"+e.y;aZ(u+" "+translate("attempted"));new MyAjax.marchSend(r,e.x,e.y,s.id,o,"attacks",function(e){if(e.ok&&e.dat.result.success){aZ(u+" "+translate("Successfully"));aX(u);if(t)t("OK")}else{aZ(u+" "+translate("failed and returned error")+": "+e.errmsg);if(t)t(translate("Error")+": "+e.errmsg)}})}function v(e){var t=Tabs.Search;var n=e.target.parentNode.parentNode.id;if(n==UID["tabSearch_tsw_0"]){if(Data.options.search.sort_list=="0")Data.options.search.sort_list="-0";else Data.options.search.sort_list="0"}else if(n==UID["tabSearch_tsw_1"]){if(Data.options.search.sort_list=="1")Data.options.search.sort_list="-1";else Data.options.search.sort_list="1"}else if(n==UID["tabSearch_tsw_2"]){if(Data.options.search.sort_list=="2")Data.options.search.sort_list="-2";else Data.options.search.sort_list="2"}else if(n==UID["tabSearch_tsw_3"]){if(Data.options.search.sort_list=="3")Data.options.search.sort_list="-3";else Data.options.search.sort_list="3"}else if(n==UID["tabSearch_tsw_4"]){if(Data.options.search.sort_list=="4")Data.options.search.sort_list="-4";else Data.options.search.sort_list="4"}else if(n==UID["tabSearch_tsw_5"]){if(Data.options.search.sort_list=="5")Data.options.search.sort_list="-5";else Data.options.search.sort_list="5"}else if(n==UID["tabSearch_tsw_6"]){if(Data.options.search.sort_list=="6")Data.options.search.sort_list="-6";else Data.options.search.sort_list="6"}s()}function m(){var e=Tabs.Search;switch(Data.options.search.sort_list){case"-0":n.sort(function(e,t){return t.d-e.d});break;case"0":n.sort(function(e,t){return e.d-t.d});break;case"-1":n.sort(function(e,t){return t.x-e.x});break;case"1":n.sort(function(e,t){return e.x-t.x});break;case"-2":n.sort(function(e,t){e=e.a.toLowerCase();t=t.a.toLowerCase();if(e>t)return-1;if(e<t)return 1;return 0});break;case"2":n.sort(function(e,t){e=e.a.toLowerCase();t=t.a.toLowerCase();if(e>t)return 1;if(e<t)return-1;return 0});break;case"-3":n.sort(function(e,t){e=e.n.toLowerCase();t=t.n.toLowerCase();if(e>t)return-1;if(e<t)return 1;return 0});break;case"3":n.sort(function(e,t){e=e.n.toLowerCase();t=t.n.toLowerCase();if(e>t)return 1;if(e<t)return-1;return 0});break;case"-4":n.sort(function(e,t){return t.m-e.m});break;case"4":n.sort(function(e,t){return e.m-t.m});break;case"-5":n.sort(function(e,t){return t.t-e.t});break;case"5":n.sort(function(e,t){return e.t-t.t});break;case"-6":n.sort(function(e,t){return t.l-e.l});break;case"6":n.sort(function(e,t){return e.l-t.l});break;default:n.sort(function(e,t){return t.d-e.d});break}}var e=Tabs.Search;var t="<table class="+UID["row_style"]+" id="+bS("tabSearch_WildTab")+" width=100%>"+"	<tr class="+UID["row_headers"]+">"+"		<td id="+bS("tabSearch_tsw_0")+' width="20px"><A><span>'+translate("Dist")+"</span></A></td>"+"		<td id="+bS("tabSearch_tsw_1")+' width="40px"><A><span>'+translate("Coords")+"</span></A></td>"+"		<td id="+bS("tabSearch_tsw_5")+' width="60px"><A><span>'+translate("Type")+"</span></A></td>"+"		<td id="+bS("tabSearch_tsw_6")+' width="20px"><A><span>'+translate("Level")+"</span></A></td>"+"		<td id="+bS("tabSearch_tsw_3")+' width="200px" style="overflow-x:auto"><A><span>'+translate("Owner")+"</span></A></td>"+"		<td id="+bS("tabSearch_tsw_4")+' width="40px" align=right><A><span>'+translate("Might")+"</span></A></td>"+"		<td id="+bS("tabSearch_tsw_2")+"><A><span>"+translate("Alliance")+"</span></A></td>"+'		<td style="background:none"></td>'+"	</tr>";var n=e.getWildernessesList(),r=[];m();for(var i=0;i<n.length;i++){var o=null;if(n[i].m!=null&&n[i].m!="?")o=bD(n[i].m," ");else o="?";if(n[i].l<7&&!n[i].n){n[i].n="-";n[i].a="-";o="-"}t+="<tr><td>"+n[i].d+"</td>"+"	<td align=center>"+n[i].x+","+n[i].y+"</td>"+"	<td align=left>"+translate(Map.names.type[n[i].t])+"</td>"+"	<td align=right>"+n[i].l+"</td>"+"	<td align=left>"+eQ(n[i].ai,n[i].n)+"</td>"+"	<td align=right>"+o+"</td>"+"	<td align=left>"+eQ(n[i].ai,n[i].a)+"</td>"+"	<td>"+"		<input id="+bS("tabSearch_Att_"+i)+" ref="+i+' class=Xtrasmall style="width:auto !important;" type=submit value="'+translate("Attack")+'" />';if(n[i].id&&n[i].id!=""&&n[i].n&&n[i].n!=""&&n[i].n!="-"){var u=n[i].id+"_"+n[i].n;var a=bS("tabSearchWild_Msg_"+i);t+="	&nbsp &nbsp<input id="+a+" ref="+u+' class="Xtrasmall '+UID["btn_blue"]+'" style="width:auto !important;" type=submit value="'+translate("Msg")+'" /></td>';r.push(a)}t+="	</td>"+"</tr>"}document.getElementById(UID["tabSearch_WildList"]).innerHTML=t+"</table>";for(var f=0;f<7;f++)document.getElementById(UID["tabSearch_tsw_"+f]).addEventListener("click",v,false);for(var l=0;l<r.length;l++)document.getElementById(r[l]).addEventListener("click",bF,false);var c=Seed.player.alliance?Seed.player.alliance.id:-1;for(var i=0;i<n.length;i++){var h=document.getElementById(UID["tabSearch_Att_"+i]);h.addEventListener("click",p,false);if(!n[i].ai||n[i].ai==0||n[i].ai==null||n[i].ai!=c){h.disabled=false;Element.removeClassName(h,UID["btn_disabled"]);Element.addClassName(h,UID["btn_green"])}else{h.disabled=true;Element.removeClassName(h,UID["btn_green"]);Element.addClassName(h,UID["btn_disabled"])}}}var e=Tabs.Search;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabSearchW"]).className="selected";document.getElementById(UID["tabSearchW"]).style.zIndex=1;e.lastSubTab="tabSearchW";e.contentType=1;var t="<div class="+UID["content"]+">"+"<table class="+UID["table"]+" width=100%>"+"	<tr>"+"		<td width=3%><input id="+bS("tabSearch_WildG")+" type=checkbox "+(Data.options.search.grassland?"CHECKED":"")+" /></td>"+"		<td width=20%> "+translate("Grassland")+"</td>"+"		<td width=3%><input id="+bS("tabSearch_WildL")+" type=checkbox "+(Data.options.search.lake?"CHECKED":"")+" /></td>"+"		<td width=20%> "+translate("Lake")+"</td>"+"		<td width=3%><input id="+bS("tabSearch_WildP")+" type=checkbox "+(Data.options.search.plain?"CHECKED":"")+" /></td>"+"		<td width=20%> "+translate("Plain")+"</td>"+"		<td width=31%>"+translate("Min level")+": "+r("Min",bK(Data.options.search.min_level,"1"))+"</td>"+"	</tr><tr>"+"		<td><input id="+bS("tabSearch_WildH")+" type=checkbox "+(Data.options.search.hill?"CHECKED":"")+" /></td>"+"		<td> "+translate("Hill")+"</td>"+"		<td><input id="+bS("tabSearch_WildM")+" type=checkbox "+(Data.options.search.mountain?"CHECKED":"")+" /></td>"+"		<td> "+translate("Mountain")+"</td>"+"		<td><input id="+bS("tabSearch_WildF")+" type=checkbox "+(Data.options.search.forest?"CHECKED":"")+" /></td>"+"		<td> "+translate("Forest")+"</td>"+"		<td width=31%>"+translate("Max level")+": "+r("Max",bK(Data.options.search.max_level,"10"))+"</td>"+"	</tr>"+"</table>"+"<table class="+UID["table"]+" width=100%>"+"	<tr>"+"		<td width=3%><input id="+bS("tabSearch_Unowned")+" type=checkbox "+(Data.options.search.unowned?"CHECKED":"")+" /></td>"+"		<td width=20%> "+translate("Unowned only")+"</td>"+"		<td width=77% align=center>&nbsp</td>"+"	</tr>"+"</table>"+"</div>"+"<div id="+bS("tabSearch_Wilds")+' style="height:430px">'+"	<div class="+UID["title"]+">"+translate("Wildernesses list")+"</div>"+"	<div id="+bS("tabSearch_WildList")+" class="+UID["status_ticker"]+'	 style="height:400px; max-height:400px; width:540px; max-height:540px; overflow:auto; white-space:nowrap; margin-top:1px !important"></div>'+"	</div>";document.getElementById(UID["tabSearch_Content"]).innerHTML=t;document.getElementById(UID["tabSearch_WildG"]).addEventListener("click",i,false);document.getElementById(UID["tabSearch_WildL"]).addEventListener("click",i,false);document.getElementById(UID["tabSearch_WildP"]).addEventListener("click",i,false);document.getElementById(UID["tabSearch_WildH"]).addEventListener("click",i,false);document.getElementById(UID["tabSearch_WildM"]).addEventListener("click",i,false);document.getElementById(UID["tabSearch_WildF"]).addEventListener("click",i,false);document.getElementById(UID["tabSearch_LvMin"]).addEventListener("change",n,false);document.getElementById(UID["tabSearch_LvMax"]).addEventListener("change",n,false);document.getElementById(UID["tabSearch_Unowned"]).addEventListener("click",i,false);s()},refreshMapData:function(e){var t=Tabs.Search;t.checkMapBusy=false;t.checkMapData(e);t.show()},checkMapData:function(e){var t=Tabs.Search;if(t.checkMapBusy)return false;t.checkMapBusy=true;Data.options.search.target.alliance="*";Data.options.search.target.player="*";t.scanMap(e,Data.options.search.target.distance,function(){bI("****** Setting checkMapBusy to FALSE");Tabs.Search.checkMapBusy=false});return true},scanMap:function(e,t,n){function u(e){if(e==null){progressBarPop.getContentDiv().innerHTML="<B>"+translate("Bummer, there was an error while scanning the map")+".</B>";progressBarPop.allowClose(true);if(n)n(false);return}if(e.done){aX("<B>scanMap</B>: "+translate("complete"));var t=be();Data.options.search.last_update=(new Date(t*1e3)).myString();if(n)n(true);progressBarPop.destroy()}}var r=Tabs.Search;if(e==0||e==1){for(var i in Data.map.players){if(Data.map.players[i]&&Data.map.players[i][2]){if(!Data.map.evolution[i])Data.map.evolution[i]={};Data.map.evolution[i].m=Data.map.players[i][2]}}}var s=Data.options.search.target.x;var o=Data.options.search.target.y;if(t==null)t=Data.options.search.target.distance||16;bI("======> search tab scanMap ("+s+","+o+", "+t+")");progressBar.init(800+Math.randRange(1,50),100,300,150,translate("Message"),200,true,r.container);switch(e){case 0:progressBar.start({steps:100,delay:1,byCount:true,title:translate("Scanning map for cities/wildernesses")+"...",stepText:translate("Please wait...")});Map.scanMap({x:s,y:o,radius:t,city_detail:true,wild_detail:true,force_request:true},u);break;case 1:progressBar.start({steps:100,delay:1,byCount:true,title:translate("Scanning map for cities")+"...",stepText:translate("Please wait...")});Map.scanMap({x:s,y:o,radius:t,city_detail:true,wild_detail:false,force_request:true},u);break;case 2:progressBar.start({steps:100,delay:1,byCount:true,title:translate("Scanning map for wildernesses")+"...",stepText:translate("Please wait...")});Map.scanWilds({x:s,y:o,radius:t},u);break}}};Tabs.Single={tabOrder:SINGLE_TAB_ORDER,tabLabel:"Single",tabDisabled:!SINGLE_TAB_ENABLE,container:null,contentType:0,lastSubTab:"tabSingleAttack",init:function(e){var t=Tabs.Single;t.container=e;var n="<div class="+UID["title"]+">"+translate("Single attack")+"</div>"+"<ul class=tabs>"+'	<li class="tab first"><a id='+bS("tabSingleAttack")+">"+translate("Attack")+"</a></li>"+"	<li class=tab><a id="+bS("tabSinglePresets")+">"+translate("Presets")+"</a></li>"+"	<li class=tab><a id="+bS("tabSingleTargets")+">"+translate("Targets")+"</a></li>"+"</ul>"+"<div id="+bS("tabSingle_Content")+' style="padding-top:0px; height:655px; max-height:655px; overflow-y:auto; width:540px; max-width:540px; overflow-x:auto"></div>';t.container.innerHTML=n;document.getElementById(UID["tabSingleAttack"]).addEventListener("click",t.tabSingleAttack,false);document.getElementById(UID["tabSinglePresets"]).addEventListener("click",t.tabSinglePresets,false);document.getElementById(UID["tabSingleTargets"]).addEventListener("click",t.tabSingleTargets,false);window.addEventListener("unload",t.onUnload,false);t.contentType=bV(Data.options.single.current_tab);t.show()},show:function(){var e=Tabs.Single;switch(bV(e.contentType)){case 0:e.tabSingleAttack();break;case 1:e.tabSinglePresets();break;case 2:e.tabSingleTargets();break}},onUnload:function(){var e=Tabs.Single;bI("===============  Tabs.Single.onUnload");Data.options.single.current_tab=e.contentType},tabSingleAttack:function(){function d(t){dJ(e.container,Data.options.single.target)}function v(){function n(e){if(e!="OK"){try{t.getContentDiv().innerHTML="<B>"+e+"</b>";t.allowClose(true)}catch(n){}}else{try{t.getContentDiv().innerHTML="<b>"+translate("OK")+"</b>";setTimeout(function(){t.destroy()},1e3)}catch(n){}}}var t=new aw(e.container,300,150,"",false);t.bd().innerHTML="<div class="+UID["title"]+"><center><b>"+scriptName+" : "+translate("Message")+"</b></center></div>";t.getContentDiv().innerHTML=translate("Attacking");m(n)}function m(e){var t=Tabs.Single;var n=Seed.cities[CAPITAL.id].id;var r=CAPITAL.id;var i,s;var o=Data.options.single.target;var u=aA(o.units);s=bb(CAPITAL.id,u);if(s!=null){e(aW(s,"fb"));return}if((i=bB())==null){e(aW(3,"fb"));return}var a=null;if(o.include_great_dragon){if((a=dC(true,o.dragons))==null){e(aW(5,"fb"));return}if(a&&a!=null)u[a]=1}var f=translate("Single attack sent to")+": "+o.type+translate(" at ")+o.x+"/"+o.y;aZ(f+" "+translate("attempted"));new MyAjax.marchSend(n,o.x,o.y,i.id,u,"attacks",function(t){if(t.ok){aZ(f+" "+translate("Successfully"));aX(f);e("OK")}else{aZ(f+" "+translate("failed and returned error")+": "+t.errmsg);e(translate("Error")+": "+t.errmsg)}})}function g(e){dq("tabSingle",Data.options.single.target.units,Data.options.single.target)}function y(e){var t=Tabs.Single;var n=e.target.name.split("_");if(n[0]=="SA"){var r=all_unit_types[n[1]];var i=Data.options.single.target.units;i[r]=e.target.value;var i=Data.options.single.target.saved_units;i[r]=e.target.value;var s=ba(Data.options.single.target.x,Data.options.single.target.y,Data.options.single.target.units);document.getElementById(UID["tabSingle_Distance"]).innerHTML=bu(Seed.cities[CAPITAL.id].x,Seed.cities[CAPITAL.id].y,Data.options.single.target.x,Data.options.single.target.y)+" ("+bz(s)+")"}}function b(e){var t=Tabs.Single;var n=Seed.cities[CAPITAL.id];var r=bV(e.target.getAttribute("ref"));var i=Data.options.single.presets[r].units;var s={};Data.options.single.target.units={};for(var o=0;o<all_unit_types.length;o++){Data.options.single.target.units[all_unit_types[o]]=0;Data.options.single.target.saved_units[all_unit_types[o]]=0}for(var u in i){var a=aV(n,u);var f=a.incity;if(f<i[u]&&i[u]>0)s[u]=f;else if(i[u]<=0)s[u]=0;else s[u]=i[u];Data.options.single.target.units[u]=s[u];Data.options.single.target.saved_units[u]=s[u]}document.getElementById(UID["tabSingle_Troops"]).innerHTML="<tr align=center class="+UID["row_headers"]+">"+"	<td colspan=10>"+translate("Troops")+":&nbsp;</td></tr>";du(document.getElementById(UID["tabSingle_Troops"]),1,"SA",all_unit_types,Data.options.single.target.units,Data.options.single.target.saved_units,y,true)}function w(e){var t=Tabs.Single;var n=bV(e.target.getAttribute("ref"));Data.options.single.preset.name=Data.options.single.presets[n].name;Data.options.single.preset.units=aA(Data.options.single.presets[n].units);t.tabSinglePresets()}function E(e){var t=Tabs.Single;var n=bV(e.target.getAttribute("ref"));Data.options.single.presets.splice(n,1);t.tabSingleAttack()}function S(){var e=Tabs.Single;if(Data.options.single.history&&Data.options.single.history.length>0){var t=aA(Data.options.single.history);for(var n=t.length-1;n>=0;n--){if(t[n].x==Data.options.single.target.x&&t[n].y==Data.options.single.target.y)Data.options.single.history.splice(n,1)}}var r={x:Data.options.single.target.x,y:Data.options.single.target.y,type:Data.options.single.target.type,level:Data.options.single.target.level,id:Data.options.single.target.id,n:Data.options.single.target.n,units:aA(Data.options.single.target.saved_units),dragons:aA(Data.options.single.target.dragons),ai:Data.options.single.target.ai,inc:Data.options.single.target.include_great_dragon,comment:Data.options.single.target.comment};Data.options.single.history.push(r)}function x(t){var n=bV(t.target.getAttribute("ref"));dj(e.container,Data.options.single.target.x,Data.options.single.target.y,Data.options.single.target.type,Data.options.single.target.level,Data.options.single.target.id,Data.options.single.target.n,Data.options.single.target.saved_units,Data.options.single.target.ai,Data.options.single.target.include_great_dragon,true,Data.options.single.target.dragons,Data.options.single.target.comment)}var e=Tabs.Single;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabSingleAttack"]).className="selected";document.getElementById(UID["tabSingleAttack"]).style.zIndex=1;e.lastSubTab="tabSingleAttack";e.contentType=0;var t='<div class="'+UID["title"]+'">'+translate("Max ")+translate("Troops")+" "+bD(bV(bJ(CAPITAL.id).max_troops)," ")+"</div>"+"<div class="+UID["content"]+">"+"	<div>"+"		<b>"+translate("Coords")+":&nbsp;</b>&nbsp;"+"		X: <input id="+bS("tabSingle_CoordsX")+' size=1 maxlength=3 type=text value="'+Data.options.single.target.x+'" /> '+"		Y: <input id="+bS("tabSingle_CoordsY")+' size=2 maxlength=3 type=text value="'+Data.options.single.target.y+'" /> '+"		&nbsp <b>"+translate("Distance")+":</b> <span id="+bS("tabSingle_Distance")+"></span>"+"		&nbsp <input id="+bS("tabSingle_Save")+' class="'+UID["btn_green"]+' small" style="width:auto !important;" type=submit value=" '+translate("Save")+' " />'+"		&nbsp <input id="+bS("tabSingle_Spy")+' class="'+UID["btn_green"]+' small" style="width:auto !important;" type=submit value=" '+translate("Spy")+' " />'+"		&nbsp <input id="+bS("tabSingle_Bookmark")+' class="'+UID["btn_blue"]+' small" style="width:auto !important;" type=submit value=" '+translate("Bookmark")+' " />';if(Data.options.single.target.id&&Data.options.single.target.id!=""&&Data.options.single.target.n&&Data.options.single.target.n!=""){var n=Data.options.single.target.id+"_"+Data.options.single.target.n;t+="	&nbsp <input id="+bS("tabSingle_Msg")+" ref="+n+' class="'+UID["btn_blue"]+' small" style="width:auto !important;" type=submit value=" '+translate("Msg")+' " />'}t+="	<br><br><label>"+translate("description")+" :</label>&nbsp"+"		<textarea id="+bS("tabSingle_Comment")+' cols="80" rows="2" wrap="PHYSICAL">'+Data.options.single.target.comment+"</textarea>"+'		<br><center><input type=button value="'+translate("Attack")+'" id='+bS("tabSingle_Attack")+" class="+UID["btn_red"]+" /></center><br>"+"		<div class="+UID["status_ticker"]+' style="height:auto !important;margin:5px 10px !important;">'+"			<center><span id="+bS("tabSingle_Tile")+"></span></center>"+"		</div>"+"	</div>"+"  <div>"+"	<table id="+bS("tabSingle_Troops")+" class="+UID["table"]+" width=100%>"+"		<tr align=center class="+UID["row_headers"]+">"+"			<td colspan=10>"+translate("Troops")+":&nbsp;</td>"+"		</tr>"+"	</table>"+"	</div><br>"+"  <div>"+"	<table id="+bS("tabSingle_Dragons")+" class="+UID["table"]+" width=100%>"+"		<tr align=center class="+UID["row_headers"]+">"+"			<td colspan=10>"+translate("Include Great Dragon")+":&nbsp;</td>";var r=[];for(var i=0;i<Seed.dragonList.length;i++){var s=Seed.dragonList[i];if(i%5===0)t+="</tr><tr>";t+='	<td class=right><span title="'+translate(s.type)+'">'+translate(Names.getTroopAbbr(s.type))+":<span></td>"+"	<td align=center><input type=checkbox id="+bS("tabSingle_Dragons_"+i)+' ref="'+i+'" '+(Data.options.single.target.dragons[s.type]?" checked":"")+" /></td>";r.push(i)}t+="</tr>"+"	</table>"+"</div></div><br>"+"<div class="+UID["status_ticker"]+' style="height:260px; max-height:260px; overflow-y:auto; margin-top:15px !important">'+'	<table class="'+UID["table_targets"]+'">'+"	<tr class="+UID["row_headers"]+" cellpadding=1 >"+"		<td width=15%>"+translate("Preset")+"</td>"+"		<td width=55%>"+translate("Troops")+"</td>"+"	</tr>";var o,u=[];for(var a=0;a<Data.options.single.presets.length;a++){if(a%2==1)o="White";else o="rgb(239,239,224)";t+='<tr valign=middle style="border-bottom: 1px solid #898989; background-color:'+o+'"><td width=15%>'+Data.options.single.presets[a].name+"</td>"+"	<td align=left width=55%>"+cq(Data.options.single.presets[a].units," ")+"</td>"+"	<td align=center width=30%><input id="+bS("tabSingle_SetTroops_"+a)+" ref="+a+' class="Xtrasmall '+UID["btn_blue"]+'" style="width:auto !important;" type=submit value="'+translate("Choose")+'" />&nbsp'+"		<input id="+bS("tabSingle_Edit_"+a)+" ref="+a+' class="Xtrasmall '+UID["btn_green"]+'" style="width:auto !important;" type=submit value="'+translate("Edit")+'" />&nbsp'+"		<input id="+bS("tabSingle_Delete_"+a)+" ref="+a+' class="Xtrasmall '+UID["btn_red"]+'" style="width:auto !important;" type=submit value=" X " /></td>'+"</tr>";u.push(UID["tabSingle_SetTroops_"+a])}+"</div>";document.getElementById(UID["tabSingle_Content"]).innerHTML=t;document.getElementById(UID["tabSingle_CoordsX"]).addEventListener("change",g,false);document.getElementById(UID["tabSingle_CoordsY"]).addEventListener("change",g,false);document.getElementById(UID["tabSingle_Save"]).addEventListener("click",S,false);document.getElementById(UID["tabSingle_Bookmark"]).addEventListener("click",x,false);document.getElementById(UID["tabSingle_Comment"]).addEventListener("change",function(){Data.options.single.target.comment=document.getElementById(UID["tabSingle_Comment"]).value},false);document.getElementById(UID["tabSingle_Attack"]).addEventListener("click",v,false);if(Data.options.single.target.id&&Data.options.single.target.id!=""&&Data.options.single.target.n&&Data.options.single.target.n!="")document.getElementById(UID["tabSingle_Msg"]).addEventListener("click",bF,false);du(document.getElementById(UID["tabSingle_Troops"]),1,"SA",all_unit_types,Data.options.single.target.units,Data.options.single.target.saved_units,y,true);for(var i=0;i<r.length;++i){document.getElementById(UID["tabSingle_Dragons_"+r[i]]).addEventListener("change",function(e){var t=e.target.getAttribute("ref");Data.options.single.target.dragons[Seed.dragonList[t].type]=e.target.checked;var n=false;for(var r=0;r<Seed.dragonList.length&&!n;r++){var i=Seed.dragonList[r];if(Data.options.single.target.dragons[i.type])n=true}if(n)Data.options.single.target.include_great_dragon=true;else Data.options.single.target.include_great_dragon=false},false)}for(var a=0;a<u.length;a++){var f=document.getElementById(UID["tabSingle_SetTroops_"+a]);var l=document.getElementById(UID["tabSingle_Edit_"+a]);var c=document.getElementById(UID["tabSingle_Delete_"+a]);f.addEventListener("click",b,false);l.addEventListener("click",w,false);c.addEventListener("click",E,false)}g();var h=document.getElementById(UID["tabSingle_Spy"]);h.addEventListener("click",d,false);var p=Data.options.single.target;if(!p.ai||p.ai==0||p.ai==null||p.ai!=(Seed.player.alliance?Seed.player.alliance.id:-1))bG(h,true,"btn_green","btn_disabled");else bG(h,false,"btn_green","btn_disabled")},tabSinglePresets:function(){function a(e){var t=e.target.id.split("_");var n=bV(e.target.value);for(i=0;i<all_unit_types.length;i++)document.getElementById(UID["tabSingle_Trp"]+"_"+i).style.backgroundColor="";if(isNaN(n)||n<-1)e.target.style.backgroundColor="red";else e.target.style.backgroundColor="";e.target.value=n;Data.options.single.preset.units[all_unit_types[t[1]]]=n}function f(){var e=Tabs.Single;for(var t=0;t<all_unit_types.length;t++)Data.options.single.preset.units[all_unit_types[t]]=0;e.tabSinglePresets()}function l(){var e=Tabs.Single;if(Data.options.single.presets&&Data.options.single.presets.length>0){var t=aA(Data.options.single.presets);for(var n=t.length-1;n>=0;n--){if(t[n].name==Data.options.single.preset.name)Data.options.single.presets.splice(n,1)}}var r={name:Data.options.single.preset.name,units:aA(Data.options.single.preset.units)};Data.options.single.presets.push(r);e.tabSinglePresets()}function c(t){var n=t.target.id.split("_");var r=0;var i=bV(Seed.cities[CAPITAL.id].units[all_unit_types[n[1]]]);e.totalForces=0;for(var s=0;s<all_unit_types.length;s++)if(s!=n[1])e.totalForces=bV(e.totalForces)+bV(Data.options.single.preset.units[all_unit_types[s]]);r=bJ(CAPITAL.id).max_troops-bV(e.totalForces);if(r>i)r=i;Data.options.single.preset.units[all_unit_types[n[1]]]=bV(r);e.tabSinglePresets()}var e=Tabs.Single;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabSinglePresets"]).className="selected";document.getElementById(UID["tabSinglePresets"]).style.zIndex=1;e.lastSubTab="tabSinglePresets";e.contentType=1;var t="<div class="+UID["title"]+">"+translate("Army presets")+"</div>"+"	<div id="+bS("tabSingle_Presets")+" class="+UID["status_ticker"]+' style="margin-bottom:5px !important">'+"	<label><b>"+translate("Preset name")+" :</b></label>"+"	&nbsp &nbsp<input id="+bS("tabSingle_Name")+' size=30 maxlength=50 type=text value="'+Data.options.single.preset.name+'" /><br><br>'+"	<table id="+bS("tabSingle_Troops")+" class="+UID["table"]+">"+"		<tr align=left class="+UID["row_headers_left"]+">"+"			<td colspan=3 width=50%>"+translate("Troops")+":&nbsp;</td>"+"			<td width=15%>"+translate("Total")+"</td>"+"		</tr>";var n=bS("tabSingle_Trp");var r=bS("tabSingle_MaxT");var s=Seed.cities[CAPITAL.id];for(i=0;i<all_unit_types.length;i++){var o=bV(Data.options.single.preset.units[all_unit_types[i]]);var u=aV(s,all_unit_types[i]);t+="<tr><td class=right width=25%>"+translate(Names.troops.byName[all_unit_types[i]][1])+":</td>"+"	<td width=15%><input type=text id="+n+"_"+i+' maxlength=9 style="width:55px" size=2 value="'+o+'"></td>'+"	<td width=10%><input class=small id="+r+"_"+i+" ref="+i+' type=button  style="width:auto !important;" value=" Max " ></td>'+"	<td align=right width=15%>"+bD(u.total," ")+"</td>"+"	<td width=35%>&nbsp</td>"+"</tr>"}t+="</table><br>"+"<table class="+UID["table"]+' style="margin-top:3px" width=60%>'+"	<tr valign=top align=center>"+"		<td width=40%><label><input id="+bS("tabSingle_clearAll")+' type=button class="'+UID["btn_green"]+'" value="'+translate("Clear all")+'" /></label></td>'+"		<td width=40%><label><input id="+bS("tabSingle_savePreset")+' type=button value="'+translate("Save preset")+'" /></label></td>'+"	</tr>"+"</table><br>"+"<br></div>";document.getElementById(UID["tabSingle_Content"]).innerHTML=t;document.getElementById(UID["tabSingle_Name"]).addEventListener("change",function(){Data.options.single.preset.name=document.getElementById(UID["tabSingle_Name"]).value},false);document.getElementById(UID["tabSingle_clearAll"]).addEventListener("click",f,false);document.getElementById(UID["tabSingle_savePreset"]).addEventListener("click",l,false);for(i=0;i<all_unit_types.length;i++){document.getElementById(n+"_"+i).addEventListener("change",a,false);butMax=document.getElementById(r+"_"+i);butMax.addEventListener("click",c,false);bG(butMax,true,"btn_green")}},tabSingleTargets:function(){function v(t){var n=bV(t.target.getAttribute("ref"));dJ(e.container,Data.options.single.history[n])}function m(t){var n=bV(t.target.getAttribute("ref"));Data.options.single.target.x=Data.options.single.history[n].x;Data.options.single.target.y=Data.options.single.history[n].y;Data.options.single.target.type=Data.options.single.history[n].type;Data.options.single.target.level=Data.options.single.history[n].level;Data.options.single.target.id=Data.options.single.history[n].id;Data.options.single.target.n=Data.options.single.history[n].n;Data.options.single.target.ai=Data.options.single.history[n].ai;Data.options.single.target.units=aA(Data.options.single.history[n].units);Data.options.single.target.dragons=aA(Data.options.single.history[n].dragons);Data.options.single.target.saved_units=aA(Data.options.single.history[n].units);Data.options.single.target.include_great_dragon=Data.options.single.history[n].inc;Data.options.single.target.comment=Data.options.single.history[n].comment;e.tabSingleAttack()}function g(t){var n=bV(t.target.getAttribute("ref"));Data.options.single.history.splice(n,1);e.tabSingleTargets()}function y(t){var n=bV(t.target.getAttribute("ref"));dj(e.container,Data.options.single.history[n].x,Data.options.single.history[n].y,Data.options.single.history[n].type,Data.options.single.history[n].level,Data.options.single.history[n].id,Data.options.single.history[n].n,Data.options.single.history[n].units,Data.options.single.history[n].ai,Data.options.single.history[n].inc,true,Data.options.single.history[n].dragons,Data.options.single.history[n].comment)}var e=Tabs.Single;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabSingleTargets"]).className="selected";document.getElementById(UID["tabSingleTargets"]).style.zIndex=1;e.lastSubTab="tabSingleTargets";e.contentType=2;var t='<div class="'+UID["title"]+'">'+translate("Targets")+"</div>"+"	<div id="+bS("tabSingle_Targets")+" class="+UID["status_ticker"]+' style="height:390px; max-height:390px; width:540px; max-width:540px; overflow-y:auto ; overflow-x:auto ; margin-top:1px !important"></div>'+"	</div>";document.getElementById(UID["tabSingle_Content"]).innerHTML=t;var t="<table class="+UID["row_style"]+">"+"	<tr class="+UID["row_headers"]+">"+'		<td width="15px">&nbsp</td>'+'		<td width="35px"><A><span>'+translate("Dist")+"</span></A></td>"+'		<td width="50px"><A><span>'+translate("Coords")+"</span></A></td>"+'		<td width="160px"><A><span>'+translate("Target")+"</span></A></td>"+'		<td width="175px"><A><span>'+translate("Troops")+"</span></A></td>"+"	</tr>";var n=[];for(var r=0;r<Data.options.single.history.length;r++){var i="",s="";if(!Data.options.single.history[r].comment||Data.options.single.history[r].comment==null||Data.options.single.history[r].comment=="")i='style="border-bottom: 1px solid #898989;"';if(r%2==1)s="White";else s="rgb(239,239,224)";var o=ba(Data.options.single.history[r].x,Data.options.single.history[r].y,Data.options.single.history[r].units);t+='<tr valign=top style="background-color:'+s+'">'+"	<td><input id="+bS("tabSingle_Delete_"+r)+" ref="+r+' class="Xtrasmall '+UID["btn_red"]+'" style="width:auto !important;" type=submit value=" X " /></td>'+"	<td "+i+">"+bu(Seed.cities[CAPITAL.id].x,Seed.cities[CAPITAL.id].y,Data.options.single.history[r].x,Data.options.single.history[r].y)+"<br> ("+bz(o)+")</td>"+"	<td align=center "+i+">"+Data.options.single.history[r].x+","+Data.options.single.history[r].y+"</td>"+"	<td align=left "+i+">"+Data.options.single.history[r].type+"</td>"+"	<td align=left "+i+">"+cq(Data.options.single.history[r].units,"<br>")+"</td>"+"	<td><input id="+bS("tabSingle_Recall_"+r)+" ref="+r+' class="Xtrasmall '+UID["btn_green"]+'" style="width:auto !important;" type=submit value="'+translate("Recall")+'" /><br>'+"		<input id="+bS("tabSingle_Bookmark_"+r)+" ref="+r+' class="Xtrasmall '+UID["btn_blue"]+'" style="width:auto !important;" type=submit value="'+translate("Bookmark")+'" /></td>';if(Data.options.single.history[r].id&&Data.options.single.history[r].id!=""&&Data.options.single.history[r].n&&Data.options.single.history[r].n!=""){var u=Data.options.single.history[r].id+"_"+Data.options.single.history[r].n;var a=bS("tabSingle_Msg_"+r);t+="	<td><input id="+bS("tabSingle_Spy_"+r)+" ref="+r+' class="Xtrasmall '+UID["btn_green"]+'" style="width:auto !important;" type=submit value="'+translate("Spy")+'" /><br>'+"		<input id="+a+" ref="+u+' class="Xtrasmall '+UID["btn_blue"]+'" style="width:auto !important;" type=submit value="'+translate("Msg")+'" /></td>';n.push(a)}else{t+="	<td><input id="+bS("tabSingle_Spy_"+r)+" ref="+r+' class="Xtrasmall '+UID["btn_green"]+'" style="width:auto !important;" type=submit value="'+translate("Spy")+'" /></td>'}t+="</tr>";if(Data.options.single.history[r].comment&&Data.options.single.history[r].comment!=null&&Data.options.single.history[r].comment!="")t+='<tr valign=top style="background-color:'+s+'"><td colspan=4 style="border-bottom: 1px solid #898989;">'+Data.options.single.history[r].comment+"</td><td colspan=2>&nbsp</td></tr>"}document.getElementById(UID["tabSingle_Targets"]).innerHTML=t+"</table>";for(var r=0;r<Data.options.single.history.length;r++){var f=document.getElementById(UID["tabSingle_Recall_"+r]);var l=document.getElementById(UID["tabSingle_Delete_"+r]);var c=document.getElementById(UID["tabSingle_Bookmark_"+r]);var h=document.getElementById(UID["tabSingle_Spy_"+r]);f.addEventListener("click",m,false);l.addEventListener("click",g,false);c.addEventListener("click",y,false);h.addEventListener("click",v,false);var p=Data.options.single.history[r];if(!p.ai||p.ai==0||p.ai==null||p.ai!=(Seed.player.alliance?Seed.player.alliance.id:-1))bG(h,true,"btn_green","btn_disabled");else bG(h,false,"btn_green","btn_disabled")}for(var d=0;d<n.length;d++)document.getElementById(n[d]).addEventListener("click",bF,false)},hide:function(){var e=Tabs.Single;Data.options.single.current_tab=e.contentType}};Tabs.Spies={tabOrder:SPY_TAB_ORDER,tabLabel:"Spy",tabDisabled:!SPY_TAB_ENABLE,container:null,enabled:false,attackTimer:null,marchTimer:null,attackErrors:0,contentType:0,lastSubTab:"tabSpyAttack",running:{start_at:0},last_report:null,init:function(e){var t=Tabs.Spies;Data.setDefaultValues("spies");t.container=e;var n="<div class="+UID["title"]+">"+translate("Spy One Target")+"</div>"+"<div id="+bS("tabSpy_Status")+" class="+UID["status_ticker"]+' style="margin-bottom:5px !important">'+"	<center><input id="+bS("tabSpy_OnOff")+' type=button value="OnOff" /></center>'+"	<div id="+bS("tabSpy_Report")+' style="margin-top:5px;height:140px; max-height:140px; width:540px; max-width:540px; overflow:auto;">'+"		<table id="+bS("tabSpy_Marches")+" class="+UID["table"]+"></table>"+"	</div>"+"	<div id="+bS("tabSpy_Feedback")+" class="+UID["status_feedback"]+"></div>"+"</div>"+"<ul class=tabs>"+'	<li class="tab first"><a id='+bS("tabSpyAttack")+">"+translate("Spy")+"</a></li>"+"	<li class=tab><a id="+bS("tabSpyHistory")+">"+translate("History")+"</a></li>"+"	<li class=tab><a id="+bS("tabSpyStats")+">"+translate("Stats")+"</a></li>"+"	<li class=tab><a id="+bS("tabSpyLastReport")+">"+translate("Last report")+"</a></li>"+"</ul>"+"<div id="+bS("tabSpy_Content")+' style="padding-top:0px; height:440px; overflow-y:auto"></div>';t.container.innerHTML=n;document.getElementById(UID["tabSpyAttack"]).addEventListener("click",t.tabSpyAttack,false);document.getElementById(UID["tabSpyHistory"]).addEventListener("click",t.tabSpyHistory,false);document.getElementById(UID["tabSpyStats"]).addEventListener("click",t.tabSpyStats,false);document.getElementById(UID["tabSpyLastReport"]).addEventListener("click",t.tabSpyLastReport,false);document.getElementById(UID["tabSpy_OnOff"]).addEventListener("click",function(){t.setSpyEnable(!Data.options.spies.enabled)},false);t.contentType=bV(Data.options.spies.current_tab,0);t.marchTick();t.setSpyEnable(false);window.addEventListener("unload",t.onUnload,false);t.show()},show:function(){var e=Tabs.Spies;e.marchTick();switch(e.contentType||0){case 0:e.tabSpyAttack();break;case 1:e.tabSpyHistory();break;case 2:e.tabSpyStats();break;case 3:e.tabSpyLastReport();break}},hide:function(){var e=Tabs.Spies;clearTimeout(e.marchTimer);Data.options.spies.current_tab=e.contentType},onUnload:function(){var e=Tabs.Spies;if(Data.options.spies.enabled&&e.running.start_at!=0)Data.stats.spies.run_time+=be()-e.running.start_at;Data.options.spies.current_tab=e.contentType},tabSpyAttack:function(){function r(e){var t=bV(e.target.value);var n=bV(t*1.5);if(t<bK(MIN_DELAY_BETWEEN_WAVE,3)||t>3600){e.target.style.backgroundColor="red";return}document.getElementById(UID["tabSpy_DelayMax"]).innerHTML=n;e.target.style.backgroundColor="";Data.options.spies.delay_min=t;Data.options.spies.delay_max=n}function i(e){var t=bV(document.getElementById(UID["tabSpy_MaxMarches"]).value);if(t<0||t>Seed.cities[CAPITAL.id].figures.marches.maximum){e.target.style.backgroundColor="red";return}e.target.style.backgroundColor="";Data.options.spies.max_marches=t}function s(){var e=Tabs.Spies;if(Data.options.spies.history&&Data.options.spies.history.length>0){var t=aA(Data.options.spies.history);for(var n=t.length-1;n>=0;n--){if(t[n].x==Data.options.spies.target.x&&t[n].y==Data.options.spies.target.y)Data.options.spies.history.splice(n,1)}}var r={x:Data.options.spies.target.x,y:Data.options.spies.target.y,type:Data.options.spies.target.type,level:Data.options.spies.target.level,id:Data.options.spies.target.id,n:Data.options.spies.target.n,units:aA(Data.options.spies.target.units),ai:Data.options.spies.target.ai,comment:Data.options.spies.target.comment};Data.options.spies.history.push(r)}var e=Tabs.Spies;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabSpyAttack"]).className="selected";document.getElementById(UID["tabSpyAttack"]).style.zIndex=1;e.lastSubTab="tabSpyAttack";e.contentType=0;var t='<div class="'+UID["title"]+'">'+translate("Spy")+"</div>"+"<div class="+UID["content"]+">"+"	<div>"+"		<b>"+translate("Coords")+":&nbsp;</b>&nbsp;"+"		X: <input id="+bS("tabSpy_CoordsX")+' size=1 maxlength=3 type=text value="'+Data.options.spies.target.x+'" /> '+"		Y: <input id="+bS("tabSpy_CoordsY")+' size=2 maxlength=3 type=text value="'+Data.options.spies.target.y+'" /> '+"		&nbsp <b>"+translate("Distance")+":</b> <span id="+bS("tabSpy_Distance")+"></span>"+"		&nbsp <input id="+bS("tabSpy_Save")+' class="'+UID["btn_green"]+' small" style="width:auto !important;" type=submit value=" '+translate("Save")+' " />';if(Data.options.spies.target.id&&Data.options.spies.target.id!=""&&Data.options.spies.target.n&&Data.options.spies.target.n!=""){var n=Data.options.spies.target.id+"_"+Data.options.spies.target.n;t+="	&nbsp <input id="+bS("tabSpy_Msg")+" ref="+n+' class="'+UID["btn_blue"]+' small" style="width:auto !important;" type=submit value=" '+translate("Msg")+' " />'}t+="		<br><br><label>"+translate("description")+" :</label>&nbsp"+"		<textarea id="+bS("tabSpy_Comment")+' cols="80" rows="2" wrap="PHYSICAL">'+Data.options.spies.target.comment+"</textarea><br>"+"		<div class="+UID["status_ticker"]+' style="height:auto !important;margin:5px 10px !important;">'+"			<center><span id="+bS("tabSpy_Tile")+"></span></center>"+"		</div>"+"	</div>"+"  <div>"+"	<table id="+bS("tabSpy_Troops")+" class="+UID["table"]+">"+"		<tr align=center class="+UID["row_headers"]+">"+"			<td colspan=8>"+translate("Spies number")+":&nbsp;</td>"+"		</tr>"+"	</table>"+"	</div><br>"+"	<table class="+UID["table"]+">"+"		<tr>"+"			<td class=right> "+translate("Delete spy Reports")+":&nbsp;</td>"+"			<td><input id="+bS("tabSpy_DelReports")+" type=checkbox "+(Data.options.spies.delete_reports?"CHECKED":"")+" /></td>"+"		</tr><tr>"+"			<td class=right>"+translate("Stop if any troops lost")+":&nbsp;</td>"+"			<td><input id="+bS("tabSpy_StopOnLoss")+" type=checkbox "+(Data.options.spies.stop_on_loss?"CHECKED":"")+" /></td>"+"		</tr><tr>"+"			<td class=right>"+translate("Delay Between Attacks")+":&nbsp;</td>"+"			<td>"+"				<input id="+bS("tabSpy_DelayMin")+' type=text size=1 maxlength=4 value="'+Data.options.spies.delay_min+'" />'+"				 to <span id="+bS("tabSpy_DelayMax")+">"+Data.options.spies.delay_max+"</span>&nbsp;"+translate("seconds")+"			</td>"+"		</tr><tr>"+"			<td class=right> "+translate("Maximum simultaneous marches")+":&nbsp;</td>"+"			<td><input id="+bS("tabSpy_MaxMarches")+' type=text size=1 maxlength=2 value="'+Data.options.spies.max_marches+'" /></td>'+"		</tr>"+"	</table>"+"</div>";document.getElementById(UID["tabSpy_Content"]).innerHTML=t;document.getElementById(UID["tabSpy_CoordsX"]).addEventListener("change",e.bU,false);document.getElementById(UID["tabSpy_CoordsY"]).addEventListener("change",e.bU,false);document.getElementById(UID["tabSpy_Save"]).addEventListener("click",s,false);document.getElementById(UID["tabSpy_Comment"]).addEventListener("change",function(){Data.options.spies.target.comment=document.getElementById(UID["tabSpy_Comment"]).value},false);document.getElementById(UID["tabSpy_DelReports"]).addEventListener("click",function(e){Data.options.spies.delete_reports=e.target.checked},false);document.getElementById(UID["tabSpy_StopOnLoss"]).addEventListener("click",function(e){Data.options.spies.stop_on_loss=e.target.checked},false);document.getElementById(UID["tabSpy_DelayMin"]).addEventListener("change",r,false);document.getElementById(UID["tabSpy_MaxMarches"]).addEventListener("change",i,false);if(Data.options.spies.target.id&&Data.options.spies.target.id!=""&&Data.options.spies.target.n&&Data.options.spies.target.n!="")document.getElementById(UID["tabSpy_Msg"]).addEventListener("click",bF,false);du(document.getElementById(UID["tabSpy_Troops"]),1,"SP",spy_unit_types,Data.options.spies.target.units,undefined,e.bi,false);e.bU()},tabSpyHistory:function(){function h(t){var n=bV(t.target.getAttribute("ref"));Data.options.spies.target.x=Data.options.spies.history[n].x;Data.options.spies.target.y=Data.options.spies.history[n].y;Data.options.spies.target.type=Data.options.spies.history[n].type;Data.options.spies.target.level=Data.options.spies.history[n].level;Data.options.spies.target.id=Data.options.spies.history[n].id;Data.options.spies.target.n=Data.options.spies.history[n].n;Data.options.spies.target.ai=Data.options.spies.history[n].ai;Data.options.spies.target.units=aA(Data.options.spies.history[n].units);Data.options.spies.target.comment=Data.options.spies.history[n].comment;e.tabSpyAttack()}function p(t){var n=bV(t.target.getAttribute("ref"));Data.options.spies.history.splice(n,1);e.tabSpyHistory()}var e=Tabs.Spies;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabSpyHistory"]).className="selected";document.getElementById(UID["tabSpyHistory"]).style.zIndex=1;e.lastSubTab="tabSpyHistory";e.contentType=1;var t='<div class="'+UID["title"]+'">'+translate("History")+"</div>"+"	<div id="+bS("tabSpy_HistoryList")+" class="+UID["status_ticker"]+' style="height:400px; max-height:400px; width:540px; max-width:540px; overflow-y:auto ; overflow-x:auto ; margin-top:1px !important"></div>'+"	</div>";document.getElementById(UID["tabSpy_Content"]).innerHTML=t;var t="<table class="+UID["row_style"]+">"+"	<tr class="+UID["row_headers"]+">"+'		<td width="10px">&nbsp</td>'+'		<td width="35px"><A><span>'+translate("Dist")+"</span></A></td>"+'		<td width="50px"><A><span>'+translate("Coords")+"</span></A></td>"+'		<td width="160px"><A><span>'+translate("Target")+"</span></A></td>"+'		<td width="175px"><A><span>'+translate("Troops")+"</span></A></td>"+"	</tr>";var n=[];for(var r=0;r<Data.options.spies.history.length;r++){var i="",s="";if(!Data.options.spies.history[r].comment||Data.options.spies.history[r].comment==null||Data.options.spies.history[r].comment=="")i='style="border-bottom: 1px solid #898989;"';if(r%2==1)s="White";else s="rgb(239,239,224)";var o=ba(Data.options.spies.history[r].x,Data.options.spies.history[r].y,Data.options.spies.history[r].units);t+='<tr valign=top style="background-color:'+s+'">'+"	<td><input id="+bS("tabSpy_Delete_"+r)+" ref="+r+' class="Xtrasmall '+UID["btn_red"]+'" style="width:auto !important;" type=submit value=" X " /></td>'+"	<td "+i+">"+bu(Seed.cities[CAPITAL.id].x,Seed.cities[CAPITAL.id].y,Data.options.spies.history[r].x,Data.options.spies.history[r].y)+"<br> ("+bz(o)+")</td>"+"	<td align=center "+i+">"+Data.options.spies.history[r].x+","+Data.options.spies.history[r].y+"</td>"+"	<td align=left "+i+">"+Data.options.spies.history[r].type+"</td>"+"	<td align=left "+i+">"+cq(Data.options.spies.history[r].units,"<br>")+"</td>"+"	<td><input id="+bS("tabSpy_Recall_"+r)+" ref="+r+' class="Xtrasmall '+UID["btn_green"]+'" style="width:auto !important;" type=submit value="'+translate("Recall")+'" />';if(Data.options.spies.history[r].id&&Data.options.spies.history[r].id!=""&&Data.options.spies.history[r].n&&Data.options.spies.history[r].n!=""){var u=Data.options.spies.history[r].id+"_"+Data.options.spies.history[r].n;var a=bS("tabSpy_Msg_"+r);t+="	<br><input id="+a+" ref="+u+' class="Xtrasmall '+UID["btn_blue"]+'" style="width:auto !important;" type=submit value="'+translate("Msg")+'" />';n.push(a)}t+="</td></tr>";if(Data.options.spies.history[r].comment&&Data.options.spies.history[r].comment!=null&&Data.options.spies.history[r].comment!="")t+='<tr valign=top style="background-color:'+s+'"><td colspan=5 style="border-bottom: 1px solid #898989;">'+Data.options.spies.history[r].comment+"</td><td colspan=2>&nbsp</td></tr>"}document.getElementById(UID["tabSpy_HistoryList"]).innerHTML=t+"</table>";for(var r=0;r<Data.options.spies.history.length;r++){var f=document.getElementById(UID["tabSpy_Recall_"+r]);var l=document.getElementById(UID["tabSpy_Delete_"+r]);f.addEventListener("click",h,false);l.addEventListener("click",p,false)}for(var c=0;c<n.length;c++)document.getElementById(n[c]).addEventListener("click",bF,false)},tabSpyStats:function(){var e=Tabs.Spies;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabSpyStats"]).className="selected";document.getElementById(UID["tabSpyStats"]).style.zIndex=1;e.lastSubTab="tabSpyStats";e.contentType=2;var t="<div class="+UID["title"]+">"+translate("Attacks Stats")+"</div>"+"<div id="+bS("tabSpyStats_Statbox")+" class="+UID["status_ticker"]+">"+"<div id="+bS("tabSpyStats_Status")+"></div>"+"<br/>"+"<center><input id="+bS("tabSpyStats_Clear")+' type=button value="'+translate("Clear Stats")+'" /></center>'+"<br></div>";document.getElementById(UID["tabSpy_Content"]).innerHTML=t;document.getElementById(UID["tabSpyStats_Clear"]).addEventListener("click",function(){e.aY();e.bL()},false);e.bL()},tabSpyLastReport:function(){var e=Tabs.Spies;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabSpyLastReport"]).className="selected";document.getElementById(UID["tabSpyLastReport"]).style.zIndex=1;e.lastSubTab="tabSpyLastReport";e.contentType=3;var t="<div id="+bS("tabSpy_ShowReport")+" class="+UID["status_ticker"]+' style="height:395px; max-height:395px; width:540px; max-width:540px; overflow-y:auto ; overflow-x:auto ; margin-top:1px !important"></div>';document.getElementById(UID["tabSpy_Content"]).innerHTML=t;var t="<div class="+UID["title"]+">"+translate("Last report")+"</div>";if(e.last_report)t+="<center>"+Messages.displaySpyReport(e.last_report)+"</center>";document.getElementById(UID["tabSpy_ShowReport"]).innerHTML=t},gotSpyReport:function(e){function a(e,t){var n="Recall march "+t;aZ(n+" "+translate("attempted"));new MyAjax.marchRecall(e,t,function(e){if(e.ok){aZ(n+" "+translate("succeeded"))}else{aZ(n+" "+translate("failed and returned error")+": "+e.errmsg)}})}var t=Tabs.Spies,n=false;if(!e)return;if(e.report.location.x==Data.options.spies.target.x&&e.report.location.y==Data.options.spies.target.y&&e.report_notification.report_type=="SpyReport"){t.last_report=Messages.details[e.report_notification.id];var r=null;for(var i in Data.marches.spies){r=i;break}if(as(Data.stats.spies.total_attacks))Data.stats.spies.total_attacks=0;++Data.stats.spies.total_attacks;for(var s in e.report.attacker.units){if(e.report.attacker.units[s][0]!=e.report.attacker.units[s][1]){var o=bV(e.report.attacker.units[s][0])-bV(e.report.attacker.units[s][1]);aF(Data.stats.spies.loss,s,o,true)}}Data.marches.spies[r].has_report=true;t.bL();if(Data.options.spies.stop_on_loss&&e.report.attacker.name==Seed.player.name){for(var s in e.report.attacker.units){if(e.report.attacker.units[s][0]!=e.report.attacker.units[s][1]){n=true;var u=(new Date(e.report_notification.created_at*1e3)).myString();t.setSpyEnable(false);aS(UID["tabSpy_Feedback"],translate("Troops lost")+"! ("+u+")");aX(translate("Spy")+": "+translate("Troops lost")+"! ("+u+")");for(var i in Data.marches.spies){if(Data.marches.spies[i].status==="marching")a(Data.marches.spies[i].city_id,i)}return}}}if(Data.options.spies.delete_reports&&e.report.attacker.name==Seed.player.name&&!n)Messages.deleteMessage(e.report_notification.id)}},aY:function(){var e=Tabs.Spies;var t=be();Data.stats.spies={start_at:t,run_time:0,total_attacks:0,loss:{}};e.bL()},bL:function(){var e=Tabs.Spies;var t=document.getElementById(UID["tabSpyStats_Status"]);if(t==null)return;var n=Data.stats.spies.run_time;if(Data.options.spies.enabled)n+=be()-e.running.start_at;var r=n>0?n/3600:1;var i="<table class="+UID["table"]+">"+"	<tr>"+"		<td class=right>"+translate("Start Date")+": </td>"+"		<td colspan=>"+(new Date(Data.stats.spies.start_at*1e3)).myString()+"</td>"+"	</tr><tr>"+"		<td class=right>"+translate("Run Time")+": </td>"+"		<td>"+bE(n,true)+"</td>"+"	</tr><tr>"+"		<td class=right>"+translate("Attacks")+": </td>"+"		<td>"+Data.stats.spies.total_attacks+"</td>"+"	<tr valign=top align=right>"+"		<td class=right>"+translate("Troops lost")+": </td>";var s=true;for(var o in Data.stats.spies.loss){var u=Math.round(Data.stats.spies.loss[o]/r);if(s)s=false;else i+="	<tr align=right><td></td>";i+="		<td>"+translate(o)+":</td>"+"		<td>"+bD(Data.stats.spies.loss[o]," ")+"</td>"+"		<td>("+bD(u," ")+" /"+translate("h")+")</td>"+"	</tr>"}i+="</table>";t.innerHTML=i},bU:function(e){dq("tabSpy",Data.options.spies.target.units,Data.options.spies.target)},bi:function(e){var t=Tabs.Spies;var n=e.target.name.split("_");if(n[0]=="SP"){var r=spy_unit_types[n[1]];var i=Data.options.spies.target.units;i[r]=e.target.value;var s=ba(Data.options.spies.target.x,Data.options.spies.target.y,Data.options.spies.target.units);document.getElementById(UID["tabSpy_Distance"]).innerHTML=bu(Seed.cities[CAPITAL.id].x,Seed.cities[CAPITAL.id].y,Data.options.spies.target.x,Data.options.spies.target.y)+" ("+bz(s)+")"}},setSpyEnable:function(e){var t=Tabs.Spies;var n=document.getElementById(UID["tabSpy_OnOff"]);clearTimeout(t.attackTimer);Data.options.spies.enabled=e;if(e){Messages.addSpyReportListener(t.gotSpyReport);n.value=translate("Attacking").toUpperCase();n.className=UID["btn_on"];t.spyAttackTick();t.running.start_at=be();Data.stats.spies.start_at=be()}else{Messages.removeReportListener("spies",t.gotSpyReport);n.value=translate("Disabled").toUpperCase();n.className=UID["btn_off"];if(t.running.start_at!==0){Data.stats.spies.run_time+=be()-t.running.start_at}}},spyAttackTick:function(){var e=Tabs.Spies,t,n,r,i=0;clearTimeout(e.attackTimer);if(!Data.options.spies.enabled)return;t=Data.options.spies.target.type+translate(" at ")+Data.options.spies.target.x+"/"+Data.options.spies.target.y;var s=translate("Spy to ")+t;var o=UID["tabSpy_Feedback"];var u=cK();i=u.count;n=u.delay;var a=dB(s,o,i,n,Marches.count.spies,Data.options.spies.max_marches,null,false);if(a!=0){e.attackTimer=setTimeout(e.spyAttackTick,n*1e3);return}r=bb(CAPITAL.id,Data.options.spies.target.units);if(r!==null){bM(s,o,r,true,n);e.attackTimer=setTimeout(e.spyAttackTick,n*1e3);return}aZ(s+" "+translate("attempted"));new MyAjax.marchSpy(Seed.cities[CAPITAL.id].id,Data.options.spies.target.x,Data.options.spies.target.y,Data.options.spies.target.units,"spies",function(e){var t=Tabs.Spies,n,r;if(e.ok&&e.dat.result.success){t.attackErrors=0;var i=bV(Data.options.spies.delay_min,bK(MIN_DELAY_BETWEEN_WAVE,3));var u=bV(Data.options.spies.delay_max,bV(i*1.5));n=Math.floor(Math.random()*(u-i+1)+i);aZ(s+" "+translate("Successfully"));aX(s);aS(o,s);t.attackTimer=setTimeout(t.spyAttackTick,n*1e3)}else{t.attackErrors++;r=30*t.attackErrors*t.attackErrors;aZ(s+" "+translate("failed and returned error")+": "+e.errmsg+" - "+translate("Retry in")+" "+r+" "+translate("seconds"));aX(s+" "+translate("failed"));if(e.status===429){r=E429_DELAY;bM(s+" "+translate("failed")+" - <b>API</b> ",o,6,false,r)}else if(e.status===509){r=600;bM(s+" "+translate("failed")+" - ",o,6,false,r)}else aS(o,s+" "+translate("failed"));t.attackTimer=setTimeout(t.spyAttackTick,r*1e3)}})},marchTick:function(){var e=Tabs.Spies;clearTimeout(e.marchTimer);Marches.updateTable(document.getElementById(UID["tabSpy_Marches"]),"spies");e.marchTimer=setTimeout(e.marchTick,1e3)}};Tabs.Tower={tabOrder:TOWER_TAB_ORDER,tabLabel:"Tower",tabDisabled:!TOWER_TAB_ENABLE,container:null,alarmTimer:null,deleteTimer:null,fetchTimer:null,logTab:null,maxEntries:100,saveEntries:100,readList:[],clockTimer:0,checkSetDefenseBusy:false,contentType:0,lastSubTab:"tabTowerWall",intervalWarning:0,startup:true,init:function(e){var t=Tabs.Tower;t.container=e;var n="<div class="+UID["title"]+">"+translate("Sentinel tower")+"</div>"+"<div class="+UID["status_ticker"]+' style="height:250px; max-height:250px; overflow-y:auto ; margin-bottom:5px ; margin-top:1px !important">'+"	<div id="+bS("tabTower_LogList")+' style="height:227px; max-height:227px; overflow-y:auto ; overflow-x:auto; margin-bottom:1px">'+"		<table id="+bS("tabTower_Log")+" class="+UID["table_console"]+" cellpadding=0 cellspacing=1 width=100%>"+"		</table>"+"	</div>"+"	<div id="+bS("tabTower_Warning")+" valign=bottom></div>"+"</div>"+"<ul class=tabs>"+'	<li class="tab first"><a id='+bS("tabTowerWall")+">"+translate("Wall management")+"</a></li>"+"	<li class=tab><a id="+bS("tabTowerConfig")+">"+translate("Config")+"</a></li>"+"	<li class=tab><a id="+bS("tabTowerMessage")+">"+translate("Message")+"</a></li>"+"</ul>"+"<div id="+bS("tabTower_Content")+' style="padding-top:0px; height:405px; overflow-y:auto"></div>'+"<div id="+bS("tabTower_SwfPlayer")+"></div>";t.container.innerHTML=n;document.getElementById(UID["tabTowerWall"]).addEventListener("click",t.tabTowerWall,false);document.getElementById(UID["tabTowerConfig"]).addEventListener("click",t.tabTowerConfig,false);document.getElementById(UID["tabTowerMessage"]).addEventListener("click",t.tabTowerMessage,false);t.logTab=document.getElementById(UID["tabTower_Log"]);Data.options.messages_tower=[];t.printTab();t.deleteTick();Messages.addAlarmReportListener(t.gotAlarmReport);window.addEventListener("unload",t.onUnload,false);t.contentType=bV(Data.options.tower.current_tab);t.show();t.startup=false},tabTowerWall:function(){function r(){var e=Seed.cities[CAPITAL.id];var t="<table class="+UID["row_style"]+' style="margin-top:3px" width=100%>'+"	<tr class="+UID["row_headers"]+" align=center>"+"		<td width=40%>"+translate("Troops")+"</td>"+"		<td width=15%>"+translate("Total")+"</td>"+"		<td width=15%>"+translate("Defense")+"</td>"+"		<td width=15%>"+translate("In city")+"</td>"+"		<td width=15%>"+translate("In march")+"</td>"+"	</tr>";for(var n=0;n<all_unit_types.length;n++){var r=aV(e,all_unit_types[n]);t+="	<tr valign=top>"+"		<td class=right width=40%>"+translate(all_unit_types[n])+":</td>"+"		<td align=right width=15%>"+bD(r.total," ")+"</td>"+"		<td align=right width=15%>"+(r.indefense>0?"<b>"+bD(r.indefense," ")+"</b>":bD(r.indefense," "))+"</td>"+"		<td align=right width=15%>"+bD(r.incity," ")+"</td>"+"		<td align=right width=15%>"+(r.marches?"&nbsp;+&nbsp;<b>"+bD(r.marches," ")+"</b>":"")+"</td>"+"	</tr>"}t+="</table>";document.getElementById(UID["tabTower_DefForce"]).innerHTML=t}function i(){var e=Tabs.Tower;var t="<select id="+bS("tabTower_SelBoxPreset")+">";if(Data.options.wall.presets&&Data.options.wall.presets.length>0){for(var n=0;n<Data.options.wall.presets.length;n++){t+='<option value="'+Data.options.wall.presets[n].name+'" '+(Data.options.tower.preset==Data.options.wall.presets[n].name?"selected":"")+">"+Data.options.wall.presets[n].name+"</option>"}}else{t+='<option value="-" '+(Data.options.tower.preset=="-"?"selected":"")+">"+translate("None")+"</option>"}t+="</select>";document.getElementById(UID["tabTower_SelPreset"]).innerHTML=t}function s(){var e=Tabs.Tower;var t=Seed.cities[CAPITAL.id];var n="";var r=[];var i=false;if(Data.options.tower.preset&&Data.options.tower.preset!="-"){for(var s=0;s<Data.options.wall.presets.length&&!i;s++){if(Data.options.tower.preset==Data.options.wall.presets[s].name){i=true;var o=Data.options.wall.presets[s].units;for(var u in o){if(o[u]>0)r.push(bD(o[u]," ")+" "+translate(u));else if(o[u]==-1)r.push("Max "+translate(u))}}}if(r.length>0)n=r.join(", ");else n="---"}else n="---";document.getElementById(UID["tabTower_PresetTroops"]).innerHTML='<font color="#000000">'+n+"</font>";if(Data.options.tower.preset&&Data.options.tower.preset!="-"){document.getElementById(UID["tabTower_PresetButton"]).innerHTML="<input id="+bS("tabTower_SetDef")+' class="Xtrasmall '+UID["btn_blue"]+'" style="width:auto !important;" type=submit value="'+translate("Set Def")+'" />';document.getElementById(UID["tabTower_SetDef"]).addEventListener("click",f,false)}}function o(e){var t=Tabs.Tower;var n=document.getElementById(UID["tabTower_SelBoxPreset"]);var r=n.value;n.value=r;Data.options.tower.preset=r;s()}function u(){var e=Tabs.Tower;var t=Seed.cities[CAPITAL.id];var n={};for(var i=0;i<all_unit_types.length;i++){var s=aV(t,all_unit_types[i]);var o=s.incity+s.indefense;if(o>0)n[all_unit_types[i]]=o}if(e.checkSetDefenseBusy)return false;e.checkSetDefenseBusy=true;df(e.container,t.id,n,function(){bI(translate("wall-defenders-updated"));Tabs.Tower.checkSetDefenseBusy=false;r()})}function a(){var e=Tabs.Tower;var t=Seed.cities[CAPITAL.id];var n={};if(e.checkSetDefenseBusy)return false;e.checkSetDefenseBusy=true;df(e.container,t.id,n,function(){bI(translate("wall-defenders-updated"));Tabs.Tower.checkSetDefenseBusy=false;r()})}function f(){var e=Tabs.Tower;var t=Seed.cities[CAPITAL.id];if(Data.options.tower.preset&&Data.options.tower.preset!="-"){var n=false;for(var i=0;i<Data.options.wall.presets.length&&!n;i++){if(Data.options.tower.preset==Data.options.wall.presets[i].name){var s=Data.options.wall.presets[i].units;var o={};for(var u in s){var a=aV(t,u);var f=a.incity+a.indefense;if(f<s[u]||s[u]==-1)o[u]=f;else o[u]=s[u]}if(e.checkSetDefenseBusy)return false;e.checkSetDefenseBusy=true;df(e.container,t.id,o,function(){bI(translate("wall-defenders-updated"));Tabs.Tower.checkSetDefenseBusy=false;r()});n=true}}}}function l(e){var t=Tabs.Tower;var n=e.target;var r=Seed.cities[CAPITAL.id].id;var i=Seed.cities[CAPITAL.id].defended;var s=0;for(var o=0;o<all_unit_types.length;o++){s+=aV(Seed.cities[CAPITAL.id],all_unit_types[o]).indefense}if(s==0)return;var u=translate("Switching defense");aZ(u+" "+translate("attempted"));var a=new aw(t.container,300,165,"",false,null);a.bd().innerHTML="<div class="+UID["title"]+"><center><b>"+scriptName+" : "+translate("Message")+"</b></center></div>";a.getContentDiv().innerHTML=translate("Switch defense wall status");new MyAjax.dr(r,i,function(e){if(e.ok){aZ(u+" "+translate("Successfully"));aX(u);n.className=UID[Seed.cities[CAPITAL.id].defended?"btn_off":"btn_on"];n.value=translate(Seed.cities[CAPITAL.id].defended?"Defend":"Hiding").toUpperCase();a.destroy()}else{aZ(u+" "+translate("failed and returned error")+": "+e.errmsg);if(e.errmsg)a.getContentDiv().innerHTML=translate("Error while setting defense wall status")+" : "+e.errmsg;else a.getContentDiv().innerHTML=translate("Error while setting defense wall status");a.allowClose(true)}});var f=Seed.cities[CAPITAL.id].defended;n.className=UID[f?"btn_off":"btn_on"];n.value=translate(f?"Defend":"Hiding").toUpperCase()}var e=Tabs.Tower;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabTowerWall"]).className="selected";document.getElementById(UID["tabTowerWall"]).style.zIndex=1;e.lastSubTab="tabTowerWall";var t=translate(Seed.cities[CAPITAL.id].defended?"Defend":"Hiding").toUpperCase();e.contentType=0;var n='<div class="'+UID["title"]+'">'+translate("Wall management")+"</div>"+"<div id="+bS("tabTower_HistoryList")+" class="+UID["status_ticker"]+' style="height:355px; max-height:355px; width:540px; max-width:540px; overflow-y:auto ; overflow-x:auto ; margin-top:1px !important">'+"	<table class="+UID["table_targets"]+' style="margin-top:3px" width=100%>'+"		<tr valign=top>"+"			<td width=25%><label><input id="+bS("tabTower_AllDef")+' type=button value="'+translate("Troops max")+'" /></label></td>'+"			<td width=25%><label><input id="+bS("tabTower_NoDef")+' type=button value="'+translate("remove-all")+'" /></label></td>'+"			<td width=50% align=right><b>"+translate("wall-defense-strategy")+":</b>"+"			&nbsp <input id="+bS("tabTower_setWallStat")+" type=button value="+t+" class="+UID[Seed.cities[CAPITAL.id].defended?"btn_off":"btn_on"]+"></input></td>"+"		</tr>"+"	</table>"+"	<table class="+UID["table_targets"]+' style="margin-top:3px" width=100%>'+"		<tr valign=top>"+"			<td width=25%><div id="+bS("tabTower_SelPreset")+"></div></td>"+"			<td align=left width=65%><div id="+bS("tabTower_PresetTroops")+"></div></td>"+"			<td align=left width=10%><div id="+bS("tabTower_PresetButton")+"></div></td>"+"		</tr>"+"	</table>"+"	<div id="+bS("tabTower_DefForce")+"></div>"+"</div>";document.getElementById(UID["tabTower_Content"]).innerHTML=n;document.getElementById(UID["tabTower_AllDef"]).addEventListener("click",u,false);document.getElementById(UID["tabTower_NoDef"]).addEventListener("click",a,false);document.getElementById(UID["tabTower_setWallStat"]).addEventListener("click",l,false);document.getElementById(UID["tabTower_SelPreset"]).addEventListener("change",o,false);r();i();s()},tabTowerConfig:function(){function n(e){var t=Tabs.Tower;try{if(e=="attack")document.getElementById(UID["tabTower_Stop"]).disabled=false;else document.getElementById(UID["tabTower_SStop"]).disabled=false}catch(n){}SoundPlayer.PlaySound(e,true)}function r(e){var t=Tabs.Tower;Data.options.tower.enabled=e}function i(e){var t=Tabs.Tower;Data.options.tower.send_message=e}function s(e){var t=Tabs.Tower;Data.options.tower.nospy=e;t.printTab()}function o(e){var t=Tabs.Tower;Data.options.tower.delete_report=e;t.deleteTick()}function u(e){var t=Tabs.Tower;SoundPlayer.StopSound(e);if(e=="attack")document.getElementById(UID["tabTower_Stop"]).disabled=true;else document.getElementById(UID["tabTower_SStop"]).disabled=true}function a(){var e=Tabs.Tower;var t=aA(Data.options.attacks.units[1]);var n="";var r=[];for(var i in t){if(t[i]>0){var s=bD(t[i]," ")+" "+translate(i);r.push(s)}}if(r.length>0)test_troups=r.join(", ");var o=bV((new Date).getTime());var u=new Date(o+155e3);var a={id:1,type:0,arrive_at:u,alliance:"Tower alarm test",x:0,y:0,units:t,troups:test_troups,general:0,op:Seed.cities[WATER_OUTPOST.id]?Seed.cities[WATER_OUTPOST.id].id:0};Data.options.messages_tower.push(a);e._addTab(a,false)}function f(){var e=Tabs.Tower;var t={spy:1};var n="1 "+translate("spy");var r=bV((new Date).getTime());var i=new Date(r+105e3);var s={id:1,type:1,arrive_at:i,alliance:"Tower alarm test",x:0,y:0,units:t,troups:n,general:0,op:Seed.cities[CAPITAL.id]?Seed.cities[CAPITAL.id].id:0};Data.options.messages_tower.push(s);e._addTab(s,false)}function l(e){var t=Tabs.Tower;var n=document.getElementById(UID["tabTower_chkTime"]);var r=bV(n.value);n.value=r;Data.options.tower.delay=r}function c(e){var t=Tabs.Tower;var n=document.getElementById(UID["tabTower_DelTime"]);var r=bV(n.value);n.value=r;Data.options.tower.delete_delay=r;t.deleteTick()}function h(e,t,n,r){function o(e,t,n){function s(e){r=this.checked;if(i!=null)i(this.checked)}this.aK=s;var r=t;var i=n}var i=Tabs.Tower;var s=document.getElementById(e);if(r&&r()==false){s.disabled=true;return}if(t)s.checked=true;s.addEventListener("change",(new o(e,t,n)).aK,false)}function p(e){var t=Tabs.Tower;var n=document.getElementById(UID["tabTower_chkUnit"]);var r=bV(n.value);n.value=r;Data.options.tower.unit=r}function d(e){var t=Tabs.Tower;var n=document.getElementById(UID["tabTower_DelUnit"]);var r=bV(n.value);n.value=r;Data.options.tower.delete_unit=r;t.deleteTick()}var e=Tabs.Tower;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabTowerConfig"]).className="selected";document.getElementById(UID["tabTowerConfig"]).style.zIndex=1;e.lastSubTab="tabTowerConfig";e.contentType=1;var t='<div class="'+UID["title"]+'">'+translate("Tower configuration")+"</div>"+"<div id="+bS("tabTower_ConfigBox")+" class="+UID["status_ticker"]+' style="height:355px; max-height:355px; width:540px; max-width:540px; overflow-y:auto ; overflow-x:auto ; margin-top:1px !important">'+"<table class="+UID["table"]+' width=100% style="color:#000;">'+"	<tr valign=top>"+"		<td><label><input id="+bS("tabTower_Alert")+" type=checkbox /></label></td>"+"		<td colspan=2><label>"+translate("Enable the sentinel tower")+"</label></td>"+"	</tr><tr valign=top>"+"		<td></td><td colspan=2><label>"+translate("Check sentinel reports every ")+"</label>"+"		<input id="+bS("tabTower_chkTime")+' size=1 maxlength=2 type=text value="'+Data.options.tower.delay+'" />&nbsp'+"		<select id="+bS("tabTower_chkUnit")+" size=1>"+"			<option value=1 "+(Data.options.tower.unit==1?"selected":"")+">"+translate("Seconds")+"</option>"+"			<option value=60 "+(Data.options.tower.unit==60?"selected":"")+">"+translate("minutes")+"</option>"+"			<option value=3600 "+(Data.options.tower.unit==3600?"selected":"")+">"+translate("hours")+"</option>"+"		</select>"+"		</td>"+"	</tr><tr valign=top>"+'		<td  style="font-size:2px">&nbsp</td>'+"	</tr><tr valign=top>"+"		<td><label><input id="+bS("tabTower_NoSpy")+" type=checkbox /></label></td>"+"		<td colspan=2><label>"+translate("Hide spy alerts")+"</label></td>"+"	</tr><tr valign=top>"+"		<td><label><input id="+bS("tabTower_Del")+" type=checkbox /></label></td>"+"		<td colspan=2><label>"+translate("Do not show alerts obsolete since")+" :</label>"+"		<input id="+bS("tabTower_DelTime")+' size=1 maxlength=2 type=text value="'+Data.options.tower.delete_delay+'" />&nbsp'+"		<select id="+bS("tabTower_DelUnit")+" size=1>"+"			<option value=60 "+(Data.options.tower.delete_unit==60?"selected":"")+">"+translate("minutes")+"</option>"+"			<option value=3600 "+(Data.options.tower.delete_unit==3600?"selected":"")+">"+translate("hours")+"</option>"+"			<option value=86400 "+(Data.options.tower.delete_unit==86400?"selected":"")+">"+translate("days")+"</option>"+"		</select>"+"		</td>"+"	</tr><tr valign=top>"+"		<td><label><input id="+bS("tabTower_SendMsg")+" type=checkbox /></label></td>"+"		<td colspan=2><label>"+translate("Send a message to alliance members in case of attack")+"</label></td>"+"	</tr>"+"</table>"+"<br>"+"<table class="+UID["table"]+' style="color:#000;">'+"	<tr valign=top>"+"		<td colspan=2><b>"+translate("Sound configuration")+": </b></td>"+"	</tr><tr valign=top>"+"		<td><label><input id="+bS("tabTower_Sound")+" type=checkbox "+(Data.options.sound.enable_sentinel?"CHECKED ":"")+"/></label></td>"+"		<td><label>"+translate("Play sound on incoming sentinel report")+"</label></td>"+"	</tr><tr valign=top>"+"		<td></td>"+"		<td><table cellpadding=0 cellspacing=0>"+"				<tr valign=top>"+"					<td><label>"+translate("Attack sound file")+"</label></td>"+"					<td><input id="+bS("tabTower_File")+' size=50 maxlength=160 type=text value="'+Data.options.sound.URL_attack+'" />&nbsp</td>'+"					<td><input id="+bS("tabTower_Play")+" type=submit value=Play>"+"						<input id="+bS("tabTower_Stop")+" type=submit value=Stop>"+"						<input id="+bS("tabTower_Default")+" type=submit value=Default>"+"						<input id="+bS("tabTower_Test")+" type=submit value=Test></td>"+"				</tr><tr valign=top>"+"					<td><label>"+translate("Spy sound file")+"</label></td>"+"					<td><input id="+bS("tabTower_SFile")+' size=50 maxlength=160 type=text value="'+Data.options.sound.URL_spy+'" />&nbsp</td>'+"					<td><input id="+bS("tabTower_SPlay")+" type=submit value=Play>"+"						<input id="+bS("tabTower_SStop")+" type=submit value=Stop>"+"						<input id="+bS("tabTower_SDefault")+" type=submit value=Default>"+"						<input id="+bS("tabTower_STest")+" type=submit value=Test></td>"+"				</tr>"+"			</table>"+"		</td>"+"	</tr><tr valign=top>"+"		<td><label><input id="+bS("tabTower_Repeat")+" type=checkbox "+(Data.options.sound.repeat_attack?"CHECKED ":"")+"/></label></td>"+"		<td><label>"+translate("Repeat attack alarm every")+" </label>"+"			<input id="+bS("tabTower_Every")+' size=2 maxlength=5 type=text value="'+Data.options.sound.attack_rdelay+'" />'+translate("minutes").toLowerCase()+"</td>"+"	</tr><tr valign=top>"+"		<td><label><input id="+bS("tabTower_SRepeat")+" type=checkbox "+(Data.options.sound.repeat_spy?"CHECKED ":"")+"/></label></td>"+"		<td><label>"+translate("Repeat spy alarm every")+" </label>"+"			<input id="+bS("tabTower_SEvery")+' size=2 maxlength=5 type=text value="'+Data.options.sound.spy_rdelay+'" />'+translate("minutes").toLowerCase()+"</td>"+"	</tr>"+"</table>"+"</div>";document.getElementById(UID["tabTower_Content"]).innerHTML=t;h(UID["tabTower_Alert"],Data.options.tower.enabled,r);h(UID["tabTower_NoSpy"],Data.options.tower.nospy,s);h(UID["tabTower_Del"],Data.options.tower.delete_report,o);h(UID["tabTower_SendMsg"],Data.options.tower.send_message,i);document.getElementById(UID["tabTower_chkTime"]).addEventListener("change",l,false);document.getElementById(UID["tabTower_chkUnit"]).addEventListener("change",p,false);document.getElementById(UID["tabTower_DelTime"]).addEventListener("change",c,false);document.getElementById(UID["tabTower_DelUnit"]).addEventListener("change",d,false);document.getElementById(UID["tabTower_Sound"]).addEventListener("change",function(e){Data.options.sound.enable_sentinel=e.target.checked},false);document.getElementById(UID["tabTower_Repeat"]).addEventListener("change",function(e){Data.options.sound.repeat_attack=e.target.checked},false);document.getElementById(UID["tabTower_SRepeat"]).addEventListener("change",function(e){Data.options.sound.repeat_spy=e.target.checked},false);document.getElementById(UID["tabTower_Every"]).addEventListener("change",function(e){Data.options.sound.attack_rdelay=e.target.value},false);document.getElementById(UID["tabTower_SEvery"]).addEventListener("change",function(e){Data.options.sound.spy_rdelay=e.target.value},false);document.getElementById(UID["tabTower_File"]).addEventListener("change",function(){Data.options.sound.URL_attack=document.getElementById(UID["tabTower_File"]).value},false);document.getElementById(UID["tabTower_Play"]).addEventListener("click",function(){n("attack")},false);document.getElementById(UID["tabTower_Stop"]).addEventListener("click",function(){u("attack")},false);document.getElementById(UID["tabTower_Default"]).addEventListener("click",function(){document.getElementById(UID["tabTower_File"]).value=SoundPlayer.DEFAULT_SOUND_URL.attack;Data.options.sound.URL_attack=SoundPlayer.DEFAULT_SOUND_URL.attack;n("attack")},false);document.getElementById(UID["tabTower_Test"]).addEventListener("click",a,false);document.getElementById(UID["tabTower_Stop"]).disabled=true;document.getElementById(UID["tabTower_SFile"]).addEventListener("change",function(){Data.options.sound.URL_spy=document.getElementById(UID["tabTower_SFile"]).value},false);document.getElementById(UID["tabTower_SPlay"]).addEventListener("click",function(){n("spy")},false);document.getElementById(UID["tabTower_SStop"]).addEventListener("click",function(){u("spy")},false);document.getElementById(UID["tabTower_SDefault"]).addEventListener("click",function(){document.getElementById(UID["tabTower_SFile"]).value=SoundPlayer.DEFAULT_SOUND_URL.spy;Data.options.sound.URL_spy=SoundPlayer.DEFAULT_SOUND_URL.spy;n("spy")},false);document.getElementById(UID["tabTower_STest"]).addEventListener("click",f,false);document.getElementById(UID["tabTower_SStop"]).disabled=true},tabTowerMessage:function(){var e=Tabs.Tower;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabTowerMessage"]).className="selected";document.getElementById(UID["tabTowerMessage"]).style.zIndex=1;e.lastSubTab="tabTowerMessage";e.contentType=2;var t='<div class="'+UID["title"]+'">'+translate("Message configuration")+"</div>"+"<div id="+bS("tabTower_MsgBox")+" class="+UID["status_ticker"]+' style="height:355px; max-height:355px; width:540px; max-width:540px; overflow-y:auto ; overflow-x:auto ; margin-top:1px !important">'+"<table class="+UID["table"]+' width=100% style="color:#000;">'+"	<tr valign=top>"+"		<td><label>"+translate("Subject")+" :</label></td>"+"		<td><input id="+bS("tabTower_subject")+' size=50 maxlength=160 type=text value="'+Data.options.tower.msg_subject+'" /></td>'+"	</tr><tr valign=top>"+"		<td><label>"+translate("Message")+" :</label></td>"+"		<td><textarea id="+bS("tabTower_body")+' cols="60" rows="10" wrap="PHYSICAL">'+Data.options.tower.msg_body+"</textarea></td>"+"	</tr>"+"</table>"+"<br>"+"<table class="+UID["table"]+' style="color:#000;">'+"	<tr valign=top>"+"		<td><b>"+translate("Parameters")+" :</b></td>"+"	</tr><tr valign=top>"+"		<td><label>%1 = "+translate("Ennemy name and alliance")+"</label></td>"+"	</tr><tr valign=top>"+"		<td><label>%2 = "+translate("Ennemy coordinates")+"</label></td>"+"	</tr><tr valign=top>"+"		<td><label>%3 = "+translate("Attack forces")+"</label></td>"+"	</tr><tr valign=top>"+"		<td><label>%4 = "+translate("Attack arrival time")+"</label></td>"+"	</tr><tr valign=top>"+"		<td><label>%5 = "+translate("My name")+"</label></td>"+"	</tr><tr valign=top>"+"		<td><label>%6 = "+translate("My city/OP name where the attack is coming")+"</label></td>"+"	</tr><tr valign=top>"+"		<td><label>%7 = "+translate("My city/OP coordinates")+"</label></td>"+"	</tr>"+"</table>"+"</div>";document.getElementById(UID["tabTower_Content"]).innerHTML=t;document.getElementById(UID["tabTower_subject"]).addEventListener("change",function(){Data.options.tower.msg_subject=document.getElementById(UID["tabTower_subject"]).value},false);document.getElementById(UID["tabTower_body"]).addEventListener("change",function(){Data.options.tower.msg_body=document.getElementById(UID["tabTower_body"]).value},false)},onUnload:function(){var e=Tabs.Tower;bI("===============  Tabs.Tower.onUnload")},hide:function(){var e=Tabs.Tower;Data.options.tower.current_tab=e.contentType;clearInterval(e.intervalWarning)},show:function(){var e=Tabs.Tower;e.intervalWarning=setInterval(e.displayWarning,1e3);switch(e.contentType||0){case 0:e.tabTowerWall();break;case 1:e.tabTowerConfig();break;case 2:e.tabTowerMessage();break}},displayWarning:function(){var e=Tabs.Tower;var t=SoundPlayer.alertString.replace("&incoming_spy&",SoundPlayer.getFirstAlert().spy).replace("&incoming_attack&",SoundPlayer.getFirstAlert().attack);document.getElementById(UID["tabTower_Warning"]).innerHTML=t},printTab:function(){var e=Tabs.Tower;e.logTab.innerHTML="";e._addTab("",true);for(var t=0;t<Data.options.messages_tower.length;t++)e._addTab(Data.options.messages_tower[t],false)},_addTab:function(e,t){var n=Tabs.Tower;if(!t&&Data.options.tower.nospy&&e.type==1)return;var r=n.logTab.getElementsByTagName("tr");var i=r.length;var s=n.logTab.insertRow(t==true?0:1);s.vAlign="top";if(t){s.id=0;s.className=UID["row_headers"]}else{if(i%2==1)s.style.backgroundColor="White";else s.style.backgroundColor="rgb(239,239,224)";s.id=e.id}var o;var u;for(var a=0;a<5;a++){o=s.insertCell(a);if(t){switch(a){case 0:u=translate("Type");break;case 1:u=translate("Arrival time");break;case 2:u=translate("Attacker");break;case 3:u=translate("Alliance");break;default:u=translate("Troops");break}}else{switch(a){case 0:u=e.type==0?translate("Attack"):translate("Spy");if(bV(e.op)!=0)u=u+iJ(bV(e.op));break;case 1:if(e.arrive_at!=0)u=(new Date(e.arrive_at)).formatDate()+" "+(new Date(e.arrive_at)).formatTime();else u="";break;case 2:if(e.x!=-1)u=e.x+","+e.y;else u="";break;case 3:u=e.alliance;break;default:u=e.troups;break}}o.innerHTML=u;if(a>2)o.width="30%";else if(a==2)o.width="10%";else o.width="15%";if(t){o.style.fontWeight="bold"}else{o.style.fontWeight="normal";o.style.color="Black"}}if(!t&&e.type==0&&e.op!=0){if(document.getElementById(UID["goto_reinforcement"])){document.getElementById(UID["goto_reinforcement"]).addEventListener("click",function(e){var t=document.getElementById(UID["goto_reinforcement"]).getAttribute("ref");if(bV(t)!=0)Data.options.alliance.reinforce_id=t;var n=tabManager;for(aO in n.tabList)if(n.tabList[aO].name=="Alliance"){var r=n.tabList[aO];break}if(n.currentTab.name!=r.name){n.setTabStyle(document.getElementById(r.uid),true);n.setTabStyle(document.getElementById(n.currentTab.uid),false);n.currentTab.obj.hide();n.currentTab.div.style.display="none";n.currentTab=r;r.div.style.display="block";Data.options.currentTab=r.name}r.obj.show();Tabs.Alliance.tabAllianceReinforcement()},false)}}},removeRow:function(e){var t=Tabs.Tower;for(var n=0;n<t.logTab.rows.length;n++){if(t.logTab.rows[n].id==e.id){t.logTab.deleteRow(n);break}}},deleteTick:function(){var e=Tabs.Tower;clearTimeout(e.deleteTimer);if(Data.options.tower.delete_report){var t;for(var n=Data.options.messages_tower.length-1;n>=0;n--){t=Date.parse(Data.options.messages_tower[n].arrive_at)/1e3;var r=bV(be());var i=r-t;if(i>=Data.options.tower.delete_delay*Data.options.tower.delete_unit){e.removeRow(Data.options.messages_tower[n]);Data.options.messages_tower.splice(n,1)}}e.deleteTimer=setTimeout(e.deleteTick,Data.options.tower.delete_delay*Data.options.tower.delete_unit*1e3)}},gotAlarmReport:function(e,t){var n=Tabs.Tower;var r={id:t,type:0,arrive_at:0,alliance:"",x:0,y:0,units:{},troups:"",general:0,op:0};if(!e)return;if(e.report.warnings){var i=e.report.warnings;if(i.attacker_name)r.alliance=i.attacker_name;if(i.attacker_title&&i.attacker_title.alliance){if(r.alliance)r.alliance=r.alliance+" / "+i.attacker_title.alliance;else r.alliance=i.attacker_title.alliance}if(i.outpost_attack)r.op=i.march_incoming;if(i.attacker_coords){r.x=i.attacker_coords.x;r.y=i.attacker_coords.y}if(i.march_type&&i.march_type=="SpyMarch"){r.type=1}if(i.general_rank)r.general=i.general_rank;if(i.attacker_units){var s=[];for(var o in i.attacker_units){var u=bD(i.attacker_units[o]," ")+" "+translate(o);s.push(u)}if(s.length>0)r.troups=s.join(", ");r.units=aA(i.attacker_units)}if(i.march_arrival_time){r.arrive_at=n.getTimeAlarm(i.march_arrival_time);var a=Date.parse(r.arrive_at)/1e3;if(bV(be())-a>=Data.options.tower.delete_delay*Data.options.tower.delete_unit)return}}var f=false;for(var l=0;l<Data.options.messages_tower.length&&!f;l++){if(Data.options.messages_tower[l].id==t)f=true}if(!f){Data.options.messages_tower.push(r);n._addTab(r,false)}},getTimeAlarm:function(e){var t=0;if(e.length>=19){var n=bV(e.substr(0,4));var r=bV(e.substr(5,2));if(r==0)r=bV(e.substr(6,1));var i=bV(e.substr(8,2));if(i==0)i=bV(e.substr(9,1));var s=bV(e.substr(11,2));if(s==0)s=bV(e.substr(12,1));var o=bV(e.substr(14,2));if(o==0)o=bV(e.substr(15,1));var u=bV(e.substr(17,2));if(u==0)u=bV(e.substr(18,1));t=new Date(Date.UTC(n,r-1,i,s,o,u))}return t}};Tabs.Wall={tabOrder:WALL_TAB_ORDER,tabLabel:"Wall",tabDisabled:!WALL_TAB_ENABLE,container:null,contentType:0,totalForces:0,lastSubTab:"tabWallManagement",checkSetDefenseBusy:false,init:function(e){var t=Tabs.Wall;t.container=e;var n="<div class="+UID["title"]+">"+translate("wall-choose-defenders")+"</div>"+"<ul class=tabs>"+'	<li class="tab first"><a id='+bS("tabWallManagement")+">"+translate("Wall management")+"</a></li>"+"	<li class=tab><a id="+bS("tabWallSetDefense")+">"+translate("wall-manage-defense")+"</a></li>"+"	<li class=tab><a id="+bS("tabDragonManagement")+">"+translate("Dragons management")+"</a></li>"+"</ul>"+"<div id="+bS("tabWall_Content")+' style="padding-top:0px; height:655px; max-height:655px; overflow-y:auto; width:540px; max-width:540px; overflow-x:auto"></div>';t.container.innerHTML=n;document.getElementById(UID["tabWallManagement"]).addEventListener("click",t.tabWallManagement,false);document.getElementById(UID["tabWallSetDefense"]).addEventListener("click",t.tabWallSetDefense,false);document.getElementById(UID["tabDragonManagement"]).addEventListener("click",t.tabDragonManagement,false);window.addEventListener("unload",t.onUnload,false);t.contentType=bV(Data.options.wall.current_tab);t.show()},show:function(){var e=Tabs.Wall;switch(bV(e.contentType)){case 0:e.tabWallManagement();break;case 1:e.tabWallSetDefense();break;case 2:e.tabDragonManagement();break}},onUnload:function(){var e=Tabs.Wall;bI("===============  Tabs.Wall.onUnload");Data.options.wall.current_tab=e.contentType},hide:function(){},tabWallManagement:function(){function f(e){var t=Seed.cities[e];var n="<table class="+UID["row_style"]+' style="margin-top:3px" width=100%>'+"	<tr class="+UID["row_headers"]+" align=center>"+"		<td width=40%>"+translate("Troops")+"</td>"+"		<td width=15%>"+translate("Total")+"</td>"+"		<td width=15%>"+translate("Defense")+"</td>"+"		<td width=15%>"+translate("In city")+"</td>"+"		<td width=15%>"+translate("In march")+"</td>"+"	</tr>";for(var r=0;r<all_unit_types.length;r++){var i=aV(t,all_unit_types[r]);n+="	<tr valign=top>"+"		<td class=right width=40%>"+translate(all_unit_types[r])+":</td>"+"		<td align=right width=15%>"+bD(i.total," ")+"</td>"+"		<td align=right width=15%>"+(i.indefense>0?"<b>"+bD(i.indefense," ")+"</b>":bD(i.indefense," "))+"</td>"+"		<td align=right width=15%>"+bD(i.incity," ")+"</td>"+"		<td align=right width=15%>"+(i.marches?"&nbsp;+&nbsp;<b>"+bD(i.marches," ")+"</b>":"")+"</td>"+"	</tr>"}n+="</table>";return n}function l(){var e=Tabs.Wall;var t=Seed.cities[CAPITAL.id];var n={};for(var r=0;r<all_unit_types.length;r++){var i=aV(t,all_unit_types[r]);var s=i.incity+i.indefense;if(s>0)n[all_unit_types[r]]=s}if(e.checkSetDefenseBusy)return false;e.checkSetDefenseBusy=true;df(e.container,t.id,n,function(){bI(translate("wall-defenders-updated"));Tabs.Wall.checkSetDefenseBusy=false;e.tabWallManagement()})}function c(){var e=Tabs.Wall;var t=Seed.cities[CAPITAL.id];var n={};if(e.checkSetDefenseBusy)return false;e.checkSetDefenseBusy=true;df(e.container,t.id,n,function(){bI(translate("wall-defenders-updated"));Tabs.Wall.checkSetDefenseBusy=false;e.tabWallManagement()})}function h(e){var t=Tabs.Wall;var n=Seed.cities[CAPITAL.id];var r=bV(e.target.getAttribute("ref"));var i=Data.options.wall.presets[r].units;var s={};for(var o in i){var u=aV(n,o);var a=u.incity+u.indefense;if(a<i[o]||i[o]==-1)s[o]=a;else s[o]=i[o]}if(t.checkSetDefenseBusy)return false;t.checkSetDefenseBusy=true;df(t.container,n.id,s,function(){bI(translate("wall-defenders-updated"));Tabs.Wall.checkSetDefenseBusy=false;new MyAjax.setCustomization("GreatDragon",Data.options.wall.presets[r].armor,Data.options.wall.presets[r].scales,function(e){});t.tabWallManagement()})}function p(e){var t=Tabs.Wall;var n=bV(e.target.getAttribute("ref"));Data.options.wall.preset.name=Data.options.wall.presets[n].name;Data.options.wall.preset.units=aA(Data.options.wall.presets[n].units);Data.options.wall.preset.scales=Data.options.wall.presets[n].scales;Data.options.wall.preset.armor=Data.options.wall.presets[n].armor;t.tabWallSetDefense()}function d(e){var t=Tabs.Wall;var n=bV(e.target.getAttribute("ref"));Data.options.wall.presets.splice(n,1);t.tabWallManagement()}function v(e){var t=Tabs.Wall;var n=e.target;var r=Seed.cities[CAPITAL.id].id;var i=Seed.cities[CAPITAL.id].defended;var s=0;for(var o=0;o<all_unit_types.length;o++){s+=aV(Seed.cities[CAPITAL.id],all_unit_types[o]).indefense}if(s==0)return;var u=translate("Switching defense");aZ(u+" "+translate("attempted"));var a=new aw(t.container,300,165,"",false,null);a.bd().innerHTML="<div class="+UID["title"]+"><center><b>"+scriptName+" : "+translate("Message")+"</b></center></div>";a.getContentDiv().innerHTML=translate("Switch defense wall status");new MyAjax.dr(r,i,function(e){if(e.ok){aZ(u+" "+translate("Successfully"));aX(u);n.className=UID[Seed.cities[CAPITAL.id].defended?"btn_off":"btn_on"];n.value=translate(Seed.cities[CAPITAL.id].defended?"Defend":"Hiding").toUpperCase();a.destroy()}else{aZ(u+" "+translate("failed and returned error")+": "+e.errmsg);if(e.errmsg)a.getContentDiv().innerHTML=translate("Error while setting defense wall status")+" : "+e.errmsg;else a.getContentDiv().innerHTML=translate("Error while setting defense wall status");a.allowClose(true)}});var f=Seed.cities[CAPITAL.id].defended;n.className=UID[f?"btn_off":"btn_on"];n.value=translate(f?"Defend":"Hiding").toUpperCase()}var e=Tabs.Wall;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabWallManagement"]).className="selected";document.getElementById(UID["tabWallManagement"]).style.zIndex=1;e.lastSubTab="tabWallManagement";e.contentType=0;var t="<div id="+bS("tabWall_Results")+' style="height:640px">'+"	<div class="+UID["title"]+">"+translate("Wall management")+"</div>"+"	<div id="+bS("tabWall_ResultList")+" class="+UID["status_ticker"]+' style="height:600px; max-height:600px; overflow-y:auto ; overflow-x:auto ; margin-top:1px !important"></div>'+"	</div>";document.getElementById(UID["tabWall_Content"]).innerHTML=t;var n=[];var r=translate(Seed.cities[CAPITAL.id].defended?"Defend":"Hiding").toUpperCase();var t="<table class="+UID["table"]+' style="margin-top:3px" width=100%>'+"	<tr valign=top>"+"		<td width=25%><label><input id="+bS("tabWall_AllDef")+' type=button value="'+translate("Troops max")+'" /></label></td>'+"		<td width=25%><label><input id="+bS("tabWall_NoDef")+' type=button value="'+translate("remove-all")+'" /></label></td>'+"		<td width=50% align=right><b>"+translate("wall-defense-strategy")+":</b>"+"		&nbsp <input id="+bS("tabWall_setWallStat")+" type=button value="+r+" class="+UID[Seed.cities[CAPITAL.id].defended?"btn_off":"btn_on"]+"></input></td>"+"	</tr>"+"</table><br>"+f(CAPITAL.id)+'<br><table class="'+UID["table_targets"]+'">'+"	<tr class="+UID["row_headers"]+" cellpadding=1 >"+"		<td width=15%>"+translate("Preset")+"</td>"+"		<td width=55%>"+translate("Troops")+"</td>"+"	</tr>";var i;for(var s=0;s<Data.options.wall.presets.length;s++){if(s%2==1)i="White";else i="rgb(239,239,224)";t+='<tr valign=middle style="border-bottom: 1px solid #898989; background-color:'+i+'"><td width=15%>'+Data.options.wall.presets[s].name+"</td>"+"	<td align=left width=55%>"+cq(Data.options.wall.presets[s].units," ")+", "+translate(Data.options.wall.presets[s].scales)+","+translate(Data.options.wall.presets[s].armor)+"</td>"+"	<td align=center width=30%>"+"      <input id="+bS("tabWall_SetDefense_"+s)+" ref="+s+' class="Xtrasmall '+UID["btn_blue"]+'" style="width:auto !important;" type=submit value="'+translate("Set Def")+'" />&nbsp'+"		<input id="+bS("tabWall_Edit_"+s)+" ref="+s+' class="Xtrasmall '+UID["btn_green"]+'" style="width:auto !important;" type=submit value="'+translate("Edit")+'" />&nbsp'+"		<input id="+bS("tabWall_Delete_"+s)+" ref="+s+' class="Xtrasmall '+UID["btn_red"]+'" style="width:auto !important;" type=submit value=" X " /></td>'+"</tr>";n.push(UID["tabWall_SetDefense_"+s])}document.getElementById(UID["tabWall_ResultList"]).innerHTML=t+"</table>";document.getElementById(UID["tabWall_AllDef"]).addEventListener("click",l,false);document.getElementById(UID["tabWall_NoDef"]).addEventListener("click",c,false);document.getElementById(UID["tabWall_setWallStat"]).addEventListener("click",v,false);for(var s=0;s<n.length;s++){var o=document.getElementById(UID["tabWall_SetDefense_"+s]);var u=document.getElementById(UID["tabWall_Edit_"+s]);var a=document.getElementById(UID["tabWall_Delete_"+s]);o.addEventListener("click",h,false);u.addEventListener("click",p,false);a.addEventListener("click",d,false)}},tabWallSetDefense:function(){function l(){var e;for(var t=0;t<Seed.dragonList.length;t++){Seed.dragons[Seed.dragonList[t].type];if(Seed.dragons[Seed.dragonList[t].type].name=="GreatDragon"){e=Seed.dragons[Seed.dragonList[t].type]}}if(document.getElementById("preset_scales_"+e.id))Data.options.wall.preset.scales=document.getElementById("preset_scales_"+e.id).value;else Data.options.wall.preset.scales=""}function c(){var e;for(var t=0;t<Seed.dragonList.length;t++){Seed.dragons[Seed.dragonList[t].type];if(Seed.dragons[Seed.dragonList[t].type].name=="GreatDragon"){e=Seed.dragons[Seed.dragonList[t].type]}}if(document.getElementById("preset_armor_"+e.id))Data.options.wall.preset.armor=document.getElementById("preset_armor_"+e.id).value;else Data.options.wall.preset.armor=""}function h(e){var t=e.target.id.split("_");var n=bV(e.target.value);for(i=0;i<all_unit_types.length;i++)document.getElementById(UID["tabWall_Trp"]+"_"+i).style.backgroundColor="";if(isNaN(n)||n<-1)e.target.style.backgroundColor="red";else e.target.style.backgroundColor="";e.target.value=n;Data.options.wall.preset.units[all_unit_types[t[1]]]=n}function p(){var e=Tabs.Wall;var t=Seed.cities[CAPITAL.id];for(var n=0;n<all_unit_types.length;n++){var r=aV(t,all_unit_types[n]);var i=r.incity+r.indefense;if(i>0)Data.options.wall.preset.units[all_unit_types[n]]=i;else Data.options.wall.preset.units[all_unit_types[n]]=0}e.tabWallSetDefense()}function d(){var e=Tabs.Wall;for(var t=0;t<all_unit_types.length;t++){Data.options.wall.preset.units[all_unit_types[t]]=0}e.tabWallSetDefense()}function v(){c();l();var e=Tabs.Wall;if(Data.options.wall.presets&&Data.options.wall.presets.length>0){var t=aA(Data.options.wall.presets);for(var n=t.length-1;n>=0;n--){if(t[n].name==Data.options.wall.preset.name)Data.options.wall.presets.splice(n,1)}}var r={name:Data.options.wall.preset.name,units:aA(Data.options.wall.preset.units),scales:Data.options.wall.preset.scales,armor:Data.options.wall.preset.armor};Data.options.wall.presets.push(r);e.tabWallManagement()}function m(){c();l();var e=Tabs.Wall;var t=Seed.cities[CAPITAL.id];var n=Data.options.wall.preset.units;var r={};for(var i in n){var s=aV(t,i);var o=s.incity+s.indefense;if(o<n[i]||n[i]==-1)r[i]=o;else r[i]=n[i]}if(e.checkSetDefenseBusy)return false;e.checkSetDefenseBusy=true;df(e.container,t.id,r,function(){bI(translate("wall-defenders-updated"));Tabs.Wall.checkSetDefenseBusy=false;e.tabWallSetDefense()});new MyAjax.setCustomization("GreatDragon",Data.options.wall.preset.armor,Data.options.wall.preset.scales,function(e){})}function g(t){var n=t.target.id.split("_");var r=Seed.cities[CAPITAL.id];var i={};var s=aV(r,all_unit_types[n[1]]);var o=bV(s.incity)+bV(s.indefense);Data.options.wall.preset.units[all_unit_types[n[1]]]=bV(o);e.tabWallSetDefense()}function y(e){var t="n/a";if(e.customizations&&e.customizations.scales&&e.slots&&e.slots.scales){t="<select id=preset_scales_"+e.id+">";for(var n=0;n<e.customizations.scales.length;n++){t+="<option "+(e.customizations.scales[n]==e.slots.scales?"selected":"")+' value="'+e.customizations.scales[n]+'">'+translate(e.customizations.scales[n])+"</option>"}t+="</select>"}return t}function b(e,t){var n=translate("Not ready")+w(t);if(e.customizations&&e.customizations.armor&&e.slots&&e.slots.armor){n="<select id=preset_armor_"+e.id+">";for(var r=0;r<e.customizations.armor.length;r++){n+="<option "+(e.customizations.armor[r]==e.slots.armor?"selected":"")+' value="'+e.customizations.armor[r]+'">'+translate(e.customizations.armor[r])+"</option>"}n+="</select>"}return n}function w(e){var t=["BodyArmor","ClawGuards","TailGuard","Helmet"];var n=0;for(var r=0;r<t.length;r++){if(bV(Seed.player.items[e+t[r]])!==0){n++}}if(n==4)return"";else return" ("+translate("Got")+" "+n+"/4)"}var e=Tabs.Wall;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabWallSetDefense"]).className="selected";document.getElementById(UID["tabWallSetDefense"]).style.zIndex=1;e.lastSubTab="tabWallSetDefense";e.contentType=1;var t="<div id="+bS("tabWall_Results")+' style="height:570px">'+"	<div class="+UID["title"]+">"+translate("wall-manage-defense")+"</div>"+"	<div id="+bS("tabWall_Status")+" class="+UID["status_ticker"]+' style="margin-bottom:5px !important">'+"	<label><b>"+translate("Preset name")+" :</b></label>"+"	&nbsp &nbsp<input id="+bS("tabWall_Name")+' size=30 maxlength=50 type=text value="'+Data.options.wall.preset.name+'" /><br><br>'+"	<table id="+bS("tabWall_Troops")+" class="+UID["table"]+">"+"		<tr align=left class="+UID["row_headers_left"]+">"+"			<td colspan=3 width=50%>"+translate("Troops for defense")+":&nbsp;</td>"+"			<td width=10%>"+translate("Total")+"</td>"+"			<td width=10%>"+translate("Defense")+"</td>"+"			<td width=10%>"+translate("In city")+"</td>"+"			<td width=10%>"+translate("In march")+"</td>"+"		</tr>";var n=bS("tabWall_Trp");var r=bS("tabWall_MaxT");var s=Seed.cities[CAPITAL.id];for(i=0;i<all_unit_types.length;i++){var o=bV(Data.options.wall.preset.units[all_unit_types[i]]);var u=aV(s,all_unit_types[i]);t+="<tr><td class=right width=25%>"+translate(Names.troops.byName[all_unit_types[i]][1])+":</td>"+"	<td width=15%><input type=text id="+n+"_"+i+' maxlength=9 style="width:55px" size=2 value="'+o+'"></td>'+"	<td width=10%><input class=small id="+r+"_"+i+" ref="+i+' type=button  style="width:auto !important;" value=" Max " ></td>'+"	<td align=right width=15%>"+bD(u.total," ")+"</td>"+"	<td align=right width=15%>"+bD(u.indefense," ")+"</td>"+"	<td align=right width=15%>"+bD(u.incity," ")+"</td>"+"	<td align=right width=15%>"+(u.marches?"&nbsp;+&nbsp;<b>"+bD(u.marches," ")+"</b>":"")+"</td>"+"</tr>"}t+="<tr><td colspan=4 class=jewel>"+translate("Enter -1 as troop quantity to use the maximum available")+"</td></tr>"+"</table><br>";t+="<table class="+UID["table"]+' style="margin-top:3px" width=60%>'+"	<tr valign=top align=center>"+"		<td width=25%><label><input id="+bS("tabWall_setAll")+' type=button class="'+UID["btn_green"]+'" value="'+translate("Troops max")+'" /></label></td>'+"		<td width=25%><label><input id="+bS("tabWall_clearAll")+' type=button class="'+UID["btn_green"]+'" value="'+translate("Clear all")+'" /></label></td>'+"	</tr>"+"</table><br>";t+="<table class="+UID["table"]+">"+"		<tr align=center class="+UID["row_headers"]+">"+"			<td>"+translate("Dragons")+"</td>"+"			<td>"+translate("Scales")+"</td>"+"			<td>"+translate("Armor")+"</td>"+"		</tr>";for(var a=0;a<Seed.dragonList.length;a++){var f=Seed.dragons[Seed.dragonList[a].type];if(f.name=="GreatDragon"){t+="<tr><td class=right>"+translate(f.name)+":</td>"+"<td> "+y(f,"nomEcaille")+"</td>"+"<td> "+b(f,Seed.dragonList[a].type,"nomArmure")+"</td></tr>"}}t+="</table><br>"+"<table class="+UID["table"]+' style="margin-top:3px" width=60%>'+"	<tr valign=top align=center>"+"		<td width=25%><label><input id="+bS("tabWall_savePreset")+' type=button value="'+translate("Save preset")+'" /></label></td>'+"		<td width=25%><label><input id="+bS("tabWall_setDefense")+' type=button value="'+translate("wall-update-defenders")+'" /></label></td>'+"	</tr>"+"</table><br>"+"<br>"+"<br><div id="+bS("tabDragonManagement_Feedback")+" class="+UID["status_feedback"]+"></div></div></div>";+"<br></div></div>";document.getElementById(UID["tabWall_Content"]).innerHTML=t;document.getElementById(UID["tabWall_Name"]).addEventListener("change",function(){Data.options.wall.preset.name=document.getElementById(UID["tabWall_Name"]).value},false);document.getElementById(UID["tabWall_setAll"]).addEventListener("click",p,false);document.getElementById(UID["tabWall_clearAll"]).addEventListener("click",d,false);document.getElementById(UID["tabWall_savePreset"]).addEventListener("click",v,false);document.getElementById(UID["tabWall_setDefense"]).addEventListener("click",m,false);for(var a=0;a<Seed.dragonList.length;a++){Seed.dragons[Seed.dragonList[a].type];if(Seed.dragons[Seed.dragonList[a].type].name=="GreatDragon"){if(document.getElementById(UID["preset_scales_"+Seed.dragons[Seed.dragonList[a].type].id])){document.getElementById(UID["preset_scales_"+Seed.dragons[Seed.dragonList[a].type].id]).addEventListener("change",l,false);if(document.getElementById(UID["preset_scales_"+Seed.dragons[Seed.dragonList[a].type].id]).value==Data.options.wall.preset.scales){document.getElementById(UID["preset_scales_"+Seed.dragons[Seed.dragonList[a].type].id]).value=Data.options.wall.preset.scales}}if(document.getElementById(UID["preset_armor_"+Seed.dragons[Seed.dragonList[a].type].id])){document.getElementById(UID["preset_armor_"+Seed.dragons[Seed.dragonList[a].type].id]).addEventListener("change",c,false);if(document.getElementById(UID["preset_armor_"+Seed.dragons[Seed.dragonList[a].type].id]).value==Data.options.wall.preset.armor){document.getElementById(UID["preset_armor_"+Seed.dragons[Seed.dragonList[a].type].id]).value=Data.options.wall.preset.armor}}}}for(i=0;i<all_unit_types.length;i++){document.getElementById(n+"_"+i).addEventListener("change",h,false);butMax=document.getElementById(r+"_"+i);butMax.addEventListener("click",g,false);bG(butMax,true,"btn_green")}},tabDragonManagement:function(){function s(e){var t=e.target.getAttribute("ref").split("_");var n=t[1];var r=t[2];var i,s;if(document.getElementById("armor_"+r))i=document.getElementById("armor_"+r).value;if(document.getElementById("scales_"+r))s=document.getElementById("scales_"+r).value;new MyAjax.setCustomization(n,i,s,function(e){var t="";if(e.dat.result.success){var n=e.dat.result.unit_type.substring(e.dat.result.unit_type.indexOf("::")+2);t="OK : "+translate(n)+"("+translate(e.dat.result.slots.scales==undefined?"GreenScales":e.dat.result.slots.scales)+","+translate(e.dat.result.slots.armor==undefined?"GreenArmor":e.dat.result.slots.armor)+")"}else t=translate("Failed");aS(UID["tabDragonManagement_Feedback"],t)})}function o(e){var t="n/a";if(e.customizations&&e.customizations.scales&&e.slots&&e.slots.scales){t="<select id=scales_"+e.id+">";for(var n=0;n<e.customizations.scales.length;n++){t+="<option "+(e.customizations.scales[n]==e.slots.scales?"selected":"")+' value="'+e.customizations.scales[n]+'">'+translate(e.customizations.scales[n])+"</option>"}t+="</select>"}return t}function u(e,t){var n=translate("Not ready")+a(t);if(e.customizations&&e.customizations.armor&&e.slots&&e.slots.armor){n="<select id=armor_"+e.id+">";for(var r=0;r<e.customizations.armor.length;r++){n+="<option "+(e.customizations.armor[r]==e.slots.armor?"selected":"")+' value="'+e.customizations.armor[r]+'">'+translate(e.customizations.armor[r])+"</option>"}n+="</select>"}return n}function a(e){var t=["BodyArmor","ClawGuards","TailGuard","Helmet"];var n=0;for(var r=0;r<t.length;r++){if(bV(Seed.player.items[e+t[r]])!==0){n++}}if(n==4)return"";else return" ("+translate("Got")+" "+n+"/4)"}var e=Tabs.Wall;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabDragonManagement"]).className="selected";document.getElementById(UID["tabDragonManagement"]).style.zIndex=1;e.lastSubTab="tabDragonManagement";e.contentType=2;var t="<div id="+bS("tabWall_Results")+' style="height:570px">'+"	<div class="+UID["title"]+">"+translate("Dragons management")+"</div>"+"	<div id="+bS("tabWall_Dragon")+" class="+UID["status_ticker"]+' style="margin-bottom:5px !important">'+"	<table id="+bS("tabWall_Dragons")+" class="+UID["table"]+">"+"		<tr align=center class="+UID["row_headers"]+">"+"			<td>"+translate("Dragons")+"</td>"+"			<td>"+translate("Armor")+"&nbsp;&&nbsp;"+translate("Scales")+"</td>"+"			<td>"+translate("Update")+"</td>"+"		</tr>";for(var n=0;n<Seed.dragonList.length;n++){var r="";if(n%2==1)r="White";else r="rgb(239,239,224)";var i=Seed.dragons[Seed.dragonList[n].type];t+='<tr style="background-color:'+r+'"><td class=right>'+translate(i.name)+":</td>"+"<td> "+u(i,Seed.dragonList[n].type)+"<br/>"+o(i)+"</td>"+"<td><input class=small id="+bS("eq"+"_"+i.id)+" ref=armor_"+i.name+"_"+i.id+' type=button  style="width:auto !important;" value="Ok" ></td></tr>'}t+="</table><br>"+"<br>"+"<br><div id="+bS("tabDragonManagement_Feedback")+" class="+UID["status_feedback"]+"></div></div></div>";document.getElementById(UID["tabWall_Content"]).innerHTML=t;for(var n=0;n<Seed.dragonList.length;n++){var i=Seed.dragons[Seed.dragonList[n].type];document.getElementById(UID["eq"+"_"+i.id]).addEventListener("click",s,false)}}};Tabs.Waves={tabOrder:WAVE_TAB_ORDER,tabLabel:"Wave",tabDisabled:!WAVE_TAB_ENABLE,container:null,enabled:false,attackTimer:null,marchTimer:null,attackErrors:0,contentType:0,lastSubTab:"tabWaveAttack",running:{start_at:0},last_report:null,init:function(e){var t=Tabs.Waves;Data.setDefaultValues("waves");t.container=e;var n=""+"<div class="+UID["title"]+">"+translate("Wave")+"</div>"+"<div id="+bS("tabWave_Status")+" class="+UID["status_ticker"]+' style="margin-bottom:5px !important">'+"	<center><input id="+bS("tabWave_OnOff")+' type=button value="OnOff" /></center>'+"	<div id="+bS("tabWave_Report")+' style="margin-top:5px;height:140px; max-height:140px; width:540px; max-width:540px; overflow:auto;">'+"		<table id="+bS("tabWave_Marches")+" class="+UID["table"]+">"+"		</table>"+"	</div>"+"	<div id="+bS("tabWave_Feedback")+" class="+UID["status_feedback"]+"></div>"+"</div>"+"<ul class=tabs>"+'	<li class="tab first"><a id='+bS("tabWaveAttack")+">"+translate("Attack")+"</a></li>"+"	<li class=tab><a id="+bS("tabWaveHistory")+">"+translate("History")+"</a></li>"+"	<li class=tab><a id="+bS("tabWaveStats")+">"+translate("Stats")+"</a></li>"+"	<li class=tab><a id="+bS("tabWaveLastReport")+">"+translate("Last report")+"</a></li>"+"</ul>"+"<div id="+bS("tabWave_Content")+' style="padding-top:0px; height:440px; overflow-y:auto"></div>';t.container.innerHTML=n;document.getElementById(UID["tabWaveAttack"]).addEventListener("click",t.tabWaveAttack,false);document.getElementById(UID["tabWaveHistory"]).addEventListener("click",t.tabWaveHistory,false);document.getElementById(UID["tabWaveStats"]).addEventListener("click",t.tabWaveStats,false);document.getElementById(UID["tabWaveLastReport"]).addEventListener("click",t.tabWaveLastReport,false);document.getElementById(UID["tabWave_OnOff"]).addEventListener("click",function(){t.setWaveEnable(!Data.options.waves.enabled)},false);window.addEventListener("unload",t.onUnload,false);t.setWaveEnable(Data.options.waves.enabled);t.contentType=bV(Data.options.waves.current_tab);t.show()},tabWaveAttack:function(){function a(t){dJ(e.container,Data.options.waves.target)}function f(e){var t=bV(e.target.value);var n=bV(t*1.5);if(t<bK(MIN_DELAY_BETWEEN_WAVE,3)||t>3600){e.target.style.backgroundColor="red";return}document.getElementById(UID["tabWave_DelayMax"]).innerHTML=n;e.target.style.backgroundColor="";Data.options.waves.delay_min=t;Data.options.waves.delay_max=n}function l(e){var t=bV(document.getElementById(UID["tabWave_MaxMarches"]).value);if(t<0||t>Seed.cities[CAPITAL.id].figures.marches.maximum){e.target.style.backgroundColor="red";return}e.target.style.backgroundColor="";Data.options.waves.max_marches=t}function c(){var e=Tabs.Waves;if(Data.options.waves.history&&Data.options.waves.history.length>0){var t=aA(Data.options.waves.history);for(var n=t.length-1;n>=0;n--){if(t[n].x==Data.options.waves.target.x&&t[n].y==Data.options.waves.target.y)Data.options.waves.history.splice(n,1)}}var r={x:Data.options.waves.target.x,y:Data.options.waves.target.y,type:Data.options.waves.target.type,level:Data.options.waves.target.level,id:Data.options.waves.target.id,n:Data.options.waves.target.n,units:aA(Data.options.waves.target.saved_units),dragons:aA(Data.options.waves.target.dragons),ai:Data.options.waves.target.ai,inc:Data.options.waves.target.include_great_dragon,comment:Data.options.waves.target.comment};Data.options.waves.history.push(r)}function h(t){var n=bV(t.target.getAttribute("ref"));dj(e.container,Data.options.waves.target.x,Data.options.waves.target.y,Data.options.waves.target.type,Data.options.waves.target.level,Data.options.waves.target.id,Data.options.waves.target.n,Data.options.waves.target.saved_units,Data.options.waves.target.ai,Data.options.waves.target.include_great_dragon,true,Data.options.waves.target.dragons,Data.options.waves.target.comment)}var e=Tabs.Waves;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabWaveAttack"]).className="selected";document.getElementById(UID["tabWaveAttack"]).style.zIndex=1;e.lastSubTab="tabWaveAttack";e.contentType=0;var t='<div class="'+UID["title"]+'">'+translate("Max ")+translate("Troops")+" "+bD(bV(bJ(CAPITAL.id).max_troops)," ")+"</div>"+"<div class="+UID["content"]+">"+"	<div>"+"		<b>"+translate("Coords")+":&nbsp;</b>&nbsp;"+"		X: <input id="+bS("tabWave_CoordsX")+' size=1 maxlength=3 type=text value="'+Data.options.waves.target.x+'" /> '+"		Y: <input id="+bS("tabWave_CoordsY")+' size=2 maxlength=3 type=text value="'+Data.options.waves.target.y+'" /> '+"		&nbsp <b>"+translate("Distance")+":</b> <span id="+bS("tabWave_Distance")+"></span>"+"		&nbsp <input id="+bS("tabWave_Save")+' class="'+UID["btn_green"]+' small" style="width:auto !important;" type=submit value=" '+translate("Save")+' " />'+"		&nbsp <input id="+bS("tabWave_Spy")+' class="'+UID["btn_green"]+' small" style="width:auto !important;" type=submit value=" '+translate("Spy")+' " />'+"		&nbsp <input id="+bS("tabWave_Bookmark")+' class="'+UID["btn_blue"]+' small" style="width:auto !important;" type=submit value=" '+translate("Bookmark")+' " />';if(Data.options.waves.target.id&&Data.options.waves.target.id!=""&&Data.options.waves.target.n&&Data.options.waves.target.n!=""){var n=Data.options.waves.target.id+"_"+Data.options.waves.target.n;t+="	&nbsp <input id="+bS("tabWave_Msg")+" ref="+n+' class="'+UID["btn_blue"]+' small" style="width:auto !important;" type=submit value=" '+translate("Msg")+' " />'}t+="		<br><br><label>"+translate("description")+" :</label>&nbsp"+"		<textarea id="+bS("tabWave_Comment")+' cols="80" rows="2" wrap="PHYSICAL">'+Data.options.waves.target.comment+"</textarea><br>"+"		<div class="+UID["status_ticker"]+' style="height:auto !important;margin:5px 10px !important;">'+"			<center><span id="+bS("tabWave_Tile")+"></span></center>"+"		</div>"+"	</div>"+"  <div>"+"	<table id="+bS("tabWave_Troops")+" class="+UID["table"]+" width=100%>"+"		<tr align=center class="+UID["row_headers"]+">"+"			<td colspan=10>"+translate("Troops for Wave Attack")+":&nbsp;</td>"+"		</tr>"+"	</table>"+"	</div><br>"+"  <div>"+"	<table id="+bS("tabWave_Dragons")+" class="+UID["table"]+" width=100%>"+"		<tr align=center class="+UID["row_headers"]+">"+"			<td colspan=10>"+translate("Include Great Dragon")+":&nbsp;</td>";var r=[];for(var i=0;i<Seed.dragonList.length;i++){var s=Seed.dragonList[i];if(i%5==0)t+="</tr><tr>";t+='	<td class=right><span title="'+translate(s.type)+'">'+translate(Names.getTroopAbbr(s.type))+":<span></td>"+"	<td align=center><input type=checkbox id="+bS("tabWave_Dragons_"+i)+' ref="'+i+'" '+(Data.options.waves.target.dragons[s.type]?" checked":"")+" /></td>";r.push(i)}t+="</tr>"+"	</table>"+"	</div><br>"+"	<table class="+UID["table"]+">"+"		<tr>"+"			<td class=right> "+translate("Delete Battle Reports")+":&nbsp;</td>"+"			<td><input id="+bS("tabWave_DelReports")+" type=checkbox "+(Data.options.waves.delete_reports?"CHECKED":"")+" /></td>"+"		</tr><tr>"+"			<td class=right>"+translate("Stop if any troops lost")+":&nbsp;</td>"+"			<td><input id="+bS("tabWave_StopOnLoss")+" type=checkbox "+(Data.options.waves.stop_on_loss?"CHECKED":"")+" /></td>"+"		</tr><tr>"+"			<td class=right>"+translate("Delay Between Attacks")+":&nbsp;</td>"+"			<td>"+"				<input id="+bS("tabWave_DelayMin")+' type=text size=1 maxlength=4 value="'+Data.options.waves.delay_min+'" />'+"				 to <span id="+bS("tabWave_DelayMax")+">"+Data.options.waves.delay_max+"</span>&nbsp;"+translate("seconds")+"			</td>"+"		</tr><tr>"+"			<td class=right> "+translate("Maximum simultaneous marches")+":&nbsp;</td>"+"			<td><input id="+bS("tabWave_MaxMarches")+' type=text size=1 maxlength=2 value="'+Data.options.waves.max_marches+'" /></td>'+"		</tr><tr>"+"			<td class=right> "+translate("Send even without Dragon")+":&nbsp;</td>"+"			<td><input id="+bS("tabWave_SendWithoutDragon")+" type=checkbox "+(Data.options.waves.send_without_dragon?"CHECKED":"")+" /></td>"+"		</tr>"+"	</table>"+"</div>";document.getElementById(UID["tabWave_Content"]).innerHTML=t;document.getElementById(UID["tabWave_CoordsX"]).addEventListener("change",e.bU,false);document.getElementById(UID["tabWave_CoordsY"]).addEventListener("change",e.bU,false);document.getElementById(UID["tabWave_Save"]).addEventListener("click",c,false);document.getElementById(UID["tabWave_Bookmark"]).addEventListener("click",h,false);document.getElementById(UID["tabWave_Comment"]).addEventListener("change",function(){Data.options.waves.target.comment=document.getElementById(UID["tabWave_Comment"]).value},false);document.getElementById(UID["tabWave_DelReports"]).addEventListener("click",function(e){Data.options.waves.delete_reports=e.target.checked},false);document.getElementById(UID["tabWave_StopOnLoss"]).addEventListener("click",function(e){Data.options.waves.stop_on_loss=e.target.checked},false);document.getElementById(UID["tabWave_SendWithoutDragon"]).addEventListener("click",function(e){Data.options.waves.send_without_dragon=e.target.checked},false);document.getElementById(UID["tabWave_DelayMin"]).addEventListener("change",f,false);document.getElementById(UID["tabWave_MaxMarches"]).addEventListener("change",l,false);if(Data.options.waves.target.id&&Data.options.waves.target.id!=""&&Data.options.waves.target.n&&Data.options.waves.target.n!="")document.getElementById(UID["tabWave_Msg"]).addEventListener("click",bF,false);du(document.getElementById(UID["tabWave_Troops"]),1,"AW",wave_unit_types,Data.options.waves.target.units,Data.options.waves.target.saved_units,e.bi,true);for(var i=0;i<r.length;++i){document.getElementById(UID["tabWave_Dragons_"+r[i]]).addEventListener("change",function(e){var t=e.target.getAttribute("ref");Data.options.waves.target.dragons[Seed.dragonList[t].type]=e.target.checked;var n=false;for(var r=0;r<Seed.dragonList.length&&!n;r++){var i=Seed.dragonList[r];if(Data.options.waves.target.dragons[i.type])n=true}if(n)Data.options.waves.target.include_great_dragon=true;else Data.options.waves.target.include_great_dragon=false},false)}e.bU();var o=document.getElementById(UID["tabWave_Spy"]);o.addEventListener("click",a,false);var u=Data.options.waves.target;if(!u.ai||u.ai==0||u.ai==null||u.ai!=(Seed.player.alliance?Seed.player.alliance.id:-1))bG(o,true,"btn_green","btn_disabled");else bG(o,false,"btn_green","btn_disabled")},tabWaveHistory:function(){function v(t){var n=bV(t.target.getAttribute("ref"));dJ(e.container,Data.options.waves.history[n])}function m(t){var n=bV(t.target.getAttribute("ref"));Data.options.waves.target.x=Data.options.waves.history[n].x;Data.options.waves.target.y=Data.options.waves.history[n].y;Data.options.waves.target.type=Data.options.waves.history[n].type;Data.options.waves.target.level=Data.options.waves.history[n].level;Data.options.waves.target.id=Data.options.waves.history[n].id;Data.options.waves.target.n=Data.options.waves.history[n].n;Data.options.waves.target.ai=Data.options.waves.history[n].ai;Data.options.waves.target.units=aA(Data.options.waves.history[n].units);Data.options.waves.target.dragons=aA(Data.options.waves.history[n].dragons);Data.options.waves.target.saved_units=aA(Data.options.waves.history[n].units);Data.options.waves.target.include_great_dragon=Data.options.waves.history[n].inc;Data.options.waves.target.comment=Data.options.waves.history[n].comment;e.tabWaveAttack()}function g(t){var n=bV(t.target.getAttribute("ref"));Data.options.waves.history.splice(n,1);e.tabWaveHistory()}function y(t){var n=bV(t.target.getAttribute("ref"));dj(e.container,Data.options.waves.history[n].x,Data.options.waves.history[n].y,Data.options.waves.history[n].type,Data.options.waves.history[n].level,Data.options.waves.history[n].id,Data.options.waves.history[n].n,Data.options.waves.history[n].units,Data.options.waves.history[n].ai,Data.options.waves.history[n].inc,true,Data.options.waves.history[n].dragons,Data.options.waves.history[n].comment)}var e=Tabs.Waves;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabWaveHistory"]).className="selected";document.getElementById(UID["tabWaveHistory"]).style.zIndex=1;e.lastSubTab="tabWaveHistory";e.contentType=1;var t='<div class="'+UID["title"]+'">'+translate("History")+"</div>"+"	<div id="+bS("tabWave_HistoryList")+" class="+UID["status_ticker"]+' style="height:390px; max-height:390px; width:540px; max-width:540px; overflow-y:auto ; overflow-x:auto ; margin-top:1px !important"></div>'+"	</div>";document.getElementById(UID["tabWave_Content"]).innerHTML=t;var t="<table class="+UID["row_style"]+">"+"	<tr class="+UID["row_headers"]+">"+'		<td width="10px">&nbsp</td>'+'		<td width="35px"><A><span>'+translate("Dist")+"</span></A></td>"+'		<td width="50px"><A><span>'+translate("Coords")+"</span></A></td>"+'		<td width="160px"><A><span>'+translate("Target")+"</span></A></td>"+'		<td width="175px"><A><span>'+translate("Troops")+"</span></A></td>"+"	</tr>";var n=[];for(var r=0;r<Data.options.waves.history.length;r++){var i="",s="";if(!Data.options.waves.history[r].comment||Data.options.waves.history[r].comment==null||Data.options.waves.history[r].comment=="")i='style="border-bottom: 1px solid #898989;"';if(r%2==1)s="White";else s="rgb(239,239,224)";var o=ba(Data.options.waves.history[r].x,Data.options.waves.history[r].y,Data.options.waves.history[r].units);t+='<tr valign=top style="background-color:'+s+'">'+"	<td><input id="+bS("tabWave_Delete_"+r)+" ref="+r+' class="Xtrasmall '+UID["btn_red"]+'" style="width:auto !important;" type=submit value=" X " /></td>'+"	<td "+i+">"+bu(Seed.cities[CAPITAL.id].x,Seed.cities[CAPITAL.id].y,Data.options.waves.history[r].x,Data.options.waves.history[r].y)+"<br> ("+bz(o)+")</td>"+"	<td align=center "+i+">"+Data.options.waves.history[r].x+","+Data.options.waves.history[r].y+"</td>"+"	<td align=left "+i+">"+Data.options.waves.history[r].type+"</td>"+"	<td align=left "+i+">"+cq(Data.options.waves.history[r].units,"<br>")+"</td>"+"	<td><input id="+bS("tabWave_Recall_"+r)+" ref="+r+' class="Xtrasmall '+UID["btn_green"]+'" style="width:auto !important;" type=submit value="'+translate("Recall")+'" /><br>'+"		<input id="+bS("tabWave_Bookmark_"+r)+" ref="+r+' class="Xtrasmall '+UID["btn_blue"]+'" style="width:auto !important;" type=submit value="'+translate("Bookmark")+'" /></td>';if(Data.options.waves.history[r].id&&Data.options.waves.history[r].id!=""&&Data.options.waves.history[r].n&&Data.options.waves.history[r].n!=""){var u=Data.options.waves.history[r].id+"_"+Data.options.waves.history[r].n;var a=bS("tabWave_Msg_"+r);t+="	<td><input id="+bS("tabWave_Spy_"+r)+" ref="+r+' class="Xtrasmall '+UID["btn_green"]+'" style="width:auto !important;" type=submit value="'+translate("Spy")+'" /><br>'+"		<input id="+a+" ref="+u+' class="Xtrasmall '+UID["btn_blue"]+'" style="width:auto !important;" type=submit value="'+translate("Msg")+'" /></td>';n.push(a)}else{t+="	<td><input id="+bS("tabWave_Spy_"+r)+" ref="+r+' class="Xtrasmall '+UID["btn_green"]+'" style="width:auto !important;" type=submit value="'+translate("Spy")+'" /></td>'}t+="</tr>";if(Data.options.waves.history[r].comment&&Data.options.waves.history[r].comment!=null&&Data.options.waves.history[r].comment!="")t+='<tr valign=top style="background-color:'+s+'"><td colspan=5 style="border-bottom: 1px solid #898989;">'+Data.options.waves.history[r].comment+"</td><td colspan=2>&nbsp</td></tr>"}document.getElementById(UID["tabWave_HistoryList"]).innerHTML=t+"</table>";for(var r=0;r<Data.options.waves.history.length;r++){var f=document.getElementById(UID["tabWave_Recall_"+r]);var l=document.getElementById(UID["tabWave_Delete_"+r]);var c=document.getElementById(UID["tabWave_Bookmark_"+r]);var h=document.getElementById(UID["tabWave_Spy_"+r]);f.addEventListener("click",m,false);l.addEventListener("click",g,false);c.addEventListener("click",y,false);h.addEventListener("click",v,false);var p=Data.options.waves.history[r];if(!p.ai||p.ai==0||p.ai==null||p.ai!=(Seed.player.alliance?Seed.player.alliance.id:-1))bG(h,true,"btn_green","btn_disabled");else bG(h,false,"btn_green","btn_disabled")}for(var d=0;d<n.length;d++)document.getElementById(n[d]).addEventListener("click",bF,false)},tabWaveStats:function(){var e=Tabs.Waves;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabWaveStats"]).className="selected";document.getElementById(UID["tabWaveStats"]).style.zIndex=1;e.lastSubTab="tabWaveStats";e.contentType=2;var t="<div class="+UID["title"]+">"+translate("Attacks Stats")+"</div>"+"<div id="+bS("tabWaveStats_Statbox")+" class="+UID["status_ticker"]+">"+"<div id="+bS("tabWaveStats_Status")+"></div>"+"<div id="+bS("tabWaveStats_Percent")+"></div>"+"<br/>"+"<center><input id="+bS("tabWaveStats_Clear")+' type=button value="'+translate("Clear Stats")+'" /></center>'+"<br></div>";document.getElementById(UID["tabWave_Content"]).innerHTML=t;document.getElementById(UID["tabWaveStats_Clear"]).addEventListener("click",function(){e.aY();e.bL()},false);e.bL()},tabWaveLastReport:function(){var e=Tabs.Waves;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabWaveLastReport"]).className="selected";document.getElementById(UID["tabWaveLastReport"]).style.zIndex=1;e.lastSubTab="tabWaveLastReport";e.contentType=3;var t="<div id="+bS("tabWave_ShowReport")+" class="+UID["status_ticker"]+' style="height:395px; max-height:395px; width:540px; max-width:540px; overflow-y:auto ; overflow-x:auto ; margin-top:1px !important"></div>';document.getElementById(UID["tabWave_Content"]).innerHTML=t;var t="<div class="+UID["title"]+">"+translate("Last report")+"</div>";if(e.last_report)t+="<center>"+Messages.displayBattleReport(e.last_report)+"</center>";document.getElementById(UID["tabWave_ShowReport"]).innerHTML=t},gotBattleReport:function(e){function f(e,t){var n="Recall march "+t;aZ(n+" "+translate("attempted"));new MyAjax.marchRecall(e,t,function(e){if(e.ok){aZ(n+" "+translate("succeeded"))}else{aZ(n+" "+translate("failed and returned error")+": "+e.errmsg)}})}var t=Tabs.Waves,n=false;if(!e)return;if(e.report.location.x==Data.options.waves.target.x&&e.report.location.y==Data.options.waves.target.y&&e.report_notification.report_type=="BattleReport"){var r=null;for(var i in Data.marches.waves){var s=Data.marches.waves[i];if(s.general.id===e.report.attacker.general.id){r=i;break}}t.last_report=Messages.details[e.report_notification.id];if(r&&r!=null)t.trackStats(r,e);var o=e.report.spoils.items;if(o.length!==0)Seed.fetchPlayer({noCities:true});if(!Data.options.waves.delete_reports&&!Data.options.waves.stop_on_loss)return;if(Data.options.waves.stop_on_loss&&e.report.attacker.name==Seed.player.name){for(var u in e.report.attacker.units){if(e.report.attacker.units[u][0]!=e.report.attacker.units[u][1]){n=true;var a=(new Date(e.report_notification.created_at*1e3)).myString();t.setWaveEnable(false);aS(UID["tabWave_Feedback"],translate("Troops lost")+"! ("+a+")");aX(translate("Wave")+": "+translate("Troops lost")+"! ("+a+")");for(var i in Data.marches.waves){if(Data.marches.waves[i].status==="marching")f(Data.marches.waves[i].city_id,i)}return}}}if(Data.options.waves.delete_reports&&e.report.attacker.name==Seed.player.name&&!n)Messages.deleteMessage(e.report_notification.id)}},aY:function(){var e=Tabs.Waves;var t=be();Data.stats.waves={start_at:t,run_time:0,total_attacks:0,loss:{},items:{},resources:{}};e.bL()},bL:function(){var e=Tabs.Waves;var t=document.getElementById(UID["tabWaveStats_Status"]);if(t==null)return;var n=Data.stats.waves.run_time;if(Data.options.waves.enabled)n+=be()-e.running.start_at;var r=n>0?n/3600:1;var i="<table class="+UID["table"]+">"+"	<tr>"+"		<td class=right>"+translate("Start Date")+": </td>"+"		<td colspan=>"+(new Date(Data.stats.waves.start_at*1e3)).myString()+"</td>"+"	</tr><tr>"+"		<td class=right>"+translate("Run Time")+": </td>"+"		<td>"+bE(n,true)+"</td>"+"	</tr><tr>"+"		<td class=right>"+translate("Attacks")+": </td>"+"		<td>"+Data.stats.waves.total_attacks+"</td>"+"	<tr valign=top align=right>"+"		<td class=right>"+translate("Troops lost")+": </td>";var s=true;for(var o in Data.stats.waves.loss){var u=Math.round(Data.stats.waves.loss[o]/r);if(s)s=false;else i+="	<tr align=right><td></td>";i+="		<td>"+translate(o)+":</td>"+"		<td>"+bD(Data.stats.waves.loss[o]," ")+"</td>"+"		<td>("+bD(u," ")+" /"+translate("h")+")</td>"+"	</tr>"}i+="</tr><tr valign=top align=right>"+"		<td class=right>"+translate("Resources")+": </td>";var s=true;for(var o in Data.stats.waves.resources){var u=Math.round(Data.stats.waves.resources[o]/r);if(s)s=false;else i+="	<tr align=right><td></td>";i+="			<td>"+translate(o)+":</td>"+"			<td>"+bD(Data.stats.waves.resources[o]," ")+"</td>"+"			<td>("+bD(u," ")+" /"+translate("h")+")</td>"+"		</tr>"}i+="<tr valign=top align=right>"+"		<td class=right>"+translate("Items")+": </td>";var a=[];for(var o in Data.stats.waves.items)a.push({desc:translate(o),qty:Data.stats.waves.items[o]});if(a.length>0){a.sort(function(e,t){e=e.desc.toLowerCase();t=t.desc.toLowerCase();if(e>t)return 1;if(e<t)return-1;return 0});for(var f=0;f<a.length;f++){var u=Math.round(a[f].qty/r);if(f>0)i+="<tr align=right><td></td>";i+="		<td>"+a[f].desc+":</td>"+"		<td>"+bD(a[f].qty," ")+"</td>"+"		<td>("+bD(u," ")+" /"+translate("h")+")</td>"+"	</tr>"}}i+="</table>";t.innerHTML=i},trackStats:function(e,t){var n=Tabs.Waves;if(DEBUG_MARCHES)bf("Tabs.Waves.trackStats: "+e);if(as(Data.stats.waves.total_attacks))Data.stats.waves.total_attacks=0;if(as(Data.stats.total.total_attacks))Data.stats.total.total_attacks=0;++Data.stats.waves.total_attacks;++Data.stats.total.total_attacks;var r=t.report.spoils.resources;for(var i in r){aF(Data.stats.waves.resources,i,bV(r[i]),false);aF(Data.stats.total.resources,i,bV(r[i]),false)}var s=t.report.spoils.kill_items;for(var i in s){aF(Data.stats.waves.resources,i,bV(s[i]),false);aF(Data.stats.total.resources,i,bV(s[i]),false)}var o=t.report.spoils.items;for(var u=0;u<o.length;u++){aF(Data.stats.waves.items,o[u],1,true);aF(Data.stats.total.items,o[u],1,true)}for(var i in t.report.attacker.units){if(t.report.attacker.units[i][0]!=t.report.attacker.units[i][1]){var a=bV(t.report.attacker.units[i][0])-bV(t.report.attacker.units[i][1]);aF(Data.stats.waves.loss,i,a,true);aF(Data.stats.total.loss,i,a,true)}}Data.marches.waves[e].has_report=true;n.bL()},bU:function(e){dq("tabWave",Data.options.waves.target.units,Data.options.waves.target)},bi:function(e){var t=Tabs.Waves;var n=e.target.name.split("_");if(n[0]=="AW"){var r=wave_unit_types[n[1]];var i=Data.options.waves.target.units;i[r]=e.target.value;var i=Data.options.waves.target.saved_units;i[r]=e.target.value;var s=ba(Data.options.waves.target.x,Data.options.waves.target.y,Data.options.waves.target.units);document.getElementById(UID["tabWave_Distance"]).innerHTML=bu(Seed.cities[CAPITAL.id].x,Seed.cities[CAPITAL.id].y,Data.options.waves.target.x,Data.options.waves.target.y)+" ("+bz(s)+")"}},setWaveEnable:function(e){var t=Tabs.Waves;var n=document.getElementById(UID["tabWave_OnOff"]);clearTimeout(t.attackTimer);Data.options.waves.enabled=e;if(e){Messages.addBattleReportListener(t.gotBattleReport);n.value=translate("Attacking").toUpperCase();n.className=UID["btn_on"];t.waveAttackTick();t.running.start_at=be();Data.stats.waves.start_at=be()}else{Messages.removeReportListener("waves",t.gotBattleReport);n.value=translate("Disabled").toUpperCase();n.className=UID["btn_off"];if(t.running.start_at!==0){Data.stats.waves.run_time+=be()-t.running.start_at}}},onUnload:function(){var e=Tabs.Waves;if(Data.options.waves.enabled&&e.running.start_at!=0){Data.stats.waves.run_time+=be()-e.running.start_at}},waveAttackTick:function(){var e=Tabs.Waves,t,n,r,i,s=0;clearTimeout(e.attackTimer);if(!Data.options.waves.enabled)return;t=Data.options.waves.target.type+translate(" at ")+Data.options.waves.target.x+"/"+Data.options.waves.target.y;var o=translate("Wave attack to ")+t;var u=UID["tabWave_Feedback"];var a=cK();s=a.count;n=a.delay;r=bB();var f=dB(o,u,s,n,Marches.count.waves,Data.options.waves.max_marches,r,true);if(f!=0){e.attackTimer=setTimeout(e.waveAttackTick,n*1e3);return}Data.options.waves.target.units=aA(Data.options.waves.target.saved_units);i=bb(CAPITAL.id,Data.options.waves.target.units);if(i!==null){bM(o,u,i,true,n);e.attackTimer=setTimeout(e.waveAttackTick,n*1e3);return}if(Data.options.waves.target.include_great_dragon){var l=null;if((l=dC(true,Data.options.waves.target.dragons))==null){if(!Data.options.waves.send_without_dragon){bM(o,u,5,false,n);e.attackTimer=setTimeout(e.waveAttackTick,n*1e3);return}}else{Data.options.waves.target.units[l]=1}}aZ(o+" "+translate("attempted"));new MyAjax.marchSend(Seed.cities[CAPITAL.id].id,Data.options.waves.target.x,Data.options.waves.target.y,r.id,Data.options.waves.target.units,"waves",function(e){var t=Tabs.Waves,n,r;if(e.ok&&e.dat.result.success){t.attackErrors=0;var i=bV(Data.options.waves.delay_min,bK(MIN_DELAY_BETWEEN_WAVE,3));var s=bV(Data.options.waves.delay_max,bV(i*1.5));n=Math.floor(Math.random()*(s-i+1)+i);aZ(o+" "+translate("Successfully"));aX(o);aS(u,o);t.attackTimer=setTimeout(t.waveAttackTick,n*1e3)}else{t.attackErrors++;r=30*t.attackErrors*t.attackErrors;aZ(o+" "+translate("failed and returned error")+": "+e.errmsg+" - "+translate("Retry in")+" "+r+" "+translate("seconds"));aX(o+" "+translate("failed"));if(e.status===429){r=E429_DELAY;bM(o+" "+translate("failed")+" - <b>API</b> ",u,6,false,r)}else if(e.status===509){r=600;bM(o+" "+translate("failed")+" - ",u,6,false,r)}else aS(u,o+" "+translate("failed"));t.attackTimer=setTimeout(t.waveAttackTick,r*1e3)}})},marchTick:function(){var e=Tabs.Waves;clearTimeout(e.marchTimer);Marches.updateTable(document.getElementById(UID["tabWave_Marches"]),"waves");e.marchTimer=setTimeout(e.marchTick,1e3)},show:function(){var e=Tabs.Waves;e.marchTick();switch(e.contentType||0){case 0:e.tabWaveAttack();break;case 1:e.tabWaveHistory();break;case 2:e.tabWaveStats();break;case 3:e.tabWaveLastReport();break}},hide:function(){var e=Tabs.Waves;clearTimeout(e.marchTimer);Data.options.waves.current_tab=e.contentType}};Tabs.Wheel={tabOrder:WHEEL_TAB_ORDER,tabLabel:"Fortuna",tabDisabled:!WHEEL_TAB_ENABLE,container:null,contentType:0,lastSubTab:"tabWheelPlay",minigame_id:0,last_results:[],last_type:"regular",played:0,timer:0,autoTimer:0,refreshTimer:0,delay:0,is_running:false,init:function(e){var t=Tabs.Wheel;t.container=e;Data.setDefaultValues("wheel");var n="<div class="+UID["title"]+">"+translate("Fortuna's chance")+"</div>"+"<ul class=tabs>"+'	<li class="tab first"><a id='+bS("tabWheelPlay")+">"+translate("Play")+"</a></li>"+"	<li class=tab><a id="+bS("tabWheelStats")+">"+translate("Stats")+"</a></li>"+"</ul>"+"<div id="+bS("tabWheel_Content")+' style="padding-top:0px; height:655px; max-height:655px; overflow-y:auto; width:540px; max-width:540px; overflow-x:auto"></div>';t.container.innerHTML=n;document.getElementById(UID["tabWheelPlay"]).addEventListener("click",t.tabWheelPlay,false);document.getElementById(UID["tabWheelStats"]).addEventListener("click",t.tabWheelStats,false);window.addEventListener("unload",t.onUnload,false);t.contentType=bV(Data.options.wheel.current_tab);t.played=0;t.show()},show:function(){var e=Tabs.Wheel;switch(bV(e.contentType)){case 0:e.tabWheelPlay();break;case 1:e.tabWheelStats();break}},onUnload:function(){var e=Tabs.Wheel;bI("===============  Tabs.Wheel.onUnload");Data.options.wheel.current_tab=e.contentType},tabWheelPlay:function(){function i(){var e=Tabs.Wheel;if(e.refreshTimer)clearInterval(e.refreshTimer);if(Data.options.wheel.auto_refresh)e.refreshTimer=setInterval(S,1e3)}function s(e){var t=Tabs.Wheel;var n=document.getElementById(UID["tabWheel_chkTime"]);var r=document.getElementById(UID["tabWheel_chkUnit"]);var i=bV(n.value);var s=bV(r.value);n.value=i;r.value=s;if(i*s<1){n.style.backgroundColor="red";r.style.backgroundColor="red";return}n.style.backgroundColor="";r.style.backgroundColor="";Data.options.wheel.delay=i;Data.options.wheel.unit=s}function o(){var e=Tabs.Wheel,t=0,n=Data.options.wheel.type=="regular"?0:1;if(document.getElementById(UID["tabWheel_nbTickets"]))document.getElementById(UID["tabWheel_nbTickets"]).innerHTML=" ("+translate("You have")+" <b>"+c()+"</b>)";if(document.getElementById(UID["tabWheel_nbGold"]))document.getElementById(UID["tabWheel_nbGold"]).innerHTML=" ("+translate("You have")+" <b>"+l()+"</b>)";bG(document.getElementById(UID["tabWheel_Play"]),false);bG(document.getElementById(UID["tabWheel_Choose"]),false);bG(document.getElementById(UID["tabWheel_Refresh"]),false);bG(document.getElementById(UID["tabWheel_Stop"]),false,"btn_off");var r="<table class="+UID["table_wrap"]+' style="border:1px solid #898989; background:none" width="479px" height=100% style="white-space:wrap">';if(c()==0&&n==0||l()==0&&n==1){r+='	<tr valign=center align=center style="height:308px">'+"	<td width=100%><span class="+UID["red"]+"><b>"+translate("You have")+" 0 "+translate(n==0?"FortunasTicket":"FortunasGoldenTicket")+"</b></span></td>"+"</tr>"}else{for(var i=0;i<4;i++){r+='	<tr valign=center align=center style="height:76px">';for(var s=0;s<3;s++){r+="	<td  id="+bS("tabWheel_box_"+t)+' width="158px" style="border:1px solid #898989"><div id='+bS("tabWheel_square_"+t)+"></div></td>";t++}r+="</tr>"}}r+="</table>";if(document.getElementById(UID["tabWheel_Grid"]))document.getElementById(UID["tabWheel_Grid"]).innerHTML=r;if(document.getElementById(UID["tabWheel_played"]))document.getElementById(UID["tabWheel_played"]).innerHTML="("+translate("played this session")+" <b>"+e.played+"</b>)";if(c()>0&&n==0||l()>0&&n==1){if(e.minigame_id&&e.minigame_id!=0&&e.last_type==Data.options.wheel.type){for(var o=0;o<e.last_results.length;o++){if(document.getElementById(UID["tabWheel_square_"+o]))document.getElementById(UID["tabWheel_square_"+o]).innerHTML=translate(e.last_results[o].type);if(document.getElementById(UID["tabWheel_box_"+o]))document.getElementById(UID["tabWheel_box_"+o]).style.backgroundColor="rgb(245,245,228)";var u=false;for(var a=0;a<Data.options.wheel.mandatory[n].length&&!u;a++){if(Data.options.wheel.mandatory[n][a]==e.last_results[o].type){u=true;if(document.getElementById(UID["tabWheel_box_"+o]))document.getElementById(UID["tabWheel_box_"+o]).style.backgroundColor="rgb(255,190,165)"}}var u=false;for(var a=0;a<Data.options.wheel.optional[n].length&&!u;a++){if(Data.options.wheel.optional[n][a]==e.last_results[o].type){u=true;if(document.getElementById(UID["tabWheel_box_"+o]))document.getElementById(UID["tabWheel_box_"+o]).style.backgroundColor="rgb(255,220,205)"}}}bG(document.getElementById(UID["tabWheel_Choose"]),true,"btn_green");if((Data.options.wheel.auto_play||e.played>=Data.options.wheel.max_auto&&Data.options.wheel.max_auto>0)&&!e.is_running){bG(document.getElementById(UID["tabWheel_Play"]),true)}else if(Data.options.wheel.auto_refresh){bG(document.getElementById(UID["tabWheel_Refresh"]),true);if(e.is_running){bG(document.getElementById(UID["tabWheel_Stop"]),true,"btn_off");bG(document.getElementById(UID["tabWheel_Refresh"]),false)}}}else if(!Data.options.wheel.auto_play||e.played>=Data.options.wheel.max_auto&&Data.options.wheel.max_auto>0||!e.minigame_id||e.minigame_id==0)bG(document.getElementById(UID["tabWheel_Play"]),true)}else bG(document.getElementById(UID["tabWheel_Play"]),false)}function u(e){var t=Tabs.Wheel;if(e<2)var n=Data.options.wheel.mandatory[Data.options.wheel.type=="regular"?0:1][e];else var n=Data.options.wheel.optional[Data.options.wheel.type=="regular"?0:1][e];var r=f();var i='<span class=left>- &nbsp</span><select id="'+bS("tabWheel_sel"+e)+'" ref='+e+">"+'	<option value="null">&nbsp</option>';for(var s=0;s<r.length;s++){var o="",u="";if(r[s].type==n)o="selected";if(r[s].desc.length>38)u=r[s].desc.substring(0,35)+"...";else u=r[s].desc;i+='<option value="'+r[s].type+'" '+o+">"+u+"</option>"}i+="</select>";var a="tabWheel_item"+(e+1);if(document.getElementById(UID[a]))document.getElementById(UID[a]).innerHTML=i}function a(e,t,n){var r=Data.options.wheel.type=="regular"?0:1;if(!Data.stats.wheel.items[r][e])Data.stats.wheel.items[r][e]=[0,0,0];if(!t){Data.stats.wheel.items[r][e][0]++;Data.stats.wheel.total_grids[r]++}else if(!n){Data.stats.wheel.items[r][e][1]++;Data.stats.wheel.total_played[r]++}else{Data.stats.wheel.items[r][e][2]++;Data.stats.wheel.last_won[r].push({item:e,at:be()})}}function f(e){var t=Tabs.Wheel;var n=[];for(var r in Seed.items){for(item=0;item<Seed.items[r].length;item++){var i=false;for(var s=0;s<n.length&&!i;s++)if(n[s].type==Seed.items[r][item].type)i=true;if(!i)n.push({desc:translate(Seed.items[r][item].type,true),type:Seed.items[r][item].type})}}n.sort(function(e,t){e=e.desc.toLowerCase();t=t.desc.toLowerCase();if(e>t)return 1;if(e<t)return-1;return 0});return n}function l(){return bV(Seed.player.items["FortunasGoldenTicket"]||0)+(Seed.player.tickets.gold_club?1:0)}function c(){return bV(Seed.player.items["FortunasTicket"]||0)+(Seed.player.tickets.fortunas_chance?1:0)}function h(){if(e.timer)clearTimeout(e.timer);if(e.autoTimer)clearTimeout(e.autoTimer);e.is_running=true;bG(document.getElementById(UID["tabWheel_Choose"]),false);bG(document.getElementById(UID["tabWheel_Refresh"]),false);bG(document.getElementById(UID["tabWheel_Stop"]),false,"btn_off");MyAjax.getMinigame(Data.options.wheel.type||"regular",function(e){var t=Tabs.Wheel,n=Data.options.wheel.type=="regular"?0:1;if(e&&e.ok){t.last_results=aA(e.list);t.last_type=Data.options.wheel.type;var r=0,i=0,s=0;for(var o=0;o<Data.options.wheel.mandatory[n].length&&!l;o++){var u=Data.options.wheel.mandatory[n][o];if(u!=null&&u!=undefined&&u!="null")r++}for(var f=0;f<e.list.length;f++){a(e.list[f].type);if(document.getElementById(UID["tabWheel_square_"+f]))document.getElementById(UID["tabWheel_square_"+f]).innerHTML=translate(e.list[f].type);if(document.getElementById(UID["tabWheel_box_"+f]))document.getElementById(UID["tabWheel_box_"+f]).style.backgroundColor="rgb(245,245,228)";var l=false;for(var o=0;o<Data.options.wheel.mandatory[n].length&&!l;o++){if(Data.options.wheel.mandatory[n][o]==e.list[f].type){i++;l=true;if(document.getElementById(UID["tabWheel_box_"+f]))document.getElementById(UID["tabWheel_box_"+f]).style.backgroundColor="rgb(255,190,165)"}}var l=false;for(var o=0;o<Data.options.wheel.optional[n].length&&!l;o++){if(Data.options.wheel.optional[n][o]==e.list[f].type){s++;l=true;if(document.getElementById(UID["tabWheel_box_"+f]))document.getElementById(UID["tabWheel_box_"+f]).style.backgroundColor="rgb(255,220,205)"}}}t.minigame_id=e.id;Seed.player.tickets.fortunas_chance=e.ticket;Seed.player.tickets.gold_club=e.golden;if(bV(t.minigame_id)>0)bG(document.getElementById(UID["tabWheel_Choose"]),true,"btn_green");if(Data.options.wheel.auto_refresh&&(i<r||s<Data.options.wheel.number)){bG(document.getElementById(UID["tabWheel_Stop"]),true,"btn_off");t.delay=Data.options.wheel.delay*Data.options.wheel.unit;t.timer=setTimeout(h,Data.options.wheel.delay*Data.options.wheel.unit*1e3+Math.randRange(10,500))}else{if(Data.options.wheel.auto_play&&(t.played<Data.options.wheel.max_auto||Data.options.wheel.max_auto==0)){bG(document.getElementById(UID["tabWheel_Stop"]),true,"btn_off");t.autoTimer=setTimeout(y,Data.options.wheel.delay*Data.options.wheel.unit*1e3+Math.randRange(10,500))}else SoundPlayer.PlaySound("fortuna");bG(document.getElementById(UID["tabWheel_Refresh"]),true)}}})}function p(e){var t=Tabs.Wheel;var n=document.getElementById(UID["tabWheel_AutoMax"]);var r=bV(n.value);n.value=r;if(r<0){n.style.backgroundColor="red";return}n.style.backgroundColor="";Data.options.wheel.max_auto=r}function d(e){var t=Tabs.Wheel;var n=document.getElementById(UID["tabWheel_number"]);var r=bV(n.value);n.value=r;Data.options.wheel.number=r}function v(e){var t=Tabs.Wheel;var n=Data.options.wheel.type=="regular"?0:1;var r=e.target.getAttribute("ref");var i=e.target.value;Data.options.wheel.mandatory[n][r]=i;o()}function m(e){var t=Tabs.Wheel;var n=Data.options.wheel.type=="regular"?0:1;var r=e.target.getAttribute("ref");var i=e.target.value;Data.options.wheel.optional[n][r]=i;o()}function g(e){var t=Tabs.Wheel;Data.options.wheel.type=e.target.value;if(t.timer)clearTimeout(t.timer);t.is_running=false;o();for(var n=0;n<8;n++)u(n)}function y(){function n(e){var t=Tabs.Wheel;if(e.ok&&e.item){t.played++;t.minigame_id=0;dk("Fortuna : "+translate("You won")+" <b>"+translate(e.item.type)+"</b>");dptp4Notifications.showFortunaWin(translate("You won")+" "+translate(e.item.type));SoundPlayer.PlaySound("fortuna");a(e.item.type,true,true);if(document.getElementById(UID["tabWheel_played"]))document.getElementById(UID["tabWheel_played"]).innerHTML="("+translate("played this session")+" <b>"+t.played+"</b>)";if(Data.options.wheel.auto_play&&t.played<Data.options.wheel.max_auto){bG(document.getElementById(UID["tabWheel_Refresh"]),false);bG(document.getElementById(UID["tabWheel_Stop"]),true,"btn_off");t.delay=Data.options.wheel.delay*Data.options.wheel.unit;t.timer=setTimeout(h,Data.options.wheel.delay*Data.options.wheel.unit*1e3+Math.randRange(10,500))}else{t.is_running=false;o()}}else{bG(document.getElementById(UID["tabWheel_Stop"]),false,"btn_off");dk(translate("Error while retrieving the item won")+" : "+e.errmsg)}}var e=Tabs.Wheel;if(e.timer)clearTimeout(e.timer);if(e.autoTimer)clearTimeout(e.autoTimer);bG(document.getElementById(UID["tabWheel_Choose"]),false);bG(document.getElementById(UID["tabWheel_Refresh"]),false);bG(document.getElementById(UID["tabWheel_Stop"]),false,"btn_off");for(var t=0;t<e.last_results.length;t++)a(e.last_results[t].type,true);MyAjax.saveMinigame(e.minigame_id,e.last_type,n,false)}function b(){function r(e){var t=Tabs.Wheel;if(e.ok&&e.item){n.getContentDiv().innerHTML=translate("You won")+"\n\n <b>"+translate(e.item.type)+"</b>";t.minigame_id=0;dk("Fortuna : "+translate("You won")+" <b>"+translate(e.item.type)+"</b>");a(e.item.type,true,true)}else n.getContentDiv().innerHTML=translate("Error while retrieving the item won")+" : "+e.errmsg;n.allowClose(true);n.notifyClose=o()}var e=Tabs.Wheel;if(e.timer)clearTimeout(e.timer);if(e.autoTimer)clearTimeout(e.autoTimer);e.is_running=false;bG(document.getElementById(UID["tabWheel_Choose"]),false);bG(document.getElementById(UID["tabWheel_Refresh"]),false);bG(document.getElementById(UID["tabWheel_Stop"]),false,"btn_off");for(var t=0;t<e.last_results.length;t++)a(e.last_results[t].type,true);var n=new aw(e.container,300,165,"",false,null);n.bd().innerHTML="<div class="+UID["title"]+"><center><b>"+scriptName+" : "+translate("Message")+"</b></center></div>";n.getContentDiv().innerHTML=translate("Please wait...");MyAjax.saveMinigame(e.minigame_id,e.last_type,r,false)}function w(){var e=Tabs.Wheel;bG(document.getElementById(UID["tabWheel_Play"]),false);e.played=0;i();h()}function E(){var e=Tabs.Wheel;if(e.timer)clearTimeout(e.timer);if(e.autoTimer)clearTimeout(e.autoTimer);e.is_running=false;o()}function S(){var e=Tabs.Wheel,t=document.getElementById(UID["tabWheel_wait"]);if(e.is_running&&Data.options.wheel.auto_refresh){if(t)t.innerHTML=translate("Refresh in")+" "+e.delay+"s";e.delay--;if(e.delay<0)e.delay=0}else{if(t)t.innerHTML=""}}var e=Tabs.Wheel;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabWheelPlay"]).className="selected";document.getElementById(UID["tabWheelPlay"]).style.zIndex=1;e.lastSubTab="tabWheelPlay";e.contentType=0;bS("tabWheel_Type");var t="<div id="+bS("tabWheel_grid")+' style="height:640px">'+"<div class="+UID["title"]+">"+translate("Play")+" "+translate("Fortuna's chance")+"</div>"+"<div class="+UID["content"]+">"+"	<table class="+UID["table"]+' style="margin-top:3px" width=100%>'+"		<tr valign=top align=left>"+"			<td width=5%><input type=radio name="+UID["tabWheel_Type"]+' value="regular" /></td>'+"			<td width=35% align=left><label>"+translate("FortunasTicket")+"<span id="+bS("tabWheel_nbTickets")+"></span></label></td>"+"			<td width=60% align=center><label><input id="+bS("tabWheel_Play")+' type=button value="'+translate("Play")+'" /></label></td>'+"		</tr>"+"		<tr valign=top align=left>"+"			<td width=5%><input type=radio name="+UID["tabWheel_Type"]+' value="golden" /></td>'+"			<td align=left width=35%><label>"+translate("FortunasGoldenTicket")+"<span id="+bS("tabWheel_nbGold")+"></span></label></td>"+"			<td width=60% align=center><label><input id="+bS("tabWheel_Choose")+' type=button value="'+translate("Choose")+'" /></label></td>'+"		</tr>"+"	</table><br>"+"	<center><div id="+bS("tabWheel_Grid")+' style="padding-top:0px; height:311px; max-height:311px; overflow-y:auto; width:479px; max-width:479px"></div></center>'+"	<br>"+"	<table class="+UID["table"]+' style="margin-top:3px" width=100%>'+"		<tr valign=top align=center>"+"			<td width=30%><label><input id="+bS("tabWheel_Refresh")+' type=button value="'+translate("Refresh")+'" /></label></td>'+"			<td width=40% class=jewel><div id="+bS("tabWheel_wait")+"></div></td>"+"			<td width=30%><label><input id="+bS("tabWheel_Stop")+' type=button value="'+translate("Stop")+'" /></label></td>'+"		</tr>"+"	</table><br>"+"	<div class="+UID["title"]+' style="margin-bottom:10px">'+translate("Config")+"</div>"+"	<table class="+UID["table"]+' width=100% style="color:#000;">'+"		<tr valign=top>"+"			<td><label><input id="+bS("tabWheel_AutoRefresh")+" "+(Data.options.wheel.auto_refresh?"CHECKED ":"")+" type=checkbox /></label></td>"+"			<td><label>"+translate("Auto-refresh wheel prize list every")+"&nbsp</label>"+"				<input id="+bS("tabWheel_chkTime")+' size=1 maxlength=2 type=text value="'+Data.options.wheel.delay+'" />&nbsp'+"				<select id="+bS("tabWheel_chkUnit")+" size=1>"+"					<option value=1 "+(Data.options.wheel.unit==1?"selected":"")+">"+translate("Seconds")+"</option>"+"					<option value=60 "+(Data.options.wheel.unit==60?"selected":"")+">"+translate("minutes")+"</option>"+"					<option value=3600 "+(Data.options.wheel.unit==3600?"selected":"")+">"+translate("hours")+"</option>"+"				</select>"+"			</td>"+"		</tr><tr valign=top>"+'			<td  style="font-size:2px">&nbsp</td>'+"		</tr><tr valign=top>"+"			<td></td><td><label>"+translate("Stop the wheel when found the following items")+"&nbsp"+"		</tr><tr valign=top>"+"			<td colspan=2>"+"				<table class="+UID["table"]+' width=100% style="color:#000;"><tr valign=top>'+"					<td width=50%><table width=100%><tr valign=top><td><div id="+bS("tabWheel_item1")+"></div></td></tr></table></td>"+"					<td width=50%><table width=100%><tr valign=top><td><div id="+bS("tabWheel_item2")+"></div></td></tr></table></td>"+"				</tr></table>"+"			</td>"+"		</tr><tr valign=top>"+"			<td width=5%></td><td><label>"+translate("And at least")+"&nbsp"+"				<select id="+bS("tabWheel_number")+" size=1>"+"					<option value=1 "+(Data.options.wheel.number==1?"selected":"")+">1</option>"+"					<option value=2 "+(Data.options.wheel.number==2?"selected":"")+">2</option>"+"					<option value=3 "+(Data.options.wheel.number==3?"selected":"")+">3</option>"+"					<option value=4 "+(Data.options.wheel.number==4?"selected":"")+">4</option>"+"					<option value=5 "+(Data.options.wheel.number==5?"selected":"")+">5</option>"+"					<option value=6 "+(Data.options.wheel.number==6?"selected":"")+">6</option>"+"				</select>&nbsp"+translate("of the following items")+"</label></td>"+"		</tr><tr valign=top>"+"		</tr>"+"	</table>"+"	<table class="+UID["table"]+' width=100% style="color:#000;">'+"		<tr valign=top>"+"			<td width=50%><table width=100%>"+"				<tr valign=top><td><div id="+bS("tabWheel_item3")+"></div></td></tr>"+"				<tr valign=top><td><div id="+bS("tabWheel_item4")+"></div></td></tr>"+"				<tr valign=top><td><div id="+bS("tabWheel_item5")+"></div></td></tr>"+"			</table></td>"+"			<td width=50%><table width=100%>"+"				<tr valign=top><td><div id="+bS("tabWheel_item6")+"></div></td></tr>"+"				<tr valign=top><td><div id="+bS("tabWheel_item7")+"></div></td></tr>"+"				<tr valign=top><td><div id="+bS("tabWheel_item8")+"></div></td></tr>"+"			</table>"+"			</td>"+"		</tr>"+"	</table>"+"	<table class="+UID["table"]+' width=100% style="color:#000;">'+"		<tr valign=top>"+"			<td><label><input id="+bS("tabWheel_AutoPlay")+" "+(Data.options.wheel.auto_play?"CHECKED ":"")+" type=checkbox /></label></td>"+"			<td><label>"+translate("Auto-play : Maximum tickets to play ")+"&nbsp</label>"+"				<input id="+bS("tabWheel_AutoMax")+' size=1 maxlength=4 type=text value="'+Data.options.wheel.max_auto+'" />&nbsp (0 = '+translate("no max")+")"+"			</td>"+"			<td width=20% align=right class=jewel><div id="+bS("tabWheel_played")+"></div></td>"+"		</tr>"+"	</table>"+"</div>";document.getElementById(UID["tabWheel_Content"]).innerHTML=t;document.getElementById(UID["tabWheel_Play"]).addEventListener("click",w,false);document.getElementById(UID["tabWheel_Refresh"]).addEventListener("click",h,false);document.getElementById(UID["tabWheel_AutoRefresh"]).addEventListener("change",function(t){Data.options.wheel.auto_refresh=t.target.checked;if(e.timer)clearTimeout(e.timer);i()},false);document.getElementById(UID["tabWheel_AutoPlay"]).addEventListener("change",function(t){Data.options.wheel.auto_play=t.target.checked;if(e.timer)clearTimeout(e.timer)},false);document.getElementById(UID["tabWheel_chkTime"]).addEventListener("change",s,false);document.getElementById(UID["tabWheel_chkUnit"]).addEventListener("change",s,false);document.getElementById(UID["tabWheel_number"]).addEventListener("change",d,false);document.getElementById(UID["tabWheel_AutoMax"]).addEventListener("change",p,false);document.getElementById(UID["tabWheel_Choose"]).addEventListener("click",b,false);document.getElementById(UID["tabWheel_Stop"]).addEventListener("click",E,false);document.getElementById(UID["tabWheel_item1"]).addEventListener("change",v,false);document.getElementById(UID["tabWheel_item2"]).addEventListener("change",v,false);document.getElementById(UID["tabWheel_item3"]).addEventListener("change",m,false);document.getElementById(UID["tabWheel_item4"]).addEventListener("change",m,false);document.getElementById(UID["tabWheel_item5"]).addEventListener("change",m,false);document.getElementById(UID["tabWheel_item6"]).addEventListener("change",m,false);document.getElementById(UID["tabWheel_item7"]).addEventListener("change",m,false);document.getElementById(UID["tabWheel_item8"]).addEventListener("change",m,false);var n=document.getElementsByName(UID["tabWheel_Type"]);for(r=0;r<n.length;r++){n[r].addEventListener("change",g,false);n[r].checked=n[r].value==Data.options.wheel.type}i();o();for(var r=0;r<8;r++){u(r)}},tabWheelStats:function(){function r(){var e=Tabs.Wheel;Data.stats.wheel={type:"regular",total_grids:[0,0],total_played:[0,0],items:[{},{}],last_won:[[],[]]};o()}function s(e){var t=Tabs.Wheel;Data.stats.wheel.type=e.target.value;o()}function o(){var e=Tabs.Wheel,t=0,n=Data.stats.wheel.type=="regular"?0:1;var r=bV(Data.stats.wheel.total_grids[n]);var i=bV(Data.stats.wheel.total_played[n]);var s="<div id="+bS("tabWheelStats_Report")+" class="+UID["status_ticker"]+' style="height:545px; max-height:545px; overflow-y:auto ; overflow-x:auto ; margin-top:1px !important">'+"<table class="+UID["table"]+" width=100%>"+"	<tr>"+"		<td class=right width=15%>"+translate("Total grids displayed")+": </td>"+"		<td width=25%>"+bD(Math.round(r/12))+"</td>"+"		<td width=20%>&nbsp</td>"+"		<td class=right width=15%>"+translate("Total grids played")+": </td>"+"		<td width=25%>"+bD(Math.round(i/12))+"</td>"+"	</tr>"+"</table>"+"<div id="+bS("tabWheelStats_ItemsWon")+' style="height:75px; max-height:75px; overflow-y:auto; margin-top:1px !important"></div>'+"<div id="+bS("tabWheelStats_ItemsStats")+' style="height:440px; max-height:440px; overflow-y:auto; margin-top:1px !important"></div>'+"</div>";document.getElementById(UID["tabWheelStats_Content"]).innerHTML=s;var s="<table class="+UID["row_style"]+" width=100%>"+"	</tr><tr class="+UID["row_headers"]+">"+'		<td width="60%">'+translate("Last items won")+"</td>"+'		<td width="40%">'+translate("Date")+"</td>"+"	</tr>";var o=aA(Data.stats.wheel.last_won[n]);o.sort(function(e,t){return t.at-e.at});for(var t=0;t<o.length;t++){s+="<tr><td class=left>"+translate(o[t].item,true)+"</td>"+"	<td align=right>"+(new Date(o[t].at*1e3)).myString()+"</td>"+"</tr>"}document.getElementById(UID["tabWheelStats_ItemsWon"]).innerHTML=s+"</table>";var s="<table class="+UID["row_style"]+" width=100%>"+"	<tr class="+UID["row_headers"]+">"+"		<td valign=middle width=33%><b>"+translate("Items")+"</b></td>"+"		<td valign=middle width=20% colspan=2><b>"+translate("All grids")+"</b></td>"+"		<td valign=middle width=40% colspan=4><b>"+translate("Grids played")+"</b></td>"+"		<td valign=middle width=7% colspan=2><b>"+translate("Chance")+"</b></td>"+"	</tr>"+"	<tr class="+UID["row_headers"]+">"+"		<td valign=middle width=30%>&nbsp</td>"+"		<td valign=middle width=13%><b>"+translate("Displayed")+"</b></td>"+"		<td valign=middle width=7%><b>"+translate("%age")+"</b></td>"+"		<td valign=middle width=13%><b>"+translate("Played")+"</b></td>"+"		<td valign=middle width=7%><b>"+translate("%age")+"</b></td>"+"		<td valign=middle width=13%><b>"+translate("Won")+"</b></td>"+"		<td valign=middle width=7%><b>"+translate("%age")+"</b></td>"+"		<td valign=middle width=7%><b>"+translate("to win")+"</b></td>"+"	</tr>";var u=[];for(var a in Data.stats.wheel.items[n]){var f=Data.stats.wheel.items[n][a];u.push({item:a,found:bV(f[0]),played:bV(f[1]),won:bV(f[2])})}u.sort(function(e,t){if(e.found<t.found)return 1;else if(e.found>t.found)return-1;else{e=translate(e.item,true).toLowerCase();t=translate(t.item).toLowerCase();if(e>t)return 1;else if(e<t)return-1;return 0}});for(var t=0;t<u.length;t++){var l=bV(u[t].found);var c=Math.round(l/r*1e4)/100;var h=bV(u[t].played);var p=h>0?Math.round(h/i*1e4)/100+"%":"";var d=bV(u[t].won);var v=d>0?Math.round(d/Math.round(i/12)*1e4)/100+"%":"";var m=d>0?Math.round(d/(h*12)*1e4)/100+"%":"";s+="<tr><td class=left>"+translate(u[t].item,true)+"</td>"+"	<td align=right>"+bD(l)+"</td>"+"	<td align=right>"+c+"%</td>"+"	<td align=right>"+(h>0?bD(h):"")+"</td>"+"	<td align=right>"+p+"</td>"+"	<td align=right>"+(d>0?bD(d):"")+"</td>"+"	<td align=right>"+v+"</td>"+"	<td align=right>"+m+"</td>"+"</tr>"}document.getElementById(UID["tabWheelStats_ItemsStats"]).innerHTML=s+"</table>"}var e=Tabs.Wheel;document.getElementById(UID[e.lastSubTab]).className="";document.getElementById(UID[e.lastSubTab]).style.zIndex=0;document.getElementById(UID["tabWheelStats"]).className="selected";document.getElementById(UID["tabWheelStats"]).style.zIndex=1;e.lastSubTab="tabWheelStats";e.contentType=1;var t="<div id="+bS("tabWheel_stats")+' style="height:655px">'+"<div class="+UID["title"]+">"+translate("Stats")+" "+translate("Fortuna's chance")+"</div>"+"<div class="+UID["content"]+">"+"	<table class="+UID["table"]+' style="margin-top:3px" width=100%>'+"		<tr valign=top align=left>"+"			<td width=5%><input type=radio name="+UID["tabWheelStats_Type"]+' value="regular" /></td>'+"			<td width=35% align=left><label>"+translate("FortunasTicket")+"</label></td>"+"			<td width=20%>&nbsp</td>"+"			<td width=5%><input type=radio name="+UID["tabWheelStats_Type"]+' value="golden" /></td>'+"			<td align=left width=35%><label>"+translate("FortunasGoldenTicket")+"</label></td>"+"		</tr>"+"	</table>"+"	<div id="+bS("tabWheelStats_Content")+' style="padding-top:0px; height:580px; max-height:580px; overflow-y:auto"></div>'+"	<center><input id="+bS("tabWheelStats_Clear")+' type=button value="'+translate("Clear Stats")+'" /></center>'+"</div></div>";document.getElementById(UID["tabWheel_Content"]).innerHTML=t;document.getElementById(UID["tabWheelStats_Clear"]).addEventListener("click",function(){r();o()},false);var n=document.getElementsByName(UID["tabWheelStats_Type"]);for(i=0;i<n.length;i++){n[i].addEventListener("change",s,false);n[i].checked=n[i].value==Data.stats.wheel.type}o()},hide:function(){var e=Tabs.Wheel;if(e.refreshTimer)clearInterval(e.refreshTimer)}};Tabs.Options={tabOrder:OPTIONS_TAB_ORDER,tabLabel:"Opts",tabDisabled:!OPTIONS_TAB_ENABLE,container:null,refreshTimer:null,flashRefreshTimer:null,refreshPlayerBusy:false,init:function(e){var t=Tabs.Options;t.container=e;t.own=Seed.player.alliance?Seed.player.alliance.id:-1;var n=new Array(4);for(var r=0;r<n.length;r++){n[r]=""}switch(Data.options.autoCollect.unit){case 1:n[1]="selected";break;case 60:n[2]="selected";break;case 3600:n[3]="selected";break;case 86400:n[4]="selected";break;default:n[3]="selected"}try{m="<div class="+UID["title"]+' style="margin-bottom:10px">'+translate("Options")+"</div>"+'<div style="height:665px; max-height:665px; width:540px; max-width:540px; overflow-y:auto; overflow-x:auto; color:#000;">'+"<table class="+UID["table"]+">"+"	<tr valign=top>"+"		<td><b>"+translate("Game Options")+": </b></td>"+"	</tr>"+"	<tr valign=top>"+"		<td>"+"		<label>"+"		<input id="+bS("tabOptions_CB_Collect")+" type=checkbox "+(Data.options.autoCollect.enabled?"CHECKED ":"")+" /> "+translate("Auto harvest resources from outposts every")+"		</label> "+"		<input id="+bS("tabOptions_collectTime")+' size=1 maxlength=2 type=text value="'+Data.options.autoCollect.delay+'" />'+"		<select id="+bS("tabOptions_collectUnit")+" size=1>"+"			<option value=1 "+n[1]+">"+translate("Seconds")+"</option>"+"			<option value=60 "+n[2]+">"+translate("minutes")+"</option>"+"			<option value=3600 "+n[3]+">"+translate("hours")+"</option>"+"			<option value=86400 "+n[4]+">"+translate("days")+"</option>"+"		</select>"+"		</td>"+"	</tr><tr valign=top>"+"		<td>"+"		<label><input id="+bS("tabOptions_CB_UTCtime")+" type=checkbox "+(Data.options.utc_time?" CHECKED ":"")+" /> "+translate("Check to use UTC time instead of local time")+"</label>"+"		</td>"+"	</tr><tr valign=top>"+"		<td>"+"		<label><input id="+bS("tabOptions_CB_Speedups")+" type=checkbox "+(Data.options.speedups_enabled?" CHECKED ":"")+" /> "+translate("Enable use of speed-ups in attacks waves")+"</label>"+"		</td>"+"	</tr><tr valign=top>"+"		<td>"+"		<label><input id="+bS("tabOptions_CB_Confirmation")+" type=checkbox "+(Data.options.use_speedup_confirmation?" CHECKED ":"")+" /> "+translate("Enable confirmation on use of speed-ups")+"</label>"+"		</td>"+"	</tr><tr valign=top>"+"		<td>"+"		<label><input id="+bS("tabOptions_CB_JobsSpeedups")+" type=checkbox "+(Data.options.jobs_speedups_enabled?" CHECKED ":"")+" /> "+translate("Enable use of speed-ups in training/resurrection jobs")+"</label>"+"		</td>"+"	</tr><tr valign=top>"+"		<td>"+"		<label><input id="+bS("tabOptions_CB_JobsCancel_Confirmation")+" type=checkbox "+(Data.options.jobs_cancel_confirmation?" CHECKED ":"")+" /> "+translate("Enable confirmation on cancelling job in training/resurrection")+"</label>"+"		</td>"+"	</tr><tr valign=top>"+"	</tr>"+"</table>"+"<br>"+"<table class="+UID["table"]+">"+"	<tr valign=top>"+"		<td><b>"+translate("Script Options")+": </b></td>"+"	</tr><tr valign=top>"+"		<td>"+translate("Script language")+": &nbsp"+"		<select id="+bS("tabOptions_language")+" size=1>";for(var i=0;i<Translation.available_langs.length;i++){m+='	<option value="'+Translation.available_langs[i].code+'" '+(Data.options.user_language==Translation.available_langs[i].code?"selected":"")+">"+translate(Translation.available_langs[i].desc)+"</option>"}m+="		</select>"+"		</td>"+"	</tr><tr valign=top>"+"		<td>"+"		<label><input id="+bS("tabOptions_CB_Drag")+" type=checkbox "+(Data.options.popUp.drag?" CHECKED ":"")+" /> "+translate("Enable window drag")+"</label>"+"		</td>"+"	</tr><tr valign=top>"+"		<td>"+"		<label><input id="+bS("tabOptions_CB_Verbose")+" type=checkbox "+(Data.options.aZ.enabled?" CHECKED ":"")+" /> "+translate("Enable verbose logging")+"</label>"+"		</td>"+"	</tr><tr valign=top>"+"		<table cellpadding=3><tr valign=top>"+"			<td>&nbsp<label>"+translate("Wiki URL")+"</label>&nbsp &nbsp</td>"+"			<td><input id="+bS("tabOptions_Wiki")+' size=50 maxlength=200 type=text value="'+Data.options.wikiUrl+'" />&nbsp</td>'+"		</tr><tr valign=top>"+"			<td>&nbsp<label>"+translate("Forum link")+"</label>&nbsp &nbsp</td>"+"			<td><input id="+bS("tabOptions_Forum")+' size=50 maxlength=200 type=text value="'+Data.options.forumUrl+'" />&nbsp</td>'+"		</tr></table>"+"	</tr>"+"</table>"+"<br>"+"<table class="+UID["table"]+' style="color:#000;">'+"	<tr valign=top>"+"		<td colspan=4><b>"+translate("Sound configuration")+": </b></td>"+"	</tr><tr valign=top>"+"		<td><label><input id="+bS("tabOptions_JobsSound")+" type=checkbox "+(Data.options.sound.enable_jobs?"CHECKED ":"")+"/></label></td>"+"		<td><label>"+translate("Play sound on task completion")+". "+translate("Sound file")+" "+translate("for")+" :</label></td>"+"	</tr><tr valign=top>"+"		<td></td>"+"		<td><table cellpadding=0 cellspacing=0>"+"				<tr valign=top>"+"					<td><label>"+translate("Building")+"</label></td>"+"					<td><input id="+bS("tabOptions_BFile")+' size=40 maxlength=150 type=text value="'+Data.options.sound.URL_building+'" />&nbsp</td>'+"					<td><input id="+bS("tabOptions_BPlay")+" type=submit value=Play>"+"						<input id="+bS("tabOptions_BStop")+" type=submit value=Stop>"+"						<