// when the page loads we create the gateway
function body_onLoad() {
	objGateway = new gateway("serverpages/eliza.cfm");
	objGateway.setListener('elizaSays');
}



// this function sends the patient's comments to Eliza
function patientSays() {
	var conversation = document.getElementById('conversation');
	var patientField = document.getElementById('patientField');
	var patientComment = patientField.value;
	var conversationScroll = document.getElementById('conversationScroll');
	patientField.value = "";
	conversation.innerHTML = conversation.innerHTML + '<p class=\'patient\'>&gt; ' + patientComment + '</p>';
	conversationScroll.focus();
	objGateway.setArguments( {patient:patientComment} ).request();
}



// this function handles the response from Eliza
function elizaSays(packet) {
	var conversation = document.getElementById('conversation');
	var patientField = document.getElementById('patientField');
	var conversationScroll = document.getElementById('conversationScroll');
	conversation.innerHTML = conversation.innerHTML + '<p class=\'eliza\'>&quot;' + packet + '&quot;</p>';
	// these two lines cause the conversation window to scroll 
	// to the bottom then return focus to the patient input field
	conversationScroll.focus();
	patientField.focus();
}


