// This version of the cart takes 'size' and 'color' options along with
// item_id, name, and cost.
//
// USAGE:
// To add a product:
//   <a href="#" onclick="addToCart('00231','T-Shirt','12.00','XXL','Red');return false;"></a>
// 
// To show the current shopping cart:
// 
//   <a href="#" onclick="showCart();return false;"></a>

// Business email address - split up to fight spambots.
//var business = 'orders' + '@' + 'welshgoose.co.uk'; 
var business = 'madgettspoultry' + '@' + 'btconnect.com'; //madgettspoultry@btconnect.com
// Paypal shopping cart URL.
var paypal_url = 'https://www.paypal.com/cart/';
// Currency
var currencyCode = 'GBP';

var cartWin = null;
var winName = 'cartwindow';
var winProps = 'width=800,height=600,scrollbars,location,resizable,status';

function addToCart (qty,name,price) {
  // Set URL for adding an item
  var cartUrl = paypal_url 
        + 'add=1'
        + '&business=' + escape(business)
        + '&currency_code=' + escape(currencyCode)
        + '&amount=' + escape(price);

  if (name != '') {
    cartUrl += '&item_name=' + escape(name);
  }

  if (qty != '' && qty != 0) {
    cartUrl += '&quantity=' + escape(qty);
    cartUrl += '&undefined_quantity=1';
  }

  // Add the item
  openCartWin(cartUrl);
}

function showCart() {
 // Set URL for viewing the cart
 var viewUrl = paypal_url + 'display=1' 
    + '&business=' + escape(business);
 // Show the cart
 openCartWin(viewUrl);
}

function openCartWin (loadUrl) { 
  // Does window exist? 
  if (!cartWin || cartWin.closed) { 
    // No - Open new window 
    cartWin = window.open(loadUrl,winName,winProps); 
  } else { 
    // Yes - Focus existing window and load new URL 
    cartWin.location = loadUrl; 
    cartWin.focus(); 
  }  
} 

// Kill the cart window when the page changes
function killCart() {
 cartWin.close();
 cartWin = null;
}
window.onunload = function() {
 killCart();
};


