//-------------------------------------------------------
// Xdk JavaScipt support routines
// (c) 2001-2005 RepubliCorp P/L
// Version 1.3
// Author: John Bradnam
//-------------------------------------------------------

//----------------------------------------------
//Timeouts and retries
//----------------------------------------------

var WAIT_FOR_PAGE_LOAD_TIME  = 2000;  //Time in mS after requesting page before page loading is checked
var CHECK_FOR_PAGE_LOAD_TIME = 1000;  //Time period in mS before retesting if page is loaded
var CHECK_FOR_PAGE_RETRIES   = 5;     //Number of times to test if page loaded before timing out
var CHECK_FOR_PAGE_MESSAGE   = false; //true or false whether message window is displayed if timed out
var CHECK_FOR_TOC_PAGE_TIME  = 250;   //Time in mS before retesting if TOC has been loaded

//----------------------------------------------
//Generic popup functions
//----------------------------------------------

var m_sErrLinksToObjects = 'Hyperlinks to objects do not work in popups.'

var m_PopupDiv = null;
var m_PopupShadowDiv = null;
var m_PopupTopicDiv = null;
var m_PopupDivStyle = null;
var m_PopupIFrame = null;
var m_PopupIFrameStyle = null;
var m_wPopupClickX  = 0;
var m_wPopupClickY  = 0;
var m_wPopupScrollX = 0;
var m_wPopupScrollY = 0;
var m_wPopupClientX = 0;
var m_wPopupClientY = 0;
var m_wPopupMenuX   = 0;
var m_wPopupMenuY   = 0;
var m_fPopupTimeoutExpired = false;
var sUsrAgent = navigator.userAgent.toLowerCase();
var wLoc = sUsrAgent.indexOf("opera");
var fMS  = (navigator.appName.indexOf("Microsoft") != -1);
var fIE  = ((fMS) && (wLoc == -1));
var fIE4 = ((fIE) && (parseInt(navigator.appVersion) >= 4));
var fIE6 = ((fIE) && (sUsrAgent.indexOf("msie 6.0") != -1));
var fNS7 = ((sUsrAgent.indexOf("gecko") != -1) && (navigator.productSub > 20020820));
var fOPR = ((fMS) && ((wLoc == -1) || (sUsrAgent.substr(wLoc + 6,1).valueOf() >= 7)));
var dRetryCount = CHECK_FOR_PAGE_RETRIES;

/*
alert("navigator.userAgent = '"+navigator.userAgent+"'"+
      "\r\nnavigator.appCodeName = '"+navigator.appCodeName+"'"+
      "\r\nnavigator.appName = '"+navigator.appName+"'"+
      "\r\nnavigator.appVersion = '"+navigator.appVersion+"'"+
      "\r\nnavigator.productSub = "+navigator.productSub);
*/

function XdkOnMouseOver(event)
{
  var oBody               = document.body;
  window.m_wPopupMenuX    = event.clientX;
  window.m_wPopupMenuY    = event.clientY;
  window.m_wPopupScrollX  = oBody.scrollLeft;
  window.m_wPopupScrollY  = oBody.scrollTop;
  window.m_wPopupClientX  = oBody.clientWidth;
  window.m_wPopupClientY  = oBody.clientHeight;
  if (!fIE) {
    window.m_wPopupClickX = event.clientX;
    window.m_wPopupClickY = event.clientY;
  }
  else {
    var oBanner = oBody.firstChild;
    var wHeight = 0;
    if (oBanner.id == "XdkBanner") {
      wHeight                = oBanner.offsetHeight;
      window.m_wPopupScrollX = oBanner.nextSibling.scrollLeft;
      window.m_wPopupScrollY = oBanner.nextSibling.scrollTop;
      window.m_wPopupClientX = oBanner.nextSibling.clientWidth;
      window.m_wPopupClientY = oBanner.nextSibling.clientHeight;
    }
    //Record mouse position over link for popup positioning
    window.m_wPopupClickX  = event.clientX + window.m_wPopupScrollX;
    window.m_wPopupClickY  = event.clientY + window.m_wPopupScrollY - wHeight;
  }
} //XdkOnMouseOver

function XdkPopup(sUrl)
{
  //Only work on IE4 and higher for Windows
  if ((fIE4) && (navigator.userAgent.toLowerCase().indexOf("mac") == -1)) {
    if (m_PopupDiv == null) {
      var oTag = document.all.tags("div");
      for (var iDiv = 0; iDiv < oTag.length; iDiv++) {
        if (oTag(iDiv).id == "XdkPopup")
          m_PopupDiv       = oTag(iDiv);
        if (oTag(iDiv).id == "XdkPopupShadow")
          m_PopupShadowDiv = oTag(iDiv);
        if (oTag(iDiv).id == "XdkPopupTopic")
          m_PopupTopicDiv  = oTag(iDiv);
      } //for
      m_PopupIFrame = eval("m_PopupDiv.document.frames['XdkPopupIFrameName']");
      m_PopupDivStyle = eval("m_PopupDiv.style");
      m_PopupIFrameStyle = eval("document.all['XdkPopupIFrameName'].style");
    }
    if (this.name == "XdkPopupIFrameName") {
      //Use existing window
      location.href = sURL;
      parent.window.m_fPopupTimeoutExpired = false;
    }
    else {
      m_PopupIFrame.location.href = sUrl;
      window.m_fPopupTimeoutExpired = false;
    }
    setTimeout("_XdkPopup()",200);
  }
  else {
    var wX = window.m_wPopupClickX;
    var wY = window.m_wPopupClickY;
    if (!fIE) {
      wX = window.screenX + (window.outerWidth - window.innerWidth) + wX;
      if ((wX + 440) > screen.availWidth)
        wX = screen.availWidth - 440;
      wY = window.screenY + (window.outerHeight - window.innerHeight) + wY;
      if ((wY + 340) > screen.availHeight)
        wY = screen.availHeight - 340;
    }
    var sParam = "titlebar=no,toolbar=no,status=no,location=no,menubar=no,resizable=yes,scrollbars=yes,";
    sParam = sParam + "height=300,width=400";
    sParam = sParam + ",screenX=" + wX + ",screenY=" + wY;
    window.open(sUrl,"",sParam);
  }
} //XdkPopup

function _XdkPopup()
{
  if ((window.m_PopupIFrame.document.readyState == "complete") && (window.m_PopupIFrame.document.body != null))
    _XdkResize();
  else
    setTimeout("_XdkPopup()",200);
} //_XdkPopup

function _XdkResize()
{
  window.m_PopupDivStyle.visibility = "hidden";
  var oSize         = new _XdkGetPointObject(0,0);
  _XdkGetPopupSize(window.m_PopupIFrame,oSize);
  window.m_PopupDivStyle.width  = oSize.x;
  window.m_PopupDivStyle.height = oSize.y;
  var oPosition     = new _XdkGetPointObject(0,0);
  _XdkGetPopupPosition(oPosition,oSize);
  window.m_PopupDivStyle.left = oPosition.x;
  window.m_PopupDivStyle.top = oPosition.y;
  window.m_PopupShadowDiv.style.left = 6;
  window.m_PopupShadowDiv.style.top = 6;
  window.m_PopupShadowDiv.style.width = oSize.x;
  window.m_PopupShadowDiv.style.height = oSize.y;
  window.m_PopupTopicDiv.style.width = oSize.x;
  window.m_PopupTopicDiv.style.height = oSize.y;
  window.m_PopupIFrameStyle.width = oSize.x;
  window.m_PopupIFrameStyle.height = oSize.y;
  window.m_PopupDivStyle.visibility = "visible";
  setTimeout("_XdkResizeTimeout();", 100);
  return false;
} //_XdkResize

