
// HB's Main Object
HomeBubble = {
	Box: {
		Content: {},
		Lightbox: {},
		Menu: {}
	},
	Ctl: {
		Transition: {},
		General: {},
		Histo:{}
	},
	Paths: {
		PATH_JST: 'public/js/front/',						// Javascript
		PATH_PLG: '/plugins/front/',						// JQuery plugins
		PATH_CSS: '../../css/front',						// Css
		PATH_IMG: '../../images/front/',						// Images
		PATH_HTC: '/plugins/front/iepngfix_v2/blank.gif',   // HTC's blank image fix
		BASEURL:  '',						// BaseUrl Site
		BASEWEB : '/',
		HOST_LINK: 'http://www.home-bubble.com/'
	},
	Language: null
}

// Skip a line for each file to avoid missing cariage return error


HomeBubble.Box.Content.homeAnim = {
	initialize: function () {
		
		//Lorsqu'on clique sur "Mon portail"
		
		$('#myAccount').click(function(){
			$(".genLoginID").fadeOut(function(){
				$(this).css('background', 'url("../../../images/front/gui/bkg/genLoginInputOrange.png") no-repeat scroll 0 0 transparent');
				$(this).fadeIn(function(){
					$(this).fadeOut(function(){
							$(this).css('background', 'url("../../../images/front/gui/bkg/genLoginInput.png") no-repeat scroll 0 0 transparent');
							$(this).fadeIn(function(){
									$(".genLoginPass").fadeOut(function(){
										$(this).css('background', 'url("../../../images/front/gui/bkg/genLoginInputOrange.png") no-repeat scroll 0 0 transparent');
										$(this).fadeIn(function(){
											$(this).fadeOut(function(){
												$(this).css('background', 'url("../../../images/front/gui/bkg/genLoginInput.png") no-repeat scroll 0 0 transparent');
												$(this).fadeIn();
											})
										})
									});
							});
					});
					
				});
			});
			return false;
		})

		
		$('.ui-dialog').find('input').live('keypress',function(e) {
			if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
				$(this).parent().parent().parent().parent().find('.ui-dialog-buttonpane').find('button:first').click(); /* Assuming the first one is the action button */
				return false;
			}
		});
		
		//Quand on clique sur "Enter" ca valide la question secrÃ¨te (changement de mot de passe)
		$('#authRequestPasswordForm').live('keypress',function(e) {
		
			if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
				
				$('#authFormButton').trigger('click'); /* Assuming the first one is the action button */
				return false;
			}
		});
		
		//Quand on clique sur "Enter" ca change le mot de passe
		$('#authChangePassword').live('keypress',function(e) {
		
			if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
				
				$('#authFormButtonValidPassword').trigger('click'); /* Assuming the first one is the action button */
				return false;
			}
		});
		
		//Quand on clique sur "Enter" ca change le mot de passe
		$('#newsletterForm').live('keypress',function(e) {
		
			if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
				
				$('.newsEnrollButton').trigger('click'); /* Assuming the first one is the action button */
				return false;
			}
		});
		
		
		
		/*	$('.subMainLink').click(function(){
				$('.blockBtnMenuLeftSelected').removeClass('blockBtnMenuLeftSelected').addClass('blockBtnMenuLeft');
				$('.blockBtnMenuMiddleSelected').removeClass('blockBtnMenuMiddleSelected').addClass('blockBtnMenuMiddle');
				$('.blockBtnMenuRightSelected').removeClass('blockBtnMenuRightSelected').addClass('blockBtnMenuRight');
				//$("this .blockBtnMenuLeft").removeClass('blockBtnMenuLeft').addClass('blockBtnMenuLeftSelected');
			});*/
				
	/*		$('#homehover').hover(function(){
				$('#homeMemberScreen').fadeIn(100);
			});
			$('#homehover').mouseout(function(){
				$('#homeMemberScreen').fadeOut();
			});*/
			
			$("#commentAppleStoreCarousel").jCarouselLite({
				visible		: 1,							
				scroll		: 1,
				auto		: 5000,							
				speed		: 1500,							
				vertical	: true,						
				circular	: true
				
			});
	
			$("#genMoreInfoCarousel").jCarouselLite({
					btnNext		: "#homeActRight",								
					btnPrev		: "#homeActLeft",							
					visible		: 1,							
					scroll		: 1,
					auto		: 5000,							
					speed		: 1500,							
					vertical	: true,						
					circular	: true							
			    });
			    
	    /* Add friend div appears on click on 'envoyer Ã  un ami'. De mÃªme pour mot de pass oubliÃ©*/
	    
     	$('#genLoginMorePassword').click(function(){
	    	$('#genSideBarPassword').slideToggle();
	    });
	    
	    $('#genLoginMoreFriend').click(function(){
	    	$('#genSideBarFriend').slideToggle();
	    });
	
		/* Search login and password default words disappear */
		$("#genSearchInputElement").focus(function() {
			if($(this).attr("value") == $(this).attr("alt")) {
				$(this).attr("value", "");
			}
		});
		
		$("#genSearchInputElement").blur(function() {
			if($(this).attr("value") == "") {
				$(this).attr("value", $(this).attr("alt"));
			}	
		});
		
		
		$("#homeNumContainer div").mouseover(function(){
			
			$(this).css("cursor" , "pointer")
			
		});
		
		$("#homeNumContainer div").click(function(){
				clearTimeout(timer);
			$("#homeHeadLink").css("color","#000");
				$(this).siblings('div').removeClass().addClass("homeNumInactive");
				animNumber = $(this).attr('rel');
			//	alert(animNumber);
				
				
				$(this).removeClass().addClass("homeNumActive");
				$("#homeContent div").hide();
				
				if(animNumber == 'info'){
					//alert( 'yes');
					$("#homeFirst").fadeIn("slow");
					
				}else if(animNumber == '3'){
					$("#homeSecond").fadeIn("slow");
				}else{
					$("#homeThird").fadeIn("slow");
				}
				
				$(this).siblings('div').removeClass().addClass("homeNumInactive");
				
		});
		
		$("#homeHeadLink").click(function(){
			
			clearTimeout(timer);
			
			$('#homeNumContainer div').siblings('div').removeClass().addClass("homeNumInactive");	
			$("#homeZero").removeClass().addClass("homeContentBox");
			$("#homeHeadLink").css("color","#A4186A");
			
	 		$("#homeZero").fadeIn();
			$("#homeFirst").fadeOut();
			$("#homeSecond").fadeOut();
			$("#homeThird").fadeOut();
			//this.currentElement = 4;
			$(this).oneTime('4s',function(){
					$("#homeZero").fadeOut(function(){
					HomeBubble.Box.Content.homeAnim.animeElement();	
					});
					
			});
		
			
			
			
		});
					
		HomeBubble.Box.Content.homeAnim.animeElement();
			
		
			
		
	
	},
	currentElement: 0,
	animeElement: function(){
		
		
		previousElement = this.currentElement;
		currentElement = (previousElement + 1)%4;
		arrDivs = {
			0: 'homeSecond',
			1: 'homeZero',
			2: 'homeFirst',
			3: 'homeThird'
		}
		
		if(currentElement == 1 ){
			
			$("#homeHeadLink").css("color","#A4186A");
			
		}else{
			
			$("#homeHeadLink").css("color","#000");
			
		}
		
		var currentDIV = "#" + arrDivs[currentElement];
		var previousDIV = "#" + arrDivs[previousElement];
		
		var numberCurrent = "#homeNum" + $(currentDIV).attr("rel");
		var numberPrevious = "#homeNum" + $(previousDIV).attr("rel");
		
		$(previousDIV).fadeOut(300, function(){
			
			$(numberPrevious).removeClass().addClass("homeNumInactive");
			$(numberCurrent).removeClass().addClass("homeNumActive");
			
			$(currentDIV).fadeIn(function(){
								
				
			});

		});
		
		this.currentElement = currentElement;
		
		timer =	setTimeout(HomeBubble.Box.Content.homeAnim.animeElement, 8000);
	
	}
    
}

HomeBubble.Box.Content.Offer = {
	initialize: function () {
		/*
			$(".offSubscribeButton").click(function(){
				
				alert("Pas encore disponible");
			
			});
		*/
    }

}

HomeBubble.Box.Content.HomeTabs = {
	
	identity : function(){
			$('body').click(function(){
	
				strUrl = HomeBubble.Paths.HOST_LINK + 'member/auth/checksession';
				$.post(strUrl, {update:true }, function(data){

					if(data == 'false')
					window.location.replace(HomeBubble.Paths.HOST_LINK+'expired');
					//window.location = HomeBubble.Paths.HOST_LINK+'accueil';
					
				});
			});
	},initialize: function () {


	
	var totalPicture = $("#totalPictureIndex").html();
	
	$("#pictureJson").everyTime(10000,function(i) {
			
		//	normalPictureIndex = $('#normalPictureIndex').html();
		var blurPictureIndex = $('#blurPictureIndex').html();
		
		$("#peopleTalkContent").fadeOut(function(){
			$("#peopleTalkText").html('');
		});
		$("#peopleTalk").fadeOut();
		$('#normalPicture').fadeOut(function(){
			
			
			
			$.post( '/index/people/', {update:true, folder: $("#picture"+blurPictureIndex).html() }, function(data){
				
					if (data.result) {
					 	$("#peopleTalkText").html(data.peopleText[0]);
						$("#peopleLink").attr('href', data.peopleLink[0]);

						$("#peopleTalkContent").fadeIn('slow');
						
					}
				
				
			}, 'json');
			
			$('#blurPicture').fadeOut();
			
			$("#peopleTalk").fadeIn('slow');
			$(this).attr('src', '/images/front/pco/people/'+ $("#picture"+blurPictureIndex).html() +'/normal.png'  ).fadeIn('slow',function(){
				
				newBlur = parseInt($('#blurPictureIndex').html())+1;
				if(newBlur > totalPicture){
					newBlur = 1;
				}

				$('#blurPicture').attr('src', '/images/front/pco/people/'+  $("#picture"+newBlur).html() +'/blur.png'  ).fadeIn('slow');
				$('#blurPictureIndex').html(newBlur);
			});
			
		});
		
	});

	

	$('.genButtonWait').live('click', function(){
		
		$(".genRightBot", this).html('<div class="genButtonLoading">patentiez...</div>');
		$(this).oneTime('2s',function(){
				$(".genRightBot", this).html('');
			});
		});
	
	
	// Return on current tab of no click 
	$("#genTabs").mouseleave(function(){
		
		// retireve current tab active
		var tabTitle = $("#genTabs").attr("class");
		var tabTitleID = "#" + tabTitle;
		
		// retrieve corresponding content
		var tabContent = $(tabTitleID).attr("title"); 	
		var tabContentID = "#" + tabContent;
			
			// Put all tabs to off
			$("#genTabButtonContainer a").addClass("genTabInactive");
			
			//Put current tab to on
			$(tabTitleID).removeClass().addClass("genTabActive");
			
			// Put all tab content to off
			$(tabContentID).siblings().css("display","none");
			
			// Show correspondong content
			$(tabContentID).show();
		
	});
	

	jQuery.preloadImages = function()
		{
		  for(var i = 0; i<arguments.length; i++)
		  {
		    jQuery("<img>").attr("src", arguments[i]);
		  }
		}

		
		
		$.preloadImages("../../images/front/pco/bubbles/bank.png"
						
						
						);  	
	
	
	$("#genTabButtonContainer a").mousedown(function(){
			$("#genTabButtonContainer a").addClass("genTabInactive");	
			$(this).removeClass().addClass("genTabActive");	
			var tab = "#" + $(this).attr("title");
			$(tab).siblings().css("display","none");
			$(tab).show();
			$("#genTabs").unbind('mouseleave');
			
	});
	
	// Tabs on the homepage
	$("#genTabButtonContainer a").mouseover(function(){
		
		$("#genTabButtonContainer a").addClass("genTabInactive");	
		$(this).removeClass().addClass("genTabActive");	
		var tab = "#" + $(this).attr("title");
		$(tab).siblings().css("display","none");
		$(tab).show();
		
	});
		
		
		
	
		
		

	
	}
    
}

HomeBubble.Box.Content.ScanQuestion = {
	initialize: function () {
		
			$("#questContainer a").click(function(){
				
				$(".questShowColor").css('color', '#6E90A6');
				$(".questFadeColor").css('color', '#6E90A6');	
				$(this).css('color' , '#EC6432');
				
				/*var answerIDdiv = "#" + $(this).attr("id")+"div";
				
				$("#questContainer div").css("display","none");
								
				$(answerIDdiv).fadeIn();*/
							
			});
			
			
			
			
			
    }
}

HomeBubble.Box.Content.SignIn = {
	initialize: function () {

		
		window.onbeforeunload = function(){
			if(updateUserInfo()){
			return true;
			}
		}
		
		
		function updateUserInfo(){
		//all your ajax code
		
		//  Usefull to save parcours le parcours client demandÃ© par Bertrand 
		  //	alert('no don\'t leave');
		
		
		}
		
		// Login function
		HomeBubble.Box.Content.SignIn.major();
		
		HomeBubble.Box.Content.SignIn.blinkLogin();
		
		//************************ Variables and functions ***************************************//
		var emailNotExist = true;
		var extraEmailNotExist = true;
		var date_regexp= /^(\d{1,2}\/){2}\d{4}$/; // regular expression pour la date
		
		
		
		//************************ VÃ©rification d'un email existant ************************//

		$("#signInEmail").blur(function(){
		
			// RÃ©cupÃ©ration de l'email saisi par l'utilisateur
			var email = $("#signInEmail").val();	

			if(email != ""){
				// Envoie de l'email via ajax
				$.ajax({
					type: "POST",
					url: HomeBubble.Paths.BASEWEB + 'default/signin/checkemailajax',
					data: "email="+ email,
					success: function(data){
						//Si l'email existe dÃ©jÃ , on informe l'utilisateur
						if(data == "not ok"){
						
							$('#emailResult').css("display", "block");
							$("#emailInvalid").fadeOut();
							emailNotExist = false;
						}
						// Sinon tout va bien
						if (data == "ok"){
						
						
						//	$('#emailResult').css("display", "none");	
							emailNotExist = true;
							$('#emailResult').css("display", "none");
							$("#emailInvalid").slideUp();
							$('#failureEmail').slideUp();
						}
					}
				
				});
			
			//	$.scrollTo( 'body', 800);				
				
			}else{
				$('#emailResult').css("display", "none");
			}

			
		});
		
		//************************ VÃ©rification de l'email conjoint (existant ou pas) ************************//

		$("#emailExtra").blur(function(){
		
			// RÃ©cupÃ©ration de l'email saisi par l'utilisateur
			var email = $("#emailExtra").val();	
		
			if(email != ""){
				// Envoie de l'email via ajax
				$.ajax({
					type: "POST",
					url: HomeBubble.Paths.BASEWEB + 'default/signin/checkemailajax',
					data: "email="+ email,
					success: function(data){
						//Si l'email existe dÃ©jÃ , on informe l'utilisateur
						if(data == "not ok"){
							$('#emailExtraError').slideDown();
							$("#emailInvalid").fadeOut();
							extraEmailNotExist = false;
							$.scrollTo( 'body', 800);
						}
						// Sinon tout va bien
						if (data == "ok"){	
							extraEmailNotExist = true;
							$('#emailExtraError').slideUp();

						}
					}
				
				});				
				
			}
			else{
				$('#emailExtraError').slideUp();
			}
			
			
			
		});
		
		//************************ Datepicker in signIn form ************************//
	/*
		$.datepicker.setDefaults($.extend({showMonthAfterYear: false}, $.datepicker.regional['fr']));
		$('#birth').datepicker({
					changeMonth: true,
					changeYear: true,
					defaultDate: '-18y',
					yearRange: '-90:+18'
		});
		*/
 		
	/*	$("#birth").blur(function(){
			var date = $("#birth").val();
			
			if( HomeBubble.Box.Content.SignIn.checkDate(date) ){
			
					//alert('true');
			}else{
			//	alert('false');
					$('#dateResult').slideDown();
			}
 						
 			
			
		});*/
		
		//******************** Soumission du formulaire aprÃ¨s clique sur le bouton "valider" ************************//
	
		$('#formButtonSubscribe').click(function(){
		
				
				
				// dÃ©finition des diffÃ©rentes variables
				var email = $('#signInEmail').val();
				var password = $('#signInPassword').val();
				var confirmPassword = $('#confirmSignInPassword').val();
				var answer =  $('#answer').val();
				var question = $('#secretQuestion').attr('value');
				var civility = $('#civility').attr('value');
				var firstName = $('#firstName').val();
				var lastName = $('#lastName').val();
				var birth = $('#birth').val();
				var address = $('#address').val();
				var zipCode = $('#zipCode').val();
				var city = $('#signInCity').val();	
				var emailExtra = $('#emailExtra').val();
				var confirmEmailExtra = $('#confirmEmailExtra').val();
				var idProvider = $("#idProvider").val();
				
				var partner = $('#partner').attr('checked'); 
				var generalConditions = $('#generalConditions').attr('checked'); 
				
				var passwordValid = false;
				var confirmPasswordValid = false;
				var confirmEmailExtraValid = true;
				var emailNotEqual = true;
				var emailValid = HomeBubble.Box.Content.SignIn.checkEmail(email);
				
				if(email == emailExtra){
					emailNotEqual = false;
					$('#emailEqual').slideDown();
				}
				else{
					emailNotEqual = true;
					$('#emailEqual').slideUp();
				}
				
				if(emailExtra != '' || confirmEmailExtra != ''){
					
					$('#signFormExtraSubscribe').slideDown();
				}
				
				// Husband/Spouse email
				if(confirmEmailExtra != emailExtra){
					
					$('#confirmEmailExtraError').slideDown();
					confirmEmailExtraValid = false;
				}else{
					
					$('#confirmEmailExtraError').slideUp();
					confirmEmailExtraValid = true;
				}
				
				emailExtraValid = true;
				if(emailExtra != ''){
					var emailExtraValid = HomeBubble.Box.Content.SignIn.checkEmail(emailExtra);
					if(emailExtraValid == false){
						$("#emailExtraInvalid").slideDown();
					}else{
						$("#emailExtraInvalid").slideUp();
					}
				}
			
				if ( emailValid == false){
		 				 	$("#emailInvalid").slideDown();
		 				// 	alert('no');
				}else{
					emailValid = true;	
					$("#emailInvalid").slideUp();
				}
 				
	 			
				if(emailNotExist == false){
			 			$('#failureEmail').slideDown(function(){
			 				
			 			});
			 	}
			 	
			 	//confirm password must be the same as password
			 	if(confirmPassword == password){
			 		confirmPasswordValid = true;
			 		$('#confirm_passwordResult').slideUp();
			 	}
			 	
			 	if(confirmPassword != password){
			 		confirmPasswordValid = false;
			 		$('#confirm_passwordResult').slideDown();
			 	}
	 				
 				if(answer == ''){
 					$("#answerResult").slideDown();
 					answerCheck = false;
 				}else{
 					$("#answerResult").slideUp();
					 answerCheck = true;	
 				}
 				
				if(firstName == ''){
 					$("#firstnameResult").slideDown();
 					firstnameCheck = false;
 				}else{
 					firstnameCheck = true;
					 $("#firstnameResult").slideUp();	
 				}
 				
 				if(lastName == ''){
 					$("#lastnameResult").slideDown();
 					lastnameCheck = false;
 				}else{
 					$("#lastnameResult").slideUp();
 					lastnameCheck = true;	
 				}
 			/*
 				if( HomeBubble.Box.Content.SignIn.checkDate(date) ){
			
					alert('true');
					
				}else{
					alert('false');
						$('#dateResult').slideDown();
				}
 			*/	
 					//password must be greater than 6 caracters
 			
 				if(password.length < 6){
 				
 					$('#signInPasswordError').slideDown();
 					passwordValid=false;
 				}
 				 if(password.length >= 6){
 				 	$('#signInPasswordError').slideUp();
					passwordValid=true;
 				}
			
				
  				if(partner == true){	
		  			partner = 1;
		  		} else {
		  			partner = 0;
		  		}
		
				//Si les conditions gÃ©nÃ©rales ne sont pas cochÃ©es, on informe l'utilisateur
				if( generalConditions == false ){
					
					$('#generalConditionsResult').slideDown();
				}
				
				if( generalConditions == true ){
					
					$('#generalConditionsResult').slideUp();
				}
				
				//Si l'utilisateur n'a pas choisit de question, on l'informe
				if( question==''){
					$('#questionResult').slideDown();
				}
				
				if( question!=''){
					$('#questionResult').slideUp();
				}
				
				//Cryptage du password en md5
				password = md5(password, false, false);
				answer = md5(answer, false, false);
	 
	 			// Validation du formulaire et envoie des donnÃ©es par ajax
	 			//if ($('.signForm').valid() && generalConditions == true && question!='' && emailNotExist == true ){
	 			if ( generalConditions == true && question!='' && emailNotExist == true &&  answerCheck == true && lastnameCheck == true && firstnameCheck == true && passwordValid == true && confirmPasswordValid == true && extraEmailNotExist == true && confirmEmailExtraValid == true && emailNotEqual == true && emailValid == true && emailExtraValid== true){
	 				
 					$('#formButtonSubscribe').unbind('click');
	 
					//On efface le message d'erreur de l'email
		 			$('#failureEmail').hide();
	 
					$.ajax({
						type: "POST",
					
						url: HomeBubble.Paths.BASEWEB + 'default/signin/signinajax',
						data: "email="+ email+"&password="+ password+"&question="+ question+"&answer="+ answer+"&civility="+ civility+"&firstName="+ firstName+"&lastName="+ lastName+"&birth="+ birth+"&address="+ address+"&zipCode="+ zipCode+"&city="+ city+"&emailExtra="+ emailExtra+"&partner="+ partner+"&generalConditions="+ generalConditions+"&idProvider="+idProvider ,
						success: function(data){
						pos = data.indexOf('<');
									if (pos > 0)
										data = data.substring(0, pos);
										//alert(data);
								if(data == "ok"){
									
									$("#emailDone").attr('value', email);
									$("#registerDone").submit();
									
							//		window.location.href = HomeBubble.Paths.BASEWEB +'/nouveau-membre/email/'+email;
								
									
											// On remonte en haut de la page
											$.scrollTo( 'body', 800);
												
											
											//On efface le formulaire et les message d'erreurs s'il y en a eu et on affiche un message de bon fonctionnement
											$('#failure').hide();
											$('.signForm').hide();
											$('#success h2').fadeIn(2000, function(){
													$("#successEmail").text(email);
													$('#success p').fadeIn();
											});
										}
								}
				
						});
							
			
				}else{
					$.scrollTo( 'body', 500);
					$('#failure').fadeIn();
					
				}
			return false;
		
		});
		
		//*****************************************************************************************//
		
		//Focus on email field 
		$("#signInEmail").focus();
		$("#signInEmail").attr("value", "");
		$("#signInPassword").attr("value", "");
		
		// Show tip for password
		$("#signInPassword").focus(function(){
			$("#signInPasswordTip").slideDown().fadeTo(4000, 0.6);
			
		});
		
		$('#signInPassword').pstrength();
		
		// Show tip for date of birth (dob))
		$("#birth").focus(function(){
			$("#birthTip").slideDown().fadeTo(4000, 0.6);
			
		});
		
		// More info in subscribe form
		$("#signInMoreInfo").click(function(){
			$("#signFormLegal").slideToggle();	
		});
		
		// Sign in Couple
		$("#signInCouple").click(function(){
		
			$("#signFormExtraSubscribe").slideToggle();
			$("#signFormExtraSubscribeTop").slideToggle();
			$("#signFormExtraSubscribeBottom").slideToggle();
			
			
		});
		
		



	
	},
	checkDate: function(dateStr){
		
//	alert('yes');		
//	function isDate(dateStr) {

				var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
				var matchArray = dateStr.match(datePat); // is the format ok?
				
				if (matchArray == null) {
			//	alert("Please enter date as either mm/dd/yyyy or mm-dd-yyyy.");
				return false;
				}
				
				month = matchArray[1]; // p@rse date into variables
				day = matchArray[3];
				year = matchArray[5];
				
				if (month < 1 || month > 12) { // check month range
			//	alert("Month must be between 1 and 12.");
				return false;
				}
				
				if (day < 1 || day > 31) {
			//	alert("Day must be between 1 and 31.");
				return false;
				}
				
				if ((month==4 || month==6 || month==9 || month==11) && day==31) {
			//	alert("Month "+month+" doesn`t have 31 days!")
				return false;
				}
				
				if (month == 2) { // check for february 29th
				var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
				if (day > 29 || (day==29 && !isleap)) {
			//	alert("February " + year + " doesn`t have " + day + " days!");
				return false;
				}
				}
				return true; // date is valid
		

	},
	checkEmail: function(email){
					var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
					if (!filter.test(email)) {
						return false;
					}else{
						return true;
					}
			},
	blinkLogin: function(){
		
		
			$("#genAlreadyMember").click(function(){
				
				$(".genLoginID").fadeOut().fadeIn(function(){
					$(".genLoginPass").fadeOut().fadeIn(function(){
						
						$(".genLoginID").fadeOut().fadeIn(function(){
					$(".genLoginPass").fadeOut().fadeIn();
				});
				
					});
				});
					
				return false;
					
		});
		
	},modal_signin_failed_behaviour:function(){

			$("#genEmail2").focus(function() {
				if($(this).attr("value") == $(this).attr("alt")) {
					$(this).attr("value", "");
				}
				$("#genLoginPersistant2").slideDown('slow');
			});

			$("#genEmail2").blur(function() {
				if($(this).attr("value") == "") {
					$(this).attr("value", $(this).attr("alt"));
				}	
			});

			$("#genPassword2").focus(function() {
				if($(this).attr("value") == $(this).attr("alt")) {
					$(this).attr("value", "");
				}

				$("#genLoginPersistant2").slideDown('slow');

			});

			$("#genPassword2").blur(function() {
				if($(this).attr("value") == "") {
					$(this).attr("value", $(this).attr("alt"));
				}	
			});

		
	},major: function(){
	
	
		$("#genEmail").focus(function() {
			if($(this).attr("value") == $(this).attr("alt")) {
				$(this).attr("value", "");
			}
			$("#genLoginPersistant").slideDown('slow');
		});
		
		$("#genEmail").blur(function() {
			if($(this).attr("value") == "") {
				$(this).attr("value", $(this).attr("alt"));
			}	
		});
		
		$("#genPassword").focus(function() {
			if($(this).attr("value") == $(this).attr("alt")) {
				$(this).attr("value", "");
			}
			
			$("#genLoginPersistant").slideDown('slow');
			
		});
		
		$("#genPassword").blur(function() {
			if($(this).attr("value") == "") {
				$(this).attr("value", $(this).attr("alt"));
			}	
		});
		
		$("#genLoginSubmit").click(function(){
				HomeBubble.Box.Content.SignIn.sign_in();
			return false;	
		});
	
	},sign_in:function(){
		
		if( $("#genEmail").attr('value') == $("#genEmail").attr("alt") || $("#genPassword").attr('value') == $("#genPassword").attr("alt") ){
			
			strUrl = HomeBubble.Paths.BASEWEB + 'member/message/loginajax/';
			$("#genLoginResult").load( strUrl , {message: 'empty'} , function(){
				
				$(this).slideDown( "slow" , function(){
					$(this).oneTime("4s", function() {
					     $(this).slideUp("slow");
					});
					
				});
					
			});
			
		}else{
		
			String.prototype.reverse = function(){
				splitext = this.split("");
				revertext = splitext.reverse();
				reversed = revertext.join("");
				return reversed;
			}
			x = new String('This is a test.');

			email = $("#genEmail").attr('value');
			password = md5($("#genPassword").attr('value'));
			inverse = password.reverse();
			captchaInput = $('#captchaInput').attr('value');
			captchaId = $('#captchaId').attr('value');
			//alert('email'+' '+password+' '+captchaInput+' '+captchaId);
								
			strUrl = $("#genLoginForm").attr('action');
			
			$.post( strUrl , {email: email , password: inverse, captchaId: captchaId, captchaInput: captchaInput} , function(data){
				if(data.result){
					//alert('ok');
					$('#genLoginError').slideUp();
					
					window.location = HomeBubble.Paths.HOST_LINK+"membre/";
				//	window.location = "http://www.home-bubble.com/membre/";

				}else{

					if(data.captchaImg)
					{	
						strUrl = "/signin/signinfailed";
						$("#signInFailedModal").load(strUrl, { update:true}, function(){
							$("#signInFailedModal #captchaImg").attr("src", data.captchaImg);
							$("#signInFailedModal #captchaId").attr("value", data.captchaId);
							$("#signInFailedModal #captcha").slideDown();
							
						}).dialog({
								bgiframe: true,
								autoOpen: true,
								height: 'auto',
								draggable: true,
								resizable: true,
								width: '370px',
								modal: true,
								closeOnEscape: false,
								buttons: {
								/***  Bouton Valider et ses options  ***/
								"Valider": function() {
										HomeBubble.Box.Content.SignIn.sign_in_modal();
									}, 
									/***  Bouton annuler et ses options  ***/		
									"Annuler": function() {
										$(this).dialog('destroy');
									}

								},
								/***  Fonction "close"  ***/
								close: function() {
									$(this).dialog('destroy');
								}
						
							
						});
						
						

					}else{
						$('#genLoginError').slideDown(function(){
							$(this).oneTime('4s',function(){
								$(this).slideUp();
							});
						});
					}
						/*
					$("#genLoginHover").fadeOut( 'normal' ,  function(){
						$("#genLoginContent").fadeIn();	
						$('#genLoginError').slideDown();				
					});
					*/
					
				}
			}, 'json');
		}
		
	},sign_in_modal: function(){
		
		if( $("#genEmail2").attr('value') == $("#genEmail2").attr("alt") || $("#genPassword2").attr('value') == $("#genPassword2").attr("alt") ){
			
			strUrl = HomeBubble.Paths.BASEWEB + 'member/message/loginajax/';
			$("#genLoginResult2").load( strUrl , {message: 'empty'} , function(){
				
				$(this).slideDown( "slow" , function(){
					$(this).oneTime("4s", function() {
					     $(this).slideUp("slow");
					});
					
				});
					
			});
			
		}else{
			
					
			String.prototype.reverse = function(){
				splitext = this.split("");
				revertext = splitext.reverse();
				reversed = revertext.join("");
				return reversed;
			}
			x = new String('This is a test.');

			email = $("#genEmail2").attr('value');
			password = md5($("#genPassword2").attr('value'));
			inverse = password.reverse();
			captchaInput = $('#captchaInput').attr('value');
			captchaId = $('#captchaId').attr('value');
			//alert('email'+' '+password+' '+captchaInput+' '+captchaId);
								
			strUrl = $("#genLoginForm2").attr('action');
			
			$.post( strUrl , {email: email , password: inverse, captchaId: captchaId, captchaInput: captchaInput} , function(data){
				if(data.result){
				
					$('#genLoginError2').slideUp();
					
					window.location = HomeBubble.Paths.HOST_LINK+"membre/";
				//	window.location = "http://www.home-bubble.com/membre/";

				}else{
					
					if(data.captchaImg)
					{	

							$("#captchaImg").attr("src", data.captchaImg);
							$("#captchaId").attr("value", data.captchaId);
							$("#captcha").slideDown();

					}else{
						
						$('#genLoginError2').slideDown(function(){
							$(this).oneTime('4s',function(){
								$(this).slideUp();
							});
						});						
						
					}



				}
			}, 'json');
		}			

	}
 
}



