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 (clearlistfield != '' && (XhrObj.responseText == 'Super votre message est parti' || XhrObj.responseText == 'Super vous &ecirc;tes abonn&eacute;' || XhrObj.responseText == 'Modification effectu&eacute;e'))
        	{
        		clearInputText(clearlistfield);
				/*var blind_form_var = document.getElementById('blind_form');
				$(blind_form_var).hide("slide", { direction: "up" }, 1000);*/
        	}
        	
        	content.innerHTML = XhrObj.responseText ;
            if (reload)
            	sendAjaxData(reload_data, reload_page, 'POST', reload_div, false, null, null);
    	}else
			content.innerHTML = '<img src="library/images/commun/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) {

	//alert(document.getElementById("hd_prov").value);
	var poststr = '';
	var inputValue = '';
	var inputName = '';
	var alertText = '';
	var err = false;
	var obligatoire = false;
	
	if (idtype > 0){   
		poststr += "idt=" + idtype + "&";
	}
	
	if (document.getElementById("id")){
		var id = document.getElementById("id").value;
		if (id > 0)
			poststr += "id=" + encodeURI(id) + "&";
	}
	
	
	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 (inputName == 'contact')
				{
					if (document.getElementById(inputName).checked) 
					{
						alert(inputValue);
					}
				}*/
								
				if (obligatoire && inputValue == ''){
					//alertText += "Veuillez saisir le champ " + inputName;
					document.getElementById('updated_div').style.display='block';
					document.getElementById('updated').innerHTML='Oups, formulaire incomplet...';
					document.getElementById(inputName).style.border='1px solid #51BCE7';
					err = true;
				}
				else
				{
					document.getElementById(inputName).style.border='1px solid #353535';
					poststr += inputName + "=" + inputValue + "&";
				}
			}
			else if (document.getElementsByName(inputName)){ 
				
				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';

	
	//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 = '';
			}
		}
	}
}

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 checkFile(fichier){
	document.getElementById("fichier").value="";
	if (fichier != '')
	{
		document.getElementById("lb_file").innerHTML = fichier;
		document.getElementById("lb_file").style.display = "block";
		document.getElementById("existantfile").value = fichier;
	}
}
function undisplayFileTxt(){
	document.getElementById("lb_file").innerHTML = "";
	document.getElementById("lb_file").style.display = "none";
	document.getElementById("existantfile").value = "";
}

function checkMail(mail) {
	if(mail!=""){
		if ((mail.indexOf("@")>=0)&&(mail.lastIndexOf(".")>mail.indexOf("@"))) {
			return true
		} else {
			return false
		}
	}else{
		return true
	}
}
function buildCompass(str){
	document.getElementById("pageTitle").innerHTML = str;
}
function displayPage(pageFile){
	//alert(pageFile);
	window.open(pageFile);
	buildCompass('PLANNINGS&nbsp;&nbsp;&#8250;&#8250;&nbsp;&nbsp;Ajouter un planning');
	undisplayUpdatedText();
	Effect.BlindDown('blinddown_form'); return false;
}