var battlesString = "";
var battlesTable = null;

var lineIndex = 1;

var layoutType = null;

var closeTimeouts = new Array();

var battleSaveParameters = new Array();
var lastFocus = null;
var battleSavedType = null;

var commonTimeout = 300;

var todoAfterLayout = "";

var blockTimers = false;
var listBattlesDone = false;

var counterTimeouts = new Array();

var kick1 = null;
var kick2 = null;
var defence = null;

var elevatorParameters = "";

var lastMagicUsageTime = 0;
var magicUsedThisStep = false;

var mineKicksCount = 0;
var mineKicksTotal = 100;

function aAL(a) {
    addAfterLayout(a);
}

var regexpBody = new RegExp('([^a-zA-Z]body|^body)\\s*=\\s*\\[\\s*(((\\[\\[)|(\\]\\])|([^\\]\\[]))*)\\s*\\]');

function getParam(list) {
	var res = regexpBody.exec(list);
	var returnvar;
	if(res)
		return res[2].replace('[[','[').replace(']]',']');
	else
		return '';
}

function processTags(tags) {
    for (var i = 0; i < tags.length; i++) {
        var tip = tags[i].getAttribute("title");
        if (tip && tip != "") {
            tip = getParam(tip).
                    replace(/\&lt;small\&gt;/g, "").replace(/&lt;\/small\&gt;/g, "").replace(/\&lt;b\&gt;/g, "").replace(/\&lt;\/b\&gt;/g, "").
                    replace(/\&lt;br\/\&gt;/g, "\n").
                    replace(/\&lt;font color=red\&gt;/g, "\n").replace(/\&lt;\/font\&gt;/g, "\n").
                    replace(/\<small\>/g, "").replace(/\<\/small\>/g, "").replace(/\<b\>/g, "").replace(/\<\/b\>/g, "").
                    replace(/\<br\/\>/g, "\n").
                    replace(/\<font color=red\>/g, "\n").replace(/\<\/font\>/g, "\n");
            tags[i].setAttribute("alt", tip);
            tags[i].setAttribute("title", tip);
        }
    }
}

function createTooltips() {
    if (navigator.appVersion.indexOf("MSIE") != -1 && navigator.appVersion.indexOf("Opera") == -1) {
        var tags = top.main.window.document.body.getElementsByTagName("IMG");
        processTags(tags);
        tags = top.main.window.document.body.getElementsByTagName("SPAN");
        processTags(tags);
    } else if (top.main.window.init) {
        if (typeof top.main.window.document.attachEvent != 'undefined') {
           top.main.window.init();
           top.main.window.document.attachEvent('onmousemove', top.main.window.moveMouse);
           top.main.window.document.attachEvent('onclick', top.main.window.checkMove); }
        else {
           top.main.window.init();
           top.main.window.document.addEventListener('mousemove', top.main.window.moveMouse, false);
           top.main.window.document.addEventListener('click', top.main.window.checkMove, false);
        }
    }
}

function addAfterLayout(functionText) {
    todoAfterLayout += functionText;
}

function updateAfterLayout() {
    var lastPos = 0;

//    alert(todoAfterLayout);

    try {
        eval(todoAfterLayout);
    } catch(ex) {
    }

    todoAfterLayout = "";

    createTooltips();

    top.main.window.ignoreSelects = true;
    var form = top.main.window.document.getElementById("actionForm");
    if (kick1 != null && form) {
        setRadioValue(form.kick, kick1);
    }
    if (kick2 != null && form) {
        setRadioValue(form.kick2, kick2);
    }
    if (defence != null && form) {
        setRadioValue(form.defence, defence);
    }
    top.main.window.ignoreSelects = false;
}

function setRadioValue(radios, value) {
    for (var i = 0; i < radios.length; i++) {
        if (radios[i].value == value) {
            radios[i].checked = true;
            break;
        }
    }
}

function include_dom(script_filename, charset) {
    var js = top.main.window.document.createElement("script");
    js.setAttribute("type", "text/javascript");
    js.setAttribute("charset", charset);
    js.setAttribute("src", script_filename);
    top.main.window.document.getElementsByTagName("head").item(0).appendChild(js);
}

function clearTooltips() {
}

var loadAnyway = false;

function setLoadAnyway() {
    loadAnyway = true;
}

function setLayout(layout) {
    top.main.window.battlesType = null;
    top.main.window.layoutDone = false;
    top.main.window.layoutType = layout;

    blockTimers = false;
    listBattlesDone = false;

    if (layout == 'action' || layout == 'search' || layout == 'current' || layout.substr(0, 4) == 'mine') {
        for (var counterTimeout in counterTimeouts) {
            try {
                clearTimeout(counterTimeouts[counterTimeout]);
            } catch(ex) {
                document.getElementById("messages").innerHTML += ex + "<br/>";
            }
        }

        counterTimeouts = new Array();
    }

    if (!top.main.window.document.getElementById('layoutDiv') && !loadAnyway) {
        todoAfterLayout = "";
        return;
    }

    loadAnyway = false;

    if (!top.main.window.document.getElementById('layoutDiv')) {
        top.main.window.document.open('text/html; charset=utf-8', 'blank.html');
        try {
            top.main.window.document.write(
                    '<html>\n' +
                    '<head>\n' +
                    '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>' +
                    '<link href="' + __picsPath + 'battle/battle.css" type="text/css" rel="stylesheet"/>' +
                    '<script type="text/javascript">' +
                    'var __session = "' + __session + '";' +
                    'var __hostPath = "' + __hostPath + '";' +
                    'var __picsPath = "' + __picsPath + '";' +
                    'var __city = "' + __city + '";' +
                    'var p = top.frames["voc_shower"].window;' +
                    '</script></head><body style="margin: 0px; padding: 0px; background-color: #DEDEDE;" scroll="auto" onload="top.frames[\'voc_shower\'].window.updateAfterLayout();"><div id="layoutDiv">');
        } catch(ex) {
        }

        top.main.window.document.write(getLayoutText(layout));

        top.main.window.layoutDone = true;
        top.main.window.layoutType = layout;

        top.main.window.document.write('</div><textarea id="holdtext" cols="10" rows="1" style="display: none;"></textarea><div id="oMenu" style="position: absolute;" class="menu" onMouseOut="closeMenu(event);"></div><div id="hint1" class="ahint"></div>');
        top.main.window.document.write('<div style="border: 1px solid white; color: black; visibility: hidden; position: absolute; top: 0px; left: 80%; width: 100px; height: 16px; padding-top: 1px; font-size: 11px; font-weight: bold; vertical-align: middle; text-align: center; background-image: url(\'' + __picsPath + 'battle/loading.gif\')" id="loadingFrame">Loading...</div>');
        top.main.window.document.write('</body></html>');
        top.main.window.document.close();

        top.main.window.langPack = langPack;

        try {
            include_dom(__picsPath + 'chat/common.js', "utf-8");
        } catch(ex) { }
        try {
            include_dom(__picsPath + 'js/boxover.js', "cp1251");
        } catch(ex) { }
        try {
            include_dom(__picsPath + 'battle/battle.js', "utf-8");
        } catch(ex) { }
        
        top.main.window.layoutType = layout;
    }

    if (top.main.window.document.getElementById('layoutDiv')) {
        if (layout != layoutType) {
            top.main.window.document.getElementById("layoutDiv").innerHTML = getLayoutText(layout);
        }

        try {
            updateAfterLayout();
        } catch(ex) {
        }

        top.main.window.layoutDone = true;
    }

    top.main.window.layoutDone = true;
    top.main.window.layoutType = layout;
    layoutType = layout;
}

function getLayoutText(layout) {
    var result = null;

    if (layout == "list") {
        result = getListLayout();
    } else if (layout == "search") {
        result = getSearchLayout();
    } else if (layout == "action") {
        result = getActionLayout();
    } else if (layout == "log") {
        result = getLogLayout();
    } else if (layout == "mineList") {
        result = getMineListLayout();
    } else if (layout == "mineElevator") {
        result = getMineElevatorLayout();
    } else if (layout == "mineRoom") {
        result = getMineRoomLayout();
    }

    return result; //  + '<script type="text/javascript">top.frames["voc_shower"].window.updateAfterLayout();</script>'
}

function setRoomData(requestId, name, description, image, actions, bots) {
    if (top.main.window.document.getElementById("roomImage")) {
        var imageDiv = top.main.window.document.getElementById("roomImage");
        imageDiv.innerHTML = '<img src="' + __picsPath + "mine/" + image + '.jpg" style="border: 1px solid black;" width="500" height="300" title="' + name + '"/>'
        imageDiv.style.width = "500px";
        imageDiv.style.height = "300px";
        imageDiv.style.position = "relative";

        var i = 0;
        var newBot;

        for (i = 0; i < actions.length; i++) {
            if (actions[i][8]) {
                newBot = top.main.window.document.createElement("DIV");
                newBot.innerHTML = '<img src="' + __picsPath + 'design/img/spacer.gif" ' +
                                      'width="' + actions[i][4] + '" height="' + actions[i][5] + '" title="header=[] body=[' + actions[i][6] + " {" + actions[i][9] + '}]" ' +
                                      'onClick="submitMineRoomAction(' + actions[i][0] + ', \'' + requestId + '\', ' + actions[i][9] + ', \'' + actions[i][7] + '\')" ' +
                                      'style="cursor: pointer;" onMouseOver="this.src=\'' + __picsPath + "mine/" + actions[i][1] + '.gif\';" onMouseOut="this.src=\'' + __picsPath + 'design/img/spacer.gif\';"/>';
                newBot.style.position = "absolute";
                newBot.style.left = actions[i][2] + "px";
                newBot.style.top = actions[i][3] + "px";
                imageDiv.appendChild(newBot);
            } else {
                newBot = top.main.window.document.createElement("DIV");
                newBot.innerHTML = '<img src="' + __picsPath + 'design/img/spacer.gif" ' +
                                      'width="' + actions[i][4] + '" height="' + actions[i][5] + '" title="header=[] body=[' + actions[i][6] + langPack["mineActionKicking"] + ']" ' +
                                      'onClick="submitMineRoomAction(' + actions[i][0] + ', \'' + requestId + '\', ' + actions[i][9] + ', \'' + actions[i][7] + '\')" ' +
                                      'style="cursor: pointer;" onMouseOver="this.src=\'' + __picsPath + "mine/" + actions[i][1] + '.gif\';" onMouseOut="this.src=\'' + __picsPath + 'design/img/spacer.gif\';"/>';
                newBot.style.position = "absolute";
                newBot.style.left = actions[i][2] + "px";
                newBot.style.top = actions[i][3] + "px";
                imageDiv.appendChild(newBot);
            }
        }

        if (bots) {
            for (i = 0; i < bots.length; i++) {
                var bot = bots[i];
                // bid, name, image, positionX, positionY, count
                newBot = top.main.window.document.createElement("DIV");
                newBot.style.position = "absolute";
                newBot.innerHTML = '';

                newBot.innerHTML += '<img src="' + __picsPath + 'mines/bots/' + bot[2] + '" ' +
                                      ' title="header=[] body=[' + bot[1] + ' (' + bot[5] + ")" + ']" onClick="submitMineBotAttack(' + bot[0] + ', ' + bot[5] + '); return false;" style="cursor: pointer;"/>';

                newBot.style.left = bot[3] + "px";
                newBot.style.top = bot[4] + "px";
                imageDiv.appendChild(newBot);
            }
        }
    }

    if (top.main.window.document.getElementById("roomName")) {
        top.main.window.document.getElementById("roomName").innerHTML = name;
    }

    if (top.main.window.document.getElementById("roomDescription")) {
        top.main.window.document.getElementById("roomDescription").innerHTML = description;
    }
}

function setSearchParameters(name, date) {
    try {
        var table = top.main.window.document.getElementById("searchResults");
        while (table.rows.length != 0) {
            table.deleteRow(0);
        }
    } catch(ex) {
    }

    top.main.window.document.getElementById("searchName").value = name;
    if (date) {
        top.main.window.document.getElementById("searchDate").value = date;
    }

    top.main.window.document.getElementById("cellDuel").className = "bgF";
    top.main.window.document.getElementById("cellTeams").className = "bgF";
    top.main.window.document.getElementById("cellMess").className = "bgF";
    top.main.window.document.getElementById("cellCurrent").className = "bgF";
    top.main.window.document.getElementById("cellSearch").className = "bgF";

    top.main.window.document.getElementById("cellADuel").className = "f";
    top.main.window.document.getElementById("cellATeams").className = "f";
    top.main.window.document.getElementById("cellAMess").className = "f";
    top.main.window.document.getElementById("cellACurrent").className = "f";
    top.main.window.document.getElementById("cellASearch").className = "f";

    top.main.window.document.getElementById("cellSearch").className = "bgF2";
    top.main.window.document.getElementById("cellASearch").className = "f2";

    top.main.window.document.getElementById("searchResults");
}