function _XdkResizeTimeout()
{
  if ((m_PopupIFrame.document.readyState == "complete") && (m_PopupIFrame.document.body != null)) {
    window.m_fPopupTimeoutExpired = true;
    if (m_PopupIFrame.document)
      m_PopupIFrame.document.body.onclick = _XdkPopupClicked;
    document.onmousedown = _XdkPopupParentClicked;
  }
  else
	setTimeout("_XdkResizeTimeout()", 100);
} //_XdkResizeTimeout

function _XdkGetPointObject(x, y)
{
  this.x = x;
  this.y = y;
} //_XdkGetPointObject

function _XdkGetPopupSize(oWindow,oSize)
{
  var wClientWidth  = document.body.clientWidth;
  var wClientHeight = document.body.clientHeight;
  var oBody         = oWindow.document.body;
  var wX            = wClientWidth - 20;
  var wY            = 1;
  oWindow.resizeTo(1,1);
  oWindow.resizeTo(1,1);
  oWindow.resizeTo(wX,oBody.scrollHeight);
  oWindow.resizeTo(wX,oBody.scrollHeight);
  oSize.x           = wX;
  oSize.y           = oBody.scrollHeight;
  var wBottom       = 25;
  var wTop          = oSize.x;
  var wMiddle       = 0;
  while (wX != wMiddle) {
    wMiddle         = wX;
    wX              = (wBottom + wTop) >> 1;
    oWindow.resizeTo(wX,oSize.y);
    oWindow.resizeTo(wX,oSize.y);
    if ((oBody.scrollHeight > oSize.y) || (oBody.scrollWidth > wX))
      wBottom       = wX;
    else
      wTop          = wX;
  } //while
  wX                = wBottom;
  oWindow.resizeTo(wX,wY);
  oWindow.resizeTo(wX,wY);
  oSize.x           = oBody.scrollWidth + 20;
  if (oSize.y < 40)
    oSize.y         = 40;
  oWindow.resizeTo(oSize.x,oSize.y);
  oWindow.resizeTo(oSize.x,oSize.y);
  return;
} //_XdkGetPopupSize

function _XdkGetPopupPosition(oPosition,oSize)
{
  var wClickX    = window.m_wPopupClickX;
  var wClickY    = window.m_wPopupClickY;
  var wMaxWidth  = window.m_wPopupClientX + window.m_wPopupScrollX - 20;
  var wMaxHeight = window.m_wPopupClientY + window.m_wPopupScrollY - 20;
  if (wClickX + oSize.x < wMaxWidth)
    oPosition.x = wClickX;
  else
    oPosition.x = wMaxWidth - oSize.x - 8;
  if (wClickY + oSize.y + 20 < wMaxHeight)
    oPosition.y = wClickY + 10;
  else
    oPosition.y = wMaxHeight - oSize.y - 20;
  if (oPosition.x < 0) oPosition.x = 1;
  if (oPosition.y < 0) oPosition.y = 1;
} //_XdkGetPopupPosition

function _XdkPopupParentClicked()
{
  _XdkPopupClicked();
  return;
} //_XdkPopupParentClicked

function _XdkPopupClicked()
{
  var fResult = false;
  if (window.m_fPopupTimeoutExpired) {
    var oEvent = m_PopupIFrame.window.event;
    if ((oEvent != null) &&
        (oEvent.srcElement != null) &&
        (oEvent.srcElement.tagName == "A") &&
        (oEvent.srcElement.href.indexOf("javascript:") == 0) &&
        (oEvent.srcElement.href.indexOf(".") != -1)) {
      //Call through an object error
      m_PopupIFrame.window.event.cancelBubble = true;
      alert(m_sErrLinksToObjects);
    }
    else {
      if (m_PopupIFrame.document)
        m_PopupIFrame.document.body.onclick = null;
      document.onclick = null;
      document.onmousedown = null;
      m_PopupDivStyle.visibility = "hidden";
      fResult = true;
    }
  }
  return fResult;
} //_XdkPopupClicked

//----------------------------------------------
//Generic tracking functions
//----------------------------------------------

function XdkTrack(sFrameSetUrl,sTocFrameName)
{
  var sUrl = "";
  var wHash = 0;
  var oTop = XdkGetWindowTop();
  var date  = new Date();
  date.setYear(date.getYear() + 1);
  if ((window.top.name != "ga_history") && ((window.frameElement == null) || (window.frameElement.tagName != "IFRAME"))) {
    var sThisUrl = "none";
    if (navigator.cookieEnabled) {
      var aCookie = document.cookie.split("; ");
      for (var i=0; i < aCookie.length; i++) {
        var aCrumb = aCookie[i].split("=");
        if ((aCrumb[0] == "RpoTrack") && (aCrumb[1] != "none")) {
          //Before we access the cookie, check to see if the toc window is present
          try{
            sUrl = window.location.href;
            wHash = sUrl.lastIndexOf('#');
            if (wHash != -1)
              sUrl = sUrl.substr(0,wHash);
            if (oTop.frames[sTocFrameName].fObject == true)
              oTop.frames[sTocFrameName].document.toc.setCurrent(sUrl);
            else
              oTop.frames[sTocFrameName].setCurrent(sUrl);
            //Will only get here if the toc is loaded and running
            sThisUrl = unescape(aCrumb[1]);
            if (sThisUrl != window.location.href) {
              window.status = "Switching to " + sThisUrl;
              setTimeout("_XdkTrackWait('" + sThisUrl + "','" + sTocFrameName + "')",WAIT_FOR_PAGE_LOAD_TIME);
            }
            else
              document.cookie = "RpoTrack=none;path=/;expires=" + date.toGMTString();
          }
          catch(wError) {
            setTimeout("XdkTrack('" + sFrameSetUrl + "','" + sTocFrameName + "')",CHECK_FOR_TOC_PAGE_TIME);
            sThisUrl = "";
          }
          break;
        }
      } //for
    }
    if (sThisUrl == "none") {
      if (oTop.frames[sTocFrameName] != null)
        _XdkTrackWait(location.href,sTocFrameName);
      else {
        if (navigator.cookieEnabled) {
          document.cookie = "RpoTrack=" + escape(location.href) + ";path=/;expires=" + date.toGMTString();
          var aCookie = document.cookie.split("; ");
          var i = 0;
          while ((i < aCookie.length) && (aCookie[i].split("=")[0] != "RpoTrack"))
            i++;
          if (i == aCookie.length)
            alert("Side entry is not supported because cookies are not being saved")
          window.location.replace(sFrameSetUrl);
//        open(sFrameSetUrl,"_top");
        }
      }
    }
  }
} //XdkTrack

