
var f10yrprob = new Array();
f10yrprob[1] = 1.1;
f10yrprob[2] = 1.3;
f10yrprob[3] = 1.6;
f10yrprob[4] = 2.0;
f10yrprob[5] = 2.4;
f10yrprob[6] = 2.9;
f10yrprob[7] = 3.5;
f10yrprob[8] = 4.3;
f10yrprob[9] = 5.2;
f10yrprob[10] = 6.3;
f10yrprob[11] = 7.6;
f10yrprob[12] = 9.2;
f10yrprob[13] = 11.1;
f10yrprob[14] = 13.3;
f10yrprob[15] = 16.0;
f10yrprob[16] = 19.1;
f10yrprob[17] = 22.8;
f10yrprob[18] = 27.0;
f10yrprob[19] = 31.9;
f10yrprob[20] = 37.3;
f10yrprob[21] = 43.4;
f10yrprob[22] = 20.0;
f10yrprob[23] = 57.0;
f10yrprob[24] = 64.2;
f10yrprob[25] = 71.4;
f10yrprob[26] = 78.2;
f10yrprob[27] = 84.4;

var m10yrprob = new Array();
m10yrprob[1] = 2.6;
m10yrprob[2] = 3.0;
m10yrprob[3] = 3.5;
m10yrprob[4] = 4.0;
m10yrprob[5] = 4.7;
m10yrprob[6] = 5.4;
m10yrprob[7] = 6.3;
m10yrprob[8] = 7.3;
m10yrprob[9] = 8.4;
m10yrprob[10] = 9.7;
m10yrprob[11] = 11.2;
m10yrprob[12] = 12.9;
m10yrprob[13] = 14.8;
m10yrprob[14] = 17.0;
m10yrprob[15] = 19.5;
m10yrprob[16] = 22.4;
m10yrprob[17] = 25.5;
m10yrprob[18] = 29.0;
m10yrprob[19] = 32.9;
m10yrprob[20] = 37.1;
m10yrprob[21] = 41.7;
m10yrprob[22] = 46.6;
m10yrprob[23] = 51.8;
m10yrprob[24] = 57.3;
m10yrprob[25] = 62.8;
m10yrprob[26] = 68.4;
m10yrprob[27] = 73.8;
m10yrprob[28] = 79.0;
m10yrprob[29] = 83.7;
m10yrprob[30] = 87.9;


 
var step = new Array(7);
step[-1] = 'question';
step[0] = 'sex';
step[1] = 'age';
step[2] = 'sbp';
step[3] = 'hyprx';
step[4] = 'diabetes';
step[5] = 'cigs';
step[6] = 'cvd';
step[7] = 'af';
step[8] = 'lvh';
step[9] = 'calculate';
step[10] = 'results';


var score = new Array();
for(i=0;i<=8;i++) {
	score[step[i]]='i';
}

function itdover (jvar) {
	jvar.background = '#999999';
	jvar.color = '#FFFFFF';
	jvar.padding = '3px';
}

function itdout (jvar) {
	jvar.background = '#FFFF99';
	jvar.color = '#000000';
	jvar.padding = '3px';
}


function calculate() {
	document.getElementById('calculate').style.display='block';
	for(i=0;i<=4;i++) {
		document.getElementById('calculate').innerHTML = '<div align=\"left\" style="width:100%;padding-left:15px;align:left">Calculating<br /> Stroke Risk</div>';
		setTimeout("document.getElementById('calculate').innerHTML = '<div align=\"left\" style=\"width:100%;padding-left:15px;align:left\">Calculating<br /> Stroke Risk.</div>';",i*1111);
		setTimeout("document.getElementById('calculate').innerHTML = '<div align=\"left\" style=\"width:100%;padding-left:15px;align:left\">Calculating<br /> Stroke Risk..</div>';",i*1222);
		setTimeout("document.getElementById('calculate').innerHTML = '<div align=\"left\" style=\"width:100%;padding-left:15px;align:left\">Calculating<br /> Stroke Risk...</div>';",i*1333);
		setTimeout("document.getElementById('calculate').innerHTML = '<div align=\"left\" style=\"width:100%;padding-left:15px;align:left\">Calculating<br /> Stroke Risk....</div>';",i*1444);
		if(i==4) 	setTimeout('hidedivs(9)',9000);
	}
}

