BastianKanaan / MyFreeFarm Berater

// ==UserScript==
// @name           MyFreeFarm Berater
// @namespace      https://github.com/BastianKanaan/GMscripts_MyFreeFarm
// @author         BastianKanaan
// @description    Extends MyFreeFarm
// @icon           data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAAA8CAYAAAA6/NlyAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB94BGgo6NO+u5q4AAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAS0ElEQVRo3t2aeYxl11ngf+fub3+172t3V1cv7sVuJ3bs7jh2QtoMDoHEwRlCbMJEATRiSaKBQTNBCKGwBwSDNAyTQVGCYJIMEINjxrFix3E73mO7TW/V1VXVtS+v6i13v+ee+aNvQSXDaCTS7W7nSE/v3veuzrm/8y3nO9934Dq08cE+APv9E/1//tDN+16/9+hNJ/l+bXv3jAHw4zf1P/sLdx5TRqXyc++fHPvsGzW+/kbC5vMOyyvrfOSDJz99eM/gj+09fkK9Na/fW8sVzr86NfOl7ydgB+iK46TnVz75wJNtHZX3rcuUI8dvFS9cnuHQ7YcOWprTfvb8pUe/H4BzwH7g0H/59INfq3Z09++ZHBPHbn8LpVKF3WNdWPlOdeIdd962MDf/8vSl+XPX8mW0awxrAiPAgd/4xXf+wdaG74yP7BL9w/vp7x2h1WrRM3SYwf5+8cLz31Yf/w8f/fK1nn3tGkt2D3AE6J7o6xoc7Cjyq//pt3ntm88wMzvDhfMX+dmP/AJJnDKxe0j09HQZDzzwns+9GVW6CBwGjgIdhbz91vfdffjg6soWrhcwf+p5Cu7L3DwhWTkdYvVWCeOEQsFm//5dY1/4wld+880kYQeYBG4CqoD23uMTk0mcQJTQF9R4/48PM3mwDU2HDz5Y5dk/+VPc5YuErZpKooZ9LSVsXOX+BNAB7AUK2X1yx97C7oXpNQb7Nrn5pw5hOA6FthLFYh4hdD7+B8NceHGKi2eqYm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md5jI+Uyte5qRrD06Q9Nqb/sw1NbCIFj64gWTFaUfA37kken6oyA/HHUMfwqWuV6tANwJ/BrwF9le+W7gs6OVwnYq4k9vGuy8cP/+8jPQb/4L6/0w8BPAFxHi+I7//puZyx/YMc5f2MXKEa5z07Ii2k8AN2c7KwG8e8czd+Rs+wN2tTM33Nv9L/XRA9wP3PVdGpf7rue6rsYL/x8HbwtumjbAVwAAAABJRU5ErkJggg==
// @date           01.04.2015
// @version        2.4.2
// @include        /^http:\/\/(|www\.|s\d+\.)au\.myfreefarm\.com\/.*$/
// @include        /^http:\/\/(|www\.|s\d+\.)veselaferma\.com\/.*$/
// @include        /^http:\/\/(|www\.|s\d+\.)myfreefarm\.com\.br\/.*$/
// @include        /^http:\/\/(|www\.|s\d+\.)myfreefarm\.de\/.*$/
// @include        /^http:\/\/(|www\.|s\d+\.)myfreefarm\.cz\/.*$/
// @include        /^http:\/\/(|www\.|s\d+\.)myfreefarm\.dk\/.*$/
// @include        /^http:\/\/(|www\.|s\d+\.)myfreefarm\.gr\/.*$/
// @include        /^http:\/\/(|www\.|s\d+\.)migranjalinda\.es\/.*$/
// @include        /^http:\/\/(|www\.|s\d+\.)mabelleferme\.fr\/.*$/
// @include        /^http:\/\/(|www\.|s\d+\.)myfreefarm\.com\.hr\/.*$/
// @include        /^http:\/\/(|www\.|s\d+\.)myfreefarm\.ae\/.*$/
// @include        /^http:\/\/(|www\.|s\d+\.)myfreefarm\.ir\/.*$/
// @include        /^http:\/\/(|www\.|s\d+\.)myfreefarm\.it\/.*$/
// @include        /^http:\/\/(|www\.|s\d+\.)enkicsitanyam\.hu\/.*$/
// @include        /^http:\/\/(|www\.|s\d+\.)myfreefarm\.nl\/.*$/
// @include        /^http:\/\/(|www\.|s\d+\.)myfreefarm\.co\.nz\/.*$/
// @include        /^http:\/\/(|www\.|s\d+\.)myfreefarm\.no\/.*$/
// @include        /^http:\/\/(|www\.|s\d+\.)wolnifarmerzy\.pl\/.*$/
// @include        /^http:\/\/(|www\.|s\d+\.)pt\.myfreefarm\.com\/.*$/
// @include        /^http:\/\/(|www\.|s\d+\.)fermavesela\.ro\/.*$/
// @include        /^http:\/\/(|www\.|s\d+\.)mojaderewnja\.ru\/.*$/
// @include        /^http:\/\/(|www\.|s\d+\.)myfreefarm\.se\/.*$/
// @include        /^http:\/\/(|www\.|s\d+\.)th\.myfreefarm\.com\/.*$/
// @include        /^http:\/\/(|www\.|s\d+\.)tr\.myfreefarm\.com\/.*$/
// @include        /^http:\/\/(|www\.|s\d+\.)myfreefarm\.co\.uk\/.*$/
// @include        /^http:\/\/(|www\.|s\d+\.)myfreefarm\.com\/.*$/
// @include        /^http:\/\/(|www\.|s\d+\.)myfreefarm\.com\.vn\/.*$/
// @exclude        http://*/dyn_bubbles.php*
// @exclude        http://*/nachrichten/bbhelp.php*
// @exclude        http://*/payment/*
// @grant          GM_addStyle
// @grant          GM_deleteValue
// @grant          GM_getValue
// @grant          GM_listValues
// @grant          GM_log
// @grant          GM_registerMenuCommand
// @grant          GM_setValue
// @grant          GM_xmlhttpRequest
// @grant          unsafeWindow
// @require        https://raw.githubusercontent.com/BastianKanaan/GMscripts_MyFreeFarm/master/MyFreeFarm_Common_functions.user.js
// ==/UserScript==

//***********************************************************************************************************
unsafeData.beraterDone=false;
// global variables
const VERSION=GM_info["script"]["version"];
const neededVersionFunctionFile="2.1.3";
const GM_Home  =GM_info["script"]["namespace"];
const GM_Source=GM_info["script"]["namespace"];
// [version,date,[[de,en],[de,en],...]]
const CHANGELOG=[["2.0","29.05.2014",[["Migration nach openuserjs.org","Migration to openuserjs.org"],["Script wird jetzt auf GitHub entwickelt","Script now developed on GitHub"]]]
                ,["2.1.1","14.06.2014",[["Neu: Changelog","New: Changelog"],["Bugfixes","Bugfixes"]]]
                ,["2.1.2","28.06.2014",[["Ge"+a_dots+"ndert: Berechnung des \"Rekursiv ben"+o_dots+"tigt\"-Wertes","Change: Calculation of \"Recursive needed\" value"],["Neu: Optionen bzgl. Globaler Zeit und Bauernmarkt","New: Options according to global time and farmersmarket"],["Bugfix: Event nach Bedienung eines Farmis","Bugfix: Event after handling a farmi"]]]
                ,["2.2","11.07.2014",[["Refaktorierung der Zonen-Daten","Refactoring of zones data"]]]
                ,["2.2.1","12.07.2014",[["Bugfix","Bugfix"]]]
                ,["2.3","14.08.2014",[["Anpassung an Firefox 30","Adaptation to Firefox 30"]]]
                ,["2.3.1","15.08.2014",[["Bugfix: Zeit von anderen Accounts auf dem Server (Umloggen)","Bugfix: Time of other account on the server (login)"],["Bugfix: Ignorieren von verwelkten Gestecken","Bugfix: Ignoring of faded arrangements"],["Ge"+a_dots+"ndert: Spezieller Portal-Login nicht mehr ben"+o_dots+"tigt","Change: Special Portal-Login not needed anymore"]]]
                ,["2.3.2","17.08.2014",[["Bugfix: Farmi MiniInfo verschwindet","Bugfix: Farmi MiniInfo vanishes"],["Neu: Goldesel Waltraud Log","New: Donkey Luke Log"]]]
                ,["2.3.3","19.08.2014",[["Neu: Baumereiprodukte und -quests durch Patch 18.08.2014","New: Forestry products and quests by patch 18.08.2014"]]]
                ,["2.3.4","22.08.2014",[["Bugfix: S"+a_dots+"gewerk und Schreinerei durch Patch 18.08.2014","Bugfix: Sawmill and carpentry by patch 18.08.2014"]]]
                ,["2.3.5","23.11.2014",[["Bugfix: Im Markt wird manchmal die Menge nicht selektiert, wenn man ein Produkt kaufen will","Bugfix: Sometimes the amout of a product is not selected when buying a product"]]]
                ,["2.3.6","08.12.2014",[["Bugfix: DonkeyInfoPanel-Verhalten, wenn von zwei Computern auf einen Account zugegriffen wird","Bugfix: Multi user handling of donkey info panel (when accessing an account from several computers)"]]]
                ,["2.3.7","16.12.2014",[["Aktualisierung der Daten","Update of data"]]],
                ,["2.4.0","01.02.2015",[["Anpassung an Firefox 35","Fix for Firefox 35"],["Neu: G"+u_dots+"terhof","New: Megafield"]]]
                ,["2.4.1","12.02.2015",[["Bugfix: Logging Waltraud","Bugfix: Logging Waltraud"]]]
                ,["2.4.2","01.04.2015",[["Aktualisierung der Daten","Update of data"]]]
                ];
if(!VERSIONfunctionFile){
    alert("Hi, I am the Berater-Script.\nThe function-file is missing.\nPlease install me again.");
    location.href=GM_Source;
}else if(compareVersions(neededVersionFunctionFile,VERSIONfunctionFile)>0){
    alert("Hi, I am the Berater-Script.\nThe function-file is too old.\nPlease install me again.");
    location.href=GM_Source;
}
var DEVMODE=GM_getValue("devmode",false);
var DEVMODE_EVENTS=GM_getValue("devmode_events",false);
var DEVMODE_FUNCTION=GM_getValue("devmode_function",false);
var DEVMODE_LOG_WARNING=GM_getValue("devmode_log_warning",false);
var DEVMODE_LOG_ERROR=GM_getValue("devmode_log_error",false);
var hotkeymap=explode(GM_getValue("hotkeymap"),"do_main/hotkeymap",{"prevPage":37,"nextPage":39,"farm1":49,"farm2":50,"farm3":51,"guild":52,"city1":53,"city2":54,"farmilog":70,"help":72,"market":77,"marketstand":188,"messages":78,"options":79,"profit":80,"sgh":83,"overview":85,"contract":86,"systemmessage":88});
var FARMNAME=null;
var USERLEVEL=null;

// Constants
const INIT_CSS_STYLES = {
    "systemMsg_marketsale":[[],""],
    "systemMsg_contractsale":[[],"font-style:italic;"],
    "lowrack":[[],"background:orangered;color:#000;"],
    "farmicart_lowrack":[[],"color:yellow!important;"],
    "timeholder":[[],"background:url(\"http://mff.wavecdn.de/mff/guild/help_back.jpg\") -25px -25px;border:1px groove #4d240e;border-radius:10px;padding:5px;margin-bottom:5px;"],
    "timer":[[],"background-color:#de9008;color:white;font-weight:bold;text-align:center;"],
    "watertimer":[[],"background-color:blue;color:white;font-weight:bold;text-align:center;"],
    "timer_ready":[[],"background-color:red;color:white;font-weight:bold;text-align:center;"],
    "prod_border_lowamount":[[],"border:1px solid blue;"],
    "prod_border_missing":[[],"border:1px solid red;"],
    "cloud_back_noprice":[[],"background-color:white;"],
    "cloud_border_noprice":[["cloud_back_noprice"],"border:2px solid black;"],
    "cloud_back_below":[[],"background-color:#fdd;"],
    "cloud_border_below":[["cloud_back_below"],"border:2px solid red;"],
    "cloud_back_between":[[],"background-color:#ffe87c;"],
    "cloud_border_between":[["cloud_back_between"],"border:2px solid #ff8c00;"],
    "cloud_back_above":[[],"background-color:#dfd;"],
    "cloud_border_above":[["cloud_back_above"],"border:2px solid green;"],
    "farmi_price_unknown":[[],"background-color:none;"],
    "farmi_price_low":[[],"background-color:#FF3333;"],
    "farmi_price_between":[[],"background-color:yellow;"],
    "farmi_price_above":[[],"background-color:#22AA22;"],
    "farmi_amount_missing":[["farmi_price_above"],"border:1px solid red;"],
    "farmi_amount_low":[["farmi_price_above"],"border:1px solid blue;"],
    "farmi_amount_above":[["farmi_price_above"],"border:1px solid grey;"]};
const IMAGES={"leftarrow":"data:image/gif;base64,R0lGODlhIwAaAPcAAEQWBLyCVIROJKRqNFwyBOy2dGQ6JNyiZIRSPJxuVHxCDMySVIxeNLR2PFwyFPzSpEwmBNyefIxWJHRGJOy6lGw6FLSGZJxqRJRePFQmFMSSbKRyRKx6VOSqfIxiTHxONHRKNKRiPOSqdKx2TFwuBIRWNPzKlLyKXHw6DIQ+JJxmLHQyFIRGJHQ6FKxqROy6hGxCHLyOZMyabMR+ZIxOJHQ2BGxCJMyedJxeLJpmPLx6VOSyjEQeBPCyfIRCHMSCXMqSZGQyHF8mBHNGLLB+TJVaPMSGZKRqTJpiRFkuFJRWNPzOpHQ6HPC+jOSidJ1eNFwiBGIyDPzitOKmfIxWLPi+nMiWdKpyTMR6XLiCXIJOLLRyPHQ+JIxaPLRyVKh2RGwyFEwmDGk6HJxePOSqhIxONLx6TFouDPzOnK5uTHxCHNCadIxOLGpCLEceDNSSZFguHKVqPPS+fGs+JIxWPPzWtNyihHpKJO6+lLSGbKJuRNSWbKx6XPSufKdmRLB6TIpaNKx2VNCmdOy2jOyydIlKHMyObPyyhOy2fMySXPjGnHQ2HIRKLGwyDFwqDPzSrMyOXPy2hHxGLPy+jPzmvJRWLLR2ROCibIRCFJxmRFQiDLRyRJxmNMyOZNyedPyyfLx+TGQuFPzOrL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BAjYkAEkOFazgBDXUELPsPm/MkQNdXSwDyG4XCJObOUOQg8IXOWgDydCQ7LLCCtQ4cQU7R4gXgxVX7NVFDjbfkpduZWxxizZb7CB0OFtA0oTRKzTRDTSJ5EDMWcxckIPUOdx8CyC3vP0AcDdfcQGvvbWusUIRFiSSiDjlQhPHG/oNUdcK23W5N6+AzNHhSRAXcY8Z2whugTgVLH3EERa89+AcXf74Y29XPJDCCl2WtEAD1wi+jTp99CCOMOwYDhE7RThB+hViPEANxKxTgws199zTzTUyACBDKg2ok0cv4nB8BkMWpGJBDGaIQQ/L1CTDshhnSPPBNdvAI4MMGjXQwD9YaWXKAxZkj07696NDyv78q9NAKttIn/rYl5FrNCAgADs=",
              "settings":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAHw0lEQVR4Xu2Wa1BU5xnHnz1nz17YXZab3C8CagSRgJpiMBIvQEXHW2oN/ZDYQlrbaRqVekFiHWplL+yy7IImwaCpjdGGGpEEBSIaZRprsBWLqGAw2orcFpHFXc6evZy379meyTh0sdikM/3Q38x/5p1zzrvv/33e532ehf95/k9pqWqhwVh6x2DU9xtM+s91OtUbxcXFEngK1IaD2QZDdQB4gYAnoNVqFSyglqjImKmrV64JWZSxJD0kLFyr8JPdKCkpCYFJoDW+tw0E0OQSCq/u1VfHwNOi12sycARsV9quuAcHB9HAwAA60/ypy1hhuAhPoKamhtRVHj5UXnXU2nzpBjr2yQWX1vTegxLju8nwtKh0qjRNaQm3uP3+/fseE+9WVz1S636zyHvkDiq0lb+98M7hWutnl2+hlrbbHr3/0RmkLj+IqqqqqAmPQKVSBcI4irYVfQEAFqfTeR8wDMNAXFy8TCQUrwNvSMm20NDQtOTUFBkpJIHDzbrBbB60CQSCVzZu3Oj0akCjKfkuIURDlZXG78NjqMvUqQCgFAqFNiwgCALkcrkAj2PBCwIEgdOnxYodDgc4HQy4nAx8ebPL7mCcjYWb845MmISUmDqU8mwquFjX0aqqt9b88xaUpAh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UQrAMAhDp3fMKT1k9iGs0tgiy4/wGqNFI/kM5IoiYuQb5WWYRk7zjGS7UBUAz3I3rbkn68ddUUuWT7espPkvAM22vFu2bs8V2v/7tnoB7YUnCmjChpYAAAAASUVORK5CYII=",
              "exclamationMark":"data:image/gif;base64,R0lGODlhGAAYAKEBAAAAAP///////////yH5BAEAAAIALAAAAAAYABgAAAJGlC+gy4B/QJi0BgeRtBZns3GU94Xi9UXnmKonmZpd64pwbNNaroN8n5gBfZUbTWY8Moa1SbL008mcwykKaH1mkEzQsjssAAA7",
              "graph":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAYdJREFUeNpi/P//P8NgBkwMgxyMOnDUgaMOHHUgrQGooMaFgWAmSAkQtwyUexjx1SSMjIwwyY9ALEAvB46mQSIBGzTp3IPiFqgYSWnwPxR/oIEDW5DMh+EuDDcMoANfYXHgc3Q3DGQU/x3MaRCU1r5gEV82WNLgHPSoBeIJIIdTKw0yA3Ev1GAQng/EPEQ6LhnJ3G9AbIYvwMh1YCmWBD6HCMcZA/FPJD1+hGKUVAc6QaPiMxYHfoOGLC4gCsQPkdRXEFPVEevAP9Co/E8AbwdiISz2ghy+C0ndNGLrYmIdiIxBpf5GPI58iJ6uoOkVJr8RX0hTEoKgjGCPlg6fQB0EavWkQaP5PzSd5UPFkdPcSSDmJKU1Q+1ixhgtnaFjgs02elR1oMywF4cDnwwGB8IyxQcsDrxNqgOZaFjPrsciPpfaTX5KqjoeaOH9Fhq1LQTKyeHd5AeFhspg7NW9IqL2oCYuJTUXd9HZgW9JdSAz1JG36eTAaSRlktGhj1EHjjpwCDgQIMAAkAsvxuJFQs4AAAAASUVORK5CYII=",
              "questActiveMain1":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACQAAAAjCAYAAAD8BaggAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/w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55ooSeiEEcQpudHZ2kltzIXAkGeaHNPzr0wjhSHXGQaJY1sE5YCC5+P5Lp7nYoRg2/oBAuVxaHqRU/Mtji+ERGGKe90WHtv1azSXQrpRSq57OpKAVD1P1bleXAOkjbgQWmBEjkIgpUIphUQipIVAgBBYUmHQ6NSgtUatNm3xboepuTbrR8uMbSoRWjkcPw59wzx+/8dpLad4to3jWEglkUaApcDQWKOhxVZ4XkNxmpnllUi4dorhXNYElgRD73/7uemvlETnBgN04pR22CVwJMOjASPrCihXYJRGRGeh72a+WN7HI1M/pr/Ws66CbREMFEm1aa0Bunbz6IU+6z+r20aqxXbS2xpkbwU3q6XNoZcRs2rmRqONIMkMbW1Y50viNCY3McVigHZAsYxpv8yz/z7HmXFDp6VXS5awsvc47YzOGqBXJqfP85z6xfY/f8Tb/LHEzwlce9UTe69KQq575wsV1wgkUhribo59LEEUHMJcYWtBfDbl2GvH+dP5CZwbHcYrAyxGEZk25GnOy8dn5lf9/wJQwbkwjqp/7PzqbR+7hL6Sw0cf/Y5YfYgiV6nU+7UnLqwvwkAmep8Vv/2DYx/XCN2J83fakd67ugGd25v1tx6+Izs820AYaBwMOXGBh/8BKS/fbJ55ZE4AAAAASUVORK5CYII=",
              "questActiveFoodworld":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACQAAAAjCAYAAAD8BaggAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB94BHgsUNGoJEuIAAA1WSURBVFjDpZh5sFXFmcB/3X2Wu757376xg6yyi2KIGAVRZgxKlMrojClGE0ZNImiMOhmjlUomVsYZRqORqBNNDBr3uA5IiGIEEVFA1iAIDx68fb/33eUs3fPHewgM1PwzX1VXnVN1Tn+/b+n+vm7BoFw4Dm5YUMOtj7SwcEwNw+MpPnUbWDR1KPc+MYWa1KvDbltc+cCT69qXNzTTsevByYy5RPHCKpuOZkM8aRDaoGwbbcCYEAEEgCUEoRH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xOIhkjFrWpSCve227x5hrFX54+aa8XGFr2bqaipp7B9httDAQBGOOLwZ3ojJDZwITqNBFbIAQIBF6oyfiQ93268wlae/rZ8v5m/A0B865dhG3bSGmRiguOtCrueCKCcRWjqk5O3Hj4KMX+Ip72KXZ7SAnac6jo6iEMtZfNmQGg737tnNOINot2ojH3y/dQG4qeRxCG5IsBxYKHH2hKEtBVOh2hPVKpFJa06cpIHn5L0dKguHKxGtxiBuSD1+6jekgZiZISpNDYrkNJMoqqrUEpacXjA76xWjL+6S4yAgEoRyBQBJ7Gth2SVogfGrpzHkpCiKCnv4T2Tp+KdJLKUsUzGwTrt1jIlEVl6Umafs/wce4tqipqCUKNFAZd8MgDpUUPbXQQBgMhk9poTh3GGHwdEnoGrQMMGscW+EYjpSQWcVFKEYs5JEdMYffxWkrKq8GK8voGjRu1iUYVOf/LQzHbthxiWFcAlovRIQKBkgMDNGGoO7MFj2zBw8KI07PaCIwGYYOSNkZqjNE40qEgiyglcG2bXE4y9Pw7KTo15PvupqtsBlkrTmV9BK0tNu0FX4Mt4YvXVuJNLCHiWCjsgVMtYKTEWDYYesLB6mp1ZvpPA8p7vunO5IVblCgNXqgJtSEXhPTkAnryRXrzHv3FEJntoFho4+Yv/h5X2UTq6kk23IMZci2tfjnNeah24TWzmpq+JDLbiTAaZSukhJhlkapMEGiTOQEkll8x9TSgned3+FVRxyp4PloDCowWBFrja4MfanSg0RgECi0MGE3gF7B0ATwfocFYLslUmlRZGdn2RtxUFdr3EIOZrhAICVMypdz/wPY4kAOw3t9z7DSg43OyL11dMva6SKApiTgDTbkc6BClFCDBFiCEGiw04uT1CxKMwAiDDgsU8h6BDqgeORKkQiAwGHqyuUHjDE/3728+AQNgRZ3Tt6LUL53rv7qk/vp01OGq/3hDDPgIOahZndpHiZM7vTADl2WnJqQ+5TkcpAfQLy5fGPy1uQdhoPOzPhpO8vA/0PHUrsuSeDkAAAAASUVORK5CYII=",
              "floppyDisk":"data:image/png;base64,iVBORw0KGgoAAAAN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EteSi7T4w6yElvnkrpfW2jzXSl4WUiJTzhp7qwo4Acm51Yw4nXRHXXRLGgldtjPK3lmws1meneJMMm8HcGE6i5ZRuVXIsaJ58KZEXltZtfV1z34TU9/WjKauE/3rI/aCbknjViGHLNezLO4C4GoxxIfFEJp5g4m0CcA7qRqpbJXJyQqvSZZHOa1xIRYg0lCPIG2DaKoKOGj98iN2NhndxCREo3GT8bQJrSFWCjlm5qqQXSORrthOtajMfPoTenFwRjfofearlveqjpovbPy7NBVd1zG/B5GhL0F2jZ2SwNTCDBndZKWQY2XqJksb8M2+SqQraFGZRLpCu2Rwpn4HD5//iX1tqOoaJU1EiJ//o5lZuM17LdN4AmEkCSpjWXKvn7aibfbZhyGRrtAddZFIV5jXRfvYz+sih179Ol3tLSBJYBiU1tYYXeraekhcmThuqvkC45EZFG8ASZKQJBDGavzpuec/5Wy7TKOPIy8eobGh3r529aqOWi4yuLgLj2wwdPQJQdj2JDLVfIEzoSlkpwtp08gwkESRGiIODHTDwBQdG01m2PM1RASjhlatcOTuXgD7WSRsv+3+9vTPTD0bZ3g4xMdr9xDwymgooBaQlToANBRkVNtm+7emrlPSRMIRLwMjj9q+/wMharssRMjy2wAAAABJRU5ErkJggg==",
              "category_f2_active":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAYAAADE6YVjAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB94EBQ8JC2vypPEAAAU1SURBVEjHpZZtbFNVGMd/96Xt3WvH1o1269Z1Y6DAdC5MgQUmCJgIMRgMStSQgAnBGKIfkPjJRYMvQCQKRjFICC/iCwaYYBREXsaYwtxYEGRA6Vq2dRu0u+tcd7vutn7o2JggTn2+nHOee8/5n+f8n+d/jsBtdvqbtTGANFv+bd4+IIHRWR+9XSpqT4S5z74u3PIOdbo0Lbb7s41QWotoUpAQB79EYZR9nSjRsMYjgZkjgASASy5PbHxBHgAdne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gqnPVXN3Ma3WfegTtGAl7jHgKRFQioAeukd1khoaaziEsopZGs2zIpNESAFSBQti9O8bEmeAUk5DgTTBNWp/HtaV7JxfYAjn27ksgXnYNgjWEnBoDSKpDn1cCA5TNMTz1Lk3nDi2feHJpkHsazjOigSkSaNSNNS6vSrWPPkKxzdsgWAqulTkM+cy/KnS2hlw9+fK6bASGkOSDaTRhVTUGR50gr2+t9l+WMBeOxqwD75iv8MQNgYRtp5DITLObv/EsY0DUtIzgeThnyC/gdD2KR1nYbEAgck0nizFCzzc37/fMa0YUxznP8jwhSkdZ3a2AX5W4t03JXINgyNttIW3G4viiIzjowL8Y+1ZQlM06AhsWjStWgSydEt62wj1e+cL171X2Vg4gVDY9SUCZb5qb/oznzs3wCTHVSIZqCsjAAAAABJRU5ErkJggg==",
              "category_f5_active":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAYAAADE6YVjAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB94EBQ8NHmJDhR4AAAajSURBVEjHfZZ/bFPXFcc/7/nZfk6cxHEcgp0fYJKYkMSQOKmA0BGapIIJEJqmLqOdKpVu3f5gq8akskI3daKgbZqKhtiPbhVd1Q2Nlf6AMrRBCGHi1wZJYIESfhoSSJrEsV9skvjXe29/vOAORnekq3vvOVfne86733PuE5iRnmO7iSsTOoDDPXdGOw3YeFgep/vcNhlRUGIpnv76q8IDbWZx+oPtOsBFTzcm2YYJ04xFBUwzM/+1ftQOKipqfJrGcBNKLEVBYY4QaN2IBHDur7/QAXqKesm25z/iTAZUNNVMMpmibnotwcEISjqFQzLjryzhjPQXzBYTZsxgk/m33Et9eClxZVgHBOFBBn1z+rDZsw3/mo6maySmU3hHVhBWFEJKmitdJ7kV6mVbQyEA+3oG6FAKeaqlhXneObgcEgBeX4ALwu/x3/EzmRIRTn+wVT/vukiuy8Uy4VmCwTsZp0ePnqBm+ibtK3K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rvL0vIh/vg//Cr87UV+cuEab797kZ/98A7eWG44YdOaMlCA04sNfuOpOaanGjRmF8hqdWaaVeabGSubbX5weYUOwvS+JvtnUmYbhp39/hXj9Hlxeto6WVLHFFBBiSKSi9KSIGsa5IOQyxuz68mrW53I2s6Q3e6A5lTCr3z9WZ49NQ9vXuOv3/mE65ff5q3/c59bE3X2YmCr3OPh/wNkVB9DQgBo6gAAAABJRU5ErkJggg==",
              "category_r2_active":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACoAAAAqCAYAAADFw8lbAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB94EBRAtJsi//W8AABHySURBVFjDVZhZrKXXWaafNf3DHs9Up+pUuapck+MqV2zHVYk7lWADpiEBxWEKYjKG5iLyTavVSKilFrkw0LetSA1RBBcgc0MgIIKgu4ksYgOOHcdluygPNZ9Tp07Vmac9/MOauPhPObClvX9t7b3W+tY3vO/7feKPfuMnWNkZYbqKH/viQzzR0bz9xjzfv7HKyrVLvPcvlgVjiA88QGvuIJNzB5ienqbX6+GPD59TqXpGGXFWaHEIGSeQZEAgUBPEdnRxydt42Vf+ZXWz89JgMGB7e5vd5Xu41bscqhZ47ESL3oEjZN0p+p2cRAnurI25vrhDohSz3RzxOz/2KMlUzue+eIbzfc2r353n3WsLLFy8ynvXYfPgQVqHDzN79Cizs7OY0+7ZtJu8oFvqaZPqXCuN0gopJUJIhIAYIcaA957gA847nHO42hW+iK/UI/c1/6H51vr6Opt3FlBrC/zwzAr9g8fI+zN0Oi2yJGVlY8yHCxskUaDJ4cc/f4LzKvD3L1/n4nsfcvO1e7xbGfTHjjN76hSHDx+m9ah4Np9MvpJ0WufyPCfLMhKToI1GKY2SEiEEADFGfAh47/DOY52jriqqusrrdv25qlt9zvfDW3qn/+LE5ce+dXdphpeXrnP8+gKPnwgYc5AkSTl6cAKhJdfv7CLe/INf4nw34S/evMV773/IpZdX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ZVEm1YtAAAAAElFTkSuQmCC"
             }
// cases(%=number): %=money, "c%"=coins, "f%"=fictive money
const NPC=[[,0.5,1.1,1.34,2.75,3.95,8.05,17.8,18.5,"f85","f110","f180","f280",,,,,0.16,0.52,1.02,1.44,1.96,2.28,3.8,3.69,"f340",4.38,"f510","f590",12.4,"f650",3.49,5.19,8.75,6,15.63,16.88,37.5,3.9,52.44,51.75,60.25,58.13,66.19,18.2,"c79",150,,1200,,1200,,,,,4500,,14400,1200,,"c125",,"c23",,4800,4200,,,,,,,,750,2100,"c25",,,,,,,10800,12000,,1500,3300,,,,,"f650","f1500","f1500",5000,12000,"c10",,"c20",,"c5","c5","c5","c5",,"c5",,,10.12,3.72,"f155.1","f545.7",37.42,23.32,7.44,82.36,"f106.8","f148.8","f69.6","f196.8","f278.4","f408","f240","f324","f250","f864",47.15,140.56,125.88,,"f12.8","f73.5","f127","f106","f53.05","f113.75","f44","f33.33","f71.3","f73.2","f181.2","f321","f316","f491","f350","f484.2","f906.5","f421.7","f473.5","f749.98","f237.1","f675","f975",12.25,37.5,"f1025","f1100","f810",,"f231","f6500","f58","f137.67","f197.67","f342.5","f830","f700.5","f1063.2","f704.42","f734","f339.53",3.1,3.15,3.27,7.3,4.9,5.92,6.61,6.1,7.3,5.6,5.2,3.6,10,8.1,23.5,7.8,8.2,,,,,,,,,,,,,"f410","f490","f503","f589","f469","f1312","f598","f533","f480","f420","f1620","f1030","f675","f950","f2350","f2400","f2450","f3550","f3600","f3650","f8000","f8000"],{},[],[]]; // task_new_plant task_new_product
    /*
    var new_NPC=NPC.clone();
    new_NPC[0][221]='f8000';
    GM_log(implode(new_NPC));
    */
const INIT_NPC_SAISON={"94":false,"95":false,"96":false,"98":false,"100":false,"101":false,"102":false,"103":false,"105":false}; // task_new_product
const ALL_ZONES = {"farm":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24],"farmersmarket":["farmersmarket-0","farmersmarket-1","farmersmarket-2","farmersmarket-3","farmersmarket-4","farmersmarket-5","farmersmarket-6"],"forestry":["forest","sawmill","carpentry"],"city":["windmill"],"foodworld":["foodworld-0","foodworld-1","foodworld-2","foodworld-3","foodworld-4"]}; // task_new_zone
unsafeData.ALL_ZONES=ALL_ZONES.clone();
const DATA_zones = {"1":{"location":"farm","farmNr":0,"zoneNr":1,"productional":true},"2":{"location":"farm","farmNr":0,"zoneNr":2,"productional":true},"3":{"location":"farm","farmNr":0,"zoneNr":3,"productional":true},"4":{"location":"farm","farmNr":0,"zoneNr":4,"productional":true},"5":{"location":"farm","farmNr":0,"zoneNr":5,"productional":true},"6":{"location":"farm","farmNr":0,"zoneNr":6,"productional":true},"7":{"location":"farm","farmNr":1,"zoneNr":1,"productional":true},"8":{"location":"farm","farmNr":1,"zoneNr":2,"productional":true},"9":{"location":"farm","farmNr":1,"zoneNr":3,"productional":true},"10":{"location":"farm","farmNr":1,"zoneNr":4,"productional":true},"11":{"location":"farm","farmNr":1,"zoneNr":5,"productional":true},"12":{"location":"farm","farmNr":1,"zoneNr":6,"productional":true},"13":{"location":"farm","farmNr":2,"zoneNr":1,"productional":true},"14":{"location":"farm","farmNr":2,"zoneNr":2,"productional":true},"15":{"location":"farm","farmNr":2,"zoneNr":3,"productional":true},"16":{"location":"farm","farmNr":2,"zoneNr":4,"productional":true},"17":{"location":"farm","farmNr":2,"zoneNr":5,"productional":true},"18":{"location":"farm","farmNr":2,"zoneNr":6,"productional":true},"19":{"location":"farm","farmNr":3,"zoneNr":1,"productional":true},"20":{"location":"farm","farmNr":3,"zoneNr":2,"productional":true},"21":{"location":"farm","farmNr":3,"zoneNr":3,"productional":true},"22":{"location":"farm","farmNr":3,"zoneNr":4,"productional":true},"23":{"location":"farm","farmNr":3,"zoneNr":5,"productional":true},"24":{"location":"farm","farmNr":3,"zoneNr":6,"productional":true},"windmill":{"location":"city","cityNr":2,"zoneNr":1,"productional":true},"forest":{"location":"forestry","productional":true},"sawmill":{"location":"forestry","zoneNr":1,"productional":true},"carpentry":{"location":"forestry","zoneNr":2,"productional":true},"foodworld-0":{"location":"foodworld","productional":false},"foodworld-1":{"location":"foodworld","zoneNr":1,"productional":true},"foodworld-2":{"location":"foodworld","zoneNr":2,"productional":true},"foodworld-3":{"location":"foodworld","zoneNr":3,"productional":true},"foodworld-4":{"location":"foodworld","zoneNr":4,"productional":true},"farmersmarket-0":{"location":"farmersmarket","productional":false},"farmersmarket-1":{"location":"farmersmarket","zoneNr":1,"productional":true},"farmersmarket-2":{"location":"farmersmarket","zoneNr":2,"productional":true},"farmersmarket-3":{"location":"farmersmarket","zoneNr":3,"productional":true},"farmersmarket-4":{"location":"farmersmarket","zoneNr":4,"productional":true},"farmersmarket-5":{"location":"farmersmarket","zoneNr":5,"productional":true},"farmersmarket-6":{"location":"farmersmarket","zoneNr":6,"productional":true}}; // task_new_zone
// All single-slot-zones themselves and all slots of multi-slot-zones
var ALL_SLOTS={};
// [farm, forestry, recipes, powerups]
// Growing duration in min
const PRODUCT_GROWTIME=[[,20,45,45,90,120,240,480,960,240,720,1440,2880,,,,,15,90,240,480,600,500,800,720,1000,780,2000,3000,950,4000,1000,720,1200,800,2000,880,3000,960,4000,4800,5500,6200,6800,7200,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,2880,,,,,,720,,,,,,,740,,,700,360,135,2160,1000,1440,1680,540,5100,840,1080,480,1320,1800,2520,1260,1620,720,3780,6400,7400,7800,640,180,180,90,90,200,200,100,130,150,80,80,120,120,120,375,300,240,300,480,220,360,3120,3240,1440,1920,1440,2520,840,600,,,210,130,260,190,160,195,250,90,150,300,420,270,540,220,180,315,390,250,230,345,600,245,880,360,510,440,240,,,,,,,,,,,,,240,240,180,210,350,60,180,250,290,380,180,325,120,210,480,480,480,480,480,480,1440,1440],{"1":600,"2":960,"3":2160,"4":480,"5":2750,"6":490,"7":1200,"8":2520,"41":300,"42":345,"43":360,"44":270,"45":300,"46":330,"47":420,"48":480,"49":510,"50":180,"51":210,"52":240,"53":480,"54":510,"55":540,"56":300,"57":375,"58":470,"59":360,"60":450,"61":420,"101":240,"102":700,"103":640,"104":360,"105":960,"106":90,"107":120,"108":1320,"109":570,"110":330,"111":160,"112":935,"113":120,"114":300,"115":180,"116":1040,"117":1920,"118":300,"119":1440,"120":2010,"121":480,"122":300,"123":840,"124":690,"125":480,"126":240,"127":255,"128":525,"129":375,"130":410,"131":480,"132":225,"133":120,"500":0,"501":0,"502":0,"511":0,"512":0}]; // task_new_plant task_new_product
// Points earned at cropping
const PRODUCT_POINTS=[[,3,17,10,44,64,128,267,600,750,950,1540,2350,,,,,1,7,24,42,63,52,88,92,3100,108,4500,5000,319,5400,179,133,229,157,405,733,2569,211,3611,4444,5220,6028,6769,1833,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,2500,,,,,,0,,,,,,,0,,0,0,179,31,2300,4900,490,340,240,1174,890,1240,580,1640,2320,3400,2000,2700,1250,7200,1475,6540,7955,0,36,36,18,18,40,36,20,26,30,16,16,24,24,24,3600,60,48,60,69,44,72,5400,7750,450,2600,8250,9725,6250,0,,,41,30,45,36,27,54,36,23,17,23,252,165,310,137,114,207,258,173,161,257,420,192,701,290,425,380,220,,,,,,,,,,,,,520,625,460,650,810,394,515,634,660,762,1343,1500,361,852,1245,1255,1275,1312,1362,1425,45000,45000],{"1":30,"2":48,"3":108,"4":24,"5":138,"6":0,"7":60,"8":126,"21":0,"22":0,"23":0,"24":0,"25":0,"41":150,"42":105,"43":108,"44":108,"45":60,"46":66,"47":294,"48":144,"49":153,"50":54,"51":42,"52":48,"53":48,"54":51,"55":54,"56":33,"57":38,"58":47,"59":39,"60":45,"61":42,"101":48,"102":140,"103":128,"104":74,"105":0,"106":18,"107":66,"108":0,"109":114,"110":70,"111":32,"112":187,"113":24,"114":60,"115":36,"116":208,"117":384,"118":660,"119":0,"120":0,"121":96,"122":60,"123":168,"124":138,"125":24,"126":48,"127":51,"128":105,"129":75,"130":82,"131":96,"132":45,"133":24,"500":0,"501":0,"502":0,"511":0,"512":0}]; // task_new_plant task_new_product

// Required quest to unlock product
const PRODUCT_QUEST=[{"117":["main",2,15],"118":["main",2,25],"119":["main",2,35],"120":["main",2,45],"121":["main",2,50],"123":["main",2,15],"124":["main",2,25],"125":["main",2,35]},{"1":["forestry",1,3],"2":["forestry",1,9],"3":["forestry",1,24],"4":["forestry",1,47],"5":["forestry",1,63],"7":["forestry",2,35],"8":["forestry",2,45],"21":["forestry",1,3],"22":["forestry",1,9],"23":["forestry",1,24],"24":["forestry",1,47],"25":["forestry",1,63],"26":["forestry",2,35],"27":["forestry",2,45],"41":["forestry",1,6],"42":["forestry",1,6],"43":["forestry",1,6],"44":["forestry",1,9],"45":["forestry",1,9],"46":["forestry",1,9],"47":["forestry",1,24],"48":["forestry",1,24],"49":["forestry",1,24],"50":["forestry",1,47],"51":["forestry",1,47],"52":["forestry",1,47],"53":["forestry",1,63],"54":["forestry",1,63],"55":["forestry",1,63],"56":["forestry",2,35],"57":["forestry",2,35],"58":["forestry",2,35],"59":["forestry",2,45],"60":["forestry",2,45],"61":["forestry",2,45],"101":["forestry",1,12],"102":["forestry",1,18],"103":["forestry",1,21],"104":["forestry",1,27],"105":["forestry",1,30],"106":["forestry",1,33],"107":["forestry",1,36],"108":["forestry",1,39],"109":["forestry",1,42],"110":["forestry",1,60],"111":["forestry",1,50],"112":["forestry",1,53],"115":["forestry",1,66],"116":["forestry",1,69],"117":["forestry",1,75],"118":["forestry",1,72],"119":["forestry",2,16],"120":["forestry",2,24],"121":["forestry",2,35],"122":["forestry",2,35],"123":["forestry",2,36],"124":["forestry",2,42],"125":["forestry",2,43],"126":["forestry",2,46],"127":["forestry",2,46],"128":["forestry",2,47],"129":["forestry",2,47],"130":["forestry",2,48],"131":["forestry",2,48],"132":["forestry",2,49]}];
// Required products to produce
const PRODUCT_REQUIRE=[{"25":[[0,9,30]],"27":[[0,10,12]],"28":[[0,11,8]],"30":[[0,12,5]],"111":[[0,110,5]],"116":[[0,2,1980]],"117":[[0,7,550]],"118":[[0,4,1020]],"119":[[0,38,650]],"120":[[0,42,110]],"121":[[0,43,100]],"122":[[0,112,130],[0,116,35]],"123":[[0,113,220],[0,117,35]],"124":[[0,114,345],[0,118,35]],"125":[[0,115,80],[0,119,35]],"130":[[0,17,400]],"131":[[0,21,150]],"132":[[0,20,100],[0,10,2]],"133":[[0,19,100],[0,10,2]],"134":[[0,17,400],[0,6,25]],"135":[[0,21,150],[0,6,25]],"136":[[0,2,120]],"137":[[0,1,200]],"138":[[0,1,200],[0,23,30]],"139":[[0,18,150],[0,22,30]],"140":[[0,21,150],[0,22,30]],"141":[[0,26,100],[0,144,3]],"142":[[0,26,100],[0,25,3]],"143":[[0,26,100],[0,25,3],[0,144,3]],"144":[[0,21,450]],"145":[[0,33,300],[0,12,2]],"146":[[0,35,200],[0,10,4],[0,12,2]],"147":[[0,37,60],[0,12,2]],"148":[[0,31,250],[0,26,150],[0,27,7]],"149":[[0,21,300],[0,43,10],[0,22,50],[0,121,4]],"150":[[0,38,60],[0,119,6],[0,17,50]],"152":[[0,151,5]],"155":[[0,152,5],[0,28,6]],"156":[[0,152,8],[0,28,5]],"157":[[0,152,2],[0,28,9]],"161":[[0,1,300],[0,17,150]],"162":[[0,1,250],[0,20,200]],"163":[[0,22,190],[0,26,120]],"164":[[0,1,150],[0,10,30]],"165":[[0,10,10],[0,12,5]],"166":[[0,10,10],[0,27,7]],"167":[[0,40,60],[0,111,10]],"168":[[0,10,10],[0,42,25]],"169":[[0,6,300],[0,9,15],[0,121,3]],"170":[[0,1,200],[0,43,20],[0,121,4]],"200":[[-1,1200],[0,171,24],[0,172,20],[0,173,12]],"201":[[-1,1400],[0,171,25],[0,172,18],[0,174,15]],"202":[[-1,1500],[0,172,22],[0,173,19],[0,174,16]],"203":[[-1,1460],[0,172,19],[0,173,16],[0,175,29]],"204":[[-1,1510],[0,171,7],[0,173,18],[0,174,8],[0,176,21]],"205":[[-1,1622],[0,171,14],[0,173,22],[0,176,10],[0,177,12]],"206":[[-1,1787],[0,174,16],[0,176,9],[0,177,10],[0,178,9]],"207":[[-1,1894],[0,173,15],[0,175,10],[0,177,11],[0,179,8]],"208":[[-1,1950],[0,173,12],[0,175,13],[0,178,15],[0,180,18]],"209":[[-1,2110],[0,171,12],[0,176,21],[0,179,7],[0,181,9]],"210":[[-1,2250],[0,171,12],[0,175,5],[0,179,34],[0,182,11]],"211":[[-1,2357],[0,172,9],[0,176,12],[0,181,22],[0,183,18]],"212":[[-1,2488],[0,171,13],[0,182,13],[0,183,16],[0,184,6]],"213":[[-1,2595],[0,171,3],[0,179,8],[0,185,7],[0,186,9],[0,187,7]],"214":[[0,0,2],[0,171,10],[0,172,14],[0,173,13],[0,174,18]],"215":[[0,0,2],[0,171,12],[0,172,22],[0,174,10],[0,175,19]],"216":[[0,0,2],[0,173,14],[0,175,8],[0,177,19],[0,178,16]],"217":[[0,0,3],[0,171,19],[0,177,5],[0,178,17],[0,180,13]],"218":[[0,0,3],[0,180,9],[0,181,8],[0,182,9],[0,183,9]],"219":[[0,0,3],[0,179,4],[0,182,1],[0,185,6],[0,186,15],[0,187,7]],"220":[[-1,1500],[0,171,70],[0,172,180],[0,173,80],[0,174,80],[0,188,1]],"221":[[-1,1500],[0,171,80],[0,172,50],[0,173,65],[0,174,140],[0,189,1]]},{"41":[[1,21,1]],"42":[[1,21,1]],"43":[[1,21,1]],"44":[[1,22,1]],"45":[[1,22,1]],"46":[[1,22,1]],"47":[[1,23,1]],"48":[[1,23,1]],"49":[[1,23,1]],"50":[[1,24,1]],"51":[[1,24,1]],"52":[[1,24,1]],"53":[[1,25,1]],"54":[[1,25,1]],"55":[[1,25,1]],"56":[[1,26,1]],"57":[[1,26,1]],"58":[[1,26,1]],"59":[[1,27,1]],"60":[[1,27,1]],"61":[[1,27,1]],"101":[[1,41,4]],"102":[[1,41,18],[1,42,2]],"103":[[1,44,11]],"104":[[1,42,1],[1,43,5]],"105":[[1,44,20],[1,45,50],[1,46,70]],"106":[[1,49,1]],"107":[[1,46,1]],"108":[[1,47,125],[1,48,65],[1,49,32]],"109":[[1,47,5]],"110":[[1,50,9],[1,51,4]],"111":[[1,52,4]],"112":[[1,50,12],[1,51,7],[1,52,6]],"113":[[1,42,1]],"114":[[1,41,1],[1,43,1]],"115":[[1,53,8],[1,55,2]],"116":[[1,53,120],[1,54,40],[1,55,40]],"117":[[1,53,80],[1,54,65],[1,55,125]],"118":[[1,53,6],[1,54,8]],"119":[[1,54,20],[1,55,25]],"120":[[1,54,35],[1,55,40]],"121":[[1,56,7],[1,57,4]],"122":[[1,58,9]],"123":[[1,57,4],[1,58,5]],"124":[[1,56,9],[1,57,4]],"125":[[1,58,3]],"126":[[1,61,5]],"127":[[1,60,3]],"128":[[1,60,6],[1,61,5]],"129":[[1,59,10],[1,60,8],[1,61,5]],"130":[[1,60,9],[1,61,8]],"131":[[1,59,6],[1,61,12]],"132":[[1,59,10],[1,60,8],[1,61,5]],"133":[[1,42,1]]}]; // task_new_product task_new_picnic_product
// Yielded amount of production
const PRODUCT_YIELD=[,{"1":1,"2":1,"3":1,"4":1,"5":1,"7":1,"8":1,"21":1,"22":1,"23":1,"24":1,"25":1,"26":1,"27":1,"41":5,"42":3,"43":3,"44":4,"45":2,"46":2,"47":7,"48":3,"49":3,"50":3,"51":2,"52":2,"53":8,"54":4,"55":4,"56":5,"57":3,"58":5,"59":6,"60":4,"61":3,"101":1,"102":1,"103":1,"104":1,"105":1,"106":1,"107":1,"108":1,"109":1,"110":1,"111":1,"112":1,"113":1,"114":1,"115":1,"116":1,"117":1,"118":1,"119":1,"120":1,"121":1,"122":1,"123":1,"124":1,"125":1,"126":1,"127":1,"128":1,"129":1,"130":1,"131":1,"132":1,"133":1}]; // task_new_product
    /*
    var new_data=PRODUCT_YIELD.clone();
    new_data[1][7]=;
    GM_log(implode(new_data));
    */
const ANIMAL_MOVE=[,,[false,0,0,255,10,10,505],[false,0,0,280,1,0,525],[false,0,0,280,1,25,500],,,,,,,[false,2,20,120,4,0,200]];
// Upgrade-data of buildings
// BUILDING_UPGRADES[zoneType][levelNr-1][needed level,buildcost,bonus,animalamount]
const BUILDING_UPGRADES={"1":[[1,2000,0.95,0],[15,21500,0.9,0],[21,76000,0.85,0],[27,192300,0.8,0],[33,"c20",0.8,0]],"2":[[2,2500,1,5],[7,15200,1,10],[12,32500,1,15],[23,134500,0.9,20],[29,350800,0.8,20]],"3":[[11,3400,1,2],[13,16300,1,3],[17,50200,1,4],[25,159600,0.9,5],[32,441000,0.8,6]],"4":[[14,6200,1,2],[18,33500,1,3],[20,76000,1,4],[28,210500,0.9,5],[34,482000,0.8,6]],"5":[[19,6800,1,1],[22,44800,1,2],[26,128200,1,3],[31,230600,0.9,4],[35,482000,0.8,4]],"7":[[16,5200,1,1],[19,33500,0.95,1],[25,106400,0.9,1],[30,230600,0.85,1],[33,441000,0.8,1]],"8":[[18,6800,1,1],[21,38000,0.95,1],[27,128200,0.9,1],[31,230600,0.85,1],[35,482000,0.8,1]],"9":[[27,8100,1,1],[30,53200,0.95,1],[33,140300,0.9,1],[36,264600,0.85,1],[38,597200,0.8,1]],"10":[[30,9700,1,1],[33,70200,0.95,1],[34,153700,0.9,1],[37,289200,0.85,1],[39,626300,0.8,1]],"11":[[16,10000,1,1],[20,85000,1,3],[24,200000,1,5],[28,"c22",0.9,6],[32,"c38",0.8,6]],"12":[[15,38000,1,2],[17,17200,1,3],[23,54600,1,4],[29,168800,0.9,5],[38,472400,0.8,6]],"13":[[31,16800,1,1],[32,86400,0.95,1],[34,174200,0.9,1],[36,362800,0.85,1],[38,796300,0.8,1]],"14":[[35,19400,1,1],[37,97100,0.95,1],[39,218400,0.9,1],[40,509800,0.85,1],[41,1388600,0.8,1]],"15":[[37,23000,1,1],[37,95300,1,2],[38,198500,1,3],[38,391700,0.9,4],[39,842200,0.8,5]],"16":[[38,97100,1,1],[39,209736,0.95,1],[40,467711,0.9,1],[41,1080413,0.85,1],[42,2538970,0.8,1]],"17":[[10,1000,1,1]],"18":[[10,5000,1,1]],"19":[[28,250000,1,1]],"fw1":[[11,7000,1,1],[11,24600,0.95,1],[11,64200,0.9,1],[11,114400,0.85,1],[11,186300,0.8,1]],"fw2":[[12,8400,1,1],[12,32500,0.95,1],[12,68900,0.9,1],[12,122400,0.85,1],[12,178600,0.8,1]],"fw3":[[12,11200,1,1],[12,43300,0.95,1],[12,91900,0.9,1],[12,163200,0.85,1],[12,238100,0.8,1]],"fl1":[[23,85000,0.95,36]],"fl2":[[23,75000,1,1]],"fl3":[[31,900000,1,1]],"fl6":[[31,900000,1,1]]};  // task_new_building
// produced thing -> production area
const PRODUCT2BUILDING=[[,1,1,1,1,1,1,1,1,2,3,4,5,,,,,1,1,1,1,1,1,1,1,7,1,8,9,1,10,1,1,1,1,1,1,1,1,1,1,1,1,1,1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,11,,,,,,1,,,,,,,1,,,1,1,1,12,8,1,1,1,1,13,13,13,13,13,13,14,14,14,14,1,1,1,1,"fw1","fw1","fw1","fw1","fw1","fw1","fw2","fw2","fw2","fw2","fw2","fw2","fw2","fw2",7,"fw1","fw1","fw1","fw2","fw2","fw2",15,9,1,1,16,16,16,1,,,"fw3","fw3","fw3","fw3","fw3","fw3","fw3","fw3","fw3","fw3","fl1","fl1","fl1","fl1","fl1","fl1","fl1","fl1","fl1","fl1","fl1","fl1","fl1","fl1","fl1","fl1","fl1","fl1","fl1",,,,,,,,,,,"fl2","fl2","fl2","fl2","fl2","fl2","fl2","fl2","fl2","fl2","fl2","fl2","fl2","fl2","fl2","fl2","fl2","fl2","fl2","fl2","fl2","fl2",,],{"1":"forest","2":"forest","3":"forest","4":"forest","5":"forest","7":"forest","8":"forest","21":"forest","22":"forest","23":"forest","24":"forest","25":"forest","26":"forest","27":"forest","41":"sawmill","42":"sawmill","43":"sawmill","44":"sawmill","45":"sawmill","46":"sawmill","47":"sawmill","48":"sawmill","49":"sawmill","50":"sawmill","51":"sawmill","52":"sawmill","53":"sawmill","54":"sawmill","55":"sawmill","56":"sawmill","57":"sawmill","58":"sawmill","59":"sawmill","60":"sawmill","61":"sawmill","101":"carpentry","102":"carpentry","103":"carpentry","104":"carpentry","105":"carpentry","106":"carpentry","107":"carpentry","108":"carpentry","109":"carpentry","110":"carpentry","111":"carpentry","112":"carpentry","113":"carpentry","114":"carpentry","115":"carpentry","116":"carpentry","117":"carpentry","118":"carpentry","119":"carpentry","120":"carpentry","121":"carpentry","122":"carpentry","123":"carpentry","124":"carpentry","125":"carpentry","126":"carpentry","127":"carpentry","128":"carpentry","129":"carpentry","130":"carpentry","131":"carpentry","132":"carpentry","133":"carpentry","300":"forest"},[],[,"windmill","windmill","windmill","windmill","windmill","windmill","windmill","windmill","windmill","windmill","windmill","windmill","windmill","windmill","windmill","windmill","windmill","windmill","windmill","windmill","windmill","windmill","windmill","windmill","windmill","windmill","windmill","windmill","windmill","windmill","windmill","windmill","windmill","windmill","windmill"]];// task_new_plant task_new_product
unsafeData.PRODUCT2BUILDING=PRODUCT2BUILDING.clone();
// produced thing <- production area
const BUILDING2PRODUCT=[,,[9],[10],[11],[12],,[25,144],[27,111],[28,152],[30],[91],[110],[116,117,118,119,120,121],[122,123,124,125],[151],[155,156,157]]; // task_new_product
unsafeData.BUILDING2PRODUCT=BUILDING2PRODUCT.clone();
// building -> -/field/stable/factory/foodworld
const BUILDINGTYPE={"0":0,"1":1,"2":2,"3":2,"4":2,"5":2,"6":0,"7":3,"8":3,"9":3,"10":3,"11":2,"12":2,"13":3,"14":3,"15":2,"16":3,"17":0,"18":0,"19":3,"fl1":1,"fl2":4,"fw1":4,"fw2":4,"fw3":4} // task_new_building
unsafeData.BUILDINGTYPE=BUILDINGTYPE.clone();
const BUILDING_SIZE={"1":120,"forest":25,"fl0":17,"fl1":36,"19":[11,9]};
unsafeData.BUILDING_SIZE=BUILDING_SIZE.clone();
// Needed input of a zone
// BUILDING_INPUT[buildTyp]{output}[alternatives]=[[prod1,amount1||reducing time1],...]
const BUILDING_INPUT=[,,{"9":[[[1,600]],[[2,1200]]]},{"10":[[[3,900]],[[4,1800]]]},{"11":[[[5,2400]],[[6,4800]]]},{"12":[[[7,4800]],[[8,9600]]]},,{"25":[[[9,30]]],"144":[[[21,450]]]},{"27":[[[10,12]]],"111":[[[110,5]]]},{"28":[[[11,8]]],"152":[[[151,5]]]},{"30":[[[12,5]]]},{"91":[[[92,14400]],[[93,28800]]]},{"110":[[[108,3600]],[[109,1800]]]},{"116":[[[2,1980]]],"117":[[[7,550]]],"118":[[[4,1020]]],"119":[[[38,650]]],"120":[[[42,110]]],"121":[[[43,100]]]},{"122":[[[112,130],[116,35]]],"123":[[[113,220],[117,35]]],"124":[[[114,345],[118,35]]],"125":[[[115,80],[119,35]]]},{"151":[[[153,1560]],[[154,3120]]]},{"155":[[[152,5],[28,6]]],"156":[[[152,8],[28,5]]],"157":[[[152,2],[28,9]]]}]; // task_new_product
unsafeData.BUILDING_INPUT=BUILDING_INPUT.clone();
// Zone  2 -> "9":[[[0,1,600]],[[0,2,1200]]]
// Zone  3 -> "10":[[[0,3,900]],[[0,4,1800]]]
// Zone  4 -> "11":[[[0,5,2400]],[[0,6,4800]]]
// Zone  5 -> "12":[[[0,7,4800]],[[0,8,9600]]]
// Zone 11 -> "91":[[[0,92,14400]],[[0,93,28800]]]
// Zone 12 -> "110":[[[0,108,3600]],[[0,109,1800]]]
// Zone 15 -> "151":[[[0,153,1560]],[[0,154,3120]]]
// price of an animal. formula: cost=Math.round(ANIMALCOST[zone][0]+nr*ANIMALCOST[zone][1])
const ANIMALCOST=[,,[309,1000/19],[419,320],[529,320],[1599,2600/3],,,,,,[999,1000],[789,320],,,[2400,1200],,,]; // task_new_building
// sizes of Farmis [width,height,left,top] in px , taken from setFarmis()
const FARMISIZE=[,[40,60,-1,-5],[30,40,0,0],[30,40,2,0],[33,45,2,0],[33,45,4,2],[40,65,2,-11],[40,65,-2,-20],[45,60,-2,-14]];
// QUESTS[questType][campaign][nr]=[[[type1,id1,amount1],...],waitdays,points,more]
// more: Array of items:
// [0,money]
// [1,type of gained product,id of gained product,amount]
// [2,number of accessed rack]
// [3,number of accessed farm]
// [4,type of product,id of product,minutes this product grows faster]]
// [5,number of additional farmis ('<img src=GFX+"adbonus.gif" style="border:0;height:15px;">')]
// [6,Erhoehung der Lagerkapazitaet Staemme um x]
// [7,Giessbonus x%]
// [8,id of accessed zone]
// [9,type of accessed product,id of accessed product]
// [10] access to watering of forest
// [11,number of additional farmi slots]
// [12,id of gained farmhouse item]
// [13,id of gained gift]
// task_new_quest:
const QUESTS = {"main":{"1":[,[[[0,17,43],[0,9,1]],1,142,[[0,54]]],[[[0,1,173],[0,9,2]],1,348,[[0,145]]],[[[0,18,192],[0,17,288]],1,255,[[0,73]]],[[[0,18,672],[0,9,10]],1,1883,[[0,608]]],[[[0,17,922],[0,9,19]],1,2304,[[0,890]]],[[[0,20,360],[0,18,960]],1,3300],[[[0,19,540],[0,20,720]],1,6413],[[[0,2,240],[0,21,245]],1,2895],[[[0,20,1440],[0,9,24]],1,11700,[[1,0,47,1]]],[[[0,21,1152],[0,9,48]],1,16200],[[[0,9,72],[0,22,1037]],1,16202],[[[0,20,3456],[0,10,27]],1,25476],[[[0,18,8064],[0,10,48]],1,15660],[[[0,23,3110],[0,9,144]],1,57240],[[[0,10,96],[0,9,180]],1,33930,[[1,0,59,1]]],[[[0,9,240],[0,6,1836]],1,62190],[[[0,10,384],[0,9,144]],1,70920],[[[0,10,192],[0,23,6739]],1,116280,[[2,2]]],[[[0,22,7518],[0,9,216]],1,108956],[[[0,11,150],[[0,10,272],[0,110,112]]],1,34650],[[[0,7,1350],[0,12,50]],1,78375,[[1,0,63,1]]],[[[0,23,15552],[0,9,1008]],1,318600],[[[0,29,6552],[0,25,130]],1,373645,[[3,2]]],[[[0,1,51840],[[0,27,55],[0,111,51]]],1,60579],[[[0,11,280],[0,12,210]],1,138705],[[[[0,10,672],[0,110,276]],[0,12,210]],1,169785],[[[0,1,75600],[0,2,25000]],1,42131,[[1,0,90,1]]],[[[0,11,480],[0,12,272]],1,206760],[[[0,9,2688],[[0,10,1024],[0,110,420]]],1,448320],[[[0,12,320],[0,11,560]],1,242160],[[[0,29,14742],[[0,27,194],[0,111,180]]],1,836328,[[2,3]]],[[[0,20,77760],[0,12,383]],1,620831,[[1,0,78,1]]],[[[0,12,540],[0,32,14600]],1,449550],[[[0,32,50400],[0,25,432]],1,1208880],[[[[0,10,1760],[0,110,722]],[0,11,1000]],1,481800,[[3,3]]],[[[0,9,4800],[0,12,595]],1,749738],[[[0,26,46550],[[0,27,216],[0,111,201]]],1,933756,[[1,0,77,1]]],[[[0,1,259200],[0,30,216]],1,252960],[[[0,23,51840],[0,28,230]],1,856800],[[[0,9,5280],[[0,10,1795],[0,110,736]]],1,849816],[[[0,25,475],[0,30,238]],1,1665576,[[1,0,80,1]]],[[[0,34,64152],[0,28,253]],1,1704780],[[[0,11,1320],[0,12,880]],1,615120],[[[[0,27,238],[0,111,221]],[0,24,30294]],1,576923,[[1,0,76,1]]],[[[[0,10,2304],[0,110,945]],[0,30,259]],1,538272],[[[0,9,5760],[[0,10,2304],[0,110,945]]],1,976320],[[[0,37,13800],[0,25,518]],1,5559806,[[1,0,61,1]]],[[[0,9,5760],[[0,10,1958],[0,110,803]]],1,927072],[[[0,28,276],[0,30,259]],1,417312],[[[0,12,1040],[0,30,281]],1,376253,[[1,0,52,1]]],[[[0,20,72000],[0,12,800]],1,732000,[[4,0,23,15]]],[[[0,12,4000],[[0,10,1920],[0,110,787]]],1,1683600],[[[0,23,64800],[0,9,4800]],1,1395000],[[[0,25,432],[0,28,230]],1,373680,[[4,0,24,15]]],[[[0,24,72000],[[0,27,216],[0,111,201]]],1,1135800],[[[0,7,18000],[[0,10,1920],[0,110,787]]],1,1083600],[[[[0,27,216],[0,111,201]],[0,11,1200]],1,423000,[[4,0,31,15]]],[[[0,31,103700],[0,30,216]],1,2965498],[[[0,11,1200],[0,25,432]],1,478080,[[4,0,21,10]]],[[[0,21,57600],[[0,10,1920],[0,110,787]]],1,813600],[[[0,12,800],[[0,27,216],[0,111,201]]],1,427800,[[4,0,29,15]]],[[[0,29,27300],[0,25,432]],1,1506635],[[[0,4,48000],[0,9,4800]],1,855000],[[[0,28,230],[[0,27,216],[0,111,201]]],1,318600,[[4,0,33,15]]],[[[0,33,43200],[0,25,432]],1,1685880,[[5,1]]],[[[0,9,4800],[0,12,800]],1,822000,[[4,0,22,10]]],[[[0,8,18000],[0,28,230]],1,1792800],[[[[0,10,1920],[0,110,787]],[0,11,1200]],1,550800,[[4,0,34,15]]],[[[0,34,64800],[0,30,216]],1,1704960],[[[0,6,10800],[0,28,230]],1,207000],[[[0,11,1200],[[0,10,1920],[0,110,787]]],1,550800,[[4,0,35,20]]],[[[0,35,12950],[[0,27,216],[0,111,201]]],1,932692],[[[0,25,432],[0,11,1200]],1,478080],[[[0,32,72000],[0,12,800]],1,1722000,[[4,0,36,15]]],[[[0,36,24500],[0,9,4800]],1,3235000],[[[[0,27,216],[0,111,201]],[0,30,216]],1,320760,[[4,0,7,10]]],[[[0,26,66500],[0,28,230]],1,1298451],[[[0,12,800],[[0,10,1920],[0,110,787]]],1,555600,[[4,0,37,30]]],[[[0,37,3833],[0,9,4800]],1,2017431],[[[0,28,230],[0,25,432]],1,373680],[[[0,33,43200],[0,12,800]],1,1767000,[[4,0,38,15]]],[[[0,38,108000],[0,30,216]],1,3594960],[[[0,9,4800],[0,28,230]],1,712800,[[4,0,19,5]]],[[[0,5,72000],[[0,10,1920],[0,110,787]]],1,963600],[[[0,30,216],[0,9,4800]],1,714960,[[4,0,39,30]]],[[[0,39,2867],[0,12,800]],1,1834778],[[[[0,10,1920],[0,110,787]],[0,25,432]],1,474480],[[[0,32,72000],[[0,27,216],[0,111,201]]],1,1585800,[[4,0,40,30]]],[[[0,40,2250],[0,12,800]],1,1782000],[[[0,25,432],[0,11,1200]],1,478080,[[4,0,20,10]]],[[[0,3,64000],[0,30,216]],1,374960],[[[[0,27,216],[0,111,201]],[0,11,1200]],1,423000,[[4,0,41,30]]],[[[0,41,1975],[[0,10,1920],[0,110,787]]],1,1819998],[[[0,11,1200],[[0,27,216],[0,111,201]]],1,423000,[[4,0,8,15]]],[[[0,24,72000],[[0,10,1280],[0,110,787]]],1,1172400,[[5,1]]],[[[0,12,800],[0,9,4800]],1,822000,[[4,0,26,15]]],[[[0,36,24500],[0,28,230]],1,2867800],[[[0,31,103700],[[0,10,1920],[0,110,787]]],1,3064138,[[4,0,42,30]]],[[[0,28,230],[0,25,432]],1,373680],[[[0,42,1680],[0,30,216]],1,1693960,[[4,0,33,15]]],[[[0,4,80000],[0,30,210]],2,722800],[[[0,6,48000],[0,12,300]],2,854400],[[[0,1,800000],[0,25,320]],2,998400,[[4,0,32,10]]],[[[0,35,64000],[0,32,12000]],2,1629600],[[[0,26,108000],[0,11,540]],2,1452600],[[[0,39,12000],[0,9,5600]],2,2160000,[[4,0,43,30]]],[[[0,43,10000],[[0,27,600],[0,111,558]]],2,2556000],[[[0,24,184000],[0,25,480]],2,2248000],[[[0,9,10200],[[0,10,24000],[0,110,9840]]],2,2205600],[[[0,23,108000],[0,91,250]],2,1359600,[[12,105]]],[[[0,34,36936],[0,37,10580]],2,1959726],[[[0,29,78624],[0,26,5200]],2,2164176],[[[0,44,2016],[0,28,1600]],2,2059245],[[[[0,10,12000],[0,110,4920]],[0,12,1200]],2,1536000],[[[0,30,840]],2,906800,[[12,123]]],[[[0,40,3240],[0,36,9800]],2,1265312],[[[0,91,750],[0,31,72590]],2,1233972],[[[0,26,113050],[[0,27,600],[0,111,558]]],2,1874430],[[[0,38,7020],[0,42,2352]],2,2134942],[[[0,41,9480],[0,9,28800]],2,1886172,[[5,1]]],[[[0,23,174960],[0,22,98515]],2,2267541],[[[0,8,5040],[0,7,3780]],2,2022804],[[[0,32,27000],[[0,10,24000],[0,110,9840]]],2,2357400],[[[0,39,2580],[0,37,7935]],2,1525641,[[1,0,99,1]]],[[[0,33,51840],[0,35,20720]],2,2464720],[[[0,43,5000],[0,21,146880]],2,2139910],[[[0,31,60664],[0,26,100520]],2,1945541],[[[0,20,100800],[0,9,15360]],2,1216320,[[4,0,44,20]]],[[[[0,10,10080],[0,110,4132]],[0,11,4500]],2,1571400],[[[0,7,18900],[0,38,5400]],2,2239480],[[[0,40,3500],[0,35,12000]],2,1168200],[[[0,91,1000]],2,600000,[[12,137]]],[[[0,44,4400],[0,26,22400]],2,1284560],[[[0,3,280000],[0,31,40000]],2,1328000],[[[0,12,1200],[0,39,3900]],2,1228860],[[[0,7,9800],[0,2,240000]],2,1003320],[[[0,26,60000],[0,1,275000]],2,1031000],[[[0,11,6400]],2,1088000],[[[0,6,14444],[0,33,34000]],2,1158911],[[[[0,27,625],[0,111,581]]],2,1078125],[[[0,38,8600],[0,41,2900]],2,1056220],[[[0,43,4050],[0,7,5250]],2,1133280],[[[0,9,16200]],2,453600,[[5,1]]],[[[0,25,900],[[0,10,5400],[0,110,2214]]],2,990000],[[[0,37,8600]],2,1016520],[[[0,28,300],[[0,10,7500],[0,110,3075]]],2,1050000],[[[0,30,400],[0,42,3600]],2,1096880],[[[0,29,51000],[0,9,3600]],2,1069800],[[[0,91,175],[0,8,18200]],2,1087560],[[[0,36,10300],[0,41,3800]],2,1312700],[[[0,24,90000],[[0,10,800],[0,110,328]]],2,1028000],[[[0,22,95500],[0,1,300000]],2,930300],[[[0,35,13000],[0,32,33000]],2,1176800],[[[0,17,155000],[0,21,99999]],2,1049993],[[[0,38,13000],[[0,27,250],[0,111,232]]],2,1104650],[[[0,37,4444],[0,39,3333]],2,1083225],[[[0,2,122000],[0,21,122000]],2,1146800],[[[0,20,112000],[[0,10,2800],[0,110,1148]]],2,1097600],[[[0,9,1111],[0,26,66000]],2,1142108],[[[0,11,2320],[0,23,72000]],2,1200800],[[[0,19,116000],[0,25,900]],2,976200,[[5,1]]],[[[0,5,220000],[0,12,720]],2,1049600],[[[0,18,240000],[0,6,50000]],2,1028000],[[[0,41,4400],[0,1,150000]],2,1076640],[[[0,40,3250],[0,30,500]],2,1069300],[[[0,29,45000],[0,20,25000]],2,1050000],[[[0,91,840],[0,1,510000]],2,1014000],[[[0,34,45000],[0,12,680]],2,1190400],[[[0,31,425000],[0,43,2800]],2,1048680],[[[[0,10,7500],[0,110,3075]],[0,3,140000]],2,1048000,[[7,5]]]]
                       ,"2":[,[[[0,8,6500],[0,12,300]],,495000],[[[0,34,18600],[0,111,75]],,496298],[[[0,33,5650],[0,30,315]],,498270],[[[0,26,15600],[0,9,11200]],,506380],[[[0,37,2150],[0,12,530]],,508530],[[[0,18,175000],[0,91,505]],,511250],[[[0,108,6350],[0,7,5400]],,505010],[[[0,35,6530],[0,110,950]],,507946],[[[0,24,19150],[0,27,412]],,511190],[[[0,23,33000],[0,25,480]],,518500,[[3,4]]],[[[0,28,366],[0,46,100]],,516000],[[[0,116,460],[0,11,1400]],,523880],[[[0,21,42000],[0,9,8000]],,534800],[[[0,32,15420],[0,10,3630]],,540204],[[[0,7,5000],[0,30,265]],,550550,[[9,0,117],[9,0,123]]],[[[0,116,480],[0,91,777]],,551640],[[[0,19,84000],[0,110,1255]],,554475],[[[0,117,917],[0,18,277000]],,559816],[[[0,12,625],[0,109,42000]],,560400],[[[0,108,12300],[0,116,670]],,559600],[[[0,5,50500],[0,26,32000]],,564800],[[[0,117,490],[0,9,16000]],,569520],[[[0,29,16600],[0,31,24000]],,574600],[[[0,33,18200],[0,11,1800]],,589560],[[[0,4,40450],[0,116,1560]],,594810,[[9,0,118],[9,0,124]]],[[[0,3,110000],[0,12,515]],,599200],[[[0,17,75000],[0,10,6800]],,605000],[[[0,91,700],[0,34,9900]],,610080],[[[0,2,155000],[0,28,305]],,615000],[[[0,37,3800],[0,118,1450]],,617360,[[8,"20"]]],[[[0,1,172350],[0,111,558]],,622350],[[[0,117,1090],[0,36,5800]],,625320],[[[0,12,900],[0,25,310]],,624400],[[[0,31,38380],[0,118,1800]],,623304],[[[0,38,9200],[0,116,840]],,623304,[[9,0,119],[9,0,125]]],[[[0,65,10],[0,27,680]],,623333],[[[0,36,7500],[0,9,8000]],,627000],[[[0,6,13150],[0,110,2214]],,626620],[[[0,37,2415],[0,11,2000]],,625453],[[[0,119,735],[0,30,360]],,626280],[[[0,21,19000],[0,10,6120]],,630200],[[[0,33,14400],[0,35,4750]],,634970],[[[0,38,8200],[0,111,116]],,640341],[[[0,73,30],[0,28,600]],,650000],[[[0,42,2980],[0,117,430]],,660324,[[9,0,120]]],[[[0,39,2250],[0,12,666]],,696030],[[[0,40,2400],[0,30,286]],,700580],[[[0,41,2200],[0,118,2275]],,702800],[[[0,20,36000],[0,23,38000]],,706400],[[[0,43,1850],[0,120,690]],,709770,[[9,0,121]]],[[[0,108,14000],[0,8,13200]],,715040],[[[0,40,1950],[0,9,14200]],,719600],[[[0,39,1900],[0,116,1540]],,729920],[[[0,27,268],[0,43,1300]],,735580],[[[0,42,2300],[0,109,34850]],,740010],[[[0,112,3300],[0,121,500]],,748000],[[[0,41,2500],[0,111,138]],,754830],[[[0,119,1000],[0,29,22750]],,760250],[[[0,112,3300],[0,22,52300]],,766260],[[[0,32,24799],[0,9,13333]],,766260,[[8,"21"]]],[[[0,113,9100],[0,27,400]],,750000],[[[0,44,1142],[0,144,790]],,755000],[[[0,154,1695],[0,111,210]],,760000],[[[0,24,39500],[0,118,2350]],,765000],[[[0,153,6250],[0,26,22650]],,765000],[[[0,23,39500],[0,28,385]],,770000],[[[0,6,34500],[0,122,37]],,770000],[[[0,32,13400],[0,10,3900]],,775000],[[[0,39,990],[0,38,8400]],,775000],[[[0,144,1150],[0,123,46]],,780000],[[[0,9,7900],[0,151,85]],,780000],[[[0,5,56200],[0,4,41500]],,785000],[[[0,64,15],[0,152,80]],,785000],[[[0,31,28500],[0,91,550]],,790000],[[[0,20,59000],[0,30,720]],,790000,[[8,"22"]]],[[[0,114,15000],[0,29,25000]],,795000],[[[0,120,400],[0,11,4500]],,795000],[[[0,2,150000],[0,6,45000]],,800000],[[[0,40,9000],[0,25,200]],,800000],[[[0,7,28000],[0,30,225]],,805000],[[[0,32,65000],[0,1,190000]],,805000],[[[0,109,125000],[0,108,65000]],,810000],[[[0,22,92000],[0,27,450]],,810000],[[[0,124,1125],[0,21,85000]],,815000],[[[0,36,9500],[0,112,6600]],,815000],[[[0,116,840],[0,24,63000]],,820000],[[[0,26,63000],[0,117,700]],,820000],[[[0,152,120],[0,44,15000]],,825000],[[[0,144,450],[0,113,30000]],,825000],[[[0,125,650],[0,151,550]],,830000,[[8,"23"]]],[[[0,115,1680],[0,10,4200]],,835000],[[[0,154,7500],[0,118,3300]],,840000],[[[0,153,18500],[0,31,22000]],,845000],[[[0,42,2250],[0,110,1450]],,850000],[[[0,43,1500],[0,1,150000]],,855000],[[[0,41,2200],[0,12,1100]],,860000],[[[0,157,550],[0,120,600]],,865000],[[[0,33,14000],[0,35,16500]],,870000],[[[0,21,29500],[0,112,11500]],,875000],[[[0,10,3500],[0,114,18200]],,880000],[[[0,22,32000],[0,123,1250]],,885000],[[[0,30,650],[0,155,350]],,890000],[[[0,91,1050],[0,7,14000]],,895000],[[[0,29,18400],[0,26,21200]],,900000],[[[0,28,650],[0,152,250]],,905000],[[[0,157,320],[0,156,410]],,910000],[[[0,121,1000],[0,9,15000]],,915000],[[[0,44,62000],[0,144,450]],,920000],[[[0,8,18000],[0,12,1350]],,925000],[[[0,113,18000],[0,27,350]],,930000],[[[0,21,42500],[0,122,1850]],,935000],[[[0,22,95000],[0,120,950]],,940000],[[[0,40,5500],[0,41,6800]],,945000],[[[0,116,2500],[0,38,18600]],,950000],[[[0,111,650],[0,119,750]],,955000],[[[0,36,18500],[0,37,12000]],,960000],[[[0,6,32500],[0,117,1450]],,965000],[[[0,34,27500],[0,32,32100]],,970000],[[[0,151,600],[0,11,1200]],,980000],[[[0,125,1000],[0,124,1600]],,985000,[[8,"24"]]]]
                       }
               ,"forestry":{"1":[,[[[0,4,3300],[0,19,4500],[0,24,1400]],,51520],[[[0,5,2600],[0,17,8000],[0,91,50]],,50360],[[[0,6,1250],[0,21,6600],[0,18,7300]],,0,[[1,1,1,5],[8,"forest"],[9,1,1],[9,1,21]]],[[[0,22,1400],[0,7,750]],,48630],[[[0,25,64],[0,3,3200],[1,21,8]],,50800],[[[0,8,650],[0,27,85],[0,4,4800],[0,91,25]],,0,[[8,"sawmill"],[9,1,41],[9,1,42],[9,1,43]]],[[[0,10,420],[0,19,1600]],,39360],[[[0,2,6000],[0,22,2100],[0,21,1800]],,38980],[[[0,24,1800],[1,21,12],[1,41,10]],,0,[[1,1,2,5],[9,1,2],[9,1,22],[9,1,44],[9,1,45],[9,1,46]]],[[[0,3,3200],[0,5,3150],[0,20,1900]],,36200],[[[0,27,40],[0,18,7700]],,39240],[[[0,91,60],[1,22,30],[1,44,12]],,0,[[8,"carpentry"],[9,1,101]]],[[[0,8,300],[0,6,2000]],,39600],[[[0,17,16000],[1,22,30],[1,42,10]],,34520],[[[0,11,90],[1,101,6],[1,22,18]],,0,[[10]]],[[[0,22,800],[0,7,430],[0,2,2200]],,32642],[[[0,10,380]],,30400],[[[0,9,460],[1,41,20]],,0,[[9,1,102]]],[[[0,19,2600],[0,3,3000],[0,18,5400],[0,4,1200]],,31740],[[[0,91,15],[0,26,1700]],,31420],[[[0,25,35],[0,5,2800],[1,102,4]],,0,[[9,1,103]]],[[[0,24,1900],[0,6,1400]],,31060],[[[0,20,1350],[0,23,1250],[0,1,4900]],,30230],[[[0,12,75],[0,21,2500],[1,45,15]],,0,[[1,1,3,5],[9,1,3],[9,1,23],[9,1,47],[9,1,48],[9,1,49]]],[[[0,8,310],[0,9,240]],,31520],[[[0,7,130],[0,6,400],[0,27,30]],,32562],[[[0,3,5400],[1,23,18],[1,103,3]],,0,[[9,1,104]]],[[[0,11,185]],,31450],[[[0,22,1900],[0,91,22],[0,2,2600]],,30940],[[[0,10,110],[1,41,32],[1,101,24]],,0,[[9,1,105]]],[[[0,25,55],[1,46,27]],,35025],[[[0,20,2300],[0,23,1350],[1,43,36]],,34485],[[[0,5,2000],[1,104,12],[1,47,72]],,0,[[9,1,106]]],[[[0,26,2100],[0,8,150]],,36600],[[[0,3,2200],[0,18,4500],[0,19,3000],[0,4,1400],[0,17,2800]],,37520],[[[0,9,600],[1,106,20]],,0,[[9,1,107]]],[[[0,7,700]],,37380],[[[0,29,1400],[0,12,40]],,42000],[[[0,1,45000],[1,107,52],[1,48,18]],,0,[[9,1,108]]],[[[0,5,3000],[0,11,240]],,44400],[[[0,3,5800],[0,9,380],[0,21,2400]],,46970],[[[0,6,1600],[1,102,12],[1,23,48]],,0,[[9,1,109]]],[[[0,25,75]],,48500],[[[0,29,1200],[0,8,1300],[0,17,20000],[0,2,5600],[1,49,24]],,50340,[[5,1]]],[[[0,20,5400],[0,10,100],[1,42,35]],,52325],[[[0,26,450],[0,25,45],[0,9,850]],,52510],[[[0,5,18000],[0,4,3600],[1,109,50]],,0,[[1,1,4,5],[9,1,4],[9,1,24],[9,1,50],[9,1,51],[9,1,52]]],[[[0,11,100],[0,3,9200],[1,45,30],[1,103,18]],,52207],[[[0,91,50],[0,22,3300],[0,18,4000],[1,46,45]],,52953],[[[1,101,40],[1,21,80],[1,48,30]],,0,[[9,1,111]]],[[[0,21,3000],[0,23,1600],[0,6,800]],,51960],[[[0,25,50],[0,24,2200],[1,43,60]],,53008],[[[1,104,70],[1,107,55],[1,24,60]],,0,[[9,1,112]]],[[[0,8,500],[0,7,450]],,50730],[[[0,91,35],[0,2,3500],[0,29,1200],[1,23,30]],,52432],[[[0,11,290],[1,52,30]],,50496,[[5,1]]],[[[0,10,360],[0,9,720],[1,106,100]],,52200],[[[0,27,75],[1,112,15]],,50049,[[11,1]]],[[[0,23,2000],[0,12,60],[1,42,50],[1,102,20]],,53630],[[[1,50,65],[1,47,30],[1,111,50]],,0,[[9,1,110]]],[[[0,109,3500],[0,24,2500],[1,48,30]],,50792],[[[0,11,275],[1,22,60]],,51934],[[[0,10,250],[0,12,100],[1,41,50],[1,23,33]],,0,[[1,1,5,5],[9,1,5],[9,1,25],[9,1,53],[9,1,54],[9,1,55]]],[[[0,9,250],[0,23,4000]],,51800],[[[0,25,90],[0,18,6400],[0,21,1000],[1,44,50]],,55282],[[[0,108,7500],[1,53,15],[1,112,5]],,0,[[9,1,115]]],[[[0,6,500],[0,22,6250]],,48650],[[[0,3,9700],[0,17,30000],[0,5,2200],[1,25,36]],,51590],[[[0,91,50],[1,115,26],[1,101,62]],,0,[[9,1,116]]],[[[0,112,2900],[0,12,80],[1,22,32]],,54505],[[[0,108,3700],[0,11,200]],,51020],[[[0,27,125],[1,115,22]],,0,[[9,1,118]]],[[[0,29,2700],[1,104,27]],,54896],[[[0,10,380],[0,19,5100],[1,50,65],[1,109,8]],,52508],[[[0,91,40],[1,118,10],[1,50,80],[1,107,65]],,0,[[9,1,117],[7,5]]]]
                        ,"2":[,[[[0,111,45],[0,9,380]],,48150],[[[1,21,400]],,,[[6,100]]],[[[0,12,100],[0,5,315]],,49140],[[[1,24,350]],,,[[6,100]]],[[[0,26,3200],[0,9,220],[1,106,30]],,47452],[[[1,22,450]],,,[[6,100]]],[[[0,11,150],[1,111,35]],,51945],[[[1,21,600],[1,41,80]],,,[[6,100]]],[[[0,8,555],[1,44,40],[1,45,30]],,46164],[[[0,91,55],[1,23,550]],,,[[6,100]]],[[[1,25,150]],,103843],[[[1,102,22]],,276206],[[[1,115,45]],,145202],[[[1,21,650],[1,22,100]],,,[[6,100]]],[[[1,110,15]],,124977],[[[1,53,120],[1,55,50],[1,54,50]],,,[[9,1,119]]],[[[0,7,5200],[0,6,1200],[0,24,3500]],,103941],[[[1,21,350],[1,22,300]],,,[[6,100]]],[[[0,10,240],[0,27,85],[0,26,2500]],,135945],[[[1,1,125],[1,2,100],[1,3,90],[1,4,70],[1,5,50]],,138279],[[[1,109,30]],,168612],[[[0,144,40],[0,110,100],[0,12,50]],,,[[6,100]]],[[[1,103,20]],,179495],[[[1,53,210],[1,55,160]],,,[[9,1,120]]],[[[1,41,100],[1,48,75],[1,52,50]],,156645],[[[1,25,190]],,,[[6,100]]],[[[0,11,400]],,125956],[[[1,24,220],[1,47,50],[1,43,85]],,114596],[[[1,118,20]],,221544],[[[1,1,250],[1,2,200],[1,3,180],[1,4,140],[1,5,100]],,,[[6,100]]],[[[0,110,100],[0,12,80],[1,41,45],[1,53,40],[1,52,20]],,237672],[[[1,41,100],[1,21,80],[1,43,125],[1,42,75]],,257504],[[[1,46,70],[1,49,50],[1,23,60],[1,25,80]],,273176],[[[0,10,60],[1,118,5],[0,27,100],[0,26,8000]],,288144],[[[1,5,200],[1,4,200],[1,3,200]],,,[[1,1,7,5],[9,1,7],[9,1,26],[9,1,56],[9,1,57],[9,1,58],[9,1,121],[9,1,122],[13,309]]],[[[1,121,20],[1,122,5]],,288473,[[9,1,123]]],[[[1,123,15],[1,56,120]],,313426],[[[0,11,500],[1,111,40],[0,5,8000],[0,1,15000]],, 346934],[[[1,24,200],[1,23,200],[1,53,100],[1,58,50]],,305630],[[[1,54,100],[1,42,150],[1,51,250]],,512943],[[[0,12,200],[1,110,20],[0,6,3000],[0,7,2500]],,382357],[[[1,109,15],[1,107,15],[1,106,4],[1,102,8]],,311131,[[9,1,124]]],[[[1,124,25]],,401729,[[9,1,125]]],[[[1,125,80]],,298927],[[[1,7,250],[1,5,200],[1,1,500]],,,[[1,1,8,5],[9,1,8],[9,1,27],[9,1,59],[9,1,60],[9,1,61],[13,310]]],[[[0,27,80],[0,26,3000],[1,27,80],[1,122,5],[1,121,10]],,337285,[[9,1,126],[9,1,127]]],[[[1,126,20],[1,127,20]],,322536,[[9,1,128],[9,1,129]]],[[[1,128,10],[1,129,5]],,377008,[[9,1,130],[9,1,131]]],[[[1,130,10],[1,131,5]],,390178,[[9,1,132]]],[[[1,132,35],[1,41,400]],,807960]]
                        }
               ,"foodworld":{"1":[,[[[0,2,17000]],2,57800],[[[0,21,2000],[0,23,2500],[0,22,2750]],2,97800],[[[0,3,30000]],2,60000],[[[0,1,10000],[0,20,2500],[0,10,50]],2,36500],[[[0,22,6000]],2,62400],[[[0,4,8000]],2,70400],[[[0,131,40],[0,137,21],[0,140,23]],2,65400],[[[0,24,3000],[0,10,80]],2,70400],[[[0,1,6000],[0,2,4000],[0,5,2500]],2,65000],[[[0,19,2000],[0,109,3500],[0,2,7000]],2,55100],[[[0,11,50],[0,22,2500]],2,41400],[[[0,10,70],[0,110,45],[0,9,100]],2,49000],[[[0,6,2500],[0,21,2000],[0,17,9000]],2,91000],[[[0,20,4500],[0,21,3500],[0,10,30]],2,87600],[[[0,108,1500],[0,109,4000]],2,78500],[[[0,23,2000],[0,26,600],[0,9,150]],2,70660],[[[0,6,2200],[0,22,5000]],2,108320],[[[0,21,4000],[0,26,3500]],2,126000],[[[0,24,1200],[0,10,85],[0,17,20000]],2,42230],[[[0,1,20000],[0,12,35],[0,20,7500]],2,91450,[[8,"foodworld-3"]]]]
                            }
               };
unsafeData.QUESTS=QUESTS.clone();
const INIT_questDataItem = {"nr":0,"time":0,"calcTo":0,"state":0,"given":{}};
const INIT_questData = {"main":{"1":INIT_questDataItem.clone(),"2":INIT_questDataItem.clone()},"forestry":{"1":INIT_questDataItem.clone(),"2":INIT_questDataItem.clone()},"foodworld":{"1":INIT_questDataItem.clone()}};
// state: 0:not available, 1:not activated, 2:active
/*
// Generate PRODUCT_QUEST
var new_PRODUCT_QUEST=[];
for(var type in QUESTS){
    if(!QUESTS.hasOwnProperty(type)){ continue; }
    for(var campaign in QUESTS[type]){
        if(!QUESTS[type].hasOwnProperty(campaign)){ continue; }
        for(var nr=1;nr<QUESTS[type][campaign].length;nr++){
            if(QUESTS[type][campaign][nr][3]){
                for(var i=0;i<QUESTS[type][campaign][nr][3].length;i++){
                    if(QUESTS[type][campaign][nr][3][i][0]==9){
                        if(!new_PRODUCT_QUEST[QUESTS[type][campaign][nr][3][i][1]]){ new_PRODUCT_QUEST[QUESTS[type][campaign][nr][3][i][1]]={}; }
                        new_PRODUCT_QUEST[QUESTS[type][campaign][nr][3][i][1]][QUESTS[type][campaign][nr][3][i][2]] = [type,parseInt(campaign,10),nr];
                    }
                }
            }
        }
    }
}
for(type=0;type<new_PRODUCT_QUEST.length;type++){
    new_PRODUCT_QUEST[type].sortObj();
}
GM_log("new_PRODUCT_QUEST:\n"+implode(new_PRODUCT_QUEST));
*/
const INIT_valMinRack={"v":200,"e":50,"o":10,"z":0,"f1":25,"f2":10,"f3":10,"f4":0,"fw1":10,"fw2":10,"fw3":10};
const LEVEL_POINTS=[0,0,58,2420,6620,15620,27900,58700,101700,163100,211900
                   ,276900,359000,467000,730000,1190000,1750000,2680000,3900000,5660000,7850000
                   ,10590000,15300000,20640000,26020000,37340000,50030000,65160000,85030000,108900000,139150000
                   ,175520000,222430000,276920000,345930000,429330000,535520000,669000000,797010000,927020000,1069440000
                   ,1202920000,1336400000,1469880000,1603360000,1896272000,2220357000,2576977000,2967479000,3393198000,3855457000
                   ,4355565000,4894822000,5474516000,6095926000,6760322000,7468962000,8223098000,9023973000,9872820000,10770866000
                   ,11719330000,12719423000,13772351000,14879311000,16041494000,17260085000,18536263000,19871201000,21266065000,22722017000
                   ,24240212000,25821802000,27467932000,29179741000,30958366000,32804936000,34720579000,36706414000,38763560000,40893128000
                   ,43096227000,45373962000,47727432000,50157733000,52665958000,55253195000,57920530000,60669042000,63499810000,66413907000
                   ,69412404000,72496369000,75666864000,78924952000,82271688000,85708127000,89235321000,92854318000,96566163000,100371897000
                   ]; // task_new_level
const VARIABLES = {
            "USER":{"bargeld":["Cash amount",2],
                    "calcToLodgeCampaign":["Target lodge campaign",5],
                    "calcToLodgeQuest":["Target lodge quest",5],
                    "calcToQuest":["Target quest",3],
                    "changedata":["Data version",1],
                    "clubmemberLog":["Log-data club",1],
                    "contractSave":["Saved contract templates",3],
                    "css_styles":["CSS",3],
                    "farmiLog":["Log-data farmies",1],
                    "farmiOk":["Limit at farmi-log",5],
                    "farmname":["Name of farm",2],
                    "highlight":["Highlighted users",3],
                    "highlightProducts":["Highlighted products",3],
                    "infoPanelFormulas":["Mode",4],
                    "kauf":["Log-data sales",5],
                    "logSales":["Log-data sales",1],
                    "lastContractTo":["Last contract recipient",2],
                    "lastOffer":["Last market offer",2],
                    "levelLog":["Log-data points",1],
                    "lodgeCampaignNr":["Lodge campaign",5],
                    "lodgeQuestData":["Lodge quest data",5],
                    "lodgeQuestNr":["Lodge quest number",5],
                    "lodgeTimeEnd":["Lodge quest time",5],
                    "lotteryCollectForPrize":["Lottery collect data",3],
                    "lotteryLastLot":["Lottery taken time",2],
                    "lotteryLog":["Log-data lottery",1],
                    "marketOffers":["Market offers",5],
                    "ownMarketOffers":["Own market offers",2],
                    "marketOfferTimes":["Market offer times",5],
                    "modeBuildPreise":["Mode",4],
                    "modeBuyNotepad":["Mode",4],
                    "modeLotteryLog":["Mode",5],
                    "modeMarket":["Mode",4],
                    "modeProfittable":["Mode",4],
                    "modeProfittableFeed":["Mode",5],
                    "modeProfittableSterne":["Mode",5],
                    "modeQuestsTable":["Mode",4],
                    "modeStatistic":["Mode",4],
                    "modeStockTable":["Mode",4],
                    "nachrichten":["Messages",1],
                    "nachrichten_doread":["Messages auto-read",5],
                    "nachrichten_doreadState":["Messages auto-read",5],
                    "nachrichten_letzte":["Messages",2],
                    "nachrichten_system":["Messages",5],
                    "nachrichtvorlage":["Message template",3],
                    "notepad":["Notepad",3],
                    "prodBestand":["Product stock",5],
                    "prodBlock":["Blocked products",2],
                    "prodGrowTime":["Product growtime",2],
                    "prodMinRack":["Minimal rackamounts",2],
                    "prodMinRackInit":["Minimal rackamounts",3],
                    "prodRequire":["Recursive needed products",5],
                    "prodStock":["Product stock",2],
                    "prodStockMax":["Product stock limit",2],
                    "prodYield":["Product yield",2],
                    "quest":["Quest number",5],
                    "questState":["Quest state",5],
                    "questTime":["Quest time",5],
                    "questData":["Quest data",2],
                    "raisedEvents":["Raised events",4],
                    "session":["Session",4],
                    "show":["Mode",4],
                    "totalFarmis":["Farmi needings",2],
                    "valAssumeWater":["Option",3],
                    "valAutoCrop":["Option",3],
                    "valAutoWater":["Option",3],
                    "valClickErrorbox":["Option",3],
                    "valContractLogAmount":["Option",3],
                    "valDrag":["Option",3],
                    "valEmptyFieldForestLimit":["Option",5],
                    "valErnte":["Option",5],
                    "valErnteMsg":["Option",3],
                    "valFarmiLimits":["Option",3],
                    "valFarmiMiniInfo":["Option",3],
                    "valGamecursor":["Option",3],
                    "valGiess":["Option",5],
                    "valGiessAnnehm":["Option",5],
                    "valGiessNotw":["Option",5],
                    "valGlobalTimeAdd":["Option",3],
                    "valGlobaltimeShowCroppedZone":["Option",3],
                    "valHotkey":["Option",3],
                    "valJoinPreise":["Option",3],
                    "valKauflimit":["Option",3],
                    "valKauflimitNPC":["Option",3],
                    "valLeereFelderLimit":["Option",5],
                    "valLimitEmptyFields":["Option",3],
                    "valMessageRe":["Option",3],
                    "valMessagesSystemMarkRead":["Option",3],
                    "valMinRack":["Option",3],
                    "valMinRackE":["Option",5],
                    "valMinRackF":["Option",5],
                    "valMinRackP":["Option",5],
                    "valMinRackV":["Option",5],
                    "valMinRackFarmis":["Option",3],
                    "valMinRackForestryFarmis":["Option",3],
                    "valMinRackGrowing":["Option",3],
                    "valMinRackLodgeQuest":["Option",5],
                    "valMinRackMan":["Option",3],
                    "valMinRackPlantsize":["Option",3],
                    "valMinRackQuest":["Option",5],
                    "valMinRackRecursive":["Option",3],
                    "valMoveAnimals":["Option",3],
                    "valMsgFormat":["Option",3],
                    "valNachr":["Option",5],
                    "valPrivNachr":["Option",3],
                    "valProtectMinRack":["Option",3],
                    "valQuicklinks":["Option",3],
                    "valSpoilerZoneUpdate":["Option",5],
                    "valStatistik":["Option",3],
                    "valStatistikNpc":["Option",5],
                    "valStatistikTime":["Option",5],
                    "valVerkaufLimitDown":["Option",3],
                    "valVerkaufLimitUp":["Option",3],
                    "valWaterNeeded":["Option",3],
                    "vertraegeIn":["Contracts received",1],
                    "vertraegeOut":["Contracts sent",1],
                    "vertraegePreise":["Contract prices",3],
                    "zoneAnimals":["Amount of animals",5],
                    "zoneBlock":["Blocked zones",5],
                    "zoneBonus":["Zones bonus",5],
                    "zoneBonusSpecialAmount":["Zone special product",5],
                    "zoneBonusSpecialProduct":["Zone special product",5],
                    "zoneEndProducts":["Zones productions",5],
                    "zoneEndTimes":["Zones endtimes",5],
                    "zoneErnte":["Zones productions",5],
                    "zoneFieldData":["Zones productions",5],
                    "zoneProductionData":["Zones productions",5],
                    "zoneMainprod":["Zones productions",5],
                    "zones":["Zones",2],
                    "zoneTyp":["Zones types",5],
                    "zoneWaterTimes":["Times watering",5]},
          "SERVER":{"buildPreiseShowAll":["Mode",5],
                    "changedata":["Data version",1],
                    "competition":["Competition data",2],
                    "farmNamen":["Farm names",2],
                    "gut":["Product prices",3],
                    "gutBeob":["Product observed prices",2],
                    "npcSaison":["Products saisons",2],
                    "pagedataNachrichtenNew":["Page attributes",4],
                    "pagedataStadtMarktstand":["Page attributes",4],
                    "pagedataVertraegeNew":["Page attributes",4],
                    "pagedataVertraegeOverview":["Page attributes",4],
                    "preisBeob":["Price observation",2],
                    "prodId":["Product names lookup",2],
                    "prodName":["Product names",2],
                    "prodNameSort":["Product names",2],
                    "prodPlantSize":["Plant sizes",2],
                    "prodPoints":["Product points",2],
                    "prodRequire":["Recursive needed products",2],
                    "prodTyp":["Product types",2],
                    "sessionlost":["Page attributes",4],
                    "username":["Username",4],
                    "valNimmBeob":["Option",3]},
         "COUNTRY":{"changedata":["Data version",1],
                    "pagedataLogin":["Page attributes",4],
                    "valServerTimeOffset":["Option",3]},
          "GLOBAL":{"changedata":["Data version",1],
                    "devmode":["Option",3],
                    "devmode_function":["Option",3],
                    "devmode_events":["Option",3],
                    "hotkeymap":["Option",3],
                    "loginbusy":["Page attributes",4],
                    "logindata":["Accounts",3],
                    "tutorial":["Tutorial step",1],
                    "updateCheck":["Script update",5],
                    "valAutoLogin":["Option",3],
                    "valUpdate":["Option",3]}
};
    
var npcSaison = INIT_NPC_SAISON.clone();
var prodName=new Array();
var prodId=new Array();
var recipeNameToId=null; //TODO maybe rename / save as var
var prodTyp=new Array(); //c:coins, v:plant, e:product, u:garbage, z:deco, f:forestry, d:forestry deco
var prodBlock=new Array(); //c:only by club, u:garbage, l:level too low, t:not tradable, f:forestry, q:forestry quest too low
var prodMinRackInit=new Array(); // initial minimal rack amounts
// integer<0 is possible and means something like "product is produced"
// call: unsafeWindow.prodMinRackAddon.add(type,1,"Mill-Queue",20000);
// call: unsafeWindow.prodMinRackAddon.remove(type,1,"Mill-Queue");
var prodMinRackAddon=new Array(new Array(), new Object()); // additional minimal rack data from addons
unsafeWindow.prodMinRackAddon=new Object();
unsafeWindow.prodMinRackAddon.newdata=new Array();
unsafeWindow.prodMinRackAddon.busy=false;
var prodMinRack=new Array(); // + quest amount - field and powerup amounts
var prodNameSort=new Array(); // sorted by type(cveoz)
var prodStock=new Array();
var prodStockMax=new Array();//if not id is undefined then there is no max
var prodPlantSize=new Array();
var prodYield=new Array();
var prodRequire=new Array();
var prodPoints=new Array();
var prodGrowTime=new Array();
var gut=new Array();
var gutBeob=new Array();
var preisBeob=new Array();
var questData;
var css_styles=new Object();
var regMsgMarketsaleContent,regMsgContractsaleContent,regMsgContractsaleList,regMsgFriend;
var valAutoWater, valWaterNeeded, valAssumeWater, valAutoCrop, valErnteMsg, valLimitEmptyFields, valStatistik, valClickErrorbox, valGlobaltimeShowCroppedZone;
var valMoveAnimals, valMinRackMan, valMinRack, valMinRackPlantsize, valMinRackFarmis,valMinRackForestryFarmis, valMinRackGrowing, valMinRackRecursive, valFarmiLimits, valFarmiMiniInfo
var upjersAds, buyNotePadShowBlocked, show;
var farmiLog, farmiDailyCount, levelLog, levelLogId, lotteryLog, lotteryLogId, logSales, logSalesId, logDonkey;
var zoneAddToGlobalTime;
var totalAnimals, totalErnte, totalFarmis, totalPowerups, totalQuest, totalRecursive, totalZones, totalEndtime;
var valKauflimit, valKauflimitNPC, highlightProducts, highlightUser, valNimmBeob, valVerkaufLimitDown, valVerkaufLimitUp, valJoinPreise, lastOffer, protectMinRack, ownMarketOffers;
var valMessagesSystemMarkRead;
var megafieldVehicle;
top.unsafeData.autoAction=null;
var gameLocation=[null,null];
unsafeData.gameLocation=gameLocation.clone();

//***********************************************************************************************************
// developer functions
if(DEVMODE_FUNCTION){ tracking.init("berater"); }

//***********************************************************************************************************
//*********************** FUNCTIONS *************************************************************************
// DOM
function SortableTable (sortRow){
    // Sortable HTML table inspired by http://www.webtoolkit.info/
    // example-call: new SortableTable(x);
    // sorting by value-attribute of td-elements
    // only cols with sortdir-attribute in the thead-cell
    function sortCol(cell){
    try{
        var tableEl=cell;
        while(tableEl.tagName!="TABLE"){ tableEl=tableEl.parentNode; }
        var tbody=tableEl.getElementsByTagName("tbody")[0];
        var sortRow=cell.parentNode;
        var newclass,oldclass,sortdir;
        // clone the rows
        var newRows=new Array();
        for(j=0; j < tbody.rows.length; j++){
            newRows[j]=tbody.rows[j];
        }
        //sort them
        newRows.sort(function(a,b){
            aa=parseFloat(a.cells[cell.cellIndex].getAttribute("value"),10);
            if (isNaN(aa)) aa=0;
            bb=parseFloat(b.cells[cell.cellIndex].getAttribute("value"),10);
            if (isNaN(bb)) bb=0;
            return (aa-bb);
        });
        // set classes of headercells
        if (cell.getAttribute("sortdir") == "Asc"){
            newRows.reverse();
            sortdir="Desc";
        }else{
            sortdir="Asc";
        }
        cell.setAttribute("sortdir",sortdir);
        for(var i=0; i<sortRow.cells.length; i++){
            if(typeof(sortRow.cells[i].getAttribute("sortdir"))=="string"){
                oldclass=sortRow.cells[i].getAttribute("class");
                newclass=oldclass.replace(/sortableCol(.*)\b/,"sortableCol"+(i==cell.cellIndex?sortdir:""));
                if(oldclass!=newclass){ sortRow.cells[i].setAttribute("class",newclass); }
            }
        }
        // rebuild table
        for(i=0;i<newRows.length;i++){
            tbody.appendChild(newRows[i]);
        }
        tableEl=null;tbody=null;sortRow=null;newRows=null;
    }catch(err){ GM_logError("sortCol\n"+sortRow.cells[i].innerHTML+"\n"+err); }
    }
    // constructor actions
    try{
    for(var i=0; i<sortRow.cells.length; i++){
        if(typeof(sortRow.cells[i].getAttribute("sortdir"))=="string"){
            var oldclass=sortRow.cells[i].getAttribute("class");
            sortRow.cells[i].setAttribute("class",(oldclass?oldclass+" ":"")+"sortableCol");
            sortRow.cells[i].addEventListener("click",function (){
                sortCol(this);
                return false;
            },false);
        }
    }
    }catch(err){ GM_logError("SortableTable\n"+err); }
 }
function bar(size,markvalue,maxvalue){
    size=Math.floor(size);
    var mark=Math.floor(size*markvalue/maxvalue);
    var cell=createElement("div",{"style":"border:2px solid black; position:absolute;width:"+size+"px;height:12px;"});
        createElement("div",{"style":"position:absolute;width:"+mark+"px;height:12px;background-color:#5555FF;"},cell);
    return cell;
}
function setSelRange(inputEl, selStart, selEnd){
 if (inputEl.setSelectionRange){
  inputEl.focus();
  inputEl.setSelectionRange(selStart, selEnd);
 }else if (inputEl.createTextRange){
  var range=inputEl.createTextRange();
  range.collapse(true);
  range.moveEnd('character', selEnd);
  range.moveStart('character', selStart);
  range.select();
 }
}

// Strings
function getKeySymbol(keyCode){
    if((46<keyCode)&&(keyCode<91)){ return String.fromCharCode(keyCode); }
    var codelist={"8":"backspace","9":"tab","13":"enter","16":"shift","17":"ctrl","18":"alt","19":"pause/break","20":"caps lock","27":"escape","33":"page up","34":"page down","35":"end","36":"home","37":"<-","38":"up arrow","39":"->","40":"down arrow","45":"insert","46":"delete","91":"left window key","92":"right window key","93":"select key","96":"numpad 0","97":"numpad 1","98":"numpad 2","99":"numpad 3","100":"numpad 4","101":"numpad 5","102":"numpad 6","103":"numpad 7","104":"numpad 8","105":"numpad 9","106":"*","107":"+","109":"-","110":"decimal point","111":"divide","112":"F1","113":"F2","114":"F3","115":"F4","116":"F5","117":"F6","118":"F7","119":"F8","120":"F9","121":"F10","122":"F11","123":"F12","144":"num lock","145":"scroll lock","186":"semi-colon","187":"equal sign","188":",","189":"dash","190":"period","191":"forward slash","192":"grave accent","219":"open bracket","220":"back slash","221":"close braket","222":"single quote"};
    return codelist[keyCode]?codelist[keyCode]:"key("+keyCode+")";
}

// Game
function igm(name,append,betreff){
try{
    var link=createElement("span",{"to":name,"subject":(betreff?betreff:""),"class":"link playerMsg"});
    createElement("div",{},link);
    link.addEventListener("click",function(){
    try{
        if(unsafeWindow.messages_write_block == 1){
            unsafeWindow.showDiv("messages_view_info");
            unsafeWindow.hideDiv("messages_view_form");
        }else{
            unsafeWindow.hideDiv("messages_view_info");
            unsafeWindow.showDiv("messages_view_form");
        }
        $("messages_view_name").value = this.getAttribute("to");
        $("messages_view_subject").value = this.getAttribute("subject");
        $("messages_view_body").value = "";
        unsafeWindow.hideDiv("messages_list");
        unsafeWindow.hideDiv("messages_contacts");
        unsafeWindow.showDiv("messages_view");
        unsafeWindow.messagesNavi("new");
        unsafeWindow.messagesCalcBody();
    }catch(err){GM_logError("igm.click\n"+err);}
    },false);
    link.addEventListener("mouseover",function(event){
        toolTip.show(event,getText("writeMessage"),this);
    },false);
    if (append){ append.appendChild(link); }
    return link;
}catch(err){GM_logError("igm\n"+err);}
}
function vertrag(name,append){
    var link=createElement("span",{"to":name,"class":"link playerContract"});
    createElement("div",{},link);
    link.addEventListener("click",function(){
        var pagedata=new Object();
        pagedata["to"]=this.getAttribute("to");
        window.setTimeout(function(){
            GM_setValue(COUNTRY+"_"+SERVER+"_pagedataVertraegeNew",implode(pagedata));
            if($top("multiframe")){
                toolTip.hide(this);
                $top("multiframe").src="../vertraege/new.php";
                $top("multiframe").style.display="block";
            }else{
                window.open("../vertraege/new.php");
            }
        },0);
    },false);
    link.addEventListener("mouseover",function(event){
        toolTip.show(event,getText("sendContract"));
    },false);
    if (append) append.appendChild(link);
    return link;
}
function stats(name,append){
    var link=createElement("span", {"mouseOverText":getText("statistics"),"class":"link playerStats","href":"../stadt/stats.php?search=1&searchterm="+name});
    createElement("div",{},link);
    if($top("shop")){
        link.addEventListener("click",function(){
            toolTip.hide(this);
            showShopframePage(this.getAttribute("href"));
        },false);
    }else{
        link.addEventListener("click",function(){location.href=this.getAttribute("href");},false);
    }
    link.addEventListener("mouseover",function(event){
        toolTip.show(event,this.getAttribute("mouseOverText"),this);
    },false);
    if (append) append.appendChild(link);
    return link;
}

function loadProductData(){
    try{
    if(DEVMODE_FUNCTION){ var trackingHandle = tracking.start("berater","loadProductData"); }
        gut=explode(GM_getValue(COUNTRY+"_"+SERVER+"_gut"),"loadProductData/gut",[]);
        gutBeob=explode(GM_getValue(COUNTRY+"_"+SERVER+"_gutBeob"),"loadProductData/gutBeob",[]);
        preisBeob=explode(GM_getValue(COUNTRY+"_"+SERVER+"_preisBeob"),"loadProductData/preisBeob",[]); //isNotSent,time,min,max,amount 
        prodName=explode(GM_getValue(COUNTRY+"_"+SERVER+"_prodName"),"loadProductData/prodName",[]);
        prodId=explode(GM_getValue(COUNTRY+"_"+SERVER+"_prodId"),"loadProductData/prodId",[]);
        prodPlantSize=explode(GM_getValue(COUNTRY+"_"+SERVER+"_prodPlantSize"),"loadProductData/err/prodPlantSize",[]);
        prodStock=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_prodStock"),"loadProductData/prodStock",[]);
        prodStockMax=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_prodStockMax"),"loadProductData/prodStockMax",[]);
        prodYield=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_prodYield"),"loadProductData/prodYield",[]);
        prodRequire=explode(GM_getValue(COUNTRY+"_"+SERVER+"_prodRequire"),"loadProductData/prodRequire",[]);
        prodTyp=explode(GM_getValue(COUNTRY+"_"+SERVER+"_prodTyp"),"loadProductData/prodTyp",[]);//c:coins, v:plant, e:product, u:garbage, z:deco, f:forestry, r:recipe
        prodGrowTime=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_prodGrowTime"),"loadProductData/prodGrowTime",[]);
        prodPoints=explode(GM_getValue(COUNTRY+"_"+SERVER+"_prodPoints"),"loadProductData/prodPoints",[]);
        prodNameSort=explode(GM_getValue(COUNTRY+"_"+SERVER+"_prodNameSort"),"loadProductData/err/prodNameSort",[]);
        prodBlock=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_prodBlock"),"loadProductData/err/prodBlock",[]);
        prodMinRackInit=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_prodMinRackInit"),"loadProductData/err/prodMinRackInit",[]);
        prodMinRack=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_prodMinRack"),"loadProductData/err/prodMinRack",[]);
    if(DEVMODE_FUNCTION){ tracking.end("berater",trackingHandle); }
    }catch(err){ GM_logError("loadProductData\n"+err); }
}
function updateProductDataFarm(){
    try{
    if(DEVMODE_FUNCTION){ var trackingHandle = tracking.start("berater","updateProductDataFarm"); }
        if(USERLEVEL<parseInt(unsafeWindow.currentuserlevel,10)){
            raiseEvent("gameUserlevelUp");
        }
        USERLEVEL=parseInt(unsafeWindow.currentuserlevel,10);
        if(!(prodName instanceof Array)){ prodName=[]; }
        if(!(prodId instanceof Array)){ prodId=[]; }
        if(!(prodPlantSize instanceof Array)){ prodPlantSize=[]; }
        if(!(prodStock instanceof Array)){ prodStock=[]; }
        if(!(prodStockMax instanceof Array)){ prodStockMax=[]; }
        if(!(prodYield instanceof Array)){ prodYield=[]; }
        if(!(prodRequire instanceof Array)){ prodRequire=[]; }
        if(!(prodTyp instanceof Array)){ prodTyp=[]; }
        if(!(prodGrowTime instanceof Array)){ prodGrowTime=[]; }
        if(!(prodPoints instanceof Array)){ prodPoints=[]; }
        if(!(prodNameSort instanceof Array)){ prodNameSort=[]; }
        if(!(prodBlock instanceof Array)){ prodBlock=[]; }
 
        if(!prodName[0]||!(prodName[0] instanceof Array)){ prodName[0]=[]; } 
        if(!prodId[0]||(typeof prodId[0]!="object")||(prodId[0] instanceof Array)){ prodId[0]={}; } 
        if(!prodPlantSize[0]||!(prodPlantSize[0] instanceof Array)){ prodPlantSize[0]=[]; } 
        if(!prodStock[0]||!(prodStock[0] instanceof Array)){ prodStock[0]=[]; } 
        if(!prodStockMax[0]||!(prodStockMax[0] instanceof Array)){ prodStockMax[0]=[]; } 
        if(!prodYield[0]||!(prodYield[0] instanceof Array)){ prodYield[0]=[]; } 
        if(!prodRequire[0]||!(prodRequire[0] instanceof Array)){ prodRequire[0]=[]; } 
        if(!prodTyp[0]||!(prodTyp[0] instanceof Array)){ prodTyp[0]=[]; } 
        if(!prodGrowTime[0]||!(prodGrowTime[0] instanceof Array)){ prodGrowTime[0]=[]; } 
        if(!prodPoints[0]||!(prodPoints[0] instanceof Array)){ prodPoints[0]=[]; } 
        // if(!prodBlock[0]||!(prodBlock[0] instanceof Array)){ prodBlock[0]=[]; } 
        
        //c:only by club, u:garbage, l:level too low, t:not tradable, f:forestry, q:forestry quest too low, r:recipe, p:powerup, b:block recipe/powerup
        prodBlock[0]=["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","ct","","ct","","ct","ct","","ct","","","","","","","","","","ct","ct","ct","ct","ct","ct","ct","","","","","","","ct","","ct","","","ct","","","ct","ct","ct","","","","","","","","t","","","","","","","t","","t","t","","","","","","","","","","","","","","","","","","","","","","t","","","","","","","","","","","","","","","","","","","","","","","","","","","","","t","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","ut","ut",,,,,,,,,,,"","","","","","","","","","","","","","","t","t","t","t","t","t","t","t"]; // task_new_plant task_new_product
         /*
        var new_prodBlock=prodBlock[0].clone();
        new_prodBlock[221]="";
        GM_log(implode(new_prodBlock));
        */
        var help={"v":[],"e":[],"o":[],"fw1":[],"fw2":[],"fw3":[],"fw4":[],"z":[],"fl":[],"fla":[]};
        // for(var v=1;v<unsafeWindow.produkt_name.length;v++){
        for(var v in unsafeWindow.produkt_name){
            if(!unsafeWindow.produkt_name.hasOwnProperty(v)){continue;}
            if(isNaN(gut[v])){ gut[v]=0; }
            prodName[0][v]=unsafeWindow.produkt_name[v];
            prodId[0][prodName[0][v]]=v;
            prodPlantSize[0][v]=unsafeWindow.produkt_x[v]*unsafeWindow.produkt_y[v];
            var c=(unsafeWindow.rackElement[v]&&unsafeWindow.rackElement[v].number)?unsafeWindow.rackElement[v].number:0;
            prodStock[0][v]=(c?parseInt(c,10):0);
            prodYield[0][v]=(unsafeWindow.produkt_ernte[v]?parseInt(unsafeWindow.produkt_ernte[v],10):0);
            prodTyp[0][v]=unsafeWindow.produkt_category[v];
            prodRequire[0][v]=PRODUCT_REQUIRE[0][v];
            prodGrowTime[0][v]=PRODUCT_GROWTIME[0][v]; //TODO take from game?
            prodPoints[0][v]=PRODUCT_POINTS[0][v]; //TODO take from game?
            if(prodTyp[0][v]=="u"){
                prodBlock[0][v]="ut";
            }else{
                if(typeof prodBlock[0][v]=="undefined"){
                    prodBlock[0][v]="t";
                }
                // Hack: split picnic products in different categories
                if(prodTyp[0][v]=="fw"){ // task_new_picnic_product
                    switch(parseInt(v,10)){
                    case 130:case 131:case 132:case 133:case 134:case 135:case 145:case 146:case 147:
                        prodTyp[0][v]+="1"; break;
                    case 136:case 137:case 138:case 139:case 140:case 141:case 142:case 143:case 148:case 149:case 150:
                        prodTyp[0][v]+="2"; break;
                    case 161:case 162:case 163:case 164:case 165:case 166:case 167:case 168:case 169:case 170:
                        prodTyp[0][v]+="3"; break;
                    default: prodTyp[0][v]+="4";
                    }
                }
                if(help[prodTyp[0][v]]){
                    help[prodTyp[0][v]].push(v);
                }
                if(USERLEVEL<unsafeWindow.produkt_level[v]){
                    prodBlock[0][v]+="l"+unsafeWindow.produkt_level[v];
                }
                if(PRODUCT_QUEST[0][v]&&(questData[PRODUCT_QUEST[0][v][0]][PRODUCT_QUEST[0][v][1]]["nr"]<=PRODUCT_QUEST[0][v][2])){
                    prodBlock[0][v]+="q";
                }
            }
        }
        prodTyp[0][0]="c";
        try{ prodStock[0][0]=parseInt($("coins").innerHTML,10); }catch(err){}
        prodNameSort[0]=[0].concat(help["v"],help["e"],help["o"],help["fw1"],help["fw2"],help["fw3"],help["fw4"],help["fl"],help["fla"],help["z"]);
        // quest boni
        for(var v=1;v<questData["main"]["1"]["nr"];v++){
            if(QUESTS["main"]["1"][v]&&QUESTS["main"]["1"][v][3]){
                for(var w=0;w<QUESTS["main"]["1"][v][3].length;w++){
                    if(QUESTS["main"]["1"][v][3][w][0]==4){
                        prodGrowTime[QUESTS["main"]["1"][v][3][w][1]][QUESTS["main"]["1"][v][3][w][2]]-=QUESTS["main"]["1"][v][3][w][3];
                    }
                }
            }
        }
        publishProductData();
    if(DEVMODE_FUNCTION){ tracking.end("berater",trackingHandle); }
    }catch(err){
        GM_logError("updateProductDataFarm\n"+err);
        loadProductData();
    }
}
function updateProductDataForestry(){
    try{
    if(DEVMODE_FUNCTION){ var trackingHandle = tracking.start("berater","updateProductDataForestry"); }
        prodName[1]={};
        if(!prodId[1]||(typeof prodId[1]!="object")||(prodId[1] instanceof Array)){ prodId[1]={}; } 
        if(!prodPlantSize[1]||(typeof prodPlantSize[1]!="object")||(prodPlantSize[1] instanceof Array)){ prodPlantSize[1]={}; } 
        if(!prodStock[1]||(typeof prodStock[1]!="object")||(prodStock[1] instanceof Array)){ prodStock[1]={}; } 
        if(!prodStockMax[1]||(typeof prodStockMax[1]!="object")||(prodStockMax[1] instanceof Array)){ prodStockMax[1]={}; } 
        if(!prodYield[1]||(typeof prodYield[1]!="object")||(prodYield[1] instanceof Array)){ prodYield[1]={}; } 
        if(!prodRequire[1]||(typeof prodRequire[1]!="object")||(prodRequire[1] instanceof Array)){ prodRequire[1]={}; } 
        if(!prodTyp[1]||(typeof prodTyp[1]!="object")||(prodTyp[1] instanceof Array)){ prodTyp[1]={}; } 
        if(!prodGrowTime[1]||(typeof prodGrowTime[1]!="object")||(prodGrowTime[1] instanceof Array)){ prodGrowTime[1]={}; } 
        if(!prodPoints[1]||(typeof prodPoints[1]!="object")||(prodPoints[1] instanceof Array)){ prodPoints[1]={}; } 
        if(!prodNameSort[1]||!(prodNameSort[1] instanceof Array)){ prodNameSort[1]=[]; } 
        if(!prodBlock[1]||(typeof prodBlock[1]!="object")||(prodBlock[1] instanceof Array)){ prodBlock[1]={}; } 
 
        var help={"f1":[],"f2":[],"f3":[],"f4":[],"f5":[]};
        for(var v in unsafeWindow.produkt_name_forestry){
            if(!unsafeWindow.produkt_name_forestry.hasOwnProperty(v)){continue;}    
            prodName[1][v]=unsafeWindow.produkt_name_forestry[v];
            prodId[1][prodName[1][v]]=v;
            prodPlantSize[1][v]=1;
            // prodStock
            // prodStockMax
            prodYield[1][v]=PRODUCT_YIELD[1][v];
            if((v==105)||(v==108)||(v==116)||(v==117)||(v==119)||(v==120)){ prodTyp[1][v]="f5"; } // farmhouse-items from carpentry
            else if(v<20){ prodTyp[1][v]="f1"; } // saplings
            else if(v<40){ prodTyp[1][v]="f2"; } // logs
            else if(v<100){ prodTyp[1][v]="f3"; } // sawmill-products
            else if(v<500){ prodTyp[1][v]="f4"; } // carpentry-products
            else { prodTyp[1][v]="u"; } // useless "products"
            prodRequire[1][v]=PRODUCT_REQUIRE[1][v];
            prodGrowTime[1][v]=PRODUCT_GROWTIME[1][v];
            prodPoints[1][v]=PRODUCT_POINTS[1][v];
            
            if(prodTyp[1][v]=="u"){
                prodBlock[1][v]="qtu";
            }else{
                prodBlock[1][v]="t";
                if((unsafeWindow.forestry_unlock==undefined)||(PRODUCT_QUEST[1][v]&&(questData[PRODUCT_QUEST[1][v][0]][PRODUCT_QUEST[1][v][1]]["nr"]<=PRODUCT_QUEST[1][v][2]))){
                    prodBlock[1][v]+="q";
                }
                if(v==113||v==114){ prodBlock[1][v]+="s"; } 
                if(help[prodTyp[1][v]]){
                    help[prodTyp[1][v]].push(v);
                }
            }
        }
        prodNameSort[1]=help["f1"].concat(help["f2"],help["f3"],help["f4"],help["f5"]);
        // prodName[1].sortObj();
        publishProductData();
    if(DEVMODE_FUNCTION){ tracking.end("berater",trackingHandle); }
    }catch(err){ GM_logError("updateProductDataForestry\n"+err); }
}
function updateProductDataWindmill(){
    try{
    if(DEVMODE_FUNCTION){ var trackingHandle = tracking.start("berater","updateProductDataWindmill"); }
        if(!prodName[2]||!(prodName[2] instanceof Array)){ prodName[2]=[]; } 
        if(!prodId[2]||(typeof prodId[2]!="object")||(prodId[2] instanceof Array)){ prodId[2]={}; } 
        if(!prodPlantSize[2]||!(prodPlantSize[2] instanceof Array)){ prodPlantSize[2]=[]; } 
        if(!prodStock[2]||!(prodStock[2] instanceof Array)){ prodStock[2]=[]; } 
        if(!prodStockMax[2]||!(prodStockMax[2] instanceof Array)){ prodStockMax[2]=[]; } 
        // if(!prodYield[2]||!(prodYield[2] instanceof Array)){ prodYield[2]=[]; } 
        // if(!prodRequire[2]||!(prodRequire[2] instanceof Array)){ prodRequire[2]=[]; } 
        if(!prodTyp[2]||!(prodTyp[2] instanceof Array)){ prodTyp[2]=[]; } 
        // if(!prodGrowTime[2]||!(prodGrowTime[2] instanceof Array)){ prodGrowTime[2]=[]; } 
        // if(!prodPoints[2]||!(prodPoints[2] instanceof Array)){ prodPoints[2]=[]; } 
        if(!prodBlock[2]||!(prodBlock[2] instanceof Array)){ prodBlock[2]=[]; } 

        prodYield[2]=[];
        prodRequire[2]=[];
        prodGrowTime[2]=[];
        prodPoints[2]=[];
        // GM_log("formulas:\n"+print_r(unsafeWindow.formulas,"",true,"\n"));
        for(var v in unsafeWindow.formulas[0]){
            if(!unsafeWindow.formulas[0].hasOwnProperty(v)){continue;}
            pId=unsafeWindow.formulas[0][v][0];
            // GM_log("updateProductDataWindmill loop formulas v="+v+" pId="+pId);
            prodName[2][pId]="*"+unsafeWindow.formulas[0][v][2];
            prodId[2]["*"+unsafeWindow.formulas[0][v][2]]=pId;
            prodId[2][unsafeWindow.formulas[0][v][2]]=pId;
            prodPlantSize[2][pId]=1;
            if(!prodStock[2][pId]||(typeof prodStock[2][pId]!="number")){ prodStock[2][pId]=0; }
            //1=earn prods,2=earn extra amount,3=earn extra score
            if(unsafeWindow.formulas[0][v][5][0]!=0){ prodTyp[2][pId]="r0"; }
            else if(unsafeWindow.formulas[0][v][5][1]!=0){ prodTyp[2][pId]="r1"; }
            else if(unsafeWindow.formulas[0][v][5][2]!=0){ prodTyp[2][pId]="r2" }
            prodBlock[2][pId]="rt"+(USERLEVEL<unsafeWindow.formulas[0][v][1]?"l":"")+(unsafeWindow.formulas[0][v]["endremain"]<0?"s":"");
        }
        // prodTyp[2].sortObj();
        var help={"r0":[],"r1":[],"r2":[]};
        for(var v in prodTyp[2]){
            if(!prodTyp[2].hasOwnProperty(v)){continue;}
            if(help[prodTyp[2][v]]){ help[prodTyp[2][v]].push(v); }
        }
        prodNameSort[2]=help["r0"].concat(help["r1"],help["r2"]);
        publishProductData();
    if(DEVMODE_FUNCTION){ tracking.end("berater",trackingHandle); }
    }catch(err){ GM_logError("updateProductDataWindmill\n"+err); }
}
function updateProductDataPowerup(){
    try{
    if(DEVMODE_FUNCTION){ var trackingHandle = tracking.start("berater","updateProductDataPowerup"); }
        if(!prodName[3]||!(prodName[3] instanceof Array)){ prodName[3]=[]; } 
        if(!prodId[3]||(typeof prodId[3]!="object")||(prodId[3] instanceof Array)){ prodId[3]={}; } 
        if(!prodPlantSize[3]||!(prodPlantSize[3] instanceof Array)){ prodPlantSize[3]=[]; } 
        if(!prodStock[3]||!(prodStock[3] instanceof Array)){ prodStock[3]=[]; } 
        if(!prodStockMax[3]||!(prodStockMax[3] instanceof Array)){ prodStockMax[3]=[]; } 
        if(!prodYield[3]||!(prodYield[3] instanceof Array)){ prodYield[3]=[]; } 
        if(!prodRequire[3]||!(prodRequire[3] instanceof Array)){ prodRequire[3]=[]; } 
        if(!prodTyp[3]||!(prodTyp[3] instanceof Array)){ prodTyp[3]=[]; } 
        if(!prodGrowTime[3]||!(prodGrowTime[3] instanceof Array)){ prodGrowTime[3]=[]; } 
        if(!prodPoints[3]||!(prodPoints[3] instanceof Array)){ prodPoints[3]=[]; } 
        if(!prodBlock[3]||!(prodBlock[3] instanceof Array)){ prodBlock[3]=[]; } 
    
        var pId;
        for(var v in unsafeWindow.formulas[0]){
            if(!unsafeWindow.formulas[0].hasOwnProperty(v)){continue;}
            pId=unsafeWindow.formulas[0][v][0];
            // GM_log("updateProductDataPowerup loop formulas v="+v+" pId="+pId);
            prodName[3][pId]=unsafeWindow.formulas[0][v][2];
            prodPlantSize[2][pId]=1;
            prodStock[3][pId]=0;
            prodYield[3][pId]=1;
            prodRequire[3][pId]=[[2,pId,1]];
            for(var i=0;i<unsafeWindow.formulas[0][v][3].length;i++){
                prodRequire[3][pId].push([0,unsafeWindow.formulas[0][v][3][i][0],unsafeWindow.formulas[0][v][3][i][1]]);
            }
            //1=earn prods,2=earn extra amount,3=earn extra score
            if(unsafeWindow.formulas[0][v][5][0]!=0){ prodTyp[3][pId]="p0"; }
            else if(unsafeWindow.formulas[0][v][5][1]!=0){ prodTyp[3][pId]="p1"; }
            else if(unsafeWindow.formulas[0][v][5][2]!=0){ prodTyp[3][pId]="p2"; }
            prodGrowTime[3][pId]=Math.round(unsafeWindow.formulas[0][v][4]/60);
            prodPoints[3][pId]=unsafeWindow.formulas[0][v][8];
            prodBlock[3][pId]="pt"+(USERLEVEL<unsafeWindow.formulas[0][v][1]?"l":"");
        }
        if (unsafeWindow.poweruprack == null) unsafeWindow.poweruprack = 0;
        for(var v in unsafeWindow.poweruprack){
            if(!unsafeWindow.poweruprack.hasOwnProperty(v)){continue;}
            pId=unsafeWindow.poweruprack[v][0];
            // GM_log("updateProductDataPowerup loop poweruprack v="+v+" pId="+pId);
            prodName[3][pId]=unsafeWindow.poweruprack[v][2];
            prodStock[3][pId]=unsafeWindow.poweruprack[v]["rack"];
            if(unsafeWindow.poweruprack[v]["endremain"]<0){ prodBlock[3][pId]+="s"; }
        }
        for(var v=0;v<prodName[3].length;v++){
            prodId[3][prodName[3][v]]=v;
        }
        // prodTyp[3].sortObj();
        var help={"p0":[],"p1":[],"p2":[]};
        for(var v in prodTyp[3]){
            if(!prodTyp[3].hasOwnProperty(v)){continue;}
            if(help[prodTyp[3][v]]){ help[prodTyp[3][v]].push(v); }
        }
        prodNameSort[3]=help["p0"].concat(help["p1"],help["p2"]);
        publishProductData();
    if(DEVMODE_FUNCTION){ tracking.end("berater",trackingHandle); }
    }catch(err){ GM_logError("updateProductDataPowerup\n"+err); }
}
function publishProductData(){
    window.setTimeout(function(){
    try{
    if(DEVMODE_FUNCTION){ var trackingHandle = tracking.start("berater","publishProductData"); }
        top.unsafeData.prodName     =prodName.clone();
        top.unsafeData.prodNameSort =prodNameSort.clone();
        top.unsafeData.prodTyp      =prodTyp.clone();
        top.unsafeData.prodBlock    =prodBlock.clone();
        top.unsafeData.prodYield    =prodYield.clone();
        top.unsafeData.prodRequire  =prodRequire.clone();
        top.unsafeData.prodStock    =prodStock.clone();
        top.unsafeData.prodStockMax =prodStockMax.clone();
        top.unsafeData.prodGrowTime =prodGrowTime.clone();
        top.unsafeData.prodPlantSize=prodPlantSize.clone();
        top.unsafeData.prodPoints   =prodPoints.clone();
        top.unsafeData.prodId       =prodId.clone();
        top.unsafeData.gut          =gut.clone();
        top.unsafeData.preisBeob    =explode(GM_getValue(COUNTRY+"_"+SERVER+"_preisBeob","[]"),"publishProductData/preisBeob",[]).clone();
    if(DEVMODE_FUNCTION){ tracking.end("berater",trackingHandle); }
    }catch(err){ GM_logError("publishProductData\n"+err); }
    },0);
}
function saveProductData(){
    try{
    if(DEVMODE_FUNCTION){ var trackingHandle = tracking.start("berater","saveProductData"); }
        GM_setValue(COUNTRY+"_"+SERVER+"_prodName",implode(prodName,"saveProductData\prodName"));
        GM_setValue(COUNTRY+"_"+SERVER+"_prodNameSort",implode(prodNameSort,"saveProductData\prodNameSort"));
        GM_setValue(COUNTRY+"_"+SERVER+"_prodId",implode(prodId,"saveProductData\prodId"));
        GM_setValue(COUNTRY+"_"+SERVER+"_prodPoints",implode(prodPoints,"saveProductData\prodPoints"));
        GM_setValue(COUNTRY+"_"+SERVER+"_prodPlantSize",implode(prodPlantSize,"saveProductData\prodPlantSize"));
        GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_prodStock",implode(prodStock,"saveProductData\prodStock"));
        GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_prodStockMax",implode(prodStockMax,"saveProductData\prodStockMax"));
        GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_prodYield",implode(prodYield,"saveProductData\prodYield"));
        GM_setValue(COUNTRY+"_"+SERVER+"_prodRequire",implode(prodRequire,"saveProductData\prodRequire"));
        GM_setValue(COUNTRY+"_"+SERVER+"_prodTyp",implode(prodTyp,"saveProductData\prodTyp"));
        GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_prodGrowTime",implode(prodGrowTime,"saveProductData\prodGrowTime"));
        GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_prodBlock",implode(prodBlock,"saveProductData\prodBlock"));
        GM_setValue(COUNTRY+"_"+SERVER+"_gut",implode(gut,"saveProductData\gut"));
        GM_setValue(COUNTRY+"_"+SERVER+"_gutBeob",implode(gutBeob,"saveProductData\gutBeob"));
    if(DEVMODE_FUNCTION){ tracking.end("berater",trackingHandle); }
    }catch(err){ GM_logError("saveProductData\n"+err); }
}

/* 
function checkRequest(request){
    if((request.readyState==4)&&(request.status==200)){
        var response=request.responseText;
        if(response!=0){
            var result=eval('('+response+')');
            if(result[0]!=0){
                return result;
            }
        }
    }
    return null;
}
*/
// function for validation of AJAX-response. taken from game and shrunk on return value
function checkRequest(request, mode) {
try{
    if (request.readyState == 4 && request.status == 200) {
        response = request.responseText;
        if ((response!="failed") && (response!="maintenance") && (response!=0)) {
            var result = eval("(" + response + ")");
            if (result.datablock) {
                return result.datablock;
            } else {
                return result;
            }
        }
    }
    return 0;
}catch(err){GM_logError("checkRequest\n"+err);return null;} 
}
function showMultiframePage(page){
try{
//GM_log("showMultiframePage:"+page);
    top.window.wrappedJSObject.gclr();
    top.window.wrappedJSObject.clr();
    var i=0,help;
    while (help=$top("kunde"+(i++))){ help.style.display="none"; }
    closeInfoPanel();
    if(help=$top("einkaufszettel")){ help.style.display="none"; }
    if(help=$top("popup_garden")){ help.style.display="block"; }
    if(help=$top("multiframe")){ help.style.display="block"; }
    if(help=$top("multiframe")){ help.src=page; }
}catch(err){GM_logError("showMultiframePage page="+page+"\n"+err);} 
}
function showShopframePage(page){
    var cell=$top("shop");
    if(cell){
        if (top.window.wrappedJSObject.city!=1){
            top.document.addEventListener("gameCity1",function(){
                GM_log("showShopframePage:in stad 1");
                top.document.removeEventListener("gameCity1",arguments.callee,false);
                showShopframePage(page);
            },false);
            click($top("speedlink_city1"));
        }else if (cell.style.display!="block"){
            cell.style.display="block";
            cell.style.visibility="visible";
            cell=$top("transp3");
            cell.style.display="block";
            cell.style.visibility="visible";
            showShopframePage(page);
        }else{
            $top("travel2city").style.display="none";
            $top("shopframe").src=page;
        }
        //closeInfoPanel();
    }else{
        location.href=page;
    }
    cell=null;
}
function showMessage(from,page,msg){
//GM_log("showMessage:"+from+":"+page+":"+msg);
    //click($top("menueimg1"));
    showMultiframePage("http://s"+SERVER+"."+GAMEPAGES[COUNTRY]+"/nachrichten/read.php?from="+from+"&page="+page+"&msg="+msg+"&mass=0");
}
function showSGH(){
    top.document.addEventListener("gameCity1",function(){
        click($top("cityzone_1_2"));
        top.document.removeEventListener("gameCity1",arguments.callee,false);
    },false);
    click($top("speedlink_city1"));
}
function showLottery(){
    var div=$top("speedlink_city2");
    if(div&&($top("lotterycontainer"))){
        top.document.addEventListener("gameCity2",function(){
            click($top("cityzone_2_8"));
            top.document.removeEventListener("gameCity2",arguments.callee,false);
        },false);
        click(div);
    }
    div=null;
}
function goToDonkey(){
try{
    var div;
    if((gameLocation[0]=="farm")&&(gameLocation[1]==0)){
        if(div=$("farm_inner_waltraud")){
            click(div);
        }
    }else if(div=$("speedlink_farm1")){
        document.addEventListener("gameFarmOpened",function(){
            document.removeEventListener("gameFarmOpened",arguments.callee,false);
            window.setTimeout(goToDonkey,100);
        },false);
        click(div);
    }
    div=null;
}catch(err){GM_logError("goToDonkey\n"+err);}
}

function showGoToMarketToolTip(event,prod,add1,add2){
    var str='<table>';
    str += '<tr><th colspan="2" class="lightBg">'+getText("goToMarketOfX").replace(/%1%/,prodName[0][prod])+'</th></tr>';
    if(add1){
        str += add1;
        str += '<tr><td colspan="2" style="border-bottom:1px solid black;"></td></tr>';
    }
    str += '<tr><td>'+getText("marketPrice")+'</td><td style="text-align:right;">'+(gut[prod]>=100?moneyFormatInt(gut[prod]):moneyFormat(gut[prod]))+'</td></tr>';
    str += '<tr><td>'+getText("inventory")+'</td><td style="text-align:right;">'+numberFormat(prodStock[0][prod])+'</td></tr>';
    str += '<tr><td>'+getText("value")+'</td><td style="text-align:right;">'+moneyFormatInt(gut[prod]*prodStock[0][prod])+'</td></tr>';
    if(add2){
        str += '<tr><td colspan="2" style="border-bottom:1px solid black;"></td></tr>';
        str += add2;
    }
    str += '</table>';
    toolTip.show(event,str);
    str=null;
}
function showStatisticFullscreen(pid){
    var mode=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_modeStatistic"),"showStatisticFullscreen/modeStatistic");
    var newdiv=createElement("div",{"style":"position:absolute;top:0;left:0;height:"+window.innerHeight+"px;width:"+window.innerWidth+"px;background-color:white;color:black;z-index:995;"},ALL,getText("loading")+"...");
    var url=STAT_VIEW[COUNTRY]+"/chart.php?w="+window.innerWidth+"&h="+window.innerHeight+"&t=h"+mode["time"]+"&shownpc="+(mode["npc"]?1:0)+"&clip=1&server1="+SERVER+"&product1="+pid+"&color1=green";
    var newobject=createElement("object",{"data":url,"type":"type=image/svg+xml","style":"position:absolute;top:0;left:0;","width":window.innerWidth+"px","height":window.innerHeight+"px"},newdiv);
    createElement("param",{"name":"src","value":url},newobject);
    var newimg=createElement("img",{"src":GFX+"close.jpg","class":"link","style":"position:absolute;top:30px;right:10px;z-index:2;"},newdiv);
    newimg.addEventListener("click",function(){removeElement(this.parentNode);},false);
    newimg=createElement("div",{"style":"position:absolute;top:0px;left:40%;padding:5px;z-index:2;border-width:0px 2px 2px 2px;border-style:solid;border-radius:0px 0px 10px 10px;background-color:white;"},newdiv);
    produktPic(0,pid,newimg);
    createElement("span",{"style":"font-weight:bold;"},newimg,prodName[0][pid]);
    newdiv=null;newobject=null;newimg=null;
}

function calcProductionTime(buildingType,productType,productId,bonus,feedTime,feedAmount){
// bonus like 0.85
try{
    var time;
    switch(buildingType){
    case 1:
    case "forest":
        time=calcGrowDuration(prodGrowTime[productType][productId]*60,bonus);
        break;
    case 2:
        var totalTime=prodGrowTime[productType][productId]*60*bonus;
        time=totalTime;
        if(!feedAmount){
            feedAmount=Math.ceil(totalTime/feedTime);
        }
        totalTime*=0.5;
        if(unsafeWindow.premium==0 && USERLEVEL>9){ totalTime+=5; } // hack: non-premiums cant feed completely
        for(var i=1;i<=feedAmount;i++){
            if(time-feedTime>=totalTime){
                time-=feedTime;
            } else { break; }
        }
        totalTime=null;
        time=[time,i-1];
        break;
    case 3:
    case 4:
        time=prodGrowTime[productType][productId]*60*bonus;
        break;
    case "windmill":
        time=parseInt(unsafeWindow.formulas[0][productId][4],10);
        //time*=bonus;
        break;
    case "forest":
        time=calcGrowDuration(prodGrowTime[productType][productId]*60,bonus);
        break;
    case "sawmill":
    case "carpentry":
        time=prodGrowTime[productType][productId]*60*bonus;
        break;
    }
    return time;
}catch(err){GM_logError("calcProductionTime product:"+[productType,productId]+" bonus="+bonus+" \n"+err);return 0;}
}
function calcGrowDuration(growDurationInitial,bonus){
//growDurationInitial in seconds, bonus like 0.85
    var gesamtdauer=0;
    while(growDurationInitial>0){
        growDurationInitial *= bonus;
        var help=Math.min(growDurationInitial,86400);
        growDurationInitial -= help;
        gesamtdauer += help;
    }
    return Math.round(gesamtdauer);
}
function calcGrowTimes(growDurationInitial,period,bonus){
    return period/calcGrowDuration(growDurationInitial,bonus);
}

// Zones
var zones=new function(){
    var data;
    const INIT_zoneItem={"animals":null,"block":"blpqs","bonus":0,"bonusSpecial":null,"building":null,"crop":[],"endproduct":null,"endtime":NEVER,"mainproduct":null,"production":[[{},{}],0,0,true],"slots":null,"watertime":NEVER};
    const INIT_zoneSlotItem={"block":"blpqs"};
    this.init=function(){
        try{
            data=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_zones","{}"),"zones.init/data",{});
            for(var zoneNrF in data){
                if(!data.hasOwnProperty(zoneNrF)){ continue; }
                if((typeof data[zoneNrF]!="object")||(data[zoneNrF] instanceof Array)){
                    zones.create(zoneNrF);
                }
            }
        }catch(err){GM_logError("zones.init\n"+err);}
    }
    this.save=function(){
        try{
            GM_setValueCache(COUNTRY+"_"+SERVER+"_"+USERNAME+"_zones",implode(data,"zones.save/data"));
        }catch(err){GM_logError("zones.save\n"+err);}
    }
    this.create=function(zoneNrF){
        try{
            data[zoneNrF]=INIT_zoneItem.clone();
            if(isNaN(zoneNrF)){
                var building;
                switch(zoneNrF){
                case "farmersmarket-0": building="fl0";break;
                case "farmersmarket-1": building="fl1";break;
                case "farmersmarket-2": building="fl2";break;
                case "farmersmarket-3": building="fl3";break;
                case "farmersmarket-4": building="fl4";break;
                case "farmersmarket-5": building="fl5";break;
                case "farmersmarket-6": building="fl6";break;
                case "windmill":        building="windmill";break;
                case "forest":          building="forest";break;
                case "sawmill":         building="sawmill";break;
                case "carpentry":       building="carpentry";break;
                case "foodworld-0":     building="fw0";break;
                case "foodworld-1":     building="fw1";break;
                case "foodworld-2":     building="fw2";break;
                case "foodworld-3":     building="fw3";break;
                case "foodworld-4":     building="fw4";break;
                default:                building=null;
                }
                zones.setBuilding(zoneNrF,building);
            }
        }catch(err){GM_logError("zones.create\n"+err);}
    }
    this.swap=function(zoneNr1,zoneNr2){
        try{
            if(data[zoneNr1]&&data[zoneNr1]){
                var help=data[zoneNr1].clone();
                data[zoneNr1]=data[zoneNr2].clone();
                data[zoneNr2]=help;
            }
        }catch(err){GM_logError("zones.swap\n"+err);}
    }   
    // Values
    this.setAnimals=function(zoneNrF,value){
        try{
            if(!data[zoneNrF]){
                zones.create(zoneNrF);
            }
            if(data[zoneNrF]["animals"]!=value){
                data[zoneNrF]["animals"]=value;
                zones.save();
                calcTotalAnimals();
            }
        }catch(err){GM_logError("zones.setAnimals\n"+err);}
    }
    this.getAnimals=function(zoneNr){
        try{
            var zoneNrF=zoneNr.toString().replace(/\.\d+$/g,"");
            if(data[zoneNrF]){
                return data[zoneNrF]["animals"];
            }else{
                return INIT_zoneItem["animals"];
            }
        }catch(err){GM_logError("zones.getAnimals\n"+err);}
    }
    this.setBlock=function(zoneNr,value){
        // b: payment
        // l: level requirement
        // p: premium-feature
        // q: quest
        // s: status
        // t: type (not handled)
        try{
            zoneNr=zoneNr.toString();
            var slot=(zoneNr.match(/\.(\d+)$/)?parseInt(/\.(\d+)$/.exec(zoneNr)[1],10):null);
            var zoneNrF=zoneNr.replace(/\.\d+$/g,"");
            if(!data[zoneNrF]){
                zones.create(zoneNrF);
            }
            if(slot){
                if(data[zoneNrF]["slots"][slot]["block"]!=value){
                    data[zoneNrF]["slots"][slot]["block"]=value;
                    zones.save();
                }
            }else if(data[zoneNrF]["block"]!=value){
                data[zoneNrF]["block"]=value;
                zones.save();
            }
        }catch(err){GM_logError("zones.setBlock zoneNr="+zoneNr+"\n"+implode(data[zoneNrF])+"\n"+err);}
    }
    this.getBlock=function(zoneNr){
        try{
            zoneNr=zoneNr.toString();
            var slot=(zoneNr.match(/\.(\d+)$/)?parseInt(/\.(\d+)$/.exec(zoneNr)[1],10):null);
            var zoneNrF=zoneNr.replace(/\.\d+$/g,"");
            if(!data[zoneNrF]){
                return INIT_zoneItem["block"];
            }else if(data[zoneNrF]["block"]){
                return data[zoneNrF]["block"];
            }else if(slot&&data[zoneNrF]["slots"]){
                return data[zoneNrF]["slots"][slot]["block"];
            }else{
                return "";
            }
        }catch(err){GM_logError("zones.getBlock zoneNr="+zoneNr+"\n"+err);}
    }
    this.setBonus=function(zoneNrF,value){
        try{
            if(!data[zoneNrF]){
                zones.create(zoneNrF);
            }
            if(data[zoneNrF]["bonus"]!=value){
                data[zoneNrF]["bonus"]=value;
                zones.save();
            }
        }catch(err){GM_logError("zones.setBonus\n"+err);}
    }
    this.getBonus=function(zoneNr){
        try{
            var zoneNrF=zoneNr.toString().replace(/\.\d+$/g,"");
            if(data[zoneNrF]){
                return data[zoneNrF]["bonus"];
            }else{
                return INIT_zoneItem["bonus"];
            }
        }catch(err){GM_logError("zones.getBonus\n"+err);}
    }
    this.setBonusSpecial=function(zoneNrF,value){
        try{
            if(!data[zoneNrF]){
                zones.create(zoneNrF);
            }
            if(data[zoneNrF]["bonusSpecial"]==null){
                if(value!=null){
                    data[zoneNrF]["bonusSpecial"]=value;
                    zones.save();
                }
            }else if((value==null)||(data[zoneNrF]["bonusSpecial"][0]!=value[0])||(data[zoneNrF]["bonusSpecial"][1]!=value[1])){
                data[zoneNrF]["bonusSpecial"]=value;
                zones.save();
            }
        }catch(err){GM_logError("zones.setBonusSpecial\n"+err);}
    }
    this.getBonusSpecial=function(zoneNr){
        try{
            var zoneNrF=zoneNr.toString().replace(/\.\d+$/g,"");
            if(data[zoneNrF]){
                return data[zoneNrF]["bonusSpecial"];
            }else{
                return INIT_zoneItem["bonusSpecial"];
            }
        }catch(err){GM_logError("zones.getBonusSpecial\n"+err);}
    }
    this.setBuilding=function(zoneNrF,value){
        /*  BUILDING    NAME                    TYPE        
            0           empty       
            1           Field                   Field       
            2           Chickens                Stable      
            3           Cows                    Stable      
            4           Sheep                   Stable      
            5           Bees                    Stable      
            6           Clubhouse
            7           Cheese                  Factory 
            8           Mayo                    Factory 
            9           Whool                   Factory 
            10          Bonbons                 Factory 
            11          Fishs                   Stable  
            12          Goats                   Stable  
            13          Oil                     Factory 
            14          Special-Oil             Factory 
            15          Angora shed             Stable  
            16          Knitting mill           Factory 
            17          Architectural office
            18          Pony farm
            19          Megafield               Factory
            fw1         Soda stall              Foodworld
            fw2         Snack booth             Foodworld
            fw3         Pastry shop             Foodworld
            fl1         Flower meadow           Farmersmarket
            fl2         Flower workshop         Farmersmarket
            fl3                                 Farmersmarket
        */  
        try{
            if(!data[zoneNrF]){
                zones.create(zoneNrF);
            }
            if(data[zoneNrF]["building"]!=value){
                data[zoneNrF]["building"]=value;
                switch(value){
                case 13: // Oil
                case 14: // Special oil
                case 16: // Knitting
                case "windmill":
                case "sawmill": case "carpentry":
                case "fw1": case "fw2": case "fw3": // Foodworld
                case "fl2": // Flowers
                    data[zoneNrF]["slots"]=[];
                    for(var i=1;i<=3;i++){
                        data[zoneNrF]["slots"][i]=INIT_zoneSlotItem.clone();
                    }
                break;
                default:
                    data[zoneNrF]["slots"]=null;
                }               
                zones.save();
            }
        }catch(err){GM_logError("zones.setBuilding\n"+err);}
    }
    this.getBuilding=function(zoneNr){
        try{
            var zoneNrF=zoneNr.toString().replace(/\.\d+$/g,"");
            if(data[zoneNrF]){
                return data[zoneNrF]["building"];
            }else{
                return INIT_zoneItem["building"];
            }
        }catch(err){GM_logError("zones.getBuilding zoneNr="+zoneNr+"\n"+err);}
    }
    this.getBuildingName=function(zoneNr){
        try{
            return getBuildingName(zones.getBuilding(zoneNr));
        }catch(err){GM_logError("zones.getBuildingName\n"+err);}
    }
    this.getLocation=function(zoneNr){
        try{
            var zoneNrF=zoneNr.toString().replace(/\.\d+$/g,"");
            if(DATA_zones[zoneNrF]){
                return DATA_zones[zoneNrF];
            }else{
                GM_logWarning("getLocation returns null\nzoneNr="+zoneNr);
                return null;
            }
        }catch(err){ GM_logError("getLocation\n"+err);return null; }
    }   
    // Production
    this.setProduction=function(zoneNrS,value){
        // production[0][i]={"id":item,...}
        // i = product-type
        // case production : item=[[amount,points,endtime,nextwatertime],...]
        // - amount : amount of production with these times
        // - points : points given for this production
        // - endtime : time of cropping (without future waterings)
        // - nextwatertime : NEVER if not possible to water in future
        // case deco : item=[[amount1,time1],[amount2,time2],...]
        // case garbage : item=amount
        // production[1]=[,int,int,,int]||int : free places for currently planting with that size
        // production[2]=[,int,int,,int]||int : free places for possibly planting with that size (cropped field)
        // production[3]=true||false : flag if data is ready    
        try{
            if(!data[zoneNrS]){
                zones.create(zoneNrS);
            }
            data[zoneNrS]["production"]=value;
            zones.processProduction(zoneNrS);
        }catch(err){GM_logError("zones.setProduction\n"+err);}
    }
    this.getProduction=function(zoneNrS){
        try{
            if(data[zoneNrS]){
                return data[zoneNrS]["production"];
            }else{
                return INIT_zoneItem["production"];
            }
        }catch(err){GM_logError("zones.getProduction\n"+err);}
    }
    this.processProduction=function(zoneNrS){
        try{
            if(DEVMODE_FUNCTION){ var trackingHandle = tracking.start("berater","zones.processProduction",[zoneNrS]); }
                var err_trace="begin";
                var zoneNrF=zoneNrS.toString().replace(/\.\d+$/g,"");
                var help;
                data[zoneNrS]["crop"]=new Array();
                data[zoneNrS]["endtime"]=NEVER;
                data[zoneNrS]["endproduct"]=null;
                data[zoneNrS]["watertime"]=NEVER;
                data[zoneNrS]["mainproduct"]=null;
                if(!zones.getBlock(zoneNrS)){
                    var currLocation=zones.getLocation(zoneNrS).location;
                    var currBonus=zones.getBonus(zoneNrS);
                    var currBonusSpecial=zones.getBonusSpecial(zoneNrS);
                    var zoneErnteCurr=new Object();
                    var iZoneTyp=zones.getBuilding(zoneNrS);
                    var isProductional=zones.isProductional(zoneNrS);
                    var nowServer=unsafeWindow.Zeit.Server;
                    var c=0,item;
                    err_trace="product loop";
                    for(var iType=0;iType<data[zoneNrS]["production"][0].length;iType++){
                        for(var iProdStr in data[zoneNrS]["production"][0][iType]){
                            if(!data[zoneNrS]["production"][0][iType].hasOwnProperty(iProdStr)){ continue; }
                            var iProd = parseInt(iProdStr,10);
                            if((prodTyp[iType][iProd]!="u")&&(prodTyp[iType][iProd]!="z")){ // only products
                                item=data[zoneNrS]["production"][0][iType][iProdStr];
                                for(var i=0;i<item.length;i++){
                                    var z=item[i][2];
                                    var w=item[i][3];
                                    if (data[zoneNrS]["mainproduct"]==iProd){ c += item[i][0]; }
                                    else{ c -= item[i][0]; }
                                    if (c<1){
                                        data[zoneNrS]["mainproduct"]=iProd;
                                        c=item[i][0];
                                    }
                                    if (!zoneErnteCurr[iType]){ zoneErnteCurr[iType]={}; }
                                    if (!zoneErnteCurr[iType][iProdStr]){ zoneErnteCurr[iType][iProdStr]=[0,0]; }
                                    zoneErnteCurr[iType][iProdStr][0] += item[i][0]; 
                                    zoneErnteCurr[iType][iProdStr][1] += item[i][1];
                                    if(w){
                                        data[zoneNrS]["watertime"]=Math.min(data[zoneNrS]["watertime"],w);
                                        if(valAssumeWater[currLocation]&&(nowServer<=z)&&(w<=z)){
                                            // calculate future watering
                                            // w<nowServer means that now can be watered. because it isnt watered, assume that watering is not wanted
                                            // if (nowServer<=w){
                                            w=Math.max(0,Math.min(86400,w-nowServer)); // time till watering
                                            z-=nowServer; // remaining time
                                            z=nowServer+w+calcGrowDuration(z-w,(100-currBonus-((currBonusSpecial&&(iProd==currBonusSpecial[0]))?currBonusSpecial[1]:0))/100);
                                        }
                                    }
            
                                    if (z < data[zoneNrS]["endtime"]){
                                        data[zoneNrS]["endtime"]=z;
                                        data[zoneNrS]["endproduct"]=iProd;
                                    }
                                }
                            }
                        }
                    }
                    if(isProductional){
                        for(var iTypeStr in zoneErnteCurr){
                            if(!zoneErnteCurr.hasOwnProperty(iTypeStr)){ continue; }
                            for(var iProdStr in zoneErnteCurr[iTypeStr]){
                                if(!zoneErnteCurr[iTypeStr].hasOwnProperty(iProdStr)){ continue; }
                                if(iTypeStr=="0"){
                                    // zoneErnteCurr[iTypeStr][iProdStr][0] /= 10; // Fix Seberoth ... why ... TODO!
                                }
                                data[zoneNrS]["crop"].push([parseInt(iTypeStr,10),parseInt(iProdStr,10)].concat(zoneErnteCurr[iTypeStr][iProdStr]));
                            }
                        }
                    }
                    // too many empty fields
                    err_trace="empty fields";
                    if(now<data[zoneNrS]["endtime"]){
                        if(!isNaN(valLimitEmptyFields[iZoneTyp])){
                            if(data[zoneNrS]["production"][1][1]>valLimitEmptyFields[iZoneTyp]){
                                data[zoneNrS]["endtime"]=NEVER;
                                data[zoneNrS]["endproduct"]=null;
                            }
                        }else if(valGlobaltimeShowCroppedZone[currLocation]&&(data[zoneNrS]["production"][1][1]>0)){
                            data[zoneNrS]["endtime"]=NEVER;
                            data[zoneNrS]["endproduct"]=null;
                        }
                    }
                    // create watering timer
                    if(iZoneTyp==1){
                        var farmNR=Math.floor((zoneNrF-1)/6)+1;
                        var zoneNr=zoneNrF-6*(farmNR-1);
                        createZoneTimer("zoneTimerWater_"+zoneNrS,zoneNrS,"zoneTimerWater","top:20px;left:5px;",$("farm"+farmNR+"_pos"+zoneNr));
                    }
                }
                err_trace="readyZone";
                zones.checkReady(zoneNrS);
                err_trace="timer";
                updateZoneTimer("zoneTimer_"+zoneNrS,zoneNrS,"zonetimer");
                updateZoneTimer("zoneTimerWater_"+zoneNrS,zoneNrS,"zoneTimerWater");
                updateZoneTimer("globalZoneTimer_"+zoneNrS,zoneNrS,"zonetimer");
                updateZoneTimer("globalZoneTimerWater_"+zoneNrS,zoneNrS,"zoneTimerWater");
                calcTotalEndtime();
                zones.save();
                if(DEVMODE_FUNCTION){ tracking.end("berater",trackingHandle); }
            }catch(err){ GM_logError("zones.processProduction ("+err_trace+") zoneNrS="+zoneNrS+" iProdStr="+iProdStr+" \n"+err); }
    }
    this.flagProduction=function(zoneNrS){
        try{
            if(!data[zoneNrS]){
                zones.create(zoneNrS);
            }
            data[zoneNrS]["production"][3]=false;
        }catch(err){GM_logError("zones.flagProduction\n"+err);}
    }
    this.getEndproduct=function(zoneNr){
        try{
            if(data[zoneNr]&&data[zoneNr]["endproduct"]){
                return data[zoneNr]["endproduct"];
            }else{
                return INIT_zoneItem["endproduct"];
            }
        }catch(err){GM_logError("zones.getEndproduct\n"+err);}
    }
    this.getEndtime=function(zoneNr){
        try{
            if(data[zoneNr]&&data[zoneNr]["endtime"]){
                return data[zoneNr]["endtime"];
            }else{
                return INIT_zoneItem["endtime"];
            }
        }catch(err){GM_logError("zones.getEndtime\n"+err);}
    }
    this.getWatertime=function(zoneNr){
        try{
            if(data[zoneNr]&&data[zoneNr]["watertime"]){
                return data[zoneNr]["watertime"];
            }else{
                return INIT_zoneItem["watertime"];
            }
        }catch(err){GM_logError("zones.getWatertime\n"+err);}
    }
    this.getCrop=function(zoneNr){
    // {"prodId1":[amount1,points1],"prodId2":[amount2,points2],...}
        try{
            if(data[zoneNr]&&data[zoneNr]["crop"]){
                return data[zoneNr]["crop"];
            }else{
                return INIT_zoneItem["crop"];
            }
        }catch(err){GM_logError("zones.getCrop\n"+err);}
    }
    this.getMainproduct=function(zoneNr){
        try{
            if(data[zoneNr]&&data[zoneNr]["mainproduct"]){
                return data[zoneNr]["mainproduct"];
            }else{
                return INIT_zoneItem["mainproduct"];
            }
        }catch(err){GM_logError("zones.getMainproduct\n"+err);}
    }
    this.checkReady=function(zoneNrS){
        try{
            var readyZoneAdded=0;
            if((!zones.getBlock(zoneNrS))&&(zones.isProductional(zoneNrS))){
                var zoneNrF=zoneNrS.toString().replace(/\.\d+$/g,"");
                var farmNR=Math.floor((zoneNrF-1)/6)+1;
                var zoneNr=zoneNrF-6*(farmNR-1);
                var currZoneType=zones.getBuilding(zoneNrF);
                var currLocation=zones.getLocation(zoneNrF);
                var zT=zones.getEndtime(zoneNrS);
                var zTw=zones.getWatertime(zoneNrS);
                var div;
    
                if (zT==NEVER){ // empty
                    if(unsafeData.readyZone[zoneNrS]&&(unsafeData.readyZone[zoneNrS][1]=="e")){
                        if(!unsafeData.readyZone[zoneNrS][2]){ unsafeData.readyZone[zoneNrS][2]=true; }
                    }else{
                        unsafeData.readyZone[zoneNrS]=[currLocation.farmNr==undefined?currLocation.location:currLocation.farmNr,"e",true];
                        readyZoneAdded=1;
                    }
                    if((currZoneType==1)&&(div=$("farm_production_ready"+farmNR+"_"+zoneNr))){
                        div.setAttribute("class","farm_production_ready1 fieldReady");
                    }
                }else if(zT<=unsafeWindow.Zeit.Server){ //READY
                    if(unsafeData.readyZone[zoneNrS]&&(unsafeData.readyZone[zoneNrS][1]=="r")){
                        if(!unsafeData.readyZone[zoneNrS][2]){ unsafeData.readyZone[zoneNrS][2]=true; }
                    }else{
                        if(DEVMODE){GM_log("checkReady readyZone add=READY zoneNrS="+zoneNrS);}
                        unsafeData.readyZone[zoneNrS]=[currLocation.farmNr==undefined?currLocation.location:currLocation.farmNr,"r",true];
                        readyZoneAdded=1;
                    }
                    if((currZoneType==1)&&(div=$("farm_production_ready"+farmNR+"_"+zoneNr))){
                        div.setAttribute("class","farm_production_ready1 fieldReady");
                    }
                // running (unsafeWindow.Zeit.Server<zT)
                }else if(valWaterNeeded[currLocation.location]&&(zTw<unsafeWindow.Zeit.Server)&&(zones.getBonus(zoneNrF)>0)){
                    //zTw<zT removes the watertimer if ready later then the field timer
                    if(unsafeData.readyZone[zoneNrS]&&(unsafeData.readyZone[zoneNrS][1]=="w")){
                        if(!unsafeData.readyZone[zoneNrS][2]){ unsafeData.readyZone[zoneNrS][2]=true; }
                    }else{
                        if(DEVMODE){GM_log("checkReady readyZone add:WATER zoneNrS:"+zoneNrS);}
                        unsafeData.readyZone[zoneNrS]=[currLocation.farmNr==undefined?currLocation.location:currLocation.farmNr,"w",true];
                        readyZoneAdded=1;
                    }
                    if((currZoneType==1)&&(div=$("farm_production_ready"+farmNR+"_"+zoneNr))){
                        div.setAttribute("class","farm_production_ready1 fieldWaterReady blinking");
                    }
                }else if(unsafeData.readyZone[zoneNrS]){
                    if(DEVMODE){GM_log("checkReady readyZone add:DELETE zoneNrS:"+zoneNrS);}
                    delete unsafeData.readyZone[zoneNrS];
                    if((currZoneType==1)&&(div=$("farm_production_ready"+farmNR+"_"+zoneNr))){
                        div.setAttribute("class","farm_production_ready1");
                    }
                }
                div=null;
            }
            return readyZoneAdded;
        }catch(err){GM_logError("zones.checkReady zoneNrS="+zoneNrS+"\n"+err);}
    }
    // Type
    this.isMultiSlot=function(zoneNrF){
    try{
        if(!data[zoneNrF]){
            zones.create(zoneNrF);
        }
        if(data[zoneNrF]["slots"]==null){
            return false;
        }else{
            return true;
        }
    }catch(err){GM_logError("isMultiSlot\n"+err);}
    }
    this.isProductional=function(zoneNr){
        try{
            var zoneNrF=zoneNr.toString().replace(/\.\d+$/g,"");
            if(DATA_zones[zoneNrF]){
                return DATA_zones[zoneNrF]["productional"];
            }else{
                GM_logWarning("zones.isProductional returns null\nzoneNr="+zoneNr);
                return null;
            }
        }catch(err){ GM_logError("zones.isProductional\n"+err);return null; }
    }
}
unsafeData.zones=zones;
function getBuildingName(building){
    try{
        if(unsafeWindow.buildinginfos[0][building]){
            return unsafeWindow.buildinginfos[0][building][10];
        }else if(getText(building)){
            return getText(building);
        }else{
            return "???";
        }
    }catch(err){GM_logError("getBuildingName\n"+err);}
}
// Totals
function calcTotalRecursive(recursionCount,stack){
try{
 if(DEVMODE_FUNCTION){ var trackingHandle = tracking.start("berater","calcTotalRecursive",[recursionCount]); }
    if(recursionCount>100){throw("TOO MUCH RECURSION")}
    var err_trace="init";
    var help;
    var next=false;
    var nextStack={};
    if(!stack){
        totalRecursive=new Array(new Object(),new Object(),new Object(),new Object());
        stack=prodStock.clone();
        for(var type in prodMinRack){
            if(!prodMinRack.hasOwnProperty(type)){ continue; }
            for(var iProd in prodMinRack[type]){
                if (!prodMinRack[type].hasOwnProperty(iProd)){ continue; }
                if(!stack[type]){ stack[type]={}; }
                stack[type][iProd]-=prodMinRack[type][iProd];
            }
        }
    }
    err_trace="step";
    for(var type in stack){
        if(!stack.hasOwnProperty(type)){ continue; }
        for(var iProd in stack[type]){
            if(!stack[type].hasOwnProperty(iProd)){ continue; }
            if(stack[type][iProd]<0){
                if((typeof prodRequire[type][iProd]=="object")&&(totalZones[PRODUCT2BUILDING[type][iProd]]>0)){
                    err_trace="prodRequire";
                    for(var i=0;i<prodRequire[type][iProd].length;i++){
                        err_trace="prodRequire "+i;
                        if(prodRequire[type][iProd][i][0]>-1){
                            help=-stack[type][iProd]/prodYield[type][iProd]*prodRequire[type][iProd][i][2];
                            if(!nextStack[prodRequire[type][iProd][i][0]]){
                                nextStack[prodRequire[type][iProd][i][0]]={}; 
                            }
                            if(!nextStack[prodRequire[type][iProd][i][0]][prodRequire[type][iProd][i][1]]){
                                nextStack[prodRequire[type][iProd][i][0]][prodRequire[type][iProd][i][1]]=0;
                            }
                            next=true;
                            nextStack[prodRequire[type][iProd][i][0]][prodRequire[type][iProd][i][1]]-=help;
                            if(!totalRecursive[prodRequire[type][iProd][i][0]][prodRequire[type][iProd][i][1]]){
                                totalRecursive[prodRequire[type][iProd][i][0]][prodRequire[type][iProd][i][1]]=0;
                            }
                            totalRecursive[prodRequire[type][iProd][i][0]][prodRequire[type][iProd][i][1]]+=help;
                        }
                    }
                }

            }       
        }
    }
    if(next){ calcTotalRecursive(++recursionCount,nextStack); }
 if(DEVMODE_FUNCTION){ tracking.end("berater",trackingHandle); }
}catch(err){ GM_logError("calcTotalRecursive ("+err_trace+")\ntype="+type+" iProd="+iProd+" help="+implode(help)+" i="+i+"\n"+err); }
}
function calcTotalErnte(){
    try{
        var help;
        totalErnte=new Array(new Object(),new Object(),new Object(),new Object());
        for(var i in ALL_ZONES){
            if(!ALL_ZONES.hasOwnProperty(i)){ continue; }
            for(var j=0;j<ALL_ZONES[i].length;j++){
                try{
                    var zoneNrF=ALL_ZONES[i][j];
                    if(help=zones.getCrop(zoneNrF)){
                        for(var k=0;k<help.length;k++){
                            if(!totalErnte[help[k][0]][help[k][1]]){ totalErnte[help[k][0]][help[k][1]]=0; }
                            totalErnte[help[k][0]][help[k][1]] += help[k][2];
                        }
                    }
                }catch(err){ GM_logError("calcTotalErnte loop\ni="+i+" j="+j+" zoneNrF="+zoneNrF+" help="+implode(help)+"\n"+err); }
            }
        }
        //GM_log("calcTotalErnte totalErnte:"+implode(totalErnte));
    }catch(err){ GM_logError("calcTotalErnte\nzoneNrF="+zoneNrF+"\n"+err); }
}
function calcTotalFarmis(){
    try{
        totalFarmis[0]=new Object();
        var farmiNr=-1;
        // GM_log("farmisinfo:\n"+print_r(unsafeWindow.farmisinfo,"",true,"\n"));       
        // GM_log("farmilist:\n"+print_r(unsafeWindow.farmilist,"",true,"\n"));     
        if(top.window.wrappedJSObject.farmisinfo&&top.window.wrappedJSObject.farmisinfo[0]){
            for(var farmiNr in top.window.wrappedJSObject.farmisinfo[0]){ // loop through all farmis...
                if(!top.window.wrappedJSObject.farmisinfo[0].hasOwnProperty(farmiNr)){continue;}
                if(top.window.wrappedJSObject.farmilist[farmiNr]==1){ // ...which are waiting...
                    // {"id":integer(string),"pic":integer(string),"verkauft":"0","price":float(string),"p1":prod(string),"a1":amount(string),...,"p7":...,"a7":...}
                    if(valFarmiLimits[0]<=top.window.wrappedJSObject.farmisinfo[0][farmiNr]["costQuotient"]){ // ...and pay enough
                        for(var i=1 ; i <= 7 ; i++){ // 7=max-amount of products per farmi
                            var pid=top.window.wrappedJSObject.farmisinfo[0][farmiNr]["p"+i];
                            var amount=parseInt(top.window.wrappedJSObject.farmisinfo[0][farmiNr]["a"+i],10);
                            if((pid > 0) && (amount > 0)){
                                if (totalFarmis[0][pid]) totalFarmis[0][pid] += amount;
                                else totalFarmis[0][pid]=amount;
                            }
                        }
                    }
                }
            }
            // totalFarmis[0].sortObj();
        }
    }catch(err){GM_logError("calcTotalFarmis \n"+err);}
    //GM_log("calcTotalFarmis totalFarmis:"+implode(totalFarmis[0]));
    //calcProdMinRack(); //TODO possible security error this in wrappedJSObject .. and the calcProMinRack/doBuyNotePad is in unsafeWindow
}
function calcTotalPowerups(){
try{
    totalPowerups=new Object();
    if(unsafeWindow.poweruprack){
        for(var v in unsafeWindow.poweruprack){
            if(!unsafeWindow.poweruprack.hasOwnProperty(v)){continue;}
            if(unsafeWindow.poweruprack[v][5] && unsafeWindow.poweruprack[v][5][0]){ //problem in the game made this visible
                var k=parseInt(unsafeWindow.poweruprack[v][5][0][0],10);
                totalPowerups[k]=parseInt(unsafeWindow.poweruprack[v]["rack"],10)*parseInt(unsafeWindow.poweruprack[v][5][0][1],10);
            }
        }
    }
    //GM_log("calcTotalPowerups totalPowerups:"+implode(totalPowerups));
}catch(err){ GM_logError("calcTotalPowerups\n"+err); }
}
function calcTotalQuest(quTyp){
    try{
        // GM_log("calcTotalQuest quTyp="+quTyp);
        totalQuest[quTyp]=new Array(new Object(),new Object());
        var questCurr;
        for(var camp in questData[quTyp]){
            if (!questData[quTyp].hasOwnProperty(camp)){ continue; }
            // GM_log("calcTotalQuest camp="+camp);
            // GM_log("questData["+quTyp+"]["+camp+"]="+implode(questData[quTyp][camp]));
            if(questData[quTyp][camp]["calcTo"]>0){
                questCurr=questData[quTyp][camp]["data"];
                // GM_log("calcTotalQuest questCurr="+implode(questCurr));
                if(questCurr&&questCurr[0]){
                    for(var j=0;j<questCurr[0].length;j++){
                        if(questCurr[0][j][3]){
                            if(!totalQuest[quTyp][questCurr[0][j][0]][questCurr[0][j][1]]){ totalQuest[quTyp][questCurr[0][j][0]][questCurr[0][j][1]]=0; }
                            totalQuest[quTyp][questCurr[0][j][0]][questCurr[0][j][1]]+=questCurr[0][j][2];
                        }
                    }               
                }               
                for(var pTyp in questData[quTyp][camp]["given"]){
                    if (!questData[quTyp][camp]["given"].hasOwnProperty(pTyp)){ continue; }
                    for(var p in questData[quTyp][camp]["given"][pTyp]){
                        if (!questData[quTyp][camp]["given"][pTyp].hasOwnProperty(p)){ continue; }
                        if(totalQuest[quTyp][pTyp]&&totalQuest[quTyp][pTyp][p]){
                            totalQuest[quTyp][pTyp][p]=Math.max(0,totalQuest[quTyp][pTyp][p]-questData[quTyp][camp]["given"][pTyp][p]);
                        }
                    }
                }
                for(var q=questData[quTyp][camp]["nr"]+1;q<=questData[quTyp][camp]["calcTo"];q++){
                    // GM_log("calcTotalQuest q="+q);
                    if(QUESTS[quTyp][camp][q]){
                        for(var j=0;j<QUESTS[quTyp][camp][q][0].length;j++){
                            questCurr=getQuestBestAlternative(QUESTS[quTyp][camp][q][0][j]);
                            if(!totalQuest[quTyp][questCurr[0]][questCurr[1]]){ totalQuest[quTyp][questCurr[0]][questCurr[1]]=0; }
                            totalQuest[quTyp][questCurr[0]][questCurr[1]]+=questCurr[2];
                        }
                    }
                }
            }
        }
        // GM_log("totalQuest["+quTyp+"]="+implode(totalQuest[quTyp]));
    }catch(err){ GM_logError("calcTotalQuest quTyp="+quTyp+" camp="+camp+" q="+q+"\n"+err); }
    // GM_log("calcTotalQuest END");
}
function calcTotalZones(){
try{
    totalZones=new Object();
    var zoneNrF,currZoneTyp;
    for(var i in ALL_ZONES){
        if(!ALL_ZONES.hasOwnProperty(i)){ continue; }
        for(var j=0;j<ALL_ZONES[i].length;j++){
            try{
                zoneNrF=ALL_ZONES[i][j];
                if(!zones.getBlock(zoneNrF)){
                    currZoneTyp=zones.getBuilding(zoneNrF)
                    if(!totalZones[currZoneTyp]){
                        totalZones[currZoneTyp]=0; 
                    }
                    totalZones[currZoneTyp]++;
                }
            }catch(err){ GM_logError("calcTotalErnte loop\ni="+i+" j="+j+" zoneNrF="+zoneNrF+"\n"+err); }
        }
    }
}catch(err){ GM_logError("calcTotalZones\n"+err); }
}
function calcTotalAnimals(){
try{
    totalAnimals=[,,0,0,0,0,,,,,,0,0];
    var help;
    for(var i=0;i<ALL_ZONES["farm"].length;i++){
        help=zones.getAnimals(ALL_ZONES["farm"][i]);
        if(help>0){
            totalAnimals[zones.getBuilding(ALL_ZONES["farm"][i])]+=help;
        }
    }
}catch(err){ GM_logError("calcTotalAnimals\n"+err); }
}
function calcTotalEndtime(){                
    try{
        totalEndtime=NEVER;
        for(var i in ALL_ZONES){
            if(!ALL_ZONES.hasOwnProperty(i)){ continue; }
            for(var j=0;j<ALL_ZONES[i].length;j++){
                zoneNrF=ALL_ZONES[i][j];
                if((!zones.getBlock(zoneNrF))&&(zones.getBuilding(zoneNrF)!=0)&&((i=="farm")||zoneAddToGlobalTime[zoneNrF])){
                    help=zones.getEndtime(zoneNrF);
                    if(help==NEVER){
                        if(valGlobaltimeShowCroppedZone[i]){
                            totalEndtime=-1;
                            GM_setValueCache(COUNTRY+"_"+SERVER+"_"+USERNAME+"_totalEndtime",totalEndtime);
                            return;
                        }
                    }else{
                        totalEndtime=Math.min(totalEndtime,help);
                        if(valWaterNeeded[i]){
                            totalEndtime=Math.min(totalEndtime,zones.getWatertime(zoneNrF));
                        }
                    }
                }
            }
        }
        GM_setValueCache(COUNTRY+"_"+SERVER+"_"+USERNAME+"_totalEndtime",totalEndtime);
    }catch(err){ GM_logWarning("calcTotalEndtime\ni="+i+" j="+j+" zoneNrF="+zoneNrF+"\n"+err); }
}
// calcProdMinRackInit: sets base values
// -> calcProdMinRack: adds quests, farmis, growing, addons, forestry 
// (calls calcTotalQuest,calcTotalErnte)
// -> doBuyNotepad, doRack, TODO doFarmis!
// TODO: switch this logic to: calcTotalX -> calcProdMinRack
function calcProdMinRackInit(){
    try{
    if(DEVMODE_FUNCTION){ var trackingHandle = tracking.start("berater","calcProdMinRackInit"); }
        prodMinRackInit=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_prodMinRackInit"),"calcProdMinRackInit/prodMinRackInit",[[],{},{},{}]);
        if(!(prodMinRackInit instanceof Array)){ prodMinRackInit=[]; }
        for(var type in prodName){
            if(!prodName.hasOwnProperty(type)){continue;}
            if(type==1){
                if((!prodMinRackInit[type])||(typeof prodMinRackInit[type]!="object")||(prodMinRackInit[type] instanceof Array)){ prodMinRackInit[type]={}; } 
            }else{
                if((!prodMinRackInit[type])||(!(prodMinRackInit[type] instanceof Array))){ prodMinRackInit[type]=[]; } 
            }
            if(!valMinRackMan){ // detail-setting option (else see buildPreise)
                for(var prod in prodName[type]){
                    //GM_log("prodName type:"+type+" prod:"+prod);
                    if(!prodName[type].hasOwnProperty(prod)){continue;}
                    if((!valMinRack[prodTyp[type][prod]])||(prodBlock[type][prod])){ // .match(/t/)
                        prodMinRackInit[type][prod]=0;
                    }else if(prodTyp[type][prod]=="v"){
                        prodMinRackInit[type][prod]=valMinRack[prodTyp[type][prod]]/(valMinRackPlantsize?prodPlantSize[type][prod]:1);
                    }else{
                        prodMinRackInit[type][prod]=valMinRack[prodTyp[type][prod]];
                    }
                }
            }
            // prodMinRackInit[type].sortObj();
        }
        GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_prodMinRackInit",implode(prodMinRackInit,"calcProdMinRackInit\prodMinRackInit"));
        unsafeData.prodMinRackInit=prodMinRackInit.clone();
        calcProdMinRack();
    if(DEVMODE_FUNCTION){ tracking.end("berater",trackingHandle); }
    }catch(err){ GM_logError("calcProdMinRackInit\ntype="+type+" prod="+prod+"\n"+err); }
}
function calcProdMinRack(caller){
        try{
        if(DEVMODE){ GM_log("begin calcProdMinRack"); }
        prodMinRack=prodMinRackInit.clone();
        // Quest
        var err_trace="quest";
        for(var quTyp in QUESTS){
            if(!QUESTS.hasOwnProperty(quTyp)){ continue; }
            calcTotalQuest(quTyp);
            for(var type in totalQuest[quTyp]){
                if(!totalQuest[quTyp].hasOwnProperty(type)){ continue; }
                for(var prod in totalQuest[quTyp][type]){
                    if(!totalQuest[quTyp][type].hasOwnProperty(prod)){ continue; }
                    if(!prodMinRack[type][prod]){prodMinRack[type][prod]=0;}
                    prodMinRack[type][prod] += totalQuest[quTyp][type][prod];
                }
            }
        }
        // Farmis
        err_trace="farmis";
        if(valMinRackFarmis){
            for(var prod in totalFarmis[0]){
                if(!totalFarmis[0].hasOwnProperty(prod)){ continue; }
                if(!prodMinRack[0][prod]){ prodMinRack[0][prod]=0;}
                prodMinRack[0][prod] += totalFarmis[0][prod];
            }
        }
        if(valMinRackForestryFarmis){
            for(var prod in totalFarmis[1]){
                if(!totalFarmis[1].hasOwnProperty(prod)){ continue; }
                if(!prodMinRack[1][prod]){ prodMinRack[1][prod]=0;}
                prodMinRack[1][prod] += totalFarmis[1][prod];
            }
        }
        // Addons
        err_trace="prodMinRackAddon";
        for(var type in prodMinRackAddon){
            if (!prodMinRackAddon.hasOwnProperty(type)){ continue; }
            for(var prod in prodMinRackAddon[type]){
                if(!prodMinRackAddon[type].hasOwnProperty(prod)){ continue; }
                if(prodMinRackAddon[type][prod]){
                    for(var k in prodMinRackAddon[type][prod]){
                        if(!prodMinRackAddon[type][prod].hasOwnProperty(k)){ continue; }
                        if(!prodMinRack[type][prod]){prodMinRack[type][prod]=0;}
                        prodMinRack[type][prod] += prodMinRackAddon[type][prod][k];
                    }
                }
            }
        }
        // Growing products
        err_trace="growing";
        if(valMinRackGrowing){
            calcTotalErnte();
            for(var type in totalErnte){
                if (!totalErnte.hasOwnProperty(type)){ continue; }
                for(var prod in totalErnte[type]){
                    if(!totalErnte[type].hasOwnProperty(prod)){ continue; }
                    if(!prodMinRack[type][prod]){prodMinRack[type][prod]=0;}
                    prodMinRack[type][prod] -= totalErnte[type][prod];
                }
            }
            for(var prod in totalPowerups){
                if(!totalPowerups.hasOwnProperty(prod)){ continue; }
                if(!prodMinRack[0][prod]){prodMinRack[0][prod]=0;}
                prodMinRack[0][prod] -= totalPowerups[prod];
            }
        }
        err_trace="recursive";
        //GM_log("Before calcTotalRecursive prodMinRack:"+implode(prodMinRack[1]));
        if(valMinRackRecursive){
            calcTotalRecursive(1); // recursive need products calculation
            for(var type in totalRecursive){
                if (!totalRecursive.hasOwnProperty(type)){ continue; }
                for(var prod in totalRecursive[type]){
                    if(!totalRecursive[type].hasOwnProperty(prod)){ continue; }
                    if(!prodMinRack[type][prod]){ prodMinRack[type][prod]=0; }
                    prodMinRack[type][prod] += totalRecursive[type][prod];
                }
            }
        }
        //GM_log("After calcTotalRecursive totalRecursive:"+implode(totalRecursive));
        //GM_log("After calcTotalRecursive prodMinRack:"+implode(prodMinRack[1]));
        //GM_log("After calcTotalRecursive prodStock:"+implode(prodStock[1]));
        
        // delete wrong values
        err_trace="QA";
        for(var type in prodMinRack){
            if (!prodMinRack.hasOwnProperty(type)){ continue; }
            for(var prod in prodMinRack[type]){
                if(!prodMinRack[type].hasOwnProperty(prod)){ continue; }
                try{ 
                    if(prodMinRack[type][prod]<0){ // delete negatives
                        prodMinRack[type][prod]=0;
                    }else if((type==0)&&(prodBlock[0][prod].match(/l/))){ // delete non-availables
                        prodMinRack[type][prod]=0;
                    }
                }catch(err){}
            }
        }

        err_trace="save";
        unsafeData.prodMinRack=prodMinRack.clone();
        unsafeData.prodMinRackSettings = {"valMinRackGrowing":valMinRackGrowing,"valMinRackFarmis":valMinRackFarmis,"valMinRackFarmis":valMinRackFarmis,"valMinRackRecursive":valMinRackRecursive};
        GM_setValueCache(COUNTRY+"_"+SERVER+"_"+USERNAME+"_prodMinRack",implode(prodMinRack));
        doBuyNotepad();
        doRack();
        doFarmis();
        raiseEvent("gameCalcProdMinRack");
        if(DEVMODE){ GM_log("end calcProdMinRack"); }
        }catch(err){ GM_logError("calcProdMinRack ("+err_trace+")\ntype="+type+" prod="+prod+"\n"+err); }
    }

function getQuestBestAlternative(arr){
// item=[prodType,prodId,amount]. arr=item or arr=[item,item,...]
    if(typeof arr[0]=="object"){
        var returnId,minPrice=null,currPrice;
        for(var k=0;k<arr.length;k++){
            if(arr[k][0]!=0){
                currPrice=0;
            }else if(isNaN(NPC[0][arr[k][1]])){
                currPrice=arr[k][2]*gut[arr[k][1]];
            }else{
                currPrice=arr[k][2]*Math.min(gut[arr[k][1]],NPC[0][arr[k][1]]);
            }
            if((minPrice==null)||(currPrice<minPrice)){
                minPrice=currPrice;
                returnId=k;
            }
        }
        return arr[returnId];
    } if(typeof arr=="object"){
        return arr;
    } else {
        GM_logWarning("getQuestBestAlternative bad call arr="+implode(arr));
        return [];
    }
}
unsafeData.getQuestBestAlternative=getQuestBestAlternative;
function setCalcToQuest(type,campaign,nr){
try{
    // GM_log("setCalcToQuest type="+type+" campaign="+campaign+" nr="+nr); 
    if(QUESTS[type]&&QUESTS[type][campaign]&&questData[type][campaign]){
        questData[type][campaign]["calcTo"] = Math.min(nr,QUESTS[type][campaign].length);
        GM_setValueCache(COUNTRY+"_"+SERVER+"_"+USERNAME+"_questData",implode(questData));
        unsafeData.questData=questData.clone();     
        // if(farmiLog){ doFarmis(); } //hack bypass early call
        calcProdMinRack();
        handleQuestLine(); 
    }
}catch(err){ GM_logError("setCalcToQuest\n"+err); }
}
unsafeData.setCalcToQuest=setCalcToQuest;
function handleQuestLine(){
try{
    // GM_log("unsafeWindow.quests_status:\n"+print_r(unsafeWindow.quests_status,"",true,"\n"));        
    var div,help;
    for(var type in questData){
        if (!questData.hasOwnProperty(type)){ continue; }
        for(var campaign in questData[type]){
            if(!questData[type].hasOwnProperty(campaign)){continue;}
            // GM_log("questData["+type+"]["+campaign+"]:\n"+print_r(questData[type][campaign],"",true,"\n"));
            if((type=="foodworld")&&unsafeWindow.quests_status&&unsafeWindow.quests_status[type]&&unsafeWindow.quests_status[type][campaign]&&unsafeWindow.quests_status[type][campaign]["data"]){
                unsafeWindow.quests_status[type][campaign]["questid"]=unsafeWindow.quests_status[type][campaign]["data"]["questid"]; //Bugfix
            }
            if(unsafeWindow.quests_status&&unsafeWindow.quests_status[type]&&unsafeWindow.quests_status[type][campaign]){
                help=parseInt(unsafeWindow.quests_status[type][campaign]["questid"],10);
                if(isNaN(help)){ help=1; };
                switch(implode([type,campaign])){
                case implode(["main","2"]):{
                    if(USERLEVEL<31){ help=-1; }
                break;}
                case implode(["forestry","1"]):{
                    if(USERLEVEL<20){ help=-1; }
                break;}
                case implode(["forestry","2"]):{
                    if(questData["forestry"]["1"]["nr"]<35){ help=-1; }
                break;}
                case implode(["foodworld","1"]):{
                    if(USERLEVEL<12){ help=-1; }
                break;}
                }               
                // if((type=="forestry")&&(campaign=="2")){ help++; } // Bugfix
                if(questData[type][campaign]["nr"]!=help){
                    switch(type){
                    case "main":{ logBubble.add(getText("pleaseOpenX").replace(/%1%/,getText("quest"+type+campaign))+" ("+questData[type][campaign]["nr"]+"&ne;"+help+")"); break;}
                    case "forestry":{ logBubble.add(getText("pleaseOpenX").replace(/%1%/,getText("lodge"))+" ("+questData[type][campaign]["nr"]+"&ne;"+help+")"); break;}
                    case "foodworld":{ logBubble.add(getText("pleaseOpenX").replace(/%1%/,getText("foodworld"))+" ("+questData[type][campaign]["nr"]+"&ne;"+help+")"); break;}
                    }
                    if(!QUESTS[type][campaign][questData[type][campaign]["nr"]]){
                        questData[type][campaign]["nr"]=help;
                        questData[type][campaign]["given"] = new Object();
                        questData[type][campaign]["time"] = 0;
                        GM_setValueCache(COUNTRY+"_"+SERVER+"_"+USERNAME+"_questData",implode(questData));
                        unsafeData.questData=questData.clone();
                    }
                }
            }else{
                help=QUESTS[type][campaign].length;
                switch(implode([type,campaign])){
                case implode(["main","2"]):{
                    if(USERLEVEL<31){ help=-1; }
                break;}
                case implode(["forestry","1"]):{
                    if(USERLEVEL<20){ help=-1; }
                break;}
                case implode(["forestry","2"]):{
                    if(questData["forestry"]["1"]["nr"]<35){ help=-1; }
                break;}
                case implode(["foodworld","1"]):{
                    if(USERLEVEL<12){ help=-1; }
                break;}
                }
                if(questData[type][campaign]["nr"]!=help){
                    questData[type][campaign]["nr"]=help;
                    questData[type][campaign]["given"] = new Object();
                    questData[type][campaign]["time"] = 0;
                    GM_setValueCache(COUNTRY+"_"+SERVER+"_"+USERNAME+"_questData",implode(questData));
                    unsafeData.questData=questData.clone();
                }
            }
            if(div=$("quests_status_bar_"+type+campaign)){
                if(questData[type][campaign]["nr"]==0){
                    div.style.display="block"; // quest number unknown
                    switch(type){
                    case "main":{ logBubble.add(getText("informationIsMissing")+" "+getText("pleaseOpenX").replace(/%1%/,getText("quest"+type+campaign))); break;}
                    case "forestry":{ logBubble.add(getText("informationIsMissing")+" "+getText("pleaseOpenX").replace(/%1%/,getText("lodge"))); break;}
                    case "foodworld":{ logBubble.add(getText("informationIsMissing")+" "+getText("pleaseOpenX").replace(/%1%/,getText("foodworld"))); break;}
                    }                       
                }else if((questData[type][campaign]["nr"]==-1)||(questData[type][campaign]["calcTo"]==-1)){
                    div.style.display="none"; // do not show quest
                }else if(QUESTS[type][campaign][questData[type][campaign]["nr"]]){
                    div.style.display="block"; // quest available
                }else{
                    div.style.display="none"; // all quests done
                }
                if(!unsafeWindow.premium){
                    switch(type){
                    case "forestry":{
                        div.addEventListener("click",function(){ 
                            if((gameLocation[0]=="city")&&(gameLocation[1]==2)){
                                unsafeWindow.close_page();
                                unsafeWindow.showDiv("transp3");
                                unsafeWindow.initCampaigns();
                            }else{
                                document.addEventListener("gameCity2",function(){
                                    document.removeEventListener("gameCity2",arguments.callee,false);
                                    unsafeWindow.close_page();
                                    unsafeWindow.showDiv("transp3");
                                    unsafeWindow.initCampaigns();
                                },false);
                                click($("speedlink_city2"));                                
                            }
                        },false);
                    break;}
                    case "foodworld":{
                        div.addEventListener("click",function(){ 
                            if(gameLocation[0]=="foodworld"){
                                click($("foodworld_questblock"));
                            }else{
                                document.addEventListener("gameFoodworldOpened",function(){
                                    document.removeEventListener("gameFoodworldOpened",arguments.callee,false);
                                    click($("foodworld_questblock"));
                                },false);
                                click($("speedlink_foodworld"));                                
                            }
                        },false);
                    break;}
                    }
                }
            }
        }
    }
    div=null;
}catch(err){GM_logError("handleQuestLine\ntype="+type+"\ncampaign="+campaign+"\n"+err);}
};
//***********************************************************************************************************

function do_shop(){
    if(pageZusatz["s"]=="3"){
        // Decoration - Shop
        npcSaison=explode(GM_getValue(COUNTRY+"_"+SERVER+"_NpcSaison"),"do_shop/npcSaison",INIT_NPC_SAISON);
        for(var v in npcSaison){
            if(!npcSaison.hasOwnProperty(v)){ continue; }
            npcSaison[v]=(document.getElementsByClassName("s"+v).length>0);
        }
        unsafeData.npcSaison=npcSaison.clone();
        GM_setValue(COUNTRY+"_"+SERVER+"_NpcSaison",implode(npcSaison));
    }
}

function do_stats(){
    var canddiv;
    var currStat="1";
    try{ currStat=pageZusatz["type"]; }
    catch(err){ currStat="1"; }
    if (typeof pageZusatz["search"]!="undefined"){ currStat="0"; }
    if (typeof pageZusatz["guildsearch"]!="undefined"){
        unsafeWindow.initGuildsearch();
        $("guildname").value=pageZusatz["guildsearch"];
        unsafeWindow.stats_searchGuild();
    }

    switch (currStat){
    case "0": // Einzelspieler
        try {
            loadProductData();
            var newdiv=$("spielerinfo");
            var newdiv1;
            for(var v=0;v<newdiv.childElementCount;v++){
                newdiv1=createElement("div",{"class":"hoverBgLightblue","style":"height:15px;width:100%;"});
                newdiv.insertBefore(newdiv1,newdiv.children[v]);
                newdiv1.appendChild(newdiv.children[v+1]); // left cell
                newdiv1.appendChild(newdiv.children[v+1]); // right cell
                removeElement(newdiv.children[v+1]); // br node
            }

            canddiv=$("spielerinfo").getElementsByClassName("cright3");
            var thisUser=/(.*?)&nbsp;/.exec(canddiv[0].firstElementChild.innerHTML+"&nbsp;")[1];
            canddiv[0].insertBefore(vertrag(thisUser),canddiv[0].firstElementChild);
            canddiv[0].insertBefore(stats(thisUser),canddiv[0].firstElementChild);
            canddiv[0].insertBefore(igm(thisUser),canddiv[0].firstElementChild);

            var nextQuest=parseInt(canddiv[5].innerHTML,10)+1;
            if(QUESTS["main"]["1"][nextQuest]){
                canddiv[5].parentNode.setAttribute("nextQuest",nextQuest);
                canddiv[5].parentNode.addEventListener("mouseover",function(event){
                    var nextQuest=this.getAttribute("nextQuest");
                    var str="<div style='border-bottom:1px solid black;'>"+getText("quest_farm")+"&nbsp;"+nextQuest+"</div>";
                    for(var i=0;i<QUESTS["main"]["1"][nextQuest][0].length;i++){
                        if(typeof QUESTS["main"]["1"][nextQuest][0][i][0]=="object"){
                            for(var j=0;j<QUESTS["main"]["1"][nextQuest][0][i].length;j++){                 
                                str += "<div>*"+numberFormat(QUESTS["main"]["1"][nextQuest][0][i][j][2])+"&nbsp;"+prodName[QUESTS["main"]["1"][nextQuest][0][i][j][0]][QUESTS["main"]["1"][nextQuest][0][i][j][1]]+"</div>";
                            }
                        }else{
                            str += "<div>"+numberFormat(QUESTS["main"]["1"][nextQuest][0][i][2])+"&nbsp;"+prodName[QUESTS["main"]["1"][nextQuest][0][i][0]][QUESTS["main"]["1"][nextQuest][0][i][1]]+"</div>";
                        }
                    }
                    toolTip.show(event,str);
                },false);
            }
            nextQuest=null;
        } catch(err){}
        break;
    // Spielerlisten
    case "1": case "2": case "3": case "4": case "5": case "6": case "7": case "8": case "10": case "11":
        if($("rankinghead")){
            canddiv=createElement("input",{"class":"text","maxlength":"5","style":"margin-left:10px;width:40px;"},$("rankinghead"));
            canddiv.addEventListener("mouseover",function(event){ toolTip.show(event,getText("goToRank")); },false);
            canddiv.addEventListener("change",function(){
                var ranksPerPage=15;
                var targetPage=parseInt(this.value,10);
                if(targetPage>0){
                    targetPage=Math.ceil(targetPage/ranksPerPage);
                    location.href="stats.php?page="+targetPage+"&type="+currStat;
                }else{
                    this.value="";
                }
            },false);
        }

        canddiv=$("rankingcontent").getElementsByClassName("stats_name");
        for(var v=0;v<canddiv.length;v++){
            thisUser=/(.*?)&nbsp;/.exec(canddiv[v].firstElementChild.innerHTML+"&nbsp;")[1];
            thisGuild=/&nbsp;\[(.*?)\]&nbsp;/.exec(canddiv[v].firstElementChild.innerHTML+"&nbsp;");
            var help=canddiv[v].firstElementChild.innerHTML.replace(thisUser,"<a href='stats.php?search=1&searchterm="+thisUser+"'>"+thisUser+"</a>");
            if(thisGuild) help=help.replace(thisGuild[0],"&nbsp;[<a href='stats.php?guildsearch="+thisGuild[1]+"'>"+thisGuild[1]+"</a>]&nbsp;");
            canddiv[v].firstElementChild.innerHTML=help;
            canddiv[v].insertBefore(igm(thisUser),canddiv[v].firstElementChild);
        }
        break;
    }
    canddiv=null;
}

function do_wettbewerb(){ // in .de not used anymore
    var candtd=document.getElementsByTagName("table")[1].getElementsByTagName("td");
    for(var v=6;v<candtd.length;v=v+3){
        var thisUser=/(.*?)&nbsp/.exec(candtd[v].firstElementChild.innerHTML+"&nbsp")[1];
        igm(thisUser,candtd[v]);
    }
    candtd=null;
}

//***********************************************************************************************************

unsafeWindow.buildInfoPanel=function(mode,mode2){
try{
    if(typeof mode2=="undefined"){ mode2=""; }
    var div,div1;
    if(!(div=$("infoPanel"))){
        if(div1=$("garten_komplett")){
            div=createElement("div",{"id":"infoPanel","mode":"","style":"z-index:100;background-color:rgba(0,0,0,0.7);position:absolute;top:0;left:0;width:100%;height:100%;z-index:100;display:none;"},div1);
            div1=createElement("div",{"style":"position:absolute;top:50px;left:20px;width:660px;height:580px;"},div);
        }else{
            div=createElement("div",{"id":"infoPanel","mode":"","style":"z-index:100;background-color:rgba(0,0,0,0.7);position:absolute;top:0;left:0;width:100%;height:100%;z-index:100;display:none;"},ALL);
            div1=createElement("div",{"style":"position:absolute;top:50px;left:100px;width:660px;height:580px;"},div);
        }
        createElement("img",{"src":GFX+"guild/help_back.jpg","style":"position:absolute;top:0;left:0;width:100%;height:100%;z-index:-1;"},div1);
        createElement("div",{"id":"infoPanelInner","style":"position:absolute;top:0;left:0;width:596px;height:516px;margin:32px;overflow:none;"},div1);
        div1=createElement("img",{"id":"infoPanelClose","class":"link","src":GFX+"close.jpg","style":"position:absolute;top:8px;right:8px;width:20px;height:20px;"},div1);
        div1.addEventListener("click",closeInfoPanel,false);
    }
    if((mode==div.getAttribute("mode"))&&(implode(mode2)==div.getAttribute("mode2"))){
        closeInfoPanel();
    }else{
        div.setAttribute("mode",mode);
        div.setAttribute("mode2",implode(mode2));
        div.style.display="block";
        $("infoPanelInner").innerHTML="";
        if(unsafeWindow.buildInfoPanelAutomat){ unsafeWindow.buildInfoPanelAutomat(mode,mode2); }
        switch(mode){
        case "changelog": buildInfoPanelChangelog();  break;
        case "donkey":    buildInfoPanelDonkey();     break;
        case "farmies":   buildInfoPanelFarmies();    break;
        case "formulas":  buildInfoPanelFormulas();   break;
        case "level":     buildInfoPanelLevel();      break;
        case "lottery":   buildInfoPanelLottery();    break;
        case "menu":      unsafeWindow.buildInfoPanelMenu(mode2); break;
        case "profit":    buildInfoPanelProfit();     break;
        case "quests":    buildInfoPanelQuests();     break;
        case "messages":  buildInfoPanelMessages();   break;
        case "stock":     buildInfoPanelStock(mode2); break;
        case "upjersAds": buildInfoPanelUpjersAds();  break;
        case "zones":     buildInfoPanelZones();      break;
        }
        raiseEvent("gameInfoPanelOpen");
        div=null;div1=null;
    }
}catch(err){ GM_logError("buildInfoPanel mode="+implode(mode)+" mode2="+implode(mode2)+"\n"+err); }
}
function closeInfoPanel(){
    try{
        var div;
        if(div=$top("infoPanel")){
            div.setAttribute("mode","");
            div.style.display="none";
        }
        if(div=$top("infoPanelInner")){
            div.innerHTML="";
        }
        div=null;
    } catch(err){ GM_logError("closeInfoPanel\n"+err); }
}
function buildInfoPanelChangelog(){
    try{
        var table,tr,td,div;
        var container=$("infoPanelInner");
        container.innerHTML="";
        // Head
        newdiv=createElement("div",{"class":"borderBottom1Black","style":"height:50px;"},container);
        table=createElement("table",{"border":"0","cellspacing":"0","style":"width:100%;"},newdiv);
        tr=createElement("tr",{},table);
        createElement("td",{"class":"tnormal","style":"color:black;font-weight:bold;text-align:center;height:40px;"},tr,getText("adviser")+" "+VERSION);
        createElement("td",{},tr);
        // Body
        newdiv=createElement("div",{"style":"height:470px;width:100%;overflow:auto;"},container);
        table=createElement("table",{"border":"0","cellspacing":"0","style":"width:100%;"},newdiv);
        tr=createElement("tr",{},table);
        createElement("th",{},tr,getText("version"));
        createElement("th",{},tr,getText("date"));
        createElement("th",{},tr,getText("change"));
        for(var i=CHANGELOG.length-1;i>-1;i--){
            tr=createElement("tr",{"class":"hoverBgCc9 borderBottom1dashedGrey"},table);
            createElement("td",{},tr,CHANGELOG[i][0]);
            createElement("td",{},tr,CHANGELOG[i][1]);
            td=createElement("td",{},tr);
            div=createElement("ul",{},td);
            for(var j=0;j<CHANGELOG[i][2].length;j++){
                createElement("li",{},div,CHANGELOG[i][2][j][LANGUAGE=="de"?0:1]);
            }
        }
        container=null;table=null;tr=null;td=null;div=null;
    }catch(err){GM_logError("buildInfoPanelChangelog\n"+err);}
}
function buildInfoPanelStock(mode){
try{
    var help=mode["filterCategory"];
    var modeDefault={"filterCategories":[{"v":true},{"f1":true},{"r1":true},{"f1":true}],"filterCategory":{"v":true},"page":1,"prodType":0,"showAll":false};
    var modeOld=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_modeStockTable"),"buildInfoPanelStock/modeOld");
    if(typeof modeOld!="object"){ modeOld=modeDefault; }
    if(typeof mode!="object"){ mode=modeOld; }
    for(var v in modeDefault){
        if(!modeDefault.hasOwnProperty(v)){ continue; }
        if(mode[v]==undefined){ mode[v]=(modeOld[v]==undefined?modeDefault[v]:modeOld[v]); }
    }
    if(mode["prodType"]>0){ mode["page"]=2; }
    if(help){ 
        mode["filterCategories"][mode["prodType"]]=mode["filterCategory"];
    }else{
        mode["filterCategory"]=mode["filterCategories"][mode["prodType"]];
    }
    GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_modeStockTable",implode(mode,"buildInfoPanelStock/mode"));
    var container=$("infoPanelInner");
    container.innerHTML="";
    //head line
    var newdiv=createElement("div",{"class":"borderBottom1Black","style":"height:50px;width:100%;font-color:black;overflow:none;"},container);
    var newtable=createElement("table",{"border":"0","cellspacing":"0","style":"width:100%;"},newdiv);
    var newtr=createElement("tr",{},newtable);
    // switch price / stock
    var newtd=createElement("td",{"align":"center"},newtr);
    if(mode["prodType"]==0){
        newdiv=createElement("div",{"class":"link naviItem"+(mode["page"]==1?"Active":"")},newtd,getText("prices"));
        newdiv.addEventListener("click",function(){
            buildInfoPanelStock({"page":1});
        },false);
    }else{
        newdiv=createElement("div",{"class":"naviItemInactive"},newtd,getText("prices"));
    }
    newdiv=createElement("div",{"class":"link naviItem"+(mode["page"]==2?"Active":"")},newtd,getText("stock"));
    newdiv.addEventListener("click",function(){
        buildInfoPanelStock({"page":2});
    },false);
    // switch prodType
    newtd=createElement("td",{"align":"left"},newtr);
    newdiv = createElement("select",{},newtd);
    createElement("option",{"value":0},newdiv,getText("farm"));
    createElement("option",{"value":1},newdiv,getText("forestry"));
    createElement("option",{"value":2},newdiv,getText("recipes"));
    createElement("option",{"value":3},newdiv,getText("powerups"));
    newdiv.addEventListener("change",function(){
        buildInfoPanelStock({"prodType":parseInt(this.value,10)});
    },false);
    newdiv.value=mode["prodType"];
    // switch filterCategory
    newtd=createElement("td",{"align":"right"},newtr);

    newdiv=createElement("div",{"style":"-moz-user-select:none;float:right;"},newtd);
    newdiv.addEventListener("mouseover",function(event){
        var mouseOverText=event.target.getAttribute("mouseOverText");
        if(mouseOverText){
            mouseOverText='<div>'+getText("click")+'&nbsp;/&nbsp;'+getText("clickCtrl")+'</div><div>'+mouseOverText+'</div>';
            toolTip.show(event,mouseOverText);
        }
    },false);
    newdiv.addEventListener("click",function(filterCategory){
    return function(event){
        var thisFilter=explode(event.target.getAttribute("filter"),"buildInfoPanelStock\thisFilter");
        if(thisFilter){
            if(event.ctrlKey){
                for(var i=thisFilter.length-1;i>-1;i--){
                    if(filterCategory[thisFilter[i]]){
                        delete filterCategory[thisFilter[i]];
                    }else{
                        filterCategory[thisFilter[i]]=true;
                    }
                }
            }else{
                filterCategory={};
                for(var i=thisFilter.length-1;i>-1;i--){
                    filterCategory[thisFilter[i]]=true;
                }
            }
            buildInfoPanelStock({"filterCategory":filterCategory});
        }
    }}(mode["filterCategory"]),false);
    switch(mode["prodType"]){
    case 0:{
        createElement("div",{"class":"link rackcat1v"+(mode["filterCategory"]["v"]?"_active":""),"filter":'["v"]',"mouseOverText":getText("category_v"),"style":"float:left;"},newdiv);
        createElement("div",{"class":"link rackcat1e"+(mode["filterCategory"]["e"]?"_active":""),"filter":'["e"]',"mouseOverText":getText("category_e"),"style":"float:left;"},newdiv);
        createElement("div",{"class":"link rackcat5"+(mode["filterCategory"]["o"]?"_active":""),"filter":'["o"]',"mouseOverText":getText("category_o"),"style":"float:left;"},newdiv);
        createElement("div",{"class":"link rackcat10"+(mode["filterCategory"]["c"]||mode["filterCategory"]["z"]?"_active":""),"filter":'["c","z"]',"mouseOverText":getText("category_c")+"<br>"+getText("category_z"),"style":"float:left;"},newdiv);
        newdiv1=createElement("div",{"style":"float:left;width:53px;"},newdiv);
        for(var i=1;i<=4;i=i+2){
            createElement("div",{"class":"link rackcat2"+i+(mode["filterCategory"]["fw"+i]?"_active":""),"filter":'["fw'+i+'"]',"mouseOverText":getText("category_fw"+i),"style":"float:left;"},newdiv1);
            if(i==3){ i=0; }
        }
        createElement("div",{"class":"link rackcat30fl"+(mode["filterCategory"]["fl"]?"_active":""),"filter":'["fl"]',"mouseOverText":getText("category_fl"),"style":"float:left;"},newdiv);
        createElement("div",{"class":"link rackcat30fla"+(mode["filterCategory"]["fla"]?"_active":""),"filter":'["fla"]',"mouseOverText":getText("category_fla"),"style":"float:left;"},newdiv);
    } break;
    case 1:{
        for(var i=1;i<=5;i++){
            newdiv1=createElement("div",{"class":"category_f"+i+(mode["filterCategory"]["f"+i]?"_active":"")+" link","filter":'["f'+i+'"]',"mouseOverText":getText("category_f"+i),"style":"display:inline-block;"},newdiv);
        }
    } break;
    case 2:{
        for(var i=0;i<=2;i++){
            newdiv1=createElement("div",{"class":"category_r"+i+(mode["filterCategory"]["r"+i]?"_active":"")+" link","filter":'["r'+i+'"]',"mouseOverText":getText("category_r"+i),"style":"display:inline-block;"},newdiv);
        }
    } break;
    case 3:{
        for(var i=0;i<=2;i++){
            newdiv1=createElement("div",{"class":"category_r"+i+(mode["filterCategory"]["p"+i]?"_active":"")+" link","filter":'["p'+i+'"]',"mouseOverText":getText("category_p"+i),"style":"display:inline-block;"},newdiv);
        }
    } break;
    }

    //the table
    newdiv=createElement("div",{"class":"borderBottom1Black","style":"height:430px;overflow:auto;"},container);
    newtable=createElement("table",{"border":"0","cellspacing":"0","style":"width:100%;"},newdiv);
    newtable.addEventListener("mouseover",function(event){
        var node=event.target;
        var mouseOverText=node.getAttribute("mouseOverText");
        while((node!=this)&&(!mouseOverText)){
            node=node.parentNode;
            mouseOverText=node.getAttribute("mouseOverText");
        }
        if(mouseOverText){ toolTip.show(event,mouseOverText); }
        node=null;mouseOverText=null;
    },false);

    var thead=createElement("thead",{},newtable); // sortable table
    var newtablebody=createElement("tbody",{},newtable);

    var sumwert=0;
    newtr=createElement("tr",{},thead);
    switch(mode["page"]){
    case 1:{
        createElement("th",{"colspan":"2"},newtr,getText("product"));
        createElement("th",{},newtr,getText("inventory"));
        createElement("th",{},newtr,"&nbsp;"+getText("NPCprice"));
        createElement("th",{},newtr,"&nbsp;"+getText("observed"));
        createElement("th",{},newtr,getText("marketPrice"));
        createElement("th",{},newtr,getText("afterFee"));

        var prevTyp=null;
        for(var w=0;w<prodNameSort[mode["prodType"]].length;w++){
        try{
            v=prodNameSort[mode["prodType"]][w];
            if((!prodBlock[mode["prodType"]][v].match(/t/))&&(mode["showAll"]||((!prodBlock[mode["prodType"]][v].match(/l/))&&(!prodBlock[mode["prodType"]][v].match(/q/))))){
                if (mode["filterCategory"][prodTyp[mode["prodType"]][v]]){
                    if(prodTyp[mode["prodType"]][v]!="c"){ sumwert += prodStock[mode["prodType"]][v]*gut[v]; }
                    if((prevTyp!=null)&&(prevTyp!=prodTyp[mode["prodType"]][v])){
                        newtr=createElement("tr",{"class":"hoverBgCc9 borderTop1dashedBlack"},newtablebody);
                    }else{
                        newtr=createElement("tr",{"class":"hoverBgCc9"},newtablebody);
                    }
                    prevTyp=prodTyp[mode["prodType"]][v];
    
                    newdiv=createElement("td",{},newtr);
                    produktPic(mode["prodType"],v,newdiv);
    
                    newdiv=createElement("td",{},newtr);
                    newa=createElement("a",{"prodId":v},newdiv,prodName[mode["prodType"]][v]);
                    if(prodBlock[mode["prodType"]][v].match(/l/)){
                        newtr.setAttribute("mouseOverText",getText("levelXneeded").replace(/%1%/,/l(\d+)/.exec(prodBlock[mode["prodType"]][v])[1]));
                        newa.style.textDecoration="none";
                    }else if(prodBlock[mode["prodType"]][v].match(/t/)){
                        newa.style.textDecoration="none";
                    }else{
                        if(mode["prodType"]==0){
                            newtr.setAttribute("mouseOverText",getText("value")+":&nbsp;"+moneyFormatInt(prodStock[mode["prodType"]][v]*gut[v]));
                            newa.setAttribute("mouseOverText",'<table class="tmenu"><tr><th colspan="2" class="lightBg">'+getText("goToMarketOfX").replace(/%1%/,prodName[mode["prodType"]][v])+'</th></tr><tr><td>'+getText("value")+'</td><td style="text-align:right;">'+moneyFormatInt(prodStock[mode["prodType"]][v]*gut[v])+'</td></table>');
                            newa.setAttribute("class","link");
                            newa.addEventListener("click",function(){showMarket(this.getAttribute("prodId"));},false);
                        }
                    }
    
                    createElement("td",{"style":"text-align:right;"},newtr,prodBlock[mode["prodType"]][v]?"<span style='color:red;'>---</span>":(prodStock[mode["prodType"]][v]?numberFormat(prodStock[mode["prodType"]][v]):"-"));
                    newtd=createElement("td",{"style":"text-align:right;"},newtr);
                    if(NPC[mode["prodType"]][v]){
                        if(!isNaN(NPC[mode["prodType"]][v])){
                            newtd.innerHTML=numberFormat(NPC[mode["prodType"]][v],2);
                        }else if (NPC[mode["prodType"]][v].match(/^f/)){
                            newtd.innerHTML="("+numberFormat(parseFloat(NPC[mode["prodType"]][v].replace("f",""),10),2)+")";
                        }else if (NPC[mode["prodType"]][v].match(/^c/)){
                            coinsFormat(parseInt(NPC[mode["prodType"]][v].replace("c",""),10),newtd);
                        }
                        if((npcSaison[v]!=undefined)&&(!npcSaison[v])){
                            newtd.style.textDecoration="line-through";
                            newtd.setAttribute("class","hoverNoTextDecoration");
                        }
                    }else{
                        newtd.innerHTML="&nbsp;";
                    }
    
                    newtd=createElement("td",{"style":"text-align:right;"},newtr,(gutBeob[v]?numberFormat(gutBeob[v],2):"&nbsp;"));
                    if(preisBeob[v]){
                        if(preisBeob[v][4]>0){
                            newtd.setAttribute("mouseOverText",getFormattedDateStr(preisBeob[v][1])+"&nbsp;"+getDaytimeStr(preisBeob[v][1])+"<br>"+moneyFormat(preisBeob[v][2])+"&nbsp;-&nbsp;"+moneyFormat(preisBeob[v][3])+"<br>#"+numberFormat(preisBeob[v][4]));
                        }else{
                            newtd.setAttribute("mouseOverText",getFormattedDateStr(preisBeob[v][1])+"&nbsp;"+getDaytimeStr(preisBeob[v][1])+"<br>#"+numberFormat(preisBeob[v][4]));
                            newtd.style.textDecoration="line-through";
                            newtd.setAttribute("class","hoverNoTextDecoration");
                        }
                        if(now-preisBeob[v][1]>259200){ // 3 days
                            if(now-preisBeob[v][1]>604800){ // 7 days
                                newtd.style.color="red";
                            }else{
                                newtd.style.color="yellow";
                            }
                        }
                    }else if(!prodBlock[mode["prodType"]][v]){
                        newtd.setAttribute("mouseOverText","---");
                    }
    
                    newtd=createElement("td",{"style":"text-align:right;"},newtr);
                    if(valNimmBeob){
                        newtd.innerHTML=numberFormat(gut[v],2);
                    }else{
                        createElement("span",{"style":"font-size:0;"},newtd,numberFormat(gut[v],2));
                        newinput=createElement("input",{"id":"inp"+v,"tabindex":parseInt(w,10)+1,"value":numberFormat(gut[v],2),"class":"text","size":"10","maxlength":"10","style":"text-align:right; background-color:transparent; color:black;"},newtd);
                        newinput.addEventListener("blur",function(){
                            this.value=numberFormat(gut[this.id.replace("inp","")],2);
                        },false);
                        newinput.addEventListener("change",function(){
                            var currId=this.id.replace("inp","");
                            var preis=Math.max(0,parseFloat(this.value.replace(regDelimThou,"").replace(regDelimDeci,"."),10));
                            var thisNode=this;
                            var yesFkt = function(){
                                gut[currId]=preis;
                                GM_setValue(COUNTRY+"_"+SERVER+"_gut",implode(gut));
                                raiseEventTop("gameChangedGut");
                                thisNode.value=numberFormat(preis,2);
                                thisNode.parentNode.nextSibling.innerHTML=numberFormat(0.9*preis,2);
                                thisNode=null;
                            };
                            var noFkt = function(){
                                thisNode.value=numberFormat(gut[currId],2);
                                thisNode=null;
                            };
                            if(preis==0){
                                alert2(getText("alertSetPriceNone").replace(/%PRODUCT%/,prodName[mode["prodType"]][currId]),getText("yes"),getText("no"),yesFkt,noFkt);
                            }else if((!isNaN(NPC[mode["prodType"]][currId]))&&(preis>NPC[mode["prodType"]][currId])){
                                alert2(getText("alertSetPriceOverNPC").replace(/%PRODUCT%/,prodName[mode["prodType"]][currId]).replace(/%PRICE%/,moneyFormat(preis)).replace(/%NPC%/,moneyFormat(NPC[mode["prodType"]][currId])),getText("yes"),getText("no"),yesFkt,noFkt);
                            }else if ((gutBeob[currId]!=undefined)&&(gutBeob[currId]>0)){
                                if(preis<0.7*gutBeob[currId]){
                                    alert2(getText("alertSetPriceUnderObs").replace(/%PRODUCT%/,prodName[mode["prodType"]][currId]).replace(/%PRICE%/,moneyFormat(preis)).replace(/%OBS%/,moneyFormat(gutBeob[currId])),getText("yes"),getText("no"),yesFkt,noFkt);
                                }else if (1.3*gutBeob[currId]<preis){
                                    alert2(getText("alertSetPriceOverObs").replace(/%PRODUCT%/,prodName[mode["prodType"]][currId]).replace(/%PRICE%/,moneyFormat(preis)).replace(/%OBS%/,moneyFormat(gutBeob[currId])),getText("yes"),getText("no"),yesFkt,noFkt);
                                }else{
                                    yesFkt();
                                }
                            }else{
                                yesFkt();
                            }
                            this.style.backgroundColor="transparent";
                        },false);
                    }
                    createElement("td",{"style":"text-align:right;"},newtr,numberFormat(0.9*gut[v],2));
                }
            }
        }catch(err){ GM_logError("buildInfoPanelStock\nmode="+implode(mode)+"\nv="+v+"\n"+err); }
        }
    break;}
    case 2:{
        var valMinRackMan=GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valMinRackMan",false);
        createElement("th",{"align":"center"},newtr,"&nbsp;");
        newtd=createElement("th",{"align":"left","class":"link hoverBgLightblue","sortdir":"Desc"},newtr,getText("product"));
        newtd=createElement("th",{"align":"right","class":"link hoverBgLightblue","sortdir":"Asc"},newtr,getText("inventory"));
        newtd=createElement("th",{"align":"right","class":"link hoverBgLightblue","sortdir":"Asc"},newtr,"&nbsp;"+getText("value"));
        createElement("th",{"align":"right","style":"padding-right:20px"},newtr,"&nbsp;"+getText("minRack"));
        new SortableTable(newtr);

        for(var w=0;w<prodNameSort[mode["prodType"]].length;w++){
        try{
            v=prodNameSort[mode["prodType"]][w];
            if(mode["showAll"]||((!prodBlock[mode["prodType"]][v].match(/l/))&&(!prodBlock[mode["prodType"]][v].match(/q/)))){
                if (mode["filterCategory"][prodTyp[mode["prodType"]][v]]){
                    if((mode["prodType"]==0)&&(prodTyp[mode["prodType"]][v]!="c")){ sumwert+=prodStock[mode["prodType"]][v]*gut[v]; }
                    newtr=createElement("tr",{"class":"hoverBgCc9","v":v},newtablebody);
    
                    newdiv=createElement("td",{},newtr);
                    produktPic(mode["prodType"],v,newdiv);
    
                    newdiv=createElement("td",{"value":w},newtr);
                    newa=createElement("a",{"prodId":v},newdiv,prodName[mode["prodType"]][v]);
                    if(prodBlock[mode["prodType"]][v].match(/l/)){
                        newtr.setAttribute("mouseOverText",getText("levelXneeded").replace(/%1%/,/l(\d+)/.exec(prodBlock[mode["prodType"]][v])[1]));
                        newa.style.textDecoration="none";
                    }else if(prodBlock[mode["prodType"]][v].match(/t/)){
                        newa.style.textDecoration="none";
                    }else if(mode["prodType"]==0){
                        newtr.setAttribute("mouseOverText",getText("marketPrice")+":&nbsp;"+moneyFormat(gut[v])); 
                        newa.setAttribute("mouseOverText",'<table class="tmenu"><tr><th colspan="2" class="lightBg">'+getText("goToMarketOfX").replace(/%1%/,prodName[mode["prodType"]][v])+'</th></tr><tr><td>'+getText("marketPrice")+'</td><td style="text-align:right;">'+moneyFormat(gut[v])+'</td></table>');
                        newa.setAttribute("class","link");
                        newa.addEventListener("click",function(){showMarket(this.getAttribute("prodId"));},false);
                    }
    
                    if(prodBlock[mode["prodType"]][v].match(/l/)){
                        createElement("td",{"align":"right","value":0},newtr,"<span style='color:red;'>---</span>");
                        createElement("td",{"align":"right","value":0},newtr,"<span style='color:red;'>---</span>");
                    }else if(prodStock[mode["prodType"]][v]){
                        createElement("td",{"align":"right","value":prodStock[mode["prodType"]][v]},newtr,numberFormat(prodStock[mode["prodType"]][v]));
                        if(mode["prodType"]==0&&(!prodBlock[mode["prodType"]][v].match(/t/))){
                            createElement("td",{"align":"right","value":prodStock[mode["prodType"]][v]*gut[v]},newtr,numberFormat(prodStock[mode["prodType"]][v]*gut[v])); 
                        }else{
                            createElement("td",{"align":"right","value":0},newtr,"-");
                        }
                    }else{
                        createElement("td",{"align":"right","value":0},newtr,"-");
                        createElement("td",{"align":"right","value":0},newtr,"-");
                    }
    
                    newtd=createElement("td",{"align":"right","style":"padding-right:20px"},newtr);
                    if(valMinRackMan){
                        newinput=createElement("input",{"tabindex":parseInt(w,10)+1,"value":numberFormat(prodMinRackInit[mode["prodType"]][v]),"class":"text","size":"10","maxlength":"10","style":"text-align:right; background-color:transparent; color:black;"},newtd);
                        newinput.addEventListener("blur",function(){
                            this.value=numberFormat(parseInt(this.value.replace(regDelimThou,""),10));
                        },false);
                        newinput.addEventListener("change",function(prodType,currId){ return function(){
                            prodMinRackInit[prodType][currId]=parseInt(this.value.replace(regDelimThou,""),10);
                            GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_prodMinRackInit",implode(prodMinRackInit));
                            raiseEventTop("gameChangedProdMinRackInit");
                        }}(mode["prodType"],v),false);
                    }else{
                        createElement("span",{},newtd,numberFormat(prodMinRackInit[mode["prodType"]][v]));
                    }
                }
            }
        }catch(err){ GM_logError("buildInfoPanelStock\nmode="+implode(mode)+"\nv="+v+"\n"+err); }
        }
    break;}
    }
    newtablebody.setAttribute("height",Math.min(361,19*newtablebody.childElementCount)+"px");

    //foot line
    newdiv=createElement("div",{},container);
    newtable=createElement("table",{"border":"0","cellspacing":"0","style":"width:100%;"},newdiv);
    newtr=createElement("tr",{},newtable);
    newtd=createElement("td",{"align":"center"},newtr);
    newdiv=createElement("input",{"type":"checkbox","class":"link","checked":mode["showAll"]},newtd);
    newdiv.addEventListener("click",function(){
        buildInfoPanelStock({"showAll":this.checked});
    },false);
    createElement("span",{},newtd,getText("showAll"));
    newtd=createElement("td",{"align":"center"},newtr);
    if((mode["prodType"]==0)&&(mode["page"]==1)&&(!valNimmBeob)){
        newdiv=createElement("button",{"class":"link button_new","style":"margin-right:10px;"},newtd,getText("takeObservedPrices"));
        newdiv.addEventListener("click",function(){
            alert2(getText("confirmUseObservedPrices"),getText("yes"),getText("no"),function(){
                for(var v=0;v<gutBeob.length;v++){
                    gut[v]=gutBeob[v];
                    if(!isNaN(NPC[0][v])){ gut[v]=Math.min(gut[v],NPC[0][v]); }
                }
                GM_setValue(COUNTRY+"_"+SERVER+"_gut",implode(gut));
                raiseEventTop("gameChangedGut");
                buildInfoPanelStock();
            });
        },false);
    }
    newtd=createElement("td",{"align":"center","style":"font-weight:bold;"},newtr,getText("stockValue")+":&nbsp;"+moneyFormatInt(sumwert));
    newtable=null;thead=null;newtablebody=null;newtr=null;newtd=null;newdiv=null;newdiv1=null;
}catch(err){ GM_logError("buildInfoPanelStock\nmode="+implode(mode)+"\n"+err); }
}
function buildInfoPanelProfit(mode){
try{
    var err_trace="init";
    //GM_log("buildInfoPanelProfit "+implode(mode));
    var modeDefault={"perc":0.9,"showAll":false,"sort":"gut","buildingLevel":{},"feed":{},"filterCategory":{"v":true}};
    var modeOld=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_modeProfittable"),"buildInfoPanelProfit/modeOld");
    if(typeof modeOld!="object"){ modeOld=modeDefault; }
    if(typeof mode!="object"){ mode=modeOld; }
    for(var v in modeDefault){
        if(!modeDefault.hasOwnProperty(v)){ continue; }
        if(mode[v]==undefined){ mode[v]=(modeOld[v]==undefined?modeDefault[v]:modeOld[v]); }
    }   
    if(!mode["buildingLevel"]["1"]){ mode["buildingLevel"]["1"]=1; }
    // [alternative, fully fed(0/1)]
    err_trace="calc array";
    var profit=new Array();
    var c=-1;
    var help, currBuilding, preis, preisBeob, menge, bonus, currInput;
    for(var v=0;v<prodName[0].length;v++){ 
        if((mode["showAll"]||(!prodBlock[0][v]))&&(prodGrowTime[0][v])){
            if(mode["filterCategory"][prodTyp[0][v]]){
                    profit[++c]=new Object();
                    profit[c]["id"]=v;
                    currBuilding=PRODUCT2BUILDING[0][v];
                    if(!mode["buildingLevel"][currBuilding]){ mode["buildingLevel"][currBuilding]=1; }
                    profit[c]["level"]=mode["buildingLevel"][currBuilding];
                    profit[c]["maxlevel"]=BUILDING_UPGRADES[currBuilding].length;
                    if(!mode["showAll"]){
                        while((profit[c]["maxlevel"]>1)&&(USERLEVEL<BUILDING_UPGRADES[currBuilding][profit[c]["maxlevel"]-1][0])){ profit[c]["maxlevel"]--; }
                        profit[c]["level"]=Math.min(profit[c]["level"],profit[c]["maxlevel"]);
                    }
                    bonus=BUILDING_UPGRADES[currBuilding][profit[c]["level"]-1][2];
                    switch(BUILDINGTYPE[currBuilding]){
                    case 1:{ // Fields
                        if(questData["main"]["1"]["nr"]>170){ bonus-=0.05; }
                        profit[c]["input"]=[];
                        profit[c]["input"][0]=[[]];
                        profit[c]["dauer"] = calcProductionTime(1,0,v,bonus);
                        profit[c]["runs"]  = 86400/profit[c]["dauer"];
                        preis=gut[v];
                        preisBeob=(gutBeob[v]?gutBeob[v]:0);
                        if(!isNaN(NPC[0][v])){
                            preis=Math.min(NPC[0][v],preis);
                            preisBeob=Math.min(NPC[0][v],preisBeob); 
                        }
                        menge=profit[c]["runs"]*(BUILDING_SIZE[currBuilding]/prodPlantSize[0][v]);
                        profit[c]["input"][0][0][0]=[v,menge,preis,preisBeob];
                        profit[c]["menge"] = menge*prodYield[0][v];
                        profit[c]["punkte"]= menge*prodPoints[0][v];
                        help=profit[c]["input"][0][0];
                    break;}
                    case 2:{ // Stable
                        if(!mode["feed"][v]){ mode["feed"][v]=[0,0]; }
                        if(typeof mode["feed"][v][0]!="number"){ mode["feed"][v][0]=0; }
                        if(typeof mode["feed"][v][1]!="number"){ mode["feed"][v][1]=0; }
                        profit[c]["input"]=[];
                        help=[];
                        for(var alt=0;alt<BUILDING_INPUT[currBuilding][v].length;alt++){
                            profit[c]["input"][alt]=[[],[]];
                            help[alt]=[[],[]];
                            help[alt][0]=calcProductionTime(2,0,v,bonus,BUILDING_INPUT[currBuilding][v][alt][0][1]/BUILDING_UPGRADES[currBuilding][profit[c]["level"]-1][3]);
                            help[alt][1]=calcProductionTime(2,0,v,bonus,BUILDING_INPUT[currBuilding][v][alt][0][1]/BUILDING_UPGRADES[currBuilding][profit[c]["level"]-1][3],1);
                            for(var i=0;i<BUILDING_INPUT[currBuilding][v][alt].length;i++){
                                currInput=BUILDING_INPUT[currBuilding][v][alt][i];
                                preis=gut[currInput[0]];
                                preisBeob=(gutBeob[currInput[0]]?gutBeob[currInput[0]]:0);
                                if(!isNaN(NPC[0][currInput[0]])){
                                    preis=Math.min(NPC[0][currInput[0]],preis);
                                    preisBeob=Math.min(NPC[0][currInput[0]],preisBeob); 
                                }
                                menge=help[alt][1][1]*86400/help[alt][1][0];
                                profit[c]["input"][alt][1][i]=[currInput[0],menge,preis,preisBeob];
                                menge=help[alt][0][1]*86400/help[alt][0][0];
                                profit[c]["input"][alt][0][i]=[currInput[0],menge,preis,preisBeob];
                            }
                        }
                        if(!help[mode["feed"][v][0]]){ mode["feed"][v][0]=0; }
                        if(!help[mode["feed"][v][0]][mode["feed"][v][1]]){ mode["feed"][v][1]=0; }
                        profit[c]["dauer"] = help[mode["feed"][v][0]][mode["feed"][v][1]][0];
                        profit[c]["runs"]  = 86400/profit[c]["dauer"];
                        profit[c]["menge"] = profit[c]["runs"]*BUILDING_UPGRADES[currBuilding][profit[c]["level"]-1][3]*prodYield[0][v];
                        profit[c]["punkte"]= profit[c]["menge"]*prodPoints[0][v];
                        help=profit[c]["input"][mode["feed"][v][0]][mode["feed"][v][1]];
                    break;}
                    case 3:{ // Factory
                        if(!mode["feed"][v]){ mode["feed"][v]=[0,0]; }
                        if(typeof mode["feed"][v][0]!="number"){ mode["feed"][v][0]=0; }
                        if(typeof mode["feed"][v][1]!="number"){ mode["feed"][v][1]=0; }
                        profit[c]["input"]=[];
                        help=[];
                        for(var alt=0;alt<BUILDING_INPUT[currBuilding][v].length;alt++){
                            profit[c]["input"][alt]=[[]];
                            help[alt]=[[]];
                            help[alt][0][0]=calcProductionTime(3,0,v,bonus);
                            for(var i=0;i<BUILDING_INPUT[currBuilding][v][alt].length;i++){
                                currInput=BUILDING_INPUT[currBuilding][v][alt][i];
                                preis=gut[currInput[0]];
                                preisBeob=(gutBeob[currInput[0]]?gutBeob[currInput[0]]:0);
                                if(!isNaN(NPC[0][currInput[0]])){
                                    preis=Math.min(NPC[0][currInput[0]],preis);
                                    preisBeob=Math.min(NPC[0][currInput[0]],preisBeob); 
                                }                                   
                                menge=currInput[1]*86400/help[alt][0][0];
                                profit[c]["input"][alt][0][i]=[currInput[0],menge,preis,preisBeob];
                            }
                        }
                        if(!help[mode["feed"][v][0]]){ mode["feed"][v][0]=0; }
                        if(!help[mode["feed"][v][0]][mode["feed"][v][1]]){ mode["feed"][v][1]=0; }
                        profit[c]["dauer"] = help[mode["feed"][v][0]][mode["feed"][v][1]][0];
                        profit[c]["runs"]  = 86400/profit[c]["dauer"];
                        profit[c]["menge"] = profit[c]["runs"]*BUILDING_UPGRADES[currBuilding][profit[c]["level"]-1][3]*prodYield[0][v];
                        profit[c]["punkte"]= profit[c]["menge"]*prodPoints[0][v];
                        help=profit[c]["input"][mode["feed"][v][0]][mode["feed"][v][1]];
                    break;}
                    case 4:{ // Foodworld, flowers
                        profit[c]["input"]=[];
                        profit[c]["input"][0]=[[]];
                        profit[c]["dauer"]=calcProductionTime(BUILDINGTYPE[currBuilding],0,v,bonus);
                        profit[c]["runs"]  = 86400/profit[c]["dauer"];
                        for(var i=0;i<prodRequire[0][v].length;i++){
                            currInput=prodRequire[0][v][i];
                            switch(currInput[0]){
                            case -1:{
                                preis=1;
                                preisBeob=1;
                                menge=currInput[1]*profit[c]["runs"];
                                profit[c]["input"][0][0][i]=[-1,menge,preis,preisBeob];
                            break;}
                            case 0:{
                                preis=gut[currInput[1]];
                                preisBeob=(gutBeob[currInput[1]]?gutBeob[currInput[1]]:0);
                                if(!isNaN(NPC[0][currInput[1]])){
                                    preis=Math.min(NPC[0][currInput[1]],preis);
                                    preisBeob=Math.min(NPC[0][currInput[1]],preisBeob); 
                                }
                                menge=currInput[2]*profit[c]["runs"];
                                profit[c]["input"][0][0][i]=[currInput[1],menge,preis,preisBeob];
                            break;}
                            }
                        }
                        profit[c]["menge"] = profit[c]["runs"]*BUILDING_UPGRADES[currBuilding][profit[c]["level"]-1][3]*prodYield[0][v];
                        profit[c]["punkte"]= profit[c]["menge"]*prodPoints[0][v];
                        help=profit[c]["input"][0][0];
                    break;}
                    }
                    menge=profit[c]["menge"];
                    preis=mode["perc"]*gut[v];
                    preisBeob=mode["perc"]*(gutBeob[v]?gutBeob[v]:0);
                    profit[c]["output"]=[v,menge,preis,preisBeob];
                    profit[c]["gut"]=menge*preis
                    profit[c]["gutBeob"]=menge*preisBeob;
                    for(var i=0;i<help.length;i++){
                        profit[c]["gut"]-=help[i][1]*help[i][2];
                        profit[c]["gutBeob"]-=help[i][1]*help[i][3];
                    }
                
                // GM_log(prodName[0][v]+":"+implode(profit[c]));
            }
        }
    }
    profit.sort(function (a,b){return b[mode["sort"]] - a[mode["sort"]];});
    // console.log("variable:\n"+print_r(profit,"",true,"\n"));
   
    //head line
    err_trace="head line";
    var table,newtr,newtd,newspan,newdiv,newtable1,newtr1,newtd1;
    var container=$("infoPanelInner");
    container.innerHTML="";
    newdiv=createElement("div",{"class":"borderBottom1Black","style":"height:50px;"},container);
    table=createElement("table",{"border":"0","cellspacing":"0","style":"width:100%;"},newdiv);
    newtr=createElement("tr",{},table);
    createElement("td",{"class":"tnormal","style":"color:black;font-weight:bold;text-align:center;"},newtr,getText("profitTable"));
    // switch bar to filter category
    newtd=createElement("td",{"align":"right"},newtr);
    newdiv=createElement("div",{"style":"-moz-user-select:none;width:212px;"},newtd);
    newdiv.addEventListener("mouseover",function(event){
        var mouseOverText=event.target.getAttribute("mouseOverText");
        if(mouseOverText){
            mouseOverText='<div>'+getText("click")+'&nbsp;/&nbsp;'+getText("clickCtrl")+'</div><div>'+mouseOverText+'</div>';
            toolTip.show(event,mouseOverText);
        }
    },false);
    newdiv.addEventListener("click",function(filterCategory){
    return function(event){
        var thisFilter=explode(event.target.getAttribute("filter"),"buildInfoPanelProfit\thisFilter");
        if(thisFilter){
            if(event.ctrlKey){
                for(var i=thisFilter.length-1;i>-1;i--){
                    if(filterCategory[thisFilter[i]]){
                        delete filterCategory[thisFilter[i]];
                    }else{
                        filterCategory[thisFilter[i]]=true;
                    }
                }
            }else{
                filterCategory={};
                for(var i=thisFilter.length-1;i>-1;i--){
                    filterCategory[thisFilter[i]]=true;
                }
            }
            buildInfoPanelProfit({"filterCategory":filterCategory});
        }
    }}(mode["filterCategory"]),false);
    createElement("div",{"class":"link rackcat1v"+(mode["filterCategory"]["v"]?"_active":""),"filter":'["v"]',"mouseOverText":getText("category_v"),"style":"float:left;"},newdiv);
    createElement("div",{"class":"link rackcat1e"+(mode["filterCategory"]["e"]?"_active":""),"filter":'["e"]',"mouseOverText":getText("category_e"),"style":"float:left;"},newdiv);
    createElement("div",{"class":"link rackcat5"+(mode["filterCategory"]["o"]?"_active":""),"filter":'["o"]',"mouseOverText":getText("category_o"),"style":"float:left;"},newdiv);
    newdiv1=createElement("div",{"style":"float:left;width:53px;"},newdiv);
    for(var i=1;i<=4;i=i+2){
        createElement("div",{"class":"link rackcat2"+i+(mode["filterCategory"]["fw"+i]?"_active":""),"filter":'["fw'+i+'"]',"mouseOverText":getText("category_fw"+i),"style":"float:left;"},newdiv1);
        if(i==3){ i=0; }
    }
    createElement("div",{"class":"link rackcat30fl"+(mode["filterCategory"]["fl"]?"_active":""),"filter":'["fl"]',"mouseOverText":getText("category_fl"),"style":"float:left;"},newdiv);
    createElement("div",{"class":"link rackcat30fla"+(mode["filterCategory"]["fla"]?"_active":""),"filter":'["fla"]',"mouseOverText":getText("category_fla"),"style":"float:left;"},newdiv);

    // the table
        err_trace="table";
        newdiv=createElement("div",{"class":"borderBottom1Black","style":"height:440px;width:100%;overflow:auto;"},container);
        table=createElement("table",{"border":"0","cellspacing":"0","style":"width:100%;"},newdiv);
        table.addEventListener("mouseover",function(event){
            var node=event.target;
            var mouseOverText=node.getAttribute("mouseOverText");
            while((node!=this)&&(!mouseOverText)){
                node=node.parentNode;
                mouseOverText=node.getAttribute("mouseOverText");
            }
            if(mouseOverText){ toolTip.show(event,mouseOverText); }
            node=null;mouseOverText=null;
        },false);
   
        err_trace="tablehead";
        newtr=createElement("tr",{"style":"color:black;"},table);
        newtd=createElement("th",{"class":"link hoverBgCc9"+(mode["sort"]=="product"?" sortableColDesc":"")},newtr,getText("product"));
        newtd.addEventListener("click",function(){
            buildInfoPanelProfit({"sort":"product"});
        },false);
        newtd=createElement("th",{"class":"link hoverBgCc9"+(mode["sort"]=="dauer"?" sortableColDesc":"")},newtr,getText("duration"));
        newtd.addEventListener("click",function(){
            buildInfoPanelProfit({"sort":"dauer"});
        },false);
        newtd=createElement("th",{"style":"border-bottom:1px dashed black;"},newtr);
        newtd=createElement("th",{"class":"link hoverBgCc9"+(mode["sort"]=="punkte"?" sortableColDesc":"")},newtr,getText("points"));
        newtd.addEventListener("click",function(){
            buildInfoPanelProfit({"sort":"punkte"});
        },false);
        newtd=createElement("th",{"class":"link hoverBgCc9"+(mode["sort"]=="gut"?" sortableColDesc":"")},newtr,getText("prices"));
        newtd.addEventListener("click",function(){
            buildInfoPanelProfit({"sort":"gut"});
        },false);
        newtd=createElement("th",{"class":"link hoverBgCc9"+(mode["sort"]=="gutBeob"?" sortableColDesc":"")},newtr,getText("observed"));
        newtd.addEventListener("click",function(){
            buildInfoPanelProfit({"sort":"gutBeob"});
        },false);
   
        err_trace="tablebody";
        for(var v=0;v<profit.length;v++){
            var buildingNr=PRODUCT2BUILDING[0][profit[v]["id"]];
            var buildingName=getBuildingName(buildingNr);
            newtr=createElement("tr",{"nr":v,"prod":profit[v]["id"],"class":"hoverBgCc9","style":"color:black;"},table);
            newtd=createElement("td",{},newtr);
            newtd=createElement("div",{"style":"position:relative;height:100%;"},newtd);
            produktPic(0,profit[v]["id"],newtd);
                newtable1=createElement("table");
                newtr1=createElement("tr",{},newtable1);
                createElement("td",{},newtr1,getText("dailyYield"));
                createElement("td",{"style":"text-align:right;padding-left:10px;"},newtr1,numberFormat(profit[v]["menge"],1));
                newtr1=createElement("tr",{},newtable1);
                createElement("td",{},newtr1,getText("yield"));
                createElement("td",{"style":"text-align:right;padding-left:10px;"},newtr1,numberFormat(profit[v]["menge"]/profit[v]["runs"]));
                newtr1=createElement("tr",{},newtable1);
                createElement("td",{},newtr1,getText("dailyRuns"));
                createElement("td",{"style":"text-align:right;padding-left:10px;"},newtr1,numberFormat(profit[v]["runs"],3));
            newspan=createElement("span",{"class":"link","data":newtable1.innerHTML},newtd,prodName[0][profit[v]["id"]]);
            newspan.addEventListener("mouseover",function(event){ 
                showGoToMarketToolTip(event,this.parentNode.parentNode.parentNode.getAttribute("prod"),this.getAttribute("data")); 
            },false);
            newspan.addEventListener("click",function(){
                showMarket(this.parentNode.parentNode.parentNode.getAttribute("prod"));
            },false);
            if(typeof profit[v]["level"]=="number"){
                help=mode["buildingLevel"].clone();
                help[buildingNr]=(profit[v]["level"]+1)%(profit[v]["maxlevel"]+1);
                newspan=createElement("span",{"mouseOverText":"<table cellspacing=0><tr><th class='lightBg'>"+buildingName+"</th></tr><tr><td>"+getText("upgradeLevel")+"</td></tr><tr><td>("+getText("clickToChange")+")</td></tr></table>","class":"link","nextLevel":implode(help,"nextLevel")},newtd); // ,"mouseOverText":"max "+profit[v]["maxlevel"]
                for(var w=1;w<=profit[v]["maxlevel"];w++){ createElement("img",{"src":w<=profit[v]["level"]?GFX+"star.png":IMAGES["starGrey"]},newspan); }
                newspan.addEventListener("click",function(){
                    var prod=this.parentNode.parentNode.parentNode.getAttribute("prod");
                    var nextLevel=explode(this.getAttribute("nextLevel"),"nextLevel.click",{});
                    buildInfoPanelProfit({"jumpTo":prod,"buildingLevel":nextLevel});
                },false);
            }
            if(profit[v]["input"]&&(profit[v]["input"].length>1)){
                newspan=produktPic(0,profit[v]["input"][mode["feed"][profit[v]["id"]][0]][mode["feed"][profit[v]["id"]][1]][0][0],newtd);
                newdiv=createElement("div");
                newtable1=createElement("table",{"cellspacing":0},newdiv);
                newtr1=createElement("tr",{},newtable1);
                createElement("th",{"colspan":2,"class":"lightBg"},newtr1,buildingName);
                newtr1=createElement("tr",{},newtable1);
                createElement("td",{"colspan":2},newtr1,getText("feed")+":");
                for(var i=0;i<profit[v]["input"].length;i++){
                    for(var j=0;j<profit[v]["input"][i].length;j++){
                        newtr1=createElement("tr",{},newtable1);
                        var help=((profit[v]["input"].length>1)&&(mode["feed"][profit[v]["id"]][0]==i)&&(mode["feed"][profit[v]["id"]][1]==j))?"background-color:#BB6600;":"";
                        createElement("td",{"style":"text-align:right;"+help},newtr1,numberFormat(profit[v]["input"][i][j][0][1],1));
                        createElement("td",{"style":help},newtr1,prodName[0][profit[v]["input"][i][j][0][0]]);
                    }
                }
                newtr1=createElement("tr",{},newtable1);
                createElement("td",{"colspan":2},newtr1,"("+getText("clickToChange")+")");
                newspan.setAttribute("class",newspan.getAttribute("class")+" link");
                help=mode["feed"].clone();
                if(1+mode["feed"][profit[v]["id"]][1]<profit[v]["input"][mode["feed"][profit[v]["id"]][0]].length){
                    help[profit[v]["id"]]=[help[profit[v]["id"]][0],1+help[profit[v]["id"]][1]];
                }else if(1+mode["feed"][profit[v]["id"]][0]<profit[v]["input"].length){
                    help[profit[v]["id"]]=[1+help[profit[v]["id"]][0],0];
                }else{
                    help[profit[v]["id"]]=[0,0];
                }
                newspan.setAttribute("nextFeed",implode(help,"nextFeed.click"));
                profit[v]["input"][mode["feed"][profit[v]["id"]][0]][mode["feed"][profit[v]["id"]][1]]
                newspan.addEventListener("click",function(){
                    var prod=this.parentNode.parentNode.parentNode.getAttribute("prod");
                    var nextFeed=explode(this.getAttribute("nextFeed"),"nextFeed.click",{});
                    buildInfoPanelProfit({"jumpTo":prod,"feed":nextFeed});
                },false);
                newspan.setAttribute("mouseOverText",newdiv.innerHTML);
            }
            createElement("td",{"style":"text-align:right;"},newtr,getTimeStr(profit[v]["dauer"],1));
   
            createElement("td",{"style":"text-align:right;"},newtr,getDaytimeStr(now+profit[v]["dauer"],1)+"&nbsp;"+getText("shortOClock"));
            newdiv=createElement("div");
            newtable1=createElement("table",{"cellspacing":0},newdiv);
            newtr1=createElement("tr",{},newtable1);
            createElement("th",{"colspan":2,"class":"lightBg"},newtr1,buildingName);
            newtr1=createElement("tr",{},newtable1);
            createElement("td",{},newtr1,getText("points"));
            createElement("td",{"style":"padding-left:10px;"},newtr1,numberFormat(profit[v]["punkte"]/profit[v]["runs"]));
            newtr1=createElement("tr",{},newtable1);
            createElement("td",{},newtr1,getText("dailyRuns"));
            createElement("td",{},newtr1,numberFormat(profit[v]["runs"],3));
            createElement("td",{"style":"text-align:right;padding-left:10px;","mouseOverText":newdiv.innerHTML},newtr,numberFormat(profit[v]["punkte"]));
   
            newdiv=createElement("div");
            newtable1=createElement("table",{"cellspacing":0},newdiv);
            newtr1=createElement("tr",{},newtable1);
            createElement("th",{"colspan":6,"class":"lightBg"},newtr1,buildingName);
            newtr1=createElement("tr",{},newtable1);
            createElement("td",{"colspan":4},newtr1);
            createElement("td",{"colspan":2,"style":"text-align:center;"},newtr1,getText("observed"));
            if(profit[v]["input"]){
                if(profit[v]["input"].length>1){
                    help=profit[v]["input"][mode["feed"][profit[v]["id"]][0]][mode["feed"][profit[v]["id"]][1]];
                }else{
                    help=profit[v]["input"][0][0];
                }
                for(var j=0;j<help.length;j++){
                    newtr1=createElement("tr",{},newtable1);
                    if(prodName[0][help[j][0]]){
                        createElement("td",{"style":"text-align:right;"},newtr1,numberFormat(help[j][1]/profit[v]["runs"]));
                        createElement("td",{},newtr1,prodName[0][help[j][0]]);
                        createElement("td",{"style":"text-align:right;padding-left:10px;"},newtr1,"("+moneyFormat(help[j][2])+")");
                        createElement("td",{"style":"text-align:right;"},newtr1,moneyFormatInt(-help[j][1]*help[j][2]/profit[v]["runs"]));
                        createElement("td",{"style":"text-align:right;padding-left:10px;"},newtr1,"("+moneyFormat(help[j][3])+")");
                        createElement("td",{"style":"text-align:right;"},newtr1,moneyFormatInt(-help[j][1]*help[j][3]/profit[v]["runs"]));
                    }else{
                        createElement("td",{"colspan":3},newtr1);
                        createElement("td",{"style":"text-align:right;"},newtr1,moneyFormatInt(-help[j][1]*help[j][2]/profit[v]["runs"]));
                        createElement("td",{"style":"text-align:right;padding-left:10px;"},newtr1);
                        createElement("td",{"style":"text-align:right;"},newtr1,moneyFormatInt(-help[j][1]*help[j][3]/profit[v]["runs"]));
                    }
                }
            }
            newtr1=createElement("tr",{},newtable1);
            createElement("td",{"style":"text-align:right;"},newtr1,numberFormat(profit[v]["output"][1]/profit[v]["runs"]));
            createElement("td",{},newtr1,prodName[0][profit[v]["output"][0]]);
            createElement("td",{"style":"text-align:right;padding-left:10px;"},newtr1,"("+moneyFormat(profit[v]["output"][2])+")");
            createElement("td",{"style":"border-bottom:1px solid black;text-align:right;"},newtr1,moneyFormatInt(profit[v]["output"][1]*profit[v]["output"][2]/profit[v]["runs"]));
            createElement("td",{"style":"text-align:right;padding-left:10px;"},newtr1,"("+moneyFormat(profit[v]["output"][3])+")");
            createElement("td",{"style":"border-bottom:1px solid black;text-align:right;"},newtr1,moneyFormatInt(profit[v]["output"][1]*profit[v]["output"][3]/profit[v]["runs"]));
            newtr1=createElement("tr",{},newtable1);
            createElement("td",{"style":"border-bottom:1px solid black;","colspan":3},newtr1);
            createElement("td",{"style":"border-bottom:1px solid black;text-align:right;"},newtr1,moneyFormatInt(profit[v]["gut"]/profit[v]["runs"]));
            createElement("td",{"style":"border-bottom:1px solid black;padding-left:10px;"},newtr1);
            createElement("td",{"style":"border-bottom:1px solid black;text-align:right;"},newtr1,moneyFormatInt(profit[v]["gutBeob"]/profit[v]["runs"]));
            newtr1=createElement("tr",{},newtable1);
            createElement("td",{"colspan":2},newtr1,getText("dailyRuns"));
            createElement("td",{"colspan":4,"style":"padding-left:10px;"},newtr1,numberFormat(profit[v]["runs"],3));
            createElement("td",{"style":"text-align:right;","mouseOverText":newdiv.innerHTML},newtr,moneyFormatInt(profit[v]["gut"]));
            createElement("td",{"style":"text-align:right;","mouseOverText":newdiv.innerHTML},newtr,moneyFormatInt(profit[v]["gutBeob"]));
   
            if(mode["jumpTo"]&&(mode["jumpTo"]==profit[v]["id"])){
                delete mode["jumpTo"];
                table.scrollTop=newtr.offsetTop;
                newspan=createElement("div",{"id":"vanishDiv","style":"position:absolute;top:0;left:0;height:15px;width:100%;background-color:blue;opacity:0.7;"},newtr.firstElementChild.firstElementChild);
                var intervalVanishDiv=window.setInterval(function(){
                    try{
                        var div=$("vanishDiv");
                        if(div){
                            var opac=parseFloat(div.style.opacity,10)-0.05;
                            if(opac>0){ div.style.opacity=opac; }
                            else{ 
                                removeElement(div);
                                window.clearInterval(intervalVanishDiv);
                            }
                        }else{ window.clearInterval(intervalVanishDiv); }
                    }catch(err){}
                },100);
            }
        }
   
        // foot line
        err_trace="foot line";
        newdiv=createElement("div",{},container);
        table=createElement("table",{"border":"0","cellspacing":"0","style":"width:100%;"},newdiv);
        newtr=createElement("tr",{},table);
        newtd=createElement("td",{"align":"center"},newtr);
        newspan=createElement("input",{"type":"checkbox","class":"link","checked":mode["showAll"]},newtd);
        newspan.addEventListener("click",function(){
            buildInfoPanelProfit({"showAll":this.checked});
        },false);
        createElement("span",{},newtd,getText("showAll"));    
        
        newtd=createElement("td",{"align":"center"},newtr);
        newspan=createElement("input",{"type":"checkbox","class":"link","checked":(mode["perc"]==0.9)},newtd);
        newspan.addEventListener("click",function(){
            buildInfoPanelProfit({"perc":this.checked?0.9:1});
        },false);
        createElement("span",{},newtd,"90%");    
        
        
        err_trace="saving";
        container=null;table=null;newtr=null;newtd=null;newspan=null;newdiv=null;newtable1=null;newtr1=null;newtd1=null;
        GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_modeProfittable",implode(mode,"buildInfoPanelProfit/modeProfittable"));
    }catch(err){ GM_logError("buildInfoPanelProfit ("+err_trace+")\nv="+v+"\n"+err); }
}
function buildInfoPanelQuests(mode){
try{
    var err_trace="init";
    var modeDefault={"type":"main","campaign":"1","sort":"product"};
    var modeOld=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_modeQuestsTable"),"buildInfoPanelQuests/modeOld");
    if(typeof modeOld!="object"){ modeOld=modeDefault; }
    if(typeof mode!="object"){ mode=modeOld; }
    for(var v in modeDefault){
        if(!modeDefault.hasOwnProperty(v)){ continue; }
        if(mode[v]==undefined){ mode[v]=(modeOld[v]==undefined?modeDefault[v]:modeOld[v]); }
    }   
    if(QUESTS[mode["type"]]==undefined){ mode["type"]="main"; }
    if(QUESTS[mode["type"]][mode["campaign"]]==undefined){ mode["campaign"]="1"; }
  
    //head line
    err_trace="head line";
    var help;
    var table,tr,td,span,div,div1,table1,tr1,td1,tr2,td2;
    var container=$("infoPanelInner");
    container.innerHTML="";
    table=createElement("table",{"border":"0","cellspacing":"0","style":"width:100%;"},container);
    tr=createElement("tr",{},table);
    createElement("td",{"class":"tnormal","style":"color:black;font-weight:bold;text-align:center;"},tr,getText("quests"));
    // switch bar
    td=createElement("td",{},tr);
    td=createElement("div",{"style":"float:right"},td);
    for(var type in QUESTS){
        if(!QUESTS.hasOwnProperty(type)){ continue; }
        for(var campaign in QUESTS[type]){
            if(!QUESTS[type].hasOwnProperty(campaign)){ continue; }
            // createElement("td",{"class":"link hoverBgLightbrown","style":""+((type==mode["type"])&&(campaign==mode["campaign"])?"background-color:lightblue;":"")},tr2,campaign);
            div=createElement("div",{"class":"link quests_status_bar_item quests_status_bar_"+type+campaign+(((type==mode["type"])&&(campaign==mode["campaign"]))?"_active":""),"style":"-moz-user-select:none;display:block;","next":implode({"type":type,"campaign":campaign},"buildInfoPanelQuests/next")},td);
            div.addEventListener("mouseover",function(event){
                var help=explode(this.getAttribute("next"),"buildInfoPanelQuests/next");
                toolTip.show(event,getText("quest"+help["type"]+help["campaign"]));
            },false);
            div.addEventListener("click",function(event){
                buildInfoPanelQuests(explode(this.getAttribute("next"),"buildInfoPanelQuests/next"));
            },false);
            if(questData[type]&&questData[type][campaign]&&(questData[type][campaign]["nr"]==-1)){
                createElement("div",{"class":"rack_lock_page","style":"transform:scale(0.7);"},div);
            }
        }
        // createElement("td",{"style":"width:100px;","colspan":help},tr1,getText(type=="main"?"farm":type));
    }
    // quest table
    err_trace="table";
    div=createElement("div",{"style":"height:300px;width:100%;font-color:black;overflow:auto;border-top:1px solid black;","id":"questTable"},container);
    table=createElement("table",{"border":"0","cellspacing":"0","style":"width:100%;","class":"black"},div);

    err_trace="table.head";
    tr=createElement("tr",{},table);
    td=createElement("th",{},tr,getText("nr"));
    td=createElement("th",{},tr,getText("demand"));
    td=createElement("th",{"colspan":"2"},tr,getText("value"));
    td=createElement("th",{},tr,getText("reward"));
   
    err_trace="table.body";
    var questCurr,item,str,mouseOver;
    var questDone,questTotal={};
    for(var v=1;v<QUESTS[mode["type"]][mode["campaign"]].length;v++){
        if(questCurr=QUESTS[mode["type"]][mode["campaign"]][v]){
            tr=createElement("tr",{"class":"hoverBgCc9 borderBottom1dashedGrey"},table); // white-space:nowrap;
            if((!questData[mode["type"]])||(!questData[mode["type"]][mode["campaign"]])){
                questDone = true;
            }else if(questData[mode["type"]][mode["campaign"]]["nr"]>v){ 
                questDone = true;
                tr.style.opacity=0.6; 
            }else if(questData[mode["type"]][mode["campaign"]]["nr"]==v){ 
                questDone = false;
                tr.style.backgroundColor="lightblue"; 
            }else{
                questDone = false;
            }
            createElement("td",{},tr,v);
            td=createElement("td",{},tr); // icon, name
            td1=createElement("td",{"style":"padding-right:10px;text-align:right;"},tr); // amount
            td2=createElement("td",{"style":"padding-right:10px;text-align:right;"},tr); // value
            for(var i=0;i<questCurr[0].length;i++){
                if(questCurr[0][i]){
                    if(typeof questCurr[0][i][0]=="object"){
                        help=[null,null,];
                        for(var j=0;j<questCurr[0][i].length;j++){
                            item=questCurr[0][i][j];
                            if((item[0]==0)&&(!prodBlock[0][item[1]].match(/t/))){
                                help[2]=(item[2]*gut[item[1]]);
                            }else{
                                help[2]=0;
                            }
                            if((help[1]==null)||(help[2]<help[1])){
                                help[0]=j;
                                help[1]=help[2];
                            }
                        }
                        for(var j=0;j<questCurr[0][i].length;j++){
                            item=questCurr[0][i][j];
                            str="font-style:italic;"
                            if(j!=help[0]){
                                str+="text-decoration:line-through;";
                                mouseOver=false;
                            }else if(questDone){
                                mouseOver=false;
                            }else{
                                if(!questTotal[item[0]]){ questTotal[item[0]]={}; }
                                if(!questTotal[item[0]][item[1]]){ questTotal[item[0]][item[1]]=0; }
                                questTotal[item[0]][item[1]]+=item[2];
                                mouseOver=true;
                            }
                            div=createElement("div",{"prod":item[1],"style":str},td);
                            if(prodBlock[item[0]][item[1]].match(/[lq]/)){
                                div.classList.add("red");
                                div.addEventListener("mouseover",function(event){ toolTip.show(event,getText("levelTooLow")); },false); // TODO: correct text if blocked by quest
                            }else if((item[0]==0)&&(!prodBlock[0][item[1]].match(/t/))){
                                div.classList.add("link");
                                div.addEventListener("mouseover",function(event){ showGoToMarketToolTip(event,this.getAttribute("prod")); },false);
                                div.addEventListener("click",function(){ showMarket(this.getAttribute("prod")); },false);
                            }
                            produktPic(item[0],item[1],div);
                            createElement("span",{"style":str},div,prodName[item[0]][item[1]]);
                            div=createElement("div",{"style":str},td1,numberFormat(item[2]));
                            if(mouseOver){
                                div.style.color=(prodStock[item[0]][item[1]]<questTotal[item[0]][item[1]]?"red":"green");
                                div.setAttribute("data",implode([item,questTotal[item[0]][item[1]]],"buildInfoPanelQuests/data"));
                                div.addEventListener("mouseover",function(event){
                                    var data=explode(this.getAttribute("data"),"buildInfoPanelQuests/data"); 
                                    var container,table,tr;
                                    container=createElement("div");
                                    table=createElement("table",{},container);
                                    tr=createElement("tr",{},table);
                                    createElement("td",{},tr,getText("inventory"));
                                    createElement("td",{"style":"text-align:right;"},tr,numberFormat(prodStock[data[0][0]][data[0][1]]));
                                    tr=createElement("tr",{"class":"borderBottom1Black"},table);
                                    createElement("td",{},tr,getText("total"));
                                    createElement("td",{"style":"text-align:right;"},tr,numberFormat(data[1]));
                                    tr=createElement("tr",{},table);
                                    createElement("td",{},tr);
                                    createElement("td",{"style":"text-align:right;"},tr,numberFormat(prodStock[data[0][0]][data[0][1]]-data[1]));
                                    toolTip.show(event,container.innerHTML);
                                    data=null;
                                    container=null;table=null;tr=null;
                                },false);
                            }
                            createElement("div",{"style":str},td2,item[0]==0?moneyFormatInt(item[2]*gut[item[1]]):"--");
                        }
                    }else{
                        item=questCurr[0][i];
                        if(questDone){
                            mouseOver=false;
                        }else{
                            if(!questTotal[item[0]]){ questTotal[item[0]]={}; }
                            if(!questTotal[item[0]][item[1]]){ questTotal[item[0]][item[1]]=0; }
                            questTotal[item[0]][item[1]]+=item[2];
                            mouseOver=true;
                        }
                        div=createElement("div",{"prod":item[1]},td);
                        if(prodBlock[item[0]][item[1]].match(/[lq]/)){
                            div.classList.add("red");
                            div.addEventListener("mouseover",function(event){ toolTip.show(event,getText("levelTooLow")); },false); // TODO: correct text if blocked by quest
                        }else if((item[0]==0)&&(!prodBlock[0][item[1]].match(/t/))){
                            div.classList.add("link");
                            div.addEventListener("mouseover",function(event){ showGoToMarketToolTip(event,this.getAttribute("prod")); },false);
                            div.addEventListener("click",function(){ showMarket(this.getAttribute("prod")); },false);
                        }
                        produktPic(item[0],item[1],div);
                        createElement("span",{},div,prodName[item[0]][item[1]]);
                        div=createElement("div",{},td1,numberFormat(item[2]));
                        if(mouseOver){
                            div.style.color=(prodStock[item[0]][item[1]]<questTotal[item[0]][item[1]]?"red":"green");
                            div.setAttribute("data",implode([item,questTotal[item[0]][item[1]]],"buildInfoPanelQuests/data"));
                            div.addEventListener("mouseover",function(event){
                                var data=explode(this.getAttribute("data"),"buildInfoPanelQuests/data"); 
                                var container,table,tr;
                                container=createElement("div");
                                table=createElement("table",{},container);
                                tr=createElement("tr",{},table);
                                createElement("td",{},tr,getText("inventory"));
                                createElement("td",{"style":"text-align:right;"},tr,numberFormat(prodStock[data[0][0]][data[0][1]]));
                                tr=createElement("tr",{"class":"borderBottom1Black"},table);
                                createElement("td",{},tr,getText("total"));
                                createElement("td",{"style":"text-align:right;"},tr,numberFormat(data[1]));
                                tr=createElement("tr",{},table);
                                createElement("td",{},tr);
                                createElement("td",{"style":"text-align:right;"},tr,numberFormat(prodStock[data[0][0]][data[0][1]]-data[1]));
                                toolTip.show(event,container.innerHTML);
                                data=null;
                                container=null;table=null;tr=null;
                            },false);
                        }                       
                        createElement("div",{},td2,item[0]==0?moneyFormatInt(item[2]*gut[item[1]]):"--");
                    }
                }
            }
            td=createElement("td",{"style":"white-space:nowrap;"},tr);
            if(questCurr[2]>0){ 
                div=createElement("div",{},td);
                pointsFormat(questCurr[2],"div",div);  // 70ms
            }
            if(questCurr[3]){
                for(var w=0;w<questCurr[3].length;w++){
                    switch(questCurr[3][w][0]){
                    case 0:{
                        createElement("div",{},td,moneyFormat(questCurr[3][w][1]));
                    break;}
                    case 1:{
                        div=createElement("div",{},td);
                        produktPic(questCurr[3][w][1],questCurr[3][w][2],div);
                        createElement("span",{},div,numberFormat(questCurr[3][w][3])+"&nbsp;"+prodName[questCurr[3][w][1]][questCurr[3][w][2]]);
                    break;}
                    case 2:{
                        createElement("div",{},td,getText("activation")+": "+getText("rackX").replace(/%1%/,questCurr[3][w][1]));
                    break;}
                    case 3:{
                        createElement("div",{},td,getText("activation")+": "+getText("farmX").replace(/%1%/,questCurr[3][w][1]));
                    break;}
                    case 4:{
                        div=createElement("div",{},td);
                        produktPic(questCurr[3][w][1],questCurr[3][w][2],div);
                        createElement("span",{},div,getText("productTimeSaving").replace(/%1%/,questCurr[3][w][3]).replace(/%2%/,prodName[questCurr[3][w][1]][questCurr[3][w][2]]));
                    break;}
                    case 5:{
                        div=createElement("div",{},td);
                        createElement("img",{"src":GFX+"adbonus.gif","style":"border:0;height:15px;"},div);
                        createElement("span",{},div,getText("additionalFarmi").replace(/%1%/,questCurr[3][w][1]));
                    break;}
                    case 6:{
                        createElement("div",{},td,getText("additionalLogCapacity").replace(/%1%/,questCurr[3][w][1]));
                    break;}
                    case 7:{
                        createElement("div",{},td,getText("waterBonus").replace(/%1%/,questCurr[3][w][1]));
                    break;}
                    case 8:{
                        if(DATA_zones[questCurr[3][w][1]]["location"]=="farm"){
                            createElement("div",{},td,getText("activation")+": "+getText("farmzone").replace(/%1%/,1+((questCurr[3][w][1]-1)%6)).replace(/%2%/,Math.ceil(questCurr[3][w][1]/6)));
                        }else{
                            createElement("div",{},td,getText("activation")+": "+zones.getBuildingName(questCurr[3][w][1]));
                        }
                    break;}
                    case 9:{
                        div=createElement("div",{},td);
                        createElement("span",{},div,getText("activation")+": ");
                        produktPic(questCurr[3][w][1],questCurr[3][w][2],div);
                        createElement("span",{},div,prodName[questCurr[3][w][1]][questCurr[3][w][2]]);
                    break;}
                    case 10:{
                        createElement("div",{},td,getText("activation")+": "+getText("wateringFeature"));
                    break;}
                    case 11:{
                        div=createElement("div",{},td);
                        createElement("img",{"src":GFX+"adbonus.gif","style":"border:0;height:15px;"},div);
                        createElement("span",{},div,getText("additionalForestFarmiSlot").replace(/%1%/,questCurr[3][w][1]));
                    break;}
                    case 12:{
                        div=createElement("div",{},td);
                        createElement("span",{},div,unsafeWindow.quest_reward_6+": ");
                        createElement("img",{"src":GFX+"farmhouse/thumbs/"+questCurr[3][w][1]+".jpg","style":"border:0;height:30px;width:30px;"},div);
                    break;}
                    case 13:{
                        div=createElement("div",{},td);
                        createElement("span",{},div,getText("shadowboxitem")+": ");
                        createElement("img",{"src":GFX+"gifts/"+questCurr[3][w][1]+".gif","style":"border:0;height:30px;width:30px;"},div);
                    break;}
                    }
                }
            }
        }
    }
    // all quests done
    if(questData[mode["type"]]&&questData[mode["type"]][mode["campaign"]]&&(questData[mode["type"]][mode["campaign"]]["nr"]>=QUESTS[mode["type"]][mode["campaign"]].length)){
        tr=createElement("tr",{"class":"hoverBgCc9 borderBottom1dashedGrey","style":"color:black;"},table);
        tr.style.backgroundColor="lightblue";
        createElement("td",{},tr,questData[mode["type"]][mode["campaign"]]["nr"]);
        createElement("td",{},tr);
        createElement("td",{},tr);
        createElement("td",{},tr);
    }
    // scroll to current quest
    if(questData[mode["type"]][mode["campaign"]]["nr"]>1){
        window.setTimeout(function(scr){        
            $("questTable").scrollTop=scr;
        },0,table.children[Math.min(table.childElementCount,questData[mode["type"]][mode["campaign"]]["nr"])].offsetTop);
    }
    err_trace="select calcTo";
    div=createElement("div",{"style":"height:20px;width:100%;font-color:black;overflow:auto;border-top:1px solid black;"},container);
    createElement("span",{},div,getText("calcTo")+":");
    span = createElement("select",{"id":"selectQuestCalcTo","style":"width:auto;height:18px;margin-left:5px;","mode":implode(mode,"buildInfoPanelQuests/selectQuestCalcTo")},div);
    createElement("option",{"value":-1},span,getText("hide"));
    createElement("option",{"value":0},span,"--");
    for(var i=questData[mode["type"]][mode["campaign"]]["nr"];i<QUESTS[mode["type"]][mode["campaign"]].length;i++){
        createElement("option",{"value":i},span,i);
    }
    span.addEventListener("change",function(){
        if(isNaN(this.value)){return false;}
        var mode=explode(this.getAttribute("mode"),"buildInfoPanelQuests/selectQuestCalcTo");
        setCalcToQuest(mode["type"],mode["campaign"],this.value);
        buildInfoPanelQuestsTotal(mode);
    },false);
    span.value = questData[mode["type"]][mode["campaign"]]["calcTo"];

    err_trace="total table";
    div=createElement("div",{"style":"height:155px;width:100%;overflow:auto;","id":"questTableTotal"},container);
    function buildInfoPanelQuestsTotal(mode){
    try{
        var err_trace="init";
        var modeDefault={"type":"main","campaign":"1","sort":"product"};
        var modeOld=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_modeQuestsTable"),"buildInfoPanelQuestsTotal/modeOld");
        if(typeof modeOld!="object"){ modeOld=modeDefault; }
        if(typeof mode!="object"){ mode=modeOld; }
        for(var v in modeDefault){
            if(!modeDefault.hasOwnProperty(v)){ continue; }
            if(mode[v]==undefined){ mode[v]=(modeOld[v]==undefined?modeDefault[v]:modeOld[v]); }
        }           
        err_trace="calc object";
        var obj=new Object();
        var questCurr,item,help;
        for(var v=questData[mode["type"]][mode["campaign"]]["nr"];v<=questData[mode["type"]][mode["campaign"]]["calcTo"];v++){
            questCurr=QUESTS[mode["type"]][mode["campaign"]][v];
            if(questCurr){
                for(var i=0;i<questCurr[0].length;i++){
                    if(questCurr[0][i]){
                        if(typeof questCurr[0][i][0]=="object"){
                            help=[null,null,];
                            for(var j=0;j<questCurr[0][i].length;j++){
                                item=questCurr[0][i][j];
                                if((item[0]==0)&&(!prodBlock[0][item[1]].match(/t/))){
                                    help[2]=(item[2]*gut[item[1]]);
                                }else{
                                    help[2]=0;
                                }
                                if((help[1]==null)||(help[2]<help[1])){
                                    help[0]=j;
                                    help[1]=help[2];
                                }
                            }
                            item=questCurr[0][i][help[0]];
                        }else{
                            item=questCurr[0][i];
                        }
                        if(!obj[item[0]]){ obj[item[0]]={}; }
                        if(!obj[item[0]][item[1]]){ obj[item[0]][item[1]]=0; }
                        obj[item[0]][item[1]] += item[2];
                    }
                }
            }
        }
        err_trace="calc array";
        var arr=new Array(); // [type,prodId,amount,amountValue,missing,missingValue]
        for(var type in obj){
            if(!obj.hasOwnProperty(type)){continue;}
            for(var prod in obj[type]){
                if(!obj[type].hasOwnProperty(prod)){continue;}
                help=(prodStock[type][prod]?prodStock[type][prod]:0);
                if((item[0]==0)&&(gut[prod])){
                    arr.push([type,prod,obj[type][prod],obj[type][prod]*gut[prod],(obj[type][prod]-help),(obj[type][prod]-help)*gut[prod]]);
                }else{
                    arr.push([type,prod,obj[type][prod],0,(obj[type][prod]-help),0]);
                }
            }
        }
        err_trace="sort array";
        switch(mode["sort"]){
        case "product": arr.sort(function (a,b){ if(a[0]==b[0]){ return(a[1]-b[1]); }else{ return(a[0]-b[0]); } }); break;
        case "absolute": arr.sort(function (a,b){ return(b[2]-a[2]); }); break;
        case "absoluteValue": arr.sort(function (a,b){ return(b[3]-a[3]); }); break;
        case "relative": arr.sort(function (a,b){ return(b[4]-a[4]); }); break;
        case "relativeValue": arr.sort(function (a,b){ return(b[5]-a[5]); }); break;
        }
        
        // table
        err_trace="table";
        var container,table,tr,td,div;
        container=$("questTableTotal");
        container.innerHTML="";
        table=createElement("table",{"class":"black","border":"0","cellspacing":"0","style":"width:100%;"},container);
        table.addEventListener("mouseover",function(event){
            var node=event.target;
            var mouseOverText=node.getAttribute("mouseOverText");
            while((node!=this)&&(!mouseOverText)){
                node=node.parentNode;
                mouseOverText=node.getAttribute("mouseOverText");
            }
            if(mouseOverText){ toolTip.show(event,mouseOverText); }
            node=null;mouseOverText=null;
        },false);
    
        err_trace="table.head";
        tr=createElement("tr",{"class":"borderBottom1dashedBlack"},table);
        td=createElement("th",{"class":"link hoverBgCc9"+(mode["sort"]=="product"?" sortableColDesc":"")},tr,getText("product"));
        td.addEventListener("click",function(){
            buildInfoPanelQuestsTotal({"sort":"product"});
        },false);       
        td=createElement("th",{"class":"link hoverBgCc9"+(mode["sort"]=="absolute"?" sortableColDesc":"")},tr,getText("absolute"));
        td.addEventListener("click",function(){
            buildInfoPanelQuestsTotal({"sort":"absolute"});
        },false);       
        td=createElement("th",{"class":"link hoverBgCc9"+(mode["sort"]=="absoluteValue"?" sortableColDesc":"")},tr,getText("value"));
        td.addEventListener("click",function(){
            buildInfoPanelQuestsTotal({"sort":"absoluteValue"});
        },false);       
        td=createElement("th",{"class":"link hoverBgCc9"+(mode["sort"]=="relative"?" sortableColDesc":"")},tr,getText("relative"));
        td.addEventListener("click",function(){
            buildInfoPanelQuestsTotal({"sort":"relative"});
        },false);       
        td=createElement("th",{"class":"link hoverBgCc9"+(mode["sort"]=="relativeValue"?" sortableColDesc":"")},tr,getText("value"));
        td.addEventListener("click",function(){
            buildInfoPanelQuestsTotal({"sort":"relativeValue"});
        },false);       
    
        err_trace="table.body";
        help=null;
        for(var i=0;i<arr.length;i++){
            item=arr[i];
            tr=createElement("tr",{"class":"hoverBgCc9","prod":item[1]},table);
            if(mode["sort"]=="product"){
                if(help==null){
                    help=item[0];
                } else if(help!=item[0]){
                    tr.classList.add("borderTop1dashedBlack");
                    help=item[0];
                }
            }
            if(prodBlock[item[0]][item[1]].match(/[lq]/)){
                tr.classList.add("red");
                tr.addEventListener("mouseover",function(event){ toolTip.show(event,getText("levelTooLow")); },false); // TODO: correct text if blocked by quest
            }else if((item[0]==0)&&(!prodBlock[0][item[1]].match(/t/))){
                tr.classList.add("link");
                tr.addEventListener("mouseover",function(event){ showGoToMarketToolTip(event,this.getAttribute("prod")); },false);
                tr.addEventListener("click",function(){ showMarket(this.getAttribute("prod")); },false);
            }
            td=createElement("td",{"style":"white-space:nowrap;"},tr);
            div=createElement("div",{},td);
            produktPic(item[0],item[1],div);
            createElement("span",{},div,prodName[item[0]][item[1]]);
            createElement("td",{"style":"text-align:right;"},tr,numberFormat(item[2]));
            createElement("td",{"style":"text-align:right;"},tr,item[3]==0?"--":moneyFormatInt(item[3]));
            createElement("td",{"style":"text-align:right;"},tr,numberFormat(item[4]));
            createElement("td",{"style":"text-align:right;"},tr,item[5]==0?"--":moneyFormatInt(item[5]));
        }
    
        err_trace="saving";
        container=null;table=null;thead=null;tbody=null;tr=null;td=null;span=null;div=null;table1=null;tr1=null;td1=null;tr2=null;td2=null;
        GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_modeQuestsTable",implode(mode,"buildInfoPanelQuestsTotal/modeQuestsTable"));
        }catch(err){ GM_logError("buildInfoPanelQuestsTotal ("+err_trace+")\n"+err); }
    }   
    buildInfoPanelQuestsTotal(mode);
    
    err_trace="saving";
    container=null;table=null;thead=null;tbody=null;tr=null;td=null;span=null;div=null;table1=null;tr1=null;td1=null;tr2=null;td2=null;
    GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_modeQuestsTable",implode(mode,"buildInfoPanelQuests/modeQuestsTable"));
    }catch(err){ GM_logError("buildInfoPanelQuests ("+err_trace+")\n"+err); }
}
function buildInfoPanelZones(){
    try{
        var container=$("infoPanelInner");
        container.innerHTML="";
        var c,totalPunkte=0,zoneNrF,points,endDay,help;
        createElement("div",{"class":"tnormal borderBottom1Black","align":"center","style":"line-height:30px;font-weight:bold;"},container,getText("overview"));
        container=createElement("div",{"style":"width:595px;height:485px;overflow:auto;"},container);
        // Zones
        newtable=createElement("table",{"style":"width:100%;","border":"1"},container);
        for(var i in ALL_ZONES){
            if(!ALL_ZONES.hasOwnProperty(i)){ continue; }
            c=0;
            newtr=createElement("tr",{},newtable);
            createElement("th",{"colspan":"6"},newtr,getText(i));                           
            for(var j=0;j<ALL_ZONES[i].length;j++){
                zoneNrF=ALL_ZONES[i][j];
                if(zones.isProductional(zoneNrF)&&(!zones.getBlock(zoneNrF))){
                    if(c%3==0){
                        newtr=createElement("tr",{"style":"width:100%;"},newtable); 
                    }
                    newtd=createElement("td",{"style":"width:33%;","colspan":"2","zoneNrF":zoneNrF,"class":"link hoverBgCc9"},newtr);
                    newtd.addEventListener("mouseover",function(event){
                        toolTip.show(event,toolTipZoneProduction(this.getAttribute("zoneNrF")));
                    },false);
                    newtd.addEventListener("click",function(){
                        closeInfoPanel();
                        goToZone(this.getAttribute("zoneNrF"));
                    },false);
                    newdiv=createElement("div",{"style":"position:relative;top:0;height:70px;overflow:hidden;"},newtd);
                    createElement("div",{"class":"zoneBg70_"+zones.getBuilding(zoneNrF),"style":"position:absolute;opacity:0.3;"},newdiv);
                    newdiv1=createElement("div",{"style":"position:absolute;top:0;height:61px;width:100%;overflow:auto;"},newdiv);
                    newdiv=createElement("div",{},newdiv1);
                    help=zones.getEndtime(zoneNrF);
                    if (help!=NEVER){
                        endDay=countDays(now,help);
                        if(endDay==0){ 
                            newdiv.innerHTML=getDaytimeStr(help,1)+"&nbsp;"+getText("shortOClock"); 
                        }else if(getText("day"+endDay)){ 
                            newdiv.innerHTML=getText("day"+endDay)+" "+getDaytimeStr(help,1)+"&nbsp;"+getText("shortOClock");
                        }else{
                            newdiv.innerHTML=new Date(1000*help).toLocaleString();
                        }
                    }else{
                        newdiv.innerHTML=getText("idle");
                    }
                    if (help<now){
                        newdiv.style.textDecoration="blink";
                        newdiv.style.fontWeight="bold";
                    }
                    points=0;
                    if(help=zones.getCrop(zoneNrF)){
                        for(var k=0;k<help.length;k++){
                            newdiv=createElement("div",{"style":"line-height:16px;"},newdiv1);
                            produktPic(help[k][0],help[k][1],newdiv);
                            createElement("div",{"style":"display:inline-block;"},newdiv,numberFormat(help[k][2])+" "+prodName[help[k][0]][help[k][1]]);
                            points += help[k][3];
                        }
                    }else{
                        newdiv=createElement("div",{"style":"line-height:16px;"},newdiv1);
                        createElement("div",{"style":"display:inline-block;"},newdiv,"???");
                    }
                    pointsFormat(points,"div",newdiv1);
                    totalPunkte += points;
                    c++;
                }
            }
        }
        // Total production
        newtable=createElement("table",{"style":"width:100%;margin-top:10px;","border":"1"},container);
        newtr=createElement("tr",{},newtable);
        createElement("th",{},newtr,getText("total"));
        newtd=createElement("th",{"class":"link hoverBgCc9"},newtr,getText("missing"));
        newtd.addEventListener("mouseover",function(event){ toolTip.show(event,getText("toSGH")); },false);
        newtd.addEventListener("click",showSGH,false);
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{},newtr);
        for(var k in totalErnte[0]){
            if(!totalErnte[0].hasOwnProperty(k)){ continue; }
            newdiv=createElement("div",{"style":"height:16px"},newtd);
            produktPic(0,k,newdiv);
            createElement("div",{"style":"display:inline-block;"},newdiv,numberFormat(totalErnte[0][k])+" "+prodName[0][k]);
        }
        pointsFormat(totalPunkte,"div",newtd);
        var newtdfehlt=createElement("td",{},newtr);

        // Farmi overview
        newtable=createElement("table",{"style":"width:100%;margin-top:10px;","border":"1"},container);
        newtr=createElement("tr",{},newtable);
        createElement("th",{},newtr,getText("farmi"));
        createElement("th",{},newtr,getText("products"));
        createElement("th",{},newtr,getText("money"));
        createElement("th",{"colspan":"2"},newtr,getText("value"));
        var farmiNr=-1;
        var farmiCount=0;
        var farmiSum=new Object;
        var farmiCash=0;
        var farmiWert=0;
        while (top.window.wrappedJSObject.farmisinfo[0][++farmiNr]){
            if (!top.window.wrappedJSObject.farmisaway[farmiNr]){
            farmiCount++;
            newtr=createElement("tr",{},newtable);
            newtd=createElement("td",{"class":"link hoverBgCc9","name":farmiNr},newtr);
            var farmiGfxNr=top.window.wrappedJSObject.farmisinfo[0][farmiNr]["pic"];
            createElement("img",{"src":GFX+"verkauf/kunde_"+farmiGfxNr+"_still.gif","style":"width:"+FARMISIZE[farmiGfxNr][0]+"px;height:"+FARMISIZE[farmiGfxNr][1]+"px;"},newtd);
            newtd.addEventListener("click",function(){
                closeInfoPanel();
                if ($("citymaincontainer").style.display=="block"){
                    unsafeWindow.initZones(1);
                    unsafeWindow.showMain();
                }
                unsafeWindow.showCart(parseInt(this.getAttribute("name"),10));
            },false);
            newtd=createElement("td",{},newtr);
            var cash=parseFloat(top.window.wrappedJSObject.farmisinfo[0][farmiNr]["price"],10);
            var wert=0;
            for(var i=1 ; i <= 7 ; i++){ // 7=maxanzahl produkte pro farmi
                var pid=parseInt(top.window.wrappedJSObject.farmisinfo[0][farmiNr]["p"+i],10);
                var amount=parseInt(top.window.wrappedJSObject.farmisinfo[0][farmiNr]["a"+i],10);
                if((pid > 0) && (amount > 0)){
                    newdiv=createElement("div",{},newtd);
                    produktPic(0,pid,newdiv);
                    newdiv1=createElement("div",{"class":"link hoverBgCc9","style":"display:inline-block;"+(prodStock[0][pid]<amount?"color:red;":""),"prod":pid},newdiv,numberFormat(amount)+"&nbsp;"+prodName[0][pid]);
                    newdiv1.addEventListener("mouseover",function(event){ showGoToMarketToolTip(event,this.getAttribute("prod")); },false);
                    newdiv1.addEventListener("click",function(){showMarket(this.getAttribute("prod"));},false);
                    if (farmiSum[pid]) farmiSum[pid] += amount;
                    else farmiSum[pid]=amount;
                    wert += amount*gut[pid];
                }
            }
            farmiCash += cash;
            farmiWert += wert;
            newtd=createElement("td",{"style":"text-align:right;"},newtr);
                createElement("div",{},newtd,moneyFormat(cash));
                createElement("div",{},newtd,numberFormat(100*cash/wert,1)+"%");
            newtd=createElement("td",{"style":"text-align:right;"},newtr);
                newdiv=createElement("div",{},newtd,moneyFormat(wert));
                newdiv.addEventListener("mouseover",function(event){ toolTip.show(event,"100%"); },false);
                newdiv=createElement("div",{},newtd,moneyFormat(0.9*wert));
                newdiv.addEventListener("mouseover",function(event){ toolTip.show(event,"90%"); },false);
            newtd=createElement("td",{"style":"text-align:right;"},newtr);
                newdiv=createElement("div",{},newtd,(cash>wert?"+":"")+moneyFormatInt(cash-wert));
                newdiv.addEventListener("mouseover",function(event){ toolTip.show(event,"100%"); },false);
                newdiv=createElement("div",{},newtd,(cash>0.9*wert?"+":"")+moneyFormatInt(cash-0.9*wert));
                newdiv.addEventListener("mouseover",function(event){ toolTip.show(event,"90%"); },false);
            }
        }
        if (farmiCount>0){
            newtr.setAttribute("class","borderBottom2");
            newtr=createElement("tr",{"class":"borderTop2"},newtable);
            createElement("td",{},newtr);
            newtd=createElement("td",{},newtr);
            for(var v in farmiSum){
                if(!farmiSum.hasOwnProperty(v)){ continue; }
                newdiv=createElement("div",{},newtd);
                produktPic(0,v,newdiv);
                createElement("div",{"style":"display:inline-block;"},newdiv,numberFormat(farmiSum[v])+"&nbsp;"+prodName[0][v]);
            }
            newtd=createElement("td",{"style":"text-align:right;"},newtr);
            createElement("div",{},newtd,moneyFormat(farmiCash));
            createElement("div",{},newtd,numberFormat(100*farmiCash/farmiWert,1)+"%");
            newtd=createElement("td",{"style":"text-align:right;"},newtr);
            newdiv=createElement("div",{},newtd,moneyFormat(farmiWert));
            newdiv.addEventListener("mouseover",function(event){ toolTip.show(event,"100%"); },false);
            newdiv=createElement("div",{},newtd,moneyFormat(0.9*farmiWert));
            newdiv.addEventListener("mouseover",function(event){ toolTip.show(event,"90%"); },false);
            newtd=createElement("td",{"style":"text-align:right;"},newtr);
            newdiv=createElement("div",{},newtd,(farmiCash>farmiWert?"+":"")+moneyFormatInt(farmiCash-farmiWert));
            newdiv.addEventListener("mouseover",function(event){ toolTip.show(event,"100%"); },false);
            newdiv=createElement("div",{},newtd,(farmiCash>0.9*farmiWert?"+":"")+moneyFormatInt(farmiCash-0.9*farmiWert));
            newdiv.addEventListener("mouseover",function(event){ toolTip.show(event,"90%"); },false);
        }else{
            newtr=createElement("tr",{},newtable);
            createElement("td",{"colspan":"6"},newtr,"---");
        }
        for(var w=0;w<prodNameSort[0].length;w++){
            var v=prodNameSort[0][w];
            if((!prodBlock[0][v].match(/t/))&&(!prodBlock[0][v].match(/l/))){
                var amount1=(farmiSum[v]?farmiSum[v]:0)-prodStock[0][v];
                var amount=amount1+prodMinRack[0][v];
                if (amount>0){
                    newdiv=createElement("div",{},newtdfehlt);
                    produktPic(0,v,newdiv);
                    newdiv1=createElement("div",{"style":"display:inline-block;","class":"link hoverBgCc9","name":v},newdiv,numberFormat(amount)+(amount1>0?"&nbsp;("+numberFormat(amount1)+")":"")+"&nbsp;"+prodName[0][v]);
                    newdiv1.addEventListener("mouseover",function(event){showGoToMarketToolTip(event,this.getAttribute("name"));},false);
                    newdiv1.addEventListener("click",function(){showMarket(this.getAttribute("name"));},false);
                }
            }
        }
        newtdfehlt=null;

    }catch(err){GM_logError("buildInfoPanelZones\n"+err);}
}
function buildInfoPanelUpjersAds(){
    try{
        var container=$("infoPanelInner");
        container.innerHTML="";
        createElement("div",{"align":"center","style":"font-weight:bold;line-height:30px;"},container,getText("upjersAdvertising"));
        for(var v=0;v<upjersAds.length;v++){
            createElement("div",{"style":"padding:5px;margin:5px;border:1px solid black;"},container,upjersAds[v]);
        }
    }catch(err){GM_logError("buildInfoPanelUpjersAds\n"+err);}
}
function buildInfoPanelLottery(mode){
    try{
        var modeDefault={"total":false};
        var modeOld=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_modeInfoPanelLottery"),"buildInfoPanelLottery/modeOld");
        if(typeof modeOld!="object"){ modeOld=modeDefault; }
        if(typeof mode!="object"){ mode=modeOld; }
        for(var v in modeDefault){
            if(!modeDefault.hasOwnProperty(v)){ continue; }
            if(mode[v]==undefined){ mode[v]=(modeOld[v]==undefined?modeDefault[v]:modeOld[v]); }
        }
        GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_modeInfoPanelLottery",implode(mode,"buildInfoPanelLottery/mode"));    
        // implode data older than last month
        var stichtag=new Date();
        stichtag=Math.round(((new Date(stichtag.getFullYear(),stichtag.getMonth()-1,1)).getTime())/1000);
        var month;
        for(var v=lotteryLog.length-1;v>=0;v--){
            if(lotteryLog[v][0].match(/\d+\.\d+\.\d+/)){
                if(getTime(lotteryLog[v][0])<stichtag){
                    month=/\d+\.(\d+)\.(\d+)/.exec(lotteryLog[v][0]);
                    if(month[1].length==1){
                        month=month[2]+"-0"+month[1];
                    }else{
                        month=month[2]+"-"+month[1];
                    }
                    for(var w=0;w<lotteryLog.length;w++){
                        if(lotteryLog[w][0]==month){ break; }
                    }
                    if(!lotteryLog[w]){
                        lotteryLog[w]=[month,[],[],{},[]];
                    }
                    if(lotteryLog[v][1]>0){
                        if(lotteryLog[v][2]&&(!lotteryLog[v][2].isEmpty())){
                            if(!lotteryLog[w][2][lotteryLog[v][1]]){ lotteryLog[w][2][lotteryLog[v][1]]=0; }
                            lotteryLog[w][2][lotteryLog[v][1]]++;
                            for(var p in lotteryLog[v][2]){
                                if(!lotteryLog[v][2].hasOwnProperty(p)){ continue; }
                                if(!lotteryLog[w][3][p]){ lotteryLog[w][3][p]=0; }
                                lotteryLog[w][3][p] += lotteryLog[v][2][p];
                            }
                        }else{
                            if(!lotteryLog[w][1][lotteryLog[v][1]]){ lotteryLog[w][1][lotteryLog[v][1]]=0; }
                            lotteryLog[w][1][lotteryLog[v][1]]++;
                        }
                    }
                    // lotteryLog[w][2].sortObj(sortObjFunctions["productId"]);
                    if(lotteryLog[v][3]){
                        for(var p=0;p<lotteryLog[v][3].length;p++){
                            if(!lotteryLog[w][4][lotteryLog[v][3][p]]){ lotteryLog[w][4][lotteryLog[v][3][p]]=0; }
                            lotteryLog[w][4][lotteryLog[v][3][p]]++;
                        }
                    }
                    lotteryLog.splice(v,1);
                }
            }
        }
        lotteryLog.sort(sortObjFunctions["date"]);
        GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_lotteryLog",implode(lotteryLog));

        var container,newdiv,newtable,newtable1,newtr,newtr1,newtd,newinput;
        container=$("infoPanelInner");
        container.innerHTML="";
        // Head
        newdiv=createElement("div",{"class":"borderBottom1Black","style":"height:30px;"},container);
        newtable=createElement("table",{"class":"tnormal","style":"font-weight:bold;width:100%;"},newdiv);
        newtr=createElement("tr",{},newtable);
        createElement("td",{"class":"tnormal","style":"font-weight:bold;text-align:center;"},newtr,getText("lotteryLog"));
        newtd=createElement("td",{},newtr);
        newdiv=createElement("div",{"class":"link naviItem"+(!mode["total"]?"Active":"")},newtd,getText("detail"));
        newdiv.addEventListener("click",function(){
            buildInfoPanelLottery({"total":false});
        },false);
        newdiv=createElement("div",{"class":"link naviItem"+(mode["total"]?"Active":"")},newtd,getText("total"));
        newdiv.addEventListener("click",function(){
            buildInfoPanelLottery({"total":true});
        },false);
        // Content
        newdiv=createElement("div",{"style":"height:485px;overflow:auto;"},container);
        newtable=createElement("table",{"style":"line-height:16px;width:100%","border":"1"},newdiv);
        newtr=createElement("tr",{},newtable);
        if(mode["total"]){
            // prepare data
            var lotteryLogTotal=[[],[],{},[]];
            for(var v=lotteryLog.length-1;v>=0;v--){
                if(lotteryLog[v][0].match(/\d+\.\d+\.\d+/)){
                    if(lotteryLog[v][1]>0){
                        if(lotteryLog[v][2]&&(!lotteryLog[v][2].isEmpty())){
                            if(!lotteryLogTotal[1][lotteryLog[v][1]]){ lotteryLogTotal[1][lotteryLog[v][1]]=0; }
                            lotteryLogTotal[1][lotteryLog[v][1]]++;
                            for(var p in lotteryLog[v][2]){
                                if(!lotteryLog[v][2].hasOwnProperty(p)){ continue; }
                                if(!lotteryLogTotal[2][p]){ lotteryLogTotal[2][p]=0; }
                                lotteryLogTotal[2][p] += lotteryLog[v][2][p];
                            }
                        }else{
                            if(!lotteryLogTotal[0][lotteryLog[v][1]]){ lotteryLogTotal[0][lotteryLog[v][1]]=0; }
                            lotteryLogTotal[0][lotteryLog[v][1]]++;
                        }
                    }
                    // lotteryLogTotal[2].sortObj(sortObjFunctions["productId"]);
                    if(lotteryLog[v][3]){
                        for(var p=0;p<lotteryLog[v][3].length;p++){
                            if(!lotteryLogTotal[3][lotteryLog[v][3][p]]){ lotteryLogTotal[3][lotteryLog[v][3][p]]=0; }
                            lotteryLogTotal[3][lotteryLog[v][3][p]]++;
                        }
                    }
                }else{
                    for(var j=0;j<4;j++){
                    if(j==2){ continue; }
                        for(var i=0;i<lotteryLog[v][j+1].length;i++){
                            if(lotteryLog[v][j+1][i]>0){
                                if(!lotteryLogTotal[j][i]){ lotteryLogTotal[j][i]=0; }
                                lotteryLogTotal[j][i] += lotteryLog[v][j+1][i];
                            }
                        }
                    }

                    for(var prod in lotteryLog[v][3]){
                        if(!lotteryLog[v][3].hasOwnProperty(prod)){ continue; }
                        if(!lotteryLogTotal[2][prod]){ lotteryLogTotal[2][prod]=0; }
                        lotteryLogTotal[2][prod] += lotteryLog[v][3][prod];
                    }
                }
            }
            // plot table
            createElement("th",{"style":"white-space:nowrap;"},newtr,getText("dailyTicket"));
            createElement("th",{"style":"white-space:nowrap;"},newtr,getText("boughtTickets"));

            newtr=createElement("tr",{},newtable);
            newtd=createElement("td",{},newtr);
            newdiv=createElement("div",{"style":"margin-bottom:3px;"},newtd);
            newdiv.addEventListener("mouseover",function(event){ toolTip.show(event,getText("keptLots")); },false);
            var c=0;
            for(var i=0;i<lotteryLogTotal[0].length;i++){
                if(lotteryLogTotal[0][i]>0){
                    c += lotteryLogTotal[0][i];
                    newdiv1=createElement("div",{"style":"position:relative;display:inline-block;margin-right:2px;"},newdiv);
                    createElement("img",{"style":"width:20px;border:0;","src":GFX+"city/"+i+".jpg"},newdiv1);
                    createElement("span",{},newdiv1,lotteryLogTotal[0][i]);
                }
            }
            if(c>0){ createElement("div",{"style":"position:relative;display:inline-block;"},newdiv,"&nbsp;=&nbsp;"+c+sign_mult); }

            var changedLots=0;
            newdiv=createElement("div",{"style":""},newtd);
            newdiv.addEventListener("mouseover",function(event){ toolTip.show(event,getText("exchangedLots")); },false);
            for(var i=0;i<lotteryLogTotal[1].length;i++){
                if(lotteryLogTotal[1][i]>0){
                    changedLots += lotteryLogTotal[1][i];
                    newdiv1=createElement("div",{"style":"position:relative;display:inline-block;margin-right:2px;"},newdiv);
                    createElement("img",{"style":"width:20px;border:0;","src":GFX+"city/"+i+".jpg"},newdiv1);
                    createElement("span",{},newdiv1,lotteryLogTotal[1][i]);
                }
            }
            if(changedLots>0){ createElement("div",{"style":"position:relative;display:inline-block;"},newdiv,"&nbsp;=&nbsp;"+changedLots+sign_mult); }

            var c,sum=0;
            newtable1=createElement("table",{"style":"display:inline-block;padding-right:5px;margin-right:5px;","border":"0","cellspacing":"0"},newtd);
            for(var prod in lotteryLogTotal[2]){
                if(!lotteryLogTotal[2].hasOwnProperty(prod)){ continue; }
                newtr1=createElement("tr",{"class":"link hoverBgLightblue","prod":prod},newtable1);
                newtr1.addEventListener("mouseover",function(event){ showGoToMarketToolTip(event,this.getAttribute("prod")); },false);
                newtr1.addEventListener("click",function(){showMarket(this.getAttribute("prod"));},false);
                produktPic(0,prod,createElement("td",{},newtr1));
                createElement("td",{"style":"text-align:right;"},newtr1,numberFormat(lotteryLogTotal[2][prod]));
                createElement("td",{"style":"padding-right:5px;"},newtr1,prodName[0][prod]);
                c=lotteryLogTotal[2][prod]*gut[prod];
                sum += c;
                createElement("td",{"style":"text-align:right;"},newtr1,moneyFormat(c));
            }
            newtr1=createElement("tr",{},newtable1);
            createElement("td",{"colspan":"2"},newtr1);
            createElement("td",{"style":"border-top:1px solid black;"},newtr1,sign_sum);
            createElement("td",{"style":"border-top:1px solid black;text-align:right;"},newtr1,moneyFormat(sum));
            newtr1=createElement("tr",{},newtable1);
            createElement("td",{"colspan":"2"},newtr1);
            createElement("td",{},newtr1,sign_average);
            createElement("td",{"style":"text-align:right;"},newtr1,moneyFormat(sum/changedLots));

            c=0;
            newtd=createElement("td",{},newtr);
            for(var i=0;i<lotteryLogTotal[3].length;i++){
                if(lotteryLogTotal[3][i]>0){
                    c += lotteryLogTotal[3][i];
                    newdiv1=createElement("div",{"style":"position:relative;display:inline-block;margin-right:2px;"},newdiv);
                    createElement("img",{"style":"width:20px;border:0;","src":GFX+"city/"+i+".jpg"},newdiv1);
                    createElement("span",{},newdiv1,lotteryLogTotal[3][i]);
                }
            }
            if(c>0){ createElement("div",{"style":"position:relative;display:inline-block;"},newdiv,"&nbsp;=&nbsp;"+c+sign_mult); }
        }else{
            createElement("th",{"style":"white-space:nowrap;"},newtr,getText("day"));
            createElement("th",{"style":"white-space:nowrap;"},newtr,getText("dailyTicket"));
            createElement("th",{"style":"white-space:nowrap;"},newtr,getText("boughtTickets"));

            for(var v=lotteryLog.length-1;v>=0;v--){
                newtr=createElement("tr",{},newtable);
                createElement("td",{},newtr,lotteryLog[v][0]);

                if(lotteryLog[v][0].match(/\d+\.\d+\.\d+/)){
                    newtd=createElement("td",{},newtr);
                    newdiv=createElement("div",{"style":"display:inline-block;margin-right:3px;vertical-align:top;"},newtd);
                    if(lotteryLog[v][1]>0){ createElement("img",{"style":"width:20px;border:0;","src":GFX+"city/"+lotteryLog[v][1]+".jpg"},newdiv); }
                    if(lotteryLog[v][2]){
                        var c,sum=0;
                        newtable1=createElement("table",{"style":"display:inline-block;border-right:1px solid black;padding-right:5px;margin-right:5px;","border":"0","cellspacing":"0"},newtd);
                        for(var prod in lotteryLog[v][2]){
                            if(!lotteryLog[v][2].hasOwnProperty(prod)){ continue; }
                            newtr1=createElement("tr",{"class":"link hoverBgLightblue","prod":prod},newtable1);
                            newtr1.addEventListener("mouseover",function(event){ showGoToMarketToolTip(event,this.getAttribute("prod")); },false);
                            newtr1.addEventListener("click",function(){showMarket(this.getAttribute("prod"));},false);
                            produktPic(0,prod,createElement("td",{},newtr1));
                            createElement("td",{"style":"text-align:right;"},newtr1,numberFormat(lotteryLog[v][2][prod]));
                            createElement("td",{"style":"padding-right:5px;"},newtr1,prodName[0][prod]);
                            c=lotteryLog[v][2][prod]*gut[prod];
                            sum += c;
                            createElement("td",{"style":"text-align:right;"},newtr1,moneyFormat(c));
                        }
                        createElement("div",{"style":"display:inline-block;vertical-align:bottom;"},newtd,moneyFormat(sum));
                    }

                    newtd=createElement("td",{},newtr);
                    if(lotteryLog[v][3]){
                        for(var w=0;w<lotteryLog[v][3].length;w++){
                            createElement("img",{"style":"width:20px;border:0;","src":GFX+"city/"+lotteryLog[v][3][w]+".jpg"},newtd);
                        }
                    }
                }else{
                    newtd=createElement("td",{},newtr);
                    newdiv=createElement("div",{"style":"margin-bottom:3px;"},newtd);
                    newdiv.addEventListener("mouseover",function(event){ toolTip.show(event,getText("keptLots")); },false);
                    var c=0;
                    for(var i=0;i<lotteryLog[v][1].length;i++){
                        if(lotteryLog[v][1][i]>0){
                            c += lotteryLog[v][1][i];
                            newdiv1=createElement("div",{"style":"position:relative;display:inline-block;margin-right:2px;"},newdiv);
                            createElement("img",{"style":"width:20px;border:0;","src":GFX+"city/"+i+".jpg"},newdiv1);
                            createElement("span",{},newdiv1,lotteryLog[v][1][i]);
                        }
                    }
                    if(c>0){ createElement("div",{"style":"position:relative;display:inline-block;"},newdiv,"&nbsp;=&nbsp;"+c+sign_mult); }

                    var changedLots=0;
                    newdiv=createElement("div",{"style":""},newtd);
                    newdiv.addEventListener("mouseover",function(event){ toolTip.show(event,getText("exchangedLots")); },false);
                    for(var i=0;i<lotteryLog[v][2].length;i++){
                        if(lotteryLog[v][2][i]>0){
                            changedLots += lotteryLog[v][2][i];
                            newdiv1=createElement("div",{"style":"position:relative;display:inline-block;margin-right:2px;"},newdiv);
                            createElement("img",{"style":"width:20px;border:0;","src":GFX+"city/"+i+".jpg"},newdiv1);
                            createElement("span",{},newdiv1,lotteryLog[v][2][i]);
                        }
                    }
                    if(changedLots>0){ createElement("div",{"style":"position:relative;display:inline-block;"},newdiv,"&nbsp;=&nbsp;"+changedLots+sign_mult); }

                    var sum=0;
                    for(var prod in lotteryLog[v][3]){
                        if(!lotteryLog[v][3].hasOwnProperty(prod)){ continue; }
                        newdiv=createElement("div",{"class":"link hoverBgLightblue","prod":prod,"style":"position:relative;display:inline-block;margin-right:3px;"},newtd);
                        newdiv.addEventListener("mouseover",function(event){ showGoToMarketToolTip(event,this.getAttribute("prod")); },false);
                        newdiv.addEventListener("click",function(){showMarket(this.getAttribute("prod"));},false);
                        produktPic(0,prod,newdiv);
                        createElement("span",{"style":"text-align:right;"},newdiv,numberFormat(lotteryLog[v][3][prod]));
                        c=lotteryLog[v][3][prod]*gut[prod];
                        sum += c;
                    }
                    createElement("div",{},newtd,moneyFormat(sum)+"&nbsp;("+sign_average+moneyFormat(sum/changedLots)+")");

                    c=0;
                    newtd=createElement("td",{},newtr);
                    for(var i=0;i<lotteryLog[v][4].length;i++){
                        if(lotteryLog[v][4][i]>0){
                            c += lotteryLog[v][4][i];
                            newdiv1=createElement("div",{"style":"position:relative;display:inline-block;margin-right:2px;"},newdiv);
                            createElement("img",{"style":"width:20px;border:0;","src":GFX+"city/"+i+".jpg"},newdiv1);
                            createElement("span",{},newdiv1,lotteryLog[v][4][i]);
                        }
                    }
                    if(c>0){ createElement("div",{"style":"position:relative;display:inline-block;"},newdiv,"&nbsp;=&nbsp;"+c+sign_mult); }
                }
            }
        }
        container=null;newdiv=null;newtable=null;newtable1=null;newtr=null;newtr1=null;newtd=null;newinput=null;
    }catch(err){GM_logError("buildInfoPanelLottery\n"+err);}
}
function buildInfoPanelDonkey(mode){
    try{
        var modeDefault={"total":false};
        var modeOld=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_modeInfoPanelDonkey"),"buildInfoPanelDonkey/modeOld");
        if(typeof modeOld!="object"){ modeOld=modeDefault; }
        if(typeof mode!="object"){ mode=modeOld; }
        for(var v in modeDefault){
            if(!modeDefault.hasOwnProperty(v)){ continue; }
            if(mode[v]==undefined){ mode[v]=(modeOld[v]==undefined?modeDefault[v]:modeOld[v]); }
        }
        GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_modeInfoPanelDonkey",implode(mode,"buildInfoPanelDonkey/mode"));  
        // implode data older than last month
    try{
        var stichtag=new Date();
        stichtag=Math.round(((new Date(stichtag.getFullYear(),stichtag.getMonth()-1,1)).getTime())/1000);
        var month;
        for(var v=logDonkey.length-1;v>=0;v--){
            for(var w=logDonkey[v][2].length-1;w>=0;w--){
                if(!logDonkey[v][2][w][3]){ logDonkey[v][2][w][3]=1; }
            }
        }
        for(var v=logDonkey.length-1;v>=0;v--){
            if(logDonkey[v][0].match(/\d+\.\d+\.\d+/)){
                if(getTime(logDonkey[v][0])<stichtag){
                    month=/\d+\.(\d+)\.(\d+)/.exec(logDonkey[v][0]);
                    if(month[1].length==1){
                        month=month[2]+"-0"+month[1];
                    }else{
                        month=month[2]+"-"+month[1];
                    }
                    for(var w=0;w<logDonkey.length;w++){
                        if(logDonkey[w][0]==month){ break; }
                    }
                    if(!logDonkey[w]){
                        logDonkey[w]=[month,0,[]];
                    }
                    logDonkey[w][1]+=logDonkey[v][1];
                    for(var i=logDonkey[v][2].length-1;i>=0;i--){
                        for(var j=logDonkey[w][2].length-1;j>=0;j--){
                            if((logDonkey[v][2][i][0]==logDonkey[w][2][j][0])&&(logDonkey[v][2][i][1]==logDonkey[w][2][j][1])&&(logDonkey[v][2][i][2]==logDonkey[w][2][j][2])){
                                logDonkey[w][2][j][3]+=logDonkey[v][2][i][3];
                                break;
                            }
                        }
                        if(j<0){
                            logDonkey[w][2].push(logDonkey[v][2][i]);
                        }
                    }
                    logDonkey.splice(v,1);
                }
            }
        }
        logDonkey.sort(sortObjFunctions["date"]);
        GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_logDonkey",implode(logDonkey));
    }catch(err){GM_logError("buildInfoPanelWaltraud (old data)\nv="+v+"\n"+err);}
    
        var container,newdiv,newtable,newtr,newtd;
        container=$("infoPanelInner");
        container.innerHTML="";
        // Head
        newdiv=createElement("div",{"class":"borderBottom1Black","style":"height:30px;"},container);
        newtable=createElement("table",{"class":"tnormal","style":"font-weight:bold;width:100%;"},newdiv);
        newtr=createElement("tr",{},newtable);
        createElement("td",{"class":"tnormal","style":"font-weight:bold;text-align:center;"},newtr,getText("logDonkey"));
        newtd=createElement("td",{},newtr);
        newdiv=createElement("div",{"class":"link naviItem"+(!mode["total"]?"Active":"")},newtd,getText("detail"));
        newdiv.addEventListener("click",function(){
            buildInfoPanelDonkey({"total":false});
        },false);
        newdiv=createElement("div",{"class":"link naviItem"+(mode["total"]?"Active":"")},newtd,getText("total"));
        newdiv.addEventListener("click",function(){
            buildInfoPanelDonkey({"total":true});
        },false);
        // Content
        newdiv=createElement("div",{"style":"height:485px;overflow:auto;"},container);
        newtable=createElement("table",{"style":"line-height:16px;width:100%","border":"1"},newdiv);
        newtr=createElement("tr",{},newtable);
        if(mode["total"]){
        /*
            // prepare data
            var lotteryLogTotal=[[],[],{},[]];
            for(var v=lotteryLog.length-1;v>=0;v--){
                if(lotteryLog[v][0].match(/\d+\.\d+\.\d+/)){
                    if(lotteryLog[v][1]>0){
                        if(lotteryLog[v][2]&&(!lotteryLog[v][2].isEmpty())){
                            if(!lotteryLogTotal[1][lotteryLog[v][1]]){ lotteryLogTotal[1][lotteryLog[v][1]]=0; }
                            lotteryLogTotal[1][lotteryLog[v][1]]++;
                            for(var p in lotteryLog[v][2]){
                                if(!lotteryLog[v][2].hasOwnProperty(p)){ continue; }
                                if(!lotteryLogTotal[2][p]){ lotteryLogTotal[2][p]=0; }
                                lotteryLogTotal[2][p] += lotteryLog[v][2][p];
                            }
                        }else{
                            if(!lotteryLogTotal[0][lotteryLog[v][1]]){ lotteryLogTotal[0][lotteryLog[v][1]]=0; }
                            lotteryLogTotal[0][lotteryLog[v][1]]++;
                        }
                    }
                    // lotteryLogTotal[2].sortObj(sortObjFunctions["productId"]);
                    if(lotteryLog[v][3]){
                        for(var p=0;p<lotteryLog[v][3].length;p++){
                            if(!lotteryLogTotal[3][lotteryLog[v][3][p]]){ lotteryLogTotal[3][lotteryLog[v][3][p]]=0; }
                            lotteryLogTotal[3][lotteryLog[v][3][p]]++;
                        }
                    }
                }else{
                    for(var j=0;j<4;j++){
                    if(j==2){ continue; }
                        for(var i=0;i<lotteryLog[v][j+1].length;i++){
                            if(lotteryLog[v][j+1][i]>0){
                                if(!lotteryLogTotal[j][i]){ lotteryLogTotal[j][i]=0; }
                                lotteryLogTotal[j][i] += lotteryLog[v][j+1][i];
                            }
                        }
                    }

                    for(var prod in lotteryLog[v][3]){
                        if(!lotteryLog[v][3].hasOwnProperty(prod)){ continue; }
                        if(!lotteryLogTotal[2][prod]){ lotteryLogTotal[2][prod]=0; }
                        lotteryLogTotal[2][prod] += lotteryLog[v][3][prod];
                    }
                }
            }
            // plot table
            createElement("th",{"style":"white-space:nowrap;"},newtr,getText("dailyTicket"));
            createElement("th",{"style":"white-space:nowrap;"},newtr,getText("boughtTickets"));

            newtr=createElement("tr",{},newtable);
            newtd=createElement("td",{},newtr);
            newdiv=createElement("div",{"style":"margin-bottom:3px;"},newtd);
            newdiv.addEventListener("mouseover",function(event){ toolTip.show(event,getText("keptLots")); },false);
            var c=0;
            for(var i=0;i<lotteryLogTotal[0].length;i++){
                if(lotteryLogTotal[0][i]>0){
                    c += lotteryLogTotal[0][i];
                    newdiv1=createElement("div",{"style":"position:relative;display:inline-block;margin-right:2px;"},newdiv);
                    createElement("img",{"style":"width:20px;border:0;","src":GFX+"city/"+i+".jpg"},newdiv1);
                    createElement("span",{},newdiv1,lotteryLogTotal[0][i]);
                }
            }
            if(c>0){ createElement("div",{"style":"position:relative;display:inline-block;"},newdiv,"&nbsp;=&nbsp;"+c+sign_mult); }

            var changedLots=0;
            newdiv=createElement("div",{"style":""},newtd);
            newdiv.addEventListener("mouseover",function(event){ toolTip.show(event,getText("exchangedLots")); },false);
            for(var i=0;i<lotteryLogTotal[1].length;i++){
                if(lotteryLogTotal[1][i]>0){
                    changedLots += lotteryLogTotal[1][i];
                    newdiv1=createElement("div",{"style":"position:relative;display:inline-block;margin-right:2px;"},newdiv);
                    createElement("img",{"style":"width:20px;border:0;","src":GFX+"city/"+i+".jpg"},newdiv1);
                    createElement("span",{},newdiv1,lotteryLogTotal[1][i]);
                }
            }
            if(changedLots>0){ createElement("div",{"style":"position:relative;display:inline-block;"},newdiv,"&nbsp;=&nbsp;"+changedLots+sign_mult); }

            var c,sum=0;
            newtable1=createElement("table",{"style":"display:inline-block;padding-right:5px;margin-right:5px;","border":"0","cellspacing":"0"},newtd);
            for(var prod in lotteryLogTotal[2]){
                if(!lotteryLogTotal[2].hasOwnProperty(prod)){ continue; }
                newtr1=createElement("tr",{"class":"link hoverBgLightblue","prod":prod},newtable1);
                newtr1.addEventListener("mouseover",function(event){ showGoToMarketToolTip(event,this.getAttribute("prod")); },false);
                newtr1.addEventListener("click",function(){showMarket(this.getAttribute("prod"));},false);
                produktPic(0,prod,createElement("td",{},newtr1));
                createElement("td",{"style":"text-align:right;"},newtr1,numberFormat(lotteryLogTotal[2][prod]));
                createElement("td",{"style":"padding-right:5px;"},newtr1,prodName[0][prod]);
                c=lotteryLogTotal[2][prod]*gut[prod];
                sum += c;
                createElement("td",{"style":"text-align:right;"},newtr1,moneyFormat(c));
            }
            newtr1=createElement("tr",{},newtable1);
            createElement("td",{"colspan":"2"},newtr1);
            createElement("td",{"style":"border-top:1px solid black;"},newtr1,sign_sum);
            createElement("td",{"style":"border-top:1px solid black;text-align:right;"},newtr1,moneyFormat(sum));
            newtr1=createElement("tr",{},newtable1);
            createElement("td",{"colspan":"2"},newtr1);
            createElement("td",{},newtr1,sign_average);
            createElement("td",{"style":"text-align:right;"},newtr1,moneyFormat(sum/changedLots));

            c=0;
            newtd=createElement("td",{},newtr);
            for(var i=0;i<lotteryLogTotal[3].length;i++){
                if(lotteryLogTotal[3][i]>0){
                    c += lotteryLogTotal[3][i];
                    newdiv1=createElement("div",{"style":"position:relative;display:inline-block;margin-right:2px;"},newdiv);
                    createElement("img",{"style":"width:20px;border:0;","src":GFX+"city/"+i+".jpg"},newdiv1);
                    createElement("span",{},newdiv1,lotteryLogTotal[3][i]);
                }
            }
            if(c>0){ createElement("div",{"style":"position:relative;display:inline-block;"},newdiv,"&nbsp;=&nbsp;"+c+sign_mult); }
        */
        }else{
            createElement("th",{"style":"white-space:nowrap;"},newtr,getText("day"));
            createElement("th",{"style":"white-space:nowrap;"},newtr,getText("points"));
            createElement("th",{"style":"white-space:nowrap;"},newtr,getText("goods"));

            for(var v=logDonkey.length-1;v>=0;v--){
                newtr=createElement("tr",{},newtable);
                createElement("td",{},newtr,logDonkey[v][0]);
                newtd=createElement("td",{},newtr);
                pointsFormat(logDonkey[v][1],"span",newtd);
                newtd=createElement("td",{},newtr);
                if(logDonkey[v][2]){
                    for(var w=0;w<logDonkey[v][2].length;w++){
                        switch(logDonkey[v][2][w][0]){
                        case 1:{
                            newdiv=createElement("div",{"class":"hoverBgLightblue","prod":logDonkey[v][2][w][2]},newtd);
                            if(logDonkey[v][2][w][1]==0){
                                newdiv.classList.add("link");
                                newdiv.addEventListener("mouseover",function(event){ showGoToMarketToolTip(event,this.getAttribute("prod")); },false);
                                newdiv.addEventListener("click",function(){showMarket(this.getAttribute("prod"));},false);
                            }
                            produktPic(logDonkey[v][2][w][1],logDonkey[v][2][w][2],newdiv);
                            createElement("span",{},newdiv,numberFormat(logDonkey[v][2][w][3])+"&nbsp;"+prodName[logDonkey[v][2][w][1]][logDonkey[v][2][w][2]]);
                            if((logDonkey[v][2][w][1]==0)&&(gut[logDonkey[v][2][w][2]])){
                                createElement("span",{"style":"padding-left:5px;"},newdiv,"("+moneyFormat(logDonkey[v][2][w][3]*gut[logDonkey[v][2][w][2]])+")");
                            }
                        break;}
                        case 5:{
                            newdiv=createElement("div",{},newtd);
                            createElement("img",{"src":GFX+"adbonus.gif","style":"border:0;height:15px;"},newdiv);
                            createElement("span",{},newdiv,unsafeWindow.t_donkey_farmiadd);
                            if(logDonkey[v][2][w][3]>1){
                                createElement("span",{},newdiv," ("+logDonkey[v][2][w][3]+"x)");
                            }
                        break;}
                        case 12:{
                            newdiv=createElement("div",{},newtd);
                            createElement("span",{},newdiv,unsafeWindow.quest_reward_6+": ");
                            createElement("img",{"src":GFX+"farmhouse/thumbs/"+logDonkey[v][2][w][1]+".jpg","style":"border:0;height:50px;width:50px;"},newdiv);
                            if(logDonkey[v][2][w][3]>1){
                                createElement("span",{},newdiv," ("+logDonkey[v][2][w][3]+"x)");
                            }
                        break;}
                        case 13:{
                            newdiv=createElement("div",{},newtd);
                            createElement("span",{},newdiv,getText("shadowboxitem")+": ");
                            createElement("img",{"src":GFX+"gifts/"+logDonkey[v][2][w][1]+".gif","style":"border:0;height:50px;width:50px;"},newdiv);
                            if(logDonkey[v][2][w][3]>1){
                                createElement("span",{},newdiv," ("+logDonkey[v][2][w][3]+"x)");
                            }
                        break;}
                        }
                    }
                }
            }
        }
        container=null;newdiv=null;newtable=null;newtr=null;newtd=null;
    }catch(err){GM_logError("buildInfoPanelWaltraud\n"+err);}
}
function buildInfoPanelFarmies(mode){
    try{
        var modeDefault={"limit":95};
        var modeOld=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_modeInfoPanelFarmies"),"buildInfoPanelFarmies/modeOld");
        if(typeof modeOld!="object"){ modeOld=modeDefault; }
        if(typeof mode!="object"){ mode=modeOld; }
        for(var v in modeDefault){
            if(!modeDefault.hasOwnProperty(v)){ continue; }
            if(mode[v]==undefined){ mode[v]=(modeOld[v]==undefined?modeDefault[v]:modeOld[v]); }
        }
        GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_modeInfoPanelFarmies",implode(mode,"buildInfoPanelFarmies/mode"));    
        var newFarmiumsatz=new Object();
        var totalPrice=0;
        var totalWert=0;
        var totalPriceOk=0;
        var totalWertOk=0;
        var countFarmisOk=0;
        var countFarmisAll=0;
        var totalProducts=new Object();

        var container,newdiv,newtable,newtr,newtd;
        container=$("infoPanelInner");
        container.innerHTML="";
        newdiv=createElement("div",{"style":"height:100%;width:565px;overflow:auto;"},container);
        newtable=createElement("table",{"style":"width:100%","border":"1"},newdiv);
        newtable.addEventListener("mouseover",function(event){
            var node=event.target;
            var mouseOverText=node.getAttribute("mouseOverText");
            while((node!=this)&&(!mouseOverText)){
                node=node.parentNode;
                mouseOverText=node.getAttribute("mouseOverText");
            }
            if(mouseOverText){ toolTip.show(event,mouseOverText); }
            node=null;mouseOverText=null;
        },false);

        // selection bar on the right side
        newdiv1=createElement("div",{"class":"link","style":"position:absolute;top:0;right:0;border:1px solid black;"},container);
        newdiv1.addEventListener("mouseover",function(event){
            var node=event.target;
            var mouseOverText=node.getAttribute("mouseOverText");
            while((node!=this)&&(!mouseOverText)){
                node=node.parentNode;
                mouseOverText=node.getAttribute("mouseOverText");
            }
            if(mouseOverText){ toolTip.show(event,mouseOverText); }
            node=null;mouseOverText=null;
        },false);
        for(var v=200;v>-1;v--){
            newdiv=createElement("div",{"class":"hoverBgRed","style":"width:20px;height:2.5px;","mouseOverText":v+"%"},newdiv1);
            if (v<=mode["limit"]){ newdiv.style.backgroundColor="blue"; }
            if (v==90||v==100) newdiv.style.borderTop="1px solid black";
            newdiv.addEventListener("click",function(){
                buildInfoPanelFarmies({"limit":parseInt(this.getAttribute("mouseOverText"),10)});
            },false);
        }

        // Farmi table
        newtr=createElement("tr",{},newtable);
        createElement("th",{"style":"border-bottom:2px solid black;"},newtr,"");
        createElement("th",{"style":"border-bottom:2px solid black;"},newtr,getText("products"));
        createElement("th",{"style":"border-bottom:2px solid black;"},newtr,getText("money"));
        createElement("th",{"style":"border-bottom:2px solid black;","colspan":"2"},newtr,getText("value"));

        var borderTop;
        var c=0;
        var prev=null;
        for(var v=0;v<farmiLog.length;v++){
            countFarmisAll++;
            newtr=createElement("tr",{"class":"hoverBgCc9"},newtable);
            if (prev==null){
                borderTop="2px solid black;";
                newtd1=createElement("td",{"style":"border-top:"+borderTop},newtr,farmiLog[v][1]);
                c=1;
            }else if (farmiLog[v][1]!=farmiLog[prev][1]){
                borderTop="2px solid black;";
                newtd1.innerHTML += "<br>("+c+")";
                newtd1=createElement("td",{"style":"border-top:"+borderTop},newtr,farmiLog[v][1]);
                c=1;
            }else{
                borderTop="1px solid black;";
                newtd1.rowSpan=++c;
            }
            newtd=createElement("td",{"style":"border-top:"+borderTop},newtr);
            var wert=0;
            for(var w in farmiLog[v][3]){
                if(!farmiLog[v][3].hasOwnProperty(w)){ continue; }
                newdiv=createElement("div",{"style":"line-height:16px;"},newtd);
                produktPic(0,w,newdiv);
                createElement("div",{"style":"display:inline-block;"},newdiv,numberFormat(farmiLog[v][3][w])+"&nbsp;"+prodName[0][w]);
                wert += farmiLog[v][3][w]*gut[w];
            }
            totalPrice += farmiLog[v][2];
            totalWert += wert;
            newtd=createElement("td",{"style":"text-align:right;border-top:"+borderTop},newtr);
                createElement("div",{},newtd,moneyFormatInt(farmiLog[v][2]));
                newdiv=createElement("div",{},newtd,numberFormat(100*farmiLog[v][2]/wert,1)+"%");
                if (100*farmiLog[v][2]>mode["limit"]*wert){
                    countFarmisOk++;
                    for(var w in farmiLog[v][3]){
                        if(!farmiLog[v][3].hasOwnProperty(w)){ continue; }
                        if(totalProducts[w]==undefined){ totalProducts[w]=[0,0]; }
                        totalProducts[w][0]++;
                        totalProducts[w][1]+=farmiLog[v][3][w];
                    }
                    totalPriceOk += farmiLog[v][2];
                    totalWertOk += wert;

                }else{ newdiv.style.backgroundColor="red"; }
            newtd=createElement("td",{"style":"text-align:right;border-top:"+borderTop},newtr);
                createElement("div",{"mouseOverText":"100%"},newtd,moneyFormatInt(wert));
                createElement("div",{"mouseOverText":"90%"},newtd,moneyFormatInt(0.9*wert));
            newtd=createElement("td",{"style":"text-align:right;border-top:"+borderTop},newtr);
                createElement("div",{"mouseOverText":"100%"},newtd,(farmiLog[v][2]>wert?"+":"")+moneyFormatInt(farmiLog[v][2]-wert));
                createElement("div",{"mouseOverText":"90%"},newtd,(farmiLog[v][2]>0.9*wert?"+":"")+moneyFormatInt(farmiLog[v][2]-0.9*wert));
            if(!newFarmiumsatz[farmiLog[v][1]]){ newFarmiumsatz[farmiLog[v][1]]=0; }
            newFarmiumsatz[farmiLog[v][1]] += farmiLog[v][2];
            prev=v;
        }
        if(countFarmisAll>0){ newtd1.innerHTML += "<br>("+c+")"; }
        for(var v in newFarmiumsatz){
            if(!newFarmiumsatz.hasOwnProperty(v)){ continue; }
            newFarmiumsatz[v]=Math.round(100*newFarmiumsatz[v])/100;
            for(var w=0;w<levelLog.length;w++){
                if(levelLog[w][0]==v){ levelLog[w][5]=newFarmiumsatz[v]; break; } //dont override all because data could be joined to monthly
            }
        }
        GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_levelLog",implode(levelLog),70);
        for(var v in totalProducts){
            if(!totalProducts.hasOwnProperty(v)){ continue; }
            totalProducts[v][2]=totalProducts[v][1]/totalProducts[v][0];
        }

        if(countFarmisAll>0){
            newtr=createElement("tr");
            newtable.insertBefore(newtr,newtable.children[1]);
            createElement("td",{},newtr,getText("total")+"<br>("+countFarmisOk+")");
            newtd=createElement("td",{"id":"tdTotalProducts"},newtr);
            function buildTotalProducts(mode){
                $("tdTotalProducts").innerHTML="";
                var newtable=createElement("table",{cellspacing:"0",cellpadding:"0"},$("tdTotalProducts"));
                var newtr=createElement("tr",{},newtable);
                var newtd=createElement("td",{"class":"link hoverBgLightblue","style":"text-align:center;padding-right:3px;border-bottom:1px solid black;"},newtr,getText("product"));
                if (mode==0){
                    newtd.style.backgroundColor="lightblue";
                    totalProducts.sortObj(sortObjFunctions["int"],true);
                }else{
                    newtd.addEventListener("click",function(){buildTotalProducts(0);},false);
                    totalProducts.sortObj(function(mode){return function(a,b){return (a[1][mode-1]-b[1][mode-1]);}}(mode),true);
                }
                newtd=createElement("td",{"class":"link hoverBgLightblue","style":"text-align:center;border-left:1px solid black;border-bottom:1px solid black;padding-left:3px;padding-right:3px;"},newtr,sign_mult);
                if (mode==1){ newtd.style.backgroundColor="lightblue"; }
                else{
                    newtd.addEventListener("click",function(){buildTotalProducts(1);},false);
                }
                newtd=createElement("td",{"class":"link hoverBgLightblue","style":"text-align:center;border-left:1px solid black;border-bottom:1px solid black;padding-left:3px;padding-right:3px;"},newtr,sign_sum);
                if (mode==2){ newtd.style.backgroundColor="lightblue"; }
                else{
                    newtd.addEventListener("click",function(){buildTotalProducts(2);},false);
                }
                newtd=createElement("td",{"class":"link hoverBgLightblue","style":"text-align:center;border-left:1px solid black;border-bottom:1px solid black;padding-left:3px;padding-right:3px;"},newtr,sign_sum+"/"+sign_mult);
                if (mode==3){ newtd.style.backgroundColor="lightblue"; }
                else{
                    newtd.addEventListener("click",function(){buildTotalProducts(3);},false);
                }
                for(var i=0;i<totalProducts.order.length;i++){
                    var v=totalProducts.order[i];
                    //newdiv=createElement("div",{"style":"line-height:16px;"},newtd);
                    newtr=createElement("tr",{"class":"hoverBgCc9"},newtable);
                    newtd=createElement("td",{"style":"padding-right:3px;"},newtr);
                    produktPic(0,v,newtd);
                    createElement("div",{"style":"display:inline-block;"},newtd,prodName[0][v]);
                    createElement("td",{"style":"text-align:right;border-left:1px solid black;padding-left:3px;padding-right:3px;"},newtr,numberFormat(totalProducts[v][0]));
                    createElement("td",{"style":"text-align:right;border-left:1px solid black;padding-left:3px;padding-right:3px;"},newtr,numberFormat(totalProducts[v][1]));
                    createElement("td",{"style":"text-align:right;border-left:1px solid black;padding-left:3px;padding-right:3px;"},newtr,numberFormat(totalProducts[v][2]));
                }
                newtable=null;newtr=null;newtd=null;
            }
            buildTotalProducts(0);
            newtd=createElement("td",{"style":"text-align:right;"},newtr);
                createElement("div",{},newtd,moneyFormatInt(totalPriceOk));
                createElement("div",{},newtd,numberFormat(100*totalPriceOk/totalWertOk,1)+"%");
            newtd=createElement("td",{"style":"text-align:right;"},newtr);
                createElement("div",{"mouseOverText":"100%"},newtd,moneyFormatInt(totalWertOk));
                createElement("div",{"mouseOverText":"90%"},newtd,moneyFormatInt(0.9*totalWertOk));
            newtd=createElement("td",{"style":"text-align:right;"},newtr);
                createElement("div",{"mouseOverText":"100%"},newtd,(totalPriceOk>totalWertOk?"+":"")+moneyFormatInt(totalPriceOk-totalWertOk));
                createElement("div",{"mouseOverText":"90%"},newtd,(totalPriceOk>0.9*totalWertOk?"+":"")+moneyFormatInt(totalPriceOk-0.9*totalWertOk));

            newtr=createElement("tr",{"class":"hoverBgCc9"});
            newtable.insertBefore(newtr,newtable.children[2]);
            newtd=createElement("td",{},newtr);
                createElement("div",{},newtd,sign_average+" ("+countFarmisOk+")");
            newtd=createElement("td",{},newtr,"");
                createElement("div",{},newtd,">"+numberFormat(mode["limit"])+"%");
            newtd=createElement("td",{"style":"text-align:right;"},newtr);
                createElement("div",{},newtd,moneyFormatInt(totalPriceOk/countFarmisOk));
            newtd=createElement("td",{"style":"text-align:right;"},newtr);
                createElement("div",{"mouseOverText":"100%<br>"+sign_average+"[>"+numberFormat(mode["limit"])+"%]"},newtd,moneyFormatInt(totalWertOk/countFarmisOk));
                createElement("div",{"mouseOverText":" 90%<br>"+sign_average+"[>"+numberFormat(mode["limit"])+"%]"},newtd,moneyFormatInt(0.9*totalWertOk/countFarmisOk));
                createElement("div",{"mouseOverText":"100%<br>"+sign_sum+"[>"+numberFormat(mode["limit"])+"%]/"+getText("all"),"style":"border-top:1px solid black;"},newtd,moneyFormatInt(totalWertOk/countFarmisAll));
                createElement("div",{"mouseOverText":" 90%<br>"+sign_sum+"[>"+numberFormat(mode["limit"])+"%]/"+getText("all")},newtd,moneyFormatInt(0.9*totalWertOk/countFarmisAll));
            newtd=createElement("td",{"style":"text-align:right;"},newtr);
                createElement("div",{"mouseOverText":"100%"},newtd,(totalPriceOk>totalWertOk?"+":"")+moneyFormatInt((totalPriceOk-totalWertOk)/countFarmisOk));
                createElement("div",{"mouseOverText":" 90%"},newtd,(totalPriceOk>0.9*totalWertOk?"+":"")+moneyFormatInt((totalPriceOk-0.9*totalWertOk)/countFarmisOk));
                createElement("div",{"mouseOverText":"100%","style":"border-top:1px solid black;"},newtd,(totalPriceOk>totalWertOk?"+":"")+moneyFormatInt((totalPriceOk-totalWertOk)/countFarmisAll));
                createElement("div",{"mouseOverText":" 90%"},newtd,(totalPriceOk>0.9*totalWertOk?"+":"")+moneyFormatInt((totalPriceOk-0.9*totalWertOk)/countFarmisAll));

            newtr=createElement("tr",{"class":"hoverBgCc9"});
            newtable.insertBefore(newtr,newtable.children[3]);
            newtd=createElement("td",{},newtr);
                createElement("div",{},newtd,sign_average+" ("+countFarmisAll+")");
            newtd=createElement("td",{},newtr);
                createElement("div",{},newtd,getText("all"));
            newtd=createElement("td",{"style":"text-align:right;"},newtr);
                createElement("div",{},newtd,moneyFormatInt(totalPrice/countFarmisAll));
            newtd=createElement("td",{"style":"text-align:right;"},newtr);
                createElement("div",{"mouseOverText":"100%"},newtd,moneyFormatInt(totalWert/countFarmisAll));
                createElement("div",{"mouseOverText":"90%"},newtd,moneyFormatInt(0.9*totalWert/countFarmisAll));
            newtd=createElement("td",{"style":"text-align:right;"},newtr);
                createElement("div",{"mouseOverText":"100%"},newtd,(totalPrice>totalWert?"+":"")+moneyFormatInt((totalPrice-totalWert)/countFarmisAll));
                createElement("div",{"mouseOverText":"90%"},newtd,(totalPrice>0.9*totalWert?"+":"")+moneyFormatInt((totalPrice-0.9*totalWert)/countFarmisAll));
        }
        container=null;newdiv=null;newtable=null;newtr=null;newtd=null;
    }catch(err){GM_logError("buildInfoPanelFarmies\n"+err);}
}
function buildInfoPanelFormulas(mode){
    try{
        // unsafeWindow.formulas[0][id]:
        // 0: id
        // 1: needed level
        // 2: name
        // 3: ingredients [[id,amount],[id,amount],[id,amount]]
        // 4: baking time in sek
        // 5: gain [0|[prod,amount],0|[prod,+val,time in sek],0|[prod,+pts,time in sek]]
        // 6: price money
        // 7: price coins
        // 8: points for baking
        // 9: [0,1,2,3,4,5,6]
        //10: ?
        //endremain: time to end
        //end: date until recipe is buyable 
        var modeDefault={"showAll":false,"filterType":"0,1,2,"};
        var modeOld=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_modeInfoPanelFormulas"),"buildInfoPanelFormulas/modeOld");
        if(typeof modeOld!="object"){ modeOld=modeDefault; }
        if(typeof mode!="object"){ mode=modeOld; }
        for(var v in modeDefault){
            if(!modeDefault.hasOwnProperty(v)){ continue; }
            if(mode[v]==undefined){ mode[v]=(modeOld[v]==undefined?modeDefault[v]:modeOld[v]); }
        }
        GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_modeInfoPanelFormulas",implode(mode,"buildInfoPanelFormulas/mode"));  
        var container=$("infoPanelInner");
        container.innerHTML="";
        var newdiv,newdiv1,newtable,newtr,newtd,newtd1,newinput;
        newdiv=createElement("div",{"class":"borderBottom1Black","style":"height:50px;"},container);
        newtable=createElement("table",{"style":"width:100%;","border":0,"cellspacing":0},newdiv);
        newtr=createElement("tr",{},newtable);
        createElement("td",{"class":"tnormal","style":"font-weight:bold;text-align:center;"},newtr,getText("recipes"));
        newtd=createElement("td",{},newtr);
        newinput=createElement("input",{"type":"checkbox","class":"link","checked":mode["showAll"]},newtd);
        newinput.addEventListener("click",function(){
            buildInfoPanelFormulas({"showAll":this.checked});
        },false);
        createElement("span",{"style":"margin-right:10px;"},newtd,getText("showAll"));
        newtd=createElement("td",{"align":"right"},newtr);
        newtd.addEventListener("click",function(filterType){
        return function(event){
            var thisFilter=event.target.getAttribute("filter");
            if(thisFilter){
                if(!event.ctrlKey){
                    filterType=thisFilter;
                }else if(filterType.search(thisFilter)!=-1){
                    filterType.replace(thisFilter,"")
                }else{
                    filterType+=thisFilter;
                }
                buildInfoPanelFormulas({"filterType":filterType});
            }
        }}(mode["filterType"]),false);
        newtd.addEventListener("mouseover",function(event){
            var mouseOverText=event.target.getAttribute("mouseOverText");
            if(mouseOverText){
                mouseOverText='<div>'+getText("click")+'&nbsp;/&nbsp;'+getText("clickCtrl")+'</div><div>'+mouseOverText+'</div>';
                toolTip.show(event,mouseOverText);
            }
        },false);       
        for(var v=0;v<=2;v++){
            createElement("div",{"class":"link category_r"+v+(mode["filterType"].search(v+",")!=-1?"_active":""),"filter":v+",","style":"display:inline-block;","mouseOverText":getText("category_r"+v)},newtd);
        }
    
        newdiv=createElement("div",{"style":"height:465px;width:100%;overflow:auto;"},container);
        newtable=createElement("table",{"style":"line-height:16px;width:100%","border":"1","cellspacing":0},newdiv);
        var thead=createElement("thead",{},newtable); // sortable table
        var newtbody=createElement("tbody",{},newtable);
    
        newtr=createElement("tr",{"class":"borderBottom2"},thead);
        createElement("th",{"sortdir":"Asc","class":"link"},newtr,getText("nr"));
        createElement("th",{"sortdir":"Asc","class":"link"},newtr,getText("lvl"));
        createElement("th",{"sortdir":"Asc","class":"link"},newtr,getText("title"));
        createElement("th",{"sortdir":"Asc","class":"link"},newtr,getText("ingredients"));
        createElement("th",{"sortdir":"Asc","class":"link"},newtr,getText("time"));
        createElement("th",{"sortdir":"Asc","class":"link"},newtr,getText("gain"));
        createElement("th",{"sortdir":"Asc","class":"link"},newtr,getText("price"));
        new SortableTable(newtr);
    
        for(var v in unsafeWindow.formulas[0]){
            if(!unsafeWindow.formulas[0].hasOwnProperty(v)){ continue; }
            if(mode["showAll"]||((USERLEVEL>=unsafeWindow.formulas[0][v][1])&&(unsafeWindow.formulas[0][v]["endremain"]>=0))){
                if(((mode["filterType"].search("0,")!=-1)&&(unsafeWindow.formulas[0][v][5][0]!=0))||((mode["filterType"].search("1,")!=-1)&&(unsafeWindow.formulas[0][v][5][1]!=0))||((mode["filterType"].search("2,")!=-1)&&(unsafeWindow.formulas[0][v][5][2]!=0))){
                    newtr=createElement("tr",{"class":"hoverBgCc9"},newtbody);
                    createElement("td",{"value":unsafeWindow.formulas[0][v][0],"style":(unsafeWindow.formulas[0][v]["endremain"]>=0?"":"background-color:red;")},newtr,unsafeWindow.formulas[0][v][0]);
                    createElement("td",{"value":unsafeWindow.formulas[0][v][1],"style":(USERLEVEL>=unsafeWindow.formulas[0][v][1]?"":"background-color:red;")},newtr,unsafeWindow.formulas[0][v][1]);
                    // Title
                    newtd1=createElement("td",{},newtr,unsafeWindow.formulas[0][v][2]);
                    // Ingredients
                    newtd=createElement("td",{},newtr);
                    var sum1=0;
                    var sumPts=0;
                    var preis=0;
                    for(var w=0;w<unsafeWindow.formulas[0][v][3].length;w++){
                        preis=!isNaN(NPC[0][unsafeWindow.formulas[0][v][3][w][0]])?Math.min(NPC[0][unsafeWindow.formulas[0][v][3][w][0]],gut[unsafeWindow.formulas[0][v][3][w][0]]):gut[unsafeWindow.formulas[0][v][3][w][0]];
                        sum1 += unsafeWindow.formulas[0][v][3][w][1]*preis;
                        newdiv=createElement("div",{"class":"link hoverBgLightblue","prod":unsafeWindow.formulas[0][v][3][w][0],"value":preis*unsafeWindow.formulas[0][v][3][w][1]},newtd);
                        newdiv.addEventListener("mouseover",function(event){showGoToMarketToolTip(event,this.getAttribute("prod"),null,'<tr><td>'+sign_sum+'</td><td style="text-align:right;">'+moneyFormatInt(parseInt(this.getAttribute("value"),10))+'</td></tr>');},false);
                        newdiv.addEventListener("click",function(){showMarket(this.getAttribute("prod"));},false);
                        produktPic(0,unsafeWindow.formulas[0][v][3][w][0],newdiv);
                        newdiv=createElement("span",{},newdiv,numberFormat(unsafeWindow.formulas[0][v][3][w][1]));
                    }
                    newtd.setAttribute("value",sum1);
                    createElement("div",{},newtd,"("+moneyFormatInt(sum1)+")");
                    var sum=-sum1;
                    // Time
                    createElement("td",{"value":unsafeWindow.formulas[0][v][4]},newtr,getTimeStr(unsafeWindow.formulas[0][v][4],1)+getText("shortHours"));
                    // Gain
                    newtd=createElement("td",{"style":"width:80px;"},newtr);
                    if(unsafeWindow.formulas[0][v][5][0]!=0){
                        // Products
                        preis=!isNaN(NPC[0][unsafeWindow.formulas[0][v][5][0][0]])?Math.min(NPC[0][unsafeWindow.formulas[0][v][5][0][0]],gut[unsafeWindow.formulas[0][v][5][0][0]]):gut[unsafeWindow.formulas[0][v][5][0][0]];
                        sum1=unsafeWindow.formulas[0][v][5][0][1]*preis;
                        sum += sum1;
                        newdiv=createElement("div",{"class":"link hoverBgLightblue","prod":unsafeWindow.formulas[0][v][5][0][0],"value":sum1},newtd);
                        newdiv.addEventListener("mouseover",function(event){showGoToMarketToolTip(event,this.getAttribute("prod"));},false);
                        newdiv.addEventListener("click",function(){showMarket(this.getAttribute("prod"));},false);
                        produktPic(0,unsafeWindow.formulas[0][v][5][0][0],newdiv);
                        createElement("span",{},newdiv,unsafeWindow.formulas[0][v][5][0][1]);
                        createElement("div",{},newtd,"("+moneyFormatInt(sum1)+")");
                    }else if(unsafeWindow.formulas[0][v][5][1]!=0){
                        // Crop amount boost
                        createElement("div",{},newtd,getTimeStr(unsafeWindow.formulas[0][v][5][1][2],1)+getText("shortHours"));
                        newdiv=createElement("div",{"class":"link hoverBgLightblue","prod":unsafeWindow.formulas[0][v][5][1][0],"style":"white-space:nowrap;"},newtd);
                        newdiv.addEventListener("mouseover",function(event){showGoToMarketToolTip(event,this.getAttribute("prod"));},false);
                        newdiv.addEventListener("click",function(){showMarket(this.getAttribute("prod"));},false);
                        produktPic(0,unsafeWindow.formulas[0][v][5][1][0],newdiv);
                        createElement("span",{},newdiv,"+"+unsafeWindow.formulas[0][v][5][1][1]+"val&nbsp;(+"+numberFormat(100*unsafeWindow.formulas[0][v][5][1][1]/(prodYield[0][unsafeWindow.formulas[0][v][5][1][0]]-1))+"%)");
                        preis=!isNaN(NPC[0][unsafeWindow.formulas[0][v][5][1][0]])?Math.min(NPC[0][unsafeWindow.formulas[0][v][5][1][0]],gut[unsafeWindow.formulas[0][v][5][1][0]]):gut[unsafeWindow.formulas[0][v][5][1][0]];
                        sum1=0;
                        for(var i=0;i<ALL_ZONES["farm"].length;i++){
                            if((zones.getBuilding(ALL_ZONES["farm"][i])==1)&&(!zones.getBlock(ALL_ZONES["farm"][i]))){
                                sum1 += preis*unsafeWindow.formulas[0][v][5][1][1]*Math.ceil(calcGrowTimes(60*prodGrowTime[0][unsafeWindow.formulas[0][v][5][1][0]],unsafeWindow.formulas[0][v][5][1][2],1-(zones.getBonus(ALL_ZONES["farm"][i])/100)))*BUILDING_SIZE["1"]/prodPlantSize[0][unsafeWindow.formulas[0][v][5][1][0]];
                            }
                        }
                        sum += sum1;
                        createElement("div",{},newtd,"("+moneyFormatInt(sum1)+")");
                        newtd.setAttribute("value",sum1);
                    }else if(unsafeWindow.formulas[0][v][5][2]!=0){
                        // Crop points boost
                        createElement("div",{},newtd,getTimeStr(unsafeWindow.formulas[0][v][5][2][2],1)+getText("shortHours"));
                        newdiv=createElement("div",{"class":"link hoverBgLightblue","prod":unsafeWindow.formulas[0][v][5][2][0],"style":"white-space:nowrap;"},newtd);
                        newdiv.addEventListener("mouseover",function(event){showGoToMarketToolTip(event,this.getAttribute("prod"));},false);
                        newdiv.addEventListener("click",function(){showMarket(this.getAttribute("prod"));},false);
                        produktPic(0,unsafeWindow.formulas[0][v][5][2][0],newdiv);
                        createElement("span",{},newdiv,"+");
                        pointsFormat(unsafeWindow.formulas[0][v][5][2][1],"span",newdiv);
                        createElement("span",{},newdiv,"&nbsp;(+"+numberFormat(100*unsafeWindow.formulas[0][v][5][2][1]/prodPoints[0][unsafeWindow.formulas[0][v][5][2][0]])+"%)");
                        sum1=0;
                        for(var i=0;i<ALL_ZONES["farm"].length;i++){
                            if((zones.getBuilding(ALL_ZONES["farm"][i])==1)&&(!zones.getBlock(ALL_ZONES["farm"][i]))){
                                sum1 += unsafeWindow.formulas[0][v][5][2][1]*Math.ceil(calcGrowTimes(60*prodGrowTime[0][unsafeWindow.formulas[0][v][5][2][0]],unsafeWindow.formulas[0][v][5][2][2],1-(zones.getBonus(ALL_ZONES["farm"][i])/100)))*BUILDING_SIZE["1"]/prodPlantSize[0][unsafeWindow.formulas[0][v][5][2][0]];
                            }
                        }
                        sumPts=sum1;
                        newdiv=createElement("div",{},newtd);
                        createElement("span",{},newdiv,"(");
                        pointsFormat(sum1,"span",newdiv);
                        createElement("span",{},newdiv,")");
                        newtd.setAttribute("value",0);
                    }
                    pointsFormat(unsafeWindow.formulas[0][v][8],"div",newtd);
                    sumPts += unsafeWindow.formulas[0][v][8];
                    // Price
                    newtd=createElement("td",{},newtr);
                    if(unsafeWindow.formulas[0][v][6]>0){
                        sum1=unsafeWindow.formulas[0][v][6];
                        sum -= sum1;
                        newspan=createElement("div",{},newtd,moneyFormatInt(sum1));
                        newtd.setAttribute("value",sum1);
                    }
                    if(unsafeWindow.formulas[0][v][7]>0){
                        sum1=unsafeWindow.formulas[0][v][7]*gut[0];
                        sum -= sum1;
                        newspan=createElement("div",{"class":"link hoverBgLightblue"},newtd,coinsFormat(unsafeWindow.formulas[0][v][7],createElement("div")).parentNode.innerHTML);
                        newspan.addEventListener("mouseover",function(event){showGoToMarketToolTip(event,"0");},false);
                        newspan.addEventListener("click",function(){showMarket("0");},false);
                        createElement("div",{"style":"clear:both;"},newtd,"("+moneyFormatInt(sum1)+")");
                        newtd.setAttribute("value",sum1);
                    }
                    //createElement("td",{},newtr,unsafeWindow.formulas[0][v][8]);
                    //createElement("td",{},newtr,unsafeWindow.formulas[0][v][9]);
                    // Title
                    createElement("div",{},newtd1,moneyFormatInt(sum));
                    newtd1.setAttribute("value",sum);
                    pointsFormat(sumPts,"div",newtd1);
                }
            }
        }
        container=null;
        newtable=null;thead=null;newtbody=null;newtr=null;newtd=null;newtd1=null;newdiv=null;newinput=null;
    }catch(err){GM_logError("buildInfoPanelFormulas\n"+err);}
}
unsafeWindow.buildInfoPanelMenu=function(mode){
    try{
        var container,newdiv,newdiv1;
        container=$("infoPanelInner");
        container.innerHTML="";
        newdiv=createElement("div",{"id":"infoPanelL","style":"position:absolute;left:0;width:105px;overflow:auto;height:515px;border-right:2px solid #685338;padding-right:5px;"},container);
        newdiv1=createElement("div",{"style":"padding-top:5px;border-bottom:1px solid #685338;font-weight:bold;float:left;width:100%;"},newdiv,getText("adviser"));
        newdiv1.addEventListener("mouseover",function(event){
            toolTip.show(event,getText("showChangelog")); 
        },false);
        newdiv1.classList.add("link");
        newdiv1.addEventListener("click",function(event){
            unsafeWindow.buildInfoPanel("changelog");
        },false);
        if(USERNAME){
            newdiv1=createElement("div",{"id":"infoPanelNaviOptions","class":"link naviItem","style":"margin-top:5px;width:95px;"},newdiv,getText("options"));
            newdiv1.addEventListener("click",function(event){ unsafeWindow.buildInfoPanelMenu("options"); },false);
        }else{
            createElement("div",{"id":"infoPanelNaviOptions","class":"naviItemInactive","style":"margin-top:5px;width:95px;"},newdiv,getText("options"));
        }
        newdiv1=createElement("div",{"id":"infoPanelNaviAccounts","class":"link naviItem","style":"margin-top:5px;width:95px;"},newdiv,getText("accounts"));
        newdiv1.addEventListener("click",function(event){ unsafeWindow.buildInfoPanelMenu("accounts"); },false);
        newdiv1=createElement("div",{"id":"infoPanelNaviHotkeys","class":"link naviItem","style":"margin-top:5px;width:95px;"},newdiv,getText("hotkeys"));
        newdiv1.addEventListener("click",function(event){ unsafeWindow.buildInfoPanelMenu("hotkeys"); },false);
        if(USERNAME){
            newdiv1=createElement("div",{"id":"infoPanelNaviCss","class":"link naviItem","style":"margin-top:5px;width:95px;"},newdiv,"CSS");
            newdiv1.addEventListener("click",function(event){ unsafeWindow.buildInfoPanelMenu("css"); },false);
            newdiv1=createElement("div",{"id":"infoPanelNaviImport","class":"link naviItem","style":"margin-top:5px;width:95px;"},newdiv,"Import/Export");
            newdiv1.addEventListener("click",function(event){ unsafeWindow.buildInfoPanelMenu("import"); },false);
        }else{
            createElement("div",{"id":"infoPanelNaviCss","class":"naviItemInactive","style":"margin-top:5px;width:95px;"},newdiv,"CSS");
            createElement("div",{"id":"infoPanelNaviImport","class":"naviItemInactive","style":"margin-top:5px;width:95px;"},newdiv,"Import/Export");
        }
        createElement("div",{"id":"infoPanelR","style":"position:absolute;left:115px;width:480px;overflow:auto;height:515px;"},container);
        // paypal
        newdiv=createElement("div",{"style":"position:absolute;left:0;bottom:0;"},container);
        newdiv1=createElement("form",{"id":"paypalForm","target":"_blank","action":"https://www.paypal.com/cgi-bin/webscr","method":"post"},newdiv);
        createElement("input",{"type":"hidden","name":"cmd","value":"_donations"},newdiv1);
        createElement("input",{"type":"hidden","name":"business","value":"jessicakanaan@web.de"},newdiv1);
        createElement("input",{"type":"hidden","name":"lc","value":((LANGUAGE=="de")?"DE":"US")},newdiv1);
        createElement("input",{"type":"hidden","name":"item_name","value":"MyFreeFarm Script"},newdiv1);
        createElement("input",{"type":"hidden","name":"no_note","value":"0"},newdiv1);
        createElement("input",{"type":"hidden","name":"currency_code","value":"EUR"},newdiv1);
        createElement("input",{"type":"hidden","name":"bn","value":"PP-DonationsBF:btn_donate_LG.gif:NonHostedGuest"},newdiv1);
        createElement("input",{"type":"image","style":"border:none;background:transparent;","src":"https://www.paypalobjects.com/"+((LANGUAGE=="de")?"de_DE/DE":"en_US")+"/i/btn/btn_donate_LG.gif","name":"submit","alt":"PayPal"},newdiv1);
        createElement("img",{"alt":"","border":"0","src":"https://www.paypalobjects.com/en_US/i/scr/pixel.gif","width":"1","height":"1"},newdiv1);
        // call automat
        if(unsafeWindow.buildInfoPanelAutomatMenu){ unsafeWindow.buildInfoPanelAutomatMenu(mode); }
        // switch call
        switch(mode){
        case "options": buildInfoPanelOptions(); break;
        case "accounts": buildInfoPanelAccounts(false); break;
        case "hotkeys": buildInfoPanelHotkeys(); break;
        case "css": buildInfoPanelCss(); break;
        case "import": buildInfoPanelImport(); break;
        }
        container=null;newdiv=null;newdiv1=null;
    }catch(err){GM_logError("buildInfoPanelMenu\n"+err);}
}
function buildInfoPanelOptions(){
    try{
        var container,newdiv,newtable,newtr,newtd,newtr,newtd1,newinput;
        newdiv=$("infoPanelNaviOptions");
        newdiv.classList.remove("naviItem");
        newdiv.classList.add("naviItemActive");
        container=$("infoPanelR");
        newtable=createElement("table",{"style":"width:100%;","border":"1","class":"hoverRowBgCc9"},container);
        newtr=createElement("tr",{},newtable);
        newtd=createElement("th",{"colspan":"3"},newtr,getText("farm"));
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"type":"checkbox","class":"link","checked":valAutoWater["farm"]},newtd);
        newinput.addEventListener("click",function(){
            valAutoWater["farm"]=this.checked;
            unsafeData.valAutoWater=valAutoWater;
            GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valAutoWater",implode(valAutoWater),9);
        },false);
        createElement("td",{},newtr,getText("settings_valAutoWater")[0]);
        createElement("td",{},newtr,getText("settings_valAutoWater")[1]);
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"type":"checkbox","class":"link","checked":valAutoCrop["farm"]},newtd);
        newinput.addEventListener("click",function(){
            valAutoCrop["farm"]=this.checked;
            unsafeData.valAutoCrop=valAutoCrop;
            GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valAutoCrop",implode(valAutoCrop),11);
        },false);
        createElement("td",{},newtr,getText("settings_valAutoCrop")[0]);
        createElement("td",{},newtr,getText("settings_valAutoCrop")[1]);
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"type":"checkbox","class":"link","checked":valAssumeWater["farm"]},newtd);
        newinput.addEventListener("click",function(){
            valAssumeWater["farm"]=this.checked;
            GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valAssumeWater",implode(valAssumeWater),10);
        },false);
        createElement("td",{},newtr,getText("settings_valAssumeWater")[0]);
        createElement("td",{},newtr,getText("settings_valAssumeWater")[1]);
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"type":"checkbox","class":"link","checked":valWaterNeeded["farm"]},newtd);
        newinput.addEventListener("click",function(){
            valWaterNeeded["farm"]=this.checked;
            GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valWaterNeeded",implode(valWaterNeeded),12);
        },false);
        createElement("td",{},newtr,getText("settings_valWaterNeeded")[0]);
        createElement("td",{},newtr,getText("settings_valWaterNeeded")[1]);
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"id":"inputvalErnteMsg","type":"checkbox","class":"link","checked":valErnteMsg},newtd);
        newinput.addEventListener("click",function(){
            valErnteMsg=this.checked;
            GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valErnteMsg", valErnteMsg,13);
        },false);
        createElement("td",{},newtr,getText("settings_valCropMsg")[0]);
        createElement("td",{},newtr,getText("settings_valCropMsg")[1]);
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"value":valLimitEmptyFields["1"],"class":"text","maxlength":"2","size":"2px","style":"background-color:transparent;text-align:center;"},newtd);
        newinput.addEventListener("focus",function(){this.style.backgroundColor="lightblue";},false);
        newinput.addEventListener("blur",function(){this.style.backgroundColor="transparent";},false);
        newinput.addEventListener("keyup",function(){
            var help=parseInt(this.value,10);
            if(isNaN(help)||(help<0)){
                this.value="";
            }else{
                this.value=help;
                valLimitEmptyFields["1"]=help;
                GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valLimitEmptyFields",implode(valLimitEmptyFields),14);
                for(var v=0;v<ALL_ZONES["farm"].length;v++){ 
                    if(zones.getBuilding(ALL_ZONES["farm"][v])==1){
                        zones.processProduction(ALL_ZONES["farm"][v]); 
                    }
                }
            }
        },false);
        createElement("td",{},newtr,getText("settings_valLimitEmptyFields")[0]);
        createElement("td",{},newtr,getText("settings_valLimitEmptyFields")[1]);
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"type":"checkbox","class":"link","checked":valGlobaltimeShowCroppedZone["farm"]},newtd);
        newinput.addEventListener("click",function(){
            valGlobaltimeShowCroppedZone["farm"]=this.checked;
            GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valGlobaltimeShowCroppedZone",implode(valGlobaltimeShowCroppedZone),16);
        },false);
        createElement("td",{},newtr,getText("settings_valGlobaltimeShowCroppedZone")[0]);
        createElement("td",{},newtr,getText("settings_valGlobaltimeShowCroppedZone")[1]);
        
        newtr=createElement("tr",{},newtable);
        createElement("td",{"align":"center"},newtr);
        createElement("td",{},newtr,getText("settings_valMoveAnimals")[0]);
        newtd=createElement("td",{},newtr,getText("settings_valMoveAnimals")[1]);
        for(var v=0;v<ANIMAL_MOVE.length;v++){ if(ANIMAL_MOVE[v]){
            newspan=createElement("span",{"style":"display:inline-block;margin-right:15px;"},newtd);
            produktPic(0,BUILDING2PRODUCT[v][0],newspan);
            newinput=createElement("input",{"id":"inputvalMoveAnimals"+v,"type":"checkbox","class":"link","checked":valMoveAnimals[v]},newspan);
            newinput.addEventListener("click",function(){
                valMoveAnimals[this.id.replace("inputvalMoveAnimals","")]=this.checked;
                GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valMoveAnimals", implode(valMoveAnimals),15);
            },false);
        }}
        
        // ***********************************************************************
        newtr=createElement("tr",{},newtable);
        newtd=createElement("th",{"colspan":"3"},newtr,getText("farmis"));
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newdiv=createElement("div",{"style":"white-space:nowrap;"},newtd);
        newinput=createElement("input",{"id":"inputvalFarmiLimits0","value":valFarmiLimits[0],"class":"text","maxlength":"3","size":"3px","style":"background-color:transparent;text-align:center;"},newdiv);
        newinput.addEventListener("focus",function(){this.style.backgroundColor="lightblue";},false);
        newinput.addEventListener("blur",function(){this.style.backgroundColor="transparent";},false);
        newinput.addEventListener("change",function(){
            var help=parseInt(this.value,10);
            if (isNaN(help)){
                this.value="";
            }else{
                help=Math.max(0,Math.min(999,Math.min(help,valFarmiLimits[1])));
                valFarmiLimits[0]=help;
                doFarmis();
                this.value=help;
                GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valFarmiLimits", implode(valFarmiLimits),19);
                unsafeData.valFarmiLimits=valFarmiLimits.clone();
            }
        },false);
        createElement("span",{},newdiv,"%");
        newdiv=createElement("div",{"style":"white-space:nowrap;"},newtd);
        newinput=createElement("input",{"id":"inputvalFarmiLimits1","value":valFarmiLimits[1],"class":"text","maxlength":"3","size":"3px","style":"background-color:transparent;text-align:center;"},newdiv);
        newinput.addEventListener("focus",function(){this.style.backgroundColor="lightblue";},false);
        newinput.addEventListener("blur",function(){this.style.backgroundColor="transparent";},false);
        newinput.addEventListener("change",function(){
            var help=parseInt(this.value,10);
            if (isNaN(help)){
                this.value="";
            }else{
                help=Math.max(0,Math.min(999,Math.max(help,valFarmiLimits[0])));
                valFarmiLimits[1]=help;
                doFarmis();
                this.value=help;
                GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valFarmiLimits", implode(valFarmiLimits),20);
                unsafeData.valFarmiLimits=valFarmiLimits.clone();
            }
        },false);
        createElement("span",{},newdiv,"%");
        createElement("td",{},newtr,getText("settings_valFarmiLimits")[0]);
        createElement("td",{},newtr,getText("settings_valFarmiLimits")[1]+" ("+getText("default")+":&nbsp;90,100)");
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"id":"inputvalFarmiMiniInfo","type":"checkbox","class":"link","checked":valFarmiMiniInfo},newtd);
        newinput.addEventListener("click",function(){
            valFarmiMiniInfo=this.checked;
            GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valFarmiMiniInfo", valFarmiMiniInfo,21);
            doFarmis();
        },false);
        createElement("td",{},newtr,getText("settings_valFarmiMiniInfo")[0]);
        createElement("td",{},newtr,getText("settings_valFarmiMiniInfo")[1]);
    
        // ***********************************************************************
        newtr=createElement("tr",{},newtable);
        newtd=createElement("th",{"colspan":"3"},newtr,getText("farmersmarket"));

        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"value":valLimitEmptyFields["fl1"],"class":"text","maxlength":"2","size":"2px","style":"background-color:transparent;text-align:center;"},newtd);
        newinput.addEventListener("focus",function(){this.style.backgroundColor="lightblue";},false);
        newinput.addEventListener("blur",function(){this.style.backgroundColor="transparent";},false);
        newinput.addEventListener("keyup",function(){
            var help=parseInt(this.value,10);
            if(isNaN(help)||(help<0)){
                this.value="";
            }else{
                this.value=help;
                valLimitEmptyFields["fl1"]=help;
                GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valLimitEmptyFields",implode(valLimitEmptyFields),14);
                zones.processProduction("farmersmarket-1"); 
            }
        },false);
        createElement("td",{},newtr,getText("settings_valLimitEmptyFields")[0]);
        createElement("td",{},newtr,getText("settings_valLimitEmptyFields")[1]);        
        
        newtd1=null;
        for(var j=0;j<ALL_ZONES["farmersmarket"].length;j++){
            zoneNrF=ALL_ZONES["farmersmarket"][j];
            if(zones.isProductional(zoneNrF)){
                newtr=createElement("tr",{},newtable);
                newtd=createElement("td",{"align":"center"},newtr);
                newinput=createElement("input",{"zoneNrF":zoneNrF,"type":"checkbox","class":"link","checked":zoneAddToGlobalTime[zoneNrF]},newtd);
                if(zones.getBlock(zoneNrF)){ newinput.disabled=true; }
                newinput.addEventListener("click",function(){
                    var zoneNrF=this.getAttribute("zoneNrF");
                    zoneAddToGlobalTime[zoneNrF]=this.checked;
                    unsafeData.zoneAddToGlobalTime=zoneAddToGlobalTime[zoneNrF];
                    GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valGlobalTimeAdd", implode(zoneAddToGlobalTime));
                    zones.processProduction(zoneNrF);
                },false);
                newtd=createElement("td",{},newtr);
                if(zones.getBlock(zoneNrF)){ newtd.style.opacity="0.6"; }
                createElement("span",{},newtd,zones.getBuildingName(zoneNrF));
                if(newtd1==null){
                    newtd1=createElement("td",{"rowspan":1},newtr,getText("settings_valzoneAddToGlobalTime")[1]);
                }else{
                    newtd1.rowSpan++;
                }
            }
        }
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"type":"checkbox","class":"link","checked":valGlobaltimeShowCroppedZone["farmersmarket"]},newtd);
        newinput.addEventListener("click",function(){
            valGlobaltimeShowCroppedZone["farmersmarket"]=this.checked;
            GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valGlobaltimeShowCroppedZone",implode(valGlobaltimeShowCroppedZone),16);
        },false);
        createElement("td",{},newtr,getText("settings_valGlobaltimeShowCroppedZone")[0]);
        createElement("td",{},newtr,getText("settings_valGlobaltimeShowCroppedZone")[1]);
        
        // ***********************************************************************
        newtr=createElement("tr",{},newtable);
        newtd=createElement("th",{"colspan":"3"},newtr,getText("windmill"));

        newtd1=null;
        for(var j=0;j<ALL_ZONES["city"].length;j++){
            zoneNrF=ALL_ZONES["city"][j];
            if(zones.isProductional(zoneNrF)){
                newtr=createElement("tr",{},newtable);
                newtd=createElement("td",{"align":"center"},newtr);
                newinput=createElement("input",{"zoneNrF":zoneNrF,"type":"checkbox","class":"link","checked":zoneAddToGlobalTime[zoneNrF]},newtd);
                if(zones.getBlock(zoneNrF)){ newinput.disabled=true; }
                newinput.addEventListener("click",function(){
                    var zoneNrF=this.getAttribute("zoneNrF");
                    zoneAddToGlobalTime[zoneNrF]=this.checked;
                    unsafeData.zoneAddToGlobalTime=zoneAddToGlobalTime[zoneNrF];
                    GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valGlobalTimeAdd", implode(zoneAddToGlobalTime));
                    zones.processProduction(zoneNrF);
                },false);
                newtd=createElement("td",{},newtr);
                if(zones.getBlock(zoneNrF)){ newtd.style.opacity="0.6"; }
                createElement("span",{},newtd,zones.getBuildingName(zoneNrF));
                if(newtd1==null){
                    newtd1=createElement("td",{"rowspan":1},newtr,getText("settings_valzoneAddToGlobalTime")[1]);
                }else{
                    newtd1.rowSpan++;
                }
            }
        }

        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"type":"checkbox","class":"link","checked":valGlobaltimeShowCroppedZone["windmill"]},newtd);
        newinput.addEventListener("click",function(){
            valGlobaltimeShowCroppedZone["windmill"]=this.checked;
            GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valGlobaltimeShowCroppedZone",implode(valGlobaltimeShowCroppedZone),16);
        },false);
        createElement("td",{},newtr,getText("settings_valGlobaltimeShowCroppedZone")[0]);
        createElement("td",{},newtr,getText("settings_valGlobaltimeShowCroppedZone")[1]);
        
        // ***********************************************************************
        newtr=createElement("tr",{},newtable);
        newtd=createElement("th",{"colspan":"3"},newtr,getText("forestry"));
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        var newinput=createElement("input",{"id":"inputvalGiess","type":"checkbox","class":"link","checked":valAutoWater["forestry"]},newtd);
        newinput.addEventListener("click",function(){
            valAutoWater["forestry"]=this.checked;
            unsafeData.valAutoWater=valAutoWater;
            GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valAutoWater",implode(valAutoWater),9);
        },false);
        createElement("td",{},newtr,getText("settings_valAutoWater")[0]);
        createElement("td",{},newtr,getText("settings_valAutoWater")[1]);
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"type":"checkbox","class":"link","checked":valAutoCrop["forestry"]},newtd);
        newinput.addEventListener("click",function(){
            valAutoCrop["forestry"]=this.checked;
            unsafeData.valAutoCrop=valAutoCrop;
            GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valAutoCrop",implode(valAutoCrop),11);
        },false);
        createElement("td",{},newtr,getText("settings_valAutoCrop")[0]);
        createElement("td",{},newtr,getText("settings_valAutoCrop")[1]);
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"type":"checkbox","class":"link","checked":valAssumeWater["forestry"]},newtd);
        newinput.addEventListener("click",function(){
            valAssumeWater["forestry"]=this.checked;
            GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valAssumeWater",implode(valAssumeWater),10);
        },false);
        createElement("td",{},newtr,getText("settings_valAssumeWater")[0]);
        createElement("td",{},newtr,getText("settings_valAssumeWater")[1]);
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"type":"checkbox","class":"link","checked":valWaterNeeded["forestry"]},newtd);
        newinput.addEventListener("click",function(){
            valWaterNeeded["forestry"]=this.checked;
            GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valWaterNeeded",implode(valWaterNeeded),12);
        },false);
        createElement("td",{},newtr,getText("settings_valWaterNeeded")[0]);
        createElement("td",{},newtr,getText("settings_valWaterNeeded")[1]);
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"value":valLimitEmptyFields["forest"],"class":"text","maxlength":"2","size":"2px","style":"background-color:transparent;text-align:center;"},newtd);
        newinput.addEventListener("focus",function(){this.style.backgroundColor="lightblue";},false);
        newinput.addEventListener("blur",function(){this.style.backgroundColor="transparent";},false);
        newinput.addEventListener("keyup",function(){
            var help=parseInt(this.value,10);
            if(isNaN(help)||(help<0)){
                this.value="";
            }else{
                this.value=help;
                valLimitEmptyFields["forest"]=help;
                GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valLimitEmptyFields",implode(valLimitEmptyFields));
                zones.processProduction("forest");
            }
        },false);
        createElement("td",{},newtr,getText("settings_valLimitEmptyFields_forest")[0]);
        createElement("td",{},newtr,getText("settings_valLimitEmptyFields_forest")[1]);
        
        newtd1=null;
        for(var j=0;j<ALL_ZONES["forestry"].length;j++){
            zoneNrF=ALL_ZONES["forestry"][j];
            if(zones.isProductional(zoneNrF)){
                newtr=createElement("tr",{},newtable);
                newtd=createElement("td",{"align":"center"},newtr);
                newinput=createElement("input",{"zoneNrF":zoneNrF,"type":"checkbox","class":"link","checked":zoneAddToGlobalTime[zoneNrF]},newtd);
                if(zones.getBlock(zoneNrF)){ newinput.disabled=true; }
                newinput.addEventListener("click",function(){
                    var zoneNrF=this.getAttribute("zoneNrF");
                    zoneAddToGlobalTime[zoneNrF]=this.checked;
                    unsafeData.zoneAddToGlobalTime=zoneAddToGlobalTime[zoneNrF];
                    GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valGlobalTimeAdd", implode(zoneAddToGlobalTime));
                    zones.processProduction(zoneNrF);
                },false);
                newtd=createElement("td",{},newtr);
                if(zones.getBlock(zoneNrF)){ newtd.style.opacity="0.6"; }
                createElement("span",{},newtd,zones.getBuildingName(zoneNrF));
                if(newtd1==null){
                    newtd1=createElement("td",{"rowspan":1},newtr,getText("settings_valzoneAddToGlobalTime")[1]);
                }else{
                    newtd1.rowSpan++;
                }
            }
        }
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"type":"checkbox","class":"link","checked":valGlobaltimeShowCroppedZone["forestry"]},newtd);
        newinput.addEventListener("click",function(){
            valGlobaltimeShowCroppedZone["forestry"]=this.checked;
            GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valGlobaltimeShowCroppedZone",implode(valGlobaltimeShowCroppedZone),16);
        },false);
        createElement("td",{},newtr,getText("settings_valGlobaltimeShowCroppedZone")[0]);
        createElement("td",{},newtr,getText("settings_valGlobaltimeShowCroppedZone")[1]);
        
        // **********************************************************************
        newtr=createElement("tr",{},newtable);
        newtd=createElement("th",{"colspan":"3"},newtr,unsafeWindow.foodworld_title);
        
        newtd1=null;
        for(var j=0;j<ALL_ZONES["foodworld"].length;j++){
            zoneNrF=ALL_ZONES["foodworld"][j];
            if(zones.isProductional(zoneNrF)){
                newtr=createElement("tr",{},newtable);
                newtd=createElement("td",{"align":"center"},newtr);
                newinput=createElement("input",{"zoneNrF":zoneNrF,"type":"checkbox","class":"link","checked":zoneAddToGlobalTime[zoneNrF]},newtd);
                if(zones.getBlock(zoneNrF)){ newinput.disabled=true; }
                newinput.addEventListener("click",function(){
                    var zoneNrF=this.getAttribute("zoneNrF");
                    zoneAddToGlobalTime[zoneNrF]=this.checked;
                    unsafeData.zoneAddToGlobalTime=zoneAddToGlobalTime[zoneNrF];
                    GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valGlobalTimeAdd", implode(zoneAddToGlobalTime));
                    zones.processProduction(zoneNrF);
                },false);
                newtd=createElement("td",{},newtr);
                if(zones.getBlock(zoneNrF)){ newtd.style.opacity="0.6"; }
                createElement("span",{},newtd,zones.getBuildingName(zoneNrF));
                if(newtd1==null){
                    newtd1=createElement("td",{"rowspan":1},newtr,getText("settings_valzoneAddToGlobalTime")[1]);
                }else{
                    newtd1.rowSpan++;
                }
            }
        }
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"type":"checkbox","class":"link","checked":valGlobaltimeShowCroppedZone["foodworld"]},newtd);
        newinput.addEventListener("click",function(){
            valGlobaltimeShowCroppedZone["foodworld"]=this.checked;
            GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valGlobaltimeShowCroppedZone",implode(valGlobaltimeShowCroppedZone),16);
        },false);
        createElement("td",{},newtr,getText("settings_valGlobaltimeShowCroppedZone")[0]);
        createElement("td",{},newtr,getText("settings_valGlobaltimeShowCroppedZone")[1]);
        
        // **********************************************************************
        newtr=createElement("tr",{},newtable);
        newtd=createElement("th",{"colspan":"3"},newtr,getText("minRackamount"));
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"id":"inputvalMinRackMan","type":"checkbox","class":"link","checked":valMinRackMan},newtd);
        newinput.addEventListener("click",function(){
            valMinRackMan=this.checked;
            GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valMinRackMan",valMinRackMan,22);
            var cand=$("infoPanelR").getElementsByClassName("minRackConfig");
            if(valMinRackMan){
                for(var v=0;v<cand.length;v++){
                    cand[v].disabled=true;
                    cand[v].parentNode.parentNode.style.opacity=0.6;
                }
            }else{
                for(var v=0;v<cand.length;v++){
                    cand[v].disabled=false;
                    cand[v].parentNode.parentNode.style.opacity=1;
                }
                calcProdMinRackInit();
            }
            cand=null;
        },false);
        createElement("td",{},newtr,getText("settings_valMinRackMan")[0]);
        newtd=createElement("td",{"class":"link"},newtr,getText("settings_valMinRackMan")[1]);
        newtd.addEventListener("click",function(){
            unsafeWindow.buildInfoPanel("stock",{"page":2});
        },false);
        
        newTd1=null;
        for(var v in valMinRack){
            if(!valMinRack.hasOwnProperty(v)){ continue; }
            newtr=createElement("tr",{},newtable);
            newtd=createElement("td",{"align":"center"},newtr);
            newinput=createElement("input",{"id":"inputvalMinRack_"+v,"class":"text minRackConfig","value":valMinRack[v],"maxlength":"4","size":"5px","style":"background-color:transparent;text-align:center;"},newtd);
            if(valMinRackMan){
                newinput.disabled=true;
                newtr.style.opacity=0.6;
            }
            newinput.addEventListener("focus",function(){this.style.backgroundColor="lightblue";},false);
            newinput.addEventListener("blur",function(){this.style.backgroundColor="transparent";},false);
            newinput.addEventListener("keyup",function(){
                var help=parseInt(this.value,10);
                if (isNaN(help)){
                    this.value="";
                }else{
                    this.value=help;
                    valMinRack[this.id.replace("inputvalMinRack_","")]=help;
                    GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valMinRack",implode(valMinRack,"valMinRack"));
                    calcProdMinRackInit();
                }
            },false);
            createElement("td",{},newtr,getText("category_"+v));
            if(newTd1==null){
                newTd1=createElement("td",{},newtr,getText("settings_valMinRack")[1]);
            } else {
                newTd1.rowSpan++;
            }
        }
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"class":"text minRackConfig","type":"checkbox","checked":valMinRackPlantsize},newtd);
        if(valMinRackMan){
            newinput.disabled=true;
            newtr.style.opacity=0.6;
        }
        newinput.addEventListener("click",function(){
            GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valMinRackPlantsize",this.checked,24);
            calcProdMinRackInit();
        },false);
        createElement("td",{},newtr,getText("settings_valMinRackPlantsize")[0]);
        createElement("td",{},newtr,getText("settings_valMinRackPlantsize")[1]);
        
        // newtr=createElement("tr",{},newtable);
        // newtd=createElement("th",{"colspan":"3"},newtr,getText("minRackamount"));
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"id":"inputvalMinRackGrowing","type":"checkbox","class":"link","checked":valMinRackGrowing},newtd);
        newinput.addEventListener("click",function(){
            valMinRackGrowing=this.checked;
            GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valMinRackGrowing",valMinRackGrowing,26);
            calcProdMinRack();
        },false);
        createElement("td",{},newtr,getText("settings_valMinRackGrowing")[0]);
        createElement("td",{},newtr,getText("settings_valMinRackGrowing")[1]);
        
        newTd1=null;
        for(var typ in questData){
            if(!questData.hasOwnProperty(typ)){ continue; }
            for(var camp in questData[typ]){
                if(!questData[typ].hasOwnProperty(camp)){ continue; }
                newtr=createElement("tr",{},newtable);
                newtd=createElement("td",{"align":"center"},newtr);
                var newsel = createElement("select",{"id":"selectQuestCalcTo_"+typ+"_"+camp,"style":"width:auto;height:18px;margin-left:5px;"},newtd);
                createElement("option",{"value":-1},newsel,getText("hide"));
                createElement("option",{"value":0},newsel,"--");
                for(var i=questData[typ][camp]["nr"];i<QUESTS[typ][camp].length;i++){
                    createElement("option",{"value":i},newsel,i);
                }
                newsel.addEventListener("change",function(){
                    if(isNaN(this.value)){return false;}
                    var help=this.id.split("_");
                    setCalcToQuest(help[1],help[2],this.value);
                },false);
                newsel.value = questData[typ][camp]["calcTo"];
                newtd=createElement("td",{},newtr,getText(typ=="main"?"farm":typ)+" "+camp);
                if(newTd1==null){
                    newTd1=createElement("td",{},newtr,getText("settings_valMinRackQuest")[1]);
                } else {
                    newTd1.rowSpan++;
                }
            }
        }
        newsel=null;i=null;
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"id":"inputvalMinRackRecursive","type":"checkbox","class":"link","checked":valMinRackRecursive},newtd);
        newinput.addEventListener("click",function(){
            valMinRackRecursive=this.checked;
            GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valMinRackRecursive",valMinRackRecursive,29);
            calcProdMinRack();
        },false);
        createElement("td",{},newtr,getText("settings_valMinRackRecursive")[0]);
        createElement("td",{},newtr,getText("settings_valMinRackRecursive")[1]);
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"id":"inputvalMinRackFarmis","type":"checkbox","class":"link","checked":valMinRackFarmis},newtd);
        newinput.addEventListener("click",function(){
            valMinRackFarmis=this.checked;
            GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valMinRackFarmis",valMinRackFarmis,30);
            calcProdMinRack();
        },false);
        createElement("td",{},newtr,getText("settings_valMinRackFarmis")[0]);
        createElement("td",{},newtr,getText("settings_valMinRackFarmis")[1]);
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"id":"inputvalMinRackForestryFarmis","type":"checkbox","class":"link","checked":valMinRackForestryFarmis},newtd);
        newinput.addEventListener("click",function(){
            valMinRackForestryFarmis=this.checked;
            GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valMinRackForestryFarmis",valMinRackForestryFarmis,31);
            calcProdMinRack();
        },false);
        createElement("td",{},newtr,getText("settings_valMinRackForestryFarmis")[0]);
        createElement("td",{},newtr,getText("settings_valMinRackForestryFarmis")[1]);
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"id":"inputvalProtectMinRack","type":"checkbox","class":"link","checked":GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valProtectMinRack",false)},newtd);
        newinput.addEventListener("click",function(){
            GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valProtectMinRack",this.checked,32);
        },false);
        createElement("td",{},newtr,getText("settings_protectMinRack")[0]);
        createElement("td",{},newtr,getText("settings_protectMinRack")[1]);
        
        // *******************************************************************
        newtr=createElement("tr",{},newtable);
        newtd=createElement("th",{"colspan":"3"},newtr,getText("market"));
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"id":"inputvalKauflimit00","value":valKauflimit[0][0],"class":"text","maxlength":"3","size":"2px","style":"background-color:transparent;text-align:center;"},newtd);
        newinput.addEventListener("focus",function(){this.style.backgroundColor="lightblue";},false);
        newinput.addEventListener("blur",function(){this.style.backgroundColor="transparent";},false);
        newinput.addEventListener("keyup",function(){
            var help=parseInt(this.value,10);
            if (isNaN(help)){
                this.value="";
            }else{
                valKauflimit[0][0]=help;
                this.value=valKauflimit[0][0];
                GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valKauflimit",implode(valKauflimit),33);
            }
        },false);
        createElement("span",{},newtd,"%");
        createElement("td",{},newtr,getText("settings_valBuyingLimitDown")[0]);
        newtd=createElement("td",{},newtr,getText("settings_valBuyingLimitDown")[1]);
        newinput=createElement("input",{"id":"inputvalKauflimit01","value":valKauflimit[0][1],"class":"text","maxlength":"6","size":"10px","style":"background-color:#"+valKauflimit[0][1]+";color:#F0FFEF;"},newtd);
        newinput.addEventListener("keyup",function(){
            this.value=this.value.replace(/[^0-9a-f]/ig,"");
            this.style.backgroundColor="#"+this.value;
        },false);
        newinput.addEventListener("change",function(){
            var color=this.value;
            if(!color.match(/^([0-9a-f]{3}){1,2}$/i)){
                color="990000";
                this.value=color;
            }
            this.style.backgroundColor="#"+this.value;
            valKauflimit[0][1]=this.value;
            GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valKauflimit",implode(valKauflimit),34);
        },false);
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"id":"inputvalKauflimit1","value":valKauflimit[1],"class":"text","maxlength":"3","size":"2px","style":"background-color:transparent;text-align:center;"},newtd);
        newinput.addEventListener("focus",function(){this.style.backgroundColor="lightblue";},false);
        newinput.addEventListener("blur",function(){this.style.backgroundColor="transparent";},false);
        newinput.addEventListener("keyup",function(){
            var help=parseInt(this.value,10);
            if (isNaN(help)){
                this.value="";
            }else{
                if(help<0){ help*=-1; }
                valKauflimit[1]=help;
                this.value=valKauflimit[1];
                GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valKauflimit",implode(valKauflimit),35);
            }
        },false);
        createElement("span",{},newtd,"%");
        createElement("td",{},newtr,getText("settings_valBuyingLimit")[0]);
        createElement("td",{},newtr,getText("settings_valBuyingLimit")[1]);
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"id":"inputvalKauflimitNPC","type":"checkbox","class":"link","checked":GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valKauflimitNPC",true)},newtd);
        newinput.addEventListener("click",function(){
            GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valKauflimitNPC",this.checked,36);
        },false);
        createElement("td",{},newtr,getText("settings_valBuyingLimitNPC")[0]);
        createElement("td",{},newtr,getText("settings_valBuyingLimitNPC")[1]);
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newdiv=createElement("div",{},newtd);
        newinput=createElement("input",{"id":"inputvalVerkaufLimitDown","value":GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valVerkaufLimitDown",95),"class":"text","maxlength":"3","size":"2px","style":"background-color:transparent;text-align:center;"},newdiv);
        newinput.addEventListener("focus",function(){this.style.backgroundColor="lightblue";},false);
        newinput.addEventListener("blur",function(){this.style.backgroundColor="transparent";},false);
        newinput.addEventListener("change",function(){
            var valVerkaufLimitDown=parseInt(this.value,10);
            var valVerkaufLimitUp=parseInt($("inputvalVerkaufLimitUp").value,10);
            valVerkaufLimitDown=Math.min(valVerkaufLimitDown,valVerkaufLimitUp);
            if (isNaN(valVerkaufLimitDown)){
                this.value="";
            }else{
                this.value=valVerkaufLimitDown;
                GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valVerkaufLimitDown", valVerkaufLimitDown,37);
            }
        },false);
        createElement("span",{},newdiv,"%");
        newdiv=createElement("div",{},newtd);
        newinput=createElement("input",{"id":"inputvalVerkaufLimitUp","value":GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valVerkaufLimitUp",130),"class":"text","maxlength":"3","size":"2px","style":"background-color:transparent;text-align:center;"},newdiv);
        newinput.addEventListener("focus",function(){this.style.backgroundColor="lightblue";},false);
        newinput.addEventListener("blur",function(){this.style.backgroundColor="transparent";},false);
        newinput.addEventListener("change",function(){
            var valVerkaufLimitDown=parseInt($("inputvalVerkaufLimitDown").value,10);
            var valVerkaufLimitUp=parseInt(this.value,10);
            valVerkaufLimitUp=Math.max(valVerkaufLimitDown,valVerkaufLimitUp);
            if (isNaN(valVerkaufLimitUp)){
                this.value="";
            }else{
                this.value=valVerkaufLimitUp;
                GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valVerkaufLimitUp", valVerkaufLimitUp,38);
            }
        },false);
        createElement("span",{},newdiv,"%");
        createElement("td",{},newtr,getText("settings_valSellingLimit")[0]);
        createElement("td",{},newtr,getText("settings_valSellingLimit")[1]);
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"id":"inputvalJoinPreise","type":"checkbox","class":"link","checked":GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valJoinPreise",false)},newtd);
        newinput.addEventListener("click",function(){ GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valJoinPreise", this.checked,39); },false);
        createElement("td",{},newtr,getText("settings_valJoinPrices")[0]);
        createElement("td",{},newtr,getText("settings_valJoinPrices")[1]);
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"id":"inputvalQuicklinks","type":"checkbox","class":"link","checked":GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valQuicklinks",true)},newtd);
        newinput.addEventListener("click",function(){GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valQuicklinks", this.checked,40);},false);
        createElement("td",{},newtr,getText("settings_valQuicklinks")[0]);
        createElement("td",{},newtr,getText("settings_valQuicklinks")[1]);
        
        function drawDivHighlightUser(name,color,parent){
            newdiv=createElement("div",{},parent);
            newinput=createElement("input",{"value":name,"class":"text","maxlength":"20","size":"25px","style":"background-color:transparent;"},newdiv);
            newinput.addEventListener("focus",function(){this.style.backgroundColor="lightblue";},false);
            newinput.addEventListener("blur",function(){this.style.backgroundColor="transparent";},false);
            newinput=createElement("input",{"value":color,"class":"text","maxlength":"6","size":"10px","style":"background-color:#"+color+";color:#F0FFEF;"},newdiv);
            newinput.addEventListener("keyup",function(){
                this.value=this.value.replace(/[^0-9a-f]/ig,"");
                this.style.backgroundColor="#"+this.value;
            },false);
            newdiv.addEventListener("change",function(){
                var tableCell=this.parentNode;
                var candinput=tableCell.getElementsByTagName("input");
                var highlightUser=new Object();
                for(var v=0;v<candinput.length;v+=2){
                    var name=candinput[v].value;
                    if(highlightUser[name]){
                        // remove duplicate
                        removeElement(candinput[v].parentNode);
                        v-=2;
                    }else{
                        var color=candinput[v+1].value;
                        if(!color.match(/^([0-9a-f]{3}){1,2}$/i)){
                            color="20b2aa";
                            candinput[v+1].value=color;
                            candinput[v+1].style.backgroundColor="#"+color;
                        }
                        highlightUser[name]=color;
                    }
                }
                if(highlightUser[""]==undefined){
                    drawDivHighlightUser("","20b2aa",tableCell);
                }else{
                    delete highlightUser[""];
                }
                GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_highlight",implode(highlightUser),41);
                candinput=null;tableCell=null;
            },false);
        }
        var highlightUser=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_highlight","{}"),"buildInfoPanel/options/highlightUser",{});
        highlightUser[""]="20b2aa";
        newtr=createElement("tr",{},newtable);
        createElement("td",{"align":"center"},newtr);
        createElement("td",{},newtr,getText("highlightUser"));
        newtd=createElement("td",{},newtr);
        for(var name in highlightUser){
            if(!highlightUser.hasOwnProperty(name)){ continue; }
            drawDivHighlightUser(name,highlightUser[name],newtd);
        }
        
        newtr=createElement("tr",{},newtable);
        createElement("td",{"align":"center"},newtr);
        createElement("td",{},newtr,getText("highlightProducts"));
        newtd=createElement("td",{},newtr);
        newdiv=createElement("div",{},newtd);
        newinput=createElement("input",{"type":"checkbox","class":"link","checked":highlightProducts[0]},newdiv);
        newinput.addEventListener("click",function(){
            highlightProducts[0]=this.checked;
            $("highlightProducts0").disabled=highlightProducts[0];
            $("highlightProducts1").disabled=highlightProducts[0];
            if(highlightProducts[0]){
                // todo calc highlightProducts[1]
                $("highlightProducts0").value=-1;
                $("highlightProducts1").value=-1;
            } else {
                var i=0;
                for(var prod in highlightProducts[1]){
                    if(!highlightProducts[1].hasOwnProperty(prod)){ continue; }
                    if(i>1){continue;}
                    $("highlightProducts"+i).value=prod;
                    i++;
                }
            }
            GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_highlightProducts",implode(highlightProducts),42);
        },false);
        createElement("span",{},newdiv,getText("useQuestProducts"));
        for(var i=0;i<2;i++){
            newinput=createElement("select",{"id":"highlightProducts"+i,"class":"link2"},newtd);
            createElement("option",{"value":"-1"},newinput,"--");
            for(var v=0;v<prodNameSort[0].length;v++){
                if((!prodBlock[0][prodNameSort[0][v]].match(/t/))&&(!prodBlock[0][prodNameSort[0][v]].match(/l/))){
                    createElement("option",{"value":prodNameSort[0][v]},newinput,prodName[0][prodNameSort[0][v]]);
                }
            }
            if(highlightProducts[0]){
                newinput.disabled=true; 
                newinput.value=-1;
            }
            newinput.addEventListener("change",function(){
                highlightProducts[1]={};
                highlightProducts[1][$("highlightProducts0").value]=true;
                highlightProducts[1][$("highlightProducts1").value]=true;
                GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_highlightProducts",implode(highlightProducts),43);
            },false);
        }
        if(!highlightProducts[0]){
            var i=0;
            for(var prod in highlightProducts[1]){
                if(!highlightProducts[1].hasOwnProperty(prod)){ continue; }
                if(i>1){continue;}
                $("highlightProducts"+i).value=prod;
                i++;
            }
        }
            
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"id":"inputvalNimmBeob","type":"checkbox","class":"link","checked":GM_getValue(COUNTRY+"_"+SERVER+"_valNimmBeob",false)},newtd);
        newinput.addEventListener("click",function(){ GM_setValue2(COUNTRY+"_"+SERVER+"_valNimmBeob",this.checked,44); },false);
        createElement("td",{},newtr,getText("settings_valUseObservedPrices")[0]);
        createElement("td",{},newtr,getText("settings_valUseObservedPrices")[1]);
        
        // ********************************************************************
        newtr=createElement("tr",{},newtable);
        newtd=createElement("th",{"colspan":"3"},newtr,getText("messages"));
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"id":"inputvalNachr","value":GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valPrivNachr",100),"class":"text","maxlength":"5","size":"5px","style":"background-color:transparent;text-align:center;"},newtd);
        newinput.addEventListener("focus",function(){this.style.backgroundColor="lightblue";},false);
        newinput.addEventListener("blur",function(){this.style.backgroundColor="transparent";},false);
        newinput.addEventListener("keyup",function(){
            var valPrivNachr=parseInt(this.value,10);
            if (isNaN(valPrivNachr)){
                this.value="";
            }else{
                this.value=valPrivNachr;
                GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valPrivNachr", valPrivNachr,45);
            }
        },false);
        createElement("td",{},newtr,getText("settings_valPrivateMessages")[0]);
        createElement("td",{},newtr,getText("settings_valPrivateMessages")[1]);
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"id":"inputvalNachr","value":GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valNachr",100),"class":"text","maxlength":"5","size":"5px","style":"background-color:transparent;text-align:center;"},newtd);
        newinput.addEventListener("focus",function(){this.style.backgroundColor="lightblue";},false);
        newinput.addEventListener("blur",function(){this.style.backgroundColor="transparent";},false);
        newinput.addEventListener("keyup",function(){
            var valNachr=parseInt(this.value,10);
            if (isNaN(valNachr)){
                this.value="";
            }else{
                this.value=valNachr;
                GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valNachr", valNachr,46);
            }
        },false);
        createElement("td",{},newtr,getText("settings_valMarketMessages")[0]);
        createElement("td",{},newtr,getText("settings_valMarketMessages")[1]);
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"id":"inputvalMessageRe","type":"checkbox","checked":GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valMessageRe",true),"class":"link"},newtd);
        newinput.addEventListener("click",function(){ GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valMessageRe", this.checked,47); },false);
        createElement("td",{},newtr,getText("settings_valMessageRe")[0]);
        createElement("td",{},newtr,getText("settings_valMessageRe")[1]);
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"id":"inputvalContractLogAmount","value":GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valContractLogAmount",200),"class":"text","maxlength":"5","size":"5px","style":"background-color:transparent;text-align:center;"},newtd);
        newinput.addEventListener("focus",function(){this.style.backgroundColor="lightblue";},false);
        newinput.addEventListener("blur",function(){this.style.backgroundColor="transparent";},false);
        newinput.addEventListener("keyup",function(){
            var valContractLogAmount=parseInt(this.value,10);
            if (isNaN(valContractLogAmount)){
                this.value="";
            }else{
                this.value=valContractLogAmount;
                GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valContractLogAmount", valContractLogAmount,17);
            }
        },false);
        createElement("td",{},newtr,getText("settings_valContractLogAmount")[0]);
        createElement("td",{},newtr,getText("settings_valContractLogAmount")[1]);
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"type":"checkbox","checked":valMessagesSystemMarkRead,"class":"link"},newtd);
        newinput.addEventListener("click",function(){ GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valMessagesSystemMarkRead", this.checked,47); },false);
        createElement("td",{},newtr,getText("settings_valMessagesSystemMarkRead")[0]);
        createElement("td",{},newtr,getText("settings_valMessagesSystemMarkRead")[1]);
            
        // *********************************************************************
        newtr=createElement("tr",{},newtable);
        newtd=createElement("th",{"colspan":"3"},newtr,getText("general"));
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"id":"inputvalAutoLogin","type":"checkbox","class":"link","checked":GM_getValue("valAutoLogin",false)},newtd);
        newinput.addEventListener("click",function(){GM_setValue2("valAutoLogin", this.checked,48);},false);
        createElement("td",{},newtr,getText("settings_valAutoLogin")[0]);
        createElement("td",{},newtr,getText("settings_valAutoLogin")[1]);
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"id":"inputvalUpdate","type":"checkbox","class":"link","checked":GM_getValue("valUpdate",true)},newtd);
        newinput.addEventListener("click",function(){GM_setValue2("valUpdate", this.checked,49);},false);
        createElement("td",{},newtr,getText("settings_valUpdate")[0]);
        createElement("td",{},newtr,getText("settings_valUpdate")[1]);
        
        if (STAT_SERVER[COUNTRY]){
            newtr=createElement("tr",{},newtable);
            newtd=createElement("td",{"align":"center"},newtr);
            newinput=createElement("input",{"id":"inputvalStatistik","type":"checkbox","class":"link","checked":valStatistik},newtd);
            newinput.addEventListener("click",function(){
                valStatistik=this.checked;
                GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valStatistik", valStatistik,50);
            },false);
            createElement("td",{},newtr,getText("settings_valSendStatistics")[0]);
            createElement("td",{},newtr,getText("settings_valSendStatistics")[1]);
        }
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{},newtr);
        createElement("td",{},newtr,getText("settings_valServerTimeOffset")[0]);
        newtd=createElement("td",{},newtr);
        newinput=createElement("button",{"type":"button","class":"link2"},newtd,"-");
        newinput.addEventListener("click",function(){
            valServerTimeOffset=Math.max(-86400,valServerTimeOffset-3600);
            GM_setValue(COUNTRY+"_valServerTimeOffset",valServerTimeOffset);
            nowServerOff=unsafeWindow.Zeit.Server+valServerTimeOffset;
            this.parentNode.children[1].innerHTML=(valServerTimeOffset<0?"":"+")+Math.round(valServerTimeOffset/3600)+getText("shortHours");
            this.parentNode.children[3].innerHTML=getFormattedDateStr(nowServerOff)+"&nbsp;"+getDaytimeStr(nowServerOff);
        },false);
        createElement("span",{"style":"margin-right:5px;"},newtd,(valServerTimeOffset<0?"":"+")+Math.round(valServerTimeOffset/3600)+getText("shortHours"));
        newinput=createElement("button",{"type":"button","class":"link2"},newtd,"+");
        newinput.addEventListener("click",function(){
            valServerTimeOffset=Math.min(86400,valServerTimeOffset+3600);
            GM_setValue(COUNTRY+"_valServerTimeOffset",valServerTimeOffset);
            nowServerOff=unsafeWindow.Zeit.Server+valServerTimeOffset;
            this.parentNode.children[1].innerHTML=(valServerTimeOffset<0?"":"+")+Math.round(valServerTimeOffset/3600)+getText("shortHours");
            this.parentNode.children[3].innerHTML=getFormattedDateStr(nowServerOff)+"&nbsp;"+getDaytimeStr(nowServerOff);
        },false);
        createElement("span",{"style":"margin-left:10px;"},newtd,getFormattedDateStr(nowServerOff)+"&nbsp;"+getDaytimeStr(nowServerOff));
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"id":"inputvalGamecursor","type":"checkbox","class":"link","checked":GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valGamecursor",true)},newtd);
        newinput.addEventListener("click",function(){GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valGamecursor", this.checked,51);},false);
        createElement("td",{},newtr,getText("settings_valGamecursor")[0]);
        createElement("td",{},newtr,getText("settings_valGamecursor")[1]);
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"id":"inputvalDrag","type":"checkbox","class":"link","checked":GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valDrag",false)},newtd);
        newinput.addEventListener("click",function(){GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valDrag", this.checked,52);},false);
        createElement("td",{},newtr,getText("settings_valDrag")[0]);
        createElement("td",{},newtr,getText("settings_valDrag")[1]);
        
        /*
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"id":"inputvalDrag","type":"checkbox","class":"link","checked":valClickErrorbox},newtd);
        newinput.addEventListener("click",function(){
            valClickErrorbox=this.checked;
            GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valClickErrorbox", valClickErrorbox,53);
        },false);
        createElement("td",{},newtr,getText("settings_valClickErrorbox")[0]);
        createElement("td",{},newtr,getText("settings_valClickErrorbox")[1]);
        */
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"id":"inputvalHotkey","type":"checkbox","class":"link","checked":GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valHotkey",true)},newtd);
        newinput.addEventListener("click",function(){GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valHotkey", this.checked,54);},false);
        createElement("td",{},newtr,getText("settings_valHotkeys")[0]);
        createElement("td",{},newtr,getText("settings_valHotkeys")[1]);
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"colspan":"2","align":"center"},newtr);
        newinput=createElement("button",{"type":"button","class":"link2"},newtd,getText("settings_cacheReset")[0]);
        newinput.addEventListener("click",function(){
            alert2(getText("settings_cacheReset")[1],getText("yes"),getText("no"),function(){
                for(var i=1000; i >=0; --i){unsafeWindow.clearInterval(i);}
                window.setTimeout(function(){
                    var protect={"kauf":1,"farmiLog":1,"vertraegeIn":1,"vertraegeOut":1,"levelLog":1,"nachrichten":1};
                    var help=cloneInto(GM_listValues(), unsafeWindow);
                    for(var v=help.length-1;v>-1;v--){
                    if(help[v].match(COUNTRY+"_"+SERVER+"_"+USERNAME+"_")){
                        var curr=help[v].replace(COUNTRY+"_"+SERVER+"_"+USERNAME+"_","");
                        if(!protect[curr]){ GM_deleteValue(help[v]); }
                    }
                    }
                    top.location.href=top.location.href;
                },500);
            });
        },false);
        createElement("td",{},newtr,getText("settings_cacheReset")[1]);
        
        // *****
        newtr=createElement("tr",{},newtable);
        newtd=createElement("th",{"colspan":"3"},newtr,"Developing");
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"id":"inputDevmode","type":"checkbox","class":"link","checked":DEVMODE},newtd);
        newinput.addEventListener("click",function(){GM_setValue2("devmode",DEVMODE=this.checked,55);},false);
        createElement("td",{},newtr,"Developer Mode");
        createElement("td",{},newtr);
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"id":"inputDevmodeEvents","type":"checkbox","class":"link","checked":DEVMODE_EVENTS},newtd);
        newinput.addEventListener("click",function(){GM_setValue2("devmode_events",DEVMODE_EVENTS=this.checked,56);},false);
        createElement("td",{},newtr,"Developer Mode");
        createElement("td",{},newtr,"Show events (reload page)");
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"id":"inputDevmodeFunctions","type":"checkbox","class":"link","checked":DEVMODE_FUNCTION},newtd);
        newinput.addEventListener("click",function(){GM_setValue2("devmode_function",DEVMODE_FUNCTION=this.checked);},false);
        createElement("td",{},newtr,"Developer Function");
        createElement("td",{},newtr,"Show function calls");
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"id":"inputDevmodeLogWarning","type":"checkbox","class":"link","checked":DEVMODE_LOG_WARNING},newtd);
        newinput.addEventListener("click",function(){GM_setValue2("devmode_log_warning",DEVMODE_LOG_WARNING=this.checked);},false);
        createElement("td",{"rowspan":"2"},newtr,"Logging");
        createElement("td",{},newtr,"Show warnings in screen");
        
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"align":"center"},newtr);
        newinput=createElement("input",{"id":"inputDevmodeLogWarning","type":"checkbox","class":"link","checked":DEVMODE_LOG_ERROR},newtd);
        newinput.addEventListener("click",function(){GM_setValue2("devmode_log_error",DEVMODE_LOG_ERROR=this.checked);},false);
        createElement("td",{},newtr,"Show errors in screen");
        
        newtable=null;newtr=null;newtd=null;newdiv=null;newinput=null;
        
    }catch(err){GM_logError("buildInfoPanelOptions\n"+err);}
}
function buildInfoPanelAccounts(showPW){
    try{
        var container,newtable,newtr,newtd,newinput,newselect,newdiv;
        newdiv=$("infoPanelNaviAccounts");
        newdiv.classList.remove("naviItem");
        newdiv.classList.add("naviItemActive");
        var logindata=explode(GM_getValue("logindata","[]"),"buildInfoPanelAccounts/logindata",[]);
        container=$("infoPanelR");
        container.innerHTML="";
        newtable=createElement("table",{"align":"center"},container);
        newtr=createElement("tr",{},newtable);
        createElement("th",{},newtr);
        createElement("th",{},newtr,getText("server"));
        createElement("th",{},newtr,getText("name"));
        createElement("th",{},newtr,getText("password"));
        createElement("th",{"colspan":2},newtr);
        for(var v=0;v<logindata.length;v++){
            newtr=createElement("tr",{"v":v},newtable);
            newtd=createElement("td",{},newtr);
            newinput=createElement("input",{"type":"checkbox","class":"link","checked":logindata[v][4]},newtd);
            newinput.addEventListener("mouseover",function(event){ toolTip.show(event,getText("accountActive")); },false);
            newinput.addEventListener("change",function(){
                logindata[this.parentNode.parentNode.getAttribute("v")][4]=this.checked;
                GM_setValueCache("logindata",implode(logindata),57);
            },false);
            newtd=createElement("td",{},newtr);
            newinput=createElement("input",{"class":"text","style":"width:20px","maxlength":"2"},newtd);
            if (isNaN(logindata[v][1])){ logindata[v][1]="0";}
            if (logindata[v][1]!="0"){ newinput.value=logindata[v][1]; }
            newinput.addEventListener("change",function(){
                var readin=parseInt(this.value,10);
                if (isNaN(readin) || (readin<1)){
                    alert2(getText("invalidServer"),getText("ok")); this.value="";
                }else{
                    this.value=readin;
                    logindata[this.parentNode.parentNode.getAttribute("v")][1]=readin;
                    GM_setValueCache("logindata",implode(logindata),57);
                }
            },false);
            newselect=createElement("select",{},newtd);
            for(var w in GAMEPAGES){
                if(!GAMEPAGES.hasOwnProperty(w)){ continue; }
                createElement("option",{"value":w},newselect,w);
            }
            newselect.value=logindata[v][0];
            newselect.addEventListener("change",function(){
                logindata[this.parentNode.parentNode.getAttribute("v")][0]=this.value;
                GM_setValueCache("logindata",implode(logindata),57);
            },false);

            newtd=createElement("td",{},newtr);
            newinput=createElement("input",{"value":logindata[v][2],"class":"text","style":"width:140px","maxlength":"20"},newtd);
            newinput.addEventListener("change",function(){
                logindata[this.parentNode.parentNode.getAttribute("v")][2]=this.value;
                GM_setValueCache("logindata",implode(logindata),57);
            },false);

            newtd=createElement("td",{},newtr);
            newinput=createElement("input",{"value":enc(logindata[v][3],-4242),"class":"text","style":"width:140px","maxlength":"20"},newtd);
            if (!showPW){ newinput.type="password"; }
            newinput.addEventListener("change",function(){
                logindata[this.parentNode.parentNode.getAttribute("v")][3]=enc(this.value,4242);
                GM_setValueCache("logindata",implode(logindata),57);
            },false);

            newtd=createElement("td",{},newtr);
            if (v>0){
                newdiv=createElement("div",{"class":"link2","style":"width:14px;height:10px;"},newtd);
                createElement("img",{"src":GFX+"quest_up.gif","style":"width:14px;height:10px;"},newdiv);
                newdiv.addEventListener("mouseover",function(){this.style.backgroundColor="blue";},false);
                newdiv.addEventListener("mouseout",function(){this.style.backgroundColor="transparent";},false);
                newdiv.addEventListener("click",function(showPW){ return function(){
                    var currLine=parseInt(this.parentNode.parentNode.getAttribute("v"),10);
                    logindata.splice(currLine-1,2,logindata[currLine],logindata[currLine-1]);
                    GM_setValueCache("logindata",implode(logindata),57);
                    buildInfoPanelAccounts(showPW);
                }}(showPW),false);
            }
            if (v<logindata.length-1){
                newdiv=createElement("div",{"class":"link2","style":"width:14px;height:10px;"},newtd);
                createElement("img",{"src":GFX+"quest_down.gif","style":"width:14px;height:10px;"},newdiv);
                newdiv.addEventListener("mouseover",function(){this.style.backgroundColor="blue";},false);
                newdiv.addEventListener("mouseout",function(){this.style.backgroundColor="transparent";},false);
                newdiv.addEventListener("click",function(showPW){ return function(){
                    var currLine=parseInt(this.parentNode.parentNode.getAttribute("v"),10);
                    logindata.splice(currLine,2,logindata[currLine+1],logindata[currLine]);
                    GM_setValueCache("logindata",implode(logindata),57);
                    buildInfoPanelAccounts(showPW);
                }}(showPW),false);
            }

            newtd=createElement("td",{},newtr);
            createElement("img",{"src":GFX+"popin/contracts/anullieren.gif","class":"link2","style":"width: 16px;height: 16px;"},newtd);
            newtd.addEventListener("mouseover",function(event){
                toolTip.show(event,getText("delete"));
                this.style.backgroundColor="blue";
            },false);
            newtd.addEventListener("mouseout",function(){this.style.backgroundColor="transparent";},false);
            newtd.addEventListener("click",function(showPW){ return function(){
                var currLine=parseInt(this.parentNode.getAttribute("v"),10);
                logindata.splice(currLine,1);
                GM_setValueCache("logindata",implode(logindata),57);
                buildInfoPanelAccounts(showPW);
            }}(showPW),false);
        }
        newtr=createElement("tr",{},newtable);
        newtd=createElement("td",{"colspan":"5","class":"link","style":"font-weight:bold;font-size:16px;text-align:right;"},newtr,"+");
        newtd.addEventListener("mouseover",function(){this.style.backgroundColor="blue";},false);
        newtd.addEventListener("mouseout",function(){this.style.backgroundColor="transparent";},false);
        newtd.addEventListener("click",function(showPW){ return function(){
            logindata.push([COUNTRY,"0","","",false]); // new empty line
            GM_setValueCache("logindata",implode(logindata),57);
            buildInfoPanelAccounts(showPW);
        }}(showPW),false);
        newdiv=createElement("div",{"align":"center"},container);
        newinput=createElement("input",{"type":"checkbox","class":"link","checked":showPW},newdiv);
        newinput.addEventListener("click",function(){buildInfoPanelAccounts(this.checked);},false);
        createElement("span",{},newdiv,getText("showPasswords"));
        container=null;newtable=null;newtr=null;newtd=null;newinput=null;newselect=null;newdiv=null;
    }catch(err){GM_logError("buildInfoPanelAccounts\n"+err);}
}
function buildInfoPanelHotkeys(){
    try{
        var container,newtable,newtr,newtd,newinput,newdiv;
        newdiv=$("infoPanelNaviHotkeys");
        newdiv.classList.remove("naviItem");
        newdiv.classList.add("naviItemActive");
        container=$("infoPanelR");
        newtable=createElement("table",{"align":"center","border":"1","class":"hoverRowBgCc9"},container);
        for(var tr in getText("settings_hotkeymap")){
            if(!getText("settings_hotkeymap").hasOwnProperty(tr)){ continue; }
            newtr=createElement("tr",{},newtable);
            newtd=createElement("td",{},newtr);
            newinput=createElement("input",{"id":"hotkey"+tr,"value":getKeySymbol(hotkeymap[tr]),"class":"text","style":"width:80px;"},newtd);
            newinput.addEventListener("keyup",function(event){
                this.value=getKeySymbol(event.keyCode);
                hotkeymap[this.id.replace("hotkey","")]=event.keyCode;
                GM_setValue2("hotkeymap",implode(hotkeymap),58);
            },false);
            createElement("td",{},newtr,getText("settings_hotkeymap")[tr]);
        }
        container=null;newtable=null;newtr=null;newtd=null;newinput=null;newdiv=null;
    }catch(err){GM_logError("buildInfoPanelHotkeys\n"+err);}
}
function buildInfoPanelCss(){
    try{
        var container,newtable,newtr,newtd,newinput,newdiv;
        newdiv=$("infoPanelNaviCss");
        newdiv.classList.remove("naviItem");
        newdiv.classList.add("naviItemActive");
        container=$("infoPanelR");
        newtable=createElement("table",{"align":"center"},container);
        for(var v in css_styles){
            if(!css_styles.hasOwnProperty(v)){ continue; }
            newtr=createElement("tr",{},newtable);
            createElement("td",{},newtr,v);
            newtd=createElement("td",{},newtr);
            var help=GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_"+v,css_styles[v][1]);
            newinput=createElement("input",{"name":v,"value":help,"class":"text","style":"width:250px;"},newtd);
            newinput.addEventListener("keyup",function(){
                var v=this.getAttribute("name");
                if(this.value==""){ this.value=INIT_CSS_STYLES[v][1]; }
                css_styles[v][1]=this.value;
                var help=css_styles[v][1];
                for(var w=0;w<css_styles[v][0].length;w++){
                    help=css_styles[css_styles[v][0][w]][1]+help;
                }
                this.parentNode.nextSibling.firstElementChild.setAttribute("style",help);
                GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_css_styles",implode(css_styles));
            },false);
            newtd=createElement("td",{},newtr);
            for(var w=0;w<css_styles[v][0].length;w++){
                help=css_styles[css_styles[v][0][w]][1]+help;
            }
            newdiv=createElement("div",{"style":help},newtd,"test");
        }
        container=null;newtable=null;newtr=null;newtd=null;newinput=null;newdiv=null;
    }catch(err){GM_logError("buildInfoPanelCss\n"+err);}
}
function buildInfoPanelImport(mode,showData,onlyThisAccount){
    try{
        var container,newtable,newtr,newtd,newinput,newdiv;
        newdiv=$("infoPanelNaviImport");
        newdiv.classList.remove("naviItem");
        newdiv.classList.add("naviItemActive");
        container=$("infoPanelR");
        container.innerHTML="";
        newdiv=createElement("div",{"style":"left:0px;position:absolute;width:450px;"},container);
        newinput=createElement("div",{"class":"link naviItem"+(mode=="export"?"Active":""),"style":"width:40%;"},newdiv,"Export");
        newinput.addEventListener("click",function(){
            buildInfoPanelImport("export",false,true);
        },false);
        newinput=createElement("div",{"class":"link naviItem"+(mode=="import"?"Active":""),"style":"width:40%;"},newdiv,"Import");
        newinput.addEventListener("click",function(){
            buildInfoPanelImport("import",false,true);
        },false);
        container=createElement("div",{"id":"beraterDataImportContainer","style":"position:absolute;top:30px;left:5px;height:485px;width:475px;overflow:auto;"},container);
        switch(mode){
        case "export":{
            // if (showData&&(!onlyThisAccount)){
            //  if(!confirm("Attention! Showing all data of all accounts can slow down your browser. Continue?")){
            //      showData=false;
            //  }
            // }
            createElement("div",{},container,"Click the lines to remove them.");

            var newdiv=createElement("div",{},container);
            var newinput=createElement("input",{"type":"checkbox","checked":showData},newdiv);
            newinput.addEventListener("click",function(){
                showExportData(this.checked,onlyThisAccount);
            },false);
            createElement("span",{},newdiv,"Show the data");

            newdiv=createElement("div",{},container);
            newinput=createElement("input",{"type":"checkbox","checked":onlyThisAccount},newdiv);
            newinput.addEventListener("click",function(){
                showExportData(showData,this.checked);
            },false);
            createElement("span",{},newdiv,"Only this account");

            newinput=createElement("button",{"class":"link"},container,"Create string!");
            newinput.addEventListener("click",function(){
                var save="";
                var help=$("beraterDataImportContainer").getElementsByTagName("tr");
                for(var v=0;v<help.length;v++){
                    var help2=help[v].getElementsByTagName("td");
                    save += help2[0].innerHTML+":"+help2[1].innerHTML+":"+help2[2].firstElementChild.innerHTML+"::";
                }
                prompt("Copy this string to a text-file", save.slice(0,save.length-2));
            },false);
            var newtable=createElement("table",{"border":"1","class":"hoverRowBgCc9","style":"width:100%"},container);
            var newtr,newtd;
            var help=cloneInto(GM_listValues(), unsafeWindow);
            help.sort();
            if(onlyThisAccount){
                for(var v=0;v<help.length;v++){
                    if(help[v].search(COUNTRY+"_"+SERVER+"_"+USERNAME)!=-1){
                        var help2=GM_getValue(help[v]);
                        var help3="s";
                        if(help2==""){ help2=" "; }
                        if(typeof help2=="number"){ help3="n"; }
                        else if(typeof help2=="boolean"){ help3="b"; }
                        else{ help2=help2.replace(/(:+)/g,":"); }
                        newtr=createElement("tr",{},newtable);
                        newtr.addEventListener("click",function(){ removeElement(this); },false);
                        createElement("td",{},newtr,help[v].replace(COUNTRY+"_"+SERVER+"_"+USERNAME+"_",""));
                        createElement("td",{},newtr,help3);
                        newtd=createElement("td",{"style":(showData?"":"display:none;")},newtr);
                        createElement("div",{"style":"max-height:100px;width:270px;overflow:auto;"},newtd,help2);
                    }
                }
            }else{
                for(var v=0;v<help.length;v++){
                    var help2=GM_getValue(help[v]);
                    var help3="s";
                    if(help2==""){ help2=" "; }
                    if(typeof help2=="number"){ help3="n"; }
                    else if(typeof help2=="boolean"){ help3="b"; }
                    else{ help2=help2.replace(/(:+)/g,":"); }
                    newtr=createElement("tr",{},newtable);
                    newtr.addEventListener("click",function(){ removeElement(this); },false);
                    createElement("td",{},newtr,help[v]);
                    createElement("td",{},newtr,help3);
                    newtd=createElement("td",{"style":(showData?"":"display:none;")},newtr);
                    createElement("div",{"style":"max-height:100px;width:270px;overflow:auto;"},newtd,help2);
                }
            }
            container=null;newdiv=null;newtable=null;newtr=null;newtd=null;newinput=null;
        break;}
        case "import":{
            createElement("div",{},container,"Click the lines to remove them.");

            var newdiv=createElement("div",{},container);
            var newinput=createElement("input",{"type":"checkbox","checked":showData},newdiv);
            newinput.addEventListener("click",function(){
                showImportData(this.checked,onlyThisAccount);
            },false);
            createElement("span",{},newdiv,"Show the data");

            newdiv=createElement("div",{},container);
            newinput=createElement("input",{"type":"checkbox","checked":onlyThisAccount},newdiv);
            newinput.addEventListener("click",function(){
                showImportData(showData,this.checked);
            },false);
            createElement("span",{},newdiv,"Only this account");

            newinput=createElement("button",{"class":"link"},container,"Enter data-string");
            newinput.addEventListener("click",function(){
                var promptdata=prompt("Please enter the data-string","");
                if(promptdata){
                    var container=$("beraterDataImportContainer");
                    var newtable=container.getElementsByTagName("table");
                    if(newtable[0]){ removeElement(newtable[0]); }
                    newtable=createElement("table",{"border":"1","class":"hoverRowBgCc9","style":"width:100%"},container);
                    var newtr,newtd;
                    var help=promptdata.split("::");
                    for(var v=0;v<help.length;v++){
                        var help2=help[v].split(":");
                        var impName=(onlyThisAccount?COUNTRY+"_"+SERVER+"_"+USERNAME+"_":"")+help2.splice(0,1)[0];
                        var impType=help2.splice(0,1)[0];
                        var impContent=help2.join(":");
                        if(impContent==" "){ impContent=""; }
                        if((impType=="n")||(impType=="b")||(impType=="s")){
                            newtr=createElement("tr",{},newtable);
                            newtr.addEventListener("click",function(){ removeElement(this); },false);
                            createElement("td",{},newtr,impName);
                            createElement("td",{},newtr,impType);
                            newtd=createElement("td",{"style":(showData?"":"display:none;")},newtr);
                            createElement("div",{"style":"max-height:100px;width:280px;overflow:auto;"},newtd,impContent);
                        }
                    }
                    container=null;newtable=null;newtr=null;newtd=null;
                }
            },false);
            newinput=createElement("button",{"class":"link"},container,"Import this!");
            newinput.addEventListener("click",function(){
                var help=$("beraterDataImportContainer").getElementsByTagName("tr");
                for(var v=0;v<help.length;v++){
                    var help2=help[v].getElementsByTagName("td");
                    switch(help2[1].innerHTML){
                    case "n": GM_setValue2(help2[0].innerHTML,parseInt(help2[2].getElementsByTagName("div")[0].innerHTML,10),59);break;
                    case "b": GM_setValue2(help2[0].innerHTML,help2[2].getElementsByTagName("div")[0].innerHTML=="true",60);break;
                    case "s": GM_setValue2(help2[0].innerHTML,help2[2].getElementsByTagName("div")[0].innerHTML,61);break;
                    }
                }
                alert2("done",getText("ok"));
            },false);
        break;}
        }
        container=null;newtable=null;newtr=null;newtd=null;newinput=null;newdiv=null;
    }catch(err){GM_logError("buildInfoPanelImport\n"+err);}
}
function buildInfoPanelLevel(){
    try{
        var container=$("infoPanelInner");
        container.innerHTML="";
        // GM_log("levelLog:\n"+print_r(levelLog,"",true,"\n"));
        newdiv=createElement("div",{"style":"height:400px;overflow:auto;color:black;"},container);
        // todayStr=getDateStr(now,2,false);
        levelLog[levelLogId][1]=parseInt($("pkt").innerHTML.replace(/\D/g,""),10);
        var totalumsatz=[0,0,[0,0]];
        var day,days;

        newtable=createElement("table",{"border":"1","style":"width:100%;"},newdiv);
        thead=createElement("thead",{},newtable); // sortable table
        newtbody=createElement("tbody",{"class":"hoverRowBgCc9"},newtable);
        newtfoot=createElement("tfoot",{},newtable);

        newtr=createElement("tr",{"class":"borderBottom2"},thead);
        createElement("th",{"class":"link","sortdir":"Asc","style":"border-right:2px solid black;"},newtr,getText("day"));
        createElement("th",{"class":"link","sortdir":"Asc"},newtr,getText("points"));
        createElement("th",{"class":"link","sortdir":"Asc"},newtr,"+");
        createElement("th",{"class":"link","sortdir":"Asc","style":"border-right:2px solid black;"},newtr,getText("rank"));
        createElement("th",{"class":"link","sortdir":"Asc"},newtr,getText("market"));
        createElement("th",{"class":"link","sortdir":"Asc"},newtr,getText("contract"));
        createElement("th",{"class":"link","sortdir":"Asc"},newtr,unsafeWindow.customerarecalled.replace(/%FARMI%/,""));
        new SortableTable(newtr);

        for(var v=levelLog.length-1;v>=0;v--){
            if(levelLog[v][0].match(/^\d+-\d+$/)){
                day=/^(\d+)-(\d+)$/.exec(levelLog[v][0]);
                day.swap(2,3);
                day[0]=1;
                day[1]=parseInt(day[1],10);
                day[2]=parseInt(day[2],10);
                days=(new Date(day[2],day[1],0)).getDate();
            }else{
                day=levelLog[v][0].split(/\./);
                day[0]=parseInt(day[0],10);
                day[1]=parseInt(day[1],10);
                day[2]=parseInt(day[2],10);
                days=1;
                // doubling with month-entry
                day[3]=day[2]+(day[1]<10?"0":"")+day[1];
                for(var w=levelLog.length-1;w>=0;w--){
                    if(levelLog[w][0]==day[3]){ days=0;break; } 
                }
            } 
            day=(new Date(day[2],day[1]-1,day[0]));

            newtr=createElement("tr",{"align":"right"},newtbody);

            // Sundays
            if (day.getDay()==0){
                newtr.setAttribute("class","borderBottom2");
            }

            createElement("td",{"value":day.getTime(),"style":"text-align:right;border-right:2px solid black;"},newtr,levelLog[v][0]==todayServerStr?getText("day0"):levelLog[v][0]);
            createElement("td",{"value":levelLog[v][1]},newtr,numberFormat(levelLog[v][1]));
            if(v==0){
                createElement("td",{"value":0},newtr);
            }else{
                createElement("td",{"value":(levelLog[v][1]-levelLog[v-1][1])},newtr,numberFormat(levelLog[v][1]-levelLog[v-1][1]));
            }
            createElement("td",{"value":levelLog[v][2],"style":"border-right:2px solid black;"},newtr,levelLog[v][2]?numberFormat(levelLog[v][2]):"");
            for(var w=0;w<=1;w++){
                createElement("td",{"value":levelLog[v][w+3]},newtr,numberFormat(levelLog[v][w+3]));
                totalumsatz[w] += levelLog[v][w+3];
            }
            if(levelLog[v][5]>0){
                createElement("td",{"value":levelLog[v][5]},newtr,numberFormat(levelLog[v][5]));
                totalumsatz[2][0] += days;
                totalumsatz[2][1] += levelLog[v][5];
            }else{
                createElement("td",{"value":0},newtr,"-");
            }
        }
        newtbody.scrollTop=newtbody.scrollHeight;
        //if (newdiv.scrollTop ==0) newdiv.scrollTop=(newdiv.scrollHeight < newdiv.clientHeight)?0:newdiv.scrollHeight - newdiv.clientHeight;

        newtr=createElement("tr",{"class":"borderTop2","align":"right"},newtfoot);
        createElement("td",{"style":"border-right:2px solid black;"},newtr,sign_average);
        createElement("td",{},newtr);
        if(v>1){
            var daycount=1+Math.round((now-getTime(levelLog[1][0]))/86400);
            createElement("td",{},newtr,numberFormat((levelLog[v-1][1]-levelLog[0][1])/daycount));
        }else{
            createElement("td",{},newtr);
        }
        createElement("td",{"style":"border-right:2px solid black;"},newtr);
        var daycount=1+Math.round((now-getTime(levelLog[0][0]))/86400);
        for(var w=0;w<2;w++){
            createElement("td",{},newtr,numberFormat(totalumsatz[w]/daycount));
        }
        createElement("td",{},newtr,numberFormat(totalumsatz[2][1]/totalumsatz[2][0]));

        newdiv=createElement("div",{"style":"height:106px;margin-top:10px;overflow:auto;color:black;"},container);
        for(var w=0;w<prodNameSort[0].length;w++){
            var v=prodNameSort[0][w];
            if((!prodBlock[0][v].match(/t/))&&(buyNotePadShowBlocked||((!prodBlock[0][v].match(/l/))&&(!prodBlock[0][v].match(/q/))))){
                if(0<prodMinRack[0][v]){
                    if (prodStock[0][v]==0){
                        newdiv1=createElement("div",{"class":"link hoverBgCc9","prod":v,"style":"line-height:16px;"},newdiv);
                        newdiv1.addEventListener("mouseover",function(event){ showGoToMarketToolTip(event,this.getAttribute("prod")); },false);
                        newdiv1.addEventListener("click",function(){ showMarket(this.getAttribute("prod")); },false);
                        produktPic(0,v,newdiv1);
                        createElement("span",{"style":"font-weight:bold;"},newdiv1,getText("stockXmissing").replace(/%1%/,prodName[0][v]));
                    }else if(prodStock[0][v]<prodMinRack[0][v]){
                        newdiv1=createElement("div",{"class":"link hoverBgCc9","prod":v,"style":"line-height:16px;"},newdiv);
                        newdiv1.addEventListener("mouseover",function(event){ showGoToMarketToolTip(event,this.getAttribute("prod")); },false);
                        newdiv1.addEventListener("click",function(){ showMarket(this.getAttribute("prod")); },false);
                        produktPic(0,v,newdiv1);
                        createElement("span",{"style":"font-weight:bold;"},newdiv1,getText("stockXlow").replace(/%1%/,prodName[0][v])+" ("+numberFormat(prodStock[0][v])+")");
                    }
                }
            }
        }
    }catch(err){GM_logError("buildInfoPanelLevel\n"+err);}
}
function buildInfoPanelMessages(mode){
try{
    var modeDefault={"type":1,"filterProduct":-1,"filterPlayer":""};
    var modeOld=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_modeInfoPanelMessages"),"buildInfoPanelMessages/modeOld");
    if(typeof modeOld!="object"){ modeOld=modeDefault; }
    if(typeof mode!="object"){ mode=modeOld; }
    for(var v in modeDefault){
        if(!modeDefault.hasOwnProperty(v)){ continue; }
        if(mode[v]==undefined){ mode[v]=(modeOld[v]==undefined?modeDefault[v]:modeOld[v]); }
    }
    GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_modeInfoPanelMessages",implode(mode,"buildInfoPanelMessages/mode"));  
    if(!logSales){
        logSales=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_logSales","[]"),"buildInfoPanelMessages/logSales",[]);
        logSales.sort(sortObjFunctions["int"],true);
        logSalesId=new Object();
        for(var v=logSales.length-1;v>=0;v--){
            logSalesId[logSales[v][0]]=v;
        }
    }
    var plotLogSales=new Array();
    var soldProducts=new Array();
    var sumTurnover=0,sumProfit=0,help,help1;
    if(mode["filterPlayer"]){
        var regFilterPlayer=new RegExp("^"+mode["filterPlayer"].replace(/\./g,"\\.").replace(/\*/g,".*")+"$","i");
    }else{
        var regFilterPlayer=/./;
    }
    var container,newtable,newtr,newtd,cell,div;
    container=$("infoPanelInner");
    container.innerHTML="";
    // head
    div=createElement("div",{"class":"borderBottom1Black","style":"height:45px;"},container);
    newtable=createElement("table",{"style":"width:100%;"},div);
    newtr=createElement("tr",{},newtable);
    newtd=createElement("td",{"class":"tnormal","style":"font-weight:bold;text-align:center;"},newtr,getText("salesLog"));
    newtd=createElement("td",{},newtr);
    div=createElement("div",{"class":"link naviItem"+(mode["type"]==1?"Active":"")},newtd,getText("detail"));
    div.addEventListener("click",function(){
        buildInfoPanelMessages({"type":1});
    },false);
    div=createElement("div",{"class":"link naviItem"+(mode["type"]==2?"Active":"")},newtd,getText("goods"));
    div.addEventListener("click",function(){
        buildInfoPanelMessages({"type":2});
    },false);
    div=createElement("div",{"class":"link naviItem"+(mode["type"]==3?"Active":"")},newtd,getText("buyers"));
    div.addEventListener("click",function(){
        buildInfoPanelMessages({"type":3});
    },false);
    // content
    div=createElement("div",{"class":"borderBottom1Black","style":"overflow-y:scroll;overflow-x:hidden;height:425px;"},container);
    newtable=createElement("table",{"style":"width:100%;","cellspacing":0},div);
    newtr=createElement("tr",{},newtable);

    switch(mode["type"]){
    case 1:{
        for(var v=logSales.length-1;v>-1;v--){
            if(logSales[v][2].match(regFilterPlayer)){
                help=false;
                if(typeof logSales[v][3][0]!="object"){
                    soldProducts[logSales[v][3][0]]=true;
                    if((mode["filterProduct"]==-1)||(mode["filterProduct"]==logSales[v][3][0])){
                        sumTurnover+=logSales[v][4];
                        sumProfit+=0.9*logSales[v][4];
                        plotLogSales.push([v,Math.round(100*logSales[v][4]/logSales[v][3][1])/100]);
                    }
                }else if(logSales[v][3].length==1){
                    soldProducts[logSales[v][3][0][0]]=true;
                    if((mode["filterProduct"]==-1)||(mode["filterProduct"]==logSales[v][3][0][0])){
                        sumTurnover+=logSales[v][4];
                        sumProfit+=logSales[v][4];
                        plotLogSales.push([v,[Math.round(100*logSales[v][4]/logSales[v][3][0][1])/100]]);
                    }
                }else{
                    help=false;help1=0;
                    for(var i=logSales[v][3].length-1;i>-1;i--){
                        soldProducts[logSales[v][3][i][0]]=true;
                        help1+=logSales[v][3][i][1]*gut[logSales[v][3][i][0]];
                        if((mode["filterProduct"]==-1)||(mode["filterProduct"]==logSales[v][3][i][0])){ help=true; }
                    }
                    if(help){
                        help=[v,[]];
                        for(var i=logSales[v][3].length-1;i>-1;i--){
                            help[1][i]=Math.round(100*logSales[v][4]*gut[logSales[v][3][i][0]]/help1)/100;
                            if((mode["filterProduct"]==-1)||(mode["filterProduct"]==logSales[v][3][i][0])){
                                sumTurnover+=logSales[v][3][i][1]*help[1][i];
                                sumProfit+=logSales[v][3][i][1]*help[1][i];
                            }
                        }
                        plotLogSales.push(help);
                    }
                }
            }
        }
        createElement("th",{},newtr,getText("buyers"));
        createElement("th",{},newtr,getText("products"));
        createElement("th",{},newtr,getText("price"));
        createElement("th",{},newtr,getText("turnover"));
        createElement("th",{},newtr,getText("profit")); 
        eventListenerScroll=function(){
            if((parseInt(this.scrollTop,10)+parseInt(this.style.height,10))>0.95*parseInt(this.scrollHeight,10)){
                plot();
            }
        }
        div.addEventListener("scroll",eventListenerScroll,false);
        function plot(){
        try{
            var newtable=$("infoPanelInner").getElementsByTagName("table")[1];
            var start=newtable.childElementCount-1;
            var end=start+100;
            if(plotLogSales.length<=end){
                end=plotLogSales.length;
                newtable.parentNode.removeEventListener("scroll",eventListenerScroll,false);
            }
            var newtr,newtd,newtd1,newtd2,newtd3,newdiv;
            var help;
            for(var w=start;w<end;w++){
                var v=plotLogSales[w][0];
                newtr=createElement("tr",{"class":"hoverBgCc9","v":v},newtable);
                if(typeof logSales[v][3][0]=="object"){ newtr.style.fontStyle="italic"; }
                newtr.addEventListener("mouseover",function(event){ 
                    toolTip.show(event,toolTipSales(this.getAttribute("v")));
                },false);
                newtd=createElement("td",{"class":"link"},newtr,logSales[v][2]);
                newtd.addEventListener("click",function(){
                    buildInfoPanelMessages({"filterPlayer":logSales[this.parentNode.getAttribute("v")][2]});
                },false);
                newtd=createElement("td",{"style":"height:16px"},newtr);
                newtd1=createElement("td",{"style":"height:16px;padding-left:20px;"},newtr);
                newtd2=createElement("td",{"style":"height:16px;padding-left:20px;"},newtr);
                newtd3=createElement("td",{"style":"height:16px;padding-left:20px;"},newtr);
                if(typeof logSales[v][3][0]!="object"){
                    newdiv=createElement("div",{"class":"link","prod":logSales[v][3][0]},newtd);
                    newdiv.addEventListener("click",function(){
                        buildInfoPanelMessages({"filterProduct":this.getAttribute("prod")});
                    },false);                   
                    produktPic(0,logSales[v][3][0],newdiv);
                    createElement("span",{},newdiv,numberFormat(logSales[v][3][1])+" "+prodName[0][logSales[v][3][0]]);
                    createElement("div",{"style":"text-align:right;"},newtd1,moneyFormat(plotLogSales[w][1]));
                    createElement("div",{"style":"text-align:right;"},newtd2,moneyFormat(logSales[v][4]));                  
                    createElement("div",{"style":"text-align:right;"},newtd3,moneyFormat(0.9*logSales[v][4]));                  
                }else if(logSales[v][3].length==1){
                    newdiv=createElement("div",{"class":"link","prod":logSales[v][3][0][0]},newtd);
                    newdiv.addEventListener("click",function(){
                        buildInfoPanelMessages({"filterProduct":this.getAttribute("prod")});
                    },false);                   
                    produktPic(0,logSales[v][3][0][0],newdiv);
                    createElement("span",{},newdiv,numberFormat(logSales[v][3][0][1])+" "+prodName[0][logSales[v][3][0][0]]);
                    createElement("div",{"style":"text-align:right;"},newtd1,moneyFormat(plotLogSales[w][1][0]));
                    createElement("div",{"style":"text-align:right;"},newtd2,moneyFormat(logSales[v][4]));
                    createElement("div",{"style":"text-align:right;"},newtd3,moneyFormat(logSales[v][4]));
                }else{
                    help=[0,0];
                    for(var i=logSales[v][3].length-1;i>-1;i--){
                        if((mode["filterProduct"]==-1)||(mode["filterProduct"]==logSales[v][3][i][0])){
                            newdiv=createElement("div",{"class":"link","prod":logSales[v][3][i][0]},newtd);
                            newdiv.addEventListener("click",function(){
                                buildInfoPanelMessages({"filterProduct":this.getAttribute("prod")});
                            },false);                   
                            produktPic(0,logSales[v][3][i][0],newdiv);
                            createElement("span",{},newdiv,numberFormat(logSales[v][3][i][1])+" "+prodName[0][logSales[v][3][i][0]]);
                            createElement("div",{"style":"text-align:right;"},newtd1,"* "+moneyFormat(plotLogSales[w][1][i]));
                            createElement("div",{"style":"text-align:right;"},newtd2,"* "+moneyFormat(plotLogSales[w][1][i]*logSales[v][3][i][1]));
                            createElement("div",{"style":"text-align:right;"},newtd3,"* "+moneyFormat(plotLogSales[w][1][i]*logSales[v][3][i][1]));
                            help[0]++;
                            help[1]+=plotLogSales[w][1][i]*logSales[v][3][i][1];
                        }
                    }
                    if(help[0]>1){
                        createElement("div",{},newtd,"&nbsp;");
                        createElement("div",{},newtd1,"&nbsp;");
                        createElement("div",{"style":"text-align:right;border-top:1px solid black;"},newtd2,moneyFormat(help[1]));
                        createElement("div",{"style":"text-align:right;border-top:1px solid black;"},newtd3,moneyFormat(help[1]));
                    }
                }               
            }
            $("kaufDataCount").innerHTML=numberFormat(end)+"/"+numberFormat(plotLogSales.length);
            newtable=null;newtr=null;newtd=null;newdiv=null;
        }catch(err){GM_logError("buildInfoPanelMessages plot\n"+err);}      
        }
    break;}
    case 2:{
        for(var v=logSales.length-1;v>-1;v--){
            if(logSales[v][2].match(regFilterPlayer)){
                if(typeof logSales[v][3][0]!="object"){
                    if(!plotLogSales[logSales[v][3][0]]){ plotLogSales[logSales[v][3][0]]=[logSales[v][3][0],0,0,0]; }
                    plotLogSales[logSales[v][3][0]][1]+=logSales[v][3][1];
                    plotLogSales[logSales[v][3][0]][2]+=logSales[v][4];
                    plotLogSales[logSales[v][3][0]][3]+=0.9*logSales[v][4];
                }else if(logSales[v][3].length==1){
                    if(!plotLogSales[logSales[v][3][0][0]]){ plotLogSales[logSales[v][3][0][0]]=[logSales[v][3][0][0],0,0,0]; }
                    plotLogSales[logSales[v][3][0][0]][1]+=logSales[v][3][0][1];
                    plotLogSales[logSales[v][3][0][0]][2]+=logSales[v][4];
                    plotLogSales[logSales[v][3][0][0]][3]+=logSales[v][4];
                }else{
                    help1=0;
                    for(var i=logSales[v][3].length-1;i>-1;i--){
                        help1+=logSales[v][3][i][1]*gut[logSales[v][3][i][0]];
                    }
                    for(var i=logSales[v][3].length-1;i>-1;i--){
                        help=Math.round(100*logSales[v][3][i][1]*logSales[v][4]*gut[logSales[v][3][i][0]]/help1)/100;
                        if(!plotLogSales[logSales[v][3][i][0]]){ plotLogSales[logSales[v][3][i][0]]=[logSales[v][3][i][0],0,0,0]; }
                        plotLogSales[logSales[v][3][i][0]][1]+=logSales[v][3][i][1];
                        plotLogSales[logSales[v][3][i][0]][2]+=help;
                        plotLogSales[logSales[v][3][i][0]][3]+=help;
                    }
                }
            }
        }   
        plotLogSales.sort(function(a,b){return a[3]-b[3];});
        createElement("th",{},newtr,getText("product"));
        createElement("th",{},newtr,getText("quantity"));
        createElement("th",{},newtr,getText("turnover"));
        createElement("th",{},newtr,sign_average);
        createElement("th",{},newtr,getText("profit"));
        createElement("th",{},newtr,sign_average);
        for(var v=plotLogSales.length-1;v>-1;v--){
            if(!plotLogSales[v]){ continue; }
            sumTurnover+=plotLogSales[v][2];
            sumProfit+=plotLogSales[v][3];
            newtr=createElement("tr",{"class":"hoverBgCc9 link","prod":plotLogSales[v][0]},newtable);
            newtr.addEventListener("click",function(){
                buildInfoPanelMessages({"type":1,"filterProduct":this.getAttribute("prod")});
            },false);           
            newtd=createElement("td",{},newtr);
            produktPic(0,plotLogSales[v][0],newtd);
            createElement("span",{},newtd,prodName[0][plotLogSales[v][0]]);
            createElement("td",{"align":"right","style":"padding-right:3px;border-right:1px solid black"},newtr,numberFormat(plotLogSales[v][1],0));
            createElement("td",{"align":"right"},newtr,moneyFormat(plotLogSales[v][2]));
            createElement("td",{"align":"right","style":"padding-right:3px;border-right:1px solid black"},newtr,moneyFormat(plotLogSales[v][2]/plotLogSales[v][1],2));
            createElement("td",{"align":"right"},newtr,moneyFormat(plotLogSales[v][3]));
            createElement("td",{"align":"right","style":"padding-right:20px;"},newtr,moneyFormat(plotLogSales[v][3]/plotLogSales[v][1],2));
        }
    break;}
    case 3:{
        plotLogSales=new Object();
        for(var v=logSales.length-1;v>-1;v--){
            if(typeof logSales[v][3][0]!="object"){
                soldProducts[logSales[v][3][0]]=true;
                if((mode["filterProduct"]==-1)||(mode["filterProduct"]==logSales[v][3][0])){            
                    if(!plotLogSales[logSales[v][2]]){ plotLogSales[logSales[v][2]]=[logSales[v][2],{},0,0]; }
                    if(!plotLogSales[logSales[v][2]][1][logSales[v][3][0]]){ plotLogSales[logSales[v][2]][1][logSales[v][3][0]]=0; }
                    plotLogSales[logSales[v][2]][1][logSales[v][3][0]]+=logSales[v][3][1];
                    plotLogSales[logSales[v][2]][2]+=logSales[v][4];
                    plotLogSales[logSales[v][2]][3]+=0.9*logSales[v][4];
                }
            }else if(logSales[v][3].length==1){
                soldProducts[logSales[v][3][0][0]]=true;                
                if((mode["filterProduct"]==-1)||(mode["filterProduct"]==logSales[v][3][0][0])){
                    if(!plotLogSales[logSales[v][2]]){ plotLogSales[logSales[v][2]]=[logSales[v][2],{},0,0]; }
                    if(!plotLogSales[logSales[v][2]][1][logSales[v][3][0][0]]){ plotLogSales[logSales[v][2]][1][logSales[v][3][0][0]]=0; }
                    plotLogSales[logSales[v][2]][1][logSales[v][3][0][0]]+=logSales[v][3][0][1];
                    plotLogSales[logSales[v][2]][2]+=logSales[v][4];
                    plotLogSales[logSales[v][2]][3]+=logSales[v][4];
                }
            }else{
                help1=0;
                for(var i=logSales[v][3].length-1;i>-1;i--){
                    help1+=logSales[v][3][i][1]*gut[logSales[v][3][i][0]];
                }
                for(var i=logSales[v][3].length-1;i>-1;i--){
                    soldProducts[logSales[v][3][i][0]]=true;
                    if((mode["filterProduct"]==-1)||(mode["filterProduct"]==logSales[v][3][i][0])){
                        help=Math.round(100*logSales[v][3][i][1]*logSales[v][4]*gut[logSales[v][3][i][0]]/help1)/100;
                        if(!plotLogSales[logSales[v][2]]){ plotLogSales[logSales[v][2]]=[logSales[v][2],{},0,0]; }
                        if(!plotLogSales[logSales[v][2]][1][logSales[v][3][i][0]]){ plotLogSales[logSales[v][2]][1][logSales[v][3][i][0]]=0; }
                        plotLogSales[logSales[v][2]][1][logSales[v][3][i][0]]+=logSales[v][3][i][1];
                        plotLogSales[logSales[v][2]][2]+=help;
                        plotLogSales[logSales[v][2]][3]+=help;
                    }
                }
            }
        }
        help=[];
        for(var i in plotLogSales){
            if(!plotLogSales.hasOwnProperty(i)){ continue; }
            help.push(plotLogSales[i]);
        }
        plotLogSales=help.clone();
        plotLogSales.sort(function(a,b){return a[3]-b[3];});
        createElement("th",{},newtr,getText("buyers"));
        createElement("th",{},newtr,getText("products"));
        createElement("th",{},newtr,getText("turnover"));
        createElement("th",{},newtr,getText("profit"));
        for(var v=plotLogSales.length-1;v>-1;v--){
            if(!plotLogSales[v]){ continue; }
            sumTurnover+=plotLogSales[v][2];
            sumProfit+=plotLogSales[v][3];
            newtr=createElement("tr",{"class":"hoverBgCc9 link","player":plotLogSales[v][0]},newtable);
            newtr.addEventListener("click",function(){
                buildInfoPanelMessages({"type":1,"filterPlayer":this.getAttribute("player")});
            },false);           
            createElement("td",{},newtr,plotLogSales[v][0]);
            newtd=createElement("td",{},newtr);
            for(var i in plotLogSales[v][1]){
                if(!plotLogSales[v][1].hasOwnProperty(i)){ continue; }
                div=createElement("div",{},newtd);
                produktPic(0,i,div);
                createElement("span",{},div,numberFormat(plotLogSales[v][1][i])+" "+prodName[0][i]);
            }
            createElement("td",{"align":"right"},newtr,moneyFormat(plotLogSales[v][2]));
            createElement("td",{"align":"right"},newtr,moneyFormat(plotLogSales[v][3]));
        }
    break;}
    }
    // foot
    div=createElement("div",{"style":"height:45px;"},container);
    newtable=createElement("table",{"style":"width:100%;"},div);
    newtr=createElement("tr",{},newtable);
    createElement("td",{"id":"kaufDataCount"},newtr);
    newtd=createElement("td",{},newtr);
    if((mode["type"]==1)||(mode["type"]==3)){
        createElement("span",{"style":"padding-left:10px;"},newtd,getText("goods")+":");
        cell=createElement("div",{"class":"clearFilter link","style":"display:inline-block;"},newtd);
        cell.addEventListener("mouseover",function(event){ toolTip.show(event,getText("clearFilter")); },false);
        cell.addEventListener("click",function(){
            buildInfoPanelMessages({"filterProduct":-1});
        },false);
        cell=createElement("select",{"class":"link"},newtd);
        createElement("option",{"value":-1},cell,"---");
        for(var v=0;v<prodNameSort[0].length;v++){
            if(soldProducts[prodNameSort[0][v]]){
                createElement("option",{"value":prodNameSort[0][v]},cell,prodName[0][prodNameSort[0][v]]);
            }
        }
        cell.value=mode["filterProduct"];
        cell.addEventListener("change",function(){
            buildInfoPanelMessages({"filterProduct":this.value});
        },false);
    }
    createElement("td",{},newtr,getText("turnover")+": ");
    createElement("td",{"align":"right"},newtr,moneyFormat(sumTurnover));
    newtr=createElement("tr",{},newtable);
    newtd=createElement("td",{},newtr);
    newtd=createElement("td",{},newtr);
    if((mode["type"]==1)||(mode["type"]==2)){
        createElement("span",{"style":"padding-left:10px;"},newtd,getText("buyers")+":");
        cell=createElement("div",{"class":"clearFilter link","style":"display:inline-block;"},newtd);
        cell.addEventListener("mouseover",function(event){ toolTip.show(event,getText("clearFilter")); },false);
        cell.addEventListener("click",function(){
            buildInfoPanelMessages({"filterPlayer":""});
        },false);   
        cell=createElement("input",{"value":mode["filterPlayer"],"class":"link","style":"width:100px;","maxlength":"20"},newtd);
        cell.addEventListener("mouseover",function(event){ toolTip.show(event,getText("useWildcard")); },false);
        cell.addEventListener("change",function(){ 
            buildInfoPanelMessages({"filterPlayer":this.value});
        },false);
    }
    createElement("td",{},newtr,getText("profit")+": ");
    createElement("td",{"align":"right"},newtr,moneyFormat(sumProfit));
    if(mode["type"]==1){ plot(); }
    container=null;newtable=null;newtr=null;newtd=null;cell=null;div=null;
    }catch(err){GM_logError("buildInfoPanelMessages\n"+err);}   
}

function goToZone(zoneNrF){
    try{
        var currLocation=zones.getLocation(zoneNrF);        
        var div;
        switch(currLocation.location){
        case "farm":{
            if((gameLocation[0]==currLocation.location)&&(gameLocation[1]==currLocation.farmNr)){
                if(div=$("farm"+(1+currLocation.farmNr)+"_pos"+currLocation.zoneNr+"_click")){ 
                    click(div);
                }
            }else if(div=$("speedlink_farm"+(1+currLocation.farmNr))){
                document.addEventListener("gameFarmOpened",function(zoneNrF){
                return function(){
                    document.removeEventListener("gameFarmOpened",arguments.callee,false);
                    window.setTimeout(goToZone,100,zoneNrF);
                }
                }(zoneNrF),false);
                click(div); 
            }           
        break;}
        case "city":{
            if((gameLocation[0]==currLocation.location)&&(gameLocation[1]==currLocation.cityNr)){
                if((currLocation.zoneNr!=undefined)&&(div=$("cityzone_"+currLocation.cityNr+"_"+currLocation.zoneNr))){ 
                    click(div);
                }
            }else if(div=$("speedlink_city"+currLocation.cityNr)){
                document.addEventListener("gameCity"+currLocation.cityNr,function(zoneNrF,currLocation){
                return function(){
                    document.removeEventListener("gameCity"+currLocation.cityNr,arguments.callee,false);
                    window.setTimeout(goToZone,100,zoneNrF);
                }
                }(zoneNrF,currLocation),false);
                click(div); 
            }
        break;}
        case "forestry":{
            if(gameLocation[0]==currLocation.location){
                if((currLocation.zoneNr!=undefined)&&(div=$("forestry_building_click"+currLocation.zoneNr))){ 
                    click(div);
                }
            }else if(div=$("speedlink_forestry")){
                document.addEventListener("gameOpenForestry",function(zoneNrF){
                return function(){
                    document.removeEventListener("gameOpenForestry",arguments.callee,false);
                    window.setTimeout(goToZone,100,zoneNrF);
                }
                }(zoneNrF),false);
                click(div); 
            }
        break;}
        case "foodworld":{
            if(gameLocation[0]==currLocation.location){
                if((currLocation.zoneNr!=undefined)&&(div=$("food_pos"+currLocation.zoneNr))){ 
                    click(div);
                }
            }else if(div=$("speedlink_foodworld")){
                document.addEventListener("gameFoodworldOpened",function(zoneNrF){
                return function(){
                    document.removeEventListener("gameFoodworldOpened",arguments.callee,false);
                    window.setTimeout(goToZone,100,zoneNrF);
                }
                }(zoneNrF),false);
                click(div); 
            }
        break;}
        case "farmersmarket":{
            if(gameLocation[0]==currLocation.location){
                if((currLocation.zoneNr!=undefined)&&(div=$("farmersmarket_pos"+currLocation.zoneNr+"_click"))){ 
                    click(div);
                }
            }else if(div=$("speedlink_farmersmarket")){
                document.addEventListener("gameFarmersmarketOpened",function(zoneNrF){
                return function(){
                    document.removeEventListener("gameFarmersmarketOpened",arguments.callee,false);
                    window.setTimeout(goToZone,100,zoneNrF);
                }
                }(zoneNrF),false);
                click(div); 
            }           
        break;}
        }
        div=null;
    }catch(err){GM_logError("goToZone zoneNrF="+zoneNrF+"\n"+err);}
}
function calcAllSlots(){
try{
    ALL_SLOTS={};
    for(var i in ALL_ZONES){
        if(!ALL_ZONES.hasOwnProperty(i)){ continue; }
        for(var j=0;j<ALL_ZONES[i].length;j++){
            if(zones.isMultiSlot(ALL_ZONES[i][j])){
                for(var slot=1;slot<=3;slot++){
                    ALL_SLOTS[ALL_ZONES[i][j]+"."+slot]=i;
                }
            }else{
                ALL_SLOTS[ALL_ZONES[i][j]]=i;
            }
        }
    }
    unsafeData.ALL_SLOTS=ALL_SLOTS.clone();
}catch(err){ GM_logError("calcAllSlots\n"+err); }
}
function toolTipZoneProduction(zoneNrS){
    try{
        var currLocation=zones.getLocation(zoneNrS);
        var content=createElement("div");
        var time,endDay,table,tr,td;
        var help;
        table=createElement("table",{"border":"0","cellspacing":"0","cellpadding":"0"},content);
        // part: head
        tr=createElement("tr",{},table);
        td=createElement("th",{"class":"lightBg","colspan":2},tr);
        if(currLocation.location=="farm"){
            td.innerHTML=getText("farm")+" "+(1+currLocation.farmNr)+"."+currLocation.zoneNr+" ("+zones.getBuildingName(zoneNrS)+")";
        }else{
            td.innerHTML=zones.getBuildingName(zoneNrS);
        }
        // part: time
        time=zones.getEndtime(zoneNrS);
        tr=createElement("tr",{},table);
        if(time==NEVER){
            createElement("td",{"colspan":2},tr,getText("idle"));
        }else{
            time+=unsafeWindow.Zeit.Verschiebung;
            if (time<now){
                if(time+20*60*60<now){
                    createElement("td",{"colspan":2},tr,getText("readySinceX").replace(/%1%/,getFormattedDateStr(time)));
                }else{
                    createElement("td",{"colspan":2},tr,getText("readySinceX").replace(/%1%/,getDaytimeStr(time)+"&nbsp;"+getText("shortOClock")));
                }               
            } else if ((endDay=countDays(now,time))==0){
                createElement("td",{"colspan":2},tr,getText("readyAtX").replace(/%1%/,getDaytimeStr(time)+"&nbsp;"+getText("shortOClock")));
            } else if (getText("readyAtX_day"+endDay)){
                createElement("td",{"colspan":2},tr,getText("readyAtX_day"+endDay).replace(/%1%/,getDaytimeStr(time)+"&nbsp;"+getText("shortOClock")));
            } else{ 
                createElement("td",{"colspan":2},tr,getText("readyAtX").replace(/%1%/,new Date(1000*time).toLocaleString())); 
            }
        }
        // part: production
        tr=createElement("tr",{"style":"border-top:1px solid black;"},table);
        createElement("td",{"style":"border-top:1px solid black;","colspan":2},tr,getText("yield")+":");
        if(help=zones.getCrop(zoneNrS)){
            if(help.length==0){
                tr=createElement("tr",{},table);
                td=createElement("td",{"colspan":2},tr,"---");
            }else{
                for(var k=0;k<help.length;k++){
                    tr=createElement("tr",{},table);
                    td=createElement("td",{},tr);
                    produktPic(help[k][0],help[k][1],td);
                    createElement("span",{},td,numberFormat(help[k][2])+"&nbsp;"+prodName[help[k][0]][help[k][1]]);
                    td=createElement("td",{"style":"padding-left:5px;"},tr);
                    if(help[k][3]>0){ pointsFormat(help[k][3],"div",td); }
                }
            }
        }else{
            tr=createElement("tr",{},table);
            td=createElement("td",{"colspan":2},tr,"???");
        }
        table=null;tr=null;td=null;time=null;endDay=null;
        return content.innerHTML;
    }catch(err){GM_logError("toolTipZoneProduction\n"+err);}    
}
function toolTipSales(nr){
    try{
        var content=createElement("div");
        var table,tr,td;
        var time;
        if(logSales[nr]){
            time=logSales[nr][1]-valServerTimeOffset;
            table=createElement("table",{"border":"0","cellspacing":"0","cellpadding":"0"},content);
            if(typeof logSales[nr][3][0]=="object"){
                // contract
                tr=createElement("tr",{},table);
                createElement("th",{"class":"lightBg","colspan":3},tr,getText("contract"));
                tr=createElement("tr",{},table);
                createElement("td",{"colspan":3},tr,getFormattedDateStr(time,1)+",&nbsp;"+getDaytimeStr(time,1)+"&nbsp;"+getText("shortOClock"));
                tr=createElement("tr",{},table);
                createElement("td",{"colspan":3},tr,logSales[nr][2]);
                tr=createElement("tr",{"class":"borderBottom1Black"},table);
                createElement("td",{"colspan":3},tr,moneyFormat(logSales[nr][4]));              
                for(var v=0;v<logSales[nr][3].length;v++){
                    tr=createElement("tr",{},table);
                    createElement("td",{},table,numberFormat(logSales[nr][3][v][1]));
                    createElement("td",{},table,prodName[0][logSales[nr][3][v][0]]);
                    td=createElement("td",{},table);
                    if(logSales[nr][3].length==1){
                        td.innerHTML="("+moneyFormat(logSales[nr][4]/logSales[nr][3][v][1])+")"
                    }
                }
            }else{
                // marketplace
                tr=createElement("tr",{},table);
                createElement("th",{"class":"lightBg","colspan":3},tr,getText("marketplace"));
                tr=createElement("tr",{},table);
                createElement("td",{"colspan":3},tr,getFormattedDateStr(time,1)+",&nbsp;"+getDaytimeStr(time,1)+"&nbsp;"+getText("shortOClock"));
                tr=createElement("tr",{},table);
                createElement("td",{"colspan":3},tr,logSales[nr][2]);
                tr=createElement("tr",{"class":"borderBottom1Black"},table);
                createElement("td",{"colspan":3},tr,moneyFormat(logSales[nr][4]));              
                tr=createElement("tr",{},table);
                createElement("td",{},table,numberFormat(logSales[nr][3][1]));
                createElement("td",{},table,prodName[0][logSales[nr][3][0]]);
                createElement("td",{},table,"("+moneyFormat(logSales[nr][4]/logSales[nr][3][1])+")");
            }
        }

        table=null;tr=null;td=null;
        return content.innerHTML;
    }catch(err){GM_logError("toolTipSales\n"+err);} 
}

function showMarket(pid){
    try{
        if((gameLocation[0]!="city")||(gameLocation[1]!=1)){
            document.addEventListener("gameCity1",function(pid){ return function(){
                document.removeEventListener("gameCity1",arguments.callee,false);
                showMarket(pid);
            };}(pid),false);
            click($("speedlink_city1"));
        }else if($("market").style.display!="block"){
            document.addEventListener("gameOpenMarket",function(pid){ return function(){
                document.removeEventListener("gameOpenMarket",arguments.callee,false);
                showMarket(pid);
            };}(pid),false);
            unsafeWindow.close_page(); 
            unsafeWindow.hideDiv("shop");               
            unsafeWindow.hideDiv("wbwcontainer");               
            unsafeWindow.hideDiv("adcolumn");               
            $("transp3").style.visibility = "visible"; 
            unsafeWindow.showDiv("transp3"); 
            unsafeWindow.marketAction("marketinit");
        }else{
            closeInfoPanel();
            unsafeWindow.market_filter_name="";
            unsafeWindow.market_filter_pid=parseInt(pid,10);
            unsafeWindow.market_filter_own=0;
            unsafeWindow.market_guild_filter=0;
            unsafeWindow.showOffers();          
        }
    }catch(err){ GM_logError("showMarket pid="+pid+"\n"+err); }
}
function showMarketStall(){
    try{
        if((gameLocation[0]!="city")||(gameLocation[1]!=1)){
            document.addEventListener("gameCity1",function(){
                document.removeEventListener("gameCity1",arguments.callee,false);
                showMarketStall();
            },false);
            click($("speedlink_city1"));
        }else if($("market").style.display!="block"){
            document.addEventListener("gameOpenMarket",function(){
                document.removeEventListener("gameOpenMarket",arguments.callee,false);
                showMarketStall();
            },false);
            unsafeWindow.close_page(); 
            unsafeWindow.showDiv("transp3"); 
            unsafeWindow.$("transp3").style.visibility = "visible"; 
            unsafeWindow.marketAction("marketinit");
        }else{
            unsafeWindow.setMarketNavi(3);
            unsafeWindow.market_guild_filter = 0;
            unsafeWindow.market_filter_pid = -1;
            unsafeWindow.market_filter_own = 1;
            unsafeWindow.showOffers();              
        }
    }catch(err){ GM_logError("showMarketStall\n"+err); }
}
function quicklinks(){
    try{
        if (GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valQuicklinks",true)){
            var newdiv=$("market_navi5");
            if(newdiv){
                newdiv.addEventListener("mouseover",function(event){
                    $("quicklinks").style.display="block";
                },false);
                newdiv.addEventListener("mouseout",function(event){
                    $("quicklinks").style.display="none";
                },false);
        
                var highlightProducts=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_highlightProducts","[false,{}]"),"quicklinks/highlightProducts",[false,{}]);
                var divquick=createElement("div",{"id":"quicklinks","style":"display:none;position:absolute;right:-75px;top:67px;width:600px;background-color:white;z-index:10;"},newdiv);
                // if(self!=top){
                //  divquick.addEventListener("mouseover",function(){this.style.left="290px";},false);
                //  divquick.addEventListener("mouseout",function(){this.style.left="620px";},false);
                // }
    
                var newtable=createElement("table",{"border":"3px solid black;"},divquick);
                var newtr=createElement("tr",{},newtable);
                var newtd=createElement("td",{},newtr);
    
                // newdiv=createElement("div",{"style":"float:right;height:30px;padding:2px;margin-right:20px;"},newtd);
                // createElement("div",{"class":"v88"},newdiv);
                // var newa=createElement("a",{"class":"link2","href":"markt.php","style":"position:relative;top:-30px;"},newdiv);
                // newdiv=createElement("div",{"style":"width:30px;height:30px;background-color:green;opacity:0;"},newa);
                // newdiv.addEventListener("mouseover",function(){this.style.opacity="0.3";$("quicklinksName").innerHTML=getText("currentOffers");},false);
                // newdiv.addEventListener("mouseout",function(){this.style.opacity="0";$("quicklinksName").innerHTML="";},false);
                createElement("div",{"id":"quicklinksName","style":"color:black;font-weight:bold;float:right;line-height:30px;padding:2px;margin-right:170px;"},newtd);
    
                var prodTypOld="c";
                for(var w=0;w<prodNameSort[0].length;w++){
                    var v=prodNameSort[0][w];
                    if((!prodBlock[0][v].match(/t/))&&(!prodBlock[0][v].match(/l/))){
                        if (prodTypOld!=prodTyp[0][v]){
                            newtr=createElement("tr",{},newtable);
                            newtd=createElement("td",{},newtr);
                            prodTypOld=prodTyp[0][v];
                        }
                        newdiv=createElement("div",{"style":"float:left;height:30px;"+(highlightProducts[1][v]?"border:2px solid blue;border-radius:10px;":"padding:2px;")},newtd);
                        createElement("div",{"class":"v"+v},newdiv);
                        newdiv=createElement("div",{"v":v,"style":"position:relative;top:-30px;width:30px;height:30px;background-color:blue;opacity:0;"},newdiv);
                        newdiv.addEventListener("click",function(event){
                            event.stopPropagation ? event.stopPropagation() : (event.cancelBubble=true); // stop bubbling
                            showMarket(this.getAttribute("v"));
                            $("quicklinks").style.display="none";
                        },false);
                        newdiv.addEventListener("mouseover",function(){this.style.opacity="0.3";$("quicklinksName").innerHTML=prodName[0][this.getAttribute("v")];},false);
                        newdiv.addEventListener("mouseout",function(){this.style.opacity="0";$("quicklinksName").innerHTML="";},false);
                    }
                }
                divquick=null;newtable=null;newtr=null;newtd=null;newa=null;
            }
            newdiv=null;
        }
    }catch(err){ GM_logError("quicklinks\n"+err); }             
}
var timer=new function(){
    var running=[];
    this.add=function(name,node,endtime,callback){
        try{
            timer.remove(name);
            running.push([name,node,endtime,callback]);
            timer.run(name);
        }catch(err){GM_logError("timer.add name="+name+"\n"+err);}
    }
    this.remove=function(name){
        try{
            for(var i=running.length-1;i>=0;i--){
                if(running[i][0]==name){
                    running.splice(i,1);
                }
            }
        }catch(err){GM_logError("timer.remove\n"+err);}
    }
    this.run=function(){
        try{
            for(var i=running.length-1;i>=0;i--){
                if(unsafeWindow.Zeit.Server<running[i][2]){
                    running[i][1].innerHTML=getTimeStr(running[i][2]-unsafeWindow.Zeit.Server);
                }else{
                    running[i][3]();
                    running.splice(i,1);
                }
            }
        }catch(err){GM_logError("timer.run\n"+err);}
    }
}
var clocks=new function(){
    var running=[];
    this.add=function(name,node,time){
        try{
            clocks.remove(name);
            running.push([name,node,time]);
            clocks.run(name);
        }catch(err){GM_logError("clocks.add name="+name+"\n"+err);}
    }
    this.remove=function(name){
        try{
            for(var i=running.length-1;i>=0;i--){
                if(running[i][0]==name){
                    running.splice(i,1);
                }
            }
        }catch(err){GM_logError("clocks.remove\n"+err);}
    }
    this.run=function(){
        try{
            for(var i=running.length-1;i>=0;i--){
                if(running[i][1]){
                    running[i][1].innerHTML=getDaytimeStr(running[i][2]+now);
                }else{
                    running.splice(i,1);
                }
            }
        }catch(err){GM_logError("clocks.run\n"+err);}
    }
}
function createZoneTimer(name,zoneNrS,type,style,append){ // type="zonetimer" || "zonetimerWater"
    try{
        if(!$(name)){
            var div=createElement("div",{"id":name,"zoneNrS":zoneNrS,"type":type,"style":style},append);
            div.addEventListener("mouseover",function(event){
            try{
                var zoneNrS=this.getAttribute("zoneNrS");
                var type=this.getAttribute("type");
                showBlase(zoneNrS);
                if(type=="zonetimer"){
                    toolTip.show(event,toolTipZoneProduction(zoneNrS));
                }else{ // zonetimerWater
                    var newDiv1=createElement("div");
                    var newTable=createElement("table",{"border":"0","cellspacing":"0","cellpadding":"0"},newDiv1);
                    var newTr=createElement("tr",{},newTable);
                    var newTd=createElement("th",{"class":"lightBg","colspan":2},newTr,zones.getBuildingName(zoneNrS));
                    var time = zones.getWatertime(zoneNrS);
                    if(time!=NEVER){ time+=unsafeWindow.Zeit.Verschiebung; }
                    var endDay=countDays(now,time);
                    newTr=createElement("tr",{},newTable);
                    if(time==NEVER){
                        createElement("td",{"colspan":2},newTr,"---");
                    } else if(time<now){
                        createElement("td",{"colspan":2},newTr,getText("waterNeeded"));
                    } else if (endDay==0){
                        createElement("td",{},newTr,getText("waterNeededAtX").replace(/%1%/,getDaytimeStr(time)+"&nbsp;"+getText("shortOClock")));
                    } else if ((endDay==1)&&(getText("waterNeededAtX_day1"))){
                        createElement("td",{},newTr,getText("waterNeededAtX_day1").replace(/%1%/,getDaytimeStr(time)+"&nbsp;"+getText("shortOClock")));
                    } else{ 
                        createElement("td",{},newTr,getText("waterNeededAtX").replace(/%1%/,new Date(1000*time).toLocaleString())); 
                    }
                    toolTip.show(event,newDiv1.innerHTML);
                    newDiv1=null;newTable=null;newTr=null;newTd=null;
                    time=null;endDay=null;
                }
                zoneNrS=null;type=null;
            }catch(err){GM_logError("createTimer.mouseover\n"+err);}            
            },false);
            div.addEventListener("mouseout",hideBlase,false);
            div=null;
        }
        updateZoneTimer(name,zoneNrS,type)
    }catch(err){GM_logError("createZoneTimer\nname="+name+"\n"+err);}
}
function updateZoneTimer(name,zoneNrS,type){
    try{
        var div;
        if(div=$(name)){
            if(zones.getBlock(zoneNrS)){
                removeZoneTimer(name,type);
            }else if(type=="zonetimer"){
                var time=zones.getEndtime(zoneNrS);
                if (time==NEVER){ // empty
                    div.setAttribute("class","zoneTimer");
                    timer.remove(name);
                    div.innerHTML="---";
                }else if(time<=unsafeWindow.Zeit.Server){ // ready
                    div.setAttribute("class","zoneTimerReady blinking");
                    timer.remove(name);
                    div.innerHTML=getText("finished").toUpperCase()+"!";
                }else{ // running
                    div.setAttribute("class","zoneTimer");
                    timer.add(name,div,time,function(name,zoneNrS,type){ return function(){ updateZoneTimer(name,zoneNrS,type); }}(name,zoneNrS,type));
                }
            }else{
                var time=zones.getWatertime(zoneNrS);
                if ((time==NEVER)||(time<=unsafeWindow.Zeit.Server)){ // watering not possible or needed
                    removeZoneTimer(name,type);
                }else{ // wait for watering
                    div.setAttribute("class","zoneTimerWater");
                    timer.add(name,div,time,function(name,zoneNrS,type){ return function(){ updateZoneTimer(name,zoneNrS,type); }}(name,zoneNrS,type));
                }
            }
            div=null;
        }
    }catch(err){GM_logError("updateZoneTimer name:"+name+" zoneNrS:"+zoneNrS+"\n"+err);}
}
function removeZoneTimer(name){
    try{
        timer.remove(name);
        var div;
        if(div=$(name)){
            removeElement(div);
            div=null;
        }
    }catch(err){GM_logError("removeZoneTimer name:"+name+"\n"+err);}
}   
function showBlase(zoneNrF){
    try{
        $("sprcontent").style.display="none";
        var bubble=$("sprcontent2");
        bubble.style.display="";
        bubble.innerHTML="";
        if (zones.getBlock(zoneNrF).match(/p/)){
            createElement("div",{"class":"tnormal"},bubble,unsafeWindow.inforequirepremium);
        }else if (zones.getBlock(zoneNrF).match(/q/)){
            createElement("div",{"class":"tnormal"},bubble,unsafeWindow.questblock);
        }else if(!zones.getBuilding(zoneNrF)){
            // blocked
        }else if(BUILDINGTYPE[zones.getBuilding(zoneNrF)]==0){
            createElement("div",{"class":"tnormal","style":"font-weight:bold;"},bubble,unsafeWindow.buildinginfos[0][zones.getBuilding(zoneNrF)][10]);
        }else{
            var time=zones.getEndtime(zoneNrF);
            if(time==NEVER){
                createElement("font",{"class":"tmenu","style":"font-weight:bold;"},bubble,zones.getBuildingName(zoneNrF)+" "+getText("idle"));
                // createElement("font",{"class":"tnormal","style":"font-weight:bold;"},bubble,getText("emptyField"));
            }else{
                time+=unsafeWindow.Zeit.Verschiebung;
                var prod = zones.getEndproduct(zoneNrF);
                if(prod!=null){
                    switch(zones.getLocation(zoneNrF).location){
                    case "windmill":
                        createElement("div",{"class":"fm"+prod,"style":"position:absolute;top:5px;left:0;"},bubble);
                        newdiv=createElement("div",{"style":"position:absolute;top:5px;left:55px;"},bubble);
                        createElement("font",{"class":"tmenu","style":"font-weight:bold;"},createElement("div",{},newdiv),prodName[3][prod]); // unsafeWindow.formulas[0][prod][2]
                    break;
                    case "forestry":
                        createElement("div",{"class":"f_symbol"+prod,"style":"position:absolute;top:5px;left:0;"},bubble);
                        newdiv=createElement("div",{"style":"position:absolute;top:5px;left:55px;"},bubble);
                        createElement("font",{"class":"tmenu","style":"font-weight:bold;"},createElement("div",{},newdiv),prodName[1][prod]);
                    break;
                    default:
                        createElement("div",{"class":"tt"+prod,"style":"position:absolute;top:5px;left:0;"},bubble);
                        newdiv=createElement("div",{"style":"position:absolute;top:5px;left:55px;"},bubble);
                        createElement("font",{"class":"tmenu","style":"font-weight:bold;"},createElement("div",{},newdiv),prodName[0][prod]);
                    }
                }

                var newfont=createElement("font",{"class":"tmenu"},createElement("div",{},newdiv));
                if (time<now){
                    if(time+20*60*60<now){
                        newfont.innerHTML=getText("readySinceX").replace(/%1%/,getFormattedDateStr(time));
                    }else{
                        newfont.innerHTML=getText("readySinceX").replace(/%1%/,getDaytimeStr(time)+"&nbsp;"+getText("shortOClock"));
                    }
                }else if (time<NEVER){
                    var endDay=countDays(now,time);
                    if (endDay==0){
                        newfont.innerHTML=getText("readyAtX").replace(/%1%/,getDaytimeStr(time)+"&nbsp;"+getText("shortOClock"));
                    }else if ((endDay==1)&&(getText("readyAtX_day1"))){
                        newfont.innerHTML=getText("readyAtX_day1").replace(/%1%/,getDaytimeStr(time)+"&nbsp;"+getText("shortOClock"));
                    }else if ((endDay==2)&&(getText("readyAtX_day2"))){
                        newfont.innerHTML=getText("readyAtX_day2").replace(/%1%/,getDaytimeStr(time)+"&nbsp;"+getText("shortOClock"));
                    }else{
                        newfont.innerHTML=new Date(1000*time).toLocaleString();
                    }
                }
                newfont=null;
            }
        }
        bubble=null;newdiv=null;
    }catch(err){ GM_logError("showBlase zoneNrF="+zoneNrF+"\n"+err); }
}
function hideBlase(){
    try{
        $("sprcontent").style.display="";
        $("sprcontent2").style.display="none";
    }catch(err){ GM_logError("hideBlase\n"+err); }
}

var modeBuyNotepad=GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_modeBuyNotepad",0);
function doBuyNotepad(){
try{
    var err_trace="init";
    if(!show["buyNotepad"]){ return false; } // no calculation if table is hidden
    var newdiv=$("buyNotepad");
    if(newdiv){
    /* rack type 0 (farm) */
        err_trace="type 0";
        var prodMissing=new Array();
        var drawProductLines=false;
        // calculate missing products
        err_trace="type 0, missing products";
        for(var v=0;v<prodNameSort[0].length;v++){
            var prod=prodNameSort[0][v];
            if((!prodBlock[0][prod].match(/t/))&&(!prodBlock[0][prod].match(/l/))){
                var amount=prodMinRack[0][prod]-prodStock[0][prod];
                if (amount>0){
                    prodMissing.push([prod,amount,amount*(gut[prod]?gut[prod]:0)]);
                }
            }
        }
        // sorting
        err_trace="type 0, sorting";
        switch(modeBuyNotepad){
        case 0: drawProductLines=true; 
        prodMissing.sort(sortObjFunctions["productId"]);
        break;
        case 1: drawProductLines=true;
        prodMissing.sort(function(a,b){
            if(prodTyp[0][a[0]]==prodTyp[0][b[0]]){
                return(b[1][0]-a[1][0]);
            }else{
                return({"c":0,"v":1,"e":2,"o":3,"fw1":4,"fw2":5,"fw3":6,"fw4":7,"z":8}[prodTyp[0][a[0]]]-{"c":0,"v":1,"e":2,"o":3,"fw1":4,"fw2":5,"fw3":6,"fw4":7,"z":8}[prodTyp[0][b[0]]]);
            }
        }); break;
        case 2: drawProductLines=true;
        prodMissing.sort(function(a,b){
            if(prodTyp[0][a[0]]==prodTyp[0][b[0]]){
                return(a[1][0]-b[1][0]);
            }else{
                return({"c":0,"v":1,"e":2,"o":3,"fw1":4,"fw2":5,"fw3":6,"fw4":7,"z":8}[prodTyp[0][a[0]]]-{"c":0,"v":1,"e":2,"o":3,"fw1":4,"fw2":5,"fw3":6,"fw4":7,"z":8}[prodTyp[0][b[0]]]);
            }
        }); break;
        case 3: prodMissing.sort(function(a,b){return (a[1][0]-b[1][0]);}); break;
        case 4: prodMissing.sort(function(a,b){return (a[1][0]-b[1][0]);},true); break;
        case 5: prodMissing.sort(function(a,b){return (a[1][1]-b[1][1]);}); break;
        case 6: prodMissing.sort(function(a,b){return (a[1][1]-b[1][1]);},true); break;
        case 7: prodMissing.sort(function(a,b){return (a[0]-b[0]);},true); break;
        }
        // creating table
        err_trace="type 0, table";
        newdiv.innerHTML="";
        var newtable=createElement("table",{"border":"0","cellspacing":"0","cellpadding":"0"},newdiv);
        var newtr=createElement("tr",{"class":"link"},newtable);
        newtr.addEventListener("click",function(){
            modeBuyNotepad=(modeBuyNotepad+1)%7;
            GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_modeBuyNotepad",modeBuyNotepad);
            doBuyNotepad();
        },false);
        newtr.addEventListener("mouseover",function(event){toolTip.show(event,"Sortingmode: "+["Producttype, id","Producttype, amount","Producttype, amount descending","amount","amount descending","value","value descending","id"][modeBuyNotepad]+"<br>Click to change");},false);
        var newtd=createElement("td",{"colspan":"4","style":"border-bottom:1px solid black;text-align:center;"},newtr,getText("missing"));

        var oldType=null;
        var newType=null;
        var help=0; //TODO review
        for(var i=0;i<prodMissing.length;i++){
            var prod=prodMissing[i][0];
            var amountForFarmis=valMinRackFarmis?((totalFarmis[0]&&totalFarmis[0][prod]?totalFarmis[0][prod]:0)-(prodStock[0]&&prodStock[0][prod]?prodStock[0][prod]:0)):0;
            var str='<table>';
            str += '<tr><th colspan="3" class="lightBg">'+getText("goToMarketOfX").replace(/%1%/,prodName[0][prod])+'</th></tr>';
            str += '<tr><td>'+getText("minRack")+'</td><td></td><td style="text-align:right;">'+numberFormat(prodMinRackInit[0][prod])+'</td></tr>';
            for(var k in totalQuest){
                if(!totalQuest.hasOwnProperty(k)){ continue; }
                if(totalQuest[k][0][prod]){
                    str += '<tr><td>'+getText("quest_"+k)+'</td><td>+</td><td style="text-align:right;">'+numberFormat(totalQuest[k][0][prod])+'</td></tr>'; 
                }
            }
            if(valMinRackRecursive&&totalRecursive[0]&&totalRecursive[0][prod]){ 
                str += '<tr><td>'+getText("recursive")+'</td><td>+</td><td style="text-align:right;">'+numberFormat(totalRecursive[0][prod])+'</td></tr>'; 
            }
            if(valMinRackFarmis&&totalFarmis[0]&&totalFarmis[0][prod]){ str += '<tr><td>'+unsafeWindow.customerarecalled.replace(/%FARMI%/,"")+'</td><td>+</td><td style="text-align:right;">'+numberFormat(totalFarmis[0][prod])+'</td></tr>'; }
            str += '<tr><td>'+getText("inventory")+'</td><td>-</td><td style="text-align:right;">'+numberFormat(prodStock[0][prod])+'</td></tr>';
            if(valMinRackGrowing){
                if(totalErnte[0][prod]){
                    amountForFarmis -= totalErnte[0][prod];
                    str += '<tr><td>'+getText("production")+'</td><td>-</td><td style="text-align:right;">'+numberFormat(totalErnte[0][prod])+'</td></tr>';
                }
                if(totalPowerups[prod]){
                    amountForFarmis -= totalPowerups[prod];
                    str += '<tr><td>'+getText("powerups")+'</td><td>-</td><td style="text-align:right;">'+numberFormat(totalPowerups[prod])+'</td></tr>';
                }
            }
            if(prodMinRackAddon[0][prod]){
                for(var k in prodMinRackAddon[0][prod]){
                    if(!prodMinRackAddon[0][prod].hasOwnProperty(k)){ continue; }
                    str += '<tr><td>'+k+'</td><td>'+(prodMinRackAddon[0][prod][k]>0?'+':'-')+'</td><td style="text-align:right;">'+numberFormat(prodMinRackAddon[0][prod][k])+'</td></tr>';
                }
            }
            str += '<tr><td colspan="3" style="border-bottom:1px solid black;"></td></tr>';
            str += '<tr><td>'+getText("marketPrice")+'</td><td></td><td style="text-align:right;">'+moneyFormat(gut[prod])+'</td></tr>';
            str += '<tr><td>'+getText("value")+'</td><td></td><td style="text-align:right;">'+moneyFormatInt(prodMissing[i][2])+'</td></tr>';
            if(prodRequire[0][prod]){
                str += '<tr><th colspan="3" class="lightBg">'+getText("requirementPerProduction")+'</th></tr>';
                for(j in prodRequire[0][prod]){
                    if(!prodRequire[0][prod].hasOwnProperty(j)){continue;}
                    if(prodRequire[0][prod][j][0]>-1){
                        str += '<tr><td>';
                        str += prodName[prodRequire[0][prod][j][0]][prodRequire[0][prod][j][1]];
                        str += '</td><td></td><td style="text-align:right;">'+numberFormat(prodRequire[0][prod][j][2])+'</td></tr>';
                    }
                }
                if(prodYield[0][prod]){
                    str += '<tr><th colspan="3" class="lightBg">'+getText("yieldPerProduction")+'</th></tr>';
                    str += '<tr><td>'+prodName[0][prod]+'</td><td></td><td style="text-align:right;">'+numberFormat(prodYield[0][prod])+'</td></tr>';
                }
            }
            str += '</table>';
            newType=prodTyp[0][prod];
            newtr=createElement("tr",{"class":"link hoverBgCc9"+((drawProductLines&&(oldType!=null)&&(oldType!=newType))?" borderTop1dashedBlack":""),"prod":prod,"mouseOverText":str},newtable);
            oldType=newType;
            newtr.addEventListener("click",function(){showMarket(this.getAttribute("prod"));},false);
            newtr.addEventListener("mouseover",function(event){toolTip.show(event,this.getAttribute("mouseOverText"));},false);
            newtd=createElement("td",{},newtr);
            produktPic(0,prod,newtd);
            createElement("td",{"style":"text-align:right;"},newtr,numberFormat(prodMissing[i][1]));
            if(amountForFarmis>0){
                createElement("td",{"style":"padding-left:3px;text-align:right;"},newtr,"("+numberFormat(amountForFarmis)+")");
            }else{
                createElement("td",{},newtr);
            }
            createElement("td",{"style":"padding-left:3px;"},newtr,prodName[0][prod]);
        }
        help=null;
        
        if(newtable.childElementCount==1){
            newtr=createElement("tr",{},newtable);
            createElement("td",{"colspan":"3","style":"text-align:center;"},newtr,"---");
        }

    /* rack type 1 (forestry) */
        err_trace="type 1";
        var newtr=createElement("tr",{},newtable);
        var newtd=createElement("td",{"colspan":"4","style":"border-bottom:1px solid black;text-align:center;width:100%;"},newtr);
        drawProductLines=false;
        prodMissing=new Array();
        // calculate missing products
        err_trace="type 1, missing products";
        for(var prod in prodMinRack[1]){
            if(!prodMinRack[1].hasOwnProperty(prod)){ continue; }
            var amount=prodMinRack[1][prod]-(prodStock[1][prod]?prodStock[1][prod]:0);
            if (amount>0){
                prodMissing.push([prod,amount,0]); //'0'==price
            }
        }
        // sorting
        err_trace="type 1, sorting";
        switch(modeBuyNotepad){
        case 0: drawProductLines=true;
        prodMissing.sort(function(a,b){
            if(prodTyp[1][a[0]]==prodTyp[1][b[0]]){
                return(a[0]-b[0]);
            }else{
                return({"c":0,"v":1,"e":2,"o":3,"fw1":4,"fw2":5,"fw3":6,"fw4":7,"z":8}[prodTyp[1][a[0]]]-{"c":0,"v":1,"e":2,"o":3,"fw1":4,"fw2":5,"fw3":6,"fw4":7,"z":8}[prodTyp[1][b[0]]]);
            }
        }); break;
        case 1: drawProductLines=true;
        prodMissing.sort(function(a,b){
            if(prodTyp[1][a[0]]==prodTyp[1][b[0]]){
                return(b[1][0]-a[1][0]);
            }else{
                return({"f1":0,"f2":1,"f3":2,"f4":3,"f5":4}[prodTyp[1][a[0]]]-{"f1":0,"f2":1,"f3":2,"f4":3,"f5":4}[prodTyp[1][b[0]]]);
            }
        }); break;
        case 2: drawProductLines=true;
        prodMissing.sort(function(a,b){
            if(prodTyp[1][a[0]]==prodTyp[1][b[0]]){
                return(a[1][0]-b[1][0]);
            }else{
                return({"f1":0,"f2":1,"f3":2,"f4":3,"f5":4}[prodTyp[1][a[0]]]-{"f1":0,"f2":1,"f3":2,"f4":3,"f5":4}[prodTyp[1][b[0]]]);
            }
        }); break;
        case 3: prodMissing.sort(function(a,b){return (a[1][0]-b[1][0]);}); break;
        case 4: prodMissing.sort(function(a,b){return (a[1][0]-b[1][0]);},true); break;
        case 5: prodMissing.sort(function(a,b){return (a[1][1]-b[1][1]);}); break;
        case 6: prodMissing.sort(function(a,b){return (a[1][1]-b[1][1]);},true); break;
        case 7: prodMissing.sort(function(a,b){return (a[0]-b[0]);},true); break;
        }
        //prodMissing.sortObj();
        err_trace="type 1, table";
        oldType=null;
        newType=null;
        for(var i=0;i<prodMissing.length;i++){
            var prod=prodMissing[i][0];
            var amountForForestryFarmis=valMinRackForestryFarmis?((totalFarmis[1]&&totalFarmis[1][prod]?totalFarmis[1][prod]:0)-(prodStock[1]&&prodStock[1][prod]?prodStock[1][prod]:0)):0;

            var str='<table>';
            str += '<tr><th colspan="3" class="lightBg">'+prodName[1][prod]+'</th></tr>';
            str += '<tr><td>'+getText("minRack")+'</td><td></td><td style="text-align:right;">'+numberFormat(prodMinRackInit[1][prod])+'</td></tr>';
            if(totalQuest["main"]&&totalQuest["main"][1][prod]){ 
                str += '<tr><td>'+getText("quest_farm")+'</td><td>+</td><td style="text-align:right;">'+numberFormat(totalQuest["main"][1][prod])+'</td></tr>'; 
            }
            if(totalQuest["forestry"]&&totalQuest["forestry"][1][prod]){
                str += '<tr><td>'+getText("quest_forestry")+'</td><td>+</td><td style="text-align:right;">'+numberFormat(totalQuest["forestry"][1][prod])+'</td></tr>';
            }
            if(valMinRackRecursive&&totalRecursive[1]&&totalRecursive[1][prod]){ str += '<tr><td>'+getText("recursive")+'</td><td>+</td><td style="text-align:right;">'+numberFormat(totalRecursive[1][prod])+'</td></tr>'; }
            if(valMinRackForestryFarmis&&totalFarmis[1]&&totalFarmis[1][prod]){ str += '<tr><td>'+unsafeWindow.customerarecalled.replace(/%FARMI%/,"")+'</td><td>+</td><td style="text-align:right;">'+numberFormat(totalFarmis[1][prod])+'</td></tr>'; }
            str += '<tr><td>'+getText("inventory")+'</td><td>-</td><td style="text-align:right;">'+numberFormat(prodStock[1][prod])+'</td></tr>';

            if(valMinRackGrowing){
                if(totalErnte[1][prod]){
                    amountForForestryFarmis -= totalErnte[1][prod];
                    str += '<tr><td>'+getText("production")+'</td><td>-</td><td style="text-align:right;">'+numberFormat(totalErnte[1][prod])+'</td></tr>';
                }
            }
            if(prodMinRackAddon[1][prod]){
                for(var k in prodMinRackAddon[1][prod]){
                    if(!prodMinRackAddon[1][prod].hasOwnProperty(k)){ continue; }
                    str += '<tr><td>'+k+'</td><td>'+(prodMinRackAddon[1][prod][k]>0?'+':'-')+'</td><td style="text-align:right;">'+numberFormat(prodMinRackAddon[1][prod][k])+'</td></tr>';
                }
            }
            if(prodRequire[1][prod]){
                str += '<tr><th colspan="3" class="lightBg">'+getText("requirementPerProduction")+'</th></tr>';
                for(j in prodRequire[1][prod]){
                    if(!prodRequire[1][prod].hasOwnProperty(j)){continue;}
                    if(prodRequire[1][prod][j][0]>-1){
                        str += '<tr><td>';
                        str += prodName[prodRequire[1][prod][j][0]][prodRequire[1][prod][j][1]];
                        str += '</td><td></td><td style="text-align:right;">'+numberFormat(prodRequire[1][prod][j][2])+'</td></tr>';
                    }
                }
            }
            if(prodYield[1][prod]){
                str += '<tr><th colspan="3" class="lightBg">'+getText("yieldPerProduction")+'</th></tr>';
                str += '<tr><td>'+prodName[1][prod]+'</td><td></td><td style="text-align:right;">'+numberFormat(prodYield[1][prod])+'</td></tr>';
            }
            str += '</table>';

            newType=prodTyp[1][prod];
            newtr=createElement("tr",{"class":"hoverBgCc9"+((drawProductLines&&(oldType!=null)&&(oldType!=newType))?" borderTop1dashedBlack":""),"iProd":prod,"mouseOverText":str,"style":(prodBlock[1][prod].match(/b/)?"color:red;":"")},newtable);//TODO color
            oldType=newType;
            newtr.addEventListener("mouseover",function(event){toolTip.show(event,this.getAttribute("mouseOverText"));},false);
            newtd=createElement("td",{},newtr);
            produktPic(1,prod,newtd);
            createElement("td",{"style":"text-align:right;"+(prodBlock[1][prod].match(/[lq]/)&&prodBlock[1][prod].match(/t/)?"color:red;":"")},newtr,numberFormat(prodMissing[i][1]));
            if(amountForForestryFarmis>0){
                createElement("td",{"style":"padding-left:3px;text-align:right;"+(prodBlock[1][prod].match(/[lq]/)&&prodBlock[1][prod].match(/t/)?"color:red;":"")},newtr,"("+numberFormat(amountForForestryFarmis)+")");
            }else{
                createElement("td",{},newtr);
            }
            createElement("td",{"style":"padding-left:3px;"+(prodBlock[1][prod].match(/[lq]/)&&prodBlock[1][prod].match(/t/)?"color:red;":"")},newtr,prodName[1][prod]);
        }

        if(newtable.childElementCount==2){
            newtr=createElement("tr",{},newtable);
            createElement("td",{"colspan":"4","style":"text-align:center;"},newtr,"---");
        }
        newtable=null;newtr=null;newtd=null;
    }
    newdiv=null;
}catch(err){ GM_logError("doBuyNotepad ("+err_trace+")\nprod="+prod+" \n"+err); }       
}
function doMarketoffersNotepad(){
    try{
        if(!show["marketoffersNotepad"]){ return false; } // no calculation if table is hidden
        var newdiv=$("marketoffersNotepad");
        if(newdiv){
            newdiv.innerHTML="";
            var newtable=createElement("table",{"border":"0","cellspacing":"0","cellpadding":"0"},newdiv);
            var newtr=createElement("tr",{"class":"link"},newtable);
            var newtd=createElement("td",{"colspan":"5","style":"border-bottom:1px solid black;text-align:center;"},newtr,getText("marketstall"));
            newtr.addEventListener("mouseover",function(event){
                var str='<table>';
                str += '<tr><th colspan="2" class="lightBg">'+getText("goToMarketstall")+'</th></tr>';
                str += '<tr><td>'+sign_sum+'</td><td style="text-align:right;">'+moneyFormatInt(parseInt(this.getAttribute("value"),10))+'</td></tr>';
                str += '</table>';
                toolTip.show(event,str);
            },false);
            newtr.addEventListener("click",function(){showMarketStall();},false);

            var sumTotal=0;
            var oldType=null;
            var newType=null;
            for(var i=0;i<ownMarketOffers.length;i++){
                var prod=ownMarketOffers[i][0];
                var price=ownMarketOffers[i][1];
                var amount=ownMarketOffers[i][2];
                newType=prodTyp[0][prod];
                sumTotal += amount*price;
                newtr=createElement("tr",{"class":"link hoverBgCc9"+(((oldType!=null)&&(oldType!=newType))?" borderTop1dashedBlack":""),"prod":prod,"value":(amount*price)},newtable);
                oldType=newType;
                newtr.addEventListener("mouseover",function(event){
                    showGoToMarketToolTip(event,this.getAttribute("prod"),null,'<tr><td>'+sign_sum+'</td><td style="text-align:right;">'+moneyFormatInt(parseInt(this.getAttribute("value"),10))+'</td></tr>');
                },false);
                newtr.addEventListener("click",function(){showMarket(this.getAttribute("prod"));},false);
                newtd=createElement("td",{},newtr);
                produktPic(0,prod,newtd);
                createElement("td",{"style":"text-align:right;"},newtr,numberFormat(amount));
                createElement("td",{"style":"padding-left:3px;"},newtr,prodName[0][prod]);
                createElement("td",{"style":"padding-left:3px;text-align:right;"},newtr,numberFormat(Math.floor(price)));
                createElement("td",{"style":""},newtr,numberFormat(price,2).slice(-3).replace("00","--"));
            }

            newtable.firstElementChild.setAttribute("value",sumTotal);
            if(newtable.childElementCount==1){
                newtr=createElement("tr",{},newtable);
                createElement("td",{"colspan":"5","style":"text-align:center;"},newtr,"---");
            }
            newtable=null;newtr=null;newtd=null;
        }
        newdiv=null;
    }catch(err){ GM_logError("doMarketoffersNotepad\nprod="+prod+"\n"+err); }
    }
function doRack(){
    try{
        var cand=$("rackItems").getElementsByClassName("tklein2");
        for(var v=0;v<cand.length;v++){
            var currProd=parseInt(cand[v].parentNode.id.replace("rackitem",""),10);
            var cell=$(cand[v].parentNode.id+"format");
            if(!cell){
                cell=cand[v].parentNode.parentNode;
                cell.setAttribute("class",(cell.getAttribute("class")+" link").replace(/(^|\s+)link\s+/g," ").replace(/^\s+/,""));
                cand[v].style.display="none";
                cell=createElement("div",{"id":"rackitem"+currProd+"format"},cand[v].parentNode);
            }
            var str=numberFormatPrefixed(prodStock[0][currProd]);
            if(cell.innerHTML!=str){ cell.innerHTML=str; }
            str=cand[v].getAttribute("class")+(prodStock[0][currProd]<prodMinRack[0][currProd]?" lowrack":""); // .replace("tklein2","formattedRackItem")
            if(cell.getAttribute("class")!=str){ cell.setAttribute("class",str); }
            cell=null;
        }
        cand=null;
    }catch(err){ GM_logError("doRack\nv="+v+"\n"+err); }
}
function doFarmis(){
    try{
    if(DEVMODE_FUNCTION){ var trackingHandle = tracking.start("berater","doFarmis"); }
        var err_trace="init";
        // GM_log("farmiLog=\n"+print_r(farmiLog,"",true,"\n"));
        // TODO: Questproduct is not calculated in at first run. Fixed now I believe
        // this can't go in the above loop because the amountMinRack are needed to be calculated first
        var missing,belowMinRack,belowMinRackInit;
        for(var farmiNr=0;farmiNr<$("customerline").childElementCount;farmiNr++){
            missing=0;belowMinRack=0;belowMinRackInit=false;
            for(var i=1;i<=7;i++){ // 7=max-amount of products per farmi
                var pid=unsafeWindow.farmisinfo[0][farmiNr]["p"+i];
                var amount=parseInt(unsafeWindow.farmisinfo[0][farmiNr]["a"+i],10);
                if((pid > 0) && (amount > 0)){
                    if(prodStock[0][pid]<amount){ missing++; }
                    if((prodStock[0][pid]-amount)<prodMinRack[0][pid]-((valMinRackFarmis&&totalFarmis[0]&&totalFarmis[0][pid])?totalFarmis[0][pid]:0)){ belowMinRack++; }
                    if((prodStock[0][pid]-amount)<prodMinRackInit[0][pid]){ belowMinRackInit++; }
                }
            }
            unsafeWindow.farmisinfo[0][farmiNr]["missing"]=missing;
            unsafeWindow.farmisinfo[0][farmiNr]["belowMinRack"]=belowMinRack;
            unsafeWindow.farmisinfo[0][farmiNr]["belowMinRackInit"]=belowMinRackInit;
        }
        missing=null;belowMinRack=null;belowMinRackInit=null;
        var cell,customerline,str;
        if(customerline=$("customerline")){
            err_trace="customerline";
            for(var farmiNr=0;farmiNr<customerline.childElementCount;farmiNr++){
                if (!$("farmiInfo"+farmiNr)){ // assure that this code is run only once per farmi. else eventlisteners are stacked
                    // prepare the additional farmi-info-bubble
                    createElement("div",{"id":"farmiInfo"+farmiNr,"class":"farmiInfo"},$("blase"+farmiNr));
                    createElement("div",{"id":"farmiMiniInfo"+farmiNr,"class":"farmiMiniInfo"},$("kunde_"+farmiNr));
                    //createElement("div",{"id":"farmiInfo"+farmiNr,"style":"position:absolute;height:35px;top:-47px;border-radius:5px;padding:5px;color:black;font-size:0.8em;"},$("blase"+farmiNr));
                    //createElement("div",{"id":"farmiMiniInfo"+farmiNr,"style":"position:absolute;top:45px;right:15px;height:7px;width:7px;display:block;border-radius:5px;"},$("kunde_"+farmiNr));
                    // fill the bubble when shown
                    $("kunde_"+farmiNr).addEventListener("mouseover",function(event){
                        var farmiNr=this.id.replace("kunde_","");
                        // toolTip.show(event,print_r(unsafeWindow.farmisinfo[0][farmiNr],"",true));
                        var cash=parseFloat(unsafeWindow.farmisinfo[0][farmiNr]["price"],10);
                        var wert = parseFloat(unsafeWindow.farmisinfo[0][farmiNr]["marketValue"],10);
                        var cell=$("blase"+farmiNr).firstElementChild.firstElementChild;
                        var ppid, amount;
                        for(var i=1;i<=7;i++){ // 7=maxanzahl produkte pro farmi
                            if(cell.style.clear=="both"){ // line break after 4 products
                                cell=cell.nextElementSibling;
                                if(!cell){ break; }
                            }
                            pid=unsafeWindow.farmisinfo[0][farmiNr]["p"+i];
                            amount=parseInt(unsafeWindow.farmisinfo[0][farmiNr]["a"+i],10);
                            if((pid>0)&&(amount>0)){
                                if(prodStock[0][pid]<amount){
                                    // not enough in rack
                                    cell.setAttribute("style",css_styles["prod_border_missing"][1]+"overflow:hidden; margin-right:2px; marign-bottom:2px; float:left; width:15px; height:15px;border-radius:4px;");
                                }else if(prodStock[0][pid]-amount<prodMinRack[0][pid]-((valMinRackFarmis&&totalFarmis[0]&&totalFarmis[0][pid])?totalFarmis[0][pid]:0)){
                                    // selling this farmi will push the rack below the min-value
                                    cell.setAttribute("style",css_styles["prod_border_lowamount"][1]+"overflow:hidden; margin-right:2px; marign-bottom:2px; float:left; width:15px; height:15px;border-radius:4px;");
                                }else{
                                    cell.style.border="1px solid white";
                                    //css_styles["prod_border_none"][[],"1px solid white","1px solid white"];
                                    //cell.setAttribute("style",css_styles["prod_border_none"][1]+"overflow:hidden; margin-right:2px; marign-bottom:2px; float:left; width:15px; height:15px;border-radius:4px;");
                                }
                            }
                            cell=cell.nextElementSibling;
                            if(!cell){ break; }
                        }
                        cell=$("farmiInfo"+farmiNr);
                        if(!unsafeWindow.farmisinfo[0][farmiNr]["costQuotient"]){
                            // a price is missing. can't calculate, so display white
                            cell.innerHTML=moneyFormatInt(cash);
                            cell.setAttribute("style",css_styles["cloud_back_noprice"][1]+css_styles["cloud_border_noprice"][1]);
                        }else if(unsafeWindow.farmisinfo[0][farmiNr]["costQuotient"]<valFarmiLimits[0]){
                            // low case
                            cell.innerHTML=moneyFormatInt(cash)+"<br>"+numberFormat(unsafeWindow.farmisinfo[0][farmiNr]["costQuotient"],1)+"&nbsp;%<br>"+moneyFormatInt(cash-wert)+"&nbsp;|&nbsp;"+moneyFormatInt(cash-0.9*wert);
                            cell.setAttribute("style",css_styles["cloud_back_below"][1]+css_styles["cloud_border_below"][1]);
                        }else if(unsafeWindow.farmisinfo[0][farmiNr]["costQuotient"]<valFarmiLimits[1]){
                            // middle case
                            cell.innerHTML=moneyFormatInt(cash)+"<br>"+numberFormat(unsafeWindow.farmisinfo[0][farmiNr]["costQuotient"],1)+"&nbsp;%<br>"+moneyFormatInt(cash-wert)+"&nbsp;|&nbsp;+"+moneyFormatInt(cash-0.9*wert);
                            cell.setAttribute("style",css_styles["cloud_back_between"][1]+css_styles["cloud_border_between"][1]);
                        }else{
                            // high case
                            cell.innerHTML=moneyFormatInt(cash)+"<br>"+numberFormat(unsafeWindow.farmisinfo[0][farmiNr]["costQuotient"],1)+"&nbsp;%<br>+"+moneyFormatInt(cash-wert)+"&nbsp;|&nbsp;+"+moneyFormatInt(cash-0.9*wert);
                            cell.setAttribute("style",css_styles["cloud_back_above"][1]+css_styles["cloud_border_above"][1]);
                        }
                        cell=null;
                    },false);
                    // farmi is new=not in the FarmiLog
                    var farmi_id=parseInt(unsafeWindow.farmisinfo[0][farmiNr]["id"],10);                    
                    var farmiLog_id=farmiLog.length;
                    for(var v=0;v<farmiLog.length;v++){
                        if (farmiLog[v][0]==farmi_id){
                            farmiLog_id=v;
                            break;
                        }
                    }
                    if (farmiLog_id==farmiLog.length){
                        raiseEvent("gameFarmiNew");
                        //todayStr=getDateStr(now,2,false);
                        // add this new farmi
                        farmiLog.push([farmi_id,todayStr,parseFloat(unsafeWindow.farmisinfo[0][farmiNr]["price"],10),{}]);
                        for(var w=1;w<8;w++){
                            if (unsafeWindow.farmisinfo[0][farmiNr]["p"+w]!="0"){
                                farmiLog[farmiLog_id][3][unsafeWindow.farmisinfo[0][farmiNr]["p"+w]]=parseInt(unsafeWindow.farmisinfo[0][farmiNr]["a"+w],10);
                            }
                        }
                        levelLog[levelLogId][5]+=farmiLog[farmiLog_id][2];
                        levelLog[levelLogId][5]=Math.round(100*levelLog[levelLogId][5])/100;
                        // sorting
                        farmiLog.sort(function(a,b){return (getTime(b[1])-getTime(a[1]));});
                        // saving
                        GM_setValueCache(COUNTRY+"_"+SERVER+"_"+USERNAME+"_farmiLog",implode(farmiLog));
                        GM_setValueCache(COUNTRY+"_"+SERVER+"_"+USERNAME+"_levelLog",implode(levelLog));
                        window.setTimeout(doBuyNotepad,0);
                    }
                }
                if(valFarmiMiniInfo){
                    // Price
                    if(!unsafeWindow.farmisinfo[0][farmiNr]["costQuotient"]){ // unknown case
                        str = css_styles["farmi_price_unknown"][1];
                    }else if(unsafeWindow.farmisinfo[0][farmiNr]["costQuotient"]<valFarmiLimits[0]){ // low case
                        str = css_styles["farmi_price_low"][1];
                    }else if(unsafeWindow.farmisinfo[0][farmiNr]["costQuotient"]<valFarmiLimits[1]){ // middle case
                        str = css_styles["farmi_price_between"][1];
                    }else{ // high case
                        str = css_styles["farmi_price_above"][1];
                    }
                    // Rackamount
                    if(unsafeWindow.farmisinfo[0][farmiNr]["missing"]>0){
                        str += ' '+ css_styles["farmi_amount_missing"][1];
                    }else if(unsafeWindow.farmisinfo[0][farmiNr]["belowminvalue"]>0){
                        str += ' '+ css_styles["farmi_amount_low"][1];
                    }else{
                        str += ' '+ css_styles["farmi_amount_above"][1];
                    }
                    
                    cell=$("farmiMiniInfo"+farmiNr);
                    if(cell.getAttribute("style")!=str){ cell.setAttribute("style",str); }
                }
            }
            err_trace="alertAdvertEnd";
            if((unsafeWindow.customerstats)&&(unsafeWindow.customerstats["adstart"])&&(unsafeWindow.adrun)){
               var endDay = getDateStr(getTime(unsafeWindow.customerstats["adstart"])+4*86400-1);
                if((unsafeWindow.customerstats[endDay])&&(parseInt(unsafeWindow.customerstats[endDay]["count"],10)>=(farmiDailyCount+2*unsafeWindow.adrun))){
                    if(!(cell=$("alertAdvertEnd"))){
                        createElement("div",{"id":"alertAdvertEnd","style":"position:absolute;top:65px;left:0;color:white;font-weight:bold;background-color:red;padding:2px;white-space:nowrap;"},$("customerstats"),getText("advertisingEnds"));
                        window.setTimeout(function(){
                            var newdiv;
                            if(newdiv=$("alertAdvertEnd")){ removeElement(newdiv); }
                            newdiv=null;
                        },1000*(getTime(getDateStr(now,2,false))+86400-now)); // time till midnight
                    }
                }else{
                    if(cell=$("alertAdvertEnd")){ removeElement(cell); }
                }
                endDay = null;
            }else{
                if(cell=$("alertAdvertEnd")){ removeElement(cell); }
            }
        }else{
            err_trace="no customerline";
            if(cell=$("alertAdvertEnd")){ removeElement(cell); }
        }
        cell=null;str=null;
    if(DEVMODE_FUNCTION){ tracking.end("berater",trackingHandle); }
    }catch(err){ GM_logError("doFarmis ("+err_trace+")\n"+err); }
}

function do_main(){
try{
    function calcObservedPrice(mode,data){
        // data=[[amount1,price1],[amount2,price2],...]
        switch(mode){
        case 1:{ // normal mode. fast market
            data=data.clone();
            // kick upper 20% quantile
            var sum=0;
            for(var v=0;v<data.length;v++){
                sum += data[v][0];
            }
            sum=Math.floor(0.2*sum);
            for(var v=data.length-1;0<=v;v--){
                if(data[v][0]<sum){
                    sum -= data[v][0];
                    data.splice(v,1);
                }else{
                    data[v][0] -= sum;
                    sum=0;
                    break;
                }
            }
    
            // calc weighted mean
            var weights=[3,3,3,3,2,2,2,2,1,1,1,1];
            var count1=0;
            var count2=0;
            for(var v=0;v<data.length;v++){
                if (weights[v]!=undefined){
                    count1 += weights[v]*data[v][0]*data[v][1];
                    count2 += weights[v]*data[v][0];
                }
            }
            if(count2>0){
                return (Math.round(100*count1/count2)/100);
            }else{
                return 0;
            }
        break;}
        case 2:{ // decorations. slow market
            if(data.length>1){
                return data[1][1];
            }else if(data.length==1){
                return data[0][1];
            }else{
                return 0;
            }
        break;}
        }
    }
    
    var err_trace="Session";
    if(DEVMODE){ logBubble.add("Berater started"); }
    // Check if username is known
    if (!USERNAME){
        GM_log("Username is not known. Login again with running script.")
        location.href="http://www."+GAMEPAGES[COUNTRY]+"/login.php?start=1";
        return false;
    }
    // Check if browser is uptodate
    var newdiv,newdiv1,container,help;
    if(!createElement("div").children){
        newdiv=createElement("div",{"class":"alertbubble tbig link"},ALL,"Your browser could be too old.<br>This script uses functions which need Gecko&nbsp;1.9.1 (Firefox&nbsp;3.5).<br>You will get errors.");
        newdiv.addEventListener("click",function(){ removeElement(this); },false);
    }
    // Save session-id
    if (unsafeWindow.rid){  GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_session",unsafeWindow.rid); }
    // Show changelog of new version
    err_trace="Changelog of new version";
    if(CHANGELOG[CHANGELOG.length-1][0]!=GM_getValue("changelogShownVersion","")){
        container=createElement("div");
        createElement("div",{},container,getText("confirmChangelogVersion").replace("%1%",CHANGELOG[CHANGELOG.length-1][0]));
        newdiv=createElement("ul",{},container);
        for(var i=0;i<CHANGELOG[CHANGELOG.length-1][2].length;i++){
            createElement("li",{},newdiv,CHANGELOG[CHANGELOG.length-1][2][i][LANGUAGE=="de"?0:1]);
        }
        alert2(container.innerHTML,getText("ok"),getText("showChangelog"),
        function(){
            GM_setValueCache("changelogShownVersion",CHANGELOG[CHANGELOG.length-1][0]);
        },
        function(){
            GM_setValueCache("changelogShownVersion",CHANGELOG[CHANGELOG.length-1][0]);
            unsafeWindow.buildInfoPanel("changelog");
        });
    }
            
    // Container Divs
    err_trace="Container";
    var nodes=new Object();
    ALL.style.margin="5px";
    var upjersToolbarHeight=($("uptoolbar")&&$("uptoolbar").style.display!="none")?30:0;
    var content_table=document.getElementsByClassName("content_table")[0];
    container=createElement("div",{"id":"gameArea","align":"center","style":"margin-top:"+upjersToolbarHeight+"px;"},ALL);
    newdiv=createElement("div",{"id":"divBeraterButtons","style":"position:fixed;left:0;top:"+(upjersToolbarHeight+50)+"px;width:40px;border:1px groove #4D240E;border-radius:0 10px 10px 0;z-index:500;background:url(\""+GFX+"guild/help_back.jpg\") -25px -25px;"},container);
    newdiv.addEventListener("mouseover",function(event){
        var node=event.target;
        var mouseOverText=node.getAttribute("mouseOverText");
        while((node!=this)&&(!mouseOverText)){
            node=node.parentNode;
            mouseOverText=node.getAttribute("mouseOverText");
        }
        if(mouseOverText){ toolTip.show(event,mouseOverText); }
        node=null;mouseOverText=null;
    },false);
    newdiv1=createElement("div",{"id":"divBeraterButtonsOptionen","class":"link beraterButtonIcon hoverBgGreen","mouseOverText":getText("options")},newdiv);
    createElement("img",{"src":IMAGES["settings"],"style":"position:relative;top:-3px;left:-1px;;width:32px;height:32px;"},newdiv1);
    newdiv1.addEventListener("click",function(){ unsafeWindow.buildInfoPanel("menu","options"); },false);
    newdiv1=createElement("div",{"id":"divGame","style":"position:relative;top:0;margin-left:45px;"},container);
    newdiv1.appendChild(content_table);
    if(newdiv=document.querySelector('a[href="https://de.upjers.com/imprint"]')){
        newdiv=newdiv.parentNode;
        container.appendChild(newdiv);
        newdiv.style.position="relative";
        newdiv.style.top=0;
        newdiv.style.left=0;
        newdiv.style.margin=0;
    }   
    content_table.style.position = "relative";
    createElement("div",{"id":"statisticArea","align":"center","style":"margin-top:"+upjersToolbarHeight+"px;display:none;"},ALL);
    if (window.innerWidth<1180){ content_table.style.paddingRight="176px"; }
    if (window.innerHeight>830){ ALL.style.overflowY="hidden"; }
    if(newdiv=$("errorboxgarden")){
        newdiv.style.left="600px";
        newdiv.style.top="105px";
    }else if(DEVMODE){
        GM_logWarning("#errorboxgarden not found");
    }
    if(newdiv=$("popup_garden")){
        newdiv.style.top="";
    }else if(DEVMODE){
        GM_logWarning("#popup_garden not found");
    }

    err_trace="Container - divRightBorder - divMiddleBorder";
    newdiv1=$("questbarcontrol").parentNode;
    removeElement(newdiv1.firstElementChild);
    newdiv=createElement("div",{"id":"divRightBorder"},newdiv1);
    if(container=$("gamearea_spacer")){
        container.innerHTML="";
        container=createElement("div",{"id":"divMiddleBorder","style":"position:relative;height:100%;"},container);
        for(var i=0;i+1<newdiv1.childElementCount;){
            if(newdiv1.children[i].id.match(/questbarcontrol|farm_production_checker_icon/)){
                newdiv.appendChild(newdiv1.children[i]);
            }else{
                container.appendChild(newdiv1.children[i]);
            }
        }
    }

    err_trace="Container - fixedDivRight";
    newdiv=createElement("div",{"id":"fixedDivRight","style":"position:fixed;right:0;top:"+(upjersToolbarHeight)+"px;z-index:500;"},$("divGame"));
    createElement("div",{"id":"timeHolder"},newdiv);
    nodes["containerPowerupSymbols"]=new Object();
    nodes["containerPowerupSymbols"]["node"]=createElement("div",{"id":"containerPowerupSymbols"},newdiv);
    
    err_trace="Container - headercontainer";
    newdiv=createElement("div",{"style":"position:absolute;top:2px;left:210px;color:#f7bb87;z-index:10;"},$("headercontainer"));
    nodes["serverTime"]=new Object();
    nodes["serverTime"]["node"]=createElement("div",{"id":"serverTime","style":"float:left;margin-left:2px;"},newdiv);
    nodes["serverTime"]["node"].addEventListener("mouseover",function(event){ toolTip.show(event,getText("serverTime")); },false);
    function do_relogin(){
        window.setTimeout(function(){
            var help=explode(GM_getValue(COUNTRY+"_pagedataLogin","{}"),"clickListener@divSessionEnd/pagedataLogin",{});
            if(!(help["doserver"]&&(typeof help["doserver"]=="object"))){
                help["doserver"]=new Object();
            }
            help["doserver"][SERVER]=true;
            GM_setValue(COUNTRY+"_pagedataLogin",implode(help));
            if($("logoutbutton")){
                click($("logoutbutton"));
            } else {
                location.href="http://www."+GAMEPAGES[COUNTRY]+"/login.php?start=1";
            }
        },0);
    }
    nodes["sessionTimeLeft"]=new Object();
    nodes["sessionTimeLeft"]["node"]=createElement("div",{"id":"sessionTimeLeft","class":"link","style":"float:left;margin-left:2px;"},newdiv);
    nodes["sessionTimeLeft"]["node"].addEventListener("mouseover",function(event){ toolTip.show(event,getText("sessionEnd").replace(/%1%/,getDaytimeStr(valSessionEndtime))); },false);
    nodes["sessionTimeLeft"]["node"].addEventListener("click",do_relogin,false);
    nodes["sessionTimeNow"]=new Object();
    nodes["sessionTimeNow"]["node"]=createElement("div",{"id":"sessionTimeNow","style":"float:left;margin-left:2px;"},newdiv);
    nodes["sessionTimeNow"]["node"].addEventListener("mouseover",function(event){ toolTip.show(event,getText("localTime")); },false);

    USERLEVEL=parseInt(unsafeWindow.currentuserlevel,10);
    /*
    var new_PRODUCT2BUILDING=PRODUCT2BUILDING.clone();
    new_PRODUCT2BUILDING[0][154]=1;
    GM_log(implode(new_PRODUCT2BUILDING));
    */
    show=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_show","{}"),"do_main/show",{}); // buyNotepad,marketoffersNotepad
    if((typeof show!="object")||(show instanceof Array)){ show = new Object(); }
    questData=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_questData"),"questData",INIT_questData);
    if((typeof questData!="object")||(questData instanceof Array)){ questData = INIT_questData.clone(); }
    // Check structure of questData
    for(var t in questData){
        if(!questData.hasOwnProperty(t)){continue;}
        if(INIT_questData[t]){
            for(var c in questData[t]){
                if(!questData[t].hasOwnProperty(c)){continue;}
                if(!INIT_questData[t][c]){ delete questData[t][c]; }
            }
        }else{
            delete questData[t];
        }
    }
    for(var t in INIT_questData){
        if(!INIT_questData.hasOwnProperty(t)){continue;}
        if(questData[t]){ 
            for(var c in INIT_questData[t]){
                if(!INIT_questData[t].hasOwnProperty(c)){continue;}
                if(!questData[t][c]){ questData[t]=INIT_questData[t]; }
            }
        }else{
            questData[t]=INIT_questData[t];
        }
    }
    // Check quest requirements
    if(USERLEVEL<31){ questData["main"]["2"]["nr"]=-1; }
    if(USERLEVEL<20){ questData["forestry"]["1"]["nr"]=-1; }
    if(questData["forestry"]["1"]["nr"]<35){ questData["forestry"]["2"]["nr"]=-1; }
    if(USERLEVEL<12){ questData["foodworld"]["1"]["nr"]=-1; }
    unsafeData.questData=questData.clone();

    for(var t in questData){
        if(!questData.hasOwnProperty(t)){continue;}
        for(var c in questData[t]){
            if(!questData[t].hasOwnProperty(c)){continue;}
            if((0<questData[t][c]["calcTo"])&&(questData[t][c]["calcTo"]<questData[t][c]["nr"])){
                setCalcToQuest(t,c,questData[t][c]["nr"]);
            }
        }
    }
    valServerTimeOffset=GM_getValue(COUNTRY+"_valServerTimeOffset",0);
    todayStr=getDateStr(now,2,false);
    nowServerOff=unsafeWindow.Zeit.Server+valServerTimeOffset;
    todayServerStr=getDateStr(nowServerOff,2,false);

    buyNotePadShowBlocked=GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_buyNotePadShowBlocked",false);//TODO make option
    loadProductData();
    updateProductDataFarm();
    updateProductDataForestry();
    updateProductDataWindmill();
    updateProductDataPowerup();

    err_trace="Show Data";
    // SHOW DATA: BUILDING_INPUT
    /*
    for(var zone=0;zone<BUILDING_INPUT.length;zone++){
        if(!BUILDING_INPUT[zone]){continue;}
        for(var output in BUILDING_INPUT[zone]){
        if(!BUILDING_INPUT[zone].hasOwnProperty(output)){continue;}
            for(var alt=0;alt<BUILDING_INPUT[zone][output].length;alt++){
                var str="Zone "+zone+": ";
                for(var input=0;input<BUILDING_INPUT[zone][output][alt].length;input++){
                    if(input>0){ str+=", "; }
                    str+=numberFormat(BUILDING_INPUT[zone][output][alt][input][1])+" "+prodName[0][BUILDING_INPUT[zone][output][alt][input][0]]
                }
                str+=" -> "+prodName[0][output];
                GM_log(str);
            }
        }
    }   
    */

/*  
        var div=createElement("div",{"style":"z-index:950;position:fixed;top:0;background-color:white;height:800px;overflow:auto;padding-right:40px;"},ALL);
        var newimg=createElement("img",{"class":"link","src":GFX+"close.jpg","style":"position:absolute;top:8px;right:0px;width:20px;height:20px;"},div);
        newimg.addEventListener("click",function(){ removeElement(this.parentNode); },false);

        var tr,td,table=createElement("table",{"border":"1"},div);
        for(var campaign in QUESTS["forestry"]){
        if(!QUESTS["forestry"].hasOwnProperty(campaign)){continue;} 
            for(var v=1;v<QUESTS["forestry"][campaign].length;v++){
                tr = createElement("tr",{},table);
                if(questData["forestry"][campaign]["nr"]==v){ tr.style.backgroundColor="#FBB"; }
                createElement("td",{},tr,campaign);
                createElement("td",{},tr,v);
                for(var w=0;w<6;w++){
                    td = createElement("td",{"style":"white-space:nowrap;"},tr);
                    if(QUESTS["forestry"][campaign][v][0][w]){
                        produktPic(QUESTS["forestry"][campaign][v][0][w][0],QUESTS["forestry"][campaign][v][0][w][1],td);
                        createElement("span",{},td,numberFormat(QUESTS["forestry"][campaign][v][0][w][2]));
                        td.setAttribute("mouseovertext",numberFormat(QUESTS["forestry"][campaign][v][0][w][2])+" "+prodName[QUESTS["forestry"][campaign][v][0][w][0]][QUESTS["forestry"][campaign][v][0][w][1]]);
                        td.addEventListener("mouseover",function(event){ toolTip.show(event,this.getAttribute("mouseovertext")); },false);
                    }
                }
                createElement("td",{},tr,QUESTS["forestry"][campaign][v][1]);
                td=createElement("td",{},tr);
                    if(QUESTS["forestry"][campaign][v][2]){ pointsFormat(QUESTS["forestry"][campaign][v][2],"div",td); }
                td=createElement("td",{},tr);
                    if(QUESTS["forestry"][campaign][v][3]){ createElement("div",{},td,implode(QUESTS["forestry"][campaign][v][3])); }
            }
        }
        div=null;newimg=null;
        table=null;tr=null;td=null;
    });
*/
    // SHOW BUILDING DATA
    GM_registerMenuCommand(getText("adviser")+" "+"Show Data: Buildings", function(){
    try{
        var container=createElement("div",{"style":"z-index:995;position:absolute;top:0;left:0;background-color:white;height:100%;"},ALL);
        var div=createElement("img",{"class":"link","src":GFX+"close.jpg","style":"position:absolute;top:0;right:0;width:20px;height:20px;margin:5px;"},container);
        div.addEventListener("click",function(){ removeElement(this.parentNode); },false);
        div=createElement("div",{"style":"height:100%;padding-right:20px;margin-right:30px;overflow:auto;"},container);
        var table=createElement("table",{"border":"1"},div);
        var tr=createElement("tr",{},table);
        var td;
        createElement("th",{},tr);
        for(var w=1;w<unsafeWindow.buildinginfos[0][1].length;w++){
            createElement("th",{},tr,w);
        }
        createElement("th",{},tr,"BUILDING_UPGRADES");
        createElement("th",{},tr,"BUILDINGTYPE");
        createElement("th",{},tr,"COUNT");
        for(var v in unsafeWindow.buildinginfos[0]){
            if(!unsafeWindow.buildinginfos[0].hasOwnProperty(v)){continue;}     
            tr=createElement("tr",{},table);
            createElement("td",{},tr,v);
            for(var w=1;w<unsafeWindow.buildinginfos[0][v].length;w++){
                createElement("td",{},tr,implode(unsafeWindow.buildinginfos[0][v][w]));
            }
            createElement("td",{},tr,implode(BUILDING_UPGRADES[v]));
            createElement("td",{},tr,implode(BUILDINGTYPE[v]));
            createElement("td",{},tr,implode(totalZones[v]));
        }
        for(var i=1;i<=4;i++){
            v="fw"+i;
            tr=createElement("tr",{},table);
            createElement("td",{},tr,v);
            for(var w=1;w<=12;w++){
                td=createElement("td",{},tr);
                switch(w){
                case 10: td.innerHTML=getBuildingName(v); break;
                }
            }
            createElement("td",{},tr,implode(BUILDING_UPGRADES[v]));
            createElement("td",{},tr,implode(BUILDINGTYPE[v]));
            createElement("td",{},tr,implode(totalZones[v]));
        }
        for(var i=1;i<=6;i++){
            v="fl"+i;
            tr=createElement("tr",{},table);
            createElement("td",{},tr,v);
            for(var w=1;w<=12;w++){
                td=createElement("td",{},tr);
                switch(w){
                case 10: td.innerHTML=getBuildingName(v); break;
                }
            }
            createElement("td",{},tr,implode(BUILDING_UPGRADES[v]));
            createElement("td",{},tr,implode(BUILDINGTYPE[v]));
            createElement("td",{},tr,implode(totalZones[v]));
        }
        container=null;div=null;
        table=null;tr=null;td=null;
    }catch(err){ GM_logError("show building data\n"+err); }
    });
    
    valMinRackMan=GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valMinRackMan",false);
    valMinRack=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valMinRack"),"do_main/valMinRack");
    bChanged=false;
    if((typeof valMinRack=="object")&&!(valMinRack instanceof Array)){ 
        for(var v in valMinRack){
            if(!valMinRack.hasOwnProperty(v)){continue;}
            if(INIT_valMinRack[v]==undefined){ delete valMinRack[v];bChanged=true; }
            else if(typeof valMinRack[v]!="number"){ valMinRack[v]=INIT_valMinRack[v];bChanged=true; }
        }
        for(var v in INIT_valMinRack){
            if(!INIT_valMinRack.hasOwnProperty(v)){continue;}
            if(valMinRack[v]==undefined){ valMinRack[v]=INIT_valMinRack[v];bChanged=true; }
        }
    }else{
        valMinRack=INIT_valMinRack.clone();bChanged=true;
    }
    if(bChanged){ GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valMinRack",implode(valMinRack,"valMinRack")); }
    valMinRackPlantsize=GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valMinRackPlantsize",false); //Use plant ratio
    valMinRackFarmis=GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valMinRackFarmis",true);
    valMinRackForestryFarmis=GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valMinRackForestryFarmis",true);
    valMinRackGrowing=GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valMinRackGrowing",true);
    valMinRackRecursive=GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valMinRackRecursive",false);
    valFarmiLimits=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valFarmiLimits","[90,100]"),"do_main/valFarmiLimits",[90,100]);
    unsafeData.valFarmiLimits=valFarmiLimits.clone();
    valFarmiMiniInfo=GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valFarmiMiniInfo",true);

    unsafeOverwriteFunction("createAdvancedProductResponse",function(response,e,c){
        try{
            unsafeWindow._createAdvancedProductResponse(response,e,c);
        }catch(err){GM_logError("_createAdvancedProductResponse\n"+err);}
        try{
            raiseEvent("gameStartFactory");
        }catch(err){GM_logError("createAdvancedProductResponse\n"+err);}
    });
    // Farmis
    err_trace="farmis";
    if(newdiv=$("customerstats")){
        newdiv.setAttribute("class","link");
        newdiv.addEventListener("click",function(){unsafeWindow.buildInfoPanel("farmies");},false);
    }
    // farmiLog[farmiId]=[date,money,{prod1:amount,...}]
    farmiLog=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_farmiLog","[]"),"do_main/farmiLog",[]);
    if(!(farmiLog instanceof Array)){ farmiLog=[]; }
    // kick farmis older than 1 month, set this value optional?
    var dayLastMonth=new Date();
    dayLastMonth=Math.round(((new Date(dayLastMonth.getFullYear(),dayLastMonth.getMonth()-1,dayLastMonth.getDate())).getTime())/1000);
    for(var v=farmiLog.length-1;v>=0;v--){
        if (getTime(farmiLog[v][1])<=dayLastMonth){
            farmiLog.splice(v,1);
        }
    }

    function calcFarmiCost(){ //done on price change, on load and on a new farmi
    try{
    if(DEVMODE_FUNCTION){ var trackingHandle = tracking.start("berater","calcFarmiCost"); }
        // calculate costs of the farmis
        for(var farmiNr in unsafeWindow.farmisinfo[0]){
            if(!unsafeWindow.farmisinfo[0].hasOwnProperty(farmiNr)){ continue; }
            var wert=0;
            var priceMissing=0;
            for(var i=1;i<=7;i++){ // 7=max-amount of products per farmi
                var pid=unsafeWindow.farmisinfo[0][farmiNr]["p"+i];
                var amount=parseInt(unsafeWindow.farmisinfo[0][farmiNr]["a"+i],10);
                if((pid>0)&&(amount>0)){
                    if(gut[pid]>0){
                        wert += amount*gut[pid];
                    }else{
                        priceMissing++;
                    }
                }
            }
            unsafeWindow.farmisinfo[0][farmiNr]["costQuotient"]=(priceMissing>0?null:(100*parseFloat(unsafeWindow.farmisinfo[0][farmiNr]["price"],10)/wert));
            unsafeWindow.farmisinfo[0][farmiNr]["marketValue"]=(priceMissing>0?0:wert);
        }
    if(DEVMODE_FUNCTION){ tracking.end("berater",trackingHandle); }
    }catch(err){ GM_logError("calcFarmiCost\n"+err); }
    }
    // Foodworld
    err_trace="Foodworld";
    // Foodworld-Farmi
/*
    unsafeOverwriteFunction("showFoodworldFarmiCart",function(id){
        unsafeWindow._showFoodworldFarmiCart(id);
        try{
            var newdiv, sum=0, prodId, priceMissing=false;
            if(newdiv=$("food_cart_products")){
                for(var i=0;i<newdiv.childElementCount;i++){
                    prodId=parseInt(newdiv.children[i].firstElementChild.getAttribute("class").replace(/\D+/g,""),10);
                    newdiv.children[i].setAttribute("prodId",prodId);
                    newdiv.children[i].classList.add("link");
                    newdiv.children[i].addEventListener("mouseover",function(event){ showGoToMarketToolTip(event,this.getAttribute("prodId")); },false);
                    newdiv.children[i].addEventListener("click",function(event){ showMarket(this.getAttribute("prodId")); },false);
                    if(gut[prodId]){
                        sum+=gut[prodId]*unsafeWindow.foodworldfarmis[id]["products"][prodId];
                    }else{
                        newdiv.children[i].style.backgroundColor="red";
                        priceMissing=true;
                    }
                }
            }
            if(newdiv=$("food_cart_cost")){
                newdiv.innerHTML="100%:&nbsp;"+moneyFormatInt(sum)+"&nbsp;|&nbsp;90%:&nbsp;"+moneyFormatInt(0.9*sum);
            }
            if(newdiv=$("food_cart_perc")){
                if(priceMissing){
                    newdiv.style.border="4px inset #336";
                    newdiv.style.color="#336";
                    newdiv.style.backgroundColor="transparent";
                    newdiv.innerHTML="--%";
                }else{
                    var price=parseInt(unsafeWindow.foodworldfarmis[id]["price"],10);
                    if(100*price<valFarmiLimits[0]*sum){ var col="red";var col2="#fcc"; }
                    else if(100*price<valFarmiLimits[1]*sum){ var col="#d80";var col2="#ff9"; }
                    else{ var col="green";var col2="#80ff80"; }
                    newdiv.style.border="4px inset "+col;
                    newdiv.style.color=col;
                    newdiv.style.backgroundColor=col2;
                    newdiv.innerHTML=Math.round(100*price/sum)+"%";
                }
            }
            newdiv=null;
        }catch(err){ GM_logError("showFoodworldFarmiCart\n"+err); }
    });
*/
    unsafeOverwriteFunction("showFoodworldFarmiCart",function(farmi){
    try{
        unsafeWindow._showFoodworldFarmiCart(farmi);
    }catch(err){GM_logError("_showFoodworldFarmiCart\n"+err);}
    try{
        // get farmi data
        var prod,menge;
        var thisFarmiData=new Object();
        thisFarmiData["cart"]=new Array();
        thisFarmiData["money"]=parseFloat(unsafeWindow.foodworldfarmis[farmi]["price"],10);
        for(var i in unsafeWindow.foodworldfarmis[farmi]["products"]){
            if(!unsafeWindow.foodworldfarmis[farmi]["products"].hasOwnProperty(i)){ continue; }
            prod=parseInt(i,10);
            menge=unsafeWindow.foodworldfarmis[farmi]["products"][i];
            thisFarmiData["cart"].push([prod,menge,menge*gut[prod]]);
        }
        // (re-)build the table
        function buildTable(){
        try{
            var cartContent,newtable,newtr,newtd,span;
            cartContent=$("food_cart_products");
            cartContent.innerHTML="";
            var prod,menge,wert,sum=0,priceMissing=false;
            thisFarmiData["cart"].sort(function(a,b){return (b[2]-a[2]);});
            newtable=createElement("table",{"border":"0","cellspacing":"0","cellpadding":"2","style":"margin:0 auto;"},cartContent);
            for(var v=0;v<thisFarmiData["cart"].length;v++){
                prod=thisFarmiData["cart"][v][0];
                menge=thisFarmiData["cart"][v][1];
                wert=thisFarmiData["cart"][v][2];
                sum += wert;
                newtr=createElement("tr",{"class":((prodStock[0][prod]<menge)?("farmicart_missing"):((prodStock[0][prod]-menge<prodMinRack[0][prod]-((valMinRackFarmis&&totalFarmis[0]&&totalFarmis[0][prod])?totalFarmis[0][prod]:0))?"farmicart_lowrack":"")),"prod":prod},newtable);
                produktPic(0,prod,createElement("td",{},newtr));
                createElement("td",{"style":"text-align:right;font-size:16px;font-weight:bold;"},newtr,numberFormat(menge));
                newtd=createElement("td",{"class":"link","style":"width:170px;"},newtr);
                newtd.addEventListener("mouseover",function(event){ showGoToMarketToolTip(event,this.parentNode.getAttribute("prod")); },false);
                newtd.addEventListener("click",function(){showMarket(this.parentNode.getAttribute("prod"));},false);
                span=createElement("span",{"style":"font-size:16px;font-weight:bold;white-space:nowrap;"},newtd,prodName[0][prod]);
                span.style.fontSize=16*Math.min(1,170/span.offsetWidth)+"px";
                newtd=createElement("td",{"class":"link","nr":v,"style":"width:82px;text-align:right;font-size:14px;"},newtr);
                if(wert>0){
                    newtd=createElement("div",{"style":"position:relative;height:100%;padding-left:5px;padding-right:5px;"},newtd);
                    createElement("div",{"style":"position:absolute;left:0;height:100%;width:"+Math.ceil(100*wert/thisFarmiData["cart"][0][2])+"%;background-color:grey;opacity:0.6;z-index:-1;"},newtd);
                    createElement("span",{"style":"width:100%;"},newtd,moneyFormatInt(wert));
                }else{
                    newtd.style.backgroundColor="red";
                    priceMissing=true;
                }
                newtd.addEventListener("mouseover",function(event){ toolTip.show(event,getText("editPrice")); },false);
                newtd.addEventListener("click",function(){
                    var cell,newtable,newt,newtdr
                    cell=this;
                    while(cell.nodeName!="TD"){ cell=cell.parentNode; }
                    var v=cell.getAttribute("nr");
                    cell=$("cartcontentEditPrice");
                    if(cell){ removeElement(cell); }
                    newtable=createElement("div",{"id":"cartcontentEditPrice","style":"z-index:10;position:absolute;right:0;top:0;display:block;border-radius:5px;","class":"blackbox"},$("food_cart_products"));
                    newtable=createElement("table",{"cellspacing":"0","cellpadding":"0","border":"0","nr":v},newtable);
                    newtr=createElement("tr",{},newtable);
                    createElement("td",{"colspan":"2","style":"color:black;text-align:center;padding-bottom:2px;white-space:nowrap;"},newtr,getText("editPrice"));
                    newtr=createElement("tr",{},newtable);
                    createElement("td",{"colspan":"2","style":"color:black;border-bottom:1px solid black;text-align:center;padding-bottom:2px;white-space:nowrap;"},newtr,numberFormat(thisFarmiData["cart"][v][1])+"&nbsp;"+prodName[0][thisFarmiData["cart"][v][0]]);
                    newtr=createElement("tr",{},newtable);
                    createElement("td",{"style":"color:black;text-align:left;padding-top:2px;padding-right:10px;"},newtr,getText("marketPrice"));
                    createElement("td",{"style":"color:black;text-align:right;padding-top:2px;"},newtr,moneyFormat(gut[thisFarmiData["cart"][v][0]]));
                    newtr=createElement("tr",{},newtable);
                    createElement("td",{"style":"color:black;text-align:left;padding-right:10px;"},newtr,getText("NPCprice"));
                    createElement("td",{"style":"color:black;text-align:right;"},newtr,isNaN(NPC[0][thisFarmiData["cart"][v][0]])?"-":moneyFormat(NPC[0][thisFarmiData["cart"][v][0]]));
                    newtr=createElement("tr",{"style":"height:22px;"},newtable);
                    createElement("td",{"style":"color:black;text-align:left;padding-right:10px;"},newtr,getText("single"));
                    newtd=createElement("td",{},newtr);
                    cell=createElement("input",{"class":"text","type":"text","style":"color:black;text-align:right;width:60px;","value":numberFormat(thisFarmiData["cart"][v][2]/thisFarmiData["cart"][v][1],2),"maxlength":"8"},newtd);
                    cell.addEventListener("change",function(){
                        var help=parseFloat(this.value.replace(regDelimThou,"").replace(regDelimDeci,"."),10);
                        if(!isNaN(help)){
                            if(help<0){ help*=-1; }
                            help=Math.round(100*help)/100;
                            this.value=numberFormat(help,2);
                            var v=this.parentNode.parentNode.parentNode.getAttribute("nr");
                            thisFarmiData["cart"][v][2]=help*thisFarmiData["cart"][v][1];
                            this.parentNode.parentNode.nextElementSibling.children[1].firstElementChild.value=numberFormat(thisFarmiData["cart"][v][2],2);
                        }
                    },false);
                    newtr=createElement("tr",{"style":"height:22px;"},newtable);
                    createElement("td",{"style":"color:black;text-align:left;padding-right:10px;"},newtr,getText("total"));
                    newtd=createElement("td",{},newtr);
                    cell=createElement("input",{"class":"text","type":"text","style":"color:black;text-align:right;width:60px;","value":numberFormat(thisFarmiData["cart"][v][2],2),"maxlength":"9"},newtd);
                    cell.addEventListener("change",function(){
                        var help=parseFloat(this.value.replace(regDelimThou,"").replace(regDelimDeci,"."),10);
                        if(!isNaN(help)){
                            if(help<0){ help*=-1; }
                            help=Math.round(100*help)/100;
                            this.value=numberFormat(help,2);
                            var v=this.parentNode.parentNode.parentNode.getAttribute("nr");
                            thisFarmiData["cart"][v][2]=help;
                            this.parentNode.parentNode.previousElementSibling.children[1].firstElementChild.value=numberFormat(thisFarmiData["cart"][v][2]/thisFarmiData["cart"][v][1],2);
                        }
                    },false);
                    newtr=createElement("tr",{"style":"height:22px;"},newtable);
                    newtd=createElement("td",{"colspan":"2","style":"color:black;border-top:1px solid black;text-align:center;padding-top:2px;"},newtr);
                    cell=createElement("button",{"class":"link","type":"button","style":"color:black;"},newtd,getText("ok"));
                    cell.addEventListener("click",function(){
                        removeElement(this.parentNode.parentNode.parentNode.parentNode);
                        buildTable();
                    },false);
                    cell=null;newtable=null;newtr=null;newtd=null;
                },false);
            }

            newtr=createElement("tr",{},newtable);
            createElement("td",{"colspan":"3"},newtr);
            newtd=createElement("td",{"style":"padding-left:5px;padding-right:5px;border-top:1px solid #336;text-align:right;color:#336;font-size:14px;","mouseOverText":"90%: "+moneyFormatInt(0.9*sum)},newtr,moneyFormatInt(sum));
            newtd.addEventListener("mouseover",function(event){ toolTip.show(event,this.getAttribute("mouseOverText")); },false);

            newtd=$("food_cart_perc");
            if(priceMissing){
                newtd.style.border="4px inset #336";
                newtd.style.color="#336";
                newtd.style.backgroundColor="transparent";
                newtd.innerHTML="--%";
            }else{
                if(100*thisFarmiData["money"]<valFarmiLimits[0]*sum){ var col="red";var col2="#fcc"; }
                else if(100*thisFarmiData["money"]<valFarmiLimits[1]*sum){ var col="#d80";var col2="#ff9"; }
                else{ var col="green";var col2="#80ff80"; }
                newtd.style.border="4px inset "+col;
                newtd.style.color=col;
                newtd.style.backgroundColor=col2;
                newtd.innerHTML=Math.round(100*thisFarmiData["money"]/sum)+"%";
            }
            cartContent=null;newtable=null;newtr=null;newtd=null;span=null;
        }catch(err){GM_logError("showCart.buildTable\n"+err);}  
        }
        buildTable();
    }catch(err){GM_logError("showFoodworldFarmiCart\n"+err);}   
    });
    unsafeOverwriteFunction("createFoodworldFarmis",function(){
        try{
            unsafeWindow._createFoodworldFarmis();
        }catch(err){GM_logError("_createFoodworldFarmis\n"+err);}
        try{
            var div,input;
            if(div=$("food_farmis")){
                div=createElement("div",{"style":"position:absolute;bottom:-20px;"},div);
                input=createElement("input",{"type":"checkbox","checked":valFoodworldFarmiPlacing,"class":"link"},div);
                input.addEventListener("click",function(){
                    valFoodworldFarmiPlacing=this.checked;
                    GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valFoodworldFarmiPlacing",valFoodworldFarmiPlacing); 
                },false);
                div.addEventListener("mouseover",function(event){
                    toolTip.show(event,getText("settings_valFoodworldFarmiPlacing")[1]);
                },false);
            }
        }catch(err){GM_logError("createFoodworldFarmis\n"+err);}
    });
    unsafeOverwriteFunction("dragFoodworldFarmiTouch",function(id){
        try{
            unsafeWindow._dragFoodworldFarmiTouch(id);
        }catch(err){GM_logError("_dragFoodworldFarmiTouch\n"+err);}
        try{
            if(valFoodworldFarmiPlacing){
                loop:
                for(var b=0;b<=4;b++){
                    if(unsafeWindow.foodworldtables[b]&&(!unsafeWindow.foodworldtables[b]["block"])&&(!unsafeWindow.foodworldtables[b]["locked"])){
                        for(var a=1;a<=2;a++) {
                            if(!(unsafeWindow.foodworldtables[b]["chairs"]&&unsafeWindow.foodworldtables[b]["chairs"][a]&&unsafeWindow.foodworldtables[b]["chairs"][a]["id"])){
                                if(div=$("foodworldchair"+b+"_"+a+"_touch")){
                                    click(div);
                                    div=null;
                                    break loop;
                                }
                            }
                        }
                    }
                }               
            }
        }catch(err){GM_logError("dragFoodworldFarmiTouch\n"+err);}
    });
    if(newdiv=$("food_cart")){
        createElement("div",{"id":"food_cart_cost","style":"position:absolute;bottom:130px;left:135px;font-size:12px;color:#463824;"},newdiv);
        createElement("div",{"id":"food_cart_perc","style":"position:absolute;bottom:105px;left:375px;width:70px;padding:2px;text-align:right;font-size:20px;font-weight:bold;"},newdiv);       
    }
    // Foodworld-Zones
    function doFoodworld(){
    try{
        gameLocation=["foodworld",null];
        unsafeData.gameLocation=gameLocation.clone();
        var nowServer=unsafeWindow.Zeit.Server;
        var zoneNrF,zoneNrS,tempZoneProductionData,tempZoneProductionDataSlot,currBlock;
        // Buildings
        var err_trace="Buildings";
        zoneNrF="foodworld-4";
        zones.setBlock(zoneNrF,"blpqs");
        if(unsafeWindow.foodworldbuildings){
            var res,iProd,iTime,iAmount,iPoints,iSlotCount;
            for(var building in unsafeWindow.foodworldbuildings){
                if(!unsafeWindow.foodworldbuildings.hasOwnProperty(building)){continue;}
                res=unsafeWindow.foodworldbuildings[building];
                zoneNrF="foodworld-"+building;
                currBlock=(unsafeWindow.foodworldbuildings[building]["cost"]?"b":""); // foodworld building locked due to missing payment
                currBlock+=(unsafeWindow.foodworldbuildings[building]["block"]?"l":""); // foodworld building locked due to level requirement               
                zones.setBlock(zoneNrF,currBlock);
                if(zones.isMultiSlot(zoneNrF)){
                    iSlotCount=3;
                    if(!currBlock){
                        for(var slot=1;slot<=iSlotCount;slot++){
                            zoneNrS=zoneNrF+"."+slot;
                            zones.setBlock(zoneNrS,res["slots"]&&res["slots"][slot]&&res["slots"][slot]["block"]?"b":"");
                        }
                    }
                }else{
                    iSlotCount=0;
                }
                if(!currBlock){
                    zones.setBonus(zoneNrF,0); // TODO // unsafeWindow.forestry_user_buildings[building]["boni"]?unsafeWindow.forestry_user_buildings[building]["boni"]:0;
                    res=(unsafeWindow.foodworldbuildings[building]&&unsafeWindow.foodworldbuildings[building]["slots"])?unsafeWindow.foodworldbuildings[building]["slots"]:{};
                    
                    tempZoneProductionData=[[{},{}],0,0,true];
                    for(var slot=1;slot<=(iSlotCount==0?1:iSlotCount);slot++){
                        if(DEVMODE){ GM_log("doFoodworld zoneNrF="+zoneNrF+" slot="+slot+" res["+slot+"]="+implode(res[slot],"res")); }
                        if(iSlotCount>0){
                            zoneNrS=zoneNrF+"."+slot;
                        }else{
                            zoneNrS=zoneNrF;
                        }
                        if(!zones.getBlock(zoneNrS)){
                            tempZoneProductionDataSlot=[[{},{}],0,0,true];
                            if(res[slot]){
                                iProd=(res[slot]["pid"]?parseInt(res[slot]["pid"],10):null);
                                if(isNaN(iProd)){ iProd=null; }
                                if((iProd!=null)&&(res[slot]["ready"])){ // production ready
                                    iTime=nowServer;
                                }else if((iProd!=null)&&(res[slot]["remain"])){ // production busy
                                    iTime=nowServer+res[slot]["remain"]; 
                                }else{
                                    iTime=NEVER;
                                    tempZoneProductionData[1]++;
                                    tempZoneProductionDataSlot[1]++;
                                }
                                // iAmount=(res[slot]["amount"]?res[slot]["amount"]:null);
                                tempZoneProductionData[2]++;
                                tempZoneProductionDataSlot[2]++;
                                if(iProd!=null){
                                    iAmount=prodYield[0][iProd];
                                    iPoints=iAmount*prodPoints[0][iProd];                               
                                    if(!tempZoneProductionData[0][0][iProd]){ tempZoneProductionData[0][0][iProd]=[]; }
                                    tempZoneProductionData[0][0][iProd].push([iAmount,iPoints,iTime,NEVER]);
                                    if(!tempZoneProductionDataSlot[0][0][iProd]){ tempZoneProductionDataSlot[0][0][iProd]=[]; }
                                    tempZoneProductionDataSlot[0][0][iProd].push([iAmount,iPoints,iTime,NEVER]);
                                }
                            }
                            if(iSlotCount>0){
                                zones.setProduction(zoneNrS,tempZoneProductionDataSlot.clone());
                            }
                        }
                    }
                    zones.setProduction(zoneNrF,tempZoneProductionData.clone());
                    //auto-cropping
                    // if(iSlotCount=0){
                    //  var div;
                    //  if((top.unsafeData.autoAction==null) && valAutoCrop["forestry"] && (zones.getEndtime(zoneNrF)<=unsafeWindow.Zeit.Server) && (div=$("forestry_building_click"+building))){
                    //      top.unsafeData.autoAction="berater: forestry building crop";
                    //      document.addEventListener("gameOpenGlobalCommitBox",function(){
                    //          document.removeEventListener("gameOpenGlobalCommitBox",arguments.callee,false);
                    //          window.setTimeout(function(){ 
                    //              click($("globalcommitboxfooter").firstElementChild);
                    //              top.unsafeData.autoAction=null;
                    //          },500);
                    //      });
                    //      window.setTimeout(function(div){ click(div); },500,div);
                    //  }
                    //  div=null;
                    // }
                    createZoneTimer("zoneTimer_"+zoneNrF,zoneNrF,"zonetimer","position:absolute;top:-20px;left:0px;",$("food_pos"+building));
                }
            }
            building=null;res=null;iProd=null;iTime=null;maxCapacity=null;
        }
        calcTotalZones();
        // Quest
        handleQuestDataFoodworld();
        if((newdiv=$("foodworld_questblock"))&&(!newdiv.classList.contains("mouseOver"))){
            newdiv.classList.add("mouseOver");
            newdiv.addEventListener("mouseover",function(event){
                toolTip.show(event,questLineMouseOver("foodworld","1"));
            },false);
        }
        zoneNrF=null;tempZoneProductionData=null;tempZoneProductionDataSlot=null;

        err_trace="saving";
        publishProductData();
    }catch(err){GM_logError("doFoodworld ("+err_trace+")\n"+err);}
    }
    unsafeOverwriteFunction("foodworldActionResponse",function(request,action,id,table,chair){
        try{
            unsafeWindow._foodworldActionResponse(request,action,id,table,chair);
        }catch(err){GM_logError("_foodworldActionResponse\n"+err);}
        try{
            var result = checkRequest(request);
            if((result!=0)&&(result[0]!=0)){
                doFoodworld();
                switch(action){
                case "crop": raiseEvent("gameFoodworldCropped"); break;
                case "init": raiseEvent("gameFoodworldOpened"); break;
                case "open": raiseEvent("gameFoodworldOpened" + id); break
                case "production": raiseEvent("gameFoodworldStarted"); break
                // logBubble.add("gameLocation = " + gameLocation + "id = " + id);
                }           
            }
            result=null;
        }catch(err){GM_logError("foodworldActionResponse\n"+err);}
    });
    unsafeOverwriteFunction("openFoodworldBuildingSelect",function(position,slot){
        try{
            unsafeWindow._openFoodworldBuildingSelect(position,slot);
        }catch(err){GM_logError("_openFoodworldBuildingSelect\n"+err);}
        try{
            raiseEvent("gameFoodworldSlotOpened")
        }catch(err){GM_logError("openFoodworldBuildingSelect\n"+err);}
    });
        
    // Addons
    err_trace="Addons";
    // TODO remove
    document.addEventListener("gameBotStarted",function(){
        try{
            valAutoWater["farm"]=unsafeData.botConfigData[0];
            valAutoCrop["farm"]=unsafeData.botConfigData[1];
            valWaterNeeded["farm"]=unsafeData.botConfigData[2];
            for(var z in unsafeData.readyZone){
                if(!unsafeData.readyZone.hasOwnProperty(z)){continue;}
                unsafeData.readyZone[z][2]=true;
            }
        }catch(err){}
    },false);
    document.addEventListener("gameBotStopped",function(){
        window.setTimeout(function(){
        try{
            valAutoWater=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valAutoWater"),"valAutoWater",{"farm":false,"forestry":true});
            valAutoCrop=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valAutoCrop"),"valAutoCrop",{"farm":false,"forestry":true});
            valWaterNeeded=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valWaterNeeded"),"valWaterNeeded",{"farm":true,"forestry":true});
        }catch(err){}
        },0);
    },false);   
    unsafeWindow.prodMinRackAddon.add = function(type,pid,reason,amount){
    try{
        type=parseInt(type,10);
        pid=parseInt(pid,10);
        amount=parseInt(amount,10);
        if(isNaN(type)||isNaN(pid)||isNaN(amount)){
            GM_log("prodMinRackAddon.add wrong arguments:");
            GM_log([type,pid,reason,amount]);
            return false;
        }
        unsafeWindow.prodMinRackAddon.newdata.push([type,pid,reason,amount]);
        raiseEvent("gameChangedProdMinRackAddon");
    }catch(err){ GM_logError("prodMinRackAddon.add\n"+err); }
    };
    unsafeWindow.prodMinRackAddon.remove = function(type,pid,reason){
    try{
        unsafeWindow.prodMinRackAddon.newdata.push([type,pid,reason,null]);
        raiseEvent("gameChangedProdMinRackAddon");
    }catch(err){ GM_logError("prodMinRackAddon.remove\n"+err); }
    };
    unsafeWindow.prodMinRackAddon.removeAll = function(type,reason){
    try{
        for(var p in prodMinRackAddon[type]){
            if(!prodMinRackAddon[type].hasOwnProperty(p)){ continue; }
            if(prodMinRackAddon[type][p]&&prodMinRackAddon[type][p][reason]){
                unsafeWindow.prodMinRackAddon.newdata.push([type,parseInt(p,10),reason,null]);
            }
        }
        raiseEvent("gameChangedProdMinRackAddon");
    }catch(err){ GM_logError("prodMinRackAddon.removeAll\n"+err); }
    };
    document.addEventListener("gameChangedProdMinRackAddon",function(){
    try{
        // test if calculation is running
        if(unsafeWindow.prodMinRackAddon.busy){ return false; }
        // set flag
        unsafeWindow.prodMinRackAddon.busy=true;
        // get data inside
        var helper=unsafeWindow.prodMinRackAddon.newdata;
        unsafeWindow.prodMinRackAddon.newdata=new Array();
        // calculate
        var type,prod,reason,amount;
        for(var k=0;k<helper.length;k++){
            type  =helper[k][0];
            prod=helper[k][1];
            reason=helper[k][2];
            amount=helper[k][3];
            if(prodMinRackAddon[type][prod]){
                if(prodMinRackAddon[type][prod][reason]){
                    if(amount==null){ // delete existing entry
                        delete prodMinRackAddon[type][prod][reason];
                    }else if(prodMinRackAddon[type][prod][reason]!=amount){ // update existing entry
                        prodMinRackAddon[type][prod][reason]=amount;
                    } // else the entry is correct
                }else if(amount!=null){
                    prodMinRackAddon[type][prod][reason]=amount;
                }
            }else if(amount!=null){ // create new entry
                prodMinRackAddon[type][prod]=new Object();
                prodMinRackAddon[type][prod][reason]=amount;
            } // else a non-existing entry should be deleted
        }
        calcProdMinRack();
        // remove flag
        unsafeWindow.prodMinRackAddon.busy=false;
        // restart if new data meanwhile arrived
        if(unsafeWindow.prodMinRackAddon.newdata.length>0){
            arguments.callee();
        }
    }catch(err){ GM_logError("listener gameChangedProdMinRackAddon\n"+err); }
    },false);

    GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_farmname",FARMNAME);
    var documentTitle=" - "+FARMNAME+" - s"+SERVER+" - "+document.title;
    var lastGiess=null;
    var lastErnte=null;

    err_trace="zones";
    zones.init();
    for(var j=0;j<ALL_ZONES["farm"].length;j++){
        help=zones.getBlock(ALL_ZONES["farm"][j]);
        if((!help.match(/b/))&&(unsafeWindow.farmamount<Math.ceil(ALL_ZONES["farm"][j]/6))){
            GM_log("Blocking zone because farmamount is too low: "+ALL_ZONES["farm"][j]);
            zones.setBlock(ALL_ZONES["farm"][j],help+"b");
        }
    }
    zones.setBlock("windmill",USERLEVEL>=8?"":"l");
    calcAllSlots();
    calcTotalZones();
    calcTotalAnimals();

    zoneAddToGlobalTime=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valGlobalTimeAdd","{}"),"do_main/zoneAddToGlobalTime",{}); //TODO name change

    totalErnte=new Array(new Object(),new Object(),new Object()); // Value of products the farm currently produces
    totalFarmis=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_totalFarmis","[{},{}]"),"do_main/totalFarmis",[{},{}]); // Value of products the farmis want
    totalPowerups=new Object(); // Value of powerups creating products
    totalQuest=new Object(); // Value of products the quests need: totalQuest[questType][prodType][prodId]=amount
    totalRecursive=new Array(new Object(), new Object());
    
    /*
    function findRecursiveNeededProducts(type,iProd,amount,addto){ //addto=new Array(new Object(), new Object());
        if(prodRequire[type]&&prodRequire[type][iProd]){
            //if(DEVMODE_FUNCTION){GM_log("Begin findRecursiveNeededProducts name:"+prodName[type][iProd]+" iProd:"+iProd+" amount:"+amount+" totalRecursive:"+implode(totalRecursive,"findRecursiveNeededProducts\totalRecursive"));}
            var help;
            for(var i in prodRequire[type][iProd]){
                if (!prodRequire[type][iProd].hasOwnProperty(i)){ continue; }
                help=prodRequire[type][iProd][i];
                if (help[0]==type&&help[1]==iProd){continue;}
                pAmount = Math.ceil((parseInt(help[2],10)*amount)/(prodYield[type][iProd]?prodYield[type][iProd]:1));
                if(!addto){
                    if(!totalRecursive[help[0]][help[1]]){totalRecursive[help[0]][help[1]]=0;}
                    totalRecursive[help[0]][help[1]]+=pAmount;
                }else{
                    if(!addto[help[0]][help[1]]){addto[help[0]][help[1]]=0;}
                    addto[help[0]][help[1]]+=pAmount;
                }
                if(prodRequire[help[0]][help[1]]){//&&!(help[0]==type&&help[1]==iProd)){
                    findRecursiveNeededProducts(help[0],parseInt(help[1],10),pAmount,addto);
                }
            }
            help=null;
            //if(DEVMODE_FUNCTION){GM_log("End findRecursiveNeededProducts name:"+prodName[type][iProd]+" iProd:"+iProd+" amount:"+amount+" totalRecursive:"+implode(totalRecursive,"findRecursiveNeededProducts/totalRecursive"));}
        }
    }
    */
    calcTotalPowerups();
    // Value of active powerup for a field
    // currentPowerup[plantNr]=[time,+value,+points]
    var currentPowerup=new Object;
    function calcCurrentPowerup(){
    try{
        currentPowerup=new Object;
        if(unsafeWindow.poweruprack){
            for(var i in unsafeWindow.poweruprack){
                if(!unsafeWindow.poweruprack.hasOwnProperty(i)){continue;}
                var item=unsafeWindow.poweruprack[i];
                if((item[5])&&(item["remain"]>0)){
                    if(item[5][1]){
                        currentPowerup[item[5][1][0]]=[item["remain"]+unsafeWindow.Zeit.Server,item[5][1][1],0];
                        var newdiv=$("powerupSymbol"+item["0"]);
                        if(!newdiv){
                            newdiv=createElement("div",{"id":"powerupSymbol"+item["0"],"style":"position:relative;width:60px;height:87px;margin-bottom:5px;","end":item["remain"]+unsafeWindow.Zeit.Server},nodes["containerPowerupSymbols"]["node"]);
                            newdiv.addEventListener("mouseover",function(event){
                                var end=parseInt(this.getAttribute("end"),10);
                                var endDay=countDays(now,end);
                                toolTip.show(event,(getText("day"+endDay)?getText("day"+endDay):(new Date(1000*end).toLocaleString()))+"<br>"+getDaytimeStr(end));
                            },false);
                            createElement("img",{"src":GFX+"powerup2.png","border":"0"},newdiv);
                            createElement("div",{"style":"position:absolute;top:3px;left:6px;","class":"kp"+item[5][1][0]},newdiv);
                            createElement("div",{"style":"position:absolute;top:3px;left:22px;font-weight:bold;color:black;"},newdiv,"+"+item[5][1][1]);
                            createElement("div",{"style":"position:absolute;top:64px;right:0;font-weight:bold;","class":"blackbox"},newdiv,getTimeStr(item["remain"]));
                        }
                        newdiv=null;
                    }
                    if(item[5][2]){
                        currentPowerup[item[5][2][0]]=[item["remain"]+unsafeWindow.Zeit.Server,0,item[5][2][1]];
                        var newdiv=$("powerupSymbol"+item["0"]);
                        if(!newdiv){
                            newdiv=createElement("div",{"id":"powerupSymbol"+item["0"],"style":"position:relative;width:60px;height:87px;margin-bottom:5px;","end":item["remain"]+unsafeWindow.Zeit.Server},nodes["containerPowerupSymbols"]["node"]);
                            newdiv.addEventListener("mouseover",function(event){
                                var end=parseInt(this.getAttribute("end"),10);
                                var endDay=countDays(now,end);
                                toolTip.show(event,(getText("day"+endDay)?getText("day"+endDay):(new Date(1000*end).toLocaleString()))+"<br>"+getDaytimeStr(end));
                            },false);
                            createElement("img",{"src":GFX+"powerup3.png","border":"0"},newdiv);
                            createElement("div",{"style":"position:absolute;top:3px;left:6px;","class":"kp"+item[5][2][0]},newdiv);
                            createElement("div",{"style":"position:absolute;top:3px;left:22px;font-weight:bold;color:black;"},newdiv,"+"+item[5][2][1]);
                            createElement("div",{"style":"position:absolute;top:64px;right:0;font-weight:bold;","class":"blackbox"},newdiv,getTimeStr(item["remain"]));
                        }
                        newdiv=null;
                    }
                }
            }
        }
        unsafeData.currentPowerup=currentPowerup.clone();
    }catch(err){ GM_logError("calcCurrentPowerup\n"+err); }
    }
    calcCurrentPowerup();

    // powerup-data is updated
    // function isnt available anymore?
    unsafeOverwriteFunction("handlePowerups",function(page){
        try{
            unsafeWindow._handlePowerups(page);
        }catch(err){ GM_logError("_handlePowerups\n"+err); }
        try{
            // GM_log("unsafeWindow.poweruprack:\n"+implode(unsafeWindow.poweruprack));         
            calcTotalPowerups();
            updateProductDataPowerup();
            window.setTimeout(saveProductData,0);
            raiseEvent("gamePoweruprackUpdated");
        }catch(err){ GM_logError("handlePowerups\n"+err); }
    });

    unsafeOverwriteFunction("activatePowerup",function(formula){
        try{
            unsafeWindow._activatePowerup(formula);
        }catch(err){ GM_logError("_activatePowerup\n"+err); }
        try{
            document.addEventListener("gamePoweruprackUpdated",function(){
            try{
                calcCurrentPowerup();
                for(var v=0;v<ALL_ZONES["farm"].length;v++){ zones.processProduction(ALL_ZONES["farm"][v]); } //TODO
                calcProdMinRack();
                raiseEvent("gamePowerupActivated");
                this.removeEventListener("gamePoweruprackUpdated",arguments.callee,false);
            }catch(err){ GM_logError("listener gamePoweruprackUpdated\n"+err); }
            },false);
        }catch(err){ GM_logError("activatePowerup\n"+err); }
    });
    err_trace="valAutoWater";
    valAutoWater=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valAutoWater"),"valAutoWater",null); // TODO set true when automat handles it
    if(valAutoWater==null){
        valAutoWater={"farm":false,"forestry":true};
        GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valAutoWater",implode(valAutoWater,"valAutoWater"));
    }
    unsafeData.valAutoWater=valAutoWater;
    valWaterNeeded=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valWaterNeeded"),"valWaterNeeded",null);
    if(valWaterNeeded==null){
        valWaterNeeded={"farm":true,"forestry":true};
        GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valWaterNeeded",implode(valWaterNeeded,"valWaterNeeded"));
    }
    unsafeData.valWaterNeeded=valWaterNeeded;
    valAssumeWater=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valAssumeWater"),"valAssumeWater",null);
    if(valAssumeWater==null){
        valAssumeWater={"farm":true,"forestry":true};
        GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valAssumeWater",implode(valAssumeWater,"valAssumeWater"));
    }
    valAutoCrop=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valAutoCrop"),"valAutoCrop",null);
    if(valAutoCrop==null){
        valAutoCrop={"farm":false,"forestry":true};
        GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valAutoCrop",implode(valAutoCrop,"valAutoCrop"));
    }
    unsafeData.valAutoCrop=valAutoCrop;
    valErnteMsg=GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valErnteMsg",false);
    valLimitEmptyFields=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valLimitEmptyFields"),"valLimitEmptyFields",null);
    if(valLimitEmptyFields==null){
        valLimitEmptyFields={"1":3,"fl1":0,"forest":1};
        GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valLimitEmptyFields",implode(valLimitEmptyFields,"valLimitEmptyFields"));
    }
    if(typeof GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valKauflimit",110)=="number"){ GM_deleteValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valKauflimit"); }
    valKauflimit=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valKauflimit","[[85,'990000'],110]"),"do_main/valKauflimit",[[85,'990000'],110]);
    valMessagesSystemMarkRead=GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valMessagesSystemMarkRead",true);
    valFoodworldFarmiPlacing=GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valFoodworldFarmiPlacing",true);
    valStatistik=GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valStatistik",true);
    // valClickErrorbox=GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valClickErrorbox",false);
    valGlobaltimeShowCroppedZone=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valGlobaltimeShowCroppedZone"),"valGlobaltimeShowCroppedZone",null);
    if(!valGlobaltimeShowCroppedZone||(typeof valGlobaltimeShowCroppedZone!="object")||(valGlobaltimeShowCroppedZone instanceof Array)){ 
        valGlobaltimeShowCroppedZone={"farm":true,"windmill":true,"forestry":true};
        GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valGlobaltimeShowCroppedZone",implode(valGlobaltimeShowCroppedZone,"valGlobaltimeShowCroppedZone"));
    } 
    unsafeData.readyZone=new Object;
    unsafeData.zoneAddToGlobalTime=zoneAddToGlobalTime.clone();

    // Werbung
    err_trace="Advertisement";
    upjersAds=new Array();
    for(var v in unsafeWindow.welcomeblurb){
        if(!unsafeWindow.welcomeblurb.hasOwnProperty(v)){ continue; }
        if(v!="1"){
            upjersAds.push(unsafeWindow.welcomeblurb[v]);
            delete unsafeWindow.welcomeblurb[v];
        }
    }
    unsafeWindow.gclr();
    newdiv=createElement("img",{"style":"position:absolute;top:0;right:0;height:15px;width:15px;","class":"link","src":GFX+"points.gif"},$("headercontainer"));
    newdiv.addEventListener("mouseover",function(event){ toolTip.show(event,getText("upjersAdvertising")); },false);
    newdiv.addEventListener("click",function(){ unsafeWindow.buildInfoPanel("upjersAds"); },false);
    $("notepad").style.zIndex=111; // Notizen on top
    unsafeWindow.shredderCommit = function(){return;}; // Schredder weg

    // Dragging
    err_trace="Dragging";
    if(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valDrag",false)){
        $("gameArea").style.position="absolute";
        $("gameArea").style.top="5px";
        $("gameArea").style.left="5px";
        makeDraggable($("notepad"));
        makeDraggable($("divGame"),true,false);
        //makeDraggable("gardenmaincontainer");
        //makeDraggable("innermaincontainer");
        $("globaltransp").style.height="0";
        //$("transp").style.height="0";
    }

    // speedlinks
    err_trace="speedlinks";
    if(unsafeWindow.premium!=1){
        unsafeOverwriteFunction("speedLinks",function(){
            try{
                unsafeWindow._speedLinks();
            }catch(err){GM_logError("_speedLinks\n"+err);}
            try{  // taken from game-js and modified to run without premium
                var err_trace="init";
                if (!unsafeWindow.premium){
                    unsafeWindow.showDiv("farm_speedlinks");
                    var a = ["farm1", "farm2", "farm3", "farm4", "city1", "city2", "guild", "forestry", "foodworld"];
                    for (var b = 0; b <= a.length; b++) {
                        if ($("speedlink_" + a[b])) {
                            unsafeWindow.hideDiv($("speedlink_" + a[b]));
                            $("speedlink_" + a[b]).className = "speedlink link speedlink_" + a[b];
                            $("speedlink_" + a[b]).onclick = new Function("")
                        }
                    }
                    err_trace="farm";
                    for (var b = 1; b <= unsafeWindow.farmamount; b++) {
                        if (unsafeWindow.farm == b) {
                            $("speedlink_farm" + b).classList.remove("speedlink_farm" + b);
                            $("speedlink_farm" + b).classList.add("speedlink_farm" + b + "_active")
                        }
                        unsafeWindow.showDiv("speedlink_farm" + b);
                        $("speedlink_farm" + b).onclick = new Function("unsafeWindow.farm=" + b + "; unsafeWindow.farmMove(" + b + "); unsafeWindow.showMain();")
                    }
                    err_trace="city";
                    for (var b = 1; b <= 2; b++) {
                        if (unsafeWindow.city == b) {
                            $("speedlink_city" + b).classList.remove("speedlink_city" + b);
                            $("speedlink_city" + b).classList.add("speedlink_city" + b + "_active")
                        }
                        unsafeWindow.showDiv("speedlink_city" + b);
                            if(b == 1){
                                $("speedlink_city" + b).onclick = new Function("unsafeWindow.close_page();unsafeWindow.showDiv('transp3');unsafeWindow.initCity(1);");
                                
                            }else{
                                $("speedlink_city" + b).onclick = new Function("unsafeWindow.travel2City2();")
                            }           
                        if (b == 2 && unsafeWindow.currentuserlevel < 8) {
                            unsafeWindow.hideDiv("speedlink_city" + b)
                        } else {
                            unsafeWindow.showDiv("speedlink_city" + b)
                        }
                    }
                        err_trace="player_guild";
                    if (unsafeWindow.player_guild) {
                        if (unsafeWindow.inguild) {
                            $("speedlink_guild").classList.remove("speedlink_guild");
                            $("speedlink_guild").classList.add("speedlink_guild_active")
                        }
                        unsafeWindow.showDiv("speedlink_guild");
                        $("speedlink_guild").onclick = new Function("unsafeWindow.inguild=1; unsafeWindow.showMain(); unsafeWindow.initGuild();")
                    }
                        err_trace="forestry";
                    if (unsafeWindow.forestry_unlock == 1) {
                        if (unsafeWindow.forestry_quicknavi) {
                            $("speedlink_forestry").classList.remove("speedlink_forestry");
                            $("speedlink_forestry").classList.add("speedlink_forestry_active")
                        }
                        unsafeWindow.showDiv("speedlink_forestry");
                        $("speedlink_forestry").onclick = new Function("unsafeWindow.travel2forestry();")
                    }
                        err_trace="foodworld";
                    if (unsafeWindow.currentuserlevel >= 11) {
                        if (unsafeWindow.foodworld_quicknavi) {
                            $("speedlink_foodworld").classList.remove("speedlink_foodworld");
                            $("speedlink_foodworld").classList.add("speedlink_foodworld_active")
                        }
                        unsafeWindow.showDiv("speedlink_foodworld");
                        $("speedlink_foodworld").onclick = new Function("unsafeWindow.travel2foodworld();")
                    }
                        err_trace="newarea";
                    unsafeWindow.hideDiv("speedlink_farmersmarket");
                    if (unsafeWindow.farmersmarket_data) {
                        unsafeWindow.showDiv("speedlink_farmersmarket");
                        $("speedlink_farmersmarket").onclick = new Function("unsafeWindow.travel2farmersmarket();")
                    }
                }       
            }catch(err){GM_logError("speedLinks ("+err_trace+")\n"+err);}
        });
        unsafeWindow.speedLinks();
        unsafeWindow.travel2City2 = function(){
        try{
            switch(gameLocation[0]){
            case "city": unsafeWindow.initCity(2); break;
            case "forestry": 
            case "foodworld": unsafeWindow.initCity(2,0,1); break;
            default:{
                document.addEventListener("gameCity1",function(){
                    unsafeWindow.travel2City2();
                    document.removeEventListener("gameCity1",arguments.callee,false);
                },false);
                unsafeWindow.initCity(1);
            }
            }
        }catch(err){GM_logError("travel2City2\n"+err);}     
        };
        unsafeWindow.travel2forestry = function(){
        try{
            if((gameLocation[0]=="forestry")||((gameLocation[0]=="city")&&(gameLocation[1]==2))){
                unsafeWindow.farm=0; 
                unsafeWindow.city=0; 
                unsafeWindow.forestry_quicknavi=1;
                unsafeWindow.initForestry();
            }else{
                document.addEventListener("gameCity2",function(){
                    unsafeWindow.travel2forestry();
                    document.removeEventListener("gameCity2",arguments.callee,false);
                },false);
                unsafeWindow.travel2City2();
            }
        }catch(err){GM_logError("travel2forestry\n"+err);}
        };
        unsafeWindow.travel2foodworld = function(){
        try{
            if((gameLocation[0]=="foodworld")||((gameLocation[0]=="city")&&(gameLocation[1]==2))){
                unsafeWindow.farm=0; 
                unsafeWindow.city=0; 
                unsafeWindow.foodworld_quicknavi=1;
                unsafeWindow.foodworldAction('init');
            }else{
                document.addEventListener("gameCity2",function(){
                    unsafeWindow.travel2foodworld();
                    document.removeEventListener("gameCity2",arguments.callee,false);
                },false);
                unsafeWindow.travel2City2();
            }
        }catch(err){GM_logError("travel2foodworld\n"+err);}
        };
        unsafeWindow.travel2farmersmarket = function(){
        try{
            switch(gameLocation[0]){
            case "farm": case "farmersmarket":{
                unsafeWindow.farmMove(99);
            break;}
            case "city":{
                document.addEventListener("gameFarmOpened",function(){
                    unsafeWindow.travel2farmersmarket();
                    document.removeEventListener("gameFarmOpened",arguments.callee,false);
                },false);
                unsafeWindow.showTravel2Farm(1);
            break;}
            default:{
                document.addEventListener("gameCity2",function(){
                    unsafeWindow.travel2farmersmarket();
                    document.removeEventListener("gameCity2",arguments.callee,false);
                },false);
                unsafeWindow.initCity(2,0,1);;
            }
            }
        }catch(err){GM_logError("travel2farmersmarket\n"+err);}
        };
        
    }
    // andere ServerAccounts
    err_trace="Other accounts on server";
    var farmNamen=explode(GM_getValue(COUNTRY+"_"+SERVER+"_farmNamen","{}"),"do_main/farmNamen",{});
    farmNamen[USERNAME]=FARMNAME;
    if(farmNamen[USERNAME].toLowerCase()!=USERNAME){
        newdiv=createElement("div",{"class":"userinfositem link","style":"font-weight: bold;"});
        newdiv.innerHTML="("+USERNAME+")";
        newdiv1=$("userinfoscontainer");
        newdiv1.insertBefore(newdiv,newdiv1.children[1]);
    }
    GM_setValue(COUNTRY+"_"+SERVER+"_farmNamen",implode(farmNamen));

    var otherAccs=new Array();
    function calcOtherAccs(){
    try{
        otherAccs=new Array();
        var help=explode(GM_getValue("logindata","[]"),"do_main/logindata",[]);
        var help2;
        for(var v=0;v<help.length;v++){
            if((help[v][4]) && (help[v][0]==COUNTRY) && (help[v][1]==SERVER)){
                help2=[v,help[v][2],NEVER];
                if(help2[1].toLowerCase()==USERNAME){ // this account
                    help2[0]=-1;
                }else{
                    try{
                        help2[2]=GM_getValue(help[v][0]+"_"+help[v][1]+"_"+help[v][2].toLowerCase()+"_totalEndtime");
                    }catch(err){}
                }
                otherAccs.push(help2);
            }
            if(!farmNamen[help[v][2]]){ farmNamen[help[v][2]]=help[v][2]; }
        }
    }catch(err){GM_logError("calcOtherAccs\n"+err);}
    }
    calcOtherAccs();
    function testOtherAccReady(){
    try{
        var found=null;
        for(var v=0;v<otherAccs.length;v++){ if(otherAccs[v][0]>-1){
            if (otherAccs[v][2]+unsafeWindow.Zeit.Verschiebung<now){
                found=v;
                break;
            }
        }}
        if(found!=null){
            var cell=$("bubble_adtext");
            if(!cell){ cell=$("sprcontent"); }
            cell.innerHTML="";
            cell=createElement("a",{"id":"linkOtherAccReady","class":"link","dologin":otherAccs[found][0],"href":"#","style":"font-weight:bold;"},createElement("div",{"style":"height:50px;"},cell),farmNamen[otherAccs[found][1]]+" "+getText("finished").toLowerCase()+"!");
            cell.addEventListener("click",function(){
            try{
                var dologin=parseInt(this.getAttribute("dologin"),10);
                window.setTimeout(function(dologin){
                try{
                    var help=explode(GM_getValue(COUNTRY+"_pagedataLogin","{}"),"testOtherAccReady/pagedataLogin",{});
                    if(!(help["dologin"]&&(typeof help["dologin"]=="object"))){
                        help["dologin"]=new Object();
                    }
                    help["dologin"][dologin]=true;
                    GM_setValue(COUNTRY+"_pagedataLogin",implode(help));
                    if($("logoutbutton")){
                        click($("logoutbutton"));
                    } else if(GAMEPAGES[COUNTRY]){
                        location.href="http://www."+GAMEPAGES[COUNTRY]+"/login.php?start=1";
                    }
                }catch(err){ GM_logError("listener linkOtherAccReady.click\n"+err); }
                },0,dologin);
            }catch(err){ GM_logError("listener linkOtherAccReady.click\n"+err); }
            },false);
            cell=null;
            raiseEvent("gameOtherAccReady");
        }else{
            window.setTimeout(testOtherAccReady,5000);
        }
    }catch(err){GM_logError("testOtherAccReady\n"+err);}
    }
    if (otherAccs.length>1){
        newdiv=createElement("div",{"id":"divOtherAccountsTimes","class":"blackbox","style":"position:absolute;top:5px;right:150px;border:2px solid black;padding:2px;z-index:300;display:none;"},$("headercontainer"));
        newdiv.addEventListener("mouseout",function(){this.style.display="none";},false);
        newdiv.addEventListener("mouseover",function(){this.style.display="";},false);
        newdiv=createElement("div",{"style":"position:absolute;top:4px;right:220px;font-size:11px;color:#f7bb87;","class":"link"},$("headercontainer"));
        createElement("div",{"style":"display:inline-block;margin-bottom:2px;margin-right:2px;text-decoration:underline;vertical-align:top;font-size:11px;"},newdiv,getText("login"));
        newdiv1=createElement("div",{"style":"display:inline-block;"},newdiv);
        createElement("img",{"border":"0","src":GFX+"menu/logout.gif"},newdiv1);
        newdiv.addEventListener("mouseout",function(){$("divOtherAccountsTimes").style.display="none";},false);
        function fillDivOtherAccountsTimes(){
            divOtherAccountsTimes=$("divOtherAccountsTimes");
            if(divOtherAccountsTimes.style.display=="none"){
                divOtherAccountsTimes.innerHTML="";
            }else{
                var newtable=createElement("table",{"cellspacing":"0"},newdiv);
                var newtr,newtd;
                for(var v=0;v<otherAccs.length;v++){
                    if(otherAccs[v][0]>-1){
                        newtr=createElement("tr",{"class":"link hoverBgCc9","dologin":otherAccs[v][0]},newtable);
                        newtr.addEventListener("click",function(){
                            var dologin=parseInt(this.getAttribute("dologin"),10);
                            window.setTimeout(function(dologin){
                                var help=explode(GM_getValue(COUNTRY+"_pagedataLogin","{}"),"fillDivOtherAccountsTimes/pagedataLogin",{});
                                if(!(help["dologin"]&&(typeof help["dologin"]=="object"))){
                                    help["dologin"]=new Object();
                                }
                                help["dologin"][dologin]=true;
                                GM_setValue(COUNTRY+"_pagedataLogin",implode(help));
                                if($("logoutbutton")){
                                    click($("logoutbutton"));
                                } else if(GAMEPAGES[COUNTRY]){
                                    location.href="http://www."+GAMEPAGES[COUNTRY]+"/login.php?start=1";
                                }
                            },0,dologin);
                        },false);
                    }else{
                        newtr=createElement("tr",{"class":"fontWeightBold"},newtable);
                        otherAccs[v][2]=totalEndtime;
                    }
                    createElement("td",{},newtr,farmNamen[otherAccs[v][1]]);
                    newtd=createElement("td",{"style":"padding-left:5px;"},newtr);
                    var help=unsafeWindow.Zeit.Verschiebung+otherAccs[v][2];
                    if (help>now){ newtd.innerHTML=getTimeStr(help-now); }
                    else{ newtd.innerHTML=getText("finished").toLowerCase()+"!"; }
                }
                divOtherAccountsTimes.innerHTML="";
                divOtherAccountsTimes.appendChild(newtable);
                newtable=null;newtr=null;newtd=null;
                window.setTimeout(fillDivOtherAccountsTimes,1000);
            }
            divOtherAccountsTimes=null;
        }
        newdiv.addEventListener("mouseover",function(){
            $("divOtherAccountsTimes").style.display="";
            fillDivOtherAccountsTimes();
        },false);
        help=NEVER;
        for(var v=otherAccs.length-1;v>=0;v--){
            if(otherAccs[v][0]>-1){
                help=Math.min(help,otherAccs[v][2]);
            }
        }
        if(help<NEVER){
            window.setTimeout(testOtherAccReady,Math.max(0,help+unsafeWindow.Zeit.Verschiebung-now));
        }
    }

    // SessionEnd
    err_trace="SessionEnd";
    //window.setTimeout('top.location.href="main.php?page=logout";','4457000');  in the gamepage
    function timerSessionEnd(sec){
    try{
        if(sec<1){
            var help=explode(GM_getValue(COUNTRY+"_pagedataLogin","{}"),"timerSessionEnd/pagedataLogin",{});
            if(!(help["doserver"]&&(typeof help["doserver"]=="object"))){
                help["doserver"]=new Object();
            }
            help["doserver"][SERVER]=true;
            GM_setValue(COUNTRY+"_pagedataLogin",implode(help));
            if($("logoutbutton")){
                click($("logoutbutton"));
            } else if(GAMEPAGES[COUNTRY]){
                location.href="http://www."+GAMEPAGES[COUNTRY]+"/login.php?start=1";
            }
        }else{
            window.setTimeout(function(){ timerSessionEnd(sec-1); },1000);
            $("divSessionEndTime").innerHTML=getTimeStr(sec);
        }
    }catch(err){ GM_logError("timerSessionEnd\n"+err); }
    }
    var valSessionEndtime=null;
    if (unsafeWindow.logout_remain){
        valSessionEndtime=Math.floor(now+unsafeWindow.logout_remain);
        window.setTimeout(function(){
            var newdiv=createElement("div",{"id":"divSessionEnd","class":"alertbubble tbig link"},ALL,getText("relogin").replace(/%1%/,"<span id='divSessionEndTime'>0</span>"));
            newdiv.addEventListener("click",do_relogin,false);
            timerSessionEnd(Math.max(0,valSessionEndtime-now-30));
            newdiv=null;
            raiseEvent("gameSessionEnds");
        },Math.max(1,1000*unsafeWindow.logout_remain-getRandom(600000,1800000)));
    }

    // Statistik
    err_trace="Statistic";
    if (STAT_SERVER[COUNTRY]){
        function buildStatistik(mode){
        try{
            var modeDefault={"category":"c","npc":true,"showAll":false,"time":120};
            var modeOld=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_modeStatistic"),"buildStatistik/modeOld");
            if(typeof modeOld!="object"){ modeOld=modeDefault; }
            if(typeof mode!="object"){ mode=modeOld; }
            for(var v in modeDefault){
                if(!modeDefault.hasOwnProperty(v)){ continue; }
                if(mode[v]==undefined){ mode[v]=(modeOld[v]==undefined?modeDefault[v]:modeOld[v]); }
            }
            GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_modeStatistic",implode(mode,"buildStatistik/mode"));      
            var container=$("statisticArea");
            container.innerHTML="";

            // Header
            var newdiv=createElement("div",{"style":"position:fixed;width:90%;margin-left:5%;z-index:10;border:2px solid black;color:black;background-color:#ccf;"},container);
            var newselect=createElement("select",{"class":"link","style":"margin-right:20px;"},newdiv);
            createElement("option",{"value":"24"},newselect,getText("stat_days1"));
            createElement("option",{"value":"72"},newselect,getText("stat_days3"));
            createElement("option",{"value":"120"},newselect,getText("stat_days5"));
            createElement("option",{"value":"168"},newselect,getText("stat_days7"));
            newselect.value=mode["time"];
            newselect.addEventListener("change",function(){
                buildStatistik({"time":parseInt(this.value,10)});
            },false);

            newselect=createElement("input",{"type":"checkbox","class":"link","checked":mode["npc"]},newdiv);
            newselect.addEventListener("click",function(){
                buildStatistik({"npc":this.checked});
            },false);
            createElement("span",{"style":"margin-right:20px;"},newdiv,getText("NPC"));

            newselect=createElement("input",{"type":"checkbox","class":"link","checked":mode["showAll"]},newdiv);
            newselect.addEventListener("click",function(){
                buildStatistik({"showAll":this.checked});
            },false);
            createElement("span",{"style":"margin-right:20px;"},newdiv,getText("showAll"));

            var help={};
            for (var v=0;v<prodBlock[0].length;v++){
                if(prodBlock[0][v]==undefined){ continue; }
                if((!prodBlock[0][v].match(/t/))&&(mode["showAll"]||!prodBlock[0][v].match(/[lq]/))){
                    help[prodTyp[0][v]]=true;
                }
            }
            newselect=createElement("select",{"class":"link","style":"margin-right:20px;"},newdiv);
            for(var v in help){
                if(!help.hasOwnProperty(v)){ continue; }
                createElement("option",{"value":v},newselect,getText("category_"+v));
            }
            newselect.value=mode["category"];
            newselect.addEventListener("change",function(){
                buildStatistik({"category":this.value});
            },false);
            newselect=createElement("img",{"class":"link","src":GFX+"close.jpg","style":"position:absolute;top:8px;right:8px;width:20px;height:20px;"},newdiv);
            newselect.addEventListener("click",function(){
                $("gameArea").style.display="block";
                $("statisticArea").style.display="none";
                $("statisticArea").innerHTML="";
            },false);
            

            // Body
            newdiv=createElement("div",{"style":"overflow-y:auto;overflow-x:hidden;color:black;padding-top:30px;"},container);
            var newdiv1,newimg,newobject;
            for (var v=0;v<prodName[0].length;v++){
                if(prodName[0][v]==undefined){ continue; }
                if ((prodTyp[0][v]==mode["category"])&&(!prodBlock[0][v].match(/t/))&&(mode["showAll"]||!prodBlock[0][v].match(/[lq]/))){
                    newdiv1=createElement("div",{"id":"stat"+v,"class":"link smallStatistic"},newdiv);
                    if(prodBlock[0][v]){
                        createElement("div",{"style":"height:14px;font-weight:bold;color:red;"},newdiv1,prodName[0][v]+", "+moneyFormat(gut[v]));
                    }else{
                        createElement("div",{"style":"height:14px;font-weight:bold;"},newdiv1,prodName[0][v]+", "+numberFormat(prodStock[0][v],0)+", "+moneyFormat(gut[v])+", "+moneyFormat(gutBeob[v]));
                    }
                    var url=STAT_SERVER[COUNTRY]+"/chart.php?w=400&h=200&t=h"+mode["time"]+"&shownpc="+(mode["npc"]?1:0)+"&clip=1&lng1="+COUNTRY+"&server1="+SERVER+"&product1="+v+"&color1=green";
                    newobject=createElement("object",{"data":url,"type":"type=image/svg+xml","width":"400px","height":"200px"},newdiv1);
                    createElement("param",{"name":"src","value":url},newobject);
                    createElement("div",{"class":"v"+v,"style":"position:absolute;bottom:10px;left:10px;z-index:2;"},newdiv1);
                    createElement("div",{"style":"position:absolute;top:0;left:0;width:100%;height:100%;z-index:2;"},newdiv1);
                    newdiv1.addEventListener("click",function(){
                        showStatisticFullscreen(this.id.replace("stat",""));
                    },false);
                } 
            }
            /*
            if (isNaN(mode)){
            }else{
                newdiv1=createElement("div",{"style":"margin:5px;"},newdiv);
                createElement("div",{"style":"font-weight:bold"},newdiv1,prodName[0][mode]+", "+numberFormat(prodStock[0][mode],0)+", "+moneyFormat(gut[mode])+", "+moneyFormat(gutBeob[mode]));
                var breit=(window.innerWidth-60);
                var hoch=(window.innerHeight-130);
                var url=STAT_SERVER[COUNTRY]+"/chart.php?w="+breit+"&h="+hoch+"&t=h"+mode["time"]+"&shownpc="+(mode["npc"]?1:0)+"&clip=1&lng1="+COUNTRY+"&server1="+SERVER+"&product1="+mode+"&color1=green";
                newobject=createElement("object",{data:url,"type":type="image/svg+xml","width":breit+"px","height":hoch+"px"},newdiv1);
                createElement("param",{"name":"src","value":url},newobject);
                createElement("div",{"class":"v"+mode,"style":"position:relative;top:-40px;left:10px;z-index:2"},newdiv1);
            }
            */
            newdiv1=null;newimg=null;newobject=null;

            container=null;newdiv=null;newselect=null;newselect=null;
        }catch(err){ GM_logError("buildStatistik\nmode="+implode(mode)+"\n"+err); }
        }
        function sendStatData (){
        try{
            if(STAT_SERVER[COUNTRY]){
                var prodStr="";
                var preisBeob=explode(GM_getValue(COUNTRY+"_"+SERVER+"_preisBeob","[]"),"sendStatData/preisBeob",[]); //isNotSent,time,min,max,amount
                var bChanged=false;
                if(!(preisBeob instanceof Array)){
                    preisBeob=new Array();
                    bChanged=true;
                }
                gutBeob=explode(GM_getValue(COUNTRY+"_"+SERVER+"_gutBeob","[]"),"sendStatData/gutBeob",[]);
                var c=0;
                var neededTime=now-300; // Data max 5min old
                for(var v=0;v<preisBeob.length;v++){
                    if(preisBeob[v] && preisBeob[v][0] && (neededTime<preisBeob[v][1]) && (0<preisBeob[v][2]) && (preisBeob[v][2]<=gutBeob[v]) && (gutBeob[v]<=preisBeob[v][3])){
                        prodStr += ',\"product'+(++c)+'\":{\"product_id\":'+v+',\"avg_price\":'+gutBeob[v]+',\"min_price\":'+preisBeob[v][2]+',\"max_price\":'+preisBeob[v][3]+'}';
                        preisBeob[v][0]=false;
                        bChanged=true;
                    }
                }
                if(bChanged){
                    GM_setValue2(COUNTRY+"_"+SERVER+"_preisBeob",implode(preisBeob),8);
                    raiseEventTop("gameChangedBeobPrice");
                }
    
                if (c>0){
                    logBubble.add(getText("sendingXObservedPricesToServer").replace(/%1%/,c));
                    // GM_log("sendStatData sending:\n" + STAT_SERVER[COUNTRY]+'/add.php?json={\"server\":'+SERVER+',\"COUNTRY\":'+COUNTRY+',\"productcount\":'+c+prodStr+'}')
                    GM_xmlhttpRequest({
                    method: "POST",
                    url: STAT_SERVER[COUNTRY]+"/add.php",
                    data: 'json={\"server\":'+SERVER+',\"COUNTRY\":\"'+COUNTRY+'\",\"productcount\":'+c+prodStr+'}',
                    headers: {
                        "Content-Type": "application/x-www-form-urlencoded"
                    },
                    onload: function(c){
                        return function(response){
                            try{
                                logBubble.add(getText("sendingXObservedPricesToServer").replace(/%1%/,c)+" "+response.responseText)
                            }catch(err){GM_logError("sendStatData.onload\n"+err);}          
                        }
                    }(c),
                    onerror: function(response){
                        GM_logError("sendStatData.onerror\n"+response.responseText);
                    },
                    timeout: function(response){
                        GM_logError("sendStatData.timeout\n"+response.responseText);
                    }           
                    });
                    c=null;
                }
            }
        }catch(err){ GM_logError("sendStatData\n"+err); }
        }
        if(STAT_VIEW && STAT_VIEW[COUNTRY]){
            newdiv=createElement("div",{"id":"divBeraterButtonsStatistic","class":"link beraterButtonIcon hoverBgGreen","mouseOverText":getText("stat_stats")},$("divBeraterButtons"));
            createElement("img",{"src":IMAGES["graph"],"style":"position:relative;top:2px;left:0;width:25px;height:25px;"},newdiv);
            newdiv.addEventListener("click",function(){
                $("gameArea").style.display="none";
                $("statisticArea").style.display="block";
                buildStatistik();
            },false);
        }
        if (valStatistik && STAT_SERVER && STAT_SERVER[COUNTRY]){
            sendStatData();
            window.setInterval(function (){
                sendStatData();
            },310000);
        }
    }
    
    err_trace="Rack bottom";
    if(newdiv=$("canvassracklink")){
        newdiv.style.height = "55px";
    }
    if(newdiv=$("forumracklink")){
        newdiv.style.height = "55px";
    }
    if(newdiv=$("rackBottom")){
        // Spieler suchen
        newinput=createElement("input",{"value":getText("searchPlayer"),"class":"text","style":"position:absolute;top:60px;left:125px;width:85px;background:transparent;border:1px solid black;"},newdiv);
        newinput.addEventListener("click",function(){this.value="";},false);
        newinput.addEventListener("blur",function(){this.value=getText("searchPlayer");},false);
        newinput.addEventListener("keyup",function(event){
            try{
                if (event.keyCode==13){
                    // showShopframePage("http://s"+SERVER+"."+GAMEPAGES[COUNTRY]+"/stadt/stats.php?search=1&searchterm="+this.value);
                }
            }catch(err){ GM_logError("listener searchPlayer.keyup\n"+err); }
        },false);
        // Farmpedia
        newinput=createElement("a",{"href":getText("farmpediaUrl"),"target":"_blank","style":"position:absolute;top:55px;left:100px;z-index:2;","class":"link"},newdiv);
        createElement("img",{"style":"width:25px;height:25px;border:none;","src":GFX+"points.gif"},newinput);
        newinput.addEventListener("mouseover",function(event){ toolTip.show(event,getText("farmpedia")); },false);
    }

    // InfoPanel
    err_trace="InfoPanel";
    if (newdiv=$("speedlinks")){ newdiv.addEventListener("click",closeInfoPanel,false); }
    if (newdiv=$("cityline")){ newdiv.addEventListener("click",closeInfoPanel,false); }

    // Profit
    err_trace="Profit";
    newdiv=createElement("div",{"id":"divBeraterButtonsProfit","class":"link beraterButtonIcon hoverBgGreen","mouseOverText":getText("profitTable")},$("divBeraterButtons"));
    createElement("img",{"src":GFX+"farmhouse/items/76_1.png","style":"position:relative;top:-5px;left:-5px;width:40px;height:40px;"},newdiv);
    newdiv.addEventListener("click",function(){ unsafeWindow.buildInfoPanel("profit"); },false);
    
    // Preise
    err_trace="Prices";
    newdiv=createElement("div",{"id":"divBeraterButtonsPreise","class":"link beraterButtonIcon hoverBgGold","mouseOverText":getText("prices")},$("divBeraterButtons"));
    createElement("img",{"src":GFX+"money.gif","style":"width:30px;height:30px;"},newdiv);
    newdiv.addEventListener("click",function(){ unsafeWindow.buildInfoPanel("stock",{"page":1}); },false);

    // Recipes and Powerups
    err_trace="Recipes and Powerups";
    if(unsafeWindow.formulas){
        newdiv=createElement("div",{"id":"divBeraterButtonsFormulas","class":"link beraterButtonIcon hoverBgBlue","mouseOverText":getText("recipes")},$("divBeraterButtons"));
        createElement("img",{"src":GFX+"farmhouse/catalogue.gif","style":"position:relative;top:3px;left:0;width:24px;height:24px;"},newdiv);
        newdiv.addEventListener("click",function(){unsafeWindow.buildInfoPanel("formulas");},false);

        if(unsafeWindow.showPowerUps){ // hofix 13.03.2013
            unsafeOverwriteFunction("showPowerUps",function(){
                try{
                    unsafeWindow._showPowerUps();
                }catch(err){GM_logError("_showPowerUps\n"+err);}
                try{
                    var cand=$("powerselectorcontent").getElementsByClassName("blackbox");
                    for(var v=0;v<cand.length;v++){
                        if(cand[v].id.match(/^formulatimer\d+$/)){
                            cand[v].style.top="47px";
                        }
                    }
                    cand=null;
                }catch(err){GM_logError("showPowerUps\n"+err);}
            });
            unsafeWindow.showPowerUps();
        }

    }

    // Uebersicht
    err_trace="Overview";
    newdiv=$("titlepig");
    if(!newdiv){ newdiv = createElement("div",{"id":"titlepig","style":"top:12px;left:218px;width:97px;height:100px;position:absolute;"},$("headercontainer")) };
    newdiv.setAttribute("class","link");
    newdiv.addEventListener("click",function(){ unsafeWindow.buildInfoPanel("zones"); },false);
    newdiv.addEventListener("mouseover",function(event){ toolTip.show(event,getText("overview")); },false);

    // Quest
    err_trace="Quest - MouseOver";
/*
    questdata={ 
    "questid":quest number,
    "remain":seconds to the start,
    "data":{    "0":2,
                "1":{"0":{"prodId1":amountNeeded,
                          "prodId2":{"prod2a":amountNeeded,
                                     "prod2a":amountNeeded}},
                     "1":0,
                     "2":0,
                     "3":0},
                "2":{"0":points,"1":money,"2":0,"3":flagRack,"4":flagFarm","5":object,"6":0}, //Rewards
                "3":??,
                "4":??,
                "5":??,
                "6":"Short Description",
                "7":"Long Description",
                "8":waitingTime (before or after?),
                "9":??,
                "10":??},
    "entries":{"prodId1":"amountGiven","prodId2":"amountGiven"},
    "solved":0,
    "farmi":flagFarmiRewarded,
    "end":flagQuestsEnded}
*/
    highlightProducts=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_highlightProducts","[false,{}]"),"do_main/highlightProducts",[false,{}]);
    for(var type in QUESTS){
    if(!QUESTS.hasOwnProperty(type)){continue;} 
        for(var campaign in QUESTS[type]){
        if(!QUESTS[type].hasOwnProperty(campaign)){continue;}
            if(newdiv=$("quests_status_bar_"+type+campaign)){
                newdiv.setAttribute("type",implode([type,campaign],"QuestStatusBar"));
                newdiv.addEventListener("mouseover",function(event){
                    var help=explode(this.getAttribute("type"),"QuestStatusBar");
                    toolTip.show(event,questLineMouseOver(help[0],help[1]));
                },false);
            }
        }
    }
    err_trace="Quest - BeraterButton";
    newdiv=createElement("div",{"id":"divBeraterButtonsQuests","class":"link beraterButtonIcon hoverBgBlack","mouseOverText":getText("quests")},$("divBeraterButtons"));
    createElement("img",{"src":IMAGES["exclamationMark"],"style":"position:relative;top:4px;left:0;width:24px;height:24px;"},newdiv);
    newdiv.addEventListener("click",function(){unsafeWindow.buildInfoPanel("quests",null);},false);
    err_trace="Quest - Farmi amount bonus";
    farmiDailyCount=6;
    for(var v=1;v<questData["main"]["1"]["nr"];v++){
        if(QUESTS["main"]["1"][v]&&QUESTS["main"]["1"][v][3]){
            for(var w=0;w<QUESTS["main"]["1"][v][3].length;w++){
                if(QUESTS["main"]["1"][v][3][w][0]==5){
                    farmiDailyCount+=QUESTS["main"]["1"][v][3][w][1];
                }
            }
        }
    }       
    if(div=$("foodworld_questblock")){ div.removeAttribute("onclick"); }
    function calcQuestData(quTyp,campaign){
        try{
            var err_trace = "Set current data";
            // Quest data
            if(QUESTS[quTyp][campaign][questData[quTyp][campaign]["nr"]]){
                questData[quTyp][campaign]["data"]=QUESTS[quTyp][campaign][questData[quTyp][campaign]["nr"]].clone();
                for(var i=questData[quTyp][campaign]["data"][0].length-1;i>=0;i--){
                    // Alternative: if product is already given, reduce to this one
                    if(typeof questData[quTyp][campaign]["data"][0][i][0]=="object"){
                        for(var j=0;j<questData[quTyp][campaign]["data"][0][i].length;j++){
                            if(questData[quTyp][campaign]["given"][questData[quTyp][campaign]["data"][0][i][j][0]]&&questData[quTyp][campaign]["given"][questData[quTyp][campaign]["data"][0][i][j][0]][questData[quTyp][campaign]["data"][0][i][j][1]]){
                                questData[quTyp][campaign]["data"][0][i]=questData[quTyp][campaign]["data"][0][i][j];
                            }
                        }
                    }
                    // Mark the cheapest items. important at alternatives
                    if(typeof questData[quTyp][campaign]["data"][0][i][0]=="object"){
                        help=[];
                        for(var k=0;k<questData[quTyp][campaign]["data"][0][i].length;k++){
                            if(questData[quTyp][campaign]["data"][0][i][k][0]!=0){
                                help[k]=0;
                            }else if(isNaN(NPC[questData[quTyp][campaign]["data"][0][i][k][0]][questData[quTyp][campaign]["data"][0][i][k][1]])){
                                help[k]=questData[quTyp][campaign]["data"][0][i][k][2]*gut[questData[quTyp][campaign]["data"][0][i][k][1]];
                            }else{
                                help[k]=questData[quTyp][campaign]["data"][0][i][k][2]*Math.min(gut[questData[quTyp][campaign]["data"][0][i][k][1]],NPC[questData[quTyp][campaign]["data"][0][i][k][0]][questData[quTyp][campaign]["data"][0][i][k][1]]);
                            }
                            questData[quTyp][campaign]["data"][0][i][k][3]=true;
                            for(var l=0;l<k;l++){
                                if(help[k]<help[l]){ questData[quTyp][campaign]["data"][0][i][l][3]=false; }
                                else { questData[quTyp][campaign]["data"][0][i][k][3]=false; }
                            }
                        }
                        help=questData[quTyp][campaign]["data"][0].splice(i,1)
                        questData[quTyp][campaign]["data"][0]=questData[quTyp][campaign]["data"][0].concat(help[0]);
                    }else{
                        questData[quTyp][campaign]["data"][0][i][3]=true;
                    }
                }
            }else{
                questData[quTyp][campaign]["data"]=[];
            }
            // GM_log("questData["+quTyp+"]["+campaign+"]="+implode(questData[quTyp][campaign]));
            // GM_setValueCache(COUNTRY+"_"+SERVER+"_"+USERNAME+"_questData",implode(questData));
            // unsafeData.questData=questData.clone();
        }catch(err){ GM_logError("calcQuestData ("+err_trace+")\n"+err); }
    }
    function handleQuestData(){
        // GM_log("setQuest newQuestNr="+newQuestNr);
        try{
            var err_trace = "Get questdata";    
            if(unsafeWindow.questdata){
                // GM_log("unsafeWindow.questdata:\n"+print_r(unsafeWindow.questdata,"",true,"\n"));
                for(var campaign in QUESTS["main"]){
                    if(!QUESTS["main"].hasOwnProperty(campaign)){continue;}
                    if(unsafeWindow.questdata[campaign]){
                        if(!questData["main"][campaign]){ questData["main"][campaign]=INIT_questData["main"][campaign].clone(); }
                        if(unsafeWindow.questdata[campaign]["end"]&&(unsafeWindow.questdata[campaign]["end"]==1)){
                            questData["main"][campaign]["nr"]=QUESTS["main"][campaign].length;
                            questData["main"][campaign]["given"] = new Object();
                            questData["main"][campaign]["time"] = 0;
                        }else{
                            // if(!questData["main"][campaign]){continue;}
                            // Quest number
                            questData["main"][campaign]["nr"]=unsafeWindow.questdata[campaign]["questid"];
                            // Given
                            questData["main"][campaign]["given"] = new Object();
                            if(unsafeWindow.questdata[campaign]["entries"]){
                                for(var t in unsafeWindow.questdata[campaign]["entries"]){
                                    if(!unsafeWindow.questdata[campaign]["entries"].hasOwnProperty(t)){continue;}
                                    var prod = parseInt(t,10);
                                    var type = 0;
                                    if(!questData["main"][campaign]["given"][type]){ questData["main"][campaign]["given"][type] = new Object(); }
                                    if(!questData["main"][campaign]["given"][type][prod]){ questData["main"][campaign]["given"][type][prod] = 0; }
                                    questData["main"][campaign]["given"][type][prod] += parseInt(unsafeWindow.questdata[campaign]["entries"][t],10);
                                }
                            }
                            // Time
                            questData["main"][campaign]["time"] = now+unsafeWindow.questdata[campaign]["remain"];
                        }
                        calcQuestData("main",campaign);
                    }
                }
                // GM_log("questdata:\n"+print_r(questData["main"],"",true,"\n"));
                GM_setValueCache(COUNTRY+"_"+SERVER+"_"+USERNAME+"_questData",implode(questData));
                unsafeData.questData=questData.clone();
            }
            err_trace = "Calc highlightProducts"; 
            if(highlightProducts[0]){ // TODO: For all quests. Not if all given.
                highlightProducts[1]={};
                if(questData["main"]["1"]["data"]){
                    for(var j=0;j<questData["main"]["1"]["data"][0].length;j++){
                        if(questData["main"]["1"]["data"][0][j][3]){
                            highlightProducts[1][questData["main"]["1"]["data"][0][j][1]]=true;
                        }
                    }               
                }
                GM_setValueCache(COUNTRY+"_"+SERVER+"_"+USERNAME+"_highlightProducts",implode(highlightProducts));
            }
            handleQuestLine();
        }catch(err){ GM_logError("handleQuestData ("+err_trace+")\n"+err); }
    }
    unsafeOverwriteFunction("questInitGo",function(response,mode,b,h,l){
        try{
            unsafeWindow._questInitGo(response,mode,b,h,l);
        }catch(err){GM_logError("_questInitGo\n"+err);}
        try{
            handleQuestData();
        }catch(err){GM_logError("questInitGo\n"+err);}
    });
    function handleQuestDataFoodworld(){
        // GM_log("setQuest newQuestNr="+newQuestNr);
        try{
            var err_trace = "Get questdata";    
            if(unsafeWindow.foodworld_quest){
                // GM_log("unsafeWindow.foodworld_quest:\n"+print_r(unsafeWindow.foodworld_quest,"",true,"\n"));
                if(!questData["foodworld"]){ questData["foodworld"]={}; }
                for(var campaign in QUESTS["foodworld"]){
                    if(!QUESTS["foodworld"].hasOwnProperty(campaign)){continue;}
                    if(!questData["foodworld"][campaign]){ 
                        questData["foodworld"][campaign]=INIT_questData["foodworld"][campaign].clone(); 
                    }
                    if(campaign==unsafeWindow.foodworld_quest["campaignid"]){
                        if(unsafeWindow.foodworld_quest["questid"]){
                            // Quest number
                            questData["foodworld"][campaign]["nr"]=unsafeWindow.foodworld_quest["questid"];
                            // Given
                            questData["foodworld"][campaign]["given"] = new Object();
                            if(unsafeWindow.foodworld_quest["entries"]){
                                for(var t in unsafeWindow.foodworld_quest["entries"]){
                                    if(!unsafeWindow.foodworld_quest["entries"].hasOwnProperty(t)){continue;}
                                    var prod = parseInt(t,10);
                                    var type = 0;
                                    if(!questData["foodworld"][campaign]["given"][type]){ questData["foodworld"][campaign]["given"][type] = new Object(); }
                                    if(!questData["foodworld"][campaign]["given"][type][prod]){ questData["foodworld"][campaign]["given"][type][prod] = 0; }
                                    questData["foodworld"][campaign]["given"][type][prod] += parseInt(unsafeWindow.foodworld_quest["entries"][t],10);
                                }
                            }
                            // Time
                            questData["foodworld"][campaign]["time"] = now+unsafeWindow.foodworld_quest["remain"];
                        }else{
                            questData["foodworld"][campaign]["nr"]=QUESTS["foodworld"][campaign].length;
                            questData["foodworld"][campaign]["given"] = new Object();
                            questData["foodworld"][campaign]["time"] = 0;
                        }
                    }else{
                        questData["foodworld"][campaign]["nr"]=QUESTS["foodworld"][campaign].length;
                        questData["foodworld"][campaign]["given"] = new Object();
                        questData["foodworld"][campaign]["time"] = 0;
                    }
                    calcQuestData("foodworld",campaign);
                // GM_log("questdata:\n"+print_r(questData["foodworld"],"",true,"\n"));
                }
                GM_setValueCache(COUNTRY+"_"+SERVER+"_"+USERNAME+"_questData",implode(questData));
                unsafeData.questData=questData.clone();
            }
            div=null;
        }catch(err){ GM_logError("handleQuestData ("+err_trace+")\n"+err); }
    }

    // mouseover showing quest data
    function questLineMouseOver(questType,campaign){
        try{
            var container=createElement("div");
            var questDataCurr = questData[questType][campaign];
            var questCurr = QUESTS[questType][campaign][questDataCurr["nr"]];
            var questStarted = (questDataCurr["time"]<now);
            var table=createElement("table",{"border":"0","cellspacing":"0","cellpadding":"3","style":"line-height:16px;"},container);
            var tr=createElement("tr",{},table);
            var td=createElement("td",{"colspan":"3","style":"text-align:center;border-bottom:1px solid black;font-weight:bold;"},tr,getText("quest"+questType+campaign)+"<br>"+getText("nr")+" "+questDataCurr["nr"]);
            if(questStarted){ createElement("td",{"colspan":"2","style":"text-align:center;border-bottom:1px solid black;border-left:1px solid black;"},tr,getText("given")); }
            createElement("td",{"colspan":"2","style":"text-align:center;border-bottom:1px solid black;border-left:1px solid black;"},tr,getText("missing"));
            createElement("td",{"colspan":"2","style":"text-align:center;border-bottom:1px solid black;border-left:1px solid black;"},tr,getText("total"));
            var sumWert=[0,0,0]; //given,needed,total
            var menge,item,preis;
            for(var v=0;v<questDataCurr["data"][0].length;v++){
                item=questDataCurr["data"][0][v];
                menge=[,,item[2]];
                if(questStarted){ menge[0]=(questDataCurr["given"]&&questDataCurr["given"][item[0]]&&questDataCurr["given"][item[0]][item[1]])?questDataCurr["given"][item[0]][item[1]]:0; }
                else{ menge[0]=0; }
                menge[1]=Math.max(0,menge[2]-menge[0]-prodStock[item[0]][item[1]]);
                preis=null;
                if(item[0]==0){
                    preis=gut[item[1]]; 
                    if(!isNaN(NPC[item[0]][item[1]])){ preis=Math.min(preis,NPC[item[0]][item[1]]); }
                }
                tr=createElement("tr",{},table);
                if(!item[3]){ tr.style.textDecoration="line-through"; }
                td=createElement("td",{},tr);
                produktPic(item[0],item[1],td);
                createElement("td",{},tr,prodName[item[0]][item[1]]);
                createElement("td",{"style":"text-align:right;"},tr,numberFormat(100*(menge[2]-menge[1])/menge[2])+"%");
                for(var i=0;i<3;i++){
                    if((i==0)&&(!questStarted)){ continue; }
                    if(item[3]&&(preis!=null)){ sumWert[i] += menge[i]*preis; }
                    createElement("td",{"style":"text-align:right;border-left:1px solid black;"},tr,numberFormat(menge[i]));
                    createElement("td",{"style":"text-align:right;padding-left:10px;"},tr,preis!=null?moneyFormatInt(menge[i]*preis):"--");
                }
            }

            tr=createElement("tr",{},table);
            createElement("td",{"colspan":"2","style":"border-top:1px solid black;"},tr);
            createElement("td",{"style":"text-align:right;border-top:1px solid black;"},tr,numberFormat(100*(sumWert[2]-sumWert[1])/(sumWert[2]))+"%");
            for(var i=0;i<3;i++){
                if((i==0)&&(!questStarted)){ continue; }
                createElement("td",{"style":"text-align:right;border-top:1px solid black;","colspan":"2"},tr,moneyFormatInt(sumWert[i]));
            }
            
            table=createElement("table",{"border":"0","cellspacing":"0","cellpadding":"3","style":"line-height:16px;"},container);
            tr=createElement("tr",{},table);
            createElement("td",{"style":"vertical-align:top;"},tr,getText("reward")+":");
            td=createElement("td",{},tr);
            var div;
            if(questCurr[2]>0){
                pointsFormat(questCurr[2],"div",td);
            }
            if(questCurr[3]){
                for(var w=0;w<questCurr[3].length;w++){
                    switch(questCurr[3][w][0]){
                    case 0:{
                        createElement("div",{},td,moneyFormat(questCurr[3][w][1]));
                    break;}
                    case 1:{
                        div=createElement("div",{},td);
                        produktPic(questCurr[3][w][1],questCurr[3][w][2],div);
                        createElement("span",{},div,numberFormat(questCurr[3][w][3])+"&nbsp;"+prodName[questCurr[3][w][1]][questCurr[3][w][2]]);
                    break;}
                    case 2:{
                        createElement("div",{},td,getText("activation")+": "+getText("rackX").replace(/%1%/,questCurr[3][w][1]));
                    break;}
                    case 3:{
                        createElement("div",{},td,getText("activation")+": "+getText("farmX").replace(/%1%/,questCurr[3][w][1]));
                    break;}
                    case 4:{
                        div=createElement("div",{},td);
                        produktPic(questCurr[3][w][1],questCurr[3][w][2],div);
                        createElement("span",{},div,getText("productTimeSaving").replace(/%1%/,questCurr[3][w][3]).replace(/%2%/,prodName[questCurr[3][w][1]][questCurr[3][w][2]]));
                    break;}
                    case 5:{
                        div=createElement("div",{},td);
                        createElement("img",{"src":GFX+"adbonus.gif","style":"border:0;height:15px;"},div);
                        createElement("span",{},div,getText("additionalFarmi").replace(/%1%/,questCurr[3][w][1]));
                    break;}
                    case 6:{
                        createElement("div",{},td,getText("additionalLogCapacity").replace(/%1%/,questCurr[3][w][1]));
                    break;}
                    case 7:{
                        createElement("div",{},td,getText("waterBonus").replace(/%1%/,questCurr[3][w][1]));
                    break;}
                    case 8:{
                        if(DATA_zones[questCurr[3][w][1]]["location"]=="farm"){
                            createElement("div",{},td,getText("activation")+": "+getText("farmzone").replace(/%1%/,1+((questCurr[3][w][1]-1)%6)).replace(/%2%/,Math.ceil(questCurr[3][w][1]/6)));
                        }else{
                            createElement("div",{},td,getText("activation")+": "+zones.getBuildingName(questCurr[3][w][1]));
                        }
                    break;}
                    case 9:{
                        div=createElement("div",{},td);
                        createElement("span",{},div,getText("activation")+": ");
                        produktPic(questCurr[3][w][1],questCurr[3][w][2],div);
                        createElement("span",{},div,prodName[questCurr[3][w][1]][questCurr[3][w][2]]);
                    break;}
                    case 10:{
                        createElement("div",{},td,getText("activation")+": "+getText("wateringFeature"));
                    break;}
                    case 11:{
                        div=createElement("div",{},td);
                        createElement("img",{"src":GFX+"adbonus.gif","style":"border:0;height:15px;"},div);
                        createElement("span",{},div,getText("additionalForestFarmiSlot").replace(/%1%/,questCurr[3][w][1]));
                    break;}
                    }
                }
            }
            tr=createElement("tr",{},table);
            createElement("td",{},tr,getText("start")+": ");
            createElement("td",{},tr,getDateText(questDataCurr["time"])+" "+getDaytimeStr(questDataCurr["time"]));
            
            div=null;
            table=null;tr=null;td=null;
            return container.innerHTML;
        }catch(err){
            GM_logError("questLineMouseOver\n"+err);
            try{
                switch(questType){
                case "main":{ return (getText("informationIsMissing")+" "+getText("pleaseOpenX").replace(/%1%/,getText("quest"+questType+campaign))); break;}
                case "forestry":{ return (getText("informationIsMissing")+" "+getText("pleaseOpenX").replace(/%1%/,getText("lodge"))); break;}
                case "foodworld":{ return (getText("informationIsMissing")+" "+getText("pleaseOpenX").replace(/%1%/,getText("foodworld"))); break;}
                }
            }catch(err){}
            return null; 
        }
    }
    unsafeOverwriteFunction("showQuestBox",function(c){
        try{
            unsafeWindow._showQuestBox(c);
        }catch(err){GM_logError("_showQuestBox\n"+err);}
        try{
            var cand=$("questboxobjects").getElementsByClassName("questboxbarout");
            for(var i=0;i<cand.length;i++){
                var questWare = parseInt(cand[i].children[0].id.replace("questboxbarin",""),10);
                var menge = [0,0,0]; //given,stock,total
                for(var v in unsafeWindow.questdata[c]["data"][1][0]){
                    if(!unsafeWindow.questdata[c]["data"][1][0].hasOwnProperty(v)){ continue; }
                    if(typeof unsafeWindow.questdata[c]["data"][1][0][v]=="object"){
                        if(unsafeWindow.questdata[c]["data"][1][0][v][questWare]){
                            menge[2] = unsafeWindow.questdata[c]["data"][1][0][v][questWare];
                        }
                    }else{
                        if(v==questWare){
                            menge[2] = unsafeWindow.questdata[c]["data"][1][0][v];
                        }
                    }
                }
                menge[0]=((unsafeWindow.questdata[c]["entries"]&&unsafeWindow.questdata[c]["entries"][questWare])?parseInt(unsafeWindow.questdata[c]["entries"][questWare],10):0);
                menge[1]=Math.min(menge[2]-menge[0],prodStock[0][questWare]);
                createElement("div",{"style":"width:"+Math.floor(200*menge[1]/menge[2])+"px;left:"+Math.floor(200*(menge[0])/menge[2])+"px;","class":"questboxbarinPoss"},cand[i]);
                // better number-formatting
                $("questboxobj"+questWare+"_current").innerHTML = numberFormat(menge[0]);
                $("questboxobj"+questWare+"_need").innerHTML = numberFormat(menge[2]);
            }
        }catch(err){ GM_logError("showQuestBox\n"+err); }       
    });
    unsafeOverwriteFunction("questsHandler",function(status){
        try{
            unsafeWindow._questsHandler(status);
        }catch(err){GM_logError("_questsHandler\n"+err);}
        try{
            handleQuestLine();
        }catch(err){GM_logError("questsHandler\n"+err);}
    });
/* todo:
    raiseEvent("gameQuestSolvable");
    raiseEvent("gameQuestNewAvailable");
    raiseEvent("gameQuestFinished");
    raiseEvent("gameQuestAccepted");
*/
    unsafeOverwriteFunction("showQuestBoxLine",function(){
        try{
            unsafeWindow._showQuestBoxLine();
        }catch(err){GM_logError("_showQuestBoxLine\n"+err);}
        try{
            handleQuestLine();
        }catch(err){GM_logError("showQuestBoxLine\n"+err);}
    });
    function updateQuestLineTimer(){
    try{
return false;   
        for(var type in QUESTS){
            if (!QUESTS.hasOwnProperty(type)){ continue; }
            if (type=="main"){ continue; }
            for(var campaign in QUESTS[type]){
                if (!QUESTS[type].hasOwnProperty(campaign)){ continue; }
                if(nodes["questline_"+type+"_"+campaign]&&nodes["questline_"+type+"_"+campaign]["node"]){
                    if(now<questData[type][campaign]["time"]){
                        nodes["questline_"+type+"_"+campaign]["node"].children[1].innerHTML = getTimeStr(questData[type][campaign]["time"]-now,false)+" "+getText("shortHours");
                    }else{
                        handleQuestLine();
                    }
                }
            }
        }
    }catch(err){GM_logError("updateQuestLineTimer\ntype="+type+"\ncampaign="+campaign+"\n"+err);}
    }
    handleQuestData(); // --> handleQuestLine
    
    // SHOW RACK DATA
    err_trace="Show rack data";
    function showDataAllProducts(){
    try{
        var container=createElement("div",{"style":"z-index:995;position:absolute;top:0;left:0;background-color:white;height:100%;"},ALL);
        var div=createElement("img",{"class":"link","src":GFX+"close.jpg","style":"position:absolute;top:0;right:0;width:20px;height:20px;margin:5px;"},container);
        div.addEventListener("click",function(){ removeElement(this.parentNode); },false);
        div=createElement("div",{"style":"height:100%;padding-right:20px;margin-right:30px;overflow:auto;"},container);
        var table=createElement("table",{"border":"1"},div);
        var tr,td,newDiv1;
        for(var type in prodName){
        try{
            if(!prodName.hasOwnProperty(type)){continue;}
            tr=createElement("tr",{"style":"background-color:orange;color:black;"},table);
            createElement("th",{"colspan":"16"},tr,type+": "+["farm","forestry","recipes","powerups"][type]);
            tr=createElement("tr",{"style":"background-color:orange;color:black;"},table);
            createElement("th",{"style":"white-space:nowrap;"},tr,"id");
            createElement("th",{"style":"white-space:nowrap;"},tr,"Name");
            createElement("th",{},tr,"Typ");
            createElement("th",{},tr,"Stock");
            createElement("th",{},tr,"MaxStock");
            createElement("th",{},tr,"MinRack");
            createElement("th",{},tr,"MinRackInit");
            createElement("th",{},tr,"PlantSize");
            createElement("th",{},tr,"Block");
            createElement("th",{},tr,"Require");
            createElement("th",{},tr,"Yield");
            createElement("th",{},tr,"GrowTime");
            createElement("th",{},tr,"Points");
            createElement("th",{},tr,"NPC");
            createElement("th",{},tr,"gut");
            createElement("th",{},tr,"loc");
            for(var v in prodName[type]){
            try{
                if(!prodName[type].hasOwnProperty(v)){continue;}
                tr=createElement("tr",{},table);
                createElement("td",{},tr,v);
                td=createElement("td",{"style":"white-space:nowrap;"},tr);
                    produktPic(type,v,td);
                    createElement("span",{},td,prodName[type][v]);
                td=createElement("td",{},tr,prodTyp[type][v]);
                td=createElement("td",{},tr,numberFormat(prodStock[type][v]));
                td=createElement("td",{},tr,numberFormat(prodStockMax[type][v]));
                td=createElement("td",{},tr,numberFormat(prodMinRack[type][v]));
                td=createElement("td",{},tr,numberFormat(prodMinRackInit[type][v]));
                td=createElement("td",{},tr,prodPlantSize[type][v]);
                td=createElement("td",{},tr,prodBlock[type][v]);
                td=createElement("td",{},tr);
                if(typeof prodRequire[type][v]=="object"){
                    for(var i=0;i<prodRequire[type][v].length;i++){
                        if(i>0){ createElement("div",{"style":"display:inline-block;white-space:nowrap;"},td,";&nbsp;"); }
                        if(prodRequire[type][v][i][0]>-1){
                            newDiv1=createElement("div",{"style":"display:inline-block;white-space:nowrap;","class":"hoverBgLightblue","prodType":prodRequire[type][v][i][0],"prodId":prodRequire[type][v][i][1]},td);
                            newDiv1.addEventListener("mouseover",function(event){
                                toolTip.show(event,prodName[this.getAttribute("prodType")][this.getAttribute("prodId")]);
                                //toolTip.show(event,prodName[parseInt(this.getAttribute("prodType"),10)][parseInt(this.getAttribute("prodId"),10)]);
                            },false);
                            produktPic(prodRequire[type][v][i][0],prodRequire[type][v][i][1],newDiv1);
                            createElement("span",{},newDiv1,numberFormat(prodRequire[type][v][i][2]));
                        }else{
                            newDiv1=createElement("div",{"style":"display:inline-block;white-space:nowrap;","class":"hoverBgLightblue"},td);
                            createElement("span",{},newDiv1,moneyFormat(prodRequire[type][v][i][1]));
                        }
                    }
                }
                td=createElement("td",{},tr,prodYield[type][v]);
                td=createElement("td",{},tr,prodGrowTime[type][v]>0?getTimeStr(60*prodGrowTime[type][v],true):"");
                td=createElement("td",{},tr,prodPoints[type][v]==undefined?"-":numberFormat(prodPoints[type][v]));
                td=createElement("td",{},tr);
                if(!NPC[type][v]){
                    createElement("span",{},td,"-");
                }else if(!isNaN(NPC[type][v])){
                    createElement("span",{},td,moneyFormat(NPC[type][v]));
                }else if (NPC[type][v].match(/^f/)){
                    createElement("span",{},td,"*"+moneyFormat(parseFloat(NPC[type][v].replace("f",""),10)));
                }else if (NPC[type][v].match(/^c/)){
                    coinsFormat(parseInt(NPC[type][v].replace("c",""),10),td);
                }
                td=createElement("td",{},tr,gut[v]==undefined||type>0?"-":moneyFormat(gut[v]));
                td=createElement("td",{},tr,PRODUCT2BUILDING[type][v]);
            }catch(err){ GM_logError("showDataAllProducts type="+type+" v="+v+"\n"+err); }
            }
        }catch(err){ GM_logError("showDataAllProducts type="+type+"\n"+err); }
        }
        container=null;div=null;
        table=null;tr=null;td=null;newDiv1=null;
    }catch(err){ GM_logError("showDataAllProducts\n"+err); }
    }
    GM_registerMenuCommand(getText("adviser")+" "+"Show Data: Products", showDataAllProducts);
    
    // SHOW ZONE DATA
    err_trace="Show zone data";
    function showDataAllZones(){
    try{
        var prType,zoneNrS,allZones=[],currZoneType,help;
        var style="";
        for(var i in ALL_ZONES){
            if(!ALL_ZONES.hasOwnProperty(i)){ continue; }
            for(var j=0;j<ALL_ZONES[i].length;j++){
                allZones.push(ALL_ZONES[i][j].toString());
                if(zones.isMultiSlot(ALL_ZONES[i][j])){
                    for(var slot=1;slot<=3;slot++){
                        allZones.push(ALL_ZONES[i][j]+"."+slot);
                    }
                }
            }
        }
        var container=createElement("div",{"style":"z-index:995;position:absolute;top:0;left:0;background-color:white;height:100%;"},ALL);
        var div=createElement("img",{"class":"link","src":GFX+"close.jpg","style":"position:absolute;top:0;right:0;width:20px;height:20px;margin:5px;"},container);
        div.addEventListener("click",function(){ removeElement(this.parentNode); },false);
        div=createElement("div",{"style":"height:100%;padding-right:20px;margin-right:30px;overflow:auto;"},container);
        var table=createElement("table",{"border":"1"},div);
        var tr=createElement("tr",{},table);
        var td=createElement("td",{},tr,"Nr");
        createElement("td",{},tr,"Type(building,BUILDINGTYPE)");
        createElement("td",{},tr,"Block");
        createElement("td",{},tr,"AddToGlobalTime");
        createElement("td",{},tr,"Animals");
        createElement("td",{},tr,"Bonus");
        createElement("td",{},tr,"BonusSpecial");
        createElement("td",{},tr,"EndProduct");
        createElement("td",{},tr,"EndTime");
        createElement("td",{},tr,"WaterTime");
        createElement("td",{},tr,"Ernte");
        createElement("td",{},tr,"FieldData");

        
        for(var i=0;i<allZones.length;i++){
        try{
            zoneNrS=allZones[i];
            style="color:"+(zones.getBlock(zoneNrS)?"lightgrey;":"black;");
            tr=createElement("tr",{},table);
            createElement("td",{"style":style},tr,zoneNrS);
            switch(zones.getLocation(zoneNrS).location){
            case "windmill":{ prType=3; } break;
            case "forestry":{ prType=1; } break;
            default:{ prType=0; }
            }
            if(currZoneType=zones.getBuilding(zoneNrS)){
                createElement("td",{"style":style},tr,getBuildingName(currZoneType)+" ("+currZoneType+","+BUILDINGTYPE[currZoneType]+")");
            }else{
                createElement("td",{"style":style},tr,"");
            }
            createElement("td",{"style":style},tr,zones.getBlock(zoneNrS));
            createElement("td",{"style":style},tr,(isNaN(zoneNrS)?!!zoneAddToGlobalTime[zoneNrS]:true).toString());
            createElement("td",{"style":style},tr,isNaN(zones.getAnimals(zoneNrS))?"":numberFormat(zones.getAnimals(zoneNrS)));
            createElement("td",{"style":style},tr,isNaN(zones.getBonus(zoneNrS))?"":(numberFormat(zones.getBonus(zoneNrS))+"%"));
            td=createElement("td",{"style":style},tr);
            if(zones.getBonusSpecial(zoneNrS)){
                createElement("span",{},td,numberFormat(zones.getBonusSpecial(zoneNrS)[1])+"%");
                produktPic(0,zones.getBonusSpecial(zoneNrS)[0],td);
                createElement("span",{},td,"("+numberFormat(zones.getBonusSpecial(zoneNrS)[0])+")");
            }
            td=createElement("td",{"style":style},tr);
            if(help=zones.getEndproduct(zoneNrS)){
                produktPic(prType,help,td);
                createElement("span",{},td,"("+prType+","+help+")");
            }
            help=zones.getEndtime(zoneNrS);
            td=createElement("td",{"style":style+(help<now?"font-weight:bold;":"")},tr);
            if(help){
                if(help==NEVER){
                    createElement("div",{},td,"NEVER");
                } else {
                    createElement("div",{},td,getDateText(help));
                    createElement("div",{},td,getDaytimeStr(help,false,true));
                }
            }
            help=zones.getWatertime(zoneNrS);
            td=createElement("td",{"style":style+(help<now?"font-weight:bold;":"")},tr);
            if(help){
                if(help==NEVER){
                    createElement("div",{},td,"NEVER");
                } else {
                    createElement("div",{},td,getDateText(help));
                    createElement("div",{},td,getDaytimeStr(help,false,true));
                }
            }
            td=createElement("td",{"style":style},tr);
            if(help=zones.getCrop(zoneNrS)){
                for(var j=0;j<help.length;j++){
                    div=createElement("div",{"style":"white-space:nowrap;"},td);
                    produktPic(help[j][0],help[j][1],div);
                    createElement("span",{},div,numberFormat(help[j][2])+"(");
                    pointsFormat(help[j][3],"span",div);
                    createElement("span",{},div,")");
                }
            }
            td=createElement("td",{"style":style},tr);
            if(help=zones.getProduction(zoneNrS)){
                createElement("div",{"style":"white-space:nowrap;"},td,print_r(help));
            }
        }catch(err){ GM_logError("showDataAllZones row zoneNrS="+zoneNrS+"\n"+err); }
        }
        container=null;div=null;
        table=null;tr=null;td=null;
    }catch(err){ GM_logError("showDataAllZones\n"+err); }
    }
    GM_registerMenuCommand(getText("adviser")+" "+"Show Data: Zones", showDataAllZones);

    /*
    function showDataForestryFarmi(){
        var div=createElement("div",{"style":"z-index:995;position:fixed;top:0;background-color:white;height:800px;overflow:auto;padding-right:40px;"},ALL);
        var newimg=createElement("img",{"class":"link","src":GFX+"close.jpg","style":"position:absolute;top:8px;right:0px;width:20px;height:20px;"},div);
        newimg.addEventListener("click",function(){ removeElement(this.parentNode); },false);
        var table=createElement("table",{"border":"1"},div);
        var tr=createElement("tr",{},table);
        createElement("td",{"style":"max-width:120px;"},tr,"ID");
        for(var k in prodName[1]){
            if(!prodName[1].hasOwnProperty(k)){continue;}
            if(k>=500){continue;}
            produktPic(1,k,createElement("td",{"style":"max-width:120px;"},tr));
        }
        createElement("td",{"style":"max-width:120px;"},tr,"price");
        createElement("td",{"style":"max-width:120px;"},tr,"points");

        var tr=createElement("tr",{},table);
        createElement("td",{"style":"max-width:120px;"},tr,"ID");
        for(var k in prodName[1]){
            if(!prodName[1].hasOwnProperty(k)){continue;}
            if(k>=500){continue;}
            createElement("td",{"style":"max-width:120px;"},tr,k);
        }

        if(unsafeWindow.forestry_production_products.length>0){
            var tr=createElement("tr",{},table);
            createElement("td",{"style":"max-width:120px;"},tr,"{1}");
            for(var k in prodName[1]){
                if(!prodName[1].hasOwnProperty(k)){continue;}
                if(k>=500){continue;}
                createElement("td",{"style":"max-width:120px;"},tr,unsafeWindow.forestry_production_products[prodTyp[1][k].replace("f","")][k]?unsafeWindow.forestry_production_products[prodTyp[1][k].replace("f","")][k][1]:"-");
            }
            var tr=createElement("tr",{},table);
            createElement("td",{"style":"max-width:120px;"},tr,"{7}");
            for(var k in prodName[1]){
                if(!prodName[1].hasOwnProperty(k)){continue;}
                if(k>=500){continue;}
                createElement("td",{"style":"max-width:120px;"},tr,unsafeWindow.forestry_production_products[prodTyp[1][k].replace("f","")][k]?unsafeWindow.forestry_production_products[prodTyp[1][k].replace("f","")][k][7]:"-");
            }
        }

        var farmies=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_forestry_farmies","{}"),"showDataForestryFarmi/forestry_farmies",{});
        for(var v in farmies){
            if(!farmies.hasOwnProperty(v)){continue;}
            tr=createElement("tr",{},table);
            createElement("td",{},tr,v);
            farmies[v]["products"].sort(function(a,b){return -1*((parseInt(b["product"],10)>parseInt(a["product"],10))-(parseInt(b["product"],10)<parseInt(a["product"],10)));});
            for(var k in prodName[1]){
                if(!prodName[1].hasOwnProperty(k)){continue;}
                if(k>=500){continue;}
                td=createElement("td",{"style":"white-space:nowrap;"},tr);
                for(var i in farmies[v]["products"]){
                    if(!farmies[v]["products"].hasOwnProperty(i)){continue;}
                    if(farmies[v]["products"][i]["product"]==k){
                        createElement("span",{},td,farmies[v]["products"][i]["amount"]);
                        //createElement("span",{},td," x ");
                        //createElement("span",{},td,farmies[v]["products"][i]["product"]);
                        produktPic(1,farmies[v]["products"][i]["product"],td);
                    }

                }
            }
            createElement("td",{"style":"white-space:nowrap;"},tr,farmies[v]["price"]);
            createElement("td",{"style":"white-space:nowrap;"},tr,farmies[v]["points"]);
        }
        farmies=null;

        var tr=createElement("tr",{},table);
        createElement("td",{"style":"max-width:120px;"},tr,"ID");
        for(var k in prodName[1]){
            if(!prodName[1].hasOwnProperty(k)){continue;}
            if(k>=500){continue;}
            produktPic(1,k,createElement("td",{"style":"max-width:120px;"},tr));
        }
        createElement("td",{"style":"max-width:120px;"},tr,"price");
        createElement("td",{"style":"max-width:120px;"},tr,"points");

        var tr=createElement("tr",{},table);
        createElement("td",{"style":"max-width:120px;"},tr,"ID");
        for(var k in prodName[1]){
            if(!prodName[1].hasOwnProperty(k)){continue;}
            if(k>=500){continue;}
            createElement("td",{"style":"max-width:120px;"},tr,k);
        }

        if(unsafeWindow.forestry_production_products.length>0){
            var tr=createElement("tr",{},table);
            createElement("td",{"style":"max-width:120px;"},tr,"{1}");
            for(var k in prodName[1]){
                if(!prodName[1].hasOwnProperty(k)){continue;}
                if(k>=500){continue;}
                createElement("td",{"style":"max-width:120px;"},tr,unsafeWindow.forestry_production_products[prodTyp[1][k].replace("f","")][k]?unsafeWindow.forestry_production_products[prodTyp[1][k].replace("f","")][k][1]:"-");
            }
            var tr=createElement("tr",{},table);
            createElement("td",{"style":"max-width:120px;"},tr,"{7}");
            for(var k in prodName[1]){
                if(!prodName[1].hasOwnProperty(k)){continue;}
                if(k>=500){continue;}
                createElement("td",{"style":"max-width:120px;"},tr,unsafeWindow.forestry_production_products[prodTyp[1][k].replace("f","")][k]?unsafeWindow.forestry_production_products[prodTyp[1][k].replace("f","")][k][7]:"-");
            }
        }
    }
    GM_registerMenuCommand(getText("adviser")+" "+"Show Data: forestry Farmi", showDataForestryFarmi);
    */

    // NPC-shop
    err_trace="NPC shop";
    // TODO: function not existing anymore
    unsafeOverwriteFunction("shopDialog",function(e,d){
        try{
            unsafeWindow._shopDialog(e,d);
        }catch(err){GM_logError("_shopDialog\n"+err);}
        try{
            $("shopdialog_amount").addEventListener("keyup",function(event){
                try{
                    if (event.keyCode==13){
                        click(this.nextElementSibling);
                    }
                }catch(err){ GM_logError("listener searchPlayer.keyup\n"+err); }
            },false);
        }catch(err){GM_logError("shopDialog\n"+err);}
    });
    // Market
    err_trace="Market";
    valKauflimit=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valKauflimit","[[85,'990000'],110]"),"do_main/valKauflimit",[[85,'990000'],110]);
    valKauflimitNPC=GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valKauflimitNPC",true);
    highlightProducts=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_highlightProducts","[false,{}]"),"do_main/highlightProducts",[false,{}]);
    highlightUser=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_highlight","{}"),"do_main/highlightUser",{});
    highlightUser[FARMNAME]="104e8b";
    valNimmBeob=GM_getValue(COUNTRY+"_"+SERVER+"_valNimmBeob",false);

    valVerkaufLimitDown=GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valVerkaufLimitDown",95);
    valVerkaufLimitUp=GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valVerkaufLimitUp",130);
    valJoinPreise=GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valJoinPreise",false);
    lastOffer=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_lastOffer","[]"),"do_main/lastOffer",[]);
    protectMinRack=GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valProtectMinRack",false);
    ownMarketOffers=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_ownMarketOffers","[]"),"do_main/ownMarketOffers",[]);
    
    // var mode=GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_modeMarket","cveoz");
    function do_market(){
    // GM_log("function do_market");
    try{
        var err_trace="Init";

    
        // Berater Information Line
        err_trace="market_beraterline";
        var market_beraterline=$("market_beraterline");
        if(!market_beraterline){
            market_beraterline=createElement("div",{"id":"market_beraterline","style":"position:absolute;width:630px;height:40px;bottom:-40px;padding:0 20px 20px 20px;background:url('"+GFX+"market/market_back.jpg') repeat scroll 0px -470px transparent;"},$("market"));
        }
        market_beraterline.innerHTML="";
        for(var i=0;i<7;i++){
            createElement("div",{"style":"float:left;height:40px;width:90px;"},market_beraterline);
        }
        
        // loadProductData();
        var candtable; //document.getElementsByTagName("table");
        var candtr; //candtable[0].getElementsByTagName("tr");
        var row,row_title,canddiv,canda,candtd,newa,newinput,newspan,newdiv,newdiv1;
    
        /*
        var marktButtons=new Array();
        marktButtons[0]=document.querySelector('div[onclick*="\'marktstand.php\'"]'); // market stall
        marktButtons[1]=document.querySelector('div[onclick*="\'markt.php?filter=1&guild=1\'"]');   // club offers
        marktButtons[2]=document.querySelector('div[onclick*="\'markt.php?show=overview\'"]');  // overview
        marktButtons[3]=document.querySelector('div[onclick*="\'markt.php\'"]');    // current offers
        for(var v=0;v<marktButtons.length;v++){
            if(marktButtons[v]){
                marktButtons[v].setAttribute("class","link hoverBlack");
                marktButtons[v].id="marketButton_"+["marktstand","guild","overview","current"][v];
            }
        }
        */
        /*
        // Market mode
        newdiv=createElement("div",{"id":"offertypeselector","style":"position:absolute;top:0;left:500px;-moz-user-select:none;"},ALL);
        newdiv.addEventListener("mouseover",function(event){
            var mouseOverText=event.target.getAttribute("mouseOverText");
            if(mouseOverText){
                mouseOverText='<div>'+getText("click")+'&nbsp;/&nbsp;'+getText("clickCtrl")+'</div><div>'+mouseOverText+'</div>';
                toolTip.show(event,mouseOverText);
            }
        },false);
        var newdiv1=createElement("div",{"mouseOverText":getText("category_v"),"class":"link","style":"display:inline-block;height:20px;width:26px;background:url('"+GFX+"racksort2.jpg') repeat scroll -10px 0px transparent;"},newdiv);
        if (mode.match(/v/)){
            newdiv1.style.backgroundPosition="-10px -20px";
        }else{
            newdiv1.addEventListener("mouseout",function(){this.style.backgroundPosition="-10px 0px";},false);
            newdiv1.addEventListener("mouseover",function(){this.style.backgroundPosition="-10px -20px";},false);
        }
        newdiv1.addEventListener("click",function(event){
            if(event.ctrlKey){
                if(mode.match(/v/)){mode=mode.replace(/v/,"");}
                else{mode += "v";}}
            else{mode="v";}
            GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_modeMarket",mode);
            location.href=location.href;
        },false);
    
        newdiv1=createElement("div",{"mouseOverText":getText("category_c")+"<br>"+getText("category_e"),"class":"link","style":"display:inline-block;height:20px;width:26px;background:url('"+GFX+"racksort2.jpg') repeat scroll -62px 0px transparent;"},newdiv);
        if (mode.match(/c/)&&mode.match(/e/)){
            newdiv1.style.backgroundPosition="-62px -20px";
        }else{
            newdiv1.addEventListener("mouseout",function(){this.style.backgroundPosition="-62px 0px";},false);
            newdiv1.addEventListener("mouseover",function(){this.style.backgroundPosition="-62px -20px";},false);
        }
        newdiv1.addEventListener("click",function(event){
            if(event.ctrlKey){
                if(mode.match(/ce/)){mode=mode.replace(/ce/,"");}
                else{mode += "ce";}}
            else{mode="ce";}
            GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_modeMarket",mode);
            location.href=location.href;
        },false);
    
        newdiv1=createElement("div",{"mouseOverText":getText("category_o"),"class":"link","style":"display:inline-block;height:20px;width:26px;background:url('"+GFX+"racksort2.jpg') repeat scroll -62px 0px transparent;"},newdiv);
        if (mode.match(/o/)&&mode.match(/o/)){
            newdiv1.style.backgroundPosition="-62px -20px";
        }else{
            newdiv1.addEventListener("mouseout",function(){this.style.backgroundPosition="-62px 0px";},false);
            newdiv1.addEventListener("mouseover",function(){this.style.backgroundPosition="-62px -20px";},false);
        }
        newdiv1.addEventListener("click",function(event){
            if(event.ctrlKey){
                if(mode.match(/o/)){mode=mode.replace(/o/,"");}
                else{mode += "o";}}
            else{mode="o";}
            GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_modeMarket",mode);
            location.href=location.href;
        },false);
    
        newdiv1=createElement("div",{"mouseOverText":getText("category_z"),"class":"link","style":"display:inline-block;height:20px;width:26px;background:url('"+GFX+"racksort2.jpg') repeat scroll -36px 0px transparent;"},newdiv);
        if (mode.match(/z/)){
            newdiv1.style.backgroundPosition="-36px -20px";
        }else{
            newdiv1.addEventListener("mouseout",function(){this.style.backgroundPosition="-36px 0px";},false);
            newdiv1.addEventListener("mouseover",function(){this.style.backgroundPosition="-36px -20px";},false);
        }
        newdiv1.addEventListener("click",function(event){
            if(event.ctrlKey){
                if(mode.match(/z/)){mode=mode.replace(/z/,"");}
                else{mode += "z";}}
            else{mode="z";}
            GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_modeMarket",mode);
            location.href=location.href;
        },false);
        */
        var pageId=unsafeWindow.market_filter_pid;
        var userId=unsafeWindow.market_filter_name;
        var marktoffers_rows=$("marktoffers_rows");
        if(unsafeWindow.market_filter_own==0){
            // Market page
            err_trace="Market page";
            var nothingToBuy=true;
    
            // Page of a single product
            if((pageId!=-1)&&(userId=="")&&(unsafeWindow.market_guild_filter==0)){
                err_trace="Market page, single product";
                var preisKlasse=0;
                // $("offertypeselector").style.display="none";
    
                newdiv1=createElement("div",{"prod":pageId},market_beraterline.children[0]);
                newdiv1.addEventListener("mouseover",function(event){ showGoToMarketToolTip(event,this.getAttribute("prod")); },false);             
                produktPic(0,pageId,newdiv1);
                newspan=createElement("div",{"style":"display:inline-block;"},newdiv1,numberFormat(prodStock[0][pageId],0));
    
                // NPC price
                newdiv1=createElement("div",{},market_beraterline.children[0]);
                err_trace="Market page, single product, NPC";
                if(NPC[0][pageId]){
                    if(!isNaN(NPC[0][pageId])){
                        newspan=createElement("span",{},newdiv1,"NPC&nbsp;"+numberFormat(NPC[0][pageId],2));
                    }else if (NPC[0][pageId].match(/^f/)){
                        newspan=createElement("span",{},newdiv1,"*NPC*&nbsp;"+numberFormat(parseFloat(NPC[0][pageId].replace("f",""),10),2));
                    }else if (NPC[0][pageId].match(/^c/)){
                        newspan=createElement("span",{},newdiv1,"NPC&nbsp;<span style='display:inline-block;vertical-align:bottom;'>"+coinsFormat(parseInt(NPC[0][pageId].replace("c",""),10)).innerHTML+"</span>");
                        //coinsFormat(parseInt(NPC[0][pageId].replace("c",""),10),newdiv).style.cssFloat="right";
                    }
                    if((npcSaison[pageId]!=undefined)&&(!npcSaison[pageId])){
                        newspan.style.textDecoration="line-through";
                        newspan.setAttribute("class","hoverNoTextDecoration");
                    }
                }else{
                    createElement("span",{},newdiv1,"NPC&nbsp;--");
                }
                // Link to previous/next product
                err_trace="Market page, single product, prev/next";
                var c=0;
                while ((c<prodNameSort[0].length)&&(prodNameSort[0][c]!=pageId)){ c++; }
                var pageIdVor=c-1;
                if(pageIdVor<0){ pageIdVor+=prodNameSort[0].length; }
                while(prodBlock[0][prodNameSort[0][pageIdVor]].match(/t/)||prodBlock[0][prodNameSort[0][pageIdVor]].match(/l/)){
                    pageIdVor--;
                    if(pageIdVor<0){ pageIdVor+=prodNameSort[0].length; }
                }
                pageIdVor=prodNameSort[0][pageIdVor];
                var pageIdNach=c+1;
                if(pageIdNach>prodNameSort[0].length-1){ pageIdNach=0; }
                while(prodBlock[0][prodNameSort[0][pageIdNach]].match(/t/)||prodBlock[0][prodNameSort[0][pageIdNach]].match(/l/)){
                    pageIdNach++;
                    if(pageIdNach>prodNameSort[0].length-1){ pageIdNach=0; }
                }
                pageIdNach=prodNameSort[0][pageIdNach];
                newdiv1=createElement("div",{},market_beraterline.children[0]);
                newspan=createElement("div",{"class":"link2","style":"display:inline-block;padding-right:2px;","prod":pageIdVor},newdiv1,"<<");
                newspan.addEventListener("click",function(event){ showMarket(this.getAttribute("prod")); },false);
                newspan.addEventListener("mouseover",function(event){ showGoToMarketToolTip(event,this.getAttribute("prod")); },false);
                newspan=createElement("div",{"class":"link2","style":"display:inline-block;","prod":pageIdNach},newdiv1,">>");
                newspan.addEventListener("click",function(event){ showMarket(this.getAttribute("prod")); },false);
                newspan.addEventListener("mouseover",function(event){ showGoToMarketToolTip(event,this.getAttribute("prod")); },false);
    
                // Total amount of all offers
                // newtd=createElement("td",{"align":"right","style":"border-top:1px solid;"});
                // newtd.innerHTML=numberFormat(sumTotal,0);
                // candtr[candtr.length-1].insertBefore(newtd,candtr[candtr.length-1].firstElementChild);
    
                // Set price field
                err_trace="Market page, single product, set price";
                newdiv1=createElement("div",{},market_beraterline.children[1]);
                newinput=createElement("input",{"id":"marketButton_price","value":numberFormat(gut[pageId],2),"class":"text","maxlength":"10","style":"width:65px;text-align:right;background-color:#589456;"},newdiv1);
                newinput.addEventListener("mouseover",function(event){ toolTip.show(event,getText("price")+"<br>"+getText("observed")+":&nbsp;"+moneyFormat(gutBeob[pageId])); },false);
                if(valNimmBeob){
                    newinput.readOnly=true;
                }else{
                    newinput.addEventListener("focus",function(){
                        this.style.backgroundColor="white";
                        unsafeWindow.clearMarketTimer();
                    },false);
                    newinput.addEventListener("blur",function(){
                        this.style.backgroundColor="#589456";
                        if(!unsafeWindow.market_timer['update']){ unsafeWindow.market_timer['update'] = unsafeWindow.setInterval("marketTimer()",1000); }
                    },false);
                    newinput.addEventListener("change",function(){
                        var currId=unsafeWindow.market_filter_pid;
                        var preis=Math.max(0,parseFloat(this.value.replace(regDelimThou,"").replace(regDelimDeci,"."),10));
                        var thisNode=this;
                        var yesFkt = function(){
                            gut[currId]=preis;
                            GM_setValueCache(COUNTRY+"_"+SERVER+"_gut",implode(gut));
                            raiseEventTop("gameChangedGut");
                            unsafeWindow.showOffers();
                            if(!unsafeWindow.market_timer['update']){ unsafeWindow.market_timer['update'] = unsafeWindow.setInterval("marketTimer()",1000); }
                        };
                        var noFkt = function(){
                            thisNode.value=numberFormat(gut[currId],2);
                            thisNode=null;
                        };
                        if(preis==0){
                            alert2(getText("alertSetPriceNone").replace(/%PRODUCT%/,prodName[0][currId]),getText("yes"),getText("no"),yesFkt,noFkt);
                        }else if((!isNaN(NPC[0][currId]))&&(preis>NPC[0][currId])){
                            alert2(getText("alertSetPriceOverNPC").replace(/%PRODUCT%/,prodName[0][currId]).replace(/%PRICE%/,moneyFormat(preis)).replace(/%NPC%/,moneyFormat(NPC[0][currId])),getText("yes"),getText("no"),yesFkt,noFkt);
                        }else if ((gutBeob[currId]!=undefined)&&(gutBeob[currId]>0)){
                            if(preis<0.7*gutBeob[currId]){
                                alert2(getText("alertSetPriceUnderObs").replace(/%PRODUCT%/,prodName[0][currId]).replace(/%PRICE%/,moneyFormat(preis)).replace(/%OBS%/,moneyFormat(gutBeob[currId])),getText("yes"),getText("no"),yesFkt,noFkt);
                            }else if (1.3*gutBeob[currId]<preis){
                                alert2(getText("alertSetPriceOverObs").replace(/%PRODUCT%/,prodName[0][currId]).replace(/%PRICE%/,moneyFormat(preis)).replace(/%OBS%/,moneyFormat(gutBeob[currId])),getText("yes"),getText("no"),yesFkt,noFkt);
                            }else{
                                yesFkt();
                            }
                        }else{
                            yesFkt();
                        }
                    },false);
                }

                // Statistic server
                err_trace="Market page, single product, Statistic";
                if (STAT_VIEW && STAT_VIEW[COUNTRY]){
                    newdiv1=createElement("div",{"id":"marketButton_stats","class":"link2 hoverBlack","style":"position:relative;width:80px;height:40px;background: url('"+GFX+"stadt/uebersicht.gif') repeat scroll 0% 0% transparent;"},market_beraterline.children[2]);
                    createElement("div",{"style":"position:absolute;top:13px;width:80px;font-weight:bold;text-align:center;"},newdiv1,getText("statistics"));
                    newdiv1.addEventListener("click",function(){
                        showStatisticFullscreen(unsafeWindow.market_filter_pid);
                    },false);
                }
            }else{
                var preisKlasse=2;
            }
    
            if(pageId!=-1){
                //Link to NPC-Shop
                err_trace="Link to NPC";
                if(nothingToBuy && (unsafeWindow.marketlist_currentpage==1) && (prodTyp[0][pageId]=="v") && $top("shop")){
                    newdiv1=createElement("div",{"id":"marketButton_npc","class":"link2 hoverBlack","style":"position:relative;width:80px;height:40px;background: url('"+GFX+"stadt/uebersicht.gif') repeat scroll 0 0 transparent;"},market_beraterline.children[3]);
                    createElement("div",{"style":"position:absolute;top:13px;width:80px;font-weight:bold;text-align:center;"},newdiv1,getText("SGH"));
                    newdiv1.addEventListener("click",showSGH,false);
                }
            }
    
            // Page of a single user
            /*
            if(userId!=""){
                canda=candtr[3].getElementsByTagName("a");
                if(canda[1]){ var thisUser=canda[1].innerHTML; }
                newtr=createElement("tr",{},candtable[0]);
                newtd=createElement("td",{},newtr);
                if (thisUser){igm(thisUser,newtd);}
                stats(userId,newtd);
            }
            */
        }
        
        // Redesign of table
        err_trace="Redesign";
        var currId, currOffer, time, sum=[0,0];
        for(var v=0;v<marktoffers_rows.childElementCount;v++){
            err_trace="Redesign, row "+v;
            row=marktoffers_rows.children[v];
            if(row.childElementCount<6){ continue; }
            currId=/market_price_tt(\d+)/.exec(row.children[2].getAttribute("onmouseover"))[1];
            currOffer=null;
            for(var i=0;i<unsafeWindow.market_offers.length;i++){
                if(currId==unsafeWindow.market_offers[i].id){
                    currOffer=unsafeWindow.market_offers[i];
                    break;
                }
            }
            if(!currOffer){ continue; }
            row.children[3].removeAttribute("onmouseover");
            row_title=$("market_amount_tt"+currOffer["id"]);
            help=createElement("div",{},false,row_title.innerHTML);
            row_title.innerHTML="";
            row_title.appendChild(help);
            // TODO(Seberoth): What is time now?
            if(currOffer["zeit"]){
                time=parseInt(currOffer["zeit"],10)+0;
                if(countDays(time,now)==0){
                    createElement("div",{},row_title,getText("sinceX").replace(/%1%/,getDaytimeStr(time,false,true)+"&nbsp;"+getText("shortOClock")));
                }else{
                    createElement("div",{},row_title,getText("sinceX").replace(/%1%/,getFormattedDateStr(time,2,false)+",&nbsp;"+getDaytimeStr(time,false,true)+"&nbsp;"+getText("shortOClock")));
                }
            }
            var prodId=parseInt(currOffer["p"],10);
            var menge=parseInt(currOffer["a"],10);
            var preis=parseFloat(currOffer["pr"],10);
            if((pageId!=-1)&&(userId=="")&&(unsafeWindow.market_guild_filter==0)){
                createElement("div",{},row_title,getText("above")+": "+numberFormat(sum[0]));
            }
            sum[0] += menge;
            sum[1] += menge*preis;
            row.children[2].innerHTML=numberFormat(preis,2);
            row.setAttribute("offerId",currOffer["id"]);
            //GutPreis zeigen
            newdiv=createElement("div",{},false,numberFormat(gut[prodId],2));
            row.insertBefore(newdiv,row.children[6]);
            // own offers
            if((unsafeWindow.market_filter_own==0)&&(currOffer["s"])){
                row.children[5].setAttribute("class","market_buy market_noicon");
                row.children[5].setAttribute("onclick","");
            }
            if(NPC[0][prodId]&&((npcSaison[prodId]==undefined)||(npcSaison[prodId]))&&(preis>=NPC[0][prodId])){
                if(preisKlasse<1){
                    preisKlasse++;
                    row.style.borderTop="2px solid white";
                }
                if(valKauflimitNPC&&row.children[5]){ //zu teuer Link entfernen (NPC)
                    if(unsafeWindow.market_filter_own==0){
                        row.children[5].setAttribute("class","market_buy market_noicon");
                        row.children[5].setAttribute("onclick","");
                    }
                    createElement("div",{},row_title,getText("overNPCprice")+" ("+numberFormat(NPC[0][prodId],2)+")");
                }
                row.style.opacity="0.5";
                row.children[5].style.fontStyle="italic";
                if (0.9*preis>NPC[0][prodId]){ //111% NPC
                    row.style.fontStyle="italic";
                    if(preisKlasse<2){
                        preisKlasse++;
                        row.style.borderTop="2px dashed white";
                    }
                }
            }else if(gut[prodId]!=0){
                var help=100*preis/gut[prodId];
                if(help<=valKauflimit[0][0]){
                    if(row.children[5]){ row.children[5].style.backgroundColor="#"+valKauflimit[0][1]; } //billig Angebot highlight
                }else if(help>valKauflimit[1]){ //zu teuer Link entfernen (Limit)
                    if(row.children[5]){
                        if(unsafeWindow.market_filter_own==0){
                            row.children[5].setAttribute("class","market_buy market_noicon");
                            row.children[5].setAttribute("onclick","");
                        }
                        createElement("div",{},row_title,getText("overX").replace(/%1%/,valKauflimit[1]+"%"));
                    }
                    row.style.opacity="0.7";
                }
            }
            if(row.children[5].getAttribute("class").search(/market_noicon/)==-1){ nothingToBuy=false; }
            
            if (row.children[4].children[0]&&(highlightUser[row.children[4].children[0].innerHTML.replace(/[ ]\[.*\]/,"")])){
                row.children[4].children[0].style.backgroundColor="#"+highlightUser[row.children[4].children[0].innerHTML.replace(/[ ]\[.*\]/,"")];
            }
            if (highlightProducts[1][prodId]){
                row.children[1].style.backgroundColor="#20b2aa";
            }
            row.addEventListener("mouseover",function(event){ toolTip.show(event,$("market_amount_tt"+this.getAttribute("offerId")).innerHTML); },false);
        }
        if((unsafeWindow.market_filter_own==1)&&(userId=="")&&(unsafeWindow.market_guild_filter==0)){
            createElement("div",{},market_beraterline.children[0],sign_sum+"&nbsp;"+moneyFormatLimit(sum[1],100000));
        }
        // No offers
        if(sum[0]==0){
            // Page of a single product
            if((unsafeWindow.market_filter_own==0)&&(pageId!=-1)&&(userId=="")&&(unsafeWindow.market_guild_filter==0)){
                newdiv=createElement("div",{"style":"padding:2px;"},marktoffers_rows);
                createElement("div",{"style":"float:left;","class":"kp"+pageId},newdiv);
                createElement("div",{"onclick":"market_filter_name=''; market_filter_pid="+pageId+"; showOffers();","class":"market_product underline link","title":prodName[0][pageId]},newdiv,prodName[0][pageId]);
                if(NPC[0][pageId]){
                    if((npcSaison[pageId]!=undefined)&&(!npcSaison[pageId])){
                        createElement("div",{"class":"market_price"},newdiv);
                        createElement("div",{"class":"market_amount"},newdiv);
                        createElement("div",{"class":"market_seller"},newdiv);
                    }else if(!isNaN(NPC[0][pageId])){
                        createElement("div",{"class":"market_price"},newdiv,numberFormat(NPC[0][pageId],2));
                        createElement("div",{"class":"market_amount"},newdiv,"0");
                        newdiv1=createElement("div",{"class":"market_seller"},newdiv);
                        createElement("span",{},newdiv1,"NPC");
                    }else if (NPC[0][pageId].match(/^f/)){
                        createElement("div",{"class":"market_price"},newdiv,numberFormat(3*parseFloat(NPC[0][pageId].replace("f",""),10),2));
                        createElement("div",{"class":"market_amount"},newdiv,"0");
                        newdiv1=createElement("div",{"class":"market_seller"},newdiv);
                        createElement("span",{},newdiv1,"*NPC*");
                    }else{
                        createElement("div",{"class":"market_price"},newdiv);
                        createElement("div",{"class":"market_amount"},newdiv);
                        createElement("div",{"class":"market_seller"},newdiv);
                    }
                }else{
                    createElement("div",{"class":"market_price"},newdiv);
                    createElement("div",{"class":"market_amount"},newdiv);
                    createElement("div",{"class":"market_seller"},newdiv);
                }           
            }
        }
        marktoffers_rows=null;
        // Buttons
        err_trace="buttons";
        /*
        newdiv=createElement("div",{"id":"marketButton_current","class":"link hoverBlack","style":"position:absolute;top:475px;left:545px;width:80px;height:40px;font-size:8pt;background: url('"+GFX+"stadt/uebersicht.gif') repeat scroll 0% 0% transparent;"},ALL);
        newdiv.addEventListener("click",function(){showMarket();},false);
        createElement("div",{"style":"position:absolute;top:7px;left:7px;width:67px;color:white;font-weight: bold;"},newdiv,getText("currentOffers"));
        */
        newdiv1=createElement("div",{"id":"marketButton_tablePrices","class":"link2 hoverBlack","style":"position:relative;width:80px;height:40px;background:url('"+GFX+"stadt/uebersicht.gif') repeat scroll 0% 0% transparent;"},market_beraterline.children[4]);
        newdiv1.addEventListener("click",function(){
            unsafeWindow.buildInfoPanel("stock",{"page":1,"prodType":0,"filterCategory":unsafeWindow.market_filter_pid?prodTyp[0][unsafeWindow.market_filter_pid]:null});
        },false);
        createElement("div",{"style":"position:absolute;top:13px;width:80px;font-weight:bold;text-align:center;"},newdiv1,getText("prices"));
    
        newdiv1=createElement("div",{"id":"marketButton_tableStock","class":"link2 hoverBlack","style":"position:relative;width:80px;height:40px;background:url('"+GFX+"stadt/uebersicht.gif') repeat scroll 0% 0% transparent;"},market_beraterline.children[5]);
        newdiv1.addEventListener("click",function(){
            unsafeWindow.buildInfoPanel("stock",{"page":2,"prodType":0,"filterCategory":unsafeWindow.market_filter_pid?prodTyp[0][unsafeWindow.market_filter_pid]:null});
        },false);
        createElement("div",{"style":"position:absolute;top:13px;width:80px;font-weight:bold;text-align:center;"},newdiv1,getText("stock"));
    
        market_beraterline=null;
        canda=null;candtable=null;candtr=null;candtd=null;canddiv=null;newa=null;newinput=null;newspan=null;newdiv=null;newdiv1=null;
    }catch(err){ GM_logError("do_market ("+err_trace+")\n"+err); }
    }
    unsafeOverwriteFunction("showOffers",function(page){
        try{
            unsafeWindow._showOffers(page);
        }catch(err){GM_logError("_showOffers\n"+err);}
        try{
            do_market();
            // GM_log("unsafeWindow.market_offers:\n"+print_r(unsafeWindow.market_offers,"",true,"\n"));        
            raiseEvent("gameOpenMarket");
        }catch(err){GM_logError("showOffers\n"+err);}
    });
    unsafeOverwriteFunction("openMarketNewOffer",function(){
        try{
            unsafeWindow._openMarketNewOffer();
        }catch(err){GM_logError("_openMarketNewOffer\n"+err);}
        try{
            var err_trace="Init";
            var currId=unsafeWindow.market_filter_pid;
            if(currId!=-1){
                if(lastOffer[currId]){
                    $("marketnewoffer_amount").value=lastOffer[currId][0];
                    $("marketnewoffer_price1").value=lastOffer[currId][1];
                    $("marketnewoffer_price2").value=(lastOffer[currId][2]<10?"0":"")+lastOffer[currId][2];
                    if($("marketnewoffer_price_comb")){ $("marketnewoffer_price_comb").value=lastOffer[currId][1]+delimDeci+(lastOffer[currId][2]<10?"0":"")+lastOffer[currId][2]; }
                }else{
                    $("marketnewoffer_amount").value=0;
                }
                keyup($("marketnewoffer_amount"));
        
                /*
                if ($("produkt_preis1")){
                    $("lbl_produkt_max").setAttribute("class",$("lbl_produkt_max").getAttribute("class")+" link");
                    $("lbl_produkt_max").addEventListener("click",function(){
                        $("produkt_anzahl").value=this.innerHTML.replace(regDelimThou,"");
                        keyup($("produkt_anzahl"));
                    },false);
                    $("produkt_anzahl").addEventListener("focus",checkPreis,false); // fired when offer-div opens
                    $("preisschild").addEventListener("keyup",function(event){
                        checkPreis();
                        if (event.keyCode==13){
                            var submitButton=$("preisschild").querySelector("#verkaufe_markt");
                            if(submitButton.style.display!="none"){ click(submitButton); }
                            submitButton=null;
                        }
                    },false);
                    if(valJoinPreise){
                        $("produkt_preis1").setAttribute("tabindex","0");
                        $("produkt_preis2").setAttribute("tabindex","0");
                        var newinput=createElement("input",{"id":"produkt_preis_ganz","type":"text","style":"position:absolute;left:0;top:0;background-color:#002300;color:#f0ffef;width:131px;text-align:right;border:1px solid #555;","tabindex":"2","maxlength":"9","name":"p_preis_ganz","class":"text thuge"},$("produkt_preis1").parentNode);
                        newinput.addEventListener("keyup",function(event){
                            if (event.keyCode==13){
                                var submitButton=$("preisschild").querySelector("#verkaufe_markt");
                                if(submitButton.style.display!="none"){ click(submitButton); }
                                submitButton=null;
                            }else{
                                var preis=this.value.replace(regDelimThou,"").replace(regDelimDeci,".");
                                var preis1=parseInt(preis,10);
                                var preis2=(preis.search(/\./)!=-1?(preis+"00").substr(1+preis.search(/\./),2):"00");
                                $("produkt_preis1").value=preis1;
                                $("produkt_preis2").value=preis2;
                                keyup($("produkt_preis1"));
                            }
                        },false);
                        newinput=null;
                    }
                }
                */
                
                // coins
                function checkPreisCoins(){
                    //GM_log("checkPreisCoins "+oldPricesInserted);
                    window.setTimeout(function(){ // first let finish the functions
                        if(oldPricesInserted==0){ //old offer set
                            lastOffer[0]=[parseInt($("coinsanzahl").value,10),parseInt($("coinspreis").value,10),$("coinssollpreis").checked];
                            try{
                                GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_lastOffer",implode(lastOffer));
                            }catch(err){ GM_log("checkPreisCoins: 0 not saved!\n"+err); }
                        }else{
                            oldPricesInserted=0;
                            if(lastOffer[0]){
                                $("coinsanzahl").value=lastOffer[0][0];
                                $("coinspreis").value=lastOffer[0][1];
                                $("coinssollpreis").checked=lastOffer[0][2];
                                unsafeWindow.chkAmount();
                                unsafeWindow.calcMarketPrice();
                            }
                        }
                        var currPreis=parseInt($("coinsmarktpreis").innerHTML,10);
                        var currAnzahl=parseInt($("coinsanzahl").value,10);
                        var currUserPreis=parseInt($("coinsuserpreis").innerHTML,10);
            
                        if(protectMinRack){ //rack amount protection
                            prodStock[0][0]=parseInt($("lbl_produkt_max").innerHTML.replace(regDelimThou,""),10);
                            if(currAnzahl>prodStock[0][0]-prodMinRack[0][0]){
                                currAnzahl=Math.max(0,prodStock[0][0]-prodMinRack[0][0]);
                                $("coinsanzahl").value=currAnzahl;
                            }
                        }
                        var newtable=createElement("table");
                        var newtr;
                        $("divBerInfoCoins").replaceChild(newtable,$("divBerInfoCoins").getElementsByTagName("table")[0]);
                        if (gut[0]){
                            $("coinspreisschild").querySelector("#verkaufe_markt").style.display=(((100*currPreis>valVerkaufLimitDown*gut[0]) && (100*currPreis<valVerkaufLimitUp*gut[0]))?"":"none");
                            newtr=createElement("tr",{},newtable);
                            createElement("td",{"style":"color:#f0ffef;font-weight:bold;"},newtr,getText("price")+": ");
                            createElement("td",{"style":"color:#f0ffef;font-weight:bold;text-align:right;"},newtr,moneyFormatLimit(gut[0],100));
                        }
            
                        newtr=createElement("tr",{},newtable);
                        createElement("td",{"style":"color:#f0ffef;font-weight:bold;"},newtr,getText("value")+": ");
                        createElement("td",{"style":"color:#f0ffef;font-weight:bold;text-align:right;"},newtr,moneyFormatLimit(currUserPreis*currAnzahl,100));
            
                        newtr=createElement("tr",{},newtable);
                        createElement("td",{"style":"color:#f0ffef;font-weight:bold;"},newtr,getText("commission")+": ");
                        createElement("td",{"style":"color:#f0ffef;font-weight:bold;text-align:right;"},newtr,numberFormat(((currPreis-currUserPreis)/currUserPreis)*100,1)+"%");
                        if (preisBeob[0]){
                            newtr=createElement("tr",{},newtable);
                            createElement("td",{"style":"color:#f0ffef;font-weight:bold;"},newtr,"min: ");
                            createElement("td",{"style":"color:#f0ffef;font-weight:bold;text-align:right;"},newtr,moneyFormatLimit(preisBeob[0][2],100));
                        }
                        if (gutBeob[0]){
                            newtr=createElement("tr",{},newtable);
                            createElement("td",{"style":"color:#f0ffef;font-weight:bold;"},newtr,getText("observed")+": ");
                            createElement("td",{"style":"color:#f0ffef;font-weight:bold;text-align:right;"},newtr,moneyFormatLimit(gutBeob[0],100));
                        }
                        newtable=null;newtr=null;
                    },200);
                }
            /*
                if($("coinsauflager")){
                    $("coinsauflager").setAttribute("class",$("coinsauflager").getAttribute("class")+" link");
                    $("coinsauflager").addEventListener("click",function(){
                        $("coinsanzahl").value=this.innerHTML;
                        keyup($("coinsanzahl"));
                    },false);
                }
                if($("coinspreisschild")){
                    var newdiv=createElement("div",{"style":"position:absolute;top:0;left:330px;width:150px"},$("coinspreisschild"));
                    newdiv=createElement("div",{"id":"divBerInfoCoins","style":"float:left;padding:3px;background-color:#002300;border:5px solid #594230;color:#f0ffef;font-weight:bold;"},newdiv);
                    createElement("table",{},newdiv);
                    newdiv=null;
            
                    $("coinsanzahl").addEventListener("keyup",function(){ this.value=this.value.replace(/\D/g,""); },false);
                    $("coinspreis").addEventListener("keyup",function(){ this.value=this.value.replace(/\D/g,""); },false);
                    $("coinspreisschild").addEventListener("click",checkPreisCoins,false);
                    $("coinspreisschild").addEventListener("keyup",function(event){
                        checkPreisCoins();
                        if (event.keyCode==13){
                            var submitButton=$("preisschild").querySelector("#verkaufe_markt");
                            if(submitButton.style.display!="none"){ click(submitButton); }
                            submitButton=null;
                        }
                    },false);
            
                    // bugfix: no focus when coinspreisschild opens
                    $("coinspreisschild").addEventListener("DOMAttrModified",function(event){
                        if((event.target.id=="coinspreisschild")&&(event.attrName=="style")){
                            if(event.newValue.match(/display\:\s*block/)){
                                if(oldPricesInserted!=0){
                                    checkPreisCoins(); // fired when offer-div opens
                                }
                            }else{
                                if(oldPricesInserted==0){ oldPricesInserted=-1; }
                            }
                        }
                    }, false);
                }
            
                cand=null;candtable=null;
*/      
            }
        }catch(err){ GM_logError("openMarketNewOffer ("+err_trace+")\n"+err); }
    });
    unsafeOverwriteFunction("calcMarketFee",function(){
        try{
            unsafeWindow._calcMarketFee();
        }catch(err){GM_logError("_calcMarketFee\n"+err);}
        try{
            var err_trace="Init";
            var berater_box=$("marketnewoffer_berater");
            if(!berater_box){
                berater_box=createElement("div",{"style":"position:absolute;top:0px;width:175px;right:-160px;background-position:-140px 0px;","class":"market_popup"});
                newdiv=$("marketnewoffer");
                newdiv.insertBefore(berater_box,newdiv.lastElementChild);
                berater_box=createElement("div",{"id":"marketnewoffer_berater","style":"position:relative;margin-top:35px;"},berater_box);
            }
            berater_box.innerHTML="";
            var currId=unsafeWindow.market_filter_pid;
            if(currId!=-1){
                var currPreis=parseFloat($("marketnewoffer_price1").value+"."+$("marketnewoffer_price2").value,10);
                var currAnzahl=parseInt($("marketnewoffer_amount").value,10);
                // Stock amount
                err_trace="Stock amount";
                var newdiv;
                if(newdiv=$("marketcreateoffer_stockamount")){
                    newdiv.innerHTML=numberFormat(prodStock[0][currId]);
                }               
                // Rack amount protection
                err_trace="Rack amount protection";
                if(protectMinRack){ 
                    if(currAnzahl>prodStock[0][currId]-prodMinRack[0][currId]){
                        currAnzahl=Math.max(0,prodStock[0][currId]-prodMinRack[0][currId]);
                        $("marketnewoffer_amount").value=currAnzahl;
                    }
                }
                // Block Submit Button
                err_trace="Submit Button";
                var submitButton = $("market_new_button");
                if(submitButton){
                    var help=null;
                    if(NPC[0][currId]){
                        if(!isNaN(NPC[0][currId])){
                            if(100*currPreis<20*NPC[0][currId]){ help=3; }
                            else if(100*currPreis>300*NPC[0][currId]){ help=4; }
                        }else if (NPC[0][currId].match(/^f/)){
                            if(100*currPreis<2*parseFloat(NPC[0][currId].replace("f",""),10)){ help=3; }
                            else if(100*currPreis>300*parseFloat(NPC[0][currId].replace("f",""),10)){ help=4; }
                        }
                    }
                    if((help!=null)&&gut[currId]){
                        if(100*currPreis<valVerkaufLimitDown*gut[currId]){ help=1; }
                        else if(100*currPreis>valVerkaufLimitUp*gut[currId]){ help=2; }
                    };
                    if(help==null){
                        submitButton.style.display="block";
                        newdiv = $("market_new_button_block");
                        if(newdiv){ newdiv.style.display="none"; }
                    }else{
                        submitButton.style.display="none";
                        newdiv = $("market_new_button_block");
                        if(!newdiv){
                            newdiv=createElement("div",{"id":"market_new_button_block","class":"alertbox","style":"padding:2px;width:100%;text-align:center;"});
                            insertAfter(newdiv,submitButton);
                        }
                        newdiv.style.display="block";
                        switch(help){
                        case 1: newdiv.innerHTML = "Too cheap"; break;
                        case 2: newdiv.innerHTML = "Too expensive"; break;
                        case 3: newdiv.innerHTML = "Not allowed - Too cheap"; break;
                        case 4: newdiv.innerHTML = "Not allowed - Too expensive"; break;
                        }
                    }
                    help=null;
                }
                submitButton=null;
                // Info Boards
                err_trace="berater_box";
                var newtable=createElement("table",{},berater_box);
                var newtr;
                newtr=createElement("tr",{},newtable);
                createElement("td",{"style":"color:#f0ffef;font-weight:bold;"},newtr,getText("price")+": ");
                if(gut[currId]){
                    createElement("td",{"style":"color:#f0ffef;font-weight:bold;text-align:right;"},newtr,moneyFormatLimit(gut[currId],100));
                } else {
                    createElement("td",{"style":"color:#f0ffef;font-weight:bold;text-align:right;"},newtr,"--");
                }
                newtr=createElement("tr",{},newtable);
                createElement("td",{"style":"color:#f0ffef;font-weight:bold;"},newtr,getText("value")+": ");
                createElement("td",{"style":"color:#f0ffef;font-weight:bold;text-align:right;"},newtr,moneyFormatLimit(currPreis*currAnzahl,100));
                newtr=createElement("tr",{},newtable);
                createElement("td",{"style":"color:#f0ffef;font-weight:bold;"},newtr,"min: ");
                if (preisBeob[currId]){
                    createElement("td",{"style":"color:#f0ffef;font-weight:bold;text-align:right;"},newtr,moneyFormatLimit(preisBeob[currId][2],100));
                }else{
                    createElement("td",{"style":"color:#f0ffef;font-weight:bold;text-align:right;"},newtr,"--");
                }
                newtr=createElement("tr",{},newtable);
                createElement("td",{"style":"color:#f0ffef;font-weight:bold;"},newtr,getText("observed")+": ");
                if (gutBeob[currId]){
                    createElement("td",{"style":"color:#f0ffef;font-weight:bold;text-align:right;"},newtr,moneyFormatLimit(gutBeob[currId],100));
                }else{
                    createElement("td",{"style":"color:#f0ffef;font-weight:bold;text-align:right;"},newtr,"--");
                }
                newtr=createElement("tr",{},newtable);
                createElement("td",{"style":"color:#f0ffef;font-weight:bold;"},newtr,getText("NPCprice")+": ");
                if(!NPC[0][currId]){
                    createElement("td",{"style":"color:#f0ffef;font-weight:bold;text-align:right;"},newtr,"--");
                }else if(!isNaN(NPC[0][currId])){
                    createElement("td",{"style":"color:#f0ffef;font-weight:bold;text-align:right;"},newtr,moneyFormatLimit(NPC[0][currId],100));
                }else if (NPC[0][currId].match(/^f/)){
                    createElement("td",{"style":"color:#f0ffef;font-weight:bold;text-align:right;"},newtr,"*"+moneyFormatLimit(parseFloat(NPC[0][currId].replace("f",""),10),100));
                }else if (NPC[0][currId].match(/^c/)){
                    coinsFormat(parseInt(NPC[0][currId].replace("c",""),10),createElement("td",{"style":"color:#f0ffef;font-weight:bold;text-align:right;"},newtr));
                }
                newtable=null;newtr=null;newdiv=null;
            }
            currId=null;
        
        }catch(err){ GM_logError("calcMarketFee\n"+err); }
    });
    unsafeOverwriteFunction("buyMarketOffer",function(id){
        try{
            unsafeWindow._buyMarketOffer(id);
        }catch(err){GM_logError("_buyMarketOffer\n"+err);}
        try{
            for(var i=0;i<unsafeWindow.market_offers.length;i++){
                if(id==unsafeWindow.market_offers[i].id){
                    var money=parseFloat($("bar").innerHTML.replace(getText("gamecurrency"),"").replace(/\s+/g,"").replace(regDelimThou,"").replace(regDelimDeci,"."),10);
                    $("marketbuyofferamount").value = Math.min(unsafeWindow.market_offers[i].a,Math.floor(money/unsafeWindow.market_offers[i].pr));
                    window.setTimeout(function() {
                        $("marketbuyofferamount").select();
                    }, 50);
                    unsafeWindow.calcMarketOfferCost();
                    money=null;
                    break;
                }
            }   
        }catch(err){ GM_logError("buyMarketOffer\n"+err); }
    });
    unsafeOverwriteFunction("marketAction",function(action,id,open){
        try{
            unsafeWindow._marketAction(action,id,open);
        }catch(err){GM_logError("_marketAction\n"+err);}
        try{
            if(action=="marketcreateoffer"){
                var currId=unsafeWindow.market_filter_pid;
                var amount=parseInt($("marketnewoffer_amount").value,10);
                var price1=parseInt($("marketnewoffer_price1").value,10);
                var price2=parseInt($("marketnewoffer_price2").value,10);
                lastOffer[currId]=[amount,price1,price2];
                GM_setValueCache(COUNTRY+"_"+SERVER+"_"+USERNAME+"_lastOffer",implode(lastOffer));
                currId=null;amount=null;price1=null;price2=null;
            }
        }catch(err){ GM_logError("marketAction\n"+err); }
    });
    unsafeOverwriteFunction("marketActionResponse",function(request,action,id,open){
        try{
            var result = checkRequest(request)
            if((result!=0)&&(result[0]!=0)&&(result[1]["offers"])){
                //GM_log("marketActionResponse "+result[1]["offers"].length);                   
                // Save own offers
                var err_trace="Save own offers";
                var _ownMarketOffers=new Array();
                var marketOffersArr=new Array();
                var row,prod,preis,menge,menge_sum;
                err_trace="Save own offers";
                for(var v=0;v<result[1]["offers"].length;v++){
                    row=result[1]["offers"][v];
                    prod=parseInt(row["p"],10);
                    preis=parseFloat(row["pr"],10);
                    menge=parseInt(row["a"],10);
                    if(row["s"]){
                        _ownMarketOffers.push([prod,preis,menge]);
                    }
                    if(!marketOffersArr[prod]){ marketOffersArr[prod]=new Array(); }
                    // TODO(Seberoth): What is time again?
                    // marketOffersArr[prod].push([menge,preis,parseInt(row["zeit"],10)]);
                    marketOffersArr[prod].push([menge,preis]);
                }
                // sort the ownMarketOffers-data
                _ownMarketOffers.sort(function(a,b){
                    if(a[0]==b[0]){
                        return(a[1]-b[1]);
                    } else if(prodTyp[0][a[0]]==prodTyp[0][b[0]]){
                        return(a[0]-b[0]);
                    } else {
                        return({"c":0,"v":1,"e":2,"o":3,"fw1":4,"fw2":5,"fw3":6,"fw4":7,"z":8}[prodTyp[0][a[0]]]-{"c":0,"v":1,"e":2,"o":3,"fw1":4,"fw2":5,"fw3":6,"fw4":7,"z":8}[prodTyp[0][b[0]]]);
                    }
                });
                ownMarketOffers=_ownMarketOffers;

                GM_setValueCache(COUNTRY+"_"+SERVER+"_"+USERNAME+"_ownMarketOffers",implode(ownMarketOffers));
                doMarketoffersNotepad();
                // calculate all observed prices
                err_trace="Observing prices";
                for(var v=0;v<prodBlock[0].length;v++){
                    if(prodBlock[0][v]==undefined){ continue; }
                    if((!prodBlock[0][v].match(/t/))&&(!prodBlock[0][v].match(/l/))){
                        if(marketOffersArr[v]){
                            // sort offers
                            marketOffersArr[v].sort(function(a,b){
                                return((a[1]==b[1])?(a[2]-b[2]):(a[1]-b[1]));
                            });
                            marketOffersArr[v]=marketOffersArr[v].slice(0,18);
                            menge_sum=0;
                            for(var w=0;w<marketOffersArr[v].length;w++){
                                menge_sum += marketOffersArr[v][w][0];
                            }
                            gutBeob[v]=calcObservedPrice((prodTyp[0][v]=="z"?2:1),marketOffersArr[v]);
                            if (valNimmBeob){
                                if(!isNaN(NPC[0][v])){
                                    gut[v]=Math.min(gutBeob[v],NPC[0][v]);
                                }else{
                                    gut[v]=gutBeob[v];
                                }
                            }
                            if(!(preisBeob instanceof Array)){ preisBeob=new Array(); }
                            preisBeob[v]=[true,now,marketOffersArr[v][0][1],marketOffersArr[v][marketOffersArr[v].length-1][1],menge_sum];
                        }else{
                            // no offers
                            if (valNimmBeob){
                                if(!isNaN(NPC[0][v])){
                                    gut[v]=NPC[0][v];
                                }else{
                                    gut[v]=0;
                                }
                            }
                            if(!(preisBeob instanceof Array)){ preisBeob=new Array(); }
                            if(!(preisBeob[v]&&preisBeob[v][0])){
                                preisBeob[v]=[false,now,,,0];
                            }               
                        }
                    }
                }
                _ownMarketOffers=null;marketOffersArr=null;
                row=null;prod=null;preis=null;menge=null;menge_sum=null;
                if (valNimmBeob){
                    GM_setValueCache(COUNTRY+"_"+SERVER+"_gut",implode(gut));
                    raiseEventTop("gameChangedGut");
                }
                GM_setValueCache(COUNTRY+"_"+SERVER+"_gutBeob",implode(gutBeob));
                GM_setValueCache(COUNTRY+"_"+SERVER+"_preisBeob",implode(preisBeob));
                raiseEventTop("gameChangedBeobPrice");
            }
        }catch(err){GM_logError("marketActionResponse ("+err_trace+")\nv="+v+"\n"+err);}
        try{
            unsafeWindow._marketActionResponse(request,action,id,open);
        }catch(err){GM_logError("_marketActionResponse\n"+err);}
    });
    quicklinks();
    // Buy offer by pressing Enter
    if(newdiv=$("marketbuyofferamount")){
        newdiv.addEventListener("keyup",function(event){
            if(event.keyCode==13){
                unsafeWindow.calcMarketOfferCost();
                var newdiv=$("marketbuyofferbutton");
                if(newdiv.style.display=="block"){
                    click(newdiv);
                }
                newdiv=null;
            }
        },false);
    }
    // Create offer enter stock amount
    if(newdiv=$("marketcreateoffer_stockamount")){
        newdiv.setAttribute("class","link");
        newdiv.addEventListener("click",function(event){
            var newdiv=$("marketnewoffer_amount");
            if(newdiv){
                newdiv.value=prodStock[0][unsafeWindow.market_filter_pid];
                keyup(newdiv);
            }
            newdiv=null;
        },false);
    }   
    
    // Notepad for Non-Premium
    err_trace="Notepad for Non-Premium";
    if((newdiv=$("sub_notepad"))&&(newdiv.style.display=="none")){
        newdiv=insertAfter(createElement("div",{"id":"beraterNotepad","class":"submenueitem link","style":"display:block;"}),newdiv);
        createElement("img",{"src":GFX+"guild/contract.gif","style":"width:15px;height:15px;"},newdiv);
        newdiv.addEventListener("mouseover",function(event){ toolTip.show(event,unsafeWindow.lng_t_notizen); },false);
        newdiv.addEventListener("click",function(){
            $("notepadentry").value=GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_notepad","");
            unsafeWindow.calcNotepadLetters();
            unsafeWindow.showDiv("notepad");
        },false);
        newdiv=$("notepadheader");
        newdiv.getElementsByTagName("img")[0].removeAttribute("onclick");
        newdiv.getElementsByTagName("img")[0].addEventListener("click",function(){
            GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_notepad",$("notepadentry").value,72);
            unsafeWindow.hideDiv("notepad");
        },false);
    }

    // BuyNotepad
    err_trace="BuyNotepad";
    newdiv=createElement("div",{"style":"position:relative;margin-top:5px;display:block;white-space:nowrap;"},$("divRightBorder"));
    newdiv1=createElement("div",{"class":"opener link","style":"display:inline-block;vertical-align:top;background-position:0px "+(show["buyNotepad"]?-20:0)+"px;"},newdiv);
    newdiv1.addEventListener("click",function(){
        show["buyNotepad"]=!show["buyNotepad"];
        GM_setValueCache(COUNTRY+"_"+SERVER+"_"+USERNAME+"_show",implode(show));
        if(show["buyNotepad"]){
            this.style.backgroundPosition="0px -20px";
            $("buyNotepad").style.display="inline-block";
            doBuyNotepad();
        }else{
            this.style.backgroundPosition="0px 0px";
            $("buyNotepad").style.display="none";
        }
    },false);
    createElement("div",{"id":"buyNotepad","style":"display:"+(show["buyNotepad"]?"inline-block":"none")+";"},newdiv);

    // MarketoffersNotepad
    err_trace="MarketoffersNotepad";
    newdiv=createElement("div",{"style":"position:relative;margin-top:5px;display:block;white-space:nowrap;"},$("divRightBorder"));
    newdiv1=createElement("div",{"class":"opener link","style":"display:inline-block;vertical-align:top;background-position:0px "+(show["marketoffersNotepad"]?-20:0)+"px;"},newdiv);
    newdiv1.addEventListener("click",function(){
        show["marketoffersNotepad"]=!show["marketoffersNotepad"];
        GM_setValueCache(COUNTRY+"_"+SERVER+"_"+USERNAME+"_show",implode(show));
        if(show["marketoffersNotepad"]){
            this.style.backgroundPosition="0px -20px";
            $("marketoffersNotepad").style.display="inline-block";
        }else{
            this.style.backgroundPosition="0px 0px";
            $("marketoffersNotepad").style.display="none";
        }
        doMarketoffersNotepad();
    },false);
    createElement("div",{"id":"marketoffersNotepad","style":"display:"+(show["marketoffersNotepad"]?"inline-block":"none")+";"},newdiv);
    doMarketoffersNotepad();

    document.addEventListener("gameChangedOwnMarketOffers",function(){
        window.setTimeout(function(){
            ownMarketOffers=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_ownMarketOffers"),"event:gameChangedOwnMarketOffers/ownMarketOffers",{});
            doMarketoffersNotepad();
        },0);
    },false);
    // Points and level.  levelLog[day]=[points,rank,market sales,contract sales,farmi money]
    err_trace="Points and level";
    levelLog=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_levelLog","[]"),"do_main/levelLog",[]);
    if(!(levelLog instanceof Array)){ levelLog = []; }
    function setLevelLogId(){
        levelLog.sort(sortObjFunctions["date"]);
        for(levelLogId=levelLog.length-1;levelLogId>=0;levelLogId--){
            if(levelLog[levelLogId][0]==todayServerStr){ return; }
        }
        levelLog.push([todayServerStr,0,null,0,0,0]);
        setLevelLogId();
    }
    setLevelLogId();
    function getDailyRanking(){
    try{
        if(!levelLog[levelLogId][2]){
            logBubble.add(getText("requestingUserStatistic"));
            GM_xmlhttpRequest({
                method: "GET",
                url: "http://s"+SERVER+"."+GAMEPAGES[COUNTRY]+"/city/ajax.php?mode=stats&type=pkt&page=1&findme=1&rid="+unsafeWindow.rid,
                headers: {"Content-type": "application/x-www-form-urlencoded"},
                onload: function(response){
                    try{
                        var result=checkRequest(response);
                        if(result){
                            for(var i in result[1]["data"]){
                                if(!result[1]["data"].hasOwnProperty(i)){ continue; }
                                if(result[1]["data"][i]["own"]){
                                    levelLog[levelLogId][2]=((result[1].page-1)*result[1].max)+parseInt(i,10);
                                    GM_setValue2(COUNTRY+"_"+SERVER+"_"+USERNAME+"_levelLog",implode(levelLog),73);
                                    logBubble.add(getText("youAreOnRankX").replace(/%1%/,levelLog[levelLogId][2]));
                                    return;
                                }
                            }
                            logBubble.add(getText("couldNotGetPlace"));
                        }else{
                            logBubble.add(getText("couldNotGetPlace")+" ("+response.responseText+")");
                        }
                    }catch(err){ GM_logError("getDailyRanking.onload\n"+err); }
                },
                onerror: function(response){
                    GM_logError("getDailyRanking.onerror\n"+response.responseText);
                },
                timeout: function(response){
                    GM_logError("getDailyRanking.timeout\n"+response.responseText);
                }
            });
        }
    }catch(err){ GM_logError("getDailyRanking\n"+err); }
    }
    getDailyRanking();
    function plotLevelProgressBar(){
    try{
        var help;
        // data quality
        levelLog.sort(sortObjFunctions["date"]);
        if(help=$("pkt")){ 
            help=parseInt(help.innerHTML.replace(/\D/g,""),10);
            levelLog[levelLogId][1]=help;
            for(var v=levelLog.length-1;v>=0;v--){
                if(help<levelLog[v][1]){ levelLog[v][1]=0; } // points limited by current points
            }
        }
        help=0;
        for(var v=0;v<levelLog.length;v++){
            if(levelLog[v][1]<help){ levelLog[v][1]=help; } // monotony
            help=levelLog[v][1];
        }
        var month,stichtag=new Date();
        stichtag=Math.round(((new Date(stichtag.getFullYear(),stichtag.getMonth()-2,1)).getTime())/1000);
        for(var v=levelLog.length-1;v>=0;v--){
            if(levelLog[v][0].match(/^\d+\.\d+\.\d+$/)){
                if(getTime(levelLog[v][0])<stichtag){
                    // save full data for the last 3 months, else join data to monthly
                    month=/^(\d+)\.(\d+)\.(\d+)$/.exec(levelLog[v][0]);
                    if(month[2].length==1){ month[2]="0"+month[2]; }
                    month = month[3]+"-"+month[2];
                    for(var w=0;w<levelLog.length;w++){
                        if(levelLog[w][0]==month){ break; }
                    }
                    if(levelLog[w]==undefined){
                        levelLog[w]=[month,0,,0,0,0];
                    }
                    if(levelLog[w][1]<levelLog[v][1]){
                        levelLog[w][1]=levelLog[v][1];
                        levelLog[w][2]=levelLog[v][2];
                    }
                    levelLog[w][3] += levelLog[v][3];
                    levelLog[w][4] += levelLog[v][4];
                    levelLog[w][5] += levelLog[v][5];
                    levelLog.splice(v,1);
                }
            }
        }
        setLevelLogId();
        GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_levelLog",implode(levelLog));

        // plotting level log bar
        if(USERLEVEL<LEVEL_POINTS.length){
            var levelSize=959;
            var levelsum=LEVEL_POINTS[USERLEVEL+1]-LEVEL_POINTS[USERLEVEL-1];
            var newdiv=$("levelProgressBar");
            if(newdiv){ removeElement(newdiv); }
            newdiv=createElement("div",{"class":"link","id":"levelProgressBar","style":"float:left;width:"+levelSize+"px;position:relative;top:-2px;left:18px;"},content_table.firstElementChild.children[2].firstElementChild);
            newdiv.addEventListener("click",function(){unsafeWindow.buildInfoPanel("level");},false);
            newdiv.addEventListener("mouseover",function(event){
                var node=event.target;
                var mouseOverText=node.getAttribute("mouseOverText");
                while((node!=this)&&(!mouseOverText)){
                    node=node.parentNode;
                    mouseOverText=node.getAttribute("mouseOverText");
                }
                if(mouseOverText){ toolTip.show(event,mouseOverText); }
                node=null;mouseOverText=null;
            },false);

            var newdiv1=bar(levelSize*(LEVEL_POINTS[USERLEVEL]-LEVEL_POINTS[USERLEVEL-1])/levelsum,1,1);
            newdiv1.style.cssFloat="left";
            newdiv1.setAttribute("mouseOverText",getText("level")+" "+(USERLEVEL-1)+": "+numberFormat(LEVEL_POINTS[USERLEVEL-1],0)+"-"+numberFormat(LEVEL_POINTS[USERLEVEL],0));
            newdiv.appendChild(newdiv1);

            newdiv1=bar(levelSize*(LEVEL_POINTS[USERLEVEL+1]-LEVEL_POINTS[USERLEVEL])/levelsum,levelLog[levelLogId][1]-LEVEL_POINTS[USERLEVEL],LEVEL_POINTS[USERLEVEL+1]-LEVEL_POINTS[USERLEVEL]);
            newdiv1.style.cssFloat="left";
            newdiv1.style.marginLeft=Math.ceil(2+levelSize*(LEVEL_POINTS[USERLEVEL]-LEVEL_POINTS[USERLEVEL-1])/levelsum)+"px";
            newdiv1.setAttribute("mouseOverText",getText("level")+" "+(USERLEVEL)+": "+numberFormat(LEVEL_POINTS[USERLEVEL],0)+"-"+numberFormat(LEVEL_POINTS[USERLEVEL+1],0));
            newdiv.appendChild(newdiv1);

            for(var v=levelLog.length-1;v>=0;v--){
                if(levelLog[v][0].match(/^\d+\.\d+\.\d+$/)){
                    newdiv1=createElement("div",{"mouseOverText":levelLog[v][0]+"<br>"+numberFormat(levelLog[v][1]),"style":"position:absolute;width:0;margin-top:2px;height:12px;border-right:1px solid white;"},newdiv);
                    if (levelLog[v][1]<LEVEL_POINTS[USERLEVEL]){ 
                        newdiv1.style.marginLeft=Math.floor(2+levelSize*(levelLog[v][1]-LEVEL_POINTS[USERLEVEL-1])/levelsum)+"px"; 
                    } else {
                        newdiv1.style.marginLeft=Math.floor(4+levelSize*(levelLog[v][1]-LEVEL_POINTS[USERLEVEL-1])/levelsum)+"px";
                    }
                    help=levelLog[v][0].split(".");
                    if (new Date(parseInt(help[2],10),parseInt(help[1],10)-1,parseInt(help[0],10)).getDay()=="0"){ 
                        newdiv1.style.borderColor="red"; 
                    }
                }
            }
            newdiv1=null;newdiv=null;
        }
    }catch(err){ GM_logError("plotLevelProgressBar\nlevelLog["+v+"]="+implode(levelLog[v])+"\n"+err); }
    }
    plotLevelProgressBar();
    unsafeOverwriteFunction("updateMenuGo",function(){
        try{
            unsafeWindow._updateMenuGo();
        }catch(err){GM_logError("_updateMenuGo\n"+err);}
        window.setTimeout(function(){
        try{
            // calcTotalFarmis();
            // loadProductData();
            updateProductDataFarm();
            plotLevelProgressBar();
            calcProdMinRack();
            // calcProdMinRackInit();
            if(USERLEVEL<parseInt(unsafeWindow.currentuserlevel,10)){
                raiseEvent("gameUserlevelUp");
            }
            USERLEVEL=parseInt(unsafeWindow.currentuserlevel,10);
        }catch(err){ GM_logError("updateMenuGo\n"+err); }
        },0);
    });
    // Removing Advertising end on Advertising Abort
    unsafeOverwriteFunction("cancelAdResponse",function(response){
        try{
            var cell=$("alertAdvertEnd");
            if(cell){ removeElement(cell); }
            cell=null;
        }catch(err){GM_logError("cancelAdResponse\n"+err);}
        try{
            unsafeWindow._cancelAdResponse(response);
        }catch(err){GM_logError("_cancelAdResponse\n"+err);}
    });
    // Sprechblase
    err_trace="Bubble";
    createElement("div",{"id":"sprcontent2","style":"position:absolute;top:20px;left:323px;z-index:100;width:200px;height:90px;overflow:auto;display:none;"},$("sprcontent").parentNode);//same style as #sprcontent

    // Lager / Rack
    err_trace="Rack";
    newdiv=createElement("div",{"style":"display:none;"},$("lager_info"));//position:absolute;top:50px;left:58px;display:none;
    createElement("img",{"src":GFX+"adtime.gif","style":"float:left;width:14px;height:14px;margin-left:5px;"},newdiv);
    createElement("div",{"id":"lager_zeit_ziel","class":"tnormal","style":"float:left;margin-left:5px;"},newdiv);
    newdiv=createElement("div",{"id":"sendStockingContract","class":"link playerContract","style":"position:absolute;top:155px;left:10px;"},$("lager").firstElementChild);
    createElement("div",{},newdiv);
    newdiv.addEventListener("mouseover",function(event){
        try{
            if(unsafeWindow.selected&&(!prodBlock[0][unsafeWindow.selected].match(/t/))){
                toolTip.show(event,getText("storeXinContract").replace(/%1%/,prodName[0][unsafeWindow.selected]));
            }else{
                toolTip.show(event,"---");
            }
        }catch(err){ GM_logError("listener sendStockingContract.mouseover\n"+err); }
    },false);
    newdiv.addEventListener("click",function(event){
        try{
            if(unsafeWindow.selected&&(!prodBlock[0][unsafeWindow.selected].match(/t/))){
                var thisdata=new Object();
                thisdata["to"]=FARMNAME;
                thisdata["fillContract"]=new Object();
                thisdata["fillContract"][unsafeWindow.selected]=[prodStock[0][unsafeWindow.selected],1];
                GM_setValue(COUNTRY+"_"+SERVER+"_pagedataVertraegeNew",implode(thisdata));
                showMultiframePage("vertraege/new.php");
            }
        }catch(err){ GM_logError("listener sendStockingContract.click\n"+err); }
    },false);
    function showLagerZeitZiel(zoneNrF){
    try{
        // if(gameLocation[0]!="farm"){ return false; }
        var divLagerZeitZiel=$("lager_zeit_ziel");
        var growtime,help;
        switch(zones.getBuilding(zoneNrF)){
        case 1:{
            if ((unsafeWindow.mode==0)&&(prodTyp[0][unsafeWindow.selected]=="v")){
                var bonus=zones.getBonus(zoneNrF);
                if((help=zones.getBonusSpecial(zoneNrF))&&(unsafeWindow.selected==help[0])){ 
                    bonus += help[1]; 
                }
                bonus=1-(bonus/100);
                growtime=calcGrowDuration(60*prodGrowTime[0][unsafeWindow.selected],bonus);
            }
        break;}
        case "fl1":{
            if ((unsafeWindow.mode==0)&&(prodTyp[0][unsafeWindow.selected]=="fl")){
                var bonus=1-(zones.getBonus(zoneNrF)/100);
                if((help=zones.getBonusSpecial(zoneNrF))&&(unsafeWindow.selected==help[0])){
                    bonus *= 1-(help[1]/100); 
                }
                growtime=calcGrowDuration(60*prodGrowTime[0][unsafeWindow.selected],bonus);
            }
        break;}
        }
        if(growtime){
            $("lager_zeit").innerHTML=getTimeStr(growtime)+"&nbsp;"+getText("shortHours");
            if(divLagerZeitZiel.parentNode.style.display!="block"){
                divLagerZeitZiel.parentNode.style.display="block"; 
            }
            divLagerZeitZiel.innerHTML="=&nbsp;"+getDaytimeStr(now+growtime)+"&nbsp;"+getText("shortOClock");
        }else{
            hideLagerZeitZiel();
        }
        divLagerZeitZiel=null;
    }catch(err){ GM_logError("showLagerZeitZiel zoneNrF="+zoneNr+"\n"+err); }
    }
    function hideLagerZeitZiel(){
    try{
        var divLagerZeitZiel=$("lager_zeit_ziel");
        if(divLagerZeitZiel.parentNode.style.display!="none"){
            divLagerZeitZiel.parentNode.style.display="none";
        }
        divLagerZeitZiel=null;
    }catch(err){ GM_logError("hideLagerZeitZiel\n"+err); }
    }
    unsafeOverwriteFunction("selectRackItem",function(id,b){
        try{
            unsafeWindow._selectRackItem(id,b);
        }catch(err){GM_logError("selectRackItem id="+id+"\n"+err);}
        try{
            if($("gardenmaincontainer").style.display=="block"){
                var zoneNr=/parent.cache_me\((\d+?),120/.exec($("gardenarea").innerHTML);
                if(zoneNr){
                    zoneNr=parseInt(zoneNr[1],10);
                    showLagerZeitZiel(zoneNr+6*gameLocation[1]);
                }
            }else if($("farmersmarket_pos1_inner").style.display=="block"){
                showLagerZeitZiel("farmersmarket-1");
            }
        }catch(err){GM_logError("selectRackItem id="+id+"\n"+err);}
    });

    valMoveAnimals=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_valMoveAnimals","[]"),"do_main/valMoveAnimals",[]);
    // executed,speedvert,top,bottom,speedhor,left,right
    function moveAnimals(mode){
        //GM_log("moveAnimals "+mode);
        if(($("innermaincontainer").style.display == "block")&&($("animalline"+mode))){
            var cand=$("animalline"+mode).getElementsByTagName("img");
            for(var v=0;v<cand.length;v++){
                cand[v].style.top=(Math.max(ANIMAL_MOVE[mode][2],Math.min(ANIMAL_MOVE[mode][3],parseInt(cand[v].style.top,10)+ANIMAL_MOVE[mode][1]*getRandom(-1,1))))+"px";
                cand[v].style.left=(Math.max(ANIMAL_MOVE[mode][5],Math.min(ANIMAL_MOVE[mode][6],parseInt(cand[v].style.left,10)+ANIMAL_MOVE[mode][4]*getRandom(-1,1))))+"px";
            }
            cand=null;
            window.setTimeout(function(){moveAnimals(mode);},100);
        }else{
            ANIMAL_MOVE[mode][0]=false;
        }
    }

    // events general =============================================================================
    err_trace="events general";
    // rack
    for(var v in prodName[0]){
        if(!prodName[0].hasOwnProperty(v)){ continue; }
        if(v==0){ continue; } // Coins
        if (!unsafeWindow.rackElement[v]){ prodStock[0][v]=0; } // not available
        // else if ("undefined" === typeof(unsafeWindow.rackElement[v].id)){ prodStock[0][v]=0; } // empty elements
        else if ("undefined" === typeof(unsafeWindow.rackElement[v].number)){ prodStock[0][v]=0; } // no stock available
        else if (!unsafeWindow.rackElement[v].number){ prodStock[0][v]=0; } // no stock available
        else { prodStock[0][v]=parseInt(unsafeWindow.rackElement[v].number,10); }
    }
    GM_setValueCache(COUNTRY+"_"+SERVER+"_"+USERNAME+"_prodStock",implode(prodStock));
    unsafeWindow.updateRackBusy=false;
    unsafeOverwriteFunction("updateRack",function(rack,init){
        try{
            var cell=$("divUpdateRack");
            if(!cell){
                cell=createElement("div",{"id":"divUpdateRack","class":"blackbox","style":"position:absolute;top:20%;left:50%;font-weight:bold;"},$("rackItems"),"Rack updating");
                cell.style.marginLeft=(-(cell.offsetWidth)/2)+"px";
            }
            cell.style.display="block";
            cell=null;
            unsafeWindow.updateRackBusy=true;
        }catch(err){GM_logError("updateRack\n"+err);}
        try{
            unsafeWindow._updateRack(rack,init);
        }catch(err){GM_logError("_updateRack\n"+err);}
    });
    unsafeOverwriteFunction("sortRackNew",function(type){
        try{
            unsafeWindow._sortRackNew(type);
        }catch(err){GM_logError("_sortRackNew\n"+err);}
        try{
            // save rack amounts
            for(var v in prodName[0]){
                if(!prodName[0].hasOwnProperty(v)){ continue; }
                if(v==0){ continue; } // Coins
                if (!unsafeWindow.rackElement[v]){ prodStock[0][v]=0; } // not available
                // else if ("undefined" === typeof(unsafeWindow.rackElement[v].id)){ prodStock[0][v]=0; } // empty elements
                else if ("undefined" === typeof(unsafeWindow.rackElement[v].number)){ prodStock[0][v]=0; } // no stock available
                else if (!unsafeWindow.rackElement[v].number){ prodStock[0][v]=0; } // no stock available
                else { prodStock[0][v]=parseInt(unsafeWindow.rackElement[v].number,10); }
            }       
            GM_setValueCache(COUNTRY+"_"+SERVER+"_"+USERNAME+"_prodStock",implode(prodStock));
            var cell=$("divUpdateRack");
            if(cell){ cell.style.display="none"; }
            cell=null;
            window.setTimeout(function(){
                calcProdMinRack(); // -> doBuyNotepad,doRack
                unsafeWindow.updateRackBusy=false;
                raiseEvent("gameUpdateRack");
            },0);
        }catch(err){GM_logError("sortRackNew type="+type+"\n"+err);}
    });
    /*
    function doRackNavi(){
    try{
        if(unsafeWindow.racktype!=2){  // Oil: no navi
            if(unsafeWindow.userracks>1){
                if(unsafeWindow._currRack=="0"){
                    // Left arrow to last rack
                    var div = unsafe$("racknavileft");
                    div.className = "link racknavi";
                    div.onmouseover = function(e) { unsafeWindow.showDiv("racknavileftinfo"); }
                    div.onmouseout = function(e) { unsafeWindow.hideDiv("racknavileftinfo"); }
                    div.onclick = function(e) { unsafeWindow.updateRack(Math.min(unsafeWindow.userracks,(unsafeWindow.premium==1?3:2))-1); }
                    $("racknavileftinfo").innerHTML = unsafeWindow.rack_tt_info+"&nbsp;"+Math.min(unsafeWindow.userracks,(unsafeWindow.premium==1?3:2));
                    div=null;
                } else if (parseInt(unsafeWindow._currRack,10)==Math.min(unsafeWindow.userracks,(unsafeWindow.premium==1?3:2))-1){
                    // Right arrow to first rack
                    var div = unsafe$("racknaviright");
                    div.className = "link racknavi";
                    div.onmouseover = function(e) { unsafeWindow.showDiv("racknavirightinfo"); }
                    div.onmouseout = function(e) { unsafeWindow.hideDiv("racknavirightinfo"); }
                    div.onclick = function(e) { unsafeWindow.updateRack("0"); }
                    $("racknavirightinfo").innerHTML = unsafeWindow.rack_tt_info+"&nbsp;1";
                    div=null;
                }
            }
        }
    }catch(err){ GM_logError("doRackNavi\n"+err); }
    }
    doRackNavi();   
    unsafeOverwriteFunction("initRackNavi",function(){
        unsafeWindow._initRackNavi();
        doRackNavi();
    });
    */
    if(newdiv=$("rackItems")){
        newdiv.addEventListener("dblclick",function(event){
            try{
                //GM_log("dblclick on "+event.target+" id="+event.target.id+" parentNode.id="+event.target.parentNode.id);
                var currId=null;
                var node=event.target;
                while((currId==null)&&(node!=this)){
                    if(node.id.match(/rackitem\d+/)){
                        currId=/rackitem(\d+)/.exec(node.id)[1];            
                    }else{
                        node=node.parentNode;
                    }
                }
                if((currId!=null)&&(!prodBlock[0][currId].match(/t/))){ showMarket(currId); }
            }catch(err){GM_logError("listener #rackItems.dblclick\n"+err);}
        },false);
    }
    /* TODO: function is not existing anymore
    unsafeOverwriteFunction("linfo",function(title,amount,id,offset,felder,kategorie){
        unsafeWindow._linfo(title,amount,id,offset,felder,kategorie);
        var newdiv;
        var rackPopup=$("rackPopup");
        if (!isNaN(NPC[0][id])){
            newdiv=createElement("div",{"class":"tmenu","style":"position:relative;height:13px;width:172px;top:-75px;padding-left:20px;background: url('"+GFX+"lager/flaeche.gif') left top transparent;background-position:0px -155px;"},rackPopup);
            createElement("span",{"style":"float:left;width:60px;"},newdiv,getText("NPCprice")+": ");
            createElement("span",{"style":"float:left;width:100px;text-align:right;"},newdiv,moneyFormat(NPC[0][id]));
        }
        if(!prodBlock[0][id].match(/t/)){
            newdiv=createElement("div",{"class":"tmenu","style":"position:relative;height:13px;width:172px;top:-75px;padding-left:20px;background: url('"+GFX+"lager/flaeche.gif') left top transparent;background-position:0px -155px;"},rackPopup);
            createElement("div",{"style":"display:inline-block;width:60px;"},newdiv,getText("marketPrice")+": ");
            createElement("div",{"style":"display:inline-block;width:100px;text-align:right;"},newdiv,moneyFormat(gut[id]));
            newdiv=createElement("div",{"class":"tmenu","style":"position:relative;height:13px;width:172px;top:-75px;padding-left:20px;background: url('"+GFX+"lager/flaeche.gif') left top transparent;background-position:0px -155px;"},rackPopup);
            createElement("div",{"style":"display:inline-block;width:60px;"},newdiv,getText("value")+": ");
            createElement("div",{"style":"display:inline-block;width:100px;text-align:right;"},newdiv,moneyFormatInt(gut[id]*prodStock[0][id]));
            newdiv=createElement("div",{"class":"tmenu","style":"position:relative;height:25px;width:172px;top:-75px;padding-left:20px;background: url('"+GFX+"lager/flaeche.gif') left top transparent;background-position:0px -155px;"},rackPopup);
            createElement("div",{"style":"width:160px;"},newdiv,getText("clickDouble")+": "+getText("goToMarket"));
        }
        newdiv=null;rackPopup=null;
    });
    */
    unsafeOverwriteFunction("globalcommitbox",function(content,onclick,onclick2){
        try{
            unsafeWindow._globalcommitbox(content,onclick,onclick2);
        }catch(err){GM_logError("_globalcommitbox\n"+err);}
        try{
            raiseEvent("gameOpenGlobalCommitBox");
        }catch(err){GM_logError("globalcommitbox\n"+err);}
    });
    unsafeOverwriteFunction("globalBox",function(f,a,e,c,b){
        try{
            unsafeWindow._globalBox(f,a,e,c,b);
        }catch(err){GM_logError("_globalBox\n"+err);}
        try{
            raiseEvent("gameOpenGlobalBox");
        }catch(err){GM_logError("globalBox\n"+err);}
    });

    if(newdiv=$("coins")){
        newdiv1=newdiv.cloneNode(true);
        insertAfter(newdiv1,newdiv);
        newdiv1.id="coinsFormat";
        newdiv1.innerHTML=numberFormat(prodStock[0][0]);
        newdiv.style.display="none";
        newdiv.parentNode.setAttribute("class","link");
        newdiv.parentNode.addEventListener("mouseover",function(event){ showGoToMarketToolTip(event,0); },false);
        newdiv.parentNode.addEventListener("click",function(){ showMarket(0); },false);
    }

    if(COUNTRY=="SE"){ $("bar").innerHTML=$("bar").innerHTML.replace(/\.(\d\d) /,",$1 "); }
    unsafeOverwriteFunction("updatePlayerInfo",function(money,coins,points,level,deco){
        try{
            unsafeWindow._updatePlayerInfo(money,coins,points,level,deco);
        }catch(err){GM_logError("_updatePlayerInfo\n"+err);}
        try{
            // GM_log("updatePlayerInfo money="+money+" coins="+coins+" points="+points+" level="+level+" deco="+deco);
            if(money){
                if(COUNTRY=="SE"){
                    money=money.replace(/\.(\d\d) /,",$1 ");
                    $("bar").innerHTML=money;
                }
                money=parseFloat(money.replace(getText("gamecurrency"),"").replace(/\s+/g,"").replace(regDelimThou,"").replace(regDelimDeci,"."));
                unsafeData.money=money;
                GM_setValueCache(COUNTRY+"_"+SERVER+"_"+USERNAME+"_bargeld",money);
            }
            if(coins){
                var c=parseInt(coins,10);
                if(!isNaN(c)){
                    prodStock[0][0]=c;
                    $("coinsFormat").innerHTML=numberFormat(c);
                    GM_setValueCache(COUNTRY+"_"+SERVER+"_"+USERNAME+"_prodStock",implode(prodStock));
                }
            }
        }catch(err){GM_logError("updatePlayerInfo\n"+err);} 
    });
    document.addEventListener("gameDoGetData",function(){
        window.setTimeout(loadProductData,0);
    },false);
    document.addEventListener("gameChangedBeobPrice",function(){
        window.setTimeout(function(){
            // GM_log("publish GMpreisBeob");
            top.unsafeData.preisBeob=explode(GM_getValue(COUNTRY+"_"+SERVER+"_preisBeob","[]"),"eventListener@gameChangedBeobPrice/preisBeob",[]).clone();
        },0);
    },false);
    document.addEventListener("gameChangedGut",function(){
        window.setTimeout(function(){
            gut=explode(GM_getValue(COUNTRY+"_"+SERVER+"_gut","[]"),"eventListener@gameChangedGut/gut",[]);
            top.unsafeData.gut=gut.clone();
            calcFarmiCost();
        },0);
    },false);
    document.addEventListener("gameChangedLevelLog",function(){
        window.setTimeout(function(){
            levelLog=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_levelLog","[]"),"eventListener@gameChangedLevelLog/levelLog",[]);
            setLevelLogId();
        },0);
    },false);
    document.addEventListener("gameChangedProdMinRackInit",function(){
        window.setTimeout(function(){
            //if(valMinRackMan){ prodMinRackInit=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_prodMinRackInit","[]")); }
            calcProdMinRackInit();
        },0);
    },false);

    // messages
    unsafeOverwriteFunction("messagesActionResponse",function(request,mode,id){
        try{
            unsafeWindow._messagesActionResponse(request,mode,id);
        }catch(err){GM_logError("_messagesActionResponse\n"+err);}
        try{
            if(checkRequest(request,mode)){
                switch(mode){
                case "system": window.setTimeout(messagesSystem,0); break;
                }
            }
        }catch(err){GM_logError("messagesActionResponse\n"+err);}
    });
    // market: [id,time,name,[prod,amount],money]
    // contract: [id,time,name,[[prod,amount],...],money]
    function messagesSystem(){
    try{
        if(!logSales){
            logSales=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_logSales","[]"),"messagesSystem/logSales",[]);
            logSales.sort(sortObjFunctions["int"],true);
            logSalesId=new Object();
            for(var v=logSales.length-1;v>=0;v--){
                logSalesId[logSales[v][0]]=v;
            }
        }
        var j,help,help2,help3,help4,currMsg,sender,betreff,time,amount,prod,money,dayStr,price;
        var div,span;
        var countRequest=0;
        for(var i=unsafeWindow.messages_data.length-1;i>=0;i--){
            currMsg=unsafeWindow.messages_data[i];
            help=currMsg.body.replace(/\s+/g," ");
            if(help2=regMsgFriend.exec(currMsg.subject)){
                //Friendship message
                // GM_log("messagesSystem: friendship message\nmessages_data["+i+"]:\n"+print_r(unsafeWindow.messages_data[i],"",true,"\n"));
                sender=help[1];
            }else if (help2=regMsgMarketsaleContent.exec(help)){ // Market sale
                // GM_log("messages_data["+i+"] MARKET:\n"+print_r(unsafeWindow.messages_data[i],"",true,"\n"));
                switch(COUNTRY){
                case "TR":{
                    help2.push(help2.splice(2,1).toString());
                break;}
                case "SE":{
                    help2[4]=help2[4].replace(/\.(\d\d) /,",$1 ");
                    help2[4]=help2[4].replace(/\.(\d\d)$/,",$1");
                break;}
                }
                sender=help2[1];
                betreff=(getText("marketplace")+": "+help2[3]).replace(/&nbsp;/g," ");
                time=getTime(currMsg.time);
                prod=prodId[0][help2[3]];
                amount=parseInt(help2[2],10);
                money=parseFloat(help2[4].replace(regDelimThou,"").replace(regDelimDeci,"."),10);
                price=Math.round(100*money/amount)/100;
                if(logSalesId[currMsg.nnr]==undefined){
                    logSalesId[currMsg.nnr]=logSales.push([currMsg.nnr])-1;
                    dayStr=getDateStr(time,2,false);
                    for(var v=levelLog.length-1;v>=0;v--){
                        if(levelLog[v][0]==dayStr){ break; }
                    }
                    if(v<0){ v=levelLog.push([dayStr,0,null,0,0,0])-1; }
                    levelLog[v][3]+=money;
                    levelLog[v][3]=Math.round(100*levelLog[v][3])/100;

                    help3 = amount;
                    while(help3>0){
                        for(var v=ownMarketOffers.length-1;v>=0;v--){
                            if((ownMarketOffers[v][0]==prod)&&(ownMarketOffers[v][1]==price)){
                                help4 = Math.min(ownMarketOffers[v][2],help3);
                                ownMarketOffers[v][2] -= help4;
                                if(ownMarketOffers[v][2]<1){ ownMarketOffers.splice(v,1); }
                                help3 -= help4;
                                break;
                            }
                        }
                        if(v<0){ help3=0; }
                    }
                }
                j=logSalesId[currMsg.nnr];
                logSales[j][1]=time;
                logSales[j][2]=sender;
                logSales[j][3]=[prod,amount];
                logSales[j][4]=money;
                if(valMessagesSystemMarkRead&&(currMsg.read=="0")){
                    window.setTimeout(unsafeWindow.messagesAction,500*(++countRequest),"unread",i);
                }
                if(div=$("messages_list_subject"+currMsg.nnr)){
                    div.setAttribute("j",j);
                    div.addEventListener("mouseover",function(event){
                        toolTip.show(event,toolTipSales(this.getAttribute("j")));
                    },false);
                    div.classList.add("systemMsg_marketsale");
                    div.innerHTML="";
                    igm(sender,div,betreff);
                    createElement("div",{"style":"display:inline-block;width:125px;margin-right:5px;"},div,sender);
                    span=createElement("div",{"style":"display:inline-block;width:145px;margin-right:5px;text-align:right;"},div,numberFormat(amount)+"&nbsp;"+prodName[0][prod]+"&nbsp;");
                    produktPic(0,prod,span);
                    createElement("div",{"style":"display:inline-block;width:75px;margin-right:5px;text-align:right;"},div,moneyFormatInt(money));
                }
            }else if (help2=regMsgContractsaleContent.exec(help)){// Contract sale
                if(COUNTRY=="SE"){
                    help2[3]=help2[3].replace(/\.(\d\d) /,",$1 ");
                    help2[3]=help2[3].replace(/\.(\d\d)$/,",$1");
                }
                sender=help2[1];
                money=parseFloat(help2[3].replace(regDelimThou,"").replace(regDelimDeci,"."),10);
                time=getTime(currMsg.time);
                if(logSalesId[currMsg.nnr]==undefined){
                    logSalesId[currMsg.nnr]=logSales.push([currMsg.nnr])-1;
                    var dayStr=getDateStr(time,2,false);
                    for(var v=levelLog.length-1;v>=0;v--){
                        if(levelLog[v][0]==dayStr){ break; }
                    }
                    if(v<0){ v=levelLog.push([dayStr,0,null,0,0,0])-1; }
                    levelLog[v][4]+=money;
                    levelLog[v][4]=Math.round(100*levelLog[v][4])/100;
                }
                j=logSalesId[currMsg.nnr];
                logSales[j][1]=time;
                logSales[j][2]=sender;
                logSales[j][3]=new Array();
                help4=new Array();
                while(help3=regMsgContractsaleList.exec(help2[2])){
                    help2[2]=help2[2].replace(help3[0],"");
                    logSales[j][3].push([prodId[0][help3[2]],parseInt(help3[1],10)]);
                }
                betreff=getText("contract");
                if(logSales[j][3].length==1){
                    prod=logSales[j][3][0][0];
                    amount=logSales[j][3][0][1];
                    betreff+=": "+prodName[0][prod];
                }
                logSales[j][4]=money;
                if(valMessagesSystemMarkRead&&(currMsg.read=="0")){
                    window.setTimeout(unsafeWindow.messagesAction,500*(++countRequest),"unread",i);
                }
                if(div=$("messages_list_subject"+currMsg.nnr)){
                    div.setAttribute("j",j);
                    div.addEventListener("mouseover",function(event){
                        toolTip.show(event,toolTipSales(this.getAttribute("j")));
                    },false);               
                    div.classList.add("systemMsg_contractsale");
                    div.innerHTML="";
                    igm(sender,div,betreff);
                    createElement("div",{"style":"display:inline-block;width:125px;margin-right:5px;"},div,sender);
                    span=createElement("div",{"style":"display:inline-block;width:145px;margin-right:5px;text-align:right;"},div);
                    if(logSales[j][3].length==1){
                        span.innerHTML=numberFormat(amount)+"&nbsp;"+prodName[0][prod]+"&nbsp;";
                        produktPic(0,prod,span);
                    }else{
                        span.innerHTML="...";
                    }
                    createElement("div",{"style":"display:inline-block;width:75px;margin-right:5px;text-align:right;"},div,moneyFormatInt(money));
                }
            }else{
                GM_log("messagesSystem: unknown message type\nmessages_data["+i+"]:\n"+print_r(unsafeWindow.messages_data[i],"",true,"\n"));
            }
        }
        if(countRequest>0){
            if(div=$("messageAlertReadingAll")){
                removeElement(div);
            }
            if(div=$("messages_main")){
                createElement("div",{"id":"messageAlertReadingAll","class":"alertbubble","style":"left:50%;margin-left:-200px;top:100px;text-align:center;font-weight:bold;"},div,getText("pleaseWait"));
                window.setTimeout(function(){
                    removeElement($("messageAlertReadingAll"));
                },500*(++countRequest));
            }
        }
        GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_levelLog",implode(levelLog));
        GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_ownMarketOffers",implode(ownMarketOffers));
        doMarketoffersNotepad();
        GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_logSales",implode(logSales));
        }catch(err){GM_logError("messagesSystem\n"+err);}
    };
    if(newdiv=$("messages_list_check")){
        newdiv2=createElement("button",{"class":"link button_new","type":"button","style":"margin-right:5px;"},false,getText("salesLog"));
        newdiv.insertBefore(newdiv2, newdiv.firstElementChild);
        newdiv2.addEventListener("click",function(){ unsafeWindow.buildInfoPanel("messages"); },false);
    }   
    // events farm ================================================================================
    err_trace="events farm";
    unsafeOverwriteFunction("farmMove",function(b){
        try{
            unsafeWindow._farmMove(b);
        }catch(err){GM_logError("_farmMove\n"+err);}
        try{
            if(b==99){
                gameLocation=["farmersmarket"];
                unsafeData.gameLocation=gameLocation.clone();
                raiseEvent("gameFarmersmarketOpened");
            }else{
                gameLocation=["farm",unsafeWindow.farm-1];
                unsafeData.gameLocation=gameLocation.clone();
                raiseEvent("gameFarmOpened");
            }
        }catch(err){GM_logError("farmMove\n"+err);}
    });
    function doFarmZone(farmNR,zoneNr){
        try{    
            var divZone,divZoneInfo,div;
            var help,zoneNrF,data,currZoneType;
            if(divZone=$("farm"+farmNR+"_pos"+zoneNr)){
                zoneNrF=zoneNr+6*(farmNR-1);
                // zone is blocked
                divZone.style.opacity=(zones.getBlock(zoneNrF).match(/[pq]/)?0.5:1);
                if(!zones.getBlock(zoneNrF)){
                    data=unsafeWindow.farms_data.farms[farmNR][zoneNr];
                    currZoneType=parseInt(data.buildingid,10);
                    // Upgrade button
                    if(BUILDING_UPGRADES[currZoneType]&&BUILDING_UPGRADES[currZoneType][data.level]){
                        if(data.upgrade&&(!data.premiumblock)){
                            div=$("farm_upgrade_tt"+farmNR+"_"+zoneNr);
                        }else{
                            div=$("farm_buttons"+farmNR+"_"+zoneNr);
                            div=createElement("div",{"id":"farm_button_upgrade"+farmNR+"_"+zoneNr,"class":"farm_button_upgrade button_upgrade link"},div);
                            div=createElement("div",{"id":"farm_upgrade_tt"+farmNR+"_"+zoneNr,"class":"ttbox farm_button_tt"},div);
                            createElement("div",{},div,unsafeWindow.infoupdatebuilding);
                            if(isNaN(BUILDING_UPGRADES[currZoneType][data.level][1])){
                                createElement("div",{},div,BUILDING_UPGRADES[currZoneType][data.level][1].replace("c","")+"&nbsp;"+getText("coins"));
                            }else{
                                createElement("div",{},div,moneyFormatInt((1-unsafeData.carpentry_bonus/100)*BUILDING_UPGRADES[currZoneType][data.level][1]));
                            }
                            if(USERLEVEL<BUILDING_UPGRADES[currZoneType][data.level][0]){
                                createElement("div",{"class":"bonusinfo important"},div,unsafeWindow.error1005.replace("%LEVEL%",BUILDING_UPGRADES[currZoneType][data.level][0]));
                            }                           
                        }
                        if(div){
                            var help2=BUILDING_UPGRADES[currZoneType][data.level-1][2]-BUILDING_UPGRADES[currZoneType][data.level][2];
                            if(help2>0){
                                if(currZoneType==1){
                                    if(data.level>3){
                                        createElement("div",{"style":"margin-top:10px;"},div,unsafeWindow.updatetext[7].replace(/%MORE%/,numberFormat(100*help2))); // water bonus on product
                                    }else{
                                        createElement("div",{"style":"margin-top:10px;"},div,unsafeWindow.updatetext[6].replace(/%MORE%/,numberFormat(100*(1-BUILDING_UPGRADES[currZoneType][data.level][2])))); // general water bonus
                                    }
                                }else{
                                    createElement("div",{"style":"margin-top:10px;"},div,unsafeWindow.updatetext[2].replace(/%MORE%/,numberFormat(100*help2))); // reduction of time
                                }
                            }
                            help2=BUILDING_UPGRADES[currZoneType][data.level][3]-BUILDING_UPGRADES[currZoneType][data.level-1][3];
                            if(help2>0){ // more animals
                                var animalCost=0;
                                for(var nr=1;nr<=help2;nr++){
                                    animalCost += Math.round(ANIMALCOST[currZoneType][0]+(totalAnimals[currZoneType]+nr)*ANIMALCOST[currZoneType][1]);
                                }
                                createElement("div",{"style":"margin-top:10px;"},div,unsafeWindow.updatetext[1].replace(/%MORE%/,numberFormat(BUILDING_UPGRADES[currZoneType][data.level][3]))+" (+"+help2+",&nbsp;"+moneyFormatInt(animalCost)+")");
                            }
                        }
                    }
                    // Zone mouseover showing possible production
                    if(BUILDINGTYPE[currZoneType]!=0){
                        // Replace Level-Stars (else it blocks zone mouseover)
                        divZone.querySelector(".farm_pos_back").appendChild(divZone.querySelector(".farm_pos_level"));
                        divZone.querySelector(".farm_pos_click").addEventListener("mouseover",function(event){
                            var help=/^farm(\d+)_pos(\d+)_click$/.exec(this.id);
                            var farmNR=parseInt(help[1],10);
                            var zoneNr=parseInt(help[2],10);
                            var zoneNrF=zoneNr+6*(farmNR-1);
                            var currZoneType=zones.getBuilding(zoneNrF);
                            var currAnimals=zones.getAnimals(zoneNrF);
                            if(currZoneType==1){ 
                                showLagerZeitZiel(zoneNrF); 
                            }else{
                                var buildinginfo = this.querySelector(".tt");
                                if(!buildinginfo){
                                    buildinginfo=createElement("div",{"class":"tt","style":"display:none;"},this);
                                    var table,tr,td,div;
                                    table=createElement("table",{"border":"0","cellspacing":"0","cellpadding":"0"},buildinginfo);
                                    switch(BUILDINGTYPE[currZoneType]){
                                    case 2:{
                                        help="";
                                        for(var output in BUILDING_INPUT[currZoneType]){
                                            if(!BUILDING_INPUT[currZoneType].hasOwnProperty(output)){ continue; }
                                            if(prodBlock[0][output]){ continue; }
                                            tr=createElement("tr",{},table);
                                            td=createElement("td",{"style":help+"padding-right:5px;"},tr);
                                            div=createElement("div",{"style":"line-height:16px;white-space:nowrap;"},td);
                                            produktPic(0,output,div);
                                            createElement("span",{},div,numberFormat(prodYield[0][output]*currAnimals)+" "+prodName[0][output]);
                                            pointsFormat(prodYield[0][output]*currAnimals*prodPoints[0][output],"div",td);
                                            // 60*prodGrowTime[0][output]*(100-zones.getBonus(zoneNrF))/100
                                            var time=[];
                                            time[0]=calcProductionTime(2,0,output,1-zones.getBonus(zoneNrF)/100,BUILDING_INPUT[currZoneType][output][0][0][1]/currAnimals)[0];
                                            time[1]=calcProductionTime(2,0,output,1-zones.getBonus(zoneNrF)/100,BUILDING_INPUT[currZoneType][output][0][0][1]/currAnimals,1)[0];
                                            for(var alt=1;alt<BUILDING_INPUT[currZoneType][output].length;alt++){
                                                time[0]=Math.min(time[0],calcProductionTime(2,0,output,1-zones.getBonus(zoneNrF)/100,BUILDING_INPUT[currZoneType][output][alt][0][1]/currAnimals)[0]);
                                                time[1]=Math.max(time[1],calcProductionTime(2,0,output,1-zones.getBonus(zoneNrF)/100,BUILDING_INPUT[currZoneType][output][alt][0][1]/currAnimals,1)[0]);
                                            }
                                            createElement("div",{"style":"line-height:16px;white-space:nowrap;"},td,getTimeStr(time[0])+" - "+getTimeStr(time[1]));
                                            for(var alt=0;alt<BUILDING_INPUT[currZoneType][output].length;alt++){
                                                td=createElement("td",{"style":help+"border-left:1px dashed black;padding:0 5px;"},tr);
                                                for(var i=0;i<BUILDING_INPUT[currZoneType][output][alt].length;i++){
                                                    div=createElement("div",{"style":"line-height:16px;white-space:nowrap;"},td);
                                                    produktPic(0,BUILDING_INPUT[currZoneType][output][alt][i][0],div);
                                                    createElement("span",{},div,"1 - "+numberFormat(calcProductionTime(2,0,output,1-zones.getBonus(zoneNrF)/100,BUILDING_INPUT[currZoneType][output][alt][0][1]/currAnimals)[1])+" "+prodName[0][BUILDING_INPUT[currZoneType][output][alt][i][0]]);
                                                    createElement("div",{"style":"line-height:16px;white-space:nowrap;"},td,getTimeStr(BUILDING_INPUT[currZoneType][output][alt][i][1]/currAnimals));
                                                }
                                            }
                                            help="border-top:1px solid black;";
                                        }
                                    break;}
                                    case 3:{
                                        help="";
                                        for(var output in BUILDING_INPUT[currZoneType]){
                                            if(!BUILDING_INPUT[currZoneType].hasOwnProperty(output)){ continue; }
                                            if(prodBlock[0][output]){ continue; }
                                            tr=createElement("tr",{},table);
                                            td=createElement("td",{"style":help+"padding-right:10px;"},tr);
                                            div=createElement("div",{"style":"line-height:16px;white-space:nowrap;"},td);
                                            produktPic(0,output,div);
                                            createElement("span",{},div,numberFormat(prodYield[0][output])+" "+prodName[0][output]);
                                            pointsFormat(prodYield[0][output]*prodPoints[0][output],"div",td);
                                            createElement("div",{"style":"line-height:16px;white-space:nowrap;"},td,getTimeStr(60*prodGrowTime[0][output]*(100-zones.getBonus(zoneNrF))/100));
                                            for(var alt=0;alt<BUILDING_INPUT[currZoneType][output].length;alt++){
                                                td=createElement("td",{"style":help+"border-left:1px dashed black;padding:0 5px;"},tr);
                                                for(var i=0;i<BUILDING_INPUT[currZoneType][output][alt].length;i++){
                                                    div=createElement("div",{"style":"line-height:16px;white-space:nowrap;"},td);
                                                    produktPic(0,BUILDING_INPUT[currZoneType][output][alt][i][0],div);
                                                    createElement("span",{},div,numberFormat(BUILDING_INPUT[currZoneType][output][alt][i][1])+" "+prodName[0][BUILDING_INPUT[currZoneType][output][alt][i][0]]);
                                                }
                                            }
                                            help="border-top:1px solid black;"
                                        }
                                    break;}
                                    }
                                    table=null;tr=null;td=null;div=null;
                                }
                                toolTip.show(event,buildinginfo.innerHTML,this);
                                buildinginfo=null;
                            }
                            help=null;
                        },false);
                        
                    }
                    // Zone info - show current production
                    divZoneInfo=divZone.querySelector(".farm_pos_production");
                    if(!divZoneInfo){
                        divZoneInfo=createElement("div",{"class":"farm_pos_production"},divZone);
                    }
                    divZoneInfo.addEventListener("mouseover",function(event){
                        var help=/^farm(\d+)_pos(\d+)$/.exec(this.parentNode.id);
                        help=parseInt(help[2],10)+6*(parseInt(help[1],10)-1);
                        toolTip.show(event,toolTipZoneProduction(help));
                    },false);
                    // Mouseover
                    divZone.addEventListener("mouseout",function(){
                        hideBlase();
                        hideLagerZeitZiel();
                    },false);
                    divZone.addEventListener("mouseover",function(){
                        var help = /^farm(\d+)_pos(\d+)$/.exec(this.id);
                        help=parseInt(help[2],10)+6*(parseInt(help[1],10)-1)
                        showBlase(help);
                        showLagerZeitZiel(help);
                    },true);
                    // Mouseover by tooltip
                    if(div=divZone.querySelector(".farm_button_autoplant")){
                        div.addEventListener("mouseover",function(event){
                            toolTip.show(event,this.querySelector(".farm_button_tt").innerHTML,this);
                        },false);
                    }
                    if(div=divZone.querySelector(".farm_button_upgrade")){
                        div.addEventListener("mouseover",function(event){
                            toolTip.show(event,this.querySelector(".farm_button_tt").innerHTML,this);
                        },false);
                    }                       
                    if(div=divZone.querySelector(".farm_button_gardenspeedup")){
                        div.addEventListener("mouseover",function(event){
                            toolTip.show(event,this.querySelector(".farm_button_tt").innerHTML,this);
                        },false);
                    }
                    // Specific things
                    switch(currZoneType){
                    case 1:{ // field
                        // percentage of garbaged area
                        if((help=zones.getProduction(zoneNrF))&&help[2]&&(help[2][1]<BUILDING_SIZE["1"])){
                            createElement("div",{"id":"garbagePerc_"+zoneNrF,"class":"blackbox","style":"position:absolute;top:50px;left:50px;padding:4px;font-weight:bold;"},divZone.querySelector(".farm_pos_back"),numberFormat(100*help[2][1]/BUILDING_SIZE["1"])+"%");
                        }
                        // Production
                        if(div=$("farm_production_running"+farmNR+"_"+zoneNr)){
                            createElement("div",{"class":"v"+zones.getMainproduct(zoneNrF),"style":"position:absolute;"},div);
                        }
                        // Watering timer
                        createZoneTimer("zoneTimerWater_"+zoneNrF,zoneNrF,"zoneTimerWater","top:20px;left:5px;",divZone);
                    break;}
                    case 2:{ // chicken
                        // more animals
                        createElement("img",{"src":GFX+"chickenmapani2.gif","style":"position:absolute;top:30px;left:10px;"},divZone.firstElementChild.firstElementChild);
                        createElement("img",{"src":GFX+"chickenmapani2.gif","style":"position:absolute;top:30px;left:50px;"},divZone.firstElementChild.firstElementChild);
                        createElement("img",{"src":GFX+"chickenmapani1.gif","style":"position:absolute;top:50px;left:70px;"},divZone.firstElementChild.firstElementChild);
                        createElement("img",{"src":GFX+"chickenmapani1.gif","style":"position:absolute;top:60px;left:30px;"},divZone.firstElementChild.firstElementChild);
                        createElement("img",{"src":GFX+"chickenmapani1.gif","style":"position:absolute;top:80px;left:30px;"},divZone.firstElementChild.firstElementChild);
                        createElement("img",{"src":GFX+"chickenmapani2.gif","style":"position:absolute;top:100px;left:50px;"},divZone.firstElementChild.firstElementChild);
                    break;}
                    case 4:{ // sheep
                        // more animals
                        createElement("img",{"src":GFX+"sheep_ani01.gif","style":"position:absolute;top:60px;left:30px;"},divZone.firstElementChild.firstElementChild);
                        createElement("img",{"src":GFX+"sheep_ani02.gif","style":"position:absolute;top:30px;left:10px;"},divZone.firstElementChild.firstElementChild);
                    break;}
                    case 12:{ // goats
                        // more animals
                        createElement("img",{"src":GFX+"goat_ani_01.gif","style":"position:absolute;top:105px;left:50px;"},divZone.firstElementChild.firstElementChild);
                        createElement("img",{"src":GFX+"goat_ani_02.gif","style":"position:absolute;top:75px;left:30px;"},divZone.firstElementChild.firstElementChild);
                    break;}
                    case 13:{ // oil
                        if(div=$("farm_production_current13_"+zoneNr)){ divZone.appendChild(div); }
                    }
                    case 14:{ // special oil
                        if(div=$("farm_production_current14_"+zoneNr)){ divZone.appendChild(div); }
                    }
                    }                       
                }
                divZone=null;divZoneInfo=null;div=null;
            }   
        }catch(err){GM_logError("doFarmZone\nfarmNR="+farmNR+" zoneNr="+zoneNr+"\n"+err);}  
    }
    unsafeData.carpentry_bonus=parseInt($("carpentry_icon_currentbonus").innerHTML,10);
    unsafeOverwriteFunction("farmBuildPositions",function(){
        try{
            unsafeWindow._farmBuildPositions();
        }catch(err){GM_logError("_farmBuildPositions\n"+err);}
        try{
            var farmNr,zoneNr,zoneNrF,data,currZoneType,currBlock,currBonus,currBonusSpecial;
            totalAnimals=[];
            if(!unsafeData.carpentry_bonus){ unsafeData.carpentry_bonus=0; }
            for (var d in unsafeWindow.farms_data.farms) {
                if(!unsafeWindow.farms_data.farms.hasOwnProperty(d)){ continue; }
                if (d > unsafeWindow.farms_data.count) { break; }
                for (var c in unsafeWindow.farms_data.farms[d]) {
                    if(!unsafeWindow.farms_data.farms[d].hasOwnProperty(c)){ continue; }
                    data=unsafeWindow.farms_data.farms[d][c];
                    farmNr=parseInt(d,10);
                    zoneNr=parseInt(c,10);
                    zoneNrF=zoneNr+6*(farmNr-1);
                    currZoneType=parseInt(data.buildingid,10);
                    currBlock="";
                    if(BUILDINGTYPE[currZoneType]==0){
                        currBlock+="t"; //blocked by type (Club & Carpentry)
                    }
                    if(data.bulldoze&&data.bulldoze.quest){
                        currBlock+="q"; //blocked by quest
                    }
                    if(data.bulldoze&&data.bulldoze.cost){
                        currBlock+="b"; //blocked by payment
                    }
                    if(data.status=="0"){
                        currBlock+="s"; //blocked by status
                    }
                    if ((unsafeWindow.premium!=1)&&(data.premium==1)){
                        currBlock+="p"; //premium-zone but no premium-account
                    }
                    currBonus=((BUILDING_UPGRADES[currZoneType]&&BUILDING_UPGRADES[currZoneType][data.level-1])?Math.round(100*(1-BUILDING_UPGRADES[currZoneType][data.level-1][2])):0);
                    currBonusSpecial=null;
                    if (currZoneType==1){ // Field
                        if(questData["main"]["1"]["nr"]>170){ currBonus+=5; } // global bonus gained by quest 170
                        if(data.product){
                            currBonusSpecial=[parseInt(data.product,10),10]; // the id of special plant, additional bonus for special plant
                        }
                    }
                    zones.setBuilding(zoneNrF,currZoneType);
                    zones.setBlock(zoneNrF,currBlock);
                    zones.setBonus(zoneNrF,currBonus);
                    zones.setBonusSpecial(zoneNrF,currBonusSpecial);
                    if(currBlock){
                        zones.setProduction(zoneNrF,[[],0,0,true]);
                        if(zones.isMultiSlot(zoneNrF)){
                            for(var slot=1;slot<=3;slot++){ // TODO dynamic slot-amount
                                zones.setProduction(zoneNrF+"."+slot,[[],0,0,true]);
                            }
                        }
                    }
                    if(data.animals){
                        zones.setAnimals(zoneNrF,parseInt(data.animals,10));
                    }                           
                }
            }
            for (var d in unsafeWindow.farms_data.farms) {
                if(!unsafeWindow.farms_data.farms.hasOwnProperty(d)){ continue; }
                if (d > unsafeWindow.farms_data.count) { break; }
                for (var c in unsafeWindow.farms_data.farms[d]) {
                    if(!unsafeWindow.farms_data.farms[d].hasOwnProperty(c)){ continue; }
                    doFarmZone(parseInt(d,10),parseInt(c,10));
                }
            }
            calcTotalZones();
            lastGiess=null;
            lastErnte=null;
            // Event
            raiseEvent("gameFarmLoaded");
        }catch(err){GM_logError("farmBuildPositions\nzoneNrF="+zoneNrF+"\n"+err);}
    });
    // Farm filling
    // initZones > getUserFarmInfos > userFarmInfosResponse > getTimeEvents >
    // unsafeOverwriteFunction("initZones",function(farmid){
    //  unsafeWindow._initZones(farmid);
    // });

    function drawZoneNavi(zoneNrF,container){
    try{
        // logBubble.add("drawZoneNavi zoneNrF="+zoneNrF);
        var newdiv=$("zoneNavi");
        if(newdiv){ removeElement(newdiv); }
        newdiv=createElement("div",{"id":"zoneNavi"},container);
        var newdiv1;
        var c=[null,null,null];
        for(var i=0;i<ALL_ZONES["farm"].length;i++){
            if(ALL_ZONES["farm"][i]==zoneNrF){
                c[1]=i;break;
            }
        }
        if(c[1]!=null){
            c[2]=((c[1]+1)%ALL_ZONES["farm"].length);
            while(zones.getBlock(ALL_ZONES["farm"][c[2]])||(zones.getBuilding(ALL_ZONES["farm"][c[2]])!=zones.getBuilding(zoneNrF))){
                c[2]=((c[2]+1)%ALL_ZONES["farm"].length);
            }
            if (c[1]!=c[2]){
                c[0]=((c[1]+ALL_ZONES["farm"].length-1)%ALL_ZONES["farm"].length);
                while(zones.getBlock(ALL_ZONES["farm"][c[0]])||(zones.getBuilding(ALL_ZONES["farm"][c[0]])!=zones.getBuilding(zoneNrF))){
                    c[0]=((c[0]+ALL_ZONES["farm"].length-1)%ALL_ZONES["farm"].length);
                }
                if (c[0]!=c[2]){
                newdiv1=createElement("div",{"class":"link leftarrow","zone":ALL_ZONES["farm"][c[0]]},newdiv);
                newdiv1.addEventListener("click",function(){
                    if(this.parentNode){ removeElement(this.parentNode); }
                    goToZone(this.getAttribute("zone"));
                },false);
                newdiv1.addEventListener("mouseover",function(event){ 
                    var zone=parseInt(this.getAttribute("zone"),10);
                    toolTip.show(event,getText("goToZoneX").replace(/%1%/,Math.ceil(zone/6)+"."+(1+((zone-1)%6))));
                    zone=null;
                },false);
                }
                newdiv1=createElement("div",{"class":"link rightarrow","zone":ALL_ZONES["farm"][c[2]]},newdiv);
                newdiv1.addEventListener("click",function(){
                    if(this.parentNode){ removeElement(this.parentNode); }
                    goToZone(this.getAttribute("zone"));
                },false);
                newdiv1.addEventListener("mouseover",function(event){ 
                    var zone=parseInt(this.getAttribute("zone"),10);
                    toolTip.show(event,getText("goToZoneX").replace(/%1%/,Math.ceil(zone/6)+"."+(1+((zone-1)%6))));
                    zone=null;
                },false);
            }
        }
        newdiv=null;newdiv1=null;
    }catch(err){GM_logError("drawZoneNavi zoneNrF="+zoneNrF+"\n"+err);}
    }

    // field
    function checkFieldTimes(){
    try{
    if(DEVMODE_FUNCTION){ var trackingHandle = tracking.start("berater","checkFieldTimes"); }
        var zoneNr=parseInt(/parent.cache_me\((\d+?),120/.exec($("gardenarea").innerHTML)[1],10);
        var zoneNrF=zoneNr+6*gameLocation[1];
        var newData=[[{}],[,0,0,,0],[,0,0,,0],true];

        // save garden-informations
        var helpArray=new Array();//planted fields
        var helpArray2=new Array();//empty fields
        var z,p,w,iAmount,iPoints,help;
        for(var v=1;v<=BUILDING_SIZE["1"];v++){
            z=parseInt(unsafeWindow.garten_zeit[v],10);
            p=unsafeWindow.garten_prod[v];
            switch(unsafeWindow.garten_kategorie[v]){
            case "v":{ // plants
                helpArray[v]=true;
                helpArray2[v]=false;
                if (z>0){
                    iAmount=(prodYield[0][p]+((currentPowerup[p]&&(z<currentPowerup[p][0]))?currentPowerup[p][1]:0)); 
                    iPoints=(prodPoints[0][p]+((currentPowerup[p]&&(z<currentPowerup[p][0]))?currentPowerup[p][2]:0));
                
                    if ((unsafeWindow.garten_x[v]==1)&&(unsafeWindow.garten_y[v]==1)){ // only first part of a plant
                        w=parseInt(unsafeWindow.garten_wasser[v],10)+86400;
                        w=((w==86400)?1:(w<z?w:NEVER)); // watertime
                        if(!newData[0][0][p]){ newData[0][0][p]=new Array(); }
                        var notfound=true;
                        for(var i=0;i<newData[0][0][p].length;i++){
                            if((newData[0][0][p][i][2]==z)&&(newData[0][0][p][i][3]==w)){
                                newData[0][0][p][i][0]+=iAmount;
                                newData[0][0][p][i][1]+=iPoints;
                                notfound=false;break;
                            }
                        }
                        if(notfound){ newData[0][0][p].push([iAmount,iPoints,z,w]); }
                    }
                    // only show one sprinkler
                    if ((unsafeWindow.garten_x[v]==2)||(unsafeWindow.garten_y[v]!=unsafeWindow.garten_max_y[v])){
                        if ($("w"+v).style.display!="none") $("w"+v).style.display="none";
                    }else{
                        if ($("w"+v).style.display!="") $("w"+v).style.display="";
                    }
                }else{
                    helpArray[v]=true;
                    helpArray2[v]=true;
                }
            break;}
            case "z":{ // decorations
                helpArray[v]=false;
                helpArray2[v]=false;
                if ((unsafeWindow.garten_x[v]==1)&&(unsafeWindow.garten_y[v]==1)){ // only first part
                    if(!newData[0][0][p]){ newData[0][0][p]=new Array(); }
                    var notfound=true;
                    for(var i=0;i<newData[0][0][p].length;i++){
                        if((newData[0][0][p][i][2]==z)){
                            newData[0][0][p][i][0]++;
                            notfound=false;break;
                        }
                    }
                    if(notfound){ newData[0][0][p].push([1,0,z]); }
                }
            break;}
            case "u":{ // garbage
                helpArray[v]=false;
                helpArray2[v]=false;
                if(!newData[0][0][p]){ newData[0][0][p]=1; }
                else{ newData[0][0][p]++; }
            break;}
            default:{ // empty fields , p==0
                helpArray[v]=true;
                helpArray2[v]=true;
            break;}
            }
        }
        // calculate current space
        for(var v=1;v<helpArray2.length;v++){
            if(helpArray2[v]){ newData[1][1]++; }
        }
        help=helpArray2.clone();
        for(var v=1;v<help.length;v++){
            if((v%12!=0)&&help[v]&&help[v+1]){
                help[v+1]=false;
                newData[1][2]++;
            }
        }
        help=helpArray2.clone();
        for(var v=1;v<help.length;v++){
            if((v%12!=0)&&help[v]&&help[v+1]&&help[v+12]&&help[v+13]){
                help[v+1]=false;
                help[v+12]=false;
                help[v+13]=false;
                newData[1][4]++;
            }
        }
        // calculate possible space
        for(var v=1;v<helpArray.length;v++){
            if(helpArray[v]){ newData[2][1]++; }
        }
        help=helpArray.clone();
        for(var v=1;v<help.length;v++){
            if((v%12!=0)&&help[v]&&help[v+1]){
                help[v+1]=false;
                newData[2][2]++;
            }
        }
        help=helpArray.clone();
        for(var v=1;v<help.length;v++){
            if((v%12!=0)&&help[v]&&help[v+1]&&help[v+12]&&help[v+13]){
                help[v+1]=false;
                help[v+12]=false;
                help[v+13]=false;
                newData[2][4]++;
            }
        }
        // calculate garden-informations
        zones.setProduction(zoneNrF,newData.clone());
        newData=null;
        // auto-watering
        if((top.unsafeData.autoAction==null)&&valAutoWater["farm"] && (zones.getWatertime(zoneNrF)<unsafeWindow.Zeit.Server) && (lastGiess!=zoneNrF) && $("tooltipwaterall") && $("waterall")){
            top.unsafeData.autoAction="berater: field water";
            lastGiess=zoneNrF;
            window.setTimeout(function(div){
                click(div);
                top.unsafeData.autoAction=null;
            },500,$("waterall").firstElementChild);
        }
        //auto-cropping
        if((top.unsafeData.autoAction==null)&&valAutoCrop["farm"] && (zones.getEndtime(zoneNrF)<unsafeWindow.Zeit.Server) && (lastErnte!=zoneNrF) && $("tooltipcropall") && $("cropall")){
            top.unsafeData.autoAction="berater: field crop";
            lastErnte=zoneNrF;
            window.setTimeout(function(div){
                click(div);
                top.unsafeData.autoAction=null;
            },500,$("cropall").firstElementChild);
        }
        // update zone-icons
        // TODO!
        // show croppings of this field
        var cell=$("currentFieldZoneErnte");
        var newdiv;
        if(cell){ cell.innerHTML=""; }
        else{ cell=createElement("div",{"id":"currentFieldZoneErnte","style":"position:absolute;top:40px;left:0;","class":"blackbox"},$("gardenmaincontainer")); }
        help=zones.getCrop(zoneNrF);
        for(var k=0;k<help.length;k++){
            newdiv=createElement("div",{"style":"height:15px"},cell);
            produktPic(help[k][0],help[k][1],newdiv);
            createElement("span",{},newdiv,numberFormat(help[k][2])+"&nbsp;"+prodName[help[k][0]][help[k][1]]);
        }
        cell=null;newdiv=null;
    if(DEVMODE_FUNCTION){ tracking.end("berater",trackingHandle); }
    }catch(err){ GM_logError("checkFieldTimes\n"+err); }
    }

    unsafeOverwriteFunction("getGardenInfoResponse",function(request,zoneNr){
        try{
            unsafeWindow._getGardenInfoResponse(request,zoneNr);
        }catch(err){GM_logError("_getGardenInfoResponse\n"+err);}
        try{
            // GM_log("getGardenInfoResponse zoneNr="+zoneNr+"\n"+print_r(eval('('+response+')'),"",true,"\n"));
            //waterlog GM_log("getGardenInfoResponse zoneNr="+zoneNr+"\nwater: "+print_r(eval('('+response+')')["water"],"",true,"\n"));
            zoneNr=parseInt(zoneNr,10);
            var zoneNrF=zoneNr+6*gameLocation[1];
            if (!$("divErnteInfo")){ createElement("div",{"id":"divErnteInfo"},$("gardenmaincontainer")); }
            $("gardenmaincontainer").setAttribute("zoneNr",zoneNr);
            drawZoneNavi(zoneNrF,$("gardenmaincontainer"));
            showLagerZeitZiel(zoneNrF);
        
            //Klon des Anpflanzautomaten
            /*
            var newdiv;
            if($("gardencancel").childElementCount==1 && $("autoplantbutton"+zoneNr)){
                newdiv=$("autoplantbutton"+zoneNr).parentNode.cloneNode(true);
                newdiv.addEventListener("click",function(){$("gardenmaincontainer").setAttribute("style","display:none");},false);
                $("gardencancel").appendChild(newdiv);
            }
            newdiv=null;
            */
            checkFieldTimes();
        }catch(err){GM_logError("getGardenInfoResponse\n"+err);}    
    });
    unsafeOverwriteFunction("farmAction",function(mode,farm,position,s,d,b,a){
        try{
            switch(mode){
            case "dailydonkey":{
                // Only consider opening donkeyInfoPanel, if donkey is bought
                if (unsafeWindow.donkey_isset) {
                    var showDonkeyPanel=false;
                    for(var i=logDonkey.length-1;i>=0;i--){
                        if(logDonkey[i][0]==todayServerStr){ 
                            showDonkeyPanel=true;
                            break;
                        }
                    }
                
                    if(showDonkeyPanel){
                        unsafeWindow.buildInfoPanel("donkey");
                        return false;
                    }
                }
            break;}
            }
        }catch(err){GM_logError("farmAction (pre)\n"+err);}
        try{
            unsafeWindow._farmAction(mode,farm,position,s,d,b,a);
        }catch(err){GM_logError("_farmAction\n"+err);}
    });
    unsafeOverwriteFunction("farmActionResponse",function(request,mode,farmNR,zoneNr,z,d,b,a){
        try{
            unsafeWindow._farmActionResponse(request,mode,farmNR,zoneNr,z,d,b,a);
        }catch(err){GM_logError("_farmActionResponse\n"+err);}
        try{
            var r = checkRequest(request, mode);
            if((r!=0)&&(r[0]!=0)){
                var zoneNrF = zoneNr+6*(farmNR-1);
                if(zones.getBuilding(zoneNrF)==1){
                    switch(mode){
                    case "gardeninit": raiseEvent("gameFieldOpened"); break;
                    case "autoplant": raiseEvent("gameFieldPlanted"); break;
                    case "watergarden": raiseEvent("gameFieldWatered"); break;
                    case "cropgarden": raiseEvent("gameFieldCropped"); break;
                    }
                }
                switch(mode){
                case "dogbonus": doDogBen(); break;
                case "flowerarea_harvest_all": raiseEvent("gameFarmersmarketCropped"); break;
                case "flowerarea_autoplant": raiseEvent("gameFarmersmarketStarted"); break;
                case "flowerarea_water_all": raiseEvent("gameFarmersmarketWatered"); break;
                case "megafield_tour": raiseEvent("gameMegafieldTourStarted"); break;
                case "nursery_harvest": raiseEvent("gameFarmersmarketCropped"); break;
                case "nursery_startproduction": raiseEvent("gameFarmersmarketStarted"); break;
                case "sellfarmi":{
                    calcFarmiCost();
                    calcTotalFarmis();
                    doFarmis();
                    raiseEvent("gameFarmiResponse");
                break;}
                }
            } else {
                switch(mode) {
                    case "dailydonkey":
                        raiseEvent("gameDonkeyResponse");
                        if (unsafeWindow.donkey_isset && r!=0 && r[0]==0) {
                            for(var i=logDonkey.length-1;i>=0;i--){
                                if(logDonkey[i][0]==todayServerStr){
                                    return; // Don't save dummy, if entry for today found
                                }
                            }
                            // Save dummy for today's donkey log
                            var newElem=[todayServerStr,0,[]];
                            logDonkey.push(newElem);
                            GM_setValueCache(COUNTRY+"_"+SERVER+"_"+USERNAME+"_logDonkey",implode(logDonkey));
                            hideGoToDonkey();
                        }
                        break;
                }
            }
        }catch(err){GM_logError("farmActionResponse\n"+err);}
    });
    unsafeOverwriteFunction("PflanzResponse",function(request){
        try{
            unsafeWindow._PflanzResponse(request);
        }catch(err){GM_logError("_PflanzResponse\n"+err);}
        try{
            if((request.readyState==4)&&(request.status==200)){
                checkFieldTimes();
                raiseEvent("gameFieldPlanted");
            }
        }catch(err){GM_logError("PflanzResponse\n"+err);}
    });
    unsafeOverwriteFunction("WasserResponse",function(request){
        try{
            unsafeWindow._WasserResponse(request);
        }catch(err){GM_logError("_WasserResponse\n"+err);}
        try{
            if((request.readyState==4)&&(request.status==200)){
                checkFieldTimes();
                raiseEvent("gameFieldWatered");
            }
        }catch(err){GM_logError("WasserResponse\n"+err);}
    });
    unsafeOverwriteFunction("ErnteResponse",function(request){
        try{
            unsafeWindow._ErnteResponse(request);
        }catch(err){GM_logError("_ErnteResponse\n"+err);}
        try{
            if((request.readyState==4)&&(request.status==200)){
                checkFieldTimes();
                raiseEvent("gameFieldCropped");
            }
        }catch(err){GM_logError("ErnteResponse\n"+err);}
    });
    unsafeOverwriteFunction("AbrissResponse",function(request){
        try{
            unsafeWindow._AbrissResponse(request);
        }catch(err){GM_logError("_AbrissResponse\n"+err);}
        try{
            if((request.readyState==4)&&(request.status==200)){
                checkFieldTimes();
                raiseEvent("gameFieldDemolished");
            }
        }catch(err){GM_logError("AbrissResponse\n"+err);}
    });
    unsafeOverwriteFunction("killGardenTimeruns",function(){
        try{
            unsafeWindow._killGardenTimeruns();
        }catch(err){GM_logError("_killGardenTimeruns\n"+err);}
        try{        
            lastGiess=null;
            lastErnte=null;
            if ($("divErnteInfo")){ removeElement($("divErnteInfo")); }
            if ($("zoneNavi")){ removeElement($("zoneNavi")); }
            //if ($("lager_zeit_ziel").parentNode.style.display == "") $("lager_zeit_ziel").parentNode.style.display="none";
        }catch(err){GM_logError("killGardenTimeruns\n"+err);}
    });
    unsafeOverwriteFunction("errorboxgarden",function(text,onclick){
        try{
            unsafeWindow._errorboxgarden(text,onclick);
        }catch(err){GM_logError("_errorboxgarden\n"+err);}
        try{
            // Fix(Seberoth)
            // $("divErnteInfo").innerHTML=$("errorboxcontentgarden").innerHTML;
            $("divErnteInfo").innerHTML=document.getElementsByClassName('cropall_dialog_product')[0].innerHTML;
            $("divErnteInfo").style.display="block";
            if (valErnteMsg){
                // Fix(Seberoth)
                // $("errorboxgarden").style.display="none"; 
                $("globalbox").style.display="none";
                $("globaltransp").style.display="none";
            }
            // Fix(Seberoth)
            // var zoneNr=/refreshGarden\((\d)\)/.exec($("errorboxfootergarden").parentNode.innerHTML);
            var zoneNr=/refreshGarden\((\d)\)/.exec($("globalbox_button1").parentNode.innerHTML);
            if(zoneNr){
                zoneNr=zoneNr[1];
                unsafeWindow.refreshGarden(zoneNr);
            }
        }catch(err){GM_logError("errorboxgarden\n"+err);}
    });

    // Farmhouse
    unsafeOverwriteFunction("initFarmhouseResponse",function(response){
        try{
            unsafeWindow._initFarmhouseResponse(response);
        }catch(err){GM_logError("_initFarmhouseResponse\n"+err);}
        try{
            if(unsafeWindow.reallocatebuildinghead&&!$("reallocatebuildingbutton")){
                var newdiv=createElement("div",{"onclick":"initReallocateBuilding();showDiv('transp');","style":"position:absolute;top:70px;right:20px;","class":"link"},$("farmhousecontainer"));
                createElement("img",{"id":"reallocatebuildingbutton","onmouseout":"this.src=_GFX+'reallocatebuildingbutton_off.png';hideDiv('reallocatebuildinginfo');","onmouseover":"this.src=_GFX+'reallocatebuildingbutton_on.png';showDiv('reallocatebuildinginfo');","src":GFX+"reallocatebuildingbutton_off.png","class":"link","style":"width:25px;height:25px;"},newdiv);
                createElement("div",{"id":"reallocatebuildinginfo","style":"display:none;position:absolute;top:70px;right:50px;","class":"blackbox"},$("farmhousecontainer"),unsafeWindow.reallocatebuildinghead);
                newdiv=null;
            }
        }catch(err){GM_logError("initFarmhouseResponse\n"+err);}
    });
    // Dog Ben
    function doDogBen(){
        try{
            unsafeWindow.farmdog_harvest=1;
            var zoneNrF,zoneNrS,iProd,item,tempZoneProductionData;
            var allZones=[];
            var nowServer=unsafeWindow.Zeit.Server;
            for(var i=ALL_ZONES["farm"].length-1;i>=0;i--){
                zoneNrF=ALL_ZONES["farm"][i];
                if(!zones.getBlock(zoneNrF)){
                    allZones.push(zoneNrF);
                    if(zones.isMultiSlot(zoneNrF)){
                        for(var j=1;j<3;j++){
                            zoneNrS=zoneNrF+"."+j;
                            if(!zones.getBlock(zoneNrS)){
                                allZones.push(zoneNrS);
                            }
                        }
                    }
                }
            }
            for(var j=allZones.length-1;j>=0;j--){
                zoneNrS=allZones[j];
                tempZoneProductionData=zones.getProduction(zoneNrS);
                if(tempZoneProductionData&&tempZoneProductionData[0]){
                    for(var iType=0;iType<tempZoneProductionData[0].length;iType++){
                        for(var iProdStr in tempZoneProductionData[0][iType]){
                            if(!tempZoneProductionData[0][iType].hasOwnProperty(iProdStr)){ continue; }
                            iProd = parseInt(iProdStr,10);
                            if((prodTyp[iType][iProd]!="u")&&(prodTyp[iType][iProd]!="z")){ // only products
                                item=tempZoneProductionData[0][iType][iProdStr];
                                for(var i=0;i<item.length;i++){
                                    item[i][2]=Math.max(item[i][2]-600,nowServer);
                                    if(item[i][2]<item[i][3]){ item[i][3]=NEVER; }
                                }
                            }
                        }
                    }
                }
                zones.setProduction(zoneNrS,tempZoneProductionData.clone());
            }
        }catch(err){GM_logError("doDogBen\n"+err);}
    }

    // Stable
    function doStable(farmNr,zoneNr){
    try{
        var zoneNrF=zoneNr+6*(farmNr-1);
        drawZoneNavi(zoneNrF,$("building_inner"));
        if (valAutoCrop["farm"]&&(div=$("commitboxcrop"))&&(div.style.display=="block")&&(div=$("commitboxfootercrop"))){
            window.setTimeout(function(div){ click(div); },500,div.firstElementChild);
        }
        for(var v=0;v<ANIMAL_MOVE.length;v++){ if((valMoveAnimals[v])&&(!ANIMAL_MOVE[v][0])&&($("animalline"+v))){
            ANIMAL_MOVE[v][0]=true;
            moveAnimals(v);
            break;
        }}
        var data=unsafeWindow.buildingdata[farmNr][zoneNr];
        var tempZoneProductionData=[[{}],0,0,true];
        tempZoneProductionData[2]=1;
        if(data.remain==undefined){ // empty
            tempZoneProductionData[1]=1;
        }else if(data.remain>0){ // running 
                var iPrTyp=0;
                var iProd=data.pid;
                var iTime=data.remain+now-unsafeWindow.Zeit.Verschiebung;
                var iAmount=data.crop;
                var iPoints=data.crop*prodPoints[iPrTyp][iProd];
                if(!tempZoneProductionData[0][iPrTyp][iProd]){ tempZoneProductionData[0][iPrTyp][iProd]=[]; }
                tempZoneProductionData[0][iPrTyp][iProd].push([iAmount,iPoints,iTime,NEVER]);
        }else{ // done
                var iPrTyp=0;
                var iProd=data.pid;
                var iTime=zones.getEndtime(zoneNrF);
                var iAmount=data.crop;
                var iPoints=data.crop*prodPoints[iPrTyp][iProd];
                if(!tempZoneProductionData[0][iPrTyp][iProd]){ tempZoneProductionData[0][iPrTyp][iProd]=[]; }
                tempZoneProductionData[0][iPrTyp][iProd].push([iAmount,iPoints,iTime,NEVER]);               
        }
        zones.setProduction(zoneNrF,tempZoneProductionData.clone());
        tempZoneProductionData=null;
    }catch(err){GM_logError("doStable\n"+err);}
    }
    unsafeOverwriteFunction("rewriteBuildingInnerFeed",function(e,a){
        try{
            unsafeWindow._rewriteBuildingInnerFeed(e,a);
        }catch(err){GM_logError("_rewriteBuildingInnerFeed\n"+err);}
        try{
            var d = unsafeWindow.buildingdata[e][a];
            var div;
            for (var b in d.feed) {
                if(!d.feed.hasOwnProperty(b)){ continue; }
                if(div=$("feed_item"+b)){
                    var currProd=parseInt(b,10);
                    var str="blackbox"+(prodStock[0][currProd]<prodMinRack[0][currProd]?" lowrack":"");
                    createElement("div",{"id":"feed_item"+b+"_rackamount","class":str,"style":"position:absolute;top:-25px;left:-2px;font-weight:bold;"},div,numberFormatPrefixed(prodStock[0][currProd]));
                }
            }       
        }catch(err){GM_logError("rewriteBuildingInnerFeed\n"+err);}
    }); 
    unsafeOverwriteFunction("buildingInnerActionResponse",function(request,action,farm,position){
        try{
            unsafeWindow._buildingInnerActionResponse(request,action,farm,position);
        }catch(err){GM_logError("_buildingInnerActionResponse\n"+err);}
        try{
            if(checkRequest(request)){
                // logBubble.add("buildingInnerActionResponse "+action+":"+farm+":"+position);
                switch(action){
                case "init": raiseEvent("gameOpenStable"); break;
                default:
                }
            }
        }catch(err){GM_logError("buildingInnerActionResponse\n"+err);}
    });
    unsafeOverwriteFunction("newBuildingInner",function(farm,position){
        try{
            unsafeWindow._newBuildingInner(farm,position);
        }catch(err){GM_logError("_newBuildingInner\n"+err);}
        try{
            doStable(farm,position);
        }catch(err){GM_logError("newBuildingInner\n"+err);}
    }); 
    // Factory
    function doFactory(zoneNr){
        try{
        var zoneNrF=zoneNr+6*gameLocation[1];
        showBlase(zoneNrF);
        drawZoneNavi(zoneNrF,$("innermaincontainer"));
        var cand,newdiv;
        var data=unsafeWindow.farms_data.farms[unsafeWindow.farm][zoneNr];
        var tempZoneProductionData=[[{}],0,0,true];
        if (data.production&&data.production["0"]&&data.production["0"].pid){
            var iPrTyp=0;
            var iProd=parseInt(data.production["0"].pid,10);
            var iAmount=prodYield[iPrTyp][iProd];
            var iPoints=iAmount*prodPoints[iPrTyp][iProd];              
            if(data.production["0"].remain>0){ // running
                var iTime=data.production["0"].remain+now-unsafeWindow.Zeit.Verschiebung;
            }else{ // done
                var iTime=zones.getEndtime(zoneNrF);
            }
            if(!tempZoneProductionData[0][iPrTyp][iProd]){ tempZoneProductionData[0][iPrTyp][iProd]=[]; }
            tempZoneProductionData[0][iPrTyp][iProd].push([iAmount,iPoints,iTime,NEVER]);
        }else{ // empty
            tempZoneProductionData[1]=1;
        }
        tempZoneProductionData[2]=1;
        zones.setProduction(zoneNrF,tempZoneProductionData.clone());
        tempZoneProductionData=null;
        
        if(!$("articleline"+unsafeWindow.locationinfo[6])){
            cand=createElement("div",{"id":"articleline"+unsafeWindow.locationinfo[6]},$("innercontent"));
            for(var prodNr=0;prodNr<unsafeWindow.locationinfo["in"].length;prodNr++){
                newdiv=createElement("div",{"id":(gameLocation[1]+1)+"_"+zoneNr+"_article"+unsafeWindow.locationinfo["in"][prodNr],"class":"feedproduct","style":"position:absolute;top:54px;left:"+(55+60*prodNr)+"px;border:2px solid black;z-index:11;","prodNr":prodNr},cand);
                createElement("div",{"id":"articleimg"+unsafeWindow.locationinfo["in"][prodNr],"style":"position:absolute;","class":"l"+unsafeWindow.locationinfo["in"][prodNr]},createElement("div",{"style":"position:absolute;top:5px;left:5px;width:40px;height:40px;overflow:hidden;"},newdiv));
                newdiv.addEventListener("mouseover",function(event){ 
                    var prodNr = parseInt(this.getAttribute("prodNr"),10);
                    toolTip.show(event,unsafeWindow.locationinfo["need"][prodNr]+"x "+prodName[0][unsafeWindow.locationinfo["in"][prodNr]]);
                },false);
            }
        }

        var cand=$("innercontent").getElementsByClassName("feedproduct");
        for(var v=0;v<cand.length;v++){
            var currProd=parseInt(cand[v].getElementsByTagName("div")[1].getAttribute("class").replace("l",""),10);
            var str="blackbox"+(prodStock[0][currProd]<prodMinRack[0][currProd]?" lowrack":"");
            if(!$(cand[v].id+"_rackamount")){ createElement("div",{"id":cand[v].id+"_rackamount","style":"position:absolute;top:-25px;left:-2px;font-weight:bold;"},cand[v]); }
            newdiv=$(cand[v].id+"_rackamount");
            if(newdiv.getAttribute("class")!=str){ newdiv.setAttribute("class",str); }
            newdiv.innerHTML=numberFormatPrefixed(prodStock[0][currProd]);
        }
        if (valAutoCrop["farm"]&&(div=$("commitboxcrop"))&&(div.style.display=="block")&&(div=$("commitboxfootercrop"))){
            window.setTimeout(function(div){ click(div); },500,div.firstElementChild);
        }
        cand=null;newdiv=null;
        raiseEvent("gameOpenFactory");
        }catch(err){GM_logError("doFactory\n"+err);}    
    }
    // Oil factory, special oil factory
    function doFactoryOil(zoneNr){
        //GM_log("doFactoryOil "+unsafeWindow.currentposition);
        var zoneNrF=zoneNr+6*gameLocation[1];
        showBlase(zoneNrF);
        drawZoneNavi(zoneNrF,$("innermaincontainer"));
        raiseEvent("gameOpenFactoryOil");
    }
    unsafeOverwriteFunction("buildOilpressInner",function(position,buildingid,info){
        try{
            unsafeWindow._buildOilpressInner(position,buildingid,info);
        }catch(err){GM_logError("_buildOilpressInner\n"+err);}
        try{
            var zoneNr=position;
            var zoneNrF=zoneNr+6*gameLocation[1];
            var zoneNrS;
            var data=unsafeWindow.oilproduction;
            var newDiv,newDiv1;
            var tempZoneProductionData=[[{}],0,0,true];
            var tempZoneProductionDataSlot;
            for(var slot=1;slot<=3;slot++){
                zoneNrS=zoneNrF+"."+slot;
                if((slot==1)||(!unsafeWindow.oilslots[slot]["block"])){
                    zones.setBlock(zoneNrS,"");
                    tempZoneProductionDataSlot=[[{}],0,0,true];
                    tempZoneProductionData[1]++;
                    tempZoneProductionData[2]++;
                    tempZoneProductionDataSlot[1]++;
                    tempZoneProductionDataSlot[2]++;
                    if(data[slot]){
                        var iPrTyp=0;
                        var iProd=parseInt(data[slot].pid,10);
                        var iAmount=data[slot].amount;
                        var iPoints=data[slot].amount*prodPoints[iPrTyp][iProd];
                        var iTime=now+data[slot].remain;
                        var endDay=countDays(now,iTime);
                        newDiv=createElement("div",{"class":"blackbox","id":"oil_slot"+slot+"_prodinfo","style":"position:absolute;left:225px;top:25px;white-space:nowrap;"},$("oil_slot"+slot));
                        if(iTime<now){
                            if(iTime+20*60*60<now){
                                createElement("div",{},newDiv,getText("readySinceX").replace(/%1%/,getFormattedDateStr(iTime)));
                            }else{
                                createElement("div",{},newDiv,getText("readySinceX").replace(/%1%/,getDaytimeStr(iTime)+"&nbsp;"+getText("shortOClock")));
                            }               
                        } else if (endDay==0){
                            createElement("div",{},newDiv,getText("readyAtX").replace(/%1%/,getDaytimeStr(iTime)+"&nbsp;"+getText("shortOClock")));
                        } else if ((endDay==1)&&(getText("readyAtX_day1"))){
                            createElement("div",{},newDiv,getText("readyAtX_day1").replace(/%1%/,getDaytimeStr(iTime)+"&nbsp;"+getText("shortOClock")));
                        } else if ((endDay==2)&&(getText("readyAtX_day2"))){
                            createElement("div",{},newDiv,getText("readyAtX_day2").replace(/%1%/,getDaytimeStr(iTime)+"&nbsp;"+getText("shortOClock")));
                        } else{ 
                            createElement("div",{},newDiv,getText("readyAtX").replace(/%1%/,new Date(1000*iTime).toLocaleString())); 
                        }
                        newDiv1=$("oil_slot"+slot+"_img_tt_time");
                        if(newDiv1){ newDiv.appendChild(newDiv1); }
                        newDiv1=createElement("div",{},newDiv); 
                        produktPic(iPrTyp,iProd,newDiv1);
                        createElement("span",{},newDiv1,numberFormat(iAmount)+" "+prodName[iPrTyp][iProd]); 
                        pointsFormat(iPoints,"div",newDiv1);
            
                        iTime-=unsafeWindow.Zeit.Verschiebung;
                        tempZoneProductionData[1]--;
                        if(!tempZoneProductionData[0][iPrTyp][iProd]){ tempZoneProductionData[0][iPrTyp][iProd]=[]; }
                        tempZoneProductionData[0][iPrTyp][iProd].push([iAmount,iPoints,iTime,NEVER]);
                        tempZoneProductionDataSlot[1]--;
                        if(!tempZoneProductionDataSlot[0][iPrTyp][iProd]){ tempZoneProductionDataSlot[0][iPrTyp][iProd]=[]; }
                        tempZoneProductionDataSlot[0][iPrTyp][iProd].push([iAmount,iPoints,iTime,NEVER]);
                        //auto-cropping
                        if((top.unsafeData.autoAction==null)&&valAutoCrop["farm"] && (newDiv=$("oil_slot"+slot+"_cropbutton")) && (newDiv.style.display=="block")){
                            top.unsafeData.autoAction="berater: oil crop";
                            window.setTimeout(function(div){
                                click(div);
                                top.unsafeData.autoAction=null;
                            },500,newDiv);
                        }
                    }
                    zones.setProduction(zoneNrF+"."+slot,tempZoneProductionDataSlot.clone());
                } else {
                    zones.setBlock(zoneNrS,"b");
                }
            }
            zones.setProduction(zoneNrF,tempZoneProductionData.clone());
            var tempZoneProductionData=null;newDiv=null;newDiv1=null;
        }catch(err){GM_logError("buildOilpressInner\n"+err);}
    });
    // Knitting
    unsafeOverwriteFunction("strickereiAjaxActionResponse",function(request,pos,mode){
        try{
            unsafeWindow._strickereiAjaxActionResponse(request,pos,mode);
        }catch(err){GM_logError("_strickereiAjaxActionResponse\n"+err);}
        try{
            var result = checkRequest(request);
            if((result!=0)&&(result[0]!=0)){
                switch(mode){
                case "buy": break;
                case "cancel": break;
                case "crop": raiseEvent("gameFactoryKnittingCropped"); break;
                case "speedup": break;
                case "start": raiseEvent("gameFactoryKnittingStarted"); break;
                default:
                }
            }
        }catch(err){GM_logError("strickereiAjaxActionResponse\n"+err);}
    });
    unsafeOverwriteFunction("strickereiSelection",function(a,c,slot){
        try{
            unsafeWindow._strickereiSelection(a,c,slot);
        }catch(err){GM_logError("_strickereiSelection\n"+err);}
        try{
            raiseEvent("gameFactoryKnittingDialogStart");
        }catch(err){GM_logError("strickereiSelection\n"+err);}
    });
    unsafeOverwriteFunction("buildStrickereiInner",function(position,buildingid){
        try{
            unsafeWindow._buildStrickereiInner(position,buildingid);
        }catch(err){GM_logError("_buildStrickereiInner\n"+err);}        
        try{
            var zoneNr=position;
            var zoneNrF=zoneNr+6*gameLocation[1];
            var zoneNrS;
            showBlase(zoneNrF);
            drawZoneNavi(zoneNrF,$("innermaincontainer"));
            var newDiv,newDiv1;
            var tempZoneProductionData=[[{}],0,0,true];
            var tempZoneProductionDataSlot;
            var data=unsafeWindow.strickerei_data;
            for(var slot=1;slot<=3;slot++){
                zoneNrS=zoneNrF+"."+slot;
                if((slot==1)||(!data.slots[slot]["block"])){
                    zones.setBlock(zoneNrS,"");
                    tempZoneProductionDataSlot=[[{}],0,0,true];
                    tempZoneProductionData[1]++;
                    tempZoneProductionData[2]++;
                    tempZoneProductionDataSlot[1]++;
                    tempZoneProductionDataSlot[2]++;
                    if(data.slots[slot]){
                        var iPrTyp=0;
                        var iProd=data.slots[slot].pid;
                        if(iProd){
                            var iAmount=data.slots[slot].amount;
                            var iPoints=iAmount*prodPoints[iPrTyp][iProd];
                            if(data.slots[slot].ready){
                                var iTime=zones.getEndtime(zoneNrF);
                            } else{
                                var iTime=now+data.slots[slot].remain-unsafeWindow.Zeit.Verschiebung;
                            }
                            newDiv=$("strickerei_slot"+slot).children[1];
                            newDiv1=createElement("div",{},newDiv);
                            pointsFormat(iPoints,"div",newDiv1);
                            tempZoneProductionData[1]--;
                            if(!tempZoneProductionData[0][iPrTyp][iProd]){ tempZoneProductionData[0][iPrTyp][iProd]=[]; }
                            tempZoneProductionData[0][iPrTyp][iProd].push([iAmount,iPoints,iTime,NEVER]);
                            tempZoneProductionDataSlot[1]--;
                            if(!tempZoneProductionDataSlot[0][iPrTyp][iProd]){ tempZoneProductionDataSlot[0][iPrTyp][iProd]=[]; }
                            tempZoneProductionDataSlot[0][iPrTyp][iProd].push([iAmount,iPoints,iTime,NEVER]);
                            //auto-cropping
                            if(data.slots[slot].ready&&(top.unsafeData.autoAction==null)&&valAutoCrop["farm"]&&(newDiv=$("strickerei_slot"+slot))){
                                top.unsafeData.autoAction="berater: knitting crop";
                                window.setTimeout(function(div){
                                    click(div);
                                    top.unsafeData.autoAction=null;
                                },500,newDiv);
                            }
                        }
                    }
                    zones.setProduction(zoneNrF+"."+slot,tempZoneProductionDataSlot.clone());
                } else {
                    zones.setBlock(zoneNrS,"b");
                }
            }
            zones.setProduction(zoneNrF,tempZoneProductionData.clone());
            var tempZoneProductionData=null;newDiv=null;newDiv1=null;
            raiseEvent("gameOpenFactoryKnitting");
        }catch(err){GM_logError("buildStrickereiInner\n"+err);}
    });
    unsafeOverwriteFunction("innerInfosResponse",function(zoneNr){
    // oil, knitting, factory, pony
        try{
            unsafeWindow._innerInfosResponse(zoneNr);
        }catch(err){GM_logError("_innerInfosResponse\n"+err);}
        try{
            $("innermaincontainer").setAttribute("zoneNr",zoneNr);
            if(unsafeWindow.locationinfo["buildingid"]){ 
                switch(unsafeWindow.locationinfo["buildingid"]){
                case "13": doFactoryOil(zoneNr); break; // Oil
                case "14": doFactoryOil(zoneNr); break; // Special Oil
                case "16":  // Knitting
                case "17":  // Carpentry
                case "18":  // Pony
                case "19":  // Megafield
                default: 
                }
            }else{ 
            // }else if(unsafeWindow.locationinfo["in"]){ 
                doFactory(zoneNr); 
            }
        }catch(err){GM_logError("innerInfosResponse\n"+err);}
    });
    // Megafield
    err_trace="Megafield";
    // Remembering of latest vehicle. ["harvest", "fertilize"]
    megafieldVehicle = explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_megafieldVehicle"),"do_main/megafieldVehicle",[]);
    unsafeData.megafieldVehicle=megafieldVehicle.clone();
    function doMegafieldData(){
/*  megafield:
    "points": STRING(INTEGER), 
    "count": STRING(INTEGER),
    "count_buy": null,
    "area": {   "1": {  "pid": INTEGER,
                        "time": DATETIME of planting,
                        "duration": INTEGER,
                        "remain": INTEGER
                }, ...
    },
    "area_free": {  "1": DATETIME of unlocking
                    , ...
    },
    "job": {    "products": [   {   "pid": INTEGER,
                                    "quality": INTEGER,
                                    "need": INTEGER,
                                    "have": INTEGER,
                                    "amount": INTEGER,
                                    "harvest": INTEGER,
                                    "duration": INTEGER
                                }, ...
                ],
                "remain": INTEGER
    },
    "job_start": STRING(DATETIME),
    "job_endtime": "0",
    "vehicles": {   "1": {  "time": DATETIME of purchase,
                            "durability": INTEGER,
                            "range": INTEGER
                    }, ...
    },
    "vehicles_unlock": {    "1": {  "time": DATETIME of unlocking  }
                            , ...
    },
    "tour": [],
    "tutorial_step": STRING(INTEGER),
    "level": INTEGER,
    "level_rest": INTEGER,
    "level_percent": INTEGER,
    "exchangecoins": INTEGER,
    "next_tiles": { "cost": INTEGER,
                    "tiles": [INTEGER, INTEGER, ...]
    },
    "vehicle_slots": {  "1": {  "type": "harvest"|"fertilize",
                                "name": STRING,
                                "size": INTEGER,
                                "level": INTEGER,
                                "unlock": INTEGER,
                                "durability": INTEGER,
                                "range": INTEGER,
                                "duration": INTEGER,
                                "money": INTEGER
                        }, ...
    },
    "reward_info": {    "quality": INTEGER,
                        "points": INTEGER,
                        "money": INTEGER,
                        "license": INTEGER,
                        "difficultybonus_points": INTEGER,
                        "difficultybonus_money": INTEGER,
                        "difficultybonus_license": INTEGER,
                        "timebonus_points": INTEGER,
                        "timebonus_money": INTEGER,
                        "timebonus_license": INTEGER
    }
}*/        
        try{
            if(unsafeWindow.megafield_data&&unsafeWindow.megafield_data.area_free){
/*                 var str="";
                for(var i in unsafeWindow.megafield_data.vehicles){
                    str+=i+":"+getDateStr(unsafeWindow.megafield_data.vehicles[i].time)+" "+getDaytimeStr(unsafeWindow.megafield_data.vehicles[i].time)+"\n";
                }
                GM_log(str); */
                
                var zoneNrF=null;
                for(var i=0;i<ALL_ZONES["farm"].length;i++){
                    if(zones.getBuilding(ALL_ZONES["farm"][i])==19){
                        zoneNrF=ALL_ZONES["farm"][i];
                        break;
                    }
                }
                if(zoneNrF==null){
                    throw("Location of Megafield not found.");
                }
                var tempZoneProductionData=[[{}],0,0,true];
                var iPrTyp=0,iProd,iTime;
                for(var i=BUILDING_SIZE["19"][0]*BUILDING_SIZE["19"][1];i>=1;i--){
                    if(unsafeWindow.megafield_data.area_free[i]){
                        tempZoneProductionData[1]++;
                        tempZoneProductionData[2]++;
                        if(unsafeWindow.megafield_data.area[i]){
                            iProd=unsafeWindow.megafield_data.area[i].pid;
                            iTime=unsafeWindow.megafield_data.area[i].time+unsafeWindow.megafield_data.area[i].duration;
                            iTime-=unsafeWindow.Zeit.Verschiebung;
                            tempZoneProductionData[1]--;
                            if(!tempZoneProductionData[0][iPrTyp][iProd]){ tempZoneProductionData[0][iPrTyp][iProd]=[]; }
                            tempZoneProductionData[0][iPrTyp][iProd].push([1,0,iTime,NEVER]);
                        }
                    }
                }
                zones.setProduction(zoneNrF,tempZoneProductionData.clone());
            }
        }catch(err){GM_logError("_megafieldHandler\n"+err);}
    }
    doMegafieldData();
    unsafeOverwriteFunction("megafieldHandler",function(a){
        try{
            unsafeWindow._megafieldHandler(a);
        }catch(err){GM_logError("_megafieldHandler\n"+err);}
        try{
            doMegafieldData();
        }catch(err){GM_logError("megafieldHandler\n"+err);}
    });
    unsafeOverwriteFunction("buildMegafield",function(){
        try{
            unsafeWindow._buildMegafield();
        }catch(err){GM_logError("_buildMegafield\n"+err);}
        try{
            if(megafieldVehicle[0]&&(!unsafeWindow.megafield_vehicle_id)){
                unsafeWindow.megafield_move_position=2;
                unsafeWindow._setTourVehicleMegafield(megafieldVehicle[0]);
            }
            raiseEvent("gameOpenMegafield");
        }catch(err){GM_logError("buildMegafield\n"+err);}
    });
    unsafeOverwriteFunction("setTourVehicleMegafield",function(b){
        try{
            unsafeWindow._setTourVehicleMegafield(b);
        }catch(err){GM_logError("_setTourVehicleMegafield\n"+err);}
        try{
            var a;
            if(b&&(a=unsafeWindow.megafield_data.vehicle_slots[b])&&(!a.block)&&(!a.unlockable)){
                megafieldVehicle[{"harvest":0,"fertilize":1}[a.type]]=b;
                unsafeData.megafieldVehicle=megafieldVehicle.clone();                
                GM_setValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_megafieldVehicle",implode(megafieldVehicle,"setTourVehicleMegafield\megafieldVehicle"));
            }
        }catch(err){GM_logError("setTourVehicleMegafield\n"+err);}
    });
    
    // Club
    err_trace="Club";
    // Clubquest direct show
    var lastGuildQuestRequest=0;
    function clubQuestToolTip(data){
    try{
        var container=$("guildlink_tt_quest");
        container.innerHTML="";
        var newdiv=createElement("div",{"style":"position:absolute;top:5px;left:5px;"},container);
        var newspan=createElement("span",{"style":"margin-right:2px;"},newdiv);
        if(data!=0){
            createElement("img",{"src":GFX+'adtime.gif'},newspan);
            createElement("span",{"style":"font-weight:bold;"},newdiv,getTimeStr(data['remain']));
            if(data['questtype'] == 1 || data['questtype'] == 2){  // produkte oder geld in vorgegebener zeit
                var top=25;
                var left=0;
                var newdiv1;
                for(var i=1 ; i <= 2 ; i++){
                    if(data['product' + i] > 0){
                        data['sum' + i]=parseInt(data['sum' + i],10);
                        data['amount' + i]=parseInt(data['amount' + i],10);
                        var barleft=parseInt(Math.round((data['sum' + i] * 100) / data['amount' + i])-100,10);

                        if(data['questtype'] == 2){
                            data['sum' + i]=moneyFormat(data['sum' + i]);
                            data['amount' + i]=moneyFormat(data['amount' + i]);
                        }

                        newdiv=createElement("div",{"style":'position:absolute; top:' + top + 'px; left:' + left + 'px;width:40px;height:15px;'},container);
                        if(data['questtype'] == 1){
                            newdiv1=createElement("div",{"style":"position:absolute; top:0; left:5px;height:15px;width:15px; overflow:hidden;"},newdiv);
                            createElement("img",{"class":"kp" + data['product' + i], "style":"position:absolute;"},newdiv1);
                        }
                        else if(data['questtype'] == 2){
                            newdiv1=createElement("div",{"style":"position:absolute; top:0; left:5px;height:15px;width:15px;"},newdiv);
                            createElement("img",{"src":GFX+"money.gif","height":"15","width":"15"},newdiv1);
                        }
                        newdiv1=createElement("div",{"style":"position:absolute;top:0;left:23px;border:1px solid #000;background-color:#fff;width:100px;height:15px;overflow:hidden;"},newdiv);
                        createElement("div",{"style":"position:absolute;top:0;left:"+barleft+"px;background-color:#f00;width:100px;height:25px;"},newdiv1);
                        createElement("div",{"style":"position:absolute;top:0;left:0;width:100px;height:15px;color:black;font-weight:bold;text-align:center;"},newdiv1,numberFormat(data['sum' + i]));
                        createElement("div",{"style":"position:absolute;top:20px;white-space:nowrap;left:5px;"},newdiv,(data['amount' + i]==data['sum' + i])?"":('<b>' + numberFormat(data['amount' + i]-data['sum' + i]) + '/' + numberFormat(data['amount' + i]) + '</b>'));
                top += 40;
                }   }
                newdiv1=null;
            }
        }else{
            newspan.innerHTML="---";
        }
        container=null;newdiv=null;newspan=null;
    }catch(err){GM_logError("clubQuestToolTip\ndata="+implode(data)+"\n"+err);}
    }
    if((newdiv=$("speedlink_guild"))&&(newdiv1=$("speedlink_guild_tt"))){
        var str=newdiv1.innerHTML;
        newdiv1.innerHTML="";
        createElement("div",{"style":"border-bottom:1px solid black;"},newdiv1,str);
        createElement("div",{"id":"guildlink_tt_quest","style":"position:relative;width:130px;height:100px;"},newdiv1,"---");
        /* TODO: review needed. request has changed.
        newdiv.addEventListener("mouseover",function(){
            if (now-lastGuildQuestRequest>30){ // 30 seconds delay to next request
                lastGuildQuestRequest=now;
                GM_xmlhttpRequest({
                    method: "GET",
                    url: "http://s"+SERVER+"."+GAMEPAGES[COUNTRY]+"/guild/ajax/initguild.php?rid="+unsafeWindow.rid,
                    headers: {"Content-type": "application/x-www-form-urlencoded"},
                    onload: function(response){
                        if(response.responseText!=0){
                            var result=eval('(' + response.responseText + ')');
                            if(result[0]!=0){
                                clubQuestToolTip(result[0][2]);
                            }
                        }
                    }
                });
            }
        },false);
        */
    }

    // Clubquest updated
    /* TODO: function is not existing anymore
    unsafeOverwriteFunction("setGuildQuestResponse",function(request){
        unsafeWindow._setGuildQuestResponse(request);
        var result=checkRequest(request);
        if(result){
            lastGuildQuestRequest=now;
            clubQuestToolTip(result[1]);
        }
    });
    */
    
    // Clubdata loaded
    unsafeOverwriteFunction("initGuildResponse",function(response){
        try{
            unsafeWindow._initGuildResponse(response);
        }catch(err){GM_logError("_initGuildResponse\n"+err);}
        try{
            lastGuildQuestRequest=now;
            clubQuestToolTip(response[0][2]);
        }catch(err){GM_logError("initGuildResponse\n"+err);}
    });

    // Memberlist
    unsafeOverwriteFunction("openMultiBox",function(id){
        try{
            if(id==5){
                $('guildmultiboxheader').innerHTML='<img class="link" src="' + unsafeWindow.imgpath + 'button_cancel_off.png" onclick="hideDiv(\'transp9\'); hideDiv(\'guildmultibox\');" onmouseover="this.src=\'' + unsafeWindow.imgpath + 'button_cancel_on.png\';" onmouseout="this.src=\'' + unsafeWindow.imgpath + 'button_cancel_off.png\';"></div>';
                $('guildmultiboxcontent').innerHTML='';
                unsafeWindow.showGuildQuestStats(2,1,0);
                for(var i=1;i<=3;i++){
                    $('guildmultiboxmenue'+i).style.backgroundImage="url(" + unsafeWindow.imgpath + "leer.gif)";
                }
                $('guildmultiboxmenue4').style.backgroundImage="url(" + unsafeWindow.imgpath + "multiscreen_reiter4.jpg)";
                $('guildmultiboxheadline').innerHTML=unsafeWindow.guildmultibox_headline4;
                unsafeWindow.hideDiv('guildnewsticker');
                unsafeWindow.showDiv('transp9');
                unsafeWindow.showDiv('guildmultibox');
            }else{
                try{
                    unsafeWindow._openMultiBox(id);
                }catch(err){GM_logError("_openMultiBox\n"+err);}
            }
        }catch(err){GM_logError("openMultiBox\n"+err);}
    });
    $("guildmultiboxmenue4").setAttribute("onclick","openMultiBox(5)");

    unsafeOverwriteFunction("getGuildMembersResponse",function(request){
        try{
            unsafeWindow._getGuildMembersResponse(request);
        }catch(err){GM_logError("_getGuildMembersResponse\n"+err);}
        try{
            if(request.readyState == 4 && request.status == 200){
                var canddiv=Array.prototype.slice.call($("guildmultiboxcontent").getElementsByClassName("guildmemberlist_even")).concat(Array.prototype.slice.call($("guildmultiboxcontent").getElementsByClassName("guildmemberlist_uneven")));
                var newdiv,newspan,newa;
                for(var v=0;v<canddiv.length;v++){
                    newdiv=canddiv[v].children[1].firstElementChild;
                    var thisUser=/(.*?)&nbsp;/.exec(newdiv.innerHTML);
                    newdiv.innerHTML=newdiv.innerHTML.replace(thisUser[0],"");
                    newspan=createElement("span");
                    newspan.innerHTML="&nbsp;";
                    newdiv.insertBefore(newspan,newdiv.firstElementChild);
                    newa=createElement("a",{"class":"link2"});
                    newa.innerHTML=thisUser[1];
                    newdiv.insertBefore(newa,newdiv.firstElementChild);
                    newa.addEventListener("click",function(){
                        showShopframePage("http://s"+SERVER+"."+GAMEPAGES[COUNTRY]+"/stadt/stats.php?search=1&searchterm="+this.innerHTML);
                    },false);
                    //newdiv.insertBefore(igm(thisUser[1]),newdiv.firstElementChild);
                }
                newdiv=null;newspan=null;newa=null;canddiv=null;
            }
        }catch(err){GM_logError("getGuildMembersResponse\n"+err);}
    });
    // Questhistory
    unsafeOverwriteFunction("showGuildQuestStatsResponse",function(request,type,page,self){
        try{
            unsafeWindow._showGuildQuestStatsResponse(request,type,page,self);
        }catch(err){GM_logError("_showGuildQuestStatsResponse\n"+err);}
        try{
            var result=checkRequest(request);
            if(result&&result[0]!=0){
                window.setTimeout(function(){
                    if(DEVMODE){ GM_log("showGuildQuestStatsResponse "+request+":"+type+"("+typeof type+"):"+page+"("+typeof page+"):"+self+"("+typeof self+")"); };
    
                    var newdiv=$("chg_guildqueststats");
                    newdiv.setAttribute("onchange","");
                    newdiv.addEventListener("change",function(){
                        var type=parseInt($("chg_guildqueststats").value,10);
                        if(type<4){
                            unsafeWindow.showGuildQuestStats(type,1,0);
                        }else{
                            showGuildQuestStatsLastDays(7);
                        }
                    },false);
                    createElement("option",{"value":"4"},newdiv,getText("stat_days7"));
                    if(type>3){
                        newdiv.value=type;
                        newdiv.nextElementSibling.style.display="none";
                    }
    
                    //todayStr=getDateStr(now,2,false);
                    var clubmemberLog=explode(GM_getValue(COUNTRY+"_"+SERVER+"_"+USERNAME+"_clubmemberLog","[]"),"showGuildQuestStatsResponse/clubmemberLog",[]);
                    for(var u=0;u<clubmemberLog.length;u++){
                        if(typeof clubmemberLog[u][0]!="string"){
                            clubmemberLog.splice(u,1);
                            u--;continue;
                        }
                        if(!clubmemberLog[u][1] instanceof Array){
                            clubmemberLog[u][1]=[];
                        }
                        for(var v=0;v<clubmemberLog[u][1].length;v++){
                            if((typeof clubmemberLog[u][0][v][0]!="string")||(typeof clubmemberLog[u][0][v][1]!="number")){
                                clubmemberLog[u][1].splice(v,1);
                                v--;continue;
                            }
                            if(!clubmemberLog[u][1][v][2] instanceof Array){
                                clubmemberLog[u][1][v][2]=[];
                            }
                            if(clubmemberLog[u][1][v][0]=="0"){ continue; }
                            // join old data
                            var w=null;
                            if(clubmemberLog[u][1][v][0].match(/^\d+\.\d+\.\d+$/)){
                                if(now-getTime(clubmemberLog[u][1][v][0])>604800){ // 1 week (7*86400)
                                    for(var x=0;x<clubmemberLog[u][1].length;x++){
                                        if(clubmemberLog[u][1][x][0]==clubmemberLog[u][1][v][0].replace(/^(\d+\.)/,"")){
                                            w=x; break;
                                        }
                                    }
                                    if(w==null){
                                        w=clubmemberLog[u].length;
                                        clubmemberLog[u].push([0,[]]);
                                    }                           }
                            }else if(clubmemberLog[u][1][v][0].match(/^\d+\.\d+$/)){
                                if(now-getTime(clubmemberLog[u][1][v][0])>16070400){ // 6 months (6*31*86400)
                                    for(var x=0;x<clubmemberLog[u].length;x++){
                                        if(clubmemberLog[u][1][x][0]==clubmemberLog[u][1][v][0].replace(/^(\d+\.)/,"")){
                                            w=x; break;
                                        }
                                    }
                                    if(w==null){
                                        w=clubmemberLog[u].length;
                                        clubmemberLog[u].push([0,[]]);
                                    }
                                }
                            }
                            if(w!=null){
                                clubmemberLog[u][1][w][1] += clubmemberLog[u][1][v][1];
                                for(var x=0;x<clubmemberLog[u][1][v][2].length;x++){
                                    for(var y=0;y<clubmemberLog[u][1][w][2].length;y++){
                                        if(clubmemberLog[u][1][v][2][x]==clubmemberLog[u][1][w][2][y]){
                                            break;
                                        }
                                    }
                                    if(clubmemberLog[u][1][w][2][y]){
                                        clubmemberLog[u][1][w][2][y][1] += clubmemberLog[u][1][v][2][x][1];
                                    } else {
                                        clubmemberLog[u][1][w][2].push(clubmemberLog[u][1][v][2][x]);
                                    }
                                }
                                clubmemberLog[u][1].splice(v,1);
                                clubmemberLog[u][1].sort(sortObjFunctions["date"]);
                            }
                        }
                    }
    
                    var clubmembers=new Object();
                    var clubmemberLogSum=new Object();
                    for(var i=0;i<clubmemberLog.length;i++){
                        var u=clubmemberLog[i][0];
                        clubmemberLogSum[u]=[0,{}];
                        for(var j=0;j<clubmemberLog[i][1].length;j++){
                            var v=clubmemberLog[i][1][j][0];
                            if(v==todayStr){ continue; }
                            clubmemberLogSum[u][0] += clubmemberLog[i][1][j][1];
                            for(var k=0;k<clubmemberLog[i][1][j][2].length;k++){
                                var w=clubmemberLog[i][1][j][2][k][0];
                                if(clubmemberLogSum[u][1][w]==undefined){
                                    clubmemberLogSum[u][1][w]=0;
                                    clubmemberLogSum[u][1].sortObj(sortObjFunctions["productId"]);
                                }
                                clubmemberLogSum[u][1][w] += clubmemberLog[i][1][j][2][k][1];
                            }
                        }
                    }
                    var container=$("guildmultiboxcontent");
                    var newtable,newtable1,newtr,newtr1,newtd,newdiv1,cell;
                    for(var v=0;v<container.childElementCount;v++){
                        if(container.children[v].id.match(/^line\d+$/)){
                            var lineNr=parseInt(/^line(\d+)$/.exec(container.children[v].id)[1],10);
    
                            var thisUser=container.children[v].children[1].innerHTML;
                            var thisPoints=parseInt(container.children[v].children[3].innerHTML,10);
                            container.children[v].children[3].innerHTML=numberFormat(thisPoints);
    
                            clubmembers[thisUser]=[thisPoints,{}];
    
                            // reformat of info bubble