function updateShippingMethod(url, id)
{
    var now = new Date();
    var params = 'shippingMethodId='+ id + '&rt=' + now.getMilliseconds();
    createAjaxRequest(url, params, handleUpdateShippingMethod);
}

function handleUpdateShippingMethod(response)
{
    var responseHtml = processHtmlResponse(response);

    if (COMMONS.isDefined(responseHtml) && responseHtml != "")
    {
        var insertSpan = $('#totals');
        insertSpan.html(responseHtml);
    }
}

function closeLargeImage()
{
    var table = $('#divLargeImageTable');
    if (table !== null && table !== undefined)
    {
        table.css('display', 'none');
    }
    updateLargeGallery(gallery.currentIndex);
}

/**
 * Will center view large image window inside browser window
 * @param div
 */
function centerLargeImageTable(div)
{
    var marginTop = Math.round(($(window).height() - div.height()) / 2.0);
    if (marginTop < 0)
    {
        // if image is too big, use same padding as we have in the bottom 
        marginTop = div.css('marginBottom');
    }

    div.css('marginTop', marginTop);
}

function showLargeImage()
{
    switchImageCallback();

    var table = $('#divLargeImageTable');

    var div = $('#idLargeImage');
    if (COMMONS.isDefined(div))
    {
        table.css('display', '');
        centerLargeImageTable(div);
    }
}

function showLargeImage2(index)
{
    switchImageCallback();

    var table = $('#divLargeImageTable');

    var div = $('#idLargeImage');

    if (div !== null && div !== undefined)
    {
        updateLargeGallery(index);
        table.css('display', '');
        centerLargeImageTable(div);
    }
}

/**
 * This function startes zoomMode.
 * @param index index of current td (0 = first 'td')
 */
function showZoomedImage(index)
{
    // parse link of large image
    var elemA = $("#zoomImageHolder" + index).find("a");
    var hrefToSet = elemA.attr("href");

    var zooma = $('div#slideshow').zooma('slideshow', 'zoomBlock', hrefToSet);
    zooma.activate();
}

function handleProductDetailsImageClick() {
    if (zoomModeEnabled)
    {
        showZoomedImage(gallery.currentIndex);
        /* if zoom is enabled, we don't need to do anything */
        return;
    }
    if (enlargeModeEnabled)
    {
        showLargeImage2(gallery.currentIndex);
        /* if enlarge image is enabled, we don't need to do anything */
        return;
    }
}

/**
 * We will switch both galleries at the same, to open large gallery with correct image selected
 * @param index - index to set in large gallery
 */
function updateLargeGallery(index)
{
    // expected global variable 'galleryLarge'
    if (galleryLarge.currentIndex != index)
    {
        galleryLarge.goto(index);
    }
}

function switchImageCallback()
{
    $('#zoomViewfinder').hide();
    $('#zoomBlock').hide();


    updateLargeGallery(gallery.currentIndex);
}

function showProgress()
{
    $('#divProgressBar').css('display', '');
    return true;
}

function showPaymentInProgress()
{
    $('#divPaymentProcessingProgress').css('display', '');
    return true;
}