function addSearchResult(counter, time, timeout, id, type, info, hrefId) {
    var node = null;
    if (navigator.appVersion.indexOf("MSIE") != -1 && navigator.appVersion.indexOf("Opera") == -1) {
        node = top.main.window.document.getElementById("searchResults").insertRow();
    } else {
        node = top.main.window.document.createElement("TR")
    }

    if (time == '-') {
        prepareCell(node, null, counter != "" ? counter + "." : "&nbsp;", "center", null, "searchCounter");
        prepareCell(node, null, "&nbsp;", "center", null, "searchTime");
        prepareCell(node, null, "&nbsp;", "center", null, "searchTimeout");
        prepareCell(node, null, "&nbsp;", "center", null, "searchType");
        prepareCell(node, null, "&nbsp;", "center", null, "searchInfo");
    } else if (time == '?') {
        prepareCell(node, null, "&nbsp;", "center", null, "searchInfoCenter");
    } else {
        prepareCell(node, null, counter != "" ? counter + "." : "&nbsp;", "center", null, "searchCounter");

        prepareCell(node, null, '<b class="date">' + time + '</b>', "center", null, "searchTime");
        prepareCell(node, null, '<td align="center" valign="middle" bgcolor="#d2d2d2" width="25"><img src="' + __picsPath + 'design/img/time' + timeout + '.gif" title="header=[] body=[' + langPack["timeout"] + ' ' + timeout + langPack["mins"] + ' .]" height="17" width="17"></td>', "center", null, "searchTimeout");
        prepareCell(node, null, '<a target="_blank" href="/viewLog?' + escape(hrefId) + '"><img src="' + __picsPath + 'fighttype' + type + '.gif" height="17" width="17"/></a>', "center", null, "searchType");
        prepareCell(node, null, info, "center", null, "searchInfo");
    }

    if (!(navigator.appVersion.indexOf("MSIE") != -1 && navigator.appVersion.indexOf("Opera") == -1)) {
        top.main.window.document.getElementById("searchResults").appendChild(node);
    }
}

function setLog(logArray, title, notFirstTime) {
    var logHTML = "";

    if (top.main.window.document.getElementById("teamsDiv").innerHTML == "") {
        top.main.window.document.getElementById("teamsDiv").style.visibility = "hidden";
    }

    var index = 0;
    for (var i = 0; i < logArray.length; i++) {
        if (logArray[i] == '__step__') {
            index = 1 - index;
        } else {
            var alreadyHas = false;
            for (var j = i - 1; j >= i - 4; j--) {
                if (j < 0) {
                    break;
                }

                if (logArray[j] == logArray[i]) {
                    alreadyHas = true;
                    break;
                }
            }

            if (!alreadyHas) {
                logHTML += '<div class="b_logEntry' + index + '">' + logArray[i] + "</div>";
            }
        }
    }

    top.main.window.document.getElementById("logDiv").innerHTML = logHTML;
    if (title == '') {
        top.main.window.document.getElementById("logTitleDiv").style.display = 'none';
    } else {
        top.main.window.document.getElementById("logTitleDiv").style.display = 'block';
        top.main.window.document.getElementById("logTitleDiv").innerHTML = title;
    }
}

function setLogTimeoutTimer(time, name, fullTime) {
    if (time) {
        setLogTimeoutName();

        if (counterTimeouts['timeoutDiv']) {
            clearTimeout(counterTimeouts['timeoutDiv'])
        }
        outputTime(time, 'timeoutDiv', fullTime);
    }
}

function setLogTimeoutName() {
    top.main.window.document.getElementById("timeoutNameDiv").innerHTML = langPack["waiting..."] + " ";
}

var HTMLActionsKickPrefix =
        "<table bgcolor=\"#DCDCDC\" width=\"100%\" cellspacing=\"2\" cellpadding=\"0\" border=\"0\" align=\"center\">" +
        "<tr><td align=\"center\" width=\"50%\">" +
        "<img src=\"" + __picsPath + __lang + "/title_atack.gif\" width=\"87\" height=\"13\"></td>" +
        "<td align=\"center\">" +
        "<img src=\"" + __picsPath + __lang + "/title_defence.gif\" width=\"101\" height=\"13\"></td>" +
        "</tr><tr><td><table class=\"stable\" cellSpacing=\"1\" cellPadding=\"0\" border=\"0\" width=\"100%\">";

var HTMLActionsKickMidfix =
        "</table></td><td><table class=\"stable\" cellSpacing=\"1\" cellPadding=\"0\" border=\"0\" width=\"100%\">";

var HTMLActionsKickPostfix =
        "</table></td></tr></table>";

var HTMLActionsKickOne =
        "<tr><td bgcolor=\"#D2D2D2\"><input class=\"b_action\" type=\"radio\" name=\"kick\" value=\"Head\" id=\"k1\" onChange=\"saveKicks('k1', this.value);\"/> <label for=\"k1\">" +
                langPack["kickHead"] + "</label></td></tr>" +
        "<tr><td bgcolor=\"#D2D2D2\"><input class=\"b_action\" type=\"radio\" name=\"kick\" value=\"Breast\" id=\"k2\" onChange=\"saveKicks('k1', this.value);\"/> <label for=\"k2\">" +
                langPack["kickBreast"] + "</label></td></tr>" +
        "<tr><td bgcolor=\"#D2D2D2\"><input class=\"b_action\" type=\"radio\" name=\"kick\" value=\"Stomach\" id=\"k3\" onChange=\"saveKicks('k1', this.value);\"/> <label for=\"k3\">" +
                langPack["kickStomach"] + "</label></td></tr>" +
        "<tr><td bgcolor=\"#D2D2D2\"><input class=\"b_action\" type=\"radio\" name=\"kick\" value=\"Waist\" id=\"k4\" onChange=\"saveKicks('k1', this.value);\"/> <label for=\"k4\">" +
                langPack["kickWaist"] + "</label></td></tr>" +
        "<tr><td bgcolor=\"#D2D2D2\"><input class=\"b_action\" type=\"radio\" name=\"kick\" value=\"Legs\" id=\"k5\" onChange=\"saveKicks('k1', this.value);\"/> <label for=\"k5\">" +
                langPack["kickLegs"] + "</label></td></tr>";

var HTMLActionsKickTwo =
        "<tr><td bgcolor=\"#D2D2D2\">" +
              "<input class=\"b_action\" type=\"radio\" name=\"kick\" value=\"Head\" onChange=\"saveKicks('k1', this.value);\"/>" +
              "<input class=\"b_action\" type=\"radio\" name=\"kick2\" value=\"Head\" id=\"k1\" onChange=\"saveKicks('k2', this.value);\"/> <label for=\"k1\">" +
              langPack["kickHead"] + "</label></td></tr>" +
        "<tr><td bgcolor=\"#D2D2D2\">" +
              "<input class=\"b_action\" type=\"radio\" name=\"kick\" value=\"Breast\" onChange=\"saveKicks('k1', this.value);\"/>" +
              "<input class=\"b_action\" type=\"radio\" name=\"kick2\" value=\"Breast\" id=\"k2\" onChange=\"saveKicks('k2', this.value);\"/> <label for=\"k2\">" +
              langPack["kickBreast"] + "</label></td></tr>" +
        "<tr><td bgcolor=\"#D2D2D2\">" +
              "<input class=\"b_action\" type=\"radio\" name=\"kick\" value=\"Stomach\" onChange=\"saveKicks('k1', this.value);\"/>" +
              "<input class=\"b_action\" type=\"radio\" name=\"kick2\" value=\"Stomach\" id=\"k3\" onChange=\"saveKicks('k2', this.value);\"/> <label for=\"k3\">" +
              langPack["kickStomach"] + "</label></td></tr>" +
        "<tr><td bgcolor=\"#D2D2D2\">" +
              "<input class=\"b_action\" type=\"radio\" name=\"kick\" value=\"Waist\" onChange=\"saveKicks('k1', this.value);\"/>" +
              "<input class=\"b_action\" type=\"radio\" name=\"kick2\" value=\"Waist\" id=\"k4\" onChange=\"saveKicks('k2', this.value);\"/> <label for=\"k4\">" +
              langPack["kickWaist"] + "</label></td></tr>" +
        "<tr><td bgcolor=\"#D2D2D2\">" +
              "<input class=\"b_action\" type=\"radio\" name=\"kick\" value=\"Legs\" onChange=\"saveKicks('k1', this.value);\"/>" +
              "<input class=\"b_action\" type=\"radio\" name=\"kick2\" value=\"Legs\" id=\"k5\" onChange=\"saveKicks('k2', this.value);\"/> <label for=\"k5\">" +
              langPack["kickLegs"] + "</label></td></tr>";

var HTMLActionsDefenceOne =
        "<tr><td bgcolor=\"#D2D2D2\"><input class=\"b_action\" type=\"radio\" name=\"defence\" value=\"Head\" id=\"d1\" onClick=\"saveKicks('d', this.value);\"/> <label for=\"d1\">" +
                langPack["defenceH"] + "</label></td></tr>" +
        "<tr><td bgcolor=\"#D2D2D2\"><input class=\"b_action\" type=\"radio\" name=\"defence\" value=\"Breast\" id=\"d2\" onClick=\"saveKicks('d', this.value);\"/> <label for=\"d2\">" +
                langPack["defenceB"] + "</label></td></tr>" +
        "<tr><td bgcolor=\"#D2D2D2\"><input class=\"b_action\" type=\"radio\" name=\"defence\" value=\"Stomach\" id=\"d3\" onClick=\"saveKicks('d', this.value);\"/> <label for=\"d3\">" +
                langPack["defenceS"] + "</label></td></tr>" +
        "<tr><td bgcolor=\"#D2D2D2\"><input class=\"b_action\" type=\"radio\" name=\"defence\" value=\"Waist\" id=\"d4\" onClick=\"saveKicks('d', this.value);\"/> <label for=\"d4\">" +
                langPack["defenceW"] + "</label></td></tr>" +
        "<tr><td bgcolor=\"#D2D2D2\"><input class=\"b_action\" type=\"radio\" name=\"defence\" value=\"Legs\" id=\"d5\" onClick=\"saveKicks('d', this.value);\"/> <label for=\"d5\">" +
                langPack["defenceL"] + "</label></td></tr>";

var HTMLActionsDefenceTwo =
        "<tr><td bgcolor=\"#D2D2D2\"><input class=\"b_action\" type=\"radio\" name=\"defence\" value=\"HeadBreast\" id=\"d1\" onClick=\"saveKicks('d', this.value);\"/> <label for=\"d1\">" +
                langPack["defenceHB"] + "</label></td></tr>" +
        "<tr><td bgcolor=\"#D2D2D2\"><input class=\"b_action\" type=\"radio\" name=\"defence\" value=\"BreastStomach\" id=\"d2\" onClick=\"saveKicks('d', this.value);\"/> <label for=\"d2\">" +
                langPack["defenceBS"] + "</label></td></tr>" +
        "<tr><td bgcolor=\"#D2D2D2\"><input class=\"b_action\" type=\"radio\" name=\"defence\" value=\"StomachWaist\" id=\"d3\" onClick=\"saveKicks('d', this.value);\"/> <label for=\"d3\">" +
                langPack["defenceSW"] + "</label></td></tr>" +
        "<tr><td bgcolor=\"#D2D2D2\"><input class=\"b_action\" type=\"radio\" name=\"defence\" value=\"WaistLegs\" id=\"d4\" onClick=\"saveKicks('d', this.value);\"/> <label for=\"d4\">" +
                langPack["defenceWL"] + "</label></td></tr>" +
        "<tr><td bgcolor=\"#D2D2D2\"><input class=\"b_action\" type=\"radio\" name=\"defence\" value=\"LegsHead\" id=\"d5\" onClick=\"saveKicks('d', this.value);\"/> <label for=\"d5\">" +
                langPack["defenceLH"] + "</label></td></tr>";

var HTMLActionsDefenceThree =
        "<tr><td bgcolor=\"#D2D2D2\"><input class=\"b_action\" type=\"radio\" name=\"defence\" value=\"HeadBreastStomach\" id=\"d1\" onClick=\"saveKicks('d', this.value);\"/> <label for=\"d1\">" +
                langPack["defenceHBS"] + "</label></td></tr>" +
        "<tr><td bgcolor=\"#D2D2D2\"><input class=\"b_action\" type=\"radio\" name=\"defence\" value=\"BreastStomachWaist\" id=\"d2\" onClick=\"saveKicks('d', this.value);\"/> <label for=\"d2\">" +
                langPack["defenceBSW"] + "</label></td></tr>" +
        "<tr><td bgcolor=\"#D2D2D2\"><input class=\"b_action\" type=\"radio\" name=\"defence\" value=\"StomachWaistLegs\" id=\"d3\" onClick=\"saveKicks('d', this.value);\"/> <label for=\"d3\">" +
                langPack["defenceSWL"] + "</label></td></tr>" +
        "<tr><td bgcolor=\"#D2D2D2\"><input class=\"b_action\" type=\"radio\" name=\"defence\" value=\"WaistLegsHead\" id=\"d4\" onClick=\"saveKicks('d', this.value);\"/> <label for=\"d4\">" +
                langPack["defenceWLH"] + "</label></td></tr>" +
        "<tr><td bgcolor=\"#D2D2D2\"><input class=\"b_action\" type=\"radio\" name=\"defence\" value=\"LegsHeadBreast\" id=\"d5\" onClick=\"saveKicks('d', this.value);\"/> <label for=\"d5\">" +
                langPack["defenceLHB"] + "</label></td></tr>";

