// Script by DuckBoy February 16, 2007
// Additions by Vamp February 19, 2007



function roundnum(pinum){

var numtimes=0;

var currentpower=1;

var currentround;

while (numtimes<rounding.options.selectedIndex) {currentpower=currentpower*10;numtimes=numtimes+1;}

currentround=Math.round(pinum*currentpower)/currentpower;

return currentround;

}


function worksquare()
{
 sh=document.forms["square"]["squareside"].value;
 
if (sh=="") 
{
alert("Please enter a number 0 or greater");
}
{ 
pinum=roundnum(sh*sh);
}	
document.forms["square"]["area"].value= pinum;

}


function worksquare2(){

sh=document.forms["square"]["squareside"].value;

if (sh=="")
{
alert("Please enter a number 0 or greater");
}

{
 pinum=roundnum(sh*4);
}

document.forms["square"]["perimeter"].value= pinum;
}



function workrectangle(){

rectl= document.forms["rectangle"]["rectanglelength"].value;

recth= document.forms["rectangle"]["rectangleheight"].value;

if (rectl=="") rectl="0";

if (recth=="") recth="0";
{
var pinum=roundnum(rectl*recth);
}
document.forms["rectangle"]["rectarea"].value= pinum;
}

function workrectangle2(){

rectl= document.forms["rectangle"]["rectanglelength"].value;

recth= document.forms["rectangle"]["rectangleheight"].value;

if (rectl=="") rectl="0";

if (recth=="") recth="0";
{
var pinum=roundnum((2*rectl)+(2*recth));
}
document.forms["rectangle"]["rectperim"].value= pinum;

}


function worktriangle()
{
trib= document.forms["triangle"]["trianglebase"].value;

trih= document.forms["triangle"]["triangleheight"].value;

if (trib=="") trib="0";

if (trih=="") trih="0";
{
var pinum=roundnum(trib*trih/2);
}
document.forms["triangle"]["triarea"].value= pinum;
}


function workcircle()
{
 cr=document.forms["circle"]["circleradius"].value
 
if (cr=="") 
{
alert("Please enter a number 0 or greater");
}
{ 
  pinum=roundnum(Math.PI*cr*cr);
}	
document.forms["circle"]["area"].value= pinum
}

function workcircle2(){

cr=document.forms["circle"]["circleradius"].value;

if (cr=="")
{
alert("Please enter a number 0 or greater");
}
{
 pinum=roundnum(2*Math.PI*cr);
}
document.forms["circle"]["circumference"].value= pinum;
}


function workcuboid()
{
cubl= document.forms["cuboid"]["cuboidlength"].value;

cubh= document.forms["cuboid"]["cuboidheight"].value;

cubw= document.forms["cuboid"]["cuboidwidth"].value;

if (cubl=="") cylr="0";

if (cubh=="") cylh="0";

if (cubw=="") cylh="0";
{
var pinum=roundnum(cubl*cubh*cubw);
}
document.forms["cuboid"]["cubvolume"].value= pinum;
}
function workcuboid2()
{
cubl= document.forms["cuboid"]["cuboidlength"].value;

cubh= document.forms["cuboid"]["cuboidheight"].value;

cubw= document.forms["cuboid"]["cuboidwidth"].value;

if (cubl=="") cylr="0";

if (cubh=="") cylh="0";

if (cubw=="") cylh="0";
{
var pinum=roundnum((2*cubw*cubh)+(2*cubh*cubl)+(2*cubw*cubl));
}
document.forms["cuboid"]["cubsurface"].value= pinum;
}


function worksphere()
{
sr= document.forms["sphere"]["sphereradius"].value;

if (sr=="") sr="0";
{
 pinum=roundnum(4*Math.PI*sr*sr*sr/3)
}
  document.forms["sphere"]["sphererad"].value=pinum;
}

function worksphere2(){

sr= document.forms["sphere"]["sphereradius"].value;

if (sr=="") sr="0";
{
var pinum=roundnum(4*Math.PI*sr*sr);
}
document.forms["sphere"]["spheresurface"].value=pinum;
}



function workcylinder()
{
cylr= document.forms["cylinder"]["cylinderradius"].value;

cylh= document.forms["cylinder"]["cylinderheight"].value;

if (cylr=="") cylr="0";

if (cylh=="") cylh="0";
{
var pinum=roundnum(Math.PI*cylr*cylr*cylh);
}
document.forms["cylinder"]["cylvolume"].value= pinum;
}
function workcylinder2()
{
cylr= document.forms["cylinder"]["cylinderradius"].value;

cylh= document.forms["cylinder"]["cylinderheight"].value;

if (cylr=="") cylr="0";

if (cylh=="") cylh="0";
{
var pinum=roundnum((2*Math.PI*cylr*cylr)+(2*Math.PI*cylr*cylh));
}
document.forms["cylinder"]["cylsurface"].value= pinum;
}


function workcone()
{
conerad= document.forms["cone"]["coneradius"].value;

conehgt= document.forms["cone"]["coneheight"].value;

if (conerad=="") conerad="0";

if (conehgt=="") conehgt="0";
{
var pinum=roundnum(Math.PI*conerad*conerad*conehgt/3);
}
document.forms["cone"]["conevolume"].value= pinum;
}


function workcone2()
{
conerad= document.forms["cone"]["coneradius"].value;
conehgt= document.forms["cone"]["coneheight"].value;

if (conerad=="") conerad="0";

if (conehgt.value=="") conehgt.value="0";

{
var pinum=roundnum(Math.PI*conerad*Math.sqrt((conehgt*conehgt)+((conerad/2)*(conerad/2))));
}
document.forms["cone"]["conesurf"].value= pinum;

}




