// safemailto 0.2 - generate email address - antispam measure
// developed by Stuart Udall stu@cyberdelix.net (based on source from authors unknown)
function safemailto(email1, email2) {
 document.write("<a h" + "ref=" + "mail" + "to:" + email1 + "@" + email2 + ">" + email1 + "@" + email2 + "</a>");
}

// safeformto 0.1 - generate recipient line for formmail - antispam measure
// developed by Stuart Udall stu@cyberdelix.net (based on source from authors unknown)
function safeformto(email1, email2) {
 document.write("<INPUT type=hidden NAME=recipient VALUE=" + email1 + "@" + email2 + ">");
}

// placefocus 0.1 - place cursor in first editable box on a form
// based on source here: http://javascript.internet.com/forms/form-focus.html
function placefocus() {
 if (document.forms.length > 0) {
  var field = document.forms[0];
  for (i = 0; i < field.length; i++) {
   if ((field.elements[i].type == "text") || (field.elements[i].type == "textarea") || (field.elements[i].type.toString().charAt(0) == "s")) {
    document.forms[0].elements[i].focus();
    break;
   }
  }
 }
}

// formatNumber - number formatting function
// from source here: http://javascript.about.com/library/blnumfmt.htm
// copyright Stephen Chapman 24th March 2006, 10th February 2007
// permission to use this function is granted provided that this copyright notice is retained intact
function formatNumber(num,dec,thou,pnt,curr1,curr2,n1,n2) {
 var x = Math.round(num * Math.pow(10,dec));if (x >= 0) n1=n2='';var y = (''+Math.abs(x)).split('');var z = y.length - dec; if (z<0) z--; for(var i = z; i < 0; i++) y.unshift('0');y.splice(z, 0, pnt); if(y[0] == pnt) y.unshift('0'); while (z > 3) {z-=3; y.splice(z,0,thou);}var r = curr1+n1+y.join('')+n2+curr2;return r;
}

// sanitise a number field
function sanitisenumber(num) {
 return num.replace(/[^.0-9]/g,""); // strip anything that is not a number or a comma or fullstop
 //return num.replace(/[,\s\$Ła-zA-Z]/g,""); // strip commas, spaces, dollar signs, pound signs and all alphanumeric characters
}

// isEmpty 0.1 - test for undefined or blank variable
// code courtesy: http://snipplr.com/users/badkungfu
function isempty(inputStr) {
 return !(inputStr&&inputStr.length)
}

// checkform 0.1 - get confirmation before submitting
// developed by Stuart Udall stu@cyberdelix.net
function checkform() {
 if (confirm('By submitting this form, you acknowledge your\nacceptance of our Terms and Conditions.\n\nDo you wish to continue?')) {
    return true;
 } else {
    alert("Your form has not been sent.");
    return false;
 }
}

// makenavcell 0.1 - generate nav table cell, highlighting current item
// developed by Stuart Udall stu@cyberdelix.net
function makenavcell(contentURL, extras) {
 if (location.href.indexOf(contentURL) != -1) {
  classstring="navcellhigh";
 } else {
  classstring="navcell";
 }
 document.write("<td class=" + classstring + " " + extras + ">");
}

// shownavhi 0.3 - set nav image to selected state
// developed by Stuart Udall stu@cyberdelix.net
function shownavhi(ID,ext) {
 if (ID) {
  //alert(ID);
  //alert(document.getElementById(ID).src);
  //alert("/images/button_" + ID + "_selected." + ext);
  document.getElementById(ID).src="/images/button_" + ID + "_selected." + ext;
  //alert(document.getElementById(ID).src); 
 }
}

// showhover 0.3 - toggle rollover highlight
// developed by Stuart Udall stu@cyberdelix.net
function showhover(ID,state,ext) {
 oktotoggle=false;
 if (typeof(pagetitle) == "undefined") { // test for empty var
  oktotoggle=true;
 } else {
  if (pagetitle != ID) { //don't toggle this button if we're on the page the button is referring to
   oktotoggle=true;
  }
 }
 if (oktotoggle==true) {
  if (state) {
   image="/images/button_" + ID + "_hover." + ext;
  } else {
   image="/images/button_" + ID + "." + ext;
  }
  document.getElementById(ID).src=image;
 }
}

// togglesection 0.2 - toggle display of a page section
// developed by Stuart Udall stu@cyberdelix.net
function togglesection(section) {
 if (document.getElementById(section).style.display=="") { // if it's already being displayed...
  document.getElementById(section).style.display="none";// hide it
 } else {
  document.getElementById(section).style.display=""; // show it
 }
}

// rollover support script
// developed by Macromedia, Inc
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];}}
}

