// DoubleClick DART Natural Search Standard Tracking Tag for DSUS : DFA Network - Starcom IP - DFA(763) : DS Agency - SMG Search(11) : DFA Advertiser - Hillshire Farm(1419543) : DS Advertiser - Hillshire Farm(K12889): Please do not remove 
// Web site URL to be tracked: http://www.gomeat.com 
//Tag should be placed at the top of the page, after opening body tag and before DoubleClick Spotlight or Floodlight tag(s)
// Creation Date: 02-27-2009 

// DoubleClick DART Natural Search Tracking Code
if (document.referrer){
var ord = Math.random()*1000000000000;
document.write('<SCRIPT language="JavaScript1.1" SRC="http://ad.doubleclick.net/adj/N763.nso.codesrv/B3477304;dcadv=2217363;sz=1x2;ord=' + ord + '?"><\/SCRIPT>');
}

window.onload = initPage;

// global variable that gets set on a page-by-page basis. Primarily it is set within 
// the theme.master pahe
var sectionName;


function initPage(){

	if (typeof(sectionName) != "undefined" && sectionName != "searchResults")
		
		var theElm = document.getElementById(sectionName);
		
		if (theElm != null){
			theElm.className = "isCurrentPage";
		}	
	
	if (sectionName == "mealideas"){
		initRecipes();
	}
	
	if (sectionName == "products"){
		if(document.getElementById("prodInfoContainer")) {
		    initProducts();
		}
	}
	
	if(sectionName == "searchResults") {
		initResultsPreview();
	}
	
	if(sectionName == "_myStuff") {
	        initRecipes();
			initMyStuff();
	}
	
	if (sectionName == "_myRecipe"){
		initRecipes();
	}
	
	authCheck();
	initRightModules();

}

//assigns the showNonAuthenticatedMsg fxn call to certain elements on
// the pages in the event that the user is not logged in/authenticated
function authCheck(){
	
	if (typeof(isAuthenticated) != "undefined" && isAuthenticated == false){
		
		// various links that show up on various pages through out the site
		if (document.getElementById("testimonialLink") != null)
			document.getElementById("testimonialLink").onclick = showNonAuthenticatedMsg;
		if (document.getElementById("suggestProdLink") != null)
			document.getElementById("suggestProdLink").onclick = showNonAuthenticatedMsg;
		if (document.getElementById("suggestRecipeLink") != null)
			document.getElementById("suggestRecipeLink").onclick = showNonAuthenticatedMsg;
		if (document.getElementById("suggestRecipeToolLink") != null)
			document.getElementById("suggestRecipeToolLink").onclick = showNonAuthenticatedMsg;
			
		
		// MyStuff Pennant and DropDowns
		var links = document.getElementById("_myStuff").getElementsByTagName('a');
		for (var i=0;i<links.length;i++){
			links[i].onclick = showNonAuthenticatedMsg;
		}
		
		// meal ideas
		if (sectionName == "mealideas"){
		
			if (document.getElementById("detailBtns") != undefined){
				// recipe detail
				document.getElementById("addRecipeBtn").onclick = showNonAuthenticatedMsg;
				document.getElementById("addShoppingListBtn").onclick = showNonAuthenticatedMsg;
				document.getElementById("ratingContainer").onclick = showNonAuthenticatedMsg;

				if(document.getElementById("starsContainer"))
					document.getElementById("starsContainer").getElementsByTagName('span')[0].onclick = showNonAuthenticatedMsg;
			}
			else {
				// Recipe Listing
				// assign an onclick even to all the rating cells within the mealidea list
				var divs = document.getElementById("mealideasTbl").getElementsByTagName('div');
				for (var i=0;i<divs.length;i++){
					if(divs[i].className == "postListRatingCell"){
						divs[i].onclick = showNonAuthenticatedMsg;
					}
				}
			}
		}
		
		// meal ideas
		if (sectionName == "products"){
			if (document.getElementById("detailBtns") != undefined){
				document.getElementById("addShoppingListBtn").onclick = showNonAuthenticatedMsg;
			}
		}
		
					
		// Forum  Buttons/Links
		if (sectionName == "talkMeat"){
			
			if (document.getElementById("WriteNewPost") != null)
				document.getElementById("WriteNewPost").getElementsByTagName("a")[0].onclick = showNonAuthenticatedMsg;	
			
			if (document.getElementById("forumPostTable") != null){
				var forumLinks = document.getElementById("forumPostTable").getElementsByTagName("a");
				for (var i=0;i<forumLinks.length;i++){
					forumLinks[i].onclick = showNonAuthenticatedMsg;
				}
			}
		}
	}
}


