// Greg Tarrant 2005
// TarrantIT
if( top != self )
{
	top.location=self.document.location;
}
function Form_onsubmit()
{
	if (! CheckLimit())
  	    return false;
	var w = parseInt(document.getElementById("txtWidth").value);
	var l = parseInt(document.getElementById("txtLength").value);
	if (w > (l * 2))
	{
		alert("Width cannot be greater than Length X 2\n\r\n\rWith Length or "+ l +"mm, width cannot be grater than "+ (l * 2) +"mm");
		document.getElementById("txtWidth").focus();
		return false;
	}
	if (parseInt(document.getElementById("txtPlateWidth").value) > 0)
	{
	    var angle = parseInt(document.getElementById("_txtAngle").value);
	    var plateWidth = parseInt(document.getElementById("txtPlateWidth").value);
	    var birdsMouthDepth = plateWidth * Math.sin(angle / (180 / Math.PI));
	    var rafterDepth = parseInt(document.getElementById("txtRafterDepth").value);
	    if (rafterDepth / birdsMouthDepth < 3)
	    {
	        if (! confirm("Birds mouth depth will be greater than 1/3 rafter depth\n\rThis can significantly weaken rafter\n\r\n\rContinue?"))
	            return false;
	    }
	}
	return true;
}
function CompareOverhangs()
{
    if (document.getElementById("txtOverhang").value != document.getElementById("txtOverhangGable").value)
        document.getElementById("txtOverhangGable").style.backgroundColor = "yellow";
    else    
        document.getElementById("txtOverhangGable").style.backgroundColor = "";
}
function ShowBirdsCalc()
{
    document.getElementById("_txtBirdsmouthAngle").value = document.getElementById("_txtAngle").value;
    document.getElementById("divBirdsmouth").style.left = "260px";
}
function HideBirdsCalc()
{
    document.getElementById("divBirdsmouth").style.left = "-10000px";
}
function CalcFoot()
{   
    var heelCut = parseFloat(document.getElementById("txtHeelCut").value);
    if (isNaN(heelCut))
    {
        document.getElementById("txtHeelCut").select();
        alert("Please enter a valid number for Heel Cut");
        return;
    }
    var rangle = GetRangle();
    if (rangle == null)
        return;
    var footCut = heelCut / Math.tan(rangle);
    document.getElementById("spnFootCut").innerHTML = Math.round(footCut) +" mm";
    document.getElementById("txtFootCut").value = Math.round(footCut);
    var heelCut = Math.tan(rangle) * footCut;
    document.getElementById("spnHeelCut").innerHTML = Math.round(heelCut) +" mm";
    document.getElementById("txtPlateWidth").value = document.getElementById("txtFootCut").value;
}
function CalcHeel()
{
    var footCut = parseFloat(document.getElementById("txtFootCut").value);
    if (isNaN(footCut))
    {
        document.getElementById("txtFootCut").select();
        alert("Please enter a valid number for Foot Cut");
        return;
    }
    var rangle = GetRangle();
    if (rangle == null)
        return;
    var heelCut = Math.tan(rangle) * footCut;
    document.getElementById("spnHeelCut").innerHTML = Math.round(heelCut) +" mm";
    document.getElementById("txtHeelCut").value = Math.round(heelCut);
    var footCut = heelCut / Math.tan(rangle);
    document.getElementById("spnFootCut").innerHTML = Math.round(footCut) +" mm";
    document.getElementById("txtPlateWidth").value = document.getElementById("txtFootCut").value;   
}
function GetRangle()
{
    var angle = parseFloat(document.getElementById("_txtBirdsmouthAngle").value);
    if (isNaN(angle))
    {
        alert("Please enter a valid number for Angle");
        document.getElementById("_txtBirdsmouthAngle").select();
        return null;
    }
    else if(angle < 1 || angle > 45)
    {
        alert("Angle must be larger than 1 and smaller than or equal to 45");
        document.getElementById("_txtBirdsmouthAngle").select();
        return null;
    }
    else
        return angle / (180 / Math.PI);
}