var validerNumeric = new RegExp(/^\+?[0-9]+(((\.)|,)?[0-9]*)?$/);

/**
 * Class Bonification contenant les informations permettant de trouver la bonne bonification
 * en fonction du revenu et du nombre de part
 */
function Bonification(part, borneInf, borneSup, bonif){
	this.part=part;
	this.borneInf=borneInf;
	this.borneSup=borneSup;
	this.bonif=bonif;
}
Bonification.prototype = new Bonification;


/**
 * Classe static permettant de faire une recherche avec le revenu et le nombre de part pour
 * retrouver la bonification
 */
var tabBonification = [

new Bonification(	1		,	0	,	9795	,	30	),	new Bonification(	1		,	9796	,	16419	,	25	),	new Bonification(	1		,	16420	,	19871	,	20	),	new Bonification(	1		,	19872	,	24817	,	15	),	new Bonification(	1		,	24818	,	26711	,	10	),
new Bonification(	1.25	,	0	,	11098	,	30	),	new Bonification(	1.25	,	11099	,	18670	,	25	),	new Bonification(	1.25	,	18671	,	22716	,	20	),	new Bonification(	1.25	,	22717	,	27636	,	15	),	new Bonification(	1.25	,	27637	,	29886	,	10	),
new Bonification(	1.5		,	0	,	12400	,	30	),	new Bonification(	1.5		,	12401	,	20922	,	25	),	new Bonification(	1.5		,	20923	,	25561	,	20	),	new Bonification(	1.5		,	25562	,	30454	,	15	),	new Bonification(	1.5		,	30455	,	33061	,	10	),
new Bonification(	1.75	,	0	,	13703	,	30	),	new Bonification(	1.75	,	13704	,	23174	,	25	),	new Bonification(	1.75	,	23175	,	28406	,	20	),	new Bonification(	1.75	,	28407	,	33273	,	15	),	new Bonification(	1.75	,	33274	,	36237	,	10	),
new Bonification(	2		,	0	,	15006	,	30	),	new Bonification(	2		,	15007	,	25425	,	25	),	new Bonification(	2		,	25426	,	31251	,	20	),	new Bonification(	2		,	31252	,	36092	,	15	),	new Bonification(	2		,	36093	,	39412	,	10	),
new Bonification(	2.25	,	0	,	16309	,	30	),	new Bonification(	2.25	,	16310	,	27677	,	25	),	new Bonification(	2.25	,	27678	,	34096	,	20	),	new Bonification(	2.25	,	34097	,	38910	,	15	),	new Bonification(	2.25	,	38911	,	42587	,	10	),
new Bonification(	2.5		,	0	,	17612	,	30	),	new Bonification(	2.5		,	17613	,	29929	,	25	),	new Bonification(	2.5		,	29930	,	36941	,	20	),	new Bonification(	2.5		,	36942	,	41729	,	15	),	new Bonification(	2.5		,	41730	,	45762	,	10	),
new Bonification(	2.75	,	0	,	18915	,	30	),	new Bonification(	2.75	,	18916	,	32180	,	25	),	new Bonification(	2.75	,	32181	,	39786	,	20	),	new Bonification(	2.75	,	39787	,	44548	,	15	),	new Bonification(	2.75	,	44549	,	48937	,	10	),
new Bonification(	3		,	0	,	20218	,	30	),	new Bonification(	3		,	20219	,	34432	,	25	),	new Bonification(	3		,	34433	,	42631	,	20	),	new Bonification(	3		,	42632	,	47366	,	15	),	new Bonification(	3		,	47367	,	52112	,	10	),
new Bonification(	3.25	,	0	,	21521	,	30	),	new Bonification(	3.25	,	21522	,	36684	,	25	),	new Bonification(	3.25	,	36685	,	45477	,	20	),	new Bonification(	3.25	,	45478	,	50185	,	15	),	new Bonification(	3.25	,	50186	,	55287	,	10	),
new Bonification(	3.5		,	0	,	22824	,	30	),	new Bonification(	3.5		,	22825	,	38936	,	25	),	new Bonification(	3.5		,	38937	,	48322	,	20	),	new Bonification(	3.5		,	48322	,	53004	,	15	),	new Bonification(	3.5		,	53005	,	58463	,	10	),
new Bonification(	3.75	,	0	,	24127	,	30	),	new Bonification(	3.75	,	24128	,	41187	,	25	),	new Bonification(	3.75	,	41188	,	51167	,	20	),	new Bonification(	3.75	,	51168	,	55822	,	15	),	new Bonification(	3.75	,	55823	,	61638	,	10	),
new Bonification(	4		,	0	,	25430	,	30	),	new Bonification(	4		,	25431	,	43439	,	25	),	new Bonification(	4		,	43440	,	54012	,	20	),	new Bonification(	4		,	54013	,	58641	,	15	),	new Bonification(	4		,	58642	,	64813	,	10	),
new Bonification(	4.25	,	0	,	26733	,	30	),	new Bonification(	4.25	,	26734	,	45691	,	25	),	new Bonification(	4.25	,	45692	,	56857	,	20	),	new Bonification(	4.25	,	56858	,	61460	,	15	),	new Bonification(	4.25	,	61461	,	67988	,	10	),
new Bonification(	4.5		,	0	,	28036	,	30	),	new Bonification(	4.5		,	28037	,	47942	,	25	),	new Bonification(	4.5		,	47943	,	59702	,	20	),	new Bonification(	4.5		,	59703	,	64278	,	15	),	new Bonification(	4.5		,	64279	,	71163	,	10	),
new Bonification(	4.75	,	0	,	29339	,	30	),	new Bonification(	4.75	,	29340	,	50194	,	25	),	new Bonification(	4.75	,	50195	,	62546	,	20	),	new Bonification(	4.75	,	62547	,	67097	,	15	),	new Bonification(	4.75	,	67098	,	74338	,	10	),
new Bonification(	5		,	0	,	30642	,	30	),	new Bonification(	5		,	30643	,	52446	,	25	),	new Bonification(	5		,	52447	,	65392	,	20	),	new Bonification(	5		,	65393	,	69916	,	15	),	new Bonification(	5		,	69917	,	77514	,	10	),
new Bonification(	5.25	,	0	,	31945	,	30	),	new Bonification(	5.25	,	31946	,	54697	,	25	),	new Bonification(	5.25	,	54698	,	68237	,	20	),	new Bonification(	5.25	,	68238	,	72734	,	15	),	new Bonification(	5.25	,	72735	,	80689	,	10	),
new Bonification(	5.5		,	0	,	33248	,	30	),	new Bonification(	5.5		,	33249	,	56949	,	25	),	new Bonification(	5.5		,	56950	,	71083	,	20	),	new Bonification(	5.5		,	71084	,	75553	,	15	),	new Bonification(	5.5		,	75554	,	83864	,	10	),
new Bonification(	5.75	,	0	,	34551	,	30	),	new Bonification(	5.75	,	34552	,	59201	,	25	),	new Bonification(	5.75	,	59202	,	73928	,	20	),	new Bonification(	5.75	,	73929	,	78372	,	15	),	new Bonification(	5.75	,	78373	,	87039	,	10	),
new Bonification(	6		,	0	,	35854	,	30	),	new Bonification(	6		,	35855	,	61453	,	25	),	new Bonification(	6		,	61454	,	76773	,	20	),	new Bonification(	6		,	76774	,	81190	,	15	),	new Bonification(	6		,	81191	,	90214	,	10	),
new Bonification(	6.25	,	0	,	37157	,	30	),	new Bonification(	6.25	,	37158	,	63704	,	25	),	new Bonification(	6.25	,	63705	,	79618	,	20	),	new Bonification(	6.25	,	79619	,	84009	,	15	),	new Bonification(	6.25	,	84010	,	93389	,	10	),
new Bonification(	6.5		,	0	,	38459	,	30	),	new Bonification(	6.5		,	38460	,	65956	,	25	),	new Bonification(	6.5		,	65957	,	82463	,	20	),	new Bonification(	6.5		,	82464	,	86827	,	15	),	new Bonification(	6.5		,	86828	,	96564	,	10	),
new Bonification(	6.75	,	0	,	39762	,	30	),	new Bonification(	6.75	,	39763	,	68208	,	25	),	new Bonification(	6.75	,	68209	,	85308	,	20	),	new Bonification(	6.75	,	85309	,	89646	,	15	),	new Bonification(	6.75	,	89647	,	99740	,	10	),
new Bonification(	7		,	0	,	41065	,	30	),	new Bonification(	7		,	41066	,	70459	,	25	),	new Bonification(	7		,	70460	,	88153	,	20	),	new Bonification(	7		,	88154	,	92465	,	15	),	new Bonification(	7		,	92466	,	102915	,	10	),
new Bonification(	7.25	,	0	,	42368	,	30	),	new Bonification(	7.25	,	42369	,	72711	,	25	),	new Bonification(	7.25	,	72712	,	90998	,	20	),	new Bonification(	7.25	,	90999	,	95283	,	15	),	new Bonification(	7.25	,	95284	,	106090	,	10	),
new Bonification(	7.5		,	0	,	43671	,	30	),	new Bonification(	7.5		,	43672	,	74963	,	25	),	new Bonification(	7.5		,	74964	,	93843	,	20	),	new Bonification(	7.5		,	93844	,	98102	,	15	),	new Bonification(	7.5		,	98103	,	109265	,	10	),
new Bonification(	7.75	,	0	,	44974	,	30	),	new Bonification(	7.75	,	44975	,	77214	,	25	),	new Bonification(	7.75	,	77215	,	96688	,	20	),	new Bonification(	7.75	,	96689	,	100921	,	15	),	new Bonification(	7.75	,	100922	,	112440	,	10	),
new Bonification(	8		,	0	,	46277	,	30	),	new Bonification(	8		,	46278	,	79466	,	25	),	new Bonification(	8		,	79467	,	99534	,	20	),	new Bonification(	8		,	99535	,	103739	,	15	),	new Bonification(	8		,	103740	,	115615	,	10	),
new Bonification(	8.25	,	0	,	47581	,	30	),	new Bonification(	8.25	,	47582	,	81718	,	25	),	new Bonification(	8.25	,	81719	,	102379	,	20	),	new Bonification(	8.25	,	102380	,	106558	,	15	),	new Bonification(	8.25	,	106559	,	118790	,	10	),
new Bonification(	8.5		,	0	,	48885	,	30	),	new Bonification(	8.5		,	48886	,	83979	,	25	),	new Bonification(	8.5		,	83980	,	105221	,	20	),	new Bonification(	8.5		,	105222	,	109387	,	15	),	new Bonification(	8.5		,	109388	,	121961	,	10	),
new Bonification(	8.75	,	0	,	50188	,	30	),	new Bonification(	8.75	,	50189	,	86231	,	25	),	new Bonification(	8.75	,	86232	,	108066	,	20	),	new Bonification(	8.75	,	108067	,	112206	,	15	),	new Bonification(	8.75	,	112207	,	125136	,	10	),
new Bonification(	9		,	0	,	51491	,	30	),	new Bonification(	9		,	51492	,	88483	,	25	),	new Bonification(	9		,	88484	,	110911	,	20	),	new Bonification(	9		,	110912	,	115025	,	15	),	new Bonification(	9		,	115026	,	128311	,	10	),
new Bonification(	9.25	,	0	,	52794	,	30	),	new Bonification(	9.25	,	52795	,	90735	,	25	),	new Bonification(	9.25	,	90736	,	113756	,	20	),	new Bonification(	9.25	,	113757	,	117844	,	15	),	new Bonification(	9.25	,	117845	,	131486	,	10	),
new Bonification(	9.5		,	0	,	54097	,	30	),	new Bonification(	9.5		,	54098	,	92987	,	25	),	new Bonification(	9.5		,	92988	,	116601	,	20	),	new Bonification(	9.5		,	116602	,	120663	,	15	),	new Bonification(	9.5		,	120664	,	134661	,	10	),
new Bonification(	9.75	,	0	,	55400	,	30	),	new Bonification(	9.75	,	55401	,	95239	,	25	),	new Bonification(	9.75	,	95240	,	119446	,	20	),	new Bonification(	9.75	,	119447	,	123482	,	15	),	new Bonification(	9.75	,	123483	,	137836	,	10	),
new Bonification(	10		,	0	,	56703	,	30	),	new Bonification(	10		,	56704	,	97491	,	25	),	new Bonification(	10		,	97492	,	122291	,	20	),	new Bonification(	10		,	122292	,	126301	,	15	),	new Bonification(	10		,	126302	,	141011	,	10	),
new Bonification(	10.25	,	0	,	58006	,	30	),	new Bonification(	10.25	,	58007	,	99743	,	25	),	new Bonification(	10.25	,	99744	,	125136	,	20	),	new Bonification(	10.25	,	125137	,	129120	,	15	),	new Bonification(	10.25	,	129121	,	144186	,	10	),
new Bonification(	10.5	,	0	,	59309	,	30	),	new Bonification(	10.5	,	59310	,	101995	,	25	),	new Bonification(	10.5	,	101996	,	127981	,	20	),	new Bonification(	10.5	,	127982	,	131939	,	15	),	new Bonification(	10.5	,	131940	,	147361	,	10	),
new Bonification(	10.75	,	0	,	60612	,	30	),	new Bonification(	10.75	,	60613	,	104247	,	25	),	new Bonification(	10.75	,	104248	,	130826	,	20	),	new Bonification(	10.75	,	130827	,	134758	,	15	),	new Bonification(	10.75	,	134759	,	150536	,	10	),
new Bonification(	11		,	0	,	61915	,	30	),	new Bonification(	11		,	61916	,	106499	,	25	),	new Bonification(	11		,	106500	,	133671	,	20	),	new Bonification(	11		,	133672	,	137577	,	15	),	new Bonification(	11		,	137578	,	153711	,	10	),
new Bonification(	11.25	,	0	,	63218	,	30	),	new Bonification(	11.25	,	63219	,	108751	,	25	),	new Bonification(	11.25	,	108752	,	136516	,	20	),	new Bonification(	11.25	,	136517	,	140396	,	15	),	new Bonification(	11.25	,	140397	,	156886	,	10	),
new Bonification(	11.5	,	0	,	64521	,	30	),	new Bonification(	11.5	,	64522	,	111003	,	25	),	new Bonification(	11.5	,	111004	,	139361	,	20	),	new Bonification(	11.5	,	139362	,	143215	,	15	),	new Bonification(	11.5	,	143216	,	160061	,	10	),
new Bonification(	11.75	,	0	,	65824	,	30	),	new Bonification(	11.75	,	65825	,	113255	,	25	),	new Bonification(	11.75	,	113256	,	142206	,	20	),	new Bonification(	11.75	,	142207	,	146034	,	15	),	new Bonification(	11.75	,	146035	,	163236	,	10	),
new Bonification(	12		,	0	,	67127	,	30	),	new Bonification(	12		,	67128	,	115507	,	25	),	new Bonification(	12		,	115508	,	145051	,	20	),	new Bonification(	12		,	145052	,	148853	,	15	),	new Bonification(	12		,	148854	,	166411	,	10	),
new Bonification(	12.25	,	0	,	68430	,	30	),	new Bonification(	12.25	,	68431	,	117759	,	25	),	new Bonification(	12.25	,	117760	,	147896	,	20	),	new Bonification(	12.25	,	147897	,	151672	,	15	),	new Bonification(	12.25	,	151673	,	169586	,	10	),
new Bonification(	12.5	,	0	,	69733	,	30	),	new Bonification(	12.5	,	69734	,	120011	,	25	),	new Bonification(	12.5	,	120012	,	150741	,	20	),	new Bonification(	12.5	,	150742	,	154491	,	15	),	new Bonification(	12.5	,	154492	,	172761	,	10	),
new Bonification(	12.75	,	0	,	71036	,	30	),	new Bonification(	12.75	,	71037	,	122263	,	25	),	new Bonification(	12.75	,	122264	,	153586	,	20	),	new Bonification(	12.75	,	153587	,	157310	,	15	),	new Bonification(	12.75	,	157311	,	175936	,	10	),
new Bonification(	13		,	0	,	72339	,	30	),	new Bonification(	13		,	72340	,	124515	,	25	),	new Bonification(	13		,	124516	,	156431	,	20	),	new Bonification(	13		,	156432	,	160129	,	15	),	new Bonification(	13		,	160130	,	179111	,	10	)];

