<!--
var id;
var cookie_Name = "Shop_cart";
var expires = new Date (1970, 1, 1, 0, 0, 0, 0);
var cookie_Key;
var cookie_Val;
var none = "none";

var key_delim = "&";
var value_delim = "=";

//----------------------------------------------------------------------

function add_to_cart (id)
{
	var value;

	if ((value = get_cookie_key (cookie_Name, id)) == none)
		set_cookie_key (cookie_Name, id, 1);

	else
		set_cookie_key (cookie_Name, id, value);

//	alert ("|" + unescape (document.cookie.toString()) + "|");
	new_window('cart.html', 'Cart', 'scrollbars=1,menubar=1,toolbar=0,status=0,locationbar=0,width=580,height=420');

	return false;
}

//----------------------------------------------------------------------

function set_cookie_key (name, key, value)
{
	var cookie_string;

	if ((name.length < 1) || (name == none))
		return;

	if ((value == null) || (value.toString() == none))
		return;

	if ((key.length < 1) || (key == none))
	{
		setCookie (name, value);
		return;
	}

	if ((cookie_string = getCookie (name)) == none)
	{
		setCookie (name, (key + value_delim + value));
		return;
	}

	cookie_string = change_cookie (cookie_string, key, value);

	if (cookie_string.length > 0)
		setCookie (name, cookie_string);
}

//----------------------------------------------------------------------

function get_cookie_key (name, key)
{
	var cookie_string;
	var val;

	if ((name.length < 1) || (key.length < 1) || (key == null) || (key == none))
		return none;

	if ((cookie_string = getCookie (name)) == none)
		return none;

	if ((val = split_cookie (cookie_string, key)) == none)
		return none;

	else
		return val;
}

//----------------------------------------------------------------------

function kill_cookie_key (name, key)
{
	var cookie_string;

	if ((name.length < 1) || (key.length < 1) || (key == null) || (key == none))
		return;

	if ((cookie_string = getCookie (name, key)) == none)
		return;

	if (split_cookie (cookie_string, key) == none)
		return;

	cookie_string = change_cookie (cookie_string, key);

	if (cookie_string.length > 0)
	{
		setCookie (name, cookie_string);
		return;
	}

	setCookie (name, none, expires);
}

//----------------------------------------------------------------------

function change_cookie (cookie_string, key, value)
{
	var store_len, i;
	var search = key + value_delim;
	var cookie_store_index = -1;


	if (cookie_string.length < 1)
		return none;


	if (cookie_string.indexOf (key_delim) >= 0)
	{
		cookie_store = cookie_string.split (key_delim);
		if ((store_len = cookie_store.length) < 1)
			return none;
	}

	else
	{
		var cookie_store = new Array ();
		cookie_store [0] = cookie_string;
		store_len = 1;
	}

	for (i = 0; i < store_len; i++)
		if (cookie_store [i].indexOf (search) == 0)
		{
			tmp = cookie_store [i].split (value_delim);
			if ((tmp.length == 2) || (tmp [0] == key))
				cookie_store_index = i;
				break;
		}

	cookie_string = "";

	if ((value != null) && (value != none))
		cookie_store [store_len++] = key + value_delim + value;

	for (i = 0; i < store_len; i++)
	{
		if (i == cookie_store_index)
			continue;

		cookie_string += cookie_store [i];

		if ((i < (store_len - 1)) && ((store_len - ((cookie_store_index < 0) ? 0 : 1)) >= 2 ))
			cookie_string += key_delim;

//alert ("| i = " + i + " cookie_store [" + i + "] = |" + cookie_store [i] + "| cookie_string = |" + cookie_string + "|");

	}

	return cookie_string;
}

//----------------------------------------------------------------------

function split_cookie (cookie_string, key)
{
	var store_len, i;
	var search = key + value_delim;
	var cookie_store_index = -1;

	if (cookie_string.length < 1)
		return none;


	if (cookie_string.indexOf (key_delim) >= 0)
	{
		cookie_store = cookie_string.split (key_delim);
		if ((store_len = cookie_store.length) < 1)
			return none;
	}

	else
	{
		var cookie_store = new Array ();
		cookie_store [0] = cookie_string;
		store_len = 1;
	}

	for (i = 0; i < store_len; i++)
	{
		if (cookie_store [i].indexOf (search) == 0)
		{
			cookie_store_index = i;
			tmp = cookie_store [i].split (value_delim);
			if ((tmp.length != 2) || (tmp [0] != key))
				return none;

			else
				return tmp [1];
		}
	}

	return none;
}

//----------------------------------------------------------------------

// Sets cookie values. Expiration date is optional

function setCookie (name, value, expire)
{
	document.cookie = name + "=" + escape(value) + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()));
}

//----------------------------------------------------------------------

function getCookie (Name)
{
	var offset;
	var search = Name + "=";

	if (document.cookie.length > 0)
	{
//
// if there are any cookie
//

		offset = document.cookie.indexOf (search);
		if (offset != -1)
		{
//
// if cookie exists
//
			offset += search.length;
//
// set index of beginning of value
//
			end = document.cookie.indexOf (";", offset);
//
// set index of end of cookie value
//
			if (end == -1)
				end = document.cookie.length;

			return unescape(document.cookie.substring(offset, end));
		}

		else
			return none;
	}

	else
		return none;
}

//----------------------------------------------------------------------
//-->