HomeBubble.Box.Content.Archive = {
	
		initialize: function () {
					
					var idUsrBubble = $('#archiveAddStart').attr('rel');
					strUrl = HomeBubble.Paths.BASEWEB + 'member/archive/index';
					$.post(strUrl, { idUsrBubble: idUsrBubble}, function(){
						
					});
					

					/** Default loading of archive list **/
					show = 'limit';
					HomeBubble.Box.Content.Archive.update_archive(show);
					
					$("#archDisplayAll").click(function(){
						$("#archDisplayLimit").show();
						$(this).hide();
						HomeBubble.Box.Content.Archive.update_archive('all');									
					});

					$("#archDisplayLimit").click(function(){
						$("#archDisplayAll").show();
						$(this).hide();
						HomeBubble.Box.Content.Archive.update_archive();									
					});
					
					//Add an archive
					$('#archiveAddStart').click(function(){
						var idUsrBubble = $('#archiveAddStart').attr('rel');
						var bubbleFolder = $("#bubbleFolder").attr('value');
						$('#addArchive').html('<div class="genLoading"></div>');
						HomeBubble.Box.Content.Archive.add_modal_archive(idUsrBubble,bubbleFolder);
					});	
					


			},
			// Opens delete modal window
			delete_modal_archive: function(idArchive, profile){
									
					strUrl = HomeBubble.Paths.BASEWEB + 'member/archive/deletemodal';
					$('#deleteArchive').load(strUrl , { idArchive: idArchive } ).dialog({
					
						bgiframe: true,
						autoOpen: true,
						height: 'auto',
						draggable: true,
						resizable: true,
						width: 400,
						modal: true,
						closeOnEscape: false,
						buttons: {
									/***  Bouton Valider et ses options  ***/
									
									"Valider": function() {						
									HomeBubble.Box.Content.Archive.delete_archive(idArchive, profile);
			
								},
										
									/***  Bouton annuler et ses options  ***/	
										
									"Annuler": function() {
									$(this).dialog('destroy');
								}
								
							}

				});
				
			
				return false;
				
			
			},
			delete_modal_archive_behaviour: function(){
				
					/** Modal beahaviour **/			
					$("#mytest").click(function(){
						alert('test');	
					});
					
					
			},edit_modal_archive: function(idArchive, profile){
				var nameValidated = true;
				var fileValidated = true;
				strUrl = HomeBubble.Paths.BASEWEB + 'member/archive/editmodal';
				$('#editArchive').load(strUrl, {update: true, idArchive:idArchive}, function(){
					
							$('#fileTitle').blur(function(){
	   
					    	 	if($(this).val()==''){
					    	 		$('#fileTitleError').slideDown();
					    	 		nameValidated = false;
					    	 	}
					    	 	if($(this).val()!=''){
					    	 		$('#fileTitleError').slideUp();
					    	 		nameValidated = true;
					    	 }
					    	 
				    	  }); 
					
				}).dialog({
							
								bgiframe: true,
								autoOpen: true,
								height: 'auto',
								draggable: true,
								resizable: true,
								width: 500,
								modal: true,
								closeOnEscape: false,
								buttons: {
											/***  Bouton Valider et ses options  ***/
											"Valider": function() {
											if(fileValidated == true && nameValidated == true){
												HomeBubble.Box.Content.Archive.edit_archive(idArchive, profile);

												$(this).dialog('destroy');
											}
											else{
												if($('#addFormName').attr("value")==""){
													$('#addFormNameError').slideDown();
												}
												if($('#addFormFileName').attr("value")==""){
													$('#addFormFileError').slideDown();
												}
											}
											

										},
												
											/***  Bouton annuler et ses options  ***/		
											"Annuler": function() {
											$(this).dialog('destroy');
											//$('.portlet').fadeIn();
										}
										
									},
								close:function(){
										$(this).dialog('destroy');
									
								}
						});
				return false;
				
			},
			edit_archive: function(idArchive, profile){
				
				strUrl = HomeBubble.Paths.BASEWEB + 'member/archive/editajax';
				var name = $('#fileTitle').val();
				
				// Edit from the profile Archive page
				if(profile == 1){

					$('.profilePaperUsrBubbleFileName[rel='+idArchive+']').html(name);
					
																
				}
	
				$.post(strUrl, { name: name, idArchive: idArchive }, function(){
					
						show = $(".archList").attr('rel');
	   					HomeBubble.Box.Content.Archive.update_archive(show);
 							  	
					
				});			
			
			},
			update_archive:function(show){
					
					// Load default content of archive
					var idUsrBubble = $('#archiveAddStart').attr('rel');
					
					$('#archiveContent').slideUp(function(){
						
					$('#archiveContent').html('<div class="genLoading"></div>');
				//	show = $(".archList").attr('rel');
					
				
					
					strUrl = HomeBubble.Paths.BASEWEB + 'member/archive/getlistajax';
					$('#archiveContent').load(strUrl, { update: true, show: show, idUsrBubble: idUsrBubble }, function(data){
							
							
							$(this).slideDown();
							
								//Update expand list menu
									strUrl = HomeBubble.Paths.BASEWEB + 'member/archive/getnumberajax';
									$.post(strUrl , { update: true, idUsrBubble:idUsrBubble} , function(data){
									    //stuff to do *after* page is loaded;
										if(data.menu == 'show'){
											$("#archNumberElement").html("("+data.total+")");
											$("#archButtons").show();
										}else{
											$("#archButtons").hide();						
										}


									}, 'json');	
							
							//Edit an archive
							$('.archEditButton').click(function(){
							var idArchive = $(this).attr('rel');	
							$('#editArchive').html('<div class="genLoading"></div>');
							HomeBubble.Box.Content.Archive.edit_modal_archive(idArchive);
							});	
			
							
							//Delete archive
							$('.archDeleteButton').click(function(){
									idArchive = $(this).attr('rel');
									$('#deleteArchive').html('<div class="genLoading"></div>');
									HomeBubble.Box.Content.Archive.delete_modal_archive(idArchive);
							});							
							
							//Send archive by email
							$('.archEmailButton').click(function(){
								idArchive = $(this).attr('rel');
								HomeBubble.Box.Content.Archive.send_modal_archive(idArchive);
								return false;
							});
									
						});
							
					});

			},
			send_modal_archive:function(idArchive){
				strUrl = HomeBubble.Paths.BASEWEB + 'member/archive/sendmodal';
				$('#sendArchiveModal').load(strUrl, {idArchive: idArchive}, function(data){
					
				}).dialog({

									bgiframe: true,
									autoOpen: true,
									height: 'auto',
									draggable: true,
									resizable: true,
									width: 500,
									modal: true,
									closeOnEscape: false,
									buttons: {
												/***  Bouton Valider et ses options  ***/
												"Valider": function() {
													HomeBubble.Box.Content.Archive.send_archive(idArchive);
														
												},

												/***  Bouton annuler et ses options  ***/		
												"Annuler": function() {
												$(this).dialog('destroy');
												//$('.portlet').fadeIn();
											}

										},
									close:function(){
											$(this).dialog('destroy');

									}
							});
				
			},
			send_archive:function(idArchive){
				
				$("#sendArchiveFailed").slideUp();
				
				var archiveFolder = $('#archiveFolder').attr('value');
				var usrFolder = $('#usrFolder').attr('value');
				var bubbleFolder = $('#bubbleFolder').attr('value');
				var filename = $('#filename').attr('value');
				
				var lastname = $('#sendArchiveName').attr('value');
				var firstname = $('#sendArchiveNickName').attr('value');
				var emailUsr = $('#sendArchiveEmail').attr('value');
				var message = $('#sendArchiveMessage').attr('value');
				var email1 = $('#sendArchiveEmail1').attr('value');
				var email2 = $('#sendArchiveEmail2').attr('value');
				var email3 = $('#sendArchiveEmail3').attr('value');
				var email = '';

		    	arrEmail = new Array( );
		    	arrEmail[0]= email1;
				arrEmail[1]= email2;
				arrEmail[2]= email3;
				
			//	var lastnameValidated = false;
		    //	var firstnameValidated = false;
		    	var emailValidated = true;
		    	var email1Validated = true;
		    	var email2Validated = true;
		    	var email3Validated = true;
		
		    /*	if(lastname == ''){
		    		$('#sendArchiveNameError').slideDown();
		    		lastnameValidated = false;	
		    	}
		    	if(lastname != ''){
		    		$('#sendArchiveNameError').slideUp();
		    		lastnameValidated = true;	
		    	}
		
		    	if(firstname == ''){
		    		$('#sendArchiveNickNameError').slideDown();
		    		firstnameValidated = false;	
		    	}
		    	if(firstname != ''){
		    		$('#sendArchiveNickNameError').slideUp();
		    		firstnameValidated = true;	
		    	}*/
		
				if(emailUsr != ""){
			    	if(HomeBubble.Box.Content.SignIn.checkEmail(emailUsr) == false){
			    		$('#sendArchiveEmailError').slideDown();
			    		emailValidated = false;

			    	}

			    	if(HomeBubble.Box.Content.SignIn.checkEmail(emailUsr) == true){
			    		$('#sendArchiveEmailError').slideUp();
			    		emailValidated = true;

			    	}
		    	}else if(emailUsr == ""){
					$('#sendArchiveEmailError').slideDown();
		    		emailValidated = false;

				}
		
				if(email1 != ""){
		    		if(HomeBubble.Box.Content.SignIn.checkEmail(email1)== true){
		    			$('#sendArchiveEmailError1').slideUp();
		    			email1Validated = true;
		    		}
		    		  if(HomeBubble.Box.Content.SignIn.checkEmail(email1)== false){
		    			$('#sendArchiveEmailError1').slideDown();
		    			email1Validated = false;
		    		}
		    	}else if(email1 == ""){
					$('#sendArchiveEmailError1').slideDown();
	    			email1Validated = false;
				}

		    	if(email2 != ""){
		    		if(HomeBubble.Box.Content.SignIn.checkEmail(email2)== true){
		    			$('#sendArchiveEmailError2').slideUp();
		    			email2Validated = true;
		    		}
		    		  if(HomeBubble.Box.Content.SignIn.checkEmail(email2)== false){
		    			$('#sendArchiveEmailError2').slideDown();
		    			email2Validated = false;
		    		}
		    	}

		    	if(email3 != ""){
		    		if(HomeBubble.Box.Content.SignIn.checkEmail(email3)== true){
		    			$('#sendArchiveEmailError3').slideUp();
		    			email3Validated = true;
		    		}
		    		  if(HomeBubble.Box.Content.SignIn.checkEmail(email3)== false){
		    			$('#sendArchiveEmailError3').slideDown();
		    			email3Validated = false;
		    		}
		    	}
		
			/*	if(emailUsr == ""){
		    		$('#sendArchiveEmailError').slideUp();
		    		emailValidated = true;
		    	}

		    	if(email1 == ""){
		    		$('#sendArchiveEmailError1').slideUp();
		    		email1Validated = true;
		    	}*/

		    	if(email2 == ""){
		    		$('#sendArchiveEmailError2').slideUp();
		    		email2Validated = true
		    	}

				if(email3 == ""){
		    		$('#sendArchiveEmailError3').slideUp();
		    		email3Validated = true;
		    	}

				if(email1Validated == true && email2Validated == true && email3Validated == true && emailValidated == true){
					
					strUrl = HomeBubble.Paths.BASEWEB + 'member/archive/sendarchive';
					
					$.post(strUrl,{archiveFolder: archiveFolder, usrFolder: usrFolder, bubbleFolder: bubbleFolder, filename: filename, idArchive: idArchive, 'arrEmail[]': arrEmail, firstname: firstname, lastname: lastname, emailUsr: emailUsr, message: message}, function(data){
						if(data == 'sent'){
							$('#sendArchiveModal').dialog('destroy');
						}
						else{
							$("#sendArchiveFailed").slideDown();
						}
					});
					
				}
				
				
			},
			delete_archive:function(idArchive, profile){
										
						strUrl = HomeBubble.Paths.BASEWEB + 'member/archive/deleteajax/';
						
						$.post(strUrl, { idArchive: idArchive }, function(data){							
 							  if(data == 'deleted' ){
 							  	
 							  	if(profile == 1){
										
									$('.profileArchUsrBubbleFileName[rel='+idArchive+']').slideUp();
									$('.profileArchEditButton[rel='+idArchive+']').slideUp();
									$('.profileArchDeleteButton[rel='+idArchive+']').slideUp();
								
										strUrl = HomeBubble.Paths.BASEWEB + 'member/profile/archiveajax';
										//On rÃ©cupÃ¨re la nouvelle liste et on la load Ã  l'endroit de la bulle
										$('.profileArchContainer[rel='+idUsrBubble+']').load(strUrl,{idUsrBubble:idUsrBubble}, function(data){
											
											//Edit an archive
											$('.profileArchEditButton').live('click', function(){

											var idArchive = $(this).attr('rel');
											$('#editArchive').html('<div class="genLoading"></div>');
											var profile = 1;
											HomeBubble.Box.Content.Archive.edit_modal_archive(idArchive, profile);
											});	


											//Delete archive
											$('.profileArchDeleteButton').live('click', function(){
													idArchive = $(this).attr('rel');
													$('#deleteArchive').html('<div class="genLoading"></div>');
													var profile = 1;
													HomeBubble.Box.Content.Archive.delete_modal_archive(idArchive, profile);

											});
											
											
											strUrl = HomeBubble.Paths.BASEWEB + 'member/profile/countarchiveajax';
											$.post(strUrl, {idUsrBubble:idUsrBubble}, function(data){
												$('.profileNumberArchive[rel='+idUsrBubble+']').html(data);
											 	if(parseInt(data) < 1){
													//$('.archiveListIcon[rel='+idUsrBubble+']').attr("src", "/images/front/gui/bkg/spacer.gif");
													//$(".profileArchUsrBubbleFileNameHidden[rel=0]").css("border-left", "0");
													$('.archiveListIcon[rel='+idUsrBubble+']').html('<img align="left" width="16" height="16" src="/images/front/gui/bkg/spacer.gif">')
												}
											})
											
										});
									
									
									
									
								}
 							  	show = $(".todoList").attr('rel');
							   	HomeBubble.Box.Content.Archive.update_archive(show);
 							  	$('#deleteArchive').dialog('destroy');
							  	$('#archiveContent').fadeOut('500', function(){
 							  		
 							  		$('#archiveContent').fadeIn('500');	
 							  	});
 							  	
 							  	//	return 'deleted';
							  	//  alert('deleted');							  	
 							  	
 							  }else{
 							  
						   		//	alert('error');
 							  	//	return 'error-deleted';
 							  	
 							  }
 							  
						});
			
			},add_modal_archive:function(idUsrBubble,bubbleFolder, profile){
				

				var nameValidated = false;
				var fileValidated = false;
				strUrl = HomeBubble.Paths.BASEWEB + 'member/archive/addmodal';
				$('#addArchive').load(strUrl, {update: true, idUsrBubble: idUsrBubble}, function(){

						function getStats(fName){

						fullName = fName;
						shortName = fullName.match(/[^\/\\]+$/);
						return shortName;
						}
							
						 $('.addFile').change(function(){
								idFile = $(this).attr('rel');
							 	filename =	$(this).val();				
								shortname = getStats(filename);
								$("#fileTitle"+idFile).attr('value', shortname  );
							//	$("#uploaded"+idFile).attr('value', ''  );
							//	$("#fileWaitUploadResult"+idFile).fadeOut();
				    	  });
							
							
				
					
				}).dialog({
							
								bgiframe: true,
								autoOpen: true,
								height: 'auto',
								draggable: true,
								resizable: true,
								width: 680,
								modal: true,
								closeOnEscape: false,
								buttons: {
											/***  Bouton Valider et ses options  ***/
											"Valider": function() {
											
														valNoEmpty1 = "true";
														valNoEmpty2 = "true";
														valNoEmpty3 = "true";
														valNoEmpty4 = "true";
														valNoEmpty5 = "true";

														if( $('#addFile1').val() != '' ){

															if( $('#fileTitle1').val() == '' ){
																$('#fileTitleError1').slideDown();
																valNoEmpty1 = "false";
															}

														}


														if( $('#addFile2').val() != '' ){
																if( $('#fileTitle2').val() == '' ){
																	$('#fileTitleError2').slideDown();
																	valNoEmpty2 = "false";
																}

														}

														if( $('#addFile3').val() != '' ){
																if( $('#fileTitle3').val() == '' ){
																	$('#fileTitleError3').slideDown();
																	valNoEmpty2 = "false";
																}
														}


														if( $('#addFile4').val() != '' ){
																if( $('#fileTitle4').val() == '' ){
																	$('#fileTitleError4').slideDown();
																	valNoEmpty2 = "false";
																}

														}

														if( $('#addFile5').val() != '' ){
																if( $('#fileTitle5').val() == '' ){
																	$('#fileTitleError5').slideDown();
																	valNoEmpty2 = "false";
																}
														}

														if( valNoEmpty1 == "true" && valNoEmpty2 == "true" && valNoEmpty3 == "true" && valNoEmpty4 == "true" && valNoEmpty5 == "true"){

														for ( i = 1 ; i < 6 ; i++ ) {

															if(  $('#addFile'+i).val() != ''  ){

																// Alimenter tableau pour la verification cyclique des Ã©lÃ©ments postÃ©s 
																if($("#uploaded"+i).attr('value') == ''){

																	currentValue = $('#docsToBeUploaded').attr('value');
																	newValue = parseInt(currentValue) + parseInt(1);
																	$('#docsToBeUploaded').attr('value', newValue);

																	$('#fileTitleError'+i).slideUp();
																	$("#fileWaitUpload"+i).slideDown();
																	HomeBubble.Box.Content.Archive.add_archive(i, idUsrBubble, profile);
																}

															}else{

																$("#fileAddEmpty"+i).slideDown(function(){
																	$(this).oneTime('3s', function(){
																		$(this).slideUp();
																	});
																});

															}
														}

													}
										
											
										},
												
											/***  Bouton annuler et ses options  ***/		
											"Annuler": function() {
											$(this).dialog('destroy');
											//$('.portlet').fadeIn();
										}
										
									},
								close: function(){
									
									$(this).dialog('destroy');	
								}
						});
				return false;

			},add_archive:function(idForm, idUsrBubble, profile){
							
							$("#fileUploadError"+idForm).html("");
							$("#fileUploadError"+idForm).slideUp();
			    			$( "#fileWaitUpload" + idForm ).fadeIn();

			  				strUrl =  HomeBubble.Paths.BASEWEB + 'member/archive/uploadtempajax';

							var options = { 
					        url:        strUrl,  // target element(s) to be updated with server response 
					        //beforeSubmit:  showRequest,  // pre-submit callback
							dataType: 'json',
					        success:  function(data){
	
									$("#paperWaitContainer").fadeOut();
									if(data.result == true){
											
												//$('.profileArchUsrBubbleFileNameHidden[rel='+idUsrBubble+']').load();
											
										
										
												$("#fileWaitUpload"+idForm ).fadeOut(function(){
													$("#fileWaitUploadResult"+idForm).fadeIn();
												});

												uploadField = "#uploaded"+idForm;

												$( uploadField ).attr("value", "ok");

												show = 'limit';
												show = $(".archList").attr('rel');
												//$("#fileUploadError"+idForm).slideUp();

												// Affichage du message pour le tÃ©lÃ©chargement d'un Ã©lÃ©ment
												// Vidage des Ã©lÃ©ments inputs du formulaire

												currentValue = $('#docsToBeUploaded').attr('value');
												newValue = parseInt(currentValue) - parseInt(1);
												$("#docsToBeUploaded").attr( 'value' , newValue );						
												countDocsUpload = $('#docsToBeUploaded').attr('value');								

												if(countDocsUpload == 0){

													$(this).oneTime('1s', function(){
														$('#addArchive').dialog('destroy');
														// Si on est sur "Mon Compte"
														if(profile == 1) {
															strUrl = HomeBubble.Paths.BASEWEB + 'member/profile/archiveajax';
															//On rÃ©cupÃ¨re la nouvelle liste et on la load Ã  l'endroit de la bulle
															$('.profileArchContainer[rel='+idUsrBubble+']').load(strUrl,{idUsrBubble:idUsrBubble}, function(data){
																
																//Edit an archive
																$('.profileArchEditButton').live('click', function(){

																var idArchive = $(this).attr('rel');
																$('#editArchive').html('<div class="genLoading"></div>');
																var profile = 1;
																HomeBubble.Box.Content.Archive.edit_modal_archive(idArchive, profile);
																});	


																//Delete archive
																$('.profileArchDeleteButton').live('click', function(){
																		idArchive = $(this).attr('rel');
																		$('#deleteArchive').html('<div class="genLoading"></div>');
																		var profile = 1;
																		HomeBubble.Box.Content.Archive.delete_modal_archive(idArchive, profile);

																});
																
																strUrl = HomeBubble.Paths.BASEWEB + 'member/profile/countarchiveajax';
																$.post(strUrl, {idUsrBubble:idUsrBubble}, function(data){
																	$('.profileNumberArchive[rel='+idUsrBubble+']').html(data);
																	if(parseInt(data) >= 1){
																		//$('.archiveListIcon[rel='+idUsrBubble+']').attr("src", "/images/front/gui/icons/bullet_toggle_plus.png")
																	//	$(".profileArchUsrBubbleFileNameHidden").css("border-left", "1px solid #C3C3C3");
																		$('.archiveListIcon[rel='+idUsrBubble+']').html('<img align="left" src="/images/front/gui/icons/bullet_toggle_plus.png">');
																	}
																	else if(parseInt(data) < 1){
																		//$('.archiveListIcon[rel='+idUsrBubble+']').attr("src", "/images/front/gui/bkg/spacer.gif")
																		$('.archiveListIcon[rel='+idUsrBubble+']').html('<img align="left" width="16" height="16" src="/images/front/gui/bkg/spacer.gif">')
																	}
																})
																
															});
														}else{
															HomeBubble.Box.Content.Archive.update_archive(show);	
														}
														
													});
												 	//alert('destroy');
												}												
												
											

										}else if(data.result == false){
												$('#fileWaitUpload'+idForm).fadeOut(function(){
													$("#fileUploadError"+idForm).html(data.message);
													$("#fileUploadError"+idForm).fadeIn();											
												});
										}
									}  
							}

							$("#paperForm"+idForm).ajaxSubmit(options);


			    }

}
	
