function roundN(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}
function tstSelect(){ 
	var str = "", value ="", index;
	document.write(" <select name='tstSelect'>");  
document.write(" <option value=''>Select...</option>"); 
for( i=0; i<tstSelects.length; i++){
	index = tstSelects[i].lastIndexOf("%") + 1;
		value = tstSelects[i].substring(index);
		str = "<option value='"+tstSelects[i]+"'>"+value+"</option>";
		document.write( str);  
}
	document.write("</select>");  
}
function qftSelect(){ 
	var str = "", value ="", index;
	document.write(" <select name='qftSelect'>");  
document.write(" <option value='0'>IGRA Not Done</option>"); 
for( i=0; i<qftSelects.length; i++){
	index = qftSelects[i].lastIndexOf("%") + 1;
		value = qftSelects[i].substring(index);
		str = "<option value='"+qftSelects[i]+"'>"+value+"</option>";
		document.write( str);  
}
	document.write("</select>");  
}

function contactSelect(){
var str = "", value ="", index;
	document.write(" <select name='contactSelect'>");  
document.write(" <option value='0'>No Contact</option>"); 
for( i=0; i<contactSelects.length; i++){
	index = contactSelects[i].lastIndexOf("%") + 1;
		value = contactSelects[i].substring(index);
		str = "<option value='"+contactSelects[i]+"'>"+value+"</option>";
		document.write( str);  
}
	document.write("</select>");  
}
function raceSelect(){
var str = "", value ="", index;
	document.write(" <select name='raceSelect'>");  
document.write(" <option value=''>Select...</option>"); 
for( i=0; i<raceSelects.length; i++){
	index = raceSelects[i].lastIndexOf("%") + 1;
		value = raceSelects[i].substring(index);
		str = "<option value='"+raceSelects[i]+"'>"+value+"</option>";
		document.write( str);  
}
	document.write("</select>");  
}

function nativeSelect(){
var str = "", value ="", index;
	document.write(" <select name='nativeSelect'>");  
document.write(" <option value=''>Select...</option>"); 
for( i=0; i<nativeSelects.length; i++){
	index = nativeSelects[i].lastIndexOf("%") + 1;
		value = nativeSelects[i].substring(index);
		str = "<option value='"+nativeSelects[i]+"'>"+value+"</option>";
		document.write( str);  
}
	document.write("</select>");  
}

function bcgSelect(){
var str = "", value ="", index;
	document.write(" <select name='bcgSelect'>");  
document.write(" <option value=''>Select...</option>"); 
for( i=0; i<bcgSelects.length; i++){
	index = bcgSelects[i].lastIndexOf("%") + 1;
		value = bcgSelects[i].substring(index);
		str = "<option value='"+bcgSelects[i]+"'>"+value+"</option>";
		document.write( str);  
}
	document.write("</select>");  

}
function listSelect()
{
var symptName="xx"; var val=1;
var str;
document.write("<table style='width:100%;' border='0' cellspacing='0' cellpadding='0'>")
for( i=0; i < conditions.length-2 ; i+=2){
	str = conditions[i];
	var firstDeliminator = str.indexOf('%');
	symptName = String(str).substring(0,firstDeliminator); 
	val = String(str).substring(firstDeliminator+1,String(str).length); 
	var line = "<tr><td valign='top' style='padding:0 3px 3px 3px;'><label><input id='" +symptName+"' type='checkbox' name='list' value='"+val+"'>";
	document.write(line);
	document.write(symptName);
	document.write("</label></td>");
	str = conditions[i+1];
	var firstDeliminator = str.indexOf('%');
	symptName = String(str).substring(0,firstDeliminator); 
	val = String(str).substring(firstDeliminator+1,String(str).length); 
	var line = "<td valign='top' style='padding:0 3px 3px 3px;'><label><input id='" +symptName+"' type='checkbox' name='list' value='"+val+"'>";
	document.write(line);
	document.write(symptName);
	document.write("</label></td></tr>");

}
var line2 = "<tr><td style='padding:0 3px 3px 3px; width:50%;'><label><input id='Young age when infected (0-4 years)' type='checkbox' name='list' value='3.6'>Young age when infected (0-4 years)</label></td> <td style='padding:0 3px 3px 3px;'></td></tr>";
document.write(line2);
document.write("</table>");

}//listSelect
//hide the risks when 'none of these conditions' is selected
function hiderisks(norisks){
var t1List = document.getElementsByName("list");
var hide = norisks.checked;
	if(hide==true){
		for(i=0; i<15; i++){
			t1List[i].checked=false;
			t1List[i].disabled=true;
			}
	}
	else{for(i=0; i<15; i++){
			t1List[i].disabled=false;}
	}
		
}
	


