// Used to open the various results windows

function viewResults( url ) {
  w = window.open( url, "results",
    "location=0,menubar=0,toolbar=0,resizable=1,scrollbars=1,height=440,width=500" );
  w.focus();
}

function viewOther( url ) {
  w = window.open( url, "results",
    "location=0,menubar=0,toolbar=0,resizable=1,scrollbars=1,height=440,width=500" );
  w.focus();
}

// Requirements for using the following functions
// You must have a <FORM> with the following elements
// selectedPolls  select box
// PollSelect     select box
// selectedIds    hidden field

function updateSelectedPolls() {
  len = document.forms[0].selectedPolls.options.length;
  value = "";

  for( i = 0 ; i < len ; i++ ) {
    id = document.forms[0].selectedPolls.options[i].value;
    if( id == -1 )
      continue;

    value += id;
    if( i < len - 1 )
      value += ",";
  }

  document.forms[0].selectedIds.value = value;
}

function addSelectedPoll( name, id ) {
  len = document.forms[0].selectedPolls.options.length;

  for( i = 0 ; i < len ; i++ ) {
    theId = document.forms[0].selectedPolls.options[i].value;
    if( theId == id )
      return;
  }

  document.forms[0].selectedPolls.options[len] = new Option( name, id, false, false );
  updateSelectedPolls();
}

function addPoll() {
  var pollId = document.forms[0].PollSelect.selectedIndex;
  var theString = "";
  var theId = -1;

  if( document.forms[0].PollSelect.options[ pollId ].value > -1 ) {
    theString = document.forms[0].PollSelect.options[pollId].text;
    theId = document.forms[0].PollSelect.options[pollId].value;
  }

  addSelectedPoll( theString, theId );
}

function removePoll() {
  selInd = document.forms[0].selectedPolls.selectedIndex;

  if( selInd > 0 )
    document.forms[0].selectedPolls.options[ selInd ] = null;

  updateSelectedPolls();
}