HomeBubble.Box.Content.Bubble = {
	
		initialize: function () {
		
				// Initialize portlet
				$(".column").sortable({
					connectWith: '.column',
					
					revert: true,
					zIndex:4000,
					stop: function(event, ui) {
						/*
						$(".column").each(function(){
							var myArray = $(this).sortable("serialize");	
						})
						*/
						var column1 = $('#bubbleColumn1').sortable('toArray');
						var column2 = $('#bubbleColumn2').sortable('toArray');
						var column3 = $('#bubbleColumn3').sortable('toArray');
						
						strUrl = HomeBubble.Paths.BASEWEB + 'member/bubble/savebubbleposition';
						$.post( strUrl ,{ 'column1[]': column1 , 'column2[]' : column2 ,  'column3[]': column3 }, function(data){
						
									
							
						});
						
					}

				});
		
			
				$(".column").disableSelection();

		
				//Add Provider
			
				
			
				
				
		
				HomeBubble.Box.Content.Bubble.default_behaviour();
				HomeBubble.Box.Content.Bubble.update_bubble_api();
				
		},
		update_bubble_api: function(){
			
			/*
	  		bubbleApi =  $(".bubbleApiContent").attr('id');
	  		bubbleApiSelector = "#"+$(".bubbleApiContent").attr('id');
  			apiName   =  $(bubbleApiSelector).attr('rel');
	 	 	//	alert(apiName);
	  		$(bubbleApiSelector).html('<div class="genLoading"></div>');
	  		
		
			strUrl = HomeBubble.Paths.BASEWEB + 'member/api/'+apiName;
			$("#bubbleApi").load(  strUrl , { bubbleApi : bubbleApi } , function(data){

			});
				
			*/

			
			
		},
		delete_bubble_ajax: function(idUsrBubble){
			
			strUrl = HomeBubble.Paths.BASEWEB + 'member/bubble/deletebubbleajax';
			$.post(strUrl , {idUsrBubble : idUsrBubble} , function(data){
					
					if(data == 'ok'){
						$('#deleteBubble').dialog('destroy');
						$("#bubble"+idUsrBubble).fadeOut(function(){
							$("#bubble"+idUsrBubble).remove();
						});
						
					}
						
			});
			
			
		}
		,
		delete_bubble: function(idUsrBubble){
						 
						 $('#deleteBubble').html('<div class="genLoading"></div>');
						 strUrl = HomeBubble.Paths.BASEWEB + 'member/bubble/deletebubblemodal';
						$('#deleteBubble').load(strUrl , { idUsrBubble: idUsrBubble } ).dialog({
					
								bgiframe: true,
								autoOpen: true,
								width: 550,
								minHeight: 150,
								height: 'auto',
								draggable: true,
								resizable: true,
								modal: true,
								closeOnEscape: false,
								buttons: {
											/***  Bouton Valider et ses options  ***/
											
											"Supprimer la rubrique": function() {
			
											HomeBubble.Box.Content.Bubble.delete_bubble_ajax(idUsrBubble);
						
										},
												
											/***  Bouton annuler et ses options  ***/	
												
											"Annuler": function() {
											$(this).dialog('destroy');
											//$('.portlet').fadeIn();
										}
										
									},
							close: function(){
								
									$(this).dialog('destroy');
							}
		
						});	
			
			
		},
		default_behaviour:function(){
				$('.bubbleEmpty').unbind('click').click(function(){
				
					var idUsrBubble = $(this).attr('rel');
					//alert(idTheme);
					//	$('#addBookmark').html('<div class="genLoading"></div>');
					idBubble = $(".portletContainer").attr('rel');
					
					// Initialize bubble theme to 0 because we add a provider to an existing USR_BUBBLE 
					idBubbleTheme = 0;
					
					HomeBubble.Box.Content.Bubble.add_modal_provider(idBubble, idBubbleTheme, idUsrBubble);
					
				});
				
				$(".portlet-footer .ui-icon").live('click' , function() {
					idUsrBubble = $(this).attr('rel');
					HomeBubble.Box.Content.Bubble.delete_bubble(idUsrBubble);
				});
	
		},
		
		add_modal_provider:function(idBubble, idBubbleTheme, idUsrBubble){
			
			
			
			
			
			$('#addNewProvider').html('<div class="genLoading"></div>');
			strUrl = HomeBubble.Paths.BASEWEB + 'member/bubble/addprovidermodal';
			
			$('#addProvider').load(strUrl , { idBubble: idBubble, idBubbleTheme: idBubbleTheme, idUsrBubble: idUsrBubble } ).dialog({
					
						bgiframe: true,
						autoOpen: true,
						width: 620,
						height: 'auto',
						draggable: true,
						resizable: true,
						modal: true,
						closeOnEscape: false,
						buttons: {
									/***  Bouton Valider et ses options  ***/
									
									"Valider": function() {
										usrBubbleName = $("#usrBubbleName").attr('value');
										if(usrBubbleName == ''){
											$('#newNoTitle').slideDown();
										}else{
											$('#newNoTitle').slideUp();
											HomeBubble.Box.Content.Bubble.add_provider_info(idBubble,idBubbleTheme);
										}	
														
				
								},
										
									/***  Bouton annuler et ses options  ***/	
										
									"Annuler": function() {
										$(this).html('');
									$(this).dialog('destroy');
									//$('.portlet').fadeIn();
								}
								
							},
					close: function(){
							$(this).html('');
							$(this).dialog('destroy');
					}

				});
	
		},
		add_modal_behaviour_provider:function(){
						
				// Add a provider that is not in the list
				$("#addProviderNewLink").click(function(){					
					$("#addProviderNewLink").fadeOut();
					$("#nameNewProviderLabel").fadeIn(function(){
					
					
						$("#nameNewProvider").slideDown("500", function(){
						});							
					});
				});
				
				$(".addProviderLogoLink").click(function(){
				
					idUsrBubble = $("#idUsrBubbleProviderList").attr('value');
					idProvider = $(this).attr('rel');
					$('#addNewProvider').html('<div class="genLoading"></div>');
					strUrl = HomeBubble.Paths.BASEWEB + 'member/bubble/addproviderinfoform';
					$('#addNewProvider').load(strUrl, { idProvider: idProvider, idUsrBubble:idUsrBubble }, function(data){
							
					});
					
					// Put info form provider in the center of the screen after open 
					 var viewportWidth = $(window).width();  
 					 var viewportHeight = $(window).height(); 
 					 
 					 var middleWidth =  parseInt(viewportWidth/3);
 					 var middleHeight =  parseInt(viewportHeight/5);

					$('#addProvider').dialog('option', 'position', [middleWidth,middleHeight]);

				})

		},
		add_provider_info:function(){
		
			//checkbox
			$('.hooverCheckbox').each(function(index) {
			    if($(this).is(':checked')){
					$(this).attr('value', 1);
					$("#provHoover").append('<input type="hidden" name="hooverActivated" value="true"/>');
				}else{
					name = $(this).attr('name');
					$("#provHoover").append('<input type="hidden" name="'+name+'" value="0"/>');
					$("#provHoover").append('<input type="hidden" name="hooverActivated" value="false"/>');
				//	$(this).attr('value', 0);
				}
			 });
			
			
			//	test = $("input[@type=text]").serialize();
			var formValues = $("#addProviderInfoForm").serialize();
			apiLink = $("#addApiLink").attr("value");
			idUsrBubble = $("#idUsrBubbleProviderInfoForm").attr('rel');
			idProvider = $("#bubbleIdProviderInfo").attr('value');
			usrBubbleName = $("#usrBubbleName").attr('value');

		
			nameNewProvider = $('.addNewProvider').attr("value");

			// Check how many elements in columns to put new bubble in the one with the less elements
		 	columnOneNumber = $("#bubbleColumn1").children().size();
			columnTwoNumber = $("#bubbleColumn2").children().size();
		 	columnThreeNumber = $("#bubbleColumn3").children().size();
			if( columnThreeNumber <=  columnTwoNumber && columnThreeNumber <= columnOneNumber){
				column = 3;
			}					

			if( columnTwoNumber <=  columnOneNumber && columnTwoNumber <= columnThreeNumber){
				column = 2;
			}

			if( columnOneNumber <=  columnTwoNumber && columnOneNumber <= columnThreeNumber){
				column = 1;
			}


			// If new provider is a new provider entered by the user 
			if(isNaN(idProvider)){
				
					$("#addProvider").dialog("destroy");
					idUsrBubble = $("#idUsrBubbleProviderList").attr('value');
					idBubbleTheme = $("#idBubbleThemeProviderList").attr('value');
					idBubble = $('#idBubbleProviderList').attr('value');
					
					//If it is a new provider / not entered by admin
					newProvider = 1;
					strUrl = HomeBubble.Paths.BASEWEB + 'member/bubble/addproviderinfoform';
					$('#addOtherProvider').load(strUrl, { idProvider: idProvider, idUsrBubble:idUsrBubble, newProvider: newProvider, nameNewProvider: nameNewProvider, idBubbleTheme: idBubbleTheme}, function(data){
							
					}).dialog({
						
						bgiframe: true,
						autoOpen: true,
						width: 550,
						height: 'auto',
						draggable: true,
						resizable: true,
						position: 'top',
						modal: true,
						closeOnEscape: false,
						buttons: {
									/***  Bouton Valider et ses options  ***/
									
									"Valider": function() {
										
									
										
										usrBubbleName = $("#usrBubbleName").attr('value');
										usrBubbleTitle = $("#usrBubbleTitle").attr('value');
										checkTitle = true;
										checkName = true;
										
										if(usrBubbleName == '' ){
											$('#newNoName').slideDown();
											checkName = false;
										}else{
											$('#newNoName').slideUp();
										}
										
										if(usrBubbleTitle == '' ){
											$('#newNoTitle').slideDown();
											checkTitle = false;
										}else{
											$('#newNoTitle').slideUp();
										}
										
										
										if( checkTitle && checkName){	
											$('#newNoTitle').slideUp();
											$('#newNoName').slideUp();				
											HomeBubble.Box.Content.Bubble.add_new_provider_info(idUsrBubble, nameNewProvider, idBubbleTheme, idBubble);
										}
										
										
								},
										
									/***  Bouton annuler et ses options  ***/	
										
									"Annuler": function() {
									$(this).html('');
									$(this).dialog('destroy');
									//$('.portlet').fadeIn();
								}
								
							},
					close: function(){
						$(this).html('');
							$(this).dialog('destroy');
					}
						
						
					});

			}
		
			else{
	

				$(".ui-dialog-buttonpane").append('<div class="genLoadingModalSubmit">Merci de patienter...</div>');

				
	
						strUrl = HomeBubble.Paths.BASEWEB + 'member/bubble/addproviderinfoformprocess';
						$.post( strUrl, { values : formValues , idUsrBubble : idUsrBubble , idProvider:idProvider , usrBubbleName : usrBubbleName, idBubbleTheme: idBubbleTheme, idBubble: idBubble, column: column}, function(data){
							
							if( data){
									
									//$("#addProvider").dialog("destroy");
														
									window.location.href = data;
							}									
							
						});
					
				
	
			}
			
		},add_new_provider_info: function(idUsrBubble, nameNewProvider, idBubbleTheme, idBubble){
	
			titre = $("#usrBubbleTitle").attr("value");
			nameNewProvider = $("#usrBubbleName").attr("value");
			spaceClient = $("#usrBubbleSpaceClientLink").attr("value");
			identify = $("#usrBubbleIdentify").attr("value");
			password = $("#usrBubblePwd").attr("value");
			tel1 = $("#usrBubbleTel1").attr("value");
			tel2 = $("#usrBubbleTel2").attr("value");
			fax = $("#usrBubbleFax").attr("value");
			contact = $("#usrBubbleContact").attr("value");
			email = $("#usrBubbleEmail").attr("value");
			site = $("#usrBubbleSite").attr("value");
			address = $("#usrBubbleAddress").attr("value");
			other = $("#usrBubbleOther").attr("value");
			contractNumber = $("#usrBubbleContractNumber").attr("value");
			clientNumber = $("#usrBubbleClientNumber").attr("value");
			otherRef = $("#usrBubbleOtherRef").attr("value");
			idBubble = $(".portletContainer").attr('rel');
			$(".ui-dialog-buttonpane").append('<div class="genLoadingModalSubmit">Merci de patienter...</div>');


			strUrl = HomeBubble.Paths.BASEWEB + 'member/bubble/addnewproviderinfoformprocess';
			$.post(strUrl, {idUsrBubble: idUsrBubble, idBubble: idBubble, idBubbleTheme: idBubbleTheme, nameNewProvider: nameNewProvider, titre: titre, spaceClient: spaceClient, identify: identify, password: password, tel1: tel1, tel2: tel2, site: site, address: address, other: other, contractNumber:contractNumber, clientNumber: clientNumber, email:email, fax:fax, conatct:contact , otherRef:otherRef, column: column }, function(data){
				
					if(data){
						//$("#addOtherProvider").html('');
						//$("#addOtherProvider").dialog('destroy');
						window.location.href = data;
					}
				
			})
			
		},
		add_provider_info_behaviour: function(){
			
			
			$(".addProvClassTextareaShow").click(function(){
			
					$(".addProvClassTextareaHide[rel='"+$(this).attr('rel')+"']").slideDown();
				
			});
			
			
			
			
		},
		add_bubble_theme:function(idBubble){
			
		//	idBubble = $("#bubbleAdd").attr('rel');
			
			strUrl = HomeBubble.Paths.BASEWEB + 'member/bubble/addbubblethememodal';
			$('#addNewBubble').load(strUrl , { idBubble: idBubble } ).dialog({
					
						bgiframe: true,
						zIndex : 900,
						autoOpen: true,
						width: 725,
						minHeight: 300,
						height: 'auto',
						draggable: true,
						position: 'top',
						resizable: true,
						modal: true,
						closeOnEscape: false,
						buttons: {
							
	/*
									"Valider": function() {
				
								},
								*/	
									"Fermer": function() {
										$(this).html('');
									$(this).dialog('destroy');
									//$('.portlet').fadeIn();
								}
							
							},
					close: function(){
						$(this).html('');
							$(this).dialog('destroy');
					}

				});
			
			
			
			
			
		},
		add_bubble_theme_behaviour: function(){
			
			$(".bubbleThemeNewContainer").click(function(){
					idBubble = $("#idBubble").attr('rel');
					idBubbleTheme = $(this).attr('rel');
					
		
					$('#addNewBubble').dialog('destroy');
					HomeBubble.Box.Content.Bubble.add_modal_provider(idBubble, idBubbleTheme);
					
				
			});		

	
			
			
		}
		
		
		
		

}
HomeBubble.Box.Content.Bookmark = {
	
	initialize: function () {
		
					/** DEfault loading of archive list **/
					HomeBubble.Box.Content.Bookmark.update_bookmark();
					
					// Ajax Pagination feature // check getlistajax for page container (archPagination)
					
					$("#bookDisplayAll").live('click' , function(){
						$("#bookDisplayLimit").show();
						$(this).hide();
						HomeBubble.Box.Content.Bookmark.update_bookmark('all');									
					});

					$("#bookDisplayLimit").live('click', function(){
						$("#bookDisplayAll").show();
						$(this).hide();
						HomeBubble.Box.Content.Bookmark.update_bookmark();									
					});
				
					
					//Add a bookmark
					$('#bookAddStart').click(function(){
								var idUsrBubble = $('#bookAddStart').attr('rel');
								$('#addBookmark').html('<div class="genLoading"></div>');
								HomeBubble.Box.Content.Bookmark.add_modal_bookmark(idUsrBubble);
					});	
		
		
		
		
	},update_bookmark:function(show){
		
		// Load default content of archive
		$('#bookmarkContent').slideUp(function(){
				$('#bookmarkContent').html('<div class="genLoadingDashboardList"></div>');
	
	
		
		var idUsrBubble = $('#bookAddStart').attr('rel');


		strUrl = HomeBubble.Paths.BASEWEB + 'member/bookmark/getlistajax';
		$('#bookmarkContent').load(strUrl, {  show: show , idUsrBubble: idUsrBubble }, function(){
			
			
			$(this).slideDown();

			if(idUsrBubble){
				//update pagination buttons for dashboard
				id="#provFooterActionRightBookmark";
				strUrl = HomeBubble.Paths.BASEWEB + 'member/bookmark/getnumberajax';
				$.post(strUrl , { idUsrBubble: idUsrBubble} , function(data){
				    //stuff to do *after* page is loaded;
					if(data.menu == 'show'){
						$("#bookNumberElement").html("("+data.total+")");
						$("#bookButtons").show();
					}else{
						$("#bookButtons").hide();						
					}
				
				
				}, 'json');
			
			}
			
			if(!idUsrBubble){
				//update pagination buttons for dashboard
				id="#provFooterActionRightBookmark";
				strUrl = HomeBubble.Paths.BASEWEB + 'member/bookmark/getnumberajax';
				$.post(strUrl , { idUsrBubble: idUsrBubble} , function(data){
				    //stuff to do *after* page is loaded;
					if(data.menu == 'show'){
						$("#bookNumberElement").html("("+data.total+")");
						$("#bookButtons").show();
					}else{
						$("#bookButtons").hide();						
					}
				}, 'json');
			}
			
	   		//Edit a bookmark
			$('.bookEditButton').click(function(){
			var idBookmark = $(this).attr('rel');	
			$('#editBookmark').html('<div class="genLoading"></div>');
			HomeBubble.Box.Content.Bookmark.edit_modal_bookmark(idBookmark);
			});	
			
			//Delete archive
			$('.bookDeleteButton').click(function(){
					idBookmark = $(this).attr('rel');
					$('#deleteBookmark').html('<div class="genLoading"></div>');
					HomeBubble.Box.Content.Bookmark.delete_modal_bookmark(idBookmark);
			});							
			});	
	});
		
	},delete_modal_bookmark:function(idBookmark){
		
			 // Put info form provider in the center of the screen after open 
			 var viewportWidth = $(window).width();  
			 var viewportHeight = $(window).height(); 
			 
			 var middleWidth =  parseInt(viewportWidth/3);
			 var middleHeight =  parseInt(viewportHeight/5);
		
			strUrl = HomeBubble.Paths.BASEWEB + 'member/bookmark/deletemodal';
			
			$('#deleteBookmark').load(strUrl , { idBookmark: idBookmark } ).dialog({
					
						bgiframe: true,
						autoOpen: true,
						height: 'auto',
						draggable: true,
						resizable: true,
						width: 400,
						modal: true,
						position: [middleWidth,middleHeight],
						closeOnEscape: false,
						buttons: {
									/***  Bouton Valider et ses options  ***/
									
									"Valider": function() {
	
									HomeBubble.Box.Content.Bookmark.delete_bookmark(idBookmark);
				
								},
										
									/***  Bouton annuler et ses options  ***/	
										
									"Annuler": function() {
									$(this).dialog('destroy');
									//$('.portlet').fadeIn();
								}
								
							},
					close: function(){
						
							$(this).dialog('destroy');
					}

				});
		
		
		
	},delete_modal_archive_behaviour: function(){
				
				/** Modal beahaviour **/			
				$("#bookmarkModal").click(function(){
					//	alert('test');	
				});
				
	},delete_bookmark:function(idBookmark){
		
		strUrl = HomeBubble.Paths.BASEWEB + 'member/bookmark/deleteajax/';
		
		$.post(strUrl, { idBookmark: idBookmark }, function(data){							
		  if(data == 'deleted' ){
		  	show = $(".bookList").attr('rel');
		   	HomeBubble.Box.Content.Bookmark.update_bookmark(show);
		  	$('#deleteBookmark').dialog('destroy');
		  	$('#bookmarkContent').fadeOut('500', function(){
		  		
		  		$('#bookmarkContent').fadeIn('500');	
		  	});
		  	
		  	//	return 'deleted';
		  	//  alert('deleted');							  	
		  	
		  }else{
		  
	   		//	alert('error');
		  	//	return 'error-deleted';
		  	
		  }
		  
	});
		
	
		
	},edit_modal_bookmark:function(idBookmark){
		
			var nameValidated = true;
			var urlValidated = true;
			
				// Put info form provider in the center of the screen after open 
			 var viewportWidth = $(window).width();  
			 var viewportHeight = $(window).height(); 
			 
			 var middleWidth =  parseInt(viewportWidth/3);
			 var middleHeight =  parseInt(viewportHeight/5);
		
			$('#editBookmark').load(HomeBubble.Paths.BASEWEB + 'member/bookmark/editmodal', {idBookmark: idBookmark}, function(){
				//Validate the formula
	
	    	 $('#editBookName').blur(function(){
	   
	    	 	if($(this).val()==''){
	    	 		$('#editBookNameError').slideDown();
	    	 		nameValidated = false;
	    	 	}
	    	 	if($(this).val()!=''){
	    	 		$('#editBookNameError').slideUp();
	    	 		nameValidated = true;
	    	 }
	    	 
    	  }); 
    	  
	    	 $('#editBookUrl').blur(function(){

				 if($('#editBookUrl').val()!=''){
	  				$('#editBookUrlError').slideDown();
	  				urlValidated = true;
	    	 	}
	    	 	if($(this).val()=='' || $(this).val()=='http://' || $(this).val()=='https://'){
	    	 		$('#editBookUrlError').slideUp();
	    	 		urlValidated = false;
	    	 	}
    	  });
							
						}).dialog({
							
								bgiframe: true,
								autoOpen: true,
								height: 'auto',
								draggable: true,
								resizable: true,
								width: 550,
								modal: true,
								position: [middleWidth,middleHeight],
								closeOnEscape: false,
								buttons: {
												/***  Bouton Valider et ses options  ***/
												"Valider": function() {
												if(nameValidated == true && urlValidated == true){
												HomeBubble.Box.Content.Bookmark.edit_bookmark(idBookmark);
												$(this).dialog('destroy');
												}
												else{
											
													if($('#editBookName').attr("value")==""){
														$('#editBookNameError').slideDown();
													}
													if($('#editBookUrl').attr("value")=="" || $('#editBookUrl').attr("value")=="http://" || $('#editBookUrl').attr("value")=="https://"){
														$('#editBookUrlError').slideDown();
													}
												}
											},
									
											/***  Bouton annuler et ses options  ***/		
											"Annuler": function() {
												$(this).dialog('destroy');
												//$('.portlet').fadeIn();
											}

									},
								close:function(){
										$(this).dialog('destroy');
									
								}
						});
		
		
	
	},add_bookmark:function(idUsrBubble){
		
		strUrl = HomeBubble.Paths.BASEWEB + 'member/bookmark/addajax/';
		var name = $('#addBookName').val();				
		var url = $('#addBookUrl').val();


		$.post(strUrl, { name: name, url: url, idUsrBubble : idUsrBubble }, function(){
				//Define limit as default if user has not clicked on expand button
				show = 'limit';
				show = $(".bookList").attr('rel');
				HomeBubble.Box.Content.Bookmark.update_bookmark(show);
				$('#addBookmark').dialog('destroy');
		});	

	},add_modal_bookmark:function(idUsrBubble){
		
		var nameValidated = false;
		var urlValidated = false;
		
		// Put info form provider in the center of the screen after open 
		 var viewportWidth = $(window).width();  
		 var viewportHeight = $(window).height(); 
		 
		 var middleWidth =  parseInt(viewportWidth/3);
		 var middleHeight =  parseInt(viewportHeight/5);
		
		$('#addBookmark').load(HomeBubble.Paths.BASEWEB + 'member/bookmark/addmodal', { idUsrBubble: idUsrBubble}, function(){
			
			//Validate the formula
	
	    	 $('#addBookName').blur(function(){
	   
	    	 	if($(this).val()==''){
	    	 		$('#addBookNameError').slideDown();
	    	 		nameValidated = false;
	    	 	}
	    	 	if($(this).val()!=''){
	    	 		$('#addBookNameError').slideUp();
	    	 		nameValidated = true;
	    	 }
	    	 
    	  }); 
    	  
	    	 $('#addBookUrl').blur(function(){

				 if($('#addBookUrl').val()!=''){
	  				$('#addBookUrlError').slideUp();
	  				urlValidated = true;
	    	 	}
	    	 	if($(this).val()=='http://' || $(this).val()=='https://' || $(this).val()==''){
	    	 		$('#addBookUrlError').slideDown();
	    	 		urlValidated = false;
	    	 	}
    	  });
    	  
    	  
		}).dialog({
							
								bgiframe: true,
								autoOpen: true,
								height: 'auto',
								zIndex : 900,
								draggable: true,
								resizable: true,
								width: 550,
								modal: true,
								position: [middleWidth,middleHeight],
								closeOnEscape: false,
								buttons: {
											/***  Bouton Valider et ses options  ***/
											"Valider": function() {
												if(nameValidated == true && urlValidated){
													HomeBubble.Box.Content.Bookmark.add_bookmark(idUsrBubble);
												}
												else{
											
													if($('#addBookName').attr("value")==""){
														$('#addBookNameError').slideDown();
													}
													if($('#addBookUrl').attr("value")=='http://' || $('#addBookUrl').attr("value")=='https://' ||  $('#addBookUrl').attr("value")==''){
														$('#addBookUrlError').slideDown();
													}
												}
											},
											/***  Bouton annuler et ses options  ***/		
											"Annuler": function() {
												$(this).dialog('destroy');
											}
										
										},
								close:function(){
										$(this).dialog('destroy');
									
								}
						});

	},edit_bookmark:function(idBookmark){
		
 		strUrl = HomeBubble.Paths.BASEWEB + 'member/bookmark/editajax';
    	var bookName = $('#editBookName').val();
    	var url = $('#editBookUrl').val();


		if(bookName!=''){
		
			$.post(strUrl, { bookName: bookName, url: url, idBookmark: idBookmark}, function(){
				show = $(".bookList").attr('rel');
		   		HomeBubble.Box.Content.Bookmark.update_bookmark(show);
	 			$('#editBook').dialog('destroy');
						
			});		
	
		}else{
			
		$('#editBook').dialog('destroy');	
		}

	}
	
	
}
HomeBubble.Box.Content.Password = {
	
	initialize: function () {
		
	//Start modal for forget password feature
	$('#genLoginMorePassword').click(function(){	
		strUrl = HomeBubble.Paths.BASEWEB + 'default/signin/forgotpassword';
		$('#genLoginMorePasswordModal').html('<div class="genLoading"></div>');
		$('#genLoginMorePasswordModal').load(strUrl , { validate: true } ).dialog({
			bgiframe: true,	
			autoOpen: true,	
			height: 'auto',
			draggable: true,
			resizable: true,
			width: 500,
			modal: true,
			closeOnEscape: false,
			buttons: {
					/***  Bouton Valider et ses options  ***/
					"Valider": function() {	
						HomeBubble.Box.Content.Password.forgot_password();
					
						},
					/***  Bouton annuler et ses options  ***/
					"Annuler": function() {
						$(this).dialog('destroy');
					}	
				},
				close : function(){
					$(this).dialog('destroy');												
					}
			});		
							
		});
		


		
		
	    
    },forgot_password:function(){
		
		var email = $('#signInForgotPasswordFormEmail').val();
		strUrl = HomeBubble.Paths.BASEWEB + 'member/auth/checkemailpasswordajax';

			$.post(strUrl, { email: email}, function(data){	
				if(data == "exist"){	
					$('#signInForgotPasswordFail').slideUp();
					$('#signInForgotPasswordSuccess').slideDown();	
					//$('#genLoginMorePasswordModal').dialog('close');
					HomeBubble.Box.Content.Password.modal_question();
					$("#genLoginMorePasswordModal").dialog('option', 'buttons', { 
							 "Fermer": function(){
							 	$("#genLoginMorePasswordModal").dialog('destroy');
							 } 
						});
				}
				if(data== "non-exist"){	
					$('#signInForgotPasswordSuccess').slideUp();
					$('#signInForgotPasswordFail').slideDown();
				}				
			});	
	
	},modal_question: function(){
		
		
		
		
		
		
	}
			
}
HomeBubble.Box.Content.Friend = {
	
	initialize: function () {
	
		//Start modal to send to a friend
		$('#genLoginMoreFriend').click(function(){
			// Put the modal in the center of the screen after open 
			 var viewportWidth = $(window).width();  
			 var viewportHeight = $(window).height(); 
			 
			 var middleWidth =  parseInt(viewportWidth/3);
			 var middleHeight =  parseInt(viewportHeight/5);
			 
			strUrl = HomeBubble.Paths.BASEWEB + 'default/signin/friend';
			$('#genLoginMoreFriendModal').html('<div class="genLoading"></div>');
			$('#genLoginMoreFriendModal').load(strUrl , { validate: true } ).dialog({
				bgiframe: true,
				autoOpen: true,
				height: 'auto',
				draggable: true,
				position: 'top',
				resizable: true,
				width: 610,
				modal: true,
				closeOnEscape: false,
				buttons: {									
						/***  Bouton Valider et ses options  ***/
						"Valider": function() {
							
							HomeBubble.Box.Content.Friend.sendToFriend();
						},
						/***  Bouton annuler et ses options  ***/
						"Annuler": function() {
							$(this).dialog('destroy');
						}
					},
					close : function(){	
						$(this).dialog('destroy');
					}
				});
		});

    },sendToFriend:function(){
    	
    	var nameValidated = false;
    	var nicknameValidated = false;
    	var emailValidated = true;
    	var email1Validated = true;
    	var email2Validated = true;
    	var email3Validated = true;
    	
    	var name = $('#signInSendToFriendFormName').val();
    	var nickname =  $('#signInSendToFriendFormNickName').val();
    	var usrEmail =  $('#signInSendToFriendFormEmail').val();
    	var message = $('#signInSendToFriendFormMessage').val();
    	var email1 = $('#signInSendToFriendFormEmail1').val();
    	var email2 = $('#signInSendToFriendFormEmail2').val();
    	var email3 = $('#signInSendToFriendFormEmail3').val();
    	var email = '';
    	
    	
    	arrEmail = new Array( );
    	arrEmail[0]= email1;
		arrEmail[1]= email2;
		arrEmail[2]= email3; 
    	
    	/*
    	if( window.email1 ){
    		email = email1+';';
    	}
    	if(email2){
    		email = email + email2+';';
    	}
    	if(email3){
    		email = email + email3+';';
    	}
    	if(email1==''&& email2==''&&email3==''){
    		
    		email='';
    	}
    	*/
    	// Validate the form
    	if(name == ''){
    		$('#signInSendToFriendFormNameError').slideDown();
    		nameValidated = false;	
    	}
    	if(name != ''){
    		$('#signInSendToFriendFormNameError').slideUp();
    		nameValidated = true;	
    	}
    	
    	if(nickname == ''){
    		$('#signInSendToFriendFormNickNameError').slideDown();
    		nicknameValidated = false;	
    	}
    	
    	if(nickname != ''){
    		$('#signInSendToFriendFormNickNameError').slideUp();
    		nicknameValidated = true;	
    	}
    	
    	if(usrEmail != ""){
	    	if(HomeBubble.Box.Content.SignIn.checkEmail(usrEmail) == false){
	    		$('#signInSendToFriendFormEmailError').slideDown();
	    		emailValidated = false;
	    		
	    	}
	    	
	    	if(HomeBubble.Box.Content.SignIn.checkEmail(usrEmail) == true){
	    		$('#signInSendToFriendFormEmailError').slideUp();
	    		emailValidated = true;
	    		
	    	}
    	}
    	
    	if(email1 != ""){
    		if(HomeBubble.Box.Content.SignIn.checkEmail(email1)== true){
    			$('#signInSendToFriendFormEmailError1').slideUp();
    			email1Validated = true;
    		}
    		  if(HomeBubble.Box.Content.SignIn.checkEmail(email1)== false){
    			$('#signInSendToFriendFormEmailError1').slideDown();
    			email1Validated = false;
    		}
    	}
    	
    	if(email2 != ""){
    		if(HomeBubble.Box.Content.SignIn.checkEmail(email2)== true){
    			$('#signInSendToFriendFormEmailError2').slideUp();
    			email2Validated = true;
    		}
    		  if(HomeBubble.Box.Content.SignIn.checkEmail(email2)== false){
    			$('#signInSendToFriendFormEmailError2').slideDown();
    			email2Validated = false;
    		}
    	}
    	
    	if(email3 != ""){
    		if(HomeBubble.Box.Content.SignIn.checkEmail(email3)== true){
    			$('#signInSendToFriendFormEmailError3').slideUp();
    			email3Validated = true;
    		}
    		  if(HomeBubble.Box.Content.SignIn.checkEmail(email3)== false){
    			$('#signInSendToFriendFormEmailError3').slideDown();
    			email3Validated = false;
    		}
    	}
    	
    	if(usrEmail == ""){
    		$('#signInSendToFriendFormEmailError').slideUp();
    		emailValidated = true;
    	}
    	
    	if(email1 == ""){
    		$('#signInSendToFriendFormEmailError1').slideUp();
    		email1Validated = true;
    	}
    	
    	if(email2 == ""){
    		$('#signInSendToFriendFormEmailError2').slideUp();
    		email2Validated = true
    	}
    	
		if(email3 == ""){
    		$('#signInSendToFriendFormEmailError3').slideUp();
    		email3Validated = true;
    	}
    	
    	if(nicknameValidated == true && nameValidated == true && email1Validated == true && email2Validated == true && email3Validated == true && emailValidated == true){
			
			strUrl = HomeBubble.Paths.BASEWEB + 'default/signin/sendtofriend';
    
			$.post(strUrl, { 'arrEmail[]' : arrEmail, name: name, nickname: nickname,usrEmail: usrEmail, message: message}, function(data){	
					
					if(data == 'ok'){
						$('#signInSendToFriendFail').slideUp();
						$('#signInSendToFriendSuccess').slideDown();
						$("#genLoginMoreFriendModal").dialog('option', 'buttons', { 
							 "Fermer": function(){
							 	$("#genLoginMoreFriendModal").dialog('destroy');
							 } 
						});
	
					}
					else{
						$('#signInSendToFriendSuccess').slideUp();
						$('#signInSendToFriendFail').slideDown();
		
					}				
				});	
    	
    	}
    }
}
HomeBubble.Box.Content.Dashboard = {
	
	initialize: function () {

		

		/******* PORTLET ******/
		$(function() {
					$(".dashColumn").sortable({
						connectWith: ['.dashColumn'],
						revert: true,
						zIndex: '4000',
						stop: function(event, ui) {
					//alert('yes');
						var column1 = $('#dashColumn1').sortable('toArray');
						var column2 = $('#dashColumn2').sortable('toArray');
						
						strUrl = HomeBubble.Paths.BASEWEB + 'member/dashboard/savebubbleposition';
						$.post( strUrl ,{ 'column1[]': column1 , 'column2[]' : column2  }, function(data){
						
									
							
						});
						
					}
						
					});

			
		/*	$('.portlet-header').css("display", "block");
					$(".dashColumn").disableSelection();*/
			
			});
			
		/******* TEXTAREA NOTES ******/
		$('#dashContentTextArea').live('keyup' , function(){
			
			HomeBubble.Box.Content.Dashboard.update_note();
		});
		
		/**** CLOSE/OPEN PORTLET ****/
		/*
		$('.ui-icon').click(function(){
	
				$(this).parent().parent().fadeOut(2000);
		});
		*/
		/*
		$('#genButtonMemberPortal').click(function(){
			$('#addRubrik').html('<div class="genLoading"></div>');
			HomeBubble.Box.Content.Dashboard.add_modal_rubrik();
			
		});
		*/

    },update_note:function(){
    	//Update notes on key up, calling function dashboard/updatenote
    	var text = 	$('#dashContentTextArea').val();
		var idUsrBubble = $("#noteProviderContainer").attr('rel');
		if(!idUsrBubble){
			idUsrBubble = 0;
		}
    	strUrl = HomeBubble.Paths.BASEWEB + 'member/dashboard/updatenote';
    	
    	$.post(strUrl, {text: text,idUsrBubble: idUsrBubble}, function(data){
    		
    		
    
    	});
    	
    },add_modal_rubrik:function(){
    	
    	strUrl = HomeBubble.Paths.BASEWEB + 'member/dashboard/addmodalrubrik';
			
		$('#addRubrik').load(strUrl , { update: true }, function(){
				
				$('.addRubrikButton').click(function(){
					
					var id = $(this).attr('rel');
					$(id).fadeIn(2000);
					$('#addRubrik').dialog('destroy');
				})
				
			} ).dialog({
					
						bgiframe: true,
						autoOpen: true,
						height: 'auto',
						draggable: true,
						resizable: true,
						width: 400,
						modal: true,
						closeOnEscape: false,
		
						close: function(){
						
							$(this).dialog('destroy');
						}

				});

    },update_pagination_button: function(id, strUrl, numberRow){

    	$.post(strUrl,{ update: true}, function(data){
    		if(data > numberRow){
    			$(id+' .dashPortlet-footer .dashPortlet-footerRight').css("display", "block");
    			
    		}
    		if(data < numberRow || data == numberRow ){
    			$(id+' .dashPortlet-footer .dashPortlet-footerRight').css("display", "none");
    		
    		}

    	});
    	
    }
	
}
HomeBubble.Box.Content.Email = {

	initialize: function () {
					
				var idUsrBubble = $('#provStartEmail').attr('rel');
					strUrl = HomeBubble.Paths.BASEWEB + 'member/provider/view';
					$.post(strUrl, { }, function(){
						
					});
					
					$("#provStartEmail").click(function(){
						var idUsrBubble = $('#provStartEmail').attr('rel');
						HomeBubble.Box.Content.Email.add_modal_email(idUsrBubble);								
					});
					
					$("#modelLetter").change(function(){
						idType = $(this).attr('value');
						strUrl = HomeBubble.Paths.BASEWEB + 'member/provider/gettypemailcontent';
						$.post(strUrl, {idType: idType }, function(data){
						//	alert(data);
							$('#mailBody').text(data);
						});	
   					});
   					$('#mail').click(function(){
   						alert('Envoyer par mail.');
						sender = $('#senderDoc').attr('value');
						receiver = $('#receiverDoc').attr('value');
						object = $('#objectDoc').attr('value');
						title = $('#titleDoc').attr('value');
						model = $('#modelLetter').attr('value');
						content = $('#mailBody').attr('value');
						date = $('#dateDoc').attr('value');
						ref = $('#referenceDoc').attr('value');
						action = $('#actionDoc').attr('value');
							strUrl = HomeBubble.Paths.BASEWEB + 'member/provider/validatemailmodal';
						$.post(strUrl, {sender: sender,receiver:receiver, object:object, title:title, model:model, content:content,date:date, ref:ref, action:action }, function(data){
							
						});
						
						
   					});
   					$('#print').click(function(){
   						alert('Impression.');	
   					});
   					$('#preview').click(function(){
   						alert('previsualiser');	
   					});
					$('#registeredLetter').click(function(){
   						alert('Recommander');	
   					});
				
		}, add_modal_email: function (idUsrBubble){
				var idUsrBubble = $('#provStartEmail').attr('rel');
				
			//alert(idUsrBubble);
				strUrl = HomeBubble.Paths.BASEWEB + 'member/provider/addemailmodal';
				$('#emailcontent').load(strUrl, {update: true, idUsrBubble: idUsrBubble}, function(){

					
							
				}).dialog({
							
								bgiframe: true,
								autoOpen: true,
								height: 'auto',
								draggable: true,
								resizable: true,
								width: 680,
								modal: true,
								closeOnEscape: false,
								buttons: {
											/***  Bouton Valider et ses options  ***/
											"Valider": function() {
											HomeBubble.Box.Content.Email.update_archive('all');		
												$(this).dialog('destroy');
												
										},
												
											/***  Bouton annuler et ses options  ***/		
											"Annuler": function() {
											$(this).dialog('destroy');
											//$('.portlet').fadeIn();
										}
										
									},
								close: function(){
									
									$(this).dialog('destroy');	
								}
						});
		
				return false;
		}
		
}

