/**
* This JavaScript document was created
* by James Socol ((c) 2006) for the 
* Confucius Institute at Michigan
* State University. Please do not use,
* modify or distribute it without
* permission.
*/

function Ajax ()
{
	if (window.XMLHttpRequest) {
		var ajax = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		var ajax = new ActiveXObject('Microsoft.XMLHTTP');
	}
	ajax.onreadystatechange = function() { setPage(ajax) };
	return ajax;
}

function getList (category)
{
	if (category == '') {
		clearPage();
	}else{
		var ajax = new Ajax;
		ajax.open("GET", "search.asp?searchText="+category, true);
		ajax.send('');
		var searchbox = document.getElementById('searchText');
	}
}

function getItem (id)
{
	var ajax = new Ajax;
	ajax.open("GET", "view.asp?id="+id, true);
	ajax.send('');
}

function setPage (ajax)
{
	if (ajax.readyState == 4) {
		if (ajax.status == 200) {
			if (ajax.responseText != '') {
				document.getElementById('rewrite').innerHTML = ajax.responseText;
			}
		}
	} else if (ajax.readyState == 2) {
		document.getElementById('rewrite').innerHTML = 
			'<p style="text-align:center; color: #444;">'+
			'<img src="../images/loading.gif" height="24" width="24" alt="Loading." />'+
			'Loading...</p>';
	}
}

function doSearch (words)
{
	var searchbox = document.getElementById('searchText');
	if (words == '' || words == 'Search') {
		clearPage();
	} else {
		getList(words);
	}
}

function fSearch ()
{
	var searchbox = document.getElementById('searchText');
	if (searchbox.value == 'Search') {
		searchbox.value = '';
		searchbox.className = 'searchFocus';
	}
	return true;
}

function bSearch ()
{
	var searchbox = document.getElementById('searchText');
	if (searchbox.value == '') {
		searchbox.value = 'Search';
		searchbox.className = 'searchBlur';
	}
	return true;
}

function clearPage ()
{
	document.getElementById('rewrite').innerHTML = 
		'<p style="text-align:center; font-weight: bold; margin-bottom: 5em;">'+
		'Welcome! Use the links and search box to navigate our '+
		'lessons in Chinese.</p><p>&nbsp;</p><p>&nbsp;</p>';
}