﻿function ask_log_callback(result, context) {
    if (result == 'show') {
        show_ask_form();


        ask_log_show('ask_background');
        set_size();
        ask_log();
        ask_log_timer();
    }
    else if (result == 'stop') {
    }
    else
        ask_log_timer();
}

function ask_form_visible() {
    return document.getElementById('ask_main').style.display=='block';
}

function show_ask_form() {
    var f = document.getElementById('ask_iframe');
    f.src = f.src;
    toggle_center_block('ask_main', 447, 220);
    ask_log_show('ask_main');
}
function ask_log_hide_all_iframe() {
    ask_log_hide_iframe('ask_main');
    ask_log_hide_iframe('ask_background');
}

function ask_log_hide_iframe(id) {
    window.parent.document.getElementById(id).style.display = 'none';
}


function ask_log_hide_all() {
    ask_log_hide('ask_main');
    ask_log_hide('ask_background');
}

function ask_log_hide(id) {
    document.getElementById(id).style.display = 'none';
}
function ask_log_show(id) {
    document.getElementById(id).style.display = 'block';
}

function ask_chat_show() {
    window.open('/ask/ask_chat.aspx', 'ask_chat', 'toolbar=no, location=no, directories=no, status=no, resizable=no, scrollbars=auto, width=580, height=500, screenX=350, screenY=300, left=350, top=300');
}


function set_size() {

    if (document.getElementById('ask_background').style.display == 'block') {     
        document.getElementById('ask_background').style.height = document.getElementById('ask_container').offsetHeight+20 + 'px';
        document.getElementById('ask_background').style.width = document.getElementById('ask_container').offsetWidth +20 + 'px';
    }
}

function toggle_center_block(block_id, w, h) {
    f = document.getElementById(block_id);

    if (f.style.display == "block") {
        f.style.display = "none";
    } // прячем блок
    else {
        // Для начала узнаем размеры видимой области страницы
        var myWidth = 0, myHeight = 0;
        if (typeof (window.innerWidth) == 'number') {
            // для всего кроме MSIE
            myWidth = window.innerWidth;
            myHeight = window.innerHeight;
        } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
            // IE6+
            myWidth = document.documentElement.clientWidth;
            myHeight = document.documentElement.clientHeight;
        } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
            // IE4
            myWidth = document.body.clientWidth;
            myHeight = document.body.clientHeight;
        }

        // Теперь уточняем, насколько страница прокручена вниз и вбок
        var scrOfX = 0, scrOfY = 0;
        if (typeof (window.pageYOffset) == 'number') {
            // Netscape и его родственники
            scrOfY = window.pageYOffset;
            scrOfX = window.pageXOffset;
        } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
            // DOM
            scrOfY = document.body.scrollTop;
            scrOfX = document.body.scrollLeft;
        } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
            // IE6
            scrOfY = document.documentElement.scrollTop;
            scrOfX = document.documentElement.scrollLeft;
        }

        // А теперь позиционируем наш блок
        f.style.top = String(Math.round((myHeight - h) / 2) + scrOfY) + 'px';
        f.style.left = String(Math.round((myWidth - w) / 2) + scrOfX) + 'px';
        //f.style.width = w + ((3 + 1) * 2);
        //f.style.height = h + ((3 + 1) * 2);
        f.style.display = "block";
    } // показываем блок
} // toggle_center_block