var HTMLActionsTimeout =
        "<table width=\"300\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" align=\"center\"><tr><td>" +
        langPack["opponentTimeouted"] + "<br/>" +
        "<input class=\"b_action\" type=\"radio\" name=\"timeout\" value=\"TimeoutWin\"/> " + langPack["timeoutWin"] + "<br/>" +
        "<input class=\"b_action\" type=\"radio\" name=\"timeout\" value=\"TimeoutDraw\"/> " + langPack["timeoutDraw"] + "</td></tr></table>";

var HTMLActionsChangesCountPrefix =
        "<input type=\"button\" class=\"btn\" value=\"" + langPack["changeOpponent"] + " (";

var HTMLActionsChangesCountPostfix =
        ")\" style=\"cursor: pointer;\" onclick=\"changeOpponent();\"/>&nbsp;";

var HTMLActionsMagicPrefix =
        "<table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"2\"><tr>";

var HTMLActionsMagicPostfix =
        "</tr></table>";

function setActions(actionsString, magicItems) {
    top.main.window.ignoreSelects = true;
    if (top.main.window.document.getElementById("actionsDiv")) {
        var result = "<form onsubmit=\"return false;\" id=\"actionForm\">";
        if (actionsString.indexOf("k") != -1) {
            result += HTMLActionsKickPrefix;

            if (actionsString.indexOf("k1") != -1) {
                result += HTMLActionsKickOne;
            } else {
                result += HTMLActionsKickTwo;
            }

            result += HTMLActionsKickMidfix;

            if (actionsString.indexOf("d1") != -1) {
                result += HTMLActionsDefenceOne;
            } else if (actionsString.indexOf("d2") != -1) {
                result += HTMLActionsDefenceTwo;
            } else if (actionsString.indexOf("d3") != -1) {
                result += HTMLActionsDefenceThree;
            }

            result += HTMLActionsKickPostfix;
        }

        var kickName = langPack["actionKick"];

        if (actionsString.indexOf("zzzaaappp") != -1) {
            result += HTMLActionsTimeout;
            kickName = langPack["actionTimeout"];
        }

        if (actionsString.indexOf("m") != -1) {
            result += HTMLActionsMagicPrefix;

            for (var i = 0; i < magicItems.length; i++) {
                result += "<td><img src=\"" + __picsPath + "item/" + magicItems[i][0] +
                        ".gif\" title=\"header=[] body=[&lt;small&gt;&lt;b&gt;" + magicItems[i][1] + "&lt;/b&gt;&lt;br/&gt;" +
                        magicItems[i][2] +
                        "&lt;/small&gt;]\" border=\"0\" height=\"25\" width=\"40\" style=\"cursor: pointer;\" id=\"magicItem" + magicItems[i][3] + "_" + magicItems[i][5] + "\" " +
                          "onclick=\"useMagic(" + magicItems[i][3] + ", '" + magicItems[i][4] + "', '" + magicItems[i][1] + "', '" + magicItems[i][5] + "');\"" +
                          "></td>";
            }

            result += HTMLActionsMagicPostfix;
        }

        var opponentsCount = actionsString.indexOf("o");
        if (opponentsCount != -1) {
            var count = actionsString.substring(opponentsCount + 1, actionsString.indexOf(" ", opponentsCount));
            result += HTMLActionsChangesCountPrefix + count + HTMLActionsChangesCountPostfix;
        }

        result += "<input type=\"submit\" id=\"buttonForDisable\" value=\"" + kickName + "\" class=\"btn\" onclick=\"return battleSubmitAction();\"/></form>";

        top.main.window.document.getElementById("actionsDiv").innerHTML = result;

        updateTimeouts();
    }
    top.main.window.ignoreSelects = false;
}

function setUsersState(team1Names, team1HP, team2Names, team2HP) {
    var team1Wisper = "";
    var team1String = "";
    var team2Wisper = "";
    var team2String = "";

    for (var i = 0; i < team1Names.length; i++) {
        if (team1Wisper.length != 0) {
            team1Wisper += " ";
        }
        team1Wisper += 'private [' + team1Names[i] + ']';

        team1String += ' <span style="cursor: pointer;" onclick="parent.Whisper(\'to [' + team1Names[i] + ']\'); ' +
                       'top.AddLogin(event);" oncontextmenu="OpenMenu(event);return false" class="rteam">' +
                       team1Names[i] + '</span>[' + team1HP[i] + ']';
    }

    for (var i = 0; i < team2Names.length; i++) {
        if (team2Wisper.length != 0) {
            team2Wisper += " ";
        }
        team2Wisper += 'private [' + team2Names[i] + ']';

        team2String += ' <span style="cursor: pointer;" onclick="parent.Whisper(\'to [' + team2Names[i] + ']\'); ' +
                       'top.AddLogin(event);" oncontextmenu="OpenMenu(event);return false" class="lteam">' +
                       team2Names[i] + '</span>[' + team2HP[i] + ']';
    }

    top.main.window.document.getElementById("teamsDiv").innerHTML =
            '<img src="' + __picsPath + 'design/img/priv2.gif" onclick="top.Whisper(\'' + team1Wisper + '\');" style="cursor: pointer;">' +
            team1String + " <b> " + langPack["against"] + " </b>" +
            '<img src="' + __picsPath + 'design/img/priv2.gif" onclick="top.Whisper(\'' + team2Wisper + '\');" style="cursor: pointer;">' +
            team2String;
}

function setUser(type, userString, hp, mana, stamina, hpMax, manaMax, staminaMax, name, userImage, itemImages, itemNames, totalDamage, parameters, sex) {
    if (type == "user") {
        top.main.window.document.getElementById("totalsDiv").innerHTML = '<a target="_blank" href="/viewLog" style="color: black"><b>' + langPack["fullLog"] + '</b></a> | ' + langPack["totalDamage"] + ': <b>' + totalDamage + '</b>';
    }

    if (top.main.window.document.getElementById(type + "Div")) {
        top.main.window.document.getElementById(type + "Div").innerHTML =
                createUserDescription(name, userString, hp, mana, stamina, hpMax, manaMax, staminaMax, userImage, itemImages, itemNames, totalDamage, parameters, sex);
    }
}

function setUserShort(userString, hp, mana, stamina, hpMax, manaMax, staminaMax, name, hpSpeed, manaSpeed, staminaSpeed, offNavigation) {
    top.main.window.document.getElementById("userDiv").innerHTML = "" + createUserShortDescription(name, userString, hp, mana, stamina, hpMax, manaMax, staminaMax, hpSpeed, manaSpeed, staminaSpeed, offNavigation);
    if (top.main.window.document.getElementById("battleFilter")) {
        top.main.window.document.getElementById("battleFilter").value = top.main.window.battlesFilter;
    }

    if (top.main.window.document.getElementById("staminaTD")) {
        var staminaWidth = 150*(stamina/staminaMax);
        var staminaBGWidth = 150 - staminaWidth;

        top.main.window.document.getElementById("staminaTD").style.width = staminaWidth + "px";
        top.main.window.document.getElementById("staminaBGTD").style.width = staminaBGWidth + "px";
    }
}

function debugOut(outString) {
    document.getElementById("messages").innerHTML += outString + "<br/>";
}

var hpManaTimeout = null;

function hpManaUpdate(hp, hpMax, hpSpeed, mana, manaMax, manaSpeed, stamina, staminaMax, staminaSpeed) {
    var hpText = top.main.window.document.getElementById("hpText");
    var hpImg = top.main.window.document.getElementById("hpImg");
    var hpMaxImg = top.main.window.document.getElementById("hpMaxImg");

    var manaText = top.main.window.document.getElementById("manaText");
    var manaImg = top.main.window.document.getElementById("manaImg");
    var manaMaxImg = top.main.window.document.getElementById("manaMaxImg");

    var staminaText = top.main.window.document.getElementById("staminaText");
    var staminaImg = top.main.window.document.getElementById("staminaImg");
    var staminaMaxImg = top.main.window.document.getElementById("staminaMaxImg");

    if (hp > hpMax) {
        hp = hpMax;
    }

    if (mana > manaMax) {
        mana = manaMax;
    }

    if (stamina > staminaMax) {
        stamina = staminaMax;
    }

    var width = 150;

    if (hpImg && hpMaxImg) {
        var hpPart = hp/hpMax;

        var hpGreenWidth = Math.round(hpPart*width);
        var hpGrayWidth = width - hpGreenWidth;
        var hpType = '4';
        if (hpPart < 0.30) {
            hpType = '1';
        } else if (hpPart < 0.60) {
            hpType = '3';
        }

        hpImg.src = __picsPath + 'inf/hp' + hpType + '.gif';
        try {
            hpImg.style.width = hpGreenWidth + 'px';
            hpMaxImg.style.width = hpGrayWidth + 'px';
        } catch(ex) {
        }

        hpText.innerHTML = Math.round(hp) + "/" + hpMax + "&nbsp;";
    }

    if (manaImg && manaMaxImg) {
        var manaPart = mana/manaMax;
        var manaGreenWidth = Math.round(manaPart*width);
        var manaGrayWidth = width - manaGreenWidth;
        var manaType = '1';
        if (manaPart < 0.03) {
            manaType = '2';
        } else if (manaPart < 0.60) {
            manaType = '2';
        }

        manaImg.src = __picsPath + 'inf/m' + manaType + '.gif';
        try {
            manaImg.style.width = manaGreenWidth + "hp";
            manaMaxImg.style.width = manaGrayWidth + "hp";
        } catch(ex) {
        }

        manaText.innerHTML = Math.round(mana) + "/" + manaMax + "&nbsp;";
    }

    if ((layoutType == 'mineList' || layoutType == 'mineRoom') && staminaImg && staminaMaxImg) {
        var staminaPart = stamina/staminaMax;
        var staminaGreenWidth = Math.round(staminaPart*width);
        var staminaGrayWidth = width - staminaGreenWidth;

        var staminaType = '3';

        staminaImg.src = __picsPath + 'inf/hp3.gif';
        try {                                                                         
            staminaImg.style.width = staminaGreenWidth;
            staminaMaxImg.style.width = staminaGrayWidth;
        } catch(ex) {
        }

        staminaText.innerHTML = Math.round(stamina) + "/" + staminaMax + "&nbsp;";
    }

    if ((top.main.window.layoutType == 'list' || top.main.window.layoutType == 'mineList') && (hp < hpMax || mana < manaMax || stamina < staminaMax)) {
        var hpNew = new Number(hp);
        hpNew += new Number(hpSpeed);

        var manaNew = new Number(mana);
        manaNew += new Number(manaSpeed);

        var staminaNew = new Number(stamina);
        staminaNew += new Number(staminaSpeed);

        hpManaTimeout = setTimeout("hpManaUpdate(" +
                                   hpNew + ", " + hpMax + ", " + hpSpeed + ", " +
                                   manaNew + ", " + manaMax + ", " + manaSpeed + ", " +
                                   staminaNew + ", " + staminaMax + ", " + staminaSpeed + ");", 1000);
    }
}