function _XdkTrackWait(sPageUrl,sTocFrameName)
{
  var sUrl = "";
  var wHash = 0;
  var oTop = XdkGetWindowTop();
  //Set the href of the frame and when the TOC is ready, sync it
  try {
    var date = new Date();
    date.setYear(date.getYear() - 1);
    if (navigator.cookieEnabled)
      document.cookie = "RpoTrack=none;path=/;expires=" + date.toGMTString();
    sUrl = sPageUrl;
    wHash = sUrl.lastIndexOf('#');
    if (wHash != -1)
      sUrl = sUrl.substr(0,wHash);
    if (oTop.frames[sTocFrameName].fObject == true)
      oTop.frames[sTocFrameName].document.toc.setCurrent(sUrl);
    else
      oTop.frames[sTocFrameName].setCurrent(sUrl);
    //Will only get here if the toc is loaded and running
    if (window.location.href != sPageUrl) {
      window.location.href = sPageUrl;
      throw "error";
    }
    window.status = "Done";
  }
  catch(wError) {
    dRetryCount = dRetryCount - 1;
    if (dRetryCount != 0)
      setTimeout("_XdkTrackWait('" + sPageUrl + "','" + sTocFrameName + "')",CHECK_FOR_PAGE_LOAD_TIME);
    else if (CHECK_FOR_PAGE_MESSAGE == true)
      alert("Can't load page '"+sPageUrl+"'");
  }
} //_XdkTrackWait

function XdkGetWindowTop() {
  var oTop = null;
  try{
	//alert(window.top.frames(0).name);
    if (window.top.frames(0).name == "annotateframe")
      oTop = window.top.frames(2).document;
    else if (window.top.frames(0).name == "moduleframe")
      oTop = window.top.frames(1).document;
    else if (window.top.frames(0).name == "assessmentcontrol") {
	  oTop = window.top;
	  oTop.name = "ga_history";
    } else
      oTop = window.top;
  }
  catch (wError) {
    oTop = window.top;
  }
  return oTop;
} //XdkGetWindowTop

//----------------------------------------------
//Generic show/hide division functions
//----------------------------------------------

function XdkShowHide(sId) {
  if ((!fIE) || (fIE6))
    _XdkShowHideW3C(sId);
  else
    _XdkShowHideALL(sId);
} //XdkShowHide

function _XdkShowHideW3C(sId) {
  var   oDiv = null;
  var   oImg = null;

  oDiv = document.getElementById(sId);
  if ((oDiv != null) && (oDiv.tagName == "IMG")) {
    oImg = oDiv;
    oDiv = oDiv.parentNode.nextSibling;
    while ((oDiv != null) && (oDiv.tagName != "DIV"))
      oDiv = oDiv.nextSibling;
  }
  if (oDiv != null) {
    if ((oDiv.style != null) && (oDiv.style.display == "none")) {
      oDiv.style.display = "";
      if (oImg != null)
        oImg.setAttribute("src",oImg.getAttribute("show"));
    }
    else {
      oDiv.style.display = "none";
      if (oImg != null)
        oImg.setAttribute("src",oImg.getAttribute("hide"));
    }
  }
} //_XdkShowHideW3C

function _XdkShowHideALL(sId) {
  var   oCol = null;
  var   oDiv = null;
  var   oImg = null;
  var   wIndex

  oCol = document.all.item(sId);  //Can return a image and span or division
  oDiv = oCol;
  if (oCol.length != 0) {
    for (wIndex = 0;wIndex < oCol.length;wIndex++) {
      if (oCol(wIndex).tagName == "IMG")
        oImg = oCol(wIndex);
      else
        oDiv = oCol(wIndex);
    }//for
  }
  if (oDiv != null) {
    if ((oDiv.style != null) && (oDiv.style.display == "none")) {
      oDiv.style.display = "";
      if (oImg != null)
        oImg.src = oImg.show;
    }
    else {
      oDiv.style.display = "none";
      if (oImg != null)
        oImg.src = oImg.hide;
    }
  }
} //_XdkShowHideALL

//----------------------------------------------
//Create a popup menu
//----------------------------------------------

var oXdkGblMenu = null;

function XdkPopupMenu(oAnc) {
  if ((!fIE) || (fIE6))
    _XdkPopupMenuW3C(oAnc);
  else
    _XdkPopupMenuALL(oAnc);
} //XdkPopupMenu

function XdkPopupMenuExecute() {
} //XdkPopupMenuExecute

function _XdkPopupMenuW3C(oAnc) {
  var oSty       = null;
  var oMnu       = null;
  var oTbl       = null;
  var oNxt       = null;
  var oSpn       = null;
  var oRow       = null;
  var oCell      = null;
  var oTxt       = null;
  var wTop       = 0;
  var wBottom    = 0;
  var sAdd       = '';
  var oBody      = document.body;
//  var wMouseX    = window.m_wPopupClickX - 10;
//  var wMouseY    = window.m_wPopupClickY - 5;
  var wMouseX    = window.m_wPopupMenuX - 10;
  var wMouseY    = window.m_wPopupMenuY - 5;
  var wMaxWidth  = oBody.clientWidth - wMouseX;
  var wMaxHeight = oBody.clientHeight - wMouseY;
  oMnu                 = document.createElement("div");
  oSty                 = oMnu.style;
  oSty.position        = "absolute";
  oSty.visibility      = "hidden";
  oSty.overflow        = "hidden";
  oSty.backgroundColor = "menu";
  document.body.appendChild(oMnu);
  oTbl                 = document.createElement("table");
  oMnu.appendChild(oTbl);
  //Add the elements
  oTbl.style.cursor    = "default";
  oTbl.style.color     = "menutext";
  oTbl.style.backgroundColor = "menu";
  oTbl.style.border    = "2px outset threedhighlight";
  oTbl.setAttribute("cellPadding","0");
  oTbl.setAttribute("cellSpacing","0");
  if (fIE)
    oTbl.onselectstart = "javascript:return false;"
  else {
    oTbl.setAttribute("onselectstart","JavaScript:return false;");
    oTbl.setAttribute("cellSpacing","2");
    oTbl.style.padding = "1px 10px 1px 10px";
  }
  if ((oAnc.tagName == "IMG") && (oAnc.up == null))
    oAnc               = oAnc.parentElement;
  oSpn                 = oAnc.nextSibling;
  while ((oSpn != null) && (oSpn.tagName == "SPAN") && (oSpn.getAttribute("href") != null)) {
    oNxt      = oSpn.nextSibling;
    wTop      = 1;
    wBottom   = 1;
    if (oSpn == oAnc.nextSibling)
      wTop    = 2;
    if ((oNxt == null) || (oNxt.tagName != "SPAN") || (oNxt.getAttribute("href") == null))
      wBottom = 2;
    oRow      = oTbl.insertRow(-1);
    oRow.style.fontFamily    = "tahoma";
    oRow.style.fontSize      = "8pt";
    oRow.style.color         = "menutext";
    oRow.style.padding       = wTop+"px 10px "+wBottom+"px 10px";
    if (oSpn.getAttribute("href") != null)
      oRow.setAttribute("href",oSpn.getAttribute("href"));
    if (oSpn.getAttribute("target") != null)
      oRow.setAttribute("target",oSpn.getAttribute("target"));
    oCell                    = oRow.insertCell(-1);
    if (fIE) {
      oMnu.attachEvent("onmouseover",_XdkHighlightPopupMenuW3C);
      oMnu.attachEvent("onmouseout",_XdkLowlightPopupMenuW3C);
      oMnu.attachEvent("onmousedown",_XdkClickPopupMenuW3C);
    }
    else {
      oCell.setAttribute("onmouseover","JavaScript:_XdkHighlightPopupMenuW3C(this);");
      oCell.setAttribute("onmouseout","JavaScript:_XdkLowlightPopupMenuW3C(this);");
      oCell.setAttribute("onmousedown","JavaScript:_XdkClickPopupMenuW3C(this);");
    }
    sTxt               = "";
    oTxt               = oSpn.firstChild;
    while ((oTxt != null) && (oTxt.nodeType != 3))
      oTxt = oTxt.nextSibling;
    if (oTxt != null)
      sTxt             = oTxt.nodeValue;
    wCr                = sTxt.indexOf("\n");
    while (wCr != -1) {
      sTxt = sTxt.slice(0,wCr)+sTxt.slice(wCr+1);
      wCr              = sTxt.indexOf("\n");
    } //while
    oTxt               = document.createTextNode(sTxt);
    oCell.appendChild(oTxt);
    oSpn               = oNxt;
  } //while
  //show menu
  wX                   = wMouseX;
  wY                   = wMouseY;
  if (!fIE) {
    if ((wX + oTbl.offsetWidth) > window.innerWidth)
      wX               = wX - oTbl.offsetWidth;
    if ((wY + oTbl.offsetHeight) > window.innerHeight)
      wY               = wY - oTbl.offsetHeight;
    wX                 = wX + window.pageXOffset;
    wY                 = wY + window.pageYOffset;
  }
  else {
    if (wMaxWidth < oTbl.offsetWidth)
      wX               = wX - oTbl.offsetWidth;
    if (wMaxHeight < oTbl.offsetHeight)
      wY               = wY - oTbl.offsetHeight;
  }
  oSty.left            = wX;
  oSty.top             = wY;
  oSty.visibility      = "visible";
  //set event to close it
  oXdkGblMenu          = oMnu;
  if (fIE)
    document.attachEvent("onmouseup",_XdkDestroyPopupMenuW3C);
  else {
    document.captureEvents(Event.MOUSEUP);
    document.onmouseup = _XdkDestroyPopupMenuW3C;
  }
} //_XdkPopupMenuW3C

