function stripNum(num) {
var iPercent
var iDollar
var iSpace
var iComma
var numLength = num.length
//lalalla Line #114
if(numLength > 0) {
   num=num.toString();
   iPercent = num.indexOf("%");
   if(iPercent >= 0) {
      num=num.substring(0,iPercent) + "" + num.substring(iPercent + 1,numLength);
      numLength=num.length;
      }
   iDollar = num.indexOf("$");
   if(iDollar >= 0) {
      num=num.substring(0,iDollar) + "" + num.substring(iDollar + 1,numLength);
      numLength=num.length;
      }
   iSpace = num.indexOf(" ");
   if(iSpace >= 0) {
      num=num.substring(0,iSpace) + "" + num.substring(iSpace + 1,numLength);
      numLength=num.length;
      }
   iComma = num.indexOf(",");
   if(iComma >= 0) {
      num=num.substring(0,iComma) + "" + num.substring(iComma + 1,numLength);
      numLength=num.length;
      }
      num = eval(num);
} else {
num = 0;
}
return num;
}
function formatNumber(num) {
var isNeg=0;
    if(num < 0) {
       num=num*-1;
       isNeg=1;
    }
    
	onum=Math.round(num*100)/100;
		
	integer=Math.floor(onum);
	if (Math.ceil(onum) == integer) {
		decimal="00";
	} else{
		decimal=Math.round((onum-integer)*100)
	}
	decimal=decimal.toString();
	if (decimal.length<2) decimal="0"+decimal;
	integer=integer.toString();
	var tmpnum="";
	var tmpinteger="";
	var y=0;
	for (x=integer.length;x>0;x--) {
		tmpnum=tmpnum+integer.charAt(x-1);
		y=y+1;
		if (y==3 & x>1) {
			tmpnum=tmpnum+",";
			y=0;
		}
	}
	for (x=tmpnum.length;x>0;x--) {
		tmpinteger=tmpinteger+tmpnum.charAt(x-1);
	}
		
	finNum=tmpinteger+"."+decimal;
    if(isNeg == 1) {
       finNum = "-" + finNum;
    }
	return finNum;
}
function Compute(form) {

	var VOfficeVisits = stripNum(form.OfficeVisits.value);
	var VPrescriptions = stripNum(form.Prescriptions.value);
	var VDeductibles = stripNum(form.Deductibles.value);
	var VMedicalCoInsurance = stripNum(form.MedicalCoInsurance.value);
	var VMedicines = stripNum(form.Medicines.value);
	
	var VEyeExams = stripNum(form.EyeExams.value);
	var VGlasses = stripNum(form.Glasses.value);
	var VContacts = stripNum(form.Contacts.value);
	var VLenseSolutions = stripNum(form.LenseSolutions.value);
	
	var VDentalCopays = stripNum(form.DentalCopays.value);
	var VOrthodontics = stripNum(form.Orthodontics.value);
	var VDentalDeductibles = stripNum(form.DentalDeductibles.value);
	var VDentalCoInsurance = stripNum(form.DentalCoInsurance.value);
	
	var VTotalHealthCare = eval(VOfficeVisits) + eval(VPrescriptions) + eval(VDeductibles) + eval(VMedicalCoInsurance) + eval(VMedicines) + eval(VEyeExams) + eval(VGlasses) + eval(VContacts) + eval(VLenseSolutions) + eval(VDentalCopays) + eval(VOrthodontics) + eval(VDentalDeductibles) + eval(VDentalCoInsurance);
	form.TotalHealthCare.value = formatNumber(VTotalHealthCare);


	var VDependentCare = stripNum(form.DependentCare.value);
	var VTotalDependentCare = VDependentCare;
	form.TotalDependentCare.value = formatNumber(VDependentCare); 
	

	var VParking = stripNum(form.Parking.value);
	var VTransit = stripNum(form.Transit.value);
	var VTotalCommuterExpenses = eval(VParking) + eval(VTransit);
	form.TotalCommuterExpenses.value = formatNumber(VTotalCommuterExpenses); 
	
	
	var VAnnualExpenses = eval(VTotalHealthCare) + eval(VTotalDependentCare) + eval(VTotalCommuterExpenses) ;
	form.AnnualExpenses.value = formatNumber(VAnnualExpenses);

	var Vfilingstat = form.filingstat.selectedIndex;

	var Vincome = stripNum(form.Income.value);
	var taxRate;
	var eqdollar;
	var eqmin
	var eqpercent;
	var runeq = true;
	
	if (Vfilingstat == 3) {
		if (Vincome >= 349701) {
			eqdollar = 98355.50;
			eqpercent = .35;
			eqmin = 349701;
		}
		else if (Vincome >= 178351) {
			eqdollar = 41810;
			eqpercent = .33;
			eqmin = 178351;
		}
		else if (Vincome >= 110101) {
			eqdollar = 22700;
			eqpercent = .28;
			eqmin = 110101;
		}
		else if (Vincome >= 42651) {
			eqdollar = 5837.50;
			eqpercent = .25;
			eqmin = 42651;
		}
		else if (Vincome >= 11201) {
			eqdollar = 1120;
			eqpercent = .15;
			eqmin = 11201;
		}
		else {
			taxRate = .10;
			runeq = false;
		}
	}
	else if (Vfilingstat == 2) {
		if (Vincome >= 174850) {
			eqdollar = 47300;
			eqpercent = .35;
			eqmin = 174850;
		}
		else if (Vincome >= 97926) {
			eqdollar = 21915.25;
			eqpercent = .33;
			eqmin = 97926;
		}
		else if (Vincome >= 64251) {
			eqdollar = 12486.25;
			eqpercent = .28;
			eqmin = 64251;
		}
		else if (Vincome >= 31851) {
			eqdollar = 4386.25;
			eqpercent = .25;
			eqmin = 31851;
		}
		else if (Vincome >= 7825) {
			eqdollar = 782.50;
			eqpercent = .15;
			eqmin = 7825;
		}
		else {
			taxRate = .10;
			runeq = false;
		}
	}	
	else if (Vfilingstat == 1) {
		if (Vincome >= 349700) {
			eqdollar = 94601;
			eqpercent = .35;
			eqmin = 349700;
		}
		else if (Vincome >= 195851) {
			eqdollar = 43830.50;
			eqpercent = .33;
			eqmin = 195851;
		}
		else if (Vincome >= 128501) {
			eqdollar = 24972.50;
			eqpercent = .28;
			eqmin = 128501;
		}
		else if (Vincome >= 63701) {
			eqdollar = 8772.50;
			eqpercent = .25;
			eqmin = 63701;
		}
		else if (Vincome >= 15651) {
			eqdollar = 1565;
			eqpercent = .15;
			eqmin = 15651;
		}
		else {
			taxRate = .10;
			runeq = false;
		}
	}
	else  {
		if (Vincome >= 349701) {
			eqdollar = 101469.25;
			eqpercent = .35;
			eqmin = 349701;
		}
		else if (Vincome >= 160851) {
			eqdollar = 39148.75;
			eqpercent = .33;
			eqmin = 160851;
		}
		else if (Vincome >= 77101) {
			eqdollar = 15698.75;
			eqpercent = .28;
			eqmin = 77101;
		}
		else if (Vincome >= 31851) {
			eqdollar = 4386.25;
			eqpercent = .25;
			eqmin = 31851;
		}
		else if (Vincome >= 7826) {
			eqdollar = 782.50;
			eqpercent = .15;
			eqmin = 7826;
		}
		else {
			taxRate = .10;
			runeq = false;
		}
	}
	
	if (runeq == true) {
		//taxRate = Math.round(100*((Vincome - eqmin)*eqpercent + eqdollar)/Vincome)/100;
		taxRate = ((Vincome - eqmin)*eqpercent + eqdollar)/Vincome;
	}
	taxRate = taxRate.toFixed(2);
	form.TaxRate.value = taxRate;

	var VAnnualSavings = VAnnualExpenses * taxRate;
	form.AnnualSavings.value =formatNumber(VAnnualSavings);
	
	
	var VPayCycle = form.PayCycle.selectedIndex;
	var VPayCheck = 0;
	if(VPayCycle == 0) {
	   VPayCheck = 52;
	} else
	if(VPayCycle == 1) {
	   VPayCheck = 26;
	} else
	if(VPayCycle == 2) {
	   VPayCheck = 24;
	} else
	if(VPayCycle == 3) {
	   VPayCheck = 12;
	}
	
	
	var VPaycheckSavings = VAnnualSavings / VPayCheck;
	form.PaycheckSavings.value = formatNumber(VPaycheckSavings);
} 