function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
  {
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
}

function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}

function checkCookie()
{
var username=getCookie("username");
if (username!=null && username!="")
  {
  alert("Welcome again " + username);
  }
else
  {
  username=prompt("Please enter your name:","");
  if (username!=null && username!="")
    {
    setCookie("username",username,365);
    }
  }
}
$(document).ready(function(){
var thisURL = window.location.href.split("/");
//Check to see if Subcategory page
var urlname = thisURL[3].split("?")[0];
if (urlname == 'cart.htm') {
	setCookie("asin_str", "", 1);
	setCookie("sku_str", "", 1);
	
	var asin_str = '';
	var sku_str = '';
	
	$("tr.itemInfo").each(function(i){
		//var link = $(this).children(".itemImage").children("a").attr("href");
		var link = $(this).find(".itemName").children("strong").children("a").attr("href");
		var asinLink = link.split("/")[3];
		var asin = asinLink.split(".")[0];
		asin_str += asin + ",";

		if ($(this).find(".itemSKU").length > 0) {
			$(this).find(".itemSKU").children("strong").remove();
			var sku = $(this).find(".itemSKU").text();
		}
		else {
			var sku = 'Assoc';
		}
		sku_str += sku + ",";
	});
	var asin_str = asin_str.substring(0, asin_str.length-1);
	var sku_str = sku_str.substring(0, sku_str.length-1);
	
	setCookie("asin_str", asin_str, 1);
	setCookie("sku_str", sku_str, 1);
	
	/*var asin_str = getCookie("asin_str");
	var asinstring = new Array();
	asinstring = asin_str.split(",");
	$.each(asinstring, function(asinindex, asinval){
			alert("asin: " + asinval + ", ");
		});*/
}

if (urlname == 'orderConfirmation.htm') {
	/*var asin_str = getCookie("asin_str");
	var sku_str = getCookie("sku_str");
	
	var asinstring = new Array();
	var skustring = new Array();
	
	asinstring = asin_str.split(",");
	skustring = sku_str.split(",");
	
	var orderArray = [];
	orderArray = wba_confirmation.order[0];
	
	var orderID = orderArray.orderId;
	
	var productArray = [];
	productArray = orderArray.product[0];
	
	var skulist = '';

	$.each(orderArray.product, function(idy, child){
		var asin = child.asin;
		var price = child.price;
		$.each(asinstring, function(asinindex, asinval){
			if (asinval == asin) {
				setCookie("correctIndex", asinindex, 1);
			}
		});
		var correctIndex = getCookie("correctIndex");
		$.each(skustring, function(skuindex, skuval){
			if (skuindex == correctIndex) {
				setCookie("correctSku", skuval, 1);
			}
		});
		var correctSku = getCookie("correctSku");
		skulist += orderID + ", " + correctSku + ", " + price + "; ";
	});

	var skulist = skulist.substring(0, skulist.length-2);

	var aid='9312';
	var oid=skulist; 
	var oamt=$("td#totalValue").text(); 
	var additional = ''; 
	(function(){steelhouse={add:function(a,b,c,d){d=d||false;if(a.addEventListener){a.addEventListener(b,c,d)}else if(a.attachEvent){a.attachEvent("on"+b,c)}},load:function(){var a;if(typeof a=='undefined'){a=Math.random()*10000000000000000}var b=document.createElement('script');var c='px.steelhousemedia.com/st?aid='+aid+'&conv=1&order_id='+oid+'&order_amt='+oamt+'&cb='+a+additional;b.type='text/javascript';b.src=('https:'==document.location.protocol?'https://':'http://')+c;var d=document.getElementsByTagName('script');var e=Number(d.length)-1;var f=document.getElementsByTagName('script')[e];f.parentNode.insertBefore(b,f)}};steelhouse.load();})();

	setCookie("asin_str", "", 1);
	setCookie("sku_str", "", 1);*/
}

});

