// File:     common.js
// Purpose:  Contains commonly-used JavaScript routines
// security: COPYRIGHT (c) Copyright 2005 C&G Web Enterprises
// owner:    Gary Richtmeyer, gary@CandGWeb.com
// Created:  Monday, 16 May 2005 12:00:00
// Updated:
//   2005-08-05 - Remove development-only code, update email addresses
//   2005-08-06 - Changed contact page to "contact.asp" from "contact.html"
//   2005-08-16 - Changed Bible verse to KJV from NIV; minor header change
//   2006-02-04 - Changed copyright to refer to 2006
//   2007-06-01 - Changed copyright to 2007; update upper-left/right pix
//   2007-06-21 - Change upper-left logo picture
//   2008-01-11 - Changed copyright to refer to 2008
//   2008-12-22 - Changed copyright to refer to 2009
//   2008-12-22 - Changed copyright to refer to 2010

var browser_name    = navigator.appVersion
var browser_release = browser_name.substring(0,browser_name.indexOf(' '))
var browser_version = parseInt(navigator.appVersion)
var browser_type    = '?'

if (navigator.appName == "Netscape")            { browser_type = 'NS'    }
if (navigator.userAgent.indexOf("Opera") != -1) { browser_type = 'OPERA' }
if (navigator.appVersion.indexOf("MSIE") != -1) { browser_type = 'MSIE'  }

if (browser_version < 4) { size='M' }
  else { w=window.screen.width; size='L'
    if (w <= 800) { size='M' }
    if (w <= 640) { size='S' }
    }

if (document.images) {
  var button_prefix = "main_"
  var ip = "images/" + button_prefix
  aboutusdown    = new Image(126,36); aboutusdown.src    = ip + "aboutus_down.gif";
  aboutushere    = new Image(126,36); aboutushere.src    = ip + "aboutus.gif";
  aboutusover    = new Image(126,36); aboutusover.src    = ip + "aboutus_over.gif";
  aboutusup      = new Image(126,36); aboutusup.src      = ip + "aboutus_up.gif";
  audioclipsdown = new Image(126,36); audioclipsdown.src = ip + "audioclips_down.gif";
  audioclipshere = new Image(126,36); audioclipshere.src = ip + "audioclips.gif";
  audioclipsover = new Image(126,36); audioclipsover.src = ip + "audioclips_over.gif";
  audioclipsup   = new Image(126,36); audioclipsup.src   = ip + "audioclips_up.gif";
  concertsdown   = new Image(126,36); concertsdown.src   = ip + "concerts_down.gif";
  concertshere   = new Image(126,36); concertshere.src   = ip + "concerts.gif";
  concertsover   = new Image(126,36); concertsover.src   = ip + "concerts_over.gif";
  concertsup     = new Image(126,36); concertsup.src     = ip + "concerts_up.gif";
  contactdown    = new Image(126,36); contactdown.src    = ip + "contactus_down.gif";
  contacthere    = new Image(126,36); contacthere.src    = ip + "contactus.gif";
  contactover    = new Image(126,36); contactover.src    = ip + "contactus_over.gif";
  contactup      = new Image(126,36); contactup.src      = ip + "contactus_up.gif";
  gallerydown    = new Image(126,36); gallerydown.src    = ip + "gallery_down.gif";
  galleryhere    = new Image(126,36); galleryhere.src    = ip + "gallery.gif";
  galleryover    = new Image(126,36); galleryover.src    = ip + "gallery_over.gif";
  galleryup      = new Image(126,36); galleryup.src      = ip + "gallery_up.gif";
  homedown       = new Image(126,36); homedown.src       = ip + "home_down.gif";
  homehere       = new Image(126,36); homehere.src       = ip + "home.gif";
  homeover       = new Image(126,36); homeover.src       = ip + "home_over.gif";
  homeup         = new Image(126,36); homeup.src         = ip + "home_up.gif";
  linksdown      = new Image(126,36); linksdown.src      = ip + "links_down.gif";
  linkshere      = new Image(126,36); linkshere.src      = ip + "links.gif";
  linksover      = new Image(126,36); linksover.src      = ip + "links_over.gif";
  linksup        = new Image(126,36); linksup.src        = ip + "links_up.gif";
  mediadown      = new Image(126,36); mediadown.src      = ip + "media_down.gif";
  mediahere      = new Image(126,36); mediahere.src      = ip + "media.gif";
  mediaover      = new Image(126,36); mediaover.src      = ip + "media_over.gif";
  mediaup        = new Image(126,36); mediaup.src        = ip + "media_up.gif";
  newsdown       = new Image(126,36); newsdown.src       = ip + "news_down.gif";
  newshere       = new Image(126,36); newshere.src       = ip + "news.gif";
  newsover       = new Image(126,36); newsover.src       = ip + "news_over.gif";
  newsup         = new Image(126,36); newsup.src         = ip + "news_up.gif";
  productsdown   = new Image(126,36); productsdown.src   = ip + "products_down.gif";
  productshere   = new Image(126,36); productshere.src   = ip + "products.gif";
  productsover   = new Image(126,36); productsover.src   = ip + "products_over.gif";
  productsup     = new Image(126,36); productsup.src     = ip + "products_up.gif";
  referencesdown = new Image(126,36); referencesdown.src = ip + "references_down.gif";
  referenceshere = new Image(126,36); referenceshere.src = ip + "references.gif";
  referencesover = new Image(126,36); referencesover.src = ip + "references_over.gif";
  referencesup   = new Image(126,36); referencesup.src   = ip + "references_up.gif";
  }


