function deleteData( Table, ID, returnURL, fileName ) {
	
	if (confirm('Delete this user?')) {
	
		var conn = $.ajax({
			url: "bin/delete.php?table=" + Table + "&id=" + ID,
			type: "POST",
			//dataType: "html",
			success: function(responseObject){
				if (responseObject.responseText) {
				//Ext.Msg.alert('Status', responseObject.responseText);  // ALERT QUERY RESPONSE FOR DEBUGGING
				}
				else {
					if (returnURL) {
						window.location = returnURL;
					//location.reload(true);
					}
				}
			},
			failure: function(){
			//Ext.Msg.alert('Status', 'Delete failed. Please try again.');
			}
		}).responseText;
		
	}
}

function saveData( viewType, formName, returnURL, reportURL, identifier, identifier2, identifier2type, email ) {
	
	//tinyMCE.triggerSave(); // trigger tinymce hidden field updates
	
	var formValid = $("#"+formName).valid();  // call jquery validator
	
	if(formValid==true) {
	
		// SAVE FORM DATA IF CONFIRM SAVE IS TRUE (ABOVE)
		theForm = document.getElementById( formName );
	
		var query = $('#'+formName+" :input").fieldSerialize();
		
		var conn = $.ajax({
		      url: "bin/dataupdate.php?view="+viewType+"&table="+formName,
		      type: "POST",
		      data: query,
		      //dataType: "html",
		      success: function(responseText){
				if(responseText && responseText.substr(0,9)!='redirect:') {
					//Ext.Msg.alert('Status', responseObject.responseText);  // ALERT QUERY RESPONSE FOR DEBUGGING
				} else {
					// ONLY RETURN TO LIST SCREEN IF RETURNURL PROVIDED (SO IF REPORT IS RUN THEN IT DOESN'T RETURN BACK TO LIST)
					if(returnURL) {
						if(responseText.substr(0,9)=='redirect:') {
							var redirect = responseText.replace("redirect:","");
							returnURL += redirect;
						}
						window.location = returnURL;
					}
				}
		      },
			  failure: function() {
				//Ext.Msg.alert('Status', 'Save failed. Please try again.');
			  }
		   }
		).responseText;	
	}
}


function validatePassword( viewType, formName, password1, password2, returnURL, reportURL, identifier, identifier2, identifier2type ) {
var invalid = " "; // Invalid character is a space
var minLength = 6; // Minimum length
var pw1 = document.getElementById(password1).value;
var pw2 = document.getElementById(password2).value;
// check for a value in both fields.
if (pw1 == '' && pw2 == '' && viewType != 'add') {
postForm( viewType, formName, returnURL, reportURL, identifier, identifier2, identifier2type );
return true;
}
if (pw1 == '') {
alert('Please enter a password.');
return false;
}
if (pw2 == '') {
alert('Please enter your password twice.');
return false;
}
// check for minimum length
if (pw1 < minLength) {
alert('Your password must be at least ' + minLength + ' characters long. Try again.');
return false;
}
// check for spaces
if (pw1.indexOf(invalid) > -1) {
alert("Sorry, spaces are not allowed.");
return false;
}
else {
if (pw1 != pw2) {
alert ("You did not enter the same new password twice. Please re-enter your password.");
return false;
}
else {
postForm( viewType, formName, returnURL, reportURL, identifier, identifier2, identifier2type );
return true;
      }
   }
}