
function IsNumeric(sText)

{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }


function costPerBlast() {
	currentBlastFrequency = document.instantBlastQuote.currentBlastFrequency.value;
	currentBlastAmount = document.instantBlastQuote.currentBlastAmount.value;
	currentBlastAmount = currentBlastAmount.replace("$","");
	blastPrice = 99.99;
	
	// make sure they entered all numbers
	if(currentBlastFrequency == "" || currentBlastAmount == "") {
		alert("Please fill out all fields to calculate the savings!");
		return false;
	}
	
	if(currentBlastFrequency < 1 || currentBlastFrequency > 10 || IsNumeric(currentBlastFrequency) == false) {
		alert("Your current blasts per month should be a number between 1 and 10.");
		return false;
	}
	
	if(currentBlastAmount < 1 || currentBlastAmount > 5000 || IsNumeric(currentBlastAmount) == false) {
		alert("Your cost per blast should be a number between 1 and 5000");
		return false;
	}
	
	// calculate cost per blast
	theCostPerBlast = (blastPrice/currentBlastFrequency);
//	alert("Cost Per Blast " + costPerBlast.toFixed(2));
	document.getElementById("CalCostPerBlast").innerHTML = theCostPerBlast.toFixed(0);
	
	// get monthly savings
	monthlySavings = ((currentBlastAmount * currentBlastFrequency) - blastPrice);
//	alert("Monthly Savings " + monthlySavings.toFixed(2));
	document.getElementById("CalMonthlySavings").innerHTML = monthlySavings.toFixed(0);
	
	// get yearly savings
	yearlySavings = (((currentBlastAmount * currentBlastFrequency) * 12) - (blastPrice * 12));
//	alert("Yearly Savings " + yearlySavings.toFixed(2));
	document.getElementById("CalYearlySavings").innerHTML = yearlySavings.toFixed(0);
	
}
