/***********************************
Uses unobtrusive javascript.

Calculator for BMI and BSA
***********************************/

/****
For the animations. Needs to be available for almost all pages.
****/
function popitup(url) 
{
	newwindow=window.open(url,'name','height=362,width=808');
	if (window.focus) {newwindow.focus()}
	return false;
}

window.onload = function()
{ 
	if(document.getElementById && document.createTextNode) 
	{ 
  		setupfunc(); 
	}
	/*init();*/
} 

setupfunc = function()
{
	var subbsa=document.getElementById("subbsa");

	if (subbsa)
	{
		subbsa.onclick = calculatebsa;
	}

	var subpain=document.getElementById("subpaincalc");
	
	if (subpain)
	{
		self.resizeTo(1000, 780);
		self.moveTo(30, 30);
	}

	var subgord=document.getElementById("subgordcalc");
	
	if (subgord)
	{
		self.resizeTo(500, 780);
		self.moveTo(500, 30);
	}

	var subasthma=document.getElementById("frmasthmascore");

	if (subasthma)
	{
		self.resizeTo(650, 950);
		self.moveTo(0, 0);
		
		for (var i = 0; i < subasthma.q1.length; i++)
		{
			subasthma.q1[i].onclick = calculateasthmascore1;
		}

		for (var i = 0; i < subasthma.q2.length; i++)
		{
			subasthma.q2[i].onclick = calculateasthmascore2;
		}

		for (var i = 0; i < subasthma.q3.length; i++)
		{
			subasthma.q3[i].onclick = calculateasthmascore3;
		}

		for (var i = 0; i < subasthma.q4.length; i++)
		{
			subasthma.q4[i].onclick = calculateasthmascore4;
		}

		for (var i = 0; i < subasthma.q5.length; i++)
		{
			subasthma.q5[i].onclick = calculateasthmascore5;			
		}

		document.getElementById("subasthma").onclick = showanswer;		

		document.getElementById("clrasthma").onclick = clearform;
		

//		document.getElementById("logo").style.visibility = "visible";
//		document.getElementById("total25").style.visibility = "hidden";
//		document.getElementById("total20_24").style.visibility = "hidden";
//		document.getElementById("total19_0").style.visibility = "hidden";

		document.getElementById("logo").style.display = "block";
		document.getElementById("total25").style.display = "none";
		document.getElementById("total20_24").style.display = "none";
		document.getElementById("total19_0").style.display = "none";

	}
	
// set up menstruation calculator
	var submen=document.getElementById("submen");

	if (submen)
	{
		submen.onclick = calculatemen;
		
		var submeni=document.getElementById("submeni");
		submeni.onclick = nextmen;
		
		document.getElementById("meniclr").onclick = clearmeniform;
	}

// set up pregnancy calculator
	var subpreg=document.getElementById("subpreg");
	
	if (subpreg)
	{
		document.getElementById("pregclr").onclick = clearpregform;

		document.getElementById("preglastmen").onclick = calculateduedate;
		
		subpreg.onclick = pregduedate;
	}
	
// Glomerular Filtration Rate (GFR)
	var subgfr=document.getElementById("subgfr")

	if (subgfr)
	{
		subgfr.onclick = calculategfr;
	}

// Headache or Migraine
	var subhom=document.getElementById("subhom");
	
	if (subhom)
	{
		subhom.onclick = calculatehom;
	}

// Dry eye syndrome
	var subdry=document.getElementById("subdry");
	
	if (subdry)
	{
		subdry.onclick = calculatedry;
	}

// ADHD July 2008
	var subadhd=document.getElementById("subadhd");
	
	if (subadhd)
	{
		subadhd.onclick = calculateadhd;
	}

// alcohol
	var subalcohol=document.getElementById("subalcohol");
	
	if (subalcohol)
	{
		subalcohol.onclick = calculatealcohol;
		document.getElementById("frmalcohol").radsex[0].onclick = alccheckpregnancy;
		document.getElementById("frmalcohol").radsex[1].onclick = alccheckpregnancy;
		document.getElementById("frmalcohol").radpreg[0].onclick = alcchecksex;
		document.getElementById("frmalcohol").radpreg[1].onclick = alcchecksex;		
	}

// Blood count
	var subblood=document.getElementById("subblood");
	
	if (subblood)
	{
		subblood.onclick = calculatebloodcount;
	}

// AUDIT
	var subcalcaudit=document.getElementById("subcalcaudit");
	
	if (subcalcaudit)
	{
		subcalcaudit.onclick = calculateAUDIT;
		
		showClass("calcauditquestionlist", "calcauditmale", 1);
	}

// PSA
	var subpsa=document.getElementById("subpsa");
	
	if (subpsa)
	{
		subpsa.onclick = evaluatepsa;
		document.getElementById("divtoolbackground").style.backgroundImage= "none";
	}

// Calcium
	var subcalcium=document.getElementById("btncont");
	var subcalciumeval=document.getElementById("subcalcium");
	
	if (subcalcium)
	{
		subcalcium.onclick = showcalciumtable;
		subcalciumeval.onclick = showcalciumresults;
	}

// FIGO
	var subfigo=document.getElementById("subfigo");
	
	if (subfigo)
	{
		subfigo.onclick = showfigoresults;
	}

// Blood Pressure Results
	var subbp=document.getElementById("subbp");
	
	if (subbp)
	{
		subbp.onclick = showbloodpressureresults;
	}

// LDL Cholesterol Tool
	var subldl=document.getElementById("btnldlcontinue");
	
	if (subldl)
	{
		subldl.onclick = showldlinput;
		document.getElementById("subldl").onclick = showldlresults;
	}

// Schizophrenia Medication Tolerability Tool
	var subschiz=document.getElementById("subschiz");
	
	if (subschiz)
	{
		subschiz.onclick = showschizresults;
		document.getElementById("btnshowform").onclick = showschizinput;
	}

// Somac OTC Tool
	var subhtpa=document.getElementById("subhtpa");
	
	if (subhtpa)
	{
		subhtpa.onclick = showsomacotcresultsone;
		document.getElementById("subhtpb").onclick = showsomacotcresultstwo;
		document.getElementById("subhtpc").onclick = showsomacotcresultsthree;
		document.getElementById("subhtpd").onclick = showsomacotcresultsfour;
		document.getElementById("subhtpe").onclick = showsomacotcresultsfive;
	}

}







