// overlib config
document.write('<script type="text/javascript" src="/javascript/overlib.js"></script>')
if (document.all) {
  document.write('<script type="text/javascript" src="/javascript/overlib-shadow.js"></script>')
}

var requiredMissing = false
function checkRequired(oForm)
{
  requiredMissing = false
  return requiredCompleted(oForm, 0)
}

function requiredCompleted(currentElement, depth)
{
  // recursively look through DOM for <label class="required"> and then check next <input> field after <label> to see if value == ''
  // if value == '' break out of recursion and return false
  if (currentElement) {
    if (currentElement.nodeType == 1 && currentElement.nodeName.toLowerCase() == 'label') {
      if (currentElement.className.indexOf('required') != -1 || currentElement.childNodes[0].nodeValue.toLowerCase().indexOf('email') != -1) {
        if (currentElement.className.indexOf('required') != -1) {
          var emptyNotAllowed = true
        } else {
          var emptyNotAllowed = false
        }
        adjacentElement = currentElement.nextSibling
        while (adjacentElement) {
          if (adjacentElement.nodeType == 1) {
            // check <input type=text> and <textarea>
            if ((adjacentElement.nodeName.toLowerCase() == 'input' && adjacentElement.type == 'text') || adjacentElement.nodeName.toLowerCase() == 'textarea') {
              if (emptyNotAllowed && adjacentElement.value == '') {
                // replace _ with space
                fieldName = adjacentElement.name.replace(/_/g, ' ')
                // make initial capitals
                fieldName = fieldName.replace(/\b[a-z]/g, function (fullPattern) { return fullPattern.toUpperCase() })
                alert('Please enter a value for ' + fieldName)
                adjacentElement.focus()
                requiredMissing = true
              // check email addresses
              } else if (adjacentElement.name.indexOf('email') != -1 && !isEmailValid(adjacentElement)) {
                alert('Please enter a valid email address')
                adjacentElement.focus()
                requiredMissing = true
              } else {
                // speed up recursion by returning at this point because value != '' and no need to check further siblings
                return true
              }
            // check <select>
            } else if (adjacentElement.nodeName.toLowerCase() == 'select') {
              if (adjacentElement.options[adjacentElement.selectedIndex].value == '') {
                // replace _ with space
                fieldName = adjacentElement.name.replace(/_/g, ' ')
                // make initial capitals
                fieldName = fieldName.replace(/\b[a-z]/g, function (fullPattern) { return fullPattern.toUpperCase() })
                alert('Please select a value for ' + fieldName)
                adjacentElement.focus()
                requiredMissing = true
              } else {
                return true
              }
            }
          }
          adjacentElement = adjacentElement.nextSibling
        }
      }
    }
    // Traverse the tree
    var i = 0
    var currentElementChild = currentElement.childNodes[i]
    while (currentElementChild) {
      // Recursively traverse the tree structure of the child node
      if (requiredMissing) {
        return false
      }
      requiredCompleted(currentElementChild, depth + 1)
      i++
      currentElementChild = currentElement.childNodes[i]
    }
    return true
  }
}

function isEmailValid(oEmail)
{
  str = oEmail.value
  r1 = new RegExp('(@.*@)|(\\.\\.)|(@\\.)|(^\\.)')
  r2 = new RegExp('^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$')
  return (!r1.test(str) && r2.test(str))
}

function externalLinks()
{
  if (!document.getElementsByTagName) {
    return
  }
  var anchor
  var anchors = document.getElementsByTagName('a')
  for (var i = 0; i < anchors.length; i++) {
    anchor = anchors[i]
    if (anchor.getAttribute('href') && anchor.getAttribute('rel') == 'external') {
      anchor.target = '_blank'
    }
  }
}

function checkLogin(oForm)
{
  with (oForm) {
    if (username.value == '' || !isEmailValid(username)) {
      alert('Please enter a valid username')
      username.focus()
      return false
    }
    if (password.value == '' || password.value.length < 5) {
      alert('Please enter a valid password')
      username.focus()
      return false
    }
  }
  return true
}

menuOver = function() {
  if (!document.getElementById('menu')) {
    return false
  }
  elems = document.getElementById('menu').getElementsByTagName('LI')
  for (i = 0; i < elems.length; i++) {
    elems[i].onmouseover = function() {
      this.className = ' over'
    }
    elems[i].onmouseout = function() {
      this.className = this.className.replace(new RegExp(' over\\b'), '')
    }
  }
}
if (window.attachEvent) {
  window.attachEvent('onload', menuOver)
}

function findPos(obj)
{
  var curtop = 0, curleft = 0, obj
  if (obj.offsetParent) {
    while (obj.offsetParent) {
      curtop += obj.offsetTop
      curleft += obj.offsetLeft
      obj = obj.offsetParent
    }
  } else if (obj.y) {
    curtop += obj.y
    curleft += obj.x
  }
  return new Array(curleft, curtop)
}

var now
var clockInterval = 30000
var clockGraphicsURL = 'http://' + window.location.host + '/images/clock/'

function clock()
{
  if (document.getElementById('local-time') && document.getElementById('local-time').firstChild.nodeValue != '' && typeof(now) == 'undefined') {
    now = new Date(document.getElementById('local-time').firstChild.nodeValue)
    now = now.getTime()
  } else if (typeof(now) == 'undefined') {
    now = new Date()
    now = now.getTime()
  }
  now += clockInterval
  var timeNow = new Date()
  var hours = timeNow.getHours()
  var mins = timeNow.getMinutes()
  timeNow.setTime(now)
  if (document.getElementById('panel-clock')) {
    document.getElementById('panel-clock').innerHTML = hours + ':' + (mins < 10 ? '0' : '') + mins
  } else if (document.getElementById('clock')) {
    var oImgs = document.getElementById('clock').getElementsByTagName('img')
    if (hours < 10) {
      oImgs[0].src = clockGraphicsURL + '0.gif'
      oImgs[1].src = clockGraphicsURL + + hours.toString() + '.gif'
    } else {
      oImgs[0].src = clockGraphicsURL + hours.toString().substr(0, 1) + '.gif'
      oImgs[1].src = clockGraphicsURL + hours.toString().substr(1, 1) + '.gif'
    }
    if (mins < 10) {
      oImgs[3].src = clockGraphicsURL + '0.gif'
      oImgs[4].src = clockGraphicsURL + mins + '.gif'
    } else {
      oImgs[3].src = clockGraphicsURL + mins.toString().substr(0, 1) + '.gif'
      oImgs[4].src = clockGraphicsURL + mins.toString().substr(1, 1) + '.gif'
    }
  }
}

function multipleOnload()
{
  playerOverlib = overlib
  if (typeof(iframeFix) != 'undefined') {
    iframeFix()
  }
  externalLinks()
  if (typeof(myTeamMouseovers) != 'undefined') {
    myTeamMouseovers()
  }
  if (document.getElementById('clock')) {
    setInterval('clock()', clockInterval)
  }
  // call site specific onloads
  if (typeof(aOnloadFunctions) != 'undefined') {
    for (i = 0; i < aOnloadFunctions.length; i++) {
      eval(aOnloadFunctions[i])
    }
  }
}

function viewDreamteam(oSelect)
{
  url = '/'
  aUrl = window.location.pathname.split('/')
  for (var i = 0; i < aUrl.length; i++) {
    if (aUrl[i] != '') {
      url += aUrl[i] + '/'
    }
    if (i == 3) {
      break
    }
  }
  window.location = url + oSelect.options[oSelect.selectedIndex].value
}

onload = multipleOnload