// JavaScript Document
function CalculateTotal() {
	
	var numAttending = GetInputValue('numAttending');
	// alert(numAttending);
	
	if (numAttending < 10)
		document.getElementById('groupDiscount').selectedIndex = 0;
		
	if (numAttending > 9)
		document.getElementById('groupDiscount').selectedIndex = 1;

	var promoPrice = GetSelectedValue('groupDiscount');
	var promoCode = GetInputValue('promoCode').toUpperCase();
	var promoValue = GetPromoValue();
	// alert(price);
	var price = promoPrice;	
	
	if (promoValue > 0) {
		price = promoValue;
		if (promoCode == "PS07")
			document.getElementById('promoCodeDesc').innerHTML = "$20 DISCOUNT";
		else
			document.getElementById('promoCodeDesc').innerHTML = "$"+promoValue+' RATE';
	} else {
		document.getElementById('promoCodeDesc').innerHTML = "";
	}
	
/*	if (promoPrice == 75 && (promoValue == 55 || promoValue == 0)  && numAttending < 10 && promoCode != 'MEMBER07' ) {
		price = 95;

		alert('You must bring more than 10 people to receive the discount pricing that you have selected');
	}
*/
	
	var totalAmount = numAttending * price;
	//	alert(totalAmount);
	
	var totalsHTML = "Total Amount Due: $"+totalAmount;
	//if (totalAfterPromo < totalAmount)
	//	totalsHTML += "<br />Total After Discount: $"+totalAfterPromo; 
	
	document.getElementById('total').value = totalAmount; // set hidden value
	document.getElementById('totalToCharge').innerHTML = totalsHTML; // show Total Value
}

function GetPromoValue() {
	

	var promoObject = document.getElementById('promoCode');
	var promoValue = promoObject.value.toUpperCase();
	var promoRate = "";
	var promoReturn = 0;
	
	var promoDefined = false;
	
	if (typeof myPromoType[promoValue] != "undefined") {
		promoDefined = true;
		var promoType = myPromoType[promoValue];
	
		if (promoType.length > 0 && promoType == "rate")
			promoRate = myPromoValue[promoValue];
		else {
			var selectedRate = 	GetSelectedValue('groupDiscount');
			if (selectedRate > 0)
				promoRate = (selectedRate - myPromoValue[promoValue]);	
		}
	} else {
		if (promoValue.length > 0)
			alert("'"+promoValue+"' PROMO CODE does not exist");
		//	document.getElementById('promoCodeDesc').innerHTML = ("'"+promoValue+"' PROMO CODE does not exist");	
	}
	
	if (promoRate > 0)
		promoReturn = promoRate;
		
	return promoReturn;
}

function GetInputValue(iId) {
	var theInput = document.getElementById(iId);
	return theInput.value;
}
function GetSelectedValue(iSelectId) {
	var selectedValue = "";
	var theSelect = document.getElementById(iSelectId);
	if( theSelect && theSelect.type && theSelect.type.indexOf("select") == 0 )
		selectedValue = theSelect.value;
	return selectedValue;
}