HomeBubble.Box.Content.Todo = {
	
	initialize: function () {
		
					/** Default loading of archive list **/
					HomeBubble.Box.Content.Todo.update_todo();
					
					// Ajax Pagination feature // check getlistajax for page container (todoPagination)
					$("#todoDisplayAll").click(function(){
						$("#todoDisplayLimit").show();
						$(this).hide();
						HomeBubble.Box.Content.Todo.update_todo('all');									
					});

					$("#todoDisplayLimit").click(function(){
						$("#todoDisplayAll").show();
						$(this).hide();
						HomeBubble.Box.Content.Todo.update_todo();									
					});

					
					
					/*** UI Dialog ***/
					$('#todoAddStart').click(function(){
						$('#addTodo').html('<div class="genLoading"></div>');
						HomeBubble.Box.Content.Todo.add_modal_todo();		
					});
					
					/**line through on page load **/
					
			
				

					

    },update_todo_element:function(id){
    	
		var element = $('.todoElement[rel='+id+']');
		// Load default content of todo
		strUrl = HomeBubble.Paths.BASEWEB + 'member/todo/updatetodoelement';
		
		element.load(strUrl, {id: id }, function(data){
								
							$('.todoValidatedButton').unbind("click").click(function(){
								var validated = $(this).attr('rel');
								var id = $(this).parent().attr('rel');
								HomeBubble.Box.Content.Todo.change_status(id,validated);
							
							});
							
  							//Edit a todo
							$('.todoEditButton').click(function(){

							var idTodo = $(this).attr('rel');	
							$('#editTodo').html('<div class="genLoading"></div>');
							HomeBubble.Box.Content.Todo.edit_modal_todo(idTodo);
							});	
							
							$(this).css('display', 'none');
							$(this).fadeIn();
							
							//Delete Toto
							$('.todoDeleteButton[rel='+id+']').click(function(){
									idTodo = $(this).attr('rel');
									$('#todoArchive').html('<div class="genLoading"></div>');
									HomeBubble.Box.Content.Todo.delete_modal_todo(idTodo);
							});	

							
					});

	},update_todo:function(show){
    	
					// Load default content of todo
					$('#todoContent').slideUp(function(){
							$('#todoContent').html('<div class="genLoadingDashboardList"></div>');
						
				
				
					strUrl = HomeBubble.Paths.BASEWEB + 'member/todo/getlistajax';
					$('#todoContent').load(strUrl, { update: true, show:show  }, function(data){
				
							/** Checked todo list or not **/
							$('.todoValidatedButton').click(function(){
								var validated = $(this).attr('rel');
								var id = $(this).parent().attr('rel');
								HomeBubble.Box.Content.Todo.change_status(id,validated);

							});
							
		   					//Edit a todo
							$('.todoEditButton').click(function(){

							var idTodo = $(this).attr('rel');	
							$('#editTodo').html('<div class="genLoading"></div>');
							HomeBubble.Box.Content.Todo.edit_modal_todo(idTodo);
							});	
							
							$(this).slideDown();
							
								//Update expand list menu
									strUrl = HomeBubble.Paths.BASEWEB + 'member/todo/getnumberajax';
									$.post(strUrl , { update: true} , function(data){
									    //stuff to do *after* page is loaded;
										if(data.menu == 'show'){
											$("#todoNumberElement").html("("+data.total+")");
											$("#todoButtons").show();
										}else{
											$("#todoButtons").hide();						
										}


									}, 'json');
						
						
							
							//Delete Toto
							$('.todoDeleteButton').click(function(){
									idTodo = $(this).attr('rel');
									$('#todoArchive').html('<div class="genLoading"></div>');
									HomeBubble.Box.Content.Todo.delete_modal_todo(idTodo);
							});							
								});
							
					});
  
    },edit_modal_todo:function(idTodo){
    	
    	var nameValidated = true;
    	var dateValidated = true;
    	
    	// Put info form provider in the center of the screen after open 
		 var viewportWidth = $(window).width();  
		 var viewportHeight = $(window).height(); 
		 
		 var middleWidth =  parseInt(viewportWidth/3);
		 var middleHeight =  parseInt(viewportHeight/5);
  		
  		strUrl = HomeBubble.Paths.BASEWEB + 'member/todo/editmodal';
  	
    	$('#editTodo').load(strUrl,{idTodo: idTodo}, function(){

	    	
	    		$.datepicker.setDefaults($.extend({showMonthAfterYear: false}, $.datepicker.regional['fr']));
				$('#editDatepicker').datepicker({
					changeMonth: true,
					changeYear: true
				});
				
			//Validate formula
			$('#editTodoName').blur(function(){
		   
		    	 	if($(this).val()==''){
		    	 		$('#editTodoNameError').css("display","block");
		    	 		nameValidated = false;
		    	 	}
		    	 	if($(this).val()!=''){
		    	 		$('#editTodoNameError').css("display","none");
		    	 		nameValidated = true;
		    	 }
		    	 
	    	  }); 
	    	  
  			$('#editDatepicker').blur(function(){
		   
		    	 	if($(this).val()==''){
		    	 		$('#editTodoDateError').css("display","block");
		    	 		dateValidated = false;
		    	 	}
		    	 	if($(this).val()!=''){
		    	 		$('#editTodoDateError').css("display","none");
		    	 		dateValidated = true;
		    	 }
		    	 
	    	  }); 
	    	  
	    	  $('#editDatepicker').change(function(){
		   
		    	 	if($(this).val()==''){
		    	 		$('#editTodoDateError').css("display","block");
		    	 		dateValidated = false;
		    	 	}
		    	 	if($(this).val()!=''){
		    	 		$('#editTodoDateError').css("display","none");
		    	 		dateValidated = true;
		    	 }
		    	 
	    	  }); 

	

    	}).dialog({
    		
    				bgiframe: true,
    				zIndex : 900,
					autoOpen: true,
					height: 'auto',
					draggable: true,
					resizable: true,
					width: 550,
					modal: true,
					position: [middleWidth,middleHeight],
					closeOnEscape: false,
					buttons: {

							/***  Bouton Valider et ses options  ***/
							"Valider": function() {
							if(nameValidated == true && dateValidated == true){
								HomeBubble.Box.Content.Todo.edit_todo(idTodo);
							}
							else{
								$('#editTodoFormError').css("display","block");
							}
						}, 
						/***  Bouton annuler et ses options  ***/		
						"Annuler": function() {
							$(this).dialog('destroy');
						}

					},
					
					/***  Fonction "close"  ***/
					
					close: function() {
						$(this).dialog('destroy');
						$('.ui-datepicker ').css('display', 'none');
					}

    	});
    
    },edit_todo:function(idTodo){
    	
    	strUrl = HomeBubble.Paths.BASEWEB + 'member/todo/editajax';
    	var todoName = $('#editTodoName').val();
		var date = $('#editDatepicker').val();
		
		// Mettre la date en version aaaa/mm/jj pour l'insÃ©rer dans la DB
		var dateBuffer = date.split("/");
		var date = dateBuffer[2]+'/'+dateBuffer[1]+'/'+dateBuffer[0];

		if(todoName!=''){
		
			$.post(strUrl, { todoName: todoName, date: date, idTodo: idTodo}, function(){
									show = $(".todoList").attr('rel');
						
		   							HomeBubble.Box.Content.Todo.update_todo(show);
	 							  	$('#editTodo').dialog('destroy');
						
			});		
	
		}else{
			
		$('#editTodo').dialog('destroy');	
		}
    },change_status:function(id, validated){
    	
    		strUrl = HomeBubble.Paths.BASEWEB + 'member/todo/changestatus';
    		$.post(strUrl, { id:id, validated:validated},function(data){
   			HomeBubble.Box.Content.Todo.update_todo_element(id);
			


    		});
    	
    },delete_modal_todo:function(idTodo){
	    	// Put info form provider in the center of the screen after open 
			 var viewportWidth = $(window).width();  
			 var viewportHeight = $(window).height(); 
			 
			 var middleWidth =  parseInt(viewportWidth/3);
			 var middleHeight =  parseInt(viewportHeight/5);
    	
			strUrl = HomeBubble.Paths.BASEWEB + 'member/todo/deletemodal';
			$('#deleteTodo').load(strUrl , { idTodo: idTodo } ).dialog({
			
			bgiframe: true,
			autoOpen: true,
			height: 'auto',
			draggable: true,
			resizable: true,
			width: 400,
			modal: true,
			position: [middleWidth,middleHeight],
			closeOnEscape: false,
			buttons: {
						/***  Bouton Valider et ses options  ***/
						
						"Valider": function() {
						HomeBubble.Box.Content.Todo.delete_todo(idTodo);
						$(this).dialog('destroy');
	
					},
							
						/***  Bouton annuler et ses options  ***/	
							
						"Annuler": function() {
						$(this).dialog('destroy');
						//$('.portlet').fadeIn();
					}
					
				},
			close : function(){
				$(this).dialog('destroy');
				
			}
		});
		
			return false;

    },delete_todo:function(idTodo){
    	
    	strUrl = HomeBubble.Paths.BASEWEB + 'member/todo/deleteajax/';
    	$.post(strUrl, { idTodo: idTodo }, function(data){
				if(data == 'deleted' ){		  
				show = 'limit';
				show = $(".todoList").attr('rel');
						
			   	HomeBubble.Box.Content.Todo.update_todo(show);
			  	$('#deleteTodo').dialog('destroy');
			  	$('#todoContent').fadeOut('500', function(){
			  		
			  		$('#todoContent').fadeIn('500');	
			  	});

			  }
    		
    		
    		
    	})
    	
    	
    },delete_modal_todo_behaviour:function(){
    	
    	
    	
    	
    },add_modal_todo:function(){
    	
   		var nameValidated = false;
    	var dateValidated = false;
    	
		// Put info form provider in the center of the screen after open 
		 var viewportWidth = $(window).width();  
		 var viewportHeight = $(window).height(); 
		 
		 var middleWidth =  parseInt(viewportWidth/3);
		 var middleHeight =  parseInt(viewportHeight/5);
    	
    	$('#addTodo').load(HomeBubble.Paths.BASEWEB + 'member/todo/addmodal',{update:true}, function(){

	    	
   				$.datepicker.setDefaults($.extend({showMonthAfterYear: false}, $.datepicker.regional['fr']));
				$('#addDatepicker').datepicker({
					changeMonth: true,
					changeYear: true
				});
				
				//Validate formula
			$('#addTodoName').blur(function(){
		   
		    	 	if($(this).val()==''){
		    	 		$('#addTodoNameError').slideDown();
		    	 		nameValidated = false;
		    	 	}
		    	 	if($(this).val()!=''){
		    	 		$('#addTodoNameError').slideUp();
		    	 		nameValidated = true;
		    	 }
		    	 
	    	  }); 
	    	  
  			$('#addDatepicker').blur(function(){
		   
		    	 	if($(this).val()==''){
		    	 		$('#addTodoDateError').slideDown();
		    	 		dateValidated = false;
		    	 	}
		    	 	if($(this).val()!=''){
		    	 		$('#addTodoDateError').slideUp();
		    	 		dateValidated = true;
		    	 }
		    	 
	    	  }); 
	    	  
	    	  $('#addDatepicker').change(function(){
		   
		    	 	if($(this).val()==''){
		    	 		$('#addTodoDateError').slideDown();
		    	 		dateValidated = false;
		    	 	}
		    	 	if($(this).val()!=''){
		    	 		$('#addTodoDateError').slideUp();
		    	 		dateValidated = true;
		    	 }
		    	 
	    	  }); 

			

    	}).dialog({
    		
    				bgiframe: true,
    				zIndex : 900,
					autoOpen: true,
					height: 'auto',
					draggable: true,
					resizable: true,
					width: 550,
					modal: true,
					position: [middleWidth,middleHeight],
					closeOnEscape: false,
					buttons: {

							/***  Bouton Valider et ses options  ***/
							"Valider": function() {
							if(nameValidated == true && dateValidated == true){
								HomeBubble.Box.Content.Todo.add_todo();
							}
							else {
								if($('#addTodoName').attr("value")==""){
									$('#addTodoNameError').slideDown();
								}
								if($('#addDatepicker').attr("value")==""){
									$('#addTodoDateError').slideDown();
								}
							}

						},
						/***  Bouton annuler et ses options  ***/		
						"Annuler": function() {
							$(this).dialog('destroy');
						}
					},
					
					/***  Fonction "close"  ***/
					
					close: function() {
						$(this).dialog('destroy');
						$('#ui-datepicker-div ').css('display', 'none');
					}

    	});
    	
    	
    	
    },add_todo:function(){
    	
    	strUrl = HomeBubble.Paths.BASEWEB + 'member/todo/addajax';
    	var todo = $('#addTodoName').val();
		var date = $('#addDatepicker').val();

		// Mettre la date en version aaaa/mm/jj pour l'insÃ©rer dans la DB
		var dateBuffer = date.split("/");
		var date = dateBuffer[2]+'/'+dateBuffer[1]+'/'+dateBuffer[0];

		$.post(strUrl, { todo: todo, date: date}, function(){
							show = 'limit';
							show = $(".todoList").attr('rel');
   							HomeBubble.Box.Content.Todo.update_todo(show);
						  	$('#addTodo').dialog('destroy');
						
		});	
    	
    	
    	
    }

    	
}
HomeBubble.Box.Content.Button = {
	initialize: function () {
		
				$("#bubbleAdd").click(function(){
									
					idBubble =  $(this).attr('rel');
					HomeBubble.Box.Content.Bubble.add_bubble_theme(idBubble);
					//return false;
				});
				
	
		$(".genContentButton").mouseover(function(){
			
			button = $(this).attr('rel');
			label =  '#buttonLabel'+ button;
			buttonHover = 'genMemberButton'+button+'Hover';
			
			// Hiding current page button
			currentBubble = $("#genContentButtonContainer").attr('rel');
			currentToHide =  ".genMemberButton"+currentBubble;
			currentToHideClass =  "genMemberButton"+currentBubble;
			currentToHideHoverClass = "genMemberButton" + 'Hover';
			
			//Hiding current page label
			currentLabel = "#buttonLabel"+currentBubble;
			$(currentLabel).css('display','none');
			
			// If the button mouseover another button
			if(button != currentBubble){
				$(currentToHide).removeClass().addClass(currentToHideClass);
			}
			
			// If the button mouseover is the current button page
			if(button == currentBubble){
				hoverTheCurrent = "genMemberButton"+currentBubble +"Hover";
				$(currentToHide).addClass(hoverTheCurrent);
			}
			
			// Add the hover image button		
			$(".memberBubble",this).addClass(buttonHover);
			
			// Slide down current label
			$(label).css('display','inline');
						
		});
		
		// On mouseout behaviour		
		$(".genContentButton").mouseout(function(){
			
			button = $(this).attr('rel');
			label =  '#buttonLabel'+ button;
			buttonHover = 'genMemberButton'+button+'Hover';
			
			$( ".memberBubble",this).removeClass(buttonHover);
			$(label).css('display','none');			
		});

		
		// When leaves the menu system
		$("#genContentButtonContainer").mouseleave(function(){			
			currentButton = $(this).attr('rel');
			
			currentLink = ".genMemberButton"+currentButton;
			
			// Add hover to the current button
			hoverTheCurrent = "genMemberButton"+currentButton +"Hover";
			$(currentLink,this).addClass(hoverTheCurrent);
			
			// Display current label
			currentLabel = "#buttonLabel"+currentButton;
			$(currentLabel).css('display','inline');
				

		});
	
	/*	
		$(".genContentButtonContainer").mouseover(function(){
			
			currentButton = $(this).attr('rel');
			$(this).unbind('mouseleave');
		//	alert(currentButton);
			
			
			//$("input[rel='newsletter']").	

			

			
		});
		
			
		$(".genContentButtonContainer").mouseout(function(){
			
			currentButton = $(this).attr('rel');
			$(this).bind('mouseleave');
		//	alert(currentButton);
			
			
			//$("input[rel='newsletter']").	

			

			
		});
		*/
	
	
	}
    
}

HomeBubble.Box.Content.Paper = {
	initialize: function () {

		show = 'limit';
		HomeBubble.Box.Content.Paper.update_paper(show);
		
		// Ajax Pagination feature // check getlistajax for page container (todoPagination)
		$("#paperDisplayAll").click(function(){
			$("#paperDisplayLimit").show();
			$(this).hide();
			HomeBubble.Box.Content.Paper.update_paper('all');									
		});
					
		$("#paperDisplayLimit").click(function(){
			$("#paperDisplayAll").show();
			$(this).hide();
			HomeBubble.Box.Content.Paper.update_paper();									
		});
		
		//Add a paper
		$('#paperAddStart').click(function(){
				$('#addPaper').html('<div class="genLoading"></div>');
				HomeBubble.Box.Content.Paper.add_modal_paper();
		});	
	
    },update_paper:function(show){
    			
					$('#paperContent').slideUp(function(){
					$('#paperContent').html('<div class="genLoadingDashboardList"></div>');
				

	
					strUrl = HomeBubble.Paths.BASEWEB + 'member/paper/getlistajax';
					
					$('#paperContent').load(strUrl, { update: true, show: show },function(data){
									
						$(this).slideDown();
						
						//Update expand list menu
							strUrl = HomeBubble.Paths.BASEWEB + 'member/paper/getnumberajax';
							$.post(strUrl , { update: true } , function(data){
									//	alert(show);
							    //stuff to do *after* page is loaded;
								//alert(data.menu);
								if(data.menu == 'show'){
									$("#paperNumberElement").html("("+data.total+")");	
									$("#paperButtons").show();
								}else{
									$("#paperButtons").hide();						
								}


							}, 'json');
						
					   		//Edit a paper
							$('.paperEditButton').click(function(){
								var idPaper = $(this).attr('rel');	
								$('#editPaper').html('<div class="genLoading"></div>');
								HomeBubble.Box.Content.Paper.edit_modal_paper(idPaper);
							});	
					
							//Delete Paper
							$('.paperDeleteButton').click(function(){
								idPaper = $(this).attr('rel');
								$('#deletePaper').html('<div class="genLoading"></div>');
								HomeBubble.Box.Content.Paper.delete_modal_paper(idPaper);
							});	
							
							//Send Paper
							$('.paperEmailButton').click(function(){
								idPaper = $(this).attr('rel');
								HomeBubble.Box.Content.Paper.send_modal_paper(idPaper);
							});
						
						});
		
					});

    },send_modal_paper:function(idPaper){
		strUrl = HomeBubble.Paths.BASEWEB + 'member/paper/sendmodal';
		$('#sendModalPaper').load(strUrl, {idPaper: idPaper}, function(data){
			
		}).dialog({

							bgiframe: true,
							autoOpen: true,
							height: 'auto',
							draggable: true,
							resizable: true,
							width: 500,
							modal: true,
							closeOnEscape: false,
							buttons: {
										/***  Bouton Valider et ses options  ***/
										"Valider": function() {
											HomeBubble.Box.Content.Paper.send_paper(idPaper);
												
										},

										/***  Bouton annuler et ses options  ***/		
										"Annuler": function() {
										$(this).dialog('destroy');
										//$('.portlet').fadeIn();
									}

								},
							close:function(){
									$(this).dialog('destroy');

							}
					});
	
	
	
	},send_paper:function(idPaper){
		
		var paperFolder = $('#paperFolder').attr('value');
		var usrFolder = $('#usrFolder').attr('value');
		var filename = $('#filename').attr('value');
		
		var lastname = $('#sendArchiveName').attr('value');
		var firstname = $('#sendArchiveNickName').attr('value');
		var emailUsr = $('#sendArchiveEmail').attr('value');
		var message = $('#sendArchiveMessage').attr('value');
		var email1 = $('#sendArchiveEmail1').attr('value');
		var email2 = $('#sendArchiveEmail2').attr('value');
		var email3 = $('#sendArchiveEmail3').attr('value');
		var email = '';

    	arrEmail = new Array( );
    	arrEmail[0]= email1;
		arrEmail[1]= email2;
		arrEmail[2]= email3;
		
		var emailValidated = true;
    	var email1Validated = true;
    	var email2Validated = true;
    	var email3Validated = true;

		if(emailUsr != ""){
	    	if(HomeBubble.Box.Content.SignIn.checkEmail(emailUsr) == false){
	    		$('#sendArchiveEmailError').slideDown();
	    		emailValidated = false;

	    	}

	    	if(HomeBubble.Box.Content.SignIn.checkEmail(emailUsr) == true){
	    		$('#sendArchiveEmailError').slideUp();
	    		emailValidated = true;

	    	}
    	}else if(emailUsr == ""){
			$('#sendArchiveEmailError').slideDown();
    		emailValidated = false;

		}

		if(email1 != ""){
    		if(HomeBubble.Box.Content.SignIn.checkEmail(email1)== true){
    			$('#sendArchiveEmailError1').slideUp();
    			email1Validated = true;
    		}
    		  if(HomeBubble.Box.Content.SignIn.checkEmail(email1)== false){
    			$('#sendArchiveEmailError1').slideDown();
    			email1Validated = false;
    		}
    	}else if(email1 == ""){
			$('#sendArchiveEmailError1').slideDown();
			email1Validated = false;
		}

    	if(email2 != ""){
    		if(HomeBubble.Box.Content.SignIn.checkEmail(email2)== true){
    			$('#sendArchiveEmailError2').slideUp();
    			email2Validated = true;
    		}
    		  if(HomeBubble.Box.Content.SignIn.checkEmail(email2)== false){
    			$('#sendArchiveEmailError2').slideDown();
    			email2Validated = false;
    		}
    	}

    	if(email3 != ""){
    		if(HomeBubble.Box.Content.SignIn.checkEmail(email3)== true){
    			$('#sendArchiveEmailError3').slideUp();
    			email3Validated = true;
    		}
    		  if(HomeBubble.Box.Content.SignIn.checkEmail(email3)== false){
    			$('#sendArchiveEmailError3').slideDown();
    			email3Validated = false;
    		}
    	}

		if(email2 == ""){
    		$('#sendArchiveEmailError2').slideUp();
    		email2Validated = true
    	}

		if(email3 == ""){
    		$('#sendArchiveEmailError3').slideUp();
    		email3Validated = true;
    	}

		if(email1Validated == true && email2Validated == true && email3Validated == true && emailValidated == true){
			
			strUrl = HomeBubble.Paths.BASEWEB + 'member/paper/sendpaper';
			
			$.post(strUrl,{paperFolder: paperFolder, usrFolder: usrFolder, filename: filename, idPaper: idPaper, 'arrEmail[]': arrEmail, firstname: firstname, lastname: lastname, emailUsr: emailUsr, message: message}, function(data){
				if(data == 'sent'){
					$('#sendModalPaper').dialog('destroy');
				}
				else{
					$("#sendArchiveFailed").slideDown();
				}
			});
			
		}
		
		
		
	},edit_modal_paper:function(idPaper, profile){
		
		var nameValidated = true;
			
    	strUrl = HomeBubble.Paths.BASEWEB + 'member/paper/editmodal';
		$('#editPaper').load(strUrl, {update: true, idPaper: idPaper}, function(){
			
			//Validate formula
			$('#fileTitle').blur(function(){
		   
		    	 	if($(this).val()==''){
		    	 		$('#fileTitleError').slideDown();
		    	 		nameValidated = false;
		    	 	}
		    	 	if($(this).val()!=''){
		    	 		$('#fileTitleError').slideUp();
		    	 		nameValidated = true;
		    	 }
		    	 
	    	  });

		}).dialog({
							
								bgiframe: true,
								autoOpen: true,
								height: 'auto',
								draggable: true,
								resizable: true,
								width: 500,
								modal: true,
								closeOnEscape: false,
								buttons: {
											/***  Bouton Valider et ses options  ***/
											"Valider": function() {
												if(nameValidated == true){
												HomeBubble.Box.Content.Paper.edit_paper(idPaper, profile);
												$(this).dialog('destroy');
												}
												else{
													if($('#editPaperTitle').attr("value")==""){
														$('#editPaperTitleError').slideDown();
													}
												}	
											},
											/***  Bouton annuler et ses options  ***/		
											"Annuler": function() {
												$(this).dialog('destroy');
												//$('.portlet').fadeIn();
											}
									},
								close: function(){
									$(this).dialog('destroy');
								}
						});
				return false;

    	
    },edit_paper:function(idPaper, profile){

    	var title = $('#fileTitle').val();
    	
    	strUrl =  HomeBubble.Paths.BASEWEB + 'member/paper/editajax';
    	
    	$.post(strUrl, { title: title,  idPaper: idPaper}, function(){
    			show = $(".paperList").attr('rel');
    			HomeBubble.Box.Content.Paper.update_paper(show);
				
				if(profile == 1){
										
					$('.profilePaperUsrBubbleFileName[rel='+idPaper+']').html(title);
																
				}		
    		
    	});
    	
    	
    },add_modal_paper:function(profile){
    	
		var field1 = false;
		var field2 = false;
		var field3 = false;
		var field4 = false;
		var field5 = false;
			
    	strUrl = HomeBubble.Paths.BASEWEB + 'member/paper/addmodal';
		$('#addPaper').load(strUrl, {update: true}, function(){
			/*
 	 		$('#addPaperTitle').blur(function(){
	   
	    	 	if($(this).val()==''){
	    	 		$('#addPaperTitleError').slideDown();
	    	 		nameValidated = false;
	    	 	}
	    	 	if($(this).val()!=''){
	    	 		$('#addPaperTitleError').slideUp();
	    	 		nameValidated = true;
	    	 }
	    	 
    	  }); 
    	  
	 		$('#addPaperFile').blur(function(){
	   
	    	 	if($(this).val()==''){
	    	 		$('#addPaperFileError').slideDown();
	    	 		fileValidated = false;
	    	 	}
	    	 	if($(this).val()!=''){
	    	 		$('#addPaperFileError').slideUp();
	    	 		fileValidated = true;
	    	 }
	    	 
    	  }); 
    	  */
		function getStats(fName){

		fullName = fName;
		shortName = fullName.match(/[^\/\\]+$/);
		return shortName;
		}
		


    	  $('.addFile').change(function(){
				idFile = $(this).attr('rel');
			    filename =	$(this).val();				
				shortname = getStats(filename);

				$("#fileTitle"+idFile).attr('value', shortname  );
				/*
					strUrl = HomeBubble.Paths.BASEWEB + 'member/paper/cleanname';
					$.post( strUrl , { filename : filename }, function(data){
							$("#fileTitle"+idFile).attr('value', data.result  );
						//	alert (data.result);
						//	$("#uploaded"+idFile).attr('value', ''  );
						//	$("#fileWaitUploadResult"+idFile).fadeOut();
					}, 'json');
					*/
    	  }); 
			
			
		}).dialog({
							
								bgiframe: true,
								autoOpen: true,
								draggable: true,
								resizable: true,
								width: 680,
								height: 'auto',
								modal: true,
								closeOnEscape: false,
								buttons: {

											/***  Bouton Valider et ses options  ***/
											"Valider": function() {

											
											valNoEmpty1 = "true";
											valNoEmpty2 = "true";
											valNoEmpty3 = "true";
											valNoEmpty4 = "true";
											valNoEmpty5 = "true";
											
											if( $('#addFile1').val() != '' ){
												
												if( $('#fileTitle1').val() == '' ){
													$('#fileTitleError1').slideDown();
													valNoEmpty1 = "false";
												}
											//	$("#progressbar").progressbar({ value: 0 });
											}

											
											if( $('#addFile2').val() != '' ){
													if( $('#fileTitle2').val() == '' ){
														$('#fileTitleError2').slideDown();
														valNoEmpty2 = "false";
													}

												}
												
											if( $('#addFile3').val() != '' ){
													if( $('#fileTitle3').val() == '' ){
														$('#fileTitleError3').slideDown();
														valNoEmpty2 = "false";
													}
											}


											if( $('#addFile4').val() != '' ){
													if( $('#fileTitle4').val() == '' ){
														$('#fileTitleError4').slideDown();
														valNoEmpty2 = "false";
													}

												}
												
											if( $('#addFile5').val() != '' ){
													if( $('#fileTitle5').val() == '' ){
														$('#fileTitleError5').slideDown();
														valNoEmpty2 = "false";
													}
											}
								
											if( valNoEmpty1 == "true" && valNoEmpty2 == "true" && valNoEmpty3 == "true" && valNoEmpty4 == "true" && valNoEmpty5 == "true"){
											
											for ( i = 1 ; i < 6 ; i++ ) {
												
												if(  $('#addFile'+i).val() != ''  ){
												
													// Alimenter tableau pour la verification cyclique des Ã©lÃ©ments postÃ©s 
													if($("#uploaded"+i).attr('value') == ''){
														
														
														
														currentValue = $('#docsToBeUploaded').attr('value');
														newValue = parseInt(currentValue) + parseInt(1);
														$('#docsToBeUploaded').attr('value', newValue);
														
									
															$('#fileTitleError'+i).slideUp();
															$("#fileWaitUpload"+i).slideDown();
															HomeBubble.Box.Content.Paper.add_paper(i, profile);
												}
													
												}else{
													
													$("#fileAddEmpty"+i).slideDown(function(){
														$(this).oneTime('3s', function(){
															$(this).slideUp();
														});
													});
													
												}
											}
											
											}

										},
										/***  Bouton annuler et ses options  ***/		
										"Annuler": function() {
											$(this).dialog('destroy');
											//$('.portlet').fadeIn();
										}
									},
								close: function(){
									$(this).dialog('destroy');
								}
						});
				return false;  	
    	
    },add_paper:function(idForm, profile){
    			$("#fileUploadError"+idForm).html("");
				$("#fileUploadError"+idForm).slideUp();
    			$( "#fileWaitUpload" + idForm ).fadeIn();

				
			/*	function updateProgress() {
						strUrl =  HomeBubble.Paths.BASEWEB + 'member/paper/getfilesize';
					
						$.post(strUrl,{update:true},function(data){
							alert(data.tmp_name_size);
							setTimeout(updateProgress, 5);
						//	$("#progressbar").progressbar({ value: 0 });
						},'json');
					 /* var progress;
					  progress = $("#progressbar").progressbar("option","value");
					  if (progress < 100) {
					      $("#progressbar").progressbar("option", "value", progress + 1);
					      setTimeout(updateProgress, 5);
						  return false;
					  }else if(progress == 100){
						return true;
					}*/
			//	}

  				strUrl =  HomeBubble.Paths.BASEWEB + 'member/paper/uploadtempajax';
	    	//	alert(strUrl);
				var options = { 
		        url:        strUrl,  // target element(s) to be updated with server response 
		        //beforeSubmit:  showRequest,  // pre-submit callback 
				//beforeSend: function(data){	var upload_state = updateProgress();},
				dataType: 'json',
		        success:  function(data){
						$("#paperWaitContainer").fadeOut();

							if(data.result == true){
		
									$("#fileWaitUpload"+idForm ).fadeOut(function(){
										$("#fileWaitUploadResult"+idForm).fadeIn();
									});
								
									uploadField = "#uploaded"+idForm;
								
									$( uploadField ).attr("value", "ok");
							
									show = 'limit';
									show = $(".paperList").attr('rel');
									//$("#fileUploadError"+idForm).slideUp();
									// Affichage du message pour le tÃ©lÃ©chargement d'un Ã©lÃ©ment
									// Vidage des Ã©lÃ©ments inputs du formulaire
								
									currentValue = $('#docsToBeUploaded').attr('value');
									newValue = parseInt(currentValue) - parseInt(1);
									$("#docsToBeUploaded").attr( 'value' , newValue );						
									countDocUploaded = $('#docsToBeUploaded').attr('value');								
								
									if(countDocUploaded == 0){
									
										$(this).oneTime('1s', function(){
											$('#addPaper').dialog('destroy');
											if(profile = 1) {
												strUrl = HomeBubble.Paths.BASEWEB + 'member/profile/paperajax';
												$('.profileArchUsrBubbleFileNameHidden[rel=0]').load(strUrl, {update:true}, function(data){
													
													
													//Delete archive
													$('.profilePaperDeleteButton').click(function(){
															idPaper = $(this).attr('rel');

															$('#deletePaper').html('<div class="genLoading"></div>');
															var profile = 1;
															HomeBubble.Box.Content.Paper.delete_modal_paper(idPaper, profile);

													});	

													//Edit a paper
													$('.profilePaperEditButton').click(function(){

														var idPaper = $(this).attr('rel');	
														$('#editPaper').html('<div class="genLoading"></div>');
														var profile = 1;
														HomeBubble.Box.Content.Paper.edit_modal_paper(idPaper, profile);
													});
													
													strUrl = HomeBubble.Paths.BASEWEB + 'member/profile/countpaperajax';
													$.post(strUrl, {update:true}, function(data){
														$('.profileNumberPaper').html(data);
														if(parseInt(data) >= 1){
														//	$('#paperListIcon').attr("src", "/images/front/gui/icons/bullet_toggle_plus.png")
														//	$(".profileArchUsrBubbleFileNameHidden[rel=0]").css("border-left", "1px solid #C3C3C3");
															$('#paperListIcon').html('<img align="left" src="/images/front/gui/icons/bullet_toggle_plus.png">');
														}
														else if(parseInt(data) < 1){
															//$('#paperListIcon').attr("src", "/images/front/gui/bkg/spacer.gif")
															$('#paperListIcon').html('<img align="left" width="16" height="16" src="/images/front/gui/bkg/spacer.gif">')
														}
													})
												})
											}
											HomeBubble.Box.Content.Paper.update_paper(show);	

										});
									 	//alert('destroy');
									}
								}else if(data.result == false){
									$('#fileWaitUpload'+idForm).fadeOut(function(){
										$("#fileUploadError"+idForm).html(data.message);
										$("#fileUploadError"+idForm).fadeIn();											
									});

								}

						}  
				}
				
				$("#paperForm"+idForm).ajaxSubmit(options);
		    	

    },delete_modal_paper:function(idPaper, profile){
    	

			strUrl = HomeBubble.Paths.BASEWEB + 'member/paper/deletemodal';
			$('#deletePaper').load(strUrl , { idPaper: idPaper } ).dialog({
			
			bgiframe: true,
			autoOpen: true,
			height: 'auto',
			draggable: true,
			resizable: true,
			width: 400,
			modal: true,
			closeOnEscape: false,
			buttons: {
						/***  Bouton Valider et ses options  ***/
						
						"Valider": function() {
						HomeBubble.Box.Content.Paper.delete_paper(idPaper, profile);
						$(this).dialog('destroy');
	
					},
							
						/***  Bouton annuler et ses options  ***/	
							
						"Annuler": function() {
						$(this).dialog('destroy');
						//$('.portlet').fadeIn();
					}
					
				},
			close : function(){
				$(this).dialog('destroy');
				
			}
		});
		
			return false;
    
    },delete_paper:function(idPaper, profile){
    	
    	strUrl = HomeBubble.Paths.BASEWEB + 'member/paper/deleteajax/';
    	$.post(strUrl, { idPaper: idPaper }, function(data){
				if(data == 'deleted' ){	
					
	 			if(profile == 1){
						
					$('.profilePaperUsrBubbleFileName[rel='+idPaper+']').slideUp();
					$('.profilePaperEditButton[rel='+idPaper+']').slideUp();
					$('.profilePaperDeleteButton[rel='+idPaper+']').slideUp();
					
				
					strUrl = HomeBubble.Paths.BASEWEB + 'member/profile/paperajax';
					$('.profileArchUsrBubbleFileNameHidden[rel=0]').load(strUrl, {update:true}, function(data){
						
						
						//Delete archive
						$('.profilePaperDeleteButton').click(function(){
								idPaper = $(this).attr('rel');

								$('#deletePaper').html('<div class="genLoading"></div>');
								var profile = 1;
								HomeBubble.Box.Content.Paper.delete_modal_paper(idPaper, profile);

						});	

						//Edit a paper
						$('.profilePaperEditButton').click(function(){

							var idPaper = $(this).attr('rel');	
							$('#editPaper').html('<div class="genLoading"></div>');
							var profile = 1;
							HomeBubble.Box.Content.Paper.edit_modal_paper(idPaper, profile);
						});
						
						strUrl = HomeBubble.Paths.BASEWEB + 'member/profile/countpaperajax';
						$.post(strUrl, {update:true}, function(data){
							$('.profileNumberPaper').html(data);
						/*	if(parseInt(data) >= 1){
								$('#paperListIcon').attr("src", "/images/front/gui/icons/bullet_toggle_plus.png")
							//	$('#paperListIcon').html('<img align="left" src="/images/front/gui/icons/bullet_toggle_plus.png">');
							}*/
						 	if(parseInt(data) < 1){
								//$('#paperListIcon').attr("src", "/images/front/gui/bkg/spacer.gif");
								//$(".profileArchUsrBubbleFileNameHidden[rel=0]").css("border-left", "0");
								$('#paperListIcon').html('<img align="left" width="16" height="16" src="/images/front/gui/bkg/spacer.gif">')
							}
						})
					})
					
					
				}
				show = $(".paperList").attr('rel');
			   	HomeBubble.Box.Content.Paper.update_paper(show);
			  	$('#deletePaper').dialog('destroy');
			  	$('#paperContent').fadeOut('500', function(){
			  		
			  		$('#paperContent').fadeIn('500');	
			  	});

			  }

    	})
	
    }
}

