function calculateTotal(inputItem) {
	 if (document.selectionForm.Name.value == ""){
		  alert('Please fill in your name.');
		  InitForm()
	 }
	 else if (document.selectionForm.email.value == ""){
		  alert('Please fill in your E-mail.');
		  InitForm()
	 }
	 else if (document.selectionForm.phone.value == ""){
		  alert('Please fill in your Phone Number.');
		  InitForm()
	 }
	else if (document.selectionForm.address.value == ""){
		  alert('Please fill in your Address.');
		  InitForm()
	 }
	else if (document.selectionForm.city.value == ""){
		  alert('Please fill in your City.');
		  InitForm()
	 }
	 else if (document.selectionForm.state.value == ""){
		  alert('Please fill in your State.');
		  InitForm()
	 }
	 else if (document.selectionForm.zip.value == ""){
		  alert('Please fill in your Zip Code.');
		  InitForm()
	 }
  with (inputItem.form) {
    // Process each of the different input types in the form.
    if (inputItem.type == "radio") {   // Process radio buttons.
      // Subtract the previously selected radio button value from the total.
      calculatedTotal.value = eval(calculatedTotal.value) - eval(previouslySelectedRadioButton.value);
      // Save the current radio selection value.
      previouslySelectedRadioButton.value = eval(inputItem.value);
      // Add the current radio button selection value to the total.
      calculatedTotal.value = eval(calculatedTotal.value) + eval(inputItem.value);
    } 
	else {   // Process check boxes.
      if (inputItem.checked == false) {   // Item was uncheck. Subtract item value from total.
          calculatedTotal.value = eval(calculatedTotal.value) - eval(inputItem.value);
      } else {   // Item was checked. Add the item value to the total.
          calculatedTotal.value = eval(calculatedTotal.value) + eval(inputItem.value);
	  
	  }
	  taxAmount = 0.0825;
		  document.selectionForm.subtotal1.value = calculatedTotal.value;
		  document.selectionForm.subtotal.value = formatCurrency(eval(document.selectionForm.subtotal1.value));
		  if(document.selectionForm.subtotal1.value>50){
		  document.selectionForm.shipping1.value = 12;
		  document.selectionForm.shipping.value = formatCurrency(12);
		  }
		  else if(document.selectionForm.subtotal1.value>29){
		  document.selectionForm.shipping1.value = 6;
		  document.selectionForm.shipping.value = formatCurrency(6);
		  }
		  else if(document.selectionForm.subtotal1.value>15){
		  document.selectionForm.shipping1.value = 4.5;
		  document.selectionForm.shipping.value = formatCurrency(4.5);
		  }
		  else if(document.selectionForm.subtotal1.value>0){
		  document.selectionForm.shipping1.value = 3;
		  document.selectionForm.shipping.value = formatCurrency(3);
		  }
		  
		  else if(document.selectionForm.subtotal1.value = 0){
		  document.selectionForm.shipping1.value = 0;
		  document.selectionForm.shipping.value = formatCurrency(0);
		  }
		  if(document.selectionForm.state.value == "CA"){
		  document.selectionForm.tax1.value = eval(calculatedTotal.value) * taxAmount;
		  document.selectionForm.tax.value = formatCurrency(eval(document.selectionForm.tax1.value));
		  }
		  else if(document.selectionForm.state.value == "ca"){
		  document.selectionForm.tax1.value = eval(calculatedTotal.value) * taxAmount;
		  document.selectionForm.tax.value = formatCurrency(eval(document.selectionForm.tax1.value));
		  }
		  else if(document.selectionForm.state.value == "Ca"){
		  document.selectionForm.tax1.value = eval(calculatedTotal.value) * taxAmount;
		  document.selectionForm.tax.value = formatCurrency(eval(document.selectionForm.tax1.value));
		  }
		  else if(document.selectionForm.state.value == "cA"){
		  document.selectionForm.tax1.value = eval(calculatedTotal.value) * taxAmount;
		  document.selectionForm.tax.value = formatCurrency(eval(document.selectionForm.tax1.value));
		  }
		  else{
		  document.selectionForm.tax1.value = eval(calculatedTotal.value) * 0;
		  document.selectionForm.tax.value = formatCurrency(eval(document.selectionForm.tax1.value));
		  }
		  document.selectionForm.total.value = formatCurrency(eval(calculatedTotal.value) + eval(document.selectionForm.tax1.value) + eval(document.selectionForm.shipping1.value));
    }

    // Total value should never be less than 0.
    if (calculatedTotal.value < 0) {
      InitForm();
    }

    // Return total value.
    return(formatCurrency(calculatedTotal.value));
  }
  
}

// Format a value as currency.
function formatCurrency(num) {
  num = num.toString().replace(/\$|\,/g,'');
  if(isNaN(num))
     num = "0";
  sign = (num == (num = Math.abs(num)));
  num = Math.floor(num*100+0.50000000001);
  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);
}

// This function initialzes all the form elements to default values.
function InitForm() {
  // Reset values on form.
  document.selectionForm.total.value='$0';
  document.selectionForm.calculatedTotal.value=0;
  document.selectionForm.previouslySelectedRadioButton.value=0;
  document.selectionForm.tax.value='$0';
  document.selectionForm.tax1.value=0;
  document.selectionForm.shipping.value='$0';
  document.selectionForm.shipping1.value=0;
  document.selectionForm.subtotal1.value=0;
  document.selectionForm.subtotal.value='$0';


  // Set all checkboxes and radio buttons on form to unchecked.
  for (i=0; i < document.selectionForm.elements.length; i++) {
    if (document.selectionForm.elements[i].type == 'checkbox' | document.selectionForm.elements[i].type == 'radio') {
      document.selectionForm.elements[i].checked = false;
    }
  }
}

