// JavaScript Document
function updateRegion(text, li) {
    //alert (li.id);
	document.body.style.cursor = 'wait';
	new Ajax.Request(	'ajax.inc.get_infos_region.php?elem=region&id='+li.id,
		{	method:'get', onSuccess: function(t) { if(getElem('id', 'region')) getElem('id', 'region').value = t.responseText; document.body.style.cursor = 'default'; }, asynchronous:true, evalScripts:true	}
	);
}
function updateDpt(text, li) {
    //alert (li.id);
	document.body.style.cursor = 'wait';
	new Ajax.Request(	'ajax.inc.get_infos_departement.php?elem=region&id='+li.id,
		{	method:'get', onSuccess: function(t) { if(getElem('id', 'region')) getElem('id', 'region').value = t.responseText; }, asynchronous:true, evalScripts:true	}
	);
	new Ajax.Request(	'ajax.inc.get_infos_departement.php?elem=dpt&id='+li.id,
		{	method:'get', onSuccess: function(t) { if(getElem('id', 'departement')) getElem('id', 'departement').value = t.responseText; document.body.style.cursor = 'default'; }, asynchronous:true, evalScripts:true	}
	);
}
function updateVille(text, li) {
    //alert (li.id);
	document.body.style.cursor = 'wait';
	new Ajax.Request(	'ajax.inc.get_infos_ville.php?elem=region&id='+li.id,
		{	method:'get', onSuccess: function(t) { if(getElem('id', 'region')) getElem('id', 'region').value = t.responseText; }, asynchronous:true, evalScripts:true	}
	);
	new Ajax.Request(	'ajax.inc.get_infos_ville.php?elem=dpt&id='+li.id,
		{	method:'get', onSuccess: function(t) { if(getElem('id', 'departement')) getElem('id', 'departement').value = t.responseText; }, asynchronous:true, evalScripts:true	}
	);
	new Ajax.Request(	'ajax.inc.get_infos_ville.php?elem=cp&id='+li.id,
		{	method:'get', onSuccess: function(t) { if(getElem('id', 'cp')) getElem('id', 'cp').value = t.responseText; }, asynchronous:true, evalScripts:true	}
	);
	new Ajax.Request(	'ajax.inc.get_infos_ville.php?elem=lng&id='+li.id,
		{	method:'get', onSuccess: function(t) { if(getElem('id', 'maplng')) getElem('id', 'maplng').value = t.responseText; }, asynchronous:true, evalScripts:true	}
	);
	new Ajax.Request(	'ajax.inc.get_infos_ville.php?elem=lat&id='+li.id,
		{	method:'get', onSuccess: function(t) { if(getElem('id', 'maplat')) getElem('id', 'maplat').value = t.responseText; }, asynchronous:true, evalScripts:true	}
	);
	new Ajax.Request(	'ajax.inc.get_infos_ville.php?elem=ville&id='+li.id,
		{	method:'get', onSuccess: function(t) { if(getElem('id', 'ville')) getElem('id', 'ville').value = t.responseText; document.body.style.cursor = 'default'; }, asynchronous:true, evalScripts:true	}
	);
}

