/* calculation of clinical diagnosis of pneumonia */

function pneumonia_main() {
	var x1 = IsNumber(document.getElementById ('x1').value,'Age');
	var x2 = IsNumber(document.getElementById ('x2').value,'N/w cough\'s duration');
	var x5 = IsNumber(document.getElementById ('x5').value,'Maximum temperature');
	var n6 = IsNumber(document.getElementById ('n6').value,'Dyspnea');
	var n7 = IsNumber(document.getElementById ('n7').value,'Dyspnea at effort only');
	var n10 = IsNumber(document.getElementById ('n10').value,'Rigors');
	var n14 = IsNumber(document.getElementById ('n14').value,'Smoking');
	var x16 = IsNumber(document.getElementById ('x16').value,'Current temperature');
	var n17 = IsNumber(document.getElementById ('n17').value,'Signs of URI');
	var n19 = IsNumber(document.getElementById ('n19').value,'Prolonged expir.');
	var n20 = IsNumber(document.getElementById ('n20').value,'Perc.: dullness');
	var n21 = IsNumber(document.getElementById ('n21').value,'Aus.: frict. rub');
	var n22 = IsNumber(document.getElementById ('n22').value,'Aus.: dimin. insp. sound');
	var n23 = IsNumber(document.getElementById ('n23').value,'Aus.: abn. breath sound');
	
	var s = - 82.1 - 0.0054*x1 + 0.146*x2 + 1.89*x5 - 1.34*n6 + 2.63*n7 + 0.52*n10 + 0.023*n14 
		   + 0.144*x16 + 1.23*n17 - 1.4*n19 + 0.84*n20 + 0.97*n21 + 0.41*n22 + 0.52*n23 
		   + 0.00017*Math.pow((x1-45.0), 2) - 0.00912*Math.pow((x2-10.0), 2) 
		   - 0.83*Math.pow((x5-38.5), 2) - 0.33*Math.pow((x16-38.5), 2) ;
		   
	var y = 100.0/(1.0+Math.exp(-s)) ;
	document.getElementById ('y').value = Math.round(y) ;
}

function IsNumber(str, type) {
	if (isNaN(str)) {
		alert(type + " is not a number!") ;
		return Number(0) ;
  	} else if (str == '') {
		alert(type + " is not spezified!") ;
		return Number(0) ;
	} else {
		return Number(str) ;
	}
}