// Event Calendar
// copyright Stephen Chapman, 10th June 2006, 30th October 2006

var tb = 't'; // top or bottom (t or b)
var headbg = '#ccccff';  // table heading background colour
var todaybg = '#99cccc'; // current selected date background colour
var textclr = '#000000';// text colour
var linkclr = '#ff9999'; // link text colour
var noMessage =  'No event messages to display for today'; // message to display when no entry in array

var dA = new Array(); var x = 0;
// first 8 characters in ccyymmdd format for single date events
// first 8 characters in 0000mmdd format for every year events
dA[x++] = "00000101 New Year";
dA[x++] = "00000214 Valentine's day";
dA[x++] = "00001206 St Nicholas' Day";
dA[x++] = "20080917 <b>Sept. 17:&nbsp;</b><a href=http://www.engagedcitizen.org/>Center for Communication & Civic Engagement</a> <br><i>Covering Elections Abroad,</i> Comm 126, 12-1:30 pm";
dA[x++] = "20080920 <b>Sept. 20:&nbsp</b>WA State Governor's Debate, KOMO-TV4, 9pm";
dA[x++] = "20080926 <b>Sept. 26:&nbsp;</b><a href= http://www.debates.org/>Presidential Debates</a><br>1st Presidential Debate, Odegaard Library, Room 220, 6-8pm";
dA[x++] = "20081001 <b>Oct. 1:&nbsp;</b><a href=http://www.engagedcitizen.org/>Center for Communication & Civic Engagement </a><br><i>Digital Media, Viral Video, & Coverage of the Personal Behavior of Candidates,</i> Comm 126, 12-1:30 pm <br><br><i>Do Campaigns Ads Really Work? The Effectiveness of Targeted Ads in the 2008 Presidential Election: A Controlled Experiment, </i>Denny 401, 12:30-1:20pm <br><br>WA State Governor's Debate, PBS-KCTS9, 7pm";
dA[x++] = "20081002 <b>Oct. 2:&nbsp</b><a href= http://www.debates.org/>Presidential Debates</a><br>Vice Presidential Debate, Odegaard Library, Room 220, 6-8pm";
dA[x++] = "20081004 <b>Oct. 4:&nbsp</b><a href=https://wei.secstate.wa.gov/osos/secure/pages/Onlinevoterregistration.aspx>Voter Registration Deadline</a>";
dA[x++] = "20081006 <b>Oct. 6:&nbsp;</b><a href=http://www.engagedcitizen.org/>Center for Communication & Civic Engagement</a><br><i>No One Knew How to Run a Woman as Leader of the Free World: Hillary Clinton's Gender Strategy in Campaign 2008,</i> Comm 126, 3:30-5pm <br><br><a href= http://depts.washington.edu/leader/>Carlson Center</a><br><i>Community Dialogue</i>, Mary Gates Hall, Room 293 (POE Multipurpose Room), 5:30-7pm";
dA[x++] = "20081007 <b>Oct. 7:&nbsp;</b><a href= http://www.debates.org/>Presidential Debates</a><br>2nd Presidential Debate, Odegaard Library, Room 220, 6-8pm <br><br><a href=http://www.polisci.washington.edu/Conferences/conferences.html>Political Science Dept.</a><br><i>Russian-American Relations: Challenges for the New American Administration, </i> Kane Hall 220, 7pm";
dA[x++] = "20081009 <b>Oct. 9:&nbsp;</b><a href=http://jsis.washington.edu/religion/events/>Comparative Religion Program</a> <br><i>Religious Politics in America: Why the 2008 Presidential Election May Change Everything for Everyone,</i> Kane Hall 120, 7:30pm <br><br>WA State Governor's Debate, PBS-KCTS9, 7pm";
dA[x++] = "20081010 <b>Oct. 10:&nbsp;</b><a href= http://www.lib.washington.edu/govpubs/classes/constitution.html>Constitutional Read-Aloud</a><br><br><a href=http://www.polisci.washington.edu/Conferences/conferences.html>Political Science Dept.</a><br><i>Lobbying and Policy Change in Washington, DC </i>Gowen 1A, 1:30-3pm";
dA[x++] = "20081015 <b>Oct. 15:&nbsp;</b><a href= http://www.debates.org/>Presidential Debates</a><br>3rd Presidential Debate, Odegaard Library, Room 220, 6-8pm<br><br>WA State Governor's Debate, KING5-TV, 8pm";
dA[x++] = "20081016 <b>Oct. 16:&nbsp;</b><a href=http://www.engagedcitizen.org/>Center for Communication & Civic Engagement</a> <br><i>The Debates & the Dynamics of Campaign 2008,</i> Gowen 1A, 12-1:30 pm";
dA[x++] = "20081020 <b>Oct. 20:&nbsp</b><a href=http://www.kingcounty.gov/elections/registration.aspx>Last Day to Register In Person</a>";
dA[x++] = "20081027 <b>Oct. 27:&nbsp;</b><a href=http://jsis.washington.edu/religion/events/>Comparative Religion Program</a><br><i>Iran & Future of the Middle East,</i> Kane Hall 120, 7:30pm";
dA[x++] = "20081028 <b>Oct. 28:&nbsp;</b><a href=http://www.engagedcitizen.org/>Center for Communication & Civic Engagement</a> <br><i>Barack Obama & the Electoral Politics of Race, </i> Gowen 1A, 12-1:30 pm <br><br><a href=http://jsis.washington.edu/religion/events/>Comparative Religion Program</a> <br><i>The African American Church & Presidential Politics, </i>Kane Hall 120, 7:30pm";
dA[x++] = "20081031 <b>Oct. 31:&nbsp;</b><a href=http://jsis.washington.edu/religion/events/>Comparative Religion Program</a><br><i>Iraq & the US Presidential Election,</i> Kane Hall 120, 7:30pm <br><br><a href=http://www.trickorvote.org/>Trick or Vote:</a> A nationwide nonpartisan costume canvass, Downtown Seattle 1007 E. Pike St., 3:30pm";
dA[x++] = "20081104 <b>Nov. 4:&nbsp</b>General Election Day <br><br>Watch the Election Returns Live, Odegaard Library, Room 220, All Day";
dA[x++] = "20081105 <b>Nov. 5:&nbsp;</b><a href=http://www.engagedcitizen.org/>Center for Communication & Civic Engagement</a><br><i>Election 2008: What Happened and Why,</i> Comm 126, 12-1:30 pm";
dA[x++] = "20081113 <b>Nov. 13:&nbsp;</b><a href=https://go.washington.edu/uwaa/events/200811provost_election08/details.tcl>2008 Fall Provost Distinguished Lecture: </a><br><i>Election '08: What Really Happened</i> Kane 130, 7:00-9:00 pm";

