function getcoursesXML(){
	
	// check course type query string
//	alert(location.href);
	var hrefArray = location.href.split("?");
	var queryString = hrefArray[1];
//	alert(queryString);
	var queryStringArray = queryString.split("=");
	if (queryStringArray[0] != "course_type"){
		window.location.href = 'index.htm';
		return false;
	}else{
		var course_typeID = queryStringArray[1];
		if ((course_typeID == 1)||(course_typeID == 2)||(course_typeID == 3)){

			// populate hidden 'course_typeID' field
			document.getElementById("course_typeID").value = course_typeID;
			
			var dummy = "dummy=" + new Date().getTime();
			var course_str = "course_typeID=" + course_typeID;
			var url = "scripts/courses_get.php?" + course_str + "&" + dummy;
			request.open("GET", url, true);
			request.onreadystatechange = loadStep1;
			request.send(null);
			
			// populate hidden 'amount' field with correct cost for each course type
			if (course_typeID == 1){
				document.getElementById("amount").value = '400.00';	
			}else if (course_typeID == 2){
				document.getElementById("amount").value = '200.00';
			}else if (course_typeID == 3){
				document.getElementById("amount").value = '500.00';
			}
//			document.getElementById("amount").value = '0.01';

		}else{
			window.location.href = 'index.htm';
			return false;
		}
	}
	

}
function recordCourseID(selectBox){
	var courseID = selectBox.options[selectBox.selectedIndex].value;	
	var date_completion_display = document.getElementById("date_completion_display");
	
	if (courseID != ""){
		
		// display month and year in space below dropdown box
		var date_completion_val = selectBox.options[selectBox.selectedIndex].parentNode.label;
		var date_completion_str = document.createTextNode("\u00A0" + date_completion_val);
		date_completion_display.replaceChild(date_completion_str,date_completion_display.firstChild);
		
		document.getElementById("courseID").value = courseID;

		// enable all input elements on this page
		var inputFields = document.getElementsByTagName("input");
			for (i=0; i<inputFields.length; i++){
				inputFields[i].disabled=false;
		}	
	}else if (courseID == ""){
		// remove month and year from space below dropdown box
		newTxt = document.createTextNode("\u00A0");
		date_completion_display.replaceChild(newTxt,date_completion_display.firstChild);
		
		// disable all input elements on this page
		var inputFields = document.getElementsByTagName("input");
			for (i=0; i<inputFields.length; i++){
				inputFields[i].disabled=true;
		}				
	}
}
function loadStep1(){

	if (request.readyState == 4) {
		if (request.status == 200) {

	var xmldoc = request.responseXML;
	var element = xmldoc.documentElement;
	var courses = element.firstChild;
	var coursesCount = courses.childNodes.length;
	// fill hidden Paypal custom field with date_identifier value
	var date_identifier = element.childNodes[1].firstChild.nodeValue;
	var course_typeID = element.childNodes[2].firstChild.nodeValue;
	document.getElementById("custom").value = date_identifier;


	// make stepcolumn display correctly
	document.getElementById("stepPointer_Start").setAttribute("class","active_step");
	document.getElementById("stepPointer_Start").setAttribute("className","active_step");
		document.getElementById("stepPointer_Start").firstChild.onclick = "javascript:;";
	document.getElementById("stepPointer_Further").setAttribute("class","greyed_out_step");
	document.getElementById("stepPointer_Further").setAttribute("className","greyed_out_step");
		document.getElementById("stepPointer_Further").firstChild.onclick = "javascript:;";
	document.getElementById("stepPointer_Terms").setAttribute("class","greyed_out_step");
	document.getElementById("stepPointer_Terms").setAttribute("className","greyed_out_step");
		document.getElementById("stepPointer_Terms").firstChild.onclick = "javascript:;";
	document.getElementById("stepPointer_Payment").setAttribute("class","greyed_out_step");
	document.getElementById("stepPointer_Payment").setAttribute("className","greyed_out_step");
		document.getElementById("stepPointer_Payment").firstChild.onclick = "javascript:;";
	document.getElementById("stepPointer_Complete").style.visibility = "hidden";

	// delete warning message if it exists
	if (document.getElementById("warningRow")){
		document.getElementById("buttonsRow").parentNode.removeChild(document.getElementById("buttonsRow").previousSibling);
	}

	createHiddenFields();

	var formarea = document.getElementById("formarea");

	newTable = document.createElement("table");
	newTable.setAttribute("border","0");
	newTable.setAttribute("width","100%");
	newTable.setAttribute("cellSpacing","0");
	newTable.setAttribute("cellPadding","0");
	newTable.setAttribute("id","formTable");

	newTbody = document.createElement("tbody");

	newRow = document.createElement("tr");
	newRow.setAttribute("vAlign","top");
			newCol = document.createElement("td");
			newCol.setAttribute("class","message");
			newCol.setAttribute("className","message");
			newCol.setAttribute("align","left");
			newCol.setAttribute("colSpan","2");	
			newTxt = document.createTextNode("Please use this form to book your place at the Explorers Film School.");
			newCol.appendChild(newTxt);
		newRow.appendChild(newCol);
	newTbody.appendChild(newRow);

	newRow = document.createElement("tr");
	newRow.setAttribute("vAlign","top");
			newCol = document.createElement("td");
			newCol.setAttribute("align","left");
			newCol.setAttribute("colSpan","2");
			newCol.setAttribute("class","divider");
			newCol.setAttribute("className","divider");
			newHR = document.createElement("hr");
			newCol.appendChild(newHR);
		newRow.appendChild(newCol);
	newTbody.appendChild(newRow);

	newRow = document.createElement("tr");
	newRow.setAttribute("vAlign","top");
			newCol = document.createElement("td");
			newCol.setAttribute("class","larger");
			newCol.setAttribute("className","larger");
			newCol.setAttribute("align","left");
			newCol.setAttribute("colSpan","2");	
			newTxt = document.createTextNode("Course details");
			newCol.appendChild(newTxt);
		newRow.appendChild(newCol);
	newTbody.appendChild(newRow);

	newRow = document.createElement("tr");
	newRow.setAttribute("vAlign","top");

			newCol = document.createElement("td");
			newCol.setAttribute("class","fieldtags");
			newCol.setAttribute("className","fieldtags");
			newCol.setAttribute("align","right");
			newCol.setAttribute("width","50%");
	
			newTxt = document.createTextNode("Course type:");
			newCol.appendChild(newTxt);
		newRow.appendChild(newCol);

			newCol = document.createElement("td");
			newCol.setAttribute("class","info");
			newCol.setAttribute("className","info");
			newCol.setAttribute("width","50%");	
	
		if (course_typeID == 1){
			newTxt = document.createTextNode("Standard - 4 consecutive Saturdays");
			newCol.appendChild(newTxt);
		}else if (course_typeID == 2){
			newTxt = document.createTextNode("On site one-to-one tuition");
			newBR = document.createElement("br");
			newTxt2 = document.createTextNode("(Mondays and Fridays)");
			newCol.appendChild(newTxt);
			newCol.appendChild(newBR);
			newCol.appendChild(newTxt2);
		}else if (course_typeID == 3){
			newTxt = document.createTextNode("3 days intensive one-to-one tuition");
			newBR = document.createElement("br");
			newTxt2 = document.createTextNode("(Tuesday to Thursday)");
			newCol.appendChild(newTxt);
			newCol.appendChild(newBR);
			newCol.appendChild(newTxt2);
		}
			
		newRow.appendChild(newCol);
	newTbody.appendChild(newRow);

	newRow = document.createElement("tr");
	newRow.setAttribute("vAlign","top");

			newCol = document.createElement("td");
			newCol.setAttribute("class","fieldtags");
			newCol.setAttribute("className","fieldtags");
			newCol.setAttribute("align","right");
	
			newTxt = document.createTextNode("Select course:");
			newBR = document.createElement("br");
			newTxt2 = document.createTextNode("(Choose from these available dates)");
			newCol.appendChild(newTxt);
			newCol.appendChild(newBR);
			newCol.appendChild(newTxt2);
		newRow.appendChild(newCol);

			newCol = document.createElement("td");
			newCol.setAttribute("class","info");
			newCol.setAttribute("className","info");

			newSelect = document.createElement("select");
			newSelect.setAttribute("name","course");
			newSelect.setAttribute("id","course");
			newSelect.onchange = function () {recordCourseID(this);};

		// create month names array
		var month_names_array = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
		var month_name;
		
		// function used to convert numbers to their ordinal equivalent
		// eg "13" to "13th", "1" to "1st" etc
		// usage: var nNumber=12,
		// sFirstOrdinal=nNumber.toOrdinal(), // => '12th'
		// sSecondOrdinal=(22).toOrdinal(); // => '22nd'
		Number.prototype.toOrdinal=function(m){
		    return (this +
		        ["th","st","nd","rd"][(!(
		            ((m=this%10) >3) ||
		            (Math.floor(this%100/10)==1)
		        ))*m]);
		}

			// create an empty 'Please select' option
			newOption = document.createElement("option");
			newOption.setAttribute("value","");
			if (course_typeID == 2){
				newTxt = document.createTextNode("Please select date");
			}else{
				newTxt = document.createTextNode("Please select start date");
			}
			newOption.appendChild(newTxt);
			newSelect.appendChild(newOption);
			
			var month_prev = 0;
			var year_prev = 0;
						
			for (var i=0; i<coursesCount; i++){
				
				var course = courses.childNodes[i];
				var courseID = course.firstChild.firstChild.nodeValue;
				var course_year = course.childNodes[1].firstChild.nodeValue;
				var course_month = course.childNodes[2].firstChild.nodeValue;
				var course_day = course.childNodes[3].firstChild.nodeValue;
				var weekday = course.childNodes[4].firstChild.nodeValue;
				
				//alert('course_month: '+course_month);
				//alert('month_prev: '+month_prev);
				if (((course_month*1) > (month_prev*1))||((course_year*1) > (year_prev*1))){
					//alert('caught');
					if ((month_prev > 0)&&(year_prev > 0)){
						//alert('add optgroup');
						newSelect.appendChild(newOptgroup);
					}					
					
					month_name = month_names_array[course_month - 1];
					newOptgroup = document.createElement("optgroup");
					newOptgroup.setAttribute("label",month_name + " " + course_year);
					
					month_prev = course_month;
					year_prev = course_year;
				}
	
				newOption = document.createElement("option");
				newOption.setAttribute("value",courseID);
				
				var temp = (course_day*1).toOrdinal();
				
				newTxt = document.createTextNode(weekday + ' ' + (course_day*1).toOrdinal());
				newOption.appendChild(newTxt);
				newOptgroup.appendChild(newOption);				

			}
			newSelect.appendChild(newOptgroup);
	
			newCol.appendChild(newSelect);
			newBR = document.createElement("br");
			newCol.appendChild(newBR);
			newSpan = document.createElement("span");
			newSpan.setAttribute("id","date_completion_display");
			newTxt = document.createTextNode("\u00A0");			
			newSpan.appendChild(newTxt);
			newCol.appendChild(newSpan);
			
		newRow.appendChild(newCol);
	newTbody.appendChild(newRow);

	newRow = document.createElement("tr");
	newRow.setAttribute("vAlign","top");
			newCol = document.createElement("td");
			newCol.setAttribute("align","left");
			newCol.setAttribute("colSpan","2");
			newCol.setAttribute("class","divider");
			newCol.setAttribute("className","divider");
			newHR = document.createElement("hr");
			newCol.appendChild(newHR);
		newRow.appendChild(newCol);
	newTbody.appendChild(newRow);

	newRow = document.createElement("tr");
	newRow.setAttribute("vAlign","top");
			newCol = document.createElement("td");
			newCol.setAttribute("class","formheader");
			newCol.setAttribute("className","formheader");
			newCol.setAttribute("align","left");
			newCol.setAttribute("colSpan","2");	
			newTxt = document.createTextNode("Personal details");
			newCol.appendChild(newTxt);
		newRow.appendChild(newCol);
	newTbody.appendChild(newRow);

	newRow = document.createElement("tr");
	newRow.setAttribute("vAlign","top");

			newCol = document.createElement("td");
			newCol.setAttribute("class","fieldtags");
			newCol.setAttribute("className","fieldtags");
			newCol.setAttribute("align","right");
	
			newTxt = document.createTextNode("Firstname:");
			newCol.appendChild(newTxt);
		newRow.appendChild(newCol);

			newCol = document.createElement("td");
			newCol.setAttribute("class","info");
			newCol.setAttribute("className","info");

			newInput = document.createElement("input");
			newInput.setAttribute("name","firstname");
			newInput.setAttribute("id","firstname");
			newInput.setAttribute("class","textbox");
			newInput.setAttribute("className","textbox");
			newInput.onfocus = function () {resetElement(this);};	
			newCol.appendChild(newInput);

		newRow.appendChild(newCol);
	newTbody.appendChild(newRow);

	newRow = document.createElement("tr");
	newRow.setAttribute("vAlign","top");

			newCol = document.createElement("td");
			newCol.setAttribute("class","fieldtags");
			newCol.setAttribute("className","fieldtags");
			newCol.setAttribute("align","right");
	
			newTxt = document.createTextNode("Surname:");
			newCol.appendChild(newTxt);
		newRow.appendChild(newCol);

			newCol = document.createElement("td");
			newCol.setAttribute("class","info");
			newCol.setAttribute("className","info");

			newInput = document.createElement("input");
			newInput.setAttribute("name","surname");
			newInput.setAttribute("id","surname");
			newInput.setAttribute("class","textbox");
			newInput.setAttribute("className","textbox");
			newInput.onfocus = function () {resetElement(this);};	
			newCol.appendChild(newInput);

		newRow.appendChild(newCol);
	newTbody.appendChild(newRow);

	newRow = document.createElement("tr");
	newRow.setAttribute("vAlign","top");
			newCol = document.createElement("td");
			newCol.setAttribute("align","left");
			newCol.setAttribute("colSpan","2");	
			newTxt = document.createTextNode("\u00A0");
			newCol.appendChild(newTxt);
		newRow.appendChild(newCol);
	newTbody.appendChild(newRow);

	newRow = document.createElement("tr");
	newRow.setAttribute("vAlign","top");
			newCol = document.createElement("td");
			newCol.setAttribute("class","formheader");
			newCol.setAttribute("className","formheader");
			newCol.setAttribute("align","left");
			newCol.setAttribute("colSpan","2");	
			newTxt = document.createTextNode("Contact details");
			newCol.appendChild(newTxt);
		newRow.appendChild(newCol);
	newTbody.appendChild(newRow);

	newRow = document.createElement("tr");
	newRow.setAttribute("vAlign","top");
			newCol = document.createElement("td");
			newCol.setAttribute("class","fieldtags");
			newCol.setAttribute("className","fieldtags");
			newCol.setAttribute("align","right");	
			newTxt = document.createTextNode("Address:");
			newCol.appendChild(newTxt);
		newRow.appendChild(newCol);

			newCol = document.createElement("td");
			newCol.setAttribute("class","info");
			newCol.setAttribute("className","info");

			newInput = document.createElement("input");
			newInput.setAttribute("name","address1_efs");
			newInput.setAttribute("id","address1_efs");
			newInput.setAttribute("class","textbox");
			newInput.setAttribute("className","textbox");
			newInput.onfocus = function () {resetElement(this);};	
			newCol.appendChild(newInput);

		newRow.appendChild(newCol);
	newTbody.appendChild(newRow);

	newRow = document.createElement("tr");
	newRow.setAttribute("vAlign","top");
			newCol = document.createElement("td");
			newCol.setAttribute("class","fieldtags");
			newCol.setAttribute("className","fieldtags");
			newCol.setAttribute("align","right");	
			newTxt = document.createTextNode("\u00A0");
			newCol.appendChild(newTxt);
		newRow.appendChild(newCol);

			newCol = document.createElement("td");
			newCol.setAttribute("class","info");
			newCol.setAttribute("className","info");

			newInput = document.createElement("input");
			newInput.setAttribute("name","address2_efs");
			newInput.setAttribute("id","address2_efs");
			newInput.setAttribute("class","textbox");
			newInput.setAttribute("className","textbox");
			newCol.appendChild(newInput);

		newRow.appendChild(newCol);
	newTbody.appendChild(newRow);

	newRow = document.createElement("tr");
	newRow.setAttribute("vAlign","top");

			newCol = document.createElement("td");
			newCol.setAttribute("class","fieldtags");
			newCol.setAttribute("className","fieldtags");
			newCol.setAttribute("align","right");
	
			newTxt = document.createTextNode("Town/City:");
			newCol.appendChild(newTxt);
		newRow.appendChild(newCol);

			newCol = document.createElement("td");
			newCol.setAttribute("class","info");
			newCol.setAttribute("className","info");

			newInput = document.createElement("input");
			newInput.setAttribute("name","city_efs");
			newInput.setAttribute("id","city_efs");
			newInput.setAttribute("class","textbox");
			newInput.setAttribute("className","textbox");
			newInput.onfocus = function () {resetElement(this);};	
			newCol.appendChild(newInput);

		newRow.appendChild(newCol);
	newTbody.appendChild(newRow);

	newRow = document.createElement("tr");
	newRow.setAttribute("vAlign","top");

			newCol = document.createElement("td");
			newCol.setAttribute("class","fieldtags");
			newCol.setAttribute("className","fieldtags");
			newCol.setAttribute("align","right");
	
			newTxt = document.createTextNode("Postcode:");
			newCol.appendChild(newTxt);
		newRow.appendChild(newCol);

			newCol = document.createElement("td");
			newCol.setAttribute("class","info");
			newCol.setAttribute("className","info");

			newInput = document.createElement("input");
			newInput.setAttribute("name","postcode");
			newInput.setAttribute("id","postcode");
			newInput.setAttribute("class","textbox");
			newInput.setAttribute("className","textbox");
			newInput.onfocus = function () {resetElement(this);};	
			newCol.appendChild(newInput);

		newRow.appendChild(newCol);
	newTbody.appendChild(newRow);

	newRow = document.createElement("tr");
	newRow.setAttribute("vAlign","top");
			newCol = document.createElement("td");
			newCol.setAttribute("colSpan","2");
			newTxt = document.createTextNode("\u00A0");			
			newCol.appendChild(newTxt);
		newRow.appendChild(newCol);
	newTbody.appendChild(newRow);

	newRow = document.createElement("tr");
	newRow.setAttribute("vAlign","top");

			newCol = document.createElement("td");
			newCol.setAttribute("class","fieldtags");
			newCol.setAttribute("className","fieldtags");
			newCol.setAttribute("align","right");
	
			newTxt = document.createTextNode("Contact telephone:");
			newCol.appendChild(newTxt);
		newRow.appendChild(newCol);

			newCol = document.createElement("td");
			newCol.setAttribute("class","info");
			newCol.setAttribute("className","info");

			newInput = document.createElement("input");
			newInput.setAttribute("name","contact_tel");
			newInput.setAttribute("id","contact_tel");
			newInput.setAttribute("class","textbox");
			newInput.setAttribute("className","textbox");
			newInput.onfocus = function () {resetElement(this);};	
			newCol.appendChild(newInput);

		newRow.appendChild(newCol);
	newTbody.appendChild(newRow);

	newRow = document.createElement("tr");
	newRow.setAttribute("vAlign","top");

			newCol = document.createElement("td");
			newCol.setAttribute("class","fieldtags");
			newCol.setAttribute("className","fieldtags");
			newCol.setAttribute("align","right");
	
			newTxt = document.createTextNode("Email address:");
			newCol.appendChild(newTxt);

		newRow.appendChild(newCol);

			newCol = document.createElement("td");
			newCol.setAttribute("class","info");
			newCol.setAttribute("className","info");

			newInput = document.createElement("input");
			newInput.setAttribute("name","email_efs");
			newInput.setAttribute("id","email_efs");
			newInput.setAttribute("class","textbox");
			newInput.setAttribute("className","textbox");
//			newInput.setAttribute("value","shaun@shaundobson.net");
			newInput.setAttribute("value","");
			newInput.onfocus = function () {resetElement(this);};	
			newCol.appendChild(newInput);

		newRow.appendChild(newCol);
	newTbody.appendChild(newRow);

/*
	// dummy empty row to solve crazy IE bug - not having an odd number
	// of rows in this bottom section causes an extra 1 pixel gap at the
	// bottom of the div, meaning that the bottom corner images don't align
	// correctly. crazy but true

	newRow = document.createElement("tr");
	newRow.setAttribute("vAlign","top");
			newCol = document.createElement("td");
			newCol.setAttribute("class","fieldtags");
			newCol.setAttribute("colSpan","2");
			newCol.setAttribute("style","height:0px");
		newRow.appendChild(newCol);
	newTbody.appendChild(newRow);
*/

	newTable.appendChild(newTbody);

	if (document.getElementById("formTable")){
		formarea.replaceChild(newTable,formarea.firstChild);
	}else{
		formarea.appendChild(newTable);
	}

	// Populate 'back' and 'continue' buttons
	document.getElementById("backButton").style.visibility = "hidden";
	document.getElementById("continueButton").style.visibility = "visible";

//	document.getElementById("continueButton").onclick = function () {loadStep2();};
	document.getElementById("continueButton").onclick = function () {checkStep1();};

	// disable all input elements on this page
	var inputFields = document.getElementsByTagName("input");
	for (i=0; i<inputFields.length; i++){
		inputFields[i].disabled=true;
	}
	
		}
	}
}

