/****************************************************
** functions.js - Main javascript function library **
****************************************************/

/* Init actions */
function changeOnSubmit() { // disable enter key form submission (chrome, safari)
  //oldsubmit = document.forms[0].onsubmit;
  document.forms[0].action = "javascript:return false();";
  /*document.forms[0].onsubmit = function() {
    //oldsubmit();
    return false;
  }*/
}
getTopic( TOPIC_ONLOAD ).addListener( 'changeOnSubmit()' );




/* browser detection, used to get visitor's browser name and version */
var BrowserDetect = {
  init: function () {
    this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
    this.version = this.searchVersion(navigator.userAgent)
      || this.searchVersion(navigator.appVersion)
      || "an unknown version";
    this.OS = this.searchString(this.dataOS) || "an unknown OS";
  },
  searchString: function (data) {
    for (var i=0;i<data.length;i++)  {
      var dataString = data[i].string;
      var dataProp = data[i].prop;
      this.versionSearchString = data[i].versionSearch || data[i].identity;
      if (dataString) {
        if (dataString.indexOf(data[i].subString) != -1)
          return data[i].identity;
      }
      else if (dataProp)
        return data[i].identity;
    }
  },
  searchVersion: function (dataString) {
    var index = dataString.indexOf(this.versionSearchString);
    if (index == -1) return;
    return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
  },
  dataBrowser: [
    {
      string: navigator.userAgent,
      subString: "Chrome",
      identity: "Chrome"
    },
    {   string: navigator.userAgent,
      subString: "OmniWeb",
      versionSearch: "OmniWeb/",
      identity: "OmniWeb"
    },
    {
      string: navigator.vendor,
      subString: "Apple",
      identity: "Safari",
      versionSearch: "Version"
    },
    {
      prop: window.opera,
      identity: "Opera"
    },
    {
      string: navigator.vendor,
      subString: "iCab",
      identity: "iCab"
    },
    {
      string: navigator.vendor,
      subString: "KDE",
      identity: "Konqueror"
    },
    {
      string: navigator.userAgent,
      subString: "Firefox",
      identity: "Firefox"
    },
    {
      string: navigator.vendor,
      subString: "Camino",
      identity: "Camino"
    },
    {    // for newer Netscapes (6+)
      string: navigator.userAgent,
      subString: "Netscape",
      identity: "Netscape"
    },
    {
      string: navigator.userAgent,
      subString: "MSIE",
      identity: "Explorer",
      versionSearch: "MSIE"
    },
    {
      string: navigator.userAgent,
      subString: "Gecko",
      identity: "Mozilla",
      versionSearch: "rv"
    },
    {     // for older Netscapes (4-)
      string: navigator.userAgent,
      subString: "Mozilla",
      identity: "Netscape",
      versionSearch: "Mozilla"
    }
  ],
  dataOS : [
    {
      string: navigator.platform,
      subString: "Win",
      identity: "Windows"
    },
    {
      string: navigator.platform,
      subString: "Mac",
      identity: "Mac"
    },
    {
      string: navigator.platform,
      subString: "Linux",
      identity: "Linux"
    }
  ]

};
BrowserDetect.init();

function includeCss(cssHref) // include a css file dynamically based on filename
{
  var headID = document.getElementsByTagName("head")[0];
  var cssNode = document.createElement('link');
  cssNode.type = 'text/css';
  cssNode.rel = 'stylesheet';
  cssNode.href = urlPrefix + templateHome + 'css/browsers/' + cssHref;
  //cssNode.media = 'screen';
  headID.appendChild(cssNode);
}




/* browser hack css includes */
var browserName = BrowserDetect.browser.toLowerCase();
switch(browserName) { // include individual css based on browser name and version
  case "safari": // safari
    includeCss('safari.css');
    break;
  case "firefox": // firefox
    if(BrowserDetect.version >= 3) { includeCss('ff3.css'); browserName += "3"; } // ff3
    else if(BrowserDetect.version < 3) { includeCss('ff2.css'); browserName += "2"; } // ff2-
    break;
  case "chrome": // chrome
    includeCss('chrome.css');
    break;
  case "opera": // opera
    includeCss('opera.css');
    break;
  case "explorer": // ie
    if(BrowserDetect.version >= 8) { includeCss('ie8.css'); browserName += "8"; } // ie8
    else if(BrowserDetect.version == 7) { includeCss('ie7.css'); browserName += "7"; } // ie7
    else if(BrowserDetect.version < 7) { includeCss('ie6.css'); browserName += "6"; } // ie6-
    break;
}


