function getName(cookie_name) {
	if(document.cookie) {
		index = document.cookie.indexOf(cookie_name);
		if (index != -1) {
			namestart = (document.cookie.indexOf("=", index) + 1);
			nameend = document.cookie.indexOf(";", index);
			if (nameend == -1) {nameend = document.cookie.length;}
			myVar = document.cookie.substring(namestart, nameend);
			return myVar;
		}
	}
	else {
		return 'stop';
	}
}

function checkCookie(cookie_name, value) {
	if(document.cookie) {
		index = document.cookie.indexOf(cookie_name);
		if (index != -1) {
			namestart = (document.cookie.indexOf("=", index) + 1);
			nameend = document.cookie.indexOf(";", index);
			if (nameend == -1) {
				nameend = document.cookie.length;
			}
			myVar = document.cookie.substring(namestart, nameend);
			if (myVar != value) {
				var exp = new Date()
				var nowPlusOneYear = exp.getTime() + (1000 * 60 * 60 * 24 * 365)
				exp.setTime(nowPlusOneYear)
				document.cookie= cookie_name+"="+ value +"; expires=" + exp.toGMTString() + "; path=/; domain=pwmarkets.com";
			}
		}
	}
	else {
		var exp = new Date()
		var nowPlusOneYear = exp.getTime() + (1000 * 60 * 60 * 24 * 365)
		exp.setTime(nowPlusOneYear)
		document.cookie= cookie_name+"="+ value +"; expires=" + exp.toGMTString() + "; path=/; domain=pwmarkets.com";
	}
}

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=pwmarkets.com";
	if(cookie_name == "fav"){
		alert("This recipe has been added to your saved recipes section");
	}
}

function deleteFromCookie(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 = "";
	}
	value = value + "|";
	//alert(value);
	//alert(cookieString);
	//
	//var re = new RegExp (value, 'gi') ;
	cookieString = cookieString.replace(value, '') ;
	//
	x="yes";
	while(x=="yes"){
		if(cookieString.indexOf("||") != -1){
			cookieString = cookieString.replace('||', '|') ;
		}else{
			x="no";
		}
	}
	var exp = new Date()
	var nowPlusOneYear = exp.getTime() + (1000 * 60 * 60 * 24 * 365)
	exp.setTime(nowPlusOneYear)
	document.cookie= cookie_name+"="+ cookieString + "; expires=" + exp.toGMTString() + "; path=/; domain=pwmarkets.com";
	if(cookie_name == "fav"){
		alert("This recipe has been deleted from your saved recipes section");
		window.location.reload();
	}
}

//recipe print page function, called from flash recipeNav, printable Version button
function openPrint() {
	 myleft=(screen.width)?(screen.width-700)/2:100;
     myNewWin = window.open("http://www.pwmarkets.com/cooking/recPrintable.html", "printRecipe", "scrollbars=1, width=700, height=700, left="+myleft+", top=10");
	 myNewWin.focus();
}

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

//recipe send to friend function, called from flash recipeNav
function launchRecipeMail() {
	myleft=(screen.width)?(screen.width-400)/2:100;
     myNewWin2 = window.open("http://www.pwmarkets.com/cooking/recipeMailForm.html", "recipeMail", "width=400, height=350, left="+myleft+", top=40");
	 myNewWin2.focus();
}

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