//javascript file

function login() {
	var txtUsername = document.getElementById("txtUsername").value;
	var txtPassword = document.getElementById("txtPassword").value;
	var url = "include/login_inc.php?txtUsername="+txtUsername+"&txtPassword="+txtPassword+"&sid="+Math.random();
	//alert(url);
	xmlHttp = getXmlHttp();
	xmlHttp.onreadystatechange=login2; 
	xmlHttp.open("POST",url,true);
	xmlHttp.send(null);
}

function login2() {
	if ((xmlHttp.readyState==4) || (xmlHttp.readyState=="complete")) {
		var txtResponse = xmlHttp.responseText;
		txtResponse = txtResponse.match(/\S+(?:\s+\S+)*/);
		//alert("txtResponse ~"+txtResponse.match(/\S+(?:\s+\S+)*/)+"~");
		if (txtResponse=="valid") {
			window.location="addBaby.php";
		} else {
			document.getElementById("spnLoginFail").innerHTML = "Incorrect username or password";
		}
	}
}

function recover() {
	var txtEmail = document.getElementById('txtEmail').value;
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (txtEmail != '' || filter.test(txtEmail.value)) {
		document.getElementById("spnLoginFail").style.display = 'none';
		return true;
	}
	else{
		document.getElementById("spnLoginFail").innerHTML = "Incorrect E-mail Address";
		return false;
	}
}

function returnKey(event) {
	//alert(event.keyCode);
	if (event.keyCode==13) {
		login();
	}
}

