var expDays=60;
var expDate = new Date();
var cookieName = "Recently viewed";
var priceText = "Regular price:";
var salePriceText = "Sale ";
var orderableText = "Out of stock";
expDate.setTime(expDate.getTime()+(expDays*24*60*60*1000))

function setCookie(name,id,imageurl,price,saleprice,option,orderable)
{
	var theCookie,totalCookie,nextCookie,cookieArray;
	var ctr = 0 ;
	var recentItemArray = new Array();
	var the_cookie = unescape(document.cookie);
	if(the_cookie.indexOf(id) > -1)
	{
		var exists = true;
	}
	else
	{
		theCookie = escape("productName:" + name + "|id:"  + id + "|imageurl:" + imageurl + "|sp:" + saleprice + "|p:" + price + "|opt:" + option + "|out:" + orderable) + "; expires=" + expDate.toGMTString() + "; path=/";
		if(the_cookie.length > 0)
		{
			var cookieArray = the_cookie.split(";");
			for(i=0;i<cookieArray.length;i++)
			{
				if(cookieArray[i].indexOf(cookieName) > -1)
				{
					recentItemArray[ctr] = cookieArray[i];
					ctr = ctr + 1;
				}
			}
			if(ctr > 0)
			{
				for(i=0;i<ctr;i++)
				{
					if(i == 4) break;
					nextCookie = i + 1;
					passCookie = recentItemArray[i].split("=");
					document.cookie = cookieName + nextCookie + "=" + passCookie[1] + "; expires=" + expDate.toGMTString() + "; path=/";
				}
				document.cookie = cookieName + "0=" + theCookie;
			}
			else
			{
				document.cookie = cookieName + "0=" + theCookie;
			}
		}
		else
		{
			document.cookie = cookieName + "0=" + theCookie;
		}
	}
}

function writeCookie()
{
	var name,id,imageurl,price,saleprice,option,orderable,Lname,Lid,Limageurl,Lprice,Lsaleprice,Loption,Lorderable,cookieVal;
	Lname = "productName:";
	Lid = "id:";
	Limageurl = "imageurl:";
	Lprice = "p:";
	Lsaleprice = "sp:";
	Loption = "opt:";
	Lorderable = "out:";
	var nvp = new Array();
	var recentItemArray = new Array();
	var the_cookie = unescape(document.cookie);
	var ctr = 0 ;
	if(the_cookie.length > 0)
	{
		var cookieArray = the_cookie.split(";");
		for(i=0;i<cookieArray.length;i++)
		{
			if(cookieArray[i].indexOf(cookieName) > -1)
			{
				recentItemArray[ctr] = cookieArray[i];
				ctr = ctr + 1;
			}
		}
		if(recentItemArray.length>0)
		{
			//for(j=0;j<recentItemArray.length;j++)
			for(j=0;j<3;j++)
			{
				name = "";
				id = "";
				imageurl = "";
				price = "";
				saleprice = "";	
				option = "";
				orderable = "";
				cookieVal = unescape(recentItemArray[j])
				nvp = cookieVal.split("=");
				nvp = nvp[1].split("|");
				for(k=0;k<nvp.length;k++)
				{
					if(nvp[k].indexOf("productName:") > -1)
						name = nvp[k].substr(Lname.length);
					if(nvp[k].indexOf("id:") > -1)
						id = nvp[k].substr(Lid.length);
					if(nvp[k].indexOf("imageurl:") > -1)
						imageurl = nvp[k].substr(Limageurl.length);
					if(nvp[k].indexOf("sp:") > -1)
						saleprice = nvp[k].substr(Lsaleprice.length);
					if(nvp[k].indexOf("p:") > -1)
						price = nvp[k].substr(Lprice.length);
					if(nvp[k].indexOf("opt:") > -1)
						option = nvp[k].substr(Loption.length);
					if(nvp[k].indexOf("out:") > -1)
						orderable = nvp[k].substr(Lorderable.length);
				}
				document.write("<div class='you_may_also_like_product_area'><div class='you_may_also_like_product_area-img'><a href=" + id + "><img src=" + imageurl + " alt=" + name + " vspace='0' align='center' border='0' hspace='0'></a></div><p><a href=" + id + ">" + name + "</a></p>");
				
			
			if(option == "Y")
			{
				document.write("<div class='more-options'>More Colors</div>");
			}
				
			if(price != "" && saleprice != "")
			{
				document.write("<div class='swa-price-box-2'>");
					document.write("<div class='swa-price'>");
						document.write("Sale "+ saleprice + "<br><span>Orig. <span>" + price +"</span></span>");
					document.write("</div>");
				document.write("</div>");
			}
			else
			{
				if(price != "")
				{
					document.write("<div class='swa-price-box-2'>");
					document.write("<div class='swa-price'><span>");
					document.write(price);
					document.write("</span></div>");
					document.write("</div>");
				}
				if(saleprice != "")
				{
					document.write("<div class='swa-price-box-2'>");
					document.write("<div class='swa-price'>");
					document.write("Sale " + saleprice +"");	
					document.write("</div>");
					document.write("</div>");
				}
			}
			
			document.write("</div>");
			if(j<2)
			{
				document.write("<div class='you_may_also_like_product_area_space'></div>");
			}
		
			}
			
		}
	}
}
