

HomeBubble.Box.Content.homeAnim = {
	initialize: function () {
		
		$('.ui-dialog').find('input').live('keypress',function(e) {
			if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
				$(this).parent().parent().parent().parent().find('.ui-dialog-buttonpane').find('button:first').click(); /* Assuming the first one is the action button */
				return false;
			}
		});
		
		//Quand on clique sur "Enter" ca valide la question secrète (changement de mot de passe)
		$('#authRequestPasswordForm').live('keypress',function(e) {
		
			if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
				
				$('#authFormButton').trigger('click'); /* Assuming the first one is the action button */
				return false;
			}
		});
		
		//Quand on clique sur "Enter" ca change le mot de passe
		$('#authChangePassword').live('keypress',function(e) {
		
			if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
				
				$('#authFormButtonValidPassword').trigger('click'); /* Assuming the first one is the action button */
				return false;
			}
		});
		
		//Quand on clique sur "Enter" ca change le mot de passe
		$('#newsletterForm').live('keypress',function(e) {
		
			if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
				
				$('.newsEnrollButton').trigger('click'); /* Assuming the first one is the action button */
				return false;
			}
		});
			
			$("#commentAppleStoreCarousel").jCarouselLite({
				visible		: 1,							
				scroll		: 1,
				auto		: 5000,							
				speed		: 1500,							
				vertical	: true,						
				circular	: true
				
			});
	
			$("#genMoreInfoCarousel").jCarouselLite({
					btnNext		: "#homeActRight",								
					btnPrev		: "#homeActLeft",							
					visible		: 1,							
					scroll		: 1,
					auto		: 5000,							
					speed		: 1500,							
					vertical	: true,						
					circular	: true							
			    });
			    
	    /* Add friend div appears on click on 'envoyer à un ami'. De même pour mot de pass oublié*/
	    
     	$('#genLoginMorePassword').click(function(){
	    	$('#genSideBarPassword').slideToggle();
	    });
	    
	    $('#genLoginMoreFriend').click(function(){
	    	$('#genSideBarFriend').slideToggle();
	    });
	
		/* Search login and password default words disappear */
		$("#genSearchInputElement").focus(function() {
			if($(this).attr("value") == $(this).attr("alt")) {
				$(this).attr("value", "");
			}
		});
		
		$("#genSearchInputElement").blur(function() {
			if($(this).attr("value") == "") {
				$(this).attr("value", $(this).attr("alt"));
			}	
		});
		
		
		$("#homeNumContainer div").mouseover(function(){
			
			$(this).css("cursor" , "pointer")
			
		});
		
		$("#homeNumContainer div").click(function(){
				clearTimeout(timer);
			$("#homeHeadLink").css("color","#000");
				$(this).siblings('div').removeClass().addClass("homeNumInactive");
				animNumber = $(this).attr('rel');
			//	alert(animNumber);
				
				
				$(this).removeClass().addClass("homeNumActive");
				$("#homeContent div").hide();
				
				if(animNumber == 'info'){
					//alert( 'yes');
					$("#homeFirst").fadeIn("slow");
					
				}else if(animNumber == '3'){
					$("#homeSecond").fadeIn("slow");
				}else{
					$("#homeThird").fadeIn("slow");
				}
				
				$(this).siblings('div').removeClass().addClass("homeNumInactive");
				
		});
		
		$("#homeHeadLink").click(function(){
			
			clearTimeout(timer);
			
			$('#homeNumContainer div').siblings('div').removeClass().addClass("homeNumInactive");	
			$("#homeZero").removeClass().addClass("homeContentBox");
			$("#homeHeadLink").css("color","#A4186A");
			
	 		$("#homeZero").fadeIn();
			$("#homeFirst").fadeOut();
			$("#homeSecond").fadeOut();
			$("#homeThird").fadeOut();
			//this.currentElement = 4;
			$(this).oneTime('4s',function(){
					$("#homeZero").fadeOut(function(){
					HomeBubble.Box.Content.homeAnim.animeElement();	
					});
					
			});
		
			
			
			
		});
					
		HomeBubble.Box.Content.homeAnim.animeElement();
		HomeBubble.Box.Content.homeAnim.moveHoover();
		HomeBubble.Box.Content.homeAnim.movePress();
		
			
		
	
	},moveTriangle: function(number){
	
		if(number == 1){
			$('#topBullet').animate({
			    left: '85px'
			    
			  });
		}

		if(number == 2){
			$('#topBullet').animate({
			    left: '285px'
			    
			  });
		}		
		
		if(number == 3){
			$('#topBullet').animate({
			    left: '475px'
			    
			  });
		}
		
		if(number == 4){
			$('#topBullet').animate({
			    left: '665px'
			    
			  });
		}
		if(number == 5){
			$('#topBullet').animate({
			    left: '860px'
			    
			  });
		}
	
	},moveHoover: function(){

		var max = ($('#hoover0').parent().children().length);
		var cur = 0;
		var i = cur + 1;

		while(i < max)
		{
			$("#hoover"+i).fadeOut();
			i++;
		}		
		$("#hoover"+cur).fadeIn();
		$("#hoover0").everyTime('6s',function() {
			
			var max = ($('#hoover0').parent().children().length);
			var rand = Math.floor(Math.random() * max)
			var i = 0;

			while(i < max)
			{
				if (i != rand)
				  $("#hoover"+i).fadeOut('slow');
				i++;
			}
			$("#hoover"+rand).fadeIn('slow');
		});
		
	},movePress: function(){

		var max = ($('#press0').parent().children().length);
		var cur = Math.floor(Math.random() * max);
		var i = 0;

		while(i < max)
		{
			$("#press"+i).fadeOut();
			i++;
		}		
		$("#press"+cur).fadeIn();
		},

	currentElement: 0,
	animeElement: function(){



		


		$('#animValue').everyTime('6s','animBlock', function(){
			//Reinit value to 0
			var myval = $('#animValue').html();
			var myvalBottom = $('#animValueBottom').html();
		//	alert(myval);
			var animValue = parseInt(myval);
			var animValueBottom = parseInt(myvalBottom);
			
			if(animValue == 6){
				animValue = 0;
				$("#topBullet").fadeOut();
				HomeBubble.Box.Content.homeAnim.moveTriangle(1);
			}
			
			if (animValue == 1) {
				$("#topBullet").fadeIn();
			}
			
			if(animValueBottom == 2){
				animValueBottom = 0;
			}
			
			$('#bullet a').removeClass('on');
			$('.animBlock').removeClass('on');
			
			$('.animBlock').fadeOut();
			$('#block'+animValue).addClass('on');
			$('#blockBottom'+animValueBottom).addClass('on');
			
			$('#bullet'+animValue).addClass('on');

			HomeBubble.Box.Content.homeAnim.moveTriangle(animValue);

			
			total = animValue + 1;
			totalBottom = animValueBottom + 1;
		//	alert(total);
			$('#animValue').html(total);
			$('#animValueBottom').html(totalBottom);
		});

		$("#bullet a").click(function(){
			$(this).stopTime();
			var tabPosition = $('#bullet a').index(this);
			tabPosition = tabPosition;
			
			if(tabPosition == 0){
				$("#animValue").html(tabPosition);
				$("#topBullet").fadeOut();
			}else{
				$("#topBullet").fadeIn();
			}
			
			$("#animValue").html(tabPosition);
			
			$('#bullet a').removeClass('on');
			$('.animBlock').fadeOut();
			$('.animBlock').removeClass('on');

			$('#block'+tabPosition).addClass('on');
			$('#bullet'+tabPosition).addClass('on');
			
			//Animation du bas
			pos = tabPosition % 2;
			 $('#blockBottom'+pos).addClass('on');			
			HomeBubble.Box.Content.homeAnim.moveTriangle(tabPosition);
			
			$("#bullet a").removeClass('on');
			$(this).addClass('on');
			
			return false;
		});
		
		// List informations
		$('#content #homeList ul li').click(function(){

			var animValue =$('#animValue').html();
			
//			alert(animValue);

			$("#animValue").stopTime('animBlock');			
			$("#topBullet").fadeIn();
			var tabPosition = $('#content #homeList ul li').index(this);
			tabPosition = parseInt(tabPosition);
			tabPosition = tabPosition+1;

			$('#bullet a').removeClass('on');
			$('.animBlockTop').fadeOut();
			$('.animBlockTop').removeClass('on');
			
			$('#block'+tabPosition).addClass('on');
			$('#bullet'+tabPosition).addClass('on');			

			HomeBubble.Box.Content.homeAnim.moveTriangle(tabPosition);

			return false;

		});
		
	}
    
}


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


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

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

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

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


