// JavaScript Document

function getsavecurrentvalue()
{
    var saveid = document.getElementById("saveid").value;

    if (saveid != "-1")
    {


        //get savefrom value
        $.ajax({
            url: 'settlementsaveAjaxController.php?do=getSaveValue&saveId=' + saveid,
            success: function (x) {


                document.getElementById("savedailysavebefore").value = x;
                document.getElementById("savedailysaveafter").value = x;

                checksaveValue();


            }
        });
    }

}

function checksaveValue()
{
    var savedailysavebefore = Number(document.getElementById("savedailysavebefore").value);
    var savedailychangeamount = Number(document.getElementById("savedailychangeamount").value);
    var savedailysaveafter = Number(document.getElementById("savedailysaveafter").value);

    var discountvalue = document.getElementById("discountvalue").checked;
    var addvalue = document.getElementById("addvalue").checked;

    if (discountvalue == true)
    {
//        if (savedailychangeamount > savedailysavebefore)
//        {
//            document.getElementById("savedailychangeamount").value = savedailysavebefore;
//        }

        document.getElementById("savedailysaveafter").value = Number(document.getElementById("savedailysavebefore").value) - Number(document.getElementById("savedailychangeamount").value);
    }


    else if (addvalue == true)
    {

        document.getElementById("savedailysaveafter").value = Number(document.getElementById("savedailysavebefore").value) + Number(document.getElementById("savedailychangeamount").value);
    }

}

$('#subbtn').live('click', function (e) {
    var saveid = $('#saveid').val();
    if (saveid == '-1') {
        $('#saveError').show();
        $('#saveError').html("<p style='width: 65px;color: #CC3333;border: 1px solid #CC3333;'>*اختر خزنة</p>");
    } else {
        $('#saveError').hide();
        $('#myform').submit();
        $(this).attr("disabled", true);
    }
});






function checkaddvalue()
{
    var savedailysavebefore = Number(document.getElementById("savedailysavebefore").value);
    var savedailychangeamount = Number(document.getElementById("savedailychangeamount").value);

    document.getElementById("savedailysaveafter").value = Number(document.getElementById("savedailysavebefore").value) + Number(document.getElementById("savedailychangeamount").value);
}







function checkdiscountvalue()
{
    var savedailysavebefore = Number(document.getElementById("savedailysavebefore").value);
    var savedailychangeamount = Number(document.getElementById("savedailychangeamount").value);

    if (savedailychangeamount > savedailysavebefore)
    {
        document.getElementById("savedailychangeamount").value = savedailysavebefore;
    }

    document.getElementById("savedailysaveafter").value = Number(document.getElementById("savedailysavebefore").value) - Number(document.getElementById("savedailychangeamount").value);
}
