function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function Calculate(){ 
  
  var EmployeeNo=document.getElementById("txtNumberEmployees").value;
  var PatientHour=document.getElementById("txtPatientHour").value;
  var ClinicCost=document.getElementById("txtClinicCost").value;
  if (EmployeeNo!=""){
    document.getElementById("txtMonthlyCost").innerHTML= "$"+addCommas((Math.round(25833/EmployeeNo*100)/100).toFixed(2));
  }
  if (PatientHour!=""){
    document.getElementById("txtPatientDay").innerHTML=addCommas(Math.round(PatientHour*8*100)/100);
	document.getElementById("txtPatientWeek").innerHTML=addCommas(Math.round(document.getElementById("txtPatientDay").innerHTML*5*100)/100);
	document.getElementById("txtPatientMonth").innerHTML=addCommas((document.getElementById("txtPatientWeek").innerHTML.replace(",","")*50/12*100/100).toFixed(0));
	document.getElementById("txtPatientCost").innerHTML="$"+addCommas((Math.round(25833/document.getElementById("txtPatientMonth").innerHTML.replace("$","").replace(",","")*100)/100).toFixed(2));
  }
  if (ClinicCost!=""){
    document.getElementById("txtWellnessCost").innerHTML="$"+addCommas((Math.round(document.getElementById("txtPatientCost").innerHTML.replace("$","").replace(",","")*100)/100).toFixed(2));	
	document.getElementById("txtPatientSavings").innerHTML="$"+addCommas((Math.round((document.getElementById("txtClinicCost").value.replace("$","").replace(",","")-document.getElementById("txtWellnessCost").innerHTML.replace("$","").replace(",",""))*100)/100).toFixed(2));
	document.getElementById("txtEmployerSavings").innerHTML="$"+addCommas((Math.round(document.getElementById("txtPatientMonth").innerHTML.replace("$","").replace(",","")*document.getElementById("txtPatientSavings").innerHTML.replace("$","").replace(",","")*12*100)/100).toFixed(2));
  }
}