function so_clearInnerHTML(obj) {
	while(obj.firstChild) obj.removeChild(obj.firstChild);
}

function CalculateSum(mode, miles, form) {
	
		var Atext = (mode);
		var Btext = (miles);
		
		//Error checking
		
		if (Atext == "") {
			alert('Please select a mode of transportation to calculate your carbon savings.')
			return false;
			}
		
		if (Btext == "") {
			alert('Please fill in your number of miles travelled annually to calculate your carbon savings.')
			return false;
			}
		
		for (i=0; i < Btext.length; i++) {
			if (isNaN(parseInt(Btext.charAt(i)))) {
			alert('Please do not include currency symbols, commas, decimals, or other non-numeric characters in your number of miles travelled annually.')
			return false;
			}
		}
			
		// Remove any existing answers
		so_clearInnerHTML(document.getElementById("answers"));
		
		// Convert input to numbers
		var A = parseFloat(Atext);
		var B = parseFloat(Btext);
		
		// Perform calculations
		carbonRaw = (A * B);

		// Format output with commas
		function addCommas(nStr)
		{
			nStr += '';
			x = nStr.split('.');
			x1 = x[0];
			x2 = x.length > 1 ? '.' + x[1] : '';
			var rgx = /(\d+)(\d{3})/;
			while (rgx.test(x1)) {
				x1 = x1.replace(rgx, '$1' + ',' + '$2');
			}
			return x1 + x2;
		}
		
		carbonNeat = carbonRaw.toFixed(3);
		
		carbonTons = addCommas(carbonNeat);
				
		eDIV = document.createElement("div");
		eDIV.setAttribute("id","savingsVal");
		eDIV.appendChild(document.createTextNode("You could save " + carbonTons + " tons of CO2 per year by using web and audio conferencing."));
		document.getElementById("answers").appendChild(eDIV);
		
}

function ClearForm(form) {
	form.mode.value = "";
	form.miles.value = "";
	so_clearInnerHTML(document.getElementById("answers"));
}

function toggleAbout (id){
    if (document.getElementById) {
        obj = document.getElementById(id);
        if (obj.style.display == "block") {
            obj.style.display = "none";
        } else {
            obj.style.display = "block";
        }
    }
}

