/* Discounting Model
		Author: Shawn Snider
		October 13, 2004

	Product constants are from 0-100
	Service constants are from 100+
	Misc constants (ie: certificates, custom payments) are 200+;
	
	Discounts MUST be written as follows:
	20% discount = 0.2;
	5% discount = 0.05;
	ie: GLOBAL_DISCOUNT = 0.10; represents a 10% discount globally
	
	Only the first discount applies, it returns the discounted value.
*/

var GLOBAL_DISCOUNT = 0;							//All products and services, overwrites product and service discounts
var PRODUCT_DISCOUNT = 0;						//All products only
var SERVICE_DISCOUNT = 0;						//All services only

function getDiscount(itemConstant) {
	//to add product specific discount, do the following
	/*
			if (itemConstant == UNLIMITEDFTP_PRO_SMALL) {
					return 0.20; //20%
			}
	*/
	
	//do global discounts
	if (GLOBAL_DISCOUNT > 0) {
		return GLOBAL_DISCOUNT;
	}
	
	//do product discounts
	if (itemConstant < 100) {
		if (PRODUCT_DISCOUNT > 0) {
			return PRODUCT_DISCOUNT;
		}
	}
	
	if (itemConstant >= 100 && itemConstant < 200) {
		if (SERVICE_DISCOUNT > 0) {
			return SERVICE_DISCOUNT;
		}
	}
	
	return 0;
	
}

function getDiscountedPrice(itemConstant, price) {
    if (document.getElementById('priceDiscount')!=null){
		var DISCOUNT = getDiscount(itemConstant);
		price = price - (price*DISCOUNT);
	
		//update the display
		if (DISCOUNT > 0) {
			document.getElementById('priceDiscount').innerHTML='Price includes ' + (DISCOUNT * 100) + '% discount.';  
		} else {
			document.getElementById('priceDiscount').innerHTML='';
		}
	}
	return price;
	
}