﻿var RAD = 180 / Math.PI;
function CalcAngle()
{
    var pitch = parseFloat(document.getElementById("_txtPitch").value);
    if (pitch < 0)
    {
        document.getElementById("_txtPitch").value = 0;
        pitch = 0;
    }
    if (pitch > 12)
    {
        document.getElementById("_txtPitch").value = 12;
        pitch = 12;
    }
    var angle = Math.atan(pitch / 12) * RAD;
    document.getElementById("spnAngle").innerHTML = RoundTo(angle, 2) +"&deg;";
}
function CalcPitch()
{
    var angle = parseFloat(document.getElementById("_txtAngle").value);
     if (angle < 0)
     {
        document.getElementById("_txtAngle").value = 0;
        angle = 0;
    }
    if (angle > 45)
    {
        document.getElementById("_txtAngle").value = 45;
        angle = 45;
    }
    var pitch = Math.tan(angle / RAD) * 12;
    document.getElementById("spnPitch").innerHTML = RoundTo(pitch, 2) +" in 12";
    document.getElementById("spnPitch2").innerHTML = RoundTo(pitch, 2) +":12";
}
function CalcAll()
{
    SetNumeric();
    CalcAngle();
    CalcPitch();
}
function RoundTo(val, places)
{
    places = Math.pow(10, places);
    d = Math.round(val * places) / places;
    return d;
}