function check_email()
{
    var email = $('input.email').val();
    var urls = "/udata/custom/get_all_emails/?email=" + email;

    $.ajax({
        url: urls,
        success: function(data) {
            var flag = $(data).find('flag').text();

            if (flag == 1)
            {
                $('dd.hint').show();
                $('input.submit').removeClass('zf zf-submit');
                $('input.submit').attr('disabled', 'disabled');
            }
            if (flag == 0)
            {
                $('dd.hint').hide();
                $('input.submit').addClass('zf zf-submit');

                var has_class = $('input.email').parent().parent().hasClass('zf-invalid');

                if (has_class == true)
                {
                    $('input.submit').attr('disabled', 'disabled');
                }
                else
                {
                    $('input.submit').attr('disabled', '');
                }
            }
        }
    });
}

function users()
{
    var active_id = $('select#yur_status option:selected').val();
    if (active_id == 30270)
    {
        $('.jur').show();
        $('.org_name').show();
        $('.inn').show();
        $('.kpp').show();
        $('.jur_adress').show();
        $('.account').show();
        $('.contact').show();
        $('.bik').show();
        $('.kor_schet').show();

        $('.fio').hide();
        $('.fiz').hide();

        $('.pred').hide();
        $('.org_name_pred').hide();
        $('.inn_pred').hide();
        $('.jur_adress_pred').hide();
        $('.account_pred').hide();
        $('.contact_pred').hide();
        $('.bik_pred').hide();
        $('.kor_schet_pred').hide();

        $('div.contact').show();

    }
    if (active_id == 30339)
    {
        $('.jur').hide();
        $('.org_name').hide();
        $('.inn').hide();
        $('.kpp').hide();
        $('.jur_adress').hide();
        $('.account').hide();
        $('.contact').hide();
        $('.bik').hide();
        $('.kor_schet').hide();

        $('.fio').hide();
        $('.fiz').hide();

        $('.pred').show();
        $('.org_name_pred').show();
        $('.inn_pred').show();
        $('.jur_adress_pred').show();
        $('.account_pred').show();
        $('.contact_pred').show();
        $('.bik_pred').show();
        $('.kor_schet_pred').show();

        $('div.contact').show();
    }
    if (active_id == 30269)
    {
        $('.jur').hide();
        $('.org_name').hide();
        $('.inn').hide();
        $('.kpp').hide();
        $('.jur_adress').hide();
        $('.account').hide();
        $('.contact').hide();
        $('.bik').hide();
        $('.kor_schet').hide();

        $('.fio').show();
        $('.fiz').show();

        $('.pred').hide();
        $('.org_name_pred').hide();
        $('.inn_pred').hide();
        $('.jur_adress_pred').hide();
        $('.account_pred').hide();
        $('.contact_pred').hide();
        $('.bik_pred').hide();
        $('.kor_schet_pred').hide();

        $('div.contact').show();
    }
    if (active_id == '')
    {
        $('.jur').hide();
        $('.org_name').hide();
        $('.inn').hide();
        $('.kpp').hide();
        $('.jur_adress').hide();
        $('.account').hide();
        $('.contact').hide();
        $('.bik').hide();
        $('.kor_schet').hide();

        $('.fio').show();
        $('.fiz').show();

        $('.pred').hide();
        $('.org_name_pred').hide();
        $('.inn_pred').hide();
        $('.jur_adress_pred').hide();
        $('.account_pred').hide();
        $('.contact_pred').hide();
        $('.bik_pred').hide();
        $('.kor_schet_pred').hide();

        $('div.contact').show();
    }
}

function recommended()
{
    var items_width = $('div.main div.wrapper div.offers div.right div.items').width();
    var item_width_block = $('div.main div.wrapper div.offers div.right div.items div.item').eq(2).width() + 57;
    var items_count_on_page = Math.floor(items_width / item_width_block);
    var max_item_height = 0;

    for (var i = 0; i < items_count_on_page; i++)
    {
        var item_height = $('div.main div.wrapper div.offers div.right div.items div.item').eq(i).height();

        if (max_item_height < item_height)
        {
            max_item_height = item_height;
        }
    }

    max_item_height = max_item_height + 20;

    $('div.main div.wrapper div.offers div.right div.items').css('height', max_item_height+"px");
}

