        $(document).ready(function() {

            var BowlSize = new Array(12);
            BowlSize[0] = 0;
            BowlSize[1] = 6;
            BowlSize[2] = 8;
            BowlSize[3] = 10;
            BowlSize[4] = 12;
            BowlSize[5] = 15;
            BowlSize[6] = 18;
            BowlSize[7] = 21;
            BowlSize[8] = 24;
            BowlSize[9] = 27;
            BowlSize[10] = 30;
            BowlSize[11] = 36;

            $('#bCalc').click(function() {
                calculate();
            });
			
            $('#bCalcCapacity').click(function() {
                calcCapacity();
            });

            function areaFormulaA(l, w, h) {
                return parseFloat((l * w * h) / 2);
            }

            function areaFormulaB(l, w, h) {
                return parseFloat(l * w * h);
            }

            function calcBowlSize(baseBowlSizeIndex, ppmLimit, ppm, lf, isLimitMax) {
                var calculatedBowlSizeIndex; //bowl size based on PPM and line feeds

                if (ppm <= ppmLimit) {
                    calculatedBowlSizeIndex = baseBowlSizeIndex;
                }
                else if (ppm > ppmLimit & isLimitMax == 0) {
                    calculatedBowlSizeIndex = baseBowlSizeIndex + 1;
                }
                else {
                    calculatedBowlSizeIndex = 0;
                }
                if (lf == 'dual' & isLimitMax == 0) {
                    calculatedBowlSizeIndex += 1;
                }

                try {
                    var bowlSize = BowlSize[calculatedBowlSizeIndex];
                }
                catch (err) {
                    alert(err.description);
                }

                return bowlSize;

            }

            function calcCapacity() {
                var lngth = parseFloat($('#length').val());
                var wdth = parseFloat($('#width').val());
                var hght = parseFloat($('#height').val());

			
                var partArea = lngth * wdth * hght;
                var partsPerCubicFoot = (1728 / partArea) * .80;
				
				$("#capacity").html("<p>Estimated number of parts per cubic foot of storage: " + String(parseInt(partsPerCubicFoot)) + " parts.</p><hr />");
					
				$("#restitle").html("<div><h3>Results</h3></div>");

                //return parseInt(partsPerCubicFoot);
            }

            function calculate() {
                var shp = $('input[name=shape]:radio:checked').val();
                var lngth = parseFloat($('#length').val());
                var wdth = parseFloat($('#width').val());
                var hght = parseFloat($('#height').val());
                var ppm = parseFloat($('#ppm').val());
                var lf = $('input[name=line_feed]:radio:checked').val();

                if (shp != null & shp != "" &
                    lngth != null & lngth != "" &
                    wdth != null & wdth != "" &
                    hght != null & hght != "" &
                    ppm != null & ppm != "" &
                    lf != null & lf != "") {

                    // check if any dimension is 5 x longer that any other dimension 
                    var failDimensionTest = 0;
                    if (lngth > wdth & lngth > (5 * wdth)) {
                        failDimensionTest = 1;
                    }
                    if (failDimensionTest = 0 & (lngth > hght & lngth > (5 * hght))) {
                        failDimensionTest = 1;
                    }
                    if (failDimensionTest = 0 & (wdth > lngth & wdth > (5 * lngth))) {
                        failDimensionTest = 1;
                    }
                    if (failDimensionTest = 0 & (wdth > hght & wdth > (5 * hght))) {
                        failDimensionTest = 1;
                    }
                    if (failDimensionTest = 0 & (hght > lngth & hght > (5 * lngth))) {
                        failDimensionTest = 1;
                    }
                    if (failDimensionTest = 0 & (hght > wdth & hght > (5 * wdth))) {
                        failDimensionTest = 1;
                    }

                    if (failDimensionTest == 1) {
                        $("#result").html("No single dimension can be 5 times longer than any other dimension.  Please review your dimensions.");
                        return false;
                    }

                    var a = undefined; // area
                    var b = undefined; // secondary B
                    var c = undefined; // secondary C
                    switch (shp) {
                        case "block_wedge":
                            a = areaFormulaA(lngth, wdth, hght);
                            break;
                        case "block_triangle":
                            a = areaFormulaA(lngth, wdth, hght);
                            break;
                        case "block_L":
                            a = areaFormulaA(lngth, wdth, hght);
                            break;
                        case "block_T":
                            a = areaFormulaA(lngth, wdth, hght);
                            break;
                        case "cylindrical_T":
                            a = areaFormulaA(lngth, wdth, hght);
                            break;
                        case "block":
                            a = areaFormulaB(lngth, wdth, hght);
                            break;
                        case "cylindrical_block":
                            a = areaFormulaB(lngth, wdth, hght);
                            break;
                        case "long_thin_parts":
                            b = lngth;
                            break;
                        case "thin_disc":
                            c = lngth;
                            break;
                        case "thin_square":
                            if (lngth >= wdth & lngth >= hght) {
                                c = lngth;
                            }
                            else if (wdth >= lngth & wdth >= hght) {
                                c = wdth;
                            }
                            else if (hght >= wdth & hght >= lngth) {
                                c = hght;
                            }
                            break;
                    }

                    var calculatedBowlSize; //bowl size based on PPM and line feeds
                    if (a != undefined) {
                        if (a > 0 & a < 0.0046) {
                            calculatedBowlSize = calcBowlSize(1, 20, ppm, lf, 0);
                        }
                        else if (a >= 0.0046 & a < 0.0126) {
                            calculatedBowlSize = calcBowlSize(2, 20, ppm, lf, 0);
                        }
                        else if (a >= 0.0126 & a < 0.0200) {
                            calculatedBowlSize = calcBowlSize(3, 20, ppm, lf, 0);
                        }
                        else if (a >= 0.0210 & a < 0.101) {
                            calculatedBowlSize = calcBowlSize(4, 30, ppm, lf, 0);
                        }
                        else if (a >= 0.101 & a < 0.351) {
                            calculatedBowlSize = calcBowlSize(5, 30, ppm, lf, 0);
                        }
                        else if (a >= 0.351 & a < 0.701) {
                            calculatedBowlSize = calcBowlSize(6, 40, ppm, lf, 0);
                        }
                        else if (a >= 0.701 & a < 1.86) {
                            calculatedBowlSize = calcBowlSize(7, 40, ppm, lf, 0);
                        }
                        else if (a >= 1.86 & a < 3.01) {
                            calculatedBowlSize = calcBowlSize(8, 50, ppm, lf, 0);
                        }
                        else if (a >= 3.01 & a < 4.51) {
                            calculatedBowlSize = calcBowlSize(9, 50, ppm, lf, 0);
                        }
                        else if (a >= 4.51 & a < 6.21) {
                            calculatedBowlSize = calcBowlSize(10, 50, ppm, lf, 0);
                        }
                        else if (a >= 6.21 & a <= 22.0000) {
                            calculatedBowlSize = calcBowlSize(11, 40, ppm, lf, 1);
                        }
                        else {
                            calculatedBowlSize = calcBowlSize(0, 0, ppm, lf, 1);
                        }
                    }
                    else if (b != undefined) {
                        if (b <= (1 / 4)) {
                            calculatedBowlSize = calcBowlSize(1, 20, ppm, lf, 0);
                        }
                        else if (b >= (17 / 64) & b <= (1 / 2)) {
                            calculatedBowlSize = calcBowlSize(2, 20, ppm, lf, 0);
                        }
                        else if (b >= (33 / 64) & b <= (3 / 4)) {
                            calculatedBowlSize = calcBowlSize(3, 20, ppm, lf, 0);
                        }
                        else if (b >= (49 / 64) & b <= 1) {
                            calculatedBowlSize = calcBowlSize(4, 30, ppm, lf, 0);
                        }
                        else if (b >= (1 + (1 / 64)) & b <= (1 + (1 / 2))) {
                            calculatedBowlSize = calcBowlSize(5, 30, ppm, lf, 0);
                        }
                        else if (b >= (1 + (33 / 64)) & b <= 2) {
                            calculatedBowlSize = calcBowlSize(6, 30, ppm, lf, 0);
                        }
                        else if (b >= (2 + (1 / 64)) & b <= (2 + (1 / 2))) {
                            calculatedBowlSize = calcBowlSize(7, 30, ppm, lf, 0);
                        }
                        else if (b >= (2 + (33 / 64)) & b <= 3) {
                            calculatedBowlSize = calcBowlSize(8, 30, ppm, lf, 0);
                        }
                        else if (b >= (3 + (1 / 64)) & b <= (3 + (3 / 4))) {
                            calculatedBowlSize = calcBowlSize(9, 30, ppm, lf, 0);
                        }
                        else if (b >= (3 + (49 / 64)) & b <= (4 + (1 / 2))) {
                            calculatedBowlSize = calcBowlSize(10, 30, ppm, lf, 0);
                        }
                        else if (b >= (4 + (33 / 64)) & b <= (6 + (1 / 2))) {
                            calculatedBowlSize = calcBowlSize(11, 30, ppm, lf, 0);
                        }
                        else if (b > (6 + (1 / 2))) {
                            calculatedBowlSize = calcBowlSize(0, 0, ppm, lf, 1);
                        }
                        else {
                            calculatedBowlSize = calcBowlSize(0, 0, ppm, lf, 1);
                        }
                    }
                    else if (c != undefined) {
                        if (c <= (1 / 4)) {
                            calculatedBowlSize = calcBowlSize(1, 20, ppm, lf, 0);
                        }
                        else if (c >= (17 / 64) & c <= (1 / 2)) {
                            calculatedBowlSize = calcBowlSize(2, 20, ppm, lf, 0);
                        }
                        else if (c >= (33 / 64) & c <= (3 / 4)) {
                            calculatedBowlSize = calcBowlSize(3, 20, ppm, lf, 0);
                        }
                        else if (c >= (49 / 64) & c <= 1) {
                            calculatedBowlSize = calcBowlSize(4, 30, ppm, lf, 0);
                        }
                        else if (c >= (1 + (1 / 64)) & c <= (1 + (1 / 4))) {
                            calculatedBowlSize = calcBowlSize(5, 30, ppm, lf, 0);
                        }
                        else if (c >= (1 + (17 / 64)) & c <= (1 + (1 / 2))) {
                            calculatedBowlSize = calcBowlSize(6, 30, ppm, lf, 0);
                        }
                        else if (c >= (1 + (33 / 64)) & c <= (1 + (3 / 4))) {
                            calculatedBowlSize = calcBowlSize(7, 30, ppm, lf, 0);
                        }
                        else if (c >= (1 + (49 / 64)) & c <= (2 + (1 / 4))) {
                            calculatedBowlSize = calcBowlSize(8, 30, ppm, lf, 0);
                        }
                        else if (c >= (2 + (17 / 64)) & c <= (2 + (3 / 4))) {
                            calculatedBowlSize = calcBowlSize(9, 30, ppm, lf, 0);
                        }
                        else if (c >= (2 + (49 / 64)) & c <= (3 + (1 / 4))) {
                            calculatedBowlSize = calcBowlSize(10, 30, ppm, lf, 0);
                        }
                        else if (c >= (3 + (17 / 64)) & c <= 4) {
                            calculatedBowlSize = calcBowlSize(11, 30, ppm, lf, 0);
                        }
                        else if (c > 4) {
                            calculatedBowlSize = calcBowlSize(0, 0, ppm, lf, 1);
                        }
                        else {
                            calculatedBowlSize = calcBowlSize(0, 0, ppm, lf, 1);
                        }
                    }

                    if (calculatedBowlSize > 0) {
                        $("#result").html("<p>We recommend a " + String(calculatedBowlSize) + " in. basic bowl</p>");
                    }
                    else {
                        $("#result").html("<p>Please contact Hoosier directly for estimate.</p>");
                    }

                    //$("#capacity").html("<p>Feeder capacity is " + String(calcCapacity(lngth, wdth, hght)) + " parts.</p><hr />");
					
					$("#restitle").html("<div><h3>Results</h3></div>");

                }
                else {
                    alert("You are missing a required field.");
                }
            }

        });