/* Utility Functions */
function imgro(item) // rollover image replacement
{
  var imgpath = item.src;
  if(imgpath.match("_ro") == null) {
    var last_dot = imgpath.lastIndexOf(".");
    var x = imgpath.substring(0, last_dot) + "_ro" + imgpath.substring(last_dot);
    item.src = x;
  }
}
function imgundo(item) // unrollover image restoration
{
  var imgpath = item.src;
  if(imgpath.match("_ro") != null) {
    var x = imgpath.replace('_ro.','.');
    item.src = x;
  }
}

function checkEnter(e, funcToCall, funcParam) // uses enter key to submit form
{
  if(!e) {
    e = window.event;
  }
  var characterCode = (e && e.which ? e.which : (e.keyCode ? e.keyCode : event.keyCode));
  //var characterCode = (((!e || e.keycode) && !e.which) ? (!e ? event.keyCode : e.keycode) : e.which);

  if(characterCode == 13) { // enter key
    (e ? e : event).returnValue = false;
    (e ? e : event).cancelBubble = true;
    if(funcParam != undefined && funcParam != "") {
      funcToCall(funcParam); // submit the form with param
    }
    else {
      funcToCall(); // submit the form without param
    }
    return false;
  }
  else {
    return true;
  }
}


/* Email and Print Functions */
var MAILTO_CONFIRMATION = "Transmitting information to us by E-mail does not establish an attorney-client relationship.";
var VCARD_CONFIRMATION = MAILTO_CONFIRMATION;

function mailTo(email)
{
  window.parent.location = "mailto:" + email;
}

function vCard(path)
{
    window.parent.location = path;
}

function printPage()
{
  var url = window.location.href;
  url += (url.indexOf("?") == -1 ? "?" : "&") + "printver=true";
  window.open(url, 'Print', 'width=725,height=475,directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,top=20,left=20');
}

function emailPage()
{
  var url = window.location.href;
  //if(confirm(MAILTO_CONFIRMATION)) {
    window.location = "mailto:?body=" + escape(url);
  //}
}


function printPDF( pagePath, templateName, designName )
{
  var url = window.location.href;
  url += (url.indexOf("?") == -1 ? "?" : "&") + "printTo=pdfw";

  if(pagePath) {
    url += "&pagePath=" + pagePath;
  }

  if(templateName) {
    url += "&templateName=" + templateName;
  }

  if(designName) {
    url += "&designName=" + designName;
  }

  window.location = url;
}