function showsomacotcresultsfive()
{
	var frmsomac;
	frmsomac = document.getElementById("frmhtp");

	if (findcheckedvalue(frmsomac.rade1) == 0)
	{
		//If no - go to Answer C (Somac) 
		showsomachtpanswer(3);
	}
	else
	{
		//If yes - go to Answer A (refer to GP)
		showsomachtpanswer(1);
	}
}

function showsomacotcresultsfour()
{
	var frmsomac;
	frmsomac = document.getElementById("frmhtp");

	if (findcheckedvalue(frmsomac.radd1) == 0)
	{
		//If 1 true - go to Answer B (antacid)
		showsomachtpanswer(2);
		hideelem("dive");
	}
	else
	{
		//If 2 true - go to Part E 
		showelem("dive");
		showsomachtpanswer(4);
	}
}

function showsomacotcresultsthree()
{
	var frmsomac;
	frmsomac = document.getElementById("frmhtp");

	if (findcheckedvalue(frmsomac.radc1) == 0 && findcheckedvalue(frmsomac.radc2) == 0 && findcheckedvalue(frmsomac.radc3) == 0 && findcheckedvalue(frmsomac.radc4) == 0 && findcheckedvalue(frmsomac.radc5) == 0 && findcheckedvalue(frmsomac.radc6) == 0 && findcheckedvalue(frmsomac.radc7) == 0)
	{
		//If all no - go to Part D
		showelem("divd");
		showsomachtpanswer(4);
	}
	else
	{
		//If any yes - go to Answer A (refer to GP)
		showsomachtpanswer(1);
		hideelem("divd");
		hideelem("dive");
	}
}
	
function showsomacotcresultstwo()
{
	var frmsomac;
	frmsomac = document.getElementById("frmhtp");

	if (findcheckedvalue(frmsomac.radb1) == 0 && findcheckedvalue(frmsomac.radb2) == 0 && findcheckedvalue(frmsomac.radb3) == 0 && findcheckedvalue(frmsomac.radb4) == 0 && findcheckedvalue(frmsomac.radb5) == 0 && findcheckedvalue(frmsomac.radb6) == 0 && findcheckedvalue(frmsomac.radb7) == 0 && findcheckedvalue(frmsomac.radb8) == 0 && findcheckedvalue(frmsomac.radb9) == 0 && findcheckedvalue(frmsomac.radb10) == 0 && findcheckedvalue(frmsomac.radb11) == 0)
	{
		//If all no - go to Part C
		showelem("divc");
		showsomachtpanswer(4);
	}
	else
	{
		//If any yes - go to Answer A (refer to GP)
		showsomachtpanswer(1);
		hideelem("divc");
		hideelem("divd");
		hideelem("dive");
	}
}

function showsomacotcresultsone()
{
	var frmsomac;
	frmsomac = document.getElementById("frmhtp");
	
	if (findcheckedvalue(frmsomac.rada1) == 0 && findcheckedvalue(frmsomac.rada2) == 0)
	{
		//If all no - go to Answer A (refer to GP)
		showsomachtpanswer(1);
		hideelem("divb");
		hideelem("divc");
		hideelem("divd");
		hideelem("dive");
	}
	else
	{
		//If any yes - continue to Part B
		showelem("divb");
		showsomachtpanswer(4);
	}
}


