﻿
//HACK:  Redundant execution of shown events was noticed, these are flags to prevent redunandt execution until we understand why the all is happening twice.
var emailPopupShown = false;
var addToRecipeBoxPopupShown = false;
var recipeId;

//
//******************************************
//Popup Email Send To a Freind Event Handlers
//******************************************
function modalEmailSetup(){
    var modalPopup = $find('popupRBDEmailRecipeBehavior');              // <. this is the BehaviorID from the ModalPopupExtender
    modalPopup.add_shown(onModalEmailShown);
    modalPopup.add_hiding(onModalEmailHide);
}

function onModalEmailHide() {
    emailPopupShown = false;
}

//This function is called from usercontrol unEmailRecipe.ascx under recipes
function sendEmailWebTrendCall() {
    dcsMultiTrack('DCS.dcsuri', '/recipes/emailrecipethankyou.aspx', 'DCS.dcsqry', 'RecipeId=' + recipeId, 'WT.ti', 'Thank You For Forwarding a Recipe from BettyCrocker.com');
}
function onModalEmailShown() {
    if (emailPopupShown) return;
    try {
        dcsMultiTrack('DCS.dcsuri', '/recipes/EmailRecipe.aspx', 'DCS.dcsqry', 'RecipeId='+recipeId, 'WT.ti', 'Send Recipe to a Friend from BettyCrocker.com.');
        emailPopupShown = true;
    }catch(e) {
        // do not diplay error if query string cannot be parsed or web trends call fails.
    }
}
//
//*******************************************
//* Add To Recipe Box Pop Up Event Handlers
//*******************************************
//
function modalRecipeBoxSetup(){
    var modalPopup = $find('popupSaveRecipeToRecipeBoxBehavior');                // <. this is the BehaviorID from the ModalPopupExtender
    if (modalPopup === null) return;
    modalPopup.add_shown(onModalRecipeBoxShown);
    modalPopup.add_hiding(onModalRecipeBoxHide);
}

function onModalRecipeBoxShown() {
    if (addToRecipeBoxPopupShown) return;
    try {
        dcsMultiTrack('DCS.dcsuri', '/recipes/SaveRecipeBox.aspx', 'DCS.dcsqry', 'RecipeId=' + recipeId, 'WT.ti', 'Saving a Recipe to your BettyCrocker.com recipe box.');
        addToRecipeBoxPopupShown = true;
    }catch(e) {
        // do not diplay error if query string cannot be parsed or web trends call fails.
}
//Sometimes Safari 3.2 doesn't have zIndex set
document.getElementById(recipeBoxPopupId).style.zIndex = "10001";

}

function onModalRecipeBoxHide() {
    addToRecipeBoxPopupShown  = false;
}

//This function is called from usercontrol ucSaveRecipeToRecipeBox.ascx under recipes
function RecipeBoxWebTrendsSave() {
    dcsMultiTrack('DCS.dcsuri', '/recipes/RecipeBoxThankYou.aspx', 'DCS.dcsqry', 'RecipeId=' + recipeId, 'WT.ti', 'Thank You For Adding a Recipe to you BettyCrocker.com Recipe Box');
}

//Function to retreive the query string
function querySt(ji) {
    hu = window.location.search.substring(1).toLowerCase();
    gy = hu.split("&");
    for (i=0;i<gy.length;i++) {
        ft = gy[i].split("=");
        if (ft[0] == ji) {
            return ft[1];
        }
    }
}


//******************************************
//Immediate Execution on parse of script
//******************************************

//Add handler to onload on doc
Sys.Application.add_load(modalEmailSetup);

//The recipeBox is only rendered if user is logged-in
Sys.Application.add_load(modalRecipeBoxSetup);



function fireSpotLightTags() {
    var axel = Math.random() + "";
    var a = axel * 10000000000000;
    var spotpix = new Image();
    spotpix.src = "http://ad.doubleclick.net/activity;src=1869704;type=betty077;cat=print034;ord=" + a;
    spotpix.onload = dummyFunction;
}

function dummyFunction() {
}

function openPrintPagePopup(recipeId) {
    fireSpotLightTags();
    var url = "/Recipes/PrintRecipe.aspx?recipeid=" + recipeId;
    popUp(url,'print','dependent=yes,height=480,width=660,scrollbars=yes,hotkeys=no,toolbar=yes'); 
}