// togglevisibility 0.1 - toggle the visibility state of any object
// ensure to call with the parameters populated - there's no error checking! :)
// developed by Stuart Udall stu@cyberdelix.net
function togglevisibility(elementID,state) {
 if (state) {
  document.getElementById(elementID).style.visibility = "visible";
 } else { 
  document.getElementById(elementID).style.visibility = "hidden";
 }
}

// toggleblock 0.1 - show/hide visbility of any block object -----------------------------
// developed by Stuart Udall stu@cyberdelix.net
function toggleblock(block) {
 // decide whether we need to hide or show the block
 if (document.getElementById(block).style.display=="none") {
  newstyle="block";
 } else {
  newstyle="none";
 }
 // set the correct style
 document.getElementById(block).style.display=newstyle;
}

// toggleblockdelay 0.1 - wrapper for togglecol to give it a slight delay -----------------------------
// developed by Stuart Udall stu@cyberdelix.net
function toggleblockdelay(item) {
 currentitem=item;
 thistimeout = setTimeout("toggleblock(currentitem)", 350); // in milliseconds
}

// toggleblockcancel 0.1 - clear toggleblockdelay -----------------------------
// developed by Stuart Udall stu@cyberdelix.net
function toggleblockcancel() {
 clearTimeout(thistimeout);
}

// writeimgdata 0.2 - open popup and write image data directly into it
// ensure to call with the parameters populated - there's no error checking! :)
// developed by Stuart Udall stu@cyberdelix.net
function writeimgdata(contentURL, width, height, title, caption) {
 var defaulttitle="blazingfibre.net";
 var imgwin = window.open('about:blank','','width=' + width + ',height=' + height);
 // set the title to appear if none is supplied
 if (!title) {
  title=defaulttitle;
 }
 imgwin.document.open('text/html');
 imgwin.document.write('<HTML><HEAD><TITLE>' + title + '<\/TITLE><link rel="stylesheet" href="../global.css" type="text/css"><\/HEAD>');
 imgwin.document.write('<body bgcolor=black text=white vlink=black link=black alink=black leftmargin=0 rightmargin=0 topmargin=0 bottommargin=0 marginwidth=0 marginheight=0>');
 imgwin.document.write('<table border=0 cellpadding=0 cellspacing=0 width=100%>');
 imgwin.document.write('<tr><td height=20 width=20>&nbsp;</td><td>&nbsp;</td><td height=20 width=20>&nbsp;</td>');
 imgwin.document.write('<tr><td>&nbsp;</td><td valign=top align=center>');
 imgwin.document.write('<a href=# onClick=window.self.close(); onFocus="if(this.blur)this.blur()"><img src=' + contentURL + ' class=popuppicborder alt=" click to close " border=0 hspace=0 vspace=0></a>');
 imgwin.document.write('</td><td>&nbsp;</td></tr>');
 imgwin.document.write('<tr><td>&nbsp;</td><td><!-- start of text area --><br>');
 imgwin.document.write('<table border=0 cellpadding=2 cellspacing=0 width=100%>');
 imgwin.document.write('<tr><td valign=top align=left>');
 if (caption) {
  imgwin.document.write('<div class=pagenote><b>' + caption + '</b></div>');
 }
 imgwin.document.write('</td><td valign=top align=right class=pagenote>');
 imgwin.document.write('<a href=# onClick=window.self.close();>close</a>');
 imgwin.document.write('</td></tr></table><!-- end of text area -->');
 imgwin.document.write('</td><td>&nbsp;</td></tr></table>');
 imgwin.document.write('</BODY></HTML>');
 imgwin.document.close();
}

// poptofront 0.1 - pop this window to front
// developed by Stuart Udall stu@cyberdelix.net
function poptofront() {
 window.focus();
}

// safemail 0.1 - generate email address - antispam measure
// developed by Stuart Udall stu@cyberdelix.net (based on source from authors unknown)
function safemail(email1, email2) {
 document.write(email1 + "@" + email2);
}

// 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 + ">");
}

// closehome 0.1 - display "close" or "home" depending on popup state
// developed by Stuart Udall stu@cyberdelix.net 
function closehome() {
 document.write('<p align=right><i><b>');
 if (window.opener) {
  document.write('<a href=# onClick=window.self.close();>close</a>');
 } else {
  document.write('<a href="/" title="Welcome to Blazingfibre">home</a>');
 }
 document.writeln('</b></i></p>');
}

// placefocus 0.1 - place cursor in first editable box on a form
// from on source here: http://javascript.internet.com/forms/form-focus.html
// removal of auto-focusing on dropdowns by Stuart Udall stu@cyberdelix.net
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")) {
    document.forms[0].elements[i].focus();
    break;
   }
  }
 }
}