function loopForm(form) {
    var cbResults = 'Checkboxes: ';
    var radioResults = 'Radio buttons: ';

	var frmsomac;
	frmsomac = document.getElementById("frmhtp");
	radioResults = '';

	if (findcheckedvalue(frmsomac.rada1) == 1)
	{
		radioResults += '&ans=rada1';
	}
	if (findcheckedvalue(frmsomac.rada2) == 1)
	{
		radioResults += '&ans=rada2';
	}
	if (findcheckedvalue(frmsomac.radb1) == 1)
	{
		radioResults += '&ans=radb1';
	}
	if (findcheckedvalue(frmsomac.radb2) == 1)
	{
		radioResults += '&ans=radb2';
	}
	if (findcheckedvalue(frmsomac.radb3) == 1)
	{
		radioResults += '&ans=radb3';
	}
	if (findcheckedvalue(frmsomac.radb4) == 1)
	{
		radioResults += '&ans=radb4';
	}
	if (findcheckedvalue(frmsomac.radb5) == 1)
	{
		radioResults += '&ans=radb5';
	}
	if (findcheckedvalue(frmsomac.radb6) == 1)
	{
		radioResults += '&ans=radb6';
	}
	if (findcheckedvalue(frmsomac.radb7) == 1)
	{
		radioResults += '&ans=radb7';
	}
	if (findcheckedvalue(frmsomac.radb8) == 1)
	{
		radioResults += '&ans=radb8';
	}
	if (findcheckedvalue(frmsomac.radb9) == 1)
	{
		radioResults += '&ans=radb9';
	}
	if (findcheckedvalue(frmsomac.radb10) == 1)
	{
		radioResults += '&ans=radb10';
	}
	if (findcheckedvalue(frmsomac.radb11) == 1)
	{
		radioResults += '&ans=radb11';
	}
	if (findcheckedvalue(frmsomac.radc1) == 1)
	{
		radioResults += '&ans=radc1';
	}
	if (findcheckedvalue(frmsomac.radc2) == 1)
	{
		radioResults += '&ans=radc2';
	}
	if (findcheckedvalue(frmsomac.radc3) == 1)
	{
		radioResults += '&ans=radc3';
	}
	if (findcheckedvalue(frmsomac.radc4) == 1)
	{
		radioResults += '&ans=radc4';
	}
	if (findcheckedvalue(frmsomac.radc5) == 1)
	{
		radioResults += '&ans=radc5';
	}
	if (findcheckedvalue(frmsomac.radc6) == 1)
	{
		radioResults += '&ans=radc6';
	}
	if (findcheckedvalue(frmsomac.radc7) == 1)
	{
		radioResults += '&ans=radc7';
	}
	if (findcheckedvalue(frmsomac.radd1) == 1)
	{
		radioResults += '&ans=radd1';
	}
	if (findcheckedvalue(frmsomac.rade1) == 1)
	{
		radioResults += '&ans=rade1';
	}
	
/*
	for (var i = 0; i < form.elements.length; i++ ) {
        if (form.elements[i].type == 'checkbox') {
            if (form.elements[i].checked == true) {
                cbResults += form.elements[i].value + ' ';
            }
        }
        if (form.elements[i].type == 'radio') {
            alert(form.elements[i].checked);
			if (form.elements[i].checked == true) {
                radioResults += form.elements[i].value + ' ';
            }
        }
    }
*/	
    //document.getElementById("cbResults").innerHTML = cbResults;
    //document.getElementById("radioResults").innerHTML = radioResults;
	return radioResults;
}

function showsomachtpanswer(ians)
{
	var strqstring;
	strqstring = loopForm(document.frmhtp)

	if (ians == 1)
	{
		showelem("eval");
		hideelem("ansb");
		hideelem("ansc");
		showelem("ansa");
		window.open("RecordCalcResults.asp?ans=somachtpmar2009" + strqstring + "&ans=1", "", "width=50,height=50");
	}
	else if (ians == 2)
	{
		showelem("eval");
		hideelem("ansa");
		hideelem("ansc");
		showelem("ansb");
		window.open("RecordCalcResults.asp?ans=somachtpmar2009" + strqstring + "&ans=2", "", "width=50,height=50");
	}
	else if (ians == 3)
	{
		showelem("eval");
		hideelem("ansa");
		hideelem("ansb");
		showelem("ansc");
		window.open("RecordCalcResults.asp?ans=somachtpmar2009" + strqstring + "&ans=3", "", "width=50,height=50");
	}
	else
	{
		hideelem("ansa");
		hideelem("ansb");
		hideelem("ansc");
		hideelem("eval");
	}
}


function showldlinput()
{
	document.getElementById("ldllevelsinput").style.display = "block";
}

