/* AUTHOR: Dale Bechtel, Bechtel Consulting. email: wizard@qumulous.com                             */
/* DESCRIPTION: JavaScript Function Library                                                                               */
/* Copyright (c)2000, Dale Bechtel. All Rights Reserved.  http://www.qumulous.com                   */
/*--------------------------------------------------------------------------------------------------*/
//   Function            Purpose
// -------------        ----------
//  siteInit()          Initialize all site specific stuff.
//  showImg()           When user clicks on thumbnail, display target image in new window sized to image.
//  setStyles()         Load Stylesheet According To Browser Type And Version.
//  dateLastModified()  Display Date Document Was Last Modified
//  date_ddmmmyyyy()    format date as dd-mmm-yyyy
//  loadBanner()        Load a banner (or graphic) randomly from series of banner ads.
/*--------------------------------------------------------------------------------------------------*/
//     Global Variables
/*--------------------------------------------------------------------------------------------------*/
var pix;
var snapShot = null;

/*--------------------------------------------------------------------------------------------------
//      Function: siteInit( )
//  Description: Initialize all website stuff.
//       Syntax: [SCRIPT]siteInit( statStr );[/SCRIPT]
//--------------------------------------------------------------------------------------------------*/
function siteInit( statStr )
{
   window.defaultStatus = ( (statStr==null) ? "By Bechtel Consulting. (717) 652-6604 or www.qumulous.com" : statStr);
   chkFrames( "contentPage" );
}

//--------------------------------------------------------------------------------------------------
//      Function: chkFrames( Mode )   // Mode=Frameset or ContentPage
//  Description: Enforce the navigation menu frames, and prevent our pages from being hijacked.
//--------------------------------------------------------------------------------------------------
function chkFrames( Mode )
{
   if (location.protocol=="file:") { return; }

   if (Mode=="frameSet")
   {
       if (window.top != window)
	   {
	      window.top.location = window.location;
	   }
	   return;
   }

   if ( (window.name != "Main") && (window.name != "Banner") )
   {
	  siteURL = ( (siteURL==null) ? "http://www.qumulous.com/splash.html" : siteURL);
	  window.top.location = siteURL;
   }

return;

}

//--------------------------------------------------------------------------------------------------
//      Function: showPix(theURL)
//  Description: When user clicks on thumbnail, display target image in new window sized to image.
//               Automatically calculates image dimensions.
//       Syntax: <A Href="javascript:showPix('images/sticks_2.jpg');">
//--------------------------------------------------------------------------------------------------
function showPix( src )
{
   if (src == null) { alert('Sorry, There Is No Image Available At This Time...');  return; }

   pix         = new Image();
   pix.onload  = dispPix;
   pix.onerror = doError;
   pix.src     = src;
}

//--------------------------------------------------------------------------------------------------
function dispPix()
{
   if (snapShot != null && snapShot.open){ snapShot.close(); }

   var winTop    = (screen.height-this.height)/2;                          // Window Centering Calculations
   var winLeft   = (screen.width-this.width)/2;
   var winOption = "height="+(this.height+40)+",width="+this.width+",top="+winTop+",left="+winLeft;

   snapShot = window.open("","Test", winOption);
   snapShot.document.write('<HTML><head>');
   snapShot.document.write('<title>Press F5 If Image Does not Display</title>');
   snapShot.document.write('<META HTTP-EQUIV="Refresh" CONTENT="5"');
   snapShot.document.write('<SCRIPT type="text/JavaScript" language="JavaScript" Src="../Code/Bechtel.js"></SCRIPT></head>');
   snapShot.document.write('<body bgcolor=black LEFTMARGIN=0 MARGINWIDTH=0 TOPMARGIN=0 MARGINHEIGHT=0><CENTER>');
   snapShot.document.write('<IMG SRC='+this.src+' HEIGHT='+this.height+' WIDTH='+this.width+'>');
   snapShot.document.write('<INPUT TYPE="button" VALUE="Close This Picture" onClick="self.close()">');
   snapShot.document.write('</CENTER></body></html>');
   snapShot.focus();
   snapShot.location.reload();

}

//--------------------------------------------------------------------------------------------------
function doError() { alert("The image at " + this.src + " could not be found") }

//function snapClean() { if (snapShot != null && snapShot.open){ snapShot.close(); window.opener.focus();} }

function snapClean() { snapShot.close(); window.opener.focus();}

//--------------------------------------------------------------------------------------------------
//      Function: showImg( theURL, theW, theH )
//  Description: When user clicks on thumbnail, display target image in new window sized to image.
//       Syntax: <A Href="javascript:showImg('images/sticks_2.jpg', '640', '480');">
//--------------------------------------------------------------------------------------------------
function showImg( theURL, theW, theH )
{
   if ( theURL == null )
   {
   alert('Sorry, There Is No Image Available At This Time...');
   return;
   }

   var theImg    = new Image();
   var theHeight = '';
   var theWidth  = '';
   var winOption = '';
   var winTop    = '';
   var winLeft   = '';

   theImg.src = theURL;
   theHeight  = theH;
   theWidth   = theW;

   theHeight = ( (theHeight=='0') ? theImg.height : theHeight );
   theWidth  = ( (theWidth=='0') ? theImg.width : theWidth );
   winTop    = (screen.height-theHeight)/2;                          // Window Centering Calculations
   winLeft   = (screen.width-theWidth)/2;

   winOption  = "height="+theHeight+",width="+theWidth+",top="+winTop+",left="+winLeft;

   snapShot = window.open("","Test", winOption);
   snapShot.document.write("<HTML><head>");
   snapShot.document.write("<title>Close This Window When You Are Finished Viewing</title></head>");
   snapShot.document.write("<body bgcolor=white LEFTMARGIN=0 MARGINWIDTH=0 TOPMARGIN=0 MARGINHEIGHT=0>");
   snapShot.document.write("<IMG SRC="+theURL+" HEIGHT="+theHeight+" WIDTH="+theWidth+">");
   snapShot.document.write("<IMG SRC="+theURL+" HEIGHT="+theHeight+" WIDTH="+theWidth+">");
   snapShot.document.write("</body></html>");
   snapShot.focus();

}