function _XdkDestroyPopupMenuW3C() {
  if (fIE)
    document.detachEvent("onmouseup",_XdkDestroyPopupMenuW3C);
  if (oXdkGblMenu != null) {
    oXdkGblMenu.style.visibility = "hidden";
    oXdkGblMenu.parentNode.removeChild(oXdkGblMenu);
    oXdkGblMenu = null;
  }
} //_XdkDestroyPopupMenuW3C

function _XdkHighlightPopupMenuW3C(oMnu) {
  if (fIE)
    oMnu = event.srcElement;
  if (oMnu.tagName == "TD")
    oMnu = oMnu.parentNode;
  if (oMnu.tagName == "TR") {
    oMnu.style.backgroundColor = "highlight";
    oMnu.style.color = "highlighttext";
    oMnu.cells.item(0).style.color = "highlighttext";
  }
} //_XdkHighlightPopupMenuW3C

function _XdkLowlightPopupMenuW3C(oMnu) {
  if (fIE)
    oMnu = event.srcElement;
  if (oMnu.tagName == "TD")
    oMnu = oMnu.parentNode;
  if (oMnu.tagName == "TR") {
    oMnu.style.backgroundColor = "menu";
    oMnu.style.color = "menutext";
    oMnu.cells.item(0).style.color = "menutext";
  }
} //_XdkLowlightPopupMenuW3C

function _XdkClickPopupMenuW3C(oMnu) {
  var sUrl    = "";
  var sTarget = "";
  var wError  = 0;

  if (fIE)
    oMnu = event.srcElement;
  if (oMnu.tagName == "TD")
    oMnu = oMnu.parentNode;
  if (oMnu.tagName == "TR") {
    sUrl      = oMnu.getAttribute("href")
    sTarget   = oMnu.getAttribute("target");
    try {
      if ((sTarget != null) && (sTarget != ""))
        window.open(sUrl,sTarget);
      else
        window.location = sUrl;
    }
    catch (wError) {
      alert('Can\'t execute "' + sUrl + '"');
    }
  }
} //_XdkClickPopupMenuW3C

function _XdkPopupMenuALL(oAnc) {
  var oSty       = null;
  var oMnu       = null;
  var oTbl       = null;
  var oNxt       = null;
  var oSpn       = null;
  var oRow       = null;
  var wTop       = 0;
  var wBottom    = 0;
  var sAdd       = '';
  var oBody      = document.body;
  var wMouseX    = window.m_wPopupMenuX - 10;
  var wMouseY    = window.m_wPopupMenuY - 5;
  var wMaxWidth  = oBody.clientWidth - wMouseX;
  var wMaxHeight = oBody.clientHeight - wMouseY;
  oMnu                 = document.createElement("div");
  oMnu.attachEvent("onmouseover",_XdkHighlightPopupMenuALL);
  oMnu.attachEvent("onmouseout",_XdkLowlightPopupMenuALL);
  oMnu.attachEvent("onmousedown",_XdkClickPopupMenuALL);
  oSty = oMnu.style;
  oSty.position        = "absolute";
  oSty.visibility      = "hidden";
  oSty.overflow        = "hidden";
  document.body.appendChild(oMnu);
  oTbl                 = document.createElement("table");
  oMnu.appendChild(oTbl);
  //Add the elements
  oTbl.style.cursor    = "default";
  oTbl.style.color     = "menutext";
  oTbl.style.backgroundColor = "menu";
  oTbl.style.border    = "2px outset threedhighlight";
  oTbl.cellPadding     = 0;
  oTbl.cellSpacing     = 0;
  oTbl.onselectstart   = "javascript:return false;"
  if ((oAnc.tagName == "IMG") && (oAnc.up == null))
    oAnc               = oAnc.parentElement;
  oSpn                 = oAnc.nextSibling;
  while ((oSpn != null) && (oSpn.tagName == "SPAN") && (oSpn.href != null)) {
    oNxt      = oSpn.nextSibling;
    wTop      = 1;
    wBottom   = 1;
    if (oSpn == oAnc.nextSibling)
      wTop    = 2;
    if ((oNxt == null) || (oNxt.tagName != "SPAN") || (oNxt.href == null))
      wBottom = 2;
    oRow      = oTbl.insertRow(-1);
    oRow.style.fontFamily = "tahoma";
    oRow.style.fontSize   = "8pt";
    oRow.style.color      = "menutext";
    oRow.style.padding    = wTop + "px 10px " + wBottom + "px 10px";
    if (oSpn.getAttribute("href") != null)
      oRow.href=oSpn.getAttribute("href");
    if (oSpn.getAttribute("target") != null)
      oRow.target=oSpn.getAttribute("target");
    oRow.insertCell(-1).innerText = oSpn.innerText;
    oSpn               = oNxt;
  } //while
  //show menu
  if (wMaxWidth < oTbl.offsetWidth)
    oSty.left          = wMouseX - oTbl.offsetWidth;
  else
    oSty.left          = wMouseX;
  if (wMaxHeight < oTbl.offsetHeight)
    oSty.top           = wMouseY - oTbl.offsetHeight;
  else
    oSty.top           = wMouseY;
  oSty.visibility      = "visible";
  //set event to close it
  oXdkGblMenu          = oMnu;
  document.attachEvent("onmouseup",_XdkDestroyPopupMenuALL);
} //_XdkPopupMenuALL

