function initForm2(){
	/*
		// Disable fields
		document.listmenu0.result1a.disabled=true;
		document.listmenu0.result1b.disabled=true;
		document.listmenu0.result1c.disabled=true;
		document.listmenu0.result1d.disabled=true;

		document.listmenu0.result2a.disabled=true;
		document.listmenu0.result2b.disabled=true;
		document.listmenu0.result2c.disabled=true;
		document.listmenu0.result2d.disabled=true;
	*/

		// Clear all form fields in single event calculator
		document.listmenu0.result1a.value="";
		document.listmenu0.result1b.value="";
		document.listmenu0.result1c.value="";
		document.listmenu0.result1d.value="";

		// Clear all form fields in multi event calculator
		document.listmenu0.result2a.value="";
		document.listmenu0.result2b.value="";
		document.listmenu0.result2c.value="";
		document.listmenu0.result2d.value="";


		// Initialize hidden values to store totals
		document.listmenu0.TotalCCH.value = 0;
		document.listmenu0.TotalCCHTime.value = 0;
		document.listmenu0.NoCarbUsageFlag.value = 0;
		document.listmenu0.MaxHeartRate.value = 0;
	}


	function validateFields(){
		
		var errMsg = "";
		var vTotal = 0;
		//var vTTotal = document.listmenu0.result2a.value;
		

		// Validate mandatory fields are filled in
		if (document.listmenu0.firstlevel.selectedIndex == 0){
			errMsg = "Please select an Activity (and Intensity Level where applicable).";
			alert (errMsg);
			return;		
		};


		if (document.listmenu0.Weight.value == ""){
			errMsg = "Please enter a weight.";
			alert (errMsg);
			return;
		};
		
		if ((document.listmenu0.lHour.value == "") && (document.listmenu0.lMin.value == "")){
			errMsg = "Please enter an Event Length time in hours and minutes."
			alert (errMsg);
			return;				
		};

		if (document.listmenu0.HeartRate.options[document.listmenu0.HeartRate.selectedIndex].value == ""){
			errMsg = "Please select a % Maximum Heart Rate."
			alert (errMsg);
			return;				
		};

		// Check for min and max acceptable weight

		var vWeight = document.listmenu0.Weight.value;
		if (document.listmenu0.WeightUnit.options[document.listmenu0.WeightUnit.selectedIndex].value == "kg"){
			if (vWeight < 47){
				alert ("The weight entered is below acceptable values.  The maximum weight of 47 kg will be used in the calculations.");
				document.listmenu0.Weight.value = 47;		
			};
			if (vWeight > 98){
				alert ("The weight entered is above acceptable values.  The minimum weight of 98 kg will be used in the calculations.");
				document.listmenu0.Weight.value = 98;
				};
		};

		if (document.listmenu0.WeightUnit.options[document.listmenu0.WeightUnit.selectedIndex].value == "lbs"){
			if (vWeight < 104){
				alert ("The weight entered is below acceptable values.  The maximum weight of 104 lbs will be used in the calculations.");			
				document.listmenu0.Weight.value = 104;
			};
			if (vWeight > 216){
				alert ("The weight entered is above acceptable values.  The minimum weight of 216 lbs will be used in the calculations.");
				document.listmenu0.Weight.value = 216;
			};
		};
			

		// Beginning of analysis ------------------------------------------


		// Assign variables
		var vActivity = document.listmenu0.firstlevel.options[document.listmenu0.firstlevel.selectedIndex].value;

		// Determine if the activity has an associated intensity level
		if (document.listmenu0.secondlevel.length == 0){
			var vIntensity = 'NoIntensity';
		}

		else{
			var vIntensity = document.listmenu0.secondlevel.options[document.listmenu0.secondlevel.selectedIndex].value;
		}

		var vWeight = document.listmenu0.Weight.value;
		var vWeightUnit = document.listmenu0.WeightUnit.options[document.listmenu0.WeightUnit.selectedIndex].value;
		var vHour = document.listmenu0.lHour.value;
		var vMin = document.listmenu0.lMin.value;
		var vHeartRate = document.listmenu0.HeartRate.options[document.listmenu0.HeartRate.selectedIndex].value;
		var vMaxHeartRate = document.listmenu0.MaxHeartRate.value;

		// Store Maximum Heart Rate for logic in cumulative calculator
		if (vHeartRate > vMaxHeartRate){
			document.listmenu0.MaxHeartRate.value = vHeartRate;
		};


		// Call CalcCalorie Function
		// cCalcCalorie(vActivity, vIntensity, vWeight, vWeightUnit, vHour, vMin
		vTotalCalorie = cCalcCalorie(vActivity, vIntensity, vWeight, vWeightUnit, vHour, vMin);
		// alert (vTotalCalorie);

		// Call ReqCarbCalorie Function
		// cCalcReqCarbCalorie(vHeartRate, vTotalCalorie, vWeight, vWeightUnit)
		vReqCarbCalorie = cCalcReqCarbCalorie(vHeartRate, vTotalCalorie, vWeight, vWeightUnit);
		//vReqCarbCalorie = cCalcReqCarbCalorie(vHeartRate, '4000', vWeight, vWeightUnit);
		//alert (vReqCarbCalorie);	

		// Calculate Required Calories of Carbohydrates per Hour
		vReqCarbCalorieHour = cReqCarbCalorieHour(vReqCarbCalorie, vHour, vMin);
		//alert (vReqCarbCalorieHour);

		// Calculate Required Grams of Carbohydrate Per Hour
		vReqCarbHourGram = cReqCarbHourGram(vReqCarbCalorieHour);
		//alert (vReqCarbHourGram);


		// Display Results
		if (vReqCarbCalorie > 0){	// Z>0 carb usage triggered
			
			// Display results in textboxes
			document.listmenu0.result1a.value = vTotalCalorie;
			document.listmenu0.result1b.value = vReqCarbCalorie;
			document.listmenu0.result1c.value = vReqCarbCalorieHour;
			document.listmenu0.result1d.value = vReqCarbHourGram;

			// Display Summary Info
			showMessage1(vTotalCalorie, vReqCarbCalorie, vReqCarbCalorieHour, vReqCarbHourGram);
		}

		else{	// Z<=0	 No carb usage required
			
			// Display results in textboxes
			document.listmenu0.result1a.value = vTotalCalorie;
			document.listmenu0.result1b.value = "0";
			document.listmenu0.result1c.value = "0";
			document.listmenu0.result1d.value = "0";

			// Set CarbUsageFlag to 1 for cumulative calculation logic
			document.listmenu0.NoCarbUsageFlag.value = 1;

			// Display Summary Info
			showMessage2();
		};

	}


	function addTotal() {

		// Retrieve Data
		var vTotala = document.listmenu0.result1a.value;
		var vTTotala = document.listmenu0.result2a.value;

		var vTotalb = document.listmenu0.result1b.value;
		var vTTotalb = document.listmenu0.result2b.value;

		var vTotalCCH = document.listmenu0.TotalCCH.value;			// Running total Carb Carlorie 
		var vTotalCCHTime = document.listmenu0.TotalCCHTime.value;	// Running total time
		//alert (vTotalCCH + ' ' + vTotalCCHTime);

		var vHour = document.listmenu0.lHour.value;
		var vMin = document.listmenu0.lMin.value;
		var vTime = (+vHour) + (+vMin/60);	// Convert event time to hours

		var vWeight = document.listmenu0.Weight.value;
		var vWeightUnit = document.listmenu0.WeightUnit.options[document.listmenu0.WeightUnit.selectedIndex].value;
		var vHeartRate = document.listmenu0.HeartRate.options[document.listmenu0.HeartRate.selectedIndex].value;
		var vMaxHeartRate = document.listmenu0.MaxHeartRate.value;
		var vNoCarbUsageFlag = document.listmenu0.NoCarbUsageFlag.value;


		if(vTotala == ""){	//No single event data
			alert("A single event must be calculated first before you can add totals for multi-events.");
		}

		else if(vNoCarbUsageFlag == 1){ //No Carb Usage option F2

			if (document.listmenu0.result2a.value == ""){ //This condition is for first instance of totals

				// Sum and Display Results
				var vTotalEventsCalorie = (+vTotala) + (+vTTotala);
				document.listmenu0.result2a.value = vTotalEventsCalorie;
				document.listmenu0.result2b.value = 0;
				document.listmenu0.result2c.value = 0;
				document.listmenu0.result2d.value = 0;
			}

			else{

				// Sum and Display Results
				var vTotalEventsCalorie = (+vTotala) + (+vTTotala);
				document.listmenu0.result2a.value = vTotalEventsCalorie;

				// Re-calculate Carb calories
				var vReqCarbCalorie = cCalcReqCarbCalorie(vMaxHeartRate, vTotalEventsCalorie, vWeight, vWeightUnit);
				
				if(vReqCarbCalorie > 0){ // Z>0

					// Display recalculated carb calories
					document.listmenu0.result2b.value = vReqCarbCalorie;

					// Calculate Average Calories of Carbohydrates per Hour
					var vAvgCarbCalorieHour = cReqCarbCalorieHour(vReqCarbCalorie, ((+vTotalCCHTime) + (+vTime)), 0);
					document.listmenu0.result2c.value = vAvgCarbCalorieHour;

					// Calculate Average Grams of Carbohydrate Per Hour
					var vAvgCarbHourGram = cReqCarbHourGram(vAvgCarbCalorieHour);
					document.listmenu0.result2d.value = vAvgCarbHourGram;

				}

				else{	// Z<0
					document.listmenu0.result2b.value = 0;
					document.listmenu0.result2c.value = 0;
					document.listmenu0.result2d.value = 0;
	
				};				
			};

		}

		else{	//Carb Usage option	F1

			// Sum and Display Results
			document.listmenu0.result2a.value = (+vTotala) + (+vTTotala);
			document.listmenu0.result2b.value = (+vTotalb) + (+vTTotalb);

			// Calculate Average Calories of Carbohydrates per Hour
			var vAvgCarbCalorieHour = cReqCarbCalorieHour(((+vTotalCCH) + (+vTotalb)), ((+vTotalCCHTime) + (+vTime)), 0);
			document.listmenu0.result2c.value = vAvgCarbCalorieHour;

			// Calculate Average Grams of Carbohydrate Per Hour
			var vAvgCarbHourGram = cReqCarbHourGram(vAvgCarbCalorieHour);
			document.listmenu0.result2d.value = vAvgCarbHourGram;		
		};


		// Store cumulative totals in hidden object
		document.listmenu0.TotalCCH.value = ((+vTotalCCH) + (+vTotalb));			// Total Carb Calorie Hour
		document.listmenu0.TotalCCHTime.value = ((+vTotalCCHTime) + (+vTime));	// Total Event time

	}
	
	
	function clearFields1(){
		// Clear all form fields
		//document.listmenu0.Weight.value = "";
		document.listmenu0.lHour.value = "";
		document.listmenu0.lMin.value = "";

		document.listmenu0.result1a.value="";
		document.listmenu0.result1b.value="";
		document.listmenu0.result1c.value="";
		document.listmenu0.result1d.value="";

		initListGroup('chainedmenu', document.listmenu0.firstlevel, document.listmenu0.secondlevel, document.listmenu0.thirdlevel, '');
	}


	function clearFields2(){
	
			initForm2();
	}


	function checkNumeric(objName,minval, maxval,comma,period,hyphen){
		var numberfield = objName;
		if (chkNumeric(objName,minval,maxval,comma,period,hyphen) == false)	{
			numberfield.select();
			numberfield.focus();
			return false;
		}

		else{
			return true;
		}
	}

	function chkNumeric(objName,minval,maxval,comma,period,hyphen){

		// only allow 0-9 be entered, plus any values passed
		// (can be in any order, and don't have to be comma, period, or hyphen)
		// if all numbers allow commas, periods, hyphens or whatever,
		// just hard code it here and take out the passed parameters
		var checkOK = "0123456789" + comma + period + hyphen;
		var checkStr = objName;
		var allValid = true;
		var decPoints = 0;
		var allNum = "";

		for (i = 0;  i < checkStr.value.length;  i++)
		{
		ch = checkStr.value.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
		if (ch == checkOK.charAt(j))
		break;
		if (j == checkOK.length)
		{
		allValid = false;
		break;
		}
		if (ch != ",")
		allNum += ch;
		}
		if (!allValid)
		{	
		alertsay = "Please enter only these values \""
		alertsay = alertsay + checkOK + "\" in the \"" + checkStr.name + "\" field."
		alert(alertsay);
		return (false);
		}

		// set the minimum and maximum
		var chkVal = allNum;
		var prsVal = parseInt(allNum);
		if (chkVal != "" && !(prsVal >= minval && prsVal <= maxval))
		{
		alertsay = "Please enter a value greater than or "
		alertsay = alertsay + "equal to \"" + minval + "\" and less than or "
		alertsay = alertsay + "equal to \"" + maxval + "\" in the \"" + checkStr.name + "\" field."
		alert(alertsay);
		return (false);
		}
	}