//listSelect*/
function ageSelect()
{
	var str = "";
	document.write(" <select name='ageSelect'>");  
	document.write(" <option value=''>Select...</option>"); 
	for( i=18; i < 80; i++){
	str = "<option value='"+ i +"'>"+i+"</option>";
	document.write( str);  
	}
	document.write(" </select>");
}//ageSelect
function countryOfBirthSelect()
{//<select   name="countryOfBirthSelect">
	var str = "", value ="", index;
	document.write(" <select name='countryOfBirthSelect' id='country' onchange='showProv(this.value)';>");  
	document.write(" <option value=''>Select...</option>");
	for( i=0; i < countryOfBirth.length ; i++){
	    index = countryOfBirth[i].lastIndexOf("%") + 1;
		value = countryOfBirth[i].substring(index);
		str = "<option value='"+countryOfBirth[i]+"'>"+value+"</option>";
		document.write( str);  
	}
	document.write(" </select>");
}//countryOfBirthSelect
function showProv(input)
{
	index = input.lastIndexOf("%")+1;
    countrya=input.substring(index);
	if(countrya=="United States of America")
	{document.getElementById("usSelect").style.display="";
	document.getElementById("race").style.display="";
	}
	else{document.getElementById("usSelect").style.display="none"; document.getElementById("race").style.display="none";}
	if(countrya=="Canada (Pacific Coast of B.C.)" | countrya=="Canada (Other)")
	{document.getElementById("native").style.display="";
	}
	else{document.getElementById("native").style.display="none";}
	if(countrya=="India")
	{document.getElementById("indiaSelect").style.display="";
	}
	else{document.getElementById("indiaSelect").style.display="none";}
	if(countrya=="Brazil")
	{document.getElementById("brazilSelect").style.display="";
	}
	else{document.getElementById("brazilSelect").style.display="none";}
	if(countrya=="Argentina")
	{document.getElementById("argentinaSelect").style.display="";
	}
	else{document.getElementById("argentinaSelect").style.display="none";}
	if(countrya=="China")
	{document.getElementById("chinaSelect").style.display="";
	}
	else{document.getElementById("chinaSelect").style.display="none";}
	if(countrya=="Australia")
	{document.getElementById("aussieSelect").style.display="";
	}
	else{document.getElementById("aussieSelect").style.display="none";}
}

function usaStateSelect()
{
	var str = "", value ="", index;
	document.write(" <select name='usaStateSelect'>"); 
	document.write(" <option value=''>Select...</option>");
	for( i=0; i < usaState.length ; i++){
	    index = usaState[i].lastIndexOf("%") + 1;
		value = usaState[i].substring(index);
		str = "<option value='"+usaState[i]+"'>"+value+"</option>";
		document.write( str);  
	}
	document.write(" </select>");
}
function indiaStateSelect()
{
	var str = "", value ="", index;
	document.write(" <select name='indiaStateSelect'>"); 
	document.write(" <option value=''>Select...</option>");
	for( i=0; i < indiaState.length ; i++){
	    index = indiaState[i].lastIndexOf("%") + 1;
		value = indiaState[i].substring(index);
		str = "<option value='"+indiaState[i]+"'>"+value+"</option>";
		document.write( str);  
	}
	document.write(" </select>");
}
function brazilStateSelect()
{
	var str = "", value ="", index;
	document.write(" <select name='brazilStateSelect'>"); 
	document.write(" <option value=''>Select...</option>");
	for( i=0; i < brazilState.length ; i++){
	    index = brazilState[i].lastIndexOf("%") + 1;
		value = brazilState[i].substring(index)
		str = "<option value='"+brazilState[i]+"'>"+value+"</option>";
		document.write( str);  
	}
	document.write(" </select>");
}
function chinaStateSelect()
{
	var str = "", value ="", index;
	document.write(" <select name='chinaStateSelect'>"); 
	document.write(" <option value=''>Select...</option>");
	for( i=0; i < chinaState.length ; i++){
	    index = chinaState[i].lastIndexOf("%") + 1;
		value = chinaState[i].substring(index)
		str = "<option value='"+chinaState[i]+"'>"+value+"</option>";
		document.write( str);  
	}
	document.write(" </select>");
}
function argentinaStateSelect()
{
	var str = "", value ="", index;
	document.write(" <select name='argentinaStateSelect'>"); 
	document.write(" <option value=''>Select...</option>");
	for( i=0; i < argentinaState.length ; i++){
	    index = argentinaState[i].lastIndexOf("%") + 1;
		value = argentinaState[i].substring(index)
		str = "<option value='"+argentinaState[i]+"'>"+value+"</option>";
		document.write( str);  
	}
	document.write(" </select>");
}
function aussieStateSelect()
{
	var str = "", value ="", index;
	document.write(" <select name='aussieStateSelect'>"); 
	document.write(" <option value=''>Select...</option>");
	for( i=0; i < aussieState.length ; i++){
	    index = aussieState[i].lastIndexOf("%") + 1;
		value = aussieState[i].substring(index)
		str = "<option value='"+aussieState[i]+"'>"+value+"</option>";
		document.write( str);  
	}
	document.write(" </select>");
}