function _XdkDestroyPopupMenuALL() {
  document.detachEvent("onmouseup",_XdkDestroyPopupMenuALL);
  if (oXdkGblMenu != null) {
    oXdkGblMenu.style.visibility = "hidden";
    oXdkGblMenu.removeNode(true);
    oXdkGblMenu = null;
  }
} //_XdkDestroyPopupMenuALL

function _XdkHighlightPopupMenuALL() {
  var oMnu = event.srcElement;

  if (oMnu.tagName == "TD")
    oMnu = oMnu.parentElement;
  if (oMnu.tagName == "TR") {
    oMnu.style.backgroundColor = "highlight";
    oMnu.style.color = "highlighttext";
  }
} //_XdkHighlightPopupMenuALL

function _XdkLowlightPopupMenuALL() {
  var oMnu = event.srcElement;

  if (oMnu.tagName == "TD")
    oMnu = oMnu.parentElement;
  if (oMnu.tagName == "TR") {
    oMnu.style.backgroundColor = "menu";
    oMnu.style.color = "menutext";
  }
} //_XdkLowlightPopupMenuALL

function _XdkClickPopupMenuALL() {
  var sUrl    = "";
  var sTarget = "";
  var wError  = 0;
  var oMnu    = event.srcElement;

  if (oMnu.tagName == "TD")
    oMnu = oMnu.parentElement;
  if (oMnu.tagName == "TR") {
    sUrl      = oMnu.getAttribute("href")
    sTarget   = oMnu.getAttribute("target");
    try {
      if (sTarget != null)
        window.open(sUrl,sTarget);
      else
        window.location = sUrl;
    }
    catch (wError) {
      alert('Can\'t execute "' + sUrl + '"');
    }
  }
} //_XdkClickPopupMenuALL

//----------------------------------------------
//Generic title area
//----------------------------------------------

function XdkBanner(wLines) {
  var oRest   = null;
  var oNext   = null;
  var oNsr    = null;
  var oScroll = null;
  var wHeight = 0;
  var wTopPad = 6;
  var wBotPad = 0;

  if ((fIE) || (fNS7) || (fOPR)) {
    var fIFrame = ((window.frames.length != 0) && (window.frames(0).name != "XdkPopupIFrameName"));
    var oBody   = document.body;
    var oBanner = oBody.firstChild;
    if ((oBanner != null) && (wLines != 0)) {
      oNsr                = document.createElement("div");
      oNsr.id             = "XdkBanner";
      if (fIE)
        oNsr.style.width  = oBody.clientWidth;
      else
        oNsr.style.width  = oBody.offsetWidth + "px";
      oNsr.style.height   = "0px";
      oNsr.style.overflow = "hidden";
      document.body.insertBefore(oNsr,oBanner);
//    oBanner.insertAdjacentElement("beforeBegin",oNsr);
      wTopPad             = 6;
      while ((oBanner != null) && (wLines != 0)) {
        while ((oBanner.tagName == "SCRIPT") || 
               ((oBanner.tagName == "DIV") && 
                (oBanner.className.toLowerCase().indexOf("section") != -1))) {
          if (oBanner.firstChild == null)
            oNext = oBanner.nextSibling;
          else
            oNext = oBanner.firstChild;
          _XdkRemoveNodeAndPromoteChildren(oBanner);
//        oBanner.removeNode(false);
          oBanner = oNext;
        } //while
        if (oBanner.tagName == "TABLE") {
          if (fIE)
            wHeight = wHeight + oBanner.scrollHeight + 2;
          else
            wHeight = wHeight + oBanner.offsetHeight + 2;
          wTopPad = 6;
          wLines  = wLines - 1;
        }
        else if (oBanner.nodeType != 3) {
          oBanner.style.margin = "0px";
          oBanner.style.textIndent = "0";
          oNext = _XdkGetNextSibling(oBanner);
          if ((wLines == 1) || 
              ((oNext != null) && (oNext.tagName == "TABLE")))
            wBotPad = 6;
          else
            wBotPad = 0;
          oBanner.style.padding = wTopPad + "px 6px " + wBotPad + "px 6px";
          if (wLines == 1)
            oBanner.style.borderBottom = "solid 1pt #c0c0c0";
//        if (fIE)
//          wHeight = wHeight + oBanner.scrollHeight;
//        else
            wHeight = wHeight + oBanner.offsetHeight;
          wTopPad = 0;
          wLines  = wLines - 1;
        }
        oBanner   = oBanner.nextSibling;
        oNsr.appendChild(oNsr.nextSibling);
//      oNsr.appendChild(oNsr.nextSibling.removeNode(true));
      } //while
	  if (fIE)
        oNsr.style.height           = wHeight;
	  else
        oNsr.style.height           = wHeight + "px";
      oRest                         = oNsr.nextSibling;
      if (oRest != null) {
        oBody.style.overflow        = "hidden";
        oScroll                     = document.createElement("div");
        oScroll.id                  = "XdkScroll";
        if (fIE) {
          oScroll.style.width       = oBody.style.width;
          oScroll.style.overflowX   = "auto";
          oScroll.style.overflowY   = "auto";
        }
        else {
          oScroll.style.width       = innerWidth+"px";
          oScroll.style.overflow    = "auto";
        }
        oScroll.style.padding       = "5px";
        if (fIFrame) {
          oScroll.style.padding     = "0px";
          if (fIE)
            oScroll.style.overflowY = "auto";
        }
        oBody.style.margin          = "0px";
        oBody.style.padding         = "0px";
        document.body.insertBefore(oScroll,oRest);
//      oRest.insertAdjacentElement("beforeBegin",oScroll);
        oRest                       = oScroll.nextSibling;
        while (oRest != null) {
          oNext                     = oRest.nextSibling;
          if ((oRest.nodeType == 3) || 
              ((oRest.tagName != "SCRIPT") && 
               ((oRest.style == null) || (oRest.style.position != "absolute")))) {
            oScroll.appendChild(oRest);
//          oScroll.appendChild(oRest.removeNode(true));
            if ((!fIE) && (oRest.style != null) && (oRest.tagName == "P"))
              oRest.style.marginRight = "5px";
          }
          oRest                     = oNext;
        } //while
//      window.attachEvent('onresize',_XdkOnResizeBody); //IE only
        if (window.onresize == null)
          window.onresize = _XdkOnResizeBody;
        window.onresize();
//      _XdkOnResizeBody();
      }
    }
    else if (fIFrame) {
      oBody.scroll           = "no";
      oBody.style.overflow   = "hidden";
      oBody.style.margin     = "0px";
    }
  }
  else {
    document.body.style.paddingRight = "5px";
//  document.body.style.overflow = "auto";
  }
} //XdkBanner

