function Calculate(whatToCalc)
{


	var gallons = parseFloat(document.frmCalculator.frmGallons.value);
	var currentCalc = parseInt(document.frmCalculator.frmCurrentCalc.value);

	var currentAlk = parseFloat(document.frmCalculator.frmCurrentAlk.value);
	var currentMag = parseInt (document.frmCalculator.frmCurrentMag.value);
	var desiredCalc = parseInt(document.frmCalculator.frmDesiredCalc.value);
	var desiredAlk = parseFloat(document.frmCalculator.frmDesiredAlk.value);
	var desiredMag = parseInt(document.frmCalculator.frmDesiredMag.value);


	var calcRecipe = document.frmCalculator.frmCalcRecipe.options[document.frmCalculator.frmCalcRecipe.selectedIndex].value;
	var alkRecipe = document.frmCalculator.frmAlkRecipe.options[document.frmCalculator.frmAlkRecipe.selectedIndex].value;

	var result = 0;
	var resultstring = "";
	warning = ""

	if (gallons <= 0 || isNaN(gallons) || gallons=="")
	{
		alert("Enter the gallons of your aquarium");

		return 0;
	}
	
if (whatToCalc == 1)
{
	
	
	if (currentCalc >= 0) {
		if (currentCalc >= desiredCalc || isNaN(desiredCalc)){
			alert("To calculate an amount desired calcium must be greater than current calcium");
			}}
			
	switch (calcRecipe){
    	case "Recipe1" : 
		
	    	// Calcium 1 ml adds 9.77 ppm/gal
			result = (10/9.77) * (desiredCalc - currentCalc) * gallons;
		 	resultstring = '<font color="red">Need:&nbsp;'+ parseInt(result)/10 + ' ml or ' + parseInt(result*.033814)/10 + ' fluid ounces or ' + parseInt(result/5)/10 + ' teaspoon(s)</font>';
   			warning = "This is only a suggested use.  Slowly add this amount over a few days, testing regularly and adjusting accordingly.";  
	    	break;
	    case "Recipe2" : 
        	// Calcium 1 ml adds 4.9 ppm/gal
  	    	result = (10/4.9) * (desiredCalc - currentCalc) * gallons;
			resultstring = '<font color="red">Need:&nbsp;'+ parseInt(result)/10 + ' ml or ' + parseInt(result*.033814)/10 + ' fluid ounces or ' + parseInt(result/5)/10 + ' teaspoon(s)</font>';
       		warning = "This is only a suggested use.  Slowly add this amount over a few days, testing regularly and adjusting accordingly.";  
	    	break;   
	    		case "Recipe1n" : 
		
	    	// Calcium 1 ml adds 88.5 per gram
			result = (10 * (1/85.5)) * (desiredCalc - currentCalc) * gallons;
		 	resultstring = '<font color="red">Need:&nbsp;'+ parseInt(result)/10 + ' grams  ' + parseInt(result*28.35)/10 + ' ounces or ' + parseInt(result/5)/10 + ' teaspoon(s)</font>';
   			warning = "This is only a suggested use.  Slowly add this amount over a few days, testing regularly and adjusting accordingly.";  
	    	break;
	    			case "Recipe2n" : 
		
	    	// Calcium 1 ml adds 72 per gram
			result = (10 * (1/72)) * (desiredCalc - currentCalc) * gallons;
		 resultstring = '<font color="red">Need:&nbsp;'+ parseInt(result)/10 + ' grams  ' + parseInt(result*28.35)/10 + ' ounces or ' + parseInt(result/5)/10 + ' teaspoon(s)</font>';
   			warning = "This is only a suggested use.  Slowly add this amount over a few days, testing regularly and adjusting accordingly.";  
	    	break;
	         
        default :
        	alert("Select Your Recipe");
			resultstring = "";
			break;
     }// end switch

	if (result > 0) {
		if (document.getElementById || document.all) {
			var elem = document.getElementById? document.getElementById("frmResultCalc"): document.all["frmResultCalc"];
	
			if (elem && typeof elem.innerHTML != "undefined") elem.innerHTML = resultstring;
				var elem = document.getElementById? document.getElementById("frmWarnCalc"): document.all["frmWarnCalc"];
					if (elem && typeof elem.innerHTML != "undefined") elem.innerHTML = warning;
		}
	}
}

if (whatToCalc == 2)
{

	if (currentAlk >= 0) {
		if (currentAlk >= desiredAlk || isNaN(desiredAlk)){
			alert("To calculate an amount desired alkalinity must be greater than current alkalinity");
			}
	else {
		currentAlk = currentAlk / 2.8;  // convert dKH to meq/l
		desiredAlk = desiredAlk / 2.8;  // convert dKH to meq/l
		}
	}

	switch (alkRecipe){
  		case "Recipe1" : 
	    // Recipe1 Alk part
	 	// in ml
	 	// 1 ml per gallon of aquarium water will raise alkalinity by 0.5 meq/liter (1.4 dKH).
     	result = 10 * (1/0.5) * (desiredAlk - currentAlk) * gallons;
     	resultstring = '<font color="red">Need:&nbsp;'+ parseInt(result)/10 + ' ml or ' + parseInt(result*.033814)/10 + ' fluid ounces or ' + parseInt(result/5)/10 + ' teaspoon(s)</font>';
   		warning = "This is only a suggested use.  Slowly add this amount over a few days, testing regularly and adjusting accordingly.";     
		break;
   case "Recipe2" : 
     // Recipe2 Alk part
	 // in ml
	 // 1 ml per gallon of aquarium water will raise alkalinity by 0.25 meq/liter (1.4 dKH).
     result = 10 * (1/0.25) * (desiredAlk - currentAlk) * gallons;
	 resultstring = '<font color="red">Need:&nbsp;'+ parseInt(result)/10 + ' ml or ' + parseInt(result*.033814)/10 + ' fluid ounces or ' + parseInt(result/5)/10 + ' teaspoon(s)</font>';
   	 warning = "This is only a suggested use.  Slowly add this amount over a few days, testing regularly and adjusting accordingly.";  
	 break;
   default : 
   	alert("Select your Recipe");
   	resultstring = "";
   //end switch alkalinity
	}
	
		if (result > 0) {
		if (document.getElementById || document.all) {
			var elem = document.getElementById? document.getElementById("frmResultAlk"): document.all["frmResultAlk"];
	
			if (elem && typeof elem.innerHTML != "undefined") elem.innerHTML = resultstring;
				var elem = document.getElementById? document.getElementById("frmWarnAlk"): document.all["frmWarnAlk"];
					if (elem && typeof elem.innerHTML != "undefined") elem.innerHTML = warning;
		}
	}
}

if (whatToCalc == 3)
{
	if (currentMag >= 0) {
		if (currentMag >= desiredMag || isNaN(desiredMag)){
			alert("To calculate an amount desired magnesium must be higher than current magnesium.");
			}
	else {
		// Recipes 1 & 2 one ml will increase 12.4 ppm in 1 gallon
      result = 10*(desiredMag - currentMag)* gallons / 12.4;
	  resultstring = '<font color="red">Need:&nbsp;'+ parseInt(result)/10 + ' ml or ' + parseInt(result*.033814)/10 + ' fluid ounces or ' + parseInt(result/5)/10 + ' teaspoon(s).</font>';
      warning = "This is only a suggested use.  Slowly add this amount over a few days, testing regularly and adjusting accordingly.";  
		}
	}
	if (result > 0) {
		if (document.getElementById || document.all) {
			var elem = document.getElementById? document.getElementById("frmResultMag"): document.all["frmResultMag"];
	
			if (elem && typeof elem.innerHTML != "undefined") elem.innerHTML = resultstring;
				var elem = document.getElementById? document.getElementById("frmWarnMag"): document.all["frmWarnMag"];
					if (elem && typeof elem.innerHTML != "undefined") elem.innerHTML = warning;
		}
		}

}

}
