/* Define globals */ var active_algorithm; var score_algorithm; var simd; var xmlhttp; var lockedMeans = new Array(); var non_optimum_values = new Array(); /* Init the calculator */ function initCalc() { /* Fetch active algorithm */ score_algorithm = document.getElementById('algorithm').value; switchAlgorithm(score_algorithm); /* Toggle notes off */ var allPageTags = new Array(); var allPageTags=document.getElementsByTagName("P"); for (i=0; i0 && (input.value < 0.3 || input.value > 90)) { message="In order to return a score the SIMD entered should be between 0.3 and 90."; error = true; } else if(input.value.length>0 && isNaN(parseInt(input.value))) { message="In order to return a score the SIMD entered should contain only numerical data."; error = true; } else if(input.value.length>0) { if(evnt=="updateSIMD") { getScores(document.getElementById('calculator'),"updateSIMD"); } } } else { if(document.getElementById("simd_manual")) { var temp_simd = document.getElementById("simd_manual").value; } else { temp_simd = ""; } if(evnt=="updateSIMD" && (temp_simd.length<=0 || ((temp_simd > 0.3 && temp_simd < 90) && !isNaN(parseInt(temp_simd))))) { getScores(document.getElementById('calculator'),"updateSIMD"); } } } /* check ranges */ if(ranges[input.name]) { if(input.value < ranges[input.name][0] || input.value > ranges[input.name][1]) { if(ranges[input.name][2]=="Current age") ranges[input.name][2] = "age"; message="In order to return a score the "+ranges[input.name][2]+" entered should be between "+ranges[input.name][0]+" and "+ranges[input.name][1]+"."; error = true; } } /* check notices */ if(notices[input.name]) { if(!message && (input.value < notices[input.name][0] || input.value > notices[input.name][1])) { message="Outside the usual range of "+notices[input.name][0]+"-"+notices[input.name][1]+" for "+notices[input.name][2]+"."; non_optimum_values[non_optimum_values.length] = input.name; } else { /* splice the value out, if it's there */ for(f=0;f0) { nextCall[nextCall.length+1] = "showNotice('"+input.name+"','"+message+"')"; if(input.name=="simd") { nextCall[nextCall.length+1] = 'clearNotice("postcode")'; } } else { nextCall[nextCall.length+1]= "clearNotice('"+input.name+"')"; }; setTimeout("parseValidation()",400); if(error) { return message; } } function parseValidation() { for(i=0;i=means_ranges[i][0] && age<=means_ranges[i][1]) { means_array = means_ranges[i]; } } /* set the mean value, depending on gender */ if(sex=="m" && means_array.length>0) { document.getElementById(question).getElementsByTagName('input')[0].value=means_array[2]; nextCall[nextCall.length+1] = 'clearNotice("'+question+'")'; } else if(sex=="f" && means_array.length>0) { document.getElementById(question).getElementsByTagName('input')[0].value=means_array[3]; nextCall[nextCall.length+1] = 'clearNotice("'+question+'")'; } else { nextCall[nextCall.length+1] = 'showNotice("'+question+'","A mean value can not be calculated for the age and sex entered.")'; document.getElementById(question).getElementsByTagName('input')[0].value=""; } setTimeout("parseValidation()",300); var found = false; for(f=0;f"; } } /* Update the UI with results */ function updateUI() { if (xmlhttp.readyState==1) { if(document.getElementById('ajax_loading')) document.getElementById('ajax_loading').parentNode.removeChild(document.getElementById('ajax_loading')); var spinner = document.createElement('span'); spinner.id = "ajax_loading"; document.getElementById('results').appendChild(spinner); document.getElementById('calc_submit').style.color="#666666"; document.getElementById('calc_submit').disabled="true"; } if (xmlhttp.readyState==4) { /* Update SIMD */ var manual_simd = xmlhttp.responseXML.getElementsByTagName("MANUAL")[0].firstChild.nodeValue; var manual_simd_score = xmlhttp.responseXML.getElementsByTagName("SIMD")[0].firstChild.nodeValue; var default_simd = xmlhttp.responseXML.getElementsByTagName("DEFAULT")[0].firstChild.nodeValue; if(manual_simd == "true") { var message = "A SIMD score of "+manual_simd_score+" has been used. Clear the SIMD field, above, if you wish to amend the Postcode and calculate a new SIMD."; if(message) { nextSIMD = "showNotice('simd','"+message+"'); clearNotice('postcode')"; } else { nextSIMD = "clearNotice('"+input.name+"')"; }; /* Google analytics */ if(document.getElementById('calc_submit').value=="Calculate") { if(pageTracker) { pageTracker._trackPageview("/calculator/assignvisitor/calculate/"); } } else { if(pageTracker) { pageTracker._trackPageview("/calculator/assignvisitor/recalculate/"); } } } else { var message = xmlhttp.responseXML.getElementsByTagName("NOTICE")[0].firstChild.nodeValue; if(document.getElementById("simd_manual")) { if(default_simd == "false") { document.getElementById("simd_manual").value=manual_simd_score; } } if(message) { nextSIMD = "showNotice('postcode','"+message+"'); clearNotice('simd')"; } else { nextSIMD = "clearNotice('"+input.name+"')"; }; /* Google analytics */ if(document.getElementById('calc_submit').value=="Calculate") { if(pageTracker) { pageTracker._trackPageview("/calculator/nhs/calculate/"); } } else { if(pageTracker) { pageTracker._trackPageview("/calculator/nhs/recalculate/"); } } } /* Update UI */ var resultsBlock = document.getElementById('results'); active_algorithm = xmlhttp.responseXML.getElementsByTagName("ALGORITHM")[0].firstChild.nodeValue; var score_assign = xmlhttp.responseXML.getElementsByTagName("ASSIGN")[0].firstChild.nodeValue; var score_framingham = xmlhttp.responseXML.getElementsByTagName("FRAMINGHAM")[0].firstChild.nodeValue; resultsBlock.innerHTML=null; if(lockedMeans.length > 0 || non_optimum_values.length > 0 || default_simd == "true") { var denote = "*"; } else { var denote = ""; } if(active_algorithm == "assign") { /* Update heart */ document.getElementById('heart_score').style.background="url('includes/php/dynamic_heart.php?score="+score_assign+"') 18px 7px no-repeat"; document.getElementById('heart_score').innerHTML = 'ASSIGN score is '+score_assign+''; document.getElementById('final').innerHTML=score_assign; resultsBlock.innerHTML="

ASSIGN Score: "+score_assign+""+denote+"

"; if(score_assign>=20) { resultsBlock.innerHTML+="

ASSIGN 20 or more is high risk, implying specific medical preventive actions. No need to repeat the scoring on another occasion.

"; } else { resultsBlock.innerHTML+="

ASSIGN score below 20 is not currently high risk, implying general preventive measures (nobody is free of risk) Repeat the scoring in 5 years or earlier, depending how high the current score is.

"; } var score_notes = document.createElement('p'); score_notes.id = "score_info"; var score_notes_link = document.createElement('a'); score_notes_link.id = "score_info_toggle"; score_notes_link.setAttribute("onclick","sigh(); return false;"); score_notes_link.setAttribute("href","about/beginners/"); score_notes_link.innerHTML="notes"; score_notes.appendChild(score_notes_link); document.getElementById('results').appendChild(score_notes); resultsBlock.innerHTML+="

The ASSIGN number is the risk percent of cardiovascular disease over ten years, based on the recent SHHEC study. ASSIGN 20 means 20% risk. The actual risk is probably now less than that number. What matters more is what somebody's score is in relation to other ASSIGN scores, and therefore their priority or ranking for action to lower their risk.

"; if(lockedMeans.length > 0 || default_simd == "true") resultsBlock.innerHTML+="

* In the absence of specific data for one or more variables mean population values have been used to calculate a provisional ASSIGN score. For a more specific score enter personal values for all variables, if you can, and recalculate.

"; if(non_optimum_values.length > 0) { resultsBlock.innerHTML+="

* One or more values entered are outside the usual range for which the ASSIGN score was designed. Extreme values involve extrapolation so the score is tentative. Check your data entry first. Interpret such results with care.

"; } } else if(active_algorithm == "framingham") { /* Update heart */ document.getElementById('heart_score').style.background="url('includes/php/dynamic_heart.php?score="+score_framingham+"') 18px 7px no-repeat"; document.getElementById('heart_score').innerHTML = 'Framingham score is '+score_framingham+''; document.getElementById('final').innerHTML=score_framingham; document.getElementById('bannerheart').style.backgroundImage="url(images/calculate-banner-framingham.png)"; resultsBlock.innerHTML="

Framingham Score: "+score_framingham+""+denote+"

"; resultsBlock.innerHTML+="

Based on the personal details entered above, Framingham estimates a "+score_framingham+"% chance of cardiovascular disease developing in the next 10 years.

"; if(lockedMeans.length > 0 || default_simd == "true") resultsBlock.innerHTML+="

* In the absence of specific data for one or more variables mean population values have been used to calculate a provisional Framingham score. For a more specific score enter personal values for all variables, if you can, and recalculate.

"; if(non_optimum_values.length > 0) { resultsBlock.innerHTML+="

* One or more values entered are outside the usual range for which the ASSIGN score was designed. Extreme values involve extrapolation so the score is tentative. Check your data entry first. Interpret such results with care.

"; } } resultsBlock.innerHTML+=""; non_optimum_values = new Array(); parseValidation(); } } function sigh(){ if(document.getElementById('score_notes_block').style.display=="block") { document.getElementById('score_notes_block').style.display="none"; } else { document.getElementById('score_notes_block').style.display="block"; } } function updateSIMD() { if (xmlhttp.readyState==1) { /*display loading*/ } if (xmlhttp.readyState==4) { /* Update SIMD */ simd = xmlhttp.responseXML.getElementsByTagName("SIMD")[0].firstChild.nodeValue; var manual_simd = xmlhttp.responseXML.getElementsByTagName("MANUAL")[0].firstChild.nodeValue; if(manual_simd == "true") { var message = "A SIMD score of "+simd+" has been used. Clear the SIMD field, above, if you wish to amend the Postcode and calculate a new SIMD."; if(message) { nextSIMD = "showNotice('simd','"+message+"'); clearNotice('postcode')"; } else { nextSIMD = "clearNotice('"+input.name+"')"; }; } else { var message = xmlhttp.responseXML.getElementsByTagName("NOTICE")[0].firstChild.nodeValue; if(document.getElementById("simd_manual")) { document.getElementById("simd_manual").value=simd; nextCall[nextCall.length+1] = 'showNotice("simd","Clear the SIMD field, above, if you wish to amend the Postcode and calculate a new SIMD.")'; } if(message) { if(nextCall.length>0) { nextSIMD = "showNotice('postcode','"+message+"');"; } else { nextSIMD = "showNotice('postcode','"+message+"'); clearNotice('simd')"; } } else { nextSIMD = "clearNotice('"+input.name+"')"; } } setTimeout("parseValidation()",400); } }