
lastSelectedDonationValue = 0;
function checkDonation() {
	f = document.merch_form;
	el = f.AA_donation;
	if (el.options[el.selectedIndex].value!='other') lastSelectedDonationValue = el.options[el.selectedIndex].value;
	else if (!lastSelectedDonationValue) lastSelectedDonationValue = el.options[0].value;
	if (el.options[el.selectedIndex].value=='other') {
		el.style.display = 'none';
		el = document.getElementById('donation_other');
		el.style.display = 'inline';
		el = f.AA_donation_other;
		el.value = lastSelectedDonationValue;
		formatDonation();
		el.focus();
		el.select();
	}
	toggleMembershipOffer();
}

function formatDonation(allowZeroFlag) {
	f = document.merch_form;
	el = f.AA_donation_other;
	el.value.replace(' ','');
	el.value.replace('-','');
	el.value = (Math.ceil(el.value*1)).toFixed(2);
	if (el.value=='NaN') el.value = '0.00';
	
	// check for minimum amount:
	if (f.pref_pdfAT) {
		if (f.payment_DOM) {
			// monthly pledge minimum:
			if (el.value =='-' || el.value =='0.00' || el.value < 10) {
				el.value = '10.00';
				alert('Please enter a value of $10 or more.');
			}
		} else {
			// this is a membership/renewal form
			if (el.value =='-' || el.value =='0.00' || el.value < 25) {
				el.value = '35.00';
				alert('Annual membership is $35.');
			}
		}
	} else {
		// set min donation value
		if ((el.value =='-' || el.value =='0.00') && !allowZeroFlag) el.value = '1.00';
	}
	toggleMembershipOffer();
}

function toggleMembershipOffer() {
	f = document.merch_form;
	dValue = f.AA_donation.options[f.AA_donation.selectedIndex].value;
	if (dValue=='other') dValue = f.AA_donation_other.value;
	dValue *= 1;
	if (document.getElementById('membershipOffer')) {
		if (dValue >= 35) {
			f.freeMembership.checked = true;
			document.getElementById('membershipOffer').style.display = 'block';
		} else {
			f.freeMembership.checked = false;
			document.getElementById('membershipOffer').style.display = 'none';
		}
	}
}

function showHelp(helpName) {
	helpWin=window.open('/resources/'+helpName+'.php','helpWin','width=400,height=480,status=yes,resizable=yes,scrollbars=yes');
	helpWin.focus();
	return false;
}


function setDefaultDonation(donationValue) {
	f = document.merch_form;
	el = f.AA_donation;
	el.options[el.options.length-1].selected = true;
	checkDonation();
	el = f.AA_donation_other;
	el.value = donationValue;
	formatDonation();
}

merchBackVisible = '';
function showFront(merchId) {
	el = document.getElementById('merchPhoto');
	el.src = "/resources/merchthumb.php?g="+merchId+"&s=200";
	merchBackVisible = '';
}

function showBack(merchId) {
	el = document.getElementById('merchPhoto');
	el.src = "/resources/merchthumb.php?g="+merchId+"&s=200&b=1";
	merchBackVisible = 1;
}

function addToCart() {
	f = document.merch_form;
	error = '';
	// CHECK QTY
	q = (f.qty.value*1);
	if (!q) q = 1;
	f.qty.value = q;
	// CHECK OPTIONS
	if (f.AA_merch_options) {
		if (!(f.AA_merch_options.options[f.AA_merch_options.selectedIndex].value)) {
			error = "Please select a "+f.AA_merch_optionsLabel.value+".";
		}
	}
	if (!error) {
		winW = 750;
		winH = 655;
		var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
		if (is_chrome) {
			winW += 0;
			winH += 50;
		}
		AA_merch_win = window.open('','AA_merch_win','scrollbars=no,width='+winW+',height='+winH+',top=40,left=90');
		AA_merch_win.focus();
		f.target = 'AA_merch_win';
		f.action = '/support/basket/';
		f.method = 'post';
		f.submit();
		f.action = 'javascript:void(0);';
	} else {
		alert(error);
		return false;
	}
}

function viewCart() {
	winW = 750;
	winH = 655;
	var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
	if (is_chrome) {
		winW += 0;
		winH += 50;
	}
	AA_merch_win = window.open('/support/basket/','AA_merch_win','scrollbars=no,width='+winW+',height='+winH+',top=40,left=90');
	AA_merch_win.focus();
}


function launchCheckOut() {
	winW = 750;
	winH = 655;
	var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
	if (is_chrome) {
		winW += 0;
		winH += 50;
	}
	if (allowExpressShipping) AA_merch_win = window.open('/support/basket/shipping.php','AA_merch_win','scrollbars=no,width='+winW+',height='+winH+',top=40,left=90');
	else AA_merch_win = window.open('/support/basket/checkout.php','AA_merch_win','scrollbars=no,width='+winW+',height='+winH+',top=40,left=90');
	AA_merch_win.focus();
}

function closeMerchWinCheck() {
	// safari window check
	if (document.getElementById('contentCol')) {
		if (navigator.userAgent.toLowerCase().indexOf('safari')!=-1) {
			el = document.getElementById('contentCol');
			el.onclick = onunload = function() {
				if (AA_merch_win) {
					AA_merch_win.close();
					AA_merch_win = null;
				}
			}
		}
	}
}
loadMeUp += "closeMerchWinCheck();";

function getDonationAmount() {
	f = document.merch_form;
	donation = 0;
	if (f.AA_donation) {
		donation = f.AA_donation.options[f.AA_donation.selectedIndex].value;
		if (donation=='other') {
			donation = f.AA_donation_other.value;
		}
	}
	donation *= 1;
	if (!donation) donation = 0;
	return donation;
}


function merchDonate() {
	donationWin = window.open('/support/merchandise_donate.php','AA_merchDonate_win','scrollbars=yes,width=750,height=655,top=40,left=90');
	donationWin.focus();
}

function zoomProduct(merchId) {
	imgSrc = "/resources/merchthumb.php?g="+merchId+"&s=300&p=1&b="+merchBackVisible;
	merchZoom = window.open("/resources/viewImage.php?src="+escape(imgSrc),'merchZoom','width=350,height=350');
	merchZoom.focus();
}


