function ajoutLignePlanning(path)
{	
	activeLoader();
	var lastIndex = $('#form_planning #lastIndex').val();	
	
	$.ajax({
		dataType : 'html',
		url: path,
		data: {lastIndex : lastIndex},
		type: "POST",
		success: function(result){
			$('table#lignesPlanning tbody tr:last-child').before(result);
			
			desactiveLoader();
			index = (parseInt(lastIndex)+1);
			$('#form_planning #lastIndex').val(index);
			displayBtnSupprimer();
		}
	});
}

function suppressionLignePlanning(index)
{
	$('#PLANNING'+index).remove();
	totalQtePlanning();
	displayBtnSupprimer();
}

function totalQtePlanning(input)
{
	activeLoader();
	
	QTE_DEM = $('#planning_QTE_DEM').val().replace(',', '.').replace(new RegExp(' ', 'g'), '');
	totalQte = 0;
	$('[id^="input_planning_QTE_"]').each(function(){
		qteLigne = $(this).val().replace(',', '.').replace(new RegExp(' ', 'g'), '');
		totalQte = parseFloat(totalQte) + parseFloat(qteLigne);
	});
	resteACadencer = parseFloat(QTE_DEM) - parseFloat(totalQte);

	if(resteACadencer != 0)
	{
		$('#resteACadencer').removeClass('textVert').addClass('textRouge');
	}else{
		$('#resteACadencer').removeClass('textRouge').addClass('textVert');
	}
	
	if(input){		
		$(input).val(parseFloat($(input).val()).toFixed(3));
		separateurMilier(input);
	}
	var sep = ' ';
	var reg = /(\d+)(\d{3})/;
	while( reg.test( resteACadencer)) {
		resteACadencer = resteACadencer.replace( reg, '$1' +sep +'$2');
	}	
	$('#resteACadencer .resultat').text(parseFloat(resteACadencer).toFixed(3));
	desactiveLoader();
}

function displayBtnSupprimer(){
	if($('[name^="planning_QTE_"]').length <= 1){
		$('.btn_supprimer').hide();
		$('#btnEnreg').hide();
	}
	else{
		$('.btn_supprimer').show();
		$('#btnEnreg').show();
	}
}
