function showAdminResult(tablename, resultID, callbackfunction) {
	 // if no callback function is provided, then use the standard mfc callback function
	 if (typeof callbackfunction == "undefined") {
		callbackfunction = "showEditForm";
	 }
	 xhReq = createXMLHttpRequest();
	minisitename = getMinisiteName();
	minisite_group = getMinisiteGroup();

	 var poststring = "mfcAction=processEditData&action=moderate&tablename="+tablename+"&resultID="+resultID+"&minisitename="+minisitename+"&minisite_group="+minisite_group;
	 xhReq.open("POST", "mfcPhpRequests.php", true);
	 try {
	   xhReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	 }
	 catch (e) {
		// this only works in internet explorer
	 }
	 //xhReq.onreadystatechange = showDataToModerate;
	 xhReq.onreadystatechange = window[callbackfunction];
	 xhReq.send(poststring);
}





function sendModeratedDataToServer(poststring,callbackfunction) {
	 // if no callback function is provided, then use the standard mfc callback function
	 if (typeof callbackfunction == "undefined") {
		callbackfunction = "dataModerated";
	 }


	xhReq = createXMLHttpRequest();
	
	// remove any dodgy characters
	minisite_group = getMinisiteGroup();
	poststring = poststring + "&action=saveModerate&mfcAction=processEditData&minisite_group="+minisite_group;
	 xhReq.open("POST", "mfcPhpRequests.php", true);
	 xhReq.onreadystatechange = window[callbackfunction];

	 //
	 try {
	   xhReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	   //xhReq.setRequestHeader('Content-Type','text/html')
	 }
	 catch (e) {
	 	// this only works in internet explorer
	 }
	xhReq.send(poststring);
}



function deleteCapture(tablename,id, callbackfunction) {

	 // if no callback function is provided, then use the standard mfc callback function
	 if (typeof callbackfunction == "undefined") {
		callbackfunction = "processCancelCapture";
	 }

// this is used where a record is first being created ...
	if (confirm("Cancel Data Edit?  You will lose all changes.")) {
		// delete the record from the server ...
			// in this case, the child record should be deleted from the database first
			// this is a PROPER delete as opposed to a 'delete' requested by the user / moderator, whic
			// only flags the data as deleted
			
			// so the CANCEL button should only appear for an 'add new' operation
		
			
			xhReq = createXMLHttpRequest();
			// remove any dodgy characters
			minisite_group = getMinisiteGroup();
			poststring = "";
			poststring = poststring + "&mfcAction=processEditData&tablename="+tablename+"&id="+id;
			poststring = poststring + "&action=clearParent&minisite_group="+minisite_group;
			 xhReq.open("POST", "mfcPhpRequests.php", true);
			 xhReq.onreadystatechange = window[callbackfunction];
			 //
			 try {
			   xhReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			   //xhReq.setRequestHeader('Content-Type','text/html')
			 }
			 catch (e) {
			 	// this only works in internet explorer
			 }
			//alert(poststring);
		xhReq.send(poststring);
		//setupStep1();
	}

}





