/*  Cylinder
-----------------*/


function ClearForm(form)
{
}


function ResetForm(form)
{
form.tryckarea.value="";
form.dragarea.value="";
form.diffarea.value="";
form.areafor.value="";
form.tryckvolym.value="";
form.dragvolym.value="";
form.diffvolym.value="";
form.tryckkraft.value="";
form.dragkraft.value="";
form.diffkraft.value="";
form.trycktid.value="";
form.dragtid.value="";
form.tryckhast.value="";
form.draghast.value="";
form.tryckret.value="";
form.dragret.value="";
}


function compute(form)
{
if (check(form)==false)
{
ResetForm(form);
}
else
{

form.tryckarea.value=Math.round(100*(Math.PI*(form.cyldia.value/10)*(form.cyldia.value/10)/4*form.antal.value))/100;

form.dragarea.value=Math.round(100*(((Math.PI*(form.cyldia.value/10)*(form.cyldia.value/10)/4)-(Math.PI*(form.kolvdia.value/10)*(form.kolvdia.value/10)/4))*form.antal.value))/100;

form.diffarea.value=Math.round(100*(form.tryckarea.value-form.dragarea.value))/100;

form.areafor.value=Math.round(100*(form.tryckarea.value/form.dragarea.value))/100;

form.tryckvolym.value=Math.round(100*(form.tryckarea.value*form.slagl.value/10000))/100;

form.dragvolym.value=Math.round(100*(form.dragarea.value*form.slagl.value/10000))/100;

form.diffvolym.value=Math.round(100*(form.tryckvolym.value-form.dragvolym.value))/100;

form.tryckkraft.value=Math.round(100*(form.tryckarea.value*form.tryck.value/1000))/100;

form.dragkraft.value=Math.round(100*(form.dragarea.value*form.tryck.value/1000))/100;

form.diffkraft.value=Math.round(100*(form.tryckkraft.value-form.dragkraft.value))/100;

form.trycktid.value=Math.round(100*(form.tryckvolym.value/form.flode.value*60))/100;

form.dragtid.value=Math.round(100*(form.dragvolym.value/form.flode.value*60))/100;

form.tryckhast.value=Math.round(100*(form.slagl.value/form.trycktid.value))/100;

form.draghast.value=Math.round(100*(form.slagl.value/form.dragtid.value))/100;

form.tryckret.value=Math.round(100*(form.flode.value/form.areafor.value))/100;

form.dragret.value=Math.round(100*(form.flode.value*form.areafor.value))/100;

}
}


function check(form)
{
if (form.antal.value.length==0||form.cyldia.value.length==0||form.kolvdia.value.length==0||form.slagl.value.length==0||form.tryck.value.length==0||form.flode.value.length==0){
alert("Erforderliga indata saknas!");
return false;
}
else
return true;

}
var now = new Date();
var year = now.getYear();
var month = (((now.getMonth()+1) < 10) ? "0" : "") + (now.getMonth()+1);
var day = ((now.getDate() < 10) ? "0" : "") + now.getDate();
var MonthDayYear =(" "+year+month+day+" ");



function print(form)
{
text=("<HEAD><TITLE>Utskrift cylinderberäkning</TITLE></HEAD>");
text=(text+"<BODY><FONT SIZE=4><B>Beräkning hydraulcylinder</B></FONT>");
text=(text+"<P>");
text=(text+MonthDayYear);
text=(text+"<P>");
text=(text+"<B>Indata</B><P>");
text=(text+"<TABLE WIDTH=220><tr><td WIDTH=120>Antal =<td WIDTH=60><B>"+form.antal.value+"</B><td WIDTH=40>st<tr><td>Cylinderdiameter =<td><B>"+form.cyldia.value+"</B><td>mm<tr><td>Kolvst.diameter =<td><B>"+form.kolvdia.value+"</B><td>mm<tr><td>Slaglängd =<td><B>"+form.slagl.value+"</B><td>mm<tr><td>Arbetstryck =<td><B>"+form.tryck.value+"</B><td>bar<tr><td>Flöde  =<td><B>"+form.flode.value+"</B><td>l/min</table><P>");

text=(text+"<P><BR>");
text=(text+"<B>Resultat</B><P>");

text=(text+"<TABLE WIDTH=370><tr><td WIDTH=100><td WIDTH=100>tryckande<td WIDTH=100>dragande<td WIDTH=100>differens<td width=70><TD>förhållande<tr><td>area<td><B>"+form.tryckarea.value+"</B><td><B>"+form.dragarea.value+"</B><td><B>"+form.diffarea.value+"</B><td>cm2<td><B>"+form.areafor.value+"</B><tr><td>volym<td><B>"+form.tryckvolym.value+"</B><td><B>"+form.dragvolym.value+"</B><td><B>"+form.diffvolym.value+"</B><td>l<tr><td>kraft<td><B>"+form.tryckkraft.value+"</B><td><B>"+form.dragkraft.value+"</B><td><B>"+form.diffkraft.value+"</B><td>ton<tr><td>slagtid<td><B>"+form.trycktid.value+"</B><td><B>"+form.dragtid.value+"</B><td>sek<td><tr><td>hastighet<td><B>"+form.tryckhast.value+"</B><td><B>"+form.draghast.value+"</B><td>mm/sek<td><tr><td>returflöde<td><B>"+form.tryckret.value+"</B><td><B>"+form.dragret.value+"</B><td>l/min<td></table><P>");
text=(text+"</body></html>");
msgWindow=window.open("","displayWindow","toolbar=no,width=400,height=400,directories=no,status=no,scrollbars=yes,resize=yes,menubar=yes")
msgWindow.document.write(text)
msgWindow.document.close()

}

