var child_nb;
var cal_child_1;
var cal_child_2;
var cal_child_3;
var cal_child_4;
var cal_child_5;

function initNbChild(){
	child_nb = parseInt(document.getElementById('child_nb').value);
	if(isNaN(child_nb)||child_nb == 0){
		child_nb = 1;
		document.getElementById('child_nb').value = 1;
	}
	for(i = 1 ; i<=child_nb; i++){
		document.getElementById('child_'+i).style.display = 'block';
	}
}

function HideChild(){
	if(child_nb > 1){	
		for(i = child_nb ; i<=5; i++){
			document.getElementById('child_'+i).style.display = 'none';
		}
		child_nb--;
		document.getElementById('child_nb').value = child_nb;
	}
}

function DisplayChild(){
	if(child_nb <= 5){
		for(i = 1; i <= child_nb + 1; i++){
			document.getElementById('child_'+i).style.display = 'block';
		}
		child_nb++;
		document.getElementById('child_nb').value = child_nb;
	}
}

function confirme_creation_compte(lg){
	if(!lg) lg = 'fr';
	if($('container') != null){
			$('container').remove();
	}
	
	affichage_de_base(lg);
	
	var url='/tmpl_dev_shopping/'+lg+'/mon_compte/cree_mon_compte_client_result.html';
	var get_html_infos = new Ajax(url, {
		method: 'get',
		update: $('infos_compte'),
		onSuccess: function(){
				$('loading').remove();
				//on realigne car l'element ne fait plus la meme taille
				valigncenter($('infos_compte'));
				
				$('fermer_confirme_creation_compte').addEvent('click', function(){
						var container = $('container');
						//effet de fondu avant la fermeture
						new Fx.Style(container, 'opacity', {
							onComplete : function(){
								//on detruit la galeries
								container.remove();
								if (window.ie && !window.ie7){
									$('container2').remove();
								}
								window.location.href = '/pl/account.pl';
							}
						}).start(1,0);
				});
				
				var myFx = new Fx.Style($('infos_compte'), 'opacity').start(0,1);
		},
		onFailure: function(){
			//feinte pour le problème des accents
			var txt = new Element('span');
			txt.innerHTML = 'Votre compte client a été créé.';
			alert(txt.innerHTML);
		}
	}).request();
}
function confirme_update_compte(lg){
	if(!lg) lg = 'fr';
	if($('container') != null){
			$('container').remove();
	}
	
	affichage_de_base(lg);
	
	var url='/tmpl_dev_shopping/'+lg+'/mon_compte/vos_informations_personnelles_result.html';
	var get_html_infos = new Ajax(url, {
		method: 'get',
		update: $('infos_compte'),
		onSuccess: function(){
				$('loading').remove();
				//on realigne car l'element ne fait plus la meme taille
				valigncenter($('infos_compte'));
				
				$('fermer_confirme_update_compte').addEvent('click', function(){
						var container = $('container');
						//effet de fondu avant la fermeture
						new Fx.Style(container, 'opacity', {
							onComplete : function(){
								//on detruit la galeries
								container.remove();
								if (window.ie && !window.ie7){
									$('container2').remove();
								}
								window.location.href = '/pl/account.pl';
							}
						}).start(1,0);
				});
				
				var myFx = new Fx.Style($('infos_compte'), 'opacity').start(0,1);
		},
		onFailure: function(){
			//feinte pour le problème des accents
			var txt = new Element('span');
			txt.innerHTML = 'Votre compte client a été mis à jour.';
			alert(txt.innerHTML);
			$('container').remove();
			if (window.ie && !window.ie7){
				$('container2').remove();
			}
		}
	}).request();
}
function affichage_de_base(lg){
	if(!lg) lg = 'fr';
	if($('container') != null){
			$('container').remove();
	}
	
	//creation des elements
	container = new Element('div', {
										'styles': 
										{
											'display': 'block',
											'width': '100%',
											'height': '100%',
											'padding': '0px',
											'left': '0',
											'margin': '0px',
											'position': 'fixed',
											'top': '0',
											'text-align': 'center',
											'background-image': 'url(/images/overlay.png)',
											'z-index': '5'
										}
								  }
							);
	
	if (window.ie && !window.ie7){
		container.style.position = 'absolute';
		container.style.height = document.documentElement.clientHeight;
		container.style.background = 'none';
		container.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src='/images/overlay.png')";
		container.style.zIndex = '0';
		
		container2 = new Element('div', {
										'styles': 
										{
											'display': 'block',
											'width': '100%',
											'height': '100%',
											'padding': '0px',
											'left': '0',
											'margin': '0px',
											'position': 'absolute',
											'top': '0',
											'text-align': 'center',
											'z-index': '10'
										}
								  }
							);
		//pour ie6 (pour avoir les liens cliquables
		container2.setAttribute('id','container2');
		container2.injectInside(document.body);
	}
	
	container.setAttribute('id','container');
	container.injectInside(document.body);
	
	//afficher barre de chargement
	loading = new Element('div', {
										'styles': 
										{
											'display': 'block',
											'width': '220px',
											'height': '19px',
											'padding': '0px',
											'text-align': 'left',
											'margin':'0 auto',
											'background-image': 'url(/images/smoothgallery/loading-bar-black.gif)',
											'top' : '50%'
										}
								  }
						 );
	loading.setAttribute('id','loading');
	loading.injectInside(container);
	//centrer verticalement par rapport à la page
	valigncenter(loading);
	
	var infos_compte = new Element('div', {
													'styles': 
													{
														'display': 'block',
														'width': '350px',
														'height': '105px',
														'padding': '0px',
														'text-align': 'left',
														'margin':'0 auto',
														'z-index':'1000',
														'position':'absolute'
													}
											  }
										);
		 
	infos_compte.setAttribute('id','infos_compte');
	
	if (window.ie && !window.ie7){
		infos_compte.injectInside($('container2'));
	}else{
		infos_compte.injectInside($('container'));
	}
	
	valigncenter(infos_compte);
	var myFx = new Fx.Style(infos_compte, 'opacity').set(0);
}
function valigncenter(lmt)
{
	var page = document.documentElement;
	if(lmt && page)
	{
	    var containerHeight;
	    if (page.innerWidth)
	    {
            containerHeight = page.innerHeight;
		}
		else
		{
            containerHeight = page.clientHeight;
		}
	    var lmtHeight;
	    if (lmt.innerWidth)
	    {
            lmtHeight = lmt.innerHeight;
		}
		else
		{
            lmtHeight = lmt.offsetHeight;
		}
		var y = Math.ceil((containerHeight - lmtHeight) / 2);
		if(y < 0)
		{
			y = 0;
		}
		lmt.style.position = "relative";
		lmt.style.top = y + "px";
	}
	if (document.getElementById)
	{
		document.body.style.visibility = 'visible';
	}
}

