//##############################################################################
//# Whatuwhiwhi On-line  Misc Javascript functions                             #
//# Copyright 2000 Gary Nicholson       gazzanic@ihug.co.nz                    #
//# Created 11/05/01                    Last Modified 11/05/00                 #
//# www.gazza.co.nz                     http://www.whatuwhiwhi.co.nz/index.html#
//##############################################################################
//# COPYRIGHT NOTICE                                                           #
//# Copyright 2001 Gary Nicholson  All Rights Reserved.                        #
//##############################################################################

var MONTH_NAMES = new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
var DAY_NAMES = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
var relpath = "";
var  visited = "back";
var  now = new Date;
var  calday = now.getDate();
var  calmonth = now.getMonth() + 1;
var  calyear = now.getFullYear(); 
if (calyear < 2001 || calyear > 2050) calyear = 2001;   //just in case

// display new gif if added since last visit	
var  expireDate = new Date;
     expireDate.setMonth(expireDate.getMonth()+6);
var  lastVisit = new Date(cookieVal("pageVisit"));
     document.cookie = "pageVisit="+now+";expires=" + expireDate.toGMTString();

// Work-around Netscape resize bug
       if (navigator.appName == "Netscape") {
            onresize = reDo;
            origWidth = innerWidth;
            origHeight = innerHeight;  
        }

function cookieVal(cookieName) {
var          thisCookie = document.cookie.split("; ");
             for (i=0; i<thisCookie.length; i++) {
                    if (cookieName == thisCookie[i].split("=")[0]) {
                          return thisCookie[i].split("=")[1];
                    }
              }
             visited = "";
             return "1 January 2070";    //no images displayed if new user - too much clutter
}
	
function newCheck(yyyy,mm,dd,imgname) {
     var lastChgd = new Date(yyyy,mm-1,dd);
       if (lastChgd.getTime() > lastVisit.getTime()) {
	      document.write("<IMG SRC='images/new.gif' WIDTH=24 HEIGHT=11 ALT='' NAME='" + imgname + "'>")
       }
       else {
            document.write("<img src='images/blank.gif' width=24 height=11 ALT='' NAME='" + imgname + "'>")
       }
}

function outputDate() {
     document.write(DAY_NAMES[now.getDay()] + "<BR>" + formatDate(now,"d MMM y"));
}


function writeFooter() {
     document.write("<table border='0' width='100%'><tr><td width='50' align='center' class='sic'><a href='" + relpath + "index.shtml' onClick='goBack();return false;' class='noline'><img src='" + relpath + "images/cylarr.gif' width='31' height='31' border='0'><br>Back</a></td>");
     document.write("<td class='footer' align='center'>This site designed by <a href='http://www.gazza.co.nz/'>Gazza</a><br>");
     document.write("This page was last updated on: " + document.lastModified + ".<br>");
     document.write("&copy; 2001, Whatuwhiwhi.co.nz, All Rights Reserved.</td>");
     document.write("<td width='50' align='center' class='sic'><a href='" + relpath +"index.shtml' class='noline'><img src='" + relpath + "images/hutbut.gif' width='40' height='40' border='0'><br>Home</a></td></tr></table>");
}        

function goBack() {
   if (document.referrer != "") document.location = document.referrer;
    else document.location = "index.shtml"
}
               
function reDo() {       
            if (innerWidth != origWidth || innerHeight != origHeight) {
                location.reload();
            }
}       

// get value from search URL
function searchVal(searchName){
  var  searchResult = ""; mySearch = location.search;
  searchName += "=";
  var x = searchName.length;
  var eq = mySearch.indexOf(searchName);
  if (eq > -1){
    searchResult = mySearch.substring(eq+x);
    eq = searchResult.indexOf("&");
    if (eq > -1){
      searchResult = searchResult.substring(0,eq);
    }
  } 
  return searchResult;
}

function bigPicture(picture, title, wdth, hght){
var winwdth = wdth + 50;
var winhght = hght + 95;
var disc = 'toolbar=0,location=1,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width=' + winwdth +',height=' + winhght;
var w = window.open("", "picturewin", disc);
var d = w.document;
d.open();
d.writeln("<HTML>\n<HEAD><TITLE>Whatuwhiwhi On-line</TITLE>");
d.writeln("<STYLE><!--");
d.writeln("BODY {background-color: white; font-family: Arial, Sans Serif, Serif; font-size: 25pt}");   
d.writeln("--></STYLE>");
d.writeln("</HEAD><BODY>");
d.writeln("<IMG SRC='",picture,"' WIDTH='",wdth,"' HEIGHT='",hght,"' ALT=''>");
d.writeln("<CENTER>",title,"</CENTER>");
d.writeln("<FORM><CENTER><INPUT TYPE=button VALUE=' Close ' onClick='window.close()'></CENTER></FORM>");
d.writeln("</BODY></HTML>");
d.close();
}

 function isWord(val) {
         for (var i=0; i < val.length; i++) {
                 if (!isAlphaNumeric(val.charAt(i))) { return false; }
                 }
         return true;
         }