//-------------------------------------------------------------------
// Routines for manipulating the navigation button images
//-------------------------------------------------------------------

// ImgUp: Turn the specified navigation button to the "up" position
function ImgUp(imgName) {
  if ( document.images )
         { document[imgName].src = eval(imgName + "up.src") }
    else { imgName = null; }
  return true
  }

// ImgDown: Turn the specified navigation button to the "Down" position
function ImgDown(imgName) {
  if ( document.images )
         { document[imgName].src = eval(imgName + "down.src") }
    else { imgName = null; }
  return true
  }

// ImgOver: Turn the specified navigation button to the "Over" position
function ImgOver(imgName) {
  if ( document.images )
         { document[imgName].src = eval(imgName + "over.src") }
    else { imgName = null; }
  return true
  }




//-------------------------------------------------------------------
// Routines to manipulate/show dates
//-------------------------------------------------------------------

// MakeArray:  create an array of the designated size
  function MakeArray(n) {
    this.length = n
    for (var i = 0; i <= n; i++) { this[i] = 0 }
    return this
    }


// DateStr: Return a date string formatted from the passed date value.
// e.g. abc = DateStr()  might return: Sunday, August 29 at 3:00:00 p.m.
  function DateStr(dsparm) {
    dow=new MakeArray(6); moy=new MakeArray(11)
    dow[0]='Sunday';    dow[1]='Monday';   dow[2]='Tuesday';   dow[3]='Wednesday'
    dow[4]='Thursday';  dow[5]='Friday';   dow[6]='Saturday'
    moy[0]='January';   moy[1]='February'; moy[2]='March';     moy[3]='April'
    moy[4]='May';       moy[5]='June';     moy[6]='July';      moy[7]='August'
    moy[8]='September'; moy[9]='October';  moy[10]='November'; moy[11]='December'

    if ( (dsparm=='') || (dsparm==null) ) // any passed value?
           { dsdate  = new Date() }       //   no, get today's date
      else { dsdate  = new Date(dsparm) } //   yes, get the date
    year  = dsdate.getYear()  ; hour    = dsdate.getHours()
    month = dsdate.getMonth() ; minutes = dsdate.getMinutes()
    dom   = dsdate.getDate()  ; seconds = dsdate.getSeconds()
    day   = dsdate.getDay()
    if        ( year < 100  ) { yyyy = year + 2000 }
      else if ( year < 1000 ) { yyyy = year + 1900 }
      else                    { yyyy = year }
    if        ( hour <= 11 ) { ampm='a.m.' }
      else if ( hour == 12 ) { ampm='p.m.' }
      else                   { ampm='p.m.'; hour=hour-12 }
    if ( hour == 0 ) showhour="00"; else showhour=hour
    if ( minutes < 10 ) minutes = "0" + minutes
    if ( seconds < 10 ) seconds = "0" + seconds
    return dow[day] + ", " + moy[month] + " " + dom + ", " + yyyy + " at " +
           showhour + ":" + minutes + ":" + seconds + " " + ampm
    }


//-------------------------------------------------------------------
// Routines for creating top-of-page and bottom-of-page
//-------------------------------------------------------------------

