function UpdateAmount(frm)
{

	var fr = 0;

	if (document.selfstudy.product_1.checked) {
		if (document.selfstudy.numberof_1.value == 0) {
			document.selfstudy.numberof_1.value = 1;
			document.selfstudy.numberof_1.disabled=false
		}
	} else {
		document.selfstudy.numberof_1.value = 0;
		document.selfstudy.numberof_1.disabled=true
	}
	if (document.selfstudy.product_2.checked) {
		if (document.selfstudy.numberof_2.value == 0) {
			document.selfstudy.numberof_2.value = 1;
			document.selfstudy.numberof_2.disabled=false
		}
	} else {
		document.selfstudy.numberof_2.value = 0;
		document.selfstudy.numberof_2.disabled=true
	}
	if (document.selfstudy.product_3.checked) {
		if (document.selfstudy.numberof_3.value == 0) {
			document.selfstudy.numberof_3.value = 1;
			document.selfstudy.numberof_3.disabled=false
		}
	} else {
		document.selfstudy.numberof_3.value = 0;
		document.selfstudy.numberof_3.disabled=true
	}
	if (document.selfstudy.product_4.checked) {
		if (document.selfstudy.numberof_4.value == 0) {
			document.selfstudy.numberof_4.value = 1;
			document.selfstudy.numberof_4.disabled=false
		}
	} else {
		document.selfstudy.numberof_4.value = 0;
		document.selfstudy.numberof_4.disabled=true
	}
	if (document.selfstudy.product_5.checked) {
		if (document.selfstudy.numberof_5.value == 0) {
			document.selfstudy.numberof_5.value = 1;
			document.selfstudy.numberof_5.disabled=false
		}
	} else {
		document.selfstudy.numberof_5.value = 0;
		document.selfstudy.numberof_5.disabled=true
	}
	UpdateProductTotal(frm);
	UpdateShipping();
	UpdateTotal();
}

function UpdateProductTotal(frm)
{
	var total = 0;

	if (document.selfstudy.product_1.checked) {
		total = total + (document.selfstudy.amount_1.value * document.selfstudy.numberof_1.value);
	}
	if (document.selfstudy.product_2.checked) {
		total = total + (document.selfstudy.amount_2.value * document.selfstudy.numberof_2.value);
	}
	if (document.selfstudy.product_3.checked) {
		total = total + (document.selfstudy.amount_3.value * document.selfstudy.numberof_3.value);
	}
	if (document.selfstudy.product_4.checked) {
		total = total + (document.selfstudy.amount_4.value * document.selfstudy.numberof_4.value);
	}
	if (document.selfstudy.product_5.checked) {
		total = total + (document.selfstudy.amount_5.value * document.selfstudy.numberof_5.value);
	}
	document.selfstudy.product_total.value = total.toFixed(2);
	UpdateTax();
	UpdateTotal();
}

function UpdateTax()
{
	var tax = 0;
	if (document.selfstudy.state.options[document.selfstudy.state.options.selectedIndex].value == "IL") {
		tax = document.selfstudy.product_total.value * .1;
		document.selfstudy.tax_cart.value = tax.toFixed(2);
	} else {
		tax = 0;
		document.selfstudy.tax_cart.value = tax.toFixed(2);
	}
}


function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function checkIfNumber(inputObj){
	var ok = 'Y';
	var msg = '';
	var val = trim(inputObj.value);

		if (isNaN(val) || val < 0) {
			ok = 'N';
			msg = "You must enter a number";
		}
		if (ok == 'N') {
			inputObj.value ='0';
			return false;
		}
	UpdateProductTotal(inputObj.form);
	UpdateShipping();
	UpdateTotal();
}

