/*Полезная функция*/
function $(a) {
    return document.getElementById(a);
};

/*Добавление обработчика событий*/
function addEvent(a, b, c) {
    if (a.attachEvent) {
        a.attachEvent('on' + b, c);
    } else if (a.addEventListener) {
        a.addEventListener(b, c, false);
    };
};

addEvent(window, 'load', init);
function init() {
    setTimeout(function() { setlinks() }, 5000);
};

function setlinks() {
    if ($('img1')) {
        $('img1').style.visibility = 'visible';
        $('img1').onclick = but_click;
    };
};

function click_on_link(e) {
    if (!e) e = window.event;
    var t = e.target ? e.target : e.srcElement;
    'returnValue' in e ? e.returnValue = false : e.preventDefault();
};

function show_ref() {
    if ($('d2')) {
        m = new Array();
        var c = 4096;
        for (var i = 0; i < (document.getElementById('d2').innerHTML.length / c); i++) {
            m[i] = document.getElementById('d2').innerHTML.substr(i * c, c);
        };
        $('d6').innerHTML = show_ref_menu(0, 1);
        $('d7').innerHTML = show_ref_menu(0, 0);
        $('d2').innerHTML = m[0];
        $('d2').style.display = 'block';
    };
    //show_keyws(t);
};
function show_ref_menu(n, p) {
    var a = '<br /><table border="0" class=\"t4\" width=\"100%\" cellpadding="0" cellspacing="0"><tr><td align="' + (!p ? 'left' : 'right') + '">';
    a += '<table cellpadding="6" cellspacing="0"><tr><td>';
    for (var i in m) {
        if (i == n) {
            a += '<td class=\"td5\">' + (Number(i) + 1) + '</td>';
        } else {
            a += '<td><a ' + 'class="a5" ' + 'href="Javascript:void(0);" onclick="show_ref_page(' + i + ')">' + (Number(i) + 1) + '</a></td>';
        };
        if (i > 30) {
            break;
        }
    }
    a += '</td></tr></table></td></tr></table>';
    if (p)
        a += '<br />';
    return a;
};

function show_ref_page(n) {
    $('d6').innerHTML = show_ref_menu(n, 1);
    $('d7').innerHTML = show_ref_menu(n, 0);
    $('d2').innerHTML = m[n];
    //show_keyws(t);
};
function show_keyws(str) {
    if (str) {
        var words = str.split(' ');
        for (var i in words) {
            if (words[i].length >= 3) {
                words[i] = words[i].substr(0, words[i].length - 1);
                var re = new RegExp("([а-яА-Я]*" + words[i] + "[а-яА-Я]*)", "mig");
                if ($('d1')) {
                    $('d1').innerHTML = $('d1').innerHTML.replace(re, '<span class=\"s6\">$1</span>');
                };
            };
        };
    };
};


/*Размеры всего документа*/
function getDocumentSize(doc) {
    var r = { width: 0, height: 0, x: 0, y: 0 };

    var width1 = 0, width2 = 0, width3 = 0, width4 = 0, maxWidth = 0;
    var height1 = 0, height2 = 0, height3 = 0, height4 = 0, maxHeight = 0;


    if (doc.width) maxWidth = doc.width;
    if (doc.body) {
        if (doc.body.scrollWidth) width1 = doc.body.scrollWidth;
        if (doc.body.offsetWidth) width2 = doc.body.offsetWidth;
    }
    if (doc.documentElement) {
        width3 = doc.documentElement.scrollWidth;
        width4 = doc.documentElement.clientWidth;
    }

    maxWidth = Math.max(Math.max(Math.max(width1, width2), Math.max(width3, width4)), maxWidth);
    r.x = Math.max(Math.max(width2, width4), maxWidth);

    if (doc.height) maxHeight = doc.height;
    if (doc.body) {
        if (doc.body.scrollHeight) height1 = doc.body.scrollHeight;
        if (doc.body.offsetHeight) height2 = doc.body.offsetHeight;
    }
    if (doc.documentElement) {
        height3 = doc.documentElement.scrollHeight;
        height4 = doc.documentElement.clientHeight;
    }
    maxHeight = Math.max(Math.max(Math.max(height1, height2), Math.max(height3, height4)), maxHeight);
    r.y = height4;


    r.width = maxWidth;
    r.height = maxHeight;

    return r;
};

function but_click() {
    document.getElementById('d3').style.width = '100%';
    document.getElementById('d3').style.height = '100%';
    show_window();
};

function show_window() {
    $('d4').style.display = 'inline';
    $('d4').style.top = '100px';
    $('d4').style.left = (getDocumentSize(document).x / 2 - $('d4').offsetWidth / 2) + 'px';
    $('d4').style.top = (getDocumentSize(document).y / 2 - $('d4').offsetHeight / 2) + 'px';
};

function check() {
    if ($('i1').value == 'refak.ru') {
        $('f1').submit();

    } else {
        alert('Неверно указан код');
        return false;
    };
};

window.onload = function() {
    if ($('f1'))
        $('f1').onsubmit = check;
    //show_ref();
};
window.yandex_metrika_callback = function() {
    window.yaCounter243926 = new Ya.Metrika(243926);
};
(function() {
    var i = "DOMContentLoaded", g = "onreadystatechange", c = "doScroll", f = "addEventListener", o = "attachEvent", d = "load", l = false, n = document, e = window, m = n.documentElement, h = l, j;
    function k() {
        if (!h) {
            h = !h; j = n.createElement("script"); j.type = "text/javascript";
            j.src = "//mc.yandex.ru/metrika/watch.js"; j.setAttribute("async", "true");
            m.firstChild.appendChild(j)
        }
    }
    if (n[f]) {
        function b() { n.removeEventListener(i, b, l); k() } n[f](i, b, l);
        n[f](d, k, l)
    } else {
        if (n[o]) {
            n[o](g, a); function a() {
                if (h) { return } try { m[c]("left") } catch (p) {
                    setTimeout(a, 0);
                    return
                } k()
            } if (m[c] && e == e.top) { a() } n[o]("on" + d, k)
        }
    }
})();
