//
// popup a new window with the given URL
//
function popUp(tempURL) {
	newwindow = window.open(tempURL, '_blank');
	if (window.focus) { 
		newwindow.focus(); 
	}
	return false;
}

//
// given a date, return the day of the week
//
function getDayOfWeek(adate) {
	var weekday = [ "Sunday", "Monday", "Tuesday" , "Wednesday", "Thursday", "Friday", "Saturday" ];
	return weekday[adate.getDay()];
}

//
// echo a simple sched row day
//
function echoSchedRowDay(rowDay) {
	document.write("<td class=\"xsmall\" nowrap> <div align=\"right\"> " + rowDay + "</div> </td>");
}

//
// echo the header rows for a simple sched table
//
function echoTableHeaders(sTitle) {

	document.write("<table>");
	document.write("<td width=\"20\" valign=\"top\"> </td>");
	document.write("<td width=\"600\" valign=\"top\" align=\"center\"> <h3> ");
	document.write(sTitle); 
	document.write("<br>");
	document.write("<table border=\"4\" cellspacing=\"0\" cellpadding=\"2\">");

	document.write("<tr bgcolor=\"#000000\"> ");
	document.write("<td class=\"xsmall\" width=\"40\" > <div align=\"center\"><b><font color=\"#FF9900\">  </font></b></div></td>");
	document.write("<td class=\"xsmall\" width=\"80\" > <div align=\"center\"><b><font color=\"#FF9900\">  </font></b></div></td>");
	document.write("<td class=\"xsmall\" width=\"40\" > <div align=\"center\"><b><font color=\"#FF9900\">  </font></b></div></td>");

	document.write("<td class=\"xsmall\" width=\"350\"> <b><font color=\"#FF9900\">  </font></b></td>");
	document.write("<td class=\"xsmall\" width=\"80\"> <b><font color=\"#FF9900\">  </font></b></td>");
	document.write("</tr>");

	document.write("<tr bgcolor=\"#000000\"> ");
	document.write("<td class=\"xsmall\"  > <div align=\"center\"><b><font color=\"#FF9900\"> Day </font></b></div></td>");
	document.write("<td class=\"xsmall\"  > <div align=\"center\"><b><font color=\"#FF9900\"> Date </font></b></div></td>");
	document.write("<td class=\"xsmall\"  > <div align=\"center\"><b><font color=\"#FF9900\"> H/A </font></b></div></td>");
	document.write("<td class=\"xsmall\"  > <div align=\"center\"><b><font color=\"#FF9900\"> Event </font></b></div></td>");
	document.write("<td class=\"xsmall\"  > <div align=\"center\"><b><font color=\"#FF9900\"> Start Time </font></b></div></td>");

	document.write("</tr>");
}

//
// echo a mapquest call
//
function echoSchedDirections(rHomeAddr, rHomeZip, rAddr, rZip) {

// http://www.mapquest.com/maps
// ?&1a=7878+Brighton+Rd&1z=48116-7762a&1s=MI&1y=US
// &2a=11911+Clinton+River+Rd&2z=48313-24202s=MI&2y=US

	if (rAddr.length > 0) {
		var sTemp1 = rAddr.replace(/ +/g,' ');
		var sTemp2 = sTemp1.split(' ');
		var sPlusAddr = sTemp2.join('+');

		document.write(" <a href=\"http://www.mapquest.com/maps?");
		document.write("&1a=");
		document.write(rHomeAddr);
		document.write("&1z=");
		document.write(rHomeZip);
		document.write("&1s=MI");
		document.write("&1y=US");
		document.write("&2a=");
		document.write(sPlusAddr);
		document.write("&2z=");
		document.write(rZip);
		document.write("&2s=MI");
		document.write("&2y=US");
		document.write("\" ");
		document.write(" target=_blank > (Directions) </a>");
	}
}

//
// output a simple schedule row
//
function echoSchedRow(rRowCount, rMonth, rDay, rYear, rWhere, rTime, rEvent, rHomeAddr, rAddr, rZip) {

	var rColor;
	if ((rRowCount % 2) == 1) {
		rColor = "FFFFFF";
	} else {
		rColor = "FF9900";
	}

	rRowCount++;

	document.write("<tr bgcolor=\"#" + rColor + "\" valign=\"top\">");

	var adate = new Date();
	adate.setFullYear(rYear, (rMonth-1), rDay);
	echoSchedRowDay(getDayOfWeek(adate));

	var rDate = rMonth + "/" + rDay + "/" + rYear;

	document.write("<td class=\"xsmall\" nowrap> <div align=\"right\"> " + rDate + " </div> </td>");
	document.write("<td class=\"xsmall\" nowrap> <div align=\"center\">" + rWhere + " </div> </td>");
	document.write("<td class=\"xsmall\" nowrap> <div align=\"left\"> ")
	document.write(rEvent);

	if (rWhere == "Away") {
		if (rAddr.length > 0) {
			echoSchedDirections(rHomeAddr, "48116", rAddr, rZip);
		}
	}
	document.write("</div> </td>");
	document.write("<td class=\"xsmall\" nowrap> <div align=\"right\"> " + rTime + "</div> </td>");

	document.write("</tr>");
	return rRowCount;
}