/*
  Developed by Robert Nyman, http://www.robertnyman.com
  Code/licensing: http://code.google.com/p/getelementsbyclassname/
*/
var getElementsByClassName = function(className, tag, elm) {
  if(document.getElementsByClassName) {
    getElementsByClassName = function(className, tag, elm) {
      elm = elm || document;
      var elements = elm.getElementsByClassName(className),
        nodeName = (tag)? new RegExp("\\b" + tag + "\\b", "i") : null,
        returnElements = [],
        current;
      for(var i=0, il=elements.length; i<il; i+=1){
        current = elements[i];
        if(!nodeName || nodeName.test(current.nodeName)) {
          returnElements.push(current);
        }
      }
      return returnElements;
    };
  }
  else if(document.evaluate) {
    getElementsByClassName = function(className, tag, elm) {
      tag = tag || "*";
      elm = elm || document;
      var classes = className.split(" "),
        classesToCheck = "",
        xhtmlNamespace = "http://www.w3.org/1999/xhtml",
        namespaceResolver = (document.documentElement.namespaceURI === xhtmlNamespace)? xhtmlNamespace : null,
        returnElements = [],
        elements,
        node;
      for(var j=0, jl=classes.length; j<jl; j+=1){
        classesToCheck += "[contains(concat(' ', @class, ' '), ' " + classes[j] + " ')]";
      }
      try  {
        elements = document.evaluate(".//" + tag + classesToCheck, elm, namespaceResolver, 0, null);
      }
      catch (e) {
        elements = document.evaluate(".//" + tag + classesToCheck, elm, null, 0, null);
      }
      while ((node = elements.iterateNext())) {
        returnElements.push(node);
      }
      return returnElements;
    };
  }
  else {
    getElementsByClassName = function(className, tag, elm) {
      tag = tag || "*";
      elm = elm || document;
      var classes = className.split(" "),
        classesToCheck = [],
        elements = (tag === "*" && elm.all)? elm.all : elm.getElementsByTagName(tag),
        current,
        returnElements = [],
        match;
      for(var k=0, kl=classes.length; k<kl; k+=1){
        classesToCheck.push(new RegExp("(^|\\s)" + classes[k] + "(\\s|$)"));
      }
      for(var l=0, ll=elements.length; l<ll; l+=1){
        current = elements[l];
        match = false;
        for(var m=0, ml=classesToCheck.length; m<ml; m+=1){
          match = classesToCheck[m].test(current.className);
          if(!match) {
            break;
          }
        }
        if(match) {
          returnElements.push(current);
        }
      }
      return returnElements;
    };
  }
  return getElementsByClassName(className, tag, elm);
};


// check all divs in narrow page column (if exists) to see if anything is drawn to the page, if not then hide it (allowing the wide column to be 100% width)
function hideEmptyAreas() {
  var colNames = ["top-col", "narrow-col"];

  for(var j in colNames)
  {
    var thisCol = getElementsByClassName(colNames[j], "td", getTag("contentBody"));
    if(thisCol.length > 0) { // if narrow col exists
      for(var k=0; k<thisCol.length; k++) { // loop through all narrow col divs
        var thisColDivs = thisCol[k].getElementsByTagName("DIV");
        var totalHeight = 0;
        var temp;
        var pb;

        for(var i=0; i<thisColDivs.length; i++) { // loop through all narrow col divs
          if((temp = thisColDivs[i].id) && temp.indexOf("portlet") >= 0) { // one of the main portlets
            temp = thisColDivs[i].offsetHeight;
            if(temp > 0) {
              pb = parseInt(getStyle(thisColDivs[i], "paddingBottom"));
              temp = (temp >= pb ? (temp - pb) : temp);
              totalHeight += temp;
            }
          }
        }

        if(totalHeight <= 0) {
          thisCol[k].style.display = "none";
          
          /*if(colNames[j] == "narrow-col") { // make wide col fill 100%
            var wideCol = getElementsByClassName("wide-col", "td", getTag("contentBody"));

            if(wideCol.length > 0) { // if wide col exists
              wideCol[0].className = wideCol[0].className.replace("wide-col", "");
            }
          }*/
        }
        if(colNames[j] == "top-col") { // change top-col to wide-col
          thisCol[k].className = thisCol[k].className.replace("top-col", "wide-col");
        }
      }
    }
  }
}






/***************************************** NAVIGATION MENU *****************************************/
var sub;
var subtree = new Array();
var x = 0;
var openOnLeft = false;
var maxNavWidth;
var offsetHeight = 0;//-1;
var offsetWidth = 0;
var previousItem = null;

