

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

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


		/******* PORTLET ******/
		$(function() {
					$(".dashColumn").sortable({
						connectWith: ['.dashColumn'],
						revert: true,
						zIndex: '4000',
						stop: function(event, ui) {
					//alert('yes');
						var column1 = $('#dashColumn1').sortable('toArray');
						var column2 = $('#dashColumn2').sortable('toArray');
						
						strUrl = HomeBubble.Paths.BASEWEB + 'member/dashboard/savebubbleposition';
						$.post( strUrl ,{ 'column1[]': column1 , 'column2[]' : column2  }, function(data){
							
						});
						
					}
						
					});
			});
		
			
		/******* TEXTAREA NOTES ******/
		$('#dashContentTextArea').live('keyup' , function(){
			
			HomeBubble.Box.Content.Dashboard.update_note();
		});
		
		
		
		// Launch update of Efacture elements
		
		$.post('/member/dashboard/autoarchive', {ajax: 'true'}, function(data, textStatus, xhr) {
			
			$('#dashboard-document-number').html(data.efacture_documents);
			$('#dashboard-hoover-number').html(data.ishoover);
			$('#dashboard-efacture-number').html(data.efacture_error);
			
		}, 'json');
		
		


    },

	changeBooTodoEvent:function(){
		var strUrl= HomeBubble.Paths.BASEWEB + "member/dashboard/changebootodoeventajax";
		$('#enBooTodoEvent').click(function(){
			$('#suggestEvent').html('Suggestions<a id="disBooTodoEvent"><img style="margin: 0 5px" class="imgBooToDoEvent"  rel="1" title="activé" src="/images/front/gui/btn/checked.png"></a><span id="booRappel">Rappels activés</span>');
			$.post(strUrl, {booTodoEvent: 1});
			HomeBubble.Box.Content.Dashboard.changeBooTodoEvent();
		});
			
		$('#disBooTodoEvent').click(function(){
			$('#suggestEvent').html('Suggestions<a id="enBooTodoEvent"><img style ="margin: 0 5px" class="imgBooToDoEvent"  rel="0" title="désactivé" src="/images/front/gui/btn/noChecked.png"></a><span id="booRappel">Rappels désactivés</span>');
			$.post(strUrl, {booTodoEvent: 0});
			HomeBubble.Box.Content.Dashboard.changeBooTodoEvent();
		});
	},

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

				});

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

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

    	});
    	
    }
	
}

