function ChangeSize(b)	{
        var c = b.split(",");
        document.calc.length.value = c[0];
        document.calc.width.value = c[1];
}

function ChangeLens(l)	{
        document.calc.focalLength.value = l;
}

// NS6.01 bugfix (won't show data in form field when alignment is right)
function AlignFieldsRight() {
    if (document.documentElement&&!document.all) {
      var fe = document.calc.elements;
      for (var i=0; i<fe.length; i++) {
        if (fe[i].className=='veld') fe[i].style.textAlign='right';
      }
    }
}
function AlignFieldsLeft() {
       if (document.documentElement&&!document.all) {
      var fe = document.calc.elements;
      for (var i=0; i<fe.length; i++) {
        if (fe[i].className=='veld') fe[i].style.textAlign='left';
      }
    }
}

// Calculate hypothenuse of the image

function calculatediam(f)	{
with(Math)
f.diam.value = round(100*( sqrt( (pow(f.length.value,2)) + (pow(f.width.value,2))  )))/100
document.getElementById('diam').innerHTML = f.diam.value;
}

// Calculate field of view of normal lens using the entered image length 
function calculateFOVlength(f)	{
with(Math)
f.FOVlength.value = (round(100*((360 / PI) * (atan((f.utilization.value / 100.0 * f.length.value) / (2 * f.focalLength.value))))))/100
document.getElementById('FOVlength').innerHTML = f.FOVlength.value;
}

// Calculate field of view of normal lens using the entered image width 
function calculateFOVwidth(f)	{
with(Math)
f.FOVwidth.value = (round(100*((360 / PI) * (atan((f.utilization.value / 100.0 * f.width.value) / (2 * f.focalLength.value))))))/100
document.getElementById('FOVwidth').innerHTML = f.FOVwidth.value;
}


// Calculate diagonal field of view of normal lens using the calculated image hypothenuse
function calculateFOVdiam(f)	{
with(Math)
f.FOVdiam.value = (round(100*((360 / PI)*(atan((f.utilization.value / 100.0 * f.diam.value) / (2 * f.focalLength.value))))))/100
document.getElementById('FOVdiam').innerHTML = f.FOVdiam.value;
}


// Calculate the number of images needed with the normal lens to 
// reach the entered field of view using the entered overlap and 
// landscape orientation
// Overlap is calculated as a percentage of the field of view
function calculateImNrLandscape(f)	{
with(Math)
f.ImNrLandscape.value = round(10 * (f.DesPanAngle.value/(f.FOVlength.value - ((f.Overlap.value/100) * f.FOVlength.value)))) / 10
document.getElementById('ImNrLandscape').innerHTML = f.ImNrLandscape.value;
}

// Calculate the number of images needed with the normal lens to 
// reach the entered field of view using the entered overlap and 
// landscape orientation
// Overlap is calculated as a percentage of the field of view
function calculateImNrPortrait(f)	{
with(Math)
f.ImNrPortrait.value = round(10 * (f.DesPanAngle.value/(f.FOVwidth.value - ((f.Overlap.value/100) * f.FOVwidth.value))))/10
document.getElementById('ImNrPortrait').innerHTML = f.ImNrPortrait.value;
}

// Calculate the number of images needed with the normal lens 
// to reach the entered field of view using the entered overlap 
// and portrait orientation-->
// Overlap is calculated as a percentage of the field of view
function calculateOverlapPo(f)	{
with(Math)
f.OverlapPo.value = round( 100 * (((f.GivenNrImages.value * f.FOVwidth.value) - f.DesPanAngle.value) /f.GivenNrImages.value) / f.FOVwidth.value)
document.getElementById('OverlapPo').innerHTML = f.OverlapPo.value;
}

// Calculate the percentage of overlap using a normal lens and 
// the entered number of images in landscape orientation
// Overlap is a percentage of the field of view

function calculateOverlapLa(f)	{
with(Math)
f.OverlapLa.value = round( 100 * (((f.GivenNrImages.value * f.FOVlength.value) - f.DesPanAngle.value) /f.GivenNrImages.value) / f.FOVlength.value)
document.getElementById('OverlapLa').innerHTML = f.OverlapLa.value;
}


function doall(f)	{
with(Math)	{
f.diam.value = round(100*( sqrt( (pow(f.length.value,2)) + (pow(f.width.value,2))  )))/100;
f.FOVlength.value = (round(100*((360 / PI) * (atan((f.utilization.value / 100.0 * f.length.value) / (2 * f.focalLength.value))))))/100;
f.FOVwidth.value = (round(100*((360 / PI) * (atan((f.utilization.value / 100.0 * f.width.value) / (2 * f.focalLength.value))))))/100;
f.FOVdiam.value = (round(100*((360 / PI)*(atan((f.utilization.value / 100.0 * f.diam.value) / (2 * f.focalLength.value))))))/100;
f.ImNrLandscape.value = round(10 * (f.DesPanAngle.value/(f.FOVlength.value - ((f.Overlap.value/100) * f.FOVlength.value)))) / 10;
f.ImNrPortrait.value = round(10 * (f.DesPanAngle.value/(f.FOVwidth.value - ((f.Overlap.value/100) * f.FOVwidth.value))))/10;
f.OverlapPo.value = round( 100 * (((f.GivenNrImages.value * f.FOVwidth.value) - f.DesPanAngle.value) /f.GivenNrImages.value) / f.FOVwidth.value);
f.OverlapLa.value = round( 100 * (((f.GivenNrImages.value * f.FOVlength.value) - f.DesPanAngle.value) /f.GivenNrImages.value) / f.FOVlength.value);
}
document.getElementById('diam').innerHTML = f.diam.value;
document.getElementById('FOVlength').innerHTML = f.FOVlength.value;
document.getElementById('FOVwidth').innerHTML = f.FOVwidth.value;
document.getElementById('FOVdiam').innerHTML = f.FOVdiam.value;
document.getElementById('ImNrLandscape').innerHTML = f.ImNrLandscape.value;
document.getElementById('ImNrPortrait').innerHTML = f.ImNrPortrait.value;
document.getElementById('OverlapPo').innerHTML = f.OverlapPo.value;
document.getElementById('OverlapLa').innerHTML = f.OverlapLa.value;
}