
// News

function recrutement(pPoste, pMission, pProfil, pContrat, pLieu, pSalaire, pContact) {
	
	this.poste 	= pPoste;
	this.mission= pMission;
	this.profil	= pProfil;
	this.contrat= pContrat;
	this.lieu	= pLieu;
	this.salaire= pSalaire;
	this.contact= pContact;
	
}

function initRecrut() {
	
	if (webmaster==true) 
		showDOMNode("recrut_add");
	getRecrutements();
}

function showbtnsRecrut(node, yn, auth) {
	
	if (yn && (auth!=undefined && auth!=null && auth==false) ) return;
	
	var idanal=new Array(); idanal=node.id.split("_");
	var id = idanal[1];
	var btnsid="recrutbtns_"+id;
	showhideDOMNode(btnsid, yn);
}


function getRecrutements() {
	
	//parameters: {company: 'example', limit: 12}		parameters: {n: randomnum  },

	var page='./recrutemt/getRecruts.php';
	new Ajax.Request(page, {
	    method:'get',
	    onSuccess: function(transport){
	      var response = transport.responseText || "no response text";
	      if ( ifError(response)==false) 
	    	  showRecruts(response);
	    },
	    onFailure: function(){ alert('Sorry something went wrong on loading of the page '+page); }
	});
	
}




function showRecruts(xmlinfo) {
	
	var items = new Array(); 
	items = RecrutXmltoArray(xmlinfo);

	var contentnode = getNodeRef("recrutements");
	contentnode.innerHTML="";
	
	for (var i=0; i<items.length; i++ ) {
		
		var item=items[i];
		item.mission=item.mission.replace(/&lt;/gi, "<" );
		item.mission=item.mission.replace(/&gt;/gi, ">" );
		item.profil=item.profil.replace(/&lt;/gi, "<" );
		item.profil=item.profil.replace(/&gt;/gi, ">" );
			
		
		var line="<h4 ";
		// poste + boutons
		line+="id='recrut_"+i+"' onmouseover='showbtnsRecrut(this,true, webmaster)' onmouseout='showbtnsRecrut(this, false)'>";
		line+="<span id='recrutbtns_"+i+"' style='display:none;'>" +
				"<img src=\"./actualites/bin.gif\" onmouseup=\"del_Recrut('"+item.poste+"')\" onmouseover=\"this.style.cursor='pointer'\" onmouseout=\"this.style.cursor='normal'\"/></span>"; 
		line+="<b>"+items[i].poste+"</b></h4>\n";
		// mission
		line+="<p><i><b>Mission :</b></i><br/>" + item.mission+"</p>";
		line+="<p><i><b>Profil :</b></i><br/>" + item.profil+"</p>";
		line+="<p>";
		line+="<b>Type de contrat : </b>" + item.contrat+"<br/>";
		line+="<b>Lieu du poste : </b>" + item.lieu+"<br/>";
		line+="<b>Salaire : </b>" + item.salaire+"<br/>";
		var mail=item.contact;
		if (mail== null || mail.indexOf("@")<1)
			mail="hvandermersch@imsgroupe.com";
		line+="<a href=\"mailto:"+mail+"?subject=R&eacute;ponse &agrave; votre annonce : "+item.poste+"\" style=\"color:blue\"><u>Contact</u></a href>";
		
		line+="</p>";
		line+="<p style='padding-top:20px'> </p>";
		
		contentnode.innerHTML+=line;
	}
}


function create_Recrut() {
	
	var newRecrut=new recrutement();
	
	newRecrut.poste		= getNodeValue("Recr_Poste");
	newRecrut.mission	= getNodeValue("Recr_Mission");
	newRecrut.profil	= getNodeValue("Recr_Profil");
	newRecrut.contrat	= getNodeValue("Recr_Contrat");
	newRecrut.lieu		= getNodeValue("Recr_Lieu");
	newRecrut.salaire	= getNodeValue("Recr_Salaire");
	newRecrut.contact	= getNodeValue("Recr_Contact");

	if (newRecrut.poste!=null) {
		var page='./recrutemt/createRecrut.php';
		new Ajax.Request(page, {
		    method:'post',
			parameters: { 
			pPoste 	 : newRecrut.poste, 
			pMission : newRecrut.mission,
			pProfil  : newRecrut.profil,
			pContrat : newRecrut.contrat,
			pLieu 	 : newRecrut.lieu,
			pSalaire : newRecrut.salaire,
			pContact : newRecrut.contact },
		    onSuccess: 
		    	function(transport){
			      var response = transport.responseText || "no response text";
			      if ( ifError(response)==false) {
			    	  getRecrutements();
			      }
		    	}
			,
		    onFailure: 
		    	function(){ 
			    	//alert('Sorry something went wrong on loading of the page '+page); 
			    	getRecrutements();
		    	}
		  });
	}
}


function del_Recrut(pId) {
	
	var page='./recrutemt/delRecrut.php';
	new Ajax.Request(page, {
	    method:'post',
	    parameters: {ref : pId},
	    onSuccess: 
		    function(transport){
		      var response = transport.responseText || "no response text";
		      if ( ifError(response)==false) {
		    	  getRecrutements();
		      }
		    }
	    ,
	    onFailure : 
	    	function() { 
		    	//alert('Sorry something went wrong on loading of the page '+page); 
		    	getRecrutements();
    		}
	  });
		
}


function getRecrutXml(xmlnode) {
	
	var Item = new recrutement();
	
	Item.poste		=getTagInfo("poste", 	xmlnode);
	Item.mission	=getTagInfo("mission", 	xmlnode);
	Item.profil		=getTagInfo("profil", 	xmlnode);
	Item.contrat	=getTagInfo("contrat",	xmlnode);
	Item.lieu		=getTagInfo("lieu", 	xmlnode);
	Item.salaire	=getTagInfo("salaire", 	xmlnode);
	Item.contact	=getTagInfo("contact", 	xmlnode);

	return Item; 	
}


function RecrutXmltoArray(xmlinfo) {
	
	var list=new Array();
	
	var fiches = XMLtoArray(xmlinfo,"recrutement");	
	var ind=0;
	while (	fiches[ind]!=null) {
		list[list.length]=getRecrutXml(fiches[ind]);
		ind++;
	}

	return list;
}

