var xmlHTTP_VERSIONS = new Array('MSXML2.XMLHTTP.6.0', 'MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHttp');
var ajax_path = "http://iahperd.org/textpages/membership/retirees/";
// #####################################################################################################################################
// Initializes XMLHttpRequest Object ###################################################################################################
function GetXmlHttpObject()
{
	var xmlHttp = null;
	try
	 {
	        xmlHttp = new XMLHttpRequest();
	 }

	catch(e)
	 {
	        for(var i=0; i<xmlHTTP_VERSIONS.length && !xmlHttp; ++i)
		 {
		        try
		        {
		        	xmlHttp = new ActiveXObject(xmlHTTP_VERSIONS[i]);
		        }
                        catch(e) {}
		 }
	 }

	 if(!xmlHttp)
	  {
	        alert('Error creating the XMLHttpRequest Object');
	        return;
	  }
	 else
	  {
	        return xmlHttp;
	  }
}
// #####################################################################################################################################
function ajax_login()
{
		xmlHttp_login=GetXmlHttpObject();
		if (xmlHttp_login==null)
	  	{
	  		alert ("Your browser does not support AJAX!");
	  		return;
	  	}

		var MEMBERSHIP_ID = $("#MEMBERSHIP_ID").val();
		var REMEMBERSHIP_ID = $("#REMEMBERSHIP_ID").val();

		if(MEMBERSHIP_ID.length == 0 || REMEMBERSHIP_ID.length == 0)
		 {
			$("#status").html("Missing membership number.");	
			return;
		 }
		 
		if(MEMBERSHIP_ID !=  REMEMBERSHIP_ID)
		 {
			$("#status").html("Membership entries must match.");	
			return;
		 }

		var url="doLogin.php?MEMBERSHIP_ID=" + MEMBERSHIP_ID + "&sid=" + Math.random();

		xmlHttp_login.onreadystatechange=state_login;
		xmlHttp_login.open("GET",url,true);
		xmlHttp_login.send(null);
}

function state_login()
{
	switch(xmlHttp_login.readyState)
		 {
			case 1:
			case 2:
					$("#status").html("Authenticating .. Please Wait");
			break;

			case 4:
				xml_text = xmlHttp_login.responseText;
				
				if(xml_text == "OK")
				 {
					window.location.reload(); 
				 }
				else
				 {
					$("#status").html("Invalid membership number");	 
				 }
				
				
			break;
		 }
}
// #####################################################################################################################################
function ajax_logout()
{
		xmlHttp_logout=GetXmlHttpObject();
		if (xmlHttp_logout==null)
	  	{
	  		alert ("Your browser does not support AJAX!");
	  		return;
	  	}

		var url="doLogout.php?sid=" + Math.random();

		xmlHttp_logout.onreadystatechange=state_logout;
		xmlHttp_logout.open("GET",url,true);
		xmlHttp_logout.send(null);
}

function state_logout()
{
	switch(xmlHttp_logout.readyState)
		 {
			case 1:
			case 2:
			case 3:
					$("#status").html("Authenticating .. Please Wait");
			break;

			case 4:
				xml_text = xmlHttp_logout.responseText;
				window.location.reload(); 
			break;
		 }
}

