﻿function homepage() {
  this.topArea = null
  this.pageIH = []
  this.msgPnl = null
  this.clndr = null
  this.clhelp = null
  this.clsizes = null
  this.menuitems = { i: 'Information', d: 'Northwind Demo', m: 'Market Place Demo', 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) {
      app.msgbox('Date selected: ' + FMT.format(d, FMT.toObject('FullDate', enums.dataType.date)), document.getElementById('calbut'), { img: { src: enums.images.info} })
      setTimeout(function() { app.hideMsgBox() }, 3000);
    }
    _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.setupHomePage = function(rundemo) {
  AddActivity("Button Click", "View As BABE Application");
  home.create(rundemo)
}
homepage.prototype.init = function() {
  function closeCaptions() {
    window.onscroll = null
    var ids = ['migjet', 'cvqueries', 'cvforms', 'cvrpts', 'cvext', 'brbr', 'gui1', 'bsa', 'ss', 'intfc', 'maint', 'ca']
    var xids = ['combobox', 'inputmask', 'tabctl', 'calendar', 'linkedurl', 'windows', 'forms', 'menus', 'contentmgr', 'calhelp']
    try {
      for (ix = 0; ix < ids.length; ix++) {
        document.getElementById(ids[ix]).style.display = 'none'
      }
      for (ix = 0; ix < ids.length; ix++) {
        document.getElementById(xids[ix]).style.display = 'none'
      }
    } catch (e) { }
  }
  function xcontent(content) {
    var sids = content ? content : ['Overview', 'Services', 'Technology', 'ContactUs', 'Company']
    for (var i = 0; i < sids.length; i++) {
      var node = document.getElementById(sids[i])
      if (node) {
        var els = node.getElementsByTagName('*')
        for (var e = 0; e < els.length; e++) {
          switch (els[e].nodeName.toLowerCase()) {
            case 'p':
            case 'span':
            case 'li':
              app.xlatLang.xlatElement(els[e].innerHTML, els[e])
              break
            case 'input':
              if (els[e].type == 'button')
                app.xlatLang.xlatElement(els[e].value, els[e], 'value')
              break
            case 'div2':
              if (els[e].getElementsByTagName('*').length)
                app.xlatLang.xlatElement(els[e].innerHTML, els[e], null, toEng ? 'en' : null)
              break
          }
        }
      }
    }
  }
  window.onscroll = closeCaptions
  if (app.bi.lang !== 'en') {
    var x2eel = document.getElementById('x2e')
    xcontent(['x2e'])
    if (x2eel) x2eel.style.display = ''
  }
}
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')
}
homepage.prototype.create =
function(rundemo) {
  this.createMenu = function() {
    var hm = null
    function openGI() { app.openForm('GeneralInformation') }
    function link2gui() { window.location.href = 'WebGUI_DesignGuide.aspx' }
    function link2marketpl() { window.location.href = 'SellerManager.aspx' }
    function getSizedImage(src, w, h) {
      var img = document.createElement('img');
      img.src = src;
      img.width = w;
      img.height = h;
      return img
    }
    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, getSizedImage('images/info1.gif', 48, 48), openGI);
    hm.items.add('demo0', this.menuitems.m, getSizedImage('images/market1.jpg', 48, 48), link2marketpl);
    hm.items.add('demo1', this.menuitems.d, getSizedImage('images/Lighthouse.jpg', 48, 48), beginDemo);
    hm.items.add('gui', this.menuitems.g, getSizedImage('images/bookred.gif', 48, 48), 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)
    if (elem = document.getElementById('ContactAdv')) elem.parentNode.removeChild(elem);
    var pages = ['Overview', 'Technology', 'Services', 'ContactUs', 'Company']
    for (ip = 0; ip < pages.length; ip++) {
      te = document.getElementById(pages[ip])
      if (te) {
        home.pageIH[ip] = te.innerHTML
        te.parentNode.removeChild(te)
      }
    }
    var miscElems = ['secInfo', 'hdrTech', 'secTech', 'hdrServices', 'secServices', 'hdrContact', 'secContact', 'hdrCompany', 'secCompany', 'ad_overview', 'adverts1', 'adverts2']
    for (me = 0; me < miscElems.length; me++) {
      te = document.getElementById(miscElems[me])
      if (te) te.parentNode.removeChild(te)
    }
  }
  function openHomepage() {
    _this.menu.show()
    //    showChrome()
    app.openForm('GeneralInformation.xml')
    if (rundemo) beginDemo();
  }
  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(openHomepage, 200)
      document.documentElement.scrollTop = 0;
      document.documentElement.scrollLeft = 0;
    } else this.showBrowserChoices(document.getElementById('viewBABE'))
  } catch (e) {
    alert(e.formatError())
  }
}