function opensubmenu(item, divid)
{
  previousItem = (previousItem == null ? item : previousItem);
  var frame;
  if(maxNavWidth == undefined) { // set init values
    maxNavWidth = getTag("nav").clientWidth;
  }
  var navPos = findPos(getTag("nav"), "header");
  //alert("navPos.x="+navPos.x+", navPos.y="+navPos.y);

  if(item.parentNode.parentNode.className=='submenu') { // if item is part of a submenu, and not the top tier
    while(sub != item.parentNode.parentNode) { // if we mouse over item not in last opened div, we will close last
      if(sub) { /////////// only if the object existed
        sub.style.visibility='hidden';
        getTag('hideframe'+x).style.visibility='hidden';
        x--;
        sub=subtree[x];
      }
    }//////////////////////////////////// end close last div if mouseover diff object

    if(getTag(divid)) { // open new submenu if it exhists  |getElementById(subtree[x].id+'sub'+located)|
      sub = getTag(divid);
      if(sub) { /////////////// only if it exists
        x++;
        //alert("subtree[x-1].style.marginLeft=" + parseInt(subtree[x-1].style.marginLeft) + " + " + subtree[x-1].clientWidth + "\n" + (parseInt(subtree[x-1].style.marginLeft) - sub.clientWidth) + "px");
        frame = getTag('hideframe'+x);


        if(!openOnLeft) { // right side
          var temp = (parseInt(subtree[x-1].style.marginLeft) + subtree[x-1].clientWidth + offsetWidth);
          if((temp + sub.clientWidth) > (navPos.x + maxNavWidth)) { // too wide
            openOnLeft = true;
          }
          else {
            sub.style.marginLeft = temp + "px";
            frame.style.marginLeft = temp + "px";
          }
        }
        if(openOnLeft) { // left side
          sub.style.marginLeft = (parseInt(subtree[x-1].style.marginLeft) - (sub.clientWidth + offsetWidth)) + "px";
          frame.style.marginLeft = (parseInt(subtree[x-1].style.marginLeft) - (sub.clientWidth + offsetWidth)) + "px";
        }
        sub.style.marginTop = (parseInt(subtree[x-1].style.marginTop) + item.offsetTop) + "px";
        frame.style.marginTop = (parseInt(subtree[x-1].style.marginTop) + item.offsetTop) + "px";


        sub.style.visibility = 'visible';
        frame.style.visibility = 'visible';
        frame.style.height = sub.clientHeight;
        frame.style.width = sub.clientWidth;
      }
    }/////////////////////// end new submenu /////////////////
  }//////////////////////end if part of a submenu ///////////////////////

  else { ///////////////////////// if item is the top tier, we want to open first drop down
    frame = getTag('hideframe0');
    if(sub != undefined) { // if this is not the first time we open a dropdown
      for(var y = x; y >= 0; y--) { // close all other drop downs
        subtree[y].style.visibility='hidden';
        getTag('hideframe'+y).style.visibility='hidden';
        if(previousItem != item) {
          previousItem.className='navImgNoRo';
        }
      }
      clearhidemenu();
    } /////////////////////////////////////////////////////////////////////
    if(getTag(divid)) {
      sub = getTag(divid);
      var pos = findPos(item, "nav");
      //alert("pos.x="+pos.x+", pos.y="+pos.y);
      var subWidth = sub.clientWidth;
      /*
      pos.x += navPos.x;
      pos.y += navPos.y;
      */
      pos.x = 0;
      pos.y = 0;
      sub.style.marginLeft = pos.x + "px";
      frame.style.marginLeft = pos.x + "px";
      sub.style.marginTop = (pos.y + item.clientHeight) + offsetHeight + "px";
      frame.style.marginTop = (pos.y + item.clientHeight) + offsetHeight + "px";
      if((pos.x + subWidth) > (navPos.x + maxNavWidth)) { // hug right side
        sub.style.marginLeft = (navPos.x + maxNavWidth - subWidth) + "px";
        frame.style.marginLeft = (navPos.x + maxNavWidth - subWidth) + "px";
        openOnLeft = true;
      }
      else {
        openOnLeft = false;
      }

      x = 0;
      sub.style.visibility = 'visible';
      frame.style.visibility = 'visible';
      frame.style.height = sub.clientHeight;
      frame.style.width = sub.clientWidth;
      item.onmouseout=delayhidemenu;
    }
  } /////////////////////// end of top tier dropdown area
  if(sub) {
    subtree[x] = sub;
    sub.onmouseover=clearhidemenu;
    sub.onmouseout=delayhidemenu;
  }
  previousItem = item;
}

