var xmlHttp;
var response;
var userName;

function login() {
   
    var username = document.loginForm.username.value;
    var password = document.loginForm.password.value;
    userName = username;

    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null) {
        alert ("This website uses AJAX. Javscript must be enabled!");
        return;
    }
    xmlHttp.onreadystatechange=stateChanged;
    xmlHttp.open("POST","../php/login.php",true);
    xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlHttp.send('username=' + username + '&password=' + password);
}

function stateChanged() {

    var link;
    if (xmlHttp.readyState==4) {
        response = xmlHttp.responseText;
	if (response == 'success') {
	    location.href = 'http://anashinteractive.com/flash/index.php?userName=' + userName;
	    
	    //link = 'http://anashinteractive.com/flash/index.php?userName=' + userName;
	    //newwindow=window.open(link,'blank','width=1000, height=700');
	    //if (!newwindow) {
		//alert ('You must allow popups for this site to log in from the home page.');
	    //}
	}
	else {

	    alert ("Invalid username and/or password.");
	}
    }
}

function GetXmlHttpObject() {

    var xmlHttp=null;

    try {
    // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    }
    catch (e) {
        // Internet Explorer
        try {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}