HomeBubble.Box.Content.Calendar = {

	initialize: function () {
	
		$("#synCal").click(function(){
			HomeBubble.Box.Content.Calendar.show_ical_modal();
			
			
			
			
			
		});
	

	HomeBubble.Box.Content.Calendar.calendarOnload();

		$('.dashPortletIconAgenda').click(function(){
			//HomeBubble.Box.Content.Event.update_event();
			$('#dashContentCalendar').css("display", "none");
			$('#dashContentEvent').css("display", "block");
			
			$('#dashFooterEvent').css("display", "block");
			$('#dashFooterCalendar').css("display", "none");
			//HomeBubble.Box.Content.Event.update_event(1,1);

		});
		
		$('.dashPortletIconCalendar').click(function(){
						
			$('#dashContentEvent').css("display", "none");
			$('#dashContentCalendar').css("display", "block");
	
			$('#dashFooterCalendar').css("display", "block");	
			$('#dashFooterEvent').css("display", "none");
			
			});		
		
	
	
	//	$("a:contains('sdfsdfs') .ui-state-default").
		
		
	
		/*** Datepicker inline ***/
	/*	strUrl = HomeBubble.Paths.BASEWEB + 'member/calendar/index';
		
		$("#dashContentCalendar").load(strUrl, { update: true}, function(){
			
		
		});
	*/
    },
	calendarOnload:function(){
		//$('#dashContentCalendar').html('<div class="genLoadingBig"></div>');
		$('#eventLoaderForCalendar').fadeIn();
			$(window).load(function(){

				// On prend le mois en cours
				var date = new Date();
				var currentMonth = date.getMonth()+1;
				var currentYear = date.getFullYear();
				
				// $.post --> recuperation de Ã©vÃ¨nements --> return data
				strUrl = HomeBubble.Paths.BASEWEB + 'member/calendar/loadevent';
				$.post(strUrl,{month: currentMonth, year: currentYear}, function(data){
					
					var dataBuffer = data.split(",");
				//	alert(dataBuffer.length);
					dates = new Array(); 
					for (var i=0; i<dataBuffer.length;i++){
							
							dates[i] = dataBuffer[i];
					}
					
					//alert(dates);
				//	$.datepicker.haystack[i] = dates ;
					url = HomeBubble.Paths.BASEWEB + 'member/calendar/showcalendar';
					$('#dashContentCalendar').load(url,{update: true}, function(){
						$('#eventLoaderForCalendar').fadeOut();
						$("#datepickerCalendar").datepicker( {
						//	haystack = data,
							changeMonth: true,
							changeYear: true,
							onChangeMonthYear: function(year, month, inst){						
												
								HomeBubble.Box.Content.Calendar.getEventDayHighlighted(year, month);
								
							},
							onSelect: function(dateText){
								var dateBuffer = dateText.split("/");
								var date = dateBuffer[2]+'/'+dateBuffer[1]+'/'+dateBuffer[0];
								//$('#showEvent').attr("title", "EvÃ¨nements du "+dateText+"");
								HomeBubble.Box.Content.Calendar.show_modal_event(date);
								$('#infoTip').css("display", "none");
	
							/*	var dateBuffer = dateText.split("/");
								var date = dateBuffer[2]+'/'+dateBuffer[1]+'/'+dateBuffer[0];
								alert(date);
								strUrl = HomeBubble.Paths.BASEWEB + 'member/calendar/calendarinformation';
								$('#dashCalendarInformations').css("display","block");
								$('#dashCalendarInformations').load(strUrl,{date: date }, function(){
									$('#dashContentCalendar').blur(function(){
										
										$('#dashCalendarInformations').css("display","none");
									});
									
								});*/
							},
							beforeShow: function(input) { 
								
								
							}

				
						});
						
					});			
				});
		});
		
	}
	,
    getEventDayHighlighted: function(year, month){
    	
    		// On prend le mois en cours
			//	var date = new Date();
			//	var currentMonth = date.getMonth()+1;
			
			var dayNumber =null;
			//	var currentYear = date.getFullYear();
				
				// $.post --> recuperation de Ã©vÃ¨nements --> return data
				strUrl = HomeBubble.Paths.BASEWEB + 'member/calendar/loadevent';
				$.post(strUrl,{year: year, month: month}, function(data){
			
					var dataBuffer = data.split(",");
				//	alert(dataBuffer.length);
					dates = new Array(); 
					for (var i=0; i<dataBuffer.length;i++){
							
							dates[i] = dataBuffer[i];
					}
    	
    				for (var i=0; i<dataBuffer.length;i++){
							
							//$(".ui-state-default[rel='"+dataBuffer[i]+"']").css('background-image','url(../../../images/front/gui/bkg/member/calendarDayBackgroundHighlighted.png)');
							$(".ui-state-default[rel='"+dataBuffer[i]+"']").css('color','#0091B5');
							$(".ui-state-default[rel='"+dataBuffer[i]+"']").css('font-weight','bold');
							// add class
							$(".ui-state-default[rel='"+dataBuffer[i]+"']").addClass('getMoreInfoCalendarTip');
					//		$(".ui-state-default[rel='"+dataBuffer[i]+"']").append('<div class="tetsme"></div>');
							
							$(".ui-state-default[rel='"+dataBuffer[i]+"']").attr('href','');
	
					}
					
				
				
				
				
					
			$(".getMoreInfoCalendarTip").ezpz_tooltip({ 
				contentId: "infoTip",
				contentPosition: 'rightStatic',
				offset:0,
				beforeShow: function(content){				
				}
				
			});
					
			$(".getMoreInfoCalendarTip").parent().mouseover(function(){
				$("#infoTip").html('');
				$('#infoTip').html('<div class="genLoading"></div>');
				dayNumber = $(this).attr('rel');
				strUrl2 = HomeBubble.Paths.BASEWEB + 'member/calendar/getinfotip';
				date = year+'-'+month+'-'+dayNumber;
				$('#infoTip').load(strUrl2,{ date: date});
				
			});
/*

				$(".getMoreInfoCalendarTip").tooltip({ 
					bodyHandler: function(){				
					
					return $('#infoTip').html();
					},
					track:false,
					opacity:1,
					delay:1000,
					fade: 250
				});

	*/
	
			
					/*
					$(".getMoreInfoCalendarTip").tooltip({ 
												
						    // each trashcan image works as a trigger 
						    tip: '#infoTip', 
						    // custom positioning 
					//	    position: ['top', 'center'], 
						    // move tooltip a little bit to the right 
					//	    offset: [50, 20], 
						    // use a simple show/hide effect 
						    effect: 'slideup', 
						    // there is no delay when the mouse is moved out of the trigger 
						    delay:0 ,
						   	slideOffset: 30 ,
	    					
						    onBeforeShow:function(){
						  
							
						    }
						});
						*/
				});
					
    },calendarReload: function(yearBuffer, monthBuffer){
    				$('#dashContentCalendar').html('<div class="genLoadingBigForCalendar"></div>');
					url = HomeBubble.Paths.BASEWEB + 'member/calendar/showcalendar';
					$('#dashContentCalendar').load(url,{update: true}, function(){
						
						$("#datepickerCalendar").datepicker( {
							changeMonth: true,
							changeYear: true,
							onChangeMonthYear: function(yearBuffer, monthBuffer){						
								HomeBubble.Box.Content.Calendar.getEventDayHighlighted(yearBuffer, monthBuffer);
							},
							onSelect: function(dateText){
								var dateBuffer = dateText.split("/");
								var date = dateBuffer[2]+'/'+dateBuffer[1]+'/'+dateBuffer[0];
	
								HomeBubble.Box.Content.Calendar.show_modal_event(date);
								$('#infoTip').css("display", "none");
	
							}
						
						});

						//	$("#datepickerCalendar").datepicker('setDate', new Date(monthBuffer+'/01/'+yearBuffer));		
					});	
					
					

    },show_modal_event:function(date){

    	$('#eventModal').html('<div class="genLoading"></div>');
    	var dateBuffer = date.split("/");
    	dateFr = dateBuffer[2]+'/'+dateBuffer[1]+'/'+dateBuffer[0];
  
		// Put info form provider in the center of the screen after open 
		 var viewportWidth = $(window).width();  
		 var viewportHeight = $(window).height(); 
		 
		 var middleWidth =  parseInt(viewportWidth/3);
		 var middleHeight =  parseInt(viewportHeight/5);
    	
    	HomeBubble.Box.Content.Calendar.calendarReload(dateBuffer[0], dateBuffer[1]);
    	
    	strUrl = HomeBubble.Paths.BASEWEB + 'member/calendar/calendarinformation';
    	$('#eventModal').attr("title", "EvÃ¨nement(s) du "+dateFr+"");
		$('#eventModal').load(strUrl, {update: true, date: date}, function(){
		var dateBuffer = date.split("/");

		}).dialog({
			modal: true,
			position: [middleWidth,middleHeight],
			height: 'auto',
			width: 360,
			close: function(){
				$(this).dialog('destroy');
				$('#ui-datepicker-div ').css('display', 'none');
						},
			buttons:{
				"Ajouter": function(){
					$(this).dialog('destroy');					
					HomeBubble.Box.Content.Event.add_modal_event('eventAddStartCalendar', date);
									
				},				
				"Retour":function(){
					$(this).dialog('destroy');
				}
			}

		});

    },
	show_ical_modal:function(){
	// Start modal to link your calendar to your caldendar client on your computer
	
	$('#IcalModal').html('');
	$('#IcalModal').html('<div class="genLoading"></div>');
	strUrl = HomeBubble.Paths.BASEWEB + 'member/calendar/syncalendar';
	$('#IcalModal').load(strUrl, {update: true}, function(data){
		//alert(data);


		}).dialog({
			modal: true,
			//position: [middleWidth,middleHeight],
			height: 'auto',
			width: 650,
			close: function(){
				$(this).dialog('destroy');
				},
			buttons:{				
				"Fermer":function(){
					$(this).dialog('destroy');
				}
			}

		});

	
	},
	ical_modal_behaviour:function(){
	
		$(".syncLogoLink").click(function(){
			
			calendarType = $(this).attr('rel');
			$(".syncLogoLink").removeClass("syncLogoSelect");		
			$(this).addClass("syncLogoSelect");
			$(".syncInfoContent").hide();
			$('#syncInfo'+calendarType).slideDown();	
			return false;
		});
		
	
	},
    show_event_modal_behaviour:function(){
    	
    	$('.eventModalEditButton').click(function(){
    	
    		var idEvent = $(this).attr("rel");
			strUrl = HomeBubble.Paths.BASEWEB + 'member/calendar/editmodal';
    		//Use the same edit view as event list but here we need a valid button
			$('#eventModal').html('<div class="genLoading"></div>');
			$('#eventModal').load(strUrl, {update:true, idEvent: idEvent},function(){

			//Validate the formula
	
	    	 $('#editEventTitle').blur(function(){
	   
	    	 	if($(this).val()==''){
	    	 		$('#editEventTitleError').slideDown();
	    	 		nameValidated = false;
	    	 	}
	    	 	if($(this).val()!=''){
	    	 		$('#editEventTitleError').slideUp();
	    	 		nameValidated = true;
	    	 }
	    	 
	    	  }); 
	    	 
	    	 $('#editEventDate').blur(function(){
	   
	    	 	if($(this).val()==''){
	    	 		$('#editEventDateError').slideDown();
	    	 		dateValidated = false;
	    	 	}
	    	 	if($(this).val()!=''){
	    	 		$('#editEventDateError').slideUp();
	    	 		dateValidated = true;
	    	 }
    	 	}); 
    	 	
    		$('#editEventStartTime').timeEntry({
    			show24Hours: true
    			
    		});
    		
    		$('#editEventEndTime').timeEntry({
    			show24Hours: true
    			
    		});
    	 	
	    	 $('#editEventReminderDay').blur(function(){
				regular_expression = new RegExp("^(([1-9])|([1-9][0-9]))$");
				var time = $('#editEventReminderDay').attr("value");
				if($('#editEventReminderDay').attr("value")!=''){
					if(regular_expression.test(time)){
						reminderDayValidated=true;
						$('#editEventReminderDayError').slideUp();
					}
					if(!regular_expression.test(time)){
						reminderDayValidated=false;
						$('#editEventReminderDayError').slideDown();
					}
				}
				if($('#editEventReminderDay').attr("value")==''){
					$('#editEventReminderDayError').slideUp();
					}
    	 	}); 
    	 	
	    	 $('#editEventReminderMonth').blur(function(){
				regular_expression = new RegExp("^(([1-9])|([1-9][0-9]))$");
				var time = $('#editEventReminderMonth').attr("value");
				if($('#editEventReminderMonth').attr("value")!=''){
					if(regular_expression.test(time)){
						reminderMonthValidated=true;
						$('#editEventReminderMonthError').slideUp();
					}
					if(!regular_expression.test(time)){
						reminderMonthValidated=false;
						$('#editEventReminderMonthError').slideDown();
					}
				}
				if($('#editEventReminderMonth').attr("value")==''){
					$('#editEventReminderMonthError').slideUp();
				}
    	 	}); 
	
			});
			
				
    	});
    	
 	  	$('.eventModalDeleteButton').click(function(){
 	  		
  			var idEvent = $(this).attr("rel");
 	  		
    		strUrl = HomeBubble.Paths.BASEWEB + 'member/calendar/deletemodal';
    		var calendarButtonValid = 1;
			$('#eventModal').load(strUrl, {update:true, idEvent: idEvent, calendarButtonValid: calendarButtonValid});

    	});
    	
    },delete_modal_behaviour:function(isList){
    	if(isList!=1){

    			$('#eventModal').dialog('option', 'buttons', { 
				"Valider": function() { 
			    		//id of the event    		
			    		var idEvent = $('#eventDeleteModal').attr('rel');
			    		//Update the list for calendar
			    		var updateCalendarList = 1;
			    		//date of the event
						var dateFr = $('#eventModalName').attr('rel');	
						
			  			var dateBuffer = dateFr.split("/");
			    		date = dateBuffer[2]+'-'+dateBuffer[1]+'-'+dateBuffer[0];
			    		var updateList = 1;//updateList to one, to not update the list of the event but only  the calendar
			    		//delete the event
						HomeBubble.Box.Content.Event.delete_event(idEvent, updateList, date, dateFr);
						//Reload the calendar
						HomeBubble.Box.Content.Calendar.calendarReload(dateBuffer[2], dateBuffer[1]);
						//Update the list
						HomeBubble.Box.Content.Event.update_event(0,1);
						$('#eventModal').dialog('option', 'buttons', {	
							"Retour": function(){
									$(this).dialog('destroy');
									$('#ui-datepicker-div ').css('display', 'none');	
								}
							});
					},
				"Annuler":function(){

					$(this).dialog('destroy');
					$('#ui-datepicker-div ').css('display', 'none');	
					
				}
					
			});
		}
 	
    },modal_edit_behaviour: function(isList){
    	
    	    	// Datepicker in Edit Modal
		 $.datepicker.setDefaults($.extend({showMonthAfterYear: false}, $.datepicker.regional['fr']));
		$('#editEventDate').datepicker({
					changeMonth: true,
					changeYear: true
		});
				
		//Display Reminder if the user wants
		$('#editEventReminderAdd').click(function(){
				
				$('#editEventExtraInfo').fadeIn();
	
		});
			
		//Erase value of reminder on click on reminder none					    
		$('#editEventReminderNone').click(function(){
				
				$('#editEventReminderMorning').attr("checked","");
				$('#editEventReminderDay').attr("value","");
				$('#editEventReminderMonth').attr("value","");
				
				$('#editEventExtraInfo').fadeOut();
	
		});
		
		//Info on start time format	
		$('#editEventStartTime').focus(function(){
				
				$('#editEventStartTimeTip').slideDown().fadeTo(4000, 0.6);
				
		});
		
		//Info on end time format		
		$('#editEventEndTime').focus(function(){
				
				$('#editEventEndTimeTip').slideDown().fadeTo(4000, 0.6);
				
		});
		
		//If reminder add is selected, reminders are showed
		if($('#editEventReminderAdd').attr('checked') == true){
				
				$('#editEventExtraInfo').fadeIn();
		}

		//If it is an edit of the calendar(!=1) or of the list(=1)
		if(isList!=1){
				$('#eventModal').dialog('option', 'width', [630]);
			 	$('#eventModal').dialog('option', 'buttons', { 
			 		"Valider": function() { 
					//On rÃ©cupÃ¨re l'id de l'event'''
					idEvent = $('#editEventHidden').attr('value');
					var updateCalendarList = 1; //updateList to 1 to not update the event list but only the calendar. This, to not see the calendar 			and the event in the same time
					var dateFr = $('#editEventDate').attr('value');
		  			var dateBuffer = dateFr.split("/");
		    		date = dateBuffer[2]+'-'+dateBuffer[1]+'-'+dateBuffer[0];
					//id title and date exist
					if($('#editEventTitle').attr("value")!='' && $('#editEventDate').attr("value")!=''){
						HomeBubble.Box.Content.Event.edit_event(idEvent, updateCalendarList, date, dateFr); //edit the event
						HomeBubble.Box.Content.Calendar.calendarReload(dateBuffer[2], dateBuffer[1]);
						$('#eventModal').html('<div class="genLoading"></div>');
						//change buttons of the dialog
						$(this).dialog('option', 'buttons', { 
							 "Retour": function(){
							 	$(this).dialog('destroy');
							 } 
						});
						//change the width of the dialog
						$('#eventModal').dialog('option', 'width', [360]); 
					}
					else{
						
						if($('#editEventTitle').attr("value")==""){
							$('#editEventTitleError').slideDown();
						}
						if($('#editEventDate').attr("value")==""){
							$('#editEventDateError').slideDown();
						}	
					}
 
			 		
					 },
					 "Annuler": function(){
					 	$(this).dialog('destroy');
					 } 
		
				});   
		}

    }
}
HomeBubble.Box.Content.Event = {

	initialize: function () {
		var showList = 0; // variable which permits to show or not the list after the upload of this one
		
		HomeBubble.Box.Content.Event.update_event(showList);
		// Ajax Pagination feature // check getlistajax for page container (todoPagination)

		
		//Add an event
		$('.eventAddStart').click(function(){
				//To know if you have clicked on add button of calendar or add button of list
				var calendarOrList = $(this).attr('id');
				$('#addEvent').html('<div class="genLoading"></div>');
				HomeBubble.Box.Content.Event.add_modal_event(calendarOrList);
		});	

    	
    },button_initialize:function(){
		$("#eventNext").click(function(){
						$('#eventLoader').fadeIn();
						page = $("#eventPaginationNext").attr('rel');
						var showList = 1; // variable which permits to show or not the list after the upload of this one
						HomeBubble.Box.Content.Event.update_event(showList, page);	
															
		});
		
		$("#eventPrev").click(function(){
						$('#eventLoader').fadeIn();
						page = $("#eventPaginationPrev").attr('rel');
						var showList = 1; // variable which permits to show or not the list after the upload of this one
						HomeBubble.Box.Content.Event.update_event(showList, page);						
		});
},update_event: function(showList, page){

					if(page == null){
						page = 1;
					}
	
					strUrl = HomeBubble.Paths.BASEWEB + 'member/calendar/getlistajax';
					
					$('#dashContentEvent').fadeOut().load(strUrl, { update: true, page: page },function(data){
						
						$('#eventLoader').fadeOut();
						$('#eventLoaderBig').fadeOut();
					//	$('#eventLoaderBigForCalendar').fadeOut();
				   	
					//Edit an event
						$('.eventEditButton').click(function(){
						var isList = $(".eventText").attr('rel');
						var idEvent = $(this).attr('rel');	
						$('#eventModal').html('<div class="genLoading"></div>');
						HomeBubble.Box.Content.Event.edit_modal_event(idEvent, isList);
						});	
						
						
						//update pagination buttons for bookmark
						/*
						id=".Agenda";
						strUrl = HomeBubble.Paths.BASEWEB + 'member/calendar/getnumber';
						var numberRow = 6;
						HomeBubble.Box.Content.Dashboard.update_pagination_button(id, strUrl, numberRow);
*/
				
						//$(this).css('display', 'none');
					//	if(showList == 1){
							$(this).fadeIn();
					//	}
						//Delete event
						$('.eventDeleteButton').click(function(){
								idEvent = $(this).attr('rel');
								var isList = $(".eventText").attr('rel');
								$('#eventModal').html('<div class="genLoading"></div>');
								HomeBubble.Box.Content.Event.delete_modal_event(idEvent, isList);
						});	
	
					});
    
    },update_calendar_event: function(date, dateFr){
    	
			strUrl = HomeBubble.Paths.BASEWEB + 'member/calendar/calendarinformation';
		
			//load calendar information (list of events for a given day)
			$('#eventModal').load(strUrl, {update:true, date: date}, function(){
					//change the title having the good date on the title
					$('#eventModal').dialog('option', 'title', "");
					$('#eventModal').dialog('option', 'title', "EvÃ¨nements du "+dateFr+"");
			});
    	
    
	
		
    },add_modal_event:function(calendarOrList, date){
    	if(date){
		var dateBuffer = date.split("/");
		var date = dateBuffer[2]+'/'+dateBuffer[1]+'/'+dateBuffer[0];    
		var dateValidated = true;	 	
    	}
    	else{
    	date = "";
    	var dateValidated = false;
		}

		var nameValidated = false ;

    	
		// Put info form provider in the center of the screen after open 
		 var viewportWidth = $(window).width();  
		 var viewportHeight = $(window).height(); 
		 
		 var middleWidth =  parseInt(viewportWidth/3);
		 var middleHeight =  parseInt(viewportHeight/5);

	   	strUrl = HomeBubble.Paths.BASEWEB + 'member/calendar/addmodal';
		$('#addEvent').load(strUrl, {update: true, date: date}, function(){
			
				//Validate the formula
	
	    	 $('#addEventTitle').blur(function(){
	   
	    	 	if($(this).attr('value')==''){
	    	 		$('#addEventTitleError').slideDown();
	    	 		nameValidated = false;
	    	 	}
	    	 	if($(this).attr('value') != ''){
	    	 		$('#addEventTitleError').slideUp();
	    	 		nameValidated = true;

	    	 }
	    	 //	alert(nameValidated);
	    	  }); 
	    	 
	    	 $('#addEventDate').change(function(){
	   
	    	 	if($(this).val()==''){
	    	 		$('#addEventDateError').slideDown();
	    	 		dateValidated = false;
	    	 	}
	    	 	if($(this).val()!=''){
	    	 		$('#addEventDateError').slideUp();
	    	 		dateValidated = true;
	    	 }
    	 	}); 
    	 	
			 $('#addEventDate').blur(function(){
	   
	    	 	if($(this).val()==''){
	    	 		$('#addEventDateError').slideDown();
	    	 		dateValidated = false;
	    	 	}
	    	 	if($(this).val()!=''){
	    	 		$('#addEventDateError').slideUp();
	    	 		dateValidated = true;
	    	 }
			//alert(dateValidated);
    	 	}); 
    	 	
    		$('#addEventStartTime').timeEntry({
    			show24Hours: true,
				beforeShow: firstHalfHourOnly
    			
    		});

			$('#addEventEndTime').click(function(){
				//time = $('#addEventStartTime').timeEntry('getTime');	
				t = $('#addEventStartTime').attr('value');	
				time = t.split(':');

				hour = parseInt(time[0])+parseInt(1);
				min = parseInt(time[1]);
				$(this).timeEntry('setTime', new Date(0, 0, 0, hour, min, 0));
		
			});
    		
    		$('#addEventEndTime').timeEntry({
    			show24Hours: true
    			//beforeShow: firstHalfHourOnly
    		});

			function firstHalfHourOnly(oldTime, newTime, minTime, maxTime) { 
			    var increment = (newTime - (oldTime || newTime)) > 0; 
			    if (newTime.getMinutes() > 30) { 
			        newTime.setMinutes(increment ? 0 : 30); 
			        newTime.setHours(newTime.getHours() + (increment ? 1 : 0)); 
			    } 
			    return newTime; 
			}

		}).dialog({
							
								bgiframe: true,
								autoOpen: true,
								height: 'auto',
								draggable: true,
								resizable: true,
								width: 630,
								modal: true,
								position: [middleWidth,middleHeight],
								minHeight: 250,
								minWidth: 250,
								closeOnEscape: false,
								buttons: {
											/***  Bouton Valider et ses options  ***/
											"Valider": function() {
												//alert("name= "+nameValidated+ " t = " + dateValidated);
													//	alert('name='+nameValidated + 'date='+dateValidated);	
												if(nameValidated == true && dateValidated == true){
														
													HomeBubble.Box.Content.Event.add_event(calendarOrList);
													
												}
												else{
														if($('#addEventTitle').attr("value")==""){
															$('#addEventTitleError').slideDown();
														}
														if($('#addEventDate').attr("value")==""){
															$('#addEventDateError').slideDown();
														}
													
												}
										},		
												/***  Bouton annuler et ses options  ***/		
												"Annuler": function() {
													$(this).dialog('destroy');
													//$('.portlet').fadeIn();
												}
									},
								close: function(){
									$(this).dialog('destroy');
									$('#ui-datepicker-div ').css('display', 'none');
								}
						});
				return false;
				


			//	$('#addEvent').dialog('option', 'position', [middleWidth,middleHeight]);


    },add_event:function(calendarOrList){
		
    	
    	var title =  $('#addEventTitle').attr('value');
    	var date = $('#addEventDate').attr('value');
    	var startTime = $('#addEventStartTime').attr('value');
    	var endTime = $('#addEventEndTime').attr('value');
    	var morning = $('#addEventReminderMorning').attr('checked');
    	var day = $('#addEventReminderDay').attr('value');
    	var month = $('#addEventReminderMonth').attr('value');
    	var description = $('#addEventDescription').attr('value');
    	var periodicity = $('.addEventPeriodicity:checked').val(); 
    	var boolMorning;
    	
    	var reminderDayValidated = true;
    	var reminderMonthValidated = true;


    	// Change the format of the date to insert to the database
		var dateBuffer = date.split("/");
		var date = dateBuffer[2]+'/'+dateBuffer[1]+'/'+dateBuffer[0];
		
		
		regular_expression = new RegExp("^(([1-9])|([1-9][0-9]))$");
		var time = $('#addEventReminderDay').attr("value");
		if($('#addEventReminderDay').attr("value")!=''){
			if(regular_expression.test(time)){
				reminderDayValidated=true;
				$('#addEventReminderDayError').slideUp();
			}
			if(!regular_expression.test(time)){
				reminderDayValidated=false;
				$('#addEventReminderDayError').slideDown();
			}
		}
		if($('#addEventReminderDay').attr("value")==''){
			$('#addEventReminderDayError').slideUp();
			}
 
 	

		regular_expression = new RegExp("^(([1-9])|([1-9][0-9]))$");
		var time = $('#addEventReminderMonth').attr("value");
		if($('#addEventReminderMonth').attr("value")!=''){
			if(regular_expression.test(time)){
				reminderMonthValidated=true;
				$('#addEventReminderMonthError').slideUp();
			}
			if(!regular_expression.test(time)){
				reminderMonthValidated=false;
				$('#addEventReminderMonthError').slideDown();
			}
		}
		if($('#addEventReminderMonth').attr("value")==''){
			$('#addEventReminderMonthError').slideUp();
		}
 
    	
    	if(morning==true){
    		boolMorning=1;
    	}
    	if(morning==false){
    		boolMorning=0;
    	}
    	
    	if(day==''){
    		$day=0;
    	}
    	if(month==''){
    		$day=0;
    	}
		
		$('#eventLoaderBig').fadeIn();
		$('#eventLoaderBigForCalendar').fadeIn();
    	strUrl =  HomeBubble.Paths.BASEWEB + 'member/calendar/addajax';
    	
    	if(reminderDayValidated == true && reminderMonthValidated == true){
		   
				$.post(strUrl, { title: title, date: date, startTime: startTime, endTime: endTime, boolMorning: boolMorning, day: day, month: month,  description: description, periodicity: periodicity}, function(){
			    			
					if(calendarOrList == 'eventAddStartList'){
		    			var showList = 1; // variable which permits to show or not the list after the upload of this one
						HomeBubble.Box.Content.Event.update_event(showList);
					}
					if(calendarOrList=='eventAddStartCalendar'){
						var showList = 0; // variable which permits to show or not the list after the upload of this one
						HomeBubble.Box.Content.Event.update_event(showList);	
					}
					HomeBubble.Box.Content.Calendar.calendarReload(dateBuffer[2], dateBuffer[1]);	
		
					$(".dashPortletIconCalendar").attr('rel', dateBuffer[2]+'-'+dateBuffer[1]);
					
					$('#addEvent').dialog('destroy');
		 		});
 		}
    	
    },edit_modal_event:function(idEvent, isList){
    	
    	var nameValidated = true ;
    	var dateValidated = true;
    
		 // Put info form provider in the center of the screen after open 
		 var viewportWidth = $(window).width();  
		 var viewportHeight = $(window).height(); 
		 
		 var middleWidth =  parseInt(viewportWidth/3);
		 var middleHeight =  parseInt(viewportHeight/5);
    	
    	$('#eventModal').attr("title", "Editer un Ã©vÃ¨nement");
    	strUrl = HomeBubble.Paths.BASEWEB + 'member/calendar/editmodal';
		$('#eventModal').load(strUrl, {update: true, idEvent: idEvent, isList: isList}, function(){
			
			//Validate the formula
	
	    	 $('#editEventTitle').blur(function(){
	   
	    	 	if($(this).val()==''){
	    	 		$('#editEventTitleError').slideDown();
	    	 		nameValidated = false;
	    	 	}
	    	 	if($(this).val()!=''){
	    	 		$('#editEventTitleError').slideUp();
	    	 		nameValidated = true;
	    	 }
	    	 
	    	  }); 
	    	 
	    	 $('#editEventDate').blur(function(){
	   
	    	 	if($(this).val()==''){
	    	 		$('#editEventDateError').slideDown();
	    	 		dateValidated = false;
	    	 	}
	    	 	if($(this).val()!=''){
	    	 		$('#editEventDateError').slideUp();
	    	 		dateValidated = true;
	    	 }
    	 	}); 
    	 	
    		$('#editEventStartTime').timeEntry({
    			show24Hours: true
    			
    		});
    		
    		$('#editEventEndTime').timeEntry({
    			show24Hours: true
    			
    		});
    	 	
	    	 $('#editEventReminderDay').blur(function(){
				regular_expression = new RegExp("^(([1-9])|([1-9][0-9]))$");
				var time = $('#editEventReminderDay').attr("value");
				if($('#editEventReminderDay').attr("value")!=''){
					if(regular_expression.test(time)){
					//	reminderDayValidated=true;
						$('#editEventReminderDayError').slideUp();
					}
					if(!regular_expression.test(time)){
					//	reminderDayValidated=false;
						$('#editEventReminderDayError').slideDown();
					}
				}
				if($('#editEventReminderDay').attr("value")==''){
					$('#editEventReminderDayError').slideUp();
					}
    	 	}); 
    	 	
	    	 $('#editEventReminderMonth').blur(function(){
				regular_expression = new RegExp("^(([1-9])|([1-9][0-9]))$");
				var time = $('#editEventReminderMonth').attr("value");
				if($('#editEventReminderMonth').attr("value")!=''){
					if(regular_expression.test(time)){
					//	reminderMonthValidated=true;
						$('#editEventReminderMonthError').slideUp();
					}
					if(!regular_expression.test(time)){
					//	reminderMonthValidated=false;
						$('#editEventReminderMonthError').slideDown();
					}
				}
				if($('#editEventReminderMonth').attr("value")==''){
					$('#editEventReminderMonthError').slideUp();
				}
    	 	}); 

		}).dialog({
							
								bgiframe: true,
								autoOpen: true,
								height: 'auto',
								draggable: true,
								resizable: true,
								width: 630,
								modal: true,
								minHeight: 250,
								minWidth: 250,
								position: [middleWidth,middleHeight],
								closeOnEscape: false,
								buttons: {
											/***  Bouton Valider et ses options  ***/
											"Valider": function() {
												if(nameValidated==true && dateValidated == true){
													
													HomeBubble.Box.Content.Event.edit_event(idEvent);
											
													$(this).dialog('destroy');
												}
												else{
														if($('#editEventTitle').attr("value")==""){
															$('#editEventTitleError').slideDown();
														}
														if($('#editEventDate').attr("value")==""){
															$('#editEventDateError').slideDown();
														}	
												}

										},	/***  Bouton annuler et ses options  ***/		
											"Annuler": function() {
											$(this).dialog('destroy');
											//$('.portlet').fadeIn();
										}
										
									},
								close: function(){
									$(this).dialog('destroy');
									$('#ui-datepicker-div ').css('display', 'none');
								}
						});
				return false;

    },edit_event: function(idEvent, updateCalendarList, date, dateFr){

    	var title =  $('#editEventTitle').attr('value');
    	var date = $('#editEventDate').attr('value');
    	var startTime = $('#editEventStartTime').attr('value');
    	var endTime = $('#editEventEndTime').attr('value');
    	var morning = $('#editEventReminderMorning').attr('checked');
    	var day = $('#editEventReminderDay').attr('value');
    	var month = $('#editEventReminderMonth').attr('value');
    	var description = $('#editEventDescription').attr('value');
    	var hasChild = $('.editEventHasChild:checked').val();
    	var isChild = $('.editEventIsChild:checked').val();
   		var idEventParent = $('.editEventTitle').attr('rel');
   		var numberOfChildEvent = $('.editEventDate').attr('rel');
   		var idUsrBubble = $('#idUsrBubble').attr('value');
   		var periodicity = $('.editPeriodicityInfo').attr('rel'); // To save the periodicity when edit an event
    	var boolMorning;
    	// Change the format of the date to insert to the database
		var dateBuffer = date.split("/");
		var date = dateBuffer[2]+'/'+dateBuffer[1]+'/'+dateBuffer[0];
		

    	if(morning==true){
    		boolMorning=1;
    	}
    	if(morning==false){
    		boolMorning=0;
    	}
    	    	
    	if(day==''){
    		$day=0;
    	}
    	if(month==''){
    		$day=0;
    	}
  
    	strUrl = HomeBubble.Paths.BASEWEB+'member/calendar/editajax';
    	
    	$.post(strUrl, {idEvent: idEvent, title: title, date: date, startTime: startTime, endTime: endTime, boolMorning: boolMorning, day: day, month: month,description: description, periodicity: periodicity, hasChild: hasChild, isChild: isChild, idEventParent: idEventParent, numberOfChildEvent: numberOfChildEvent, idUsrBubble:idUsrBubble}, function(data){
    		$('#eventLoaderBig').fadeIn();
			//$('#eventLoaderBigForCalendar').fadeIn();
    	//Update the list only if we edit the event by clicking on the list and not on the calendar
    //	if(data =='ok'){

			if(updateCalendarList == 1){
			var showList = 0;
			}
			else{
				var showList = 1;
			}


			HomeBubble.Box.Content.Event.update_event(showList);		
	    	
	    	$('#eventModal').html('<div class="genLoading"></div>');
    		HomeBubble.Box.Content.Event.update_calendar_event(date, dateFr);
   			HomeBubble.Box.Content.Calendar.calendarReload(dateBuffer[2], dateBuffer[1]);

		//	}
    	});

    },modal_edit_behaviour: function(){
    	
    	// Datepicker in Edit Modal
		$.datepicker.setDefaults($.extend({showMonthAfterYear: false}, $.datepicker.regional['fr']));
		$('#editEventDate').datepicker({
					changeMonth: true,
					changeYear: true
		});
				
		//Display Reminder if the user wants
		$('#editEventReminderAdd').click(function(){
				
				$('#editEventExtraInfo').fadeIn();
	
		});
			
		//Erase value of reminder on click on reminder none					    
		$('#editEventReminderNone').click(function(){
				
				$('#editEventReminderMorning').attr("checked","");
				$('#editEventReminderDay').attr("value","");
				$('#editEventReminderMonth').attr("value","");
				
				$('#editEventExtraInfo').fadeOut();
	
		});
		
		//Info on start time format	
		$('#editEventStartTime').focus(function(){
				
				$('#editEventStartTimeTip').slideDown().fadeTo(4000, 0.6);
				
		});
		
		//Info on end time format		
		$('#editEventEndTime').focus(function(){
				
				$('#editEventEndTimeTip').slideDown().fadeTo(4000, 0.6);
				
		});
		
		//If reminder add is selected, reminders are showed
		if($('#editEventReminderAdd').attr('checked') == true){
				
				$('#editEventExtraInfo').fadeIn();
		}

    },modal_add_behaviour: function(){
    	
    	var nameValidated;
    	// Datepicker in Add Modal
		 $.datepicker.setDefaults($.extend({showMonthAfterYear: false}, $.datepicker.regional['fr']));
				$('#addEventDate').datepicker({
					changeMonth: true,
					changeYear: true
				});
				
		
		//Display Reminder if the user wants	    
		$('#addEventReminderAdd').click(function(){
				
				$('#addEventExtraInfo').fadeIn();
	
		});
			
		//Erase value of reminder on click on reminder none				    
		$('#addEventReminderNone').click(function(){
				
				$('#addEventReminderMorning').attr("checked","");
				$('#addEventReminderDay').attr("value","");
				$('#addEventReminderMonth').attr("value","");
				
				$('#addEventExtraInfo').fadeOut();
	
		});
			
		// Infos on start time format
		$('#addEventStartTime').focus(function(){
				
				$('#addEventStartTimeTip').slideDown().fadeTo(4000, 0.6);
				
		});
		
		//Infos on end time format	
		$('#addEventEndTime').focus(function(){
				
				$('#addEventEndTimeTip').slideDown().fadeTo(4000, 0.6);
				
		});
		
		//Show the reminder date
		$('#addEventReminderDay').blur(function(){

		});

		 if(nameValidated){
		 	return true;
		 }   	

    },delete_modal_event: function(idEvent, isList){
    	
   
		strUrl = HomeBubble.Paths.BASEWEB + 'member/calendar/deletemodal';
		$('#eventModal').attr("title", "Supprimer un Ã©vÃ¨nement");

		$('#eventModal').load(strUrl , { idEvent: idEvent, isList: isList } ).dialog({
					
						bgiframe: true,
						autoOpen: true,
						height: 'auto',
						draggable: true,
						resizable: true,
						width: 400,
						modal: true,
						minHeight: 100,
						minWidth: 250,
						closeOnEscape: false,
						buttons: {
									/***  Bouton Valider et ses options  ***/
									
									"Valider": function() {
									HomeBubble.Box.Content.Event.delete_event(idEvent);
									$(this).dialog('destroy');
				
								},
										
									/***  Bouton annuler et ses options  ***/	
										
									"Annuler": function() {
									$(this).dialog('destroy');
									//$('.portlet').fadeIn();
								}
								
							},
					close: function(){
						
							$(this).dialog('destroy');
					}

				});	
    	
    },delete_event: function(idEvent, updateList, date, dateFr){
    	
    	
   		strUrl = HomeBubble.Paths.BASEWEB + 'member/calendar/deleteajax/';
   		var hasChild = $('.deleteEventHasChild:checked').val();
		var numberOfChildEvent = $('#numberOfChild').attr('rel');
		var eventDateEn = $('#eventDateEn').attr('rel');
		var idEventParent = $('#idEventParent').attr('rel');
		var boolChildren = $('#eventBoolChildren').attr('rel');
		
		$.post(strUrl, {idEventParent: idEventParent, idEvent: idEvent, hasChild: hasChild, numberOfChildEvent: numberOfChildEvent, eventDateEn: eventDateEn, boolChildren: boolChildren }, function(data){							
		  if(data == 'deleted' ){
		  	if(!updateList == 1){
		  	//Update the list of event
		   	HomeBubble.Box.Content.Event.update_event(1);
		   	HomeBubble.Box.Content.Calendar.calendarReload();
		   	}
		   	//Update the list of event for calendar
	   		//$('#eventModal').html('<div class="genLoading"></div>');
			$('#eventLoaderBig').fadeIn();
		   	HomeBubble.Box.Content.Event.update_calendar_event(date, dateFr);
		  	
		  	$('#deleteEvent').dialog('destroy');
		  	$('#eventContent').fadeOut('500', function(){
		  		
		  		$('#eventContent').fadeIn('500');	
		  	});
		  } 
	});	
    }
}
HomeBubble.Box.Content.Activation = {
	
		initialize: function () {
			
				
				
			$("#formButtonActivation").click(function(){
		
			// RÃ©cupÃ©ration de l'email saisi par l'utilisateur
			var email = $("#activationInEmail").val();	
		

			if (email == ''){
				checkEmail = false;
				$("#emailEmpty").slideDown();	
			}else{
				checkEmail = true;
			
			}
				

			if (checkEmail == true){
				
				$("#emailEmpty").slideUp();	
				$("#accountNotExist").slideUp();
				
				
				strUrl = HomeBubble.Paths.BASEWEB + 'activation/checkemailajax';
				
				$.post(strUrl , { email:email } , function(data){
					
					if(data == "notExist"){
							$("#accountNotExist").slideDown();
					}
						// Sinon tout va bien
					if (data == "ok"){
									
						
						
						
						//$('#emailResult').css("display", "none");	
						$('.activationForm').hide();
						
						$("#activationResultEmail").text(email);
						$('#activationSuccess').fadeIn(2000, function(){		
								
						});
				
							
					}
						
				});
				
				
			}
			// Envoie de l'email via ajax
		
			
			
			
		});
				
				
				

			}

}
HomeBubble.Box.Content.Auth = {
	
		initialize: function () {
			
			var passwordValid = false;
			var confirmPasswordValid = false;
			
			
			$('#authFormButton').click(function(){
					var question = $('#authSecretQuestion').val();
					var answer = $('#authAnswer').val();
					var email = $('#authRequestPasswordForm').attr('rel');
			
					strUrl = HomeBubble.Paths.HOST_LINK + 'password/checkanswerajax';	
				//	strUrl = HomeBubble.Paths.BASEWEB + 'member/auth/checkanswerajax';	
					
					$.post(strUrl, { question: question, answer: answer, email: email}, function(data){
						
						if(data == "good answer"){
							$('#authFailureQuestion').slideUp();
							$('#authChangePassword').slideDown();
							$('#authRequestPasswordForm').slideUp();
							$('#authRequestPasswordTitle').slideUp();
							$('#authRequestChangePasswordTitle').slideDown();
						}
						if(data == "bad answer"){
							$('#authFailureQuestion').slideDown();
						}
						
						
					});
			});
			
			
			$('#authPassword').pstrength();
			
			$('#authPassword').blur(function(){
				
				var password = $('#authPassword').attr("value");
			
				if(password.length < 6){
					$('#authPasswordError').slideDown();
					passwordValid = false;
				}
				
				if(password.length > 6){
					$('#authPasswordError').slideUp();
					passwordValid = true;
				}
				
			});
			
			$('#authConfirmPassword').blur(function(){
				
				var confirmPassword = $('#authConfirmPassword').attr("value");
			
				if(confirmPassword != $('#authPassword').attr("value") ){
			
					$('#authConfirmPasswordError').slideDown();
					confirmPasswordValid = false;
				}
				
				if(confirmPassword == $('#authPassword').attr("value")){
					$('#authConfirmPasswordError').slideUp();
					confirmPasswordValid = true;
				}
				
			});
			
			$('#authFormButtonValidPassword').click(function(){
				
				var validPassword = false;
				var validConfirmPassword = false;
				
				var email = $('#authRequestPasswordForm').attr('rel');
				var password = $('#authPassword').attr("value");
				var confirmPassword = $('#authConfirmPassword').attr("value");

				strUrl = HomeBubble.Paths.BASEWEB + 'password/changepassword';
				
				if(password.length < 6){
					$('#authPasswordError').slideDown();
					validPassword = false;
				}
				
				if(password.length >= 6){
					$('#authPasswordError').slideUp();
					validPassword = true;
				}
				
				if(confirmPassword != $('#authPassword').attr("value") ){
					$('.authValidButton').slideUp();
					$('#authConfirmPasswordError').slideDown();
					validConfirmPassword = false;
				}
				
				if(confirmPassword == $('#authPassword').attr("value")){
					$('#authConfirmPasswordError').slideUp();
					validConfirmPassword = true;
				}
				
				password = md5(password, false, false);
				
				if(validPassword == true && validConfirmPassword == true){
					$.post(strUrl, { email: email, password: password}, function(data){	
							if(data == "password changed"){
								$('#authFailureChange').slideUp();
								
								$('#authChangePassword').fadeOut(function(){
									
									$('#authSuccessChange').slideDown(function(){

									});
								
								});								
							}
							if(data == "password not changed"){
								$('#authSuccessChange').slideUp();
								$('#authFailureChange').slideDown();
							}
					
					});	
				
				}
				
			});

		
		}

}
HomeBubble.Box.Content.Provider = {
	
		initialize: function () {
				
					HomeBubble.Box.Content.Provider.update_api();

					
					HomeBubble.Box.Content.Provider.password_retrieve();
					
					$('#provSelect').change(function(){
						url = $(this).attr('value');
						window.location = "/membre/bulle/"+url;
					});
					$('#provLogo').mouseenter(function(){
						//alert('pwet');
						if ($('#linkchangeicon').attr('name') != 'block')
						$('#changeicon').show();
					});
					$('#provHeaderPage').mouseleave(function(){
						if ($('#linkchangeicon').attr('name') != 'block')
						$('#changeicon').hide("slow");
						//$('#changeicon').hide();
					});
					
			
					$("#modifyProviderButton, #modifyProviderHoover").click(function(){
						
						var viewportWidth = $(window).width();  
 					    var viewportHeight = $(window).height(); 
 					 
 					    var middleWidth =  parseInt(viewportWidth/3);
 					    var middleHeight =  parseInt(viewportHeight/5);
						
						var idProvider =  $("#idProvider").attr('value');
						var idUsrBubble =  $("#idUsrBubble").attr('value');
						var customName = $("#customName").attr('value');
						var customNameSeo = $("#customNameSeo").attr('value');
							
						strUrl = HomeBubble.Paths.BASEWEB + 'member/bubble/addproviderinfoform';				
						$('#modifyProvider').load(strUrl , { idUsrBubble: idUsrBubble , idProvider : idProvider } ).dialog({
						
							bgiframe: true,
							autoOpen: true,
							width: 560,
							height: 600,
							draggable: true,
							resizable: true,
							modal: true,
							position: 'top',
							closeOnEscape: false,
							buttons: {				
										/***  Bouton Valider et ses options  ***/
										
										"Valider": function() {
										usrProviderName = $("#usrProviderName").attr('value');				
										usrBubbleName = $("#usrBubbleName").attr('value');
		
										
										if(usrBubbleName == ''){
											$('#newNoTitle').slideDown();
										}else{
											$('#newNoTitle').slideUp();
										}	
										
										if(usrProviderName == ''){
											$('#newNoName').slideDown();
										}else{
											$('#newNoName').slideUp();
										}
										
										if (usrBubbleName != '' && usrProviderName != ''){
											HomeBubble.Box.Content.Provider.modify_provider_info(customName,customNameSeo);	
										}

									},
									/***  Bouton annuler et ses options  ***/	
									"Annuler": function() {
										$(this).dialog('destroy');
										//$('.portlet').fadeIn();
									}						
							},
							close: function(){
								
									$(this).dialog('destroy');
							}
		
						});
							
					});
					
			$("#addVaccination a").click(function(){
				strUrl = HomeBubble.Paths.BASEWEB + 'member/calendar/specificdate';
				dateType = "vaccination";
				$("#addVaccinationModal").load(strUrl, {dateType: dateType}, function(){
					
					$("#subscribeVaccination").click(function(){
						var firstname = $("#firstname").attr("value");
						var dob = $("#dob").attr("value");
						HomeBubble.Box.Content.Provider.add_vaccination(firstname, dob);
					});
					
					
				}).dialog({
				
					bgiframe: true,
					autoOpen: true,
					width: 560,
					height: 'auto',
					draggable: true,
					resizable: true,
					modal: true,
					position: 'top',
					closeOnEscape: false,
					buttons: {				

							/***  Bouton annuler et ses options  ***/	
							"Annuler": function() {
								$(this).dialog('destroy');
								//$('.portlet').fadeIn();
							}						
					},
					close: function(){
						
							$(this).dialog('destroy');
					}

				});
				
				return false;
			});
					
			$("#changeicon").click(function(){

				var idUsrBubble =  $("#idUsrBubble").attr('value');
				var idProvider =  $("#idProvider").attr('value');
				var customName =  $("#customName").attr('value');
				var icon =  $("#icon").attr('value');
				var idFamily =  $("#idFamily").attr('value');
				var idProvider =  $("#idProvider").attr('value');
				var usrfolder =  $("#usrfolder").attr('value');
				var provfolder =  $("#provfolder").attr('value');
				var providerName = $('#providerName').attr('value');

				strUrl = HomeBubble.Paths.BASEWEB + 'member/provider/changeiconmodal';

				$('#modalchangeicon').load(strUrl, {icon:icon, idFamily:idFamily, usrfolder:usrfolder,provfolder:provfolder, name:name, customName:customName, idProvider:idProvider, idUsrBubble:idUsrBubble, providerName:providerName}).dialog({
					bgiframe: true,
					autoOpen: true,
					width: 500,
					height: 'auto',
					draggable: true,
					resizable: true,
					modal: true,
					position: 'top',
					closeOnEscape: false,
					buttons: {				
								/***  Bouton Valider et ses options  ***/

							"Valider": function() {	
							//	alert("yes");
								if( $('#fileToUpload').attr('value') == '' ){
										$("#ErrorLogo").html("Vous devez selectionner un fichier");
										$('#ErrorLogo').slideDown();
								}
								else
									HomeBubble.Box.Content.Provider.changeicon();
									
							},
							/***  Bouton annuler et ses options  ***/	
							"Annuler": function() {
								$(this).dialog('destroy');
								//$('.portlet').fadeIn();
							}						
					},
					close: function(){

							$(this).dialog('destroy');
					}

				})
					return false;
				});
			
			},add_vaccination:function(firstname, dob){
				
				strUrl = HomeBubble.Paths.BASEWEB + 'member/calendar/specificdateresult';
				dateType = "vaccination";
				$("#addVaccinationModal").load(strUrl, {dateType: dateType, firstname: firstname, dob: dob}, function(){
					$("#addVaccinationModal").dialog('option', 'buttons', { 
							 "Valider": function(){

							 },
							"Annuler": function(){

							}
					});
				});	
			},
			changeicon: function(){
			strUrl = HomeBubble.Paths.BASEWEB + 'member/provider/providericon';
		var options = {
				url:strUrl,
				dataType: 'json',
				success:  function(data){
					//alert(data.result);
					if(data.result == true){
						$("#ErrorLogo").slideUp();
						$("#changeIconProvider").attr("src",data.icon);
						//alert(data.icon);
						$("#modalchangeicon").dialog('destroy');
					}else{
						//alert(data.logErr );
						$("#ErrorLogo").html(data.logErr);
						$("#ErrorLogo").slideDown();
					}
					return false;		
				}
			};
			
			$("#changeIconform").ajaxSubmit(options);
			  return false;
		},
		modify_provider_info:function(customName,customNameSeo){
			

			//checkbox
			$('.hooverCheckbox').each(function(index) {
			    if($(this).is(':checked')){
					$(this).attr('value', 1);
					$("#provHoover").append('<input type="hidden" name="hooverActivated" value="true"/>');
					
					// We launch the hoover process
					strUrl = HomeBubble.Paths.BASEWEB + 'member/hoover/download';
					idUsrBubble = $("#idUsrBubble").attr('value');
					idProvider = $("#idProvider").attr('value');
					$.post(strUrl , { idUsrBubble:idUsrBubble, idProvider:idProvider }, function(){

					});
					
				}else{
					//$(this).attr('value', 0);
					name = $(this).attr('name');	
					//$("input[name="+name+"]").remove();		
					$("#provHoover").append('<input type="hidden" name="'+name+'" value="0"/>');
					$("#provHoover").append('<input type="hidden" name="hooverActivated" value="false"/>');		
				}
			 });

			
			var formValues = $("#addProviderInfoForm").serialize();
			
			idUsrBubble = $("#idUsrBubbleProviderInfoForm").attr('rel');
			idProvider = $("#bubbleIdProviderInfo").attr('value');
			usrBubbleName = $("#usrBubbleName").attr('value');
			usrProviderName = $("#usrProviderName").attr("value");
			apiLink = $("#addApiLink").attr('value');
			usrBubbleNameTemp = $("#usrBubbleNameTemp").attr('value');
			bubbleName = $("#bubbleName").attr('value');
			bubbleThemeName = $("#bubbleThemeName").attr('value');

		//	alert(apiLink);
	/*		if(!apiLink){
				apiLink = $("#usrBubbleSpaceClientLinkHidden").attr('value');
			}
	*/		
	
			strUrl = HomeBubble.Paths.BASEWEB + 'member/bubble/addproviderinfoformprocess';
			$.post( strUrl, { values : formValues , idUsrBubble : idUsrBubble , idProvider:idProvider , usrBubbleName : usrBubbleName, apiLink: apiLink, usrBubbleNameTemp:usrBubbleNameTemp, bubbleName:bubbleName, usrProviderName: usrProviderName, customNameSeo : customNameSeo}, function(data){
						

						//UPdate selfcare data link
				
						$('#modifyProvider').dialog('destroy');
						HomeBubble.Box.Content.Provider.display_api();
						HomeBubble.Box.Content.Provider.update_name();
						
						url = HomeBubble.Paths.BASEWEB + 'member/provider/updatehooverinfo';
						$('#archiveHooverInfo').load(url, {idUsrBubble: idUsrBubble, idProvider: idProvider}, function(data){
						
						});
						// IF the bubble custom name does not change
						if(usrBubbleNameTemp == usrBubbleName){
							$("#provSelfcare").slideUp();
							HomeBubble.Box.Content.Provider.update_api();		
								
						
							$("#provContentInfo").css('visibility', 'hidden');	
							// Update title
							/*
							if(customName != usrBubbleName){
								
								$("#provMainTitle").fadeOut(function(){
									
									$(this).text(usrBubbleName);
									$(this).fadeIn();
									$("#customName").attr('value', usrBubbleName);
									
								});
									
							}
						*/
							
								strUrl = HomeBubble.Paths.BASEWEB + 'member/provider/updateproviderinfocontent';
								$("#provContentInfo").load(strUrl , {idUsrBubble : idUsrBubble , idProvider:idProvider} , function(){	
									$(this).css('display', 'none');
									$(this).css('visibility', 'visible');
									$(this).fadeIn();	
								 
									// UPDATE FUNCTION FOR PASSWORD RETRIEVE
									HomeBubble.Box.Content.Provider.password_retrieve();

								});
						
						}else{

							
							window.location = HomeBubble.Paths.BASEWEB + 'membre/bulle/'+bubbleName+'/'+bubbleThemeName+'/'+data;
							
							
						}
						
						
						
						
						
						
						
						
				
			});
			
			
			
			
		},display_api:function(){

			var idProvider =  $("#idProvider").attr('value');
			strUrl = HomeBubble.Paths.BASEWEB + 'member/provider/displayapiajax';
				$.post(  strUrl , { idProvider : idProvider} , function(data){

							if(data.show == 'true'){

								$("#provApiBox").slideDown();
							}else if(data.show == 'false'){
								
								$("#provApiBox").slideUp();
								
							}

					}, 'json');

							
			
		},update_api: function(){
			
			var idProvider =  $("#idProvider").attr('value');
			var idUsrBubble =  $("#idUsrBubble").attr('value');
			
			strUrl = HomeBubble.Paths.BASEWEB + 'member/provider/updateapi';
			$("#provSelfcare").load(  strUrl , { idProvider : idProvider , idUsrBubble : idUsrBubble } , function(data){
			
						$(this).slideDown();					
						$("#provAccountTextButton").click(function(){
							//$(".genRightBot", this).html('');
							$("#provFromPost").submit();	
						});
			});

	

		},update_name: function(){
		
			var idProvider =  $("#idProvider").attr('value');
			
			strUrl = HomeBubble.Paths.BASEWEB + 'member/provider/updatenameajax';
			$.post(  strUrl , { idProvider : idProvider } , function(data){
				if(data.result == true){
					$('#provMainTitle').html(data.newName);
				}				
			},'json');
		},
		password_retrieve: function(idProvider, idUsrBubble){
			
			idProvider = $("#idProvider").attr('value');				
			idUsrBubble = $("#idUsrBubble").attr('value');
			strUrl = HomeBubble.Paths.BASEWEB + 'member/provider/passwordlinkajax';
			$.post(  strUrl , { idProvider: idProvider , idUsrBubble : idUsrBubble } , function(data){
			
				if(data.result == "true"){
					$('.provDetailsLink').slideDown();
				}else{
					
					//$('.provDetailsLink').slideDown();
					
				}
				
				$('.provPassSendLink').click(function(){
				
					strUrl = HomeBubble.Paths.BASEWEB + 'member/provider/sendpasswordajax';
					$.post(  strUrl , { idProvider: idProvider , idUsrBubble : idUsrBubble } , function(data){
						
						if(data.result == 'true'){
							$("#provPassMessage").slideDown(function(){
								$(this).oneTime('4s', function(){
									$(this).slideUp();
								});
							});
						}
					
					}, 'json');
					
				});
								
			
				
			}, 'json' );
			
			
		}
			
			
			

}
	