function editExisting(tablename,callbackfunction) {
	 // if no callback function is provided, then use the standard mfc callback function
	 if (typeof callbackfunction == "undefined") {
		callbackfunction = "showChildEditForm";
	 }


	// this child has already been saved = we are editing/moderating
	var postdata = formData("userDataCapture");
	var poststring = stripNonValidXMLCharacters(postdata);
	poststring = poststring.substr(0,poststring.length - 1);

	var theLayerChoice = document.getElementsByName("childEditGroup");
	var j=theLayerChoice.length; 
	for (i=0; i<j; i++){
		if(theLayerChoice[i].checked) {
			var lookuptablename = theLayerChoice[i].value;
		}
	}
	if (document.getElementById('photoname')) {
		photoname = getPhotoName(document.getElementById('photoname').value);
		poststring = poststring + "&photoname="+ photoname;
	}

	minisitename = getMinisiteName();
	minisite_group = getMinisiteGroup();
	poststring = poststring+ "&minisitename="+minisitename
	
	// now add the tablename
	poststring = poststring + "&tablename="+tablename;
	poststring = poststring+"&approved=0";

	// as this is an add new record, also send the name of the lookup tablename, this will be used
	// to generate a new blank lookup table record to show to the user
	poststring = poststring + "&lookuptablename="+lookuptablename;
	poststring = poststring + "&action=showFirstChildExistingParent&mfcAction=processEditData&minisite_group="+minisite_group;
	xhReq = createXMLHttpRequest();
	// remove any dodgy characters
	
	 xhReq.open("POST", "mfcPhpRequests.php", true);
	 xhReq.onreadystatechange = window[callbackfunction]; //showform;

	 //
	 try {
	   xhReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	   //xhReq.setRequestHeader('Content-Type','text/html')
	 }
	 catch (e) {
	 	// this only works in internet explorer
	 }
	xhReq.send(poststring);
}
function addlookuprecordExistingParent(tablename, callbackfunction) {
	// get the ID from the main form - this is hidden
	
	 // if no callback function is provided, then use the standard mfc callback function
	 if (typeof callbackfunction == "undefined") {
		callbackfunction = "showChildEditForm";
	 }
	
	var theLayerChoice = document.getElementsByName("childgroup");
	var j=theLayerChoice.length; 
	for (i=0; i<j; i++){
		if(theLayerChoice[i].checked) {
			var lookuptablename = theLayerChoice[i].value;
		}
	}

	
	
	//alert("addlookuprecordExistingParent");
	// save the main record, without any validation, then show a new sub record
	var postdata = formData("userDataCapture");
	var poststring = stripNonValidXMLCharacters(postdata);
	poststring = poststring.substr(0,poststring.length - 1);

	if (document.getElementById('photoname')) {
		photoname = getPhotoName(document.getElementById('photoname').value);
		poststring = poststring + "&photoname="+ photoname;
	}

	minisitename = getMinisiteName();
	minisite_group = getMinisiteGroup();
	poststring = poststring+ "&minisitename="+minisitename

	// now add the tablename
	poststring = poststring + "&tablename="+tablename;

	// as this is an add new record, also send the name of the lookup tablename, this will be used
	// to generate a new blank lookup table record to show to the user
	poststring = poststring + "&lookuptablename="+lookuptablename;
	poststring = poststring + "&action=createNewChildExistingParent&mfcAction=processEditData&minisite_group="+minisite_group;
	xhReq = createXMLHttpRequest();
	// remove any dodgy characters
	
	 xhReq.open("POST", "mfcPhpRequests.php", true);
	 xhReq.onreadystatechange = window[callbackfunction];  //showform;

	 //
	 try {
	   xhReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	   //xhReq.setRequestHeader('Content-Type','text/html')
	 }
	 catch (e) {
	 	// this only works in internet explorer
	 }
	xhReq.send(poststring);

}


function deleteNewAndReturnToExistingParent(lookuptablename, lookupid, parenttablename, parentid,callbackfunction) {
	//alert("deleteNew and return to existing");
	// we have jsut created a new child but have changed our minds so need to delete
	// the temporary record, and then show the existing parent
	// happens during an EDIT SESSION

	// this method is called if the PARENT hasn't yet been saved

		// submit the form, save the changes and then re-create the main form
		// get the ID from the main form - this is hidden


	 // if no callback function is provided, then use the standard mfc callback function
	 if (typeof callbackfunction == "undefined") {
		callbackfunction = "showEditForm";
	 }


	minisitename = getMinisiteName();
	minisite_group = getMinisiteGroup();
	poststring = poststring+ "&minisitename="+minisitename


		// save the main record, without any validation, then show a new sub record
		var postdata = formData("userDataCapture");
		var poststring = stripNonValidXMLCharacters(postdata);
		poststring = poststring.substr(0,poststring.length - 1);
		poststring = poststring+"&approved=0";


	if (document.getElementById('photoname')) {
		photoname = getPhotoName(document.getElementById('photoname').value);
		poststring = poststring + "&photoname="+ photoname;
	}


		xhReq = createXMLHttpRequest();
		// remove any dodgy characters

		poststring = poststring + "&parenttablename="+parenttablename+"&parentid="+parentid;
		poststring = poststring + "&lookuptablename="+lookuptablename+"&lookupid="+lookupid;
		poststring = poststring + "&action=DeleteNewChildExistingParent&mfcAction=processEditData&minisite_group="+minisite_group;
		 xhReq.open("POST", "mfcPhpRequests.php", true);
		 xhReq.onreadystatechange = window[callbackfunction];
	 //
		 try {
		   xhReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		   //xhReq.setRequestHeader('Content-Type','text/html')
		 }
		 catch (e) {
			// this only works in internet explorer
		 }
		//alert(poststring);
		xhReq.send(poststring);

}
function saveExistingAndReturnToExistingParent (lookuptablename, lookupid, parenttablename, parentid,callbackfunction) {
	
	 // if no callback function is provided, then use the standard mfc callback function
	 if (typeof callbackfunction == "undefined") {
		callbackfunction = "showEditForm";
	 }

	if (checkData()) {
		// submit the form, save the changes and then re-create the main form
		// get the ID from the main form - this is hidden

		// save the main record, without any validation, then show a new sub record
		var postdata = formData("userDataCapture");
		var poststring = stripNonValidXMLCharacters(postdata);
		poststring = poststring.substr(0,poststring.length - 1);
		poststring = poststring+"&approved=0";

		xhReq = createXMLHttpRequest();
		// remove any dodgy characters


		minisitename = getMinisiteName();
		minisite_group = getMinisiteGroup();
		poststring = poststring+ "&minisitename="+minisitename

		poststring = poststring + "&parenttablename="+parenttablename+"&parentid="+parentid;
		poststring = poststring + "&lookuptablename="+lookuptablename+"&id="+lookupid;
		poststring = poststring + "&action=saveExistingChildShowExistingParent&mfcAction=processEditData&minisite_group="+minisite_group;
		 xhReq.open("POST", "mfcPhpRequests.php", true);
		 xhReq.onreadystatechange = window[callbackfunction];
	 //
		 try {
		   xhReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		   //xhReq.setRequestHeader('Content-Type','text/html')
		 }
		 catch (e) {
			// this only works in internet explorer
		 }
		xhReq.send(poststring);
	}

	
}