function _XdkOnResizeBody() {
  var oBody   = document.body;
  var oBanner = document.getElementById("XdkBanner");
  var oScroll = document.getElementById("XdkScroll");
  if ((oBanner != null) && (oScroll != null)) {
    if (fIE) {
      if (oBody.clientHeight > oBanner.clientHeight)
        oScroll.style.height = oBody.clientHeight - oBanner.clientHeight - 1;
      else
        oScroll.style.height = 0;
      oScroll.style.width    = oBody.clientWidth;
      oBanner.style.width    = oBody.clientWidth;
    }
    else {
      if (innerHeight > oBanner.offsetHeight)
        oScroll.style.height = (innerHeight - oBanner.offsetHeight - 10)+"px";
      else
        oScroll.style.height = "0px";
      oScroll.style.width    = (innerWidth - 10)+"px";
      oBanner.style.width    = innerWidth+"px";
    }
  }
} //_XdkOnResizeBody

function _XdkGetNextSibling(oNode) {
  var oNext = oNode.nextSibling;
  while ((oNext != null) && (oNext.nodeType == 3))
    oNext = oNext.nextSibling;
  return oNext;
} //_XdkGetNextSibling

function _XdkRemoveNodeAndPromoteChildren(oRemove) {
  var oNext  = null;
  var oChild = oRemove.firstChild;
  while (oChild != null) {
    oNext  = oChild.nextSibling;
//  oRemove.removeChild(oChild);
    oRemove.parentNode.insertBefore(oChild,oRemove);
    oChild = oNext;
  } //while
  oRemove.parentNode.removeChild(oRemove);
} //_XdkRemoveNodeAndPromoteChildren

//----------------------------------------------
//Generic search highlighting
//----------------------------------------------

function RePublicoSelectWords(sWords, fOn) {
  if( sWords!=null && sWords!="" ) {
    var oTop = XdkGetWindowTop();
    //Show all hidden text
    var wIndex = 0;
    var oDiv   = document.all.tags("DIV");
    if (oDiv != null) {
      for (wIndex = 0;wIndex < oDiv.length;wIndex++) {
        if ((oDiv[wIndex].style != null) && (oDiv[wIndex].style.display == "none")) {
          oDiv[wIndex].style.visibility = "hidden";
          oDiv[wIndex].style.display = "";
          oDiv[wIndex].setAttribute("xdk","search",0);
        }
      } //for
    }
    // word delimeters
    //var aWords = sWords.split(sOrAnd);  //Depricated in favour of phrase highlighting for Index tab; Matthew Wanders 21/02/2005.
    if (sWords.search(" And ") > 1 || sWords.search(" Or ") > 1) {
        var aWords = sWords.split(sOrAnd);
    } else {
        var aWords=new Array(1);
        aWords[0] = sWords;
//      var aWords = sWords.split("alksjdfhljakshdflkjasdhflkjsahdlfaslkjfdhlkajsdhflkhasdlfjhaslkhflaksjhdflaksf");
    }
    var i = 0;
    var fFirst = true;
    for( i in aWords ) {
      var sWord = aWords[i];
      var oRange = oTop.frames[sTocTarget].document.body.createTextRange();
      while( oRange.findText(sWord) ) {
        if (fOn == true) {
          oRange.execCommand("BackColor",false,sSelBack);
          oRange.execCommand("ForeColor",false,sSelFore);
          if (fFirst == true)
            oRange.scrollIntoView();
          fFirst = false;
        }
        else
          oRange.execCommand("RemoveFormat",false,null);
        oRange.collapse(false);
      } //while
    }
    //Hide all hidden text
    if (oDiv != null) {
      for (wIndex = 0;wIndex < oDiv.length;wIndex++) {
        if (oDiv[wIndex].getAttribute("xdk",0) == "search") {
          oDiv[wIndex].style.display = "none";
          oDiv[wIndex].style.visibility = "visible";
          oDiv[wIndex].removeAttribute("xdk",0);
        }
      } //for
    }
  }
} //RePublicoSelectWords

//----------------------------------------------
//Image effect
//----------------------------------------------

function XdkImageEffect(oObject) {
  oObject.style.visibility='hidden';
  oObject.filters.item(0).Apply();
  oObject.style.visibility='';
  oObject.filters.item(0).Play();
} //XdkImageEffect

//----------------------------------------------
//XDK Button
//----------------------------------------------

function XdkButtonOver(oImg) {
  if (oImg.getAttribute("down") != oImg.getAttribute("src"))
    oImg.setAttribute("src",oImg.getAttribute("over"));
} //XdkButtonOver

function XdkButtonOut(oImg) {
  oImg.setAttribute("src",oImg.getAttribute("up"));
} //XdkButtonOut

function XdkButtonDown(oImg) {
  oImg.setAttribute("src",oImg.getAttribute("down"));
} //XdkButtonDown

function XdkButtonUp(oImg) {
  var sUrl    = "";
  var sTarget = "";
  var sSrc    = "";
  var wError  = 0;

  oImg.setAttribute("src",oImg.getAttribute("over"));
  sSrc      = oImg.getAttribute("src")
  sUrl      = oImg.getAttribute("href")
  sTarget   = oImg.getAttribute("target");
  if ((sUrl != null) && (sUrl != sSrc)) {
    try {
      if ((sTarget != null) && (sTarget != ""))
        window.open(sUrl,sTarget);
      else
        window.location = sUrl;
    }
    catch (wError) {
      alert('Can\'t execute "' + sUrl + '"');
    }
  }
} //XdkButtonUp

//----------------------------------------------
//XDK Tab bar
//----------------------------------------------

function XdkTabClick(oTable,sId) {
  if ((!fIE) || (fIE6))
    _XdkTabClickW3C(oTable,sId);
  else
    _XdkTabClickALL(oTable,sId);
} //XdkTabClick

function _XdkTabClickW3C(oTable,sId) {
  var wIndex;
  var oTabTbl;
  var oNxtTbl;
  var fTabbar = (sId.substring(0,3) == "XDK");
  var fLastActive = false;
  if (oTable.className != sId + "Active") {
    var oTabRow = oTable.parentNode.parentNode;
    for (wIndex = 0;wIndex < oTabRow.cells.length;wIndex++) {
      oTabCol = oTabRow.cells.item(wIndex);
      oTabTbl = oTabCol.firstChild;
      while ((oTabTbl != null) && (oTabTbl.tagName != "TABLE"))
        oTabTbl = oTabTbl.nextSibling;
      if ((oTabTbl == null) || (oTabTbl.className == null))
        ;
      else if (oTabTbl == oTable) {
        oTabTbl.className = sId + "Active";
        eval(oTabTbl.getAttribute("href"));
        fLastActive = true;
      }
      else {
        if ((oTabTbl.className == sId + "Active") && (fTabbar))
          eval(oTabTbl.getAttribute("href"));
        if (fLastActive) {
          oTabTbl.className = sId + "InactiveAfter";
          fLastActive = false;
        }
        else {
          oNxtTbl = null;
          if ((wIndex+1) != oTabRow.cells.length) {
            oNxtTbl = oTabRow.cells.item(wIndex+1).firstChild;
            while ((oNxtTbl != null) && (oNxtTbl.tagName != "TABLE"))
              oNxtTbl = oNxtTbl.nextSibling;
          }
          if (oNxtTbl == oTable)
            oTabTbl.className = sId + "InactiveBefore";
          else
            oTabTbl.className = sId + "Inactive";
        }
      }
    } //for
  }
} //_XdkTabClickW3C