function isGraphics(value){ 
  var x = value.indexOf(".");
  if (x == -1) {return false};
  var filename = value.substring(0,x);
  if (!isWord(filename)) {return false;}  
  var extension = value.substring(x+1,value.length)
  extension = extension.toLowerCase();
  if ((extension != "jpg") && (extension != "gif")) {return false};
  return true;
}


function isAlphaNumeric(value) {
   var string="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
   if (string.indexOf(value) != -1) {
        return true;
   }
   return false;
}

 // ===================================================================
 // Author: Matt Kruse <mkruse@netexpress.net>
 // WWW: http://www.mattkruse.com/
 //

 function isNull(val) {
        if (val == null) { return true; }
         return false;
         }

 function isBlank(val) {
         if (val == null) { return true; }
         for (var i=0; i < val.length; i++) {
                 if ((val.charAt(i) != ' ') && (val.charAt(i) != "\t") && (val.charAt(i) != "\n")) { return false; }
                 }
         return true;
         }

 function isInteger(val) {
         for (var i=0; i < val.length; i++) {
                 if (!isDigit(val.charAt(i))) { return false; }
                 }
         return true;
         }

 function isNumeric(val) {
         var dp = false;
         for (var i=0; i < val.length; i++) {
                 if (!isDigit(val.charAt(i))) { 
                         if (val.charAt(i) == '.') {
                                 if (dp == true) { return false; } // already saw a decimal point
                                 else { dp = true; }
                                 }
                         else {
                                 return false; 
                                 }
                         }
                 }
         return true;
         }

         
 function isDigit(num) {
         var string="1234567890";
         if (string.indexOf(num) != -1) {
                 return true;
                 }
         return false;
         }

 function formatDate(date,format) {
         format = format+"";
         var result = "";
         var i_format = 0;
         var c = "";
         var token = "";
         var y = date.getYear()+"";
         var M = date.getMonth()+1;
         var d = date.getDate();
         var H = date.getHours();
         var m = date.getMinutes();
         var s = date.getSeconds();
         var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;
         // Convert real date parts into formatted versions
         // Year
         if (y.length < 4) {
                 y = y-0+1900;
                 }
         y = ""+y;
         yyyy = y;
         yy = y.substring(2,4);
         // Month
         if (M < 10) { MM = "0"+M; }
                 else { MM = M; }
         MMM = MONTH_NAMES[M-1];
         // Date
         if (d < 10) { dd = "0"+d; }
                 else { dd = d; }
         // Hour
         h=H+1;
         K=H;
         k=H+1;
         if (h > 12) { h-=12; }
         if (h == 0) { h=12; }
         if (h < 10) { hh = "0"+h; }
                 else { hh = h; }
         if (H < 10) { HH = "0"+K; }
                 else { HH = H; }
         if (K > 11) { K-=12; }
         if (K < 10) { KK = "0"+K; }
                 else { KK = K; }
         if (k < 10) { kk = "0"+k; }
                 else { kk = k; }
         // AM/PM
         if (H > 11) { ampm="PM"; }
         else { ampm="AM"; }
         // Minute
         if (m < 10) { mm = "0"+m; }
                 else { mm = m; }
         // Second
         if (s < 10) { ss = "0"+s; }
                 else { ss = s; }
         // Now put them all into an object!
         var value = new Object();
         value["yyyy"] = yyyy;
         value["yy"] = yy;
         value["y"] = y;
         value["MMM"] = MMM;
         value["MM"] = MM;
         value["M"] = M;
         value["dd"] = dd;
         value["d"] = d;
         value["hh"] = hh;
         value["h"] = h;
         value["HH"] = HH;
         value["H"] = H;
         value["KK"] = KK;
         value["K"] = K;
         value["kk"] = kk;
         value["k"] = k;
         value["mm"] = mm;
         value["m"] = m;
         value["ss"] = ss;
         value["s"] = s;
         value["a"] = ampm;
         while (i_format < format.length) {
                 // Get next token from format string
                 c = format.charAt(i_format);
                 token = "";
                 while ((format.charAt(i_format) == c) && (i_format < format.length)) {
                         token += format.charAt(i_format);
                         i_format++;
                         }
                 if (value[token] != null) {
                         result = result + value[token];
                         }
                 else {
                         result = result + token;
                         }
                 }
         return result;
         }
         
         