function BonificationsTab(){
}
BonificationsTab.search = function(revenu, part) {
	for (var i=0; i<tabBonification.length; i++) {
		if (tabBonification[i].part == part && revenu >= tabBonification[i].borneInf && revenu <= tabBonification[i].borneSup) {
			return tabBonification[i].bonif;
		}
	}
	return null;
}


/**
 * Ouvre une boite d'alerte lors du clique sur l'aide
 */
function openHelp(){
	 window.open("handicapeHelp.html", "popup", "top=300, left=500, height=130, width=700, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no");
}

/**
 * Calcule la bonification en fonction du revenu et du nombre de part
 */
function confirmRPF(){
	var checkbox_value = document.getElementById('handicape').checked;
	var revenu_value = document.getElementById('revenuFiscalRef').value;
	var nbPart_value = document.getElementById('nbParts').value;


	if(checkbox_value == true){
		setVisibility('fiphfp', "inline", "visible");
	}
	else{
		setVisibility('fiphfp', "none", "hidden");
	}

	if (isValidRPF(revenu_value, nbPart_value)==0){

		// Replace , by .
		revenu_value = revenu_value.replace(/,/,".");
		nbPart_value = nbPart_value.replace(/,/,".");

		var bonif = BonificationsTab.search(revenu_value, nbPart_value);
		if(bonif != null){
			document.getElementById('bonification').innerHTML=bonif;

			setVisibility('bloc2KO', "none", "hidden");
			setVisibility('bloc2OK', "block", "visible");

			// Update de la liste des montants
			var listeMontant = getListeMontant(bonif, checkbox_value);
			document.getElementById('montantEpargne').options.length = listeMontant.length+1;

			// Add empty element at index 0
			document.getElementById('montantEpargne').options[0].value = 0;
			document.getElementById('montantEpargne').options[0].text = '';

			// Add all the listeMontant value in list
			for (i=0; i<listeMontant.length; i++){
				document.getElementById('montantEpargne').options[i+1].value = listeMontant[i];
				document.getElementById('montantEpargne').options[i+1].text = listeMontant[i].toFixed(2);
		    }
			document.getElementById('montantEpargne').options.selectedIndex = 0;
		}
		else{
			setVisibility('bloc2OK', "none", "hidden");
			setVisibility('bloc2KO', "block", "visible");
		}

		// In any case, refresh the two other panel (Montant et Resultat)
		refreshLists();
		refreshResultat();
		// Update style
		setPanel2Class('');

		// Scroll to div2
		document.location='#div2';
	}

}

