function gotoLoginPage() {
	// switch the user back to the map legend tab ..
	//ManageTabPanelDisplay('tab1ready','tab2focus','tab3ready','content2','tab4ready');
	// then call the login page in a separate window ...
	
	window.open("http://www.london21.org/user/login");
}
function checkUserLoggedIn() {
	 xhReq = createXMLHttpRequest();
	 // find out which minisite we are in!
        var sPath = window.location.pathname;
	var siteName = "";	    	      
	// depending on the page, either shown the mini-site boundaries or show the 
	// minisite data 
	 try {
	   xhReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	   //xhReq.setRequestHeader("Content-Type","text/html")
	 }
	 catch (e) {
		// this only works in internet explorer
	 }
	
	 xhReq.open("POST", "isLoggedIn.php");
	 xhReq.onreadystatechange = isLoggedIn;
	 xhReq.send(null);
}
function checkUserDetails() {
	var theUsername = document.getElementById("username").value;
	var thePassword = document.getElementById("password").value;
	if (theUsername.length == 0) {
		alert("Please type in your username");
		return false;
	}
	if (thePassword.length == 0) {
		alert("Please type in your password");
		return false;
	}
	return true;
}

function doLogin() {
	if (checkUserDetails()){
		var theUsername = document.getElementById("username").value;
		var thePassword = document.getElementById("password").value;
		 xhReq = createXMLHttpRequest();
		 xhReq.open("POST", "processUserLogin.php", true);
		 xhReq.onreadystatechange = isLoggedIn;

		 try {
		   xhReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		   //xhReq.setRequestHeader("Content-Type","text/html")
		 }
		 catch (e) {
			// this only works in internet explorer
		 }
		 xhReq.send("username="+theUsername+"&password="+thePassword);
	}
}
function isLoggedIn() {
   if (xhReq.readyState != 4)  { 
   		return;
   	}
	var serverResponse = xhReq.responseText;
	
	// if the user is logged in then actually switch to the tab!
	//alert(xhReq.responseText);
	if (serverResponse.indexOf("User") > -1) { 
		document.getElementById('captureinstructions').style.display = "inline"; 
		document.getElementById('currentStep').style.display = "none"; 
		ManageTabPanelDisplay('tab1ready','tab2ready','tab3ready','tab4focus','content4');
		setupStep1();
	}
	if (serverResponse == "Not Logged In") { 
		document.getElementById('captureinstructions').style.display = "none"; 
		joinHTML = "You must log in to Community Maps to add data";
		joinHTML = joinHTML + "<br><br>";
		joinHTML = joinHTML + "If you are not registered as a London21 user, click <br><a href=\"#\" onclick=\"javascript:gotoLoginPage()\">here</a>";
		joinHTML = joinHTML + " to register.  You can add data once your registration is activated.";
		joinHTML = joinHTML + "<br><br>";
		joinHTML = joinHTML + "<table>";
		joinHTML = joinHTML + "<tr><td>User e-mail:" + "</td><td><input id=\"username\" type=\"text\"></td></tr>";
		joinHTML = joinHTML + "<tr><td>Password: "+ "</td><td><input id=\"password\" onkeypress=\"checkEnterUserLogin(event)\" type=\"password\"></td></tr>";
		joinHTML = joinHTML + "<tr><td colspan = 2><button id=\"dologin\" type=\"button\" name=\"dologin\"  onclick=\"doLogin()\">Login</button></td></tr>";
		joinHTML = joinHTML + "</table>";
		joinHTML = joinHTML + "<br>";
		joinHTML = joinHTML + "If you experience problems logging in or whilst you are adding data, please <b><a href=\"http://communitymaps.london21.org/version2/includes/ContactUs.php\"><font color=\"black\">Contact Us</font></a></b>.";
		document.getElementById('currentStep').innerHTML = joinHTML;
		ManageTabPanelDisplay('tab1ready','tab2ready','tab3ready','tab4focus','content4');
		
	}
	
 }
