function ajaxFileUpload()
{
    $("#product .loading")
    .ajaxStart(function(){
        $(this).show();
    })
    .ajaxComplete(function(){
        $(this).hide();
    });
    $.ajaxFileUpload
    (
        {
            url:'product/upload/' + id,
            secureuri:false,
            fileElementId:'file',
            dataType:'json',
            success:function (data, status)
            {
                if(typeof(data.error) != 'undefined')
                {
                    if(data.error != '')
                    {
                        alert(data.error);
                    }
                    else
                    {
                        $('#product_image').html('<img src="' + data.image + '?' + Math.floor(new Date().getTime()/1000) + '" />');
                    }
                }
            },
            error:function (data, status, e)
            {
                alert(e);
            }
        }
    )
    
    return false;
}

function ajaxFileUploadExtra()
{
    $("#product .loading")
    .ajaxStart(function(){
        $(this).show();
    })
    .ajaxComplete(function(){
        $(this).hide();
    });
    $.ajaxFileUpload
    (
        {
            url:'product/upload-extra/' + id,
            secureuri:false,
            fileElementId:'file_extra',
            dataType:'json',
            success:function (data, status)
            {
                if(typeof(data.error) != 'undefined')
                {
                    if(data.error != '')
                    {
                        alert(data.error);
                    }
                    else
                    {
                        $('#product_image_extra').append('<p id="image_' + data.id + '"><img src="' + data.image + '?' + Math.floor(new Date().getTime()/1000) + '" /><a href="javascript:delete_image_extra(' + data.id + ');">Delete</a></p>');
                    }
                }
            },
            error:function (data, status, e)
            {
                alert(e);
            }
        }
    )
    
    return false;
}

function delete_image_extra(id)
{
    $.post('product/delete-image-extra', { id:id },
        function(data, status) {
            if (data.error != '')
            {
                alert(data.error);
            }
            else
            {
                $('#image_' + id).remove();
            }
        }, 'json');
}