function highLight(theParent){
	
	var elm = document.getElementById(theParent);
	if (elm.className != "isCurrentPage"){
		elm.className = "selectedLink";
	}	
}

function unHighLight(theParent){

	var elm = document.getElementById(theParent);
	if (elm.className != "isCurrentPage"){
		elm.className = "";
	}
}

function showPanel (showPanel,moduleType) {

	if (typeof(moduleType) != "undefined"){
        if (moduleType == "activity"){
            if (showPanel == "recentRecipes"){
				document.getElementById("recentRecipes").style.display = "block";
				document.getElementById("recentProducts").style.display = "none";
				document.getElementById("activityLinks").getElementsByTagName("span")[0].className = "activeLink";
				document.getElementById("activityLinks").getElementsByTagName("span")[1].className = "";
			}
			else {
				document.getElementById("recentProducts").style.display = "block";
				document.getElementById("recentRecipes").style.display = "none";
				document.getElementById("activityLinks").getElementsByTagName("span")[0].className = "";
				document.getElementById("activityLinks").getElementsByTagName("span")[1].className = "activeLink";
			}
        }
    }
    else {
        if (showPanel == "mostViewedResults"){
            document.getElementById("mostViewedResults").style.display = "block";
            document.getElementById("mostCommentedResults").style.display = "none";
            document.getElementById("popularLinks").getElementsByTagName("span")[0].className = "activeLink";
			document.getElementById("popularLinks").getElementsByTagName("span")[1].className = "";
        }
        else {
            document.getElementById("mostCommentedResults").style.display = "block";
            document.getElementById("mostViewedResults").style.display = "none";
            document.getElementById("popularLinks").getElementsByTagName("span")[0].className = "";
			document.getElementById("popularLinks").getElementsByTagName("span")[1].className = "activeLink";
        }
    }
}

// displays a 'please sign-in/register to the user,
// called from various places throughout the site
function showNonAuthenticatedMsg(){
	new Lightbox.base('nonAuthenticatedMsg', { closeOnOverlayClick : true })
	return false;
}

// global variable represting the current root application path
var appPath = getAppPath();

function getAppPath()
{
	var pathname = location.pathname;
	
	var urlParts= new Array();
	urlParts = pathname.toLowerCase().split("/"); 
	
	if (urlParts[1] == "hillshirefarm"){
		return "/hillshirefarm";
	}
	else {
		return "";
	}
}



/*
    this function is for the flash from the home page, footer links
*/

function getURL(page){
switch (page) {
case "login":
	window.location = "https://www.gomeat.com/login.aspx?ReturnUrl=http://www.gomeat.com";
	break;
case "register":
	window.location = "https://www.gomeat.com/user/CreateUser.aspx?ReturnUrl=";
	break;
case "privacy":
	window.open('http://www.saralee.com/PrivacyPolicy.aspx','contactus','width=700,height=500,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes');
	break;
case "legal":
	window.open('http://www.saralee.com/LegalStatement.aspx','contactus','width=700,height=500,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes');
	break;
case "contactus":
	window.open('http://www.saralee.com/ContactUs.aspx','contactus','width=700,height=500,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes');   
	break;
case "news":
	window.location = appPath + "/NewsRss/default.aspx";
	break;
case "browseMeal":
	window.location = appPath + "/sitecontent/featured-recipe/default.aspx";
	break;	
case "recipebox":
	window.location = appPath + "/MyStuff/recipeBox.aspx";
	break;
case "shoppinglist":
	window.location = appPath + "/MyStuff/";
	break;
case "help":
	window.location = appPath + "/help/";
	break;
case "signout":
	window.location = appPath + "/logout.aspx";
	break;
case "search":
	window.location = appPath + "/search/SearchResults.aspx?q=";
	break;
default:
	window.location = appPath + "/";
}
}
 


/*
this function plays the sound when hover over the penant nav
*/
function playSound(){

	var browserName=navigator.appName; 
    if (browserName=="Microsoft Internet Explorer"){
        document.testing.playNavSound();
    } else {
        window.document.testing.playNavSound();
    }
}


/*
    this function is for the flash from the home page, search form
*/
function doSearch(searchText){
    window.location = appPath + "/search/SearchResults.aspx?q=" + searchText;
}