function sendAjaxData(data, page, method, div, reload, reload_page, reload_div, reload_data, clearlistfield)
{
	if(document.all)
    {
        //Internet Explorer
        var XhrObj = new ActiveXObject("Microsoft.XMLHTTP") ;
    }//fin if
    else
    {
        //Mozilla
        var XhrObj = new XMLHttpRequest();
    }//fin else
    
    //d&eacute;finition de l'endroit d'affichage:
    var content = document.getElementById(div);
    
    //si on envoie par la m&eacute;thode GET:
    if(method == "GET")
    {
        if(data == 'null')
        {
            //Ouverture du fichier s&eacute;lectionn&eacute;:
            XhrObj.open("GET", page, true);
        }//fin if
        else
        {
            //Ouverture du fichier en methode GET
            XhrObj.open("GET", page+"?"+data, true);
        }//fin else
    }//fin if
    else if(method == "POST")
    {
        //Ouverture du fichier en methode POST
		XhrObj.open("POST", page + "?RANDOM="+Math.random()+String.fromCharCode(34), true); 
    }//fin elseif
 
    //Ok pour la page cible
    XhrObj.onreadystatechange = function()
    {
		if (XhrObj.readyState == 4 && XhrObj.status == 200){
            
        	if (XhrObj.responseText == 'OK' || XhrObj.responseText == 'Votre numeacute;ro a &eacute;t&eacute; envoy&eacute;' || XhrObj.responseText == '')
        	{			
        		/*if (XhrObj.responseText == 'Votre numeacute;ro a &eacute;t&eacute; envoy&eacute;')
				{*/
					//alert(document.getElementById("hide-me").style.display);
										
					document.getElementById("hide-me").style.display = "block";
					document.getElementById('updated_div').style.display='block';
					document.getElementById('updated').style.display='block';
					document.getElementById('updated_ok').style.display='none';
					setTimeout("document.getElementById('hide-me').style.display = 'none'", 2000);
					setTimeout("document.getElementById('updated_div').style.display = 'none'", 2000);
					//setTimeout("window.location = 'index.php'", 2000);
					
					//window.location = 'index.php';
				/*}*/
				/*
				if (clearlistfield != '' && XhrObj.responseText == 'OK')
				{
					clearInputText(clearlistfield);
					//Affichage popup de confirmation + marketing viral
					document.getElementById("hide-me").style.display = "block";
					document.getElementById('updated_div').style.display='block';
					document.getElementById('updated').style.display='none';
					document.getElementById('updated_ok').style.display='block';
					//document.getElementById(inputName).style.border='1px solid #51BCE7';
				}
				*/
				//window.location = reload_page;
				/*var blind_form_var = document.getElementById('blind_form');
				$(blind_form_var).hide("slide", { direction: "up" }, 1000);*/
        	}        	
        	else
				displayMessage();
        	
        	content.innerHTML = XhrObj.responseText ;
            /*if (reload)
            	sendAjaxData(reload_data, reload_page, 'POST', reload_div, false, null, null);*/
    	}else
			content.innerHTML = '<img src="../img/loader.gif">';
    }    
 
    if(method == "GET")
    {
        XhrObj.send(null);
    }//fin if
    else if(method == "POST")
    {
        XhrObj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        XhrObj.send(data);
    }//fin elseif
}//fin fonction SendData


