
// 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 () {
				
	
			$("#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 = {
	initialize: function () {
	
	

	$('.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",
						"../../images/front/pco/bubbles/bank.jpg",
						"../../images/front/pco/bubbles/bank_hover.png",
						"../../images/front/pco/bubbles/bank_hover.jpg",
						"../../images/front/pco/bubbles/children_hover.png",
						"../../images/front/pco/bubbles/children_hover.jpg",
						"../../images/front/pco/bubbles/health_hover.png",
						"../../images/front/pco/bubbles/health_hover.jpg",
						"../../images/front/pco/bubbles/health_hover.png",
						"../../images/front/pco/bubbles/health_hover.jpg",
						"../../images/front/pco/bubbles/home_hover.png",
						"../../images/front/pco/bubbles/home_hover.jpg",
						"../../images/front/pco/bubbles/organisation_hover.png",
						"../../images/front/pco/bubbles/organisation_hover.jpg",
						"../../images/front/pco/bubbles/security_hover.png",
						"../../images/front/pco/bubbles/security_hover.jpg",
						"../../images/front/pco/bubbles/shopping_hover.png",
						"../../images/front/pco/bubbles/shopping_hover.jpg",
						"../../images/front/pco/bubbles/transport_hover.png",
						"../../images/front/pco/bubbles/transport_hover.jpg",
						
						"../../images/front/gui/btn/genFooterLeft.png",
						"../../images/front/gui/btn/genFooterMid.png",
						"../../images/front/gui/btn/genFooterRight.png",
						"../../images/front/gui/btn/genSearchHover.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' , '#A4184A');
				
				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();
		
		//************************ 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();	
		

			// 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);
			
		});
		
						//************************ 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();	
		

			// 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;
					}
					// Sinon tout va bien
					if (data == "ok"){	
						extraEmailNotExist = true;
						$('#emailExtraError').slideUp();

					}
				}
				
			});
			
			//$.scrollTo( 'body', 800);
			
		});
		
		//************************ 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();
				}
				
				// 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){
										if(data == "ok"){
											// 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();
			
		});
		
		HomeBubble.Box.Content.SignIn.blinkLogin();



	
	},
	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;
					
		});
		
	},major: function(){
	
		$("#genEmail").focus(function() {
			if($(this).attr("value") == $(this).attr("alt")) {
				$(this).attr("value", "");
			}
		});
		
		$("#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(){
			
			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{
				
				$("#genLoginContent").fadeOut('500', function(){
				//	$("#genLoginHover").html('<div class="genLoadingLogin"></div>');
					
					
						$("#genLoginHover").fadeIn();	
							
						
				String.prototype.reverse = function(){
					splitext = this.split("");
					revertext = splitext.reverse();
					reversed = revertext.join("");
					return reversed;
				}
				
				
				x = new String('This is a test.');
			//	document.write(x.reverse());
				
				
				email = $("#genEmail").attr('value');
				password = md5($("#genPassword").attr('value'));
				inverse = password.reverse();
			//	alert(inverse);
					
				strUrl = $("#genLoginForm").attr('action');
				$.post( strUrl , {email: email , password: inverse} , function(data){
					if(data == 'true'){
					
					//	alert('yes');
						$('#genLoginError').slideUp();
						
						window.location = HomeBubble.Paths.HOST_LINK+"membre/bulle/organisation/";
					//	window.location = "http://www.home-bubble.com/membre/";

					}else{
						
						
						$("#genLoginHover").fadeOut( 'normal' ,  function(){
							
							$("#genLoginContent").fadeIn();	
							$('#genLoginError').slideDown();
							
						});
	
					//	alert('no');
					}
					
					
				});

				});
				
			}
			
			return false;	
		});
	
	}
 
}



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: 400,
								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){

					$('.profileArchUsrBubbleFileName[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'){
											$("#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);
							});							
									});
							
					});

			},
			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();
									
								}
 							  	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){
				
				
				
				
				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: 620,
								height:450,
								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);
																}

															}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){


			    			$( "#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 
					        success:  function(data){
									$("#paperWaitContainer").fadeOut();
									if(data == 'ok'){

											$( "#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');
													HomeBubble.Box.Content.Archive.update_archive(show);
												});
											 	//alert('destroy');
											}



										}else{
											
											$("#fileUploadError"+idForm).slideDown();

										}
									}  
							}

							$("#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-header .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: 550,
						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(){
			
			//	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,
						autoOpen: true,
						width: 615,
						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'){
						$("#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'){
						$("#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: 400,
								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',
								draggable: true,
								resizable: true,
								width: 400,
								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');
											//$('.portlet').fadeIn();
										}
										
									},
								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: 400,
			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) {
						
						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();
    	strUrl = HomeBubble.Paths.BASEWEB + 'member/dashboard/updatenote';
    	
    	$.post(strUrl, {text: text}, 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.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'){
											$("#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: 400,
					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: 400,
					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'){
									$("#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);
						});	
						});
		
					});

    },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: 400,
								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){
										
					strUrl = HomeBubble.Paths.BASEWEB + 'member/profile/archive';
					$('#profileArchive').load(strUrl,{update: true},function(data){
						
					});
																
				}		
    		
    	});
    	
    	
    },add_modal_paper:function(){
    	
		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: 620,
								height: 450,
								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.Paper.add_paper(i);
												}
													
												}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){
    	

    			$( "#fileWaitUpload" + idForm ).fadeIn();

  				strUrl =  HomeBubble.Paths.BASEWEB + 'member/paper/uploadtempajax';
	    		
				var options = { 
		        url:        strUrl,  // target element(s) to be updated with server response 
		        //beforeSubmit:  showRequest,  // pre-submit callback 
		        success:  function(data){
						$("#paperWaitContainer").fadeOut();
						if(data == 'ok'){
							
								$( "#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');
										HomeBubble.Box.Content.Paper.update_paper(show);
									});
								 	//alert('destroy');
								}
								
										
		    				
							}else{
									$("#fileUploadError"+idForm).slideDown();
								
							}
						}  
				}
				
				$("#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();
					
				}
				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="genLoadingDashboardCalendar"></div>');
			$(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(){
		
						$("#datepickerCalendar").datepicker( {
						//	haystack = data,
							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','#CB8791');
							// 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="genLoadingDashboardCalendar"></div>');
					url = HomeBubble.Paths.BASEWEB + 'member/calendar/showcalendar';
					$('#dashContentCalendar').load(url,{update: true}, function(){
						
						$("#datepickerCalendar").datepicker( {
							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: 270,
			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: 300,
			width: 470,
			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', [490]);
			 	$('#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', [270]); 
					}
					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)
		$("#eventNextTest").click(function(){
						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);	
															
		});
		
		$("#eventPrevTest").click(function(){

						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);						
		});
		
		//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);
		});	

    	
    },update_event: function(showList, page){
    	
					$('#dashContentEvent').html('<div class="genLoadingDashboardList"></div>');
					
					if(page == null){
						page = 1;
					}
	
					strUrl = HomeBubble.Paths.BASEWEB + 'member/calendar/getlistajax';
					
					$('#dashContentEvent').load(strUrl, { update: true, page: page },function(data){
						
				   		//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 = 3;
						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).val()==''){
	    	 		$('#addEventTitleError').slideDown();
	    	 		nameValidated = false;
	    	 	}
	    	 	if($(this).val()!=''){
	    	 		$('#addEventTitleError').slideUp();
	    	 		nameValidated = true;
	    	 }
	    	 
	    	  }); 
	    	 
	    	 $('#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;
	    	 }
    	 	}); 
    	 	
    		$('#addEventStartTime').timeEntry({
    			show24Hours: true
    			
    		});
    		
    		$('#addEventEndTime').timeEntry({
    			show24Hours: true
    			
    		});



		}).dialog({
							
								bgiframe: true,
								autoOpen: true,
								height: 'auto',
								draggable: true,
								resizable: true,
								width: 490,
								modal: true,
								position: [middleWidth,middleHeight],
								minHeight: 250,
								minWidth: 250,
								closeOnEscape: false,
								buttons: {
											/***  Bouton Valider et ses options  ***/
											"Valider": function() {
												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;
    	}

    	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: 490,
								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){
    	
    	//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();

		$.post(strUrl, { idEvent: idEvent, hasChild: hasChild }, 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>');
		   	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();
								$('#authSuccessChange').slideDown();
							}
							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();

					
					$("#modifyProviderButton").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: 550,
							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');
							}
		
						});
							
					});
					

			},
		modify_provider_info:function(customName,customNameSeo){
			
			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();
						// 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
								    // $('.provDetailsLink').slideDown();
									HomeBubble.Box.Content.Provider.password_retrieve();

								});
						//alert(apiLink);
						}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();					
						$("#provFromPostButton").click(function(){
							
							//$(".genRightBot", this).html('');
							$("#provFromPost").submit();
								
						});
				
			});

			
			
		},
		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();
				$('#provFooterActionLeftKeyDate').css("display","block");	
				$("#keyDateHint").show();
				
			});
			
						//display or remove periodicity
			$("#keyDateCancelText").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();
				$('#provFooterActionLeftKeyDate').slideUp();
				$("#keyDateHint").hide();
				$('#keyDateHintText').hide();
				
			});
			
			//See all the keydates
			$('.keyDateViewNext').click(function(){
				//$('#keyDateNextDate').html('<div class="genLoading"></div>');
				HomeBubble.Box.Content.keyDate.update_keyDate(2);
				$('.keyDateNextDate').slideUp();
				$('.keyDateViewNext').fadeOut(function(){
					$('.keyDateViewFirst').fadeIn();
				});
			});
			
			//See the first keydates
			$('.keyDateViewFirst').click(function(){
	
				//$('#keyDateNextDate').html('<div class="genLoading"></div>');
				$('.keyDateNextDate').slideUp();
				HomeBubble.Box.Content.keyDate.update_keyDate();
				$('.keyDateViewFirst').fadeOut(function(){
					$('.keyDateViewNext').fadeIn();
				});	
			});
			

			$(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;
				}
		
			});


			//Add a key date
			$("#keyDateAddText").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();
				}
				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){
					
					if(page == null){
						page = 1;
					}
					var idUsrBubble = $("#keyDateAdd").attr("rel");
					
					strUrl = HomeBubble.Paths.BASEWEB + 'member/provider/getlistkeydateajax';
					//See the first elements
					if(page==1){
						$('#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();
		
						});
					}
					//See all the elements
					if(page==2){
						
						$('#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();

						});
					}
					
		},
		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: 300,
								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();
   			
			$.post(strUrl, { idEvent: idEvent, hasChild: hasChild },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(2);
				$('.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();
				});	
			});
	
		}

}
HomeBubble.Box.Content.Profile = {
	
		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
			
				// 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){
						
						
						if(data.result){
							emailNotExist = true;
							$('#emailResultInvalid').slideUp();
							$('#emailResult').slideUp();	
							//alert('test');
							strUrl = HomeBubble.Paths.BASEWEB + 'member/profile/update';
							if(emailNotExist == 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();							
							}
							
						}
						
						
						
					}

				});
			//	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);

			});	
			
			//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);
			});	
			
	}

}
	
HomeBubble.Box.Content.Note = {
	
		initialize: function () {
				
					
					$('#noteContainer').html('<div class="genLoadingDashboardList"></div>');
					
					strUrl = HomeBubble.Paths.BASEWEB + 'member/dashboard/note';
					idFamily = $("#noteContainer").attr('rel');
					$('#noteContainer').load(strUrl, { idFamily: idFamily },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");
					
					strUrl = HomeBubble.Paths.BASEWEB + 'footer/addnewsletter';
					$.post(strUrl, { familyname: familyname, nickname: nickname, email: email}, function(data){
						
						if (data == 'registered'){
							$('#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');
						}
	
					});	
			
			
		}

}
