    var halves = cropped.split("."); //grab numbers to the right of the decimal
        //compare digits in right half of string to digits wanted
        var zerosNeeded = digits - halves[1].length; //number of zeros to add
        for (var i=1; i <= zerosNeeded; i++) {
                cropped += "0";
        }
        return(cropped);
} 

function scientific(num, sigDigs) {
    num = Number(num); 
    if (isNaN(num)) return num;

    var exponent = Math.floor(Math.log(Math.abs(num)) / Math.LN10); 
    if (num == 0) exponent = 0; //handle glitch if the number is zero
    
    var tenToPower = Math.pow(10, exponent);
    var mantissa = num / tenToPower;
    mantissa = Math.formatDecimals(mantissa, sigDigs-1); //use custom function
    var output = mantissa;
    //if exponent is zero, don't include e
    if (exponent != 0) {
            output += "e" + exponent;
    }
    return(output);
}


function fill(size,type,name){
    var i;
    var Strpre = "form";
	var CB;
    for(i= 0;i<size;i++){
        Strtmp = Strpre +name+eval(i);
        CB=document.getElementById(Strtmp);
		if(CB){
		    CB.value = aqwaResultsMgr.HydrostaticGetSingleResult(type, i);
		}
    }
}

function updateLocal(type){
    switch(type){
        case 1:{
                fill(1,type,"ActualDisplacedVolume");
            }
            break;
        case 2:{
                fill(1,type,"EquivilentDisplacedVolume");
            }
            break;
        case 3:{
                fill(1,type,"PrincipalAxisAngle");
               }
            break;
        case 4:{
                fill(1,type,"WaterPlaneArea");
              }
            break;
        case 5:{
                fill(1,type,"CoGToCoB");
            }
            break;
        case 6:{
                fill(2,type,"CentreOfFloatation");
            }
            break;
        case 7:{
                fill(2,type,"CoBtoMetaCentre");
            }
            break;
        case 8:{
                fill(2,type,"Principal2ndMofArea");
            }
            break;
        case 9:{
                fill(2,type,"MetacentricHt");
            }
            break;
        case 10:{
                fill(2,type,"RestoringMoment");
            }
            break;
        case 11:{
                //fill(2,type,"SpecifiedGM");
            }
            break;
        case 12:{
                fill(3,type,"CentreOfBuoyancy");
            }
            break;
        case 13:{
                fill(3,type,"CentreOfGravity");
            }
            break;
        case 14:{
                fill(3,type,"HeaveStiffness");
            }
            break;
        case 15:{
                fill(3,type,"RollStiffness");
            }
            break;
        case 16:{
                fill(3,type,"PitchStiffness");
            }
            break;
        case 17:{
                fill(3,type,"OutOfBalanceForces");
            }
            break;
        case 18:{
                fill(3,type,"OutOfBalanceMoments");
            }
            break;
        
       default:
            break;
    }

}
//here we call back to app to fill vals
function fillvals(){
    var i; 
    var CB;
    CB=document.getElementById("formStructure0");
    if(CB){
		CB.value = CurrentStruct;
	}

    for (i=1;i<19;i++){
        updateLocal(i);
    }

}

window.onload = window_onload;
function window_onload()
{
	var xfer = window.external;
    aqwaprojmgr=xfer.AppletList.WBApplet("AQWAApplet").Applet.App.PM;
   	aqwaResultsMgr = aqwaprojmgr.ResultsMgr;
   	if(!aqwaResultsMgr){
   	    xfer.AppletList.Applet("AQWAApplet").App.Script.CheckIfWorksheetInReport();
        return true;
    }
   
   	var gotResults = aqwaResultsMgr.IniHydrostaticGetResult;
   	var id = aqwaResultsMgr.Analysis.CurrentHydroID;
   	var hydObj = aqwaResultsMgr.Analysis.CurrentHydroObject;
   	if (hydObj != null)
    {
   	    var currentStruct = hydObj.Structure;
   	    var state = hydObj.UptodateState;
   	    var tttemp;
   	    if (gotResults && currentStruct && state == 2)
        {
   	        num_structures = aqwaResultsMgr.StructureCount(AQWAResultsHydrostatics);
   	        if (num_structures > 0)
            {
   	            var StructureNameSingle = aqwaResultsMgr.StructureName(AQWAResultsHydrostatics, currentStruct);
   	            CurrentIndex = 0;
   	            CurrentStruct = StructureNameSingle;
   	            fillvals();
   	        }
   	    }
   	}
   	xfer.AppletList.Applet("AQWAApplet").App.Script.CheckIfWorksheetInReport();
}

function localString( strId )
{
    var str = strId;
    if(stringTable)
        str = stringTable.String(strId);
    if (str !=""){
        return str;
    }else{
        return strId;
    }
}

</script>
</head>
    <body>
        <p class="fulldoc" id="fulldoc">
        <table border="0" width="630" >
          <tr>
            <td>
        <form name="Form">
        <p align="center">
        <b><font color="#000080">&nbsp; </font></b>         
        <b><font color="#000080">Hydrostatic Results</font></b> 

        <div align="left">

        <table border="0" width="630" cellspacing="0" cellpadding="0" align="left">
            <tr>
                <td valign="top" nowrap align="right" style="font-size: 12pt;">&nbsp;</td>
            </tr>
            <tr>
                <td valign="top" nowrap  align="right" style="width: 320px; font-size: 12pt;"><b><font color="#000080">Structure</font></b></td> 
                <td valign="middle" nowrap width="35" align="right"></td>
                <td valign="bottom" nowrap width="85"><font size="2"><input type="text" name="formStructure0" size="24" id="formStructure0" style="border-style: none"/></font></td>
                <td valign="middle" nowrap width="35" align="right"></td>
                <td valign="bottom" nowrap colspan="3" id="structcell"></td>
            </tr>
            <tr>
                <td valign="top" nowrap align="right" style="font-size: 12pt;">&nbsp;</td>
            </tr>
            <tr>
                <td valign="top" nowrap  align="right" style="width: 320px; font-size: 12pt;"><font color="#000080"><b>Hydrostatic Stiffness</b></font></td>
            </tr>
            <tr>
                <td valign="top" nowrap align="right" style="width: 320px; font-size: 12pt;">Centre of Gravity (CoG) Position:</td> 
                <td valign="middle" nowrap width="35" align="right"><font size="2" color="#000080">X:&nbsp;</font></td>
                <td valign="bottom" nowrap width="85"><font size="2"><input type="text" name="formCentreOfGravity0" size="20" id="formCentreOfGravity0" style="border-style: none"/></font></td>
                <td valign="middle" nowrap width="35" align="right"><font size="2" color="#000080">Y:&nbsp;</font></td>
                <td valign="bottom" nowrap width="85"><font size="2"><input type="text" name="formCentreOfGravity1" size="20" id="formCentreOfGravity1" style="border-style: none"/></font></td>
     