function new_items()
{
    var items_width = $('div.spec_blocks div.new div.items').width();
    var item_width_block = $('div.spec_blocks div.new div.items div.item').eq(2).width() + 57;
    var items_count_on_page = Math.floor(items_width / item_width_block);
    var max_item_height = 0;

    for (var i = 0; i < items_count_on_page; i++)
    {
        var item_height = $('div.spec_blocks div.new div.items div.item').eq(i).height();

        if (max_item_height < item_height)
        {
            max_item_height = item_height;
        }
    }

    max_item_height = max_item_height + 20;

    $('div.spec_blocks div.new div.items').css('height', max_item_height+"px");
}

function popular_items()
{
    var items_width = $('div.spec_blocks div.pop div.items').width();
    var item_width_block = $('div.spec_blocks div.pop div.items div.item').eq(2).width() + 57;
    var items_count_on_page = Math.floor(items_width / item_width_block);
    var max_item_height = 0;

    for (var i = 0; i < items_count_on_page; i++)
    {
        var item_height = $('div.spec_blocks div.pop div.items div.item').eq(i).height();

        if (max_item_height < item_height)
        {
            max_item_height = item_height;
        }
    }

    max_item_height = max_item_height + 20;

    $('div.spec_blocks div.pop div.items').css('height', max_item_height+"px");
}

function spec_items()
{
    var items_width = $('div.spec_blocks div.spec div.items').width();
    var item_width_block = $('div.spec_blocks div.spec div.items div.item').eq(2).width() + 57;
    var items_count_on_page = Math.floor(items_width / item_width_block);
    var max_item_height = 0;

    for (var i = 0; i < items_count_on_page; i++)
    {
        var item_height = $('div.spec_blocks div.spec div.items div.item').eq(i).height();

        if (max_item_height < item_height)
        {
            max_item_height = item_height;
        }
    }

    max_item_height = max_item_height + 20;

    $('div.spec_blocks div.spec div.items').css('height', max_item_height+"px");
}

