// set up to be called from the view page
function deleteItem(id)
{
    var client = new XMLHttpRequest();
    
    client.onreadystatechange = function()
    {
        if(this.readyState == 4)
        {   
            if(this.status == 200)
            {
                // remove the item from the list
                var itemList = document.getElementById('wishlist');
                var item = document.getElementById('item-' + id);
                
                itemList.removeChild(item);
                
                // update all the ranks
                pos = 0;
                
                for(var i = 0; i < itemList.length; i++)
                {
                    pos++;
                    
                    document.getElementById(itemList[i].id + '-rank').innerHTML = pos;
                }
                
                // close the floating window
                toggleFloating('delete-form', false);
            }
            else
            {
                alert('Hm... error! ' + this.status + ' ' + this.statusText);
            }
        }
    };
    
    var url = 'delete.php?id=' + id;

    client.open('GET', url, true);
    client.send();
}

// set up to be called from the edit page
function deleteItemAndRedirect(id)
{
    var client = new XMLHttpRequest();
    
    client.onreadystatechange = function()
    {
        if(this.readyState == 4)
        {   
            if(this.status == 200)
            {
                // redirect to wishlist
                window.location = '../mine';
            }
            else
            {
                alert('Hm... error! ' + this.status + ' ' + this.statusText);
            }
        }
    };
    
    var url = '../../delete.php?id=' + id;

    client.open('GET', url, true);
    client.send();
}