var SiteURL = window.location.href;
var EditorDomain = "yhst-97630651591454";
var MasterDomain = "store.yahoo.com";
var AuthDomain = "fireplacescreenshop.com";
var CookieName = "Recently_Viewed_Fire";

function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
		document.cookie = curCookie;
}

function getCookie(name) {
	var prefix = name + "=";
	var cookieStartIndex = document.cookie.indexOf(prefix);
	if (cookieStartIndex == -1)
		return null;
	var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length);
	if (cookieEndIndex == -1)
		cookieEndIndex = document.cookie.length;
	return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}

function UpdateProductCookie (id, name, image, listprice, saleprice, link, map) {
	domain_check_0 = SiteURL.indexOf(EditorDomain, 0);
	domain_check_1 = SiteURL.indexOf(MasterDomain, 0);
	domain_check_2 = SiteURL.indexOf(AuthDomain, 0);
	if (((domain_check_0 != -1) && (domain_check_1 != -1)) || (domain_check_2 != -1)) {
		listprice = listprice.replace ('$', '');
		saleprice = saleprice.replace ('$', '');

		if (map == "Yes") {
			listprice = '';
			saleprice = 'Yes';
		}

		var new_product = id + '~~~' + name + '~~~' + image + '~~~' + listprice + '~~~' + saleprice + '~~~' + link;
	
		var cookie_data = getCookie(CookieName);
		var new_cookie_data = '';
	
		if (cookie_data) {
		    product_check = cookie_data.indexOf (new_product, 0);
			if (product_check == -1) {
				var products = cookie_data.split ("&&&");
		
				if (products.length == 1) {
					new_cookie_data = products[0] + '&&&' + new_product;
				} else if (products.length == 2) {
					new_cookie_data = products[0] + '&&&' + products[1] + '&&&' + new_product;
				} else if (products.length == 3) {
					new_cookie_data = products[1] + '&&&' + products[2] + '&&&' + new_product;
				}
			}
		} else {
			new_cookie_data = new_product;
		}
	
		if (new_cookie_data) {
			if (domain_check_1 != -1)
				setCookie(CookieName, new_cookie_data, 0, "/", MasterDomain);
			else if (domain_check_2 != -1)
				setCookie(CookieName, new_cookie_data, 0, "/", AuthDomain);
		}
	}
}

function ShowProduct() {
	domain_check_0 = SiteURL.indexOf(EditorDomain, 0);
	domain_check_1 = SiteURL.indexOf(MasterDomain, 0);
	domain_check_2 = SiteURL.indexOf(AuthDomain, 0);
	if (((domain_check_0 != -1) && (domain_check_1 != -1)) || (domain_check_2 != -1)) {
		var cookie_data = getCookie(CookieName);
	
		if (cookie_data) {
			var rv_html_code = '';
	
			var products = cookie_data.split ("&&&");
			rv_html_code = rv_html_code + '		<table cellspacing="0" cellpadding="3" width="100%"><tr><td colspan="2" class="header" style="color: #494949;"><span>RECENTLY VIEWED ITEMS...</span></td></tr>';
			rv_html_code = rv_html_code + '		<tr><td style="font-size: 10px; height: 10px;><img src="http://us.st1.yimg.com/store1.yimg.com/Img/trans_1x1.gif" height="10" width="1" /></td></tr>';
			for (i=0; i < 3; i++) {
				var product_properties = '';
				if (products[i])
					product_properties = products[i].split ("~~~");
	
	
				if (product_properties) {
					rv_html_code = rv_html_code + '		<tr>';
					rv_html_code = rv_html_code + '			<td valign="top" align="center"><a href="' + product_properties[5] + '">' + product_properties[2] + '</a></td>';
					rv_html_code = rv_html_code + '			<td align="left" valign="top"><a href="' + product_properties[5] + '" class="newcrosssell">' + product_properties[1] + '</a><br>';
					rv_html_code = rv_html_code + '			<img src="http://us.st1.yimg.com/store1.yimg.com/Img/trans_1x1.gif" height="16" width="1" border="0" /><font style="font-size: 11px; font-weight: bold;">List Price: $' + product_properties[3] + '</font><br>';
					rv_html_code = rv_html_code + '			<font color="#d14c05" style="font-size: 11px; font-weight: bold;">Our Price: <b>$' + product_properties[4] + '</b></font>';
					rv_html_code = rv_html_code + '			<span style="padding: 5px 5px 5px 0; display: block; font-size: 11px; font-weight: bold;"><a class="recent-viewdetails"" href="' + product_properties[5] + '">View Details</a></span></td>';
					rv_html_code = rv_html_code + '		</tr>';
	
				}
	
			}
	rv_html_code = rv_html_code + '		</table>';
		}
	
		if (rv_html_code)
			document.getElementById('show_recently_viewed_items').innerHTML = rv_html_code;
	}
}

function DeleteCookie () {
	domain_check_1 = SiteURL.indexOf(MasterDomain, 0);
	domain_check_2 = SiteURL.indexOf(AuthDomain, 0);

	if (domain_check_1 != -1)
		setCookie(CookieName, "", 0, "/", MasterDomain);
	else if (domain_check_2 != -1)
		setCookie(CookieName, "", 0, "/", AuthDomain);
}