function initOfficeFilter() { var s = window.location.toString().split('/'); var o = document.getElementById("e.2k8.c.office.filter"); for(a in s) { if(s[a]==='race') { var race = s[parseInt(a) + 1]; for (i=0; i < o.options.length; i++) { if (o.options[i].value === race) { o.value = race; dispCountyOfficeFilter(); return; } } break; } } o.value = 'president'; dispCountyOfficeFilter(); return; } function dispCountyOfficeFilter() { var p = document.getElementById("e.2k8.county.filter"); p.selectedIndex = 0; var o = document.getElementById("e.2k8.c.office.filter"); switch( o.value) { case 'president': dispCountyOffice('President'); break; case 'senate': dispCountyOffice('Senate'); break; case 'house': dispCountyOfficeHouse(); break; case 'governor': dispCountyOffice('Governor'); break; default: } } function dispCountyFilter() { var p = document.getElementById("e.2k8.c.office.filter"); p.selectedIndex = 0; var o = document.getElementById("e.2k8.county.filter"); var county = o.value; if(county != '') { dispCounty(county); } } function dispCounty(county) { var d = document.getElementById("e.2k8.county.results"); d.innerHTML = ''; if (countyResults[county]) { var div = document.createElement('div'); var s = 'election county state' div.setAttribute('class',s); div.innerHTML = '

' + countyResults[county].county + '

' + GetCounty(countyResults[county]); d.appendChild(div); } } function GetCounty(county) { var s = ''; for (a in county) { switch(a) { case 'President': s += GetOffice(county['President'],'President',true); break; case 'Governor': s += GetOffice(county['Governor'],'Governor',true); break; case 'Senate': s += GetOffice(county['Senate'],'Senate',true); break; case 'Senate ': s += GetOffice(county['Senate '],'Senate '); break; default: if(a.toString().indexOf('District') != -1) { s += GetOffice(county[a],a,true); } break; } } return s; } function dispCountyOffice(office) { var d = document.getElementById("e.2k8.county.results"); d.innerHTML = ''; for (a in countyResults) { if(countyResults[a][office]) { break; } else { return; } } var rh = GetRaceHeader(office); d.appendChild(rh); for (a in countyResults) { var cc = GetCountyOffice(countyResults[a],office); d.appendChild(cc); } } function dispCountyOfficeHouse() { var d = document.getElementById("e.2k8.county.results"); d.innerHTML = ''; var maxDis = parseInt(numDistricts); if (!maxDis) { return; } for (x = 1; x <= maxDis; x++) { var distCount = 0; var c = GetAnchor('District_' + x); d.appendChild(c); c = GetRaceHeader('U.S. House - District ' + x); d.appendChild(c); for (a in countyResults) { if(countyResults[a]['District ' + x]) { c = GetCountyOffice(countyResults[a], 'District ' + x) d.appendChild(c); distCount++; } } if (distCount <= 0) { c = GetMessage('County-level data not collected for this race'); d.appendChild(c); } } } function GetRaceHeader(office) { var div = document.createElement('div'); div.setAttribute('class','election county office'); div.innerHTML = '

' + office + '

'; return div; } function GetAnchor(txt) { var a = document.createElement('a'); a.setAttribute('name',txt); a.setAttribute('id',txt); return a; } function GetMessage(msg) { var div = document.createElement('div'); div.setAttribute('class','election county message'); div.innerHTML = '

' + msg + '

'; return div; } function GetCountyOffice(county, office) { var div = document.createElement('div'); var s = 'election county state' div.setAttribute('class',s); if (office.indexOf('Senate') != -1) { if (county['Senate']) { s = GetOffice(county['Senate'], 'Senate'); } if (county['Senate ']) { s += GetOffice(county['Senate '], 'Senate '); } } else { s = GetOffice(county[office], office); } div.innerHTML = '

' + county.county + '

' + s; return div; } function GetOffice(office, officeStr, showOffice) { var oHeader = ''; var oFooter = ''; var cResults = ''; if (showOffice) { if (officeStr.indexOf("District") != -1) { officeStr = 'U.S. House - ' + officeStr; } oHeader = '

' + officeStr + '

'; } if (office.poll_close) { oFooter = 'Polls close at ' + office.poll_close; } else { oFooter = office.precincts + '% of precincts reporting'; cResults = GetCandidates(office.c); } var s = '
' + oHeader + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + cResults + '' + '
CandidateVotes% of votes
' + oFooter + '
' + '
'; return s; } function GetCandidates(c) { var s = ''; for ( a in c) { s += GetCandidateResults(c[a]); } return s; } function GetCandidateResults(cr) { var s = '' + '' + cr.fl_name + '' + ' (' + cr.party.toString().substring(0,3) +')' +'' +(cr.incumbent? cr.incumbent: '') +'' +'' + cr.votes +'' + '' + cr.vote_pct + '%' + '' + ''; return s; }