function LayoutStart()
{
	document.write("<table border=0 cellspacing=0 background=" + gFrameBackground + "><tbody>");
}

function LayoutEnd()
{
	document.write("</tbody></table>");
}

function RowStart()
{
	document.write("<tr>");
}

function RowEnd()
{
	document.write("</tr>");
}

function Logo()
{
	document.write("<td align=center><a href=" + gLogoURL + "><img src=" + gLogoSource + " title=\"" + gLogoTitle + "\" alt=\"" + gLogoAlt + "\"></a></td>");
}

function TitleBar()
{
	document.write("<td align=center height=" + gTitleBarHeight + "><font size=\"+3\"><b>" + gTitleBarText + "</b></font></td>");
}

function LinksColumn(linksColumn)
{
	var	j, m;
	for (j = 0, m = linksColumn.length; m > 0; j++, m--)
	{
		var	theLinksItem = linksColumn[j];
		if ( theLinksItem.length == 1 )
		{
			document.write("<p><font size=\"+1\"><b>" + theLinksItem[0] + "</b></font></p>");
		}
		else if ( theLinksItem.length == 2 )
		{
			document.write("<p><a href=" + theLinksItem[1] + " target=_blank>" + theLinksItem[0] + "</a></p>");
		}
		else if ( theLinksItem.length == 3 )
		{
			document.write("<p><a href=" + theLinksItem[1] + ">" + theLinksItem[0] + "</a></p>");
		}
		else if ( theLinksItem.length == 4 )
		{
			document.write("<p><a href=" + theLinksItem[1] + " target=_blank>" + theLinksItem[0] + "</a><br><a href=" + theLinksItem[3] + ">" + theLinksItem[2] + "</a></p>");
		}
	}
}

function SideBar()
{
	document.write("<td align=center valign=top width=" + gSideBarWidth + ">");
	LinksColumn(gFeaturedLinksColumn);
	document.write("<br></td>");
}

function PanelStart()
{
	document.write("<td align=center valign=top height=" + gPanelHeight + " width=" + gPanelWidth + " background=" + gPanelBackground + ">");
}

function PanelEnd()
{
	document.write("</td>");
}

function NavBar(pageName)
{
	var	j, m;
	document.write("<table border=0 cellpadding=0><tbody><tr>");
	for (j = 0, m = gPageData.length; m > 0; j++, m--)
	{
		var	thePageDataItem = gPageData[j];
		var	thePageDataItemName = thePageDataItem[0];
		if ( j != 0 )
		{
			document.write("<td width=24></td>");
		}
		document.write("<td align=center height=" + gNavBarHeight + " width=" + gNavBarWidth + " background=" + gNavBarBackground + "><b>");
		if ( pageName == thePageDataItemName )
		{
			document.write(thePageDataItemName);
		}
		else
		{
			document.write("<a href=" + thePageDataItem[1] + ">" + thePageDataItemName + "</a>");
		}
		document.write("</b></td>");
	}
	document.write("</tr></tbody></table><br>");
}

function ContentStart()
{
	document.write("<table width=\"90%\"><tbody><tr><td align=center>");
}

function ContentEnd()
{
	document.write("</td></tr></tbody></table>");
}

function LinkText(text)
{
	document.write("<a target=_blank href=" + text + ">" + text + "</a><br><br>");
}

function BodyText(text)
{
	document.write(text);
}

function BodyParagraph(text)
{
	document.write("<p>");
	BodyText(text);
	document.write("</p>");
}

function AnnounceText(text)
{
	document.write("<font size=\"+1\">" + text + "</font>");
}

function AnnounceParagraph(text)
{
	document.write("<p>");
	AnnounceText(text);
	document.write("</p>");
}

function SubTitleText(text)
{
	document.write("<font size=\"+2\">" + text + "</font>");
}

function SubTitleParagraph(text)
{
	document.write("<p>");
	SubTitleText(text);
	document.write("</p>");
}

function TitleText(text)
{
	document.write("<font size=\"+3\">" + text + "</font>");
}

function TitleParagraph(text)
{
	document.write("<p>");
	TitleText(text);
	document.write("</p>");
}

function ScorecardTitleParagraph(text)
{
	SubTitleParagraph(text)
}

