
//---- ADMIN: counts the characters for character-limited fields

function textCounter(field,cntfield,maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
cntfield.value = maxlimit - field.value.length;
}

//---- ADMIN: creates a url for a page/article from the item's name

function writeURL(namefield, urlfield)
{
  var f = document.form1;
  var g = f[namefield].value;

  if (g == '')
    return;

  var str = new String(g);

  // IE doesn't recognise the trim() string method so...
  str = str.replace(/^\s*/, "").replace(/\s*$/, "");

  str = str.toLowerCase();
  str = str.replace(/[^a-z0-9 -]/g, '');
  str = str.replace(/\s/g, '-');

  f[urlfield].value = str;
}

//---- ADMIN: prompts to confirm url when first saving a new page, article etc

function checkURL(field)
{
  var f = document.form1;
  var g = f[field].value;
  if (g == '')
    return true;

  var msg = 'Are you sure you are happy with the URL  \'' + g + '\'?';
  return confirm(msg);
}

//---- ADMIN: prompts to confirm when deleting items 

function checkDel(proposal, id)
{
  var f = document.delform;
  if (confirm(proposal))
  {
    f.del_id.value = id;
    f.submit();
  }
}

//---- ADMIN: shows / hides 'snippet' field depending on whether page is spiderable or not, 
//            using 'showDiv' and 'hideDiv' below 

function toggleRobots()
{
  var f = document.form1;
  var r = f.page_robots[0];

  if (r.checked)
    showDiv('snippet');
  else
    hideDiv('snippet');
}

function showDiv(id)
{
  if (document.getElementById) // DOM3 = IE5, NS6
    document.getElementById(id).style.display = 'block';
  else
  {
    if (document.layers) // Netscape 4
      document.id.display = 'block';
    else  // IE 4
      document.all.id.style.display = 'block';
  }
}

function hideDiv(id)
{
  if (document.getElementById)  // DOM3 = IE5, NS6
    document.getElementById(id).style.display = 'none';
  else
  {
    if (document.layers)  // Netscape 4
      document.id.display = 'none';
    else  // IE 4
      document.all.id.style.display = 'none';
  }
}

//---- ADMIN: submit a form without reloading the page

function noReloadSubmit()
{
  var f = document.form1;
  f.noreload.value = 1;
  f.submit();
}
