box.dom(document).ready(function(){	
	//	register form : open newsletter popin
	$('#pregnancyBook').click(function(e){
		box.ui('plugin.popin.global').open({
                id: 'popinNewsletterpregnancynotebook',
                url: '/index.php?option=com_service&view=newsletter&tpl=pregnancynotebook',
                cache: false
            });
	});
	$('#createBook').click(function(e){
		box.ui('plugin.popin.global').open({
                id: 'popinNewsletterbabynotebook',
                url: '/index.php?option=com_service&view=newsletter&tpl=babynotebook',
                cache: false
            });
	});		
	$('#personalizedFollowUp').click(function(e){
		box.ui('plugin.popin.global').open({
                id: 'popinNewslettergrosse',
                url: '/index.php?option=com_service&view=newsletter&tpl=grosse',
                cache: false
            });
	});			
	$('#discoverClubGallia').click(function(e){
		box.ui('plugin.popin.global').open({
                id: 'popinNewsletterconseil',
                url: '/index.php?option=com_service&view=newsletter&tpl=conseil',
                cache: false
            });
	});			
	$('#monthlyMenus').click(function(e){
		box.ui('plugin.popin.global').open({
                id: 'popinNewslettermenu',
                url: '/index.php?option=com_service&view=newsletter&tpl=menu',
                cache: false
            });
	});		
	box.dom(".babyBirthdaySelect").live("click",function(){
		//alert(1);
	 	box.dom(this).siblings(".yourBabyMore").show()
	});
	 
	if(parseInt($("#babyamount").val())-1<1){
		box.dom("#babyInfoLink1").hide();
	}
			//make radioBox of tab2 clickable
			$("li label").live("click",function(){		
				  $(this).parent("li").parent("ul").children("li").children("label").attr("class","");	
				  $(this).attr("class","checked");					 
			});			
			

			
				
	$(".babyInfoLink2").live("click",function(){	
		box.dom("#babyInfoLink1").show();
		var content;
		var thisObj=$(this);
	
		if(parseInt($("#babyamount").val()) == 4) {
		    box.dom(".babyInfoLink2").hide();
		}
		var babyNumber=parseInt($("#babyamount").val())+1;	
			content  = $("#babytemplate").html();						
			content  = String(content);
			
			//alert(typeof(content));
			content = content.replace('@INDEXSHOW@',String(babyNumber));
			content = content.replace(/@INDEX@/g,String(babyNumber-1));
			
			$("#babyzone").append(content).children(".yourBaby").children(".yourBabyMore:last").hide(); 
			 
			$("#babyamount").val(babyNumber);	
			
		
			$("li label").live("click",function(){		
				  $(this).parent("li").parent("ul").children("li").children("label").attr("class","");	
				  $(this).attr("class","checked");					 
			});			
			
			box.ui('form').destroy('register');
			var form=createForm();
			form.addReplacement();
			runValidator(form);
			
			
			/*box.ui('form').create({
				element: '#register'
			}).addReplacement();*/
		
		box.dom(".yourBabyMore:last").hide();
		//box.dom("#btnRegSubmit").click();
		return false;								   
	});	
	
	$("#babyInfoLink1").live("click",function(){		
			
				var i = parseInt($("#babyamount").val());
				
				if( i == 5) {
				    box.dom(".babyInfoLink2").show();
				}
				//alert(i);
				//don't allow to delete the first one
				if( i == 1){
					
					return false;
				}
				if( i <= 2){
					
					box.dom("#babyInfoLink1").hide();
				}
				
								
				var babyNumber=parseInt($("#babyamount").val())-1;
				
				//alert($(".yourBaby").length);
				
				var current = 1;
				$(".yourBaby").each(function(){
					
					if( current == (babyNumber+1))
					{
						$(this).remove();
					}
					
					current++;
				})
				
				//$(".yourBaby:last").remove();
				
				
				$("#babyamount").val(babyNumber);	
				
				box.ui('form').destroy('register');
				var form=createForm();
				form.addReplacement();
				runValidator(form);
			
				
				/*
				box.ui('form').create({
					element: '#register'
				}).addReplacement();
				*/
					return false;												   
			});
});





