﻿var iR = true;
var iG = true;
var iB = true;

var r = RandomColor(256);
var g = RandomColor(256);
var b = RandomColor(256);

var interval;


function RandomColor(range) {
    var number = Math.floor(Math.random() * range);
    return number;
}


function ChangeColor() {
    var elementT = document.getElementById("PopupPanelModalArea");
    elementT.style.backgroundColor = generateColor();

}

function generateColor() {
    if (r > 255) {
        iR = false;
    }

    if (g > 255) {
        iG = false;
    }

    if (b > 255) {
        iB = false;
    }

    if (r < 0) {
        r = 0;
        iR = true;
    }

    if (g < 0) {
        g = 0;
        iG = true;
    }

    if (b < 0) {
        b = 0;
        iB = true;
    }

    r += (iR ? RandomColor(10) : -RandomColor(10));
    g += (iG ? RandomColor(10) : -RandomColor(10));
    b += (iB ? RandomColor(10) : -RandomColor(10));

    return "rgb(" + r + "," + g + "," + b + ")"
}


function alertSize() {
    var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    return [myWidth, myHeight];
}



function getScrollXY() {
    var scrOfX = 0, scrOfY = 0;
    if (typeof (window.pageYOffset) == 'number') {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    return [scrOfX, scrOfY];
}

function Pos() {

    var CntntCtrl = document.getElementById('Cntnt');
    var ModalAreaCtrl = document.getElementById('PopupPanelModalArea');

    ModalAreaCtrl.style.top = getScrollXY()[1] + "px";
    ModalAreaCtrl.style.height = alertSize()[1] + "px";
    ModalAreaCtrl.style.width = alertSize()[0] + "px";

    CntntCtrl.style.top = (getScrollXY()[1] + (alertSize()[1] / 2) - (CntntCtrl.clientHeight / 2)) + "px";
    CntntCtrl.style.left = ((alertSize()[0] / 2) - CntntCtrl.clientWidth / 2) + "px";
}


function TogglePopupPanel() {

    var panelContainer = document.getElementById("PopupPanel");

    if (panelContainer.style.display == "none") {
        if (readCookie("topUs") != null) {
            return 0;
        }

        panelContainer.style.display = "";
        document.getElementById('PopupPanelModalArea').focus();
        window.onscroll = Pos;
        window.onresize = Pos;
        interval = setInterval("ChangeColor()", 50);
    }
    else {
        panelContainer.style.display = "none";
        clearInterval(interval);
    }
    Pos();
}


function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";

}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function Redirect() {
    Close();
    window.location = "/registratsiya-mini/";
}

function Close() {
    TogglePopupPanel();
    createCookie("topUs", "1", 7);
}

function WriteQuestion() {
    var textVar = "";
    textVar += "    <style type=\"text\/css\">";
    textVar += "            .PopupPanel";
    textVar += "            {";
    textVar += "                border: solid 1px black;";
    textVar += "                position: absolute;";
    textVar += "                background-color: white;";
    textVar += "                z-index: 100;";
    textVar += "                width: 50%;";
    textVar += "            }";
    textVar += "            ";
    textVar += "            .PopupPanelModalArea";
    textVar += "            {";
    textVar += "                height: 100%;";
    textVar += "                width: 100%;";
    textVar += "                position: absolute;";
    textVar += "                background-color: Black;";
    textVar += "                filter: progid:DXImageTransform.Microsoft.Alpha(opacity=70);";
    textVar += "                z-index: 99;";
    textVar += "                border: 0;";
    textVar += "                opacity: 0.7;";
    textVar += "            }";
    textVar += "            ";
    textVar += "            .PopupPanel .TitleBar";
    textVar += "            {";
    textVar += "                margin: 0;";
    textVar += "                color: #99CCFF;";
    textVar += "                display: block;";
    textVar += "                background-color: Black;";
    textVar += "                line-height: 20px;";
    textVar += "                font-size: 1.3em;";
    textVar += "                font-weight: bold;";
    textVar += "                font-family: Arial, Sans-Serif;";
    textVar += "                padding: 0 0 0 5px;";
    textVar += "            }";
    textVar += "            ";
    textVar += "            ";
    textVar += "            .PopupPanel .ContentArea";
    textVar += "            {";
    textVar += "                padding: 5px;";
    textVar += "                background-color: #FFFF99;";
    textVar += "                font-family: Arial, Sans-Serif;";
    textVar += "                line-height: 1.5em;";
    textVar += "                ";
    textVar += "            }";
    textVar += "            ";
    textVar += "            ";
    textVar += "        <\/style>";
    textVar += "        <div id=\"PopupPanel\" style=\"display: none\">";
    textVar += "            <div id=\"PopupPanelModalArea\" class=\"PopupPanelModalArea\">";
    textVar += "            <\/div>";
    textVar += "            <div id=\"Cntnt\" class=\"PopupPanel\">";
    textVar += "                <p class=\"TitleBar\">";
    textVar += "                    МЛМ команда Тяньши";
    textVar += "                <\/p>";
    textVar += "                <div class=\"ContentArea\">";
    textVar += "                        Не упусти возможность узнать, как";
    textVar += "                        улучшить материальную жизнь свою и своих близких!";
    textVar += "                        <br \/>";
    textVar += "                        <br \/>";
    textVar += "                        Не бойся! Это не лохотрон и";
    textVar += "                        не финансовая пирамида, это прямые продажи и домашний бизнес. Всё честно! ";
    textVar += "                        <br \/>";
    textVar += "                        <br \/>";
    textVar += "                        Возможно";
    textVar += "                        у тебя есть способности к этому и ты сможешь многого добиться!";
    textVar += "                        <br \/>";
    textVar += "                        <br \/>";
    textVar += "                        <strong><a style=\"color: Green\" href=\"#\" onclick=\"Redirect()\">Я хочу узнать больше<\/a><\/strong> - <i><strong>Я знаю, что халявы";
    textVar += "                        не существует, чтобы что-то получить - нужно вложить свой труд и инвестировать материальные";
    textVar += "                        средства в своё дело.<\/strong><\/i>";
    textVar += "                        <br \/>";
    textVar += "                        <br \/>";
    textVar += "                        <strong><a style=\"color: Red\" href=\"#\" onclick=\"Close()\">Закрыть и не показывать это окно<\/a><\/strong>";
    textVar += "                        - <i><strong>Мне не интересно узнать что-то новое, текущее положение моих финансовых дел меня";
    textVar += "                        устраивает и я довольствуюсь тем что у меня уже есть, большего мне не нужно.<\/strong><\/i>";
    textVar += "                   ";
    textVar += "                <\/div>";
    textVar += "            <\/div>";
    textVar += "        <\/div>";

    document.write(textVar);
}
