// File:     umi.js
// Purpose:  Contains commonly-used JavaScript routines
// security: COPYRIGHT (c) Copyright 2006 C&G Web Enterprises
// owner:    Gary Richtmeyer, gary@CandGWeb.com
// Created:  Saturday, 28 April 2006
// Updated:
//   2007-09-28 - Original version

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' }
    }


//*******************************************************************
// Various functions
//*******************************************************************


//-------------------------------------------------------------------
// setGlobalVars: set global variables
//   Usage: setGlobalVars(x)   x = option number of how many dirs
//                                 "up" from here is the root dir.
//   Sets the following global variables (referred to as
//   "top.xxxx" within other files):
//      baseURL    - The URL of the "root" directory
//      ImagePath  - The URL where the images are stored
//-------------------------------------------------------------------
function setGlobalVars(updirs) {
  temp = document.location.pathname    // change "\" in path
  j = temp.indexOf('\\')               // (e.g. on a PC and using MSIE)
  while ( j >= 0 ) {                   // to "/"
    temp = temp.substr(0,j) + '/' + temp.substr(j+1)
    j = temp.indexOf('\\',j)
    }
  if ( arguments.length == 0 )
         { updirs = 0 }
    else { updirs = arguments[0] }
  if ( updirs == null ) updirs = 0
  while ( updirs > 0 ) {
    temp = temp.substring(0,temp.lastIndexOf('/'))
    updirs = updirs - 1
    }
  baseURL   = document.location.protocol + '//' +
              document.location.host     +
              temp.substring(0,temp.lastIndexOf('/'))
  ImagePath = baseURL + '/images/'
  }


//-------------------------------------------------------------------
// Routines for creating top-of-page and bottom-of-page
//-------------------------------------------------------------------

//-------------------------------------------------------------------
// PageTop: set initial screen layout, header section and navigation.
// Use: PageTop('pageid','pagetitle' [,dirlevel] )
//   pageid    - ID of the active major section
//   pagetitle - Text to use as the page's title (optional)
//   dirlevel  - Directory level (0=root, 1=one "down", 2=two "down"...)
//               (defaults to "0" if omitted)
//-------------------------------------------------------------------
function PageTop(pageid,pagetitle,dirlevel) {
  setGlobalVars(dirlevel)
  thisid = pageid.toUpperCase()
//----- Top-of-page header logo  
  var temp  = ""
  temp += '<table align=center><tr>' +
          '<td align=center><img src="' + top.ImagePath + 'umilogo1.gif"></td>' +
          '<td align=center><img src="' + top.ImagePath + 'UMI-Logo-Handshake.gif"></td>' +
          '<td align=center><img src="' + top.ImagePath + 'umilogo2.gif"></td>' +
          '</tr></table><hr>'


//temp += '<table align=center class=head1><tr><td>' +
//        '&nbsp; &nbsp; &nbsp;United Members Insurance, Inc. &nbsp; &nbsp; &nbsp;' +
//        '</td></tr></table>'
//temp += '<table align=center border=0><tr><td>' +
//        '<img src="images/UMI-Logo-Handshake.gif">' +
//        '</td></tr></table>'
//temp += '<table align=center class=head2><tr><td>' +
//        '&nbsp; &nbsp; &nbsp; "A Union Agency That Understands" &nbsp; &nbsp; &nbsp;' +
//        '</td></tr></table>'
//temp += '<hr>'   
  document.write(temp)
//----- left-side-of-screen navigation buttons  
  temp  = '<table width="80%"><tr>' +
          '<td align=left  valign=top width=170><div id="menu"><ul>'

  temp += NavButton(thisid, 'HOME',                 'index.html',                'Home')
  temp += NavButton(thisid, 'ABOUTUS',              'AboutUs.html',              'About Us')
  temp += NavButton(thisid, 'FAMILY',               'UMIFamily.html',            'Our "UMI" Family')
  temp += NavButton(thisid, 'PRODUCTS',             'Products.html',             'Products List')
//if ( thisid == 'PRODUCTS' ) {
//  temp += '<table cellspacing=1 cellpadding=1>' +
//    NodeLink(thisid, 'TRUSTEE',                   'TrusteePolicy.html',        'Trustee Policy')       +
//    NodeLink(thisid, 'LEADERSHIP',                'LeadershipInsurance.html',  'Leadership Insurance') +
//    '</table><br>'
//  }
//temp += NavButton(thisid, 'GROUP',                'GroupInsurance.html',       'Group Insurance')
  temp += NavButton(thisid, 'CONTACT',              'ContactUs.html',            'Contact Us')
  temp += '</ul></div>'
  temp += '</td><td width=20>&nbsp;</td><td align=left valign=top>'
//temp += '<hr>'
  document.write(temp)
//----- show the page's title (if provided)
  if ( pagetitle == undefined ) pagetitle = ""
  if ( pagetitle != '') {
    temp = '<h2>' + pagetitle + '</h2>'
    document.write(temp)
    }

  return
  }


