/* NZSS web pages javascript */
// 2006-05-15 /images
// 2006-05-03 SED writeDate, writeTime, lastUpdated, mailToAddress
// JavaScript to interpolate random images into a page.
    var ic = 5;     // Number of alternative images
    var xoxo = new Array(ic);  // Array to hold filenames
        
xoxo[0] = "/images/NZSS1.jpg";
xoxo[1] = "/images/NZSS2.jpg";
xoxo[2] = "/images/NZSS3.jpg";
xoxo[3] = "/images/NZSS4.jpg";
xoxo[4] = "/images/NZSS5.jpg";

function pickRandom(range) {
  if (Math.random)
    return Math.round(Math.random() * (range-1));
  else {
    var now = new Date();
return (now.getTime() / 1000) % range;
}
}
// Write out an IMG tag, using a randomly-chosen image name.
var choice = pickRandom(ic);
//alert(choice);
//
function showHeadImage () {
document.writeln('<img src="'+xoxo[choice]+'" alt="New Zealand Speleological Society" title="New Zealand Speleological Society" />');
}
//
function writeDate (outDate)
{
var daylit = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
// can't make correct day display for IE4!
var mnlit = new Array("Jan", "Feb", "March", "April", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec");
//document.writeln ('writeDate ',outDate);
if (outDate>0) {
  var yr=outDate.getYear();
  var mn=outDate.getMonth();
  var dy=outDate.getDate();
  var day=outDate.getDay();
// cater for variations in the way browsers handle dates!
    if (yr>=100 && yr<=999) yr-=100;
    if (yr<1000) yr+=2000;
// partially tested for Netscape and Explorer
  document.write (' ', yr,' ',mnlit[mn],' ',dy);
  }
}
//
function writeTime (outTime)
{
if (outTime>0) {
  var hr=outTime.getHours();
  var minute=outTime.getMinutes();
  document.write (' ', hr,':',minute);
  }
}
//
function lastUpdated ()
{
var lm=Date.parse(document.lastModified);
var dlm=new Date (lm);
document.writeln('<div class="modified" align="right">Updated ');
writeDate (dlm);
writeTime (dlm);
document.writeln('</div>');
}
//
function mailToAddress (emailName,emailAddress,subJect,linkName)
{
document.write ('<a href="mailto:', emailName, '&#64;', emailAddress);
if (subJect != '') {
  document.write ('?subject=', subJect);
  }
document.write ('">', linkName, '</a>');
}
//
function mailToNZSS (emailName,subJect,linkToName)
{
  var linkName = '';
switch (arguments.length) {
  case 1 : subJect = '';
  case 2 : linkName = emailName;
           break;
  default: linkName = linkToName;
  }
mailToAddress ('nzss-'+emailName,'caves&#46;org&#46;nz',subJect,linkName);
}

