var is_opera = (navigator.userAgent.indexOf("Opera") > -1) ? true : false;
var is_ie = (navigator.userAgent.indexOf("MSIE") > -1) ? true : false;
var is_moz = ((navigator.product == "Gecko") && (!is_opera));
var tableStyle = is_ie &!is_opera ? "block" : "table";
var tableItemStyle = is_ie &!is_opera ? "block" : "table-cell";
var tableRowStyle = is_ie &!is_opera ? "block" : "table-row";
var images = new Array();
var texts = new Array();
texts.money_1 = "<img src='images/ico_gold1.png' alt='' align='absmiddle'>";
texts.money_2 = "<img src='images/ico_krist1.png' alt='' align='absmiddle'>";
texts.money_3 = "<img src='images/ico_green1.png' alt='' align='absmiddle'>";
var start_time = new Date();
function update_time(d, c)
{
    new_time = new Date();
    s = d - Math.round((new_time.getTime() - start_time.getTime()) / 1000);
    m = 0;
    h = 0;
    elem = $("time_script" + c + "");
    if (s < 0) {
        elem.innerHTML = $("nap" + c + "").innerHTML;
        elem.style.display = "inline";
    }
    else
    {
        if (s > 59) {
            m = Math.floor(s / 60);
            s = s - m * 60;
        }
        if (m > 59) {
            h = Math.floor(m / 60);
            m = m - h * 60;
        }
        if (s < 10) {
            s = "0" + s;
        }
        if (m < 10) {
            m = "0" + m;
        }
        elem.innerHTML = " " + h + ":" + m + ":" + s + " ";
        setTimeout("update_time(" + d + ", " + c + ");", 999);
    }
};
function doImage(o, g, k)
{
    var j = "images/buttons/" + g + "_a.png";
    var l = "images/buttons/" + g + "_p.png";
    if (k == "active") {
        var l = "images/buttons/" + g + "_a.png";
        var k = null;
    }
    if (k == undefined) {
        var k = null;
    }
    if (k == "skip") {
        var k = null;
    }
    var n = "img_" + images.length;
    images[n] = new Array(j, l, k);
    o.id = n;
    o.onmouseuover = function ()
    {
        changeImage(this, 0);
    };
    o.onmouseout = function ()
    {
        changeImage(this, 1);
    };
    o.onmousedown = function ()
    {
        changeImage(this, 2);
    };
    changeImage(o, 0);
};
function doWeapons(e)
{
    var f = $("weapons");
    var g = $("potions");
    if (f == undefined || g == undefined) {
        return;
    }
    var j = g.style.display == "none" ? "potions" : "weapons";
    if (e != undefined) {
        j = e;
    }
    if (j == "potions")
    {
        g.style.display = "block";
        f.style.display = "none";
        weapons_img.src = "images/but_pois_a.png";
    }
    else
    {
        g.style.display = "none";
        f.style.display = "block";
        weapons_img.src = "images/but_pois_p.png";
    }
};
function changeImage(d, e)
{
    var f = d.id;
    if (images[f] == undefined || images[f][e] == undefined || images[f][e] == null) {
        return;
    }
    d.src = images[f][e];
};
var mTitle = document.title;
var start_time = new Date();
var countTimeout = null;
function countTime(k, r, l)
{
    var n = $(k);
    var q = new Date();
    var o = r - Math.round((q.getTime() - start_time.getTime()) / 1000);
    if (o < 0)
    {
        n.innerHTML = "00:00:00";
        if (l.length > 0)
        {
            i = "?set=" + l + "&r2=" + Math.floor(Math.random() * 1000);
            setTimeout("document.location='" + i + "'", 1000);
        }
        return;
    }
    var j = min = 0;
    if (o > 59) {
        min = Math.floor(o / 60);
        o = o % 60;
    }
    if (min > 59) {
        j = Math.floor(min / 60);
        min = min % 60;
    }
    if (o < 10) {
        o = "0" + o;
    }
    if (min < 10) {
        min = "0" + min;
    }
    var p = j + ":" + min + ":" + o;
    n.innerHTML = " " + p + " ";
    document.title = " [" + p + "]    " + mTitle;
    countTimeout = window.setTimeout("countTime('" + k + "'," + r + ",'" + l + "');", 1000);
};
var countTimeouts = null;
function doTimers(q, j)
{
    for (var l = 0; ; l++)
    {
        var n = $(q + l);
        if (!n) {
            break;
        }
        if (timers[l] == undefined) {
            continue;
        }
        left_time = timers[l];
        var r = new Date();
        var o = left_time - Math.round((r.getTime() - start_time.getTime()) / 1000);
        if (o <= 0) {
            n.innerHTML = "---";
            if (j != '') {
                window[j](l);
            }
            timers[l] = undefined;
            continue;
        }
        var k = min = 0;
        if (o > 59) {
            min = Math.floor(o / 60);
            o = o % 60;
        }
        if (min > 59) {
            k = Math.floor(min / 60);
            min = min % 60;
        }
        if (o < 10) {
            o = "0" + o;
        }
        if (min < 10) {
            min = "0" + min;
        }
        var p = k + ":" + min + ":" + o;
        n.innerHTML = " " + p + " ";
    }
    countTimeouts = window.setTimeout("doTimers('" + q + "','" + j + "');", 1000);
};
function trade_timer(f)
{
    var e = $("bid_" + f);
    var d = $("buy_" + f);
    if (e) {
        e.innerHTML = "---";
    }
    if (d) {
        d.innerHTML = "---";
    }
    return "OK+" + f;
};
var tooltip_id = null;
function doInfo(l, j, k, o, n)
{
    if (popups == undefined) {
        return;
    }
    var e = popups[l];
    if (e == undefined) {
        return;
    }
    if (j != undefined && j != "") {
        e = e + "\n" + j;
    }
    e = e.replace(/\[GOLD\]/g, texts.money_1);
    e = e.replace(/\[GREEN\]/g, texts.money_3);
    e = e.replace(/\[CRYST\]/g, texts.money_2);
    doPopup(e, k, o, n);
};
function doItem(e, z, u, q, v)
{
    if (popups == undefined) {
        return;
    }
    var p = popups["item_" + e];
    if (p == undefined) {
        return;
    }
    var A = p[0];
    var w = p[1];
    var r = p[2];
    if (z != undefined && z != "") {
        r = r + "\n" + z;
    }
    if (u != undefined && u != "") {
        A = A + u;
    }
    r = r.replace(/\[GOLD\]/g, texts.money_1);
    r = r.replace(/\[GREEN\]/g, texts.money_3);
    r = r.replace(/\[CRYST\]/g, texts.money_2);
    var t = "<table class='popup_item'><tr><th colspan='2'>" + A + "</th></tr>";
    t += "<tr><td class='image'><img src='images/" + w + ".png' alt='" + A + "'><td>" + r;
    t += "</table>";
    var o = $("tooltip2");
    doPopup(t, q, v, o, 0, 0, 500);
};
function doPopup(o, l, p, n, r, k, q)
{
    if (r == undefined) {
        r = 0;
    }
    if (k == undefined) {
        k = 0;
    }
    if (q == undefined) {
        q = 100;
    }
    var e = 300;
    clearTimeout(tooltip_id);
    if (n == undefined) {
        n = $("tooltip");
    }
    o = o.replace(/-#39;/g, "'");
    o = o.replace(/\\n/g, "\n");
    o = o.replace(/\n/g, "<br>");
    if (o == "") {
        return;
    }
    n.innerHTML = o;
    n.style.display = "none";
    n.style.position = "absolute";
    p.onmouseout = function ()
    {
        hide_tooltip();
        doImageHover(p, false);
    };
    p.alt = "";
    if (is_ie && !is_opera)
    {
        x = event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
        y = event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
    }
    else {
        if (is_moz) {
            x = l.pageX;
            y = l.pageY;
        }
        else {
            x = event.pageX;
            y = event.pageY;
        }
    }
    x += r;
    y += k;
    if (document.body.clientWidth) {
        body_width = document.body.clientWidth;
        if (body_width < x + e) {
            x = body_width - e - 20;
        }
    }
    tooltip_id = setTimeout("show_tooltip2(" + x + "," + y + ",'" + n.id + "')", q);
};
function show_tooltip2(e, g, f)
{
    var j = $(f);
    j.style.left = e + "px";
    j.style.top = (g + 10) + "px";
    j.style.display = "block";
};
function hide_tooltip()
{
    clearTimeout(tooltip_id);
    $("tooltip").style.display = "none";
    if ($("tooltip2")) {
        $("tooltip2").style.display = "none";
    }
};
var started_tags = new Array();
function AddTag(e, d, f)
{
    if (f == undefined) {
        f = e;
    }
    insert_tag(e, f, d);
};
function insert_tag(r, t, q, o)
{
    obj = $(q);
    var u = true;
    if ((document.selection && obj.document.selection.createRange().text.length > 0))
    {
        obj.focus();
        obj.document.selection.createRange().text = "[" + r + "]" + obj.document.selection.createRange().text + "[/" + t + "]";
        u = false;
    }
    else
    {
        if (obj.selectionEnd)
        {
            var A = obj.selectionStart;
            var v = obj.selectionEnd;
            if (A != v)
            {
                var z = (obj.value).substring(0, A);
                var w = (obj.value).substring(A, v);
                var p = (obj.value).substring(v, obj.textLength);
                obj.value = z + "[" + r + "]" + w + "[/" + t + "]" + p;
                u = false;
            }
        }
    }
    if (u)
    {
        if (o == undefined) {
            o = r;
        }
        var n = "";
        if (started_tags[q] == undefined) {
            started_tags[q] = new Array();
        }
        if (started_tags[q][o] == undefined || started_tags[q][o] == 0) {
            n = "[" + r + "]";
            started_tags[q][o] = 1;
        }
        else {
            n = "[/" + t + "]";
            started_tags[q][o] = 0;
        }
        obj.value += n;
    }
};
function insert_text(o, k)
{
    obj = $(k);
    if ((document.selection)) {
        obj.focus();
        obj.document.selection.createRange().text = o;
    }
    else
    {
        if (obj.selectionEnd)
        {
            var l = obj.selectionStart;
            var g = obj.selectionEnd;
            var n = (obj.value).substring(0, l);
            var j = (obj.value).substring(g, obj.textLength);
            obj.value = n + o + j;
        }
        else {
            obj.value += o;
        }
    }
};
function ShowColor(f, e)
{
    if (started_tags[e] != undefined && started_tags[e]["COLOR"]) {
        return insert_tag("COLOR", "COLOR", e, "COLOR");
    }
    for (var g = 1; ; g++) {
        var j = $("colors_" + g);
        if (!j) {
            break;
        }
        j.style.display = (g == f) ? "block" : "none";
    }
};
function AddColor(d, f, e)
{
    insert_tag("COLOR=" + d, "COLOR", f, "COLOR");
    $("colors_" + e).style.display = "none";
};
function insert_message(p, r, l)
{
    obj = $(target_object);
    old_text = obj.value;
    if ((document.selection)) {
        obj.focus();
        obj.document.selection.createRange().text = p + l + r;
    }
    else
    {
        if (obj.selectionEnd)
        {
            var n = obj.selectionStart;
            var j = obj.selectionEnd;
            var o = (obj.value).substring(0, n);
            var q = (obj.value).substring(n, j);
            var k = (obj.value).substring(j, obj.textLength);
            obj.value = o + "[" + p + "]" + q + "[/" + r + "]" + k;
        }
        else {
            obj.value += p + l + r;
        }
    }
};
function addCharacter(k)
{
    var o = prompt("Введите номер перснажа или ссылку на персонажа:", "");
    if (o == null || o == undefined) {
        return;
    }
    var g = o.search(/\?set=player&id=([0-9]+)$/);
    var j = o.search(/\?set=player&id=([0-9]+)$/);
    var l = o.search(/^([0-9]+)$/);
    var n = 0;
    if (l !=- 1) {
        n = o;
    }
    else {
        if (g !=- 1) {
            n = o.substring(g + 14);
        }
        else {
            if (j !=- 1) {
                n = o.substring(j + 9);
            }
        }
    }
    if (n < 1) {
        alert("Неправильный номер игрока");
        return;
    }
    insert_text("[CHAR=" + n + "]", k);
    insert_text("[/CHAR]", k);
};
function addClan(j)
{
    var f = prompt("Введите номер клана или ссылку на клан:", "");
    if (f == null || f == undefined) {
        return;
    }
    var g = f.search(/\?set=klan&mode=info&id=([0-9]+)$/);
    var k = f.search(/^([0-9]+)$/);
    var l = 0;
    if (k !=- 1) {
        l = f;
    }
    else {
        if (g !=- 1) {
            l = f.substring(g + 12);
        }
    }
    if (l < 1) {
        alert("Неправильный номер клана");
        return;
    }
    insert_text("[CLAN=" + l + "]", j);
    insert_text("[/CLAN]", j);
};
function doGroup(j, k)
{
    var g = new Array();
    g.auction = new Array("bid_start", "bid_type");
    g.trade = new Array("fast_price", "fast_type");
    if (g[j] == undefined) {
        return;
    }
    for (var f in g[j]) {
        var l = g[j][f];
        $(l).disabled = k;
    }
};
function doImageHover(_1, _2)
{
    if (_2 == undefined) {
        _2 = true;
    }
    var _3 = _1.src;
    _3 = (_2) ? _3.replace("_p.", "_a.") : _3.replace("_a.", "_p.");
    _1.src = _3;
};
function SelectAll(obj){
    obj.focus();
    obj.select();
}
function ChangeBidMoney()
{
    var _4 = $("bid_type");
    var _5 = _4.options[_4.selectedIndex].value;
    var _6 = bprice[(_5 - 1) * 2];
    $("bid_start").value = _6;
};
function ChangeTaxMoney()
{
    var _7 = $("fast_type");
    var _8 = _7.options[_7.selectedIndex].value;
    var _9 = bprice[(_8 - 1) * 2];
    $("fast_price").value = _9;
};
function updateBid()
{
    var _a = $("bid_type");
    var _b = _a.options[_a.selectedIndex].value;
    var _c = bprice[(_b - 1) * 2];
    var _d = Math.round(bprice[(_b - 1) * 2 + 1] * 0.75);
    var _e = bprice[(_b - 1) * 2 + 1];
    var _f = _c;
    if (parseInt($("bid_start").value) < _c) {
        $("bid_start").value = _c;
        updateBid();
        return;
    }
    if (parseInt($("bid_start").value) > _d) {
        $("bid_start").value = _d;
        updateBid();
        return;
    }
    var _10 = Math.ceil((_e - $("bid_start").value) / 10);
    $("bid_step").value = _10;
    var tax = Math.ceil($("bid_start").value * taxs / 100);
    if (texts != undefined && texts["money_" + _b] != undefined) {
        tax = tax + " " + texts["money_" + _b];
    }
    $("bid_tax").innerHTML = tax;
    $("bid_tax2").innerHTML = taxs;
    $("min_tax").innerHTML = _c;
    $("max_tax").innerHTML = _d;
};
function updateTax()
{
    tradeConfirmed = 0;
    var _11 = parseInt($("fast_price").value);
    var _12 = $("fast_type");
    var _13 = _12.options[_12.selectedIndex].value;
    var _14 = bprice[(_13 - 1) * 2];
    var _15 = bprice[(_13 - 1) * 2 + 1];
    if (_11 < _14) {
        $("fast_price").value = _14;
        updateTax();
        return;
    }
    if (_11 > _15) {
        $("fast_price").value = _15;
        updateTax();
        return;
    }
    var tax = Math.ceil(_11 * taxs / 100);
    if (texts != undefined && texts["money_" + _13] != undefined) {
        tax = tax + " " + texts["money_" + _13];
    }
    $("fast_tax").innerHTML = tax;
    $("fast_tax2").innerHTML = taxs;
    $("min_fast").innerHTML = _14;
    $("max_fast").innerHTML = _15;
};
function showBox(id)
{
    var body = $('b_' + id);
    var title = $('t_' + id);

    if (body.className.search('hidden') >= 0) 
    {
        body.className = body.className.replace('hidden', 'shown');
        title.className = title.className.replace('hide', 'show');
		if(window.localStorage)
			window.localStorage.setItem(id, 1);
	}
    else
    {
        body.className = body.className.replace('shown', 'hidden');
        title.className = title.className.replace('show', 'hide');
		if(window.localStorage)
			window.localStorage.setItem(id, 0);
    }
};
function CheckShowBox(id)
{
    var body = $('b_' + id);
    var title = $('t_' + id);
	if (window.localStorage && window.localStorage.getItem(id) != undefined) {
		if (window.localStorage.getItem(id)==1) {
			body.className = body.className.replace('hidden', 'shown');
			title.className = title.className.replace('hide', 'show');
		}else{
			body.className = body.className.replace('shown', 'hidden');
			title.className = title.className.replace('show', 'hide');
		}			
	}
}