function submitFormInscriptionCandidat(F){
//	document.getElementById('lstOffres').innerHTML = "";
	if(!document.getElementById('loadingLstOffres')){
		var _img_loading = document.createElement("img");
		_img_loading.setAttribute("src", "img/loading.gif");
		_img_loading.setAttribute("id", "loadingLstOffres");
		document.getElementById('inscriptionCandidat').appendChild(_img_loading);
	}
	F.target="iframe";
	F.action="ajax.candidat_profil.php?from=coordonnees_iframe";
	F.submit();

	return false;
}
function submitFormInscriptionCandidat2(F){
//	document.getElementById('lstOffres').innerHTML = "";
	if(!document.getElementById('loadingLstOffres')){
		var _img_loading = document.createElement("img");
		_img_loading.setAttribute("src", "img/loading.gif");
		_img_loading.setAttribute("id", "loadingLstOffres");
		document.getElementById('inscriptionCandidat').appendChild(_img_loading);
	}

	new Ajax.Updater(	'inscriptionCandidat',
						"ajax.candidat_profil.php",
						{	method:'get',
							asynchronous:true,
							parameters:Form.serialize(F),
							onSuccess: function(t) { },
							onComplete: function(){	document.body.style.cursor = 'default';  },
							evalScripts:true
						}
					);

	return false;
}
function submitFormInscriptionRecruteur(F){
//	document.getElementById('lstOffres').innerHTML = "";
	if(!document.getElementById('loadingLstOffres')){
		var _img_loading = document.createElement("img");
		_img_loading.setAttribute("src", "img/loading.gif");
		_img_loading.setAttribute("id", "loadingLstOffres");
		document.getElementById('inscriptionRecruteur').appendChild(_img_loading);
	}
	F.target="iframe";
	F.action="ajax.recruteur_profil.php?from=coordonnees_iframe";
	F.submit();

	return false;
}
function submitFormInscriptionRecruteur2(F){
//	document.getElementById('lstOffres').innerHTML = "";
	if(!document.getElementById('loadingLstOffres')){
		var _img_loading = document.createElement("img");
		_img_loading.setAttribute("src", "img/loading.gif");
		_img_loading.setAttribute("id", "loadingLstOffres");
		document.getElementById('inscriptionRecruteur').appendChild(_img_loading);
	}

	new Ajax.Updater(	'inscriptionRecruteur',
						"ajax.recruteur_profil.php",
						{	method:'get',
							asynchronous:true,
							parameters:Form.serialize(F),
							onSuccess: function(t) { },
							onComplete: function(){	document.body.style.cursor = 'default';  },
							evalScripts:true
						}
					);

	return false;
}
function contactCand(idCand, link){
	new Ajax.Request(	"ajax.recruteur_contact_cand.php?redirect=0&candidat_id="+idCand,
						{	method:'get',
							asynchronous:true,
							onSuccess: function(t) {  if(t.responseText != "") alert(t.responseText);  },
							onComplete: function(){	updateListeCandidats(link, 'detail', idCand); },
							evalScripts:true
						}
					);

	return false;
}
function contactRecr(idRecr, idOffre, link){
	new Ajax.Request(	"ajax.candidat_contact_recr.php?redirect=0&recruteur_id="+idRecr+"&offre_id="+idOffre,
						{	method:'get',
							asynchronous:true,
							onSuccess: function(t) {  if(t.responseText != "") alert(t.responseText);  },
							onComplete: function(){	updateOffresEmploi(link, 'detail', idOffre); },
							evalScripts:true
						}
					);

	return false;
}
function rmCandClasseur(idCand, link){
	new Ajax.Request(	"ajax.recruteur_rmclasseur.php?redirect=0&candidat_id="+idCand,
						{	method:'get',
							asynchronous:true,
							onSuccess: function(t) { },
							onComplete: function(){	updateListeCandidats(link, 'detail', idCand); },
							evalScripts:true
						}
					);

	return false;
}
function addCandClasseur(idCand, link){
	new Ajax.Request(	"ajax.recruteur_addclasseur.php?redirect=0&candidat_id="+idCand,
						{	method:'get',
							asynchronous:true,
							onSuccess: function(t) {   },
							onComplete: function(){	updateListeCandidats(link, 'detail', idCand); },
							evalScripts:true
						}
					);

	return false;
}
function addOffreClasseur(idOffre, link){
	new Ajax.Request(	"ajax.candidat_addclasseur.php?redirect=0&offre_id="+idOffre,
						{	method:'get',
							asynchronous:true,
							onSuccess: function(t) { },
							onComplete: function(){	updateOffresEmploi(link, 'detail', idOffre); },
							evalScripts:true
						}
					);

	return false;
}
function rmOffreClasseur(idOffre, link){
	new Ajax.Request(	"ajax.candidat_rmclasseur.php?redirect=0&offre_id="+idOffre,
						{	method:'get',
							asynchronous:true,
							onSuccess: function(t) { },
							onComplete: function(){	updateOffresEmploi(link, 'detail', idOffre); },
							evalScripts:true
						}
					);

	return false;
}
function verifAdresse(F){
	/*
	address = F.adresse.value+", "+F.ville.value+", "+F.code_postal.value+", "+F.pays.value;
	geocoder = new GClientGeocoder();
	geocoder.getLatLng(address, function(point) {
		 if (!point) { alert("Impossible de localiser :\n\n" + address);}
		else { F.maplng.value=point.y; F.maplat.value=point.x; }
	});
	*/
}
function submitFormRech(F){
//	document.getElementById('lstOffres').innerHTML = "";

	var modifiedLocation = "page:" + 1 + "&type:" + "lst";
    dhtmlHistory.add(modifiedLocation, modifiedLocation);

	if(!document.getElementById('loadingLstOffres')){
		var _img_loading = document.createElement("img");
		_img_loading.setAttribute("src", "img/loading.gif");
		_img_loading.setAttribute("id", "loadingLstOffres");
		document.getElementById('lstOffres').appendChild(_img_loading);
	}
	new Ajax.Updater(	'lstOffres',
					 	'ajax.offres_emploi.php?type=lst', 	{
							method:'get',
							asynchronous:true,
							parameters:Form.serialize(F),
							onSuccess: function(t) { },
							onComplete: function(){	document.body.style.cursor = 'default';
							},
							evalScripts:true
						}
	);
	return false;
}
function submitFormRechCandidats(F){
//	document.getElementById('lstOffres').innerHTML = "";

	var modifiedLocation = "page:" + 1 + "&type:" + "lst";
    dhtmlHistory.add(modifiedLocation, modifiedLocation);

	if(!document.getElementById('loadingLstOffres')){
		var _img_loading = document.createElement("img");
		_img_loading.setAttribute("src", "img/loading.gif");
		_img_loading.setAttribute("id", "loadingLstOffres");
		document.getElementById('lstOffres').appendChild(_img_loading);
	}
	new Ajax.Updater(	'lstOffres',
					 	'ajax.liste_candidats.php?type=lst', 	{
							method:'get',
							asynchronous:true,
							parameters:Form.serialize(F),
							onSuccess: function(t) { },
							onComplete: function(){	document.body.style.cursor = 'default';  },
							evalScripts:true
						}
	);
	return false;
}
function updateInscriptionRecruteur(link){
	document.body.style.cursor = 'wait';
	document.getElementById('inscriptionRecruteur').innerHTML = "";
	if(!document.getElementById('loadingLstOffres')){
		var _img_loading = document.createElement("img");
		_img_loading.setAttribute("src", "img/loading.gif");
		_img_loading.setAttribute("id", "loadingLstOffres");
		document.getElementById('inscriptionRecruteur').appendChild(_img_loading);
	}
	sleep(500, "updateInscriptionRecruteurB('"+link+"')");
}
function updateInscriptionRecruteurB(link){
	//document.getElementById('lstOffres').style.display="none";
	new Ajax.Updater(	'inscriptionRecruteur',
						link,
						{	method:'get',
							onComplete:function(){
								// une foi la maj terminee, affichage de la popup
								//document.getElementById('lstOffres').style.display="block";
								document.body.style.cursor = 'default';
							},
							asynchronous:true,
							evalScripts:true
						}
					);


}
function updateInscriptionCandidat(link){
	document.body.style.cursor = 'wait';
	document.getElementById('inscriptionCandidat').innerHTML = "";
	if(!document.getElementById('loadingLstOffres')){
		var _img_loading = document.createElement("img");
		_img_loading.setAttribute("src", "img/loading.gif");
		_img_loading.setAttribute("id", "loadingLstOffres");
		document.getElementById('inscriptionCandidat').appendChild(_img_loading);
	}
	sleep(500, "updateInscriptionCandidatB('"+link+"')");
}
function updateInscriptionCandidatB(link){
	//document.getElementById('lstOffres').style.display="none";
	new Ajax.Updater(	'inscriptionCandidat',
						link,
						{	method:'get',
							onComplete:function(){
								// une foi la maj terminee, affichage de la popup
								//document.getElementById('lstOffres').style.display="block";
								document.body.style.cursor = 'default';
							},
							asynchronous:true,
							evalScripts:true
						}
					);


}