function showMessage1(y, z, a, b){

	newWindow = window.open('', 'newWin', 'width=480, height=520')

	newWindow.document.writeln("<html>");
	newWindow.document.writeln("<head><style>p {font-size:80%;} td {font-size:80%;}</style></head>");
	newWindow.document.writeln("<body>");
	newWindow.document.writeln("<center><font face=arial color=#26289E>");

	newWindow.document.writeln('<img src="http://www.eload.net/Images/eloadLogo.gif" width=125 align=middle>');
	newWindow.document.write("<font size=5 face=arial bold><b>&nbsp;Summary Information</b></font>");
	newWindow.document.write("<p align=justify>");
	newWindow.document.write("According to the numbers which you entered, you will need approximately <b>");
	newWindow.document.write(a);
	newWindow.document.write("</b> calories of carbohydrate per hour, or <b>");
	newWindow.document.write(b);
	newWindow.document.write("</b> grams of carboydrate per hour, during this event/training session.  This is only a guide, and your ultimate carbohydrate need will depend on many factors, including your original glycogen stores, exercise intensity, your physical condition and length of your event/training session.  You will need to experiment, ultimately deciding the best number for you as you 'train' your gastrointestinal tract to absorb these carbohydrates during the stress of exercise.");
	newWindow.document.write("</p>");
	newWindow.document.write("<p align=justify>Finally, replenishing carbohydrate is also important during your recovery period to prepare you for your next event/training session (see www.emend.cc).</p>");
	
	newWindow.document.write("<p align=justify>To assess fluid needs, please see the 'Fluid Calculator'.</p>");

	newWindow.document.writeln("<table width=425 bgcolor=#FFFFCC border=2 cellpadding=12><tr><td>");
	newWindow.document.writeln("You will need <b>" + y + "</b> total calories.<br>You will need to ingest <b>" + z + "</b> total carbohydrate calories for your <br>&nbsp;&nbsp;&nbsp; chosen % maximum heart rate.  <br>You will need to ingest <b>" + a + "</b> carbohydrate calories/hour.  <br>You will need to ingest <b>" + b + "</b> carbohydrate grams/hour. <br><font size=1>(1 carbohydrate gram = 4 Calories)</font>");

	newWindow.document.writeln("</td></tr><table>");
	newWindow.document.writeln("<br>");
	newWindow.document.writeln("</center>");

	newWindow.document.writeln('<table width=100%><tr><td align=right><a href=""><img src="../Images/Close.gif"  alt="Close" border=0 vspace=5 onClick="window.close();"></a></td></tr></table>');

	newWindow.document.writeln("</font>");
	newWindow.document.writeln("</body>");
	newWindow.document.writeln("</html>");
	newWindow.document.close() 
}

