function evalKey(e) {
	if( e.keyCode == 13 ) {
		pageJump(1);
	}
}

function pageJump(page) {
	$('CurPage').value = page;
	reqRecords();
}

function reqBio(id) {
	$('loadingIndicator').show();
	new Ajax.Request('halloffamefetchbio.asp', {
		parameters: 'id=' + id,
		onSuccess: function(transport) {
			Effect.toggle('loadingIndicator', 'blind', {duration: 0.3});
			$('ajaxTargetBio').update('<p>' + transport.responseText + '</p>');
		},
		onFailure: function() {
			Effect.toggle('loadingIndicator', 'blind', {duration: 0.3});
			$('ajaxTargetBio').update('<p>An error has occured and the biography could not be accessed.</p>');
		}
	});
	
	document.getElementById('searchName').focus();
}

function reqRecords() {
	$('ajaxTargetBio').update('');
	
	// Build hash of values to POST
	var h = $H({
		CurPage: document.getElementById('CurPage').value,
		orderBy: document.getElementById('orderBy').value,
		searchName: document.getElementById('searchName').value,
		searchSport: document.getElementById('searchSport').value,
		searchYear: document.getElementById('searchYear').value
	});
	
	$('loadingIndicator').show();
	new Ajax.Request('halloffamefetch.asp', {
		parameters: h.toQueryString(),
		onSuccess: function(transport) {
			Effect.toggle('loadingIndicator', 'blind', {duration: 0.3});
			$('ajaxTarget').update(transport.responseText);
		},
		onFailure: function() {
			Effect.toggle('loadingIndicator', 'blind', {duration: 0.3});
			$('ajaxTarget').update('<p>An error has occured and the hall of fame records could not be accessed.</p>');
		}
	});
	
	document.getElementById('searchName').focus();
}

function resort(byWhat) {
	var currSort = document.getElementById('orderBy').value.split('_');
	if( currSort[0] == byWhat ) {
		if( currSort[1] == 'ASC' ) {
			currSort[1] = 'DESC';
		}
		else {
			currSort[1] = 'ASC';
		}
		$('orderBy').value = currSort.join('_');
	}
	else {
		currSort[0] = byWhat;
		$('orderBy').value = currSort.join('_');
	}
	reqRecords();
}

// For Safari:
function trapSubmit() {
	pageJump(1);
	return false;
}