function UpdateShipping()
{
	var count = 0;
	var multiplier = 0;
	var shipping = 0;

	count = Math.abs(document.selfstudy.numberof_1.value) + Math.abs(document.selfstudy.numberof_2.value) + Math.abs(document.selfstudy.numberof_3.value) + Math.abs(document.selfstudy.numberof_4.value) + Math.abs(document.selfstudy.numberof_5.value);

		if (document.selfstudy.shippingmethod[0].checked) {
				multiplier=25;
		} else if (document.selfstudy.shippingmethod[1].checked) {
				multiplier=45;
		} 

	shipping = count*multiplier;
	document.selfstudy.shipping.value = shipping.toFixed(2);

	UpdateTotal();
}


function UpdateTotal()
{
	var total = 0;

	total = Math.abs(document.selfstudy.shipping.value) + Math.abs(document.selfstudy.tax_cart.value) + Math.abs(document.selfstudy.product_total.value);
	document.selfstudy.total.value = total.toFixed(2);

}


function setcustom(frm)
{

var included_fields = "|title|organization|ext|cellphone|member_id|";
var productlist = "";
var alreadychecked = 1;
var count = 1;
var plx = "";
var x = "";

document.selfstudy.custom.value = "";
document.selfstudy.business.value = "djohansson@hfma.org";

	for(i=0; i<document.selfstudy.elements.length; i++) 	{
		plx = document.selfstudy.elements[i].name.substr(9,1);
		if (document.selfstudy.elements[i].name.indexOf("numberof_") >= 0 && document.selfstudy.elements[i].value != '0') {
			switch(count)
			{
			case 1:
			  document.selfstudy.quantity_1.value = document.selfstudy.elements[i].value;
			  x = document.getElementById("product_"+plx);
			  document.selfstudy.item_name_1.value = x.value;
			  break;
			case 2:
			  document.selfstudy.quantity_2.value = document.selfstudy.elements[i].value;
			  x = document.getElementById("product_"+plx);
			  document.selfstudy.item_name_2.value = x.value;
			  break;
			case 3:
			  document.selfstudy.quantity_3.value = document.selfstudy.elements[i].value;
			  x = document.getElementById("product_"+plx);
			  document.selfstudy.item_name_3.value = x.value;
			  break;
			case 4:
			  document.selfstudy.quantity_4.value = document.selfstudy.elements[i].value;
			  x = document.getElementById("product_"+plx);
			  document.selfstudy.item_name_4.value = x.value;
			  break;
			case 5:
			  document.selfstudy.quantity_5.value = document.selfstudy.elements[i].value;
			  x = document.getElementById("product_"+plx);
			  document.selfstudy.item_name_5.value = x.value;
			  break;
			}
			count++;
		}

		if (included_fields.indexOf("|" + document.selfstudy.elements[i].name + "|") >= 0 && document.selfstudy.elements[i].value != '') {
			if (document.selfstudy.elements[i].name != "shippingmethod") {
				document.selfstudy.custom.value = document.selfstudy.custom.value + "|" + document.selfstudy.elements[i].name + "=" + document.selfstudy.elements[i].value;
			}

		}
	}

				if (document.selfstudy.shippingmethod[0].checked && alreadychecked) {
						document.selfstudy.custom.value = document.selfstudy.custom.value + "|shippingmethod" + "=" +  document.selfstudy.shippingmethod[0].value;
						alreadychecked = 0;
				} else if (document.selfstudy.shippingmethod[1].checked && alreadychecked) {
						document.selfstudy.custom.value = document.selfstudy.custom.value + "|shippingmethod" + "=" +  document.selfstudy.shippingmethod[1].value;
						alreadychecked = 0;
				} else if (document.selfstudy.shippingmethod[2].checked && alreadychecked) {
						document.selfstudy.custom.value = document.selfstudy.custom.value + "|shippingmethod" + "=" +  document.selfstudy.shippingmethod[2].value;
						alreadychecked = 0;
			}
			document.selfstudy.handling_cart.value = document.selfstudy.shipping.value;
document.selfstudy.submit();

}
