jQuery(function($){
	$.datepicker.regional['fr'] = {clearText: 'Effacer', clearStatus: '',
		closeText: 'Fermer', closeStatus: 'Fermer sans modifier',
		prevText: "&lt;Prec", prevStatus: "Voir le mois pre'ce'dent",
		nextText: 'Suiv&gt;', nextStatus: 'Voir le mois suivant',
		currentText: 'Courant', currentStatus: 'Voir le mois courant',
		monthNames: ['Janvier','Fe\'vrier','Mars','Avril','Mai','Juin',
		'Juillet','Aou^t','Septembre','Octobre','Novembre',"De'cembre"],
		monthNamesShort: ['Jan','Fe\'v','Mar','Avr','Mai','Jun',
		'Jul','Aou^','Sep','Oct','Nov','De\'c'],
		monthStatus: 'Voir un autre mois', yearStatus: "Voir un autre anne'e",
		weekHeader: 'Sm', weekStatus: '',
		dayNames: ['Dimanche','Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi'],
		dayNamesShort: ['Dim','Lun','Mar','Mer','Jeu','Ven','Sam'],
		dayNamesMin: ['Di','Lu','Ma','Me','Je','Ve','Sa'],
		dayStatus: 'Utiliser DD comme premier jour de la semaine', dateStatus: 'Choisir le DD, MM d',
		dateFormat: 'dd/mm/yy', firstDay: 0, 
		initStatus: 'Choisir la date', isRTL: false};
	$.datepicker.setDefaults($.datepicker.regional['fr']);
});

