//-----------------------------------------------------------------------------
// global javascript
//-----------------------------------------------------------------------------
// Use of this code is governed in accordance with the terms and conditions of
// the agreement executed between the Client and Tag New Media. It is intended
// for use on the Nature's Eye Studios site only.
//
// © Copyright Tag New Media 2006. All Rights Reserved. 
//-----------------------------------------------------------------------------

window.name = "opener";

//put anything here that you want to run on onLoad for every page
function OnPageLoad() {
	//show the javascript version of the recommendation form if it's available
	if (document.getElementById('recommend-sidebar')) {
		document.getElementById('recommend-sidebar').style.display = 'block';
	}

	return true;
}

//return the value of the radio button that is checked
//return an empty string if none are checked, or there are no radio buttons
function GetCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

//update the price based on product options
function UpdateOptionPrice() {
	framingOptionID = GetCheckedValue(document.productForm.framingOption);
	
	//only update if a framing option was chosen
	if (framingOptionID) {
		if (framingOptionID == '3') {
			//show natural frame
			document.getElementById('frame').className = 'natural';
		} else if (framingOptionID == '4') {
			//show black frame
			document.getElementById('frame').className = 'black';
		}		
		
		sizeOptionID = GetCheckedValue(document.productForm.sizeOption);
	
		framingPriceArray = priceArray[framingOptionID];
		if (framingPriceArray.length > 0) {
			//update the prices listed for each size
			for (i = 1; i <= framingPriceArray.length; i++) {
				priceElementName = 'price-' + i;
				if (document.getElementById(priceElementName)) {
					//update price for this size
					document.getElementById(priceElementName).innerHTML = '(' + framingPriceArray[i] + ')';
	
					//if this is the same as the selected size, update the total
					if (sizeOptionID == i) {
						UpdateTotal(framingPriceArray[i]);
					}
				}
			}
		}
	}
}

//update the total
function UpdateTotal(totalPrice) {
	document.getElementById('price-total').innerHTML = totalPrice;
}
