var xmlHttp;
var drawingHome;

////////////////////////////////////////////////////////////////////////////////
// AJAX Functions
////////////////////////////////////////////////////////////////////////////////

function getXMLObject()  //XML OBJECT
{
	xmlHttp = false;
	
	try 
	{
		xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");  // For Old Microsoft Browsers
	}
	catch (e) 
	{
		try 
		{
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");  // For Microsoft IE 6.0+
		}
		catch (e2) 
		{
			xmlHttp = false;   // No Browser accepts the XMLHTTP Object then false
		}
   }
   
   if (!xmlHttp && typeof XMLHttpRequest != 'undefined') 
   {
		xmlHttp = new XMLHttpRequest();        //For Mozilla, Opera Browsers
   }
   
   return xmlHttp;  // Mandatory Statement returning the ajax object created
}

function handleLoginResponse() 
{
	if (xmlHttp.readyState == 4) 
	{
		if(xmlHttp.status == 200) 
		{
			drawLoginContainer(xmlHttp.responseText);
			drawMenu();
		}
		else 
		{
			alert("Error during AJAX call. Please try again");
		}
	}
}

function handleActivateResponse()
{
	if (xmlHttp.readyState == 4) 
	{
		if(xmlHttp.status == 200) 
		{
			document.getElementById("message_div").innerHTML = xmlHttp.responseText;
		}
		else 
		{
		alert(xmlHttp.status);
			alert("Error during AJAX call. Please try again");
		}
	}
}

function handleChangePassResponse() 
{
   if (xmlHttp.readyState == 4) 
   {
     if(xmlHttp.status == 200) 
	 {
		$ret = xmlHttp.responseText;
		if ($ret == "passChanged")
		{
			document.getElementById("update_status").innerHTML = "Password Changed";
			document.getElementById("update_status").style.color = "green";
		}
		
		if ($ret == "oldPassInvalid")
		{
			document.getElementById("update_status").innerHTML = "Old Password Invalid!";
			document.getElementById("update_status").style.color = "red";
		}
		else
		{
			logoff();
		}
		
		document.getElementById("oldPass").value = "";
		document.getElementById("newPass").value = "";
     }
     else 
	 {
        alert("Error during AJAX call. Please try again");
     }
   }
}

function handleRecoverPassResponse()
{
	if (xmlHttp.readyState == 4) 
	{
		if(xmlHttp.status == 200) 
		{	
			$ret = xmlHttp.responseText;
			document.getElementById("recover_status").innerHTML = $ret;
		
			if ($ret.indexOf("Error") != -1)
				document.getElementById("recover_status").style.color = "red";
			else
				document.getElementById("recover_status").style.color = "green";
	   
		}
		else 
		{
			alert("Error during AJAX call. Please try again");
		}
	}
}

function handleNewUserResponse() 
{
   if (xmlHttp.readyState == 4) 
   {
     if(xmlHttp.status == 200) 
	 {	
		$ret = xmlHttp.responseText;
		document.getElementById("registration_status").innerHTML = $ret;
		
		if ($ret.indexOf("Error") != -1)
			document.getElementById("registration_status").style.color = "red";
		else
			document.getElementById("registration_status").style.color = "green";
	   
     }
     else 
	 {
        alert("Error during AJAX call. Please try again");
     }
   }
}

function handleTop5Response()
{
	if (xmlHttp.readyState == 4) 
	{
		if(xmlHttp.status == 200) 
		{
			document.getElementById("current_standings_container").innerHTML = xmlHttp.responseText;
		}
		else 
		{
			alert("Error during AJAX call. Please try again");
		}
		
		if (drawingHome)
			drawInfoPage();
	}
}

function handleFullStandingsResponse()
{
	if (xmlHttp.readyState == 4) 
	{
		if(xmlHttp.status == 200) 
		{
			document.getElementById("full_standings_div").innerHTML = xmlHttp.responseText;
		}
		else 
		{
			alert("Error during AJAX call. Please try again");
		}
	}
}