function handleSelectionChange() {
	var oColor = $("paypalForm").os0;
	var oSize = $("paypalForm").os1;

	if (!oColor || !oSize)
		return;
	
	var sSize = oSize.value;

	var o = aData[0];

	if (oColor.tagName.toUpperCase() == "SELECT") {
		oSizes = aData[oColor.selectedIndex];
		o = oSizes;
	} else {
		oSizes = aData[0];
		o = oSizes;		
	}

	if (oSize.tagName.toUpperCase() == "SELECT")
		o = (oSize.selectedIndex > 0 && oSize.selectedIndex < oSizes.length?o[oSize.selectedIndex]:o[0]);
	else
		o = o[0];

	if (!o)
		return;

	$("frame_price").update(formatCurrency(o.price));
	$("shipping_price").update("FREE Domestic Shipping");
	if ($("googleForm"))
		$("googleForm").ship_method_price_1.value = 0;
	if (oSize.tagName.toUpperCase() == "SELECT") {
		while(oSize.options.length > 0)
			oSize.removeChild(oSize.options[0]);

		$A(oSizes).each(function(i) {
			var oOption = new Option(i.size, i.size);
			oSize.options[oSize.options.length] = oOption;
			if (i.size == sSize)
				oSize.options[oSize.options.length - 1].selected = true;			
		});

	}
	if ($("googleForm")) {
		$("googleForm").item_description_1.value = "Color: " + oColor.value + " Size: " + oSize.value;
		$("googleForm").item_price_1.value = o.price;
		$("googleForm")["shopping-cart.merchant-private-data"].value = o.upc;
	}

	$("paypalForm").amount.value = o.price * 1 + (($("paypalForm").lens_price.value?$("paypalForm").lens_price.value:0) * 1);
	$("paypalForm").custom.value = o.upc;
}

function formatCurrency(origNum) {
	var num = origNum.toString().replace(/[^0-9\.]/g,'');
	if(num == "" || isNaN(num))
		return origNum;
	var sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	var cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}

function setMarqueeHeight(img) {
	var imgHeight = $(img).getHeight();
	var marHeight = $("customFrameScroll").getHeight();
	if (imgHeight > marHeight) {
		$("customFrameScroll").style.height = (imgHeight + 10) + "px";
	}
}

function switchTabs() {
	$('tabSunglasses').toggle();
	$('tabEyeglasses').toggle();
}

function verifySearchForm(frm) {
	if (frm.query.value.replace(/ /g, "").length == 0) {
		alert("At least one search term is required.");
		frm.query.focus();
		return false;
	}
	
	return true;
}

function addLenses(sid, fid) {
	window.open("lenses.php?" + sid + "&id=" + fid, "", "width=650,height=400");
}