function CalculateTaxes(){

	var year = document.taxform.year.value;
	var sph = parseFloat(document.taxform.sph.value);
	var spn = parseFloat(document.taxform.spn.value);
	var swh = parseFloat(document.taxform.swh.value);
	var swn = parseFloat(document.taxform.swn.value);
	var wph = parseFloat(document.taxform.wph.value);
	var wpn = parseFloat(document.taxform.wpn.value);
	var wwh = parseFloat(document.taxform.wwh.value);
	var wwn = parseFloat(document.taxform.wwn.value);
	
	

	var taxperiod = document.taxform.taxperiod.options[document.taxform.taxperiod.selectedIndex].value;
	var municipality = document.taxform.municipality.options[document.taxform.municipality.selectedIndex].value;
	var homestead = document.taxform.homestead.options[document.taxform.homestead.selectedIndex].value;
	
	var propertyValue = document.taxform.propertyvalue.value;
	propertyValue = propertyValue.replace(",", "");
	propertyValue = propertyValue.replace("$", "");
	
	var obj = document.getElementById("taxes");
	if(isNaN(propertyValue)){
		obj.innerHTML = "Please make sure to enter a number";
	}else if (propertyValue < 0){
		obj.innerHTML = "Please make sure to enter a positive number";
	}else{
		var taxes = 0;
		
		var mill = 0;
		
		
		

		if (taxperiod == "summer"){
			if (municipality =="Pontiac"){
				mill = (homestead == "homestead") ? sph : spn;
			} else if (municipality =="West Bloomfield"){
				mill = (homestead == "homestead") ? swh : swn;
			}
		}else if (taxperiod == "winter"){
			if (municipality =="Pontiac"){
				mill = (homestead == "homestead") ? wph : wpn;
			} else if (municipality =="West Bloomfield"){
				mill = (homestead == "homestead") ? wwh : wwn;
			}
		}else if (taxperiod == "total"){
			if (municipality =="Pontiac"){
				mill = (homestead == "homestead") ? sph+wph : spn+wpn;
			} else if (municipality =="West Bloomfield"){
				mill = (homestead == "homestead") ? swh+wwh : swn+wwn;
			}
		}
		
		
		taxes = mill * propertyValue;
				
		taxes = commify(parseInt(taxes/10)/100);
		propertyValue = commify(propertyValue);
		obj.innerHTML = "Your calculated " + year + " " + taxperiod + " taxes for a " + homestead + " in " + municipality + " with a property value of " + propertyValue + " will be:<br /><br /><strong>" + taxes + "</strong>";
	}
	
	obj.style.display = "block";
	
	return false;
}



/*
*This JavaScript takes an input number and adds commas in the proper places.
*As needed by its original purpose, also adds a dollar.
*Copyright 1998, David Turley <dturley@pobox.com>
*Feel free to use and build on this code as long as you include this notice.
*Last Modified March 3, 1998
*/

function commify(Num) {
var newNum = "";
var newNum2 = "";
var count = 0;
Num = ""+Num;

//check for decimal number
if (Num.indexOf('.') != -1){ //number ends with a decimal point
if (Num.indexOf('.') == Num.length-1){
Num += "00";
}
if (Num.indexOf('.') == Num.length-2){ //number ends with a single digit
Num += "0";
}

var a = Num.split(".");
Num = a[0]; //the part we will commify
var end = a[1] //the decimal place we will ignore and add back later
}
else {var end = "00";}

//this loop actually adds the commas
for (var k = Num.length-1; k >= 0; k--){
var oneChar = Num.charAt(k);
if (count == 3){
newNum += ",";
newNum += oneChar;
count = 1;
continue;
}
else {
newNum += oneChar;
count ++;
}
} //but now the string is reversed!

//re-reverse the string
for (var k = newNum.length-1; k >= 0; k--){
var oneChar = newNum.charAt(k);
newNum2 += oneChar;
}

// add dollar sign and decimal ending from above
newNum2 = "$" + newNum2 + "." + end;
return newNum2;
}
