// header.js


header = new Header()

var html

Header.imageDir = 'images/'
Header.mainDir = ''
Header.vBorder = 'b-border.gif'
Header.logo = 'chlogo.gif'
Header.textGraphic = 'nhcc-text.gif'
Header.subText = '"The end of your search for a caring church!"&nbsp;'


String.prototype.fixupDebug = String_fixupDebug
String.prototype.replace = String_replace


// header class ---------------------------------------------------------------
function Header()
{
   // Variables -------------------------------------------
   
   this.sidebarItems = new Array()
   this.debug = false

   // Methods ---------------------------------------------
   
   this.addSidebarItem  = Header_addSidebarItem
   this.write           = Header_write
   this.writeFooter     = Header_writeFooter
   this.writeLogo       = Header_writeLogo
   this.writeSidebar    = Header_writeSidebar
   this.writeTopbar     = Header_writeTopbar
   
}  // header


// Add a sidebar item ---------------------------------------------------------
function Header_addSidebarItem( text, image, url, alt )
{
   var item = new HeaderSidebarItem( text, image, url, alt )
   this.sidebarItems[this.sidebarItems.length] = item
   
}  // Header_addSidebarItem


// Write the header to the HTML page ------------------------------------------
function Header_write()
{
   html = ""
   Header.imageDir = Header.mainDir + Header.imageDir
   
   html += "<div class='h-bar'></div>"
   html += this.writeSidebar()
   html += this.writeLogo()
   html += this.writeTopbar()
   
   if( this.debug )
      html = html.fixupDebug()
   
   document.writeln( html )
   
}  // Header_write


// Write the page footer ------------------------------------------------------
function Header_writeFooter( date )
{
   var htm = ""
   
   htm += "<p><div class='footer'>"
   htm += "Questions? Comments? Contact the church office at: <b>602-482-8140</b><br>"
   htm += "Problems with the site? "
   htm += "Contact our <a href='mailto:webminister@nhcc-az.com'>Webminister</a>.<br>"
   htm += "Copyright &copy; 2002-2008. Northern Hills Community Church and its licensors. All rights reserved.<br>"
   htm += "This page last updated: " + date
   htm += "</div>"
   
   document.writeln( htm )

}  // Header_writeFooter


// Write the application logo -------------------------------------------------
function Header_writeLogo()
{
   var htm = ""
   
   htm += "<div class='logo'>"
   htm += "<img " +
            "border='0' " +
            "src='" + Header.imageDir + Header.logo + "' >"
   htm += "</div>"
   
   return htm

}  // Header_writeLogo


// Write the sidebar items ----------------------------------------------------
function Header_writeSidebar()
{
   var htm = "", i, item, side
   
   htm += "<div class='v-bar' align='center'>"
   htm += "<table border='0' cellpadding='0' cellpadding='0'>"
   htm += "<tr><td><a href='" + Header.mainDir + "index.html'>Home</a></td></tr>"

   for( i = 0; i < this.sidebarItems.length; i++ )
   {
      item = this.sidebarItems[i]
      side = ""

      side += "<tr><td>"
      
      side += "<a href='" + Header.mainDir + item.url + "'>" +
              "<img " +
                  "border='0' " +
                  "src='" + Header.imageDir + item.image + "' " +
                  "alt='" + item.alt + "'>" +
              "</a><br>"
             
      side += "<a href='" + Header.mainDir + item.url + "'>" + item.text + "</a>"

      side += "</td></tr>"

      htm += side
   }

   htm += "</table>"
   htm += "<p>"
   htm += "<img border='0' src='" + Header.imageDir + Header.vBorder + "'>"
   htm += "</div>"
   
   return htm

}  // Header_writeSidebar


// Write the top bar and text -------------------------------------------------
function Header_writeTopbar()
{
   var htm = ""

   htm += "<div class='h-bar-text' align='middle'>"
   htm += "<table><tr><td>"
   htm += "<img border='0' src='" + Header.imageDir + Header.textGraphic + "'><br>"
   htm += Header.subText
   htm += "</td></tr></table>"
   htm += "</div>"
   
   return htm
   
}  // Header_writeTopbar


// Header Sidebar Item --------------------------------------------------------
function HeaderSidebarItem( text, image, url, alt )
{
   this.text = text
   this.image = image
   this.url = url
   this.alt = alt

}  // class HeaderSidebarItem


// Replace stuff in the string for debuggins ----------------------------------
function String_fixupDebug()
{
   var s = new String( this )
   
   s = s.replace( '<xx>', '*xx*' )
   s = s.replace( '<', '&lt;' )
   s = s.replace( '>', '&gt;' )
   s = s.replace( '*xx*', '<br>' )
   s = s.replace( '&nbsp;', '&amp;nbsp;' )
   
   s = '<pre>' + s + '<pre>'
   
   return s
   
}  // String_fixupDebug


// Replace a substring with another -------------------------------------------
function String_replace( findstr, replstr )
{
   var s = new String( this )

   var pos
   
   while( ( pos = s.indexOf( findstr ) ) != -1 )
   {
      s = s.substring( 0, pos ) + replstr + s.substring( pos + findstr.length )
   }
   
   return s

}  // String_replace


// Display a picture in a new window ------------------------------------------
function showPicture( width, height, url )
{
   var attr = "height="+(height+20)+", width="+(width+20)+", copyHistory=no, " +
              "location=no, menubar=no, resizable=no, status=no, toolbar=no";
   
   window.open( url, "", attr );

}   // showPicture


// Display a flyer in a new window ------------------------------------------
function showFlyer( url )
{
   var attr = "copyHistory=no, location=no, menubar=no, scrollbars=yes resizable=yes status=no, toolbar=no";
   
   window.open( url, "", attr );

}   // showPicture