HomeBubble.Box.Content.ScanQuestion = {
	initialize: function () {
		
			$("#questContainer a").click(function(){
				
				$(".questShowColor").css('color', '#6E90A6');
				$(".questFadeColor").css('color', '#6E90A6');	
				$(this).css('color' , '#EC6432');
							
			});
			
			
			
			
			
    }
}


HomeBubble.Box.Content.SignIn = {
	initialize: function () {
		
		// Login function
		HomeBubble.Box.Content.SignIn.major();
		HomeBubble.Box.Content.SignIn.blinkLogin();
		
		//************************ Variables ***************************************//
		var emailNotExist = true;
		var extraEmailNotExist = true;
		var date_regexp= /^(\d{1,2}\/){2}\d{4}$/; // regular expression pour la date

		//************************ Vérification d'un email existant ************************//
		var emailExist = false;
		$("#signInEmail").blur(function(){
			// Récupération de l'email saisi par l'utilisateur
			var email = $("#signInEmail").attr('value');	
			if(email != ""){
				// Envoie de l'email via ajax
				$.ajax({
					type: "POST",
					url: HomeBubble.Paths.BASEWEB + 'default/signin/checkemailajax',
					dataType: 'json',
					data: "email="+ email,
					success: function(data){
						//Si tout va bien
						if(data.result == false){
							emailExist = false;
							$('#emailResult').css("display", "none");
							$("#emailInvalid").slideUp();
							$('#failureEmail').slideUp();
						}
						// Sinon l'email existe déjà, on informe l'utilisateur
						if (data.result == true){
							emailExist = true;
							$('#emailResult').css("display", "block");
							$("#emailInvalid").fadeOut();
						}
					}
				});			
			}
			else{
				$('#emailResult').css("display", "none");
			}
		});
		
		//************************ Vérification de l'email conjoint (existant ou pas) ************************//
		var extraEmailExist = false;
		$("#emailExtra").blur(function(){
			// Récupération de l'email saisi par l'utilisateur
			var email = $("#emailExtra").val();	
			if(email != ""){
				// Envoie de l'email via ajax
				$.ajax({
					type: "POST",
					url: HomeBubble.Paths.BASEWEB + 'default/signin/checkemailajax',
					dataType: 'json',
					data: "email="+ email,
					success: function(data){
						//Si tout va bien
						if(data.result == false){
							extraEmailExist = false;
							$('#emailExtraError').slideUp();
						}
						// Sinon l'email existe déjà, on informe l'utilisateur
						if (data.result == true){	
							extraEmailExist = true;
							$('#emailExtraError').slideDown();
							$("#emailInvalid").fadeOut();
						}
					}
				});					
			}
			else{
				$('#emailExtraError').slideUp();
			}

		});
		
		/******************** Form Animation ***************/
		
		// Open "Conditions générales d'utilisation"
		$("#signInMoreInfo").click(function(){
			$("#signFormLegal").slideToggle();	
		});
		
		// Open partner Box
		$("#signInCouple").click(function(){
			$("#signFormExtraSubscribe").slideToggle();
			$("#signFormExtraSubscribeTop").slideToggle();
			$("#signFormExtraSubscribeBottom").slideToggle();	
		});
		
		// Show tip for date of birth (dob))
		$("#birth").focus(function(){
			$("#birthTip").slideDown().fadeTo(4000, 0.6);
			
		});
		
		// Show tip for password
		$("#signInPassword").focus(function(){
			$("#signInPasswordTip").slideDown().fadeTo(4000, 0.6);	
		});
		
		$('#signInPassword').pstrength();
	
		
		/********************** Validate Form *****************/

		$("#signForm").validate({
			 ignoreTitle: true,	
			 rules: {
				    signInEmail: {
				      required: true,
				      email: true
				    },
					signInPassword: {
						required: true,
						minlength: 6
					},
					confirmSignInPassword: {
						equalTo: "#signInPassword"
					},
					secretQuestion: {
						required: true
					},
					answer: {
						required: true
					},
					firstName: {
						required: true
					},
					lastName: {
						required: true
					},
					zipCode: {
						minlength: 5,
						maxlength: 5,
						digits : true
					},
					emailExtra: {
						email: true
					},
					confirmEmailExtra: {
						equalTo: "#emailExtra"
					},
					generalConditions: {
						required:true
					}
				  }
		});

		$('#formButtonSubscribe').click(function(){

			//si le formulaire est valide
			if ($("#signForm").valid() && emailExist == false && extraEmailExist == false){
				
				//recuperation des données du formulaire
				var email = $('#signInEmail').attr("value");
				var password = $('#signInPassword').attr("value");
				var answer =  $('#answer').attr("value");

				var question = $('#secretQuestion').attr('value');
				var civility = $('#civility').attr('value');
				var firstName = $('#firstName').attr('value');
				var lastName = $('#lastName').attr('value');
				var birth = $('#birth').attr('value');
				var address = $('#address').attr('value');
				var zipCode = $('#zipCode').attr('value');
				var city = $('#signInCity').attr('value');
				var emailExtra = $('#emailExtra').attr('value');
				var idProvider = $("#idProvider").val();
				var partner = $('#partner').attr('checked'); 
				var generalConditions = $('#generalConditions').attr('checked');
				var service = $('#service:checked').val();
				
				//post data
				strUrl = HomeBubble.Paths.BASEWEB + 'default/signin/signinajax';
				$.post(strUrl, {email: email, password: password, answer: answer, question: question, civility: civility, firstName: firstName, lastName: lastName, birth: birth, address: address, zipCode: zipCode, city: city, emailExtra: emailExtra, idProvider: idProvider, partner: partner, generalConditions: generalConditions, service:service }, function(data){
				/*	data.answer = false;*/
					if(data.answer == "registered"){
						$("#emailDone").attr("value", email);
						$("#registerDone").submit();
					}else{
						$.scrollTo('#signForm',800);
						$("#failureInsert").slideDown();	
					}
				}, 'json');	
			}
			//sinon (formulaire non valide)
			else{
				$.scrollTo('#signForm',800);
				$("#failure").slideDown();
				
				//if the field of the partner are not empty, we show the field
				if($("#emailExtra").attr("value") != "" || $("#confirmEmailExtra").attr("value") != ""){
					$("#signFormExtraSubscribeTop").slideDown();
					$("#signFormExtraSubscribe").slideDown();
					$("#signFormExtraSubscribeBottom").slideDown();
				}
			}
			return false;
		});

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

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

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

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

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

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

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

			});

			$("#genPassword2").blur(function() {
				if($(this).attr("value") == "") {
					$(this).attr("value", $(this).attr("alt"));
				}	
			});
		
	},major: function(){
	
		$("#genEmail").focus(function() {
			if($(this).attr("value") == $(this).attr("alt")) {
				$(this).attr("value", "");
			}
			$("#genLoginPersistant").slideDown('slow');
		});
		
		$("#genEmail").blur(function() {
			if($(this).attr("value") == "") {
				$(this).attr("value", $(this).attr("alt"));
			}	
		});
		
		$("#genPassword").focus(function() {
			if($(this).attr("value") == $(this).attr("alt")) {
				$(this).attr("value", "");
			}
			
			$("#genLoginPersistant").slideDown('slow');
			
		});
		
		$("#genPassword").blur(function() {
			if($(this).attr("value") == "") {
				$(this).attr("value", $(this).attr("alt"));
			}	
		});
		
		$("#genLoginForm").validate({
			 ignoreTitle: true,	
			 rules: {
				    email: {

				    },
					password: {

					}
				  }
		});
		
		$("#genLoginSubmit").click(function(){
			if($("#genLoginForm").valid() && ($("#genEmail").attr('value') != $("#genEmail").attr("alt")) && ($("#genPassword").attr('value') != $("#genPassword").attr("alt"))){
				$("#genLoginForm").submit();
			//	HomeBubble.Box.Content.SignIn.sign_in();
			}else{
				
				
				
				
			}
				
			return false;	
		});
	
	},sign_in:function(){
		
		if( $("#genEmail").attr('value') == $("#genEmail").attr("alt") || $("#genPassword").attr('value') == $("#genPassword").attr("alt") ){
			
			strUrl = HomeBubble.Paths.BASEWEB + 'member/message/loginajax/';
			$("#genLoginResult").load( strUrl , {message: 'empty'} , function(){
				
				$(this).slideDown( "slow" , function(){
					$(this).oneTime("4s", function() {
					     $(this).slideUp("slow");
					});
					
				});
					
			});
			
		}else{
		

			email = $("#genEmail").attr('value');
			password = $("#genPassword").attr('value');

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

				}else{

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

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

					}else{
						$('#genLoginError').slideDown(function(){
							$(this).oneTime('4s',function(){
								$(this).slideUp();
							});
						});
					}
						/*
					$("#genLoginHover").fadeOut( 'normal' ,  function(){
						$("#genLoginContent").fadeIn();	
						$('#genLoginError').slideDown();				
					});
					*/
					
				}
			}, 'json');
		}
		
	},sign_in_modal: function(){
		
		if( $("#genEmail2").attr('value') == $("#genEmail2").attr("alt") || $("#genPassword2").attr('value') == $("#genPassword2").attr("alt") ){
			
			strUrl = HomeBubble.Paths.BASEWEB + 'member/message/loginajax/';
			$("#genLoginResult2").load( strUrl , {message: 'empty'} , function(){
				
				$(this).slideDown( "slow" , function(){
					$(this).oneTime("4s", function() {
					     $(this).slideUp("slow");
					});
					
				});
					
			});
			
		}else{
			
					
			email = $("#genEmail2").attr('value');
			password = $("#genPassword2").attr('value');

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

				}else{
					
					if(data.captchaImg)
					{	

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

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



				}
			}, 'json');
		}			

	}
 
}




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

