

HomeBubble.Box.Content.Calendar = {

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

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

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

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

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

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

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

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

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

    },show_modal_event:function(date){

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

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

		});

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


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

		});

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

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

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

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

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

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

    }
}

HomeBubble.Box.Content.Event = {

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

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

    	
    },button_initialize:function(){
		$("#eventNext").click(function(){
						$('#eventLoader').fadeIn();
						page = $("#eventPaginationNext").attr('rel');
						var showList = 1; // variable which permits to show or not the list after the upload of this one
						HomeBubble.Box.Content.Event.update_event(showList, page);	
															
		});
		
		$("#eventPrev").click(function(){
						$('#eventLoader').fadeIn();
						page = $("#eventPaginationPrev").attr('rel');
						var showList = 1; // variable which permits to show or not the list after the upload of this one
						HomeBubble.Box.Content.Event.update_event(showList, page);						
		});
		
		$("#todoEventNext").click(function(){
						$('#todoEventLoader').fadeIn();
						page = $("#todoEventPaginationNext").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_todoEvent(showList, page);	
															
		});
		
		$("#todoEventPrev").click(function(){
						$('#todoEventLoader').fadeIn();
						page = $("#todoEventPaginationPrev").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_todoEvent(showList, page);						
		});

},update_todoEvent: function(showList, page){
	
		if(page == null){
			page = 1;
		}
		strUrl = HomeBubble.Paths.BASEWEB + 'member/calendar/getlistajax2';
		
		$('#dashSuggestEvent').fadeOut().load(strUrl, { update: true, page: page },function(data){
			$('#todoEventLoader').fadeOut();
//			$('#eventLoaderBig').fadeOut();
			$('.eventTodoDeleteButton').click(function(){
					idEvent = $(this).attr('rel');
					var isList = $(".eventText").attr('rel');
					$('#eventModal').html('<div class="genLoading"></div>');
					HomeBubble.Box.Content.Event.delete_modal_todoEvent(idEvent, isList);
			});
			$('.eventTodoEditButton').click(function(){
				var idTodoEvent = $(this).attr('rel');	
				strUrl1 = HomeBubble.Paths.BASEWEB+'member/calendar/addajaxtodoevent';
		    	$.post(strUrl1, {idTodoEvent: idTodoEvent}, function(data){
					HomeBubble.Box.Content.Event.update_todoEvent(showList, page);
					HomeBubble.Box.Content.Event.update_event(showList, page);
					HomeBubble.Box.Content.Calendar.calendarReload();						
			});
		});
		$('#dashSuggestEvent').fadeIn();
	});

},update_event: function(showList, page){

					if(page == null){
						page = 1;
					}
	
					strUrl = HomeBubble.Paths.BASEWEB + 'member/calendar/getlistajax';
					
					$('#dashContentEvent').fadeOut().load(strUrl, { update: true, page: page },function(data){

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

		var nameValidated = false ;

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

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

	    	 }
	    	 //	alert(nameValidated);
	    	  }); 
	    	 
	    	 $('#addEventDate').change(function(){
	   
	    	 	if($(this).val()==''){
	    	 		$('#addEventDateError').slideDown();
	    	 		dateValidated = false;
	    	 	}
	    	 	if($(this).val()!=''){
	    	 		$('#addEventDateError').slideUp();
	    	 		dateValidated = true;
	    	 }
    	 	}); 
    	 	
			 $('#addEventDate').blur(function(){
	   
	    	 	if($(this).val()==''){
	    	 		$('#addEventDateError').slideDown();
	    	 		dateValidated = false;
	    	 	}
	    	 	if($(this).val()!=''){
	    	 		$('#addEventDateError').slideUp();
	    	 		dateValidated = true;
	    	 }
			//alert(dateValidated);
    	 	}); 
    	 	
			/*
    		$('#addEventStartTime').timeEntry({
    			show24Hours: true
    		});
			*/
		    /*$('#addEventStartTime').timepickr({
		        handle: '#trigger-test',
		        convention: 12 });*/
				/*
			$('#addEventEndTime').click(function(){
				//time = $('#addEventStartTime').timeEntry('getTime');

				value = $(this).attr('value');

				if(value == ''){
					
					t = $('#addEventStartTime').attr('value');	
					time = t.split(':');

					hour = parseInt(time[0])+parseInt(1);
					min = parseInt(time[1]);
					$(this).timeEntry('setTime', new Date(0, 0, 0, hour, min, 0));
							
				}	

			});
    		
    		$('#addEventEndTime').timeEntry({
    			show24Hours: true
    			//beforeShow: firstHalfHourOnly
    		});

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


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


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


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

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

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

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

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

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

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


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

		//	}
    	});

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

    },modal_add_behaviour: function(){
    	
    	var nameValidated;
    	// Datepicker in Add Modal
		$.datepicker.setDefaults($.extend({showMonthAfterYear: false}, $.datepicker.regional['fr']));

		$('#addEventDate').datepicker({
			changeMonth: true,
			changeYear: true
		});

		//Display Reminder if the user wants	    
		$('#addEventReminderAdd').click(function(){
				
				$('#addEventExtraInfo').fadeIn();
	
		});
			
		//Erase value of reminder on click on reminder none				    
		$('#addEventReminderNone').click(function(){
				
				$('#addEventReminderMorning').attr("checked","");
				$('#addEventReminderDay').attr("value","");
				$('#addEventReminderMonth').attr("value","");
				
				$('#addEventExtraInfo').fadeOut();
	
		});
			
		// Infos on start time format
		$('#addEventStartTime').focus(function(){
				
				$('#addEventStartTimeTip').slideDown().fadeTo(4000, 0.6);
				
		});
		
		//Infos on end time format	
		$('#addEventEndTime').focus(function(){
				
				$('#addEventEndTimeTip').slideDown().fadeTo(4000, 0.6);
				
		});
		
		//Show the reminder date
		$('#addEventReminderDay').blur(function(){

		});

		 if(nameValidated){
		 	return true;
		 }   	

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

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

				});	
    	
    },delete_modal_todoEvent: function(idEvent, isList){


					strUrl = HomeBubble.Paths.BASEWEB + 'member/calendar/deletetodoeventmodal';
					$('#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_todoEvent(idEvent);
												$(this).dialog('destroy');

											},

												/***  Bouton annuler et ses options  ***/	

												"Annuler": function() {
												$(this).dialog('destroy');
												//$('.portlet').fadeIn();
											}

										},
								close: function(){

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

							});	

		    },delete_todoEvent: function(idEvent, updateList, date, dateFr){
			   	
				strUrl = HomeBubble.Paths.BASEWEB + 'member/calendar/deletetodoeventajax/';

				$.post(strUrl, {idEvent: idEvent}, function(data){							
			   			HomeBubble.Box.Content.Event.update_todoEvent(1);
				  	$('#deleteEvent').dialog('destroy');
			});

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

HomeBubble.Box.Content.Activation = {
	
		initialize: function () {
				
			$("#formButtonActivation").click(function(){
		
			// Récupération de l'email saisi par l'utilisateur
			var email = $("#activationInEmail").val();	
		
			if (email == ''){
				checkEmail = false;
				$("#emailEmpty").slideDown();	
			}else{
				checkEmail = true;
			
			}
			if (checkEmail == true){
				
				$("#emailEmpty").slideUp();	
				$("#accountNotExist").slideUp();
						
				strUrl = HomeBubble.Paths.BASEWEB + 'activation/checkemailajax';
				
				$.post(strUrl , { email:email } , function(data){
					
					if(data == "notExist"){
							$("#accountNotExist").slideDown();
					}
						// Sinon tout va bien
					if (data == "ok"){
								
						//$('#emailResult').css("display", "none");	
						$('.activationForm').hide();
						
						$("#activationResultEmail").text(email);
						$('#activationSuccess').fadeIn(2000, function(){});		
					}		
				});	
			}
		});
			}
}

HomeBubble.Box.Content.Auth = {
	
		initialize: function () {


			var passwordValid = false;
			var confirmPasswordValid = false;
		
			$('#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 question = $('#authSecretQuestion').val();
				var answer = $('#authAnswer').val();
				var email = $('#email').val();	
				
				var validPassword = false;
				var validConfirmPassword = false;
				
				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;
				}
				
				if(validPassword == true && validConfirmPassword == true){
					$.post(strUrl, { email: email, password: password, question:question, answer:answer }, function(data){	
							if(data.result == "true"){
								
								$('#authFailureQuestion').slideUp();
								$('#authFailureChange').slideUp();
								$("#authRequestPasswordForm").fadeOut(function(){
									$('#authSuccessChange').slideDown(function(){});	
								});
								
							}else{
								$('#authSuccessChange').slideUp();
								if (data.moreinfo == 'wrong-anwser') {
									$('#authFailureQuestion').slideDown();
								}else{
									$('#authFailureChange').slideDown();
								}
							}
						
					}, 'json');	
				
				}
				
			});

		
		}

}