function createUserShortDescription(name, userString, hp, mana, stamina, hpMax, manaMax, staminaMax, hpSpeed, manaSpeed, staminaSpeed, offNavigation) {
    var hpPart = hp/hpMax;
    var manaPart = mana/manaMax;
    var staminaPart = stamina/staminaMax;

    if (hpManaTimeout) {
        clearTimeout(hpManaTimeout);
    }

    var hpNew = new Number(hp);
    hpNew += new Number(hpSpeed);
    var manaNew = new Number(mana);
    manaNew += new Number(manaSpeed);
    var staminaNew = new Number(stamina);
    staminaNew += new Number(staminaSpeed);

    if (layoutType != "mineRoom") {
        hpManaTimeout = setTimeout("hpManaUpdate(" +
                                   hpNew + ", " + hpMax + ", " + hpSpeed + ", " +
                                   manaNew + ", " + manaMax + ", " + manaSpeed + ", " +
                                   staminaNew + ", " + staminaMax + ", " + staminaSpeed + ");", 1000);
    }

    var width = 150;

    var hpGreenWidth = hpPart*width;
    var hpGreyWidth = width - hpPart*width;
    var hpType = '4';
    if (hpPart < 0.30) {
        hpType = '1';
    } else if (hpPart < 0.60) {
        hpType = '3';
    }

    var manaGreenWidth = manaPart*width;
    var manaGreyWidth = width - manaPart*width;
    var manaType = '1';
    if (manaPart < 0.03) {
        manaType = '2';
    } else if (manaPart < 0.60) {
        manaType = '2';
    }

    var staminaGreenWidth = staminaPart*width;
    var staminaGreyWidth = width - staminaPart*width;
    var staminaType = '1';
    if (staminaPart < 0.30) {
        staminaType = '2';
    } else if (staminaPart < 0.60) {
        staminaType = '2';
    }

    var cellWidth = width + 3;

    var result =                                   
            '<table border="0" cellpadding="0" cellspacing="0" style="margin-bottom: 0px; margin-top: 5px; margin-left: 0px; margin-right: 0px; padding: 0px;"';

    if (!offNavigation) {
            result += ' width="100%">';
    }

    result +=
            '<tr><td align="right" valign="bottom" rowspan="3" width="200" nowrap="true" style="padding-bottom: 2px;">' + userString + '&nbsp;</td>' +

            '<td align="right" width="50" style="width: 60px;"><span class="small" id="hpText">' + hp + '/' + hpMax + '&nbsp;</span></td>' +
            '<td align="left" width="' + cellWidth + '"><img src="' + __picsPath + 'inf/hp' + hpType + '.gif" alt="' + langPack["hp"] + '" width="' + hpGreenWidth + '" align="middle" height="8" id="hpImg"/>' +
                '<img src="' + __picsPath + 'inf/hp2.gif" alt="' + langPack["hp"] + '" width="' + hpGreyWidth + '" align="middle" height="8" id="hpMaxImg"/></td>' +
            '<td align="left" width="16"><img src="' + __picsPath + 'inf/hp_ico.gif" width="14" height="10" alt="' + langPack["hp"] + '" /></td>';

    if (top.main.window.battlesType == "Duel" || !offNavigation) {
        result += '<td rowspan="3" nowrap="true" align="right" style="padding-right: 1cm;"><nowrap>';
    }

    if (top.main.window.battlesType == "Duel") {
        result += createFilterString();
    }
    
    if (!offNavigation) {
        if (top.main.window.layoutType == 'mineList') {
            result += '<img src="' + __picsPath + 'navi/b_quest.gif" width="15" height="15" alt="' + langPack["quest"] + '" title="header=[] body=[' + langPack["quest"] + ']" onclick="document.location.href=\'/quest?show\'" alt="' + langPack["quest"] + '" title="' + langPack["quest"] + '" style="cursor: pointer">&nbsp;&nbsp;';
        } else {
            result +=   '<a style="color: #333333" href="view.php?action=map"><img src="' + __picsPath + 'navi/b_map.gif" width="15" height="15" alt="header=[] body=[' + langPack["map"] + ']" title="header=[] body=[' + langPack["map"] + ']"></a>&nbsp;&nbsp;';
        }
        
        if (top.main.window.layoutType != 'mineList') {
            result +=   '<img src="' + __picsPath + 'design/img/b_help.gif" width="15" height="15" onclick="window.open(\'http://' + langPack["enciclHTTP"] + '/help/fight.html\', \'help\', \'height=300,width=500,location=no,menubar=no,status=no,toolbar=no,scrollbars=yes\')" alt="' + langPack["help"] + '" title="header=[] body=[' + langPack["help"] + ']" style="cursor: pointer"/>&nbsp;&nbsp;';
        } else {
            result +=   '<img src="' + __picsPath + 'design/img/b_help.gif" width="15" height="15" onclick="window.open(\'http://' + langPack["enciclHTTP"] + '/help/mine1.html\', \'help\', \'height=300,width=500,location=no,menubar=no,status=no,toolbar=no,scrollbars=yes\')" alt="' + langPack["help"] + '" title="header=[] body=[' + langPack["help"] + ']" style="cursor: pointer"/>&nbsp;&nbsp;';
        }

        if (top.main.window.layoutType != 'mineList') {
            result +=   '<a href="view.php?' + Math.random() + '"><img src="' + __picsPath + 'design/img/b_back.gif" width="15" height="15" border="0" alt="' + langPack["back"] + '" title="header=[] body=[' + langPack["back"] + ']"/></a>';
        } else {
            result +=   '<a href="view.php" onclick="top.CheckMove(\'' + langPack["mineExitTo"] + '\'); return false;"><img src="' + __picsPath + 'design/img/b_back.gif" width="15" height="15" border="0" alt="' + langPack["back"] + '" title="header=[] body=[' + langPack["back"] + ']"/></a>' +
                     '<div id="message" class="small"></div>' +
                     '<table border="0" cellpadding="0" cellspacing="0" width="100">' +
                       '<tr>' +
                         '<td background="http://img.chaosroad.com/i/go/bg.gif" height="10" width="100"><img src="http://img.chaosroad.com/i/go/move.gif" id="move" name="move" alt="" height="10" width="1"></td>' +
                       '</tr>' +
                     '</table>';
        }
    }
    
    if (top.main.window.battlesType == "Duel" || !offNavigation) {
        result += '</nowrap></td>'; 
    }

    result += '</tr>';

    if (manaMax > 1) {
        result +=
            '<tr>' +
            '<td align="right" width="50" style="width: 50px;';

        if ((top.main.window.layoutType != 'mineList' && top.main.window.layoutType != "mineRoom") || staminaMax < 1) {
            result += 'padding-bottom: 3px;';
        }

        result +=
            '"><span class="small" id="manaText">' + mana + '/' + manaMax + '&nbsp;</span></td>' +
            '<td align="left" width="' + cellWidth + '" align="left"><img src="' + __picsPath + 'inf/m' + manaType + '.gif" alt="' + langPack["mana"] + '" width="' + manaGreenWidth + '" align="middle" height="8" id="manaImg"/>' +
                '<img src="' + __picsPath + 'inf/hp2.gif" alt="' + langPack["mana"] + '" width="' + manaGreyWidth + '" align="middle" height="8" id="manaMaxImg"/></td>' +
            '<td align="left"><img src="' + __picsPath + 'inf/mana_ico.gif" width="11" height="10" alt="' + langPack["mana"] + '" /></td>' +
            '</tr>';
    }

    if ((top.main.window.layoutType == 'mineList' || top.main.window.layoutType == 'mineRoom') && staminaMax > 1) {
        result +=
            '<tr>' +
            '<td align="right" width="50" style="width: 50px; padding-bottom: 3px;"><span class="small" id="staminaText">' + stamina + '/' + staminaMax + '&nbsp;</span></td>' +
            '<td align="left" width="' + cellWidth + '" align="left"><img src="' + __picsPath + 'inf/hp3.gif" alt="' + langPack["stamina"] + '" width="' + staminaGreenWidth + '" align="middle" height="8" id="staminaImg"/>' +
                '<img src="' + __picsPath + 'inf/hp2.gif" alt="' + langPack["stamina"] + '" width="' + staminaGreyWidth + '" align="middle" height="8" id="staminaMaxImg"/></td>' +
            '<td align="left"><img src="' + __picsPath + 'inf/stamina_ico.gif" width="14" height="10" alt="' + langPack["stamina"] + '" /></td>' +
            '</tr>';
    }

    return result + "</table>";
}

function createUserDescription(name, userString, hp, mana, stamina, hpMax, manaMax, staminaMax, userImage, itemImages, itemNames, totalDamage, parameters, sex) {
    var result = '';

    result += '<table align="center" border="0" cellpadding="0" cellspacing="0" width="220">' +
             '<tr><td align="center" colspan="4">' + userString + '</td></tr>';

    result += getSlots(150, true, userString, hp, mana, stamina, hpMax, manaMax, staminaMax, name, userImage, itemImages, itemNames, totalDamage, parameters, sex);

    result += '<tr><td align="center"><table align="center" border="0" cellpadding="0" cellspacing="0" width="100%">' +
              '<tr>' +
              '<td height="23" width="59"><img src="' + __picsPath + 'inf/p2_1.jpg" height="23" width="59"></td>' +
              '<td background="' + __picsPath + 'inf/p2bg.jpg" width="50%"></td>' +
              '<td background="' + __picsPath + 'inf/p2bg.jpg" width="50%"></td>' +
              '<td height="23" width="59"><img src="' + __picsPath + 'inf/p2_3.jpg" height="23" width="59"></td>' +
              '</tr></table></td></tr>'

    result += outputStats(150, true, userString, hp, mana, stamina, hpMax, manaMax, staminaMax, name, userImage, itemImages, itemNames, totalDamage, parameters, sex);

    result += '</table></td></tr>';

    return result + '</table>';
}

function outputStats(width, needNameHeader, userString, hp, mana, stamina, hpMax, manaMax, staminaMax, name, userImage, itemImages, itemNames, totalDamage, parameters, sex, aLinksType) {
    var result = "";
    if (aLinksType == "inventory") {
        result +=
                  langPack["experience"] + ': ' + parameters[6] + '[<a href="http://encicl.chaosroad.com/exp.html" target="_blank" style="color: black; text-decoration: none;"><b>' + parameters[13] + '</b></a>]<br/>' +
                  langPack["level"] + ': <b>' + parameters[7] + '</b><br/>' +
                  langPack["wins"] + ': ' + parameters[8] + '<br/>' +
                  langPack["losses"] + ': ' + parameters[9] + '<br/>' +
                  langPack["draws"] + ': ' + parameters[10] + '<br/>'+
                  langPack["money"] + ': <b>' + parameters[11] + '</b> <img src="' + __picsPath + 'design/img/money.gif" width="16" height="16"/><br/>';

        if (parameters[12] > 0) {
            result += ' • <a href="#" onclick="myRequest(\'skills\')" style="color: black; text-decoration: none;"><b>' + langPack["skillups"] + '</b></a>';
        }

        result += "<hr/>";

        result +=
                  langPack["strength"] + ': <b>' + parameters[0] + '</b><br/>' +
                  langPack["dexterity"] + ': <b>' + parameters[1] + '</b><br/>' +
                  langPack["intuition"] + ': <b>' + parameters[2] + '</b><br/>' +
                  langPack["power"] + ': <b>' + parameters[3] + '</b><br/>';

        if (parameters[4] > 0) {
            result +=
                  langPack["intellect"] + ': <b>' + parameters[4] + '</b><br/>';
        }

        if (parameters[5] > 0) {
            result +=
                  langPack["wisdom"] + ': <b>' + parameters[5] + '</b><br/>';
        }

        return result;
    } else {
        result =
                '<tr><td colspan="3" style="padding: 20px; padding-bottom: 0px; padding-top: 3px;" align="center"><table class="stable" cellSpacing="2" cellPadding="1" border="0" align="center" width="220">' +

                  '<tr><td bgcolor="#D2D2D2"><img src="' + __picsPath + 'design/img/ico_sila.gif" width="13" height="13"></td>' +
                  '<td bgcolor="#D2D2D2" width="90%">' + langPack["strength"] + ':</td><td bgcolor="#D2D2D2" align="center"><b>' + parameters[0] + '</b></td></tr>' +

                  '<tr><td bgcolor="#D2D2D2"><img src="' + __picsPath + 'design/img/ico_lovk.gif" width="13" height="13"></td>' +
                  '<td bgcolor="#D2D2D2" width="90%">' + langPack["dexterity"] + ':</td><td bgcolor="#D2D2D2" align="center"><b>' + parameters[1] + '</b></td></tr>' +

                  '<tr><td bgcolor="#D2D2D2"><img src="' + __picsPath + 'design/img/ico_inta.gif" width="13" height="13"></td>' +
                  '<td bgcolor="#D2D2D2" width="90%">' + langPack["intuition"] + ':</td><td bgcolor="#D2D2D2" align="center"><b>' + parameters[2] + '</b></td></tr>' +

                  '<tr><td bgcolor="#D2D2D2"><img src="' + __picsPath + 'design/img/ico_vin.gif" width="13" height="13"></td>' +
                  '<td bgcolor="#D2D2D2" width="90%">' + langPack["power"] + ':</td><td bgcolor="#D2D2D2" align="center"><b>' + parameters[3] + '</b></td></tr>';

        if (parameters[4] > 0) {
            result +=
                  '<tr><td bgcolor="#D2D2D2"><img src="' + __picsPath + 'design/img/ico_intel.gif" width="13" height="13"></td>' +
                  '<td bgcolor="#D2D2D2" width="90%">' + langPack["intellect"] + ':</td><td bgcolor="#D2D2D2" align="center"><b>' + parameters[4] + '</b></td></tr>';
        }

        if (parameters[5] > 0) {
            result +=
                  '<tr><td bgcolor="#D2D2D2"><img src="' + __picsPath + 'design/img/ico_mudr.gif" width="13" height="13"></td>' +
                  '<td bgcolor="#D2D2D2" width="90%">' + langPack["wisdom"] + ':</td><td bgcolor="#D2D2D2" align="center"><b>' + parameters[5] + '</b></td></tr>';
        }

        return result;
    }
}

