$(document).ready(function() {
    getCartPnP($('#ctl00_cphContent_ddlBillingCountry').val(), $('#ctl00_cphContent_lblSiteID').text());
});

function getPnP(country, siteid) {
    if (document.getElementById('ctl00_cphContent_chkUseDeliveryAddress').checked && country.id != 'ctl00_cphContent_ddlDeliveryCountry') {
        return;
    }
    $('#ctl00_cphContent_ddlBillingCountry').val(country.value);

    $.ajax({
        type: 'get',
        url: 'get_pnp.aspx?countryid=' + country.value + '&siteid=' + siteid,
        success: function(xml) {
            var x = $(xml);
            displayPnP(x.find('cost').text());
            $('p.postage-message').text(x.find("comment").text());
        }
    });
}

function getCartPnP(countryid, siteid) {

    $.ajax({
        type: 'get',
        url: 'get_pnp.aspx?countryid=' + countryid + '&siteid=' + siteid,

        success: function(xml) {
            var x = $(xml);
            displayPnP(x.find('cost').text());
            $('p.postage-message').text(x.find('comment').text());
        }
    });
}

function displayPnP(strPnP) {

    var pnp = parseFloat(strPnP.replace(',', '.'));
    document.getElementById('spnPnP').innerHTML = strPnP;//.toFixed(2);

    var subtotal, total;
    if ((subtotal = document.getElementById('spnSubtotal')) && (total = document.getElementById('spnTotal'))) {
      
        var sub = subtotal.innerHTML;
        sub = sub.replace(',', '.');
        sub = parseFloat(sub)
      
        total.innerHTML = (sub + pnp).toFixed(2);
    }
}

