 /*
 *  name: global.js
 *  description: JS function list for BrightMove
 *  author: bstripling
 *  date: 05/03/2007
 *
 *------------------------------------------------------------*/

/**********************************************************************************************
  better way to load JS functions than window.onload
**********************************************************************************************/

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  }
  else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

/**********************************************************************************************
  unobtrusive popups
**********************************************************************************************/

function preparePopupLinks() {
  // live chat
  var livechat_width=400;
  var livechat_height=400;

  windowLeft = (screen.width-livechat_width)/2;
  windowTop = (screen.height-(livechat_height+210))/2; 

  var popupLinkConfig = new Array;
  // popupLinkConfig["classname"] = new Array ( "targetname", "width=550,height=350,scrollbars=yes,resizable=yes,status=yes,toolbar=yes,location=yes,menubar=yes");
  popupLinkConfig["popup"] = new Array ( "popup", "scrollbars=yes,resizable=yes,status=yes,toolbar=yes,location=yes,menubar=yes");
  popupLinkConfig["popup_live_chat"] = new Array ( "LiveChat", "width=" + livechat_width + ",height=" + livechat_height + ",left=" + windowLeft + ",top=" + windowTop + ",menubar=no,status=no,statusbar=no,scrollbars=no,toolbar=no,location=no,resizable");
  
  if (!document.getElementsByTagName) return true;
  var pageLinks = document.getElementsByTagName("a");
  for (var i = 0; i < pageLinks.length; i++) 
  {
    if (((pageLinks[i].className != null) && 
         (pageLinks[i].className != "")) ||
        ((pageLinks[i].parentNode.className != null) && 
         (pageLinks[i].parentNode.className != "")))
    {
      var linkClass = " " + pageLinks[i].className + " ";
      if ((linkClass == "  ") && (pageLinks[i].parentNode.className != ""))
      {
        linkClass = " " + pageLinks[i].parentNode.className + " ";
      }
      for (var theKey in popupLinkConfig) 
      {
        if (linkClass.indexOf(" " + theKey + " ") > -1)
        {
          if ((pageLinks[i].target == "") || (pageLinks[i].target == null))
          {
            pageLinks[i].target = (popupLinkConfig[theKey][0] != "") ? popupLinkConfig[theKey][0] : theKey;
          }
          pageLinks[i].settings = popupLinkConfig[theKey][1];
          pageLinks[i].onclick = popUp;
        }
      }
    }
  }
  return true;
}

function popUp()
{
  newWin = window.open(this.href, this.target, this.settings);
  newWin.focus();
  return false;
}

addLoadEvent(preparePopupLinks);


/**********************************************************************************************
  show one section at a time - features detail list
**********************************************************************************************/

function showSection(id) {
  var tables = document.getElementsByTagName("table");
  for (var i=0; i<tables.length; i++ ) {
    if (tables[i].className.indexOf("features_detail") == -1) continue;
    if (tables[i].getAttribute("id") != id) {
      tables[i].style.display = "none";
    } else {
      tables[i].style.display = "block";
    }
  }
}

function prepareSubnav() {
  if (!document.getElementsByTagName) return false;
  if (!document.getElementById) return false;
  if (!document.getElementById("subnav")) return false;
  var nav = document.getElementById("subnav");
  var links = nav.getElementsByTagName("a");
  for (var i=0; i<links.length; i++ ) {
    var sectionId = links[i].getAttribute("href").split("#")[1];
    if (!document.getElementById(sectionId)) continue;
    document.getElementById(sectionId).style.display = "none";
    links[i].destination = sectionId;
    links[i].onclick = function() {
      showSection(this.destination);
      return false;
    }
  }
}

addLoadEvent(prepareSubnav);


/**********************************************************************************************
  ajax include
**********************************************************************************************/

//To include a page, invoke ajaxinclude("afile.htm") in the BODY of page
//Included file MUST be from the same domain as the page displaying it.
/*
var rootdomain="http://"+window.location.hostname

function ajaxinclude(url) {
  var page_request = false
  if (window.XMLHttpRequest) // if Mozilla, Safari etc
    page_request = new XMLHttpRequest()
  else if (window.ActiveXObject){ // if IE
    try {
      page_request = new ActiveXObject("Msxml2.XMLHTTP")
    } 
    catch (e){
      try {
        page_request = new ActiveXObject("Microsoft.XMLHTTP")
      }
      catch (e){}
    }
  }
  else
    return false
  page_request.open('GET', url, false) //get page synchronously
  page_request.setRequestHeader('If-Modified-Since', 'Sat, 1 Jan 2000 00:00:00 GMT')
  page_request.send(null)
  writecontent(page_request)
}

function writecontent(page_request) {
  if (window.location.href.indexOf("http")==-1 || page_request.status==200)
  document.write(page_request.responseText)
}
*/

/**********************************************************************************************
  login form add focus
**********************************************************************************************/

function addLoginFocus() {
  document.getElementById("username").focus();
}

addLoadEvent(function() {
  if(document.getElementById("login")) {
    addLoginFocus();
  }
});