function emailCatch(email){	
	if (email.length>4){	
		var ampers=0;
		var dots=0;		
		for (i=0;i<(email.length);i++){
			if (email.substring(i,(i+1))=="@"){
				ampers++;
			}
		}		
		for (i=0;i<(email.length);i++){
			if (email.substring(i,(i+1))=="."){
				dots++;
			}
		}		
	}
	if ((email.length<5)||(ampers!=1)||(dots==0)){
		return true;
	}
}
function checkStep1(){
	var errors = 0;

	// check standard text fields
	var mandatory_txt_fields = new Array("firstname","surname","address1_efs","city_efs","postcode","contact_tel");

	for (var i=0; i<mandatory_txt_fields.length; i++){
		if (document.getElementById(mandatory_txt_fields[i])){
			var field = document.getElementById(mandatory_txt_fields[i]);

			if (field.value === ""){
				highlightColumns(field);
				errors++;
			}				
		}
	}
	var email = document.getElementById("email_efs").value;
	// check email address
	if (emailCatch(email)){
		var field = document.getElementById("email_efs");
		highlightColumns(field);
		errors++;
	}

	if (errors > 0){
		// create warning row, if not already in place
		if (!document.getElementById("warningRow")){
			newRow = document.createElement("tr");
			newRow.setAttribute("vAlign","top");
			newRow.setAttribute("id","warningRow");
				newCol = document.createElement("td");
				newCol.setAttribute("class","fieldtags");
				newCol.setAttribute("className","fieldtags");
				newCol.setAttribute("align","right");	
				newTxt = document.createTextNode("\u00A0");
				newCol.appendChild(newTxt);
			newRow.appendChild(newCol);
				newCol = document.createElement("td");
				newCol.setAttribute("class","warning");
				newCol.setAttribute("className","warning");	
				newTxt = document.createTextNode("Please complete all highlighted fields above before continuing.");
				newCol.appendChild(newTxt);
			newRow.appendChild(newCol);

			document.getElementById("bookingTbody").insertBefore(newRow,document.getElementById("buttonsRow"));	
		}
	}else{
		if (document.getElementById("warningRow")){
			document.getElementById("buttonsRow").parentNode.removeChild(document.getElementById("buttonsRow").previousSibling);
		}

		document.getElementById("course_").value = filterStr(document.getElementById("course").options[document.getElementById("course").selectedIndex].value);
		document.getElementById("firstname_").value = filterStr(document.getElementById("firstname").value);
		document.getElementById("surname_").value = filterStr(document.getElementById("surname").value);
		document.getElementById("address1_").value = filterStr(document.getElementById("address1_efs").value);
		document.getElementById("address2_").value = filterStr(document.getElementById("address2_efs").value);
		document.getElementById("city_").value = filterStr(document.getElementById("city_efs").value);
		document.getElementById("postcode_").value = filterStr(document.getElementById("postcode").value);
		document.getElementById("contact_tel_").value = filterStr(document.getElementById("contact_tel").value);
		document.getElementById("email_").value = filterStr(document.getElementById("email_efs").value);

		loadStep2();
	}
}
