var expDays=60;
var expDate = new Date();
var cookieName = "Recently viewed";
var headlinetText = "Headline:";
var priceText = "Regular price:";
var salePriceText = "Sale price:";
expDate.setTime(expDate.getTime()+(expDays*24*60*60*1000))

function setCookie(name,id,headline,imageurl,price,saleprice){
	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 + "|ProductHeadline:" + headline + "|imageurl:" + imageurl + "|price:" + price + "|salepric:" + saleprice) + "; 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 == 2) 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,headline,imageurl,price,saleprice,Lname,Lid,Lheadline,Limageurl,Lprice,Lsaleprice,cookieVal
	Lname = "productName:";
	Lid = "id:";
	Lheadline = "ProductHeadline:";
	Limageurl = "imageurl:";
	Lprice = "price:";
	Lsaleprice = "salepric:";
	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){
document.write("<div class='pro-description-heading'>Recently Viewed Items</div><div class=\'spacer-img\'><img src=\'http://yst.bnssupply.com/images/spacer.gif\' alt=\' B&amp;S Supply\' width=\'30\' height=\'29\' class=\float-left\" /></div><div class='pro-recently-viewed-area'><div class='fp-pro-recentl-viewed-area'>");
				for(j=0;j<recentItemArray.length;j++){
				name = "";
				headline = "";
				id = "";
				imageurl = "";
				price = "";
				saleprice = "";							
				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("ProductHeadline:") > -1)
						headline = nvp[k].substr(Lheadline.length);
					if(nvp[k].indexOf("imageurl:") > -1)
						imageurl = nvp[k].substr(Limageurl.length);
					if(nvp[k].indexOf("price:") > -1)
						price = nvp[k].substr(Lprice.length);
					if(nvp[k].indexOf("salepric:") > -1)
						saleprice = nvp[k].substr(Lsaleprice.length);
				}

document.write("<div class='fp-pro-box-area'><div class='fp-pro-bor-box'><div class='fp-pro-img'><span class='inner_span_1'></span><span class='inner_span_2'><a href=" + id + "><img src=" + imageurl + " vspace='0' border='0' hspace='0'></a></span></div></div><div class='pro-listing-text'><span><a href=" + id + ">" + name + "</a></span>" + headline + "</div><div class='fp-regular-sale-area'><div class='fp-regular-lft-area'>Regular price:<span>"+ price +"</span></div><div class='fp-regular-right-area'>Sale price:<span>"+ saleprice +"</span></div></div><div class='add-to-cart-img'><a href=" + id + "><img src=\"http://yst.bnssupply.com/images/add-to-cart-img.jpg\" alt=\"Add To Cart\" height=\"14\" width=\"86\" /></a></div></div>");


	
	if(j<2){
	document.write("<div class=\"spacer-img\"><img src=\"http://yst.bnssupply.com/images/spacer.gif\" alt=\" B&amp;S Supply\" width=\"39\" height=\"1\" class=\"float-left\" /></div>");
	}

}

//	if(j>0){

	document.write("</div></div>");
	
	//}
}
}
}
