/*
    This routine will handle the input box's entered event.
*/
function input_entered_bind() {
    var input = $('#input');
    if (input) {
        var submit = $('#submit');
        if (submit) {
            submit.click(function(event) {
                input_entered(input);
                return false;
            });
        }
        input.keyup(function(event) {
            if (event.which == 13) {
                input_entered(input);
            }
        });
    }
}

function input_entered(input) {
    if (input) {
		var contentdiv = $('#content_div');
		/* Store the input box's text value into local varible. */
		var inputtext_unproc = input.val();
		var inputtext_unicode = string2hexstring(inputtext_unproc); // Calls out the utility function.
		var inputtext_htmlencode = string2htmlencodestring(inputtext_unproc); // Calls out the utility function.
		/* Clean up the input box's text value. */
		input.val('');
		/* Make sure the input is not empty. */
		if (inputtext_unproc.length > 0) {
			/* Clean up the display box if this is the first input. */
			if (!first_input_entered) {
				contentdiv.html('');
				first_input_entered = true;
			}
			if (contentdiv) {
				contentdiv.prepend('<p>' + inputtext_htmlencode + '</p>');
			}
		}
		input.focus();
    }
}

$(document).ready(input_entered_bind);

var first_input_entered = false;
var inputs_entered = new Array();