/*--------------------------------------------------------------------------------------------------*/
//                   Load Stylesheet According To Browser Type And Version
/*--------------------------------------------------------------------------------------------------*/
function setStyles()
{
   var browser=navigator.appName;
   var version=navigator.appVersion;
   var ver1=version.substring(0,1);
   var ver2=version.lastIndexOf("MSIE");
   var ver3=version.substring(ver2+5,ver2+6);
   var s1 = '<LINK REL="StyleSheet" HREF="Style"';
   var s2 = 'TYPE="text/css">'
   var ss ='';

   switch (browser){
      case 'Netscape' :
	     if (ver1 >= 4) { ss = 'Netscape.css'; }
	     break;

	  case 'Microsoft Internet Explorer' :
	     //if (ver1 >= 4) { ss = '.css'; }
		 if (ver3 == 3) { ss = 'IE3.css';}
	     break;

	  case 'Whatever' :
	     break;
   }

   s = (s1+ss+s2);

return s;
}

/*--------------------------------------------------------------------------------------------------*/
//  Display Date Document Was Last Modified:
//  Example: document.write("This page was updated on " + dateLastModified() );
/*--------------------------------------------------------------------------------------------------*/
function dateLastModified()
{
  var lmd = document.lastModified;
  var s   = "Unknown";
  var d1;
                                        // check if we have a valid date before proceeding
  if(0 != (d1=Date.parse(lmd)))
  {
    s = "" + date_ddmmmyyyy(new Date(d1));
  }

return s;
}

/*--------------------------------------------------------------------------------------------------*/
// format date as dd-mmm-yyyy example: 12-Jan-1998
/*--------------------------------------------------------------------------------------------------*/
function date_ddmmmyyyy(date)
{
  var d = date.getDate();
  var m = date.getMonth() + 1;
  var y = date.getYear();
                                                     // could use splitString() here but the following method is more compatible
  var mmm = ( 1==m)?'Jan':( 2==m)?'Feb':(3==m)?'Mar':( 4==m)?'Apr':( 5==m)?'May':(6==m)?'Jun':( 7==m)?'Jul':( 8==m)?'Aug':(9==m)
                   ?'Sep':(10==m)?'Oct':(11==m)?'Nov':'Dec';

return "" + (d<10?"0"+d:d) + "-" + mmm + "-" + (y<1950?2000+y:y);
}

/*--------------------------------------------------------------------------------------------------
//      Function: loadBanner()
//   Description: Load a banner (or graphic) randomly from series of banner ads.
//        Syntax:
//--------------------------------------------------------------------------------------------------*/
//     Global Variables
/*--------------------------------------------------------------------------------------------------*/
var banLink = new Array();   // Array of href anchor strings with no terminating (/a) tag.
var banPict = new Array();   // Array of img strings to embed with no closing (>) bracket.
var ratIsOn = new Array();   // Array of mouseover events.
var ratIsOf = new Array();   // Array of mouseoff events.
//---------------------------------------------------------------------------------------------------
// Setup Banner String Arrays - Should be defined in [siteName].js file and included before Bechtel.js
//---------------------------------------------------------------------------------------------------
// banLink[0] = '<A HREF="http://www.newmember.com/cgi-bin/sexbucks/sexbucks.cgi?5010565">';
// banPict[0]  = '<IMG SRC="ads/Banner-01.gif" ALT="Click here for Sex" BORDER="0" ALIGN="BOTTOM" WIDTH="468" HEIGHT="60"';
// ratIsOn[0]  = "window.status='http://www.aBlindLink01.com/enter.html';return true;";
// ratIsOf[0]  = "window.status='Back To Reality';return true;";
//---------------------------------------------------------------------------------------------------
function loadBanner()
{
var thisBan = "";
var theRest = "";
var nextBan = 0;

     nextBan =  ( Math.ceil(Math.random() * banLink.length) -1 );
	 theRest =  ( (ratIsOn[nextBan].length > 0) ? (' onmouseover=' + '"' + (ratIsOn[nextBan]) + '"') : '');
	 theRest += ( (ratIsOf[nextBan].length > 0) ? (' onmouseoff=' + '"' + (ratIsOf[nextBan]) + '"' + '></A>') : '></A>');
	 thisBan =  ( banLink[nextBan] + banPict[nextBan] + theRest );

return (thisBan);
}

/*----------------------------------------[ End Of Code ]--------------------------------------------*/