HomeBubble.Box.Content.Bubble = {
	
		initialize: function () {
		/*
			$('.deleteRubrik').live('click', function(){
				var id = $(this).attr('id');
				var tab = id.split('-');
				idBubble = tab[1];
				HomeBubble.Box.Content.EditBubble.delete_rubrik_modal(idBubble);
				return false;
			});
		
		*/
		
			
			
		
			$('.portletIconMove').live('click', function(){
					var idUsrBubble = $(this).attr('rel');
					strUrl = '/member/bubble/checkuserrights';
					$.post(strUrl, { }, function(data){
						if(data.customtabs == 'ok'){
							 	HomeBubble.Box.Content.Bubble.move_provider_modal(idUsrBubble);
						}else{
							HomeBubble.Box.Content.EditBubble.no_rights_dialog('move_provider');
						}
					},'json');


					return false;
				
			});
		
		
				// Initialize portlet
				$(".column").sortable({
					connectWith: '.column',
					
					revert: true,
					zIndex:4000,
					stop: function(event, ui) {
						/*
						$(".column").each(function(){
							var myArray = $(this).sortable("serialize");	
						})
						*/
						var column1 = $('#bubbleColumn1').sortable('toArray');
						var column2 = $('#bubbleColumn2').sortable('toArray');
						var column3 = $('#bubbleColumn3').sortable('toArray');
						
						strUrl = HomeBubble.Paths.BASEWEB + 'member/bubble/savebubbleposition';
						$.post( strUrl ,{ 'column1[]': column1 , 'column2[]' : column2 ,  'column3[]': column3 }, function(data){
						
									
							
						});
						
					}

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

				//Add Provider
				HomeBubble.Box.Content.Bubble.default_behaviour();
				HomeBubble.Box.Content.Bubble.update_bubble_api();
				
		},
 	move_provider_modal: function(idUsrBubble){
 	
			
			test = $('.genMemberTabs.active .rubrik-name').attr('id');
			var tab = test.split('rubrik-name-');
				
 			strUrl = '/member/bubble/moveprovidermodal';
 			$("#moveProvider").load(strUrl, {currentBubble:tab[1]}, function(){}).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.Bubble.move_provider(idUsrBubble);
 							
 						},
 							/***  Bouton annuler et ses options  ***/		
 							"Annuler": function() {
 							$(this).dialog('destroy');
 						}
 
 					},
 					/***  Fonction "close"  ***/
 
 					close: function() {
 						$(this).dialog('destroy');
 					}
 
 				});
		},
		move_provider:function(idUsrBubble){
			
			var idBubbleToMove = $('#idBubbleToMove').attr('value');
			
			strUrl = '/member/bubble/moveprovider';
			$.post(strUrl, {idUsrBubble:idUsrBubble, idBubble:idBubbleToMove }, function(data){
				if(data.result == "true"){
						
						$("#moveProvider").dialog('destroy');
						$("#bubble"+idUsrBubble).fadeOut(function(){
							$("#bubble"+idUsrBubble).remove();
						});
					
				}
			}, 'json');
		},
		update_bubble_api: function(){
			
			/*
	  		bubbleApi =  $(".bubbleApiContent").attr('id');
	  		bubbleApiSelector = "#"+$(".bubbleApiContent").attr('id');
  			apiName   =  $(bubbleApiSelector).attr('rel');
	 	 	//	alert(apiName);
	  		$(bubbleApiSelector).html('<div class="genLoading"></div>');
	  		
		
			strUrl = HomeBubble.Paths.BASEWEB + 'member/api/'+apiName;
			$("#bubbleApi").load(  strUrl , { bubbleApi : bubbleApi } , function(data){

			});
				
			*/

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

				});
	
		},
		logo_link:function(){
			$(".addProviderLogoLink").live('click', function(){

				idUsrBubble = $("#idUsrBubbleProviderList").attr('value');
				idProvider = $(this).attr('rel');
				$('#addNewProvider').html('<div class="genLoading"></div>');
				strUrl = HomeBubble.Paths.BASEWEB + 'member/bubble/addproviderinfoform';
				$('#addNewProvider').load(strUrl, { idProvider: idProvider, idUsrBubble:idUsrBubble }, function(data){

				});

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

				 var middleWidth =  parseInt(viewportWidth/3);
				 var middleHeight =  parseInt(viewportHeight/5);

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

			});
			
			// Add a provider that is not in the list
			$("#addProviderNewLink").click(function(){					
				$("#addProviderNewLink").fadeOut();
				$("#nameNewProviderLabel").fadeIn(function(){
				
				
					$("#nameNewProvider").slideDown("500", function(){
					});							
				});
			});
			
			
		},
		add_modal_behaviour_provider:function(idProvider, idBubble, idBubbleTheme){

				strUrl = '/member/bubble/addproviderinfoform';

				$('#addNewBubble').load(strUrl , {  idProvider: idProvider, idUsrBubble:0, idBubbleTheme:idBubbleTheme},function(){} ).dialog({

							bgiframe: true,
							zIndex : 900,
							autoOpen: true,
							width: 570,
							minHeight: 300,
							height: 'auto',
							draggable: true,
							position: 'top',
							resizable: true,
							modal: true,
							closeOnEscape: false,
							buttons: {
										"Valider": function() {
											HomeBubble.Box.Content.Bubble.add_provider_info(idBubbleTheme, idBubble);
										},

										"Annuler": function() {
											$(this).html('');
											$(this).dialog('destroy');
											HomeBubble.Box.Content.Bubble.add_bubble_theme(idBubble);
									}

								},
						close: function(){
							$(this).html('');
							$(this).dialog('destroy');
						}

					});

		},
		add_provider_info:function(idBubbleTheme, idBubble){
			
		//	alert(idBubble);
			providerName = $('#providerName').attr('value');

			if ($(".hooverCheckbox").length){
				if($(".hooverCheckbox").is(':checked')){
					$(".hooverCheckbox").attr('value', 1);
				}
			}
			//	test = $("input[@type=text]").serialize();
			var formValues = $("#addProviderInfoForm").serialize();
			apiLink = $("#addApiLink").attr("value");
			idUsrBubble = $("#idUsrBubbleProviderInfoForm").attr('rel');
			idProvider = $("#bubbleIdProviderInfo").attr('value');
			usrBubbleName = $("#usrBubbleName").attr('value');

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

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

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


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

						strUrl = HomeBubble.Paths.BASEWEB + 'member/bubble/addproviderinfoformprocess';
						$.post( strUrl, { values : formValues , idUsrBubble : idUsrBubble , idProvider:idProvider , usrBubbleName : usrBubbleName, idBubbleTheme: idBubbleTheme, idBubble: idBubble, column: column}, function(data){
							if( data){
									//$("#addProvider").dialog("destroy");
									if ( $("input:checkbox[class=hooverCheckbox]").is(':checked') ){
											// Will do the redirect elsewhere after the hoover lightbox
											HomeBubble.Box.Content.Provider.hoover(data.idUsrBubble,idProvider, data.url);
									}else{
											window.location.href = data.url;
									}
							}									
							
						}, 'json');
			}
			
		},add_new_provider_info: function(idUsrBubble, nameNewProvider, idBubbleTheme, idBubble){
	
			titre = $("#usrBubbleTitle").attr("value");
			nameNewProvider = $("#usrBubbleName").attr("value");
			spaceClient = $("#usrBubbleSpaceClientLink").attr("value");
			identify = $("#usrBubbleIdentify").attr("value");
			password = $("#usrBubblePwd").attr("value");
			tel1 = $("#usrBubbleTel1").attr("value");
			tel2 = $("#usrBubbleTel2").attr("value");
			fax = $("#usrBubbleFax").attr("value");
			contact = $("#usrBubbleContact").attr("value");
			email = $("#usrBubbleEmail").attr("value");
			site = $("#usrBubbleSite").attr("value");
			address = $("#usrBubbleAddress").attr("value");
			other = $("#usrBubbleOther").attr("value");
			contractNumber = $("#usrBubbleContractNumber").attr("value");
			clientNumber = $("#usrBubbleClientNumber").attr("value");
			otherRef = $("#usrBubbleOtherRef").attr("value");
			
			$(".ui-dialog-buttonpane").append('<div class="genLoadingModalSubmit">Merci de patienter...</div>');

			strUrl = HomeBubble.Paths.BASEWEB + 'member/bubble/addnewproviderinfoformprocess';
			$.post(strUrl, {idUsrBubble: idUsrBubble, idBubble: idBubble, idBubbleTheme: idBubbleTheme, nameNewProvider: nameNewProvider, titre: titre, spaceClient: spaceClient, identify: identify, password: password, tel1: tel1, tel2: tel2, site: site, address: address, other: other, contractNumber:contractNumber, clientNumber: clientNumber, email:email, fax:fax, conatct:contact , otherRef:otherRef, column: column }, function(data){
				
					if(data){
						//$("#addOtherProvider").html('');
						//$("#addOtherProvider").dialog('destroy');
						window.location.href = data;
					}
				
			})
			
		},
		add_provider_info_behaviour: function(){
			var rel = $(".addProvClassTextareaShow").attr('rel');
		
			if($(".addProvClassTextareaHide[rel='"+rel+"']").attr('value') != ''){
				$(".addProvClassTextareaHide[rel='"+rel+"']").show();
			}else{
				$(".addProvClassTextareaHide[rel='"+rel+"']").hide();
			}

			$(".addProvClassTextareaShow").click(function(){
					$(".addProvClassTextareaHide[rel='"+$(this).attr('rel')+"']").slideDown();
					return false;
			});
			
			
			// Hoover exception concerning the modification of a field
			if ($(".hooverCheckbox").length){
				
			
				$(".hooverCheckbox").click(function(){		
						$("#hooverOld").attr('value', 0);
				});
				
				$('.blockClient :text').each(function(i,e){
					if( $(this).attr('value') == ''){
						allFieldsAreFilled = false;
					}
					
					$(this).change(function(){
							$("#hooverOld").attr('value', 0);
					});
					
					
				}); 
		
				$('.blockClient :password').each(function(i,e){
					if( $(this).attr('value') == ''){
						allFieldsAreFilled = false;
					}
					
					$(this).change(function(){
						$("#hooverOld").attr('value', 0);
					});
					
				});	
				
			}
			
			
		},
		add_bubble_theme:function(idBubble){

			strUrl = HomeBubble.Paths.BASEWEB + 'member/bubble/addbubblethememodal';
			var seoBubbleName = $('#bubbleSeoName').attr('value');

			$('#addNewBubble').load(strUrl , { idBubble: idBubble, seoBubbleName: seoBubbleName } ).dialog({
					
						bgiframe: true,
						zIndex : 900,
						autoOpen: true,
						width: 670,
						minHeight: 500,
						height: 'auto',
						draggable: true,
						position: 'middle',
						resizable: true,
						modal: true,
						closeOnEscape: false,
						buttons: {
			
									
									"Annuler": function() {
										$(this).html('');
										$(this).dialog('destroy');
								}
							
							},
					close: function(){
						$(this).html('');
						$(this).dialog('destroy');
					}

				});
			
			
			
			
			
		},
		add_bubble_theme_behaviour: function(){
			
		/*	$(".bubbleThemeNewContainer").click(function(){
					idBubble = $("#idBubble").attr('rel');
					idBubbleTheme = $(this).attr('rel');
					
		
					$('#addNewBubble').dialog('destroy');
					HomeBubble.Box.Content.Bubble.add_modal_provider(idBubble, idBubbleTheme);
					
				
			});*/
			
			$("#bubbleTabs").tabs({
				select: function(event,ui){
					//	var selected = $(this).tabs('option', 'selected');
					//	alert(selected);
					$("#bubbleTabs li").removeClass('ui-state-active');
					$("#bubbleTabs li").removeClass('ui-tabs-selected');
					$("#ui-tabs-1").html('<div class="genNormalLoading"></div>');
					$('#providerList').hide();
				},
				ajaxOptions: {
								error: function( xhr, status, index, anchor ) {
									$( anchor.hash ).html(
										"Merci de reessayer... ");
								}
							}
				
				
			//	var selected = $tabs.tabs('option', 'selected')
				//	$(this).tabs( 'select' , '2' );
			});
			$('#bubbleTabs li').removeClass('ui-state-disabled');
			
		
			
			var seoBubbleName = $("#seoBubbleName").attr('value');
			$("#providerName").autocomplete({
							source: function(request, response) {
								$.ajax({
									url: "/member/provider/autocompleteprovider/",
									dataType: "json",

									data: {
										featureClass: "P",
										style: "full",
										maxRows: 12,
										name_startsWith: request.term,
										seoBubbleName: seoBubbleName
									},
									success: function(data) {

										response($.map(data.geonames, function(item) {

											return {
												label: item.name + ' - ' + item.bubbleName+'',
												value: item.name,
												idProvider: item.idProvider,
												idBubbleTheme: item.idBubbleTheme
											};

										}));
									}
								});
							},
							minLength: 1,
							select: function(event, ui) {
									//console.log(ui.item);
									$("#modaleFormElemBlue").append('<div class="genModalLoading"></div>');
									$('#idprovider').attr('value', ui.item.id);
									$('#addNewBubble').html();	
									$('#addNewBubble').dialog('destroy');
									var idBubble = $('#idBubble').attr('value');
									HomeBubble.Box.Content.Bubble.add_modal_behaviour_provider(ui.item.idProvider, idBubble, ui.item.idBubbleTheme);
							}
				});	
				
				$('#add_provider').click(function(){
					
					var idBubble = $('#idBubble').attr('value');

					var idBubbleTheme = 21;
					var idProvider = null;
					
					$('#addNewBubble').html();	
					$('#addNewBubble').dialog('destroy');
					
					HomeBubble.Box.Content.Bubble.add_provider_info(idBubbleTheme, idBubble);
					
					return false;
				}); 
				
				/*
				$('.bubble-item').click(function(){
					
					$('#rubrikList').show();
					$('#rubrikList .list').html('<div class="genNormalLoading"></div>')
					
					$('.bubble-selected').removeClass('bubble-selected');
					$(this).addClass('bubble-selected');
					//$('#rubrikList').hide();
					$('#providerList').hide();
					
					var id = $(this).attr('id');
					var tab = id.split('-');
					idBubble = tab[1];

					strUrl = '/member/bubble/loadrubrik';
					$('#rubrikList .list').load(strUrl, {idBubble: idBubble}, function(data){
						
					});
					return false;
				});
				*/
				$('.bubbleTheme-item').live('click', function(){
					
					$('#providerList').show();
					$('#providerList .list').html('<div class="genNormalLoading"></div>');
					
					$('.bubbleTheme-selected').removeClass('bubbleTheme-selected');
					$(this).addClass('bubbleTheme-selected');
										
					var id = $(this).attr('id');
					var tab = id.split('-');
					idBubbleTheme = tab[1];
					
					strUrl = '/member/bubble/loadprovider';
					$('#providerList .list').load(strUrl, {idBubbleTheme: idBubbleTheme}, function(data){
					//	$('#providerList').show();
					});
					
					return false;
				});
	
				$('.provider-item').live('click', function(){
					
					$('#providerList').append('<div class="genModalLoading" ></div>');
					
					var idBubbleTheme = $('.bubbleTheme-selected').attr('id');
					var tab2 = idBubbleTheme.split('-');
					idBubbleTheme = tab2[1];
					
					var idProvider = $(this).attr('id');
					var tab3 = idProvider.split('-');
					idProvider = tab3[1];
					
					$('#addNewBubble').html();	
					$('#addNewBubble').dialog('destroy');
					var idBubble = $('#idBubble').attr('value');

					HomeBubble.Box.Content.Bubble.add_modal_behaviour_provider(idProvider, idBubble, idBubbleTheme);
					
					return false;
				});
				
				//Add New provider
				$('.addEmptyRubrik').live('click', function(){
					var idBubble = $('#idBubble').attr('value');

					var idBubbleTheme = 21;
					var idProvider = null;
					
					$('#addNewBubble').html();	
					$('#addNewBubble').dialog('destroy');
					
					HomeBubble.Box.Content.Bubble.add_provider_info(idBubbleTheme, idBubble);
				})
			
		}
		
		
		
		

}

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

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


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

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

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

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

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


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

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

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

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


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

	}
	
	
}