$(document).ready(function ()
{

    var h1_cur = $('h1').text();
    
    if (h1_cur == 'Банковсое оборудование')
    {
        var files_height = $('div.price-lists').find('div.files').height();
        $('div.icq_place').css('padding-bottom', files_height+'px');
    }

    $('div.popup div.window a.go-close').click(function()
    {
        $('div.popup').fadeOut(500);
    });

    // User Orders ------------------------------------------------------------------------------------------

    $('div.orders table.blue tr.repeat_order_line').hide();

    $('span.show_repeat').toggle(function()
    {
        var tr_index = $(this).parentsUntil('tbody').index();
        var tr_next_index = tr_index - 2;
        $('div.orders table.blue tr.item_line').eq(tr_next_index).show();
        $(this).children('span.arrow').text(' ↑');
    },function()
    {
        var tr_index = $(this).parentsUntil('tbody').index();
        var tr_next_index = tr_index - 2;
        $('div.orders table.blue tr.item_line').eq(tr_next_index).hide();
        $(this).children('span.arrow').text(' ↓');
    });

    $('a.prettyPhoto').prettyPhoto();

    // Order Item -------------------------------------------------------------------------------------------

    var delivery_id_first = $('div.reg-form-delivery ul li input').eq(0).attr('checked');

    if (delivery_id_first == true)
    {
        $('div.reg-form-adress').hide();

        /*$('.country').hide();
        $('.index').hide();
        $('.region').hide();
        $('.city').hide();
        $('.street').hide();
        $('.house').hide();
        $('.flat').hide();*/
    }
    else
    {
        $('div.reg-form-adress').show();

        /*$('.country').show();
        $('.index').show();
        $('.region').show();
        $('.city').show();
        $('.street').show();
        $('.house').show();
        $('.flat').show();*/
    }

    $('div.reg-form-delivery ul li input').change(function()
    {
        var delivery_id = $(this).attr('id');

        if (delivery_id == '27255')
        {
            $('div.reg-form-adress').hide();

            /*$('.country').hide();
            $('.index').hide();
            $('.region').hide();
            $('.city').hide();
            $('.street').hide();
            $('.house').hide();
            $('.flat').hide();*/
        }
        else
        {
            $('div.reg-form-adress').show();

            /*$('.country').show();
            $('.index').show();
            $('.region').show();
            $('.city').show();
            $('.street').show();
            $('.house').show();
            $('.flat').show();*/
        }
    });

    // Payment Item -------------------------------------------------------------------------------------------

    $('div.status select').change(function()
    {
        var yur_status_count2 = $('div.status select option').length;
        var selected_id2 = 0;

        for (var k2 = 0; k2 < yur_status_count2; k2++)
        {
            var yur_status2 = $('div.status select option').eq(k2).attr('selected');

            if (yur_status2 == true)
            {
                selected_id2 = $('div.status select option').eq(k2).index();
            }
        }

        if (selected_id2 == 0)
        {
            $('div.reg-form-payment input').css('display', 'none');
            $('div.reg-form-payment input').eq(0).css('display', 'block');
            $('div.reg-form-payment input').eq(0).attr('checked', 'checked');
            $('div.reg-form-payment input').eq(1).css('display', 'block');
            $('div.reg-form-payment label').css('display', 'none');
            $('div.reg-form-payment label').eq(0).css('display', 'block');
            $('div.reg-form-payment label').eq(1).css('display', 'block');
        }

        if (selected_id2 == 1)
        {
            $('div.reg-form-payment input').css('display', 'block');
            $('div.reg-form-payment label').css('display', 'block');
        }

        if (selected_id2 == 2)
        {
            $('div.reg-form-payment input').css('display', 'none');
            $('div.reg-form-payment input').eq(1).css('display', 'block');
            $('div.reg-form-payment input').eq(1).attr('checked', 'checked');
            $('div.reg-form-payment input').eq(2).css('display', 'block');
            $('div.reg-form-payment label').css('display', 'none');
            $('div.reg-form-payment label').eq(1).css('display', 'block');
            $('div.reg-form-payment label').eq(2).css('display', 'block');
        }
    });

    // Loading Service Price --------------------------------------------------------------------------------

    proizvoditel_change = false;

    var pro = parseInt($('div.proizvoditels ul.proizvoditels li.active').children('span.value').text());
    var mod = parseInt($('div.models ul.models li.active').children('span.value').text());
    $('div.catalog div.item div.price div.value').html(pro + mod + ' <span class="rub">a</span>');

    // Changing User Profile Tabs ---------------------------------------------------------------------------

    $('div.con_tabs div.con').css('display', 'none');
    $('div.con_tabs div.con').eq(0).css('display', 'block');

    $('div.tabs div').click(function()
    {
        var tab_index = $(this).index();

        if (!$(this).hasClass('active'))
        {
            $('div.tabs div').removeClass('active');
            $(this).addClass('active');
            $('div.con_tabs div.con').css('display', 'none');
            $('div.con_tabs div.con').eq(tab_index).css('display', 'block');
        }
    });

    // Recommended Block on Main Page height ----------------------------------------------------------------

    recommended();
    new_items();
    popular_items();
    spec_items();

    // Change User Status -----------------------------------------------------------------------------------

    restoreFormData(document.getElementById('webform'));

    users();
    check_email();

    /*

    var text_log = $('input.login').val();
    var text_pass = $('input.pass').val();

    if (text_log == text_pass)
    {
        $('input.pass').parent().parent().removeClass('zf-required-ok');
    }

    */


    $('select#yur_status').change(function()
    {
        users();
        check_email();
    });

    $('input#email').change(function(){

        var email = $(this).val();
        var urls = "/udata/custom/get_all_emails/?email=" + email;

        $.ajax({
            url: urls,
            success: function(data) {
                var flag = $(data).find('flag').text();

                if (flag == 1)
                {
                    $('dd.hint').show();
                    $('input.submit').removeClass('zf zf-submit');
                    $('input.submit').attr('disabled', 'disabled');
                }
                if (flag == 0)
                {
                    $('dd.hint').hide();
                    $('input.submit').addClass('zf zf-submit');

                    var has_class = $('input.email').parent().parent().hasClass('zf-invalid');

                    if (has_class == true)
                    {
                        $('input.submit').attr('disabled', 'disabled');
                    }
                    else
                    {
                        $('input.submit').attr('disabled', '');
                    }
                }
            }
        });

    });

    /*

    $('input.pass').change(function(){
        var text = $(this).val();
        var text_pass = $('input.login').val();
        if (text == text_pass)
        {
            $(this).parent().parent().removeClass('zf-required-ok');
        }
    });*/



    // Price List Function ----------------------------------------------------------------------------------

    $('div.price-list-place div.price-lists a.price').toggle(function()
    {
        $('div.price-list-place div.background').fadeIn("slow");
        $('div.price-list-place div.price-lists div.files').fadeIn("slow");
        $('div.price-list-place div.price-lists').addClass("active");
        $(this).children('span.link').css('width', '48px');
        $(this).children('span.link').text('Закрыть');
    },function()
    {
        $('div.price-list-place div.background').fadeOut("slow");
        $('div.price-list-place div.price-lists div.files').fadeOut("slow");
        setTimeout(function () {
          $('div.price-list-place div.price-lists a.price span').css('width', '144px');
          $('div.price-list-place div.price-lists a.price span').text('Скачать весь прайс-лист');
          $('div.price-list-place div.price-lists').removeClass("active");
        }, 400);
    });

    // Filter -----------------------------------------------------------------------------------------------

    $('a.show-all-options').toggle(function()
    {
        $('div.block-filter div.filters form.catalog_filter div.com').slideDown("slow");
        $(this).text('Скрыть');
    },function()
    {
        $('div.block-filter div.filters form.catalog_filter div.com').slideUp("slow");
        $(this).text('Расширенный фильтр');
    });

    // Sort :: Add active class -----------------------------------------------------------------------------

    current_href = window.location.href;

    if (current_href.indexOf('&order_filter%5Bprice%5D') != '-1')
    {
        $('div.sort a.price_sort').addClass('active_sort');
        $('div.sort a.name_sort').removeClass('active_sort');
        $('div.sort a.count_sort').removeClass('active_sort');
    }
    if (current_href.indexOf('&order_filter%5Bname%5D') != '-1')
    {
        $('div.sort a.name_sort').addClass('active_sort');
        $('div.sort a.price_sort').removeClass('active_sort');
        $('div.sort a.count_sort').removeClass('active_sort');
    }
    if (current_href.indexOf('&order_filter%5Bcount%5D') != '-1')
    {
        $('div.sort a.count_sort').addClass('active_sort');
        $('div.sort a.name_sort').removeClass('active_sort');
        $('div.sort a.price_sort').removeClass('active_sort');
    }

    // Catalog View Mode :: Call Function -------------------------------------------------------------------

    $('div.main div.wrapper div.catalog h3.open span.button').toggle(function()
    {
        $('div.main div.wrapper div.catalog div.category.list ul.layer-two').slideDown("slow");
        $('div.main div.wrapper div.catalog h3.open span.button').text("Свернуть");
        $('div.main div.wrapper div.catalog div.category ul.layer-one li.layer-one').css("padding-bottom","30px");
        $('div.main div.wrapper div.catalog h3.open span.arrow').text("↑");
    },function()
    {
        $('div.main div.wrapper div.catalog div.category.list ul.layer-two').slideUp("slow");
        $('div.main div.wrapper div.catalog h3.open span.button').text("Развернуть");
        $('div.main div.wrapper div.catalog div.category ul.layer-one li.layer-one').css("padding-bottom","16px");
        $('div.main div.wrapper div.catalog h3.open span.arrow').text("↓");
    });

    // View Mode :: Call Function ---------------------------------------------------------------------------

    $('#table').click(function()
    {
        $.get('/udata/custom/set_way_catalog/tree', function(data) {
            location.reload();
        });
    });

    $('#line').click(function()
    {
        $.get('/udata/custom/set_way_catalog/line', function(data) {
            location.reload();
        });
    });

    $('#big').click(function()
    {
        $.get('/udata/custom/set_view_style/biggy', function(data) {
            location.reload();
        });
	});

	$('#small').click(function()
    {
        $.get('/udata/custom/set_view_style/small', function(data) {
            location.reload();
        });
	});

    // Change Amount on Compare page -------------------------------------------------------

    $('div.compare_items div.items div.item div.line div.com div.obj_info div.buy_info div.add div.basket div.count a.plus').click(function()
    {
        old_input_value = $(this).parent().children("input.number").val();
        in_basket_now = $(this).parent().children("input.amount").val();
        new_basket_amount = parseInt(in_basket_now) + 1;
        new_input_value = parseInt(old_input_value) + 1;
        $(this).parent().children("input.amount").val(new_basket_amount);
        $(this).parent().children("input.number").val(new_input_value);
    });

    $('div.compare_items div.items div.item div.line div.com div.obj_info div.buy_info div.add div.basket div.count a.minus').click(function()
    {
        old_input_value = parseInt($(this).parent().children("input.number").val());
        if (parseInt(old_input_value) > 1)
        {
            new_input_value = parseInt(old_input_value) - 1;
            in_basket_now = $(this).parent().children("input.amount").val();
            new_basket_amount = parseInt(in_basket_now) - 1;
            $(this).parent().children("input.amount").val(new_basket_amount);
            $(this).parent().children("input.number").val(new_input_value);
        }
    });

    $('div.compare_items div.items div.item div.line div.com div.obj_info div.buy_info div.add div.basket div.count input.number').change(function()
    {
        old_input_value = parseInt($(this).parent().children("input.number").val());
        in_basket_now = parseInt($(this).parent().children("input.amount").val());
        $(this).parent().children("input.amount").val(old_input_value + in_basket_now - 1);
    });

    // Numpages Controls ------------------------------------------------------------------------------------

    numpages = $("div.content div.numpages").html();

    if (numpages)
    {
        news_count = $("div.content div.numpages div.pages a").length;
        $("div.content div.numpages div.description span.total").text(news_count);
        active_count = $("div.content div.numpages div.pages a.active").index();
        $("div.content div.numpages div.description span.active").text(active_count+1);
    }

    // Login Form -------------------------------------------------------------------------------------------

    $('div.main div.wrapper div.header div.login div.com a.enter').toggle(function()
    {
        $('div.main div.wrapper div.header div.login div.com div.form').fadeIn("slow");
        $('div.main div.wrapper div.header div.login div.com a.enter').text("Закрыть");
    }
    ,function()
    {
        $('div.main div.wrapper div.header div.login div.com div.form').fadeOut("slow");
        setTimeout(function () { $('div.main div.wrapper div.header div.login div.com a.enter').text("Войдите"); }, 400);
    });

    // Change Amount on Category View page on 3'rd root -------------------------------------------------------

    $('div.left_block div.spec_blocks div.items div.item div.basket div.count a.plus').click(function()
    {
        old_input_value = $(this).parent().children("input.number").val();
        in_basket_now = $(this).parent().children("input.amount").val();
        new_basket_amount = parseInt(in_basket_now) + 1;
        new_input_value = parseInt(old_input_value) + 1;
        $(this).parent().children("input.amount").val(new_basket_amount);
        $(this).parent().children("input.number").val(new_input_value);
    });

    $('div.left_block div.spec_blocks div.items div.item div.basket div.count a.minus').click(function()
    {
        old_input_value = parseInt($(this).parent().children("input.number").val());
        if (parseInt(old_input_value) > 1)
        {
            new_input_value = parseInt(old_input_value) - 1;
            in_basket_now = $(this).parent().children("input.amount").val();
            new_basket_amount = parseInt(in_basket_now) - 1;
            $(this).parent().children("input.amount").val(new_basket_amount);
            $(this).parent().children("input.number").val(new_input_value);
        }
    });

    $('div.left_block div.spec_blocks div.items div.item div.basket div.count input.number').change(function()
    {
        old_input_value = parseInt($(this).parent().children("input.number").val());
        in_basket_now = parseInt($(this).parent().children("input.amount").val());
        $(this).parent().children("input.amount").val(old_input_value + in_basket_now - 1);
    });

    // Change Amount on Category View page ------------------------------------------------------------------

    $('div.left_block div.catalog div.objects div.basket div.count a.plus').click(function()
    {
        old_input_value = $(this).parent().children("input.number").val();
        in_basket_now = $(this).parent().children("input.amount").val();
        new_basket_amount = parseInt(in_basket_now) + 1;
        new_input_value = parseInt(old_input_value) + 1;
        $(this).parent().children("input.amount").val(new_basket_amount);
        $(this).parent().children("input.number").val(new_input_value);
    });

    $('div.left_block div.catalog div.objects div.basket div.count a.minus').click(function()
    {
        old_input_value = parseInt($(this).parent().children("input.number").val());
        if (parseInt(old_input_value) > 1)
        {
            new_input_value = parseInt(old_input_value) - 1;
            in_basket_now = $(this).parent().children("input.amount").val();
            new_basket_amount = parseInt(in_basket_now) - 1;
            $(this).parent().children("input.amount").val(new_basket_amount);
            $(this).parent().children("input.number").val(new_input_value);
        }
    });

    $('div.left_block div.catalog div.objects div.basket div.count input.number').change(function()
    {
        old_input_value = parseInt($(this).parent().children("input.number").val());
        in_basket_now = parseInt($(this).parent().children("input.amount").val());
        $(this).parent().children("input.amount").val(old_input_value + in_basket_now - 1);
    });

    // Change Amount on Special Offers page -----------------------------------------------------------------

    $('div.main div.wrapper div.offers div.right div.items div.item div.basket div.count a.plus').click(function()
    {
        old_input_value = $(this).parent().children("input.number").val();
        in_basket_now = $(this).parent().children("input.amount").val();
        new_basket_amount = parseInt(in_basket_now) + 1;
        new_input_value = parseInt(old_input_value) + 1;
        $(this).parent().children("input.amount").val(new_basket_amount);
        $(this).parent().children("input.number").val(new_input_value);
    });

    $('div.main div.wrapper div.offers div.right div.items div.item div.basket div.count a.minus').click(function()
    {
        old_input_value = parseInt($(this).parent().children("input.number").val());
        if (parseInt(old_input_value) > 1)
        {
            new_input_value = parseInt(old_input_value) - 1;
            in_basket_now = $(this).parent().children("input.amount").val();
            new_basket_amount = parseInt(in_basket_now) - 1;
            $(this).parent().children("input.amount").val(new_basket_amount);
            $(this).parent().children("input.number").val(new_input_value);
        }
    });

    $('div.main div.wrapper div.offers div.right div.items div.item div.basket div.count input.number').change(function()
    {
        old_input_value = parseInt($(this).parent().children("input.number").val());
        in_basket_now = parseInt($(this).parent().children("input.amount").val());
        $(this).parent().children("input.amount").val(old_input_value + in_basket_now - 1);
    });

    // Change Amount on Search Results page -----------------------------------------------------------------

    $('div.search_results div.item-line-small div.information div.basket div.count a.plus').click(function()
    {
        old_input_value = $(this).parent().children("input.number").val();
        in_basket_now = $(this).parent().children("input.amount").val();
        new_basket_amount = parseInt(in_basket_now) + 1;
        new_input_value = parseInt(old_input_value) + 1;
        $(this).parent().children("input.amount").val(new_basket_amount);
        $(this).parent().children("input.number").val(new_input_value);
    });

    $('div.search_results div.item-line-small div.information div.basket div.count a.minus').click(function()
    {
        old_input_value = parseInt($(this).parent().children("input.number").val());
        if (parseInt(old_input_value) > 1)
        {
            new_input_value = parseInt(old_input_value) - 1;
            in_basket_now = $(this).parent().children("input.amount").val();
            new_basket_amount = parseInt(in_basket_now) - 1;
            $(this).parent().children("input.amount").val(new_basket_amount);
            $(this).parent().children("input.number").val(new_input_value);
        }
    });

    $('div.search_results div.item-line-small div.information div.basket div.count input.number').change(function()
    {
        old_input_value = parseInt($(this).parent().children("input.number").val());
        in_basket_now = parseInt($(this).parent().children("input.amount").val());
        $(this).parent().children("input.amount").val(old_input_value + in_basket_now - 1);
    });

    // Change Amount on Catalog Item page -------------------------------------------------------------------

    $('div.catalog div.item div.operations div.buttons div.add_basket div.count a.plus').click(function()
    {
        old_input_value = $(this).parent().children("input.number").val();
        in_basket_now = $(this).parent().children("input.amount").val();
        new_basket_amount = parseInt(in_basket_now) + 1;
        new_input_value = parseInt(old_input_value) + 1;
        $(this).parent().children("input.amount").val(new_basket_amount);
        $(this).parent().children("input.number").val(new_input_value);
    });

    $('div.catalog div.item div.operations div.buttons div.add_basket div.count a.minus').click(function()
    {
        old_input_value = parseInt($(this).parent().children("input.number").val());
        if (parseInt(old_input_value) > 1)
        {
            new_input_value = parseInt(old_input_value) - 1;
            in_basket_now = $(this).parent().children("input.amount").val();
            new_basket_amount = parseInt(in_basket_now) - 1;
            $(this).parent().children("input.amount").val(new_basket_amount);
            $(this).parent().children("input.number").val(new_input_value);
        }
    });

    $('div.catalog div.item div.operations div.buttons div.add_basket div.count input.number').change(function()
    {
        old_input_value = parseInt($(this).parent().children("input.number").val());
        in_basket_now = parseInt($(this).parent().children("input.amount").val());
        $(this).parent().children("input.amount").val(old_input_value + in_basket_now - 1);
    });

    // Change Amount on Catalog Item page on Recommended Block ----------------------------------------------

    $('div.catalog div.item div.left-block-item div.recommended_items div.item div.basket div.count a.plus').click(function()
    {
        old_input_value = $(this).parent().children("input.number").val();
        in_basket_now = $(this).parent().children("input.amount").val();
        new_basket_amount = parseInt(in_basket_now) + 1;
        new_input_value = parseInt(old_input_value) + 1;
        $(this).parent().children("input.amount").val(new_basket_amount);
        $(this).parent().children("input.number").val(new_input_value);
    });

    $('div.catalog div.item div.left-block-item div.recommended_items div.item div.basket div.count a.minus').click(function()
    {
        old_input_value = parseInt($(this).parent().children("input.number").val());
        if (parseInt(old_input_value) > 1)
        {
            new_input_value = parseInt(old_input_value) - 1;
            in_basket_now = $(this).parent().children("input.amount").val();
            new_basket_amount = parseInt(in_basket_now) - 1;
            $(this).parent().children("input.amount").val(new_basket_amount);
            $(this).parent().children("input.number").val(new_input_value);
        }
    });

    $('div.catalog div.item div.left-block-item div.recommended_items div.item div.basket div.count input.number').change(function()
    {
        old_input_value = parseInt($(this).parent().children("input.number").val());
        in_basket_now = parseInt($(this).parent().children("input.amount").val());
        $(this).parent().children("input.amount").val(old_input_value + in_basket_now - 1);
    });

    // Choose Creator on Item Page ----------------------------------------------------------------------------

    $('div.proizvoditels ul.proizvoditels').toggle(function()
    {
        $('div.proizvoditels ul.proizvoditels').css("overflow", "visible");
        $('div.proizvoditels ul.proizvoditels').css("padding-top", "28px");
        $('div.proizvoditels ul.proizvoditels li').css("display", "block");
        $('div.proizvoditels ul.proizvoditels li').css("background-color", "#FFF");
    }
    ,function()
    {
        $('div.proizvoditels ul.proizvoditels').css("overflow", "hidden");
        $('div.proizvoditels ul.proizvoditels').css("padding-top", "0px");
        $('div.proizvoditels ul.proizvoditels li').css("background-color", "");

        var checked_option = $('div.proizvoditels ul.proizvoditels li.active').index();

        $('div.proizvoditel-options input').eq(checked_option).click();

        $('div.proizvoditels ul.proizvoditels li').css("display", "none");
        $('div.proizvoditels ul.proizvoditels li.active').css("display", "block");

    });

    $('div.proizvoditels ul.proizvoditels li').click(function()
    {

        proizvoditel_change = true;

        $('div.proizvoditels ul.proizvoditels li').removeClass('active');
        $(this).addClass('active');
        var pro = parseInt($('div.proizvoditels ul.proizvoditels li.active').children('span.value').text());
        var mod = parseInt($('div.models ul.models li.active').children('span.value').text());
        $('div.catalog div.item div.price div.value').html(pro + mod + ' <span class="rub">a</span>');
    });

    // Choose Color on Item Page ----------------------------------------------------------------------------

    $('div.colors ul.colors').toggle(function()
    {
        $('div.colors ul.colors').css("padding-top", "28px");
        $('div.colors ul.colors li').css("display", "block");
        $('div.colors ul.colors li').css("background-color", "#FFF");
    }
    ,function()
    {
        $('div.colors ul.colors').css("padding-top", "0px");
        $('div.colors ul.colors li').css("background-color", "");

        var checked_option = $('div.colors ul.colors li.active').index();

        $('div.color-options input').eq(checked_option).click();

        $('div.colors ul.colors li').css("display", "none");
        $('div.colors ul.colors li.active').css("display", "block");

    });

    $('div.colors ul.colors li').click(function()
    {
        $('div.colors ul.colors li').removeClass('active');
        $(this).addClass('active');
    });

    // Choose Maps on Contacts Page -------------------------------------------------------------------------

    $('div.maps div.left-block div.adress div.link span').click(function(){
        $('div.maps div.left-block div.adress.active').removeClass('active');
        $(this).parent().parent().addClass('active');
        index = $(this).parent().parent().index();
		
		YMaps.jQuery(function ()
		{
			if (index == 0)
			{
				var point_2 = new YMaps.GeoPoint(44.009553,56.320957);
				map.setCenter(point_2);
				placemark_2.openBalloon();
			}
			else
			{
				if (index == 1)
				{
					var point_3 = new YMaps.GeoPoint(44.003112,56.316823);
					map.setCenter(point_3);
					placemark_3.openBalloon();
				}
				else
				{
					(index == 2)
					{
						var point_1 = new YMaps.GeoPoint(44.069908,56.308475);
						map.setCenter(point_1);
						placemark_1.openBalloon();
					}
				}
			}	
		});
    });

    // Choose Model on Item Page ----------------------------------------------------------------------------

    $('div.models ul.models').toggle(function()
    {
        if (proizvoditel_change == true)
        {
            $('div.models ul.models').css("overflow", "visible");
            $('div.models ul.models').css("padding-top", "28px");
            $('div.models ul.models li').css("display", "block");
            $('div.models ul.models li').css("background-color", "#FFF");
        }
    }
    ,function()
    {
        if (proizvoditel_change == true)
        {
            $('div.models ul.models').css("overflow", "hidden");
            $('div.models ul.models').css("padding-top", "0px");
            $('div.models ul.models li').css("background-color", "");

            var checked_option = $('div.models ul.models li.active').index();

            $('div.model-options input').eq(checked_option).click();

            $('div.models ul.models li').css("display", "none");
            $('div.models ul.models li.active').css("display", "block");
        }
    });

    $('div.models ul.models li').click(function()
    {
        if (proizvoditel_change == true)
        {
            $('div.models ul.models li').removeClass('active');
            $(this).addClass('active');
            var pro = parseInt($('div.proizvoditels ul.proizvoditels li.active').children('span.value').text());
            var mod = parseInt($('div.models ul.models li.active').children('span.value').text());
            $('div.catalog div.item div.price div.value').html(pro + mod + ' <span class="rub">a</span>');
        }
    });

    // Payment Item -------------------------------------------------------------------------------------------

    var yur_status_count = $('div.status select option').length;
    var selected_id = 0;

    for (var k = 0; k < yur_status_count; k++)
    {
        var yur_status = $('div.status select option').eq(k).attr('selected');

        if (yur_status == true)
        {
            selected_id = $('div.status select option').eq(k).index();
        }
    }

    if (selected_id == 0)
        {
            $('div.reg-form-payment input').css('display', 'none');
            $('div.reg-form-payment input').eq(0).css('display', 'block');
            $('div.reg-form-payment input').eq(0).attr('checked', 'checked');
            $('div.reg-form-payment input').eq(1).css('display', 'block');
            $('div.reg-form-payment label').css('display', 'none');
            $('div.reg-form-payment label').eq(0).css('display', 'block');
            $('div.reg-form-payment label').eq(1).css('display', 'block');
        }

        if (selected_id == 1)
        {
            $('div.reg-form-payment input').css('display', 'block');
            $('div.reg-form-payment label').css('display', 'block');
        }

        if (selected_id == 2)
        {
            $('div.reg-form-payment input').css('display', 'none');
            $('div.reg-form-payment input').eq(1).css('display', 'block');
            $('div.reg-form-payment input').eq(1).attr('checked', 'checked');
            $('div.reg-form-payment input').eq(2).css('display', 'block');
            $('div.reg-form-payment label').css('display', 'none');
            $('div.reg-form-payment label').eq(1).css('display', 'block');
            $('div.reg-form-payment label').eq(2).css('display', 'block');
        }

});