function getSlots(width, needNameHeader, userString, hp, mana, stamina, hpMax, manaMax, staminaMax, name, userImage, itemImages, itemNames, totalDamage, parameters, sex, aLinksType) {
    var result = '';

    if (!aLinksType) {
        aLinksType = "general";
    } else if (aLinksType == "inventory") {
        result += '<tr><td align="center" colspan="4">' + userString + '</td></tr>'
    }

    var hpPart = hp/hpMax;
    var manaPart = mana/manaMax;
    var staminaPart = stamina/staminaMax;

    var hpGreenWidth = hpPart*width;
    var hpGreyWidth = width - hpPart*width;
    var hpType = '4';
    if (hpPart < 0.30) {
        hpType = '1';
    } else if (hpPart < 0.60) {
        hpType = '3';
    }

    var manaGreenWidth = manaPart*width;
    var manaGreyWidth = width - manaPart*width;
    var manaType = '1';
    if (manaPart < 0.03) {
        manaType = '2';
    } else if (manaPart < 0.60) {
        manaType = '2';
    }

    var staminaGreenWidth = staminaPart*width;
    var staminaGreyWidth = width - staminaPart*width;
    var staminaType = '1';
    if (staminaPart < 0.30) {
        staminaType = '2';
    } else if (staminaPart < 0.60) {
        staminaType = '2';
    }

    var cellWidth = width + 3;

    result +=
             '<tr><td align="center"><table cellspacing="0" cellpadding="0" border="0">' +

             '<tr>' +
                 '<td align="right" width="60"><span class="small">' + hp + '/' + hpMax + '&nbsp;</span></td>' +
                 '<td align="right" width="' + cellWidth + '" style="width: ' + cellWidth + '"><img src="' + __picsPath + 'inf/hp' + hpType + '.gif" alt="' + langPack["hp"] + '" width="' + hpGreenWidth + '" align="middle" height="8"/>' +
                    '<img src="' + __picsPath + 'inf/hp2.gif" alt="' + langPack["hp"] + '" width="' + hpGreyWidth + '" align="middle" height="8"/></td>' +
                 '<td align="left" width="16"><img src="' + __picsPath + 'inf/hp_ico.gif" width="14" height="10" alt="' + langPack["hp"] + '" /></td></tr>';

    if (needNameHeader && manaMax > 1) {
         result +=
                 '<tr><td align="right"><span class="small">' + mana + '/' + manaMax + '&nbsp;</span></td>' +
                 '<td align="right" width="' + cellWidth + '" align="left"><img src="' + __picsPath + 'inf/m' + manaType + '.gif" alt="' + langPack["mana"] + '" width="' + manaGreenWidth + '" align="middle" height="8"/>' +
                     '<img src="' + __picsPath + 'inf/hp2.gif" alt="' + langPack["mana"] + '" width="' + manaGreyWidth + '" align="middle" height="8"/></td>' +
                 '<td align="left"><img src="' + __picsPath + 'inf/mana_ico.gif" width="11" height="10" alt="' + langPack["mana"] + '" /></td></tr>';
    }

    if (aLinksType == 'inventory' && parameters[7] >= 7) { //  || (needNameHeader && staminaMax > 1 && layoutType == "mineRoom")
        result +=
                 '<tr><td align="right"><span class="small">' + stamina + '/' + staminaMax + '&nbsp;</span></td>' +
                 '<td align="right" width="' + cellWidth + '" align="left"><img src="' + __picsPath + 'inf/stamina_bg.gif" alt="' + langPack["stamina"] + '" width="' + staminaGreenWidth + '" align="middle" height="8"/>' +
                     '<img src="' + __picsPath + 'inf/hp2.gif" alt="' + langPack["stamina"] + '" width="' + staminaGreyWidth + '" align="middle" height="8"/></td>' +
                 '<td align="left"><img src="' + __picsPath + 'inf/stamina_ico.gif" width="14" height="10" alt="' + langPack["stamina"] + '" /></td></tr>';
    }

    result += '</table></td></tr>';

//    if (aLinksType == 'inventory') {
//        result +=
//                '<tr><td align="right"><span class="small">' + stamina + '/' + staminaMax + '&nbsp;</span>' +
//                '</td><td align="center"><img src="' + __picsPath + 'inf/stamina_ico.gif" width="14" height="10" alt="' + langPack["stamina"] + '" />' +
//                '</td><td align="left"><img src="' + __picsPath + 'inf/hp2.gif" alt="' + langPack["stamina"] + '" width="' + staminaGreenWidth + '" height="8"/>' +
//                '<img src="' + __picsPath + 'inf/hp2.gif" alt="' + langPack["stamina"] + '" width="' + staminaGreyWidth + '" height="8"/>' +
//                '</td></tr>';
//    }

    result += '<tr><td align="center"><table align="center" border="0" cellpadding="0" cellspacing="0" width="100%">' +
              '<tr>' +
              '<td height="23" width="59"><img src="' + __picsPath + 'inf/p1_1.jpg" height="23" width="59"></td>' +
              '<td background="' + __picsPath + 'inf/pbg1.jpg" width="50%"></td>' +
              '<td background="' + __picsPath + 'inf/pbg1.jpg" width="50%"></td>' +
              '<td height="23" width="59"><img src="' + __picsPath + 'inf/p1_3.jpg" height="23" width="59"></td>' +
              '</tr></table></td></tr>';

    result +=
            '<tr><td>' +
                '<table align="center" border="0" cellpadding="0" cellspacing="0" width="220">' +
                    '<tr><td valign="top" width="62">' +
                        '<table border="0" cellpadding="0" cellspacing="0" width="100%">' +
                        '<tr><td width="60">' + createItemImage(itemImages, itemNames, 0, 60, 20, aLinksType) + '</td></tr>' +
                        '<tr><td width="60">' + createItemImage(itemImages, itemNames, 1, 60, 20, aLinksType) + '</td></tr>' +
                        '<tr><td width="60">' + createItemImage(itemImages, itemNames, 2, 60, 60, aLinksType) + '</td></tr>' +
                        '<tr><td width="60">' + createItemImage(itemImages, itemNames, 3, 60, 80, aLinksType) + '</td></tr>' +
                        '<tr><td width="60">' + createItemImage(itemImages, itemNames, 4, 20, 20, aLinksType) + '' +
                                           '' + createItemImage(itemImages, itemNames, 5, 20, 20, aLinksType) + '' +
                                           '' + createItemImage(itemImages, itemNames, 6, 20, 20, aLinksType) + '' +
                        '</table></td>' +

                    '<td valign="top"><img src="' + __picsPath + 'chars/' + sex + '/' + userImage + '.gif" border="0" height="200" width="100"></td>' +

                    '<td valign="top" width="62">' +
                       '<table border="0" cellpadding="0" cellspacing="0" width="62">' +
                             '<tr><td width="60">' + createItemImage(itemImages, itemNames, 7, 60, 60, aLinksType) + '</td></tr>' +
                             '<tr><td width="60">' + createItemImage(itemImages, itemNames, 8, 60, 40, aLinksType) + '</td></tr>' +
                             '<tr><td width="60">' + createItemImage(itemImages, itemNames, 9, 60, 60, aLinksType) + '</td></tr>' +
                             '<tr><td width="60">' + createItemImage(itemImages, itemNames, 10, 60, 40, aLinksType) + '</td></tr>' +
                       '</table>' +
                     '</td></tr>' +
                '</table></td></tr>' +
            '<tr><td height="5"><img src="' + __picsPath + 'design/img/spacer.gif" height="5" width="1"></td></tr>';

    return result;
}

function createItemImage(itemImages, itemNames, index, width, height, aLinkType) {
    if (!itemNames || !itemImages) {
        return '';
    }

    var result = ''

    if (itemNames[index] == "slot.empty") {
        itemNames[index] = langPack["emptySlot"];
    }

    if (itemNames[index] != langPack["emptySlot"] && itemNames[index] != "slot.empty") {
        if (aLinkType == 'inventory') {
            result += '<a href="#" onclick="takeOffItem(' + index + '); return false;" target="_blank">';
        } else {
            result += '<a href="http://' + langPack["enciclHTTP"] + '/object/' + itemImages[index*3] + '.html" target="_blank">';
        }
    }

    result += '<img src="' + __picsPath + 'item/' + getItemImage(itemImages, index) + '.gif" ' +
                   'title="header=[] body=[&lt;small&gt;&lt;b&gt;' + itemNames[index] + '&lt;/b&gt;&lt;br/&gt;';

    if (itemNames[index] != langPack["emptySlot"] && itemNames[index] != "slot.empty") {
        result += getItemCondition(itemImages, index) + outSomethingIfNotZero(itemImages, index) + '&lt;/small&gt;';
    }

    result += ']" border="0" height="' + height + '" width="' + width + '"/>';

    if (itemNames[index] != langPack["emptySlot"] && itemNames[index] != "slot.empty") {
        result += '</a>'
    }

    return result;
}

function outSomethingIfNotZero(items, index) {
    if (getItemDamage(items, index).indexOf("-") != -1) {
        if (getItemDamage(items, index) != "0 - 0") {
            return '&lt;br/&gt;' + langPack["damage"] + ': ' + getItemDamage(items, index);
        }
    } else {
        if (getItemDamage(items, index) != "0") {
            return '&lt;br/&gt;' + langPack["hp"] + ': +' + getItemDamage(items, index);
        }
    }

    return "";
}

function getItemImage(items, index) {
    return items ? items[index*3] : 0;
}

function getItemCondition(items, index) {
    if (items[index*3 + 1] != '0/0') {
        return langPack["condition"] + ': ' + items[index*3 + 1];
    } else {
        return '';
    }
}

function getItemDamage(items, index) {
    return items[index*3 + 2];
}

function setCreateNewVisible(value) {
    if (value && layoutType != "Current") {
        top.main.window.document.getElementById("createNewDiv").style.display = "block";
    } else {
        top.main.window.document.getElementById("createNewDiv").style.display = "none";
    }
}

function updateBattlesList(page, totalPages, needHideSelector, canMineToday) {
    listBattlesDone = true;

    try {
        top.main.window.document.getElementById("battlesData").innerHTML = "";
        top.main.window.document.getElementById("battlesData").appendChild(battlesTable);
    } catch(ex) {
    }

    if (top.main.window.document.getElementById("typeSelector")) {
        if (needHideSelector) {
            top.main.window.document.getElementById("typeSelector").style.display = "none";
        } else {
            top.main.window.document.getElementById("typeSelector").style.display = "block";
        }
    }

    if (canMineToday != undefined && top.main.window.document.getElementById("nextMining")) {
        if (canMineToday == -1) {
            top.main.window.document.getElementById("nextMining").innerHTML = langPack["youCanMineToday"];
        } else {
            var date = new Date();
            date.setUTCHours(0);
            date.setUTCMinutes(0);
            date.setUTCSeconds(0);
            date.setUTCMilliseconds(0);
            date.setTime(date.getTime() + canMineToday + 1000*60);

            var minutes = date.getUTCMinutes();
            if (minutes < 10) {
                minutes = "0" + minutes;
            }
            
            var inTime = date.getUTCHours() + "ч. " + minutes + " мин.";

            top.main.window.document.getElementById("nextMining").innerHTML = langPack["youCantMineToday"] + " " + inTime;
        }
    }
}

function createPagesString(page, totalPages, needFilter) {
    if (totalPages <= 1) {
        var result = '';
        
        return result;
    } else {
        var result = '<tr><td colspan="4" bgcolor="#d2d2d2">' + langPack["pages"] + ': ';

        for (var i = 0; i < totalPages; i++) {
            var index = i + 1;
            if (i != page) {
                result += "<a href=\"#" + Math.random() + "\" onclick=\"updatePage(" + index + "); return false;\">";
            }

            result += index;

            if (i != page) {
                result += "</a>";
            }

            result += "&nbsp;";
        }

        result += "</td>";

        return result + "</tr>";
    }
}

var filterHTML =
          '<select id="battleFilter" name="battleFilter" onchange="submitShowList(\'Duel\', false); return false;" style="margin-left: 10px; margin-right: 10px; width: 148px;">' +
          '<option value="all">' + langPack["filterAll"] + '</option>' +
          '<option value="my">' + langPack["filterMy"] + '</option>' +
          '<option value="lower">' + langPack["filterMyLower"] + '</option>' +
          '<option value="higher">' + langPack["filterMyUpper"] + '</option>' +
          '</select>';

function createFilterString() {
    return filterHTML;
}

function prepareCell(node, width, innerHTMLText, alignType, additionalAttributes, classNameText) {
    var cell = null;
    if (navigator.appVersion.indexOf("MSIE") != -1 && navigator.appVersion.indexOf("Opera") == -1) {
        cell = node.insertCell();
    } else {
        cell = top.main.window.document.createElement("TD")
    }

    cell.setAttribute("align", alignType);
    cell.style.backgroundColor = "#d2d2d2";
    cell.style.verticalAlign = "middle";

    if (classNameText) {
        cell.className = classNameText;
    }

    for (var additional in additionalAttributes) {
        cell.setAttribute(additional, additionalAttributes[additional]);
    }

    if (width) {
        cell.setAttribute("width", width);
    }
    cell.innerHTML = innerHTMLText;

    if (!(navigator.appVersion.indexOf("MSIE") != -1 && navigator.appVersion.indexOf("Opera") == -1)) {
        node.appendChild(cell);
    }
}

