// a function to discover which radio button is selected
function radio_poll()
{  
  var correct = 0;
  var guildtotals = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  var answerstring = "<body bgcolor=\"#f9b6b6\"><center><h2>What Guild Are You? Answers</h2></center><br>";
  // loop through all radio buttons                                   
  for(var i=0; i < 5; i++)
  {        
    // if the radio is selected, use its value
    if( document.forms.f.q1[i].checked )
    {
      guildtotals[1] += i + 1;
    } 
    if( document.forms.f.q2[i].checked )
    {
      guildtotals[2] += i + 1;
    } 
    if( document.forms.f.q3[i].checked )
    {
      guildtotals[3] += i + 1;
    }
    if( document.forms.f.q4[i].checked )
    {
      guildtotals[4] += i + 1;
    } 
    if( document.forms.f.q5[i].checked )
    {
      guildtotals[5] += i + 1;
    }  
    if( document.forms.f.q6[i].checked )
    {
      guildtotals[5] += i + 1;
    } 
    if( document.forms.f.q7[i].checked )
    {
      guildtotals[6] += i + 1;
    } 
    if( document.forms.f.q8[i].checked )
    {
      guildtotals[3] += i + 1;
    } 
    if( document.forms.f.q9[i].checked )
    {
      guildtotals[6] += i + 1;
    } 
    if( document.forms.f.q10[i].checked )
    {
      guildtotals[7] += i + 1;
    } 
    if( document.forms.f.q11[i].checked )
    {
      guildtotals[1] += i + 1;
    } 
    if( document.forms.f.q12[i].checked )
    {
      guildtotals[4] += i + 1;
    }
    if( document.forms.f.q13[i].checked )
    {
      guildtotals[8] += i + 1;
    }  
    if( document.forms.f.q14[i].checked )
    {
      guildtotals[6] += i + 1;
    } 
    if( document.forms.f.q15[i].checked )
    {
      guildtotals[4] += i + 1;
    } 
    if( document.forms.f.q16[i].checked )
    {
      guildtotals[7] += i + 1;
    } 
    if( document.forms.f.q17[i].checked )
    {
      guildtotals[9] += i + 1;
    } 
    if( document.forms.f.q18[i].checked )
    {
      guildtotals[1] += i + 1;
    } 
    if( document.forms.f.q19[i].checked )
    {
      guildtotals[8] += i + 1;
    } 
    if( document.forms.f.q20[i].checked )
    {
      guildtotals[9] += i + 1;
    } 
    if( document.forms.f.q21[i].checked )
    {
      guildtotals[2] += i + 1;
    } 
    if( document.forms.f.q22[i].checked )
    {
      guildtotals[10] += i + 1;
    } 
    if( document.forms.f.q23[i].checked )
    {
      guildtotals[5] += i + 1;
    } 
    if( document.forms.f.q24[i].checked )
    {
      guildtotals[10] += i + 1;
    } 
    if( document.forms.f.q25[i].checked )
    {
      guildtotals[3] += i + 1;
    } 
    if( document.forms.f.q26[i].checked )
    {
      guildtotals[7] += i + 1;
    } 
    if( document.forms.f.q27[i].checked )
    {
      guildtotals[8] += i + 1;
    } 
    if( document.forms.f.q28[i].checked )
    {
      guildtotals[10] += i + 1;
    } 
    if( document.forms.f.q29[i].checked )
    {
      guildtotals[2] += i + 1;
    } 
    if( document.forms.f.q30[i].checked )
    {
      guildtotals[9] += i + 1;
    } 
  }
var max = 1;
var maxguild = "";
var tie = false;
for(i=2; i<10; i++)
{
  if(guildtotals[i] > guildtotals[max])
  {
    max = i;
    tie = false;
  }
  if(guildtotals[i] == guildtotals[max])
  {
    maxguild = "A Tie!";
    tie = true;
  }
}
if(!tie)
{
  if(max == 1) maxguild = "Azorius";
  if(max == 2) maxguild = "Dimir";
  if(max == 3) maxguild = "Boros";
  if(max == 4) maxguild = "Golgari";
  if(max == 5) maxguild = "Simic";
  if(max == 6) maxguild = "Selesnya";
  if(max == 7) maxguild = "Rakdos";
  if(max == 8) maxguild = "Orzhov";
  if(max == 9) maxguild = "Izzet";
  if(max == 10) maxguild = "Gruul";
}

guildtotals[1] += ": Azorius Senate<br>";
guildtotals[2] += ": House Dimir<br>";
guildtotals[3] += ": Boros Legion<br>";
guildtotals[4] += ": The Golgari<br>";
guildtotals[5] += ": Simic Combine<br>";
guildtotals[6] += ": Selesnya Conclave<br>";
guildtotals[7] += ": Cult of Rakdos<br>";
guildtotals[8] += ": Orzhov Syndicate<br>";
guildtotals[9] += ": Izzet League<br>";
guildtotals[10] += ": Gruul Clans<br>";
guildtotals.sort;

guildtotals[0] = "";

answerstring = "<b>Your Guild is: " + maxguild + "</b><br>" + guildtotals.join("");
var popwindow = window.open("","","top=30.left=30,width=400,height=400,resizable,scrollbars,menubar");
popwindow.document.open();
popwindow.document.write("<title>What Guild Are You? Answers</title>");
popwindow.document.bgColor="#f9b6b6";
popwindow.document.write(answerstring);
popwindow.document.close;                             
}

