/* ---------------------------- */
/* XMLHTTPRequest Enable */
/* ---------------------------- */
function client_createObject() {
var request_type;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
request_type = new ActiveXObject("Microsoft.XMLHTTP");
}else{
request_type = new XMLHttpRequest();
}
return request_type;
}

var httpn = client_createObject();

/* -------------------------- */
/* LOGIN */
/* -------------------------- */
/* Required: var nocache is a random number to add to request. This value solve an Internet Explorer cache issue */
var nocache = 0;
function client_login() {
// Optional: Show a waiting message in the layer with ID ajax_response
document.getElementById('login_response2').innerHTML = "<img src=ajax/heart.gif>"
// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
var email = encodeURI(document.getElementById('txtusername1').value);
var psw = encodeURI(document.getElementById('txtpassword1').value);
// Set te random number to add to URL request
nocache = Math.random();
// Pass the login variables like URL variable
httpn.open('get', 'client_login.php?email='+email+'&psw='+psw+'&nocache = '+nocache);
httpn.onreadystatechange = client_loginReply;
httpn.send(null);
}
function client_loginReply() {
if(httpn.readyState == 4){
var response = httpn.responseText;
if(response == 0){
// if login fails
document.getElementById('login_response2').innerHTML = '<span style="color:#ff0000">Login failed! Verify your id and password</span>';
// else if login is ok show a message: "Welcome + the user name".
} else {
document.getElementById('login_response2').innerHTML = 'Welcome '+response+', <a href="clients/home.php">Go to My Account</a>';
}
}
}
