﻿

// SITE INIT

function init() {
	if ( (navigator.userAgent.indexOf('Mac')!=-1) && (navigator.userAgent.indexOf('MSIE')!=-1)) { 
		location.href='unsupportedBrowser.html';
	}  else {
		preloadTabImages ();		
	}
}


// TABS
// load html documents into an iframe, and update tab images

var currentTab = ''

function switchTab(tabName) {
	//alert ("switchTab "+tabName);

	var fr2 = document.getElementById ("zoeViewComponent");
	var fr = document.getElementById ("content");
	
	switch (tabName) {
		case 'cards':
			fr2.style.display="block";
			fr.style.display="none";
			break;
		case 'cart':
			showCart();
			break;
		default:
			updateTabImages(tabName);
			fr2.style.display="none";
			fr.style.display="block";
			frames['content'].location.href=tabName+tabContentPageAffix;
			break;
	}
	updateTabImages(tabName);
	currentTab = tabName;
}

// TAB IMAGES

function preloadTabImages () {
	for (var i in tabNames) {
		MM_preloadImages(tabImagePath+tabNames[i]+tabImageSelectedAffix)
	}	
}
		
function updateTabImages(tabName) {
	for (var i in tabNames) {
		setTabImage(tabNames[i], tabNames[i]==tabName);
	}
}

function setTabImage(tabName,b) {
	var tabImageId = tabName+tabIdAffix;
	var tabImageNormal = tabImagePath+tabName+tabImageNormalAffix;
	var tabImageSelected = tabImagePath+tabName+tabImageSelectedAffix;
	var tabImage = b? tabImageSelected : tabImageNormal;	
	MM_swapImage(tabImageId,'',tabImage,1)
}



// PAYPAL


function showCart() {
	// displays the paypay shopping cart
	var theURL=getBasePayPalURL()
	+"&cmd=_cart"
	+"&display=1"
	//alert ("showCart "+theURL)
	openPayPalWindow(theURL);
}

function addItemToCartFromZoeView(index, price, caption, title, status) {
	// calls the paypay shopping cart, adding the item.
	var theURL=getBasePayPalURL()
	+"&cmd=_cart"
	+"&add=1"
	+"&item_name="+"Nuthatch Hand-Printed Card: " + caption
	+"&item_number="+index
	+"&amount="+price
	+"&no_shipping=0"
	+"&no_note=1"
	+"&currency_code=USD"
	+"&lc=US"
	+"&bn=PP-ShopCartBF"
	+"&return=http://nuthatchco.com/orderSuccessful.html"
	+"&cancel_return=http://nuthatchco.com/orderUnsuccessful.html"
	openPayPalWindow(theURL)
}

function getBasePayPalURL(){
	return "https://www.paypal.com/cgi-big/webscr?business=info@nuthatchco.com"
	//+"&image_url=https://www.paypal.com/en_US/i/logo/paypal_logo.gif"
	//return "https://www.paypal.com/cgi-big/webscr?business=info@nuthatchco.com"
	//+"&image_url=http://www.nuthatchco.com/media/logo_paypal.jpg"
}

function openPayPalWindow(theURL) {
	//alert('openPayPalWindow  '+theURL);
	window.open(theURL,"paypal", "menubar=0,resizable=1,toolbar=0,scrollbars=1,location=1,directories=0,status=1");
}


