﻿// requires String.format prototype provided in global.js

function PayPalPresenter(view) {

    this.view = view;
    this.account = "paypal";

    this.submit = function() {
        this.view.business.value = "{0}@{1}".format(this.account, document.domain.replace("www.", ""));
        this.view.no_note.value = "1";
        this.view.tax.value = "0";
        this.view.currency_code.value = "USD";
        this.view.lc.value = "US";
        this.view.action = "https://www.paypal.com/cgi-bin/webscr";
        this.view.submit();
    }

//    this.addToCart = function() {
//        this.view.add.value = "1";
//        this.view.cmd.value = "_cart";
//        this.view.item_name.value = this.view.selectedPayPalItem.itemName.value;
//        this.view.item_number.value = this.view.selectedPayPalItem.itemNumber.value;
//        this.view.amount.value = this.view.selectedPayPalItem.itemPrice.value;
//        this.view.shipping.value = this.view.selectedPayPalItem.itemShipping.value;
//        this.view.no_shipping.value = "0";
//        this.view.bn.value = "PP-ShopCartBF";
//        this.submit();
//    }

    this.makeDonation = function() {
        this.view.add.value = "0";
        this.view.cmd.value = "_xclick";
        this.view.item_name.value = "Donations";
        this.view.item_number.value = "";
        this.view.amount.value = "";
        this.view.shipping.value = "";
        this.view.no_shipping.value = "1";
        this.view.bn.value = "PP-DonationsBF";
        this.submit();
    }

    this.constructor = function() {
    }
}

function _MakeDonation_Click(sender, e) {
    try {
        document.payPalPresenter.makeDonation();
    }
    catch (err) {
        alert(err.description);
    }
}

//function _AddToCart_Click(sender, e) {
//    try {
//        sender.form.selectedPayPalItem = sender;
//        document.payPalPresenter.addToCart();
//    }
//    catch (err) {
//        alert(err.description);
//    }
//}