function updateOffresEmploi(link, _type, _page){
	/* Gestion du precedent/suivant du navigateur */
	if((_page == "" || _page == undefined)) {	_page = 0;	}
	if((_type == "" || _type == undefined)) {	_type = 'lst';	}
	var modifiedLocation = "page:" + _page + "&type:" + _type;
    dhtmlHistory.add(modifiedLocation, modifiedLocation);

	document.body.style.cursor = 'wait';
	document.getElementById('lstOffres').innerHTML = "";
	if(!document.getElementById('loadingLstOffres')){
		var _img_loading = document.createElement("img");
		_img_loading.setAttribute("src", "img/loading.gif");
		_img_loading.setAttribute("id", "loadingLstOffres");
		document.getElementById('lstOffres').appendChild(_img_loading);
	}
	sleep(0, "updateOffresEmploiB('"+link+"')");
}
function updateOffresEmploiB(link){
	//document.getElementById('lstOffres').style.display="none";

	/* Gestion du precedent/suivant du navigateur */
//	window.clearInterval(rel);
//	rel=null;
	/* Gestion du precedent/suivant du navigateur */

	new Ajax.Updater(	'lstOffres',
						link,
						{	method:'get',
							onComplete:function(){
								// une foi la maj terminee, affichage de la popup
								//document.getElementById('lstOffres').style.display="block";
								document.body.style.cursor = 'default';
/*								window.location.reload();*/
							},
							asynchronous:true,
							evalScripts:true
						}
					);


}
function updateListeCandidats(link, _type, _page){
	if((_page == "" || _page == undefined)) {	_page = 0;	}
	if((_type == "" || _type == undefined)) {	_type = 'lst';	}
	var modifiedLocation = "page:" + _page + "&type:" + _type;
	dhtmlHistory.add(modifiedLocation, "");


	document.body.style.cursor = 'wait';
	document.getElementById('lstOffres').innerHTML = "";
	if(!document.getElementById('loadingLstOffres')){
		var _img_loading = document.createElement("img");
		_img_loading.setAttribute("src", "img/loading.gif");
		_img_loading.setAttribute("id", "loadingLstOffres");
		document.getElementById('lstOffres').appendChild(_img_loading);
	}
	sleep(0, "updateListeCandidatsB('"+link+"')");
}
function updateListeCandidatsB(link){

	new Ajax.Updater(	'lstOffres',
						link,
						{	method:'get',
							onComplete:function(){
								// une foi la maj terminee, affichage de la popup
								//document.getElementById('lstOffres').style.display="block";
								document.body.style.cursor = 'default';
/*								window.location.reload();*/
							},
							asynchronous:true,
							evalScripts:true
						}
					);


}
function sleep(millis, link) {
    setTimeout(link, millis);
}
function updateFromRegion(text, li) {
	document.getElementById('ville').value="";
	document.getElementById('departement').value="";
}
function updateRecruteurInscriptionInfosVille(text, li) {
//    alert (li.id);
	document.body.style.cursor = 'wait';
	new Ajax.Updater(	'infosVille',
						'ajax.inc.recruteur_profil.update.fromville.php?id='+li.id+'&lib='+text,
						{	method:'get',
							onComplete:function(){
								// une foi la maj terminee, affichage de la popup
								//document.getElementById('lstOffres').style.display="block";
								document.body.style.cursor = 'default';
								new Ajax.Autocompleter("region", "autocomplete_choices", "ajax.autocomplete.regions.php", { paramName: "value", minChars:0, indicator: 'loadingLstOffres'});
								new Ajax.Autocompleter("departement", "autocomplete_choices", "ajax.autocomplete.departements.php", { paramName: "value", minChars:0, indicator: 'loadingLstOffres'});

							},
							asynchronous:true,
							evalScripts:true
						}
					);
}
function updateCandidatInscriptionInfosVille(text, li) {
//    alert (li.id);
	document.body.style.cursor = 'wait';
	new Ajax.Updater(	'infosVille',
						'ajax.inc.candidat_profil.update.fromville.php?id='+li.id+'&lib='+text,
						{	method:'get',
							onComplete:function(){
								// une foi la maj terminee, affichage de la popup
								//document.getElementById('lstOffres').style.display="block";
								document.body.style.cursor = 'default';
								new Ajax.Autocompleter("region", "autocomplete_choices", "ajax.autocomplete.regions.php", { paramName: "value", minChars:0, indicator: 'loadingLstOffres'});
								new Ajax.Autocompleter("departement", "autocomplete_choices", "ajax.autocomplete.departements.php", { paramName: "value", minChars:0, indicator: 'loadingLstOffres'});

							},
							asynchronous:true,
							evalScripts:true
						}
					);
}
function updateRegionFromDepartement(text, li) {
//    alert (li.id);
	document.getElementById('ville').value="";
	document.body.style.cursor = 'wait';
	new Ajax.Updater(	'infosVille',
						'ajax.inc.offres_rechercher.update.fromdepartement.php?id='+li.id+'&lib='+text,
						{	method:'get',
							onComplete:function(){
								// une foi la maj terminee, affichage de la popup
								//document.getElementById('lstOffres').style.display="block";
								document.body.style.cursor = 'default';
								new Ajax.Autocompleter("region", "autocomplete_choices", "ajax.autocomplete.regions.php", { paramName: "value", minChars:0, indicator: 'loadingLstOffres', afterUpdateElement : updateFromRegion});
								new Ajax.Autocompleter("departement", "autocomplete_choices", "ajax.autocomplete.departements.php", { paramName: "value", minChars:0, indicator: 'loadingLstOffres', afterUpdateElement : updateRegionFromDepartement});

							},
							asynchronous:true,
							evalScripts:true
						}
					);
}
function updateRegionDepartementFromVille(text, li) {
//    alert (li.id);
	document.body.style.cursor = 'wait';
	new Ajax.Updater(	'infosVille',
						'ajax.inc.offres_rechercher.update.fromville.php?id='+li.id+'&lib='+text,
						{	method:'get',
							onComplete:function(){
								// une foi la maj terminee, affichage de la popup
								//document.getElementById('lstOffres').style.display="block";
								document.body.style.cursor = 'default';
								new Ajax.Autocompleter("region", "autocomplete_choices", "ajax.autocomplete.regions.php", { paramName: "value", minChars:0, indicator: 'loadingLstOffres', afterUpdateElement : updateFromRegion});
								new Ajax.Autocompleter("departement", "autocomplete_choices", "ajax.autocomplete.departements.php", { paramName: "value", minChars:0, indicator: 'loadingLstOffres', afterUpdateElement : updateRegionFromDepartement});

							},
							asynchronous:true,
							evalScripts:true
						}
					);
}