function cancelModeration(){
	//alert("cancel");
	doCloseInfoWindow();
	checkAdminUserLoggedIn();
	
	// clear the data from the map
	// and redisplay other data (depending on which layers are switched on or off)
	map.clearOverlays();
	updateMap(true);
}
function getPostString(tablename) {
	var postdata = formData("userDataCapture");
	var poststring = stripNonValidXMLCharacters(postdata);
	poststring = poststring.substr(0,poststring.length - 1);
	
	// now add the tablename
	//	poststring = poststring + "&tablename="+document.forms["processdata"].selected_data_type.value;
	poststring = poststring + "&tablename="+tablename;
	return poststring;
	
}
function updateData(tablename){
	// approved status is reset to 0
	if (checkData()) {
		poststring = getPostString(tablename);
		poststring = poststring+"&approved=0";
		sendModeratedDataToServer(poststring);
	}
	
}

function deleteData(tablename){
	if (confirm("You are about to delete this data - continue?")) {
		poststring = getPostString(tablename);
		poststring = poststring+"&approved=-2";
		sendModeratedDataToServer(poststring);
	}
}

function approveData(tablename) {
	//alert("approve data");
	if (checkData()) {
		var poststring = getPostString(tablename);
		poststring = poststring+"&approved=1";
		sendModeratedDataToServer(poststring);
	}
}

function refuseData(tablename) {
	poststring = getPostString(tablename);
	poststring = poststring+"&approved=-1";
	sendModeratedDataToServer(poststring);
}
function sendModeratedDataToServer(poststring) {
	xhReq = createXMLHttpRequest();
	
	// remove any dodgy characters
	
	
	
	poststring = poststring + "&action=saveModerate";
	 xhReq.open("POST", "processData.php", true);
	 xhReq.onreadystatechange = dataModerated;

	 //
	 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 dataModerated() {
	if (xhReq.readyState != 4)  {
   		return;
   	}
	var result = xhReq.responseText;
	//alert(result);
	if (result.indexOf("Your changes have been saved") > -1) {
		alert("Your changes have been saved");
	}
	// clear the map, alert the user, and refresh the displayed list of items for moderation ..
	doCloseInfoWindow();
	checkAdminUserLoggedIn();
	
	// clear the data from the map
	// and redisplay other data (depending on which layers are switched on or off)
	map.clearOverlays();
	updateMap(true);
	
}



function cancelCapture() {
	if (confirm("Cancel Data Capture?  You will lose all changes.")) {
		clearAllValues();
	}
}
function deleteCapture(tablename,id) {
// this is used where a record is first being created ...
	if (confirm("Cancel Data Capture?  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
			poststring = "";
			poststring = poststring + "&tablename="+tablename+"&id="+id;
			poststring = poststring + "&action=clearParent";
			 xhReq.open("POST", "processData.php", true);
			 xhReq.onreadystatechange = processCancelCapture;
			 //
			 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 processCancelCapture() {
if (xhReq.readyState != 4)  {
   		return;
   	}
	var result = xhReq.responseText;
	clearAllValues();
}




function saveData(tablename) {
	if (checkData()) {
		saveToServer(tablename);
	}

}

function saveToServer(tablename) {

	//alert("all data correct");
	
	xhReq = createXMLHttpRequest();
	poststring = formData("userDataCapture");
	
	
	
	// remove any dodgy characters
	
	//poststring = poststring.replace("\'"," ");
	poststring = stripNonValidXMLCharacters(poststring);
	//poststring = escape(poststring);
	// remove any single quotes ..
	
	poststring = poststring.substr(0,poststring.length - 1);




	// check if there is any information about a photo that has been uploaded
	// this will be held on a separate form as photos need separate handling
	if (document.getElementById('photoname')) {
		photoname = getPhotoName(document.getElementById('photoname').value);
		poststring = poststring + "&photoname="+ photoname;
	}
	// now add the tablename
	//poststring = poststring + "&tablename="+document.forms["processdata"].selected_data_type.value;
	poststring = poststring + "&tablename="+tablename;
	// now add the user id
	poststring = poststring + "&userID="+myUsername;


	// now add the minisite information ...
	 //var sPath = window.location;
//
	 //var paths = String(sPath).split("=");
	 //var minisitename = paths[1];
	 minisitename = getMinisiteName();
	poststring = poststring + "&minisitename="+minisitename;

	// if this is a geometry, then add coordinate information
	if (pts.length > 0) { 
		poststring = poststring + "&hasgeometry=true";
		// now add the coordinate information 
		poststring = poststring + "&geometrytype="+document.forms["processdata"].selected_geometrytype.value;

		// now iterate through the points and add to the push statement
		var pointsstring = "&points=";
	
		for (var i=0;i< pts.length ; i++) {
			pt = pts[i];
			pointsstring = pointsstring + pt.x +" "+pt.y +",";
		}
		//remove the last comma from pointstring
		pointsstring = pointsstring.substr(0,pointsstring.length -1);
		poststring = poststring + "&"+pointsstring;
	} // has pts.length > 0
	else {
		poststring = poststring + "&hasgeometry=false";
	} // pts.length = 0
	 
	 poststring = poststring +"&action=saveParent";
	 //xhReq.open("POST", "processDataCapture.php", true);
	 xhReq.open("POST", "processData.php", true);
	 xhReq.onreadystatechange = processed;
	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 processed() {

	// wait for the request to be ready
   if (xhReq.readyState != 4)  {
   		return;
   	}
	var result = xhReq.responseText;
	alert(result);
	startCapture = false;
	// clear all values if there has been a geometry captured ...
	if (pts.length > 0) {
		// note that this calls another response and invalidates the current response
		clearAllValues();
	}
	
}