function addMineRequest(creator, members, comment, timeCreatedInMillis, isFree, isInThisRequest, canBeStarted, requestId) {
    var node = null;
    if (navigator.appVersion.indexOf("MSIE") != -1 && navigator.appVersion.indexOf("Opera") == -1) {
        node = battlesTable.insertRow();
    } else {
        node = top.main.window.document.createElement("TR")
    }

    var bigCell = "";

    node.className =  'b_line' + lineIndex;

    prepareCell(node, '50', '<b>' + timeCreatedInMillis + '</b>', 'center');

    var teamString = "";
    for (var i = 0; i < members.length; i++) {
        teamString += members[i] + " ";
    }

    if (comment != "") {
        comment = " (" + comment + ")";
    }

    if (teamString == "") {
        prepareCell(node, null, creator + " " + langPack["mineTogether"] + langPack["mineNobodyYet"] + comment, 'left');
    } else {
        prepareCell(node, null, creator + " " + langPack["mineTogether"] + teamString + comment, 'left');
    }

    var cell = "";

    if (isFree) {
        cell = '<input type="button" class="btn" style="width: 70px;" onclick="submitMineAttach(\'' + requestId + '\'); return false;" value="' + langPack["mineAttach"] + '"/>';
    } else if (isInThisRequest) {
        cell = '<input type="button" class="btn" style="width: 70px;" onclick="submitMineLeave(\'' + requestId + '\'); return false;" value="' + langPack["mineReject"] + '"/>';
    }

    if (canBeStarted) {
        cell += '&nbsp;<input type="button" class="btn" style="width: 70px;" onclick="submitMineStart(\'' + requestId + '\'); return false;" value="' + langPack["mineStart"] + '"/>';
    }

    prepareCell(node, '155', cell, 'center');

    lineIndex = 3 - lineIndex;

    if (!(navigator.appVersion.indexOf("MSIE") != -1 && navigator.appVersion.indexOf("Opera") == -1)) {
        battlesTable.appendChild(node);
    }
}

function addBattle(counter, millisToGo, subType, time, startTime, timeout, comment, teams, battleId, isSelf, isFree, type, actions, hrefId) {
    var node = null;
    if (navigator.appVersion.indexOf("MSIE") != -1 && navigator.appVersion.indexOf("Opera") == -1) {
        node = battlesTable.insertRow();
    } else {
        node = top.main.window.document.createElement("TR")
    }

    var bigCell = "";

    node.className =  'b_line' + lineIndex;

    if (top.main.window.battlesType == "Current") {
        bigCell += '<b>' + time + '</b>';
        bigCell += ' <img src="' + __picsPath + 'design/img/time' + timeout + '.gif" tooltip="' + langPack["timeout"] + ' ' + timeout + ' ' + langPack["mins"] + '" height="17" width="17">';
    } else {
        prepareCell(node, '50', '<b>' + time + '</b>', 'center');
        prepareCell(node, '25', '<img src="' + __picsPath + 'design/img/time' + timeout + '.gif" tooltip="' + langPack["timeout"] + ' ' + timeout + ' ' + langPack["mins"] + '" height="17" width="17">', 'center');
    }

    var result = "";
    if (top.main.window.battlesType == "Current") {
        result += '<a target="_blank" href="/viewLog?' + hrefId + '&lastPage">';
    }
    result += '<img src="' + __picsPath + 'fighttype' + subType + '.gif" height="17" width="17">';
    if (top.main.window.battlesType == "Current") {
        result += '</a>';
    }

    if (top.main.window.battlesType == "Current") {
        bigCell += ' ' + result;
    } else {
        prepareCell(node, '25', result, 'center');
    }

    if (top.main.window.battlesType == "Mess" || top.main.window.battlesType == "Teams") {
        result = "";
        result += " <small>[<span id=\"bCounter" + counter + "\" >" + getCounterString(millisToGo, "bCounter" + counter) + "</span>]</small>";
        if (counterTimeouts["bCounter" + counter]) {
            clearTimeout(counterTimeouts["bCounter" + counter]);
        }

        outputTime(millisToGo, "bCounter" + counter, 0);

        if (top.main.window.battlesType == "Current") {
            bigCell += ' ' + result;
        } else {
            prepareCell(node, '60', result, 'center');
        }
    }

    var cell = "";

    if (actions.indexOf("accepting") != -1) {
        cell += '<nowrap><input type="button" class="btn" style="width: 70px;" onclick="submitRefuse(\'' + battleId + '\'); return false;" value="' + langPack["reject"] + '"/>&nbsp;';
        cell += '<input type="button" class="btn" style="width: 70px;" onclick="submitAccept(\'' + battleId + '\'); return false;" value="' + langPack["accept"] + '"/></nowrap>';
    }

    if (top.main.window.battlesType != "Current") {
        if (isSelf) {
            if (type == "Duel" && actions.indexOf("accepting") == -1) {
                cell += '<input type="button" class="btn" style="width: 70px;" onclick="submitCancel(\'' + battleId + '\'); return false;" value="' + langPack["cancel"] + '"/>';
            }
        } else if (isFree) {
            if (type == "Teams") {
                cell += '<input type="button" class="btn" style="width: 70px;" onclick="submitAttach1(\'' + battleId + '\'); return false;" value="' + langPack["toTeam1"] + '"/>&nbsp;';
                cell += '<input type="button" class="btn" style="width: 70px;" onclick="submitAttach2(\'' + battleId + '\'); return false;" value="' + langPack["toTeam2"] + '"/>';
            } else if (type == "Mess") {
                cell += '<input type="button" class="btn" style="width: 70px;" onclick="submitAttach(\'' + battleId + '\'); return false;" value="' + langPack["accept"] + '"/>';
            } else if (type == "Duel" && (teams.length < 2 || teams[1] == "")) {
                cell += '<input type="button" class="btn" style="width: 70px;" onclick="submitAttach(\'' + battleId + '\'); return false;" value="' + langPack["accept"] + '"/>';
            }
        } else {
            if (type == "Duel" && actions.indexOf("inBattle") != -1) {
                cell += '<input type="button" class="btn" style="width: 70px;" onclick="submitRefuse2(\'' + battleId + '\'); return false;" value="' + langPack["refuse"] + '"/>';
            }
        }

        if (!isFree) {
            top.main.window.document.getElementById("createNew").style.display = "none";
        }
    }

    result = "";
    result += '&nbsp;';

    var limit = teams.length;
    if (type == "Teams") {
        limit -= 2;
    }

    var teamsCount = 0;

    for (var i = 0; i < limit; i++) {
        if (type == "Teams" && i == 0) {
            result += teams[teams.length - 2] + " ";
        }

        if (i != 0) {
            result += " <b> " + langPack["against"] + " </b> ";
            if (type == "Teams") {
                result += teams[teams.length - 1] + " ";
            }
        }
        result += teams[i];

        if (teams[i] == "") {
            result += langPack["noOpponents"];
        } else {
            teamsCount++;
        }
    }

    if (limit < 2 && type != "Mess" && type != "Teams") {
        result += " <b> " + langPack["against"] + " </b> ";
        result += langPack["noOpponents"];
    }

    if (limit < 2 && type == "Teams") {
        result += " <b> " + langPack["against"] + " </b> ";
        if (type == "Teams") {
            result += teams[teams.length - 1] + " ";
        }
        result += langPack["noOpponents"];
    }

    if (comment != "" && comment != "-" && comment != "&mdash;") {
        if (actions.indexOf("removeComment") != -1) {
            result += '<img src="' + __picsPath + 'drop.gif" tooltip="&lt;small&gt;' + langPack["removeComment"] + '.&lt;/small&gt;" alt="" style="cursor: pointer;" onclick="removeComment(\'' + battleId + '\')">';
        }
        result += " " + langPack["comment"] + ": " + comment;
    }

    var additional = new Array();
    additional["onContextMenu"] = "return OpenMenu(event)";
    additional["onClick"] = "return AddLogin(event)";

    if (top.main.window.battlesType == "Current") {
        bigCell += ' ' + result;
        bigCell += ' ' + cell;
    } else {
        if (!((cell != '' || top.main.window.battlesType == "Duel") && top.main.window.battlesType != "Current")) {
            additional["colspan"] = "2";
            prepareCell(node, null, result, 'left', additional);
        } else {
            prepareCell(node, null, result, 'left', additional);
            prepareCell(node, '150', cell, 'center');
        }
    }

    if (top.main.window.battlesType == "Current") {
        prepareCell(node, '100%', bigCell, 'left');
    }

    lineIndex = 3 - lineIndex;

    if (!(navigator.appVersion.indexOf("MSIE") != -1 && navigator.appVersion.indexOf("Opera") == -1)) {
        battlesTable.appendChild(node);
    }
}

function outputTime(millisToGo, counterDivName, fullTime) {
    if (blockTimers) {
        return;
    }

    var timeToNext = 500;
    var nextTime = millisToGo - timeToNext;

    if (layoutType == 'list' && !listBattlesDone) {
        counterTimeouts[counterDivName] = setTimeout("outputTime(" + nextTime + ", '" + counterDivName + "', " + fullTime + ")", timeToNext);
        return;
    }

    var counterDiv = top.main.window.document.getElementById(counterDivName);

    try {
        if (counterDiv == null) {
            var spans = top.main.window.document.getElementsByTagName("span");
            for (var i = 0; i < spans.length; i++) {
                if (spans[i].id == counterDivName) {
                    counterDiv = spans[i];
                    break;
                }
            }
        }
    } catch(ex) {
    }

    if (!counterDiv) {
        return;
    }

    var counterTimeout = setTimeout("outputTime(" + nextTime + ", '" + counterDivName + "', " + fullTime + ")", timeToNext);
    counterTimeouts[counterDivName] = counterTimeout;

    var timeline = "";

    if (counterDivName == 'timeoutDiv' && fullTime > 10) {
        var percent = new Number(millisToGo)/new Number(fullTime);
        var width1 = 200 - 200*percent;
        var width2 = 200*percent;

        if (width1 + width2 > 200) {
            if (width1 > width2) {
                width1 = 200;
                width2 = 0;
            } else if (width2 > width1) {
                width1 = 0;
                width2 = 200;
            } else {
                width1 = 200;
                width2 = 0;
            }
        }

        timeline = '<table border="0" cellpadding="0" cellspacing="0"><tr><td>' +
                        '<img src="' + __picsPath + 'go/move.gif" width="' + width1 + '" height="10" alt=""/></td><td>' +
                        '<img src="' + __picsPath + 'go/bg.gif" width="' + width2 + '" height="10" alt=""/></td></tr></table>';
    }

    if (millisToGo < 1000) {
        if (timeline != "") {
            counterDiv.innerHTML = timeline;
        } else {
            counterDiv.innerHTML = "00:00";
        }

        clearTimeout(counterTimeout);
    } else {
        if (timeline != "") {
            counterDiv.innerHTML = timeline;
        } else {
            counterDiv.innerHTML = getCounterString(millisToGo, counterDivName);
        }
    }
}

function getCounterString(millisToGo, counterDivName) {
    var seconds = Math.floor(millisToGo/1000);
    var minutes = Math.floor(seconds/60);
    var hours = Math.floor(minutes/60);

    minutes = minutes - hours*60;
    seconds = seconds - minutes*60;

    var timeToOut = (hours == 0 ? "" : (hours < 10 ? "0" + hours : hours) + ":") +
                    (minutes < 10 ? "0" + minutes : minutes) + ":" +
                    (seconds < 10 ? "0" + seconds : seconds);

    if (timeToOut != "NaN:NaN:NaN") {
        if (counterDivName == 'timeoutDiv' && layoutType == 'log') {
            return '[' + timeToOut + ']';
        } else {
            return timeToOut;
        }
    } else {
        return "";
    }
}

function getType(type) {
    if (type == "Duel") {
        return langPack["typeDuel"];
    } else if (type == "Teams") {
        return langPack["typeTeams"];
    } else if (type == "Mess") {
        return langPack["typeMess"];
    } else {
        return type
    }
}

function setListFailure(error) {
    top.main.window.document.getElementById("battlesData").innerHTML = '<div style="text-align: center;">' + error + "</div>";
}

function clearBattles(type, filter, notNeedClearStrings) {
    if (!notNeedClearStrings) {
        top.main.window.battlesType = type;

        battlesString = "";
        battlesTable = top.main.window.document.createElement("table");
        battlesTable.className = "b_table";
        battlesTable.setAttribute("align", "center");
        battlesTable.setAttribute("bgcolor", "#dcdcdc");
        battlesTable.setAttribute("cellpadding", "0");
        battlesTable.setAttribute("cellspacing", "2");
        battlesTable.setAttribute("border", "0");
        battlesTable.setAttribute("width", "100%");

        lineIndex = 1;

        if (!filter || filter == "") {
            filter = "my";
        }

        top.main.window.battlesFilter = filter;
    }

    top.main.window.parameters = new Array();
    
    top.main.window.document.getElementById("battlesData").innerHTML = "";

    top.main.window.document.getElementById("createNewDiv").innerHTML = getCreateNewForm(top.main.window.battlesType);

    if (top.main.window.document.getElementById("cellDuel")) {
        top.main.window.document.getElementById("cellDuel").className = "bgF";
        top.main.window.document.getElementById("cellTeams").className = "bgF";
        top.main.window.document.getElementById("cellMess").className = "bgF";
        top.main.window.document.getElementById("cellCurrent").className = "bgF";
        top.main.window.document.getElementById("cellSearch").className = "bgF";

        top.main.window.document.getElementById("cellADuel").className = "f";
        top.main.window.document.getElementById("cellATeams").className = "f";
        top.main.window.document.getElementById("cellAMess").className = "f";
        top.main.window.document.getElementById("cellACurrent").className = "f";
        top.main.window.document.getElementById("cellASearch").className = "f";

        top.main.window.document.getElementById("cell" + type).className = "bgF2";
        top.main.window.document.getElementById("cellA" + type).className = "f2";
    }

    if (top.main.window.document.getElementById("createNew")) {
        top.main.window.document.getElementById("createNew").style.display = "block";
        top.main.dataRestored = false;
    }
}

