//NOTE: _varName indicates JavaScript variable, $VarName indicates jQuery variable

//This is for tracking timeout events
var _windowTimeout = setTimeout("backToSearch()", 45000);

//Track the cursor's current focus
var $CurrentFocus;
$(document).ready(function() {
	//Bind focus events to all the text fields
	$(':text').bind('focus', function() {
		$CurrentFocus = $(this);
	});

	//Set the focus to the top text field when the document loads
	$(":text[name='query']").trigger('focus');
});

/*printChar takes the current "virtual keyboard's" keypress and adds it to the
* field that currently has the focus
* INPUT: _char - the character to add to the field
* OUTPUT: the updated string, placed in the field
*/
function printChar(_char) {
	//Clear the page redirect timeout
	clearTimeout(_windowTimeout);

	//Get the value already in the field
	//var _currentValue = $CurrentFocus.attr('value');
	//I'm hard-coding the value with the single query field to try and fix the touchscreen focus problem
	var _currentValue = document.getElementById('searchForm').query.value;
	var _newValue;

	if(_char == "backspace") {//If the user clicked "backspace" REMOVE the last character
		_newValue = _currentValue.substr(0, _currentValue.length-1);
	}
	else {//Otherwise, add the character to the value from the field
		_newValue = _currentValue + _char;
	}

	//Put the updated value back into the field
	//$CurrentFocus.attr('value', _newValue);
	document.getElementById('searchForm').query.value = _newValue;

	//Make sure focus is still on that field
	//$CurrentFocus.trigger('focus');

	//Reset the timeout
	_windowTimeout = setTimeout("backToSearch()", 45000);
}


function backToSearch() {
	window.location = "http://www.marcwest.net/intro.html";
}
