function selectAll() {
	//Checks all checkboxes on page regardless of the amount of forms
	//Requires a checkbox with the name/id "select_all" to initiate this function on click
	var x = document.getElementsByTagName("input");
	for(i=0; i<x.length; i++) {
		if((x[i].type == "checkbox") && (x[i].name != "select_all")) {
			x[i].checked = (document.getElementById("select_all").checked == false) ? false : true;
		}
	}
}

function copyChecked() {
	//Grabs the value of all checked checkboxes, builds a comma seperated string and dumps the string into a hidden field
	var c = new Array();
	var z = 0; //A counter for assembling the array nicely
	var x = document.getElementsByTagName("input");
	for(i=0; i<x.length; i++) {
		if((x[i].type == "checkbox") && (x[i].name != "select_all")) {
			if(x[i].checked == true) {
				c[z] = x[i].value;
				z++;
			}
		}
	}
	document.getElementById("selected").value = c.join(",");
}

function moreInfo(info) {
	var text = "";
	switch(info) {
		case  	  "clear": text = "The primary aim of the West London Floating Classrooom is to provide cost-effective environmental education and youth programmes to the diverse communties of Hounslow, Hillingdon and Ealing, in order to encourage enjoyment and understanding of local heritage.<br /><div style='color:#000;line-height:12px;'>Telephone: 01895 832662<br />Email: contact@elsdale.co.uk</div>"; break;
		case  "corporate": text = "The Elsdale is available for Corporate &amp; Private events. Click to find out more."; break;
		case "programmes": text = "Details for teachers of the educational prrgrammes we provide on board."; break;
		case   "bookings": text = "Here you can see our events calendar, choose your dates &amp; make a booking online for your event."; break;
		case 	"support": text = "Helpful hints and contact information for the West London Folating Classroom."; break;
		case 	  "canal": text = "The history of the canal and links for more information."; break;
		case 	   "work": text = "Work carried out by students on our boat."; break;
		case  "education": text = "Teachers; bring your class on-board and engage in a special learning experience."; break;
		case 	 "routes": text = "Further information about The Grand Union Canal."; break;
		case  "downloads": text = "Download information about the WLFC."; break;
	}
	document.getElementById("menu_overview").innerHTML = text;
}

function requestForm(cmd,uID,targetDiv) {
	var oXmlHttp = zXmlHttp.createRequest();
	oXmlHttp.open("get","fetch.php?cmd="+cmd+"&id="+uID,true);
	oXmlHttp.onreadystatechange = function() {
		if(oXmlHttp.readyState == 4) {
			if(oXmlHttp.status == 200) {
				document.getElementById(targetDiv).innerHTML = oXmlHttp.responseText;
			} else {
				document.getElementById(targetDiv).innerHTML = "An error occured: "+oXmlHttp.statusText;
			}
		}
	};
	oXmlHttp.send(null);
}
	
function getRequestBody(oForm) {
	var aParams = new Array();
	for(i=0; i < oForm.elements.length; i++) {
		//Check to see if element is a checkbox, only include if selected.
		if(oForm.elements[i].type == "checkbox") {
			if(oForm.elements[i].checked == true) {
				var sParam = encodeURIComponent(oForm.elements[i].name);
				sParam += "=";
				sParam += encodeURIComponent(oForm.elements[i].value);
				aParams.push(sParam);
			}
		} else {
			var sParam = encodeURIComponent(oForm.elements[i].name);
			sParam += "=";
			sParam += encodeURIComponent(oForm.elements[i].value);
			aParams.push(sParam);
		}
	}
	return aParams.join("&");
}
	
function sendRequest(targetForm,targetDiv,refreshCmd,refreshTargetDiv,refreshParam) {
	var oForm = document.forms[targetForm];
	var sBody = getRequestBody(oForm);
	
	var oXmlHttp = zXmlHttp.createRequest();
	oXmlHttp.open("post","insert.php",true);
	oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	
	oXmlHttp.onreadystatechange = function() {
		if(oXmlHttp.readyState == 4) {
			if(oXmlHttp.status == 200) {
//				alert(oXmlHttp.responseText);
			} else {
//				alert("An error occurred: "+oXmlHttp.statusText);
			}
			showHide(0,targetDiv,0,0);
			if(refreshCmd != "") requestForm(refreshCmd,refreshParam,refreshTargetDiv);
		}
	};
	oXmlHttp.send(sBody);
}
