
// Calculates the booking costs

var LOWEST_COST = 20;
var MASTER_SLOT_WEIGHTING = 2;
var SESSION_SLOT_USE_WEIGHTING = 1;
//var MASTER_CODES = ['XCFASE4', 'XCFAIC1', 'XCFBSE1', 'XCFBSM4'];
var MASTER_CODES = ['ASE4', 'AIC1', 'BSE1', 'BSM4'];
var EARLY_BIRD_DISCOUNT = 0.01  //10%
var SLOT_COSTS = [30,30,25,25]; // other slots cost 20;

// Early bird discount date
var EARLY_BIRD_DISCOUNT_BY_DATE = new Date().setFullYear(2010,03,05);
var EARLY_BIRD_DISCOUNT_RATE = 0.0 // 10% = 0.10 which has been changed to zero to remove the discount

var number_of_slots = 0;


function isEarlyBirdDiscountDate()
{
	var today = new Date();

	if (EARLY_BIRD_DISCOUNT_BY_DATE > today)
	{
		return true;
	}
	return false;
}

function isMasterClass(code)
{
	for (x in MASTER_CODES)
	{
		if( code == MASTER_CODES[x])
		{
			return true;
		}
	}
	return false;
}

function numberOfSlotsUsed()
{
	return number_of_slots;
}

//This function calculates the cost of each course from its course code
function getCost(aCourseCodes)
{
	var cost = 0
	number_of_slots = 0;

// find counter position - number of slots used
	for (x in aCourseCodes)
	{
		if (isMasterClass(aCourseCodes[x]))
			addMaster();
		else
			addSession();
	}

// determine cost
// start with the last master
	if (isMasterClass(aCourseCodes[aCourseCodes.length - 1]))
	{
		for (var i=0; i < MASTER_SLOT_WEIGHTING; i++ )
		{
			if (numberOfSlotsUsed() - i > SLOT_COSTS.length)
			{
				cost += LOWEST_COST;
			}
			else
			{
				cost += SLOT_COSTS[number_of_slots - 1 - i];
			}
		}
	}
	else
	{
		for (var i=0; i < SESSION_SLOT_USE_WEIGHTING; i++ )
		{
			if (numberOfSlotsUsed() - i > SLOT_COSTS.length)
			{
				cost += LOWEST_COST;
			}
			else
			{
				cost += SLOT_COSTS[number_of_slots -1 - i];
			}
		}
	}
	return cost;
}


function addMaster()
{
	number_of_slots += MASTER_SLOT_WEIGHTING;
}

function addSession()
{
	number_of_slots += SESSION_SLOT_USE_WEIGHTING;
}
