﻿google.load("jquery", "1.3.2");

// For each checked input, add the appropriate price
function updateTotalPrice()
{
  var TotalPrice = 0;
  $('#brid #divBooking ul li.liPrice input:checked').each(function() {
    switch ($(this).next('label').html())
    {
      case "Gazetteer £250":
        TotalPrice += 250;
        break;
      case "Eighth £584":
        TotalPrice += 584;
        break;
      case "Quarter £715":
        TotalPrice += 715;
        break;
      case "Half Page £954":
        TotalPrice += 954;
        break;
      case "Full Page £1591":
        TotalPrice += 1591;
        break;
      case "Back Cover £2500":
        TotalPrice += 2500;
        break;
      default:
        TotalPrice = "Error";
    } // switch
  });
  $('#east #divBooking ul li.liPrice input:checked').each(function() {
    switch ($(this).next('label').html())
    {
      case "Standard £250":
        TotalPrice += 250;
        break;
      case "Quarter £400":
        TotalPrice += 400;
        break;
      case "Half Page £670":
        TotalPrice += 670;
        break;
      case "Full Page £1,300":
        TotalPrice += 1300;
        break;
      case "Back Cover £2,500":
        TotalPrice += 2500;
        break;
      case "Real Attractions Map £250":
        TotalPrice += 250;
        break;
      default:
        TotalPrice = "Error";
    } // switch
  });
  $('#divBooking #labSubmit').html("Total Price &pound;" + TotalPrice);
} // updateTotalPrice

google.setOnLoadCallback(function() {
  
  // Set initial totalPrice
  updateTotalPrice();
  
  // Update on price changes
  $('#divBooking ul li.liPrice input').click(updateTotalPrice);
  
  // If invoice address is blank, copy from fAddress
  $('#divBooking ul li.liAddress input').blur(function() {
    if ($('#divBooking ul li.liInvoice input').val() == null || $('#divBooking ul li.liInvoice input').val() == '')
      $('#divBooking ul li.liInvoice input').val($('#divBooking ul li.liAddress input').val());
  });
  
});