﻿function prepareCalculator()
{
    if (document.getElementById && document.getElementsByTagName)
    {
        if (document.getElementById("calculator"))
        {
            var calcButton = document.getElementById("btnPondVolume");
            calcButton.onclick = function calcGallons()
            {
                var length = document.getElementById("txtPondLength");
                var width = document.getElementById("txtPondWidth");
                var depth = document.getElementById("txtPondDepth");
                var gallons = document.getElementById("txtPondGallons");
                gallons.value = "" + (length.value * width.value * depth.value) * 7.5;
            }

            var aboveLink = document.getElementById("above").firstChild;
            var belowLink = document.getElementById("below").firstChild;

            aboveLink.onclick = function recommendFilter()
            {
                var gallons = document.getElementById("txtPondGallons");
                document.location.href = "/recommendedfilters.aspx?temp=above&gallons=" + gallons.value;
                return false;
            }
            belowLink.onclick = function recommendFilter()
            {
                var gallons = document.getElementById("txtPondGallons");
                document.location.href = "/recommendedfilters.aspx?temp=below&gallons=" + gallons.value;
                return false;
            }
        }
    }
}

function addLoadEvent(func)
{
    var oldonload = window.onload;
    if (typeof window.onload != 'function')
    {
        window.onload = func;
    }
    else
    {
        window.onload = function ()
        {
            if (oldonload)
            {
                oldonload();
            }
            func();
        }
    }
}

addLoadEvent(prepareCalculator);
