

/* -------------------------- */
/* LOGIN */
/* -------------------------- */
/* Required: var nocache is a random number to add to request. This value solve an Internet Explorer cache issue */
function login() 
{
	var nocache = 0;
	var http = create_http();
	// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
	var uid = encodeURI(document.getElementById('user').value);
	var pwd = document.getElementById('pwd').value;
	var mid = encodeURI(document.getElementById('mid').value);

	// Set te random number to add to URL request
	nocache = Math.random();
	// Pass the login variables like URL variable
	http.onreadystatechange = function() 
	{
		if(http.readyState == 4){
			var response = http.responseText;
			
			if(response == 1) {
				window.location = '/interface/index.php';
			}
			else if (response == 2){
				window.location = '/inactive.php';
			}
			else{ //response = 0. or page not found
				// if login fails
				document.getElementById('login_error_msg').innerHTML='Login Failed! Try again.';
			} 
//			alert('response: ' + response);
		}
	}
//	alert('opening: ' +  'login.php?user='+uid+'&pwd='+pwd+'&mid='+mid+'&nocache='+nocache);
	http.open('GET', '/login.php?user='+uid+'&pwd='+md5(pwd)+'&mid='+mid+'&nocache='+nocache, true);
	http.send(null);
}
	
	
	
	




