
var jslf='\n';

function get_cookie(name)
{
 var cookies=document.cookie.split('; ');
 var temp;
 for(i=0;i<cookies.length;i++)
 {
  temp=cookies[i].split('=');
  if(temp[0]==name)
   return(temp[1]);
 }
 return(null);
} 

draw_styles();

var poll=get_cookie("poll");
if(poll!=null)
 draw_results();
else
 draw_poll();


function draw_poll()
{
document.write(""+
""+jslf+
"<table width=142 cellpadding=0 cellspacing=0 border=0 class='polltable'>"+jslf+
"<form method=post name='pollform' onSubmit='document.pollform.redirect.value=document.location;' action='/TServe/modules/poll_navbar/poll.cgi'>"+jslf+
"<input type=hidden name='display_votes' value=''>"+jslf+
"<input type=hidden name='redirect' value=''>"+jslf+
"<input type=hidden name='poll' value='2007-10-3'>"+jslf+
"<input type=hidden name='action' value='submit'>"+jslf+
" <tr>"+jslf+
"  <td width=100%>"+jslf+
"   <table width=100% cellpadding=1 cellspacing=0 border=0 class='pollquestion'>"+jslf+
"    <tr>"+jslf+
"     <td>Why Haven't You Attended A Rally Against Illegal Immigration?</td>"+jslf+
"    </tr>"+jslf+
"   </table>"+jslf+
"   <table width=100% cellpadding=1 cellspacing=0 border=0>"+jslf+
"<tr><td><input type=radio name='selection' value='1'></td><td width=100% class='pollselections'>I don't have the time</td></tr>"+jslf+
"<tr><td><input type=radio name='selection' value='2'></td><td width=100% class='pollselections'>I'm not that concerned</td></tr>"+jslf+
"<tr><td><input type=radio name='selection' value='3'></td><td width=100% class='pollselections'>I don't know where they are</td></tr>"+jslf+
"<tr><td><input type=radio name='selection' value='4'></td><td width=100% class='pollselections'>I'm not physically able</td></tr>"+jslf+
"<tr><td><input type=radio name='selection' value='5'></td><td width=100% class='pollselections'>I have attended a rally</td></tr>"+jslf+
""+jslf+
"   </table>"+jslf+
"   <table width=100% cellpadding=1 cellspacing=0 border=0 class='pollbutton'>"+jslf+
"    <tr>"+jslf+
"     <td style='text-align: center;'><input type=submit value='My Choice'></td>"+jslf+
"    </tr>"+jslf+
"   </table>"+jslf+
"  </td>"+jslf+
" </tr>"+jslf+
"</form>"+jslf+
"</table>"+jslf+
"");}

function draw_styles()
{
document.write(""+
""+jslf+
"<style>"+jslf+
".polltable { border: 3px outset rgb(200,150,200); background-color: rgb(255,255,255); }"+jslf+
".pollquestion { background-color: rgb(225,180,255); color: #000000; font: Bold 11px Helvetica, sans-serif; border-bottom: 3px outset rgb(200,150,200); }"+jslf+
".pollbutton { background-color: rgb(225,180,255); border-top: 3px outset rgb(200,150,200); }"+jslf+
".pollbutton input { background-color: rgb(255,255,255); border-color: rgb(255,255,255); color: #000000; font:  11px Helvetica, sans-serif; }"+jslf+
".pollselections { color: #000000; font: Bold 10px Helvetica, sans-serif; }"+jslf+
".pollnames { font: Bold 10px Helvetica, sans-serif; border-bottom: 1px solid #cccccc;}"+jslf+
".pollvotedisplay { color: #000000; font:  9px Verdana, sans-serif; border-bottom: 1px solid #000000; }"+jslf+
".pollgraph { background-color: rgb(160,100,200); border-bottom: 1px solid #cccccc; }"+jslf+
"</style>"+jslf+
"");}

function draw_results()
{
 var results=get_cookie('results').split('|');
 var options=get_cookie('options').split('|');
 var question=get_cookie('question');
 var display_votes=get_cookie('display_votes');
 var total=0; var graphwidth=142-(1*6); var graphheight=5; var graphpct=graphwidth/100; 
 for(i=0;i<results.length;i++)
 {
  total=total+parseInt(results[i]);
 }

 document.write("<table cellpadding=1 cellspacing=0 border=0 width=142 class='polltable'>"+jslf);
 document.write("<tr><td colspan=2 class='pollquestion'>"+question+"</td></tr>"+jslf);

 for(i=0;i<results.length;i++)
 {
  percentage=parseInt((results[i]/total)*100);
  imgwidth=parseInt(percentage*graphpct);
  blankwidth=graphwidth-imgwidth;
  document.write("<tr><td class='pollnames'>"+options[i]+"</td><td class='pollnames' align=right>"+percentage+"%</td></tr>"+jslf);
  document.write("<tr><td class='pollgraph' width='100%' colspan=2><img src='/TServe/modules/poll_navbar/graph.gif' width='"+imgwidth+"' height='"+graphheight+"'><img src='/TServe/modules/poll_navbar/graphhollow.gif' width='"+blankwidth+"' height='"+graphheight+"'></td></tr>"+jslf);
  if(display_votes != null)
   document.write("<tr><td class='pollvotedisplay' colspan=2>"+results[i]+" Votes</td></tr>"+jslf);
 }
 if(display_votes != null)
  document.write("<tr align=center><td colspan=2 class='pollquestion'>"+total+" Total Votes</td></tr>"+jslf);

 document.write("</table>"+jslf);
}