//-------------------------------------------------------------------
// PageBottom: Create bottom-of-page HTML text
//    PageBottom( pageid [, HITBOX | NOHITBOX ] )
//      pageid - Identifier assigned to this page.
//               Sets the appropriate navigation button.
//      HITBOX | NOHITBOX
//               Should the "hitbox" be generated for tracking hits?
//               If omitted, NOHITBOX is assumed.
//-------------------------------------------------------------------
function PageBottom(pageid,hitbox) {

  if ( hitbox == null ) hitbox = ''
  hitbox  = hitbox.toUpperCase()
  _hitbox = ( hitbox == 'HITBOX' )

  temp  = ''
  // Copyright & credits area
  temp += '<hr><table width="100%"><tr>' +
          '<td align=left valign=top><font size="1">' +
          'Copyright &copy; 2007 United Members Insurance, Inc.' +
          '<br>Web site by <a href="http://www.CandGWeb.com/" target="_new">' +
          'C&amp;G Web Enterprises</a></font></td>'
  // page counter "hitbox" area
  temp += '<td align=center>'
  if ( _hitbox )
         { temp += '<a href="http://www.easycounter.com/" target="_new"><img ' +
                   'src="http://www.easycounter.com/counter.php?pamperyourselfbyjudy" ' +
                   'border="0" alt="Free Web Counter" ></a>'
           }
    else { temp += '&nbsp;' }
  temp += '</td>'
  // Date & feedback area
  temp += '<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@UnitedMembersInsurance.com?subject=' +
          'UnitedMembersInsurance%20Website%20Feedback,%20' +
          'PageId=' + pageid + '/URL=' + self.location.href + '">' +
          'Contact us!</a></font></td>'
  temp += '</tr></table></font>'
//temp += ETextFont()               // Circumvent Netscape bug
  temp += '</center></div>'
  document.write(temp)
  return
  }



//-------------------------------------------------------------------
// NavButton: Generate HTML for a major section in the nav bar
// Use: NavButton(callerid,thisitem,thisurl,navtitle)
//   callerid  - Section ID of requester
//   thisitem  - Section ID associated with the following items
//   thisurl   - URL of target file
//   navtitle  - description for the "bubble" text
//-------------------------------------------------------------------
function NavButton(callerid,thisitem,thisurl,navtitle) {
  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 = '<li class="youarehere">' }
    else { result = '<li>' }
  result += '<a href="' + thisurl + '">' + navtitle + '</a></li>'
  return result
  }


// Return a start/end text font tag with desired face
function STextFont() { return '<FONT FACE="Verdana,Arial,Helvetica">' }
function ETextFont() { return '</FONT>' }


//-------------------------------------------------------------------
// NodeLink: Generate HTML for a node "under" a major section
// Use: NodeLink(callerid,thisitem,thisurl,thisdesc)
//   callerid  - Node ID of requester
//   thisitem  - Node ID associated with the following items
//   thisurl   - URL of target file
//   thisdesc  - text for the link description
//-------------------------------------------------------------------
function NodeLink(callerid,thisitem,thisurl,thisdesc) {
  if ( callerid == thisitem )
         linkclass = 'nodehere'
    else linkclass = 'nodenothere'
  if ( thisurl.substr(thisurl,11) == "javascript:")
         { temp = thisurl }
    else { temp = top.baseURL + '/' + thisurl }
  return '<tr valign=top><td><img src="' + top.ImagePath        +
         'rightred2.gif" align=bottom width=7 height=14></td>'  +
         '<td><a href="' + temp + '">'                          +
         '<span class=' + linkclass + '>' + thisdesc + '</span></a></td></tr>'
  }

//-------------------------------------------------------------------
// PrevPage: Show a "return to previous page" link
//    PrevPage( [text-for-return-link] )
//-------------------------------------------------------------------
function PrevPage(prevtitle) {
	if (prevtitle == undefined) prevtitle = ''
	if (prevtitle == '')        prevtitle = 'Return to calling page'
  document.writeln('<a href="javascript:history.back();">' +
                   '<img src="' + top.ImagePath +
                   'callpage.gif" ' +
                   'border=0 align=middle>' + prevtitle + '</a>')
  }


//-------------------------------------------------------------------
// 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
    }


function loremipsum() {
  // Lorem Ipsum Generator
  // Version 2.0
  // Copyright 2003 - 2005 Marcus Campbell
  // Open-source code under the GNU GPL:
  // http://www.gnu.org/licenses/gpl.txt

  this.source = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";

  this.getLetters = function getLetters(value) {
          var output = new String();
          if (isNaN(value))
                  value = this.source.length;
          var tempSource = this.growSource(value / this.source.length + 1);
          for (var i = 0; i < value; i++)
                  output += tempSource.charAt(i);
          return output;
  }

  this.getWords = function getWords(value) {
          var output = new String();
          var pattern = /[\w\!\.\?\;\,\:]+/g;
          var matches = this.source.match(pattern);
          if (isNaN(value))
                  value = matches.length;
          var tempSource = this.growSource(value / matches.length);
          var tempMatches = tempSource.match(pattern);
          for (var i = 0; i < value; i++) {
                  if (i > 0)
                          output += " ";
                  output += tempMatches[i];
          }
          return output;
  }

  this.growSource = function growSource(value) {
          var output = new String();
          for (var i = 0; i < value; i++) {
                  if (i > 0)
                          output += " ";
                  output += this.source;
          }
          return output;
  }
}
var lipsum = new loremipsum();
