		function newXMLHttpRequest() {

			  var xmlreq = false;
			
			  if (window.XMLHttpRequest) {
			
			    // Create XMLHttpRequest object in non-Microsoft browsers
			    xmlreq = new XMLHttpRequest();
			
			  } else if (window.ActiveXObject || !(window.XMLHttpRequest)) {
			
			    // Create XMLHttpRequest via MS ActiveX
			    try {
			      // Try to create XMLHttpRequest in later versions
			      // of Internet Explorer
			
			      xmlreq = new ActiveXObject("Msxml2.XMLHTTP");
			
			    } catch (e1) {
			
			      // Failed to create required ActiveXObject
			
			      try {
			        // Try version supported by older versions
			        // of Internet Explorer
			
			        xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
			
			      } catch (e2) {
			
			        // Unable to create an XMLHttpRequest with ActiveX
			      }
			    }
			  }
			  return xmlreq;
			}
			
			
			function loginUser(cmd,userName,password,secureId) {
			  // Obtain an XMLHttpRequest instance
			  var req = newXMLHttpRequest();
			  // Set the handler function to receive callback notifications
			  // from the request object
			  var handlerFunction = getReadyStateHandler(req, processResponse);
			  req.onreadystatechange = handlerFunction;
			  
			  // Open an HTTP POST connection to the xdrive api.
			  // Third parameter specifies request is asynchronous.
			  req.open("POST", ("/ProxyServlet?rand=" + Math.random()), true);
			  
			  var params = "{\"user\":{\"type\":\"MemberObject\",\"username\":\"" + userName + "\",\"password\":\"" + password +   "\",\"secureId\":\"" + secureId + "\"}}";
			  
			  // Specify that the body of the request contains form data
			 req.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=UTF-8");
			 req.send("data="+params + "&cmd=" + cmd );
			  
			}
			
			
	function openLogin()	{
		var legacy = window.open("/includes/legacy_notice.jsp", "legacyNotice", "width=400, height=230");
		legacy.focus();
	}

	
	function aolLoginUser(cmd,token,userName) {
			  // Obtain an XMLHttpRequest instance
			  var req = newXMLHttpRequest();
			  // Set the handler function to receive callback notifications
			  // from the request object
			  var handlerFunction = getReadyStateHandler(req, checkResponse,userName);
			  req.onreadystatechange = handlerFunction;
			  
			  // Open an HTTP POST connection to the xdrive api.
			  // Third parameter specifies request is asynchronous.
			  req.open("POST", ("/ProxyServlet?rand=" + Math.random()), true);
			  
			  var params = token;
			  
			
			  // Specify that the body of the request contains form data
			 req.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=UTF-8");
			 req.send("token="+params + "&cmd=" + cmd );
			  
	}
			
		

 var submitted = false;
 	function doSubmit() {
		if (submitted)
			return false;

		if (document.loginform.screenname.value == "") {
			alert("Please enter the screen name.");
		}	else if (document.loginform.password.value == "") {
			alert("Please enter the password.");
		}	else {
			document.cookie = "cookietest=yes; path=/;";
			var testCookie = document.cookie;
			if (testCookie.indexOf("cookietest=yes") == -1)	{
				alert('This application requires cookies to be set in the browser. Please enable cookies.');
			}	else {
			
				var username = trimString(document.loginform.screenname.value);
				var password = document.loginform.password.value;
				var secureid=null;
				if(document.getElementById("secureid") != null)
					secureid = document.getElementById("secureid").value;

				submitted = true;
				loginUser("member.login",username,password,secureid);
				return false;
			}
		}
		return false;
	}
	

	function trimString(str) {
		return str.replace(/ /g,"");
	}




	function displayError(message, show) {
		var displayError = (show == null || show) ? true : false;
		if(displayError) {
			var loginError = "Oops...There was an error. ";
			//var errorMessage = document.getElementById("errorMessage");
			var errorMessage = "";
			//if(errorMessage != null) errorMessage.innerHTML = loginError + ((message == null) ? "" : message);
			if(errorMessage != null) errorMessage = loginError + ((message == null) ? "" : message);
			alert(errorMessage);
			//document.getElementById("errorMessage").style.display="block";
		}
//		var error = document.getElementById("error");
//		if(error != null) error.style.display = displayError ? "block" : "none";
	}

	function displaySecureIdField(displaySecureId) {
		
		if (displaySecureId)
		{
			document.getElementById("loginFields").style.display="none";
			document.getElementById("secureIdField").style.display =  "block";
			document.getElementById("secureid").value = "";
			document.getElementById("secureid").focus();
			

		}
		else
		{
			document.getElementById("secureIdField").style.display =  "none";
			document.getElementById("loginFields").style.display="block";
		}
	
		
	}

	
	function processGetgetInfoResponse(getInfoResponse){
		if(getInfoResponse!= null && getInfoResponse.response) {
			if(getInfoResponse.response.statusCode != null && getInfoResponse.response.statusCode == 200) {
				if(getInfoResponse.response.data != null && getInfoResponse.response.data.token != null && getInfoResponse.response.data.userData.loginId != null)
					loginId = getInfoResponse.response.data.userData.loginId;
				if((getInfoResponse.response.data.userData.loginId).indexOf("@") == -1)
					getInfoResponse.response.data.userData.loginId = getInfoResponse.response.data.userData.loginId + "@aol.com";
				var userName = getInfoResponse.response.data.userData.loginId;
				aolLoginUser("member.aollogin", token, userName);
			} 

		}

	}