function ScorecardParagraph(head,text0,text1,link1,text2,link2)
{
	document.write("<p>");
	if ( head != "" )
	{
		document.write("<b>" + head + "</b> ");
	}
	if ( text0 != "" )
	{
		document.write(text0);
	}
	if ( ( text1 != "" ) && ( link1 != "" ) )
	{
		document.write("<br><a href=" + link1 + ">" + text1 + "</a>");
	}
	if ( ( text2 != "" ) && ( link2 != "" ) )
	{
		document.write(", <a href=" + link2 + ">" + text2 + "</a>");
	}
	document.write("</p>");
}

function Prologue(pageName)
{
	LayoutStart();
		RowStart();
			Logo();
			TitleBar();
		RowEnd();
		RowStart();
			SideBar();
			PanelStart();
				NavBar(pageName);
				ContentStart();
}

function Epilogue()
{
				ContentEnd();
			PanelEnd();
		RowEnd();
	LayoutEnd();
}

function Calendar()
{
	var	j, m;
	for (j = 0, m = gCalendarData.length; m > 0; j++, m--)
	{
		var	theCalendarItem = gCalendarData[j];
		var	theDate = new Date(theCalendarItem[0],theCalendarItem[1]-1,theCalendarItem[2]);
		document.write("<p><font size=\"+2\">" + gWeekdays[theDate.getDay()] + ", " + gMonths[theCalendarItem[1]-1] + " " + theCalendarItem[2] + ", " + theCalendarItem[0] + "</font><br><font size=\"+1\">" + theCalendarItem[3] + "<a target=_blank href=" + theCalendarItem[6] + ">" + theCalendarItem[4] + "</a>" + theCalendarItem[5] + "</font></p>" );
	}
}

function LinksTable()
{
	var	j, m;
	document.write("<table width=\"100%\"><tbody align=center valign=top><tr>");
	for (j = 0, m = gLinksData.length; m > 0; j++, m--)
	{
		if ( j != 0 )
		{
			document.write("<td width=\"5%\"></td>");
		}
		document.write("<td width=\"30%\">");
		LinksColumn(gLinksData[j]);
		document.write("</td>");
	}
	document.write("</tr></tbody></table>");
}

function ContactCaptainTable(fullName,phone,email)
{
	var	j, m;
	var	theWidth = 33;
	if ( phone == "" )
	{
		theWidth = 50;
	}
	TitleText("Contact your Precinct Captain");
	document.write("<table width=\"100%\"><tbody align=center valign=top><tr>");
	document.write("<td width=\"" + theWidth + "%\"><font size=\"+1\"><a href=index.html?captain>" + fullName + "</a></font></td>");
	if ( phone != "" )
	{
		document.write("<td width=\"" + theWidth + "%\">" + phone + "</td>");
	}
	document.write("<td width=\"" + theWidth + "%\"><font size=\"+1\"><a href=mailto:" + email + ">" + email + "</a></font></td>");
	document.write("</tr></tbody></table><br>");
}

function ContactOfficeholderTableData(officeholder)
{
	document.write("<td width=\"33%\"><font size=\"+1\"><b>" + officeholder[1] + "</b><br><a target=_blank href=" 
		+ officeholder[3] + ">" + officeholder[2] + "</a></font><br><font size=\"-1\">" + officeholder[4] + "<br>");
	if ( officeholder[5] != "" )
	{
		document.write(officeholder[5] + "<br>");
	}
	document.write("<a href=" + officeholder[7] + ">" + officeholder[6] + "</a><br>");
	if ( officeholder.length > 9 )
	{
		document.write("<a href=" + officeholder[9] + ">" + officeholder[8] + "</a>");
	}
	document.write("</font></td>");
}

function ContactLookup(data,key)
{
	var	j, m;
	var	choice;
	for ( j = 0, m = data.length; m > 0; j++, m-- )
	{
		if ( key == data[j][0] )
		{
			choice = data[j];
			break;
		}
	}
	return	choice;
}

function ContactUSCongressTable(houseNumber)
{
	var	representative = ContactLookup(gUSHouseData,houseNumber);
	TitleText("Contact your US Representatives");
	document.write("<table width=\"100%\"><tbody align=center valign=top><tr>");
	ContactOfficeholderTableData(representative);
	ContactOfficeholderTableData(gUSSenateData[0]);
	ContactOfficeholderTableData(gUSSenateData[1]);
	document.write("</tr></tbody></table><br>");
}

