//IMPORTANT:   Change domain in Line 51 !!!!!
myRecName = "";
function changeTitle(title){
weeklyrec = location.search ? unescape(location.search.substring(1)):'none';
if (weeklyrec != "none") {
	if(weeklyrec.indexOf("&") != -1){
	title = weeklyrec.substring(weeklyrec.indexOf("&")+1);
	document.title = "This Week's "+title+" Recipe";
	}else{
	document.title = title;
	}
}
}

myName = document.location.href;

equals = myName.indexOf("=");
and = myName.indexOf("&");
	if (and != -1){
	recID = myName.substring(equals+1, and);
	}else{
	recID = myName.substring(equals+1);
	}
myRecName = recID;

newDay = "";
var dude;
myleft=(screen.width)?(screen.width-400)/2:100;
settings = "statusbar=0,scrollbars=0,menubar=0,resizable=1,top=30,left=" + myleft + ",width=400,height=250";
//
function writeTheDay (theDay) {
cookie_name = "addDay"
		var exp = new Date()
		var nowPlusOneYear = exp.getTime() + (1000 * 60 * 60 * 24 * 365)
		exp.setTime(nowPlusOneYear)
		document.cookie= cookie_name+"="+ theDay +"; expires=" + exp.toGMTString() + "; path=/; domain=sprouts.com";
		document.location = "menuPlanner.php"
}
//
function addMe () {
		index = document.cookie.indexOf('addDay');
		if (index != -1) {
			namestart = (document.cookie.indexOf("=", index) + 1);
			nameend = document.cookie.indexOf(";", index);
			if (nameend == -1) {
				nameend = document.cookie.length;
			}
			myDayVar = document.cookie.substring(namestart, nameend);
			if (myDayVar == "zip" && newDay == "") {
				dude = window.open("chooseDay.html?"+myRecName, "Choose", settings);
				dude.focus();
				return;
			}
			
		}else if (newDay == ""){
		dude = window.open("chooseDay.html?"+myRecName, "Choose", settings);
		dude.focus();
		return;
		}else {
		myDayVar = newDay;
		//alert(myDayVar);
		dude.window.close();
		}
		if (myDayVar == "zip") {
			myDayVar = newDay;
			//alert(myDayVar);
			dude.window.close();
		}
		index = document.cookie.indexOf('addDay');
		notCookieStringStart = document.cookie.substring(0, index);
		notCookieStringEnd = document.cookie.substring(index+11);
		notCookieString = notCookieStringStart+notCookieStringEnd;
		//
		index = notCookieString.indexOf(myDayVar);
		if (index != -1) {
			namestart = (notCookieString.indexOf("=", index) + 1);
			nameend = notCookieString.indexOf(";", index);
			if (nameend == -1) {
				nameend = notCookieString.length;
			}
			myVar = notCookieString.substring(namestart, nameend) +  ",";
			//alert(notCookieString.substring(namestart, nameend));
			if (notCookieString.substring(namestart, nameend) == myDayVar){
				myVar = "";
			}
		}else{
			myVar = "";
		}
		
		cookie_name = myDayVar;
		var exp = new Date()
		var nowPlusOneYear = exp.getTime() + (1000 * 60 * 60 * 24 * 365)
		exp.setTime(nowPlusOneYear)
		document.cookie= cookie_name+"="+ myVar + myRecName +"; expires=" + exp.toGMTString() + "; path=/; domain=sprouts.com";
		writeTheDay ('zip');
		//document.location = "/recipe/MenuPlanner.html"
}

function txtMe (pageName) {
		//mypageNameEnd =  pageName.lastIndexOf(".");
		myRecName = pageName;
		index = document.cookie.indexOf('addDay');
		if (index != -1) {
			namestart = (document.cookie.indexOf("=", index) + 1);
			nameend = document.cookie.indexOf(";", index);
			if (nameend == -1) {
				nameend = document.cookie.length;
			}
			myDayVar = document.cookie.substring(namestart, nameend);
			if (myDayVar == "zip" && newDay == "") {
				dude = window.open("chooseDay.html?"+myRecName, "Choose", settings);
				dude.focus();
				return;
			}
		}else if (newDay == ""){
			
			dude = window.open("chooseDay.html?"+myRecName, "Choose", settings);
			dude.focus();
			return;
		}else {
			myDayVar = newDay;
			//alert(myDayVar);
			dude.window.close();
		}
		if (myDayVar == "zip") {
		myDayVar = newDay;
		//alert(myDayVar);
		dude.window.close();
		}
		index = document.cookie.indexOf('addDay');
		notCookieStringStart = document.cookie.substring(0, index);
		notCookieStringEnd = document.cookie.substring(index+11);
		notCookieString = notCookieStringStart+notCookieStringEnd;
		//
		index = notCookieString.indexOf(myDayVar);
		if (index != -1) {
			namestart = (notCookieString.indexOf("=", index) + 1);
			nameend = notCookieString.indexOf(";", index);
			if (nameend == -1) {
				nameend = notCookieString.length;
			}
			myVar = notCookieString.substring(namestart, nameend) +  ",";
			//alert(notCookieString.substring(namestart, nameend));
			if (notCookieString.substring(namestart, nameend) == myDayVar){
				myVar = "";
			}
		}else{
			myVar = "";
		}
		
		cookie_name = myDayVar;
		var exp = new Date()
		var nowPlusOneYear = exp.getTime() + (1000 * 60 * 60 * 24 * 365)
		exp.setTime(nowPlusOneYear)
		document.cookie= cookie_name+"="+ myVar + myRecName +"; expires=" + exp.toGMTString() + "; path=/; domain=sprouts.com";
		writeTheDay ('zip');
		//document.location = "MenuPlanner.html"
}

function setCookie(cookie_name, value) {
	index = document.cookie.indexOf(cookie_name);
	if(index != -1){
		fromCookieToEnd = document.cookie.substring(index);
		nextCookieStart = fromCookieToEnd.indexOf(";");
		if(nextCookieStart == -1){
			nextCookieStart = fromCookieToEnd.length;
		}
		cookieStart = fromCookieToEnd.indexOf("=");
		cookieString = fromCookieToEnd.substring(cookieStart+1,nextCookieStart);
	}else{
		cookieString = "";
	}
	//
	var exp = new Date()
	var nowPlusOneYear = exp.getTime() + (1000 * 60 * 60 * 24 * 365)
	exp.setTime(nowPlusOneYear)
	document.cookie= cookie_name+"="+ value + "|" + cookieString + "; expires=" + exp.toGMTString() + "; path=/; domain=sprouts.com";
	alert("This recipe has been added to your favorites section");
}

//recipe print page function for php recipes, called from flash event page printable version button
function openPHPprint(recID,loc) {
	 myleft=(screen.width)?(screen.width-700)/2:100;
     myNewWin = window.open("recPrintable.php?recID="+recID+"&location="+loc, "printRecipe", "scrollbars=1, width=700, height=700, left="+myleft+", top=10");
	 myNewWin.focus();
}

//recipe send to friend function for php recipes, called from flash event pages
function launchPHPRecipeMail(recID,loc) {
	myleft=(screen.width)?(screen.width-700)/2:100;
     myNewWin2 = window.open("recipeMailForm.php?recID="+recID+"&location="+loc, "recipeMail", "width=700, height=750, left="+myleft+", top=40");
	 myNewWin2.focus();
}