function results () {
	document.getElementById('calculate').style.display='none';
	document.getElementById('results').style.display='block';
	document.getElementById('results').innerHTML = 'Results....';
	var result = 0
	for(i=1;i<=8;i++) {
		result += score[step[i]]
	}
	var risk
	var text
	var outof
	var avgrisk
	
	if(score['sex'] == "F") {
		outof = 27;
		if(result > 27) risk = 'Greater Than 84.4';
		else risk = f10yrprob[result];
	
		if(score['age'] == 0 || score['age'] == 1 ) avgrisk = 3.0;
		else if(score['age'] == 2) avgrisk = 4.7;
		else if(score['age'] == 3 || score['age'] == 4) avgrisk = 7.2;
		else if(score['age'] == 5 || score['age'] == 6) avgrisk = 10.9;
		else if(score['age'] == 7 || score['age'] == 8) avgrisk = 15.5;
		else if(score['age'] == 9 || score['age'] == 10) avgrisk = 23.9;
		
	} else {
		outof = 30;
		if(result > 30) risk = 'Greater Than 87.9';
		else risk = m10yrprob[result];

		if(score['age'] == 0 || score['age'] == 1 ) avgrisk = 5.9;
		else if(score['age'] == 2 || score['age'] == 3) avgrisk = 7.8;
		else if(score['age'] == 4) avgrisk = 11.0;
		else if(score['age'] == 5 || score['age'] == 6) avgrisk = 13.7;
		else if(score['age'] == 7 || score['age'] == 8) avgrisk = 18.0;
		else if(score['age'] == 9 || score['age'] == 10) avgrisk = 22.3;

	}
	
	
	text  = '<div class="r2" style="widht:100%;padding:3px;align:left"><b>Total Points: <font class="s4">' + result + '</font> out of ' + outof + '</b><br /><br />'
		+  'Your 10-Year Stroke Probability is <font class="s4">'+risk+'%</font><br /><br />'
		+  'Average 10-year Probability based on your age group is <font class="s4">'+ avgrisk +'%</font><br /><br />';
	
	if(risk < avgrisk) {
		text += 'Your Risk of Stroke is <b class="dg">lower</b> than the average person at your age.';
	} else if (risk < avgrisk) {
		text += 'Your Risk of Stroke is <b>equal to</b> that of an average person at your age.';
	} else {
		text += 'Your Risk of Stroke is <b class="dr s4">higher</b> than an average person at your age.</b></div>';
	}
	text += '<br /><br /><center><a href="javascript:void(window.location=\'/\')">Restart</a></center>';
	document.getElementById('results').innerHTML = text;
}


function trackscore(category,sc) {
	score[category]=sc;
}

function hidedivs(show) {
	
	if(show == -1) {
		document.getElementById('calculaterisk').style.height='350px';
		window.location="#calculaterisk";
	}
	
	for(i=-1;i<=8;i++) {
		if(i == (show+1)) display='block';
		else display='none';
		document.getElementById('question').style.display='none';
		document.getElementById('sbpf').style.display='none';
		document.getElementById('sbpm').style.display='none';
		document.getElementById(step[i]).style.display=display;
	}
	if((show+1) == 2) {
		if(score['sex'] == "F") {
			document.getElementById('sbpf').style.display='block';
		} else {
			document.getElementById('sbpm').style.display='block';
		}
	}
	
	if(show == 8) calculate();
	if(show == 9) results();
}
function strokescore(sp,value) {
	trackscore(step[sp],value);
	hidedivs(sp);
}

function strokescoregv(sp,value,impactf,impactm) {
	if(score['sex'] == "F" && value == 'Y') {
		score[step[sp]] = impactf; 	
	} else if(score['sex'] == "M" && value == 'Y') {
		score[step[sp]] = impactm; 
	} else if(value == 'N') {
		score[step[sp]] = 0; 
	}
	hidedivs(sp);
}


function strokescore3(sp,value) {
	if(score['sex'] == "F" && value == 'Y') {
		if(score['sbp'] == 10) score['hyprx'] = 0; 
		else if(score['sbp'] == 9) score['hyprx'] = 0; 
		else if(score['sbp'] == 8) score['hyprx'] = 1; 
		else if(score['sbp'] == 7) score['hyprx'] = 1; 
		else if(score['sbp'] == 6) score['hyprx'] = 2; 
		else if(score['sbp'] == 5) score['hyprx'] = 3; 
		else if(score['sbp'] == 4) score['hyprx'] = 3; 
		else if(score['sbp'] == 3) score['hyprx'] = 4; 
		else if(score['sbp'] == 2) score['hyprx'] = 5; 
		else if(score['sbp'] == 1) score['hyprx'] = 5; 
		else if(score['sbp'] == 0) score['hyprx'] = 6; 
	} else if(score['sex'] == "M" && value == 'Y') {
		score['hyprx'] = 2; 
	} else if(value == 'N') {
		score['hyprx'] = 0; 
	}
	hidedivs(sp);
}


