// Creates an XMLHttpRequest instance
function createXmlHttpRequestObject()
{
	
	// xmlHttp will store the reference to the XMLHttpRequest object
	var xmlHttp;
	// Try to instantiate the native XMLHttpRequest object
	try
	{
		// Create an XMLHttpRequest object
		xmlHttp = new XMLHttpRequest();
	}
	catch(e)
	{
		// Assume IE6 or older
		try
		{
			xmlHttp = new ActiveXObject("Microsoft.XMLHttp");
		}
		catch(e) { }
	}
	// Return the created object or display an error message
	if (!xmlHttp)
		alert("Error creating the XMLHttpRequest object.");
	else
		
		return xmlHttp;
}

/* ********************* */
// Performs a server request and assigns a callback function
function executeGetSecteurs(pId)
{
// Continue only if xmlHttp isn't void
if (xmlHttp)
{
// Try to connect to the server
try
{
// Initiate server request
document.getElementById('updating').style.visibility = 'visible';

var url = "includes/get_secteurs.php?id="+pId;
xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange = handleRequestStateChange;
xmlHttp.send(null);
}
// Display an error in case of failure
catch (e)
{
alert("Can't connect to server:\n" + e.toString());
}
}
}

/* *************************** */
// Function executed when the state of the request changes
function handleRequestStateChange()
{
// Continue if the process is completed
if (xmlHttp.readyState == 4)
{
// Continue only if HTTP status is "OK"
if (xmlHttp.status == 200)
{
try
{
// Retrieve the response
response = xmlHttp.responseText;
// Do something with the response
//alert(response);
//alert (document.getElementById("secteur").innerHTML);
document.getElementById("sectors_list").innerHTML = response;
document.getElementById('updating').style.visibility = 'hidden';

}
catch(e)
{
// Display error message
alert("Error reading the response: " + e.toString());

}
}
else
{
// Display status message
alert("There was a problem retrieving the data:\n" + xmlHttp.statusText);
}
}
}

/* create ajax object */
/*
// Hide the "Updating..." message
document.getElementById('updating').style.visibility = 'hidden';
*/
var xmlHttp = createXmlHttpRequestObject();
