
//---- 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: prompts to check an article url and makes it mandatory (deprecated)

function checkURL(description, fieldname)
{
  var f = document.form1;
  var g = f[fieldname].value;

  if (g == '')
  {
    alert('Please enter a value for ' + description);
    return false;
  }

  var str = new String(g);

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

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

//---- ADMIN: prompt to check an article category (deprecated)

function checkSaveCategory(proposal)
{
  var f = document.form1;
  if (confirm(proposal))
    f.confirm.value = 1;
  f.submit();
}

//---- ADMIN: prompts when saving an article (deprecated)

function checkSaveArticle(proposal, button)
{
  var f = document.form1;
  if (confirm(proposal))
  {
    f.confirm.value = 1;
    if (button == 'SAVE AND CONTINUE')
      f.stayonpage.value = 1;
  }
  f.submit();
}

//---- ADMIN: prompts when deleting an article url (deprecated)

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

//---- ADMIN: shows / hides the date for an article, using 'showDiv' and 'hideDiv'

function checkArtStatus()
{
  var f = document.form1;
  var r = f.art_status[1];

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

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';
  }
}

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';
  }
}

//---- FRONT END: document.write and standard D'Weaver functions

function getintouch () {
	document.write ('<a href="mailto:info@allthingsmac.co.uk">email us</a>');
}

function gitbanner () {
	document.write ('<a href="mailto:info@allthingsmac.co.uk"><img src="/2011images/email.png" alt="email us" title="email us"></a>');
}

function clients () {
	document.write ('<iframe class="iframe" frameborder="0" scrolling="no" width="212" height="248" src="/2011clients.htm"></iframe>');
}

function useful () {
	document.write ('<iframe class="iframe" frameborder="0" scrolling="no" width="212" height="220" src="/2011useful.htm"></iframe>');
}

function rsssub () {
	document.write ('<a href="/rss/feed.xml" target="_blank">Subscribe to AllThingsMac</a>');
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}