/**
 * Refresh the lists by selecting the first element
 */
function refreshLists(){
	document.getElementById('montantEpargne').selectedIndex = 0;
	document.getElementById('dureeEpargne').selectedIndex = 0;
	document.getElementById('montantEpargne').disabled = false;
	document.getElementById('dureeEpargne').disabled = false;
}

/**
 * Refresh the panel resultat
 */
function refreshResultat(){
	document.getElementById('montantTotalEpargne').innerHTML = '';
	document.getElementById('montantTotalEtat').innerHTML = '';
	document.getElementById('montantTotal').innerHTML = '';
	setVisibility('participationFIPHFP', "none", "hidden");
}

/**
 * Resfresh all informations
 */
function resfreshAll(){
	refreshLists();
	refreshResultat();

	setVisibility('bloc2OK', "block", "visible");
	setVisibility('bloc2KO', "none", "hidden");
	setVisibility('fiphfp', "none", "hidden");

	document.getElementById('bonification').innerHTML='';
	document.getElementById('handicape').checked = false;
	document.getElementById('revenuFiscalRef').value = '';
	document.getElementById('nbParts').value = '';
	document.getElementById('confirmButton').disabled = true;
	document.getElementById('montantEpargne').disabled = true;
	document.getElementById('dureeEpargne').disabled = true;

	// Update style
	setPanel2Class("Disabled");
	setPanel3Class("Disabled");

	// Scroll to div1
	document.location='#div1';
}

