<!-- Hide from non-JavaScript Browsers --
// --------------------------------------------------------------------------------
// David F. Dafoe --  Library of utility functions                               //
// --------------------------------------------------------------------------------

var slideWin = null;	// don't use this file in the window itself!

var baseURL;	// ----- following is implementation-specific -----------------------
if (location.href.substr(0,16) == "http://localhost")
  {   baseURL = "http://localhost/davidandbecky/";	// baseURL could be called "server"
  }
else if  (location.href.substr(0,4) == "http")
  {   baseURL = "http://davidandbecky.com/";
  }
else
   { temp = location.href;	// loading file directly - not through server
     pos  = temp.indexOf ("/DavidAndBecky");   
     slashPos = temp.indexOf ("/", pos + 1);
     baseURL = temp.slice (0, slashPos + 1);	// ignore everything after this slash
   }

function gotoLink (resource) // 2006-09-27 added this to use in select statement to jump to another URL
{ self.location.href = resource
}

function writeFooter ()
{ document.writeln ('<hr width=90% height=10>');
  document.write ('<p class=footer>');
  lastUpdated();
// ----- tbd there's probably a better way ------------
  document.writeln ('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\'faq.htm\'>frequently asked questions</p>');  
}

function lastUpdated()
{// ---------------------------------------------------------------------------------------- 
 // Original:  http://www.jwp.bc.ca/saulm/html/bornon.htm  				
 // 01/09/2001 DFD - Y2K compliant and cross-browser (current versions) compatible
 // writes out plain text, no formatting
 // ---------------------------------------------------------------------------------------- 
 
 var days = new Array(8);
 days[1] = "Sunday"; 	days[2] = "Monday"; 	days[3] = "Tuesday";	days[4] = "Wednesday";	days[5] = "Thursday";
 days[6] = "Friday"; 	days[7] = "Saturday";
 var months = new Array(13);
 months[1] = "January";		months[2] = "February";		months[3] = "March";	months[4] = "April";		months[5] = "May";
 months[6] = "June";		months[7] = "July";			months[8] = "August";	months[9] = "September";	months[10] = "October";
 months[11] = "November";	months[12] = "December";
 var dateObj = new Date(document.lastModified);
 
 x_str = navigator.appVersion;
 is_htm = location.href.indexOf (".htm") >= 0; // will also return false if server implicitly returns the index
// document.writeln ("navigator.appVersion = " + x_str +   " is_htm = " + is_htm + "</BR>");
 if (x_str.indexOf ("Apple") >= 0 & is_htm == false) 
   { } // Macs may have problems getting the date of the doc. Tried a better fix but it didn't work at all.
 else if (Date.parse(document.lastModified) == 0) // Test to see if date is unavailable, e.g. sc!ript-generated page
   document.write("Last Revised: (not available)"); // could make it today's date for scripts?
 else
   { var wday = days[dateObj.getDay() + 1]; // need to add 1
     var lmonth = months[dateObj.getMonth() + 1];
     var date = dateObj.getDate();
	 var fyear = dateObj.getFullYear();
    document.write("Last Revised: " +  wday + ", " + lmonth + " " + date + ", " + fyear);
   };
}

function setCookie(name, value, expire) {
          document.cookie = name + "=" + escape(value)
          + ((expire == null) ? "" : ("; expires=" + expire));
// ----- Sets cookie values. Expiration date is optional ---------------------------
//Notice the use of escape to encode special characters (semicolons, commas, spaces) in the value string. This function
//assumes that cookie names do not have any special characters.
// document.writeln ("SetCookie: " + "name=" + name + " value=" + value)
}

