﻿function confirmPayment() {
    var manualConfirmMessage = "Do you wish to complete manual payment ? ";

    if (type == "O") {
        var ptype = $('#DropDownListPaymentType').val();
        if (ptype == 'C') {
            return confirm('You have selected payment by check.\r\n\r\nAre you ready to submit your registration ?');
        }
        else {
            return confirm('You have selected payment by credit card.\r\n\r\nAre you ready to begin to the credit card payment process ? ')
        }   
    }
    else {
        var mc = $("#ManualCostField").val();
        var mcNumber = Number(mc.replace(/[^0-9\.]+/g, ""));
        if (mcNumber == 0) {
            alert("Cost cannot be 0!!");
            return false;
        }
        var tc = $("#TotalCostField").val();
        var tcNumber = Number(tc.replace(/[^0-9\.]+/g, ""));

        if (mcNumber != tcNumber) {
            if (!confirm("Total cost entered is not equal to system calculated cost.\r\nDo you wish to override cost ?"))
            {
                return false;
            }
            manualConfirmMessage = "Do you wish to complete manual payment with cost override ?";
        }

        return confirm(manualConfirmMessage);
    }
}

function processPaymentButtonState() {
    if (type == "O") {
        var ptype = $('#DropDownListPaymentType').val();
        if ((ptype != undefined) && (ptype != 'X')) {
            $('#buttonPayment').removeAttr('disabled');
        }
        else {
            $('#buttonPayment').attr('disabled', 'disabled');
        }
    }
    else {
        $('#buttonPayment').removeAttr('disabled');
    }
}

function displayPaymentTypeMessage(value) {
    if (value == 'X') {
        $("#paymentmessage").text('Please select a payment type');
        $('#buttonPayment').attr('disabled', 'disabled');
    }
    else if (value == 'C') {
        $("#paymentmessage").text('If paying by check, click on the Finish button. Please note that registration will be complete after we receive the check.');
        $('#buttonPayment').removeAttr('disabled');
    }
    else if (value == 'P') {
        $("#paymentmessage").text('If paying by credit card, you will be directed to the PayPal site where you will enter your credit card details.\nPlease note that registration will be complete only after we receive the payment from PayPal.');
        $('#buttonPayment').removeAttr('disabled');
    }
}