HomeBubble.Box.Content.Provider = {

	autoArchive: 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/autoarchive/true';				
		$('#editAutoArchive').html('<div class="genNormalLoading"></div>').load(strUrl , { idUsrBubble: idUsrBubble , idProvider : idProvider },function(){
			//alert($('.addProvTextarea').attr('value'));
			if($('.addProvTextarea').attr('value') != '' ){

			}
		} ).dialog({

			bgiframe: true,
			autoOpen: true,
			width: 560,
			minHeight: 350,
			draggable: true,
			resizable: true,
			modal: true,
			position: 'center',
			closeOnEscape: false,
			buttons: {				
					

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

					},
				
					"Annuler": function() {
						$(this).dialog('destroy');
						//$('.portlet').fadeIn();
					}						
			},
			close: function(){

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

		});
		*/
		
		return false;
		
		
		
		
	}
	,	initialize: function () {
		
		$("#close-checkuserinfo").die().live('click',function(){
			//console.log('close');
			$('#lightbox').fadeOut('slow',function(){
				$("#lightboxOverlay").fadeOut();
			});
			return false;
		});
		
		// $("#bubble-plus-button").die().live('click',function(){
		// 	window.location.href = "/membre/service/produit/bubble-plus";
		// });

			/*
					$('.hooverCheckbox').live('click', function(){
						
						if(! $('.hooverCheckbox').is(':checked')){
							console.log('done');
							$('.auto-archive-button').removeClass("on");
						}
						
					})
			*/	
					HomeBubble.Box.Content.Provider.update_api();
					HomeBubble.Box.Content.Provider.password_retrieve();
					
					$('#provSelect').change(function(){
						url = $(this).attr('value');
						window.location = "/membre/bulle/"+url;
					});
					$('#changeIconProvider').mouseover(function(){
				//		alert('pwet');
					
						$('#changeicon').slideDown(function(){
							$(this).oneTime('4s',function(){
								$(this).slideUp();
							});
					
						});
					});
					/*
					$('#provHeaderPage').mouseleave(function(){
						if ($('#linkchangeicon').attr('name') != 'block')
						$('#changeicon').slideUp();
						//$('#changeicon').hide();
					});
					*/
			
					$(".modifyProviderButton, #modifyProviderHoover, #auto_archive").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').html('<div class="genNormalLoading"></div>').load(strUrl , { idUsrBubble: idUsrBubble , idProvider : idProvider },function(){
							//alert($('.addProvTextarea').attr('value'));
							if($('.addProvTextarea').attr('value') != '' ){
								
							}
						} ).dialog({
						
							bgiframe: true,
							autoOpen: true,
							width: 560,
							height: 600,
							draggable: true,
							resizable: true,
							modal: true,
							position: 'top',
							closeOnEscape: false,
							buttons: {				
										/***  Bouton Valider et ses options  ***/
										
										"Valider": function() {
										usrProviderName = $("#usrProviderName").attr('value');				
										usrBubbleName = $("#usrBubbleName").attr('value');
		
										
										if(usrBubbleName == ''){
											$('#newNoTitle').slideDown();
										}else{
											$('#newNoTitle').slideUp();
										}	
										
										if(usrProviderName == ''){
											$('#newNoName').slideDown();
										}else{
											$('#newNoName').slideUp();
										}
										
										if (usrBubbleName != '' && usrProviderName != ''){
											HomeBubble.Box.Content.Provider.modify_provider_info(customName,customNameSeo);	
										}

									},
									/***  Bouton annuler et ses options  ***/	
									"Annuler": function() {
										$(this).dialog('destroy');
										//$('.portlet').fadeIn();
									}						
							},
							close: function(){
								
									$(this).dialog('destroy');
							}
		
						});
							
					});
					
			$("#addVaccination").click(function(){
				strUrl = HomeBubble.Paths.BASEWEB + 'member/calendar/specificdate';
				dateType = "vaccination";
				idUsrBubble = $("#idUsrBubble").attr("value");
				$("#addVaccinationModal").load(strUrl, {dateType: dateType}, function(){
					
					$("#dob").datepicker({
						changeMonth: true,
						changeYear: true,
						yearRange: '-100y:0y' 
					});
					
					
				}).dialog({
				
					bgiframe: true,
					autoOpen: true,
					width: 560,
					height: 'auto',
					draggable: true,
					resizable: true,
					modal: true,
					position: 'top',
					closeOnEscape: false,
					buttons: {
							"Valider": function() {
								
								var firstname = $("#firstname").attr("value");
								var dobFr = $("#dob").attr("value");
								dateBuffer = dobFr.split('/');
								dob = dateBuffer[2]+'-'+dateBuffer[1]+'-'+dateBuffer[0];
								
								var firstnameValidated = false;
								var dobValidated = false
								
								if(firstname != ""){
									firstnameValidated = true;
									$("#vacFirstnameNotValidated").slideUp();
								}
								else if(firstname == ""){
									firstnameValidated = false;
									$("#vacFirstnameNotValidated").slideDown();
								}
								
								if(dobFr != ""){
									dobValidated = true;
									$("#vacDobNotValidated").slideUp();
								}
								else if(dobFr == ""){
									dobValidated = false;
									$("#vacDobNotValidated").slideDown();
								}

								var arrVaccin = new Array();
								$(".vaccination").each(function(i,e){
									if($(this).is(":checked")){
										arrVaccin.push($(this).attr("value"));
										//arrVaccin[i] = $(this).attr("value");
									}
									else{
										arrVaccin.push(0);
									}
								})
								
								//Si les données du formulaire sont correctes, on appelle la fonction qui va posté les infos
								if(firstnameValidated == true && dobValidated == true){
									HomeBubble.Box.Content.Provider.add_vaccination(firstname, dob, arrVaccin, idUsrBubble);	
								}
								

							},				

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

				});
				
				return false;
			});
					
			$("#modifyChangeIcon, #addChangeIcon").click(function(){

				var idUsrBubble =  $("#idUsrBubble").attr('value');
				var icon =  $("#icon").attr('value');
				var idProvider =  $("#idProvider").attr('value');
			
				var type = $(this).attr('rel');
			//	alert(type);

				strUrl = HomeBubble.Paths.BASEWEB + 'member/provider/changeiconmodal';
				
				if(type == 'no-icon'){
					
					$('#modalchangeicon').load(strUrl, {icon:icon,  idProvider:idProvider, idUsrBubble:idUsrBubble},function(){
						
						$(".ui-button-text:contains('Supprimer')").parent().addClass('ui-dialog-cancel');
						$(".ui-button-text:contains('Supprimer')").parent().removeClass('ui-state-default');
						
					}).dialog({
						bgiframe: true,
						autoOpen: true,
						width: 700,
						height: 'auto',
						draggable: true,
						resizable: true,
						modal: true,
						position: 'top',
						closeOnEscape: false,
						buttons: {				
									/***  Bouton Valider et ses options  ***/

								"Valider": function() {

									valNoEmpty1 = "true";

									if( $('#addFile1').val() != '' ){

										if( $('#fileTitle1').val() == '' ){
											$('#fileTitleError1').slideDown();
											valNoEmpty1 = "false";
										}
									}



									if( valNoEmpty1 == "true" ){

										for ( i = 1 ; i < 2 ; 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.Provider.changeicon(i, idUsrBubble);
												}
											}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');
						}

					})
					
				}else{
					
					$('#modalchangeicon').load(strUrl, {icon:icon,  idProvider:idProvider, idUsrBubble:idUsrBubble}, function(){
						
						$(".ui-button-text:contains('Supprimer')").parent().addClass('ui-dialog-cancel');
						$(".ui-button-text:contains('Supprimer')").parent().removeClass('ui-state-default');
					}).dialog({
						bgiframe: true,
						autoOpen: true,
						width: 700,
						height: 'auto',
						draggable: true,
						resizable: true,
						modal: true,
						position: 'top',
						closeOnEscape: false,
						buttons: {				
									/***  Bouton Valider et ses options  ***/

								"Valider": function() {

									valNoEmpty1 = "true";

									if( $('#addFile1').val() != '' ){

										if( $('#fileTitle1').val() == '' ){
											$('#fileTitleError1').slideDown();
											valNoEmpty1 = "false";
										}
									}



									if( valNoEmpty1 == "true" ){

										for ( i = 1 ; i < 2 ; 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.Provider.changeicon(i, idUsrBubble);
												}
											}else{

												$("#fileAddEmpty"+i).slideDown(function(){
													$(this).oneTime('3s', function(){
													$(this).slideUp();
													});
												});

											}
										}
									}
								},
								/***  Bouton annuler et ses options  ***/	
								"Supprimer": function() {
									HomeBubble.Box.Content.Provider.deleteicon();
								//	HomeBubble.Box.Content.Provider.changeicon(1, idUsrBubble);
									//$('.portlet').fadeIn();
								},
								/***  Bouton annuler et ses options  ***/	
								"Annuler": function() {
									$(this).dialog('destroy');
									//$('.portlet').fadeIn();
								}						
						},
						close: function(){

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

					})
				}


				
			});
				
				
			return false;
				
			},deleteicon: function(){
				var idUsrBubble = $('#idUsrBubble').attr('value');
				var icon = $('#icon').attr('value');
				var idProvider = $('#idProvider').attr('value');
				strUrl = '/member/provider/deleteicon';
				
				$.post(strUrl, { idUsrBubble: idUsrBubble, icon: icon, idProvider: idProvider}, function(data){
					if(data.result == true){
						$('#modalchangeicon').dialog('destroy');
						$('#changeIconProvider').attr('src', '/images/front/gui/bkg/yourimage.jpg');
						$('.provChangeIcon').html("Ajouter image");
						$('.provChangeIcon').attr("rel", "no-icon");
					}else if(data.result == false){
						
					}
				}, 'json');
				
				
			},changeicon: function(idForm, idUsrBubble){

				$("#fileUploadError"+idForm).html("");
				$("#fileUploadError"+idForm).slideUp();
    			$( "#fileWaitUpload" + idForm ).fadeIn();

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

				var options = { 
		        url:        strUrl,  // target element(s) to be updated with server response 
		        //beforeSubmit:  showRequest,  // pre-submit callback
				dataType: 'json',
				forceSync: true,
		        success:  function(data, statusText, xhr, $form){

//	alert('status: ' + statusText + '\n\nresponseText: \n' + data + '\n\nThe output div should have already been updated with the responseText.');

						$("#paperWaitContainer").fadeOut();
						
						if(data.result == "true"){
									//$('#modifyChangeIcon').css("display", "block");
								//	$("#addChangeIcon").html("Modifier image");
								//	$("#addChangeIcon").attr("rel", "icon");
									//$('.profileArchUsrBubbleFileNameHidden[rel='+idUsrBubble+']').load();
								
									if ($('.provChangeIcon').attr('id') == 'addChangeIcon') {
										$('.provChangeIcon').html($('.addChangeIconName').html());
										$('.provChangeIcon').attr('rel', 'icon');
									}; 
							
									$("#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');
											
												$("#ErrorLogo").slideUp();
												$("#changeIconProvider").attr("src",data.icon);
												//alert(data.icon);
												$("#modalchangeicon").dialog('destroy');
												$("#addIcon").fadeOut();
										
											
										});
									 	//alert('destroy');
									}												
									
								

							}else if(data.result == "false"){
									$('#fileWaitUpload'+idForm).fadeOut(function(){
										$("#fileUploadError"+idForm).html(data.message);
										$("#fileUploadError"+idForm).fadeIn();											
									});
							}
							
							
						
						}
				
						
				}

				$("#paperForm"+idForm).ajaxSubmit(options);			
				return false;
			
			//	function showResponse(responseText, statusText, xhr, $form)  { 
				    // for normal html responses, the first argument to the success callback 
				    // is the XMLHttpRequest object's responseText property 

				    // if the ajaxSubmit method was passed an Options Object with the dataType 
				    // property set to 'xml' then the first argument to the success callback 
				    // is the XMLHttpRequest object's responseXML property 

				    // if the ajaxSubmit method was passed an Options Object with the dataType 
				    // property set to 'json' then the first argument to the success callback 
				    // is the json data object returned by the server 

				    
			//	}

			},add_vaccination:function(firstname, dob, arrVaccin, idUsrBubble){

				strUrl = HomeBubble.Paths.BASEWEB + 'member/calendar/specificdateresult';
				dateType = "vaccination";
				$.post(strUrl, {dateType: dateType, firstname: firstname, dob: dob, 'arrVaccin[]': arrVaccin, idUsrBubble: idUsrBubble}, function(){
					
					$("#addVaccinationModal").dialog('option', 'buttons', { 
							"Fermer": function(){
								$(this).dialog("destroy");
							}
					});
					
					HomeBubble.Box.Content.keyDate.update_keyDate(1);
					
					$("#addVaccinationSuccess").slideDown(function(){
						$(this).oneTime('3s',function(){			
							$("#addVaccinationModal").dialog('destroy');	
						});				
					})
		
				});	
			},hoover: function(idUsrBubble,idProvider,url_redirect){

			//		$("#modifyProvider").append('<input type="hidden" name="closeModal" value="true" id="closeModal" />');

					//checkbox for the hoover project
					if ($(".hooverCheckbox").length){

							submitLocked = false;

						 if($(".hooverCheckbox").is(':checked')){

								allFieldsAreFilled = true;

								// check that all fields are filled up for connection
								$('.blockClient :text').each(function(i,e){
									if( $(this).attr('value') == ''){
										allFieldsAreFilled = false;
									}
								}); 

								$('.blockClient :password').each(function(i,e){
									if( $(this).attr('value') == ''){
										allFieldsAreFilled = false;
									}
								}); 


								if( allFieldsAreFilled == true ){
									$('.hooverError').slideUp();

									// The option was already checked

									if($("#hooverOld").attr('value') != '1'){

											// Set the value to 1 for the data
											isHoover = 1;
											$(".hooverCheckbox").attr('value', 1);
										//	$("#provHoover").append('<input type="hidden" name="hooverActivated" value="true"/>');

											// We launch the hoover process
											
											
											$("#lightbox-content").load( '/member/efacture/check-userinfo-lightbox', { redirect : url_redirect }, function(){
												
													HomeBubble.Box.Content.Lightbox.launch(function(){

													if ($("#idUsrBubble").length){
														idUsrBubble = $("#idUsrBubble").attr('value');
													}

													if ($("#idProvider").length){
														idProvider = $("#idProvider").attr('value');
													}

													if(url_redirect != 'false'){		
														// HomeBubble.Box.Content.Lightbox.closeit();
														// window.location.href = url_redirect;
													}
												
											});
										
											
											/*
											strUrl =  '/member/efacture/check-userinfo';
											$.ajax({
												type: "POST",
											 	url: strUrl,
											  	async: false,
												dataType : 'json',
												data: "idUsrBubble="+idUsrBubble+"&idProvider="+idProvider,
												success: function(data){

														if(data.result){
															
															$("#lightbox-content").html('<div class="genModalLoading"></div>').load('/member/efacture/check-userinfo-lightbox/message/success');
															$('.auto-archive-button').removeClass('off');
															
															if(url_redirect != 'false'){
																window.location.href = url_redirect;
															}
															
														}else{
															$('.auto-archive-button').addClass('off');
															
															$("#lightbox-content").html(data.message);
															if(url_redirect != 'false'){
															 	window.location.href = url_redirect;
															}															
															
														}
														
														
												}
											 });
											*/			

											});

									}
								}else{

									$('.hooverError').slideDown();
									return false;
								}


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

					}
					
					$("#bubble-plus-button").die().live('click',function(){
						window.location.href = "/membre/service/produit/bubble-plus";
					});

		},modify_provider_info:function(customName,customNameSeo){
			

			HomeBubble.Box.Content.Provider.hoover(false,false,'false');

			
			var formValues = $("#addProviderInfoForm").serialize();
			
			idUsrBubble = $("#idUsrBubbleProviderInfoForm").attr('rel');
			idProvider = $("#bubbleIdProviderInfo").attr('value');
			usrBubbleName = $("#usrBubbleName").attr('value');
			usrProviderName = $("#usrProviderName").attr("value");
			apiLink = $("#addApiLink").attr('value');
			usrBubbleNameTemp = $("#usrBubbleNameTemp").attr('value');
			bubbleName = $("#bubbleName").attr('value');
			bubbleThemeName = $("#bubbleThemeName").attr('value');
			closeModal = $("#closeModal").attr('value');
			
			// submit bubble information
			strUrl = HomeBubble.Paths.BASEWEB + 'member/bubble/addproviderinfoformprocess';
			$.ajax({
			  url: strUrl,
			  type: 'POST',
			async : true,
			  dataType: 'json',
			  data:{ values : formValues , idUsrBubble : idUsrBubble , idProvider:idProvider , usrBubbleName : usrBubbleName, apiLink: apiLink, usrBubbleNameTemp:usrBubbleNameTemp, bubbleName:bubbleName, usrProviderName: usrProviderName, customNameSeo : customNameSeo},
			  complete: function(xhr, textStatus) {
			    //called when complete
			  },
			  success: function(data, textStatus, xhr) {
			    //called when successful
					//UPdate selfcare data link						
					if(closeModal == "true"){
						$('#modifyProvider').dialog('destroy');
					}
					
					//alert(data.url);
					
					HomeBubble.Box.Content.Provider.display_api();
					HomeBubble.Box.Content.Provider.update_name();
					
					isHoover = 0;
					if ( $(".hooverCheckbox").attr('value') == 1  ) {
						isHoover = 1;
					
						url = HomeBubble.Paths.BASEWEB + 'member/provider/updatehooverinfo';
						$('#archiveHooverInfo').load(url, {idUsrBubble: idUsrBubble, idProvider: idProvider, isHoover : isHoover}, function(data){
					
						});
					};
					
					// IF the bubble custom name does not change
					if(usrBubbleNameTemp == usrBubbleName){
						$("#provSelfcare").slideUp();
						HomeBubble.Box.Content.Provider.update_api();		
							
					
						$("#provContentInfo").css('visibility', 'hidden');	
				
						
							strUrl = HomeBubble.Paths.BASEWEB + 'member/provider/updateproviderinfocontent';
							$("#provContentInfo").load(strUrl , {idUsrBubble : idUsrBubble , idProvider:idProvider} , function(){	
								$(this).css('display', 'none');
								$(this).css('visibility', 'visible');
								$(this).fadeIn();	
							 
								// UPDATE FUNCTION FOR PASSWORD RETRIEVE
								HomeBubble.Box.Content.Provider.password_retrieve();

							});
					
					}else{

						//alert(HomeBubble.Paths.BASEWEB + 'membre/bulle/'+bubbleName+'/'+bubbleThemeName+'/'+data.url);
						window.location = HomeBubble.Paths.BASEWEB + 'membre/bulle/'+bubbleName+'/'+bubbleThemeName+'/'+data.url;
							
					}
			  },
			  error: function(xhr, textStatus, errorThrown) {
			    //called when there is an error
			  }
			});
			/*
			$.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						
						if(closeModal == "true"){
							$('#modifyProvider').dialog('destroy');
						}
						
						//alert(data.url);
						
						HomeBubble.Box.Content.Provider.display_api();
						HomeBubble.Box.Content.Provider.update_name();
						
						isHoover = 0;
						if ( $(".hooverCheckbox").attr('value') == 1  ) {
							isHoover = 1;
						
							url = HomeBubble.Paths.BASEWEB + 'member/provider/updatehooverinfo';
							$('#archiveHooverInfo').load(url, {idUsrBubble: idUsrBubble, idProvider: idProvider, isHoover : isHoover}, function(data){
						
							});
						};
						
						// IF the bubble custom name does not change
						if(usrBubbleNameTemp == usrBubbleName){
							$("#provSelfcare").slideUp();
							HomeBubble.Box.Content.Provider.update_api();		
								
						
							$("#provContentInfo").css('visibility', 'hidden');	
					
							
								strUrl = HomeBubble.Paths.BASEWEB + 'member/provider/updateproviderinfocontent';
								$("#provContentInfo").load(strUrl , {idUsrBubble : idUsrBubble , idProvider:idProvider} , function(){	
									$(this).css('display', 'none');
									$(this).css('visibility', 'visible');
									$(this).fadeIn();	
								 
									// UPDATE FUNCTION FOR PASSWORD RETRIEVE
									HomeBubble.Box.Content.Provider.password_retrieve();

								});
						
						}else{

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

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

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

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

					}, 'json');

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

	

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

}
	

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

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

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

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

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

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

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

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

				if($("#keyDateName").attr("value")!="Nom"){
					nameValidated = true;
				}
		
			});
			
			/*
			$('#keyDatetartTime').timeEntry({
    			show24Hours: true
    			
    		});

			$('#keyDateEventEndTime').click(function(){
				//time = $('#addEventStartTime').timeEntry('getTime');
				var value = $(this).attr('value');
				
				if(value == ''){
					t = $('#keyDatetartTime').attr('value');	
					time = t.split(':');

					hour = parseInt(time[0])+parseInt(1);
					min = parseInt(time[1]);
					$(this).timeEntry('setTime', new Date(0, 0, 0, hour, min, 0));					
				}

			});
    		
    		$('#keyDateEventEndTime').timeEntry({
    			show24Hours: true
    			//beforeShow: firstHalfHourOnly
    		});
			*/

			//Add a key date
			$("#keyDateAddText, #keyDateValidButton").click(function(){
				if($('#keyDateName').attr('value') != ''){
					nameValidated = true;
				}
				if($('#keyDateName').attr('value') == ''){
					nameValidated = false;
				}
				
				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();
					$('.provFooterActionKeyDate').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 startTime = $('#keyDatetartTime').attr('value');
				var endTime = $("#keyDateEventEndTime").attr('value');
				var description = $('#keyDateEventDescription').attr('value');


				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, startTime: startTime, endTime: endTime, description: description }, 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");
						
						$('#keyDatetartTime').attr('value', '');
						$("#keyDateEventEndTime").attr('value', '');
					    $('#keyDateEventDescription').attr('value', '');
						
						$('#startTime').slideUp();
						$('#endTime').slideUp();
						$('#keydateDescription').slideUp();
							
					//	$('#keyDateNextDate').html('<div class="genLoading"></div>');	
		 				 HomeBubble.Box.Content.keyDate.update_keyDate();
		 			//	HomeBubble.Box.Content.keyDate.edit_keyDate_button();
		
		 				
					 });
				
			
		},
		update_keyDate: function(page){
					$('#keyDateNextDate').html('<div class="genLoading"></div>');
					if(page == null){
						page = 1;
					}
					var idUsrBubble = $("#keyDateAdd").attr("rel");
					
					strUrl = HomeBubble.Paths.BASEWEB + 'member/provider/getlistkeydateajax';
					//See all the elements
					if(page == 'all'){
						
						$('#keyDateNextDate').load(strUrl, { update: true, page: page, idUsrBubble: idUsrBubble }, function(){				
								$('.keyDateViewNext').css("display", "none");
								$('.keyDateViewFirst').css("display", "block");
								$("#keydateNext").css("display", "none");
								$("#keydatePrev").css("display", "none");
								$('#keyDateNextDate').slideDown();
								HomeBubble.Box.Content.keyDate.edit_keyDate_button();

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

					
		},
		edit_keyDate_modal: function(idEvent){
		

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

		},
		edit_keyDate: function(idEvent){
			
			var name = $('#editKeyDateTitle').attr("value");
			var date = $('#editKeyDateDate').attr("value");
			var hasChild = $('.editKeyDateHasChild:checked').val();
    		var isChild = $('.editKeyDateIsChild:checked').val();
   			var idEventParent = $('.editKeyDateTitle').attr('rel');
			var morning = $('#editKeyDateReminderMorning').attr('checked');
			var day = $("#editKeyDateReminderDay").attr("value");
			var month = $("#editKeyDateReminderMonth").attr("value");
			var numberOfChildEvent = $('.editKeyDateDate').attr('rel');
			var periodicity = $('.editPeriodicityInfo').attr('rel'); // To save the periodicity when edit an event
			var idUsrBubble = $('#editKeyDateContainerRightInputHidden').attr('rel');
			var dateBuffer = date.split("/");
			var date = dateBuffer[2]+'/'+dateBuffer[1]+'/'+dateBuffer[0];
			var startTime = $('#editKeyDateStartTime').attr("value");
			var endTime = $('#editKeyDateEndTime').attr("value");
			var desc = $('#keyDateEventDescription2').val();
			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, startTime: startTime, endTime: endTime, desc: desc}, function(){
			//	$('#keyDateNextDate').html('<div class="genLoading"></div>');
				HomeBubble.Box.Content.keyDate.update_keyDate();
			});
	
		},
		edit_modal_behaviour: function(){

		// Datepicker in Edit Modal
	 	$.datepicker.setDefaults($.extend({showMonthAfterYear: false}, $.datepicker.regional['fr']));
		$('#editKeyDateDate').datepicker({
					changeMonth: true,
					changeYear: true
		});
				
		//Display Reminder if the user wants
		$('#editKeyDateReminderAdd').click(function(){
				
				$('#editKeyDateExtraInfo').fadeIn();
	
		});
			
		//Erase value of reminder on click on reminder none					    
		$('#editKeyDateReminderNone').click(function(){
				
				$('#editKeyDateReminderMorning').attr("checked","");
				$('#editKeyDateReminderDay').attr("value","");
				$('#editKeyDateReminderMonth').attr("value","");
				
				$('#editKeyDateExtraInfo').fadeOut();
	
		});

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

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

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

				HomeBubble.Box.Content.keyDate.update_keyDate();
				$('.keyDateViewFirst').fadeOut(function(){
					$('.keyDateViewNext').fadeIn();
					$("#keydateNext").slideDown();
					$("#keydatePrev").slideDown();
				});	
			});
	
		}, showDateFormat: function() {
			
				$('#keyDatetartTime').focus(function(){
					$('.addEventStartTimeTip').show('slow');
				});
				$('#keyDateEventEndTime').focus(function(){
					$('.addEventEndTimeTip').show('slow');
				});
				$('#keyDatetartTime').blur(function(){
					$('.addEventStartTimeTip').hide('slow');
				});
				$('#keyDateEventEndTime').blur(function(){
					$('.addEventEndTimeTip').hide('slow');
				});

		}

}