function getFormValueToSendAjax(inputList, ajaxFile, idtype, reload_page, reload_div, emptyInput, divResult, clearlistfield) {

	var poststr = '';
	var inputValue = '';
	var inputName = '';
	var alertText = '';
	var err = false;
	var obligatoire = false;
	
	if (inputList != '')
	{
		tabInput = inputList.split("|");
		for(cptInput=0;cptInput<tabInput.length;cptInput++)
		{
			obligatoire = false;
			inputName = tabInput[cptInput];
			
			//On regarde si le champs est obligatoire
			if (inputName.charAt(0) == "*")
			{
				obligatoire = true;
				inputName = inputName.substring(1);
			}
			
			if (document.getElementById(inputName))
			{
				inputValue = document.getElementById(inputName).value;
								
				if (obligatoire && inputValue == ''){
					//alertText += "Veuillez saisir le champ " + inputName;
					document.getElementById("hide-me").style.display = "block";
					document.getElementById('updated_div').style.display='block';
					document.getElementById('updated').innerHTML='Nous ne pourrons pas vous recontacter sans votre num&eacute;ro de t&eacute;l&eacute;phone ;-)';
					document.getElementById(inputName).style.border='1px solid #B4D13B';
					err = true;
				}
				else
				{
					document.getElementById(inputName).style.border='1px solid #B4D13B';
					poststr += inputName + "=" + inputValue + "&";
				}
				
			}
			else if (document.getElementsByName(inputName))
			{ 	
				if (inputName == "rb_reponse")
				{
					//alert(document.myform.rb_reponse.length);
					//inputValue = document.getElementById(inputName).checked;
					//alert(inputValue);
					for (var i=0; i<document.myform.rb_reponse.length;i++) {
						if (document.myform.rb_reponse[i].checked) {
							inputValue = document.myform.rb_reponse[i].value;
						}
					}
					poststr += inputName + "=" + inputValue + "&";
				}
				else
				{
					inputValue = document.forms['myform'].elements[inputName].checked;
					//inputValue = document.getElementsByName(inputName).value;
					
					if (obligatoire && inputValue == ''){
						alertText += "Veuillez saisir le champ " + inputName;
						err = true;
					}
					else
						poststr += inputName + "=" + inputValue + "&";
				}
			}
		}
		
		if (alertText != '')
			alert(alertText);
		
	}
	
	if (poststr != '' && !err)
		poststr = poststr.substring(0,poststr.length - 1);
	
	//document.getElementById(divResult).style.display = 'block';
	//document.getElementById('updated_div').style.opacity = "1";
	//document.getElementById('updated_div').style.filter = 'alpha(opacity=100)';
	
	//document.body.style.opacity = "0.2";
	//document.body.style.filter = 'alpha(opacity=20)';
	
	
	//alert(ajaxFile);
	
	if (!err)
	{
		if (reload_page != '')
			sendAjaxData(poststr, ajaxFile, 'POST', divResult, true, reload_page, reload_div, 'idt=' + idtype, clearlistfield);
		else
			sendAjaxData(poststr, ajaxFile, 'POST', divResult, false, null, null, '', clearlistfield); 
	
		if (emptyInput)
		{
			if (document.getElementById("id"))
				document.getElementById("id").value = '';
			
			for(cptInput=0;cptInput<tabInput.length;cptInput++)
			{
				inputName = tabInput[cptInput];
			
				if (inputName.charAt(0) == "*")
					inputName = inputName.substring(1);
				
				if (document.getElementById(inputName))
					document.getElementById(inputName).value = '';
			}
		}
	}
	else
	{
		displayMessage();
	}
}


function displayMessage(){
	document.getElementById("hide-me").style.display = "block";
	document.getElementById("updated_div").style.display = "block";
	setTimeout("document.getElementById('hide-me').style.display = 'none'", 2000);
	setTimeout("document.getElementById('updated_div').style.display = 'none'", 2000);
}

function getIdValueToSendAjax(ajaxFile, idtype, id, reload_page, reload_div, confirmation) {

	var poststr = '';
	
	if (id > 0){   
		poststr += "id=" + id + "&";
	}
	if (idtype > 0){   
		poststr += "idt=" + idtype + "&";
	}
	if (poststr != '')
		poststr = poststr.substring(0,poststr.length - 1);
	
	document.getElementById("updated").style.display = 'block';
		
	if(confirm(confirmation))
	{
		if (idtype > 0)
			sendAjaxData(poststr, ajaxFile, 'POST', 'updated', true, reload_page, reload_div, 'idt=' + idtype);
		else
			sendAjaxData(poststr, ajaxFile, 'POST', 'updated', true, reload_page, reload_div, null);
	}
	
	if (document.getElementById("id"))
		document.getElementById("id").value = '';
}

function addValueToInput(str) {
	tab = str.split("|");
	for(cptstr=0;cptstr<tab.length;cptstr++)
	{
		//alert(tabInput[0]);
		tabInput = tab[cptstr].split(":");
		document.getElementById(tabInput[0]).value = tabInput[1];
	}	
}
function undisplayUpdatedText(){
	document.getElementById("updated").style.display = 'none';
}
function clearInputText(str){
	//str = id:0|libelle:|...
	if (str != '')
	{
		tab = str.split("|");
		for(cptstr=0;cptstr<tab.length;cptstr++)
		{
			tabInput = tab[cptstr].split(":");
			if (document.getElementById(tabInput[0]))
			document.getElementById(tabInput[0]).value = tabInput[1];
		}
	}
}

function checkMail(mail) {
	if(mail!=""){
		if ((mail.indexOf("@")>=0)&&(mail.lastIndexOf(".")>mail.indexOf("@"))) {
			return true
		} else {
			return false
		}
	}else{
		return true
	}
}