$(function(){
/*	
	$('#delivery_form label').wrap('<div></div>').each(function(){
		$('#'+$(this).attr('for')).insertAfter(this);	
	});
*/	
	//$('#delivery_form label,#delivery_form input').wrap('<div></div>');


//, monthNames : ['Janvier', 'F&#233;vrier', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Ao&#251;t', 'Septembre', 'Octobre', 'Novembre', 'D&#233;cembre'] 
	$('INPUT.date').attr('readonly','readonly').datepicker({dateFormat: 'dd/mm/yy'});
	$('#f1').change(function(){
		$(this).parent().parent().children('fieldset').hide();		
		if($(this).val()=='une entreprise'){
			$('#s1_0').show();			
		}
		else if($(this).val()=='un particulier'){
			$('#s1_1').show();
		}
	});
	
	$('#f2_1').change(function(){
		$(this).parent().parent().children('fieldset').hide();
		switch($(this).val()){
			case 'Piano':{
				$('#s2_0').show();break;
			}
			case 'Coffre-fort ou armoire forte':{
				$('#s2_1').show();break;
			}
			case 'Dèmènagement':{
				$('#s2_2').show();break;
			}
			case 'Objet d\'art':{
				$('#s2_3').show();break;
			}
			case 'Autre':{
				$('#s2_4').show();break;
			}
		}
		
		if(this.selectedIndex==3){
			$('#s2_2').show();
			
		}		
	});
	
	$('#f2_20').change(function(){
		$(this).parent().parent().children('fieldset').hide();
		if($(this).val()=='ne sait pas'){
			$('#s2_2_0').show();
		}
		else if($(this).val().indexOf('préciser')!=-1){
			$('#s2_2_1').show();
		}
	});
	
	$('#f3_6').change(function(){
		$('#s3_0').hide();
		$('#i_f3_7').hide();
		if($(this).val().indexOf('RdC')!=-1){
			$('#s3_0').hide();			
		}
		else if($(this).val().indexOf('7')!=-1){
			$('#s3_0').show();
			$('#i_f3_7').show();
		}
		else if($(this).val().match(/\d/)){
			$('#s3_0').show();
		}
	});
	
	$('#f3_8').change(function(){
		$('#s3_0_0').hide();
		if($(this).val()=='Non'){
			$('#s3_0_0').show();
		}
	});

	$('#f3_13').change(function(){
		$('#s3_0_0_0').hide();
		if($(this).val().indexOf('preciser')!=-1){
			$('#s3_0_0_0').show();
		}
	});
	
/*	
	$('#f3_10').change(function(){
		$('#s3_1').hide();
		if($(this).val()=='Oui'){
			$('#s3_1').show();
		}		
	})
	*/
		$('#f3_10').change(function(){
		$('#s3_1').hide();
		if($(this).val()=='Oui'){
			$('#i_f3_11_3s').hide(); $('#i_f3_11_4s').hide();
			$('#f3_11_3').click(function(){	if($(this).attr('checked')) $('#i_f3_11_3s').show(); else  $('#i_f3_11_3s').hide(); });
			$('#f3_11_4').click(function(){	if($(this).attr('checked')) $('#i_f3_11_4s').show(); else  $('#i_f3_11_4s').hide(); });
			$('#s3_1').show();
		}		
	})
	

	$('#s3_1 .cb').change(function(){
		if($("#s3_1 input:checked").length==0){
			alert('Si il y a des difficultés particulières, vous devez sélectionner au moins une des 4 options ci-dessous');
			this.checked=true;
		}
	});
	
/*	
	$('#f3_11').change(function(){
		$('#s3_1_0').hide();
		if($(this).val().indexOf('(préciser)')!=-1){
			$('#s3_1_0').show();
		}		
	})
*/	
	
$('#s4_1 .cb').change(function(){
	if($("#s4_1 input:checked").length==0){
		alert('Si il y a des difficultés particulières, vous devez sélectionner au moins une des 4 options ci-dessous');
		this.checked=true;
	}
});

$('#f4_6').change(function(){
	$('#s4_0').hide();
	$('#i_f4_7').hide();
	if($(this).val().indexOf('RdC')!=-1){
		$('#s4_0').hide();			
	}
	else if($(this).val().indexOf('7')!=-1){
		$('#s4_0').show();
		$('#i_f4_7').show();
	}
	else if($(this).val().match(/\d/)){
		$('#s4_0').show();
	}
});

$('#f4_8').change(function(){
	$('#s4_0_0').hide();
	if($(this).val()=='Non'){
		$('#s4_0_0').show();
	}
});

$('#f4_13').change(function(){
	$('#s4_0_0_0').hide();
	if($(this).val().indexOf('preciser')!=-1){
		$('#s4_0_0_0').show();
	}
});

	$('#f4_10').change(function(){
		$('#s4_1').hide();
		if($(this).val()=='Oui'){
			$('#i_f4_11_3s').hide(); $('#i_f4_11_4s').hide();
			$('#f4_11_3').click(function(){	if($(this).attr('checked')) $('#i_f4_11_3s').show(); else  $('#i_f4_11_3s').hide(); });
			$('#f4_11_4').click(function(){	if($(this).attr('checked')) $('#i_f4_11_4s').show(); else  $('#i_f4_11_4s').hide(); });
			$('#s4_1').show();
		}		
	})
	
	$('#f4_11').change(function(){
		$('#s4_1_0').hide();
		if($(this).val().indexOf('(préciser)')!=-1){
			$('#s4_1_0').show();
		}		
	});
	
	$('#f5_1').change(function(){
		$('#s5_0').hide();
		if($(this).val()=='Oui'){
			$('#s5_0').show();
		}		
	})
	
	$('#delivery_form *:input').change();

	$('#delivery_form').submit(function(){	
		var fieldsets = $('#delivery_form FIELDSET FIELDSET:hidden');
			$.each( fieldsets, function(i, n){ 
				$(n).remove();
			});
	});
	
	
	$('#s2_2_0 input[readonly!=readonly]').change(function(){
		var volume=$('#f2_21').val()*2+$('#f2_22').val()*1+$('#f2_23').val()*1+$('#f2_24').val()*0.5+$('#f2_25').val()*0.5+$('#f2_26').val()*0.2;
		$('#f2_27').val(volume);
	})
	
	
});
