<!-- formulaire de tarifs -->

//UDSms - propal
function initForm(){
	//remise à zéro
	document.form1.valInit.value=0;
	document.form1.total.value=document.form1.valInit.value;
	document.form1.totaltotal.value=document.form1.valInit.value;
	for (i=0; i < document.form1.elements.length; i++) {
		if ((document.form1.elements[i].type == 'checkbox') | (document.form1.elements[i].type == 'radio')) {
			document.form1.elements[i].checked = false;
		}
		if (document.form1.elements[i].type == "select-one"){
			document.form1.elements[i].options[0].selected = true;
		}
  	}
	document.form1.print.disabled = false;
}


//////////////////////////////////////
function format(valeur,decimal,separateur) {
// formate un chiffre avec 'decimal' chiffres après la virgule et un separateur
	var deci=Math.round( Math.pow(10,decimal)*(Math.abs(valeur)-Math.floor(Math.abs(valeur)))) ; 
	var val=Math.floor(Math.abs(valeur));
	if ((decimal==0)||(deci==Math.pow(10,decimal))) {val=Math.floor(Math.abs(valeur)); deci=0;}
	var val_format=val+"";
	var nb=val_format.length;
	for (var i=1;i<4;i++) {
		if (val>=Math.pow(10,(3*i))) {
			val_format=val_format.substring(0,nb-(3*i))+separateur+val_format.substring(nb-(3*i));
		}
	}
	if (decimal>0) {
		var decim=""; 
		for (var j=0;j<(decimal-deci.toString().length);j++) {decim+="0";}
		deci=decim+deci.toString();
		val_format=val_format+"."+deci;
	}
	if (parseFloat(valeur)<0) {val_format="-"+val_format;}
	return val_format;
}
/////////////////////////////////////



function updateVal(inputItem){
	/*document.form1.total.value = 0;
	document.form1.totaltotal.value = 0;
	document.form1.total.value = eval(inputItem.value);
	document.form1.totaltotal.value = eval(inputItem.value);*/
	var num = Math.pow(10, 2);
	var separatMill = " ";
	
	var montantTTC = eval(document.form1.tbNbEleves.value)*1.4;
	/*document.form1.tbRedevTTC.value = (Math.round(montantTTC * num) / num);*/
	document.form1.tbRedevTTC.value = format(montantTTC,2,separatMill);
	
	/*var montantHT = eval(document.form1.tbRedevTTC.value)/1.196;*/
	var montantHT = montantTTC/1.196;
	/*document.form1.tbMontantHT.value = (Math.round(montantHT * num) / num);*/
	document.form1.tbMontantHT.value = format(montantHT,2,separatMill);
	
	document.form1.total.value = document.form1.tbRedevTTC.value;
	document.form1.sousTotal.value = document.form1.tbMontantHT.value;
	
	/*
	var valHT = eval(document.form1.total.value)/1.196;
	var num1 = Math.pow(10, 2);
	document.form1.sousTotal.value = (Math.round(valHT * num1) / num1);
	*/
	document.form1.totaltotal.value = eval(document.form1.total.value);
	/*for (i=0; i < document.form1.elements.length; i++) {
		if ((document.form1.elements[i].type == 'checkbox') | (document.form1.elements[i].type == 'radio')) {
			document.form1.elements[i].checked = false;
		}
		if (document.form1.elements[i].type == "select-one"){
			document.form1.elements[i].options[0].selected = true;
		}
  	}*/
}

function printClick(etatCgv){
	if (etatCgv.checked == true){
		 /*IMPRESSION ON*/
		window.print();
	}else{
		/* IMPRESSION OFF*/
		alert('Merci d\'accepter les conditions générales de vente pour pouvoir imprimer ce document.');
	}
}
