//***************************************************//
//***** This function checks to see if a field  ****//
//***** is Null or blank  ---- DJH 10/25/06    ****//
//************************************************//
function emptyvalidation(entered) {
	with (entered)
		{
		if (value == null || value == "") {
			return false;
			}
		else {
			return true;
			} // END IF	
		} // END with(entered)
}
//*********************************************************//
//** calculate the ASCII code of the given character **//
function CalcKeyCode(aChar) {
  var character = aChar.substring(0,1);
  var code = aChar.charCodeAt(0);
  return code;
}
//**********************************************************//
//**** ASCII Characters - 48 to 57 are the digits 0-9 *****//
//**** ASCII Character 46 is the period .  ***************//
//**** Original ASCII Test - cCode < 48 || cCode > 57 ***//
function checkNumber(val) {
  var strPass = val.value;
  var strLength = strPass.length;
  var lchar = val.value.charAt((strLength) - 1);
  var cCode = CalcKeyCode(lchar);

  if (cCode < 46 || cCode > 57 || cCode == 47) {
    var myNumber = val.value.substring(0, (strLength) - 1);
    val.value = myNumber;
  }
  return false;
}
//**** ASCII Character 45 is the minus sign/hyphen - ******//
//** Decided not to allow the minus sign since a user could put **//
//** it anywhere in the string - Would have to validate each  **//
//** cost string to ensure there wasn't a minus sign in between **//
//** numeric characters. **//
// **** ----  knobs.selectedIndex == null || *******//
//**************************************************************//
//***** This function checks to see that there is at least ****//
//***** one cost value - can't submit form if all cost    ****//
//***** fields are blank  ---- DJH 10/25/06              ****//
//**********************************************************//
function ValidateOneCostAmount(thisform) {
	with (thisform) {						
		if (
		(emptyvalidation(bodyCost) == false)&&
		(emptyvalidation(neck_cost) == false) && 
		(emptyvalidation(tuner_cost) == false) && 
		(emptyvalidation(bridge_cost) == false) && 
		(emptyvalidation(pickguard_cost) == false) && 
		(emptyvalidation(string_ferrules_cost) == false) && 
		(emptyvalidation(control_plate_cost) == false) && 
		(emptyvalidation(knobs_cost) == false) && 
		(emptyvalidation(switch_tip_cost) == false) && 
		(emptyvalidation(string_tree_cost) == false) &&
		(emptyvalidation(neck_plate_cost) == false) &&  
		(emptyvalidation(screws_cost) == false) && 
		(emptyvalidation(input_jack_cover_plate_cost) == false) && 
		(emptyvalidation(misc_hardware_1_cost) == false) && 
		(emptyvalidation(misc_hardware_2_cost) == false) && 
		(emptyvalidation(switch_cost) == false) && 
		(emptyvalidation(pots_cost) == false) && 
		(emptyvalidation(pickups_cost) == false) && 
		(emptyvalidation(wiring_kit_cost) == false) && 
		(emptyvalidation(input_jack_cost) == false) && 
		(emptyvalidation(misc_electronics_cost) == false)
			) 
		{
			alertMessage = "ALERT-MESSAGE - All costs are blank" + "\n" + "Please enter at least one part cost.";
			return true;
		}
		else {
			return false;
		} // END IF	
	} // END with(thisform)
} // END ValidateOneCostAmount(thisform)
//******************************************************//
//**** PACKAGE Radio button validations ***************//
//**** knobs_package[0] - No Knobs radio button ******//
//**** knobs_package[1] - Each radio button ******//
//**** knobs_package[2] - Package radio button **//
//**********************************************// 
//**** Generic Radio Button Validation Function ************//
//**** Pass the radio button, cost field, quantity and  ***//
//**** fieldName (knobs - pots) ====== DJH 10/30/06 ******//
//*=====================================================*//
function PackageValidation(packageField, costField, qty, fieldName) {
	with (packageField) {
		if (packageField[1].checked) {

			if (((costField.value == null || costField.value == 0)) &&
				(qty.selectedIndex == 0)) {
				alertMessage = "You have indicated that the " + fieldName + " will be sold as each." + "\n" + "Please enter a " + fieldName + " cost and quantity in the " + fieldName + " Qty dropdown menu.";
				costField.focus();
				return true;
					} // END IF  cost = 0 && qty.selectedIndex == 0
					
				else if (((costField.value == null || costField.value == 0)) &&
				(qty.selectedIndex != 0)){
					alertMessage = "You have indicated that the " + fieldName + " will be sold as each." + "\n" + "Please enter a " + fieldName + " cost.";
					costField.focus();
					return true;
					} // END ELSE IF cost = 0 && qty.selectedIndex == 0
					
					else if (qty.selectedIndex == 0){
					alertMessage = "You have indicated that the " + fieldName + " will be sold as each." + "\n" + "Please enter a " + fieldName + " quantity in the " + fieldName + " Qty dropdown menu.";
					costField.focus();
					return true;
					} // END ELSE IF (qty.selectedIndex == 0)
					
			} // IF (knobs_package[1].checked)
		else if (packageField[2].checked){
		
				if ((costField.value == null || costField.value == 0)) {
				alertMessage = "You have indicated that the " + fieldName + " will be sold in a package." + "\n" + "Please enter a " + fieldName + " package cost.";
				costField.focus();
				return true;
				} // END IF (((costField.value == null || costField.value == 0))
				
			} // END ELSE IF (packageField[2].checked)
		else
			{
				return false;
			} // END IF (packageField[1].checked)
	} // end with (packageField)
}// End Function PackageValidation(packageField, costField, qty, fieldName)
//**********************************************************************************//
//**********************************************************//
//***** This Main Function calls the other validation  ****//
//***** functions - DJH 10/25/06                     ****//
//******************************************************// 
function GuitarCalcFormValidation(thisform) {
	with (thisform) {
		if (ValidateOneCostAmount(thisform))
			{
			alert(alertMessage);
			body_type.focus();
			return false;
			}	
		else {
			if (PackageValidation(knobs_package, knobs_cost, knobs, "knobs"))
				{
				alert(alertMessage);
				knobs_cost.focus();
				return false;
				}
			else
				{
				if (PackageValidation(pots_package, pots_cost, pots, "pots"))
				{
					alert(alertMessage); 
					pots_cost.focus();
					return false;
					}
				else
					{
					action = "guitar-building-calculator-results.asp";
					document.guitar_building_calculator_form.submit();
					return true;
					} // END IF	(PotsValidation(thisform))
				} // END IF	(KnobsValidation(thisform))
		} // END IF	(ValidateOneCostAmount(thisform))
	} // end with (thisform)
} // End Function GuitarCalcFormValidation(thisform)
