/*
    *** AJAX ***
    
    You have to initialize the parameters: ajaxMethod, ajaxURL and ajaxParams.
    For example:
    var ajaxMethod  = "POST";
    var ajaxURL     = "myfile.php";
    var ajaxParams  = "a=1&b=2&c=3"; or null
*/


// The ajax request object

var ajaxRequest = null;

function createAjaxRequestObject()
{
	try
	{
	    ajaxRequest = new XMLHttpRequest();
	}
	catch(e)
	{   // for Microsoft IE6 or older
		try
		{
			ajaxRequest = new ActiveXObject('Msxml2.XMLHTTP');
		}
		catch(e)
		{
		
		    try
			{
			    ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e)
			{
				ajaxRequest = null;
			}
		}
	}
	
	if(ajaxRequest == null)
	{
	    alert("Error creating the XMLHttpRequest object.");
	}
}


function processAjaxRequest()
{
	createAjaxRequestObject();

	try
	{
		ajaxRequest.open(ajaxMethod, ajaxURL, true);    // true means asyncron
        ajaxRequest.onreadystatechange = function ()
        {
            if(ajaxRequest.readyState == 4)
            {
                if(ajaxRequest.status == 200)
                {
                        try
                        {
                            showAjaxResponse();
                        }
                        catch(e)
                        {
                        }
                }
                else
                {
                    alert("There was a problem retrieving the data:\n" + ajaxRequest.statusText);
                }
            }
        };
        
        // For the POST
        if(ajaxMethod == 'POST')
        {
            ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        }
        
        ajaxRequest.send(ajaxParams);      // - your parameters:  send("param1=x&param2=y")
                                            //   or send(null) and use JSON or GET
    }
    catch(e)
    {
        alert("Can't connect to server:\n" + e.toString());
    }
    
}