function showldlresults()
{
	var iage;
	var ssex, schd, scad, spad, saaa, sdia, shistory, ssmoker, sbp;
	var fldl, fhdl, ftot, ftri;
	var frmldl;
	var brisk;
	
	if (isNaN(document.getElementById("txtage").value) || document.getElementById("txtage").value == "") 
	{
		document.getElementById("txtage").focus();
		alert('Please enter your age.');
	}
	else
	{
		document.getElementById("ldllevelsresults").style.display = "block";
		document.getElementById("ldlresandref").style.display = "block";
		showelem("divtlc");

		frmldl = document.getElementById("frmldllevels");
		
		iage = document.getElementById("txtage").value;
		
		ssex = findcheckedvalue(frmldl.radsex);
		
		schd = findcheckedvalue(frmldl.radchd);
		scad = findcheckedvalue(frmldl.radcad);
		spad = findcheckedvalue(frmldl.radpad);
		saaa = findcheckedvalue(frmldl.radaaa);
		sdia = findcheckedvalue(frmldl.raddia);
		shistory = findcheckedvalue(frmldl.radhistory);
		ssmoker = findcheckedvalue(frmldl.radsmoker);
		sbp = findcheckedvalue(frmldl.radbp);
		
		fldl = document.getElementById("txtldl").value;
		fhdl = document.getElementById("txthdl").value;
		ftot = document.getElementById("txttot").value;
		ftri = document.getElementById("txttri").value;
		
		if(isNaN(fldl) || fldl == "")
		{
			fldl = 0;
		}
		if(isNaN(fhdl) || fhdl == "")
		{
			fhdl = 0;
		}
		if(isNaN(ftot) || ftot == "")
		{
			ftot = 0;
		}
		if(isNaN(ftri) || ftri == "")
		{
			ftri = 0;
		}
		
		if(schd == "yes" || scad == "yes" || spad == "yes" || saaa == "yes" || sdia == "yes" || shistory == "yes" || ssmoker == "yes" || sbp == "yes")
		{
			brisk = true;
		}
		else
		{
			brisk = false;
		}
		
		if(ssex == "male" && iage > 44)
		{
			brisk = true;
		}
		
		if(ssex == "female" && iage > 54)
		{
			brisk = true;
		}

		window.open("RecordCalcResults.asp?ans=ldlleveldec2008&ans=" + ssex + "&ans=" + iage + "&ans=" + schd + "&ans=" + scad + "&ans=" + spad + "&ans=" + saaa + "&ans=" + sdia + "&ans=" + shistory + "&ans=" + ssmoker + "&ans=" + sbp + "&ans=" + brisk + "&ans=" + fldl + "&ans=" + fhdl + "&ans=" + ftot + "&ans=" + ftri, "", "width=50,height=50");
		
		if(brisk)
		{
			document.getElementById("divrisks").style.display = "block";
		}
		else
		{
			document.getElementById("divrisks").style.display = "none";
		}
		
		// ldl
		if(fldl == 0)
		{
			document.getElementById("ldllvl").innerHTML = "No data - ";
			hideelem("divldloptimal");
			hideelem("divldlnearoptimal");
			hideelem("divldlhigh");
			showelem("divldlnodata");
		}
		else if(fldl < 100)
		{
			document.getElementById("ldllvl").innerHTML = "Optimal - ";
			showelem("divldloptimal");
			hideelem("divldlnearoptimal");
			hideelem("divldlhigh");
			hideelem("divldlnodata");
		}
		else if(fldl < 130)
		{
			document.getElementById("ldllvl").innerHTML = "Near optimal/above optimal - ";
			hideelem("divldloptimal");
			showelem("divldlnearoptimal");
			hideelem("divldlhigh");
			hideelem("divldlnodata");
		}
		else if(fldl < 160)
		{
			document.getElementById("ldllvl").innerHTML = "Borderline high - ";
			hideelem("divldloptimal");
			hideelem("divldlnearoptimal");
			showelem("divldlhigh");
			hideelem("divldlnodata");
		}
		else if(fldl < 190)
		{
			document.getElementById("ldllvl").innerHTML = "High - ";
			hideelem("divldloptimal");
			hideelem("divldlnearoptimal");
			showelem("divldlhigh");
			hideelem("divldlnodata");
		}
		else
		{
			document.getElementById("ldllvl").innerHTML = "Very high - ";
			hideelem("divldloptimal");
			hideelem("divldlnearoptimal");
			showelem("divldlhigh");
			hideelem("divldlnodata");
		}
		
		// hdl
		if(fhdl == 0)
		{
			document.getElementById("hdllvl").innerHTML = "No data - ";
			showelem("divhdlnodata");
			hideelem("divhdlhigh");
			hideelem("divhdlnormal");
			hideelem("divhdllow");
		}
		else if(fhdl < 40)
		{
			document.getElementById("hdllvl").innerHTML = "Low - ";
			hideelem("divhdlnodata");
			hideelem("divhdlhigh");
			hideelem("divhdlnormal");
			showelem("divhdllow");
		}
		else if(fhdl < 60)
		{
			document.getElementById("hdllvl").innerHTML = "Normal - ";
			hideelem("divhdlnodata");
			hideelem("divhdlhigh");
			showelem("divhdlnormal");
			hideelem("divhdllow");
		}
		else
		{
			document.getElementById("hdllvl").innerHTML = "High - ";
			hideelem("divhdlnodata");
			showelem("divhdlhigh");
			hideelem("divhdlnormal");
			hideelem("divhdllow");
		}
		
		// total
		if(ftot == 0)
		{
			document.getElementById("totlvl").innerHTML = "No data - ";
			hideelem("divtotdesirable");
			hideelem("divtothigh");
			showelem("divtotnodata");
		}
		else if(ftot < 200)
		{
			document.getElementById("totlvl").innerHTML = "Desirable - ";
			showelem("divtotdesirable");
			hideelem("divtothigh");
			hideelem("divtotnodata");
		}
		else if(ftot < 240)
		{
			document.getElementById("totlvl").innerHTML = "Borderline high - ";
			hideelem("divtotdesirable");
			showelem("divtothigh");
			hideelem("divtotnodata");
		}
		else
		{
			document.getElementById("totlvl").innerHTML = "High - ";
			hideelem("divtotdesirable");
			showelem("divtothigh");
			hideelem("divtotnodata");
		}
		
		// triglycerides
		if(ftri == 0)
		{
			document.getElementById("trilvl").innerHTML = "No data - ";
			hideelem("divtrinormal");
			hideelem("divtrihigh");
			showelem("divtrinodata");
		}
		else if(ftri < 150)
		{
			document.getElementById("trilvl").innerHTML = "Normal - ";
			showelem("divtrinormal");
			hideelem("divtrihigh");
			hideelem("divtrinodata");
		}
		else if(ftri < 200)
		{
			document.getElementById("trilvl").innerHTML = "Borderline high - ";
			hideelem("divtrinormal");
			showelem("divtrihigh");
			hideelem("divtrinodata");
		}
		else if(ftri < 500)
		{
			document.getElementById("trilvl").innerHTML = "High - ";
			hideelem("divtrinormal");
			showelem("divtrihigh");
			hideelem("divtrinodata");
		}
		else
		{
			document.getElementById("trilvl").innerHTML = "Very high - ";
			hideelem("divtrinormal");
			showelem("divtrihigh");
			hideelem("divtrinodata");
		}
	}	
}

function showelem(elemid)
{
	document.getElementById(elemid).style.display = "block";
}

function hideelem(elemid)
{
	document.getElementById(elemid).style.display = "none";
}

