function renameList(id) {
    var listform = document.forms["list_edit_"+id];
    var listlink = $("listlink_"+id);
    var share = $("share_"+id);
    var abort = $("abort_"+id);
    var rename = $("rename_"+id);
    
	// $("drag_" + id).hide();
   
    listform.style.display = 'inline';
    listlink.style.display = 'none';
    share.style.display = 'none';
    rename.style.display = 'none';
    abort.style.display = 'inline';
    
    abort.onclick = function() {
        listform.style.display = 'none';
        listlink.style.display = 'inline';
        share.style.display = 'inline';
        rename.style.display = 'inline';
        abort.style.display = 'none';
        return false;
    }
}

function setListShare(id, checked)
{
    var action = checked ? 'share' : 'unshare';
    document.location.href = '?' + action + '=' + id;
}

function favAction(choice) {
    var tolist = $('tolist');
    var addnote = $('addnote');
    
    if (choice == 'move' || choice == 'copy') {
        tolist.style.display = 'inline';    
        addnote.style.display = 'none';
    } else if (choice == 'add') {
        tolist.style.display = 'none';
        addnote.style.display = 'inline';
    } else {
        tolist.style.display = 'none';
        addnote.style.display = 'none';
    }
}
/*
function dupAction() {
    var choice = $('dest').selectedIndex;
    var target = $('newlist');
    if (choice == 1) {
        target.style.display = 'inline';    
    } else {
        target.style.display = 'none';  
    }
}
*/
function dupAction() {
    var choice = $('targetID').selectedIndex;
    var target = $('newlist');
    var submit = $('copySubmit');

    if (choice == 1) {
        target.style.display = 'inline';
        submit.style.display = 'none';
    } else {
        target.style.display = 'none';  
        submit.style.display = 'inline';
    }
}

function validateSimpleList()
{
	var fields = $$('input.qty');
	var numitems = 0;
	for (var i = fields.length - 1; i >= 0; i--)
	{
		if (! checkQuantityValue(fields[i].value))
		{
			alert('You have entered an invalid quantity value.');
			return false;
		}

		if (fields[i].value.length && fields[i].value != 0)
		{
			++numitems;
		}
	}

	if (numitems == 0)
	{
		alert('You have not entered any quantities.');
		return false;
	}

	return true;
}

function onSubmitAddToListForm(field,listID)
{
	try
	{
		var errormsg = 'Unable to add item to list.';

		field.value = trim(field.value);

		if (field.value.length == 0)
		{
			alert('Please enter the item\'s sku.');
			return;
		}

		if ($('qty_each_' + field.value))
		{
			alert('That item is already in the list.');
			return;
		}

		var req = new Ajax.Request('/_ajax/addtolist.cfm',
		{
			method: 'post',
			parameters: {sku:field.value,shoplist:listID},
			onSuccess: function(data)
			{
				if (data.responseJSON)
				{
					if (data.responseJSON.success)
					{
						document.location.href = '/account/list_simple.cfm?listID='+listID;
					}
					else if (data.responseJSON.message)
					{
						alert(data.responseJSON.message);
					}
					else
					{
						alert(errormsg);
					}
				}
				else
				{
					alert(errormsg);
				}
			},
			onFailure: function(data)
			{
				alert(errormsg);
			}
		});
	}
	catch (err)
	{
		alert(errormsg);
	}
}
