function toggle_authors() {
  tmp = document.getElementsByTagName('span');
  for (i=0;i<tmp.length;i++)
  {
    if (tmp[i].className == 'author') {
      tmp[i].style.display = (tmp[i].style.display == 'inline') ? 'none' : 'inline';
    }
  }
}

function toggle_span(name) {
  var header_name = name + '-header'
  tmp = document.getElementsByTagName('span');
  for (i = 0; i < tmp.length; i++) {
    if (tmp[i].className == header_name) {
      tmp[i].style.display = (tmp[i].style.display == 'inline') ? 'none' : 'inline';
    }
    if (tmp[i].className == name) {
      tmp[i].style.display = (tmp[i].style.display == 'inline') ? 'none' : 'inline';
    }
  }
}

function set_span_display(name, on) {
  var header_name = name + '-header'
  tmp = document.getElementsByTagName('span');
  for (i = 0; i < tmp.length; i++) {
    if (tmp[i].className == header_name) {
      tmp[i].style.display = (on) ? 'inline' : 'none';
    }
    if (tmp[i].className == name) {
      tmp[i].style.display = (on) ? 'inline' : 'none';
    }
  }
}

function get_cookie(name) {
  var found = false;
  var start = 0;
  var end = 0;
  var c = document.cookie;
   
  var i = 0;
  while (i <= c.length) {
    start = i;
    end = start + name.length;
    if (c.substring(start, end) == name) {
      found = true;
      break;
    }
    i++;
  }
  if (found) {
    start = end + 1;
    end = c.indexOf(";", start);
    if (end < start)
      end = c.length;
  
    if (c.substring(start, start + 1) == '"' && c.substring(end - 1, end) == '"') {
      start += 1;
      end -= 1;
    }
    return c.substring(start, end);
  }
  return "";
}

function welcome() {
  var uname = get_cookie("uname");
  if (uname.length == 0) {
    uname = "Anon"
  }
  document.write('Welcome, ' + uname);
}

function submit_new_line() {
  var uname = get_cookie("uname");
  if (uname.length == 0) {
    if (!confirm("Your contribution is about to be submitted as from 'Anon'.")) {
      alert('Please log in and submit again.');
      window.open("/minilog.htm", "Login",
                  "height=300, width=460, status=no, location=no, toolbar=no, directories=no, menubar=no, resizable, scrollbars");
      return;
    }
  }

  document.forms.new_line.submit();
}
