/** 
* Factory System Installation
*
* @author	  RaphaeL Pralat <raph@plus2.fr>
* @version    CVS: $Id: Recruiter.js,v 1.10 2007-10-08 08:59:51 cvs Exp $
* @uses       http://prototype.conio.net/
* @uses       http://bennolan.com/behaviour/
* @uses       http://script.aculo.us
*/

var	YoujobRecruiter = {

	rules :				{

		/*CONNEXION DANS LE HEADER COTE RECRUTEUR*/
	'#b_connexion' : function(el) {
		el.onclick = function() {
			if($('connexion2').style.display == 'none'){
			    if($('connection_click')) {
			        $('connection_click').style.display = 'none';
			    }
        		$('b_connexion').className = "on";
        		$('b_connexion').blur();
        		Effect.Appear('connexion2',{duration:0.3});
        	}/*else{
        	    $('connection_click').style.display = 'block';
        		$('a_connexion').className = "";
        		$('a_connexion').blur();
        		Effect.Fade('connexion',{duration:0.3});
        	}*/
		}
	},    
	    
	'#mailToSales' : function(el) {
		el.onclick = function() {
			form = $('formMail').serialize();
            ajax = new Ajax.Updater('errorMailToSales', '/recruiter/ajaxMailToSales', {
				parameters	: form,
				method		: 'post',
				onSuccess   : YoujobRecruiter.alertMailSend,
				onFailed    : YoujobRecruiter.alertMailSend
			});
			$('formMail').reset();
		}
	},
	    
	'.ajaxLoadRecruiterUserList' : function(el) {
		el.onclick = function() {
			offerId = findParamInClass('offerId', this);

			new Ajax.Updater('listUserOffer', '/ajaxyoujob/ajaxLoadRecruiterUserList', {
				parameters	: 'offerId=' + offerId,
				method		: 'post',
				onComplete	: YoujobRecruiter.reload
			});
		}
	},

	'.ajaxLoadRecruiterUserInfo' : function(el) {
		el.onclick = function() {
			userId = findParamInClass('userId', this);
			offerId = findParamInClass('offerId', this);

			new Ajax.Updater('userInfo', '/ajaxyoujob/ajaxLoadRecruiterUserInfo', {
				parameters	: 'userId=' + userId + '&offerId=' + offerId,
				method		: 'post',
				onComplete	: YoujobRecruiter.reload,
				evalScripts     : true
			});
		}
	},

	
	'.repVideo' : function(el) {
		el.onclick = function() {
			mediaId = findParamInClass('mediaId', this);
			if(mediaId!='' && mediaId!='false'){
			new Ajax.Updater('player', '/ajaxyoujob/ajaxLoadRecruiterRepVideo', {
				parameters	: 'mediaId=' + mediaId,
				method		: 'post',
				onComplete	: YoujobRecruiter.reload,
				evalScripts     : true
			});
			}
		}
	},
	
	
	'.cvVideo' : function(el) {
		el.onclick = function() {
			userId = findParamInClass('userId', this);

			new Ajax.Updater('player', '/ajaxyoujob/ajaxLoadRecruiterCvVideo', {
				parameters	: 'mediaId=' + userId,
				method		: 'post',
				onComplete	: YoujobRecruiter.reload,
				evalScripts     : true
			});
		}
	},
	
	'.rdvVisio' : function(el) {
			el.onclick = function() {
			userId = findParamInClass('userId', this);
			userFn = findParamInClass('userFn', this);
			userLn = findParamInClass('userLn', this);
			$('userId').value = userId;
			$('visioWith').value = userFn + " " + userLn;
			$('sendRecommandationForm').style.display = "block";
			}

	},	
	
	'.delCandidat' : function(el) {
		el.onclick = function() {
			mediaId = findParamInClass('mediaId', this);
			offerId = findParamInClass('offerId', this);
			pg = findParamInClass('pg', this);
			new Ajax.Updater('listVideoCandidat', '/ajaxyoujob/ajaxLoadRecruiterDelCandidat', {
				parameters	: 'mediaId=' + mediaId + '&offerId=' + offerId + '&pg=' + pg  ,
				method		: 'post',
				onComplete	: YoujobRecruiter.reload,
				evalScripts     : true
			});
		}
	},
 
	
	'.pav' : function(el) {
		el.onclick = function() {
			pg = findParamInClass('pg', this);
			offerId = findParamInClass('offerId', this);
			new Ajax.Updater('listVideoCandidat', '/ajaxyoujob/ajaxLoadRecruiterPav', {
				parameters	: 'pg=' + pg + '&offerId=' + offerId,
				method		: 'post',
				onComplete	: YoujobRecruiter.reload,
				evalScripts     : true
			});
		}
	},
		
	'.closeForm' : function(el) {
			el.onclick = function() {
			$('sendRecommandationForm').style.display = "none";
			}

	},
	
		'.getVideo' : function(el) {
		el.onclick = function() {
			var mediaId = findParamInClass('mediaId', this);
			var videoimage = findParamInClass('videoimage', this);
			videoimage = (videoimage)? videoimage : "/themes/default/images/temp/logo-youjobV2.jpg";
//			if (videopath !=''){				
//				videopath= (videopath)?videopath.replace(/-/g,'_'):"";
//				videopath= (videopath)?videopath.replace('_','-'):"";
				videopath = "mediaId="+mediaId+"&autostart=false&lightcolor=0x557722&backcolor=0x000000&frontcolor=0xCCCCCC&image="+videoimage;
				FO = {	movie:"/player/flvplayer.swf",width:"360",height:"280",majorversion:"7",build:"0",bgcolor:"#FFFFFF",allowfullscreen:"true",
							flashvars: videopath };
				 UFO.create(FO, "player1");
//			}
		}
	},

		
	'.recruitMessageAction' : function(el) {
		el.onclick = function() {
			var id;
			var action;
			id = findParamInClass('id', this);
			action = findParamInClass('action', this);
			
			
			new Ajax.Updater('recruitMessageContent', '/ajaxyoujob/recruitMessage', {
				parameters	: 'id=' + id + '&action=' + action,
				method		: 'post',
				onComplete	: YoujobRecruiter.reload,
				evalScripts     : true
			});
		}
	},

	'.elementVideo' : function(el) {	
		el.onmouseover = function() {	
			this.style.background="#EEEEEE";
			var fname = findParamInClass('fname',this);
			var lname = findParamInClass('lname',this);
			var town = findParamInClass('town',this);
			var fname = (fname)?fname.replace(/-/g,' '):"";
			var lname = (lname)?lname.replace(/-/g,' '):"";
			var town = (town)?town.replace(/-/g,' '):"";
			$('userFirstname').innerHTML=(fname)?fname:" ";
			$('userLastname').innerHTML=(lname)?lname:" ";
			$('userTown').innerHTML=(town)?town:" ";	
			}
		el.onmouseout = function() {
			this.style.background="#FFFFFF";
		}
				
	},
	
		'.deleteVideoByRecruiter' : function(el) {
			el.onclick = function() {
			mediaId = findParamInClass('mediaId', this);
			companyId = findParamInClass('companyId', this);
			page = findParamInClass('page', this);
			nbElement = findParamInClass('nbElement', this);
			new Ajax.Updater('modulevideo', '/ajax/deleteVideoByRecruiter', {
				parameters	: 'mediaId=' + mediaId + '&companyId=' + companyId + '&page=' + page + '&nbElement=' + nbElement,
				method		: 'post',
				onComplete	: YoujobRecruiter.reload
			});
		}
	},
	
		'.currentPage' : function(el) {
			el.onclick = function() {
			companyId = findParamInClass('companyId', this);
			page = findParamInClass('page', this);
			nbElement = findParamInClass('nbElement', this);
			new Ajax.Updater('modulevideo', '/ajax/ajaxRecruiterVideoTurnPage', {
				parameters	: 'companyId=' + companyId + '&page=' + page + '&nbElement=' + nbElement,
				method		: 'post',
				onComplete	: YoujobRecruiter.reload
			});
		}
	},
	
/*
		'.deleteVideoConfi' : function(el) {
		el.onclick = function() {
			mediaId = findParamInClass('mediaId', this);
			companyId = findParamInClass('companyId', this);
			var o=document.createElement("div")
			o.className="playVideo";
			o.id="playVideo";
			$('modulevideo').appendChild(o);
			var output="<div class='deleteVideoByRecruiter mediaId_"+mediaId+" companyId_"+companyId+"'>Oui</div> <div class='close'>Non</div>";
			o.innerHTML=output;
			o.style.zindex = 10;
			o.style.position = "absolute";
			o.style.width = "100px";
			o.style.height = "100px";
			o.style.top = "50px";     
			o.style.left = "100px";
			o.style.filter = "alpha(opacity=50)";
			o.style.opacity = ".50";
		}
	},	
	
*/	
	
	'.showFormRecruiter' : function(el) {
		el.onclick = function() {
			typeForm = findParamInClass('formule',this);
			$('monimage').style.display = 'none';
		}
	},
	
	'lastbutnotleast': {}
	}, /** rules **/

	'reload' :	function(ajax) {
		 Behaviour.apply(YoujobRecruiter.rules);
	},
	
	
	
	/**
	* User Ask For interview
	*
	*/
	'.userInterview' : function(el) {
		el.onclick = function() {
			new Ajax.Updater('sendRecommandationForm', '/ajaxyoujob/userInterview',{
			parameters	: "user="+findParamInClass('userId',this),
			method		: 'post',
			onComplete	: YoujobRecruiter.reload
			});
			alert ("rr");
			$('sendRecommandationForm').style.display = "block";
			new Effect.Appear('sendRecommandationForm');
		}
	},
	
	'alertMailSend' : function(transport){               
                  var response = transport.responseText || "no response text";
                  if(response == "true"){
                    alert("Votre message a bien été envoyé. Un conseiller va prendre contact avec vous.");
                  }else{
                    alert("Suite à un trop grand nombre de demandes, votre demande n'a malheureusement pas &#233;té prise en compte. Merci de réessayer plus tard ou de nous contacter eu 01 53 53 10 10");                   
                  }
                  
    }
	


}


function findParamInClass(param, el) {
   var regexp = new RegExp(param + '_([A-Za-z0-9/:?&\-\._]+)');
   var mymatch = regexp.exec(el.className);
   if(mymatch) {
       return mymatch[1];
   }
   return false;
}

Behaviour.register(YoujobRecruiter.rules);