HomeBubble.Box.Content.Email = {
	
	editor1: null,
	html: null,

	initialize: function () {


		HomeBubble.Box.Content.Email.close_confirmation_mail();

				var idUsrBubble = $('#provStartEmail').attr('rel');
					strUrl = '/member/provider/view';
					$.post(strUrl, { }, function(){
						
					});
					
					$("#provStartEmail").live('click',	function(){
						strUrl = '/member/bubble/checkuserrights';
						
						$.post(strUrl, {}, function(data){
							if(data.customtabs == 'ok'){
								var idUsrBubble = $('#provStartEmail').attr('rel');
								HomeBubble.Box.Content.Email.add_modal_email(idUsrBubble);	
								return false;
								
							}
							else{
								var idUsrBubble = $('#provStartEmail').attr('rel');
								HomeBubble.Box.Content.Email.add_modal_email(idUsrBubble, data.customtabs);	
								// HomeBubble.Box.Content.EditBubble.no_rights_dialog('edit_letter');
							}
							
							
						}, 'json');
						return false;
					});
					
					$("#writeLetter").live('click',	function(){

						strUrl = '/member/bubble/checkuserrights';
						
						$.post(strUrl, {}, function(data){
							if(data.customtabs == 'ok'){
								var idUsrBubble = '';
								HomeBubble.Box.Content.Email.add_modal_email(idUsrBubble);	
								return false;
								
							}
							else{
								HomeBubble.Box.Content.EditBubble.no_rights_dialog('edit_letter');
							}
							
							
						}, 'json');
						return false;
					});
					
		
				
		}, 
		
		close_confirmation_mail: function(){
			
			
			$('#close-confirmation-letter').die().live('click', function(){
				$('#emailcontent').dialog('destroy');
				return false;
				
				
			});
			
			$('#closeButtonModal').click(function(){
				$('#emailcontent').dialog('destroy');
			});
		},
				
		add_modal_email: function (idUsrBubble, haveRights){
			 var viewportWidth = $(window).width();  
			 var viewportHeight = $(window).height(); 
			 
			 var middleWidth =  parseInt(viewportWidth/3);
			 var middleHeight =  parseInt(viewportHeight/5);

			if (haveRights == "not ok") {
				$('.ui-dialog').die().live('click', function() {
					 $('#emailcontent').dialog('destroy');
					HomeBubble.Box.Content.EditBubble.no_rights_dialog('edit_letter');
					return false;
				});
			}
				//$('#emailcontent').html();
				//alert(idUsrBubble);
				strUrl = HomeBubble.Paths.BASEWEB + 'member/provider/addemailmodal';
				$('#emailcontent').html('').load(strUrl, {idUsrBubble: idUsrBubble}, function(){
				
								//Change letter mode
								$("#modelLetter").change(function(){
									idLetterModel = $(this).attr('value');
									strUrl = '/member/provider/gettypemailcontent';
									$.post(strUrl, {idLetterModel: idLetterModel }, function(data){
										$('#objectDoc').attr("value", data.subject);
											HomeBubble.Box.Content.Email.editor1.setData( data.text ,function(){
											});
									}, 'json');	
								});

								//send email and check email form
								$("#letterForm").validate({
									 ignoreTitle: true,	
									 rules: {
										titleDoc: {required:true}

										  }
								});

								$("#cancelGiga").live('click', function(){
									$('#letterSubcribeContainer').slideUp(function(){
										$('#letterForm').slideDown();
									})
									return false;
								});

								$("#dateDoc").datepicker();
								
								//Change provider
								$('#changeProvider').change(function(){
									var id = $(this).attr('value');
									var tab = id.split('-');

									var idProvider = tab[0];
									var idUsrBubble = tab[1];
									
									$('#idUsrBubble').attr('value', idUsrBubble);
									
									strUrl = '/member/provider/email-provider-update';
									$.post(strUrl, {idProvider: idProvider, idUsrBubble: idUsrBubble}, function(data){
										if(data.address == null){
											$('#receiverDoc').attr('value', '');	
										}else{
											$('#receiverDoc').attr('value', data.address);	
										}
										
										if(data.ref == null){
											$('#referenceDoc').attr('value', '');	
										}else{
											$('#referenceDoc').attr('value', data.ref);	
										}
										
										
									}, 'json');
								});

							
				}).dialog({
							
					bgiframe: true,
					autoOpen: true,
					height: 'auto',
					draggable: true,
					resizable: true,
					width: 680,
					modal: true,
					position: 'top',
					closeOnEscape: false,
					buttons: {
								/***  Bouton Valider et ses options  ***/
								
							"Imprimer": function() {		
									$("#letterForm").submit();
							},
							
							"Enregistrer": function() {	
							
								if ($("#letterForm").valid()){
									sender = $('#senderDoc').attr('value');
									receiver = $('#receiverDoc').attr('value');
									object = $('#objectDoc').attr('value');
									title = $('#titleDoc').attr('value');
									model = $('#modelLetter').attr('value');
									content = HomeBubble.Box.Content.Email.editor1.getData();
									date = $('#dateDoc').attr('value');
									ref = $('#referenceDoc').attr('value');
									action = $('#actionDoc').attr('value');
									signature = $('#signature').attr('value');
									
									if(idUsrBubble == ''){
										var bubbleOrga = true;
										idUsrBubble = $('#idUsrBubble').attr('value');
									}

									strUrl = '/member/provider/generatepdf';

									$.post(strUrl, {sender: sender,receiver:receiver, object:object, title:title, model:model, content:content,date:date, ref:ref, action:action, idUsrBubble: idUsrBubble, signature: signature}, function(data){
										if(data == 'no-rights-for-the-user'){
											$.scrollTo('body',500);
											$('#letterForm').slideUp(function(){
												$('#letterSubcribeContainer').slideDown();
											})
										}else{
											strUrl = '/member/provider/confirmationmail';
											var rubrique = $('#changeProvider').val();
											var tab = rubrique.split('-');
											var idProvider = tab[0];
											
											$('#emailcontent').html('').load(strUrl, {idProvider: idProvider}, function(){
												$.scrollTo('body',500);
												$('.ui-dialog-buttonpane').hide();
												HomeBubble.Box.Content.Archive.update_archive('limit');		
												HomeBubble.Box.Content.Paper.update_paper('limit');
											});
											// $('#emailcontent').dialog('destroy');
										}

									});

								}else{
									$.scrollTo('body',600);
								}
							},
							
							"Pré-visualiser": function() {
									
								
								
								sender = $('#senderDoc').attr('value');
								receiver = $('#receiverDoc').attr('value');
								object = $('#objectDoc').attr('value');
								title = $('#titleDoc').attr('value');
								model = $('#modelLetter').attr('value');
								content = HomeBubble.Box.Content.Email.editor1.getData();
								date = $('#dateDoc').attr('value');
								ref = $('#referenceDoc').attr('value');
								signature = $('#signature').attr('value');

								strUrl = '/member/provider/letterpreview';
								$('#emailPreviewContainer').load(strUrl, {sender: sender,receiver:receiver, object:object, title:title, model:model, content:content,date:date, ref:ref, signature: signature}, function(data){
									$.scrollTo('body',800);
									$('.emailModalBackground').slideUp(function(){
										$('.ui-dialog-buttonpane').hide();
										$('#emailPreviewContainer').slideDown();
									});

									$('#preview-back').click(function(){
										$('#emailPreviewContainer').slideUp(function(){
											$('.emailModalBackground').slideDown();
												$('.ui-dialog-buttonpane').show();
										});
										return false;
									})
								});
							},

							"Annuler": function() {		
								$(this).dialog('destroy');
							}

						},
						/***  Fonction "close"  ***/

						close: function() {
							$(this).dialog('destroy');
						}

					});

				return false;
		}
		
}


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