function getCookie(Name) {
// ----- The following function returns a cookie value, given the name of the cookie -----
          var vsearch = Name + "=";
		  var end;
          if (document.cookie.length > 0) { // if there are any cookies
                    offset = document.cookie.indexOf(vsearch) 
                    if (offset != -1) { // if cookie exists 
                              offset += vsearch.length 
                              // set index of beginning of value
                              end = document.cookie.indexOf(";", offset) 
                              // set index of end of cookie value
                              if (end == -1) 
                                        end = document.cookie.length
                              return unescape(document.cookie.substring(offset, end))
                    } 
          };

// document.writeln ("GetCookie: " + Name + "=" + unescape(document.cookie.substring(offset, end)))
}
function thisfName ()
// ---------------------------------------------------------------------------------------------------- 
// returns file name of current page only for HTML pages.  If URL was loaded without explicit 
// file reference, return "index.htm";  .  If non-HTML file, return "" 
// ---------------------------------------------------------------------------------------------------- 
{	URL = window.location.href;
// ----- check for a null file name if user loaded URL without explicit file reference ---------------
	slashPos = URL.lastIndexOf ('/');
	if (slashPos == URL.length - 1 || URL.substr (slashPos, slashPos+1) == "#")  return "index.htm";
	
	ishtm = (URL.indexOf('.htm') > -1);  
	ishtml = (URL.indexOf('.html') > -1);
	if (ishtm || ishtml)
	{ gotfName = URL.substr (slashPos+1, URL.length-1);
	  return gotfName.toLowerCase ();
// e.g. http://www.goofy.com/goofyspage.htm
//      01234567890123456789012345678901234
// slashPos=20, URL.length=35 
	}
	else return "";
}

function fNameInitialMatch (fName1, fName2)
// ------ Compare initial parts of two .htm or .html file names ----------
{ // ------ convert each string to lower case ----------
  fName1 = fName1.toLowerCase ();
  fName2 = fName2.toLowerCase ();
  if (fName1.indexOf('.htm') == -1 || fName2.indexOf('.htm') == -1)  return false;
  // strip off file extension from both names
  fName1 = fName1.substr (0, fName1.indexOf('.htm')); 
  fName2 = fName2.substr (0, fName2.indexOf('.htm')); 

  // ----- strip off any directories which may qualify file name -----
  slashPos = fName1.lastIndexOf ('/');
  if (slashPos != -1)
    fName1 = fName1.substr (slashPos+1, fName1.length-slashPos-1);
  slashPos = fName2.lastIndexOf ('/');
  if (slashPos != -1)
    fName2 = fName2.substr (slashPos+1, fName2.length-slashPos-1);	//  document.writeln ('<font size=1>comparing ' + fName1 + ' to ' + fName2 + ' </font>');      

  // compare the initial part of each file name
  if (fName1.length >= fName2.length) return fName1.substr (0, fName2.length) == fName2;
  else return fName2.substr (0, fName1.length) == fName1;
}

function isEven (number)
// ----- returns true if number is even --------------------------
{ return (number % 2) == 0;
}
/* -- causes IE to squawk -----
function jump2album ()
{ i 	= document.album.albSelect.selectedIndex; 
  link  = document.album.albSelect.options[i].value; 
  if (link != "*") location.href = link
}

function loadAlbum (stateFlag)
{ i 	= document.album.albSelect.selectedIndex; 
  alb  	= document.album.albSelect.options[i].value; 
  if (alb != "*") location.href = "photoAlbum.pl?albSelect=" + alb + "&statePar=" + stateFlag
}

function loadAlbumFromHome ()	// I know, this is a kludge ...
{ i 	= document.album.albSelect.selectedIndex; 
  alb  	= document.album.albSelect.options[i].value; 
  if (alb != "*") location.href = "cgi-bin/photoAlbum.pl?albSelect=" + alb + "&statePar=" + 'displayAlbum'
}

function resetPage ()
{ if (thisfName () == 'index.htm' || thisfName () == 'index.asp') document.album.reset () // tbd what about index.asp?
}
*/

function makeWin (win, ref) 
{ if (win == 'slideWin') 
    { slideWin = window.open (ref, win, 'menubar=no,resizable=yes,scrollbars=yes,width=800, height=880');
      slideWin.focus ();
    }
}

function closeWin (win) 
{ if (win == 'slideWin') 
    { if (slideWin != null) slideWin.close ();
    }
}

// End -->