function _XdkTabClickALL(oTable,sId) {
  var fTabbar = (sId.substring(0,3) == "XDK");
  var fLastActive = false;
  if (oTable.className != sId + "Active") {
    var oTabRow = oTable.parentElement.parentElement;
    var oTabCol = oTabRow.firstChild;
    while (oTabCol != null) {
      if ((oTabCol.firstChild == null) || (oTabCol.firstChild.className == null))
        ;
      else if (oTabCol.firstChild == oTable) {
        oTabCol.firstChild.className = sId + "Active";
        eval(oTabCol.firstChild.href);
        fLastActive = true;
      }
      else {
        if ((oTabCol.firstChild.className == sId + "Active") && (fTabbar))
          eval(oTabCol.firstChild.href);
        if (fLastActive) {
          oTabCol.firstChild.className = sId + "InactiveAfter";
          fLastActive = false;
        }
        else if ((oTabCol.nextSibling != null) && (oTabCol.nextSibling.firstChild == oTable))
          oTabCol.firstChild.className = sId + "InactiveBefore";
        else
          oTabCol.firstChild.className = sId + "Inactive";
      }
      oTabCol = oTabCol.nextSibling;
    } //while
  }
} //_XdkTabClickALL

function XdkTabIFrame(sUrl,sTarget) {
  if ((!fIE) || (fIE6))
    _XdkTabIFrameW3C(sUrl,sTarget);
  else
    _XdkTabIFrameALL(sUrl,sTarget);
} //XdkTabIFrame

function _XdkTabIFrameW3C(sUrl,sTarget)
{
  var oFrame = document.getElementById(sTarget);
  if (oFrame != null)
    oFrame.setAttribute("src",sUrl);
} //_XdkTabIFrameW3C

function _XdkTabIFrameALL(sUrl,sTarget)
{
  var oFrame = document.all[sTarget];
  if (oFrame != null)
    oFrame.src = sUrl;
} //_XdkTabIFrameALL

//----------------------------------------------
//XDK Play sound file
//----------------------------------------------

function XdkPlaySoundFile(sFile) {
  if (fIE)
    _XdkPlaySoundFileIE(sFile);
  else
    _XdkPlaySoundFileNS(sFile);
} //XdkPlaySoundFile

function _XdkPlaySoundFileNS(sFile) {
  var oSound = document.getElementById("XdkSound");
  if (oSound == null) {
    oSound = document.createElement("embed");
    oSound.setAttribute("id","XdkSound");
    oSound.setAttribute("hidden","true");
    document.body.appendChild(oSound);
  }
  oSound.setAttribute("loop","1");
  oSound.setAttribute("src","./Multimedia/" + sFile);
} //_XdkPlaySoundFileNS

function _XdkPlaySoundFileIE(sFile) {
  var oSound = document.all.XdkSound;
  if (oSound == null) {
    oSound = document.createElement("bgsound");
    oSound.id = "XdkSound";
    document.body.appendChild(oSound);
  }
  oSound.loop = 1;
  oSound.src  = './Multimedia/' + sFile;
} //_XdkPlaySoundFileIE

//----------------------------------------------
//XDK column control
//----------------------------------------------

function XdkColumnMouseDown(oTable,sId) {
  oTable.className = sId + "Down";
} //XdkColumnMouseDown

function XdkColumnMouseOut(oTable,sId) {
  oTable.className = sId + "Up";
} //XdkColumnMouseOut

function XdkColumnMouseUp(oTable,sId) {
  oTable.className = sId + "Down";
  oTable.style.cursor = "wait";
  oTable.setAttribute("id",sId);
  if ((!fIE) || (fIE6))
    setTimeout("_XdkColumnMouseUpW3C('"+sId+"')",10);
  else
    setTimeout("_XdkColumnMouseUpALL('"+sId+"')",10);
} //XdkColumnMouseUp

function _XdkColumnMouseUpW3C(sId) {
  var sRow1    = "";
  var sRow2    = "";
  var wRow1    = 0;
  var wRow2    = 0;
  var wLastRow = 0;
  var oTmp     = null;
  var oTbl     = null;
  var oRow1    = null;
  var oRow2    = null;
  var fSwap    = false;

  var oTable = document.getElementById(sId);
  //Sort column
  var fDescend = (oTable.getAttribute("ascend") == "1");
  //Find which column to sort
  var wCol = 0;
  var oCol = oTable.parentNode;
  if (oCol.tagName == "TD") {
    oRow1  = oCol.parentNode;
    while (oRow1.cells.item(wCol) != oCol)
      wCol = wCol + 1;
    oTbl   = oRow1.parentNode.parentNode;
    wRow1  = 1;
    wRow2  = 2;
    //Sort rows
    do {
      fSwap    = false;
      wLastRow = oTbl.rows.length - 1;
      while ((wRow1 < wLastRow) && (wRow2 <= wLastRow)) {
        wRow2 = wRow1 + 1;
        sRow1 = _XdkColumnGetTextW3C(oTbl,(fDescend ? wRow2 : wRow1),wCol);
        sRow2 = _XdkColumnGetTextW3C(oTbl,(fDescend ? wRow1 : wRow2),wCol);
        if (sRow1 <= sRow2)
          wRow1 = wRow1 + 1;
        else {
          while ((sRow1 > sRow2) && (wRow2 < wLastRow)) {
            wRow2 = wRow2 + 1;
            if (!fDescend)
              sRow2 = _XdkColumnGetTextW3C(oTbl,wRow2,wCol);
            else
              sRow1 = _XdkColumnGetTextW3C(oTbl,wRow2,wCol);
          } //while
          oRow1 = oTbl.rows.item(wRow1);
          oTmp  = oRow1.parentNode;
          if (sRow1 < sRow2)
            oTmp.insertBefore(oRow1,oTbl.rows.item(wRow2));
          else if (wRow2 < wLastRow)
            oTmp.insertBefore(oRow1,oTbl.rows.item(wRow2+1));
          else
            oTmp.appendChild(oRow1);
          if (wRow1 != 1)
            wRow1 = wRow1 - 1;
          fSwap = true;
        }
      } //while
    } while (fSwap == true);
    //Set image and clear all other column graphics
    oRow1 = oTbl.rows.item(0);
    for (wCol = 0;wCol < oRow1.cells.length;wCol++) {
      oTbl = oRow1.cells.item(wCol).firstChild;
      while ((oTbl != null) && (oTbl.nodeName != "TABLE"))
        oTbl = oTbl.nextSibling;
      if (oTbl != null) {
        if (oTbl != oTable) {
          _XdkColumnSetGraphicW3C(oTbl,"./Images/RpoColumnNone.gif");
          oTbl.removeAttribute("ascend");
        }
        else if (fDescend) {
          _XdkColumnSetGraphicW3C(oTbl,"./Images/RpoColumnDown.gif");
          oTbl.setAttribute("ascend","0");
        }
        else {
          _XdkColumnSetGraphicW3C(oTbl,"./Images/RpoColumnUp.gif");
          oTbl.setAttribute("ascend","1");
        }
      }
    } //for
  }
  oTable.style.cursor = "";
  oTable.className = sId + "Up";
} //_XdkColumnMouseUpW3C

