function help(pageName, pxWide, pxHigh) {
	// pageName: pass either the full path to the help file, or the name only (no extension) for local help html files
	extAt = pageName.indexOf(".", pageName.length-5);
	if(extAt > 0) {
		pageName = pageName.toString();
	} else {
		// having the window name lets the browser re-use a window of the same name. The .toString is needed on IE or the open function does nothing
		pageName = "help/"+pageName+".html";
	}
	w = window.open(pageName, "Help", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=auto,resizable=yes,width="+pxWide+",height="+pxHigh);
	if(w == null || w.closed) {
		alert("New window was closed by a pop-up blocker, disable the pop-up blocker for your internal site.");
		return;
	}
	w.focus();
}

// asyncFlag lets the sv function know that it's OK to run async, unless unload was triggered
var asyncFlag = 1;
/* onchange is winning the race against window.onbeforeunload (at least on Firefox 3)
	which makes the final edit fire off async AJAX, which makes it
	fail to save when the user has typed something in a field
	and then clicks a link that exits the page. It's slower to leave an edited data field
	with async off, but something in window.onbeforeunload or the AJAX call needs a better trick
	to be reliable on exiting the form with a changed field.
	Async flag off in Firefox inhibits onreadystatechange, call next function in-line instead (IE calls onreadystatechange anyway)
*/

// make AJAX objects, and check for old pre-ajax browser
var ajaxAvail = 1;	// flag to indicate that AJAX is available in this browser
if(window.XMLHttpRequest) {
	gSsnPref = new XMLHttpRequest();					// code for IE7+, Firefox, Chrome, Opera, Safari
	gSqlData = new XMLHttpRequest();
	gPgClose = new XMLHttpRequest();	// always called syncronously, to wait for possible other AJAX async to finish when page unloads
	gChkDate = new XMLHttpRequest();	// always called syncronously, to wait for possible other AJAX async to finish when page unloads
} else if(window.ActiveXObject) {
	gSsnPref = new ActiveXObject("Microsoft.XMLHTTP");	// code for IE6, IE5
	gSqlData = new ActiveXObject("Microsoft.XMLHTTP");
	gPgClose = new ActiveXObject("Microsoft.XMLHTTP");
	gChkDate = new ActiveXObject("Microsoft.XMLHTTP");
} else ajaxAvail = 0;

if(ajaxAvail) {
	// ---- saving user's "session preferences" function
	gSsnPref.onreadystatechange=function() {
		if(gSsnPref.readyState==4) {
			if(gSsnPref.responseText == "0") location.reload();
			else alert(gSsnPref.responseText);
		}
	}
	// ---- saving data to mysql table function
	gSqlData.onreadystatechange=function() {
		if(gSqlData.readyState==4) {
			// if the page is unloading, Firefox (maybe others too) returns null responseText, presumably ignoring future feedback 
			// from the actual ajax program called. So ignoring a null just eliminates error reporting on a presumably correct saving of the data
			if((gSqlData.responseText.substr(0,1) != "0") && (gSqlData.responseText.length>0)) {
				alert("Save data message:\n\n"+gSqlData.responseText);
				return;
			}
			if(gSqlData.responseText.substr(1,1)=="&") {
				var updt = gSqlData.responseText.substr(2).split("=",2);
				document.getElementById(updt[0]).value = updt[1];
			}
		}
	}
	// ---- check date format (using php for consistency) - errors don't get reported to user
	gChkDate.onreadystatechange=function() {
		if(gChkDate.readyState==4) {
			if(gChkDate.responseText.substr(0,2)=="0&") {
				var updt = gChkDate.responseText.substr(2).split("=",2);
				document.getElementById(updt[0]).value = updt[1];
			}
		}
	}	
}
function prefUpdate(nm,vl) {
	if(!ajaxAvail) {alert ("Your browser does not support AJAX. You must update your browser to something newer than 2002!"); return false;}
	var url="../common-incl/prefSaveAjax.php?nm="+nm+"&vl="+vl;
	gSsnPref.open("GET",url,true);
	gSsnPref.send(null);
}	
function sv(table, id, nm, vl, nm2, vl2) {
	if(!ajaxAvail) {alert ("Your browser does not support AJAX. You must update your browser to something newer than 2002!"); return false;}
	// saves one or two values "vl" into the SQL field "nm" for record with the "id" in "table" 
	if((typeof nm2) == "undefined") var vltwo = "";
	else var vltwo = "&"+nm2+"="+encodeURIComponent(vl2);
	switch(table) {
		case "org": var url="../organizations/orgSaveAjax.php?id="+id+"&"+nm+"="+encodeURIComponent(vl)+vltwo; break;
		case "peo": var url="../people/peoSaveAjax.php?id="+id+"&"+nm+"="+encodeURIComponent(vl)+vltwo; break;
		default: alert("Invalid or missing table identifier.");
	}
	gSqlData.open("GET",url,asyncFlag);
	gSqlData.send(null);
}
function pageClose() {
	if(!ajaxAvail) return true;	// if no AJAX, then don't care about this
	var url="../common-incl/pageCloseAjax.php";
	gPgClose.open("GET",url,false);
	gPgClose.send(null);	// opens a php session, which will (I think) wait for any other open session to close before proceding
}	
function checkDateFormat(nm,vl) {
	if(!ajaxAvail) return true;	// if no AJAX, then don't care about this
	if(vl.length==0) return true;
	var url="../common-incl/dateFormatAjax.php?nm="+nm+"&vl="+vl;
	gChkDate.open("GET",url,true);
	gChkDate.send(null);
}	


