/* Recently Viewed - @ FAST PIVOT @ */

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

function setCookie(name,id,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 + "|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 == 3) 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,Lname,Lid,Limageurl,Lprice,Lsaleprice,cookieVal
	Lname = "productName:";
	Lid = "id:";
	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("<table width='592' border='0' align='left' cellpadding='0' cellspacing='0'><tr><td align='left' valign='top' class='rv-head-line'><img src='http://lib.store.yahoo.net/lib/about-wigs/rv-head-img.jpg' alt='' width='141' height='29' border='0' /></td></tr><tr><td align='center' valign='top'><img src='http://lib.store.yahoo.net/lib/about-wigs/spacer.gif' alt='' width='1' height='14' border='0' /></td></tr><tr><td align='left' valign='top'><table width='136' border='0' align='left' cellpadding='0' cellspacing='0'><tr>");
				for(j=0;j<recentItemArray.length;j++){
				name = "";
				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("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);
				}

if(powerReviews){

	var aid = id.replace(".html", "");

	document.write("<td width='136' align='center' valign='top'><table width='136' border='0' align='center' cellpadding='0' cellspacing='0'><tr><td align='center' valign='top'><a href=" + id + "><img src=" + imageurl + " alt='' border='0' /></a></td></tr><tr><td height='33' align='center' valign='top'><span class='pro-name'><a href=" + id + ">" + name + "</a></span></td></tr><tr><td align='center' valign='top' class='yp-txt'>Your Price: " + price + "</td></tr><tr><td align='center' valign='top'><div class='pr_snippet_category'><script type=text/javascript>var pr_snippet_min_reviews=0; try{POWERREVIEWS.display.snippet(document, { pr_page_id : '" + aid + "' });}catch(err){}</script></div></td></tr></table></td>");

} else {

	document.write("<td width='136' align='center' valign='top'><table width='136' border='0' align='center' cellpadding='0' cellspacing='0'><tr><td align='center' valign='top'><a href=" + id + "><img src=" + imageurl + " alt='' border='0' /></a></td></tr><tr><td height='33' align='center' valign='top'><span class='pro-name'><a href=" + id + ">" + name + "</a></span></td></tr><tr><td align='center' valign='top' class='yp-txt'>Your Price: " + price + "</td></tr></table></td>");

}

if(j<3){
	document.write("<td align='left' valign='top' width='16'><img src='http://lib.store.yahoo.net/lib/about-wigs/spacer.gif' alt='' width='16' height='1'/></td>");
	}
				}
document.write("</tr></table></td></tr></table>");
			
		}		
						
	}
}
