var bundles = 0, quarters = 1, years = 0, my_total = 0.0, totalQuarters = 0.00;
var level;

var levels = new Array();
levels[0] = Array("Individual", 45.00);
levels[1] = Array("Family (2 Copies/Quarter)", 60.00);
levels[2] = Array("Sponsor (3 Copies/Quarter)", 75.00);
levels[3] = Array("Benefactor (4 Copies/Quarter)", 100.00);
levels[4] = Array("Patron (10 Copies/Quarter)", 200.00);
levels[5] = Array("Life Member", 1000.00);
	
	
function send2Paypal() {
	document.getElementById('item_name').value= "NYCV Bulk Subscription - " + bundles + " Bundle(s), " + totalQuarters + " Quarter(s)";
	document.getElementById('amount').value= my_total;
	document.form.action = "https://www.paypal.com/cgi-bin/webscr";
	//document.form.target = "_blank";
}

function sendIS2Paypal() {
	document.form.action = "https://www.paypal.com/cgi-bin/webscr";
	//document.form.target = "_blank";	
}

function send2PaypalSandbox() {
	document.getElementById('item_name').value= "NYCV Bulk Subscription - " + bundles + " Bundle(s), " + totalQuarters + " Quarter(s)";
	if (document.getElementById('amount')) document.getElementById('amount').value= my_total;
	if (document.getElementById('a3')) {
		document.getElementById('a3').value = my_total;
	}
	
	if (document.getElementById('p3')) {
		document.getElementById('p3').value = totalQuarters * 3;
	}
	
	document.form.action = "https://www.paypal.com/cgi-bin/webscr";
	//document.form.target = "_blank";
}

function setValues() {
	if (document.getElementById('nbrBundles')) bundles = document.getElementById('nbrBundles').value;
	if (document.getElementById('nbrQuarters')) quarters = document.getElementById('nbrQuarters').value;
	//updateSummary();
}

function updateLevel() {
	var index = document.getElementById('level').selectedIndex;
	level = document.getElementById('level').options[index].value;
	//my_total = levels[level][1] * quarters;
	my_total = levels[level][1];
	my_total = my_total.toFixed(2);
	document.getElementById('amount').value = my_total;
	document.form.submit();
}

function updateNbrBundles() {
	bundles = document.getElementById('nbrBundles').value;
	updateSummary();
	document.form.submit();
}

function updateNbrQuarters(type) {

	var index = document.getElementById('nbrQuarters').selectedIndex;
	quarters = document.getElementById('nbrQuarters').options[index].value;
	if (type == 1) {
		my_total = levels[level][1] * quarters;
		my_total = my_total.toFixed(2);
		document.getElementById('amount').value = my_total;
	} else updateSummary();
}

function updateSummary(){
	var my_subtotal = 0.0, my_discount = 0;
	
	totalQuarters = quarters;
	my_subtotal = (totalQuarters * (bundles * 50)) * 1.50;

	//alert(my_subtotal);
	if (totalQuarters > 3) my_discount = my_subtotal * .10;

	//alert(my_discount);
	my_total = my_subtotal - my_discount;
	my_discount = my_discount.toFixed(2);
	my_subtotal = my_subtotal.toFixed(2);
	my_total = my_total.toFixed(2);
	
	document.getElementById('nbrBundlesDiv').innerHTML = bundles;
	document.getElementById('nbrQuartersDiv').innerHTML = totalQuarters;
	document.getElementById('subtotal').innerHTML = my_subtotal;
	document.getElementById('discount').innerHTML = my_discount;
	document.getElementById('total').innerHTML = my_total;
	document.getElementById('orderTotal').value = my_total;
}
