﻿function homepage() {
  this.topArea = null
  this.pageIH = []
  this.msgPnl = null
  this.clndr = null
  this.clhelp = null
  this.clsizes = null
  this.menuitems = { i: 'Information', d: 'Demonstration', g: 'Web-GUI Guide', c: 'Company' }
  app.xlatLang.xlatConsts(this.menuitems)
}
homepage.prototype.babeView =
function() {
  return this.pageIH.length
}
homepage.prototype.showBrowserChoices =
function(anchorElem) {
  this.getMsgPanel = function() {
    this.msgPnl = document.createElement('div')
    this.msgPnl.style.cssText = 'position:relative;overflow:hidden;padding-bottom:10px;width:50%;margin-left:25%; text-align:center; height:auto;border:outset gold; font-family: Verdana;background-color:AliceBlue; border-top-width:2px;'
    title = document.createElement('div')
    title.style.cssText = 'text-align:center; font-weight:bold; background-color:red; margin-bottom:10px; color: white; font-size:medium'
    title.innerHTML = "Unsupported Browser"
    this.msgPnl.appendChild(title)
    var msg = document.createElement('span')
    msg.style.cssText = 'display:block; text-align:left; margin:5px;'
    msg.innerHTML = "This browser is not capable of viewing this site's advanced features."
    this.msgPnl.appendChild(msg)
  }
  this.showBrowserDownload = function(titleTxt, href, linkTxt) {
    this.getMsgPanel()
    var pb = document.createElement('div')
    pb.style.cssText = 'width:100%; margin-bottom:10px; margin-top:5px;'
    pb.innerHTML = titleTxt
    this.msgPnl.appendChild(pb)
    lnk = document.createElement('a')
    lnk.href = href
    lnk.innerHTML = linkTxt
    this.msgPnl.appendChild(lnk)
    anchorElem.parentNode.replaceChild(this.msgPnl, anchorElem)
  }
  this.showWindowsPreferredBrowsers = function() {
    this.getMsgPanel()
    var pb = document.createElement('div')
    pb.style.cssText = 'width:100%; margin-bottom:10px; margin-top:15px; font-weight:bold;'
    pb.innerHTML = "Preferred Window's Browsers:"
    this.msgPnl.appendChild(pb)
    lnk = document.createElement('a')
    lnk.href = 'http://www.google.com/chrome/index.html'
    lnk.style.cssText = "display:block; margin-bottom: 5px;"
    lnk.innerHTML = 'Download Google Chrome'
    this.msgPnl.appendChild(lnk)
    lnk = document.createElement('a')
    lnk.style.cssText = "display:block; margin-bottom: 5px;"
    lnk.href = 'http://www.apple.com/safari/download/'
    lnk.innerHTML = 'Download Apple Safari 4'
    this.msgPnl.appendChild(lnk)
    lnk = document.createElement('a')
    lnk.style.cssText = "display:block; margin-bottom: 5px;"
    lnk.href = 'http://www.microsoft.com/windows/internet-explorer/default.aspx'
    lnk.innerHTML = 'Download Microsoft IE 8'
    this.msgPnl.appendChild(lnk)
    anchorElem.parentNode.replaceChild(this.msgPnl, anchorElem)
  }
  if (this.msgPnl) return anchorElem.parentNode.replaceChild(this.msgPnl, anchorElem)
  if (app.bi.os === enums.browser.os.win && !app.bi.isCompatible) {
    return this.showWindowsPreferredBrowsers()
  }
  if (app.bi.os === enums.browser.os.mac) {
    if (!(app.bi.browser === enums.browser.app.Safari && app.bi.version >= 4)) {
      return this.showBrowserDownload('This site requires Safari 4 (KHTML Version/4) on the Mac.', 'http://www.apple.com/safari/download/', 'Download Safari 4')
    }
  }
  if (app.bi.os !== enums.browser.os.win && app.bi.os !== enums.browser.os.mac) {
    if (!(app.bi.browser === enums.browser.app.IE && app.bi.version >= 7 || app.bi.browser === enums.browser.app.FireFox)) {
      return this.showBrowserDownload('This site requires Firefox or IE.', 'http://www.firefoxdownload.com/', 'Download Firefox')
    }
  }
}
homepage.prototype.showCalendar = function() {
  var _this = this
  function showDate(d) {
    if (d) {
      setTimeout(function() { app.sc.msgbox.style.display = 'none' }, 5000)
      app.msgbox('Date selected: ' + FMT.format(d, FMT.toObject('FullDate', enums.dataType.date)), document.getElementById('calbut'))
    }
    _this.clndr.dispose()
    if (_this.clhelp) _this.clhelp.style.display = 'none'
    _this.clndr = null
  }
  if (this.clndr) this.clndr.dispose()
  this.clndr = CAL.createCalendar()
  this.clndr.dayFontSize = 'small'
  this.clndr.monthFontSize = 'small'
  _this.clsizes = document.getElementById('calsizes')
  if (_this.clsizes) {
    this.clndr.dayFontSize = _this.clsizes.value
    this.clndr.monthFontSize = _this.clsizes.value
    if (_this.clsizes.value.indexOf('large') !== -1) this.clndr.background = 'url(images/cal3.jpg) no-repeat center white'
    switch (this.clndr.dayFontSize) {
      case 'medium':
        this.clndr.textColor = 'white'
        this.clndr.background = 'url(images/cal2.jpg) repeat center white'
        break
      case 'large':
      case 'x-large':
      case 'xx-large':
        this.clndr.background = 'url(images/cal3.jpg) no-repeat center white'
    }
  }
  this.clndr.build()
  this.clndr.callback = showDate
  var scr = BC.getAvailScreenHW()
  BC.centerNode(this.clndr.node)
  this.clndr.show()
  if (ci = document.getElementById('calendar')) ci.style.display = 'none'
  _this.clhelp = document.getElementById('calhelp')
  if (_this.clhelp) {
    _this.clhelp.style.display = 'block'
    if (home.babeView()) { _this.clhelp.style.width = 'auto' }
    else {
      var offsets = BC.getOffsets(_this.clhelp)
      if ((clwid = this.clndr.node.offsetLeft - offsets.x - 12) > 0)
        _this.clhelp.style.width = clwid + 'px'
    }
  }
}
homepage.prototype.create =
function() {
  this.createMenu = function() {
    function beginDemo() {
      BC.maximizeScreen()
      if (app.forms['Main Switchboard']) return
      if (app.forms['GeneralInformation']) app.forms['GeneralInformation'].window().minimize()
      if (app.forms['To best view this site...']) app.forms['To best view this site...'].window().minimize()
      if (app.forms['Login']) app.closeForm(app.forms['Login'])
      //      if (app.forms['Login']) app.closeForm(app.forms['Login'].mainForm)
      app.openForm('Login.xml')
    }
    var hm = null
    function openGI() { app.openForm('GeneralInformation') }
    function link2gui() { window.location.href = 'WebGUI_DesignGuide.aspx' }
    hm = MNU.createMenu()
    hm.imagesPanelBackground = 'background-color:white;'
    hm.build()
    hm.items.node.style.fontFamily = 'Verdana'
    hm.items.node.style.fontWeight = 'bold'
    hm.items.node.style.textAlign = 'center'
    hm.items.add('gi', this.menuitems.i, 'images/info1.gif', openGI)
    hm.items.add('demo', this.menuitems.d, 'images/target1.gif', beginDemo)
    hm.items.add('gui', this.menuitems.g, 'images/bookred.gif', link2gui)
    return hm
  }
  function showChrome() {
    var win = null
    function whenDone() { return }
    function acceptableBrowser() {
      return app.bi.browser === enums.browser.app.Chrome
          || app.bi.browser === enums.browser.app.Safari && app.bi.version >= 4
          || app.bi.browser === enums.browser.app.IE && app.bi.version >= 8
    }
    if (app.bi.os === enums.browser.os.win) {
      if (!acceptableBrowser()) {
        win = app.openFormEx('To best view this site...', 'http://www.google.com/chrome/index.html')
        win.fp.sizable = false
        win.fp.resizeWindow(780, 180)
        win.fp.moveWindowTo(0, BC.getAvailScreenHW().h - win.fp.rootNode.offsetHeight)
        if (app.bi.browser === enums.browser.app.Opera) {
          win.fp.rootNode.style.zIndex = 5
          win.maximize()
        } //else bhdemo.pause(1, whenDone)
      }
    }
  }

  function setupContent() {
    if (app.xlatLang.gbElement) {
      app.xlatLang.gbElement.style.top = 'auto'
      app.xlatLang.gbElement.style.bottom = 0
    }
    for (fn in app.forms) app.forms[fn].window().close()
    if (home.clndr) {
      home.clndr.dispose()
      home.clndr  = null
    }
    if (home.clhelp) home.clhelp.style.display = 'none'
    var te = document.getElementById('viewBABE')
    if (te) te.parentNode.removeChild(te)
    var x2eel = document.getElementById('x2e')
    if (x2eel) x2eel.parentNode.removeChild(x2eel) 

    var pages = ['Overview', 'Technology', 'Services', 'ContactUs', 'Company']
    for (ip = 0; ip < pages.length; ip++) {
      te = document.getElementById(pages[ip])
      home.pageIH[ip] = te.innerHTML
      te.parentNode.removeChild(te)
    }
    var miscElems = ['secInfo', 'hdrTech', 'secTech', 'hdrServices', 'secServices', 'hdrContact', 'secContact', 'hdrCompany', 'secCompany']
    for (me = 0; me < miscElems.length; me++) {
      te = document.getElementById(miscElems[me])
      te.parentNode.removeChild(te)
    }
  }
  function setupHomepage() {
    _this.menu.show()
    //    showChrome()
    app.openForm('GeneralInformation.xml')
  }
  try {
    if (app.bi.isCompatible) {
      app.hideSystemForms()
      setupContent()
      this.menu = this.createMenu()
      this.menu.setPosition('96px', '2px')
      this.menu.hideOnClick = false
      this.menu.node.style.zIndex = 1
      var _this = this
      setTimeout(setupHomepage, 500)
    } else this.showBrowserChoices(document.getElementById('viewBABE'))
  } catch (e) {
    alert(e.formatError())
  }
}
