var _webRoot = "/";

var _labelglobalized_OffertaConclusa = '';

function countDownLastSecond_onTick(periods) { 
    if ($.countdown.periodsToSeconds(periods) <= 30) {
        $(this).css('color', 'yellow');
        if ($.countdown.periodsToSeconds(periods) <= 0) {
            var formId = $('#'+ ($(this).attr('id') + '_formid')).val();
            $('#'+formId).hide();
            $(this).html(_labelglobalized_OffertaConclusa);
        }
    } else {
        $(this).css('color', 'white');
    }
}

function countDownLastSecond_onExpiry() {
    var formId = $('#'+ ($(this).attr('id') + '_formid')).val();
    $('#'+formId).hide();
    $(this).html(_labelglobalized_OffertaConclusa);
}

function addToListaDesideri(prodId, divConfirmId, divErrorAuthId, divErrorId) {
    $.ajax({
        type: 'POST',
        url: _webRoot + 'dolistadesideri.aspx',
        data: ({idop: '1', prodid: prodId}),
        cache: false,
        dataType: 'json',
        complete: function(dataReturned, s) {
            if ((typeof dataReturned != 'undefined') &&
                (dataReturned != null) &&
                (typeof dataReturned.responseText != 'undefined') &&
                (dataReturned.responseText != null) &&
                ($.trim(dataReturned.responseText) != '') &&
                ($.trim(dataReturned.responseText) != '##error@') &&
                ($.trim(dataReturned.responseText) == '##ok@')) {
                $.fn.colorbox({width:'400px', inline:true, href:'#'+divConfirmId });
            } else {
                if ($.trim(dataReturned.responseText) == '##error@_auth') {
                    $.fn.colorbox({width:'400px', inline:true, href:'#'+divErrorAuthId });
                } else {
                    $.fn.colorbox({width:'400px', inline:true, href:'#'+divErrorId});
                }
            }
        }
    });

    return false;
}

function sayToFriend(prodId, divSayToFriendId) {
    $('#'+divSayToFriendId+'_1').show();
    $('#'+divSayToFriendId+'_2').hide();
    $('#'+divSayToFriendId+'_3').hide();
    $('#'+divSayToFriendId+'_4').hide();
    $('#'+divSayToFriendId+'_prodid').val(prodId);
    $.fn.colorbox({width:'400px', inline:true, href:'#'+divSayToFriendId });
    return false;
}

function trackOffSpeciale1_Auth(prodId, divOffSpeciale1_Auth) {
    $('#'+divOffSpeciale1_Auth+'_1').show();
    $('#'+divOffSpeciale1_Auth+'_2').hide();
    $('#'+divOffSpeciale1_Auth+'_3').hide();
    $('#'+divOffSpeciale1_Auth+'_prodid').val(prodId);
    $.fn.colorbox({width:'400px', inline:true, href:'#'+divOffSpeciale1_Auth });
    return false;
}

function trackOffSpeciale2_Auth(prodId, divOffSpeciale2_Auth) {
    $.ajax({
        type: 'POST',
        url: _webRoot + 'dousertrackingoffertespeciali.aspx',
        data: ({idop: '2',  prodid: prodId }),
        cache: false,
        dataType: 'json',
        complete: function(dataReturned, s) {
            if ((typeof dataReturned != 'undefined') &&
                (dataReturned != null) &&
                (typeof dataReturned.responseText != 'undefined') &&
                (dataReturned.responseText != null) &&
                ($.trim(dataReturned.responseText) != '') &&
                ($.trim(dataReturned.responseText) != '##error@') &&
                ($.trim(dataReturned.responseText) == '##ok@')) {
                $('#'+divOffSpeciale2_Auth+'_1').show();
                $('#'+divOffSpeciale2_Auth+'_2').hide();
            } else {
                $('#'+divOffSpeciale2_Auth+'_1').hide();
                $('#'+divOffSpeciale2_Auth+'_2').show();
            }
            $.fn.colorbox({width:'400px', inline:true, href:'#'+divOffSpeciale2_Auth });
        }
    });

    return false;
}

function trackOffSpeciale2_NotAuth(prodId, divOffSpeciale2_NotAuth) {
    $('#'+divOffSpeciale2_NotAuth+'_1').show();
    $('#'+divOffSpeciale2_NotAuth+'_2').hide();
    $('#'+divOffSpeciale2_NotAuth+'_3').hide();
    $('#'+divOffSpeciale2_NotAuth+'_prodid').val(prodId);
    $.fn.colorbox({width:'400px', inline:true, href:'#'+divOffSpeciale2_NotAuth });
    return false;
}

function trackOffSpeciale3_Auth(prodId, divOffSpeciale3_Auth) {
    $('#'+divOffSpeciale3_Auth+'_1').show();
    $('#'+divOffSpeciale3_Auth+'_2').hide();
    $('#'+divOffSpeciale3_Auth+'_3').hide();
    $('#'+divOffSpeciale3_Auth+'_prodid').val(prodId);
    $.fn.colorbox({width:'400px', inline:true, href:'#'+divOffSpeciale3_Auth });
    return false;
}


function sharePage(posterPage, pUrl, vUrl, pTitle, vTitle) {
    var posterUrl = posterPage +  pUrl +'=' + vUrl + '&'+ pTitle +'=' + vTitle;
    window.open(posterUrl);
}

function printFatt(anno, numfatt) {
    var iframe = document.createElement('iframe');
    iframe.src = '/print_fatt.aspx?k1=' + anno + '&k2=' + numfatt;
    iframe.style.display = 'none';
    document.body.appendChild(iframe);
    return false;
}
function printOrd(anno, numord) {
    var iframe = document.createElement('iframe');
    iframe.src = '/print_ord.aspx?k1=' + anno + '&k2=' + numord;
    iframe.style.display = 'none';
    document.body.appendChild(iframe);
    return false;
}
