function saveToList(listingid, type, me, dosave)
{
	/*if(type == 1002 && dosave == null)
	{
		selectList(listingid, me);
		return;
	} */
	
	new Ajax("/lists/save.cfm?id=" + listingid + "&type=" + type, {
			method: 'get', evalScripts: true,
			onComplete: function() {
					/*
					me.innerHTML = me.innerHTML.replace(/add.png/g,"added.png");
					me.innerHTML = me.innerHTML.replace(/Add /g,"Added ");
					me.style.color = "green";
					*/
					if (me.tagName == "TR") {
						var row = me.parentNode.insertRow(me.rowIndex);
						me.parentNode.deleteRow(me.rowIndex);
						
						var iconcell = row.insertCell(0);
						iconcell.className = "icon_cell";
						iconcell.noWrap = true;
						iconcell.innerHTML = '<img border="0" src="/maps/infocard/shoppinglist_added.png">';
						
						var labelcell = row.insertCell(1);
						labelcell.className = "label_cell";
						labelcell.noWrap = true;
						labelcell.innerHTML = "<a title='Saved to List' href='javascript:void(0);'>Saved to List</a> (<a href='/lists/?show=businesses'>view list</a>)";
					}
					if(me.tagName == "A")
					{
						me.title = "Saved to List";
						me.innerHTML = "<div style=\"background-image: url('/maps/infocard/shoppinglist_added.png'); width: 16px; height: 16px;\"></div>";
					}
					if(me.tagName == "TD")
					{
						me.title = "Saved to List";
						me.innerHTML = "<div style=\"background-image: url('/maps/infocard/shoppinglist_added.png'); width: 16px; height: 16px; margin:2px;\"></div>";
					}
				}
		}).request();
}

function removeFromList(listingid, type, me)
{
	new Ajax("/lists/remove.cfm?itemid=" + listingid + "&type=" + type, {
			method: 'get', evalScripts: true,
			onComplete: function(){
					/*
						me.innerHTML = me.innerHTML.replace("Remove ","Removed ");
						me.title = me.title.replace("Remove ","Removed ");
						me.style.color = "#D10000";
					*/
					// Needs to be patched up for none listings.
					$("listing_" + listingid).remove();
				}
		}).request();
}

function saveToWishList(listid, itemid, me)
{
	new Ajax("/lists/SaveToWishList.cfm?listid=" + listid + "&itemid=" + itemid,{
		method: 'get',
		onComplete: function()
		{
			if(me.tagName == "TD")
			{
				me.title = "Saved to List";
				me.innerHTML = "<div style=\"background-image: url('/maps/infocard/shoppinglist_added.png'); width: 16px; height: 16px; margin:2px;\"></div>";
			}
		}
	}).request();
}

function removeFromWishList(listid, itemid)
{
	new Ajax("/lists/RemoveFromWishList.cfm?listid=" + listid + "&itemid=" + itemid, {
			method: 'get',
			onComplete: function(){
					$("listItem_" + itemid).remove();
				}
		}).request();
}

function selectList(itemListing, me)
{
	/*
	AddToListButton = me;
	
	if(typeof(WishListPicker) == 'undefined') readyWishListPicker();
	
	new Ajax("/lists/SelectWishList.cfm?itemid=" + itemListing + "&t=" + (new Date).getTime(),{
		method: 'get', update: $(WishListPicker),
		onComplete: function()
		{
			var p = $(AddToListButton).getPosition();
			WishListPicker.style.top = p.y + "px";
			WishListPicker.style.left = p.x + "px";
			PickerContainer.style.display="block";
			$(AddToListButton).blur();
		}
	}).request();
	
	*/
	
	GB_showCenter("Save To Gift Registry","/lists/SelectWishList.cfm?itemid=" + itemListing + "&t=" + (new Date).getTime());
}


function readyWishListPicker()
{
	PickerContainer = document.createElement('DIV');
	PickerContainer.style.position = "absolute";
	PickerContainer.style.top = 0;
	PickerContainer.style.bottom = 0;
	PickerContainer.style.left = 0;
	PickerContainer.style.right = 0;
	PickerContainer.style.zIndex = 1000;
	PickerContainer.style.display = "none";
	
	PickerContainer.onclick = function()
	{	PickerContainer.style.display = "none"; };
	document.body.style.position = "relative";
	document.body.appendChild(PickerContainer);
	
	WishListPicker = document.createElement('DIV');
	WishListPicker.style.position = "absolute";
	WishListPicker.style.display = "block";
	PickerContainer.appendChild(WishListPicker);
}