function showsex(bsex)
{
	if (bsex == 0)
	{
		showClass("calcauditquestionlist", "calcauditmale", 0);
		showClass("calcauditquestionlist", "calcauditfemale", 1);
		//vrad[0].checked = "checked";
	}
	else
	{
		showClass("calcauditquestionlist", "calcauditmale", 1);
		showClass("calcauditquestionlist", "calcauditfemale", 0);
		//vrad[4].checked = "checked";
	}
	//vrad = document.getElementById("rad2");
	//alert(findcheckedvalue(frmcalcaudit.rad2a));
	//alert(vrad[0].checked);

}

function showClass(strcontainer, strclass, bshow)
{
	var items = document.getElementById(strcontainer).getElementsByTagName('*');

	var regstr = new RegExp(strclass);
	
	for(var i=0; i < items.length; i++)
	{
		if(items[i].className.match(regstr))
		{
			if (bshow == 1)
			{
				items[i].style.display = 'block';

			}
			else
			{
				items[i].style.display = 'none';
				
			}
		}
	}
}

// Blood count
function calculatebloodcount()
{
	bloodform = document.getElementById("frmbloodcount");
	
	var bpreg;
	var bathletic;
	var sanswer;
	
	if(findcheckedvalue(bloodform.radpreg) == 'yes'	)
	{
		bpreg = true;
	}
	else
	{
		bpreg = false;
	}

	if(findcheckedvalue(bloodform.radathletic) == 'yes'	)
	{
		bathletic = true;
	}
	else
	{
		bathletic = false;
	}

	// hide all answer rows
	document.getElementById("rowhaemoglobin").style.display = "none";
	document.getElementById("rowmeancorpuscularvolume").style.display = "none";
	document.getElementById("rowmeancorpuscularhaemoglobin").style.display = "none";
	document.getElementById("rowwhitebloodcells").style.display = "none";
	document.getElementById("rowplatelets").style.display = "none";
	document.getElementById("rowlymphocytes").style.display = "none";
	document.getElementById("rowmonocytes").style.display = "none";
	document.getElementById("roweosinophils").style.display = "none";
	document.getElementById("rowneutrophils").style.display = "none";

	var finputvalue1 = 0;
	sanswer = document.getElementById("anshaemoglobin");
	finputvalue1 = parseFloat(document.getElementById("txthaemoglobin").value);
	if(isNaN(finputvalue1))
	{finputvalue1 = 0;}
	else
	{
		if (navigator.appName == "Microsoft Internet Explorer")
		{
			document.getElementById("rowhaemoglobin").style.display = "block";
		}
		else
		{
			document.getElementById("rowhaemoglobin").style.display = "table-row";
		}
		
		sanswer.innerHTML = "Normal";
		
		if(finputvalue1 > 150)
		{
			if(bpreg || bathletic)
				{sanswer.innerHTML = "Your haemoglobin count is above the normal range. In extreme cases this could be due to a haemotological disease.";}
			else
				{sanswer.innerHTML = "Your haemoglobin count is above the normal range. In extreme cases this could be due to a haemotological disease.";}
		}
		else if(finputvalue1 < 115)
		{
			if(bpreg || bathletic)
				{sanswer.innerHTML = "Your haemoglobin count is below the normal range, this is most likely due to your pregnancy or very active lifestyle.";}
			else
				{sanswer.innerHTML = "Your haemoglobin count is below the normal range. This could be indicative of a condition called anaemia.";}
		}
		else
		{sanswer.innerHTML = "Normal";}
		
		if(finputvalue1 == 0){sanswer.innerHTML = "No data";}
	}
	
		
	var finputvalue2 = 0;
	sanswer = document.getElementById("ansmeancorpuscularvolume");
	finputvalue2 = parseFloat(document.getElementById("txtmcv").value);
	if(isNaN(finputvalue2))
	{finputvalue2 = 0;}
	else
	{
		if (navigator.appName == "Microsoft Internet Explorer")
		{
			document.getElementById("rowmeancorpuscularvolume").style.display = "block";
		}
		else
		{
			document.getElementById("rowmeancorpuscularvolume").style.display = "table-row";
		}
		
		sanswer.innerHTML = "Normal";
		
		if(finputvalue2 > 98)
		{
			sanswer.innerHTML = "Your blood is made up of a high proportion of red blood cells. This could indicate that you are dehydrated.";
		}
		else if(finputvalue2 < 77)
		{
			sanswer.innerHTML = "Your blood is made up of a low proportion of red blood cells. This could be indicative of a condition called anaemia.";
		}
		else
		{sanswer.innerHTML = "Normal";}
		
		if(finputvalue2 == 0){sanswer.innerHTML = "No data";}
	}
	
		
	var finputvalue3 = 0;
	sanswer = document.getElementById("ansmeancorpuscularhaemoglobin");
	finputvalue3 = parseFloat(document.getElementById("txtmch").value);
	if(isNaN(finputvalue3))
	{finputvalue3 = 0;}
	else
	{
		if (navigator.appName == "Microsoft Internet Explorer")
		{
			document.getElementById("rowmeancorpuscularhaemoglobin").style.display = "block";
		}
		else
		{
			document.getElementById("rowmeancorpuscularhaemoglobin").style.display = "table-row";
		}
		
		sanswer.innerHTML = "Normal";
		
		if(finputvalue3 > 27)
		{
			sanswer.innerHTML = "Your red blood cells have a high proportion of haemoglobin. This could be indicative of a blood disorder or dehydration.";
		}
		else if(finputvalue3 < 24)
		{
			sanswer.innerHTML = "Your red blood cells have a low proportion of haemoglobin. This could be indicative of a condition called anaemia.";
		}
		else
		{sanswer.innerHTML = "Normal";}
		
		if(finputvalue3 == 0){sanswer.innerHTML = "No data";}
	}
	
	
	var finputvalue4 = 0;
	sanswer = document.getElementById("answhitebloodcells");
	finputvalue4 = parseFloat(document.getElementById("txtwbc").value);
	if(isNaN(finputvalue4))
	{finputvalue4 = 0;}
	else
	{
		if (navigator.appName == "Microsoft Internet Explorer")
		{
			document.getElementById("rowwhitebloodcells").style.display = "block";
		}
		else
		{
			document.getElementById("rowwhitebloodcells").style.display = "table-row";
		}
		
		sanswer.innerHTML = "Normal";
		
		if(finputvalue4 > 10)
		{
			sanswer.innerHTML = "Your leukocyte count is above the normal range. In extreme cases this could be the result of leukaemia or lymphoma.";
		}
		else if(finputvalue4 < 4)
		{
			sanswer.innerHTML = "Your leukocyte count is below the normal range. In extreme cases this called be due to neutropenia.";
		}
		else
		{sanswer.innerHTML = "Normal";}
		
		if(finputvalue4 == 0){sanswer.innerHTML = "No data";}
	}
	
		
	var finputvalue5 = 0;
	sanswer = document.getElementById("ansplatelets");
	finputvalue5 = parseFloat(document.getElementById("txtplatelets").value);
	if(isNaN(finputvalue5))
	{finputvalue5 = 0;}
	else
	{
		if (navigator.appName == "Microsoft Internet Explorer")
		{
			document.getElementById("rowplatelets").style.display = "block";
		}
		else
		{
			document.getElementById("rowplatelets").style.display = "table-row";
		}
		
		sanswer.innerHTML = "Normal";
		
		if(finputvalue5 > 7.5)
		{
			sanswer.innerHTML = "Your haemoglobin level is above the normal range. This could be indicative of a condition called thrombocytosis.";
		}
		else if(finputvalue5 < 2)
		{
			sanswer.innerHTML = "Your haemoglobin level is below the normal range. This could be indicative of a condition called thrombocytopenia.";
		}
		else
		{sanswer.innerHTML = "Normal";}
		
		if(finputvalue5 == 0){sanswer.innerHTML = "No data";}
	}
	
		
	var finputvalue6 = 0;
	sanswer = document.getElementById("anslymphocytes");
	finputvalue6 = parseFloat(document.getElementById("txtlymphocytes").value);
	if(isNaN(finputvalue6))
	{finputvalue6 = 0;}
	else
	{
		if (navigator.appName == "Microsoft Internet Explorer")
		{
			document.getElementById("rowlymphocytes").style.display = "block";
		}
		else
		{
			document.getElementById("rowlymphocytes").style.display = "table-row";
		}
		
		sanswer.innerHTML = "Normal";
		
		if(finputvalue6 > 400)
		{
			sanswer.innerHTML = "Your lymphocyte count is above the normal range. In extreme cases this could be the result of leukaemia or lymphoma.";
		}
		else if(finputvalue6 < 150)
		{
			sanswer.innerHTML = "Your lymphocyte count is below the normal range. In extreme cases this could result in infection.";
		}
		else
		{sanswer.innerHTML = "Normal";}
		
		if(finputvalue6 == 0){sanswer.innerHTML = "No data";}
	}
	
	
	var finputvalue7 = 0;
	sanswer = document.getElementById("ansmonocytes");
	finputvalue7 = parseFloat(document.getElementById("txtmonocytes").value);
	if(isNaN(finputvalue7))
	{finputvalue7 = 0;}
	else
	{
		if (navigator.appName == "Microsoft Internet Explorer")
		{
			document.getElementById("rowmonocytes").style.display = "block";
		}
		else
		{
			document.getElementById("rowmonocytes").style.display = "table-row";
		}
		
		sanswer.innerHTML = "Normal";
		
		if(finputvalue7 > 1.0)
		{
			sanswer.innerHTML = "Your monocyte count is above the normal range. In extreme cases this could be the result of leukaemia or lymphoma.";
		}
		else if(finputvalue7 < 0.2)
		{
			sanswer.innerHTML = "Your monocyte count is below the normal range. In extreme cases this could result in infection.";
		}
		else
		{sanswer.innerHTML = "Normal";}
		
		if(finputvalue7 == 0){sanswer.innerHTML = "No data";}
	}
	
		
	var finputvalue8 = 0;
	sanswer = document.getElementById("anseosinophils");
	finputvalue8 = parseFloat(document.getElementById("txteosinophils").value);
	if(isNaN(finputvalue8))
	{finputvalue8 = 0;}
	else
	{
		if (navigator.appName == "Microsoft Internet Explorer")
		{
			document.getElementById("roweosinophils").style.display = "block";
		}
		else
		{
			document.getElementById("roweosinophils").style.display = "table-row";
		}
		
		sanswer.innerHTML = "Normal";
		
		if(finputvalue8 > 0.5)
		{
			sanswer.innerHTML = "Your eosinophil count is above the normal range. This could be indicative of a condition named eosinophillia.";
		}
		else if(finputvalue8 < 0.02)
		{
			sanswer.innerHTML = "Your eosinophil count is below the normal range. This could be indicative of a condition named eosinopenia.";
		}
		else
		{sanswer.innerHTML = "Normal";}
		
		if(finputvalue8 == 0){sanswer.innerHTML = "No data";}
	}
	
		
	var finputvalue9 = 0;
	sanswer = document.getElementById("ansneutrophils");
	finputvalue9 = parseFloat(document.getElementById("txtneutrophils").value);
	if(isNaN(finputvalue9))
	{finputvalue9 = 0;}
	else
	{
		if (navigator.appName == "Microsoft Internet Explorer")
		{
			document.getElementById("rowneutrophils").style.display = "block";
		}
		else
		{
			document.getElementById("rowneutrophils").style.display = "table-row";
		}
		
		sanswer.innerHTML = "Normal";
		
		if(finputvalue9 > 3.5)
		{
			sanswer.innerHTML = "Your neutrophil count is above the normal range. In extreme cases this could be the result of leukaemia or lymphoma.";
		}
		else if(finputvalue9 < 1)
		{
			sanswer.innerHTML = "Your neutrophil count is below the normal range. In extreme cases this called be due to neutropenia.";
		}
		else
		{sanswer.innerHTML = "Normal";}
		
		if(finputvalue9 == 0){sanswer.innerHTML = "No data";}
	}

	// record results
	window.open("RecordCalcResults.asp?ans=bloodcountjuly2008&ans=" + bpreg + "&ans=" + bathletic + "&ans=" + finputvalue1 + "&ans=" + finputvalue2 + "&ans=" + finputvalue3 + "&ans=" + finputvalue4 + "&ans=" + finputvalue5 + "&ans=" + finputvalue6 + "&ans=" + finputvalue7 + "&ans=" + finputvalue8 + "&ans=" + finputvalue9, "", "width=50,height=50");

}