function removeHeaderForFinish() {
    blockTimers = true;

    top.main.window.document.getElementById("timeoutNameDiv").innerHTML = "";
    top.main.window.document.getElementById("timeoutNameDiv").style.height = "0px";
    top.main.window.document.getElementById("timeoutNameDiv").style.display = "none";

    top.main.window.document.getElementById("timeoutDiv").innerHTML = "";
    top.main.window.document.getElementById("timeoutDiv").style.height = "0px";
    top.main.window.document.getElementById("timeoutDiv").style.display = "none";

    top.main.window.document.getElementById("teamsDiv").innerHTML = "";
    top.main.window.document.getElementById("teamsDiv").style.height = "0px";
    top.main.window.document.getElementById("teamsDiv").style.display = "none";
}

function removeHeaderForUserFinish() {
    blockTimers = true;

    top.main.window.document.getElementById("timeoutNameDiv").innerHTML = "";
    top.main.window.document.getElementById("timeoutNameDiv").style.height = "0px";
    top.main.window.document.getElementById("timeoutNameDiv").style.display = "none";

    top.main.window.document.getElementById("timeoutDiv").innerHTML = "";
    top.main.window.document.getElementById("timeoutDiv").style.height = "0px";
    top.main.window.document.getElementById("timeoutDiv").style.display = "none";
}

var layoutsHTML = new Array();

function getListLayout() {
    if (layoutsHTML["list"]) {
        return layoutsHTML["list"];
    }

    var result = '<div id="typeSelector">' +
            '<table border="0" width="100%" align="center">' +
                '<tr><td colspan="6"><div id="userDiv"></div></td></tr>' +
                '<tr class="bgF">' +
                    '<td width="14%" align="center" class="bgF" id="cellDuel"><a href="#" onclick="updateList(\'Duel\'); return false;" class="f" id="cellADuel">' + langPack["typeDuel"] + '</a></td>' +
                    '<td width="14%" align="center" class="bgF"><a href="#" onclick="return false;" class="f" id="cellADuel">' + langPack["typeDogovor"] + '</a></td>' +
                    '<td width="14%" align="center" class="bgF" id="cellTeams"><a href="#" onclick="updateList(\'Teams\'); return false;" class="f" id="cellATeams">' + langPack["typeTeams"] + '</a></td>' +
                    '<td width="14%" align="center" class="bgF" id="cellMess"><a href="#" onclick="updateList(\'Mess\'); return false;" class="f" id="cellAMess">' + langPack["typeMess"] + '</a></td>' +
                    '<td width="14%" align="center" class="bgF" id="cellCurrent"><a href="#" onclick="updateList(\'Current\'); return false;" class="f" id="cellACurrent">' + langPack["typeCurrent"] + '</a></td>' +
                    '<td width="14%" align="center" class="bgF" id="cellSearch"><a href="#" onclick="updateList(\'Search\'); return false;" class="f" id="cellASearch">' + langPack["typeSearch"] + '</a></td>' +
                '</tr>' +
            '</table>' +
            '</div>' +

            '<div id="createNewDiv" style="display: none;"></div>' +
            '<div id="battlesData"></div><br/><br/>';

    layoutsHTML["list"] = result;

    return result;
}

function getMineListLayout() {
    if (layoutsHTML["mineList"]) {
        return layoutsHTML["mineList"];
    }

    var result =
            '<table border="0" width="100%" align="center">' +
                '<tr><td colspan="6"><div id="userDiv"></div></td></tr>' +
            '</table>' +

            '<div id="createNewDiv" style="display: none;"></div>' +
            '<div id="battlesData"></div><div id="nextMining" style="text-align: center;"></div><br/><br/>';

    layoutsHTML["mineList"] = result;

    return result;
}

function getMineElevatorLayout() {
    return  '<table cellspacing="2" cellpadding="2" border="0" height="100%" width="100%">' +
              '<tr>' +
                '<td align="center"><h3 style="color: #8f0000; font-family: Arial; font-size: 12pt; font-weight: bold; text-align: center; margin-bottom: 0px; margin-top: 0px; padding-top: 0px; padding-bottom: 0px;">' +
                    langPack["liftDriving"] + '</h3></td>' +
              '</tr>' +
              '<tr>' +
                '<td align="center" valign="top">' +
                  '<table width="394" height="248" border="0" cellpadding="0" cellspacing="0">' +
                    '<tr>' +
                      '<td height="14" colspan="3"><img src="' + __picsPath + 'mines/top_el.jpg" width="394" height="14"></td>' +
                    '</tr>' +
                    '<tr>' +
                      '<td height="220"><img src="' + __picsPath + 'mines/left_el.jpg" width="46" height="220"></td>' +
                      '<td height="220">' +

                        '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ' +
                                'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" ' +
                                'width="300" height="220" id="lift" align="middle">' +
                        '<param name="allowScriptAccess" value="always" />' +
                        '<param name="movie" value="' + __picsPath + 'mines/lift.swf?' + elevatorParameters + '"/>' +
                        '<param name="menu" value="false" />' +
                        '<param name="quality" value="high" />' +
                        '<param name="bgcolor" value="#090b06" />' +
                        '<embed src="' + __picsPath + 'mines/lift.swf?' + elevatorParameters + '" menu="false" quality="high" swLiveConnect="true" ' +
                                'bgcolor="#090b06" width="300" height="220" name="lift" ' +
                                'align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" ' +
                                'pluginspage="http://www.macromedia.com/go/getflashplayer" />' +
                        '</object>' +

                    '</td>' +
                    '<td height="220"><img src="' + __picsPath + 'mines/right_el.jpg" width="48" height="220"></td>' +
                  '</tr>' +
                  '<tr>' +
                    '<td height="14" colspan="3"><img src="' + __picsPath + 'mines/under_el.jpg" width="394" height="14"></td>' +
                  '</tr>' +
                '</table>' +
              '</td>' +
            '</tr>' +
          '</table>';
}

function setKicksCount(kicks, totalKicks) {
    mineKicksCount = kicks;
    mineKicksTotal = totalKicks;

    var kicksDone = (mineKicksCount/mineKicksTotal)*100;
    var kicksEmpty = 100 - kicksDone;

    top.main.window.document.getElementById("kickLength").innerHTML =
        '<table cellspacing="0" cellpadding="0" border="0" align="right"><tr>' +
        '<td><img src="' + __picsPath + '/go/move.gif" width="' + kicksDone + '" height="5" title="header=[] body=[' + langPack["mineOptionProgress"] + ']"/></td>' +
        '<td><img src="' + __picsPath + '/go/bg.gif" width="' + kicksEmpty + '" height="5" title="header=[] body=[' + langPack["mineOptionProgress"] + ']"/></td></tr></table>';
}

function getMineRoomLayout() {
    if (layoutsHTML["mineRoom"]) {
        return layoutsHTML["mineRoom"];
    }

    var kicksDone = 0;
    var kicksEmpty = 100;

    var result =
            '<style>\n' +
            'td {\n' +
                    'font-size: 10pt;\n' +
                    'font-family: Verdana, Arial, Helvetica, Tahoma, sans-serif;\n' +
            '}\n' +
            '</style>' +
            '<table border="0" cellspacing="2" cellpadding="0" width="97%" align="center">' +
            '<tr><td valign="top" style="padding: 20px; padding-top: 0px;">' +
                '<h3 id="roomName" style="color: #8f0000;  font-family: Arial; font-size: 12pt; font-weight: bold; text-align: center; margin-bottom: 4px; margin-top: 0px; padding-top: 0px;"></h3>' +

                '<table cellspacing="2" cellpadding="3" border="0" align="center" width="90%"><tr><td bgcolor="#D2D2D2" height="20">' +
                '<span id="roomDescription"></span></td></tr></table>' +

                '<hr>' +

                '<center><div id="userDiv" style="margin-right: 50px;"></div>' +
                    '<input type="button" value="' + langPack["mineAttack"] + '" class="btn" style="width:90px;" onclick="submitMineAttack()"> ' +
                    '<input type="button" value="' + langPack["mineView"] + '" class="btn" style="width:90px;" onclick="submitMineView()"> ' +
                    '<input type="button" value="' + langPack["mineHelp"] + '" class="btn" alt="' + langPack["help"] + '" title="' + langPack["help"] + '" style="width:90px;" onclick="submitMineHelp()"> ' +
                    '<input type="button" value="' + langPack["mineExit"] + '" onclick="submitMineLiftForceExit()" class="btn" style="width:90px;">' +
//                    '<input type="button" value="' + langPack["mineExit"] + '" onclick="submitMineForceExit()" class="btn" style="width:90px;">' +
                '</center>' +

                '<hr>' +

                '<table cellspacing="0" cellpadding="0" border="0" width="200" align="center">' +
                    '<tr><td colspan="3">' +
                        '<table cellSpacing="0" cellPadding="0" border="0" width="100%" align="center">' +
                            '<tr>' +
                                '<td width="44" height="37"><img src="' + __picsPath + 'design/img/mv1.gif" width="44" height="37" border="0"></td>' +
                                '<td width="35" height="37"><img src="' + __picsPath + 'design/img/mv2.gif" width="35" height="37" border="0"></td>' +
                                '<td width="42" height="37"><a href="#" onclick="return false;"><img src="' + __picsPath + 'design/img/mvb1.gif" width="42" height="37" border="0"></a></td>' +
                                '<td width="35" height="37"><img src="' + __picsPath + 'design/img/mv3.gif" width="35" height="37" border="0"></td>' +
                                '<td width="44" height="37"><img src="' + __picsPath + 'design/img/mv4.gif" width="44" height="37" border="0"></td>' +
                            '</tr>' +

                            '<tr>' +
                                '<td width="44" height="41"><img src="' + __picsPath + 'design/img/mv5.gif" width="44" height="41" border="0"></td>' +
                                '<td width="35" height="41"><a href="#" onclick="return false;"><img src="' + __picsPath + 'design/img/mvb2.gif" width="35" height="41" border="0"></a></td>' +
                                '<td width="42" height="41"><a href="#" onclick="return false;"><img src="' + __picsPath + 'design/img/mvb3.gif" width="42" height="41" border="0"></a></td>' +
                                '<td width="35" height="41"><a href="#" onclick="return false;"><img src="' + __picsPath + 'design/img/mvb4.gif" width="35" height="41" border="0"></a></td>' +
                                '<td width="44" height="41"><img src="' + __picsPath + 'design/img/mv6.gif" width="44" height="41" border="0"></td>' +
                            '</tr>' +
                        '</table>' +
                    '</td></tr>' +

                    '<tr><td rowspan="3" width="24" height="38"><img src="' + __picsPath + 'design/img/mv7.gif" width="24" height="38" border="0"></td>' +
                        '<td width="150" height="11"><img src="' + __picsPath + 'design/img/mv8.gif" width="150" height="11" border="0"></td>' +
                        '<td rowspan="3" width="26" height="38"><img src="' + __picsPath + 'design/img/mv9.gif" width="26" height="38" border="0"></td>' +
                    '</tr>' +
                    '<tr><td>' +
                        '<table cellSpacing="0" cellPadding="0" border="0" height="10" width="150" align="center">' +
                            '<tr>' +
                                '<td><img src="' + __picsPath + 'design/img/mp1.gif" width="1" height="10" border="0"></td>' +
                                '<td id="staminaTD" width="1" background="' + __picsPath + 'design/img/mpbg.gif"></td>' +
                                '<td width="1"><img src="' + __picsPath + 'design/img/mpr.gif" width="1" height="10" border="0"></td>' +
                                '<td id="staminaBGTD" width="149" background="' + __picsPath + 'design/img/hpbg2.gif"></td>' +
                                '<td><img src="' + __picsPath + 'design/img/hp2.gif" width="1" height="10" border="0"></td>' +
                            '</tr>' +
                        '</table>' +
                    '</td></tr>' +
                    '<tr><td width="150" height="17"><img src="' + __picsPath + 'design/img/mv10.gif" width="150" height="17"></TD></TR>' +
                '</table>' +

                '<span id="mineItems"></span>' +
            '</td><td align="left" valign="top" width="500"><div style="position: relative;">' +

            '<div style="position: absolute; top: 1px; left: 1px; z-index: 100; width: 250px; height: 40px; text-align: left;"><div id="delayTimer">' +
            '<table cellspacing="0" cellpadding="0" border="0"><tr>' +
            '<td><img src="' + __picsPath + '/go/move.gif" width="0" height="5" alt=""/></td>' +
            '<td><img src="' + __picsPath + '/go/bg.gif" width="100" height="5" alt=""/></td></tr></table></div>' +
            '<div id="delayTimerTitle" style="font-size: 9px; color: white; align: left; position: absolute; top: 7px; left: 1px;"></div></div>' +

            '<div style="position: absolute; top: 1px; left: 250px; z-index: 100; width: 250px; height: 40px; text-align: right;"><div id="kickLength">' +
            '<table cellspacing="0" cellpadding="0" border="0" align="right"><tr>' +
            '<td><img src="' + __picsPath + '/go/move.gif" width="' + kicksDone + '" height="5" alt=""/></td>' +
            '<td><img src="' + __picsPath + '/go/bg.gif" width="' + kicksEmpty + '" height="5" alt=""/></td></tr></table></div>' +
            '</div>' +

            '<div id="roomImage" style="position: absolute; top: 0px; left: 0px;"></div>' +
            
            '</div>' +
            '</td></tr>' +
            '</table>';

    layoutsHTML["mineRoom"] = result;

    return result;
}

