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) {
//				alert(oXmlHttp.responseText);
				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);
}

function showHide(target) {
	//Originally built for showing and hiding table rows, but *should* work with anything that can be referenced by its id attribute.
	var cs = document.getElementById(target).style.display;
	switch(cs) {
		case "none" :
			try {
				document.getElementById(target).style.display = "table-row";
            } catch(e) {
            	document.getElementById(target).style.display = "block";
            }
			break;
		case "table-row" :
			document.getElementById(target).style.display = "none";
			break;
		case "block" :
			document.getElementById(target).style.display = "none";
			break;
	}
}