/**
 * Определение версии IE.
 */
function is_ie_5_or_6()
{
    if (!jQuery.browser.msie)
    {
        return false;
    }

    var ie8 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 8.0") != -1);
    if (jQuery.browser.msie && ie8)
    {
        return false;
    }

    var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
    if (jQuery.browser.msie && ie55)
    {
        return true;
    }


    var is_6 = jQuery.browser.msie6 =
    $.browser.msie
    && /MSIE 6\.0/i.test(window.navigator.userAgent)
    && !/MSIE 7\.0/i.test(window.navigator.userAgent);

    return is_6;
}

var need_fix_png = is_ie_5_or_6();

function show_rom_layer()
{
    // Скрываем слой с остальным софтом.
    $('#other_soft_layer').hide('slide', { 
        direction: "left"
    }, 500, other_soft_hide_callback);
}

function show_other_soft_layer()
{
    // Скрываем слой.
    $('#rom_layer').hide('slide', { 
        direction: "right"
    }, 500, rom_hide_callback);
}

function rom_hide_callback()
{
    // Отображаем слой.
    $('#other_soft_layer').show('slide', { 
        direction: "left"
    }, 500);

    // Переназначаем событие.
    $('#slide_page').unbind('click', show_other_soft_layer);
    $('#slide_page').bind('click', show_rom_layer);

    // Меняем картинку.
    $('#slide_page_container').css('backgroundImage', "url('/images/l_arrow.png')");

    // Правим png (для IE 6).
    if (need_fix_png)
    {
        $('#slide_page').pngFix();
    }
}

function other_soft_hide_callback()
{
    // Отображаем слой c ROM.
    $('#rom_layer').show('slide', { 
        direction: "right"
    }, 500);

    // Переназначаем событие.
    $('#slide_page').unbind('click', show_rom_layer);
    $('#slide_page').bind('click', show_other_soft_layer);

    // Меняем картинку.
    $('#slide_page_container').css('backgroundImage', "url('/images/r_arrow.png')");

    // Правим png (для IE 6).
    if (need_fix_png)
    {
        $('#slide_page').pngFix();
    }
}

// Показ закладок.
function ShowLayer(AItemId, ASpan, AParentId)
{

    var FormElement = null;

    // Получаем элемент родительского контейнера, если указан.

    if (AParentId != '')
    {
        FormElement = document.getElementById(AParentId);
    }
    else
    {
        FormElement = document;
    }

    if (FormElement)
    {
        // Скрываем все tab-page'ы.
        element_array = FormElement.getElementsByTagName("div");

        if (element_array.length > 0)
        {
            for (var i = 0; i < element_array.length; i++)
            {
                if (element_array[i].getAttribute('id') == undefined)
                {
                    continue;
                }

                if (element_array[i].getAttribute('id').search("tab_page_") != -1)
                {
                    // Нельзя display: none; из-за визуального редактора
                    element_array[i].style.display = "none";
                }
            }
        }
    }

    var el = document.getElementById(AItemId);

    if (!el)
    {
        return false;
    }

    // Отображаем выбранный tab-page.
    el.style.display = "block";


    element_array = document.getElementsByTagName("li");

    // Если есть хотя бы один li
    if (element_array.length > 0)
    {
        for (var i = 0; i < element_array.length; i++)
        {
            if (element_array[i].getAttribute('id') == undefined)
            {
                continue;
            }

            // Неактивный
            if (element_array[i].getAttribute('id').search("id_tab_span_") != -1)
            {
                element_array[i].className = "";
            }

            // Активный
            if (element_array[i].getAttribute('id') == ASpan)
            {
                element_array[i].className = "current_li";
            }
        }

    }

    return true;
}

function process_buy()
{
	var elem = document.getElementById('license_count');
	var count = parseInt(elem.value);
	if (isNaN(count) || count <= 0)
	{
		elem.value = 10;
		return false;
	}

	location = 'http://www.softkey.ru/catalog/basket.php?prodid=301016&from=1424174&quantity=' + count;
	return true;
}

function show_hide_faq(AItemId)
{
    var item = $('#' + AItemId);
    var span = $('#' + AItemId + '_span');

    if (item.is(':visible'))
    {
        item.hide('slide', {
            direction: "up"
        }, 500);

        span.css('font-weight', 'normal');
    }
    else
    {
        item.show('slide', {
            direction: "up"
        }, 500);

        span.css('font-weight', 'bold');
    }
}