
//fonction used to calculate the total of the 'offre'






function controle(form1) {

	var total = 0;
	var total_full = 0;
	var rabais1 = 0;
	var rabais2 = 0;
	var assurance = 0;
	var sensibilisation = 0;
	var prix_lecon = 0;
	var nb_lecon = 0;
	var theorie_commentee = 0;
	var premier_secours = 0;
	var rabais3 = 0;
	var ordinateur1 = 0;
	var ordinateur2 = 0;
	var ordinateur3 = 0;
	var ordinateur4 = 0;
	var ordinateur5 = 0;
	var moto1 = 0;
	var moto2 = 0;
	var moto3 = 0;
	var moto4 = 0;
	var code_tmp = 0;
	var code = 0;
	var code_full = 0;
	var rabais4 = 0;

	var code_1 = 0;
	var code_2 = 0;
	var code_3 = 0;

	total = 1 * total;

	form=document.form1;
	// alert(assurance);



	// Premier secours / APS
	// Premier secours 



	if( form.premier_secours[1].checked==false && form.sensibilisation[1].checked==false ) {
		document.getElementById('div1').style.visibility="hidden";
	}

	if( form.premier_secours[1].checked==true || form.sensibilisation[1].checked==true ) {
		document.getElementById('div1').style.visibility="visible";
		document.getElementById('div1').innerHTML = "<p><strong>Inscrivez-vous maintenant pour bénéficier de cette offre</strong></p>"; 
	}

	if( form.premier_secours[1].checked==false ) {
		document.getElementById('div2').style.visibility="hidden";
	}


	if( form.premier_secours[1].checked==true ) {

		document.getElementById('div2').style.visibility="visible";
		document.getElementById('div2').innerHTML = "<input name=\"submit\" type=\"button\" value=\"Cours premiers secours\" onClick=\"javascript:document.form4.submit();\">"; 

		premier_secours=1 * form.premier_secours[1].value;

		if(total==0) {
			total=premier_secours;
		} else {
			total=premier_secours + total;
		}

		if(code==0)
		{
			code=10000;
		} else {
			code=10000 + code;
		}
		code = 1 * code;

	}


	if( form.sensibilisation[1].checked==false ) {
		document.getElementById('div3').style.visibility="hidden";
	}

	// Sensibilisation
	if( form.sensibilisation[1].checked==true ) {

		document.getElementById('div3').style.visibility="visible";
		document.getElementById('div3').innerHTML = "<input name=\"submit\" type=\"button\" value=\"Cours sensibilisation\" onClick=\"javascript:document.form2.submit();\">"; 

		sensibilisation=1 * form.sensibilisation[1].value;

		if(total==0) {
			total=sensibilisation;
		} else {
			total=sensibilisation + total;
		}

		if(code==0) {
			code=1000;
		} else {
			code=1000 + code;
		}
		code = 1 * code;

	}

	// Ordinateur 1 semaine
	// Théorie voiture sur ordinateur
	if( form.ordinateur[1].checked==true )
	{
		ordinateur1=1 * form.ordinateur[1].value;

		if(total==0) {
			total=ordinateur1;
		} else {
			total=ordinateur1 + total;
		}

		if(code==0) {
			code=10;
		} else {
			code=10 + code;
		}
		code = 1 * code;
	}

	// Ordinateur 2 semaines
	// Théorie voiture sur ordinateur
	if( form.ordinateur[2].checked==true )
	{
		ordinateur2=1 * form.ordinateur[2].value;

		if(total==0) {
			total=ordinateur2;
		} else {
			total=ordinateur2 + total;
		}

		if(code==0) {
			code=10;
		} else {
			code=10 + code;
		}
		code = 1 * code;
	}

	// Ordinateur 3 semaines
	// Théorie voiture sur ordinateur
	if( form.ordinateur[3].checked==true )
	{
		ordinateur3=1 * form.ordinateur[3].value;

		if(total==0) {
			total=ordinateur3;
		} else {
			total=ordinateur3 + total;
		}

		if(code==0) {
			code=10;
		} else {
			code=10 + code;
		}
		code = 1 * code;
	}

	// Ordinateur 1 mois
	// Théorie voiture sur ordinateur
	if( form.ordinateur[4].checked==true )
	{
		ordinateur4=1 * form.ordinateur[4].value;

		if(total==0) {
			total=ordinateur4;
		} else {
			total=ordinateur4 + total;
		}

		if(code==0) {
			code=20;
		} else {
			code=20 + code;
		}
		code = 1 * code;
	}

	// Ordinateur 2 mois
	// Théorie voiture sur ordinateur
	if( form.ordinateur[5].checked==true )
	{
		ordinateur5=1 * form.ordinateur[5].value;

		if(total==0) {
			total=ordinateur5;
		} else {
			total=ordinateur5 + total;
		}

		if(code==0) {
			code=10;
		} else {
			code=10 + code;
		}
		code = 1 * code;
	}

	// Theorie commentee
	if( form.theorie_commentee[1].checked==true )
	{
		theorie_commentee=1 * form.theorie_commentee[1].value;
		
		if(total==0) {
			total=theorie_commentee;
		} else {
			total=theorie_commentee + total;
		}

		if(code==0) {
			code=100;
		} else {
			code = 1 * code;
			code=100 + code;
		}
		code = 1 * code;

	}

	// Inscription - assurance 
	if( form.assurance[1].checked==true )
	{
		assurance=1 * form.assurance[1].value;

		if(total==0) {
			total=assurance;
		} else {
			total=assurance + total;
		}

		if(code==0) {
			code=100000;
		} else {
			code=100000 + code;
		}
		code = 1 * code;
	}




	// Nb lecons pratiques
	// Voiture
	// (nombre de leçons)
	if( form.nb_lecon_pratique.options[form.nb_lecon_pratique.selectedIndex].value != 0 )
	{
		prix_lecon = 92;
		nb_lecon = form.nb_lecon_pratique.options[form.nb_lecon_pratique.selectedIndex].value
		nb_lecon_pratique = 1 * prix_lecon * nb_lecon;

		if(nb_lecon==3)  { nb_lecon_pratique = nb_lecon_pratique - 6;   rabais1 = 6; }
		if(nb_lecon==5)  { nb_lecon_pratique = nb_lecon_pratique - 15;  rabais1 = 15; }
		if(nb_lecon==10) { nb_lecon_pratique = nb_lecon_pratique - 50;  rabais1 = 50; }
		if(nb_lecon==15) { nb_lecon_pratique = nb_lecon_pratique - 90;  rabais1 = 90; }
		if(nb_lecon==20) { nb_lecon_pratique = nb_lecon_pratique - 140; rabais1 = 140; }

		if(total==0) {
			total=nb_lecon_pratique;
		} else {
			total=nb_lecon_pratique + total;
		}
		
		if(code==0) {
			code = nb_lecon + '000000';
			code = 1 * code;
		} else {
			code_tmp = nb_lecon + '000000';
			code_tmp = 1 * code_tmp;
			code = 1 * code_tmp + code;
		}

	}






	// Moto
	// Paiement à l'heure:
	if( form.moto[1].checked==true )
	{
		moto1=1 * form.moto[1].value;

		if(total==0) {
			total=moto1;
		} else {
			total=moto1 + total;
		}

		if(code==0)
		{
			code=1;
		} else {
			code=1 + code;
		}
		code = 1 * code;
	}

	// Moto
	// Action spéciale 16-18 ans (50 cm3):
	if( form.moto[2].checked==true )
	{
		moto2=1 * form.moto[2].value;

		if(total==0) {
			total=moto2;
		} else {
			total=moto2 + total;
		}

		if(code==0) {
			code=2;
		} else {
			code=2 + code;
		}
		code = 1 * code;
	}

	// Moto
	// Forfait 8 heures:
	if( form.moto[3].checked==true )
	{
		moto3=1 * form.moto[3].value;

		if(total==0) {
			total=moto3;
		} else {
			total=moto3 + total;
		}

		if(code==0) {
			code=3;
		} else {
			code=3 + code;
		}
		code = 1 * code;
	}

	// Moto
	// Forfait 12 heures:
	if( form.moto[4].checked==true )
	{
		moto4=1 * form.moto[4].value;

		if(total==0) {
			total=moto4;
		} else {
			total=moto4 + total;
		}

		if(code==0) {
			code=4;
		} else {
			code=4 + code;
		}
		code = 1 * code;
	}




	/* RABAIS */

	/* nb_lecon + sensibilisation */
	if( nb_lecon==3 && sensibilisation!=0 ) { total = total - 10; rabais2 = 10; }
	if( nb_lecon==5 && sensibilisation!=0 ) { total = total - 20; rabais2 = 20; }
	if( nb_lecon==10 && sensibilisation!=0 ) { total = total - 50; rabais2 = 50; }
	if( nb_lecon==15 && sensibilisation!=0 ) { total = total - 75; rabais2 = 75; }
	if( nb_lecon==20 && sensibilisation!=0 ) { total = total - 100; rabais2 = 100; }

	/* sensibilisation + 8h moto */
	// if( sensibilisation!=0 && moto1!=0 ) { total = total - 30; rabais4 = 30; }
	// if( sensibilisation!=0 && moto2!=0 ) { total = total - 30; rabais4 = 30; }

	/* APS + theorie */
	// if( premier_secours!=0 && theorie_commentee!=0 ) { total = total - 9; rabais3 = 9; }
	/* APS + theorie + ordi 2 semaines */
	// if( premier_secours!=0 && theorie_commentee!=0 && ordinateur2!=0 ) { total = total - 19; rabais3 = 19; }
	/* APS + theorie + ordi 1 mois */
	// if( premier_secours!=0 && theorie_commentee!=0 && ordinateur4!=0 ) { total = total - 24; rabais3 = 24; }

	/* APS + sensibilisaton + theorie + ordi 2 semaines */
	// if( premier_secours!=0 &&  sensibilisation!=0 && theorie_commentee!=0 && ordinateur2!=0 ) { total = total - 29; rabais3 = 29; }

	/* APS + ordi 2 semaines */
	// if( premier_secours!=0 && ordinateur1!=0 ) { total = total - 10; rabais3 = 10; }
	/* APS + ordi 1 mois */
	// if( premier_secours!=0 && ordinateur2!=0 ) { total = total - 15; rabais3 = 15; }
	/* APS + sensibilisation + ordi 2 semaines */
	// if( premier_secours!=0 && sensibilisation!=0 && ordinateur1!=0 ) { total = total - 20; rabais3 = 20; }
	/* APS + sensibilisation + ordi 1 mois */
	// if( premier_secours!=0 && sensibilisation!=0 && ordinateur2!=0 ) { total = total - 25; rabais3 = 25; }

	/* sensibilisation + theorie_commentee + ordi 2 semaines */
	// if( sensibilisation!=0 && theorie_commentee!=0 && ordinateur1!=0 ) { total = total - 20; rabais3 = 20; }
	/* APS + sensibilisation + ordi 1 mois */
	// if( sensibilisation!=0 && theorie_commentee!=0 && ordinateur2!=0 ) { total = total - 20; rabais3 = 20; }

	rabais = rabais1 + rabais2 + rabais3 + rabais4;


	document.form1.rabais.value = rabais;
	document.form1.rabais_print.value = rabais + '.-';

	document.form1.total.value = total;
	document.form1.total_print.value = total + '.-';

	document.form1.total_full.value = total + rabais;
	document.form1.total_full_print.value = total + rabais + '.-';



	if( total > 0 ) {
		document.getElementById('div4').style.visibility="visible";
		document.getElementById('div4').innerHTML = "<input type=\"submit\" value=\"Imprimer l'offre\"> "; 

		document.getElementById('div5').style.visibility="visible";
		document.getElementById('div5').innerHTML = "<img src=\"images/icone_print.gif\" width=\"26\" height=\"26\" alt=\"\" />"; 

		document.getElementById('div6').style.visibility="visible";
		document.getElementById('div6').innerHTML = "<input name=\"submit\" type=\"button\" value=\"Contactez-moi\" onClick=\"javascript:document.form3.submit();\">"; 

		document.getElementById('div7').style.visibility="visible";
		document.getElementById('div7').innerHTML = "<img src=\"images/icon_mail2.jpg\" width=\"26\" height=\"26\" alt=\"\" />"; 

	} else {
		document.getElementById('div4').style.visibility="hidden";
		document.getElementById('div5').style.visibility="hidden";
		document.getElementById('div6').style.visibility="hidden";
		document.getElementById('div7').style.visibility="hidden";
	}


	code = '' + code;
	if( code!=0 && ( nb_lecon==1 || nb_lecon==3 || nb_lecon==5 ) ) { code = '-' + code; }
	code_full=code;


	// Chaine.substr(position1, longueur) 
	code_1 = code.substr(0, 2);
	code_2 = code.substr(2, 5);
	code_3 = code.substr(7, 1);

	code = code_1 + '-' + code_2 + '-' + code_3 + '-';
	// code = code_1 + '-' + code_2 + '-';

	// document.form1.code.value = code.length;
	document.form1.code.value = code;
	document.form2.code.value = code;
	document.form3.code.value = code;
	// document.form1.code_full.value = code_full;

}
