// JavaScript Document
var timeout;
function checkLogin(redirect){
	/* this function should get the username and password out of the text fields, then */
	/* create a form post and post them to the ajax url that will see if they are correct */
	/* or not. */
	postVars = new Array('username','password');
	if(document.getElementById('username').value == "" || document.getElementById('password').value == ""){
		if(document.getElementById('username').value == "")
			document.getElementById('username').style.borderColor = 'red';
		if(document.getElementById('password').value == "")
			document.getElementById('password').style.borderColor = 'red';
		return;
	}
	ajaxResponse = doAJAXRequest("ajax/generalAJAX.php?do=checkCredentials", createPostBuffer(postVars), "application/x-www-form-urlencoded");
	if(ajaxResponse == "true" && redirect == null)
		document.location="/home";
	else if(ajaxResponse == "true" && redirect != "")
		document.location=redirect;
	else{
		/* write the div that shows the error. */
		var errorDiv = document.getElementById("loginErrors");
		errorDiv.innerHTML = "<center><table width=\"300px\"><tr><td align=\"left\" width=\"48px\"><img src=\"images/error.gif\"></td><td align=\"center\">Incorrect username or password.</td></tr></table></center>";
		document.getElementById("password").value = "";
		clearTimeout(timeout);
		timeout = setTimeout("clearError()",10000);
	}
}

function clearError(){
	var errorDiv = document.getElementById("loginErrors");
	errorDiv.innerHTML = "";
}

function clearSuccess(){
	var successDiv = document.getElementById("loginSuccess");
	successDiv.innerHTML = "";
}