function delayhidemenu()
{
  var strx = '';
  strx += "previousItem.className='navImgNoRo',";
  for(var y = x; y >= 0; y--) {
    strx += "subtree["+y+"].style.visibility='hidden',";
    strx += "getTag('hideframe"+y+"').style.visibility='hidden',";
  }
  strx = strx.substring(0,strx.length-1);
  strx = "" + strx + "";
  delayhide=setTimeout(strx,500);
}

function clearhidemenu()
{
  if(typeof delayhide!="undefined") {
    clearTimeout(delayhide);
  }
}






/* Return x/y offset of an object up to a limit container */
function findPos(ctrl, limitId)
{
  var pos = {x:0, y:0};
  if(ctrl.offsetParent) {
    while(ctrl && ctrl.id != limitId) {
      pos.x += ctrl.offsetLeft;
      pos.y += ctrl.offsetTop;
      ctrl = ctrl.offsetParent;
    }
  }
  else if(ctrl.x && ctrl.y) {
    pos.x += ctrl.x;
    pos.y += ctrl.y;
  }
  return pos;
}

/* Check/uncheck all checkboxes in container */
function checkAll(containerId, checkStatus)
{
  checkBoxList = getTag(containerId).getElementsByTagName('INPUT');
  for(var i=0; i<checkBoxList.length; i++) {
    if(checkBoxList[i].type == 'checkbox'){
      checkBoxList[i].checked = checkStatus;
    }
  }
}




/* Search url changer */
var fieldDefValues = [];
var fieldIdList = [];
var search_url = [];
var search_isDate = [];
var search_isScope = []; 
function search_init(name_pre)
{
  var fieldNameList = "|";
  var fieldIdArray = fieldIdList[name_pre].split("|");
  for(var i = 0; i < fieldIdArray.length; i++) { // collect all field names from the input tag name
    var token = fieldIdArray[i];
    if(getTag(fieldIdArray[i]).name) {
      fieldNameList += getTag(fieldIdArray[i]).name + "|";
    }
  }

  var params = "";

  for( var fieldName in fieldDefValues[name_pre] ) {
    var fieldValue = getTag(fieldName).value;
    if(fieldValue != fieldDefValues[name_pre][fieldName] || getTag(fieldName).name == "search") { // not default value
      if((fieldValue.replace(/(^\s*)|(\s*$)/g, "").length > 0 && getTag(fieldName).name) || getTag(fieldName).name == "search") { // if string is more than just spaces
        if(fieldValue == fieldDefValues[name_pre][fieldName]) { // remove default value if it got through
          fieldValue = "";
        }
        else {
          fieldValue = escape(fieldValue.replace(/(^\s*)/g, "").replace(/(\s*$)/g, ""));
          /*
          fieldValue = ((getTag(fieldName).type == "select-one" && (fieldValue.indexOf(" ") >= 0 || fieldValue.indexOf("%20") >= 0)) ? 
            ("\"" + fieldValue + "\"") : 
            fieldValue); // dropdown element, surround with quotes if any spaces
          */
        }
        params += "&" + getTag(fieldName).name + "=" + fieldValue; // trim leading/trailing spaces
      }
    }
  }


  // process from/to dates
  if(search_isDate[name_pre] != undefined && search_isDate[name_pre] == true) {
    var fromDate, toDate;
    fromDate = toDate = "";

    if((temp = getTag(name_pre + "fromDate").value) != "" && temp != fieldDefValues[name_pre][name_pre + "fromDate"] && temp) {
      fromDate = temp.split("/")[2] + temp.split("/")[0] + temp.split("/")[1];
    }

    if((temp = getTag(name_pre + "toDate").value) != "" && temp != fieldDefValues[name_pre][name_pre + "toDate"] && temp) {
      toDate = temp.split("/")[2] + temp.split("/")[0] + temp.split("/")[1];
    }

    if(fromDate.length == 8) {
      params += "&date=@" + fromDate + "_";
      if(toDate.length != 8 || toDate < fromDate) {
        params += "x";
      }
    }

    if(toDate.length == 8 && (fromDate.length != 8 || toDate >= fromDate)) {
      if(fromDate.length != 8) {
        params += "&date=@_";
      }
      params += toDate;
    }
  }


  // process scope
  if(search_isScope[name_pre] != undefined && search_isScope[name_pre] == true) {
    var scope = "";
    var numChecked = 0;
    for(i = 0; i < (temp = document.getElementsByName(name_pre + "scope")).length; i++) {
      if(temp[i].checked) { // checked value
        numChecked++;
        scope += (scope == "" ? "&scope=" : ",") + temp[i].value;
      }
    }
    if(numChecked == temp.length) { // all checked, don't need to individualize
      scope = "";
    }
    params += scope;
  }


  params = (params != "" ? "?" + params.substring(1) : "");

  window.location = search_url[name_pre] + params;
}



