// JavaScript Document

function set_cookie(id, callback) {

	var callback = function () {
		window.location='index.php';
	}

	var XObj;
	try { XObj = new XMLHttpRequest(); }
	catch(e) { XObj = new ActiveXObject(Microsoft.XMLHTTP); }
	
	XObj.onreadystatechange = function () {
		if(XObj.readyState == 4) {
			if(callback) {
				callback();
			}
		}		
	}		
			
	XObj.open('POST','php/set_cookie.php?id='+id,true);
	XObj.send(null);
}

function submit_login () {

	var XObj;
	try { XObj = new XMLHttpRequest(); }
	catch(e) { XObj = new ActiveXObject(Microsoft.XMLHTTP); }
	
	XObj.onreadystatechange = function () {
		if(XObj.readyState == 4) {
			var message = XObj.responseText;
			var data = message.split("<&sect;>", 2);
		
			if(data[0] == "error") {
				alert("Sorry no account found matching the email and password you provided.");
			} else {
				alert('no error');
				//window.location='index';
			}
		}
	}
	
	var email = $('email').value;
	var password = $('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);
}
