function cl_xmlHttpObject () {
 
    var xml_http_object;
    
    try {
        xml_http_object = new XMLHttpRequest();
    } catch(e) {
        try {
            xml_http_object = new ActiveXObject("Msxml2.XMLHTTP");
        } catch(e) {
            try {
                xml_http_object = new ActiveXObject("Microsoft.XMLHTTP");
            } catch(e) {
                //alert("ERROR: Your browser does not support AJAX.");
                return false;
            }
        }
    }
    
    return xml_http_object;
 
} 
function cl_login() {
 
    var ajax = new cl_xmlHttpObject();
    
    if (ajax) {
        
        var username = document.getElementById("username").value;
        var password = document.getElementById("password").value;
        var params = "username=" + username + "&password=" + password + "&sublogin=true";
        
        ajax.onreadystatechange = function () {
            var loginDiv = document.getElementById("loginDiv");
            
            if (ajax.readyState <4) {
                loginDiv.innerHTML = "Logging in as " + username + "...";
            } else if (ajax.readyState == 4) {
                if (ajax.responseText == "0") {
                    loginDiv.innerHTML = "Login successful. Redirecting...";
                    window.location = "logged_in.php";
                } else {
                    loginDiv.innerHTML = ajax.responseText;
                }
            }
        }
        
        ajax.open("POST", "process.php", true);
        
        ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        ajax.setRequestHeader("Content-length", params.length);
        ajax.setRequestHeader("Connection", "close");
        
        ajax.send(params);
        
    } else {
        alert('Your browser does not support AJAX. Please turn on Javascript in your browser options/preferences and try again.');
    }
    
} 
