// JavaScript Document

function calcSection(sectionName,SectionRows,SectionYears) {
	/* Fill in the spreadsheet, 1 section at a time
	Section Name
	Section Rows
	Section Years
	RETURN: None - works direct on doctument.form
	*/

	var mySectionName = sectionName; 
	var mySectionRows = SectionRows; 
	var mySectionYears = SectionYears; 
	for (c=1;c<=mySectionYears;c++) {
		var mySectionTotal = 0;
		for (r=1;r<=mySectionRows;r++) {
		myCurrentValue = eval("$F('" + mySectionName + r + c +"')");
		if (myCurrentValue != "") {
			mySectionTotal = parseInt(mySectionTotal) + parseInt(myCurrentValue);
			eval("$('" + mySectionName + "T" + c + "')").innerHTML = parseInt(mySectionTotal);
			} else {
			if (parseInt(mySectionTotal) == 0) {
				eval("$('" + mySectionName + "T" + c + "')").innerHTML = 0;
			}
	
			}
		}
	}
}


//Makes sure that the entered value is a number
// use via onKeyPress="checkNum()" on the textbox
function checkNum(){
	var carCode = event.keyCode;
	//if ((carCode < 46) || (carCode > 57)){
	if ((carCode < 48) || (carCode > 57)){
		//alert(carCode);	
		alert('Please enter only numbers.');	
		event.cancelBubble = true;	
		event.returnValue = false;	
	}
}

/* String functions */
function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
/* Date functions */
today = new Date
weekDayName = new Array ("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
monthName = new Array ("January","February","March","April","May","June","July","August","September","October","November","December")
function printDate()
	{
	document.write("&nbsp;" + weekDayName[today.getDay()]+ ", " + monthName[today.getMonth()] + " " + today.getDate() + ", 20" + Right(today.getYear(), 2) + "&nbsp;")
	}

/* Round to Cents */
function cent(n) {
 pennies = n * 100;

 pennies = Math.round(pennies);

 strPennies = "" + pennies;
 len = strPennies.length;

 return strPennies.substring(0, len - 2) + "." + strPennies.substring(len - 2, len);
}
