function loadStep3(){

	// make stepcolumn display correctly
	document.getElementById("stepPointer_Start").setAttribute("class","greyed_out_step");
	document.getElementById("stepPointer_Start").setAttribute("className","greyed_out_step");
		document.getElementById("stepPointer_Start").firstChild.onclick = function () {loadStep1();};
	document.getElementById("stepPointer_Further").setAttribute("class","greyed_out_step");
	document.getElementById("stepPointer_Further").setAttribute("className","greyed_out_step");
		document.getElementById("stepPointer_Further").firstChild.onclick = function () {loadStep2();};
	document.getElementById("stepPointer_Terms").setAttribute("class","active_step");
	document.getElementById("stepPointer_Terms").setAttribute("className","active_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);
	}

	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("align","center");
			newCol.setAttribute("colSpan","2");	
			newIframe = document.createElement("iframe");
			newIframe.setAttribute("src","tandcs.htm");
			newIframe.setAttribute("name","tandcs");
			newIframe.setAttribute("id","tandcs");
			newIframe.setAttribute("frameborder","0");
			newIframe.setAttribute("frameBorder","0");
			newIframe.setAttribute("vspace","5");
			newIframe.setAttribute("vSpace","5");
			
			newCol.appendChild(newIframe);
		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("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("align","left");
			newCol.setAttribute("colSpan","2");	
				var newTable2 = document.createElement("table");
				newTable2.setAttribute("border","0");
				newTable2.setAttribute("cellSpacing","0");
				newTable2.setAttribute("cellPadding","0");
				newTable2.setAttribute("id","tandcsTable");
				var newTbody2 = document.createElement("tbody");

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

					var newCol2 = document.createElement("td");
					newCol2.setAttribute("class","fieldtags");
					newCol2.setAttribute("className","fieldtags");
					newCol2.setAttribute("id","agreetag");
					newCol2.setAttribute("width","70%");

					var newLabel = document.createElement("label");
					newLabel.setAttribute("for","agree");
					var newTxt2 = document.createTextNode("Please tick this box to indicate that you have read and agree to the above Terms & Conditions:");
					newLabel.appendChild(newTxt2);
					newCol2.appendChild(newLabel);

				newRow2.appendChild(newCol2);

					var newCol3 = document.createElement("td");
					newCol3.setAttribute("class","info");
					newCol3.setAttribute("className","info");
					newCol3.setAttribute("width","30%");
			
					newCheckbox2 = document.createElement("input");
					newCheckbox2.setAttribute("type","checkbox");
					newCheckbox2.setAttribute("class","checkbox");
					newCheckbox2.setAttribute("className","checkbox");
					newCheckbox2.setAttribute("name","agree");
					newCheckbox2.setAttribute("id","agree");
					newCheckbox2.setAttribute("value","agreed");
					newCheckbox2.onfocus = function () {resetElement(this);};
					newCheckbox2.onclick = function () {resetElement(this);};
		
					newCol3.appendChild(newCheckbox2);	
				
				newRow2.appendChild(newCol3);
				newTbody2.appendChild(newRow2);
				newTable2.appendChild(newTbody2);

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

	newTable.appendChild(newTbody);

	formarea.replaceChild(newTable,formarea.firstChild);

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

	document.getElementById("backButton").onclick = function () {loadStep2();};
	document.getElementById("continueButton").onclick = function () {checkStep3();};
}

function checkStep3(){
	var errors = 0;

	var element = document.getElementById("agree");
	var boxes_checked = 0;
	if (element.checked != true){
		highlightColumns(element);
		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("You must agree to the above Terms & Conditions 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);
		}

		createLoadingDiv();

		// prefill hidden Paypal fields
		document.getElementById("first_name").value = document.getElementById("firstname_").value;
		document.getElementById("last_name").value = document.getElementById("surname_").value;
		document.getElementById("email").value = document.getElementById("email_").value;
		document.getElementById("address1").value = document.getElementById("address1_").value;
		document.getElementById("address2").value = document.getElementById("address2_").value;
		document.getElementById("city").value = document.getElementById("city_").value;
		document.getElementById("zip").value = document.getElementById("postcode_").value;

		// now send data to PHP
		var dummy = "dummy=" + new Date().getTime();
		var url = "scripts/insert.php?" + dummy;
		request.open("POST", url, true);
//		request.onreadystatechange = function(){requestStep5();};		
//		request.onreadystatechange = function(){document.getElementById("booking").submit()};		
		request.onreadystatechange = function(){document.forms.booking.submit()};		
		request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

		var sendString = "course=" + document.getElementById("course_").value + 
				"&date_identifier=" + document.getElementById("custom").value +
				"&course_typeID=" + document.getElementById("course_typeID").value +
				"&courseID=" + document.getElementById("courseID").value +
				"&firstname=" + document.getElementById("firstname_").value +
				"&surname=" + document.getElementById("surname_").value +
				"&address1=" + document.getElementById("address1_").value +
				"&address2=" + document.getElementById("address2_").value +
				"&city=" + document.getElementById("city_").value +
				"&postcode=" + document.getElementById("postcode_").value +
				"&contact_tel=" + document.getElementById("contact_tel_").value +
				"&email=" + document.getElementById("email_").value +

				"&howhear=" + document.getElementById("howhear_").value +
				"&howhearFurther=" + document.getElementById("howhearFurther_").value +
				"&aims=" + document.getElementById("aims_").value +
				"&fitness=" + document.getElementById("fitness_").value +
				"&equipment=" + document.getElementById("equipment_").value +
				"&equipmentFurther=" + document.getElementById("equipmentFurther_").value +
				"&experience=" + document.getElementById("experience_").value;

//		alert(sendString);

		request.send(sendString);

	}
}
