﻿// **Start Consumer recipes **
function navigateToProduct(object) {
    var productId = object.options[object.selectedIndex].value;
    object.selectedIndex = 0;
    if (productId != "") {
        var url = "/Consumer/Products/ViewProduct.aspx?id=" + productId;
        window.open(url, "_self");
    }
}
// **End Consumer recipes

function doClick(buttonName, e) {
    //the purpose of this function is to allow the enter key to 
    //point to the correct button to click.
    var key;

    if (window.event)
        key = window.event.keyCode;     //IE
    else
        key = e.which;     //firefox

    if (key == 13) {
        //Get the button the user wants to have clicked
        var btn = document.getElementById(buttonName);
        if (btn != null) { //If we find the button click it
            btn.click();
            event.keyCode = 0
        }
    }
}
//End Item Finder JS

//TODO: Need better localization solution
function mo(object) {
    // if on, turn off
    if (object.src.lastIndexOf("-on") > 0) object.src = object.src.replace("-on", "");
    else {
        //if off, turn on
        if (object.src.lastIndexOf(".es") > 0) object.src = object.src.replace(".es.gif", "-on.es.gif"); //Spanish
        else object.src = object.src.replace(".gif", "-on.gif"); //English
    }
}

function AddNotesToShoppingList(notesBox) {
    PageMethods.AddNotesToShoppingList($("#" + notesBox).html());
}

function ToggleAddRemoveLink(recipeId, clientId, modification) {
    if (recipeId != 0) {
        PageMethods.ToggleAddRemoveLink(recipeId, clientId, modification, ToggleAddRemoveLink_OnComplete);
    }
}

function ToggleAddRemoveLink_OnComplete(result) {
    if ($("#" + result).html() == "Add to Recipe Box") {
        $("#" + result).html("Remove from Recipe Box");
        $("#" + result).attr("href", $("#" + result).attr("href").replace("AddToRecipeBox", "RemoveFromRecipeBox"));
    }
    else if ($("#" + result).html() == "Remove from Recipe Box") {
        $("#" + result).html("Add to Recipe Box");
        $("#" + result).attr("href", $("#" + result).attr("href").replace("RemoveFromRecipeBox", "AddToRecipeBox"));
    }
    else if ($("#" + result).html() == "Add to Shopping List") {
        $("#" + result).html("Remove from Shopping List");
        $("#" + result).attr("href", $("#" + result).attr("href").replace("AddToShoppingList", "RemoveFromShoppingList"));
    }
    else if ($("#" + result).html() == "Remove from Shopping List") {
        $("#" + result).html("Add to Shopping List");
        $("#" + result).attr("href", $("#" + result).attr("href").replace("RemoveFromShoppingList", "AddToShoppingList"));
    }
}

function OpenPrintItemFinderWindow() {
    window.open("/Consumer/Products/Locator/PrintItemFinder.aspx", "_new", "toolbar=0,location=0,width=740,height=450");
}
//End Item Finder JS

/* Start Profile Scripts */
function updateDN() {
    var temp = iFN.value + ' ' + iLN.value;
    if (temp.length < 21) {
        iDN.value = temp;
    }
    updateDNCnt();
}

function updateDNCnt() {
    document.all["spnDNCnt"].innerText = iDN.value.length;
}

/* End Profile Scripts */

// **Start: ViewDonations control **
function viewDonations(object) {
    var category = object.options[object.selectedIndex].value;
    if (category != "") {
        var url = "/Consumer/AboutTyson/TysonCares/ViewDonations.aspx?cat=" + category;
        document.getElementById("ifDonations").src = url;
    }
}
// **End: ViewDonations control **

// **Ask Willie (and anything else that needs to clear a text box... **//

function readyTextBox(object) {
    if (object.value == object.title)
        object.value = "";
}
function resetTextBox(object) {
    if (object.value == "")
        object.value = object.title;
}

// **End: Ask Willie //

function openRecipeMailSignup() {
    window.open('/Consumer/Newsletter/RecipeMailSignup.aspx', 'RecipeMailSignup', 'height=340, width=530, location=no, menubar=no, resizable=no, scrollbars=no, status=no, titlebar=no, toolbar=no');
}

/* 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";
    }
}