/**
 * Enabled or disabled panel 2
 */
function setPanel2Class(disabled){
	setClass(document.getElementById('bloc2OK'), "corpsBulleText"+disabled);
	setClass(document.getElementById('bloc2KO'), "corpsBulleText"+disabled);
	setClass(document.getElementById('table2Titre'), "table titreText2"+disabled);
	setClass(document.getElementById('table2TitreKO'), "table titreText2"+disabled);
	setClass(document.getElementById('table2SousTitre'), "corpsText2"+disabled);
	setClass(document.getElementById('table2Montant'), "table corpsText"+disabled);
}

/**
 * Enabled or disabled panel 3
 */
function setPanel3Class(disabled){
	setClass(document.getElementById('div3'), "corpsBulleText"+disabled);
	setClass(document.getElementById('table3Titre'), "table titreText2"+disabled);
	setClass(document.getElementById('table3SousTitre'), "table corpsText2"+disabled);
	setClass(document.getElementById('table3Montant'), "table corpsText"+disabled);
	setClass(document.getElementById('table3Info'), "table corpsText"+disabled);
	setClass(document.getElementById('table3SousInfo'), "table corpsText2"+disabled);
	if(disabled == "Disabled"){
		setClass(document.getElementById('puce1'), "imgOpaque");
		setClass(document.getElementById('puce2'), "imgOpaque");
		setClass(document.getElementById('impBtn'), "imgOpaque");
		document.getElementById('impBtn').disabled = true;
	}
	else{
		setClass(document.getElementById('puce1'), "imgNonOpaque");
		setClass(document.getElementById('puce2'), "imgNonOpaque");
		setClass(document.getElementById('impBtn'), "imgNonOpaque");
		document.getElementById('impBtn').disabled = false;
	}
}

