var string,operateur,selection; // Les variables à envoyer
string = '';
operateur = 'or';
selection = 'all';

var http; // Notre objet XMLHttpRequest

function createRequestObject()
{
    var http;
    if(window.XMLHttpRequest)
    { // Mozilla, Safari, ...
        http = new XMLHttpRequest();
    }
    else if(window.ActiveXObject)
    { // Internet Explorer
        http = new ActiveXObject("Microsoft.XMLHTTP");
    }
    return http;
}

function ajaxRecherche()
{
	if (string!="Search") {
		
		writediv('<img src="./modules/ajax_search_engine/img/ajax-loader.gif" alt="Chargement Ajax" title="Chargement" />','chargement'); // On écrit dans la div, que ca charge
	
	http = createRequestObject(); // On creé un objet
    //http.open('get', './recherche.php?recherche='+escape(string)+'&operateur='+operateur+'&selection='+selection, true);
    http.open('POST', './modules/ajax_search_engine/recherche.php', true);
    
    http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    
    http.onreadystatechange = handleAJAXReturn;
    
    http.send('recherche='+escape(string)+'&operateur='+operateur+'&selection='+selection);
	
	}	
    
   
}

function handleAJAXReturn()
{
    if(http.readyState == 4)
    {
        writediv('','chargement');
    	if(http.status == 200)
        {
        	writediv(http.responseText,'resultats');
        	//document.getElementById('resultats').innerHTML = http.responseText;
        }
        else
        {
            //writediv("No resultst for this search.",'resultats');
        }
    }
}

function writediv(texte,id) {
	document.getElementById(id).innerHTML = texte;
}

function changeOperateur(operateur_param) {
	operateur = operateur_param;
	ajaxRecherche();
}
function changeSelection(selection_param) {
	selection = selection_param;
	ajaxRecherche();
}
function changeRecherche(string_param) {
	string = string_param;
	ajaxRecherche();
}


