function ajaxNoCache() {
    $.ajaxSetup({
        cache: true
    });
}

function DeleteItem(id) {

    $('#order_item' + id).css('background', '#fcf5da');
    $('#order_item' + id).slideToggle('slow', function () {
        $(this).remove();
        $.ajax({
            url: "/orders/delete/",
            type: 'POST',
            data: "id=" + id,
            success: function (data) {
                $(".ordrhldr").html(data);
            }
        });
    });
    return false;
}






$(document).ready(function () {
                    
    $('body').ajaxStart(function() {
        $('input[type=submit]', this).attr('disabled', 'disabled');
    });
                        
    $('body').ajaxStop(function() {
        $("input[type=submit]").removeAttr("disabled");
    });
                    

    $('#LoginForm_username').focus(function () {
        if ($(this).val() == 'почта') {
            $(this).val('').css("color", "#000").css("font-style", "normal");
        }
    }).blur(function () {
        if ($(this).val() == '') {
            $(this).val('почта').css("color", "#999").css("font-style", "italic");
        }
    });



    $('#LoginForm_fakepassword').focus(function () {
        $(this).hide();
        $('#LoginForm_password').show().focus();
    });

    $('#LoginForm_password').focusout(function () {

        if ($(this).val() == '') {

            $(this).hide();
            $('#LoginForm_fakepassword').show();

        }


    });






    $(window).scroll(function () {
        if ($(this).scrollTop() > 100) $('a#move_up').fadeIn();
        else $('a#move_up').fadeOut(400);
    });
    $('a#move_up').click(function () {
        $('body,html').animate({
            scrollTop: 0
        }, 50);
        return false;
    });


    $(".sbmenu table tr").hover(

        function () {
            $(this).addClass("sbhover");
        }, function () {
            $(this).removeClass("sbhover");
        });
    $(".conprice tbody tr[class!='premarker']").hover(

        function () {
            $(this).addClass("cphover");
        }, function () {
            $(this).removeClass("cphover");
        });

    $('#fullmenu ul li').hover(

        function () {
            var cl = $(this).attr('id');
            cl = cl.slice(1);
            $(this).addClass("active");
            var x = $(this).offset().left - $("#page").offset().left;
            var fixx = $('#page').width() - x - $('div#' + cl).width();
            if (fixx < 0) {
                x = x + fixx - 30;
            }
            var y = $(this).offset().top + $(this).height() + 24;
            if ($.browser.msie && $.browser.version == 6) {
                y = y - 14;
            }
            $('div#' + cl).css('left', x).css('top', y);
            $('div#' + cl).show();
        }, function () {

            var cl = $(this).attr('id');
            cl = cl.slice(1);
            var menu = $(this);
            var submenu = $('div#' + cl);
            var closeTO = setTimeout(function () {
                submenu.hide();
                menu.removeClass("active");
            }, 50);
            submenu.hover(function () {
                clearTimeout(closeTO);
            }, function () {
                submenu.hide();
                menu.removeClass("active");
            });
        });
    $('#dopinfo').hide();
    $('.dopinfo').click(function () {
        $('#dopinfo').toggle();
        return false;
    });
    $('.yad_block').click(function () {
        $('#yad_block').toggle();
        return false;
    });




    ajaxNoCache();

    $("a.formPage").click(function () {
        $("#formContainer").load(this.href, function () {
            ajaxNoCache();
        });
        return false;
    });


                


});
                
function log(event, data, formatted) {
    $('#f\\:deliveryaddressstation_id').val(!data ? "" : formatted.match(/\d+(?=\))/mi));
}
                
$.fn.serializeObject = function () {
    var o = {};
    var a = this.serializeArray();
    $.each(a, function () {
        if (o[this.name] !== undefined) {
            if (!o[this.name].push) {
                o[this.name] = [o[this.name]]
            }
            o[this.name].push(this.value || '')
        } else {
            o[this.name] = this.value || ''
        }
    });
    return o
};
