function setFieldAmount(field,val) { var obj = findCurrentObj("entry_form",field); if (obj) { // val= "$" + addCommas(val); // dollar way val= addCommas(val); //val= val.replace(/,/g," ") ; // for European format val= " " + val; //val= val.replace(".",","); // change decimal back now for European format obj.innerHTML= val; } } 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; } var dHash = {}; function myDebug(key, value) { if (!dHash[key]) { alert(value); } dHash[key]="1"; } function riskColor(prob,impact,risk) { if (risk>12) { return "red"; } else if (risk>=4 && !(prob==2 && impact==2)) { return "yellow"; } else { return "darkgreen"; } } // set the impact var impactFields = [ "18", "19", "20", "21", "22", "23" ]; var impactNames = [ "Confidentiality", "Integrity", "Availability", "Authenticity", "Utility", "Control" ]; var impactValues = [ "Very Low", "Low", "Moderate", "High", "Very High" ]; var probValue = [ 10, 30, 50, 70, 90 ]; var impactValue = [ 0.05, 0.1, 0.2, 0.4, 0.8 ]; function scoreFunction () { if (document.entry_form) { var prob = "" + findCurrentObj("entry_form","field5").value; if ( prob<0) { prob = 0; } var impactOps = {}; var impact = 0; for (var i=0; i<impactFields.length; i++) { var obj = findCurrentObj("entry_form","field"+impactFields[i]); var val = 0; if (obj) { // in case hidden val = "" + obj.value; impactOps=obj.options; } if (val>0) { if (val>impact) impact = val; } } jQuery("#field6").html(impactOps[impact].text+" "); // impact severity var riskValue= probValue[prob-1]/10 * impactValue[impact-1]; var color=riskColor(prob,impact,prob*impact); if ( riskValue>0) { var riskObj = findCurrentObj("entry_form","field10"); riskObj.value = riskValue; riskObj.innerHTML = riskObj.value; riskObj.style.backgroundColor=color; } } setTimeout("scoreFunction()",500); } // start recursive function call to run javascript on page scoreFunction();