function showMessage2(){

	newWindow = window.open('', 'newWin', 'width=480, height=390')

	newWindow.document.writeln("<html>");
	newWindow.document.writeln("<head><style>p {font-size:80%;} td {font-size:80%;}</style></head>");
	newWindow.document.writeln("<body>");
	newWindow.document.writeln("<center><font face=arial color=#26289E>");

	newWindow.document.writeln('<img src="http://www.eload.net/Images/eloadLogo.gif" width=125 align=middle>');
	newWindow.document.write("<font size=5 face=arial bold><b>&nbsp;Summary Information</b></font>");
	newWindow.document.write("<p align=justify>");
	newWindow.document.write("According to the numbers which you entered, it is likely that all carbohydrate calories will come from  your glycogen stores, and that you will not need to ingest any additional carbohydrate during this event/training session.  This is only a guide, however, and your ultimate carbohydrate need will depend on many factors, including your original glycogen stores, exercise intensity, your physical condition and length of your event/training session.  You will need to experiment, ultimately deciding the best number for you.");
	newWindow.document.write("</p>");
	newWindow.document.write("<p align=justify>Finally, although you may not need carbohydrate during your event/training sesion, you will need to replenish your glycogen stores during your recovery period to prepare you for your next event/training session (see www.emend.cc).</p>");
	
	newWindow.document.write("<p align=justify>To assess fluid needs, please see the 'Fluid Calculator'.</p>");
	
	newWindow.document.writeln('<table width=100%><tr><td align=right><a href=""><img src="../Images/Close.gif"  alt="Close" border=0 vspace=5 onClick="window.close();"></a></td></tr></table>');

	newWindow.document.writeln("</font>");
	newWindow.document.writeln("</body>");
	newWindow.document.writeln("</html>");
	newWindow.document.close() 
}