/* Paging function */
var pl_pageSelected = [];
var delimiter = "";
function pl_changePage(sectionName2, pageNum, numPages, sectionOid) {
  if(pl_pageSelected[sectionName2] == undefined || pl_pageSelected[sectionName2] == false) { // initialize
    pl_pageSelected[sectionName2] = 1;
  }
  var previousPage = pl_pageSelected[sectionName2];
  var previousPage2 = (previousPage == -1 ? "ShowAll" : previousPage);
  var isSearchPaging = (sectionOid != undefined);
  var oidParam = (isSearchPaging ? ", \"" + sectionOid + "\"" : "");

  if(previousPage2 != pageNum) { // make sure we are doing a page change
    if(pageNum != "ShowAll" &&
        (pageNum == "Previous" && pl_pageSelected[sectionName2] > 1) ||
        (pageNum == "Next" && pl_pageSelected[sectionName2] < numPages) ||
        (pageNum >= 1 && pageNum <= numPages && pageNum != pl_pageSelected[sectionName2])
      ) { // changing pages

      if(previousPage != -1) { // not coming from a "view all"
        // revert old page
        getTag(sectionName2 + "Page" + pl_pageSelected[sectionName2]).innerHTML =
          "<a href='javascript:pl_changePage(\"" + sectionName2 + "\", " + pl_pageSelected[sectionName2] + ", " + numPages + oidParam + ");'>" + delimiter + pl_pageSelected[sectionName2] + delimiter + "</a>";
        if(!isSearchPaging) {
          getTag(sectionName2 + "PageContent" + pl_pageSelected[sectionName2]).style.display = "none";
        }


        // new page, determine which
        pl_pageSelected[sectionName2] =
          (pageNum == "Previous" ? (pl_pageSelected[sectionName2] - 1) :
            (pageNum == "Next" ? (pl_pageSelected[sectionName2] + 1) :
            pageNum)
          );
        getTag(sectionName2 + "Page" + pl_pageSelected[sectionName2]).innerHTML =
          "<a href='javascript:pl_changePage(\"" + sectionName2 + "\", " + pl_pageSelected[sectionName2] + ", " + numPages + oidParam + ");' class='active'>" + delimiter + pl_pageSelected[sectionName2] + delimiter + "</a>";
        if(!isSearchPaging) {
          getTag(sectionName2 + "PageContent" + pl_pageSelected[sectionName2]).style.display = "";
        }
      }
      else { // coming from a "view all", always a specific page number
        /*if(isSearchPaging) {
          WOSWebSearch.hideAll( sectionName2, sectionOid );
        }*/

        getTag(sectionName2 + "ShowAll").innerHTML =
          "<a href='javascript:pl_changePage(\"" + sectionName2 + "\", \"ShowAll\", " + numPages + oidParam + ");'>View All &gt;&gt;</a>";
        pl_pageSelected[sectionName2] = pageNum;
        for(var i = 1; i <= numPages; i++) {
          if(i == pageNum) { // unlink current page
            getTag(sectionName2 + "Page" + i).innerHTML =
              "<a href='javascript:pl_changePage(\"" + sectionName2 + "\", " + i + ", " + numPages + oidParam + ");' class='active'>" + delimiter + i + delimiter + "</a>";
          }
          else { // hide page
            if(!isSearchPaging) {
              getTag(sectionName2 + "PageContent" + i).style.display = "none";
            }
          }
        }
      }

      // load new page
      if(isSearchPaging) {
        WOSWebSearch.pageChanged( pl_pageSelected[sectionName2], sectionName2, sectionOid );
      }

      // Fix previous/next links
      if(pl_pageSelected[sectionName2] <= 1) { // no more previous
        getTag(sectionName2 + "Previous").innerHTML =
          "&lt;&lt; Previous" + delimiter;
      }
      else if((previousPage == -1 || previousPage <= 1) && pl_pageSelected[sectionName2] > 1) { // make previous a link
        getTag(sectionName2 + "Previous").innerHTML =
          "<a href='javascript:pl_changePage(\"" + sectionName2 + "\", \"Previous\", " + numPages + oidParam + ");'>&lt;&lt; Previous</a>" + delimiter;
      }

      if(pl_pageSelected[sectionName2] >= numPages) { // no more next
        getTag(sectionName2 + "Next").innerHTML =
          delimiter + "Next &gt;&gt;";
      }
      else if((previousPage == -1 || previousPage >= numPages) && pl_pageSelected[sectionName2] < numPages) { // make next a link
        getTag(sectionName2 + "Next").innerHTML =
          delimiter + "<a href='javascript:pl_changePage(\"" + sectionName2 + "\", \"Next\", " + numPages + oidParam + ");'>Next &gt;&gt;</a>";
      }
    }
    else if(pageNum == "ShowAll") { // show all pages and unlink
      for(var i = 1; i <= numPages; i++) {
        if(i == previousPage) { // restore linkage to current page
          getTag(sectionName2 + "Page" + i).innerHTML =
            "<a href='javascript:pl_changePage(\"" + sectionName2 + "\", " + i + ", " + numPages + oidParam + ");'>" + delimiter + i + delimiter + "</a>";
        }
        else { // display page
          if(!isSearchPaging) {
            getTag(sectionName2 + "PageContent" + i).style.display = "";
          }
        }
      }

      // load all pages
      if(isSearchPaging) {
        WOSWebSearch.showAll( sectionName2, sectionOid );
      }

      getTag(sectionName2 + "Previous").innerHTML =
        "&lt;&lt; Previous" + delimiter;
      getTag(sectionName2 + "Next").innerHTML =
        delimiter + "Next &gt;&gt;";
      getTag(sectionName2 + "ShowAll").innerHTML =
        "<a href='javascript:pl_changePage(\"" + sectionName2 + "\", \"ShowAll\", " + numPages + oidParam + ");' class='active'>View All &gt;&gt;</a>";
      pl_pageSelected[sectionName2] = -1; // flag that we are showing all
    }
  }
}