// calculate the expected due date
function pregduedate()
{
	var re = new RegExp;
	re = '^[0-3][0-9]-[0-1][0-9]-[1-2][0-9][0-9][0-9]$';

	if (document.getElementById("pregstartdate").value.match(re))
	{
		var dateArray = document.getElementById("pregstartdate").value.split("-");
	
		var nextDate = new Date(dateArray[2],dateArray[1] - 1,dateArray[0]);

		nextDate.setDate(nextDate.getDate() + 280);
		
		document.getElementById("edd").value = nextDate.getDate() + "-" + (nextDate.getMonth() + 1) + "-" + nextDate.getFullYear()
				
		var arrCurrent, arrNext;
		var strCurrent, strNext;
		var dateTemp;
		
		arrCurrent = document.getElementById("pregstartdate").value.split("-");
		arrNext = document.getElementById("edd").value.split("-");
		
		dateTemp = new Date(arrCurrent[2],arrCurrent[1] - 1,arrCurrent[0]);
		strCurrent = dateTemp.getFullYear() + "-" + (dateTemp.getMonth() + 1) + "-" + dateTemp.getDate();
		
		dateTemp = new Date(arrNext[2],arrNext[1] - 1,arrNext[0]);
		strNext = dateTemp.getFullYear() + "-" + (dateTemp.getMonth() + 1) + "-" + dateTemp.getDate();

		
		//window.open("RecordCalcResults.asp?ans=pregnancy&ans=" + document.getElementById("pregstartdate").value + "&ans=" + document.getElementById("edd").value, "", "width=500,height=500");
		window.open("RecordCalcResults.asp?ans=pregnancy&ans=" + strCurrent + "&ans=" + strNext, "", "width=50,height=50");
	}
	else
	{
		alert('Please enter a date in the format of "dd-mm-yyyy". eg 27-03-2007');
	}
}