HomeBubble.Box.Content.Profile = {
	
		checkSession:function(){
				strUrl = HomeBubble.Paths.BASEWEB + 'member/auth/checkSession';
					return true;
	
	},
		initialize: function () {

			$(function() {
				$("#profileTabs").tabs({
					select: function(event,ui){
					}
				});
				
			});
			

			

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

			return false;
		
		});	
		

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

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

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

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

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


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

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

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

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

			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 = false;
		 	}
		 	
		 	if(password.length < 6 || newPassword.length < 6 || confirmNewPassword.length <6){
		 		
		 		$('#profilePasswordErrorPwLength').slideDown();
		 		lengthPasswordValidated = false;
		 	}
		 	else{
		 		$('#profilePasswordErrorPwLength').slideUp();
		 		lengthPasswordValidated = true;
		 	}
			
			//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(function(){
							$(this).oneTime('3s', function(){
								$("#profileTabs").tabs( 'select' , 0 );
							});
						});*/
						
						$('#passwordSuccessContainer').dialog({

											bgiframe: true,
											autoOpen: true,
											height: 'auto',
											draggable: true,
											resizable: true,
											width: 400,
											modal: true,
											closeOnEscape: false,
											buttons: {
														/***  Bouton annuler et ses options  ***/		
														"Fermer": function() {
														$(this).dialog('destroy');
														
													/*	$(this).oneTime('3s', function(){
															$("#profileTabs").tabs( 'select' , 0 );
														});*/
														window.location = '/membre/profile';
														
													}
												},
											close: function(){
												$(this).dialog('destroy');
											}
									});
						return false;
						

					}else{
						$('#profilePasswordError').slideUp();
						$('#profilePasswordErrorPw').slideUp();
						$('#profilePasswordErrorPwLength').slideUp();						
						$('#profilePasswordSuccess').slideUp();
						$('#profilePasswordFailure').slideDown();
					}
				});
			}
			

		});
		
		//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');
			if ($('#redirect').length > 0) {
				if ($('#redirect').val() == 1) {};
				window.location = "/default/partner/delete"
			}else{
				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');
				$('.profileArchUsrBubbleFileNameHidden[rel='+idUsrBubble+']').slideToggle();
			});
			
			
			//Edit an archive
			$('.profileArchEditButton').click(function(){
				
			var idArchive = $(this).attr('rel');
			$('#editArchive').html('<div class="genLoading"></div>');
			var profile = 1;
			HomeBubble.Box.Content.Archive.edit_modal_archive(idArchive, profile);
			});	

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

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

					$('#deletePaper').html('<div class="genLoading"></div>');
					var profile = 1;
					HomeBubble.Box.Content.Paper.delete_modal_paper(idPaper, profile);
			});	
			
			//Edit a paper
			$('.profilePaperEditButton').click(function(){

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

				var idPaper = $(this).attr('rel');	
				HomeBubble.Box.Content.Paper.send_modal_paper(idPaper);
			});
			
			$("#retrieveMyArchive").click(function(){
					strUrl = '/member/service/checkservice';
					$.post(strUrl, { }, function(data){
			//		alert(data.downloadarchives);
					if(!data.downloadarchives ){
						HomeBubble.Box.Content.EditBubble.no_rights_dialog('get-archive');
					}else{
						
							strUrl = HomeBubble.Paths.BASEWEB + 'member/profile/requestarchive';
							$('#requestArchive').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.request_archive();
														  	//$(this).dialog('destroy');
														},
															/***  Bouton annuler et ses options  ***/		
															"Annuler": function() {
															$(this).dialog('destroy');
														}
													},
												close: function(){
													$(this).dialog('destroy');
												}
										});
					}
					},'json');
				return false;
			});
			
	
	},request_archive: function(){
		
		
		
		$.post('/member/profile/createactiondownload', {post: 'true'}, function(data, textStatus, xhr) {
		 
			$("#requestArchive").dialog('destroy');
			$("#retrieveMyArchive").hide();
			$('#updateDownloadRequest').append('<br/><span style="color:green">'+data.msg+'</span>');
			
			$('.ui-dialog-valid').hide();
			$('.ui-dialog-cancel').html('fermer');
	
		},'json');
		
		
	},retrieve_archive: function(){
		strUrl = HomeBubble.Paths.BASEWEB + 'member/profile/getarchive';
		top.location.href = strUrl;
		
	},delete_partner_modal: function(id){
			strUrl = HomeBubble.Paths.BASEWEB + 'member/profile/deletepartnermodal';
			$('#deletePartnerAccount').load(strUrl, {update: true},function(){}).dialog({

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

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

										}

									},
								close: function(){
									$(this).dialog('destroy');
								}
						});
			return false;
	
	},delete_partner: function(id){
		strUrl = HomeBubble.Paths.BASEWEB + 'member/profile/deletepartnerajax';
		$.post(strUrl,{idUsr: id}, function(data){
			if(data.result == true){
				$('#profileAccountPartner').slideUp(function(){
					$('#profileDeletePartner').slideUp(function(){
						$('#accountPartner').slideDown();			
					})
						
				});	
			}
		}, 'json');
	}

}
	

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

