var xmlhttp = false;
        
// If the user is using Mozilla/Firefox/Safari/etc
if (window.XMLHttpRequest) {
        //Intiate the object
        xmlhttp = new XMLHttpRequest();
        //Set the mime type
        xmlhttp.overrideMimeType('text/xml');
} else if (window.ActiveXObject) {
        //Intiate the object
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}

function preSearch() {
    //Put the form data into a variable
	var theQuery = document.getElementById('recherche').value;
	var theQuery1 = document.getElementById('regions').value;
	var theQuery2 = document.getElementById('villes').value;
	
	//var theQuery = document.rechercheregion.getElementById('recherche_region').value;
	
    //If the form data is *not* blank, query the DB and return the results
	if(theQuery !== "") {
        //Change the content of the "result" DIV to "Searching..."
        //This gives our user confidence that the script is working if it takes a moment for the result to be returned. However the user will likely never see this...
		document.getElementById('result').innerHTML = "Recherche...";
		
        //This sets a variable with the URL (and query strings) to our PHP script
		var url = 'includes/recherche_ajax.php?q='+ theQuery;
		url=url+"?sid="+Math.random();
		//var url1 = 'includes/recherche_ajax.php?q="+theQuery+"&q_regions="+theQuery1';
		//var url2 = 'includes/recherche_ajax.php?q_ville=' + theQuery2;
        //Open the URL above "asynchronously" (that's what the "true" is for) using the GET method
		xmlhttp.open('GET', "includes/recherche_ajax.php?q="+theQuery+"&q_regions="+theQuery1+"&q_ville="+theQuery2, true);
		//xmlhttp.open('GET', url1, true);
		//xmlhttp.open('GET', url2, true);
        //Check that the PHP script has finished sending us the result
		
		xmlhttp.onreadystatechange = function() {
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                //Replace the content of the "result" DIV with the result returned by the PHP script
				document.getElementById('result').innerHTML = xmlhttp.responseText + ' ';
			} else {
                //If the PHP script fails to send a response, or sends back an error, display a simple user-friendly notification
				//document.getElementById('result').innerHTML = 'Aucun résultat !';
			}
		};
		xmlhttp.send(null);  
	}
}

function preSearchRegion() {
    //Put the form data into a variable
	var theQuery1 = document.getElementById('recherche_region').value;
	//var theQuery = document.rechercheregion.getElementById('recherche_region').value;
	
    //If the form data is *not* blank, query the DB and return the results
	if(theQuery1 !== "") {
        //Change the content of the "result" DIV to "Searching..."
        //This gives our user confidence that the script is working if it takes a moment for the result to be returned. However the user will likely never see this...
		document.getElementById('result').innerHTML = "Recherche...";
		
        //This sets a variable with the URL (and query strings) to our PHP script
		var url = 'includes/recherche_ajax.php?q_region=' + theQuery1;
        //Open the URL above "asynchronously" (that's what the "true" is for) using the GET method
		xmlhttp.open('GET', url, true);
        //Check that the PHP script has finished sending us the result
		
		xmlhttp.onreadystatechange = function() {
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                //Replace the content of the "result" DIV with the result returned by the PHP script
				document.getElementById('result').innerHTML = xmlhttp.responseText + ' ';
			} else {
                //If the PHP script fails to send a response, or sends back an error, display a simple user-friendly notification
				//document.getElementById('result').innerHTML = 'Aucun résultat !';
			}
		};
		xmlhttp.send(null);  
	}
}
