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

var						YoujobUser = {

	rules :				{
	
		
    '.changeUpload' : function(el) {
        el.onclick = function() {
            var idform = mediaType = findParamInClass('idform', this);
            $('divFormUpload'+idform).style.display='block';
            $('divAddCv'+idform).style.display='none';
        }
    },

	'#userForgotPassAction' : function(el) {
		el.onclick = function() {
			//alert('yes');
			
			form = $('formForgotPass').serialize();	
			if (IsValidEmail($F('email'))=='1'){;		
			new Ajax.Updater('contentBox', '/ajax/forgotPass', {
				parameters	: form,
				method		: 'post',
				onComplete	: YoujobUser.reload
			});
			}
			
			
		}
	},
	

	'.ajaxLoadUserVideo' : function(el) {
		el.onclick = function() {
			mediaType = findParamInClass('mediaType', this);
			mediaPath = $F('user_video_path_' + mediaType);
			imagePath = $F('user_image_path_' + mediaType);
			new Effect.Opacity('videoPlayer', {duration:1, fps:25, from:1.0, to:0});
			var FO = {movie:"/player/flvplayer.swf",width:"280",height:"220",majorversion:"7",build:"0",bgcolor:"#FFFFFF",allowfullscreen:"false", flashvars:"file=http://video-ppr.youjob.fr" + mediaPath + "&autostart=true&lightcolor=0x557722&backcolor=0x000000&frontcolor=0xCCCCCC&image=http://vjob.poulet-bacon.com" + imagePath };
			UFO.create(FO, "videoPlayer");
		}
	},
	
	/**
	* User send message
	*
	*/
	'#userMessage' : function(el) {
		el.onclick = function() {
			window.location.href = "/contact/" + findParamInClass('userId',this);
		}
	},

	/**
	* User Ask For interview
	*
	*/
	'#userInterview' : function(el) {
		el.onclick = function() {
			new Ajax.Updater('sendRecommandationForm', '/ajaxyoujob/userInterview',{
			parameters	: "user="+findParamInClass('userId',this),
			method		: 'post',
			onComplete	: FactoryUser.reload
			});
			//$('sendRecommandationForm').style.display = "block";
			new Effect.Appear('sendRecommandationForm');
		}
	},
	
	'#sendAskInterview' : function(el) {
		el.onclick = function() {
			form = $('formAskForInterview').serialize();
			new Ajax.Request('/ajaxyoujob/userSendInterview',{
				parameters	: form,
				method		: 'post',
				onComplete	: FactoryUser.reload
			});
			$('formAskForInterview').reset();
			new Effect.Fold('sendRecommandationForm', {});
		}
	},
	
	'#userSendProfile' : function (el) {
		el.onclick = function (){
			new Ajax.Updater('sendRecommandationForm', '/ajaxyoujob/userSendProfile',{
				parameters	: "user="+findParamInClass('userId',this),
				method		: 'post',
				onComplete	: FactoryUser.reload
			});
			$('sendRecommandationForm').style.display = "block";
			
		}
	},
	
		'.showAllExp' : function (el) {
			el.onmouseover = function (){
			expId = findParamInClass('id', this);
			var changebgcolorId="userExp"+expId.toString();
			//var toHideId="expText"+expId.toString();
			//var toShowId="expTextAll"+expId.toString();
			$(changebgcolorId).style.background = "#CCCCCC";
			//$(toHideId).style.display = "none";
			//$(toShowId).style.display = "";	
		}
			el.onmouseout = function (){
			expId = findParamInClass('id', this);
			var changebgcolorId="userExp"+expId.toString();
			//var toHideId="expTextAll"+expId.toString();
			//var toShowId="expText"+expId.toString();
			$(changebgcolorId).style.background =(parseInt(expId/2)-(expId/2) == 0)? "#FFFFFF" :"#F5F5F5";
			//$(toHideId).style.display = "none";
			//$(toShowId).style.display = "";	
		}
	},
	

		'.toshowRecom' : function (el) {
			el.onmouseover = function (){
			recomId = findParamInClass('id', this);
			var tochangeBg="toshowRecom"+recomId.toString(); 
			var toShowId="recomText"+recomId.toString();
			$(tochangeBg).style.background="#F5F5F5";			
			$(toShowId).style.display = "";	
		}
			el.onmouseout = function (){
			recomId = findParamInClass('id', this);
			var tochangeBg="toshowRecom"+recomId.toString(); 
			var toHideId="recomText"+recomId.toString();
			$(tochangeBg).style.background="#FFFFFF";
			$(toHideId).style.display = "none";
		}
	},
	
	'#showdivDlCV' : function (el) {
		el.onmouseover = function (){
			$('divDlCV').style.visibility = 'visible';
		}
		el.onmouseout = function (){
			$('divDlCV').style.visibility = 'hidden';
		}
		
	},

	
	
	
	'lastbutnotleast': {}
	}, /** rules **/

	'reload' :	function(ajax) {
		//alert('relaod');
		 Behaviour.apply(YoujobUser.rules);
	},
	

	'refreshFromCam' : function(flv, image, type) {
		if (type == "formation") {
			$('user_video_path_1').value = "/module-webcam/" + flv;
			$('user_image_path_1').value = image;
		} else if (type == "experience") {
			$('user_video_path_2').value = "/module-webcam/" + flv;
			$('user_image_path_2').value = image;
		} else if (type == "divers") {
			$('user_video_path_3').value = "/module-webcam/" + flv;
			$('user_image_path_3').value = image;
		}
	}

}

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(YoujobUser.rules);