// dA[x++] = "20060610 New Event Calendar Started today";

// permission is granted to use this javascript provided that the below code is not altered
var pageLoaded = 0; window.onload = function() {pageLoaded = 1;}
function loaded(i,f) 
{if (document.getElementById && document.getElementById(i) != null) f(); 
else if (!pageLoaded) setTimeout('loaded(\''+i+'\','+f+')',100);
}

function monthlength(month,year) 
{var dd = new Date(year, month, 0);return dd.getDate();}
var moy = ['January','February','March','April','May','June','July','August','September','October','November','December'];
var today = new Date();
var selDate = today.getFullYear()+getmmdd(today.getMonth()+1,today.getDate());

function dispCal(yy,mm) 
{if (mm < 0 || mm > 12) {alert('month must be between 1 and 12'); 
return false;} 
if (yy != 0 && (yy < 1901 || yy > 2100)) 
{alert('year must be after 1900 and before 2101'); 
return false;} 

var dow = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat']; 
var calendar = new Date();  
var today = calendar.getDate(); calendar.setDate(1); 
if (yy > 1900) calendar.setFullYear(yy); 
if (mm > 0) calendar.setMonth(mm - 1); 
var yy = year = calendar.getFullYear(); 
var month = calendar.getMonth(); calendar.setDate(today); 
var weekday = calendar.getDay(); 
var daysInMonth = monthlength(month+1,year); 

var hilite_start = '<td width="30" style="background:' + todaybg + '" align="center"><b>'; 
var td_start = '<td width="30" align="center">'; 



var cal = '<div id="cal"><div style="border:1pt solid #ccccdd;height:130px;width:220px; font-family:Verdana; font-size:12px"><table border="0" cellspacing="0" cellpadding="2" align="center"><tr><td colspan="7" style="background:' + headbg + '" align="center"><b>' + moy[month]  + ' ' + year + '<\/b><\/td><\/tr><tr>'; 



for(dex=0; dex < 7; dex++) {cal += td_start + dow[dex] + '</td>';} cal += '<\/tr><tr>'; 
var day2 = today; 
for (dex = today; dex > 6; dex -=7) day2 = dex; weekday -= day2 - 1; 
while (weekday < 0) weekday += 7; 
for(dex=0; dex < weekday; dex++) cal += td_start + ' <\/td>'; 
for(dex=1; dex <= daysInMonth; dex++) 
{if(weekday == 7) {cal += '</tr><tr>'; weekday = 0;} 
if(selDate==year+getmmdd(month+1,dex)) cal += hilite_start +'<span'+clickDate(dex,month,year) + '>'+ dex + '<\/span><\/b><\/td>'; 
else cal += td_start + '<span '+clickDate(dex,month,year) + '>' + dex + '<\/span><\/td>'; weekday += 1;} 
for(dex=weekday; dex < 7; dex++) cal += td_start + ' <\/td>'; cal += '<\/tr><\/table><\/div>';
if (document.getElementById) 
{var mmb = month;  mm = month + 1; 

var yya = yyb = yy; 
if (mmb <1) {mmb += 12; yyb--;} 
var mma = month + 2; 
if (mma > 12) {mma -= 12; yya++;} 
var yb = yy -1; 
var ya = yy +1; cal += '<table border="0" cellspacing="0" cellpadding="2" width="210"><tr><td><a href="#" onclick="if (cala = dispCal('+yb+','+mm+')) {document.getElementById(\'cal\').innerHTML = cala; return false;}"><<</a></td><td><a href="#" onclick="if (cala = dispCal('+yyb+','+mmb+')) {document.getElementById(\'cal\').innerHTML = cala; return false;}"><</a></td><td align="right"><a href="#" onclick="if (cala = dispCal('+yya+','+mma+')) {document.getElementById(\'cal\').innerHTML = cala; return false;}">></style></a></td><td align="right"><a href="#" onclick="if (cala = dispCal('+ya+','+mm+')) {document.getElementById(\'cal\').innerHTML = cala; return false;}">>></a></td></tr></table>';} 
else {cal += '<div> </div>';} cal += '</div>'; return cal;}