HomeBubble.Box.Content.Button = {
	initialize: function () {
		
		$("#bubbleAdd").click(function(){
							
			idBubble =  $('.portletContainer').attr('rel');
			HomeBubble.Box.Content.Bubble.add_bubble_theme(idBubble);
			//return false;
		});
				
	
		$(".genContentButton").mouseover(function(){
			
			button = $(this).attr('rel');
			label =  '#buttonLabel'+ button;
			buttonHover = 'genMemberButton'+button+'Hover';
			
			// Hiding current page button
			currentBubble = $("#genContentButtonContainer").attr('rel');
			currentToHide =  ".genMemberButton"+currentBubble;
			currentToHideClass =  "genMemberButton"+currentBubble;
			currentToHideHoverClass = "genMemberButton" + 'Hover';
			
			//Hiding current page label
			currentLabel = "#buttonLabel"+currentBubble;
			$(currentLabel).css('display','none');
			
			// If the button mouseover another button
			if(button != currentBubble){
				$(currentToHide).removeClass().addClass(currentToHideClass);
			}
			
			// If the button mouseover is the current button page
			if(button == currentBubble){
				hoverTheCurrent = "genMemberButton"+currentBubble +"Hover";
				$(currentToHide).addClass(hoverTheCurrent);
			}
			
			// Add the hover image button		
			$(".memberBubble",this).addClass(buttonHover);
			
			// Slide down current label
			$(label).css('display','inline');
						
		});
		
		// On mouseout behaviour		
		$(".genContentButton").mouseout(function(){
			
			button = $(this).attr('rel');
			label =  '#buttonLabel'+ button;
			buttonHover = 'genMemberButton'+button+'Hover';
			
			$( ".memberBubble",this).removeClass(buttonHover);
			$(label).css('display','none');			
		});

		
		// When leaves the menu system
		$("#genContentButtonContainer").mouseleave(function(){			
			currentButton = $(this).attr('rel');
			
			currentLink = ".genMemberButton"+currentButton;
			
			// Add hover to the current button
			hoverTheCurrent = "genMemberButton"+currentButton +"Hover";
			$(currentLink,this).addClass(hoverTheCurrent);
			
			// Display current label
			currentLabel = "#buttonLabel"+currentButton;
			$(currentLabel).css('display','inline');
				

		});
	
	/*	
		$(".genContentButtonContainer").mouseover(function(){
			
			currentButton = $(this).attr('rel');
			$(this).unbind('mouseleave');
		//	alert(currentButton);
			
			
			//$("input[rel='newsletter']").	

			

			
		});
		
			
		$(".genContentButtonContainer").mouseout(function(){
			
			currentButton = $(this).attr('rel');
			$(this).bind('mouseleave');
		//	alert(currentButton);
			
			
			//$("input[rel='newsletter']").	

			

			
		});
		*/
	
	
	}
    
}


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