function cancelExistingReturnToExistParent(lookuptablename, lookupid, parenttablename, parentid,callbackfunction) {
	

	 // if no callback function is provided, then use the standard mfc callback function
	 if (typeof callbackfunction == "undefined") {
		callbackfunction = "showEditForm";
	 }


	// save the main record, without any validation, then show a new sub record
	xhReq = createXMLHttpRequest();
	poststring = "";
	minisitename = getMinisiteName();
	minisite_group = getMinisiteGroup();
	poststring = poststring+ "&minisitename="+minisitename

	poststring = poststring + "&parenttablename="+parenttablename+"&parentid="+parentid;
	poststring = poststring + "&lookuptablename="+lookuptablename+"&id="+lookupid;
	poststring = poststring + "&action=cancelChildShowExistParent&mfcAction=processEditData&minisite_group="+minisite_group;
	 xhReq.open("POST", "mfcPhpRequests.php", true);
	 xhReq.onreadystatechange = window[callbackfunction];
	 try {
	   xhReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	   //xhReq.setRequestHeader('Content-Type','text/html')
	 }
	 catch (e) {
		// this only works in internet explorer
	 }
	xhReq.send(poststring);
}
function deleteExistingReturnToExistParent(lookuptablename, lookupid, parenttablename, parentid,callbackfunction) {

		//alert("deleteExistingReturnToExistParent");
		
		 // if no callback function is provided, then use the standard mfc callback function
		 if (typeof callbackfunction == "undefined") {
			callbackfunction = "showEditForm";
		 }


		// save the main record, without any validation, then show a new sub record
		xhReq = createXMLHttpRequest();
		// remove any dodgy characters
		poststring = "";

		minisitename = getMinisiteName();
		minisite_group = getMinisiteGroup();
		poststring = poststring+ "&minisitename="+minisitename

		poststring = poststring + "&mfcAction=processEditData&parenttablename="+parenttablename+"&parentid="+parentid;
		poststring = poststring + "&lookuptablename="+lookuptablename+"&lookupid="+lookupid;
		poststring = poststring + "&action=deleteChildShowExistParent&minisite_group="+minisite_group;
		 xhReq.open("POST", "mfcPhpRequests.php", true);
		 xhReq.onreadystatechange = window[callbackfunction];
		 try {
		   xhReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		   //xhReq.setRequestHeader('Content-Type','text/html')
		 }
		 catch (e) {
			// this only works in internet explorer
		 }
		//alert(poststring);
		xhReq.send(poststring);
}

