// JScript File

function createCookie(name,value,days)
{
	var date = new Date();
	var expires = "";
	
	if (days)
	{	
		date.setTime(date.getTime()+(days*24*60*60*1000));	
		expires = "; expires="+date.toGMTString();
	}
		
	document.cookie = name +"="+ value + expires +"; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	if (readCookie(name) != null)
	{
		createCookie(name,"",-1);
	}
	
}

function removeFromFavs(productID)  {
	var currentShortlistProps, pospos;
	currentShortlistProps = readCookie("shortlistProps");
	// now extract productID from the cookie
	pospos = currentShortlistProps.indexOf("|" + productID + "|");
	strA = currentShortlistProps.substring(0, pospos);
	strB = currentShortlistProps.substring(pospos + 1);
	pospos = strB.indexOf("|");
	strC = strB.substring(pospos + 1);
	strFinal = strA + "|" + strC;
	createCookie("shortlistProps",strFinal);
	// refresh parent
	parent.window.location.href="view-favourites.aspx"
}

function removeFromBasket(productID)  {
	var currentBasket, pospos;
	currentBasket = readCookie("basketIDs");
	// now extract productID from the basket cookie
	pospos = currentBasket.indexOf("|" + productID + "|");
	strA = currentBasket.substring(0, pospos);
	strB = currentBasket.substring(pospos + 1);
	pospos = strB.indexOf("|");
	strC = strB.substring(pospos + 1);
	strFinal = strA + "|" + strC;
	createCookie("basketIDs",strFinal);
	
	//delete the product specific cookie
	eraseCookie("basketID" + productID);
		
	// refresh parent
	parent.window.location.href="basket.aspx"
}