
// Create XMLHttpRequest object
var http = createRequestObject();

// This is called when the user changes the completed? <select> field, in the demo request form
function changeDemoRequest(selectBox)
{

	var action = '&action=update_demo_request';
	var id = '&id=' + selectBox.id;
	var completed = '&completed=' + selectBox.value;
	var qstring = action+id+completed;

	http.open('POST','handle.php');
	http.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
	//http.onreadystatechange = handleDemoRequestResponse; TODO - see I need to update something via javascript
	http.send(qstring);

}

// An event handler which awaits a response from the server
function handleDemoRequestResponse()
{
	/* Make sure that the transaction has finished. The XMLHttpRequest object
	has a property called readyState with several states:
	0: Uninitialized
	1: Loading
	2: Loaded
	3: Interactive
	4: Finished */
	if (http.readyState == 4)
	{
		if(http.status == 200)/* The request has succeeded. */
		{
			// Get HTTP Response
			var results = http.responseText.split('|');

			var id = results[0];
			var htmlCode = results[1];

			alert("id = " + id);
			alert("htmlCode = " + htmlCode);

			// Get div sections
			var r = document.getElementById('mailed_'+id);

			// Replace div section with appropriate input field
			if ((r != null) && (htmlCode != null)) {
				r.innerHTML = htmlCode;
			}

		}
	}
}

