function init()
{
 
  galleryInit();
  checkEditing();
  document.sortFilter.search.focus();
}


function clearFilter()
{
  document.sortFilter.q.value = '';
}

function checkEditing()
{
  var editCount = 0;
  var index = 0;
  var id = '';

  do {
    var editCB = document.getElementsByName("edit" + index);

    if (editCB == null || (editCB = editCB[0]) == null)
      break;
    else if (editCB.checked) {
      if (id)
        id += '.';

      id += editCB.value;
      ++editCount;
    }

    ++index;
  } while (true);

  var editButton = document.getElementById("edit_button");

  if (editButton)
    editButton.disabled = (editCount == 0);

  var idField = document.getElementById("id");

  if (idField)
    idField.value = id;

	return true;
}

function toggleSNW(button)
{
  var snw = document.getElementById("snw");

  if (snw != null) {
    snw.name = 'snw';
    snw.value = button.checked ? '1' : '0';
  }

  document.sortFilter.submit();
}

function toggleUNC(button)
{
  var unc = document.getElementById("unc");

  if (unc != null) {
    unc.name = 'unc';
    unc.value = button.checked ? '1' : '0';
  }

  document.sortFilter.submit();
}

function doSortSubmit()
{
  document.sortFilter.submit();
}

function verifyCommentDeletion()
{
  return confirm("Are you sure you want to delete this comment?");
}

function checkRatings()
{
  var len = document.rate.comment.value.length;

  if (len > 1500) {
    alert("Your comment should be 1500 characters or less. (You currently have " + len + " characters.)");
    return false;
  }

  return true;
}

function getCookie(name)
{
  if (document.cookie != null && document.cookie.length > 0) {
    var search = name + "=";
    var offset = document.cookie.indexOf(search);

    if (offset >= 0) {
      offset += search.length;

      var end = document.cookie.indexOf(";", offset);

      if (end < 0)
        end = document.cookie.length;

      return unescape(document.cookie.substring(offset, end));
    }
  }

  return null;
}

var triedHTTP = false;
var xmlhttp = null;

function imageClick(id)
{
  if (getCookie('nocount') == 1)
    return true;

  var recents = getCookie('recents');

  if (recents != null && recents.indexOf('.' + id + '.') >= 0)
    return;

  if (!triedHTTP) {
    if (window.XMLHttpRequest)
      xmlhttp=new XMLHttpRequest();
    else if (window.ActiveXObject) // code for IE5 and IE6
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

    $triedHTTP = true;

    if (xmlhttp != null)
      xmlhttp.onreadystatechange = httpStateChange;
  }

  if (xmlhttp != null) {
    xmlhttp.open("GET", "http://www.albumartexchange.com/invoke_view_counter.php?id=" + id, true);
    xmlhttp.send(null);
  }

  return true;
}

function httpStateChange()
{
  // Nothing to do
}
