﻿function ShowToolTip(divToolTip, toolTipText) {
    
    if (toolTipText != null && toolTipText != "") {
   
        divToolTip.innerHTML = toolTipText;
        divToolTip.className = "ToolTipHover";
    }
}

function HideToolTip(divToolTip) {
    divToolTip.className = "ToolTipHoverHidden";
}

// TODO: Make this more generic

function MakeProductTabActive(newTabHeader, newTabContainer) {
   
    //Hide all tab headers
    for (var i = 0; i < g_aProductTabHeaders.length; i++) {
        document.getElementById(g_aProductTabHeaders[i]).className = "SectionItem";
    }

    // Display new tab header
    newTabHeader.className = "ActiveSectionItem";

    // Hide All Tab Containers
    for (var i = 0; i < g_aProductTabContainers.length; i++) {
        document.getElementById(g_aProductTabContainers[i]).style.display = "none";
    }

    // Display New Tab panel
        
    document.getElementById(newTabContainer).style.display = "";
}

// TODO: Make this more generic
var g_aRecipeTabHeaders = new Array("divRecipeDirectionsHeader", "divRecipeNutritionalHeader");
var g_aRecipeTabContainers = new Array("divRecipeDirections", "divRecipeNutritional");
function MakeRecipeTabActive(newTabHeader, newTabContainer) {

    //Hide all tab headers
    for (var i = 0; i < g_aRecipeTabHeaders.length; i++) {
        document.getElementById(g_aRecipeTabHeaders[i]).className = "SectionItem";
    }

    // Display new tab header
    newTabHeader.className = "ActiveSectionItem";

    // Hide All Tab Containers
    for (var i = 0; i < g_aRecipeTabContainers.length; i++) {
        document.getElementById(g_aRecipeTabContainers[i]).style.display = "none";
    }

    // Display New Tab panel
    document.getElementById(newTabContainer).style.display = "";
}

function OpenEmailModal(title, url) {
    window.open("/Foodservice/Print/Email.aspx?Title=" + title + "&Url=" + url, "Email", "height=660, width=685, status=no, toolbar=no, menubar=no, location=no");

    return false;
}

/* Watermarks */

function WatermarkFocus(txtElem, strWatermark) {
    if (txtElem.value == strWatermark) txtElem.value = "";
    txtElem.className = "";
}

function WatermarkBlur(txtElem, strWatermark) {
    if (txtElem.value == "") {
        txtElem.value = strWatermark;
        txtElem.className = "Watermark";
    }
}

function AddSelectedItem( valueToAdd, hidSelectedItems, activeItem, pnlAllId) {
    $("#" + pnlAllId).removeClass("ActiveSectionItem").addClass("SectionItem"); ;
        var tempItems = hidSelectedItems.value; 
        if (tempItems.indexOf(valueToAdd.value) == -1) {
            hidSelectedItems.value += valueToAdd.value + ",";
        }
        else {
            tempItems = tempItems.substring(0, tempItems.indexOf(valueToAdd.value)) + tempItems.substring(tempItems.indexOf(valueToAdd.value) + (valueToAdd.value.length + 1));
            hidSelectedItems.value = tempItems;
        }
        if (activeItem.className == "SectionItem") {
            activeItem.className = "ActiveSectionItem";
        }
        else {
            activeItem.className = "SectionItem";
        }
    }
    function AddAllItems(activeItem, hidSelectedItems, pnlSectionId) {

        hidSelectedItems.value = "";
        $("#" + pnlSectionId + " div").removeClass("ActiveSectionItem").addClass("SectionItem");
        if (activeItem.className == "SectionItem") {
            activeItem.className = "ActiveSectionItem";
        }
        else {
            activeItem.className = "SectionItem";
        }
}

/* Image Hover JS Begin */

function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}

function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; } 
    }
}

function MM_findObj(n, d) { //v4.0
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && document.getElementById) x = document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
    }

    /* Image Hover JS End */

/* Flash Script */
    function showFlash(path, name, width, height) {
        var MM_contentVersion = 6;
        var MM_FlashCanPlay = false;
        var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
        if (plugin) {
            var words = navigator.plugins["Shockwave Flash"].description.split(" ");
            for (var i = 0; i < words.length; ++i) {
                if (isNaN(parseInt(words[i])))
                    continue;
                var MM_PluginVersion = words[i];
            }
            MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
        }
        else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE") >= 0 && (navigator.appVersion.indexOf("Win") != -1)) {
            var flash;
            try {
                flash = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + MM_contentVersion);
                MM_FlashCanPlay = (flash != null);
            }
            catch (exception) {
                MM_FlashCanPlay = false;
            }
        }
        if (MM_FlashCanPlay) {
            document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"');
            document.write('  codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ');
            document.write(' ID="' + name + '" width="' + width + '" height="' + height + '" align="">');
            document.write(' <param name="movie" value="' + path + name + '.swf" /> <param name="wmode" value="transparent" /> <param name="menu" value="false" /> <param name="quality" value="high" /> <param name="bgcolor" value="#FFFFFF" />  ');
            document.write(' <embed src="' + path + name + '.swf" menu="false" wmode="transparent" quality="high" bgcolor="#FFFFFF"  ');
            document.write(' swLiveConnect="FALSE" width="' + width + '" height="' + height + '" name="' + name + '" align=""');
            document.write(' type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">');
            document.write(' </embed>');
            document.write(' </object>');
        }
        else {
            document.write('<img src="/' + path + name + '.gif" width="' + width + '" height="' + height + '" usemap="#' + name + '" border="0" />');
        }
    }
    /* Flash Script End */
    