// Today's Date 4.0 --------------------------------------------------------------
//
// - developed by Timothy Wallace, timothy@essex1.com
// - day & month conversion by Christopher Hadden, webmaster@jasc.com
// - daynumber and year conversion, seperator, numeric and mmddyy options,
//   date header and footer, conversion to a function by Stuart Udall, stu@cyberdelix.net
//
// when calling:
//  1. adjust the headers and footers, leaving blank if appropriate;
//     the header and footer can contain any HTML or text; substitute " for '
//  2. set the date separator (the character displayed between values)
//  3. select alphanumeric or numeric display; set numeric=0 for alphanumeric,
//     or numeric=1 for numeric
//  4. select mmddyy display; set mmddyy=0 for ddmmyy, or mmddyy=1 for mmddyy
//     display (US format)

function todaysdate(dateheader, datefooter, separator, numeric, mmddyy) {

// define internal variables
var now = new Date();
var mName = now.getMonth() + 1;
var dName = now.getDay() + 1;
var yName = now.getYear();
var dayNr = now.getDate();

// convert year to two digits (yxk compatible :)
while (yName > 99)
{
 yName = yName - 100;
}
yName = ((yName < 10) ? "0" : "") + yName;

// convert daynumber to two digits if necessary
dayNr = ((dayNr < 10) ? "0" : "") + dayNr;

// convert day to day name
if(numeric == 0) {
 if(dName == 1) Day = "Sun&nbsp;";
 if(dName == 2) Day = "Mon&nbsp;";
 if(dName == 3) Day = "Tue&nbsp;";
 if(dName == 4) Day = "Wed&nbsp;";
 if(dName == 5) Day = "Thu&nbsp;";
 if(dName == 6) Day = "Fri&nbsp;";
 if(dName == 7) Day = "Sat&nbsp;";
}
 else {
 Day = "";
}

// convert month to month name
if(numeric == 0) {
 if(mName == 1) Month = "Jan";
 if(mName == 2) Month = "Feb";
 if(mName == 3) Month = "Mar";
 if(mName == 4) Month = "Apr";
 if(mName == 5) Month = "May";
 if(mName == 6) Month = "Jun";
 if(mName == 7) Month = "Jul";
 if(mName == 8) Month = "Aug";
 if(mName == 9) Month = "Sep";
 if(mName == 10) Month = "Oct";
 if(mName == 11) Month = "Nov";
 if(mName == 12) Month = "Dec";
}
 else {
 Month = ((mName < 10) ? "0" : "") + mName;
}

// build date string
if(mmddyy == 0) {
 var todaysDate = (Day + dayNr + separator + Month + separator + yName);
}
 else {
 var todaysDate = (Day + Month + separator + dayNr + separator + yName);
}

// write date string to page
document.write(dateheader, todaysDate, datefooter);
}

// Today's Time 3.1 --------------------------------------------------------------
//
// developed by Stuart Udall, stu@cyberdelix.net
//
// when calling:
//  1. adjust the headers and footers, leaving blank if appropriate;
//     the header and footer can contain any HTML or text; substitute " for '
//  2. select numeric or alphanumeric output; set numeric=0 for alphanumeric, or
//     numeric=1 for numeric
//  3. select military (24-hour) or 12-hour AM/PM output; set military=0 for 
//     24-hour output, or set military=1 for 12-hour AM/PM output
//  4. select GMT offset.  set gmtoffset=0 to display local time unadjusted, or
//     set gmtoffset= a positive or negative number, positive to display the time
//     ahead of GMT, eg. Perth, Australia is GMT+8, therefore set gmtoffset=8

function todaystime(timeheader, timefooter, numeric, military, gmtoffset) {

// define internal variables
var now = new Date();
var CurHour = now.getHours();
var CurMinute = now.getMinutes();
var AMPM = " AM";

// adjust time for GMT
CurHour = CurHour + gmtoffset;
if (CurHour > 23) {
 CurHour = CurHour - 23 }
if (CurHour < 0) { 
 CurHour = CurHour + 23 }

// convert time to our format
if(numeric == 0) {
 if (CurMinute > 30) { 
  CurHour++ }
 if (CurHour > 24) {
  CurHour-- }
 if (CurHour > 11) { 
  AMPM = " PM"; CurHour = CurHour - 12 }
}
 else {
 if(military == 0) {
  if (CurHour > 11) { 
   AMPM = " PM"; CurHour = CurHour - 12 }
  }
 else {
  AMPM = "";
 }
 CurMinute = ((CurMinute < 10) ? "0" : "") + CurMinute;
 CurHour = ((CurHour < 10) ? "0" : "") + CurHour;
 CurHour = CurHour + ":" + CurMinute;
}

// preview time string
var previewtime = (CurHour + AMPM);

// filter prospective string
if(numeric == 0) {
 if (previewtime == "12 PM") { previewtime = "midnight" };
 if (previewtime == "0 AM") { previewtime = "midnight" };
 if (previewtime == "0 PM") { previewtime = "noon" };
}

// build time string
var todaysTime = (timeheader + previewtime + timefooter);

// write time string to page
document.write(todaysTime);
}