function selectDateChild1(date){
	document.getElementById('child_date_birth_1').value = cal_child_1.getFormatedDate('%d/%m/%Y',date);
	document.getElementById('cal_child_1').style.display = 'none';
}
function selectDateChild2(date){
	document.getElementById('child_date_birth_2').value = cal_child_2.getFormatedDate('%d/%m/%Y',date);
	document.getElementById('cal_child_2').style.display = 'none';
}
function selectDateChild3(date){
	document.getElementById('child_date_birth_3').value = cal_child_3.getFormatedDate('%d/%m/%Y',date);
	document.getElementById('cal_child_3').style.display = 'none';
}
function selectDateChild4(date){
	document.getElementById('child_date_birth_4').value = cal_child_4.getFormatedDate('%d/%m/%Y',date);
	document.getElementById('cal_child_4').style.display = 'none';
}
function selectDateChild5(date){
	document.getElementById('child_date_birth_5').value = cal_child_5.getFormatedDate('%d/%m/%Y',date);
	document.getElementById('cal_child_5').style.display = 'none';
}

function showCalendar(c){
		document.getElementById(c).style.display = 'block';
}

function initCalendar(){
	var reg_exp_date = /\d{2}\/d{2}\/d{4}/;
	dhtmlxCalendarLangModules = new Array();
	dhtmlxCalendarLangModules['fr'] = {
		langname:    'fr',
		dateformat:    '%d/%m/%Y',
		monthesFNames:    ["Janvier", "Fevrier", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Decembre"],
		monthesSNames:    ["Jan", "Fev", "Mar", "Avr", "Mai", "Jun", "Jui", "Aou", "Sep", "Oct", "Nov", "Dec"],
		daysFNames:    ["Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "vendredi", "Samedi"],
		daysSNames:    ["Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam"],
		weekend:    [0, 6],
		weekstart:    1,
		msgClose:     "Fermer",
		msgMinimize: "Reduire",
		msgToday:     "Aujourd'hui"
	}
	cal_child_1 = new dhtmlxCalendarObject('cal_child_1');
	cal_child_1.loadUserLanguage("fr");
	if(reg_exp_date.test(document.getElementById('child_date_birth_1').value))
		cal_child_1.setDate(document.getElementById('child_date_birth_1').value);
	cal_child_1.setOnClickHandler(selectDateChild1);
	cal_child_2 = new dhtmlxCalendarObject('cal_child_2');
	cal_child_2.loadUserLanguage("fr");
	if(reg_exp_date.test(document.getElementById('child_date_birth_2').value))
		cal_child_2.setDate(document.getElementById('child_date_birth_2').value);
	cal_child_2.setOnClickHandler(selectDateChild2);
	cal_child_3 = new dhtmlxCalendarObject('cal_child_3');
	cal_child_3.loadUserLanguage("fr");
	if(reg_exp_date.test(document.getElementById('child_date_birth_3').value))
		cal_child_3.setDate(document.getElementById('child_date_birth_3').value);
	cal_child_3.setOnClickHandler(selectDateChild3);
	cal_child_4 = new dhtmlxCalendarObject('cal_child_4');
	cal_child_4.loadUserLanguage("fr");
	if(reg_exp_date.test(document.getElementById('child_date_birth_4').value))
		cal_child_4.setDate(document.getElementById('child_date_birth_4').value);
	cal_child_4.setOnClickHandler(selectDateChild4);
	cal_child_5 = new dhtmlxCalendarObject('cal_child_5');
	cal_child_5.loadUserLanguage("fr");
	if(reg_exp_date.test(document.getElementById('child_date_birth_5').value))
		cal_child_5.setDate(document.getElementById('child_date_birth_5').value);
	cal_child_5.setOnClickHandler(selectDateChild5);
}