/**
 * Disabled panel 2 and 3
 */
function disabledPanel2And3(e){
	setPanel2Class("Disabled");
	setPanel3Class("Disabled");
	document.getElementById('montantEpargne').selectedIndex = 0;
	document.getElementById('dureeEpargne').selectedIndex = 0;
	document.getElementById('montantEpargne').disabled = true;
	document.getElementById('dureeEpargne').disabled = true;
	document.getElementById('confirmButton').disabled = true;
}

/**
 * Enable or disable the confirm button in the panel 2
 */
function enableConfirmButton(){
	var indiceMontant = document.getElementById('montantEpargne').selectedIndex;
	var indiceDuree = document.getElementById('dureeEpargne').selectedIndex;

	if(indiceMontant != 0 && indiceDuree != 0){
		document.getElementById('confirmButton').disabled = false;
	}
	else{
		document.getElementById('confirmButton').disabled = true;
	}
	setPanel3Class("Disabled");
}

/**
 * Retourne des messages d'erreurs si le revenu et/ou le nombre de parts entres ne sont pas valides
 */
function isValidRPF(revenu_value, nbPart_value){
	var message;
	message = '';

	if (revenu_value.length == 0){
		message = "Votre revenu doit être renseigné\n";
	}
	else if (validerNumeric.test(revenu_value) != true){
		message = "Le revenu saisi est incorrect\n";
	}
	else if(revenu_value.lastIndexOf(".") != -1 || revenu_value.lastIndexOf(",") != -1){
		message = "Le revenu saisi ne doit pas comporter de décimale\n";
	}

	if(nbPart_value.length == 0){
		message = message + "Le nombre de parts fiscales doit être renseigné\n";
	}
	else if(validerNumeric.test(nbPart_value) != true){
		message = message + "Le nombre de parts fiscales est erroné\n";
	}
	else if(nbPart_value == 0){
		message = message + "Le nombre de parts fiscales ne peut pas être égal à zéro\n";
	}
	else if(nbPart_value > 13){
		message = message + "Le nombre de parts fiscales est limité à 13 dans la simulation\n";
	}
	else if(nbPart_value%0.25 > 0){
		message = message + "Le nombre de parts fiscales doit être un multiple de 0.25\n";
	}

	if(message != ''){
		window.alert(message);
		return 1;
	}
	else{
		return 0;
	}
}

