// JavaScript functions

function daysUntil(theyear, themonth, theday) {
   var now = new Date();
   var thefuture = new Date();
   thefuture.setFullYear(theyear);
   thefuture.setMonth(themonth);
   thefuture.setDate(theday);
   var days = Math.floor((thefuture.getTime() - now.getTime()) / (1000 * 60 * 60 * 24));
   return days
}

function daysSince(theyear, themonth, theday) {
   var now = new Date();
   var thepast = new Date();
   thepast.setFullYear(theyear);
   thepast.setMonth(themonth);
   thepast.setDate(theday);
   var days = Math.floor((now.getTime() - thepast.getTime()) / (1000 * 60 * 60 * 24));
   return days
}

function calcCredit(donation) {
	var taxCredit = 0;
	if (donation <= 372) {
	   taxCredit = (.75 * donation);
	}
	if (donation > 372 && donation <= 1240) {
	   taxCredit = 279 + (0.5 * (donation - 372));
	}
	return taxCredit;
}

function taxCreditTable(tblWidth, tblMargin, tblFloat) {

	var headerText = new Array ("Donation<br />Amount", "Tax<br />Credit");
	// Draw the table
	document.write("<table style = 'width: " + tblWidth + "; ");
	document.write(tblMargin + "; ");
	document.write("float: " + tblFloat + "'>");
	
	document.write("<tr>");  // Draw the Header Row
	for (var loop = 0; loop < headerText.length; loop ++) {
		document.write("<td style='width: 75px' class='donationHeader'>");
		document.write(headerText[loop] + "</td>");
	}
	document.write("</tr>");	// End Header Row

	// Insert the calculated data
	for (var i = 1; i < 14; i++) {
			document.write("<tr>");				// New row
			document.write("<td class='donationDonor'>$");
			if (i == 13) {
				document.write("1240");			// The $1,240 Maximum
			}
			else {
				document.write(i * 100);		// Increments of $100
			}
			document.write("</td>");			// Donation amount
			
			document.write("<td class='donationTaxCredit'>$");
			if (i == 13) {
				document.write(calcCredit(1240));	// The maximum
			}
			else {
			document.write(calcCredit(i * 100));	// Tax Credit
			}
			document.write("</td>");		// Tax Credit amount
			document.write("</tr>");		// End of row
	}												// End of calculated data
	document.write("</table>");			// End of table
	return false;
}

function campaignPhone() {
	// Change back to the Campaign phone number
	document.write("(905) 000-0000");
	return false;
}
