var popup_window = null;
function OpenWin(page, width, height, status, resizable, toolbar, menubar, scrollbars)
{
  popup = open(page, "displayWindow", "width=" + width + ",height=" + height + ",status=" + status + ", resizable=" + resizable + ", toolbar=" + toolbar + ", menubar=" + menubar + ", scrollbars=" + scrollbars + "");
  popup_window = popup;
  popup.moveTo(0,0);
  popup.focus();
}

function onchange_goto(url, val, doc)
{
  url = url + val;
  doc.location.href = url;
}

function SelectAll(form)
{
  for(var i=0; i<form.options.length; i++)
  {
    form.options[i].selected = true;
  }

  return false;
}

function DeSelectAll(form)
{
  for(var i=0; i<form.options.length; i++)
  {
    form.options[i].selected = false;
  }

  return false;
}

function select_all(theElement, theFlag)
{
  var theForm = theElement.form, z = 0;
  for(z=0; z<theForm.length;z++)
  {
    if(theForm[z].type == 'checkbox' && theForm[z].name != theFlag)
    {
      theForm[z].checked = theElement.checked;
    }
  }

  return false;
}

function ViewImage(sFileName, iWeight, iHeight, sTitle)
{
  var oWindow;

  oWindow = window.open("","imageviewer","width="+iWeight+",height="+iHeight+",menubar=no,toolbar=no,scrollbar=no,status=no,resizable=yes");
  oWindow.moveTo(0,0);
  oWindow.focus();

  oWindow.document.open();
  oWindow.document.write('<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n');
  oWindow.document.write('<html xmlns=\"http://www.w3.org/1999/xhtml\">\n');
  oWindow.document.write('<head>\n');
  oWindow.document.write('<title>'+sTitle+'</title>\n');
  oWindow.document.write('<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />\n');
  oWindow.document.write('</head>\n');
  oWindow.document.write('<body>\n');
  oWindow.document.write('<div style=\"position:absolute;width:'+iWeight+'px;height:'+iHeight+'px;left:0px;top:0px\">\n');
  oWindow.document.write('<img src=\"'+sFileName+'\" alt=\"'+sTitle+'\" />\n');
  oWindow.document.write('</div>\n');
  oWindow.document.write('</body>\n');
  oWindow.document.write('</html>\n');
  oWindow.document.close();
}

function PrintContent(DivId)
{
  var GetElementByIdError = 'Uw browser ondersteunt deze functie niet! U dient deze pagina handmatig te printen via uw browser.\nDit kunt u op de volgende 2 manieren doen:\n\n1)\tBestand => Afdrukken\n2)\tCtrl+P'

  if(document.getElementById != null)   {

    var PrintContent = '<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n';
    PrintContent += '<html xmlns=\"http://www.w3.org/1999/xhtml\">\n';
    PrintContent += '<head>\n';

    if(document.getElementsByTagName != null) {
      var HeadTags = document.getElementsByTagName("head");

      if(HeadTags.length != 0)  {
        PrintContent += HeadTags[0].innerHTML+'\n';
      }
    }

    PrintContent += '</head>\n'
    PrintContent += '<body>\n';
    var DivContent = document.getElementById(DivId);
    PrintContent += DivContent.innerHTML+'\n';
    PrintContent += '</body>\n'
    PrintContent += '</html>';

    var PrintWin = window.open("","PrintWin", "width=800,height=400,status=no,toolbar=no,menubar=yes,scrollbars=yes,resizable=no");
    PrintWin.moveTo(0,0);
    PrintWin.focus();

    PrintWin.document.open();
    PrintWin.document.write(PrintContent);
    PrintWin.document.close();
    PrintWin.print();
    PrintWin.document.focus();
  } else {
    alert(GetElementByIdError);
    PrintWin.document.focus();
  }
}

function showLevel(_levelId)
{
  var thisLevel = document.getElementById(_levelId );
  if(thisLevel.style.display == "none") {
    thisLevel.style.display = "block";
  } else {
    hideLevel(_levelId);
  }

  return false;
}

function hideLevel(_levelId)
{
  var thisLevel = document.getElementById(_levelId);
  thisLevel.style.display = "none";

  return false;
}

function GoTo(url)
{
  document.location.href = url;
}

function ConfirmDelete(url, text)
{
  if(confirm(text))
  {
    document.location.href = url;
  }
  else
  {
    document.location.reload();
  }
}

function tag_shop_image(ImageName)
{
  var ImageField = opener.document.ReplyForm.ReplyPic;
  ImageField.focus();

  if (trim(ImageField.value).length > 0)
  {
    /* Veld is vol */
    if (trim(ImageName).length > 0)
    {
      if (trim(ImageField.value).indexOf(ImageName) != -1)
      {
        /* Verwijderen */
        ImageField.value = trim(trim(ImageField.value).replace(ImageName, ''));
      }
      else
      {
        /* Toevoegen */
        ImageField.value = trim(trim(ImageField.value) + ' ' + ImageName);
      }
    }
    else
    {
      /* Leegmaken */
      ImageField.value = '';
    }
  }
  else
  {
    /* Veld is leeg */
    ImageField.value = trim(ImageName);
  }
}

function tag_cat_image(ImageName)
{
  var ImageField = opener.document.ReplyForm.ReplyImg;
  ImageField.focus();
  ImageField.value = trim(ImageName);
  window.close();
}

function trim(str, chars)
{
  return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars)
{
  chars = chars || "\\s";
  return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars)
{
  chars = chars || "\\s";
  return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

String.prototype.startsWith = function(str)
{
  return (this.match("^" + str) == str)
}

String.prototype.endsWith = function(str)
{
  return (this.match(str + "$") == str)
}

var delay = (function()
{
  var timer = 0;
  return function(callback, ms)
  {
    clearTimeout (timer);
    timer = setTimeout(callback, ms);
  };
})();