// get the pregnancy start date
function calculateduedate()
{
	popUpCalendar(document.getElementById("preglastmen"), document.getElementById("pregstartdate"), "dd-mm-yyyy");
}

// clear the pregnancy form
function clearpregform()
{
	document.getElementById("edd").value = "";	
	document.getElementById("pregstartdate").value = "";		
}

// calculate the next menstruation date
function nextmen()
{
	var re = new RegExp;
	re = '^[0-3][0-9]-[0-1][0-9]-[1-2][0-9][0-9][0-9]$';

	if (document.getElementById("menidate").value.match(re))
	{
		var dateArray = document.getElementById("menidate").value.split("-");
		
		var nextDate = new Date(dateArray[2],dateArray[1] - 1,dateArray[0]);
	
		nextDate.setDate(nextDate.getDate() + 28);
		
		document.getElementById("meni").value = nextDate.getDate() + "-" + (nextDate.getMonth() + 1) + "-" + nextDate.getFullYear()
		
		var arrCurrent, arrNext;
		var strCurrent, strNext;
		var dateTemp;
		
		arrCurrent = document.getElementById("menidate").value.split("-");
		arrNext = document.getElementById("meni").value.split("-");
		
		dateTemp = new Date(arrCurrent[2],arrCurrent[1] - 1,arrCurrent[0]);
		strCurrent = dateTemp.getFullYear() + "-" + (dateTemp.getMonth() + 1) + "-" + dateTemp.getDate();
		
		dateTemp = new Date(arrNext[2],arrNext[1] - 1,arrNext[0]);
		strNext = dateTemp.getFullYear() + "-" + (dateTemp.getMonth() + 1) + "-" + dateTemp.getDate();
		
		//window.open("RecordCalcResults.asp?ans=menstruation&ans=" + document.getElementById("menidate").value + "&ans=" + document.getElementById("meni").value, "", "width=500,height=500");
		window.open("RecordCalcResults.asp?ans=menstruation&ans=" + strCurrent + "&ans=" + strNext, "", "width=50,height=50");
	
	}
	else
	{
		alert('Please enter a date in the format of "dd-mm-yyyy". eg 27-03-2007');
	}
}

