// JavaScript Document
/* LOGIN */
/* -------------------------- */
/* Required: var nocache is a random number to add to request. This value solve an Internet Explorer cache issue */
var nocache = 0;
function login() {
//	alert ("yes");
	//window.location = 'http://localhost/emedicine/index.php?action=home';
// Optional: Show a waiting message in the layer with ID ajax_response
document.getElementById('login_response').innerHTML = "Loading..."
// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
var email = encodeURI(document.getElementById('Email').value);
var psw = encodeURI(document.getElementById('Password').value);

// Set te random number to add to URL request
nocache = Math.random();
// Pass the login variables like URL variable
http.open('get', 'user.php?action=authentication&Email='+email+'&psw='+psw+'&nocache = '+nocache);
http.onreadystatechange = loginReply;
http.send(null);
}
function loginReply() {
if(http.readyState == 4){ 
var response = http.responseText;
if(response != 1){
// if login fails
document.getElementById('login_response').innerHTML = 'Either the email address and password is incorrect, or you need to activate your account.';
// else if login is ok show a message: "Welcome + the user name".
} else {	
			if (response == 1)
			{
					
				window.location = 'member.php?action=dashboard';
			}else{
document.getElementById('login_response').innerHTML = ''+response;
			}
}
}
}
