function check_all(form, item, state) {
  for (i = 0; i <= form.elements.length; i++) {
    if (form.elements[i].name == item) {
      form.elements[i].checked = state;
    }
  }
}
function clear_fields(prefix, tags, index) {
  for (i = 0; i < tags.length; i++) {
    name = prefix + '-' + tags[i] + '[' + index + ']';
    if (document.getElementsByName(name)[0]) {
        document.getElementsByName(name)[0].value='';
    }
  }
}
function set_fields(prefix, tags, index, values) {
  for (i = 0; i < tags.length; i++) {
    name = prefix + '-' + tags[i] + '[' + index + ']';
    if (document.getElementsByName(name)[0]) {
        document.getElementsByName(name)[0].value=values[i];
    }
  }
}
function getCookie(cookie)
{
  if (document.cookie.length) {
    p = document.cookie.indexOf(cookie + "=");
    if (p != -1) {
      p = p + cookie.length + 1; 
      q = document.cookie.indexOf(";", p);
      if (q == -1)
        q = document.cookie.length;
      return unescape(document.cookie.substring(p, q));
    }
  }
  return "";
}
function loginLink()
{
  if (getCookie("CLUBMATIC") != "") {
    return '<a href="/scripts/logout.php">Logout</a>';
  } else {
    return '<a href="/scripts/login.php">Login</a>';
  }
}