function ContactCALegislatureTable(assemblyNumber,senateNumber)
{
	var	assemblyMember = ContactLookup(gStateAssemblyData,assemblyNumber);
	var	senateMember = ContactLookup(gStateSenateData,senateNumber);
	TitleText("Contact your State Officeholders");
	document.write("<table width=\"100%\"><tbody align=center valign=top><tr>");
	ContactOfficeholderTableData(assemblyMember);
	ContactOfficeholderTableData(senateMember);
	ContactOfficeholderTableData(gSecrataryOfState);
	document.write("</tr></tbody></table><br>");
}

function FullPicture(parameterList)
{
	if ( parameterList.length > 3 )
	{
		document.write("<img src=custom/" + parameterList[3] + " height=\"95%\">");
	}
	else
	{
		document.write("missing parameter: name of picture file");
	}
}

function ThumbPicture(thumbnail,text,full)
{
	document.write("<a href=index.html?picture," + full + "><img src=\"custom/" + thumbnail + "\" alt=\"" + text + "\" align=left></a>");
}

function ParameterList()
{
	var	theIndex = 1;
	var	theParameterList = [ theIndex, gPageNames[ theIndex ], gPageKeys[ theIndex ] ];

	var	theURLSplit = document.URL.split("?");
	if ( theURLSplit.length > 1 )
	{
		var	theArgumentList = theURLSplit[1].split(",");
		var	j;
		var	m;
		for ( j = 0, m = gPageKeys.length; m > 0; j++, m-- )
		{
			if ( theArgumentList[ 0 ] == gPageKeys[ j ] )
			{
				theIndex = j;
				break;
			}
		}
		var	thePrefixList = [ theIndex, gPageNames[ theIndex ] ];
		theParameterList = thePrefixList.concat( theArgumentList );
	}

	return	theParameterList;
}

function PageHead(parameterList)
{
	document.write("<title>" + gSiteName + " " + parameterList[1] + "</title>");
}

