
var timer;

function DBFilesCheckOnMultipleSubmit()
{
  form = document.getElementById("multiple_files_form");
  var i = 0;
  result = false;
  while (form.elements[i])
  {
    if ((form.elements[i].type == "checkbox") && (form.elements[i].checked))
      result = true;
    i++;
  }
  if (!result) alert(" ");
  return result;
}

function DBFilesAdminItemClick(action)
{
  if (DBFilesCheckOnMultipleSubmit())
  {
    document.getElementById("action").value = action;
    document.getElementById("multiple_files_form").submit();
  }
}

function DBFilesCheckCheckBoxes(formid, checked)
{
  form = document.getElementById(formid);
  var i = 0;
  while (form.elements[i])
  {
    if (form.elements[i].type == "checkbox")
      form.elements[i].checked = checked;
    i++;
  }
}


imgIds = new Array();
imgNames = new Array();
imgNotes = new Array();
curIndex = 0;
fullsize = false;
waiting = false;
baseurl = "";

function GalleryResize(img)
{
  if (img.width > 780)
    img.width = 780;
}

function GalleryChange(direction)
{
  curIndex = (curIndex + direction + imgIds.length) % imgIds.length;
  var imgSrc = "?module=dbfiles&action=download&fileid=" + imgIds[curIndex];
  document.getElementById('viewer_image').width = "10";
  document.getElementById('viewer_image').style.width = "auto";
  document.getElementById('viewer_image').src = imgSrc;
  document.getElementById('viewer_name').innerHTML = imgNames[curIndex] + " (" + (curIndex + 1) + "/" + imgNames.length + ")";
  document.getElementById('viewer_notes').innerHTML = imgNotes[curIndex];

    GallerySetBtnsStatus();
}

function GallerySetBtnDisabled(id, disabled)
{
  /*
  btn = document.getElementById(id);
  btn.disabled = disabled;
  if (disabled)
    btn.className = "disabled";
  else
    btn.className = "";
  */

}

function GallerySetBtnsStatus()
{
  var slideBtn = document.getElementById("slideBtn");
  GallerySetBtnDisabled('firstBtn', (slideBtn.value != "Slideshow"));
  GallerySetBtnDisabled('prevBtn', ((slideBtn.value != "Slideshow") || (curIndex == 0)));
  GallerySetBtnDisabled('nextBtn', ((slideBtn.value != "Slideshow") || (curIndex == imgIds.length - 1)));
  GallerySetBtnDisabled('lastBtn', (slideBtn.value != "Slideshow"));
}

function GalleryFirst()
{
  curIndex = 0;
  GalleryChange(0);
}

function GalleryPrevious()
{
  GalleryChange(-1);
}

function GalleryNext()
{
  var slideBtn = document.getElementById("slideBtn");
  if (curIndex < imgIds.length - 1)
    GalleryChange(1);
  if ((slideBtn.value != "Slideshow") && (curIndex == imgIds.length - 1))
    GalleryShowSlides();
}

function GalleryLast()
{
  curIndex = imgIds.length - 1;
  GalleryChange(0);
}

function GalleryShowSlides()
{
  var slideBtn = document.getElementById("slideBtn");
  if (slideBtn.innerHTML == "Slideshow")
  {
    slideBtn.innerHTML = "Stop";
    timer = setInterval("GalleryNext()", 3000);
  }
  else
  {
    slideBtn.innerHTML = "Slideshow";
    clearInterval(timer);
  }
  GallerySetBtnsStatus();
}

