// JavaScript Document

function submit_login () {

	var XObj;
	try { XObj = new XMLHttpRequest(); }
	catch(e) { XObj = new ActiveXObject(Microsoft.XMLHTTP); }
	
	XObj.onreadystatechange = function () {
		if(XObj.readyState == 4) {
			var xml = XObj.responseXML;
		
			if(!xml) {
				var message = "Sorry, we have be unable to access"
					+ " any account information at this time.";
				alert(message);
				return false;
			}

			var array = xml_to_array(xml);
			var auth = array['auth'][0];
			var serial = auth['serial'];

			if(!serial) {
				var message = "Sorry no account found matching the"
					+ " email and password you provided.";
				alert(message);
				return false;
			}

			if(serial == "inactive") {
				var message = "Sorry your account is not active."
					+ " You must check your email to confirm"
					+ " this account.";
				alert(message);
				return false;
			}

			var type = auth['type'];
			login(serial, type);
		}
	}
	
	var email = _get('email').value;
	var password = _get('password').value;

	if(!email.match('@')) {
		alert("You must enter a valid email.");
		return false;
	}
	
	if(!password || password.length < 6 || password.length > 12) {
		alert("You did not enter a valid password. Your password must be 6-12 charcters long.");
		return false;
	}
	
	XObj.open('POST','php/login.php?email='+email+'&passwd='+password,true);
	XObj.send(null);
}