﻿var js_root = window.location.protocol + "//:" + window.location.hostname;
if (window.location.port != "" && window.location.port != null) {
    js_root += ":" + window.location.port;
}
js_root += "/";

function submitFormContext(in_Context) {
    $("#submitContext").val(in_Context);
    document.forms[0].submit();
}

function documentLoad(in_URL) {
    $('#documentLoader').contents().get(0).location.href="/Content/special_pages/image_download.aspx?url=" + in_URL;
}

$(document).ready(function () {
    $(".logo img").load(function () {
        var logoHeight = $(this).height();
        $(".logo").css({ "padding-top": Math.round((90 - logoHeight) / 2), "height": 90 - Math.round((90 - logoHeight) / 2) });
    });

    $(".services p").each(function () {
        $(this).prepend("•  ");
    });

    var nutritionBoxHeight;
    var hasInfo = false;
    var hasNutritionInfo = false;

    $(".row").each(function (data) {
        var quickFactInfo = $(this).children(".r").html();
        if (quickFactInfo == "N/A") {
            $(this).hide();
        }
        else {
            hasInfo = true;
        }

        if (data > 3 && quickFactInfo != "N/A") {
            hasNutritionInfo = true;
        }
        else {
            hasNutritionInfo = false;
        }
        nutritionBoxHeight = $(this).parent().height();
    });

    if (nutritionBoxHeight > 75) {
        $(".print-recipe-btn").css("top", nutritionBoxHeight + 30);
    }
    else {
        $(".print-recipe-btn").css("top", 120);
    }

    if (!hasNutritionInfo) {
        $("hr").hide();
        $(".nutritional-info-title").hide();
    }

    if (!hasInfo) {
        $(".quick-facts").hide();
        $(".print-recipe-btn").css("top", 12);
    }

    $(".result .recipe").each(function () {
        var leftRecipeContent = $(this).children(".l").html();
        var rightRecipeContent = $(this).children(".r").html();

        if (leftRecipeContent == "" && rightRecipeContent == "") {
            $(this).hide();
        }
    });
});