HomeBubble.Box.Content.keyDate = {
	
		initialize: function() {
	//	HomeBubble.Box.Content.keyDate.edit_keyDate_button();
		
			//Validate name and date
			var nameValidated = false;
			var dateValidated = false;

			
			// Hint link
			$("#keyDateHint").click(function(){
					$('#keyDateHintText').slideToggle();
			});
			

			//$('#keyDateNextDate').html('<div class="genLoadingProvider"></div>');
			HomeBubble.Box.Content.keyDate.update_keyDate(1);

			//display or remove periodicity
			$("#keyDateName").focus(function(){
				$('#keyDatePeriodicity').slideDown();
				$('#keyDateReminder').slideDown();
				$('.provFooterAction').slideDown();
				$('#provFooterActionLeftKeyDate').css("display","block");	
				$("#keyDateHint").show();
				
			});
			
			$("#keyDateDate").focus(function(){
				$('#keyDatePeriodicity').slideDown();
				$('#keyDateReminder').slideDown();
				$('.provFooterAction').slideDown();
				$('#provFooterActionLeftKeyDate').css("display","block");	
				$("#keyDateHint").show();
			});
			
			//display or remove periodicity
			$("#keyDateCancel").click(function(){
				$("#keyDateDate").attr("value","jj/mm/aaaa");
   				$("#keyDateName").attr("value","Nom");
   				$("#keyDateReminderMonth").attr("value", "");
   				$("#keyDateReminderDay").attr("value", "");
   				$('.keyDatePeriodicity:checked').attr("checked","");
   				$('.keyDatePeriodicity:[value=0]').attr("checked","checked");
   				$('#keyDateReminderMorning').attr("checked","");
				$('#keyDatePeriodicity').slideUp();
				$('#keyDateReminder').slideUp();
				$('#keyDateError').slideUp();
				$('.provFooterAction').slideUp();
				$('#provFooterActionLeftKeyDate').slideUp();
			//	$("#keyDateHint").hide();
			//	$('#keyDateHintText').hide();
				
			});
			
			//Key date suggestion
			$("#selectHint").change(function(){
				text = $(this).attr("value");
				if(text != 0){
					$("#keyDateName").attr("value", text);
				}
				
				return false;
			});		

			$(window).load(function(){			
					//Datepicker keyDate
					$('#keyDateDate').datepicker({
							changeMonth: true,
							changeYear: true
						});
					dateValidated = false;
			});

			$("#keyDateDate").focus(function(){
				if($("#keyDateDate").attr("value")=='jj/mm/aaaa'){
					$("#keyDateDate").attr("value","");
	
						}

			});
			
			$("#keyDateDate").blur(function(){
				
				if($("#keyDateDate").attr("value")==''){
					$("#keyDateDate").attr("value","jj/mm/aaaa");
			}

			});
			
			$("#keyDateName").focus(function(){
				if($("#keyDateName").attr("value")=='Nom'){
					$("#keyDateName").attr("value","");
				}
			});
			
			$("#keyDateName").blur(function(){
				
				if($("#keyDateName").attr("value")==''){
					$("#keyDateName").attr("value","Nom");
					nameValidated = false;
				}

				if($("#keyDateName").attr("value")!="Nom"){
					nameValidated = true;
				}
		
			});
			
			//keydate pagination
			$("#keydateNext").click(function(){
				page = $("#keydatePaginationNext").attr('rel');
			//	alert(page);
			
				HomeBubble.Box.Content.keyDate.update_keyDate(page);	
			});
			
			//keydate pagination
			$("#keydatePrev").click(function(){
				page = $("#keydatePaginationPrev").attr('rel');
				HomeBubble.Box.Content.keyDate.update_keyDate(page);		
			});


			//Add a key date
			$("#keyDateAddText, #keyDateValidButton").click(function(){
				if($("#keyDateDate").attr("value")!='jj/mm/aaaa'){
					dateValidated = true;
				}
				if($("#keyDateDate").attr("value")=='jj/mm/aaaa'){
					dateValidated = false;
				}
				if(dateValidated == true && nameValidated == true){
					HomeBubble.Box.Content.keyDate.add_keyDate();
					$('#keyDateError').slideUp();
					$('.provFooterAction').slideUp();
				}
				if(dateValidated == false || nameValidated == false){
					$('#keyDateError').slideDown();
				}
				
			});
		},
		add_keyDate: function(){
			
				var name = $("#keyDateName").attr("value");
				var date = $("#keyDateDate").attr("value");
				var periodicity = $('.keyDatePeriodicity:checked').val();
				var morning = $('#keyDateReminderMorning').attr('checked');
				var day = $("#keyDateReminderDay").attr("value");
				var month = $("#keyDateReminderMonth").attr("value");
				var idUsrBubble = $("#keyDateAdd").attr("rel");


				var dateBuffer = date.split("/");
				var date = dateBuffer[2]+'/'+dateBuffer[1]+'/'+dateBuffer[0];
				
				
					strUrl =  HomeBubble.Paths.BASEWEB + 'member/provider/addkeydateajax';
					$.post(strUrl, {name: name, date: date, periodicity: periodicity, day: day, month: month, idUsrBubble: idUsrBubble, morning: morning }, function(data){
		   				$("#keyDateDate").attr("value","jj/mm/aaaa");
		   				$("#keyDateName").attr("value","Nom");
		   				$("#keyDateReminderMonth").attr("value", "");
		   				$("#keyDateReminderDay").attr("value", "");
		   				$('.keyDatePeriodicity:checked').attr("checked","");
		   				$('.keyDatePeriodicity:[value=0]').attr("checked","checked");
		   				$('#keyDateReminderMorning').attr("checked","");
		   				$('#keyDatePeriodicity').slideUp();
						$('#keyDateReminder').slideUp();
						$('#provFooterActionLeftKeyDate').css("display","none");	
					//	$('#keyDateNextDate').html('<div class="genLoading"></div>');	
		 				 HomeBubble.Box.Content.keyDate.update_keyDate();
		 			//	HomeBubble.Box.Content.keyDate.edit_keyDate_button();
		
		 				
					 });
				
			
		},
		update_keyDate: function(page){
					$('#keyDateNextDate').html('<div class="genLoading"></div>');
					if(page == null){
						page = 1;
					}
					var idUsrBubble = $("#keyDateAdd").attr("rel");
					
					strUrl = HomeBubble.Paths.BASEWEB + 'member/provider/getlistkeydateajax';
					//See all the elements
					if(page == 'all'){

						$('#keyDateNextDate').load(strUrl, { update: true, page: page, idUsrBubble: idUsrBubble }, function(){				
								$('.keyDateViewNext').css("display", "none");
								$('.keyDateViewFirst').css("display", "block");
								
								$('#keyDateNextDate').slideDown();
								HomeBubble.Box.Content.keyDate.edit_keyDate_button();

						});
					}
					//See the first elements
					else{
						$('#keyDateNextDate').load(strUrl, { update: true, page: page, idUsrBubble: idUsrBubble }, function(){
								
							$('.keyDateViewNext').css("display", "block");
							$('.keyDateViewFirst').css("display", "none");
							$('#keyDateNextDate').slideDown();
								HomeBubble.Box.Content.keyDate.edit_keyDate_button();
		
						});
					}

					
		},
		edit_keyDate_modal: function(idEvent){
		

		strUrl = HomeBubble.Paths.BASEWEB + 'member/provider/keydateeditmodal';
		$('#provKeyDateModalEdit').load(strUrl, { idEvent: idEvent}, function(){
			
			
		}).dialog({
								bgiframe: true,
								autoOpen: true,
								height: 'auto',
								draggable: true,
								resizable: true,
								width: 350,
								modal: true,
								closeOnEscape: false,
								buttons: {
										
											"Valider": function() {
													HomeBubble.Box.Content.keyDate.edit_keyDate(idEvent);
													
													$(this).dialog('destroy');
				
										},
												
											
											"Annuler": function() {
											$(this).dialog('destroy');
											//$('.portlet').fadeIn();
										}
										
									},
								close: function(){
									$(this).dialog('destroy');
									$('#ui-datepicker-div ').css('display', 'none');
								}
			
			
		});

		},
		edit_keyDate: function(idEvent){
			
			var name = $('#editKeyDateTitle').attr("value");
			var date = $('#editKeyDateDate').attr("value");
			var hasChild = $('.editKeyDateHasChild:checked').val();
    		var isChild = $('.editKeyDateIsChild:checked').val();
   			var idEventParent = $('.editKeyDateTitle').attr('rel');
			var morning = $('#editKeyDateReminderMorning').attr('checked');
			var day = $("#editKeyDateReminderDay").attr("value");
			var month = $("#editKeyDateReminderMonth").attr("value");
			var numberOfChildEvent = $('.editKeyDateDate').attr('rel');
			var periodicity = $('.editPeriodicityInfo').attr('rel'); // To save the periodicity when edit an event
			var idUsrBubble = $('#editKeyDateContainerRightInputHidden').attr('rel');
			var dateBuffer = date.split("/");
			var date = dateBuffer[2]+'/'+dateBuffer[1]+'/'+dateBuffer[0];
			
			if(morning==true){
    		morning=1;
    		}
    		if(morning==false){
    		morning=0;
    		}
			strUrl = HomeBubble.Paths.BASEWEB+'member/provider/keydateeditajax';
			
			$.post(strUrl, {idEvent: idEvent,idUsrBubble: idUsrBubble, name : name, date: date, morning: morning, day: day, month: month, hasChild: hasChild, isChild: isChild, idEventParent: idEventParent, numberOfChildEvent: numberOfChildEvent, periodicity: periodicity}, function(){
			//	$('#keyDateNextDate').html('<div class="genLoading"></div>');
				HomeBubble.Box.Content.keyDate.update_keyDate();
			});
	
		},
		edit_modal_behaviour: function(){
		
		// Datepicker in Edit Modal
	 	$.datepicker.setDefaults($.extend({showMonthAfterYear: false}, $.datepicker.regional['fr']));
		$('#editKeyDateDate').datepicker({
					changeMonth: true,
					changeYear: true
		});
				
		//Display Reminder if the user wants
		$('#editKeyDateReminderAdd').click(function(){
				
				$('#editKeyDateExtraInfo').fadeIn();
	
		});
			
		//Erase value of reminder on click on reminder none					    
		$('#editKeyDateReminderNone').click(function(){
				
				$('#editKeyDateReminderMorning').attr("checked","");
				$('#editKeyDateReminderDay').attr("value","");
				$('#editKeyDateReminderMonth').attr("value","");
				
				$('#editKeyDateExtraInfo').fadeOut();
	
		});

		//If reminder add is selected, reminders are showed
		if($('#editKeyDateReminderAdd').attr('checked') == true){
				
				$('#editKeyDateExtraInfo').fadeIn();
		}
	
		},delete_keyDate_modal: function(idEvent){
			
		strUrl = HomeBubble.Paths.BASEWEB + 'member/provider/deletekeydatemodal';

		$('#provKeyDateModalDelete').load(strUrl , { idEvent: idEvent } ).dialog({
					
						bgiframe: true,
						autoOpen: true,
						height: 'auto',
						draggable: true,
						resizable: true,
						width: 420,
						modal: true,
						closeOnEscape: false,
						buttons: {
									/***  Bouton Valider et ses options  ***/
									
									"Valider": function() {
	
									HomeBubble.Box.Content.keyDate.delete_keyDate(idEvent);
									$(this).dialog('destroy');
				
								},
										
									/***  Bouton annuler et ses options  ***/	
										
									"Annuler": function() {
									$(this).dialog('destroy');
									//$('.portlet').fadeIn();
								}
								
							},
					close: function(){
						
							$(this).dialog('destroy');
					}

				});	
			
			
		},delete_keyDate: function(idEvent){
			
 			strUrl = HomeBubble.Paths.BASEWEB + 'member/provider/deletekeydateajax/';
   			var hasChild = $('.deleteKeyDateHasChild:checked').val();
			var idEventParent = $(".keyDateIdEventParent").attr("id");
			var booChildren = $("#keyDateBooChildren").attr("value");
			var dateUs = $("#keyDateUs").attr("value");
			$.post(strUrl, { idEvent: idEvent, hasChild: hasChild, idEventParent: idEventParent, booChildren: booChildren, dateUs: dateUs },function(data){
				  if(data == 'deleted' ){
					  	//Update the list of key dates
					   	HomeBubble.Box.Content.keyDate.update_keyDate();
				 	  	
					  } 
   			});
   			
		},edit_keyDate_button: function(){
			strUrl = HomeBubble.Paths.BASEWEB + 'member/provider/editkeydatebuttonajax';
			var idUsrBubble = $('#idUsrBubble').attr('value');
			
			$.post(strUrl, { update: true, idUsrBubble: idUsrBubble },function(data){
				
				
						if(data.menu == 'show'){
						 	$("#editKeyDateButtons").css('display','inline');
						//	alert( data.menu + '-> show');
						}else{
						//	alert(data.menu + '-> hide');
							$("#editKeyDateButtons").hide();						
						}
						
			//	$('#editKeyDateButtons')
				
   			}, 'json');
   			
		},keyDate_list_behaviour: function(){
			
			//Edit a keydate
			$('.keyDateEditButton').click(function(){
				var idEvent = $(this).attr('rel');
				HomeBubble.Box.Content.keyDate.edit_keyDate_modal(idEvent);
			});
			//Delete a keydate
			$('.keyDateDeleteButton').click(function(){
				var idEvent = $(this).attr('rel');
				HomeBubble.Box.Content.keyDate.delete_keyDate_modal(idEvent);
			});
								
			//See all the keydates
			$('.keyDateViewNext').unbind("click").click(function(){
				//$('#keyDateNextDate').html('<div class="genLoading"></div>');
				HomeBubble.Box.Content.keyDate.update_keyDate('all');
				$("#keydateNext").slideUp();
				$("#keydatePrev").slideUp();
				$('.keyDateNextDate').slideUp();
				$('.keyDateViewNext').fadeOut(function(){
					$('.keyDateViewFirst').fadeIn();
				});
			});
			
			//See the first keydates
			$('.keyDateViewFirst').unbind("click").click(function(){
				//$('#keyDateNextDate').html('<div class="genLoading"></div>');
				$('.keyDateNextDate').slideUp();

				HomeBubble.Box.Content.keyDate.update_keyDate();
				$('.keyDateViewFirst').fadeOut(function(){
					$('.keyDateViewNext').fadeIn();
					$("#keydateNext").slideDown();
					$("#keydatePrev").slideDown();
				});	
			});
	
		}

}
HomeBubble.Box.Content.Profile = {
	
		checkSession:function(){
				strUrl = HomeBubble.Paths.BASEWEB + 'member/auth/checkSession';
		//	$.post(strUrl, { update: true}, function(data){
			//	if(data.result == 'false')
				//	window.location = HomeBubble.Paths.BASEWEB;
					return true;
	//	}, 'json');
	},
		initialize: function () {


			$(function() {
				$("#profileTabs").tabs({
					select: function(event,ui){
						//	var selected = $(this).tabs('option', 'selected');
						//	alert(selected);
					}
					
				//	var selected = $tabs.tabs('option', 'selected')
					//	$(this).tabs( 'select' , '2' );
				});
			});
			

			

	},profile_view_behaviour: function(){
		
		//Modify a profil = load a new view in the div
		$('#profileAccountModify').click(function(){
			
			strUrl = HomeBubble.Paths.BASEWEB + 'member/profile/edit';
			$('#profileAccount').load(strUrl, { update: true}, function(){
				
			});

			return false;
		
		});	
		

		
		//Delete a profile
		$('#profileAccountDelete').click(function(){
		
			strUrl = HomeBubble.Paths.BASEWEB + 'member/profile/deleteprofilemodal';
			
			$('#deleteProfileModal').load(strUrl,{ update: true},function(){
				
			}).dialog({
							
								bgiframe: true,
								autoOpen: true,
								height: 'auto',
								draggable: true,
								resizable: true,
								width: 400,
								modal: true,
								closeOnEscape: false,
								buttons: {
											/***  Bouton Valider et ses options  ***/
											"Valider": function() {
												HomeBubble.Box.Content.Profile.delete_profile();
											//	$(this).dialog('destroy');
										
											
										},
												
											/***  Bouton annuler et ses options  ***/		
											"Annuler": function() {
											$(this).dialog('destroy');
											//$('.portlet').fadeIn();
										}
										
									},
								close: function(){
									$(this).dialog('destroy');
								}
						});
			return false;
		
		});	
		

	},profile_edit_behaviour: function(){
		//default behaviour
		emailNotExist = true;
		

		
		$("#profileInEmail").blur(function(){
		
			// Récupération de l'email saisi par l'utilisateur
			var email = $("#profileInEmail").val();	
			var emailCurrent = $("#emailCurrent").val();	
		

			// Envoie de l'email via ajax
			$.ajax({
				type: "POST",
				url: HomeBubble.Paths.BASEWEB + 'default/signin/checkemailajaxcorrected',
				data: "email="+ email+'&emailCurrent='+emailCurrent,
				dataType: 'json',
				success: function(data){
					//Si l'email existe déjà, on informe l'utilisateur
					if(data.result){
						emailNotExist = true;
						$('#emailResultInvalid').slideUp();
						$('#emailResult').slideUp();	
						//alert('test');
					}else{
						emailNotExist = false;
						if(data.msg == "invalid"){					
							$('#emailResultInvalid').slideDown();
						}else if( data.msg == 'exist'){
							$('#emailResult').slideDown();							
						}
					}
			
			
				}
				
			});
			
			//$.scrollTo( 'body', 800);
			
		});
		

		
		//Datepicker
		$.datepicker.setDefaults($.extend({showMonthAfterYear: false}, $.datepicker.regional['fr']));
		$('#profileBirth').datepicker({
					changeMonth: true,
					changeYear: true,
					defaultDate: '-18y',
					yearRange: '-90:+18'
		});


		//Cancel
		$('#profileAccountCancel').click(function(){

			strUrl = HomeBubble.Paths.BASEWEB + 'member/profile/account';
			$('#profileAccount').load(strUrl, { update: true}, function(){
				
			});
			
			return false;
		
		});	
		
		$('#profileEmailLabelButtonChange').click(function(){
			
			$(this).css("display", "none");
			$('#profileEmailLabelButtonNotChange').css("display","inline");
			var email = $('#profileInEmail').attr("value");
			$('#profileInEmail').attr("value","");
			$('#profileInEmail').removeAttr("readonly");
			$('#profileInEmail').removeAttr("disabled");
			
			$('#profileEmailLabelButtonNotChange').click(function(){
				$(this).css("display", "none");                                
				$('#profileEmailLabelButtonChange').css("display","inline");
				$('#profileInEmail').attr("readonly","readonly");
				$('#profileInEmail').attr("disabled","true");
				$('#profileInEmail').attr("value", email);
				$('.errorEmail').slideUp();
			});
			
			return false;
		});
		
		//Valid modifications
		$('#profileAccountValid').click(function(){
			var email = $('#profileInEmail').attr("value");
			var emailCurrent = $('#emailCurrent').attr("value");
			var civility = $('#profileCivility').attr("value");
			var firstname = $('#profileFirstName').attr("value");
			var lastname = $('#profileLastName').attr("value");
			var birth = $('#profileBirth').attr("value");
			var address = $('#profileAddress').attr("value");
			var city = $('#profileInCity').attr("value");
			var zipcode = $('#profileZipCode').attr("value");

			var dateBuffer = birth.split("/");
			var birth = dateBuffer[2]+'/'+dateBuffer[1]+'/'+dateBuffer[0];
			
				// Récupération de l'email saisi par l'utilisateur
			if(firstname == ""){
				var validFirstname = false;
				$('#profileFirstNameError').slideDown();
			}
			if(firstname != ""){
				var validFirstname = true;
				$('#profileFirstNameError').slideUp();
			}
			
	
			
			if(lastname == ""){
				var validLastname = false;
				$('#profileLastnameError').slideDown();
			}
			if(lastname != ""){
				var validLastname = true;
				$('#profileLastnameError').slideUp();
			}
				// Envoie de l'email via ajax
				strUrl =  HomeBubble.Paths.BASEWEB + 'default/signin/checkemailajaxcorrected';
		//		alert(strUrl);
				$.post( strUrl , { email:email , emailCurrent:emailCurrent }, function(data){
					
						if(data.result){
							emailNotExist = true;
							$('#emailResultInvalid').slideUp();
							$('#emailResult').slideUp();	
							//alert('test');
							strUrl = HomeBubble.Paths.BASEWEB + 'member/profile/update';
							if(emailNotExist == true && validFirstname == true && validLastname == true){
							$.post(strUrl, {email: email, civility: civility, firstname: firstname, lastname: lastname, birth: birth, address: address, city: city, zipcode: zipcode }, function(data){

								if(data == "updated"){
									strUrl2 = HomeBubble.Paths.BASEWEB + 'member/profile/account';
									$('#profileAccount').load(strUrl2, { update: true}, function(){
										$('#profileAccountSuccess').css("display","inline");
									});
								}	
								});
							}					
						
						}else{
							emailNotExist = false;
							if(data.msg == "invalid"){					
								$('#emailResultInvalid').slideDown();
							}else if( data.msg == 'exist'){
									$('#emailResult').slideDown();							
							}
							
						}
					
					
					
					
				}, 'json');
		
		
		/*		
				$.ajax({
					type: "POST",
					url:,
					data: "email="+ email+'&emailCurrent='+emailCurrent,
					dataType: 'json',
					success: function(data){
						
					
						
						
					}

				});
				*/
			//	alert(emailNotExist);
	
			
			
			return false;
			
			});	

	},profile_edit_password_behaviour:function(){
		
		$('#profileNewPassword').pstrength();
				
		var passwordValidated = false;
		var oldPasswordValidated = false;
		var lengthPasswordValidated = false;

		//valid new password
		$('#profileAccountValid').click(function(){
			var password = $('#profilePassword').attr("value");
			var newPassword = $('#profileNewPassword').attr("value");
			var confirmNewPassword = $('#profileConfirmNewPassword').attr("value");
			
			//Verification of the twho passwords : they have to be similar
			if($('#profileConfirmNewPassword').attr("value") == $('#profileNewPassword').attr("value")){
		 		$('#profilePasswordError').slideUp();
		 		passwordValidated = true;
		 	}
		 	else{
		 		$('#profilePasswordError').slideDown();
		 		passwordValidated = false;
		 	}
			//old password field not empty
			if($('#profilePassword').attr("value") != ''){
		 		$('#profilePasswordErrorPw').slideUp();
		 		oldPasswordValidated = true;
		 	}
		 		if($('#profilePassword').attr("value") == ''){
		 		$('#profilePasswordErrorPw').slideDown();
		 		oldPasswordValidated = true;
		 	}
		 	
		 	if(password.length < 6 || newPassword.length < 6 || confirmNewPassword.length <6){
		 		
		 		$('#profilePasswordErrorPwLength').slideDown();
		 		lengthPasswordValidated = false;
		 	}
		 	else{
		 		$('#profilePasswordErrorPwLength').slideUp();
		 		lengthPasswordValidated = true;
		 	}
			
			//MD5
			password = md5(password);
			newPassword = md5(newPassword);

			//Edit the new password
			if(passwordValidated == true && oldPasswordValidated == true && lengthPasswordValidated==true){
				strUrl = HomeBubble.Paths.BASEWEB + 'member/profile/editpassword';
				$.post(strUrl, {password: password, newPassword: newPassword }, function(data){
					if(data == "updated"){
						$('#profilePasswordError').slideUp();
						$('#profilePasswordErrorPw').slideUp();
						$('#profilePasswordErrorPwLength').slideUp();
						$('#profilePasswordFailure').slideUp();
						$('#profilePasswordSuccess').slideDown();
						
						$("#profileTabs").tabs( 'select' , 0 );

					}
					if(data == "not updated"){
						$('#profilePasswordError').slideUp();
						$('#profilePasswordErrorPw').slideUp();
						$('#profilePasswordErrorPwLength').slideUp();						
						$('#profilePasswordSuccess').slideUp();
						$('#profilePasswordFailure').slideDown();
					}
				});
			}
			else {
			
			}
			

		});
		
		//Cancel
		$('#profileAccountCancel').click(function(){
			$('#profilePassword').attr("value", "");
			$('#profileNewPassword').attr("value", "");
			$('#profileConfirmNewPassword').attr("value", "");
			});
			return false;
	
	},delete_profile: function(){
		
		strUrl = HomeBubble.Paths.BASEWEB + 'member/profile/deleteprofileajax';
		
		$.post(strUrl, {update: true}, function(data){
			
			$('#deleteProfileModal').dialog('destroy');
			window.location = HomeBubble.Paths.BASEWEB;
			
			
		})
		
		
	},share_to_partner_behaviour: function(){
	
		//share to a partner				
		$("#profileAccountClickToShare").click(function(){
			$('#profileAccountShare').slideDown();
			return false;
		});
						
		$("#profileAccountShareCancel").click(function(){
			$('#profileAccountShare').slideUp();
			return false;
		});
		
		$("#profileAccountShareEmail").blur(function(){
		
			// Récupération de l'email saisi par l'utilisateur
			var email = $("#profileAccountShareEmail").val();	
			
			$("#emailExtraErrorInvalid").slideUp();
			$("#emailExtraError").slideUp();
			
			// Envoie de l'email via ajax
			$.ajax({
				type: "POST",
				url: HomeBubble.Paths.BASEWEB + 'default/signin/checkemailajaxcorrected',
				data: "email="+ email,
				dataType: 'json',				
				success: function(data){
					//Si l'email existe déjà, on informe l'utilisateur

					if(data.result){
						emailNotExist = true;
						$('.profileError').slideUp();
					}else{
						emailNotExist = false;

						if(data.msg == 'invalid'){
							$("#emailExtraErrorInvalid").slideDown();
						}else if(data.msg == 'exist'){
							$("#emailExtraError").slideDown();							
						}
								
					}
				}
			});
			//$.scrollTo( 'body', 800);	
		});	
	
	
		$("#profileAccountShareValid").click(function(){
		//	HomeBubble.Box.Content.Profile.share_to_partner(emailNotExist);
		
		
			var email = $('#profileAccountShareEmail').attr("value");
			var confirmEmail = $('#profileAccountShareConfirmEmail').attr("value");

			var confirmEmailValidated = false;
		//	var emailValid = HomeBubble.Box.Content.SignIn.checkEmail(email);

			if(email == confirmEmail){
				$('#profileAccountConfirmEmailError').slideUp();
				confirmEmailValidated = true;
			}
			
			if(email != confirmEmail){
				confirmEmailValidated = false;
				$('#profileAccountConfirmEmailError').slideDown();
			}

			if(  confirmEmailValidated == true  ){
				
				$.ajax({
					type: "POST",
					url: HomeBubble.Paths.BASEWEB + 'default/signin/checkemailajaxcorrected',
					data: "email="+ email,
					dataType: 'json',
					success: function(data){
						//Si l'email existe déjà, on informe l'utilisateur
						if(data.result){
							emailNotExist = true;	
							// OK
							
								$("#profileAccountShareValid").unbind('click');
								strUrl = HomeBubble.Paths.BASEWEB + 'member/profile/shareajax';
								$.post(strUrl, { email: email}, function(data){
									if(data == "ok"){
										$("#accountPartner").slideUp();
										$('#accountPartnerSuccess').slideDown();
									}
								});
													
						}else{
							emailNotExist = false;	
						}
					}

				});				
					
			}
			

			


		
		
		
		
		
		
		
		
		
			return false;
		});
	
	
	
	
	
	
	
		
	},share_to_partner: function(emailNotExist){
		var email = $('#profileAccountShareEmail').attr("value");
		var confirmEmail = $('#profileAccountShareConfirmEmail').attr("value");
		
		var confirmEmailValidated = false;
		var emailValid = HomeBubble.Box.Content.SignIn.checkEmail(email);
		
		/*
		$.ajax({
			type: "POST",
			url: HomeBubble.Paths.BASEWEB + 'default/signin/checkemailajaxcorrected',
			data: "email="+ email+'&emailCurrent='+emailCurrent,
			dataType: 'json',
			success: function(data){
				//Si l'email existe déjà, on informe l'utilisateur
				if(data.result){
					emailNotExist = true;
					$('#emailResultInvalid').slideUp();
					$('#emailResult').slideUp();	
					//alert('test');
				}else{
					emailNotExist = false;
					if(data.msg == "invalid"){					
						$('#emailResultInvalid').slideDown();
					}else if( data.msg == 'exist'){
						$('#emailResult').slideDown();							
					}
				}
		
		
			}
			
		});
		*/
		
		if(email == confirmEmail){
			$('#profileAccountConfirmEmailError').slideUp();
			confirmEmailValidated = true;
		}
		if(email != confirmEmail){
			confirmEmailValidated = false;
			$('#profileAccountConfirmEmailError').slideDown();
		}
		
		if(confirmEmailValidated == true && emailValid == true && emailNotExist == true){
			$("#profileAccountShareValid").unbind('click');
			strUrl = HomeBubble.Paths.BASEWEB + 'member/profile/shareajax';
			$.post(strUrl, { email: email}, function(data){
				
				if(data == "ok"){
					$("#accountPartner").slideUp();
					$('#accountPartnerSuccess').slideDown();
			
					
				}
				
				
			})
		}
		
		
	},archive_behaviour: function(){

			$('.profileArchUsrBubbleName').click(function(){
				
				
				idUsrBubble = $(this).attr('rel');
				
				
				//$('.profileArchUsrBubbleFileNameShow').slideUp();
				//$('.profileArchUsrBubbleFileNameShow').removeClass().addClass('profileArchUsrBubbleFileNameHidden');
				$('.profileArchUsrBubbleFileNameHidden[rel='+idUsrBubble+']').slideToggle();
				//$('.profileArchUsrBubbleFileNameHidden[rel='+idUsrBubble+']').removeClass().addClass('profileArchUsrBubbleFileNameShow');
				
				
			});
			
			
			//Edit an archive
			$('.profileArchEditButton').click(function(){
				
			var idArchive = $(this).attr('rel');
			$('#editArchive').html('<div class="genLoading"></div>');
			var profile = 1;
			HomeBubble.Box.Content.Archive.edit_modal_archive(idArchive, profile);
			});	

			
			//Delete archive
			$('.profileArchDeleteButton').click(function(){
					idArchive = $(this).attr('rel');
					$('#deleteArchive').html('<div class="genLoading"></div>');
					var profile = 1;
					HomeBubble.Box.Content.Archive.delete_modal_archive(idArchive, profile);

			});	
			
			//Send archive
			$('.profileArchEmailButton').click(function(){
				idArchive = $(this).attr('rel');
				HomeBubble.Box.Content.Archive.send_modal_archive(idArchive);
			})
			
			//Delete paper
			$('.profilePaperDeleteButton').click(function(){
					idPaper = $(this).attr('rel');

					$('#deletePaper').html('<div class="genLoading"></div>');
					var profile = 1;
					HomeBubble.Box.Content.Paper.delete_modal_paper(idPaper, profile);

			});	
			
			//Edit a paper
			$('.profilePaperEditButton').click(function(){

				var idPaper = $(this).attr('rel');	
				$('#editPaper').html('<div class="genLoading"></div>');
				var profile = 1;
				HomeBubble.Box.Content.Paper.edit_modal_paper(idPaper, profile);
			});	
			
			//Send a paper
			$('.profilePaperEmailButton').click(function(){

				var idPaper = $(this).attr('rel');	
				HomeBubble.Box.Content.Paper.send_modal_paper(idPaper);
			});
			
			$("#retrieveMyArchive").click(function(){
				strUrl = HomeBubble.Paths.BASEWEB + 'member/profile/getarchivemodal';
				$('#getArchive').load(strUrl, {update: true},function(){}).dialog({

									bgiframe: true,
									autoOpen: true,
									height: 'auto',
									draggable: true,
									resizable: true,
									width: 400,
									modal: true,
									closeOnEscape: false,
									buttons: {
												/***  Bouton Valider et ses options  ***/
												"Valider": function() {
												HomeBubble.Box.Content.Profile.retrieve_archive();
												$(this).dialog('destroy');
											},

												/***  Bouton annuler et ses options  ***/		
												"Annuler": function() {
												$(this).dialog('destroy');

											}

										},
									close: function(){
										$(this).dialog('destroy');
									}
							});
				return false;
			})
			
	},retrieve_archive: function(){
		strUrl = HomeBubble.Paths.BASEWEB + 'member/profile/getarchive';
		top.location.href = strUrl;
		
	}

}
	
