var glbA = ""; // array
var glbB = ""; // array
var glbH = ""; // HTML string
var glbJ = ""; // for j=
var glbT = ""; // temporary value

function getComm(PID) { 
	glbPID = PID;
    glbDest = 'getcomm.php';
    glbParams = 'p=' + glbPID;
//alert(glbParams);
	xmlhttp = window.XMLHttpRequest? new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");
    xmlhttp.onreadystatechange = getComm2;
    xmlhttp.open("POST", glbDest, true);
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
    xmlhttp.send(glbParams);
}
function getComm2() {
    if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
//alert(xmlhttp.responseText);
		glbA = xmlhttp.responseText.split("|");  // each message
		glbH = "";
		for (glbJ=1; glbJ<glbA.length; glbJ++) {
			glbB = glbA[glbJ].split("~");  // each field
			glbH += "<hr>"+glbB[0]+" ...("+glbB[1]+" "+glbB[2]+", "+glbB[3]+")<br />";  // Text-First-Last-Location
		}
		glbT = "comms"+glbPID;
		document.getElementById(glbT).innerHTML = glbH;

	}
}
function addComm(PID) {
	glbPID = PID;
	glbT = "comms"+glbPID;
$HTML = '<form name="commForm"><br /><span style="font-size:18px; font-weight:bold; text-align:center;">';
$HTML += 'Please Make A Comment</span><br /><br />';
$HTML += 'Enter your Firstname:<br /><input type="text" name="first" value="" size="30"><br />';
$HTML += 'and your Lastname:<br /><input type="text" name="last" value="" size="30"><br />';
$HTML += 'plus your Country or Location:<br /><input type="text" name="loc" value="" size="30"><br />';
$HTML += 'For Paul\'s eyes only? <input type="checkbox" name="priv"><br />';
$HTML += 'R.S.V.P. to this email address:<br /><input type="text" name="ema" value="" size="30"><br />';
$HTML += 'Your Comment - up to 1,000 characters:<br /><textarea name="comm" rows="4" cols="36" wrap="virtual"></textarea>';
$HTML += '<br /><center><input type="button" name="submet" value="Post Comment" onclick="putComm()"></center></form>';
	document.getElementById(glbT).innerHTML = $HTML;
	document.commForm.first.focus(); // hmm... multiple open forms !!

}
function putComm() { 	
    glbDest = 'putcomm.php';
    glbParams = 'p=' + glbPID;
	glbParams += '&f=' + escape(document.commForm.first.value);
	glbParams += '&l=' + escape(document.commForm.last.value);
	glbParams += '&w=' + escape(document.commForm.loc.value);
	glbParams += '&v=' + document.commForm.priv.checked;
	glbParams += '&e=' + escape(document.commForm.ema.value);
	glbParams += '&c=' + escape(document.commForm.comm.value);
//alert(glbParams);
	xmlhttp = window.XMLHttpRequest? new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");
    xmlhttp.onreadystatechange = putComm2;
    xmlhttp.open("POST", glbDest, true);
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
    xmlhttp.send(glbParams);
}
function putComm2() {
    if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
		document.getElementById(glbT).innerHTML = xmlhttp.responseText;
	}
}