HomeBubble.Box.Content.Password = {
	
	initialize: function () {
		
	//Start modal for forget password feature
	$('#genLoginMorePassword').click(function(){	
		strUrl = HomeBubble.Paths.BASEWEB + 'default/signin/forgotpassword';
		$('#genLoginMorePasswordModal').html('<div class="genLoading"></div>');
		$('#genLoginMorePasswordModal').load(strUrl , { validate: true } ).dialog({
			bgiframe: true,	
			autoOpen: true,	
			height: 'auto',
			draggable: true,
			resizable: true,
			width: 500,
			modal: true,
			closeOnEscape: false,
			buttons: {
					/***  Bouton Valider et ses options  ***/
					"Valider": function() {	
						HomeBubble.Box.Content.Password.forgot_password();
					
						},
					/***  Bouton annuler et ses options  ***/
					"Annuler": function() {

						$(this).dialog('destroy');
					}	
				},
				close : function(){
					$(this).dialog('destroy');												
					}
			});		
				
		});
	    
		$('.dialog div').bind( "dialogopen", function(event, ui) {
			$(".ui-button-text:contains('Annuler')").parent().addClass('ui-dialog-cancel');
			$(".ui-button-text:contains('Annuler')").parent().removeClass('ui-state-default');
						
			$(".ui-button-text:contains('Valider')").parent().removeClass('ui-state-default');
			$(".ui-button-text:contains('Valider')").parent().addClass('ui-dialog-valid');
	
			$(".ui-button-text:contains('Pré-visualiser')").parent().removeClass('ui-state-default');
			$(".ui-button-text:contains('Pré-visualiser')").parent().addClass('ui-dialog-valid');			
			
			$(".ui-button-text:contains('Enregistrer')").parent().removeClass('ui-state-default');
			$(".ui-button-text:contains('Enregistrer')").parent().addClass('ui-dialog-valid');
			
			$(".ui-button-text:contains('Imprimer')").parent().removeClass('ui-state-default');
			$(".ui-button-text:contains('Imprimer')").parent().addClass('ui-dialog-valid');
			
			$(".ui-button-text:contains('Supprimer la rubrique')").parent().removeClass('ui-state-default');
			$(".ui-button-text:contains('Supprimer la rubrique')").parent().addClass('ui-dialog-valid');
			
			$(".ui-button-text:contains('Souscrire à Bubble Plus')").parent().removeClass('ui-state-default');
			$(".ui-button-text:contains('Souscrire à Bubble Plus')").parent().addClass('ui-dialog-valid');

		});

	
    },forgot_password:function(){
		
		var email = $('#signInForgotPasswordFormEmail').val();
		strUrl = HomeBubble.Paths.BASEWEB + 'member/auth/checkemailpasswordajax';

			$.post(strUrl, { email: email}, function(data){	
				if(data == "exist"){	
					$('#signInForgotPasswordFail').slideUp();
					$('#signInForgotPasswordSuccess').slideDown();	
					//$('#genLoginMorePasswordModal').dialog('close');
					HomeBubble.Box.Content.Password.modal_question();
					$("#genLoginMorePasswordModal").dialog('option', 'buttons', { 
							 "Fermer": function(){
							 	$("#genLoginMorePasswordModal").dialog('destroy');
							 } 
						});
				}
				if(data== "non-exist"){	
					$('#signInForgotPasswordSuccess').slideUp();
					$('#signInForgotPasswordFail').slideDown();
				}				
			});	
	
	},modal_question: function(){
		

	}
			
}