HomeBubble.Box.Content.Note = {
	
		initialize: function () {
				
					
					$('#noteContainer').html('<div class="genLoadingDashboardList"></div>');
					
					strUrl = HomeBubble.Paths.BASEWEB + 'member/dashboard/note';
					idUsrBubble = $("#noteContainer").attr('rel');
					$('#noteContainer').load(strUrl, { update: true, idUsrBubble: idUsrBubble },function(data){
						
				   		//Edit a paper
					
		
					});


			},
		update_note_for_provider: function(){
			
			$('#noteProviderContainer').html('<div class="genLoadingDashboardList"></div>');
			
			strUrl = HomeBubble.Paths.BASEWEB + 'member/dashboard/note';
			idUsrBubble = $("#noteProviderContainer").attr('rel');
			$('#noteProviderContainer').load(strUrl, { idUsrBubble: idUsrBubble },function(data){
				
		   		//Edit a paper
			

			});
		}

}


HomeBubble.Box.Content.Invitation = {
	
		initialize: function () {
				
	
				$('#formButtonSubscribePartner').click(function(){
						
						var email = $('#signInPartnerEmail').attr('value');
						var password = $('#signInPassword').val();
						var confirmPassword = $('#confirmSignInPassword').val();
						var answer =  $('#answer').val();
						var question = $('#secretQuestion').attr('value');
						var firstName = $('#firstName').val();
						var lastName = $('#lastName').val();
						var birth = $('#birth').val();
						var civility = $('#civility').attr('value');
						var generalConditions = $('#generalConditions').attr('checked');
						var activationCode = $('#signInActivationCode').attr('value');
						
						var emailValid = HomeBubble.Box.Content.SignIn.checkEmail(email);
						var passwordValid = false;
						var confirmPasswordValid = false;
						var questionResult = false;
						var firstnameCheck = false;
						var lastnameCheck = false;
						var questionResult = false;
						
						if ( emailValid == false){
		 				 	$("#emailInvalid").slideDown();
		 				// 	alert('no');
						}else{
							$("#emailInvalid").slideUp();
						}

						
						 //password must be greater than 6 caracters
		 				if(password.length < 6){
		 					$('#signInPasswordError').slideDown();
		 					passwordValid=false;
		 				}
		 				 if(password.length >= 6){
		 				 	$('#signInPasswordError').slideUp();
							passwordValid=true;
		 				}
						
						//confirm password must be the same as password
					 	if(confirmPassword == password){
					 		confirmPasswordValid = true;
					 		$('#confirm_passwordResult').slideUp();
					 	}
				 	
					 	if(confirmPassword != password){
					 		confirmPasswordValid = false;
					 		$('#confirm_passwordResult').slideDown();
					 	}
					 	
					 	if(firstName == ''){
		 					$("#firstnameResult").slideDown();
		 					firstnameCheck = false;
		 				}else{
		 					firstnameCheck = true;
							 $("#firstnameResult").slideUp();	
		 				}
		 				
		 				if(lastName == ''){
		 					$("#lastnameResult").slideDown();
		 					lastnameCheck = false;
		 				}else{
		 					$("#lastnameResult").slideUp();
		 					lastnameCheck = true;	
	 					}
	 					
	 					//Si les conditions générales ne sont pas cochées, on informe l'utilisateur
						if( generalConditions == false ){
							$('#generalConditionsResult').slideDown();
						}
						
						if( generalConditions == true ){
							$('#generalConditionsResult').slideUp();
						}
						
						//Si l'utilisateur n'a pas choisit de question, on l'informe
						if( question==''){
							$('#questionResult').slideDown();
						}
						
						if( question!=''){
							$('#questionResult').slideUp();
						}
						
						if(answer == ''){
		 					$("#answerResult").slideDown();
		 					answerCheck = false;
		 				}else{
		 					$("#answerResult").slideUp();
							 answerCheck = true;	
		 				}
		 				
		 				
		 				//Cryptage du password en md5
						password = md5(password, false, false);
						answer = md5(answer, false, false);
						
						
						// Validation du formulaire et envoie des données par ajax
	 					//if ($('.signForm').valid() && generalConditions == true && question!='' && emailNotExist == true ){
	 					if ( generalConditions == true && question!='' &&  answerCheck == true && lastnameCheck == true && firstnameCheck == true && passwordValid == true && confirmPasswordValid == true && emailValid == true){
	 						strUrl= HomeBubble.Paths.BASEWEB + 'default/invitation/signinajax';
	 						$.post(strUrl, {email: email,password: password, answer: answer, question : question, firstName: firstName, lastName: lastName, birth: birth, civility: civility, generalConditions: generalConditions, activationCode: activationCode  }, function(data){
	 							if(data == 'ok'){
	 								
	 									
											$('.signForm').hide();
											$('#success h2').fadeIn(2000, function(){
													
													$('#success p').fadeIn();
													
											});
	 							}
	 							
	 							
	 							
	 						})

	 
							 }
	
					
					});
				

			}

}
HomeBubble.Box.Content.Newsletter = {
	
		initialize: function () {
			
				$('.newsEnrollButton').click(function(){
					
					var familyname = $('#newsletterName').attr("value");
					var nickname = $('#newsletterNickname').attr("value");
					var email = $("#newsletterEmail").attr("value");
					
					if(familyname == '' || nickname == '' || email == ''){
							$('#newsletterNotComplete').slideDown();
					}else{
								$('#newsletterNotComplete').slideUp();
						strUrl = HomeBubble.Paths.BASEWEB + 'footer/addnewsletter';
						$.post(strUrl, { familyname: familyname, nickname: nickname, email: email}, function(data){
						
							if (data == 'registered'){
								$('#newsletterForm').slideUp(function(){
									$('#newsletterFailure').slideUp();
									$('#newsletterSuccess').slideDown();									
								});

							}
						
							if (data == 'not registered'){
							
								$('#newsletterSuccess').slideUp();
								$('#newsletterFailure').slideDown();
							}
						
						});						
					}
					

				});

			}

}


