var xhr = null; 
// Fonction de creation de l'objet XMLHttpRequest qui resservira pour chaques fonctions AJAX 
function getXhr() { 
	if(window.XMLHttpRequest) xhr = new XMLHttpRequest(); 
	else 
	 if(window.ActiveXObject) { 
	 	try {
	 		xhr = new ActiveXObject("Msxml2.XMLHTTP"); 
	 	} 
	 	catch (e) { 
	 		xhr = new ActiveXObject("Microsoft.XMLHTTP");
	 	}
	 } else { 
	 	alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest, veuillez le mettre à jour"); 
	 	xhr = false;
	 }
} 

// Premiere fonction : remplacer le contenu d'un div // 
function ajax_modify_div(idcan, iduse, nomdiv, idtext, chemin, face_portail) { 
	
	if (document.getElementById(idtext)._has_control != true) {
		alert('Vous devez saisir un commentaire !');
		return false;
	}
	
	getXhr(); 
	xhr.onreadystatechange = function() { 
		if(xhr.readyState == 4 && xhr.status == 200) {
			document.getElementById(nomdiv).innerHTML = xhr.responseText;
		}
	} 
	xhr.open("POST",chemin + 'aja_candidat_rmq.php',true); 
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
	xhr.send("kaction=1&face_portail="+face_portail+"&iditm="+idcan+"&iduse="+iduse+"&com="+document.getElementById(idtext).value+"&face_type="+document.getElementById("face_type").value);
	return true;
} 

// Premiere fonction : supprimer un commentaire // 
function ajax_remove_div(idcan, iduse, nomdiv, idcmq, chemin, face_portail) { 
	
	if (confirm("Confirmez vous la suppression de ce commentaire ?")) {
	
	getXhr(); 
	xhr.onreadystatechange = function() { 
		if(xhr.readyState == 4 && xhr.status == 200) {
			document.getElementById(nomdiv).innerHTML = xhr.responseText;
		}
	} 
	xhr.open("POST",chemin + 'aja_candidat_rmq.php',true); 
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
	xhr.send("kaction=2&face_portail="+face_portail+"&iditm="+idcan+"&idcmq="+idcmq+"&face_type="+document.getElementById("face_type").value);
	return true;
	} else {
		return false;
	}
}

// Indiquer q'une tache a été effectuée // 
function ajax_remove_tache(nomdiv, idust) { 
	
	getXhr(); 
	xhr.onreadystatechange = function() { 
		if(xhr.readyState == 4 && xhr.status == 200) {
			document.getElementById(nomdiv).innerHTML = xhr.responseText;
		}
	} 
	xhr.open("POST",'../aja_index_admin_taches.php',true); 
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
	xhr.send("kaction=2&idust="+idust);
	return true;
}

function face_add_bouton(champ, prefixe) {
	if(!champ._has_control) {
		champ.value="";
		champ._has_control=true
	}
	champ.rows=5;
	document.getElementById(prefixe+"BT").style.display="block";
	document.getElementById(prefixe+"QUI").style.display="block";
	return false;
} 

function face_remove_bouton(champ, prefixe) {
	if(champ.value=="") {
		champ.rows=1;
		champ.value="Rédigez un commentaire...";
		champ._has_control=false;
		document.getElementById(prefixe+"BT").style.display="none";
		document.getElementById(prefixe+"QUI").style.display="none";
	}
	return false;
}

function face_add_ligne(champ, prefixe) {
	if(!champ._has_control) {
		champ.value="";
		champ._has_control=true
	}
	champ.rows=5;
	return false;
} 

function face_remove_ligne(champ, prefixe) {
	if(champ.value=="") {
		champ.rows=1;
		champ.value="Redigez un commentaire...";
		champ._has_control=false;
	}
	return false;
}



