function FnCourses(form, coursePrices, membershipPrice, enquireMode) {
	
	// Construct an object if we're called as a function
	if (this.constructor === window.constructor) {
		return new arguments.callee.apply(null, arguments);
	}
	
	this.enquireMode = typeof enquireMode !== 'undefined' ? enquireMode : false;
	
	$('no-js-course-info').remove();
	
	this.form = $(form);
	
	this.prices = coursePrices;
	this.membership = membershipPrice;
	
	this.qualificationsSELECT = this.form.select('[name="programmetype"]').first();
	this.coursesSELECT = this.form.select('[name="programme"]').first();
	this.locationsSELECT = this.form.select('[name="location"]').first();
	
	this.allCourses = $(this.coursesSELECT.cloneNode(true)).writeAttribute('id',null);
	this.allLocations = $(this.locationsSELECT.cloneNode(true)).writeAttribute('id',null);
	
	this.currentQualification = false;
	this.currentCourse = false;
	this.currentLocation = false;
	
	this.events();
	
	this.changeQualification();
}

FnCourses.prototype.events = function events () {
	this.qualificationsSELECT.observe('change', this.changeQualification.bind(this));
	this.coursesSELECT.observe('change', this.changeCourse.bind(this));
	this.locationsSELECT.observe('change', this.changeLocation.bind(this));
	
	this.form.select('input[name="payment-type"], input[name="member"]').invoke('observe', 'click', this.updatePrice.bind(this));
};

FnCourses.prototype.changeQualification = function changeQualification () {
	var newQualification = this.qualificationsSELECT.value;
	
	// Don't continue if there is no actual change
	if (newQualification === this.currentQualification) {
		return;
	}
		
	this.currentQualification = newQualification;
	
	this.coursesSELECT.select('option').invoke('remove');
	
	this.coursesSELECT.options[0] = new Option('Please Select a Course', '', true, true);
	
	var currentCourses = this.allCourses.select('option.qual-' + this.currentQualification);
	
	currentCourses.each(function (opt) {
		
		this.coursesSELECT.appendChild(opt.cloneNode(true));
		
	}, this);
	
	if (this.coursesSELECT.options.length === 1) {
		this.coursesSELECT.disable();
	}
	else {
		this.coursesSELECT.enable();
	}
	
	this.changeCourse();
	
};

FnCourses.prototype.changeCourse = function changeCourse () {
	var newCourse = this.coursesSELECT.value;
		
	// Don't continue if there is no actual change
	if (newCourse === this.currentCourse) {
		return;
	}
		
	this.currentCourse = newCourse;
	
	this.locationsSELECT.select('option').invoke('remove');
	
	this.locationsSELECT.options[0] = new Option('Please Select a delivery method/location', '', true, true);
	
	var currentLocations = this.allLocations.select('option.course-' + this.currentCourse);
	
	currentLocations.each(function (opt) {
		
		this.locationsSELECT.appendChild(opt.cloneNode(true));
		
	}, this);

	
	if (this.locationsSELECT.options.length === 1) {
		this.locationsSELECT.disable();
	}
	else {
		this.locationsSELECT.enable();
	}
	
	this.changeLocation();	
};

FnCourses.prototype.changeLocation = function changeLocation () {
	if (this.enquireMode) {
		
		$('val_course').value = this.coursesSELECT.options[this.coursesSELECT.selectedIndex].text;
		$('val_method').value = this.locationsSELECT.options[this.locationsSELECT.selectedIndex].text;
		
	}
	else {
		var newLocation = this.locationsSELECT.value,
			paymentUpfrontRadio = $('payment-upfront'),
			paymentPlanRadio = $('payment-plan'),
			paymentPlanLabel = $$('label[for="payment-plan"]')[0],
			paymentPlanPara = $$('p.pay-by-instalments')[0],
			membershipOptions = $('membership-options'),
			membershipNo = $('member-no');
	
			
		// Don't continue if there is no actual change
		if (newLocation === this.currentLocation) {
			return;
		}
			
		this.currentLocation = newLocation;
		
		
		if (paymentPlanRadio.hasClassName('occu-' + this.currentLocation)) {
			paymentPlanRadio.enable();
			paymentPlanLabel.removeClassName('disabled');
		}
		else {
			paymentUpfrontRadio.checked = true;
			paymentPlanRadio.disable();
			paymentPlanLabel.addClassName('disabled');

		}		
		
		if (typeof paymentPlanPara !== 'undefined') {
			if (paymentPlanPara.hasClassName('occu-' + this.currentLocation)) {
				paymentPlanPara.show();
			}
			else {
				paymentPlanPara.hide();
			}
		}
	
		if (membershipOptions.hasClassName('occu-' + this.currentLocation)) {
	/* 		membershipOptions.select('input').invoke('enable'); */
			membershipNo.checked = true;
			membershipOptions.show();
		}
		else {
			membershipNo.checked = true;
			membershipOptions.hide();//.select('input');//.invoke('disable');
		}
	
	
		
		this.updatePrice();
	}
};

FnCourses.prototype.updatePrice = function updatePrice () {
	var membershipOptions = $('member-yes','member-join'),
		newPrice = '',
		priceGroup = this.prices[this.currentLocation],
		deposit,
		instalments,
		payments;
			
	if (this.currentLocation) {
		
		if ($('payment-plan').checked) {
			
			deposit = priceGroup.deposit.Enpr_Amount;
			instalments = priceGroup.monthly.Enpr_Amount;
			payments = priceGroup.number.Enpr_Amount;
			
			newPrice = '$' + deposit + ' + ($' + instalments + ' x ' + payments + ')';
			
		}
		else {
			
			if (membershipOptions.pluck('disabled').indexOf(true) === -1 && membershipOptions.pluck('checked').indexOf(true) !== -1) {
				newPrice = '$' + priceGroup.members.Enpr_Amount;
				if ($('member-join').checked) {
					newPrice += ' + $' + this.membership;
				}
			}
			else {
				newPrice = '$' + priceGroup.enrol.Enpr_Amount;
			}
		}
	}
	
	$('price').update(newPrice);
};