function _XdkColumnGetTextW3C(oTbl,wRow,wCol) {
  if (fIE)
    return oTbl.rows.item(wRow).cells.item(wCol).firstChild.innerText;
  else {
    var sTxt = "";
    var oTxt = null;

    var oPar = oTbl.rows.item(wRow).cells.item(wCol).firstChild;
    while ((oPar != null) && (oPar.nodeType != 1))
      oPar = oPar.nextSibling;
    if (oPar != null) {
      oTxt = oPar.firstChild;
      while ((oTxt != null) && (oTxt.nodeType != 3))
        oTxt = oTxt.nextSibling;
      if (oTxt != null)
        sTxt = oTxt.nodeValue;
    }
  }
  return sTxt;
} //_XdkColumnGetTextW3C

function _XdkColumnSetGraphicW3C(oTable,sImage) {
  var oImg = oTable.rows.item(0).cells.item(0).firstChild;
  while ((oImg != null) && (oImg.nodeName != "IMG"))
    oImg = oImg.nextSibling;
  if (oImg != null)
    oImg.setAttribute("src",sImage);
} //_XdkColumnSetGraphicW3C

function _XdkColumnMouseUpALL(sId) {
  var sRow1 = "";
  var sRow2 = "";
  var oTmp  = null;
  var oTbl  = null;
  var oRow1 = null;
  var oRow2 = null;
  var fSwap = false;

  var oTable = document.all[sId];
  //Sort column
  var fDescend = (oTable.getAttribute("ascend") == "1");
  //Find which column to sort
  var wCol = 1;
  var oCol = oTable.parentElement;
  if (oCol.tagName == "TD") {
    while (oCol.previousSibling != null) {
      wCol = wCol + 1;
      oCol = oCol.previousSibling;
    }
    //Sort rows
    var oHdr    = oCol.parentElement;
    do {
      fSwap = false;
      if ((oHdr.nextSibling == null) && (oHdr.parentElement.tagName == "THEAD"))
        oRow1 = oHdr.parentElement.nextSibling.firstChild;
      else
        oRow1 = oHdr.nextSibling;
      if (oRow1 != null) {
        while (oRow1.nextSibling != null) {
          oRow2 = oRow1.nextSibling;
          sRow1 = _XdkColumnGetTextALL((fDescend ? oRow2 : oRow1),wCol);
          sRow2 = _XdkColumnGetTextALL((fDescend ? oRow1 : oRow2),wCol);
          if (sRow1 <= sRow2)
            oRow1 = oRow1.nextSibling;
          else {
            while ((sRow1 > sRow2) && (oRow2.nextSibling != null)) {
              oRow2 = oRow2.nextSibling;
              if (!fDescend)
                sRow2 = _XdkColumnGetTextALL(oRow2,wCol);
              else
                sRow1 = _XdkColumnGetTextALL(oRow2,wCol);
            } //while
            oTmp = oRow1.nextSibling;
            oRow1.removeNode(true);
            if (sRow1 > sRow2)
              oRow2.insertAdjacentElement("afterEnd",oRow1);
            else
              oRow2.insertAdjacentElement("beforeBegin",oRow1);
            oRow1 = oTmp;
            fSwap = true;
          }
        } //while
      }
    } while (fSwap == true);
    //Set image and clear all other column graphics
    oCol = oHdr.firstChild;
    while (oCol != null) {
      oTbl = oCol.firstChild;
      if ((oTbl != null) && (oTbl.tagName == "TABLE")) {
        if (oTbl != oTable) {
          _XdkColumnSetGraphicALL(oTbl,"./Images/RpoColumnNone.gif");
          oTbl.removeAttribute("ascend");
        }
        else if (fDescend) {
          _XdkColumnSetGraphicALL(oTbl,"./Images/RpoColumnDown.gif");
          oTbl.setAttribute("ascend","0");
        }
        else {
          _XdkColumnSetGraphicALL(oTbl,"./Images/RpoColumnUp.gif");
          oTbl.setAttribute("ascend","1");
        }
      }
      oCol = oCol.nextSibling;
    } //while
  }
  oTable.style.cursor = "";
  oTable.className = sId + "Up";
} //_XdkColumnMouseUpALL

function _XdkColumnGetTextALL(oRow,wCol) {
  var oCol  = oRow.firstChild;
  var sText = "";
  while ((oCol != null) && (wCol != 1)) {
    wCol = wCol - 1;
    oCol = oCol.nextSibling;
  } //while
  if (oCol != null)
    sText = oCol.firstChild.innerText;
  return sText;
} //_XdkColumnGetTextALL

function _XdkColumnSetGraphicALL(oTable,sImage) {
  oTable.firstChild.firstChild.firstChild.firstChild.src = sImage;
} //_XdkColumnSetGraphicALL

//----------------------------------------------
//Generic print functions
//----------------------------------------------

function XdkOnBeforePrint() {
  var wIndex = 0;
  var oDiv   = document.all.tags("DIV");
  if (oDiv != null) {
    for (wIndex = 0;wIndex < oDiv.length;wIndex++) {
      if ((oDiv[wIndex].style != null) && (oDiv[wIndex].style.display == "none")) {
        oDiv[wIndex].style.display = "";
        oDiv[wIndex].setAttribute("xdk","print",0);
      }
    } //for
  }
  //Disable banner
  var oBody = document.body;
  var oBanner = oBody.firstChild;
  if (oBanner.id == "XdkBanner") {
    var oScroll = oBanner.nextSibling;
    oBody.style.overflow = "visible";
    oBanner.style.overflow = "visible";
    oScroll.style.overflow = "visible";
    oScroll.style.height = "auto"
    oScroll.style.width  = "auto";
  }
} //XdkOnBeforePrint
        
function XdkOnAfterPrint() {
  var wIndex = 0;
  var oDiv   = document.all.tags("DIV");
  if (oDiv != null) {
    for (wIndex = 0;wIndex < oDiv.length;wIndex++) {
      if (oDiv[wIndex].getAttribute("xdk",0) == "print") {
        oDiv[wIndex].style.display = "none";
        oDiv[wIndex].removeAttribute("xdk",0);
      }
    } //for
  }
  //Enable banner
  var fIFrame = ((window.frames.length != 0) && (window.frames(0).name != "XdkPopupIFrameName"));
  var oBody   = document.body;
  var oBanner = oBody.firstChild;
  if (oBanner.id == "XdkBanner") {
    var oScroll = oBanner.nextSibling;
    oBody.style.overflow = "hidden";
    oBanner.style.overflow = "hidden";
    oScroll.style.overflow = "visible";
    oScroll.style.overflowX = "auto";
    oScroll.style.overflowY = "scroll";
    if (fIFrame) {
      oScroll.style.padding    = "0px";
      oScroll.style.overflowY  = "auto";
    }
    _XdkOnResizeBody();
  }
} //XdkOnAfterPrint

//----------------------------------------------
//Photo gallery support functions
//----------------------------------------------

function XdkPhotoGalleryResizeImage() {
  try {
    PhotoGalleryResizeImage();
  }
  catch(wError) {
    setTimeout("XdkPhotoGalleryResizeImage()",500);
  }
} //XdkPhotoGalleryResizeImage

//----------------------------------------------
//Learning central
//----------------------------------------------

function XdkTweakAsp() {
  var oBody = document.body;
  var oFme = document.createElement("IFRAME")
  oFme.style.display="none"
  oFme.setAttribute("src","../../tweak.asp");
  oBody.appendChild(oFme);
// oBody.removeChild(oFme);
} //XdkTweakAsp


//-------------- end of Xdk.js --------------------------
