/*
function setCost () {
	document.getElementById("cost").innerHTML = "$" + document.getElementById("cost " + (document.getElementById("days").value)).innerHTML;
}

function hideMasterClass () {
	if (document.getElementById("days").value == "Friday") {
		document.getElementById("masterClassRow").style.display = 'none';
	}
	else {
		document.getElementById("masterClassRow").style.display = '';
	}
}

function hideSculptureClass () {
	if (document.getElementById("days").value == "Saturday") {
		document.getElementById("sculptureRow").style.display = 'none';
	}
	else {
		document.getElementById("sculptureRow").style.display = '';
	}
}
*/

// Store <select> value in a different HTML element
var storeValueElement;

// Call when a form select element has been clicked
// Mostly copied from http://www.coderanch.com/t/121849/HTML-JavaScript/object-which-user-clicked
function formSelectElementChanged (event) {
//alert ("in formSelectElementChanged");
	var target, valueElement;
	if (!event)
		event = window.event;
	if (event.target)
		target = event.target;
	else if (event.srcElement)
		target = event.srcElement;

	if (target.nodeType == 3) // defeat Safari bug
		target = target.parentNode;

//alert ("in formSelectElementChanged, target (" + target + ") target value (" + target.value + ")");
	valueElement = document.getElementById(target.value);
//var alert_string;
//alert_string = "Target value = (" + target.value + ")";
//alert_string = "value element = (" + valueElement + ")";
//alert ("in formSelectElementChanged " + alert_string);
/*	if (target.value && valueElement) {
		storeValueElement.value = valueElement.innerTHML;
	}
	else*/
//alert ("in formSelectElementChanged storeValueElement.value was (" + storeValueElement.value + ")");
		if (target.value)
			storeValueElement.value = target.value;
		else
			storeValueElement.value = "";
//alert ("in formSelectElementChanged target.value (" + target.value + ") storeValueElement.value is (" + storeValueElement.value + ") storeValueElement.id (" + storeValueElement.id + ")");
//alert ("Form HTML\n" + document.getElementById("barbsbrick").innerHTML);
}


// Get <select> element's <option>s, given select element's ID
function getSelectsOptionElements (selectID) {
	var selectElement = document.getElementById(selectID);
	if (selectElement)
		return selectElement.getElementsByTagName('option');
	else
		return null;
}

// Initialization
function initFormSelectElementChanged (id, storeValueElementID, dataArray) {
//alert ("initFormSelectElementChanged");
	var selectElement = document.getElementById(id);
	var innerHTML, children, valueElement, i;
	storeValueElement = document.getElementById(storeValueElementID);

	// Get select element's children & make sure they have correct values
	children = getSelectsOptionElements(id);
	for (i=0 ; i<children.length ; i++) {

		// If there isn't an element with ID=(children[i].value), determine 
		// the value from child's inner HTML
//		if (children[i].value && (valueElement = document.getElementById(children[i].value)) {
			
// Need to check if select values corespond to element IDs, & if they do, don't do the following...
		innerHTML = children[i].innerHTML;
//var alert_string;
//alert_string = children[i].name?children[i].name:children[i].id + " value = (" + children[i].value + "), innerHTML = (" + innerHTML + ")";
		if (innerHTML) {
			var num = innerHTML.match(/\d+/);
			if (num)
				children[i].value = num;
			else
				children[i].value = "";
//alert_string = alert_string + "\nNew value (" + children[i].value + ")";
//alert ("in initFormSelectElementChanged " + alert_string);
		}
		else
			children[i].value = ''; 
	}

	// Make sure storeValueElement's value = selected <option> value
	storeValueElement.value = children[selectElement.selectedIndex].value;
//alert ("in initFormSelectElementChanged storeValueElement.id (" + storeValueElement.id + ") \nstoreValueElement.value (" + storeValueElement.value + ") \nstoreValueElement.value should = children[selectElement.selectedIndex].value (" + children[selectElement.selectedIndex].value + ")\nselect element's selectedIndex (" + selectElement.selectedIndex + ")");
}

// The following functions are not generic & should go in a separate file
function updateDonationAmount () {
//alert ("updateDonationAmount");
	initFormSelectElementChanged("chooseamount", "amount")

	// Get the <select> element
	var obj = document.getElementById("chooseamount");

	// Show options when JS is on
	obj.style.display = "inline";

//alert ("in updateDonationAmount, obj=" + obj.id);
//	obj.onblur = formSelectElementChanged;
	obj.onchange = formSelectElementChanged;
//alert ("in updateDonationAmount, finished setting onchange");
//	obj.onfocus = formSelectElementChanged;

// Need to set amount when page 1st loads. It really only gets messed up when I reload after changing option select value, but should find out which select value is the default & set things properly.
//	formSelectElementChanged("chooseamount");

	// Instructions when JS is on
	var instructionsObj = document.getElementById("instructions");
	if (instructionsObj)
		instructionsObj.innerHTML = "<br />Choose the amount you would like to donate from the options below &#8195; <i>or</i> &#8195; enter another amount in PayPal</i>:";

}

// Uses WOM. Make sure to include WOM.js
womAdd('updateDonationAmount()');
//alert ("Woms: " + woms);
womOn ();
//alert ("Finished womOn()");
