function get_summa()
{
        if(!$("#sub_btn"))
        {
                return;
        }
        $("#sub_btn").attr("disabled", "disabled");
        var dst  = $("#new_date_start_z").val();
        var dsp  = $("#new_date_stop_z").val();
        var curr = 0;
        if ($("#currency")) {
          curr = $("#currency").val();
        }
        
        if(dst > dsp)
        {
                $("#sub_btn").removeAttr("disabled");
                $("#price").val("ошибка дат!");
                return false;
        }
        $("#price").val("ждите...");
        $.ajax(
        {
                type: "POST",
                url: "get_summa.php",
                data: ({
                        id: $("#id").val(),
                        new_date_start: dst,
                        new_date_stop: dsp,
                        "tempory_currency" : curr
                }),
                success: function(data)
                {
                        //console.log(this);
                        if(parseInt(data) <= 0)
                        {
                            $("#price").val("ошибка дат!");
                        }
                        else
                        {
                            $("#price").val(data);
                        }
                        $("#sub_btn").removeAttr("disabled");
                },
                cache: false,
                async: false
        });
}

function get_summa_tz()
{
    if(!$("#tempory_sum"))
    {
            return;
    }
    var dst = $("#new_date_start_tz").val();
    var dsp = $("#new_date_stop_tz").val();
    if(dst >= dsp)
    {
            $("#tempory_sum").val("ошибка дат!");
            return false;
    }
    $(".left:has(.load_box),.right:has(.load_box)").each(function ()
    {
        var parent_element = $(this);
        if($.browser.msie && $.browser.version == '6.0')
        {
            $(".tempory_currency").hide();
        }
        parent_element.find(".load_box").show().height(parent_element.height()).find("img").position(
        {
            of: parent_element,
            my: "center center",
            at: "center center"
        });
    });
    //$(".load_box").bgiframe();
    //$(".table-tarif:has(#tz_tarifs_list)").slideUp(800);
    //$(".table-tarif:has(#tempory_sum)").slideUp(800, function()
    //{        
        $("#tempory_sum").val("ждите...");
        $.ajax(
        {
                type: "POST",
                url: "get_summa.php",
                data: ({
                        "id": $("#id").val(),
                        "new_date_start": dst,
                        "new_date_stop": dsp,
                "tempory_currency": $(".tempory_currency").val()
                }),
                success: function(data)
                {
                $("#tempory_sum").val(data);
                $.ajax(
                {
                        type: "POST",
                        url: "get_tarifs_list.php",
                        data: ({
                                "id": $("#id").val(),
                                "new_date_start": dst,
                                "new_date_stop": dsp,
                        "tempory_currency": $(".tempory_currency").val()
                        }),
                        success: function(data)
                        {
                        $("#tz_tarifs_list").html(data);
                        /*
                        setTimeout(function()
                        {                       
                            $(".table-tarif:has(#tz_tarifs_list)").slideDown(800);
                            $(".table-tarif:has(#tempory_sum)").slideDown(800);
                        }, 100);
                        */
                        //$(".table-tarif").slideDown(600); 
                        $(".left:has(.load_box),.right:has(.load_box)").each(function ()
                        {
                            $(this).find(".load_box").hide();
                        });
                        if($.browser.msie && $.browser.version == '6.0')
                        {
                            $(".tempory_currency").show();
                        }
                        }
                });
                },
            error: function()
            {
                $("#tempory_sum").val("ошибка!");
            }
        });
    //});
}

$(document).ready(function()
{
    $(".tempory_currency").change(function ()
    {
        $(".tempory_currency").val($(this).val());
        get_summa_tz();
    }); 
    
    $("#recount_btn").click(function(){get_summa_tz();return false;});
    
    var dst = $("#new_date_start_tz").val();
    var dsp = $("#new_date_stop_tz").val();
    if(dst >= dsp)
    {
        $("#tempory_sum").val("ошибка дат!");
        return;
    }    
    if(!$("#tempory_sum"))
    {
            return;
    }
    $.ajax(
    {
        type: "POST",
        url: "get_summa.php",
        data: ({
                "id": $("#id").val(),
                "new_date_start": dst,
                "new_date_stop": dsp,
                "tempory_currency": $(".tempory_currency").val()
        }),
        success: function(data)
        {
            $("#tempory_sum").val(data);
        }
    });
    if($.browser.msie && ($.browser.version == '6.0' || $.browser.version == '7.0'))
    {
        $(".load_box").css("margin-left", "-7px");
    }
});
