/* Méthodes pour l'AJAX */
var MESSAGE_NAVIGATEUR	= "Votre navigateur est incompatible avec les technologies utilisées sur ce site.";
var MESSAGE_ERREUR	= "Un incident technique est survenu.\nVeuillez réessayer ultérieurement.";
var LOCATION_HOSTNAME	= "http://"+location.hostname;
function chargerPage(url,method,qs)
{
	var req		= null;
	var retour	= null; /* Navigateur incompatible */
	if (window.XMLHttpRequest)	req	= new XMLHttpRequest();				// Geeko
	else if (window.ActiveXObject)	req	= new ActiveXObject("Microsoft.XMLHTTP");	// IE
	if (req != null)
	{
		req.open(method,url,false);	// Non asyncrhone
		req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		req.send(qs);
		retour	= req.responseText;
	}
	return	retour;
}
function buildQs(qs, idElem)
{
	node = document.getElementById(idElem);
	if (node!=null)	
	{
		if (qs!="") qs += "&";
		qs += node.name + "=" + escape(node.value);
	}
	return	qs;
}
/* Méthode pour la page annonce_detail.php */
function enregistrerAnnonce(id)
{
	var offreId		= null;
	var scriptUrl		= LOCATION_HOSTNAME+"/ajax/enregistrerAnnonce.php";
	var retour		= null;
	if (!isNaN(parseInt(id))) offreId = id;
	if (offreId != null)
	{
		scriptUrl 	+= "?offreId="+offreId;
		retour		 = chargerPage(scriptUrl,"GET",null);
	}
	if (retour != null)	alert(retour);
	else			alert(MESSAGE_NAVIGATEUR);
}

function enregistrerAnnonceMulti (obj) {
	var scriptUrl		= LOCATION_HOSTNAME+"/ajax/enregistrerAnnonceMulti.php";

	qs = '';
	
	ids = document.getElementsByName ("selannonce");
	for (i = 0; i < ids.length; i++) {
		if (ids[i].checked) qs += '&selannonce[]='+escape (ids[i].value);
	}

	retour = chargerPage(scriptUrl+"?"+qs,"GET",null);

	alertErr (obj, "Enregistrer des offres", retour);
}

/* Methode pour la page postuler_sansminscrire.php */
function postulerAnnonce()
{
	var formPostuler			= document.getElementById("mainForm");
	var nodeOffreId				= document.getElementById("offreId");
	var nodeOffreRecruteurId		= document.getElementById("offreRecruteurId");
	if (!isNaN(parseInt(nodeOffreId.value)) && !isNaN(parseInt(nodeOffreRecruteurId.value)))
	{
		formPostuler.action = "/ajax/postulerAnnonce.php";
		formPostuler.submit();
	}
	else
		alert(MESSAGE_ERREUR);
}
/* Méthode pour la page postuler_solutions.php -- identification candidat */
function connectionCandidat()
{
	var nodePostulerBoutonValider	= document.getElementById("postulerBoutonValider");
	var scriptUrl			= LOCATION_HOSTNAME+"/ajax/connectionCandidat.php";
	var retour			= null;
	var params = "cnd_identifiant="+document.getElementById("postulerEmail").value
			+  "&cnd_motdepasse="+document.getElementById("postulerMotDePasse").value
			+  "&id="+document.getElementById("postulerId").value;
	retour				= chargerPage(scriptUrl, "POST", params);
	if (retour != null)
	{
		if (retour == "")
			window.document.location.href = "/postuler_dejamembre.php?id="+document.getElementById("postulerId").value;
		else
			alert(retour);
	}
	else
		alert(MESSAGE_NAVIGATEUR);
}
function enregistrerCVEtape3(id)
{
	var cvId		= null;
	var scriptUrl	= LOCATION_HOSTNAME+"/ajax/enregistrerCVEtape3.php";
	var retour		= null;
	if (!isNaN(parseInt(id))) cvId = id;
	if (cvId != null)
	{
		scriptUrl 	+= "?cv_id="+cvId;
		retour = chargerPage(scriptUrl,"GET",null);
		if (retour != null)	{ window.document.location.href = "/mes_cv.php"; alert(retour); }
		else			alert(MESSAGE_NAVIGATEUR);
	}
}
function enregistrerCommentaire()
{
	var nodeIdCommentaire	= document.getElementById("IdCommentaire");
	var nodeValCommentaire	= document.getElementById("ValCommentaire");
	var scriptUrl			= LOCATION_HOSTNAME+"/ajax/enregistrerCommentaire.php";
	if (nodeIdCommentaire.value!="" && nodeValCommentaire.value!="")
	{
		scriptUrl += "?id="+nodeIdCommentaire.value + "&val="+nodeValCommentaire.value;
		chargerPage(scriptUrl,"POST",null);
	}
}
