/** Form convenience Functions** &copy;Copyright Mike Brockington 2004 - 2011 All rights reserved.* Build Number:4:* This version, Copyright: 06/03/2010*/
function multiCalc(){this.calcCount=0;}/** Application specific settings*/
var appSettings={outputHidden:true,logLevel:"all",oddLogLine:true,firstRun:true};/** @function Make results area visible if not already*/
function checkResultsVisible(){if(appSettings.outputHidden){var strDivID="outputBlock";
toggleHiddenDiv2(strDivID);appSettings.outputHidden=false;}return true;}/** Delete a DOM element, such as the context menu block*  Function*  Nothing.*/
function removeElement(elementID){var target=document.getElementById(elementID);if(target){target.parentNode.removeChild(target);}else{logMsg("[200175] Target element ("+elementID+") not found.", params={level:"error"});}}
/** Create a menu block, adjacent to the DIV where the mouse was clicked*  Function*  Nothing.*/
function showContextMenu(callingObjectID, commandList){if(showOverlay){showOverlay();}thisCalculator.currentMenuRef=callingObjectID;if(document.getElementById("contextMenu") ){removeElement("contextMenu");}var target=document.getElementById(callingObjectID);
var baseDiv=document.createElement("div");baseDiv.className="contextMenu";baseDiv.id="contextMenu";if(commandList){var menuList=document.createElement("ul");var first=true;for(var i=0;i<commandList.length;i++){var menuItem=document.createElement("li");menuItem.className=commandList[i].icon+"Link";if(first){menuItem.className+=" first";
first=false;}var thisLink=document.createElement("a");thisLink.setAttribute("href", "#");thisLink.setAttribute("name", "menuItem"+i);thisLink.onclick=commandList[i].funcObj;thisLink.appendChild( document.createTextNode(commandList[i].caption));menuItem.appendChild( thisLink );menuList.appendChild( menuItem );}}var menuItem=document.createElement("li");
var closeLink=document.createElement("a");closeLink.setAttribute("href", "#");closeLink.setAttribute("name", "hrefClose");closeLink.onclick=close_menu_link;closeLink.appendChild( document.createTextNode("Close this menu"));menuItem.className="last";menuItem.appendChild( closeLink );menuList.appendChild( menuItem );
baseDiv.appendChild( menuList );target.appendChild(baseDiv);if(!document.all){baseDiv.style.top=target.offsetTop+"px";baseDiv.style.left=target.offsetLeft+target.offsetWidth+"px";}if(adjustOverlaySize){adjustOverlaySize();
}}/** Remove the context menu from view*  Function*  Nothing.*/
function close_menu_link(){hideOverlay();removeElement('contextMenu');return true;}/** Extends the Number prototype to give formatted output.*  String (Usually a) single character representing the currency in use.*  Function*  String: Formatted number, pre-fixed with given symbol.*/
Number.prototype.toCurrency=function(charCurrencySymbol){
if(charCurrencySymbol){}else{charCurrencySymbol="";}return charCurrencySymbol+this.toFixed(2).addSeperators();}/** Extends the String prototype to give formatted output.*  String (Usually a) single character representing the currency in use.*  Function*  String: Formatted number, pre-fixed with given symbol.*/
String.prototype.toCurrency=function(charCurrencySymbol)
{var fltValue=parseFloat(this);return fltValue.toCurrency(charCurrencySymbol);}/** Extends the Number prototype to give formatted output.* Uses String.prototype.addSeperators() to carry out formatting.*  String A single character to seperate each group of digits.*  Function*  String: Formatted number.*/
Number.prototype.addSeperators=function(charSeperator){if(charSeperator){return this.toString().addSeperators(charSeperator);}else{return this.toString().addSeperators();
}}/** Extends the String prototype to give formatted output.*  String A single character to seperate each group of digits.*  Function*  String: Formatted number.*/
String.prototype.addSeperators=function(charSeperator){if(charSeperator){}else{charSeperator=",";}if(this.indexOf(".") > -1){if((this.indexOf(".") < 4) || (this.length < 4)){
return this;}var numParts=null;if(this.indexOf(".") > -1){numParts=this.split(".");}else{numParts=[this, ""];}return addSeperator(numParts[0], charSeperator)+"."+numParts[1];}else{return addSeperator(this, charSeperator);}}/** Record a message to the on-screen console*  Function*  Nothing.*/
function logMsg(strMessage, objParams)
{var outArea=document.getElementById("divConsole");var CSSclassName="logEntry";if(objParams && objParams.CSSclassName && (objParams.CSSclassName !="")){CSSclassName=objParams.CSSclassName;}if(appSettings.oddLogLine){appSettings.oddLogLine=false;CSSclassName+=" evenLogLine";}else{appSettings.oddLogLine=true;CSSclassName+=" oddLogLine";
}if(appSettings.logLevel){var logEntry=document.createElement("p");logEntry.appendChild( document.createTextNode( strMessage ));logEntry.className=CSSclassName;outArea.appendChild(logEntry);}}/** Update the on-screen Progress Indicator*  Function*  Nothing.*/
function updateProgress(indicName, objParams){var thisProgress=document.getElementById(indicName);
var barMarker=document.getElementById(indicName).childNodes[1].firstChild;if(objParams && objParams.newValue && (isFinite(objParams.newValue) )){CR.progressBars[indicName].current=objParams.newValue;}else{CR.progressBars[indicName].current++;}if(objParams && objParams.maxValue && (isFinite(objParams.maxValue) )){CR.progressBars[indicName].max=objParams.maxValue;barMarker.style.backgroundColor="#006600";}if(CR.progressBars[indicName].current > CR.progressBars[indicName].max)
{CR.progressBars[indicName].max=CR.progressBars[indicName].max * 1.5;}var thisVal=(100 * CR.progressBars[indicName].current / CR.progressBars[indicName].max );barMarker.style.width=thisVal+"%";var strMessage="Completed "+CR.progressBars[indicName].current+" of "+CR.progressBars[indicName].max;thisProgress.removeChild(thisProgress.lastChild);thisProgress.appendChild( document.createTextNode( strMessage ));
}/** Update the on-screen Progress Indicator upon task completion*  Function*  Nothing.*/
function completeProgress(indicName, objParams){var thisProgress=document.getElementById(indicName);var barMarker=document.getElementById(indicName).childNodes[1].firstChild;barMarker.style.width="100%";barMarker.style.backgroundColor="#00cc00";var strMessage="Complete.";thisProgress.removeChild(thisProgress.lastChild);
thisProgress.appendChild( document.createTextNode( strMessage ));}/** Create an on-screen Progress Indicator*  Function*  Nothing.*/
function startProgress(indicName, objParams){logMsg("Task started at:"+appSettings.taskStartTime, params={level:"debug"});var thisProgress=document.getElementById(indicName);var CSSclassName="";if(objParams && objParams.CSSclassName && (objParams.CSSclassName !="")){CSSclassName=objParams.CSSclassName;}if(!CR.progressBars)
{CR.progressBars=new Object();}CR.progressBars[indicName]=new Object();if(objParams && objParams.minValue && (isFinite(objParams.minValue) )){CR.progressBars[indicName].min=objParams.minValue;}else{CR.progressBars[indicName].min=0;}if(objParams && objParams.maxValue && (isFinite(objParams.maxValue) )){CR.progressBars[indicName].max=objParams.maxValue;}else{CR.progressBars[indicName].max=100;}if(objParams && objParams.currentValue && (isFinite(objParams.currentValue) ))
{CR.progressBars[indicName].current=objParams.currentValue;}else{CR.progressBars[indicName].current=0;}var detailInfo=document.createElement("H3");detailInfo.setAttribute("class", "detailInfo");detailInfo.appendChild( document.createTextNode( "Task Progress" ));thisProgress.appendChild(detailInfo);var barWrapper=document.createElement("div");var barMarker=document.createElement("div");barWrapper.setAttribute("id", "barWrapper");
barWrapper.setAttribute("class", "barWrapper");barMarker.setAttribute("id", "barMarker");barMarker.setAttribute("class", "barMarker");barMarker.style.height="1em";barMarker.style.width="1%";barMarker.appendChild( document.createTextNode( "" ));barWrapper.appendChild( barMarker );thisProgress.appendChild(barWrapper);var strMessage="Progress Details";var detailInfo=document.createElement("p");detailInfo.setAttribute("class", "detailInfo");
detailInfo.appendChild( document.createTextNode( strMessage ));thisProgress.appendChild(detailInfo);}/** Format a DOM element and print to the results area*  Function*  Nothing.*/
function recordResultDOM(objDOMelement, objParams){var CSSclassName="resultEntry";if(objParams && objParams.CSSclassName && (objParams.CSSclassName !="")){CSSclassName=objParams.CSSclassName;}if(appSettings.oddResultsLine){appSettings.oddResultsLine=false;CSSclassName+=" evenResultsLine";
}else{appSettings.oddResultsLine=true;CSSclassName+=" oddResultsLine";}objDOMelement.className=CSSclassName;recordResults(objDOMelement);}/** Format and print to the results area*  Function*  Nothing.*/
function recordResultInline(strText){var outArea=document.getElementById("divResults");objDOMelement=document.createElement("span");objDOMelement.appendChild( document.createTextNode( strText ));objDOMelement.className="result";outArea.appendChild(objDOMelement);
outArea.appendChild( document.createTextNode( " " ));}/** Format and print to the results area*  Function*  Nothing.*/
function recordResultList(strText){var CSSclassName="";if(appSettings.oddResultsLine){appSettings.oddResultsLine=false;CSSclassName+="oddResultsLine";}else{appSettings.oddResultsLine=true;CSSclassName+="evenResultsLine";}CSSclassName+=" resultEntry";if(appSettings.firstRun){var outBlock=document.getElementById("divResults");
objDOMelement=document.createElement("ol");objDOMelement2=document.createElement("li");objDOMelement2.appendChild( document.createTextNode( strText ));objDOMelement2.className=CSSclassName;objDOMelement.setAttribute("id", "listResults");objDOMelement.appendChild(objDOMelement2);outBlock.appendChild(objDOMelement);appSettings.firstRun=false;}else{var outArea=document.getElementById("listResults");objDOMelement=document.createElement("li");
objDOMelement.appendChild( document.createTextNode( strText ));objDOMelement.className=CSSclassName;outArea.appendChild(objDOMelement);}}/** Record a plain text message to the results area, wrapped in paragraph tags*  Function*  Nothing.*/
function recordResultText(strMessage, objParams){var CSSclassName="resultEntry";var itemAction="";if(objParams && objParams.CSSclassName && (objParams.CSSclassName !="")){CSSclassName=objParams.CSSclassName;
}if(objParams && objParams.showActions ){if(CSSclassName.length > 0 ) {CSSclassName+=" ";}CSSclassName+="actionLink";itemAction=doActions;}if(CSSclassName.length > 0 ) {CSSclassName+=" ";}if(appSettings.oddResultsLine){appSettings.oddResultsLine=false;CSSclassName+="oddResultsLine";}else{appSettings.oddResultsLine=true;CSSclassName+="evenResultsLine";
}var thisEntry=document.createElement("p");if(objParams && objParams.labelText ){if(objParams.labelText.length > 0 ) {var thisLabel=document.createElement("span");thisLabel.appendChild( document.createTextNode( objParams.labelText ));thisEntry.appendChild( thisLabel );}}if(itemAction.length > 0 ) 
{addEvent(thisEntry, "click", itemAction);}thisEntry.appendChild( document.createTextNode( strMessage ));thisEntry.className=CSSclassName;if(objParams && objParams.elementID ){thisEntry.id=objParams.elementID;}else{thisEntry.id="resultLine";}recordResults(thisEntry);}/** Record a DOM element to the results area*  Function*  Nothing.*/
function recordResults(objDOMelement, objParams){var outArea=document.getElementById("divResults");
outArea.appendChild(objDOMelement);}/** Check if a variable contains a number that is useable by JavaScript*  Function*  Boolean.*/
function isValidNumber(strFieldName){if((strFieldName===null) || (strFieldName=="")){return false;}var tempString="txt"+strFieldName;var thisInput=document.getElementById(tempString);if(thisInput){if(thisInput.value){if(isFinite(thisInput.value) ){return true;
}}}return false;}/** Check if an HTML Select box has an item selected*  Function*  Boolean.*/
function isItemChosen(strFieldName){if((strFieldName===null) || (strFieldName=="")){return false;}var tempString="slct"+strFieldName;var thisSelect=document.getElementById(tempString);if(thisSelect){if(thisSelect.selectedIndex){var optionValue=thisSelect.options[thisSelect.selectedIndex].value;if((optionValue===null) || (optionValue=="") || (optionValue==0))
{return false;}return true;}}return false;}/** Get the Multiplier appropriate for the selected dimensional units*  Function*  Number*/
function getMultiplier(strFieldName){if((strFieldName===null) || (strFieldName=="")){return 1;}var tempString="slct"+strFieldName;var thisSelect=document.getElementById(tempString);if(thisSelect){return thisSelect.options[thisSelect.selectedIndex].value;
}else{return 1;}}/** Get fixed numeric value from select box or 'combo-box'*  Function*  Number, or FALSE.*/
function getConstant(strOriginalFieldName){var strFieldName=strOriginalFieldName;if(strFieldName.indexOf("slct") !=0){strFieldName="slct"+strFieldName;}var thisInput=document.getElementById(strFieldName);if(thisInput){if(thisInput.type.indexOf("select")==0) {if(thisInput.selectedIndex)
{var selectValue=thisInput.options[thisInput.selectedIndex].value;if(selectValue=="Other"){}else{return selectValue;}}}}if(strOriginalFieldName.indexOf("txt") !=0){strFieldName="txt"+strOriginalFieldName;}thisInput=document.getElementById(strFieldName);if(thisInput){if(thisInput.type=="text") 
{return thisInput.value;}}return false;}/** Get the 'name' of a dimensional unit, empty string if nothing found.*  Function*  String*/
function getDimension(strFieldName){if((strFieldName===null) || (strFieldName=="")){return "";}var tempString="slct"+strFieldName;var thisSelect=document.getElementById(tempString);if(thisSelect){
return thisSelect.options[thisSelect.selectedIndex].text;}else{return "";}}/** Get the selected choice of dimensional units*  Function*  String*/
function getUnits(strFieldName){if((strFieldName===null) || (strFieldName=="")){return "";}var tempString="slct"+strFieldName;var thisSelect=document.getElementById(tempString);if(thisSelect){return thisSelect.options[thisSelect.selectedIndex].text;
}else{return "";}}/** Get the text selected in a particular select box*  Function*  String*/
function getOption(strFieldName){return getSelectText(strFieldName);}/** Get the text value selected in a particular select box*  Function*  String*/
function getSelectValue(strFieldName){if((strFieldName===null) || (strFieldName=="")){logMsg("[200179] getSelectValue:strFieldName is null", params={level:"error"});return 0;
}var tempString="slct"+strFieldName;var thisSelect=document.getElementById(tempString);if(thisSelect){return thisSelect.options[thisSelect.selectedIndex].value;}else{return "";}}/** Get the text selected in a particular select box, identified explicitly*  Function*  String* Requires a DOM node, eg: getElementById('selectName') or a reference such as: document.formName.selectName*/
function getDOMSelectValue(objSelect){if(objSelect===null)
{logMsg("[20017A] getDOMSelectValue:objSelect is null", params={level:"error"});}else{if(objSelect.selectedIndex > -1){return objSelect.options[objSelect.selectedIndex].value;}else{logMsg("[20017B] getDOMSelectValue:selectedIndex ("+objSelect.selectedIndex+") not valid.", params={level:"error"});return "";}}return false;}/** Get the 'value' of a particular text box, identified explicitly*  Function*  String
* Requires a DOM node, eg: getElementById('inputName') or a reference such as: document.formName.inputName*/
function getDOMinputValue(objTextBox){if(objTextBox===null){logMsg("[20F18A] getDOMinputValue:objTextBox is null", params={level:"error"});}else{if(objTextBox.value){return objTextBox.value;}else{logMsg("[20F18B] getDOMinputValue:objTextBox has no value.", params={level:"warning"});return false;}}return false;
}/** Get the text selected in a particular select box*  Function*  String*/
function getSelectText(strFieldName){if((strFieldName===null) || (strFieldName=="")){return 0;}var tempString="slct"+strFieldName;var thisSelect=document.getElementById(tempString);if(thisSelect){return thisSelect.options[thisSelect.selectedIndex].text;}else{return "";}}/** Get the text from a particular text-input box
*  Function*  String Will normally contain a number*/
function getValue(strFieldName){if((strFieldName===null) || (strFieldName=="")){return 0;}var tempString="txt"+strFieldName;var thisInput=document.getElementById(tempString);if(thisInput){return thisInput.value;}else{return 0;}}/** Set the value of a particular form field*  Function*  Boolean Indicating success or failure
* strFieldName accepts a string, containing the ID of an appropriate DOM element* newValueRef accepts either a string or a reference to a SELECT element*/
function setField(strFieldName, newValueRef){var thisInput=document.getElementById(strFieldName);var newValue="";if(thisInput){if(newValueRef){if(newValueRef.options){newValue=newValueRef.options[newValueRef.selectedIndex].value;}else{newValue=newValueRef;
}}if(thisInput.type.indexOf("select")==0) {if(thisInput.selectedIndex){var indexFound=0;var searchFailed=true;for(var i=0;i<thisInput.options.length;i++){if(thisInput.options[i].text==newValue){indexFound=i;searchFailed=false;
break;}}if(searchFailed) {for(var i=0;i<thisInput.options.length;i++){if(thisInput.options[i].text.indexOf( newValue)==0 ){indexFound=i;searchFailed=false;break;}}
}if(searchFailed) {for(var i=0;i<thisInput.options.length;i++){if(thisInput.options[i].text.indexOf( newValue) > -1 ){indexFound=i;searchFailed=false;break;}}}if(searchFailed)
{var newOption=new Option(newValue, newValue, false, true);thisInput.add(newOption);return true;}else{thisInput.selectedIndex=indexFound;return true;}}return false;}if(thisInput.type=="text") {thisInput.value=newValue;if(thisInput.value==newValue){
return true;}return false;}}else{return false;}}/** Get the state of a particular radio button*  Function*  Triple-state Boolean*/
function getRadioBoolean(strRadioItem) {if((strRadioItem===null) || (strRadioItem=="") ){return this.no_such_value;}var thisButton=document.getElementById(strRadioItem);if(thisButton){
if(thisButton.checked){return true;}else{return false;}}else{return this.no_such_value;}}/** Get the state of a particular select box*  Function*  Triple-state Boolean*/
function getSelectBoolean(strSelectName, strValueExpected){if((strSelectName===null) || (strValueExpected===null) || (strSelectName=="") || (strValueExpected==NaN))
{return this.no_such_value;}var thisSelect=document.getElementById(strSelectName);if(thisSelect){var thisValue="";if(thisSelect.selectedIndex > 0){thisValue=thisSelect.options[thisSelect.selectedIndex].value;}else{thisValue=thisSelect.options[0].value.toLowerCase();}if(thisValue==strValueExpected){return true;}else{return false;
}}else{return this.no_such_value;}}/** Get the state of a particular select box*  Function*  Triple-state Boolean*/
function isSelectTrue(strSelectName){if((strSelectName===null) || (strSelectName=="") ){return this.no_such_value;}var thisSelect=document.getElementById(strSelectName);var strValueExpected1="yes";var strValueExpected2="true";
if(thisSelect){var thisValue="";if(thisSelect.selectedIndex > 0){thisValue=thisSelect.options[thisSelect.selectedIndex].value.toLowerCase();}else{thisValue=thisSelect.options[0].value.toLowerCase();}if((strValueExpected1==thisValue ) || (strValueExpected2==thisValue )){return true;}else{return false;}}else{return this.no_such_value;
}}/** Remove all results from DOM formatted console*  Function* s None*  Nothing*/
function contextMenu_ClearOutput(){hideOverlay();clearOutput2(thisCalculator.currentMenuRef);}/** Hide the overlay DIV that "grey's Out" the rest of the page*  Function* s None*  Boolean Indicating success or failure*/
function hideOverlay(){objOverlay=document.getElementById('overlay');if(objOverlay.style){objOverlay.style.display='none';
return true;}logMsg("[20017C] hideOverlay(): Unable to access objOverlay.style", params={level:"error"});return false;}/** Make the Overlay-div visible*  Function* s None*  Boolean Indicating success or failure*/
function showOverlay(){var objOverlay=document.getElementById('overlay');objOverlay.style.display='block';}/** Set height of Overlay-div, so that it takes up the whole page*  Function* s None*  Nothing
*/
function adjustOverlaySize(){var objOverlay=document.getElementById('overlay');objOverlay.style.height=(getPageWidth()+'px');}/** Get page width, in Pixels, as a bare integer* Core code from - quirksmode.org* Edit for Firefox by pHaez* Simplified from getPageSize() by MJB 05/04/2008 21:47:14*  Function* s None*  Integer*/
function getPageWidth(){var yScroll;var windowHeight;if (window.innerHeight && window.scrollMaxY){yScroll=window.innerHeight+window.scrollMaxY;
}else if (document.body.scrollHeight > document.body.offsetHeight){yScroll=document.body.scrollHeight;}else{yScroll=document.body.offsetHeight;}if (self.innerHeight){windowHeight=self.innerHeight;}else if (document.documentElement && document.documentElement.clientHeight){windowHeight=document.documentElement.clientHeight;
}else if (document.body){windowHeight=document.body.clientHeight;}if(yScroll < windowHeight){pageHeight=windowHeight;}else{pageHeight=yScroll;}return pageHeight;}/** Remove all results from DOM formatted console*  Function* s formField Optional field to give focus*  Nothing*/
function clearOutput2(formField){if(document.getElementById("divResults") ){var outArea=document.getElementById("divResults");
if(outArea.hasChildNodes()){if(removeAllChildren(outArea) ){allResults="";if(thisCalculator && thisCalculator.clearCurrent){thisCalculator.clearCurrent();}}else{("[20017D] Unable to remove child nodes from results area.", params={level:"error"});}}else{logMsg("[20017E] Unable to clear results area.", params={level:"error"});
}}else{logMsg("[20017F] Unable to find results area.", params={level:"error"});}if(document.getElementById(formField) ){document.getElementById(formField).focus();}}/** Extract the first available integer from the given string*  Function* s thisString*  null if an error occurs, or the first integer found.*/
function extractInteger(thisString){var digitPattern=/\d+/;if (digitPattern.test(thisString)) 
{retval=digitPattern.exec(thisString);if (retval==null){logMsg("[200180] Unable to extractInteger() from: "+thisString, params={level:"error"});return null}else{return retval[0];}}else{logMsg("[200181] Unable to extractInteger() from: "+thisString, params={level:"error"});return null}return null }/** Remove a single set of results from DOM formatted console*  Function
* s objButton To give a reference to identify which set of results to delete*  Nothing*/
function clearSingleResult(objButton){if(document.getElementById("divResults") ){var outArea=document.getElementById("divResults");if(outArea.hasChildNodes()){if(removeAllChildren(outArea) ){}else{logMsg("[200182] Unable to remove child nodes from results area.", params={level:"error"});}
}else{logMsg("[200183] Unable to clear results area.", params={level:"error"});}}else{logMsg("[200184] Unable to find results area.", params={level:"error"});}allResults="";}/** Remove a single set of results from DOM formatted console*  Function*  Nothing*/
function clearLastResult(){if(document.getElementById("divResults") ){var outArea=document.getElementById("divResults");if(outArea.hasChildNodes()){
if(outArea.removeChild(outArea.lastChild) ){}else{logMsg("[200185] Unable to remove last child node from results area.", params={level:"error"});}}else{}}else{logMsg("[200187] Unable to find results area.", params={level:"error"});}}/** Replace a single string in a space-separated string.*  Function
*  String containing entire class-name string, which may contain multiple names*/
function replaceCSSName(oldCSSstring, oldValue, newClassName){if((oldCSSstring==null ) || (oldCSSstring=="" ) || (oldCSSstring==oldValue )){return newClassName;}var nameList=oldCSSstring.split(" ");if(nameList.length > 0){var retval="";for(var i=0;i<nameList.length;i++){if((nameList[i]==oldValue) || (nameList[i]==newClassName))
{}else{retval+=nameList[i]+" ";}}retval+=newClassName;return retval;}else{return newClassName;}}/** Replace a single set of results from DOM formatted console*  Function*  Nothing*/
function modifyResult(thisID, newDataObj, objParams){if(document.getElementById("divResults") ){var outArea=document.getElementById("divResults");if(outArea.hasChildNodes())
{if(document.getElementById(thisID) ){var thisBlock=document.getElementById(thisID);removeAllChildren(thisBlock);thisBlock.appendChild(newDataObj);if(objParams && objParams.CSSclassName && (objParams.CSSclassName !="") && objParams.oldClassName && (objParams.oldClassName !="")){var oldValue=objParams.oldClassName;var oldCSSstring=thisBlock.className;
var newClassName=objParams.CSSclassName;thisBlock.className=replaceCSSName(oldCSSstring, oldValue, newClassName);}}else{logMsg("[200188] Unable to find results area. thisID:"+thisID, params={level:"error"});}}else{}}else{logMsg("[20018A] Unable to find results area.", params={level:"error"});
}}/** Replace a single set of results from DOM formatted console*  Function*  Nothing*/
function modifyLabel(thisID, newLabel){if(document.getElementById("divResults") ){var outArea=document.getElementById("divResults");if(outArea.hasChildNodes()){if(document.getElementById(thisID) ){var thisBlock=document.getElementById(thisID);var thisLabel=document.createElement("span");thisLabel.appendChild( document.createTextNode( newLabel ) );
if(thisBlock.hasChildNodes()){var firstNode=thisBlock.getElementsByTagName("span");if(firstNode && firstNode[0]){thisBlock.removeChild(firstNode[0]);}}if(thisBlock.hasChildNodes()){var currentContent=thisBlock.childNodes[0];thisBlock.insertBefore( thisLabel, currentContent );}else{thisBlock.appendChild( thisLabel );
}}else{logMsg("[20018B] Unable to find results area. thisID:"+thisID, params={level:"error"});}}else{}}else{logMsg("[20018D] Unable to find results area.", params={level:"error"});}}/** Remove all child nodes from a DOM tree / fragment*  Function*  Boolean Indicating success or failure*/
function removeAllChildren(DOMnode)
{if(DOMnode==undefined || DOMnode===null){return false;}while (DOMnode.hasChildNodes()){DOMnode.removeChild(DOMnode.firstChild);}return true;}/** Transform special characters into the corresponding HTML entity*  Function*  Escaped string*/
String.prototype.escapeHTML=function(){var strTemp=this;strTemp=strTemp.replace(/&/g, "&amp;");strTemp=strTemp.replace(/£/g, "&pound;");strTemp=strTemp.replace(/¥/g, "&yen;");
strTemp=strTemp.replace(/</g, "&lt;");strTemp=strTemp.replace(/\$/g, "&#36;");strTemp=strTemp.replace(/>/g, "&gt;");strTemp=strTemp.replace(/¢/g, "&cent;");strTemp=strTemp.replace(/¤/g, "&curren;");strTemp=strTemp.replace(/v/g, "&#8730;");return strTemp;}/** Opens a pop-up window and re-builds the calculation results table.*  Function*  Nothing*/
function displayPrintOutputArea(strInput){var strURL="";
var strContentStyles="<style type='text/css'>@media print{#divControls{display:none;}}\n #divCopyright{color:white;background:#333333;margin:2px;}\n #divControls{margin:1em;border:#00cc00 solid 2px;border-radius:9px;text-align:center;}\n #divCopyright{color:white;background:#333333;margin:2px;}\n .outputSection{margin:1em;padding:0.5em;border:#00cc00 solid 2px;border-radius:9px;text-align:left;}\n HR{width:90%;}</style>";var strContentTitle="<H1>Calculation Results</H1>";
var strContentControls="<div id='divControls'><a href='javascript:window.print()'>Print</a><br><a href='javascript:window.close()'>Close This Window</a></div>";var strContentFooter="<div id='divCopyright'>&#169;Copyright Mike Brockington 2004 - 2011 All rights reserved.<br>Produced by "+document.location+"</div>";var strContent="<html><head>"+strContentStyles+"</head>";strContent+="<body onLoad='window.focus();'>"+strContentTitle+strInput+strContentControls+strContentFooter+"</body></html>";
var strName="printOutput";var strHeight="500";var strWidth="700";var xMax=0;var yMax=0;if (document.all){xMax=screen.width;yMax=screen.height;}else{if (document.layers){xMax=window.outerWidth;yMax=window.outerHeight;}else{xMax=640;yMax=480;}}var xOffset=(xMax - strWidth)/2;var yOffset=(yMax - strHeight)/2;var strFeatures="resizable,location,height="+strHeight+",width="+strWidth+",screenX="+xOffset+",screenY="+yOffset+",top="+yOffset+",left="+xOffset+",scrollbars=1,resizable=1";
var boolReuse=true;var printOutput=window.open(strURL, strName, strFeatures, boolReuse);printOutput.document.open();printOutput.document.write(strContent);printOutput.document.close();printOutput.focus();}/** Show a context menu containing the given actions*  Function*  Boolean (Always FALSE)*/
function doActions(callingObject){var targetID;var thisEvent;if(callingObject.target){targetID=callingObject.target.id;thisEvent=callingObject;
}else{targetID=window.event.srcElement.id;thisEvent=window.event;}showContextMenu(targetID, commandList);preventBubbling(thisEvent);return false;}function calcResult(){checkResultsVisible();showHeaderRow();getFields(thisCalculator);calcRemaining();return false;}function showHeaderRow(){thisCalculator.calcCount++;recordResultText("Calculation No.: "+thisCalculator.calcCount, "" );}
function calcRemaining(){if(!formulaeList){logMsg("[20F174] ERROR: calcRemaining: formulaeList not found.", params={level:"debug"});return false;}for(var i=(formulaeList.length - 1);i>=0;i--){if(formulaeList[i]){if(formulaeList[i].value){}else{
if(formulaeList[i].formulae){for(var j=(formulaeList[i].formulae.length - 1);j>=0;j--){var thisResult=getCalcResult(formulaeList[i].formulae[j], formulaeList[i].fieldName);if(thisResult){formulaeList[i].value=thisResult;j=0;}}}else{
logMsg("[20F175] ERROR: calcRemaining: formulaeList["+i+"].formulae not found.", params={level:"debug"});}}var theseParams={CSSclassName:"changeMe", elementID:"result"+i, showActions:true, labelText:formulaeList[i].fieldName, labelText:formulaeList[i].unitsName};if(formulaeList[i].value){recordResultText(formulaeList[i].caption+": "+formulaeList[i].value+formulaeList[i].unitName, theseParams );
}else{logMsg("[20F171] Warning: calcRemaining: formulaeList["+i+"] :: "+formulaeList[i].caption+" could not be set.", params={level:"debug"});}}}}function getFields(currentCalcObject){if(!formulaeList){return false;}for(var i=(formulaeList.length - 1);i>=0;i--){if(formulaeList[i]){thisField=formulaeList[i].fieldName;var thisValue=getValue(thisField);
if(isNaN(thisValue)){}else{formulaeList[i].value=thisValue;}}}}/** Label an existing entry.*  Function*  Nothing*/
function labelCalcItem(calcNumber){var elementID="item"+calcNumber;var newLabel=prompt("Please enter a text label. \n\nLeave blank to cancel.");if(newLabel.length > 0){
modifyLabel(elementID, newLabel);}else{}}function getCalcResult(thisCalculation, strFieldName){var strToEvaluate="";for(var k=0;k < thisCalculation.length;k++){if((thisCalculation[k].indexOf("#")==0) || (thisCalculation[k].indexOf("!")==0) ){var tempString=thisCalculation[k].substr(1);if(thisCalculation[k].indexOf("#")==0){var inputValue=getValue(tempString);
strToEvaluate+="("+inputValue+"/"+getMultiplier(tempString)+")";}else{strToEvaluate+=" "+getConstant(tempString)+" ";}}else{strToEvaluate+=thisCalculation[k];}}var thisResult="";try{var thisCalc=strToEvaluate+"*"+getMultiplier(strFieldName);thisResult=eval(thisCalc);}catch(err){logMsg("[20F176] ERROR getCalcResult: ("+thisCalculation+", "+strFieldName+") failed, error: "+err+"\nString: "+thisCalc, params={level:"debug"});
}return thisResult;}function RealTypeOf(v){if (typeof(v)=="object"){if (v===null) return "null";if (v.constructor==(new Array).constructor) return "array";if (v.constructor==(new Date).constructor) return "date";if (v.constructor==(new RegExp).constructor) return "regex";return "object";}return typeof(v);}