function getSearchLayout() {
    if (layoutsHTML["search"]) {
        return layoutsHTML["search"];
    }

    var result = getListLayout();
    result = result.substr(0, result.length - 6);

    var date = new Date();

    result +=
            '<div id="searchTitle"></div>' +
            '<table border="0" cellpadding="2" cellspacing="0" align="center" width="99%"><tr><td colspan="3" align="center">' +
            '<table border="0" bgcolor="#DCDCDC"><tr><td width="300">' +
                '<nobr>' + langPack["battlesOf"] + ': <input name="filter" id="searchName" value="" type="text">  ' + langPack["for"] + ': ' +
                '<input name="date" id="searchDate" value="' + getNumberWithZero(date.getDate()) + '.' + getNumberWithZero(date.getMonth() + 1) + '.' + date.getFullYear() +
                        '" size="15" type="text"></nobr></td>' +
                '<td width="20"><input src="' + __picsPath + 'b_applay.gif" name="sub" type="image" onclick="getSearchResults(); return false;"></td></tr></table></td></tr>' +

            '<tr><td colspan="3"><table class="b_table" width="100%" bgcolor="#DCDCDC"><tbody id="searchResults"></tbody></table></td></tr>' +

            '<tr><td colspan="3" align="center">' +
            '<input type="button" class="btn" onclick="setPrevDate(); getSearchResults(); return false;" value="&laquo; ' + langPack["dayPrev"] + '"/>  ' +
            '<input type="button" class="btn" onclick="setNextDate(); getSearchResults(); return false;" value="' + langPack["dayNext"] + ' &raquo;"/></td></tr>' +

            '</table>' +

            '</div>';

    layoutsHTML["search"] = result;

    return result;
}

function getNumberWithZero(number) {
    if (number < 10) {
        return "0" + number;
    } else {
        return number;
    }
}

function getActionLayout() {
    if (layoutsHTML["action"]) {
        return layoutsHTML["action"];
    }

    var result = '<table cellSpacing="0" cellPadding="0" border="0" width="100%" align="center">' +
                 '<tr>' +
                 '<td valign="top" rowspan="2" width="200" style="width: 200px;"><div id="userDiv" style="margin: 0px; padding: 0px;" onContextMenu="return OpenMenu(event);" onClick="return AddLogin(event);"></div></td>' +
                 '<td valign="top" style="height: 100px;"><div style="text-align: center"><span id="timeouts"></span></div><div id="actionsDiv"></div></td>' +
                 '<td valign="top" rowspan="2" width="200" style="width: 200px;" align="center"><div id="opponentDiv" style="margin: 0px; padding: 0px;" onContextMenu="return OpenMenu(event);" onClick="return AddLogin(event);"></div></td>' +
                 '</tr>' +
                 '<tr>' +
                 '<td valign="top" style="height: 300px; margin: 0px; padding: 0px;"><div id="teamsDiv" onContextMenu="return OpenMenu(event);" onClick="return AddLogin(event);"></div><div id="logTitleDiv" style="display: none;"></div><div id="logDiv"></div><div id="totalsDiv"></div></td>' +
                 '</tr>' +
                 '</table>';

    layoutsHTML["action"] = result;

    return  result;
}

function getLogLayout() {
    var randomImage = 1 + Math.ceil(Math.random()*19);

    if (layoutsHTML["log" + randomImage]) {
        return layoutsHTML["log" + randomImage];
    }

    var result = '<table cellSpacing="0" cellPadding="0" border="0" width="100%" height="100%" align="center">' +
                 '<tr height="30">' +
                     '<td valign="top" width="200" style="width: 200px;"><div id="userDiv"></div></td>' +
                     '<td valign="top" align="center" style="margin: 0px; padding: 0px; padding-top: 13px;"><div id="teamsDiv" onContextMenu="return OpenMenu(event);" onClick="return AddLogin(event);"></div><div id="logTitleDiv" style="display:none;"></div><div id="logDiv"></div><div id="totalsDiv"></div></td>' +
                     '<td valign="top" width="240" height="30" style="width: 240px; padding: 0px; height: 30px;" align="center">' +
                            '<table width="240" cellspacing="0" cellpadding="0" border="0">' +
                            '<tr><td>' +
                                 '<div style="padding: 0px; margin: 0px; margin-left: 20px; margin-right: 20px; width: 200px; text-align: center; font-size: 11px; height: 30px;">' +
                                         '<div id="timeoutNameDiv" style="text-align: center; height: 15px;"></div>' +
                                         '<div id="timeoutDiv" style="text-align: center; margin-top: 2px; height: 15px;"><div>' +
                                 '</div>' +
                            '</td></tr>' +
                            '<tr><td>' +
                                 '<img style="margin-left: 20px; padding-right: 20px;" src="' + __picsPath + 'fight/' + randomImage + '.jpg" width="200" height="230" />' +
                            '</td></tr>' +
                            '</table>' +
                     '</td></tr>' +
                 '</table>';

    layoutsHTML["log" + randomImage] = result;

    return  result;
}

var newFormsHTML = new Array();

function getCreateNewForm(type) {
    if (newFormsHTML[type]) {
        return newFormsHTML[type];
    }

    var result =
            '<form action="#" id="createNewForm" method="post" onsubmit="return submitCreateNew();" target="formTarget" name="newBattleForm">' +
            '<span id="battleCreateData">' +
            '<table cellSpacing="2" cellPadding="0" border="0" align="center" width="100%">' +
            '<tr bgcolor="#D2D2D2">' +
            '<td bgcolor="#D2D2D2"><div class="battleCreate" id="createNew">';

    if (type == "Duel") {
        result +=
                '<input type="hidden" name="type" value="Duel"/>' +
                '<table cellspacing="0" cellpadding="2" border="0" width=""><tr>' +
                '<td>' +
                    ' ' + langPack["timeStep"] + ': <select name="timeout"><option value="3">3 ' + langPack["mins"] + '</option><option value="5">5 ' + langPack["mins"] + '</option><option value="7">7 ' + langPack["mins"] + '</option><option value="10">10 ' + langPack["mins"] + '.</option></select>' +
                    ' ' + langPack["typeBattle"] + ': <select size="1" name="subType"><option value="Normal">' + langPack["weapon"] + '</option><option value="NoWeapon">' + langPack["noWeapon"] + '</option><option value="Bloody">' + langPack["bloody"] + '</option></select>' +
                    ' ' + langPack["comment"] + ': <input name="comment" maxlength="25" type="text" style="width: 120px;" value="">' +
                    '</td>' +
                '<td width="150"> <input class="btn" type="submit" value="' + langPack["createBattle"] + '" name="newsingle" onclick="return submitCreateNew();"/></td></tr>' +
                '</table>';
    } else if (type == "Mess") {
        result +=
                '<input type="hidden" name="type" value="Mess"/>' +
                '<table cellspacing="0" cellpadding="2" border="0"><tr>' +
                '<td bgcolor="#D2D2D2">' +
                    ' ' + langPack["timeStep"] + ': <select name="timeout"><option value="3">3 ' + langPack["mins"] + '</option><option value="5">5 ' + langPack["mins"] + '</option><option value="7">7 ' + langPack["mins"] + '</option><option value="10">10 ' + langPack["mins"] + '</option></select>' +
                    ' ' + langPack["timeBefore"] + ': <select name="delay"><option value="10">10 ' + langPack["mins"] + '</option><option value="30">30 ' + langPack["mins"] + '</option><option value="45">45 ' + langPack["mins"] + '</option><option value="60">60 ' + langPack["mins"] + '</option></select></select>' +
                    ' ' + langPack["typeBattle"] + ': <select size="1" name="subType"><option value="Normal">' + langPack["weapon"] + '</option><option value="NoWeapon">' + langPack["noWeapon"] + '</option><option value="Bloody">' + langPack["bloody"] + '</option></select>' +
                    ' ' + langPack["comment"] + ': <input name="comment" maxlength="25" type="text" style="width: 120px;" value="">' +
                    '</td>' +
                    '</td>' +
                '<td width="150" bgcolor="#D2D2D2"> <input class="btn" type="submit" value="' + langPack["createBattle"] + '" name="newsingle" onclick="return submitCreateNew();"/></td></tr>' +
                '</table>';
    } else if (type == "Teams") {
        result +=
                '<input type="hidden" name="type" value="Teams"/>' +
                '<table cellSpacing="0" cellPadding="2" border="0">' +
                    '<tr bgcolor="#D2D2D2">' +
                        '<td>' + langPack["forMe"] + ':</td>' +
                        '<td><input type="text" name="for" id="for" size="5"></td>' +
                        '<td><select name="forType"><option value="any">' + langPack["levelAny"] + '</option><option value="myLevel">' + langPack["levelMy"] + '</option><option value="myLower">' + langPack["levelLower"] + '</option><option value="myUpper">' + langPack["levelUpper"] + '</option><option value="myClan">' + langPack["levelMyClan"] + '</option><option value="myLevelOne">' + langPack["level+-1"] + '</option></select></td>' +
                        '<td>' + langPack["timeStep"] + ':</td>' +
                        '<td><select name="timeout"><option value="3">3 ' + langPack["mins"] + '</option><option value="5">5 ' + langPack["mins"] + '</option><option value="10">10 ' + langPack["mins"] + '</option></select></td>' +
                        '<td>' + langPack["typeBattle"] + ':</td>' +
                        '<td><select size="1" name="subType"><option value="Normal">' + langPack["weapon"] + '</option><option value="NoWeapon">' + langPack["noWeapon"] + '</option><option value="Bloody">' + langPack["bloody"] + '</option></select></td>' +
                        '<td width="150" bgcolor="#D2D2D2">&nbsp;</td>' +
                    '</tr>' +
                    '<tr bgcolor="#D2D2D2">' +
                        '<td>' + langPack["againstMe"] + ':</td>' +
                        '<td><input type="text" name="against" size="5"></td>' +
                        '<td><select name="againstType"><option value="any">' + langPack["levelAny"] + '</option><option value="myLevel">' + langPack["levelMy"] + '</option><option value="myLower">' + langPack["levelLower"] + '</option><option value="myUpper">' + langPack["levelUpper"] + '</option><option value="clan">' + langPack["levelClan"] + '</option><option value="myLevelOne">' + langPack["level+-1"] + '</option></select></td>' +
                        '<td>' + langPack["timeBefore"] + ':</td>' +
                        '<td><select name="delay"><option value="3">3 ' + langPack["mins"] + '</option><option value="5">5 ' + langPack["mins"] + '</option><option value="10">10 ' + langPack["mins"] + '</option><option value="15">15 ' + langPack["mins"] + '</option><option value="30">30 ' + langPack["mins"] + '</option><option value="60">60 ' + langPack["mins"] + '</option></select></select></td>' +
                        '<td>' + langPack["comment"] + ':</td>' +
                        '<td><input type="text" name="comment" size="18" style="width: 120px;"></td>' +
                        '<td width="150"><input type="submit" class="btn" value="' + langPack["createBattle"] + '" onclick="return submitCreateNew();"></td>' +
                    '</tr>' +
                '</table>';
    } else {
        result +=
                '<input type="hidden" name="type" value="Mine"/>' +
                '<table cellspacing="0" cellpadding="2" border="0" width=""><tr>' +
                '<td>' +
                    ' ' + langPack["comment"] + ': <input name="comment" maxlength="25" type="text" style="width: 120px;" value="">' +
                    ' ' + langPack["password"] + ': <input name="password" maxlength="25" type="text" style="width: 120px;" value="">' +
                    '</td>' +
                '<td width="150"> <input class="btn" type="submit" value="' + langPack["createBattle"] + '" name="newsingle" onclick="return submitCreateNew();"/></td></tr>' +
                '</table>';
    }

    result += '</div></td>';

    result += '</tr></table></form>';

    newFormsHTML[type] = result;

    return result;
}

function addCloseTimeout(name, timeoutTime) {
    closeTimeouts[closeTimeouts.length] = name + "|" + timeoutTime;
    updateTimeouts();
}

function removeTimeouts() {
    closeTimeouts = new Array();
    updateTimeouts();
}

function updateTimeouts() {
    if (top.main.window.document.getElementById("timeouts")) {
        for (var i = 0; i < closeTimeouts.length; i++) {
            var timeout = closeTimeouts[i];
            var name = timeout.substring(0, timeout.lastIndexOf("|"));

            var tags = top.main.window.document.getElementById("teamsDiv").getElementsByTagName("SPAN");
            for (var j = 0; j < tags.length; j++) {
                if (tags[j].innerHTML == name) {
                    tags[j].style.color = "red";
                }
            }
        }
    }
}