function PageTop(pageid,pagetitle) {
  thisid = pageid
  bibletext = '"Serve the Lord with gladness, '         +
              'come before His presence with singing." '     
  bibleref  = 'Psalms 100:2'
  biblever  = 'KJV'

  var temp  = ""
  temp += '<table cellpadding=2 cellspacing=2 width="100%"><tr><td align=left>' +
          '<img src="images/TLlogo5b.jpg" width=325 height=200></td>'
  temp += '<td valign=middle align=center>' +
          '<font size=3 color="#005A7B" face="Verdana,Arial,Helvetica"><b>'     +
          bibletext + ' </b><nobr>-- <i>' + bibleref                            +
          '</i>&nbsp;&nbsp;(' + biblever + ')</nobr></font></td>'
  temp += '<td align=right>'                                                    +
          '<img src="images/TRlogo4.jpg" width=324 height=189'                  +
               'alt="Three Plus One Quartet">'                                  +
          '</td></tr></table><hr noshade size=3>'
  document.write(temp)

  temp  = '<table><tr><td align=left valign=top>'
  temp += NavButton(thisid,'home',       'index.html',      'Home',            126,36)
  temp += NavButton(thisid,'aboutus',    'aboutus.html',    'About Us',        126,36)
  temp += NavButton(thisid,'gallery',    'gallery.html',    'Picture Gallery', 126,36)
  temp += NavButton(thisid,'references', 'references.html', 'References',      126,36)
  temp += NavButton(thisid,'audioclips', 'audioclips.html', 'Audio Clips',     126,36)
  temp += NavButton(thisid,'products',   'products.html',   'Products',        126,36)
  temp += NavButton(thisid,'concerts',   'concerts.html',   'Concerts',        126,36)
  temp += NavButton(thisid,'contact',    'contact.asp',     'Contact Us',      126,36)
  temp += NavButton(thisid,'media',      'media.html',      'Media',           126,36)
  temp += NavButton(thisid,'news',       'news.html',       'News',            126,36)
  temp += NavButton(thisid,'links',      'links.html',      'Links',           126,36)
  temp += '</td>'
  document.write(temp)

  temp  = '<td width=1 bgcolor="#0B759D">' +
          '<img src="images/onepix.gif" width=1 height=1></td>' +
          '<td align=left valign=top>'
  if ( pagetitle != '') {
    temp += '<a name="top"><h2>' + pagetitle + '</h2></a><br>'
    }
  temp += STextFont() // circumvent Netscape bug
  document.write(temp)

  return
  }


function PageBottom(pageid) {
  var temp = ""
  temp += '</td></tr></table><br><hr>'
  temp += '<table width="100%"><tr>' +
          '<td align=left valign=top><font size="1">' +
          'Copyright &copy; 2005-2010 Three Plus One Quartet' +
          '<br>Web site by <a href="http://www.CandGWeb.com/">' +
          'C&amp;G Web Enterprises</a></font></td>'
  temp += '<td>&nbsp;</td>' +
          '<td align=right valign=top><font size="1">' +
          'Page last updated: ' + DateStr(document.lastModified)
  temp += '<br>Questions or comments about this web site? ' +
          '<a href="mailto:webmaster@ThreePlusOneQuartet.com?subject=' +
          'Three%20Plus%20One%20Quartet%20Website%20Feedback,%20' +
          'PageId=' + pageid + '/URL=' + self.location.href + '">' +
          'Contact us!</a></font></td>'
  temp += '</tr></table>' +
          '</font>' + ETextFont()
  document.write(temp)
  return
  }



//-------------------------------------------------------------------
// NavButton: Generate HTML for a major section in the nav bar
// Use: NavButton(callerid,thisitem,thisurl,navtitle,width,height)
//   callerid  - Section ID of requester
//   thisitem  - Section ID associated with the following items
//   thisurl   - URL of target file
//   navtitle  - description for the "bubble" text
//   width     - width  of the graphic (in pixels)
//   height    - height of the graphic (in pixels)
//-------------------------------------------------------------------
function NavButton(callerid,thisitem,thisurl,navtitle,width,height) {
  if (thisurl == undefined) thisurl = ''
  if (thisurl.substr(0,1) == '!')
         { thisurl = thisurl.substr(1); targ = 'target="_new" ' }
    else { thisurl = thisurl;           targ = ''               }
  imgprefix = thisitem.toLowerCase()
  if (callerid == thisitem)
         { result = '<a href="' + thisurl + '" ' + targ + '>' +
                    '<img src="' + eval(imgprefix + 'here.src') + '" ' +
                    'border=0 width=' + width + ' height=' + height +
                    ' name="' + imgprefix + '" alt="' + navtitle + '"></a>' }
    else { result = '<a href="' + thisurl + '" ' + targ +
                    'onMousedown=ImgDown("' + imgprefix + '") ' +
                    'onMouseOver=ImgOver("' + imgprefix + '") ' +
                    'onMouseOut=ImgUp("'    + imgprefix + '")>' +
                    '<img src="' + eval(imgprefix + 'up.src') + '" ' +
                    'border=0 width=' + width + ' height=' + height +
                    ' name="' + imgprefix + '" alt="' + navtitle + '"></a>' }
  return result + '<br><img src="images/onepix.gif" width=4  height=4><br>'
  }


// Return a start/end text font tag with desired face
function STextFont() { return '<FONT FACE="Verdana,Arial,Helvetica">' }
function ETextFont() { return '</FONT>' }