function start() 
{var x = '<div id="calDate" style="border:1pt solid #cccccc;width:220px; font-family:Verdana; font-size:11px"><\/div>'; 
var y = ''; 
if (tb == 't') y = x + dispCal(0,0); 
else y = dispCal(0,0) + x; document.getElementById('calendar').innerHTML = y; ev();}
loaded('calendar',start);

function clickDate(day, month, year) 
{var ct = nextDate(year + getmmdd(month+1,day));
if (ct == '') ct = nextDate('0000' + getmmdd(month+1,day));
if (ct == '') 
return 'style="color:'+textclr+'"'; 
else return 'style="cursor:pointer;color:'+linkclr+'" onclick="selDate = '+year+ getmmdd(month+1,day)+'; isDate(' + day + ',' + month + ',' + year + ');return false;"';}

function isDate(dayVal,monthVal,yearVal) 
{var ct = nextDate(yearVal + getmmdd(monthVal+1,dayVal));
if (ct == '') ct = nextDate('0000' + getmmdd(monthVal+1,dayVal));
if (ct == '') ct = noMessage;document.getElementById('calDate').innerHTML = selDate + ':<br \/>' +ct; 
return false;}

function nextDate(yymmdd) 
{var x = dA.length;
for (var i = 0; i < x; i++) 
{if (dA[i].substr(0,8) == yymmdd) 
return dA[i].substr(8);}return '';}

function getmmdd(mm,dd) 
{return (mm > 9 ? '' + mm : '0' + mm) + (dd > 9 ? dd : '0' + dd);}
function ev() 
{var ct = nextDate(selDate);
var ct = nextDate(selDate);
if (ct == '') ct = nextDate('0000' + selDate.substr(4));
if (ct == '') ct = noMessage; document.getElementById('calDate').innerHTML = selDate + ':<br \/> ' +ct;}