var tabMontant30NonHandi = [30.80, 38.50, 46.20, 53.80, 61.50, 69.20, 76.90, 84.60, 92.30, 100.00, 107.70, 115.40, 123.10, 130.80, 138.50, 146.20, 153.80, 161.50, 169.20, 176.90, 184.60, 192.30, 200.00, 207.70, 215.40, 223.10, 230.80, 238.50, 246.20, 253.80, 261.50, 269.20];
var tabMontant25NonHandi = [32.00, 40.00, 48.00, 56.00, 64.00, 72.00, 80.00, 88.00, 96.00, 104.00, 112.00, 120.00, 128.00, 136.00, 144.00, 152.00, 160.00, 168.00, 176.00, 184.00, 192.00, 200.00, 208.00, 216.00, 224.00, 232.00, 240.00, 248.00, 256.00, 264.00, 272.00];
var tabMontant20NonHandi = [33.30, 41.60, 50.00, 58.30, 66.60, 75.00, 83.30, 91.60, 100.00, 108.30, 116.60, 125.00, 133.30, 141.60, 150.00, 158.30, 166.60, 175.00, 183.30, 191.60, 200.00, 208.30, 216.60, 225.00, 233.30, 241.60, 250.00, 258.30, 266.60];
var tabMontant15NonHandi = [34.70, 43.40, 52.10, 60.80, 69.50, 78.20, 86.90, 95.60, 104.30, 113.00, 121.70, 130.40, 139.10, 147.80, 156.50, 165.20, 173.90, 182.60, 191.30, 200.00, 208.60, 217.30, 226.00, 234.70, 243.40, 252.20, 260.90];
var tabMontant10NonHandi = [36.30, 45.40, 54.50, 63.60, 72.70, 81.80, 90.90, 100.00, 109.00, 118.10, 127.20, 136.30, 145.40, 154.50, 163.60, 172.70, 181.80, 190.90, 200.00, 209.00, 218.10, 227.20, 236.30, 245.40, 254.50, 263.60];

var tabMontant30Handi = [28.80, 36.00, 43.20, 50.40, 57.60, 64.70, 71.90, 79.10, 86.30, 93.50, 100.70, 107.90, 115.10, 122.30, 129.50, 136.70, 143.90, 151.10, 158.30, 165.50, 172.70, 179.90, 187.10, 194.20, 201.40, 208.60, 215.80, 223.00, 230.20, 237.40, 244.60, 251.80, 259.00, 266.20];
var tabMontant25Handi = [30.20, 37.70, 45.30, 52.80, 60.40, 67.90, 75.50, 83.00, 90.60, 98.10, 105.70, 113.20, 120.80, 128.30, 135.80, 143.40, 150.90, 158.50, 166.00, 173.60, 181.10, 188.70, 196.20, 203.80, 211.30, 218.90, 226.40, 234.00, 241.50, 249.10, 256.60, 264.20];
var tabMontant20Handi = [31.70, 39.70, 47.60, 55.60, 63.50, 71.40, 79.40, 87.30, 95.20, 103.20, 111.10, 119.00, 127.00, 134.90, 142.90, 150.80, 158.70, 166.70, 174.60, 182.50, 190.50, 198.40, 206.30, 214.30, 222.20, 230.20, 238.10, 246.00, 254.00, 261.90];
var tabMontant15Handi = [33.50, 41.80, 50.20, 58.60, 66.90, 75.30, 83.70, 92.10, 100.40, 108.80, 117.20, 125.50, 133.90, 142.30, 150.60, 159.00, 167.40, 175.70, 184.10, 192.50, 200.80, 209.20, 217.60, 225.90, 234.30, 242.70, 251.00, 259.40, 267.70];
var tabMontant10Handi = [35.40, 44.20, 53.10, 61.90, 70.80, 79.60, 88.50, 97.30, 106.20, 115.00, 123.90, 132.70, 141.60, 150.40, 159.30, 168.10, 177.00, 185.80, 194.70, 203.50, 212.40, 221.20, 230.10, 238.90, 247.80, 256.60, 265.50];

/**
 * Get the list of montant in function of bonif and handicape
 */
function getListeMontant(bonif, handicape){
	if(handicape == false){
		switch(bonif){
			case 30: return tabMontant30NonHandi;
      		case 25: return tabMontant25NonHandi;
      		case 20: return tabMontant20NonHandi;
      		case 15: return tabMontant15NonHandi;
      		case 10: return tabMontant10NonHandi;
		}
	}
	else{
		switch(bonif){
		case 30: return tabMontant30Handi;
  		case 25: return tabMontant25Handi;
  		case 20: return tabMontant20Handi;
  		case 15: return tabMontant15Handi;
  		case 10: return tabMontant10Handi;
		}
	}
}