function AgeAtImigrationSelect()
{
	var str = "";
	document.write(" <select name='AgeAtImigrationSelect'>");
	document.write(" <option value='99'>N/A</option>");
	for( i=1; i < 80; i++){
	str = "<option value='"+ i +"'>"+i+"</option>";
	document.write( str);  
	}
	document.write(" </select>");
}//AgeAtImigrationSelect


function myfunction(form)
{
/* START WITH VALIDATION */

var immi_str = '';
var conds_str = '';

if(form.AgeAtImigrationSelect.value=='' | (form.countryOfBirthSelect.value=='0.10%0.30%3%Australia' & form.aussieStateSelect.value=='')| (form.countryOfBirthSelect.value=='0.10%1.00%17%Argentina' & form.argentinaStateSelect.value=='') | (form.countryOfBirthSelect.value=='0.0%0.0%44%China' & form.chinaStateSelect.value=='') | (form.countryOfBirthSelect.value=='0.10%1.00%26%Brazil' & form.brazilStateSelect.value=='') | (form.countryOfBirthSelect.value=='0.10%0.40%75%India' & form.indiaStateSelect.value=='') | (form.countryOfBirthSelect.value=='0.10%0%2%United States of America' & (form.usaStateSelect.value=='' | form.raceSelect.value=='')) | ((form.countryOfBirthSelect.value=='2.5%0.6%2%Canada (Other)' | form.countryOfBirthSelect.value=='5.9%1.5%2%Canada (Pacific Coast of B.C.)' ) & form.nativeSelect.value=='')| form.countryOfBirthSelect.value=='' | form.ageSelect.value=='' | form.bcgSelect.value=='' | form.contactSelect.value=='' | form.tstSelect.value=='' | form.qftSelect.value=='')
{
		if(form.AgeAtImigrationSelect.value==''){document.getElementById("imm_td").style.border='1px solid #cc0000'; immi_str = "Please specify age at immigration, if not applicable, select 'N/A'\n";}
		else{immi_stri=''; document.getElementById("imm_td").style.border='none';}
		if(form.countryOfBirthSelect.value=='0.10%0.30%3%Australia' & form.aussieStateSelect.value==''){document.getElementById("aussieSelect").style.border='1px solid #cc0000';}
		else{document.getElementById("aussieSelect").style.border='none';}
		if(form.countryOfBirthSelect.value=='0.10%1.00%17%Argentina' & form.argentinaStateSelect.value==''){document.getElementById("argentinaSelect").style.border='1px solid #cc0000';}
		else{document.getElementById("argentinaSelect").style.border='none';}
		if(form.countryOfBirthSelect.value=='0.0%0.0%44%China' & form.chinaStateSelect.value==''){document.getElementById("chinaSelect").style.border='1px solid #cc0000';}
		else{document.getElementById("chinaSelect").style.border='none';}
		if(form.countryOfBirthSelect.value=='0.10%1.00%26%Brazil' & form.brazilStateSelect.value==''){document.getElementById("brazilSelect").style.border='1px solid #cc0000';}
		else{document.getElementById("brazilSelect").style.border='none';}
		if(form.countryOfBirthSelect.value=='0.10%0.40%75%India' & form.indiaStateSelect.value==''){document.getElementById("indiaSelect").style.border='1px solid #cc0000';}
		else{document.getElementById("indiaSelect").style.border='none';}
		if(form.countryOfBirthSelect.value=='0.10%0%2%United States of America' & form.usaStateSelect.value==''){document.getElementById("usSelect").style.border='1px solid #cc0000';}
		else{document.getElementById("usSelect").style.border='none';}
		if(form.countryOfBirthSelect.value=='0.10%0%2%United States of America' & form.raceSelect.value==''){document.getElementById("race_td").style.border='1px solid #cc0000';}
		else{document.getElementById("race_td").style.border='none';}
		if((form.countryOfBirthSelect.value=='2.5%0.6%2%Canada (Other)'|form.countryOfBirthSelect.value=='5.9%1.5%2%Canada (Pacific Coast of B.C.)' ) & form.nativeSelect.value==''){document.getElementById("native_td").style.border='1px solid #cc0000';}
		else{document.getElementById("native_td").style.border='none';}
		if(form.countryOfBirthSelect.value==''){document.getElementById("cob_td").style.border='1px solid #cc0000';}
		else{document.getElementById("cob_td").style.border='none';}
		if(form.ageSelect.value==''){document.getElementById("age_td").style.border='1px solid #cc0000';}
		else{document.getElementById("age_td").style.border='none';}
		if(form.bcgSelect.value==''){document.getElementById("bcg_td").style.border='1px solid #cc0000';}
		else{document.getElementById("bcg_td").style.border='none';}
		if(form.contactSelect.value==''){document.getElementById("contact_td").style.border='1px solid #cc0000';}
		else{document.getElementById("contact_td").style.border='none';}
		if(form.tstSelect.value==''){document.getElementById("tst_td").style.border='1px solid #cc0000';}
		else{document.getElementById("tst_td").style.border='none';}
		if(form.qftSelect.value==''){document.getElementById("qft_td").style.border='1px solid #cc0000';}
		else{document.getElementById("qft_td").style.border='none';}
		alert( 'Please fill in all the unanswered questions outlined in red.\n' + immi_str);
		window.scrollTo(0,0)
		return false;}
else{
// if form is complete, then let the real math begin...
// BUT, before that happens, make sure nothing is still red.
document.getElementById("imm_td").style.border='none'
document.getElementById("aussieSelect").style.border='none';
document.getElementById("argentinaSelect").style.border='none';
document.getElementById("chinaSelect").style.border='none';
document.getElementById("brazilSelect").style.border='none';
document.getElementById("indiaSelect").style.border='none';
document.getElementById("usSelect").style.border='none';
document.getElementById("race_td").style.border='none';
document.getElementById("native_td").style.border='none';
document.getElementById("cob_td").style.border='none';
document.getElementById("age_td").style.border='none';
document.getElementById("bcg_td").style.border='none';
document.getElementById("contact_td").style.border='none';
document.getElementById("tst_td").style.border='none';
document.getElementById("conds_p").style.color='#003366';
document.getElementById("qft_td").style.border='none';

/*s = by country of birth - Smear Positive Rate - input value
a = age at imigration - if not available then age => pow-a
n = by country of birth - False positive rates due to NTM - input value; different for 5-9mm (TST=1) and 10-14mm (TST=2); 0 if 15+mm (TST=3)

b = 0.1 = for all = Baseline risk of disease
v = false positive rates due to bcg - input value; different rates based on TST reaction size (5-9mm (TST = 1); 10-14mm (TST=2); and 15+mm (TST=3)); and also different rates for vaccination at infancy vs >=2 yo.
r = Relative Risk of TB disease	
	if only one health factor checked	r = t
	if more than one health factor checked	r = Sum t
e = RR for pLTBI given specific ethnicity/race/native status
c = contact risk, casual contact (0.08) vs close contact (0.4). 

*/

// b
    var b = 0.1; //baseline risk of disease for all cases
	var b2 = 5; //risk of disease for close contacts in the first two years, using up-to-date number for older adults, 5%
//tst decides input values for n and v
	/*tst var tstSelects= new Array(
					"1%5-9 mm",
                    "2%10-14 mm",
					"3%15+ mm" );*/
	var tst = form.tstSelect.value; 
	firstDeliminator = tst.indexOf('%'); 
	var tstVal =String(tst).substring(0,firstDeliminator);  
	var tstStr = String(tst).substring(firstDeliminator+1,String(tst).length); 
//qft, if qft is positive then ptb=1, if negative then use TST to calculate risks, if qft is negative and tst not done, then ptb=0
	var qft = form.qftSelect.value;
	firstDeliminator = qft.indexOf('%');
	var qftVal = String(qft).substring(0,firstDeliminator);
	var qftStr = String(qft).substring(firstDeliminator+1,String(qft).length);
//n, s
	var ns = form.countryOfBirthSelect.value; 
	var prov=""; //string to specific state/province
	//if country is india, USA, china, brazil, argentina or australia, get state/province specific NTM rates
	if(ns == "0.10%0%2%United States of America"){
	    ns = form.usaStateSelect.value; 
		prov ="USA, ";
	}
	if(ns == "0.10%0.30%3%Australia"){
	    ns = form.aussieStateSelect.value; 
		prov ="Australia, ";
	}
	if(ns == "0.10%1.00%17%Argentina"){
	    ns = form.argentinaStateSelect.value; 
		prov ="Argentina, ";
	}
	if(ns == "0.0%0.0%44%China"){
	    ns = form.chinaStateSelect.value; 
		prov ="China, ";
	}
	if(ns == "0.10%1.00%26%Brazil"){
	    ns = form.brazilStateSelect.value; 
		prov ="Brazil, ";
	}
	if(ns == "0.10%0.40%75%India"){
	    ns = form.indiaStateSelect.value; 
		prov ="India, ";
	}
//now extract n and s, ex:  ns = "0.40%0.10%10%Albania", => n = 0.40 if 5-9mm, and 0.10 if 10-14mm; s = 10	
	var n=0;
	var firstDeliminator = ns.indexOf('%'); 
	var secondDeliminator = ns.indexOf('%', firstDeliminator+1); 
	var thirdDeliminator = ns.lastIndexOf('%');
//if 5-9mm
	if(tstVal ==1){
	var n = String(ns).substring(0,firstDeliminator); }
//if 10-14mm
	if(tstVal ==2){
	var n = String(ns).substring(firstDeliminator+1,secondDeliminator);}
//if 15mm+
    if(tstVal==3) {n=0;}
//s
	var s = String(ns).substring(secondDeliminator+1,thirdDeliminator);	
	countryOfBirthStr = prov+String(ns).substring((thirdDeliminator+1),String(ns).length);
//
//
//	
//a = age / age at immigration
var aBirth = form.ageSelect.value;
var aImmigration = form.AgeAtImigrationSelect.value;
var a = aBirth; 
if(aImmigration!=99)
			{	if(aBirth*1  < aImmigration*1){
					alert("Age at immigration is larger than your current age!");
					 return false;}
				else{a = aImmigration; }
			}

//e = ethnicity effect
e = 1; //RR is 1 if not from Canada or the US
var raceStr = "";
if(form.countryOfBirthSelect.value=='0.10%0%2%United States of America'){
var race = form.raceSelect.value;
var firstDeliminator = race.indexOf('%'); 
var e = String(race).substring(0,firstDeliminator); 
var raceStr = "<li>"+String(race).substring(firstDeliminator+1)+"</li>";
}
if(form.countryOfBirthSelect.value=='2.5%0.6%2%Canada (Other)' | form.countryOfBirthSelect.value=='5.9%1.5%2%Canada (Pacific Coast of B.C.)'){
var race = form.nativeSelect.value;
var firstDeliminator = race.indexOf('%'); 
var e = String(race).substring(0,firstDeliminator);
var raceStr = "<li>"+String(race).substring(firstDeliminator+1)+"</li>";
}



//Contact 
var ContactText=""; 
var contact = form.contactSelect.value;
var firstDeliminator = contact.indexOf('%');
var c = String(contact).substring(0,firstDeliminator);
ContactText = String(contact).substring(firstDeliminator+1);
if(form.contactSelect.value==0){ContactText="no contact";}
//BCG Status
var vacc = form.bcgSelect.value;
var v =0;
bcgText="";
var firstDeliminator = vacc.indexOf('%');
var secondDeliminator = vacc.indexOf('%',firstDeliminator+1);
var thirdDeliminator = vacc.lastIndexOf('%');
//if 5-9mm
	if(tstVal ==1){
	var v = String(vacc).substring(0,firstDeliminator); }
//if 10-14mm
	if(tstVal ==2){
	var v = String(vacc).substring(firstDeliminator+1,secondDeliminator);}
//if 15mm+
    if(tstVal==3){
	var v = String(vacc).substring(secondDeliminator+1,thirdDeliminator);}
bcgText = String(vacc).substring(thirdDeliminator+1); 
		 

//r (RR associated with specific health conditions)
	var t1List = form.list; 
	var t1ListStr = "";
	var r = 0;
	var r0 = 0; 
	if(t1List[8].checked==true){
		for (i = 0; i < t1List.length; i++) { 
			if(t1List[i].checked == true){
				r0 +=  (t1List[i].value * 1);
				t1ListStr += "<li> " + t1List[i].id +"</li>";
			}	
		}
		r = r0-15;
	}
	else{
		for (i = 0; i < t1List.length; i++) { 
			if(t1List[i].checked == true){
				r +=  (t1List[i].value * 1);
				t1ListStr += "<li> " + t1List[i].id +"</li>";
			}
		}
	}
	if(r==0){r=1;t1ListStr="";}
		
//
//var ptb;
var ptb = "";
if (c == 0)
	{ptb = 1-Math.pow((1-(s/4900)),a);}
else
	{ptb =1-Math.pow((1-c*1)*(1-(s/4900)),a);}
////////////////////////////////
//first calculate PPV for TST test
var ppvtst = (e*1) * ((ptb)/( (ptb) +(n*1/100)+(v*1) ) );
var ppv="";
//////
if((qftVal==2 && tstVal!=0) | (qftVal==0 && tstVal!=0)){ //if qft negative and tst done, or tst done but no qft, then use tst result to calculated ppv 
ppv =ppvtst;
}
if(qftVal==1 && tstVal==0){ //if qft was positive and tst wasn't done
	ppv = 0.98; //igra has 2% false positive
}
if(qftVal==1 && tstVal!=0){
	ppv = 1-((1-ppvtst)*(1-0.98))
}
if(qftVal ==0 && tstVal ==0) // if no test done
{alert("No test was done!"); return false;}
if(qftVal==2 && tstVal==0){ //if qft negative and no TST done, then ppv = 0
ppv = 0;}
////////////////////////////////
if(ppv >1) 	ppv = 1;
if(ppv <0) 	ppv = 0;
////
if (c==0.4 | r0!=0){
	if(c==0.4 && r0!=0){
		var ard0 = (ppv*1)*(b2*1)*(r0*1); //risk in first two years for a close contact & recent conversion
	}
	else if(r0==0){
		var ard0 = (ppv*1)*(b2*1)*(r*1); //risk in first two years for a close contact
	}
	else{
		var ard0 = (ppv*1)*(b*1)*(r0*1); //risk in first two years for recent convert
	}
}
var ard  =  (ppv*1)*(b*1)*(r*1); //risk thereafter, or risk for non-close contact or non-recent 

if(c==0.4|r0!=0){
	var cumul80 =(ard *  ( 78 - (aBirth * 1) ) ) + (ard0 * 1); 
	}
else{
	var cumul80 =(ard *  ( 80 - (aBirth * 1) ) );
	}

////
if(ard0>100) ard0=100;
if(ard >100) 	ard = 100;
if(ard <0) 	ard = 0;
//////////////////////// 
if(cumul80 >100) cumul80 = 100;
if(cumul80 <0) 	cumul80 = 0;



ppvrounded = roundN(ppv*100,2);  
if(c==0.4 | r0!=0){
ard0rounded =roundN(ard0,2);
}
ardrounded =roundN(ard,2);
cumul80Str =roundN(cumul80,2);
/////hep calcs//
if(aBirth>=65){
	phep=5;
	phosp=2.4;
}
else if(aBirth>=50){
	phep=2.3;
	phosp=0.6
}
else if(aBirth>=35){
	phep=1.2;
	phosp=0.2;
}
else if(aBirth>=20){
	phep=0.3;
	phosp=0.1;
}
else{
	phep=0;
	phosp=0;
}

///*****/
window.scrollTo(0,0)
if(tstVal!=0){
	tStr = "a TST reaction of <strong>" +tstStr+ "</strong>";
}
else{tStr="";}

if(qftVal!=0){
	if(tstVal!=0){
		qStr= " and a <strong>" +qftStr+"</strong> QFT Test";
	}
	else{qStr = "a <strong>" +qftStr+"</strong> QFT Test";}
}
else{qStr = "";}
if(aImmigration!=99){
	immStr=", <strong>immigrated at age "+aImmigration+"</strong>";
}
else{immStr=""};

if(c==0.4 | r0!=0){
	
	ardStr = "The risk of development of active tuberculosis disease for the next 2 years is estimated to be: <strong>" + ard0rounded + "%</strong><br /><br />The annual risk of development of active tuberculosis disease after 2 years is estimated to be: <strong>" + ardrounded + "%</strong>.";
}
else{

	ardStr= "The annual risk of development of active tuberculosis disease is estimated to be  <strong>" + ardrounded + "%</strong>.";
}
if(r>1 | e>1){

endStr = ", who has had <strong>" +  ContactText + "</strong> with active TB, and who can be characterized by:<ul><strong>" + t1ListStr + raceStr + "</strong></ul></p>";
}
else{

	endStr = ", and who has had <strong>" +  ContactText + "</strong> with active TB.</p>";
}
ageStr =form.ageSelect.value;
if(aBirth>20){
document.getElementById('results').innerHTML="<h2>Results</h2><p><a href='#' onClick='printresults();'>Printable version</a></p><p>Below are the results for a patient with " + tStr + qStr + ", who is <strong>" + ageStr + "</strong> years old, born in <strong>" + countryOfBirthStr +"</strong>"+ immStr +", whose BCG status is <strong>" +bcgText+ "</strong>" + endStr+ "<p>The likelihood that this is a true positive test (PPV) is: <strong>" + ppvrounded + "%</strong></p>" +"<p>"+ardStr+"</p>" + "<p>The cumulative risk of active tuberculosis disease, up to the age of 80, is: <strong>" + cumul80Str + "%</strong></p>"+"<p>If treated with INH, the probability of clinically significant drug-induced hepatitis is <strong>" + phep + "%</strong>, and the associated probability of hospitalization related to drug-induced hepatitis is <strong>" + phosp + "%</strong>.</p><div align='center' style='border:none;'><input type='button' name='refresh' value='Refresh' onClick='location.reload(true)'></div>";}
else{
document.getElementById('results').innerHTML="<h2>Results</h2><p><a href='#' onClick='printresults();'>Printable version</a></p><p>Below are the results for a patient with " + tStr + qStr + ", who is <strong>" + ageStr + "</strong> years old, born in <strong>" + countryOfBirthStr +"</strong>"+ immStr +", whose BCG status is <strong>" +bcgText+ "</strong>" + endStr+ "<p>The likelihood that this is a true positive test (PPV) is: <strong>" + ppvrounded + "%</strong></p>" +"<p>"+ardStr+"</p>" + "<p>The cumulative risk of active tuberculosis disease, up to age the of 80, is: <strong>" + cumul80Str + "%</strong></p>"+"<p>If treated with INH, the probability of drug-induced hepatitis is <strong>" + phep + "%</strong>.</p><div align='center' style='border:none;'><input type='button' name='refresh' value='Refresh' onClick='location.reload(true)'></div>";}

}}//function myfunction(form)
function printresults(){
var OpenWindow=window.open("", "", "height=600, width=500 ,resizable=1,menubar=0,top=80");
	OpenWindow.document.write("<h2 align='center'>The Online TST/QFT Interpreter Results<br />www.TSTin3D.com</h2><p style='font-size:10px;'>(Version 2.0 March 10, 2011)<br />Review & Analysis:<br />Stephanie Law, MSc; Dick Menzies, MD, MSc; Madhukar Pai, MD, PhD<br />Design & Programming:<br />Stephanie Law, MSc</p><p><a href=# onClick='window.print();'>Print</a></p><p>Below are the results for a patient with " + tStr + qStr + ", who is <strong>" + ageStr + "</strong> years old, born in <strong>" + countryOfBirthStr +"</strong>"+ immStr +", whose BCG status is <strong>" +bcgText+ "</strong>" + endStr+ "<p>The likelihood that this is a true positive test (PPV) is: <strong>" + ppvrounded + "%</strong></p>" +"<p>"+ardStr+"</p>" + "<p>The cumulative risk of active tuberculosis disease, up to the age of 80, is: <strong>" + cumul80Str + "%</strong></p>" + "<p>If treated with INH the probability of drug-induced hepatitis is <strong>" + phep + "%</strong> and the probability of hospitalization for drug-induced hepatitis is <strong>" + phosp + "%</strong>.</p>");
}
	
