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 openClose(target) {
	var cs = document.getElementById(target).style.display;
	switch(cs) {
		case "none" :
			document.getElementById(target).style.display = "block";
			break;
		case "block" :
			document.getElementById(target).style.display = "none";
			break;
	}
}

function closeWindow() {
	window.open('','_parent','');
	window.close();
}

function limitTextarea(target,max) {
	var len = target.value.split(/[\s]+/);
	if(len.length > max) {
		out = "";
		for(i=0; i<max; i++) out += len[i]+" ";
		target.value = out;
		return false;
	}
	return true;
}
