/*
Calculateur nitrox Deepstop
Auteur : Benjamin BERNARD
Licence d'utilisation disponible sur http://www.deepstop.fr/
*/

function calcul_nitrox_ppO2() {

	if ( document.getElementById('ppO2').value != null ) {
		var ppO2t=document.getElementById('ppO2').value;
		ppO2t=ppO2t.replace(RegExp(","),'.');
		var ppO2=parseInt(10*ppO2t);
	}

	if ( document.getElementById('ppO2').value != null && document.getElementById('propoxy').value != null && document.getElementById('ppO2').value != '' && document.getElementById('propoxy').value != '' ) {
		/* calcul de la profondeur maxi à partir de la ppO2 et du % d'O2 indiqué */
		var pm;
		var propoxy=parseInt(document.getElementById('propoxy').value)/100;
		pm=Math.round((ppO2/propoxy)-10);
		document.getElementById('profmaxi').value=pm;
	} else if ( document.getElementById('ppO2').value != null && document.getElementById('profmaxi').value != null && document.getElementById('ppO2').value != '' && document.getElementById('profmaxi').value != '') {
		/* calcul du % d'oxygène maxi possible selon la profondeur et la ppO2 indiquées */
		var propoxy;
		var pp02=parseInt(document.getElementById('ppO2').value);
		var profmaxi=parseInt(document.getElementById('profmaxi').value);
		propoxy=ppO2/(profmaxi+10);
		document.getElementById('propoxy').value=Math.round(propoxy*100);
	} else if ( document.getElementById('propoxy').value != null && document.getElementById('profmaxi').value != null && document.getElementById('propoxy').value != '' && document.getElementById('profmaxi').value != '' ) {
		/* calcul de ppO2 à la profondeur et au % d'O2 indiqué */
		var propoxy=parseInt(document.getElementById('propoxy').value)/100;
		var profmaxi=parseInt(document.getElementById('profmaxi').value);
		var ppO2;
		ppO2=(profmaxi+10)/10*propoxy;
		ppO2=Math.round(10*ppO2)/10;
		document.getElementById('ppO2').value=ppO2;
	}
}