var tabPartEtat30NonHandi = [9.20, 11.50, 13.80, 16.20, 18.50, 20.80, 23.10, 25.40, 27.70, 30.00, 32.30, 34.60, 36.90, 39.20, 41.50, 43.80, 46.20, 48.50, 50.80, 53.10, 55.40, 57.70, 60.00, 62.30, 64.60, 66.90, 69.20, 71.50, 73.80, 76.20, 78.50, 80.80];
var tabPartEtat25NonHandi = [8.00, 10.00, 12.00, 14.00, 16.00, 18.00, 20.00, 22.00, 24.00, 26.00, 28.00, 30.00, 32.00, 34.00, 36.00, 38.00, 40.00, 42.00, 44.00, 46.00, 48.00, 50.00, 52.00, 54.00, 56.00, 58.00, 60.00, 62.00, 64.00, 66.00, 68.00];
var tabPartEtat20NonHandi = [6.70, 8.40, 10.00, 11.70, 13.40, 15.00, 16.70, 18.40, 20.00, 21.70, 23.40, 25.00, 26.70, 28.40, 30.00, 31.70, 33.40, 35.00, 36.70, 38.40, 40.00, 41.70, 43.40, 45.00, 46.70, 48.40, 50.00, 51.70, 53.40];
var tabPartEtat15NonHandi = [5.30, 6.60, 7.90, 9.20, 10.50, 11.80, 13.10, 14.40, 15.70, 17.00, 18.30, 19.60, 20.90, 22.20, 23.50, 24.80, 26.10, 27.40, 28.70, 30.00, 31.40, 32.70, 34.00, 35.30, 36.60, 37.80, 39.10];
var tabPartEtat10NonHandi = [3.70, 4.60, 5.50, 6.40, 7.30, 8.20, 9.10, 10.00, 11.00, 11.90, 12.80, 13.70, 14.60, 15.50, 16.40, 17.30, 18.20, 19.10, 20.00, 21.00, 21.90, 22.80, 23.70, 24.60, 25.50, 26.40];

var tabPartEtat30Handi = [11.20, 14.0, 16.80, 19.60, 22.40, 25.30, 28.10, 30.90, 33.70, 36.50, 39.30, 42.10, 44.90, 47.70, 50.50, 53.30, 56.10, 58.90, 61.70, 64.50, 67.30, 70.10, 72.90, 75.80, 78.60, 81.40, 84.20, 87.00, 89.80, 92.60, 95.40, 98.20, 101.00, 103.80];
var tabPartEtat25Handi = [9.80, 12.30, 14.70, 17.20, 19.60, 22.10, 24.50, 27.00, 29.40, 31.90, 34.30, 36.80, 39.20, 41.70, 44.20, 46.60, 49.10, 51.50, 54.00, 56.40, 58.90, 61.30, 63.80, 66.20, 68.70, 71.10, 73.60, 76.00, 78.50, 80.90, 83.40, 85.80];
var tabPartEtat20Handi = [8.30, 10.30, 12.40, 14.40, 16.50, 18.60, 20.60, 22.70, 24.80, 26.80, 28.90, 31.00, 33.00, 35.10, 37.10, 39.20, 41.30, 43.30, 45.40, 47.50, 49.50, 51.60, 53.70, 55.70, 57.80, 59.80, 61.90, 64.00, 66.00, 68.10];
var tabPartEtat15Handi = [6.50, 8.20, 9.80, 11.40, 13.10, 14.70, 16.30, 17.90, 19.60, 21.20, 22.80, 24.50, 26.10, 27.70, 29.40, 31.00, 32.60, 34.30, 35.90, 37.50, 39.20, 40.80, 42.40, 44.10, 45.70, 47.30, 49.00, 50.60, 52.30];
var tabPartEtat10Handi = [4.60, 5.80, 6.90, 8.10, 9.20, 10.40, 11.50, 12.70, 13.80, 15.00, 16.10, 17.30, 18.40, 19.60, 20.70, 21.90, 23.00, 24.20, 25.30, 26.50, 27.60, 28.80, 29.90, 31.10, 32.20, 33.40, 34.50];

