function getHTTPObject() {

	if (window.ActiveXObject)
		return new ActiveXObject("Microsoft.XMLHTTP");
	else if (window.XMLHttpRequest)
	    return new XMLHttpRequest();
	else
		alert("Your browser does not support AJAX.");
	return null;
}
function doLogin() {

	var url = "http://www.calendargenerator.co.uk/calendar/dologin.php";
	var username =  document.clientlogin.cg_username.value;
	var password = document.clientlogin.cg_password.value;
	
	if (!username | ! password)
		return;
	
	var params = "?username="+username+"&password="+password;
	oHTTP = getHTTPObject(); 
	oHTTP.open("GET", url+params, true);
	oHTTP.onreadystatechange = useHttpResponse;
	oHTTP.send(null);
}
function useHttpResponse() {

	if(oHTTP.readyState == 4)
	{
		if (oHTTP.responseText != '#')
		{
			var arr = document.getElementsByTagName('h3');
			for(var i=0;i<arr.length;i++)
				if (arr[i].innerHTML == "Client login")
					arr[i].innerHTML = "Your calendars";
			var el = document.getElementById("client_login");
    		el.innerHTML = oHTTP.responseText;
	    } else {
	    		if (!document.clientlogin.cg_username.value && !document.clientlogin.cg_password.value)
	    			return;
	    		alert("Incorrect username/password combination.");
	    		document.clientlogin.cg_username.value = "";
	    		document.clientlogin.cg_password.value = "";
	    }
	}
}
function doLogout() {

	var url = "http://www.calendargenerator.co.uk/calendar/logout.php";
	oHTTP = getHTTPObject(); 
	oHTTP.open("GET", url, true);
	oHTTP.send(null);
	window.location = "http://www.calendargenerator.co.uk";
}

