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= "\u20AC " + 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 = [ "49", "43", "44", "45", "48", "47" ]; var impactNames = [ "Cost", "Governance", "Image", "Legal", "Schedule", "Technical" ]; var impactValues = [ "Low", "Moderate", "Significant", "Damaging", "Catastrophic" ]; var probAlpha= [ "", "A", "B", "C", "D", "E" ]; var probRange = [ "<10%", "10-30%", "30-50%", "50-70%", ">70%" ]; var probValue = [ 10, 30, 50, 70, 90 ]; function scoreFunction () { if (document.entry_form) { var probObj = findCurrentObj("entry_form","field3"); var impactObj = findCurrentObj("entry_form","field4"); var riskObj = findCurrentObj("entry_form","field5"); if (document.entry_form.cloneBugFlag) { // default back to "" probObj.innerHTML=""; impactObj.innerHTML=""; riskObj.innerHTML=""; } var prob = "" + findCurrentObj("entry_form","field1").value; if ( prob>0) { probObj.value = prob; probObj.innerHTML = probObj.value; } else { prob = 0; } var impact = 0; var domain = ""; for (var i=0; i<impactFields.length; i++) { var val = "" + findCurrentObj("entry_form","field"+impactFields[i]).value; if (val>0) { if (domain.length>0) domain += ","; domain += impactNames[i].substring(0,1); if (val>impact) impact = val; } } var impactOps= document.getElementById("field"+impactFields[0]).options; jQuery("#field2").html(impactOps[impact].text+" "); // impact severity jQuery("#field20").html(domain); // domain jQuery("#field40").html(probValue[prob-1]+"%"); //probability range var minDelay = parseFloat(findCurrentValue("entry_form","field25","0")); var maxDelay = parseFloat(findCurrentValue("entry_form","field27","0")); var likelyDelay = parseFloat(findCurrentValue("entry_form","field29","0")); var expectedDelay = (minDelay + (likelyDelay*4) + maxDelay) /6; jQuery("#field34").html(Math.round(expectedDelay)); var minCost = findCurrentValue("entry_form","field24","0"); minCost = minCost.replace(/[^\.0-9]/g,""); // strip to number with decimal or $ minCost = parseFloat(minCost); var maxCost = findCurrentValue("entry_form","field26","0"); maxCost = maxCost.replace(/[^\.0-9]/g,""); // strip to number with decimal or $ maxCost = parseFloat(maxCost); var likelyCost= findCurrentValue("entry_form","field28","0"); likelyCost= likelyCost.replace(/[^\.0-9]/g,""); // strip to number with decimal or $ likelyCost= parseFloat(likelyCost); var costImpact = (minCost + (likelyCost*4) + maxCost) /6; setFieldAmount("field32",Math.round(costImpact)); var emv = costImpact * (probValue[prob-1]/100); setFieldAmount("field9",Math.round(emv)); // expected Monetary value = cost impact * probability var index = impact + probAlpha[prob]; jQuery("#field18").html(index+" "); //Index //var impact = "" + findCurrentObj("entry_form","field2").value; if ( impact>0) { impactObj.value = impact; impactObj.innerHTML = impactObj.value; } var risk=prob * impact; var color=riskColor(prob,impact,risk); if ( risk>0) { riskObj.value = risk; riskObj.innerHTML = riskObj.value; riskObj.style.backgroundColor=color; } } setTimeout("scoreFunction()",500); } // start recursive function call to run javascript on page scoreFunction(); //limit amount of text that can be entered var limitFields = ["mSubject"] for (i=0;i<limitFields.length;i++) { var field = eval("document.entry_form."+limitFields[i]); limitField(limitFields[i], 50); } function limitField(limitFieldName, limitNum) { var field = eval("document.entry_form."+limitFieldName); var origOnKeyUp = field.onkeyup; field.onkeyup = function() { if (origOnKeyUp) { resizeTA(field); } limitText(field,limitNum); } } function limitText(limitField, limitNum) { if (limitField.value.length > limitNum) { limitField.value = limitField.value.substring(0, limitNum); } }