HomeBubble.Box.Content.Service = {
	
		initialize: function () {


	},service_behaviour: function(){
		
		$('.svcInfoButton').click(function(){
			
			var idOrder = $(this).attr('rel');
				
				
				strUrl = HomeBubble.Paths.BASEWEB + 'member/service/servicedetailajax';
				$('#svcShowInfo'+idOrder).load( strUrl, {idOrder: idOrder}, function(data){
					
					$(this).slideToggle();
					
				
				});
			
		});
		
	},order_behaviour: function(){
		
		
		$("#promoLink").click(function(){
			
			$("#promoButton").slideToggle();
			$("#promoCode").slideToggle();
			
		});

		
		// Promo button is clicked
		$('#formButtonPromo').click( function(){

			var promo =  $("#promoCode").attr('value');
			var price =  $("#price").attr('value');
		
			strUrl = HomeBubble.Paths.BASEWEB + 'member/service/checkpromoajax';
			$.post( strUrl, {promo: promo , price:price}, function(data){
			
		
			if(data.promo_exist == "no"){
		
				$(".promoFail").slideDown(function(){
					
					$(this).oneTime('4s', function(){
						$(this).slideUp();
					});
					
				});
				
			}else{
				
				$(".promoOk").slideDown();
				$("#promoPercent").attr( 'value', data.percent + '% de rÃ©duction ');
				$("#promoReductionFigure").attr('value' , data.reduction + ' Euros');
				$("#totalPrice").attr('value', data.price + ' Euros');
				$("#vat").attr('value', data.vat + ' Euros');	
				$("#newPrice").attr('value', data.price);
				
			}			
				
			}, "json");
			
			
			return false;
			
		});
		
		//Order button is clicked
		$("#svcOrderButton").click(function(){
	
			var promo =  $("#promoCode").attr('value');
			var price =  	$("#price").attr('value');
			var newPrice =	$("#newPrice").attr('value');
			var serviceName  = $("#serviceName").attr('value');
			
			
			
			strUrl = HomeBubble.Paths.BASEWEB + 'member/service/createorderajax';
			$.post( strUrl, { promo:promo, price:price , newPrice:newPrice, serviceName : serviceName } , function(data){
			
				if (data.cookieDone == 'success') {
					
					window.location = HomeBubble.Paths.BASEWEB+"membre/service/information/";
					
					
				}else{
					
					
					
				}
				
			}, "json");
			
			
			
		});
		
		
		
		
	},recap_behaviour: function(){
		
		$("#svcOrderNow").click(function(){
				
			strUrl = HomeBubble.Paths.BASEWEB + "member/service/placeorderajax";
			$.post( strUrl , { update:true } , function(data){
				
					if(data.placeOrder == 'success'){
						
						if( data.price != 0 ){
				
							//add invoice number to avoid duplicate payment in paypal
							$("#svcInvoiceNumber").attr( 'value' , data.invoiceNumber );
							
							// add invoice number to return url
							var returnUrl = $("#svcReturnUrl").attr('value');
							$("#svcReturnUrl").attr('value', returnUrl + data.invoiceNumber + '/');
						
							//add invoice number to cancel return url
							var cancelReturnUrl = $("#svcCancelReturnUrl").attr('value');
							$("#svcCancelReturnUrl").attr('value', cancelReturnUrl + data.invoiceNumber + '/');
						
							
							$('#paypalSubmitButton').trigger('click');
							
						}else if( data.price == 0){
							
							window.location = HomeBubble.Paths.HOST_LINK+"membre/service/commande/validation/"+data.invoiceNumber+"/";
							
							//alert('null mon pote');
							
							
						}
						
					}else{
						
						$("#svcErrorPlaceOrder").slideDown();
												
					}
				
				
			}, 'json');
			
			
			
		});
		
		
		
		
		

	},edit_behaviour: function(){
		
		//share to a partner				
		$("#profileAccountClickToShare").click(function(){
			$('#profileAccountShare').slideDown();
			return false;
		});
		
		
							
		$("#profileAccountShareCancel").click(function(){
			$('#profileAccountShare').slideUp();
			return false;
		});
		
		emailNotExist = true;
		$("#profileInEmail").blur(function(){
		
			// Rï¿½cupï¿½ration de l'email saisi par l'utilisateur
			var email = $("#profileInEmail").val();	
			var currentEmail = $("#currentEmail").val();

			if(email != currentEmail){
				
						// Envoie de l'email via ajax
				$.ajax({
					type: "POST",
					url: HomeBubble.Paths.BASEWEB + 'default/signin/checkemailajax',
					data: "email="+ email,
					success: function(data){
						//Si l'email existe dï¿½jï¿½, on informe l'utilisateur
						if(data == "not ok"){
							emailNotExist = false;
							$('#emailResult').slideDown();
						}
						// Sinon tout va bien
						if (data == "ok"){	
							emailNotExist = true;
							$('#emailResult').slideUp();
	
						}
					}
					
				});
				
			
					
			}
		
			
		});


		//Cancel
		$('#profileAccountCancel').click(function(){

			strUrl = HomeBubble.Paths.BASEWEB + 'member/profile/account';
			$('#profileAccount').load(strUrl, { update: true}, function(){
				
			});
			
			return false;
		
		});	
		
	
		
		//Valid modifications
		$('#svcValidData').click(function(){
		//	alert('yes');
		
			var email = $('#profileInEmail').attr("value");
			var civility = $('#profileCivility').attr("value");
			var firstname = $('#profileFirstName').attr("value");
			var lastname = $('#profileLastName').attr("value");
			var birth = $('#profileBirth').attr("value");
			var address = $('#profileAddress').attr("value");
			var city = $('#profileInCity').attr("value");
			var zipcode = $('#profileZipCode').attr("value");
			var dateBuffer = birth.split("/");
			var birth = dateBuffer[2]+'/'+dateBuffer[1]+'/'+dateBuffer[0];			
			var serviceName = $("#serviceName").attr("value");
			
			
			if(firstname == ''){
		 		$("#firstnameResult").slideDown();
		 		firstnameCheck = false;
		 	}else{
		 		firstnameCheck = true;
				$("#firstnameResult").slideUp();	
		 	}

			if(lastname == ''){
				$("#lastnameResult").slideDown();
				lastnameCheck = false;
			}else{
				$("#lastnameResult").slideUp();
				lastnameCheck = true;	
			}
			
			if(address == ''){
				$("#addressResult").slideDown();
				addressCheck = false;
			}else{
				$("#addressResult").slideUp();
				addressCheck = true;	
			}			
		
			if(zipcode == ''){
				$("#zipcodeResult").slideDown();
				zipcodeCheck = false;
			}else{
				$("#zipcodeResult").slideUp();
				zipcodeCheck = true;	
			}
			
			if(city == ''){
				$("#cityResult").slideDown();
				cityCheck = false;
			}else{
				$("#cityResult").slideUp();
				cityCheck = true;	
			}	
			
			strUrl = HomeBubble.Paths.BASEWEB + 'member/profile/update';
					if( cityCheck == true &&  zipcodeCheck == true && lastnameCheck == true && firstnameCheck == true && addressCheck == true){
						$.post(strUrl, {email: email, civility: civility, firstname: firstname, lastname: lastname, birth: birth, address: address, city: city, zipcode: zipcode }, function(data){
							
							if(data == "updated"){
								
								strUrl2 = HomeBubble.Paths.BASEWEB + 'membre/service/recapitulatif/';
								window.location = strUrl2
								
							}	
						});
			}
				return false;
			
			});	

	}

}
	
HomeBubble.Box.Content.Sfr = {
	
		initialize: function () {
				
				
				
				$("#provSfrPostButton").click(function(){
				
					    phone = $(this).attr('rel');
						// Sending the SMS
					    idUsrBubble = $("#idUsrBubble").attr('value');
					    idProvider = $("#idProvider").attr('value');
					
						HomeBubble.Box.Content.Sfr.sendsms(phone, idProvider, idUsrBubble);
									
				});
				
				$('#receiveSfrCodeAgain').click(function(){
					
						phone		= $("#provSfrPostButton").attr('rel');
						idUsrBubble = $("#idUsrBubble").attr('value');
						idProvider = $("#idProvider").attr('value');
						strUrl = HomeBubble.Paths.BASEWEB + 'member/provider/sfrresendsmsajax';	
						$.post( strUrl ,{ phone : phone, idUsrBubble : idUsrBubble, idProvider : idProvider },
						 function(data){

							if(data.result == "true"){
								
								$('#receiveSfrAgain').fadeOut();
								HomeBubble.Box.Content.Sfr.modalcode(phone, idProvider, idUsrBubble);
								
							}else if(data.result == 'false')
								
									$("#provApiConnectError").slideDown(function(){
										$(this).oneTime('4s', function(){
											$(this).slideUp();
										});
									});


							}, "json");
					
					return false;
				});
						
				

		},sendsms: function(){
			
			
				if ( phone == ''){
					
					$('#provApiInfoProblem').css('color','#B80047');
					$('#provApiInfoProblem').fadeOut(1000, function(){
						$(this).css('color','#000');
						$(this).fadeIn();
					});
					
				}else if(phone.length != 10 ){
					
					$('#provApiInfoProblem').css('color','#B80047');
					$('#provApiInfoProblem').fadeOut(1000, function(){
						$(this).css('color','#000');
						$(this).fadeIn();
					});
					
				}else{
				
				strUrl = HomeBubble.Paths.BASEWEB + 'member/provider/smssfr';				
				$.post( strUrl ,{ phone : phone, idUsrBubble : idUsrBubble, idProvider : idProvider },
				 function(data){
					
				    //stuff to do *after* page is loaded;
					//	alert(data.send);
					
						if(data.send == "askCode" || data.send == "true"  ){
						
							HomeBubble.Box.Content.Sfr.modalcode(phone, idProvider, idUsrBubble);
							//alert('yes true');
						
						}else if(data.send == 'askSMSNew'){
						
						 //	alert('Resend the sms ?');
						
						}else if(data.send == "SMSdeletedAndResend"){
								
						}else if(data.send == "sfrError"){
							
							$("#provApiConnectError").slideDown(function(){
								$(this).oneTime('4s', function(){
									$(this).slideUp();
								});
							});
						}
						
					}, "json");				
					
				}
			
			
		},
		modalcode: function(phone, idProvider, idUsrBubble){
			
						// Modal to confirm the sms sent previously	
						$('#provSfr').html('<div class="genLoading"></div>');
						
						strUrl = HomeBubble.Paths.BASEWEB + 'member/provider/modalsfr';				
						$('#provSfr').load(strUrl , { phone : phone , idProvider : idProvider, idUsrBubble: idUsrBubble } ).dialog({
						
							bgiframe: true,
							autoOpen: true,
							width: 350,
							height: 200,
							draggable: true,
							resizable: true,
							modal: true,
							closeOnEscape: false,
							buttons: {
									/***  Bouton Valider et ses options  ***/						
									"Valider": function() {
										
										HomeBubble.Box.Content.Sfr.codeSubmission(phone, idProvider, idUsrBubble);
									},
											
									/***  Bouton annuler et ses options  ***/	
											
									"Annuler": function() {
										$(this).dialog('destroy');
									}
													
							},
							close: function(){
									$(this).dialog('destroy');
							}
		
							});
							
							
							
			
			
		},
		codeSubmission: function(phone, idProvider, idUsrBubble){
			
			smsCode = $('#smsUserCode').attr('value');
			
			
			
			strUrl = HomeBubble.Paths.BASEWEB + 'member/provider/sfrsmsajax';				
			$.post(strUrl,{	 phone: phone, idProvider: idProvider , idUsrBubble: idUsrBubble, smsCode : smsCode },
			 function(data){
				
				if (data.result == "failed"){
					$("#provSfrCodeError").slideDown();
				}else if(data.result == 'success'){
					
					// on success update the block
					$('#provSfr').dialog("destroy");
					HomeBubble.Box.Content.Provider.update_api();
					
				};
				
			}, 'json');
			

			
			
			
			
		},
		modalnewsms: function(phone, idProvider, idUsrBubble){
			
			
					 
					 $('#provSfrSms').html('<div class="genLoading"></div>');
					 strUrl = HomeBubble.Paths.BASEWEB + 'member/provider/sfrsms';
					$('#provSfrSms').load(strUrl , {  phone : phone , idProvider : idProvider, idUsrBubble: idUsrBubble} ).dialog({
				
							bgiframe: true,
							autoOpen: true,
							width: 550,
							minHeight: 150,
							height: 'auto',
							draggable: true,
							resizable: true,
							modal: true,
							closeOnEscape: false,
							buttons: {
										/***  Bouton Valider et ses options  ***/
										
										"Oui": function() {
		
											// RESEND THE SMS and REPOEN CODE VALIDATION MODAL
					
									},
											
										/***  Bouton annuler et ses options  ***/	
											
										"Non": function() {
										$(this).dialog('destroy');
										
										// REPOEN CODE VALIDATION MODAL
										
									}
									
								},
						close: function(){
							
								$(this).dialog('destroy');
						}
	
					});	
			
			
		}

}
HomeBubble.Box.Content.Testimony = {
	
	initialize: function () {
		
		$('.navNumber').live('click', function(){
			
			var page = $(this).attr('rel');
			
			strUrl = '/index/testimonyajax';
			$('#testimonyContainer').load(strUrl,{page: page}, function(){
	
			});
			
			return false;
		});
		
		$('.navHistoryNext').live('click', function(){

			var page = $(this).attr('rel');
			strUrl = '/index/testimonyajax';
			$('#testimonyContainer').load(strUrl,{page: page}, function(){
	
			});
			
			return false;
		});
		
		$('.navHistoryPrev').live('click', function(){

			var page = $(this).attr('rel');
			strUrl = '/index/testimonyajax';
			$('#testimonyContainer').load(strUrl,{page: page}, function(){
	
			});
			
			return false;
		});
		
		$('#submitTestimony').click(function(){
			
			$("#testimonySuccess").slideUp();
			
			var firstNameValidated = false;
			var lastNameValidated = false;
			var emailValidated = false;
			var zipCodeValidated = false;
			var testimonyValidated = false;
			
			firstName = $("#inputTestimonySurname").attr('value');
			lastName = $("#inputTestimonyName").attr('value');
			email = $("#inputTestimonyEmail").attr('value');
			zipCode = $("#inputTestimonyZipCode").attr('value');
			testimony = $("#inputTestimonyContent").attr('value');
			
			if(firstName == ""){
				firstNameValidated = false;
				$('#firstNameError').slideDown();
			}
			else if(firstName != ""){
				firstNameValidated = true;
				$('#firstNameError').slideUp();
			}
			
			if(lastName == ""){
				lastNameValidated = false;
				$('#familyNameError').slideDown();
			}
			else if(lastName != ""){
				lastNameValidated = true;
				$('#familyNameError').slideUp();
			}			
			
			if(email == ""){
				emailValidated = false;
				$('#emailError').slideDown();
			}
			else if(email != ""){
				
				if(HomeBubble.Box.Content.SignIn.checkEmail(email)){
					emailValidated = true;
					$('#emailError').slideUp();
				}else{
					emailValidated = false;
					$('#emailError').slideDown();
				}
				
			}
			
			if(zipCode == ""){
				zipCodeValidated = false;
				$('#zipCodeError').slideDown();
			}
			else if(zipCode != ""){
				if((zipCode > 00 && zipCode < 1000 && zipCode.length > 1)){
					zipCodeValidated = true;
					$('#zipCodeError').slideUp();						
				}
				else{
					zipCodeValidated = false;
					$('#zipCodeError').slideDown();
				}

			}
			
			if(testimony == ""){
				testimonyValidated = false;
				$('#testimonyError').slideDown();
			}
			else if(testimony != ""){
				testimonyValidated = true;
				$('#testimonyError').slideUp();
			}
			
			if(firstNameValidated == true && lastNameValidated == true && emailValidated == true && zipCodeValidated == true && testimonyValidated == true){
				
				strUrl = "/index/addtestimonyajax";
				$.post(strUrl, {firstName: firstName, lastName: lastName, email: email, zipCode: zipCode, testimony: testimony},function(data){
					if(data.result == true){
						$('#testimonyFailed').slideUp();
						$("#testimonySuccess").slideDown();
						
						$("#inputTestimonySurname").attr('value', '');
						$("#inputTestimonyName").attr('value', '');
						$("#inputTestimonyEmail").attr('value', '');
						$("#inputTestimonyZipCode").attr('value', '');
						$("#inputTestimonyContent").attr('value', '');
					}
					else if(data.result == false){
						$("#testimonySuccess").slideUp();
						$('#testimonyFailed').slideDown();
					}
				},'json')
			}
			
			return false;
		});
    }
}

