function isInteger(s)
{   
	var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function isFloat(s)
{   
	if (isNaN(s)) { return false; }
	
    // All characters are numbers.
    return true;
}

function SubmitCalcForm()
{
	var jugs=document.frmCalc.txtJugs;
	var coolers=document.frmCalc.txtCoolers;
	var jugs_cost=document.frmCalc.txtJugsCost;
	var coolers_cost=document.frmCalc.txtCoolersCost;
	
	var jugs_cost_string = new String;
	var coolers_cost_string = new String;
	
	jugs_cost_string = jugs_cost.value;
	coolers_cost_string = coolers_cost.value;
	
	jugs_cost_string = jugs_cost_string.replace("$", "");
	coolers_cost_string = coolers_cost_string.replace("$", "");
	
	jugs_cost.value = parseFloat(jugs_cost_string);
	coolers_cost.value = parseFloat(coolers_cost_string);
		
	var error_string = '';
	
	if (!isInteger(jugs.value) || (jugs.value==null) || (jugs.value=="")) { error_string += ' [BOTTLES]'; }
	if (!isFloat(jugs_cost.value) || (jugs_cost.value==null) || (jugs_cost.value=="")) { error_string += ' [COST PER BOTTLE]'; }
	if (!isInteger(coolers.value) || (coolers.value==null) ||(coolers.value=="")) { error_string += ' [COOLERS]'; }
	if (!isFloat(coolers_cost.value) || (coolers_cost.value==null) || (coolers_cost.value=="")) { error_string += ' [COST PER COOLER]'; }
	
	if (error_string.length)
	{
		alert('Please correct the following fields: ' + error_string);
		return false;
	}
	
	var htmlStr
	var intA=((jugs.value)*jugs_cost.value + (coolers.value)*coolers_cost.value)*12
	var intP=parseInt((30*intA)/100).toString()
	var intA_whole_num = parseInt(intA);
	if (intA>=600) {
		htmlStr = "<p><b class=\"calc-blue\">YOU CAN SAVE:</b><b class=\"calc-green\"> $";
		htmlStr += intP;		
		htmlStr += "</b><br></p>";
		htmlStr += "<p>We've calculated that you spend approximately $";
		htmlStr += intA_whole_num;
		htmlStr += " annually on drinking water. ";
		htmlStr += "<b>Clear Water can save you approximately $";
		htmlStr += intP;
		htmlStr += '</b>. Please <a href="contactus.html">contact us</a> for more information.</p>';
	} 
	else 
	{
		htmlStr = "<p>We've calculated that you spend approximately $";
  		htmlStr += intA_whole_num;
  		htmlStr += " annually on drinking water. Sorry, but "; 
        htmlStr += "we'll need more details to provide you with your ";
        htmlStr += 'cost savings.<b> </b>Please <a href="contactus.html">contact us</a> so that we may help you further.</p>';
    }
	
	document.getElementById("savings_text").innerHTML = htmlStr;
	document.getElementById("calc-savings-display").style.display = 'block';
	document.frmCalc.txtCoolers.value = '';
	document.frmCalc.txtJugs.value = '';
	document.frmCalc.txtCoolersCost.value = '';
	document.frmCalc.txtJugsCost.value = '';

	return false
 }
 
 function close_savings_display()
 {
	document.getElementById("calc-savings-display").style.display = 'none';
 }

