/************************************************************

	Functions and variables to handle custom transactions.

*************************************************************/


/*
	Called when the installments option is clicked.
*/
function handleRecur() {
	
	var recurr_payment = document.getElementById('recurr_payment');
	var doRecur = document.getElementById('doRecur');
	var recurAmount = document.getElementById('recurAmount');
	var charge_total = document.getElementById('charge_total');
	
	var numPayments = 3;
	

	if(recurr_payment.checked) {
	
		doRecur.value = "1";
		// note: billableTotal can be found in the nopcart.js file under ManageCart()
		var paymentAmount = billableTotal/numPayments;
		recurAmount.value =  paymentAmount.toFixed(2);
		
		// The first payment recurring payment needs to be
		// set as the charge_total... they will be billed 
		// immediately for this
		charge_total.value = paymentAmount.toFixed(2);
		
	} else {
		
		doRecur.value = "0";
		// Return the total chart to billabletotal ... not the recur payment
		charge_total.value = billableTotal;
		
	}

		

}




/*
	Update the product code when selecting different member cards.
*/
function updateMembershipID_NUM(priceValue) {
	var ID_NUM = document.getElementById('ID_NUM');
	ID_NUM.value = 'member_card_'+priceValue;
	
}


/**
	Only allow the user to continue if they have selected a membership
*/
function verifyMembershipPurchase() {	
	//alert(SelectedAMembership);
	hasMembership = GetCookie("SelectedAMembership");
	
	if (hasMembership == null) hasMembership = 0;
	
	hasDebit = GetCookie("SelectedADebitMembership");
	if (hasDebit == null) hasDebit = 0;
	
	if(hasMembership == 1 || hasDebit == 1) {
		return true;		
	} else {
		alert("You must purchase at least one Membership to continue.");
		return false;
	}
	
}

function isLastMembership() {
	alert("Removed membership with num left = "+numMembershipsSelected);
	if(numMembershipsSelected <= 0) {
		alert("You must purchase at least one Membership to continue.");
		numMembershipsSelected = 0;
		SelectedAMembership = false;
		location.href="memberships.html";
	}
}

function verifyClubCardPurchase() {
	hasMembership = GetCookie("SelectedAMembership");
	if (hasMembership == null) hasMembership = 0;
	hasDebit = GetCookie("SelectedADebitMembership");
	if (hasDebit == null) hasDebit = 0;
	if (hasDebit == 1 && hasMembership == 0) {
		alert("The Club Card cannot be purchased with only a Debit Membership. Please purchase a Traditional membership and try to add the Club Card to your cart again.");
		return false;
	} else if (hasDebit == 0 && hasMembership == 0) {
		alert("The Club Card must be purchased with a Traditional Membership. Please purchase a Traditional Membership and try to add the Club Card to your cart again.");	
		return false;
	} else {
		return true;
	}
}