/* Check if image is loaded */
function isImageLoaded(img)
{
  if(!img.complete) { // some browsers have built-in load check
    return false;
  }
  if(typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) { // if fail, either should be 0
    return false;
  }
  // No other way of checking: assume it's ok.
  return true;
}



/***************************************** AJAX FUNCTIONS *****************************************/
var xhr = null;
function createXHR(xhrObj) {
  if(xhrObj && xhrObj.readyState < 4 && browser.isGecko) {
    xhrObj.abort(); //needed for FireFox
    xhrObj = null; //needed for FireFox
  }  
  if(!xhrObj) {
    if(window.XMLHttpRequest) {
      // branch for native XMLHttpRequest object - Mozilla
      try {
        xhrObj = new XMLHttpRequest();
      } catch (e) {
        xhrObj = null;
      }
    } else if(window.createRequest) {
      /* For ICEbrowser -- untested.
       * per their site 
       * http://support.icesoft.com/jive/entry.jspa?entryID=471&categoryID=21
       * There are a number of restrictions on the implementation.
       */
      try {
        xhrObj = window.createRequest();
      }
      catch(e) {
        xhrObj = null;
      }
    } else if(window.ActiveXObject) {
      // branch for IE/Windows ActiveX version
      try {
        xhrObj = new ActiveXObject("Msxml2.XMLHTTP");
      } catch(e) {
        try{
          xhrObj = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(e) {
          xhrObj = null;
        }
      } //catch
    } //if-else
  }

  return xhrObj;
}