function showMessage(){

	// This function is no longer used!!!!!
	var X = document.listmenu0.result1a.value;
	var activeTime = (+document.listmenu0.lHour.value) + ((+document.listmenu0.lMin.value)/60);
	
	var A = round_decimals(0.5 * X, 0);
	var B = round_decimals(0.75 * X, 0);
	var C = round_decimals(A/4, 0);
	var D = round_decimals(B/4, 0);
	var E = round_decimals(C/activeTime, 0);
	var F = round_decimals(D/activeTime, 0);
	

	newWindow = window.open('', 'newWin', 'width=480, height=520')

	newWindow.document.writeln("<html>");
	newWindow.document.writeln("<head><style>p {font-size:80%;} td {font-size:80%;}</style></head>");
	newWindow.document.writeln("<body>");
	newWindow.document.writeln("<center><font face=arial color=#26289E>");

	newWindow.document.writeln('<img src="http://www.eload.net/Images/eloadLogo.gif" width=125 align=middle>');
	newWindow.document.write("<font size=5 face=arial bold><b>&nbsp;Summary Information</b></font>");
	newWindow.document.write("<p align=justify>");
	newWindow.document.write("While <b>");
	newWindow.document.write(X);
	newWindow.document.write("</b> is the approximate total calories you will use during your event, your body will be deriving these calories primarily from three sources, including ingested food/fluid, fat stores in your body and carbohydrate stores (glycogen) in your body*.  Therefore, you don't have to actually ingest all of the calories that the calculator says you need, as your fat stores supply a significant percentage of these.  Depending on the intensity of your endurance activity, fat stores will supply anywhere from 25-50% of the calories needed, meaning that carbohydrate stores will supply the rest i.e. 50-75% of total calories will come from carbohydrates.  The higher the intensity, the more calories you will derive from carbohydrates.  For events longer than 1 hour (where your internal glycogen stores will supply much of what is needed), these are the calories you will need to ingest in the form of carbohydrates.");
	newWindow.document.write("</p>");
	newWindow.document.write("<p align=justify>* Actually, up to 15% of your calories in endurance exercise may be derived from the amino acids in your muscles, but for simplicity, we are ingoring this fact in these calculations.</p>");
	
	newWindow.document.writeln("<table width=350 bgcolor=#FFFFCC border=2 cellpadding=5><tr><td>");
	newWindow.document.writeln("Advised carbohydrate calories needed for this event are 50-75% of <b>" + X + "</b>, or <b>" + A + "</b> to <b>" + B + "</b> Calories, or <b>" + C + "</b> to <b>" + D + "</b> grams of carbohydrate.  This equals <b>" + E + "</b> to <b>" + F + "</b> grams of carbohydrate per hour. ");

	newWindow.document.writeln("</td></tr><table>");
	newWindow.document.writeln("<p>&nbsp;</p>");
	newWindow.document.writeln("</center>");

	newWindow.document.writeln('<table width=100%><tr><td align=right><a href=""><img src="../Images/Close.gif"  alt="Close" border=0 vspace=5 onClick="window.close();"></a></td></tr></table>');

	newWindow.document.writeln("</font>");
	newWindow.document.writeln("</body>");
	newWindow.document.writeln("</html>");
	newWindow.document.close() 
}

//-->