function saveNewAndReturnToExistingParent(lookuptablename, lookupid, parenttablename, parentid, callbackfunction) {
	
		 // if no callback function is provided, then use the standard mfc callback function
		 if (typeof callbackfunction == "undefined") {
			callbackfunction = "showEditForm";
		 }



	if (checkData()) {
		// submit the form, save the changes and then re-create the main form
		// get the ID from the main form - this is hidden

		// save the main record, without any validation, then show a new sub record
		var postdata = formData("userDataCapture");
		var poststring = stripNonValidXMLCharacters(postdata);
		poststring = poststring.substr(0,poststring.length - 1);
		poststring = poststring+"&approved=0";
		
			minisitename = getMinisiteName();
			poststring = poststring+ "&minisitename="+minisitename


	if (document.getElementById('photoname')) {
		photoname = getPhotoName(document.getElementById('photoname').value);
		poststring = poststring + "&photoname="+ photoname;
	}


		xhReq = createXMLHttpRequest();
		// remove any dodgy characters
		minisite_group = getMinisiteGroup();
		poststring = poststring + "&parenttablename="+parenttablename+"&parentid="+parentid;
		poststring = poststring + "&lookuptablename="+lookuptablename+"&id="+lookupid;
		poststring = poststring + "&action=saveNewChildShowExistingParent&mfcAction=processEditData&minisite_group="+minisite_group;
		 xhReq.open("POST", "mfcPhpRequests.php", true);
		 xhReq.onreadystatechange = window[callbackfunction];
	 //
		 try {
		   xhReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		   //xhReq.setRequestHeader('Content-Type','text/html')
		 }
		 catch (e) {
			// this only works in internet explorer
		 }
		//alert(poststring);
		xhReq.send(poststring);
	}

		
}

function showNextModerateLookup(lookuptablename, lookupid, parenttablename, parentid,callbackfunction) {
	
	 // if no callback function is provided, then use the standard mfc callback function
	 if (typeof callbackfunction == "undefined") {
		callbackfunction = "getNextModeratedLookup";
	 }

	// in this case, the child record should be deleted from the database first
	// this is a PROPER delete as opposed to a 'delete' requested by the user / moderator, whic
	// only flags the data as deleted

	// so the CANCEL button should only appear for an 'add new' operation


	xhReq = createXMLHttpRequest();
	// remove any dodgy characters
	var postdata = formData("userDataCapture");
	var poststring = stripNonValidXMLCharacters(postdata);
	poststring = poststring.substr(0,poststring.length - 1);
	
	poststring = poststring + "&parenttablename="+parenttablename+"&parentid="+parentid;
	poststring = poststring + "&lookuptablename="+lookuptablename+"&lookupid="+lookupid;
	poststring = poststring + "&action=showNextChildExistingParent&mfcAction=processEditData";
	
	minisitename = getMinisiteName();
	minisite_group = getMinisiteGroup();
	poststring = poststring+ "&minisitename="+minisitename+"&minisite_group="+minisite_group;

	 xhReq.open("POST", "mfcPhpRequests.php", true);
	 xhReq.onreadystatechange = window[callbackfunction];

	 //
	 try {
	   xhReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	   //xhReq.setRequestHeader('Content-Type','text/html')
	 }
	 catch (e) {
		// this only works in internet explorer
	 }
	//alert(poststring);
	xhReq.send(poststring);
}




function showPreviousModerateLookup(lookuptablename, lookupid, parenttablename, parentid,callbackfunction) {
	 // if no callback function is provided, then use the standard mfc callback function
	 if (typeof callbackfunction == "undefined") {
		callbackfunction = "getPreviousModeratedLookup";
	 }


	// in this case, the child record should be deleted from the database first
	// this is a PROPER delete as opposed to a 'delete' requested by the user / moderator, whic
	// only flags the data as deleted

	// so the CANCEL button should only appear for an 'add new' operation


	xhReq = createXMLHttpRequest();
	// remove any dodgy characters
	var postdata = formData("userDataCapture");
	var poststring = stripNonValidXMLCharacters(postdata);
	poststring = poststring.substr(0,poststring.length - 1);

	poststring = poststring + "&parenttablename="+parenttablename+"&parentid="+parentid;
	poststring = poststring + "&lookuptablename="+lookuptablename+"&lookupid="+lookupid;
	poststring = poststring + "&action=showPreviousChildExistingParent&mfcAction=processEditData";
	
	minisitename = getMinisiteName();
	minisite_group = getMinisiteGroup();
	poststring = poststring+ "&minisitename="+minisitename+"&minisite_group="+minisite_group;

	 xhReq.open("POST", "mfcPhpRequests.php", true);
	 xhReq.onreadystatechange = window[callbackfunction];

	 //
	 try {
	   xhReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	   //xhReq.setRequestHeader('Content-Type','text/html')
	 }
	 catch (e) {
		// this only works in internet explorer
	 }
	//alert(poststring);
	xhReq.send(poststring);
}