// get the last menstruation date
function calculatemen()
{
	popUpCalendar(document.getElementById("submen"), document.getElementById("menidate"), "dd-mm-yyyy");
}

// clear the two text boxes
function clearmeniform()
{
	document.getElementById("menidate").value = "";	
	document.getElementById("meni").value = "";		
}

function calculategfr()
{
	// Creatinine clearance = [140 – age (years)] x Lean Body Weight (kg) x 1.23 (if male)
    //     (GFR)                   -----------------------------------------------------------------------
    // (mls / min)                                      Serum creatinine (umol/L)

	var iage, fweight, ssex, fserum, fgfr;

	iage = document.getElementById("gfrage");
	
	fweight = document.getElementById("gfrweight");
	
	ssex = document.getElementById("gfrsex");
	
	fserum = document.getElementById("gfrserum");
	
	gfr = document.getElementById("gfrgfr");

	if (iage.value)
	{
		if (isNaN(iage.value))
		{
			alert("Please enter your age in years.");
			iage.focus();
		}
		else
		{
			if (fweight.value)
			{
				if(isNaN(fweight.value))
				{
					alert("Please enter your weight in kilograms (kg).");
					fweight.focus();
				}
				else
				{
					if (document.frmgfr.gfrsex[0].checked || document.frmgfr.gfrsex[1].checked)
					{
						if (fserum.value)
						{
							if(isNaN(fserum.value))
							{
								alert("Please enter your serum creatinine (umol/L).");
								fserum.focus;
							}
							else
							{
								var patientgfr;
								if(document.frmgfr.gfrsex[0].checked)
								{
									
									patientgfr = format ( ((140 - iage.value) * fweight.value * 1.23)/fserum.value , 4) + " mls/min";
									
									gfr.value = patientgfr;
									
									window.open("RecordCalcResults.asp?ans=gfr&ans=" + iage.value + "&ans=" + fweight.value + "&ans=" + fserum.value + "&ans=male&ans=" + patientgfr, "", "width=50,height=50");
								}
								else
								{
									patientgfr = format ( ((140 - iage.value) * fweight.value)/fserum.value, 4) + " mls/min";
									
									gfr.value = patientgfr;
									
									window.open("RecordCalcResults.asp?ans=gfr&ans=" + iage.value + "&ans=" + fweight.value + "&ans=" + fserum.value + "&ans=female&ans=" + patientgfr, "", "width=50,height=50");
								}
							}
						}
						else
						{
							alert("Please enter your serum creatinine (umol/L).");
							fserum.focus;
						}
					}
					else
					{
						alert("Please choose your sex.");
						ssex.focus();
					}
				}
			}
			else
			{
				alert("Please enter your weight in kilograms (kg).");
				fweight.focus();
			}
		}
	}
	else
	{
		alert("Please enter your age in years..");
		iage.focus();
	}
	
	return false;
}

function calculatehom() 
{ 
	//If they say yes to 2 or 3 out of 3 then reply is:
	//You may be experiencing migraines, you should print this page and make an appointment with your doctor to discuss your symptoms.
	
	//If yes to 1 of 3 then reply is:
	//Take note of your symptoms and speak to your doctor about them at your next consult if you are concerned.
	
	//If no to all 3 then:
	//It is most likely you are experiencing headaches, but if you have any concerns please go speak to your doctor.


	var hom;
	var q1;
	var q2;
	var q3;
	var itotal;
	itotal = 0;
	q1 = 0;
	q2 = 0;
	q3 = 0;
	
	hom = document.getElementById("frmhom");
	
	if (hom.hom1[1].checked)
	{
		itotal = itotal + 1;
		q1 = 1;
	}
	
	if (hom.hom2[1].checked)
	{
		itotal = itotal + 1;
		q2 = 1;
	}

	if (hom.hom3[1].checked)
	{
		itotal = itotal + 1;
		q3 = 1;
	}

	if (itotal == 0 )
	{
		document.getElementById("sshow0").style.display = "block";
		document.getElementById("sshow1").style.display = "none";
		document.getElementById("sshow2").style.display = "none";
	}
	else if(itotal == 1)
	{
		document.getElementById("sshow0").style.display = "none";
		document.getElementById("sshow1").style.display = "block";
		document.getElementById("sshow2").style.display = "none";
	}
	else
	{
		document.getElementById("sshow0").style.display = "none";
		document.getElementById("sshow1").style.display = "none";
		document.getElementById("sshow2").style.display = "block";
	}


	window.open("RecordCalcResults.asp?ans=hom&ans=" + q1 + "&ans=" + q2 + "&ans=" + q3 + "&ans=" + itotal, "", "width=50,height=50");
	
	return false;
} 


function format (expr, decplaces)
{
	var str = "" + Math.round (eval(expr) * Math.pow(10, decplaces))
	
	while(str.length <= decplaces)
	{
		str = "0" + str
	}
	
	var decpoint = str.length - decplaces
	
	return str.substring(0, decpoint) + "." + str.substring(decpoint, str.length);
	
	//return str.substring(0, decpoint);
}

function findcheckedvalue(frm1)
{
	var ansnum;
			
	for (var i = 0; i < frm1.length; i++)
	{
		if(frm1[i].checked)
		{
			ansnum = frm1[i].value;
		}
	}
	return ansnum;			
}

function findchecked(frm1)
{
	var ansnum;
	var i;

	for (i = 0; i < frm1.length; i++)
	{
		if(frm1[i].checked)
		{
			ansnum = i+1;
		}
	}
	return ansnum;
}
