function removePoll() {
  
  document.getElementById('poll_question').value = '';
  document.getElementById('poll_ends_in').selectedIndex = 0;
  document.getElementById('can_change_vote').checked = 0;
//  document.getElementById('hide_results').checked = 0;
  
  
  
  for (i=1;i<6;i++) {
    document.getElementById('poll_choice_'+i).value = '';
    document.getElementById('poll_choice_group_'+i).selectedIndex = 0;
  }
  
  i = 6;
  var trNext;

  while (document.getElementById('poll_choice_row_'+i)) {
    trNext = document.getElementById('poll_choice_row_'+i);
    trNext.parentNode.removeChild(trNext);
    i++;
  }

  var choicesTable = document.getElementById('poll_choices');
  
}

function disablePost(theButton) {
  
//  theButton.disabled = true;
  
}

function getGreatestRow() {
  
  i = 1;
  var greatestNumber;
  var trNext;

  while (document.getElementById('poll_choice_row_'+i)) {
    greatestNumber=i;
    i++;
  }

  return greatestNumber;
    
}

function addMorePollChoices() {
  
  var choicesTable = document.getElementById('poll_choices');
  
  var greatestRow = getGreatestRow();

  for (i=greatestRow+1;i<greatestRow+6;i++) {
    var copyRow = choicesTable.getElementsByTagName('tr')[1].cloneNode(true);
    choicesTable.getElementsByTagName('tbody')[0].appendChild(copyRow);
    copyRow.id = 'poll_choice_row_'+i;
    var textInput = copyRow.getElementsByTagName('input')[0];
    textInput.id = 'poll_choice_'+i;
    textInput.name = 'poll_choice_'+i;
    textInput.value = '';
    var selectInput = copyRow.getElementsByTagName('select')[0];
    selectInput.id = 'poll_choice_group_'+i;
    selectInput.name = 'poll_choice_group_'+i;
    selectInput.selectedIndex = 0;
    
  }

  return false;

}

function makeActiveTab(selector) {

  var tabSelectors = document.getElementById('tab_selector').childNodes;
  var selectedItemString = selector.getAttribute('href').replace('#','');
  var tabs = document.getElementById('tabs').childNodes;

  for (i in tabSelectors) {
    if (tabSelectors[i].nodeName!='LI') {
      continue;
    }
    tabSelectors[i].className = tabSelectors[i].className.replace(' active_tab_selector', '');      
  }

  selector.parentNode.className = selector.parentNode.className+' active_tab_selector';
  
  for (i in tabs) {
    
    if (tabs[i].nodeName!='DIV') {
      continue;
    }
    tabs[i].className = 'tab hidden';
    
    if (tabs[i].id==selectedItemString) {
      tabs[i].className = 'tab';
    }
    
  }
  
  return false;
  
}

function displayPostVisible() {
  
  if (document.getElementById('display_post_content').className == 'hidden') {
    // Make visible
    document.getElementById('display_post_content').className = '';
    document.getElementById('display_post_visibility_li').className = 'hide_post';
    document.getElementById('display_post_visibility').innerHTML = 'Hide post';
  } else {
    // Make hidden
    document.getElementById('display_post_content').className = 'hidden';
    document.getElementById('display_post_visibility_li').className = 'show_post';
    document.getElementById('display_post_visibility').innerHTML = 'Show post';
  }
  
  return false;
    
}

function addTabEvents() {

  var tabSelectors = document.getElementById('tab_selector').childNodes;
  for (i in tabSelectors) {
    if (tabSelectors[i].nodeName!='LI') {
      continue;
    }
    tabSelectors[i].getElementsByTagName('A')[0].setAttribute('onclick', 'return makeActiveTab(this)');
  }

  // var displayPostVisibilityLi = document.getElementById('display_post_visibility_li');
  // if (displayPostVisibilityLi) {
  //   document.getElementById('display_post_visibility_li').className = 'show_post';
  // }
  // var displayPostContent = document.getElementById('display_post_content');
  // if (displayPostContent) {
  //   document.getElementById('display_post_content').className = 'hidden';
  // }
  var displayPostVisibility = document.getElementById('display_post_visibility');
  if (displayPostVisibility) {
    document.getElementById('display_post_visibility').setAttribute('onclick', 'displayPostVisible()');
  }

//  tinyMCE.init({
//		mode : "textareas",
//  	editor_selector : "mceEditor",
//		theme : "advanced",
//		plugins: "inlinepopups",
//		dialog_type: "modal",
//		theme_advanced_buttons1: "bold,italic,separator,numlist,bullist,separator,image,link,separator,code",
//		theme_advanced_buttons2: "",
//		theme_advanced_buttons3: "",
//		theme_advanced_toolbar_align : "left",
//		theme_advanced_toolbar_location : "top"		
//	});
}

window.onload = addTabEvents;