function PageBody(parameterList)
{
	var	theIndex = parameterList[0];
	if ( theIndex == 0 )
	{
		FullPicture(parameterList);
	}
	else
	{
		Prologue(parameterList[1]);
		if ( theIndex == 1 )
		{
			TitleParagraph("Precinct " + gPrecinctNumber + " Home Page");
			SubTitleParagraph("Welcome!");
			BodyParagraph("My name is <a href=index.html?captain>" + gCaptainFullName + "</a>, and I am the Democratic Precinct Captain for Santa Clara County Precinct " + gPrecinctNumber + ". This Web Site is a source of voting and political information for the voters of Precinct " + gPrecinctNumber + ".  I hope you find something useful, here.");
		//	SubTitleParagraph("<a target=_blank href=" + gBallot + ">Thank You for Voting!</a>");
		//	AnnounceParagraph("Tuesday, November 7, 2006<br>It was an historic day for Democrats across America, and every voter played a vital role. We can all be proud that we have made our voices heard.");
		//	SubTitleParagraph("<a target=_blank href=" + gBallot + ">Complete results for the Precinct " + gPrecinctNumber + " ballot<br>courtesy of smartvoter.org</a>");
			SubTitleParagraph("<a target=_blank href=" + gBallot + ">Vote!</a>");
			AnnounceParagraph("Tuesday, November 4, 2008<br>" + gPollDescription + "<br><a target=_blank href=" + gPollMap + ">" + gPollAddress + "</a>");
			AnnounceParagraph("In addition to the <a target=_blank href=http://www.cadem.org/site/c.jrLZK2PyHmF/b.2571019/k.6400/2008.htm>Presidential</a>, <a target=_blank href=http://www.cadem.org/site/c.jrLZK2PyHmF/b.4325693/k.D686/Congress.htm>Congressional</a>, and State <a target=_blank href=http://www.cadem.org/site/c.jrLZK2PyHmF/b.4323745/k.A1B4/State_Senate.htm>Senate</a> and <a target=_blank href=http://www.cadem.org/site/c.jrLZK2PyHmF/b.4324627/k.A185/State_Assembly.htm>Assembly</a> Elections, there are several important <a target=_blank href=http://www.cadem.org/site/c.jrLZK2PyHmF/b.4213689/>Initiatives</a> on the ballot.  Check out the California Democratic Party <a target=_blank href=" + gCountyPartyEndorsement + ">endorsements</a>.");
		}
		else if ( theIndex == 2 )
		{
			TitleParagraph("About the Precinct " + gPrecinctNumber + " Web Site");
			BodyParagraph("This Web Site is a source of voting and political information for the voters of Santa Clara County Precinct " + gPrecinctNumber + ". I hope that you find something useful, here.");
			TitleParagraph("About the Precinct Captain");
			BodyParagraph("<a href=index.html?captain>" + gCaptainFullName + "</a> is a resident of Precinct " + gPrecinctNumber + ", and a Democratic activist. In cooperation with the Santa Clara County Democratic Party and the South Bay Labor Council, <a href=index.html?captain>" + gCaptainFirstName + "</a> contacts the Democratic voters of Precinct " + gPrecinctNumber + ", keeps them informed about elections, candidates and issues, and turns the voters out to the polls.");
		}
		else if ( theIndex == 3 )
		{
			TitleParagraph("Precinct " + gPrecinctNumber + " Election Calendar");
			Calendar();
		}
		else if ( theIndex == 4 )
		{
			ContactCaptainTable(gCaptainFullName,gCaptainPhone,gCaptainEMail);
			ContactUSCongressTable(gUSCongress);
			ContactCALegislatureTable(gStateAssembly,gStateSenate);
		}
		else if ( theIndex == 5 )
		{
			TitleParagraph("Precinct " + gPrecinctNumber + " Web Links");
			LinksTable();
		}
		else if ( theIndex == 6 )
		{
			TitleParagraph("About the Precinct Captain");
			ThumbPicture(gCaptainThumbnail,"a picture of "+ gCaptainFullName,gCaptainPicture);
			BodyParagraph("My name is " + gCaptainFullName + ". I am a resident of Precinct " + gPrecinctNumber + ", and a Democratic activist. In cooperation with the Santa Clara County Democratic Party and the South Bay Labor Council, I contact the Democratic voters of Precinct " + gPrecinctNumber + ", keep them informed about elections, candidates and issues, and turn the voters out to the polls.");
		//	BodyParagraph("How did I come to be a Precinct Captain?");
		}
		else if ( theIndex == 7 )
		{
			ScorecardTitleParagraph("Six for '06 Scorecard");
			ScorecardParagraph("Honest Leadership & Open Government","We will end the Republican culture of corruption and restore a government as good as the people it serves, starting with real ethics reform.","H. Res. 6, passed 1/4/2007","http://www.speaker.gov/legislation?id=0002","","");
			ScorecardParagraph("Real Security","We will protect Americans at home and lead the world by telling the truth to our troops, our citizens and our allies. We believe in a strong national defense that is both tough and smart, recognizing that homeland security begins with hometown security.","H. R. 1, passed 1/9/2007","http://www.speaker.gov/legislation?id=0004","","");
			ScorecardParagraph("Energy Independence","We will create a cleaner, greener and stronger America by reducing our dependence on foreign oil, eliminating billions in subsidies for oil and gas companies and use the savings to provide consumer relief and develop energy alternatives, and investing in energy independent technology.","H. R. 6, passed 1/18/2007","http://www.speaker.gov/legislation?id=0009","","");
			AnnounceParagraph("<a href=index.html?6for062>More...</a>");
		}
		else if ( theIndex == 8 )
		{
			ScorecardTitleParagraph("Six for '06 Scorecard");
			ScorecardParagraph("Economic Prosperity & Educational Excellence","We will create jobs that stay in America and restore opportunity for all Americans, starting with raising the minimum wage, expanding Pell grants and making college tuition tax deductible. We also believe in budget discipline that reduces our deficit.","H. R. 2, passed 1/10/2007","http://www.speaker.gov/legislation?id=0005","H. R. 5, passed 1/17/2007","http://www.speaker.gov/legislation?id=0008");
			ScorecardParagraph("A Healthcare System that Works for Everyone","We will join 36 other industrialized nations in making sure everyone has access to affordable health care, starting by fixing the prescription drug program and investing in stem cell and other medical research.","H. R. 3, passed 1/11/2007","http://www.speaker.gov/legislation?id=0006","H. R. 4, passed 1/12/2007","http://www.speaker.gov/legislation?id=0007");
			ScorecardParagraph("Retirement Security","We will ensure that a retirement with dignity is the right and expectation of every single American, starting with pension reform, expanding saving incentives and preventing the privatization of social security.","","","");
		}
		else if ( theIndex == 9 )
		{
			ScorecardTitleParagraph("100 Hour Scorecard");
			ScorecardParagraph("","We will start by cleaning up Congress, breaking the link between lobbyists and legislation and commit to pay-as-you-go, no new deficit spending.","H. Res. 6, passed 1/4/2007","http://www.speaker.gov/legislation?id=0002","","");
			ScorecardParagraph("","We will make our nation safer and we will begin by implementing the recommendations of the independent, bipartisan 9/11 Commission.","H. R. 1, passed 1/9/2007","http://www.speaker.gov/legislation?id=0004","","");
			ScorecardParagraph("","We will make our economy fairer, and we will begin by raising the minimum wage. We will not pass a pay raise for Congress until there is an increase in the minimum wage.","H. R. 2, passed 1/10/2007","http://www.speaker.gov/legislation?id=0005","","");
			ScorecardParagraph("","We will make health care more affordable for all Americans, and we will begin by fixing the Medicare prescription drug program, putting seniors first by negotiating lower drug prices.","H. R. 4, passed 1/12/2007","http://www.speaker.gov/legislation?id=0007","","");
			AnnounceParagraph("<a href=index.html?100hrs2>More...</a>");
		}
		else if ( theIndex == 10 )
		{
			ScorecardTitleParagraph("100 Hour Scorecard");
			ScorecardParagraph("","We will also promote stem cell research to offer real hope to the millions of American families who suffer from devastating diseases.","H. R. 3, passed 1/11/2007","http://www.speaker.gov/legislation?id=0006","","");
			ScorecardParagraph("","We will broaden college opportunity, and we will begin by cutting interest rates for student loans in half.","H. R. 5, passed 1/17/2007","http://www.speaker.gov/legislation?id=0008","","");
			ScorecardParagraph("","We will energize America by achieving energy independence, and we will begin by rolling back the multi-billion dollar subsidies for Big Oil.","H. R. 6, passed 1/18/2007","http://www.speaker.gov/legislation?id=0009","","");
			ScorecardParagraph("","We will guarantee a dignified retirement, and we will begin by fighting any attempt to privatize Social Security.","","","");
		}
		else if ( theIndex == 11 )
		{
			ScorecardTitleParagraph("There is a difference:");
			SubTitleParagraph("<a target=_blank href=http://factcheck.barackobama.com/factcheck/2008/01/14/obamas_strong_record_of_accomp.php>Barack Obama</a>");
			BodyText("Coauthored S. 230 with US Senator Russ Feingold<br>");
			AnnounceText("Most sweeping ethics reform law since Watergate<br><br>");
			BodyText("Was an original cosponsor of S. 2590<br>");
			AnnounceText("Google-like database of Federal funding awards<br><br>");
			BodyText("Coauthored  compliance with UNSC Resolution 1540<br>");
			AnnounceText("Comprehensive nuclear threat reduction strategy<br><br>");
			BodyText("Sponsored Illinois 93rd GA, SB 130<br>");
			AnnounceText("Expanded health care coverage for 70,000 children<br><br>");
			AnnounceText("and more...<br>");
			LinkText("http://factcheck.barackobama.com");
			SubTitleParagraph("<a target=_blank href=http://www.mccainpedia.org/index.php/Main_Page>John McCain</a>");
			AnnounceText("Voted against raising the minimum wage 19 times<br>");
			LinkText("http://www.politifact.com/truth-o-meter/statements/667");
			AnnounceText("Opposes equal pay for Women<br>");
			LinkText("http://blog.washingtonpost.com/the-trail/2008/04/24/by_juliet_eilperin_washington.html");
			AnnounceText("Would continue Bush's policy of Endless War<br>");
			LinkText("http://www.youtube.com/watch?v=MEc2ot3QGB4");
		}
		Epilogue();
	}
}
