$().ready(function(){
  $('#incex-vat-prices-toggle-link').attr('href', 'javascript:void(0);').click(toggleincexvatprices);
});

function toggleincexvatprices() {
  var link = $('#incex-vat-prices-toggle-link');
  var mode="inc";
  if (/inc/i.test(link.text())) {
    link.text('Show Ex VAT Prices');
  } else {
    link.text('Show Inc VAT Prices');
    mode="ex";
  }
  $('.switchable-price').each(function(){
    var sp = $(this);
    var inp = $('input', this);
    inp.remove();
    
    var tmp = sp.html();
    
    sp.html(inp.val());
    inp.val(tmp);
    
    sp.append(inp);
  });
  
  //inform the server that future pages should be served in this mode
  $.ajax({
      type: "POST",
      url: "/cmsapps/ecommerce/syncincexvatmode.asp",
      data: { mode: mode },
      dataType: "xml",
      success: function(data, status) {
      },
      error: function(request, status, error) {
      }
  });
  
}
