function popUp (URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open('http://www.dambrewery.com/' + URL, '" + id + "', 'toolbar=1,scrollbars=1,location=1,statusbar=1,width=700,menubar=1,resizable=1,height=550');");
}

function popPayPal(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open('https://' + URL, '" + id + "', 'toolbar=1,scrollbars=1,location=1,statusbar=1,width=700,menubar=1,resizable=1,height=550');");
}

function popGlass(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open('http://www.dambrewery.com/' + URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=1,width=200,menubar=1,resizable=1,height=200');");
}

function popOutside(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(' ' + URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,width=400,menubar=1,resizable=1,height=550');");
}

function initRollovers() {
	if (!document.getElementById) return
	
	var aPreLoad = new Array();
	var sTempSrc;
	var aImages = document.getElementsByTagName('img');

	for (var i = 0; i < aImages.length; i++) {		
		if (aImages[i].className == 'imgover') {
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '-o'+ftype);

			aImages[i].setAttribute('hsrc', hsrc);
			
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;
			
			aImages[i].onmouseover = function() {
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}	
			
			aImages[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('-o'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}
}

window.onload = initRollovers;
/////////////////////////////////////////////////////////////////////////////////////
// This version of the cart takes 'size' and 'color' options along with
// item_id, name, quantity and cost.
//
// USAGE:
// To add a product:
//   <a href="#" onclick="addToCart('1', '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 = 'gifts' + '@' + 'dambrewery.com';		
// Paypal shopping cart URL.
var paypal_url = 'https://www.paypal.com/cart/';
// Currency
var currencyCode = 'USD';

var cartWin = null;
var winName = 'cartwindow';
var winProps = 'width=740,height=400,scrollbars,location=1,resizable,status';

function addToCart (qty,name,price,size,color,combo,shipping,shipping2) {
	// 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 (combo != '') {
		cartUrl += '&on0=' + escape("Combo");
		cartUrl += '&os0=' + escape(combo);
	}
	if (color != '') {
		cartUrl += '&on0=' + escape("Color");
		cartUrl += '&os0=' + escape(color);
	}
	if (size != '') {
		cartUrl += '&on1=' + escape("Size");
		cartUrl += '&os1=' + escape(size);
	}
	if (qty != '' && qty != 0) {
		cartUrl += '&quantity=' + escape(qty);
	}
	if (shipping != '') {
    	cartUrl += '&shipping=' + escape(shipping);
	}
	if (shipping2 != '') {
    cartUrl += '&shipping2=' + escape(shipping2);
	}
	// Add the item
	openCartWin(cartUrl);
}


function handleCartItem (form) 
// Pick up values from within an HTML form used for a paypal shopping cart
// item and add the item to a cart.
// Supports select options for size and color.
{

	var name = '';
	var price = '';
	var size = '';
	var color = '';
	var combo  = '';
	var shipping = '';
	var shipping2 = '';
	var quantity = 1;
	
	// Get the form values, if the form elements exist.
	// ID, name, and price should be hidden fields.
	if (form.item_name) {
		name = form.item_name.value;
	}
	if (form.item_price) {
		price = form.item_price.value;
	}
	// Size - select, radio, or text input.
	if (form.item_size) {
		size = getInputValue(form.item_size);
	}
	// Color - select, radio, or text input.
	if (form.item_color) {
		color = getInputValue(form.item_color);
	}
	// Combo option - select, radio, or text input.
	if (form.item_combo) {
		combo = getInputValue(form.item_combo);
	}	
	if (form.shipping) {
		shipping = form.shipping.value;
	}
	if (form.shipping2) {
		shipping2 = form.shipping2.value;
	}

	// Add this item to the cart.
	addToCart(quantity, name, price, size, color, combo, shipping, shipping2);
}


function getInputValue (inputObj) 
// Return the current value (or selected value) of the input 
// field... The field can be of type radio, select, input or textarea.
// Return null if value is not found.
{
	if (inputObj.type == 'select-one') {	// select box
		return inputObj.options[inputObj.selectedIndex].value;
	} else {
		return inputObj.value;
	}
	return null;
}


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();
};