var tabPartFIPHFP30Handi = [2.60, 3.20, 3.90, 4.50, 5.20, 5.80, 6.50, 7.10, 7.80, 8.40, 9.10, 9.70, 10.40, 11.00, 11.70, 12.30, 12.90, 13.60, 14.20, 14.90, 15.50, 16.20, 16.80, 17.50, 18.10, 18.80, 19.40, 20.10, 20.70, 21.40, 22.00, 22.70, 23.30, 24.00];
var tabPartFIPHFP25Handi = [2.30, 2.80, 3.40, 4.00, 4.50, 5.10, 5.70, 6.20, 6.80, 7.40, 7.90, 8.50, 9.10, 9.60, 10.20, 10.80, 11.30, 11.90, 12.50, 13.00, 13.60, 14.20, 14.70, 15.30, 15.80, 16.40, 17.00, 17.50, 18.10, 18.70, 19.20, 19.80];
var tabPartFIPHFP20Handi = [1.90, 2.40, 2.90, 3.30, 3.80, 4.30, 4.80, 5.20, 5.70, 6.20, 6.70, 7.10, 7.60, 8.10, 8.60, 9.00, 9.50, 10.00, 10.50, 11.00, 11.40, 11.90, 12.40, 12.90, 13.30, 13.80, 14.30, 14.80, 15.20, 15.70];
var tabPartFIPHFP15Handi = [1.50, 1.90, 2.30, 2.60, 3.00, 3.40, 3.80, 4.10, 4.50, 4.90, 5.30, 5.60, 6.00, 6.40, 6.80, 7.20, 7.50, 7.90, 8.30, 8.70, 9.00, 9.40, 9.80, 10.20, 10.50, 10.90, 11.30, 11.70, 12.10];
var tabPartFIPHFP10Handi = [1.10, 1.30, 1.60, 1.90, 2.10, 2.40, 2.70, 2.90, 3.20, 3.50, 3.70, 4.00, 4.20, 4.50, 4.80, 5.00, 5.30, 5.60, 5.80, 6.10, 6.40, 6.60, 6.90, 7.20, 7.40, 7.70, 7.90];

/**
 * Get the part de l'Etat in fonction of bonif, handicape and the index of the tabMontant...
 */
function getPartEtat(bonif, handicape, indiceMontant){
	if(handicape == false){
		switch(bonif){
			case "30": return tabPartEtat30NonHandi[indiceMontant];
      		case "25": return tabPartEtat25NonHandi[indiceMontant];
      		case "20": return tabPartEtat20NonHandi[indiceMontant];
      		case "15": return tabPartEtat15NonHandi[indiceMontant];
      		case "10": return tabPartEtat10NonHandi[indiceMontant];
		}
	}
	else{
		switch(bonif){
			case "30": return tabPartEtat30Handi[indiceMontant];
	  		case "25": return tabPartEtat25Handi[indiceMontant];
	  		case "20": return tabPartEtat20Handi[indiceMontant];
	  		case "15": return tabPartEtat15Handi[indiceMontant];
	  		case "10": return tabPartEtat10Handi[indiceMontant];
		}
	}
}

/**
 * Get the part de FIPHFP in fonction of bonif and the index of the tabMontant...
 */
function getPartFIPHFP(bonif, indiceMontant){
	switch(bonif){
		case "30": return tabPartFIPHFP30Handi[indiceMontant].toFixed(2);
		case "25": return tabPartFIPHFP25Handi[indiceMontant].toFixed(2);
		case "20": return tabPartFIPHFP20Handi[indiceMontant].toFixed(2);
		case "15": return tabPartFIPHFP15Handi[indiceMontant].toFixed(2);
		case "10": return tabPartFIPHFP10Handi[indiceMontant].toFixed(2);
	}
}

/**
 * Fill the 3 amounts in the resultat panel
 */
function calculeMontants(){
	var indiceMontant = document.getElementById('montantEpargne').selectedIndex;
	var indiceDuree = document.getElementById('dureeEpargne').selectedIndex;

	// Update the montant total de l'epargne
	var montantMensuel = document.getElementById('montantEpargne').options[indiceMontant].value;
	var nbMois = document.getElementById('dureeEpargne').options[indiceDuree].value;
	var montantTotalEpargne = montantMensuel*nbMois;
	document.getElementById('montantTotalEpargne').innerHTML = montantTotalEpargne.toFixed(2);

	// Update the montant total de l'etat
	var bonif = document.getElementById('bonification').innerHTML;
	var handicape = document.getElementById('handicape').checked;
	var partEtat = getPartEtat(bonif, handicape, indiceMontant-1); // -1 because the first is empty
	document.getElementById('montantTotalEtat').innerHTML = (partEtat*nbMois).toFixed(2);
	if(handicape == true){
		document.getElementById('participationFIPHFP').innerHTML = "(dont "+(getPartFIPHFP(bonif, indiceMontant-1)*nbMois).toFixed(2)+" Euros de participation du FIPHFP)";
		setVisibility('participationFIPHFP', "inline", "visible");
	}

	// Update the montant total
	document.getElementById('montantTotal').innerHTML = (montantTotalEpargne + (partEtat*nbMois)).toFixed(2);

	// Update style
	setPanel3Class('');

	// Scroll to div3
	document.location='#div3';
}

/***************************************************
 *********************Methodes utiles***************
 ***************************************************/

function setClass(element, style){
	try{//ff
	element.setAttribute("class",style);
	}catch(error){}
	try{//ie
	element.setAttribute("className",style);
	}catch(error){}
}

function setVisibility(id, display, visibility){
	document.getElementById(id).style.display=display;
	document.getElementById(id).style.visibility=visibility;
}
