// variables

// basic time parsing

var theDate   = new Date();
var theYear   = theDate.getYear();
var theMonth  = theDate.getMonth();
var theDayMth = theDate.getDate();
var theDay    = theDate.getDay();
var theHour   = theDate.getHours();
var theMinute = theDate.getMinutes();
var theSecond = theDate.getSeconds();

function viewSource() {
  document.location.href = 'view-source:' + location.href;
}

function countDown(str1, str2) {
  var now = new Date();
  var then = new Date(str1);
  var gap = then.getTime() - now.getTime();
  gap = Math.floor(gap / (1000 * 60 * 60 * 24));
  document.write("Only " + gap + " days until " + str2);
}

function elapsedTime(str1, str2, str3) {
  var now  = new Date(str1);
  var then = new Date(str2);
  var gap = then.getTime() - now.getTime();
  gap = Math.floor(gap / (1000 * 60 * 60 * 24));
  document.write(gap + " days " + str3);
}

function guestsvalidate(form) {
  if (form.name.value == "" || form.email.value == "" ||
      form.location.value == "" || form.comments.value == "") {
    alert("Please fill out all required fields\n");
    return false;
  }

  else {
    return true;
  }
}

function validateForm(strLen, formObj) {
  for (var i = 0; i < formObj.elements.length; i++) {
    if (formObj.elements[i].value == "") {
      alert("Please fill out all required fields");
      return false;
    }
    if (formObj.elements[i].value.length > Number(strLen)) {
      alert("Please enter less characters in the body of your message.  Maximum " + strLen);
      return false;
    }
  }
  return true;
}

function intro() {
  document.write("Welcome to " + document.URL + " on " + theDate.toLocaleString());
}

function tlastMod() {
  if (Date.parse(document.lastModified) != 0) {
    document.write("Last modified: " + document.lastModified);
  }
}

function motd() {
  var string = 'Check out my work in progress, an application based on geospatial web services <A HREF="/cgi-bin/redirect.pl?url=http://cgdi-dev.geoconnections.org/prototypes/owsview/" TARGET="_blank">here</A>';
  document.write(string);
}

function sniffBrowser() {
  if (document.referrer.length > 0 && document.referrer != "[unknown origin]") {
    document.write("Referred by : " + document.referrer + "<BR>");
  }
  var re = new RegExp("nrcan");
  if (document.referrer.search(re) != -1) {
    document.write("Please update your bookmarks, this site has changed servers<BR>");
  }

  if (navigator.appName == "Netscape")
    document.write("You're using Netscape, smart choice!");
  else if (navigator.appName == "Microsoft Internet Explorer")
    document.write("You're using Microsoft IE, hum.");
  else
    document.write("What kind of browser are you using?");
}

function swapImg(str1, str2) {
  document.str1.src = "/images/" + str2;
}

function whereisTom() {
  document.write("What I'm doing right now (probable whereabouts): ");

  if ((theDay > 5) || (theDay < 1))
    document.write("I'm having a nice weekend");
  else if ((theHour < 17) && (theHour > 7) && (theDay < 6) && (theDay > 0))
    document.write("I'm at <a href='http://www.ccrs.nrcan.gc.ca' target='blank'>work</a>");
  else if ((theDay == 2) && ((theHour < 15) && (theHour > 11)))
    document.write("I'm at <a href='http://www.carleton.ca'>school</a>");
  else if ((theDay == 1) && ((theHour < 23) && (theHour > 20)))
    document.write("I'm watching <a href='http://www.wwf.com'>RAW is WAR</a>");
  else
    document.write("I'm hanging out");
}

function writePageHeader(str) {
  document.write('<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0">');
  document.write('<TR>');
  document.write('<TD CLASS="tableprops" VALIGN="top"><IMG SRC="/images/tl.gif"></TD>');
  document.write('  <TD CLASS="tableprops" WIDTH="100%">&nbsp;</TD>');
  document.write('  <TD CLASS="tableprops" VALIGN="top"><IMG SRC="/images/tr.gif"></TD>');
  document.write(' </TR>');
  document.write(' <TR>');
  document.write('  <TD CLASS="tableprops" >&nbsp;</TD>');
  document.write('  <TD ALIGN="center" BGCOLOR="#005CB8"><B CLASS="tabletdfont">' + str + '</B></TD>');
  document.write('  <TD CLASS="tableprops" >&nbsp;</TD>');
  document.write(' </TR>');
  document.write(' <TR>');
  document.write('  <TD CLASS="tableprops" VALIGN="bottom"><IMG SRC="/images/bl.gif"></TD>');
  document.write('  <TD CLASS="tableprops" WIDTH="100%">&nbsp;</TD>');
  document.write('  <TD CLASS="tableprops" VALIGN="bottom"><IMG SRC="/images/br.gif"></TD>');
  document.write(' </TR>');
  document.write('</TABLE>');
}
