function foo() {
  alert('foo');
}

// add two values together, for example 10px 20px or 8em 9em, and return the numeric value and units
// assumed the units are both the same

function addCSSUnits(x,y) {
  return((parseInt(x)+parseInt(y))+x.substr(x.length-2));
}

// return the width of an object in a stylesheet

function CSSWidth(obj) {
  if (obj==null)
    return "0px";
  if (obj.currentStyle)
    return obj.currentStyle.width;
  else
    if (window.getComputedStyle)
      return getComputedStyle(obj,"").width;
    else
      return("-");
}

// find elements of a given tag and classname (for example tables with the 'listtable' class)

function getTagAndClass(tagName,className) {
  var matches=new Array;
  var tagelems=document.getElementsByTagName("table");
  var count=0;
  for (var i=0; i<tagelems.length; i++) {
    if (tagelems[i].className==className) {
      matches[count]=tagelems[i];
      count++;
    }
  }
  return(matches);
}

function formatTables() {
  var listtables=getTagAndClass('table','listtable');
  for (var i=0; i<listtables.length; i++) {
    var rows=listtables[i].getElementsByTagName('tbody')[0].getElementsByTagName('tr');
    for (j=0; j<rows.length; j++)
      if (j%2==1)
        rows[j].className='shaded';
  }
}

function isURILocal(uri) {
  var thisloc=location.protocol+"//"+location.host;
  return (uri.substring(0,thisloc.length)==thisloc);
}

// Remove everything after the ? in a URL

function trimParams(uri) {
  return(uri.split("?")[0]);
}

function getParamValue(uri,paramName) {
  var p=uri.indexOf("?");
  if (p==-1)
    return('');
  else {
    var params=uri.substring(p+1).split('&');
    for (var i=0; i<params.length; i++) {
      nameValue=params[i].split("=");
      if (nameValue[0]==paramName)
        return(nameValue[1]);
    }
  }
  return('');
}

// Test whether a URI is for a type of non-HTML resource that we want to track
// or if the URL is not a local one
// It assumes the URL up to the ? ends with .<file-ext>

function isNonHTMLButInteresting(uri) {  
  var validExtensions="gif pdf avi doc mp3 pps ppt wav wmv"; 
  var extns=validExtensions.split(" ");
  var foundextn=false;
  uri=uri.toLowerCase();
  for (var i=0; i<extns.length && !foundextn; i++) {
    foundextn=uri.substring(uri.length-extns[i].length-1)=="."+extns[i];
  }
  return foundextn;
}

// For links that aren't HTML, add behaviour to launch in a new window/tab
// Also set them up to call the appropriate webtrends DCS function to
// indicate it was clicked, and passing campaign ID if there is one

function addBehaviourToLinks() {
  var links=document.getElementsByTagName('a');
  for (var i=0; i<links.length; i++) {
    if (isNonHTMLButInteresting(trimParams(links[i].href))) {
      addEvent(links[i],'click',handleNonHTMLLink);
      links[i].target="_blank"; // Make it appear in a separate window/tab since it is not HTML content
      if (links[i].title=="")
        links[i].title="This link will open in a separate browser window";
      else
        links[i].title=links[i].title + " - This link will open in a separate browser window";
    } else {
     if (!isURILocal(trimParams(links[i].href)) && (links[i].href.substring(0,11)!="javascript:"))
         addEvent(links[i],'click',handleNonHTMLLink);
//        links[i].target='';
    }
  }
}

// Find the path part after the host in http://<hostname>/path/ type links

function getPathFromURI(uri) {
  uri.substring(uri.indexOf("/",uri.indexOf("/")+2));
}

function handleNonHTMLLink() {
  var contents=this.childNodes;
  var text="";
  for (var i=0; i<contents.length; i++) {
    if (contents[i].tagName=='IMG')
      text=text + contents[i].alt;
    if (contents[i].nodeType==3) // a text node
      text=text+contents[i].nodeValue;
  }
  var url=this.href;
  if (isURILocal(url))		// Remove the hostname if it is a local link, otherwise leave it in
    url=url.substring(url.indexOf("/",8));
  var mc_id=getParamValue(url,'WT.mc_id');
  if (mc_id=="")
    dcsMultiTrack('DCS.dcsuri',trimParams(url),'WT.ti',text);
  else
    dcsMultiTrack('DCS.dcsuri',trimParams(url),'WT.ti',text,'WT.mc_id',mc_id);    

  // If it is a non-HTML link then open it in a trimmed-down new window
  
  //if (isNonHTMLButInteresting(trimParams(url))) {
  //  window.open(trimParams(url),'','menubar=yes, toolbar=no, location=no, directories=no, status=no, resizable=yes');
  //  return(false);
  //}
}

// dummy function that can be removed when the homepage no longer calls it

function setOnload() {
}

// Add an event listener to the window's load event to call setupPage()
// This is better than setting onLoad explicitly as this can be done multiple times

addEvent(window, 'load', setupPage);

// Function that adds all the fun behaviour

function setupPage() {
  // Format tables, for example highlight alternate rows for
  // 'listtable' class lists
  
  formatTables();

  // Add behaviour for
  addBehaviourToLinks();
  
  /* Set up the layout - do this by seeing which of the main page
     elements 'tertiary' & 'sidelinks' (left menu and links below it),
     'mainbody' (main content area), and 'rightcolumn' have content.
     It then sets the appropriate class for the 'mainbody' wrapper div.
     This will set empty columns to not display or take up space
     and for the main body element to resize appropriately.
  */
  /* commented out by JB on 28/1/2008
  var pb=document.getElementById('pagebody');
  var mb=document.getElementById('mainbody');
  var tert=document.getElementById('tertiary');
  var slink=document.getElementById('sidelinks');
  var nosidebar=(tert==null && slink==null);
  var sb=document.getElementById('sidebar');
  var rc=document.getElementById('rightcolumn');
  var norightbar=(rc==null ||  rc.childNodes.length==0 || (rc.childNodes.length==1 && rc.childNodes[0].nodeType==3));
  if (nosidebar)
    if (norightbar)
      pb.className='pb_fullwidth';
    else
      pb.className='pb_noleft';
  else
    if (norightbar)
      pb.className='pb_noright';
    else
      pb.className='pb_threecols';
  rotateImages('rotator',8000);
  */
}

/* Code for producing breadcrumbs

   It iterates through the drop down menus, finding <a> tags, 
   keeping track of what the breadcrumbs would look like to that link.
   
   It compares the current page's URL to each menu option, looking ideally for an exact match.
   If it can't find an exact match, it chooses the menu link whose URL has the most in common
   with the current URL.
   
   For example, if the current URL is /products/artix/features.htm, then
   /products/ and /products/artix/ would both match but the latter would be a better match
   
   If no menu option has anything in common with the URL, e.g. /mtositoolkit/ might not
   match any menu option, then only 'Home' is displayed.
   
*/

var myURL=location.pathname;
var bestMatch='/';
var bestBreadcrumbs='<a href="/www_iona_com/">Home</a>';

function printBreadcrumbs() {
  var men=document.getElementById('dropdownmenu');
  handleDiv(men,'<a href="/www_iona_com/">Home</a>');
  document.write(bestBreadcrumbs);
//  document.write(parseTags(men,''));
}

// Handle a <ul> tag - assume it only has <li> subelements

function handleList(ul,prefix) {
  for (var i=0; i<ul.childNodes.length; i++) {
    handleListelem(ul.childNodes[i],prefix);
  }
}

// Handle a <div> or other container HTML tag
// Basically ignore it, and look for it's descendants till a <ul> is found

function handleDiv(div,prefix) {
  for (var i=0; i<div.childNodes.length; i++) {
    if ("DIV TABLE TBODY TR TD".indexOf(div.childNodes[i].tagName)!=-1) {
      handleDiv(div.childNodes[i],prefix);
    }
    if (div.childNodes[i].tagName=='UL')
      handleList(div.childNodes[i],prefix);
  }
}

// Handle an <li> - will have a <a>, followed by potentially a submenu in the form of a <div>

function handleListelem(li, prefix) {
  var listtext='';
  for (var i=0; i<li.childNodes.length; i++) {
    if (li.childNodes[i].tagName=='A') {
      prefix=handleLink(li.childNodes[i],prefix);
    }
    var boringelements='DIV TABLE TBODY TR TD';
    if (boringelements.indexOf(li.childNodes[i].tagName)!=-1)
      handleDiv(li.childNodes[i],prefix);
  }
}

// Handle a <a> - first ensure it begins with a /
// Then iterate over its child nodes looking for the text
// Add this link to the breadcrumbs that were passed into it
// Check if the current page URL begins with the URL of the current menu option
// If it does, compare it with the best match found so far, if it's longer
// (and thus a better match), replace the current best breadcrumbs with these ones.

function handleLink(a,prefix) {
  var url=a.pathname;
  if (url.charAt(0)!='/')
    url='/' + url;
  var linkText;
  for (var i=0; i<a.childNodes.length; i++) {
    if (a.childNodes[i].nodeType==3)
      linkText=a.childNodes[i].data;
  }
  var html=prefix + ' &gt; <a href="' +url + '">' + linkText + '</a>';
  if (myURL.indexOf(url)==0 && url.length>bestMatch.length) {
    bestMatch=url;
    bestBreadcrumbs=html;
  }
  return html;
}

// Show a parse tree of a given HTML node and its children

function parseTags(node,indent) {
  var s=indent;
  if (node.nodeType==3)
    s=s+"text:" + node.data + "<br />\n";
  else
    s=s+node.nodeType + "-" + node.tagName+"<br />\n";
  for (var i=0; i<node.childNodes.length; i++) {
      s=s+parseTags(node.childNodes[i],indent+'.');
  }
  return s;
}


  var rotimages=new Array;
  var roturls=new Array;

  function setOpac(imgid,opac) {
    var img=document.getElementById(imgid);
    img.style.opacity=opac/100;
	img.style.filter="alpha(opacity="+opac+")";
    img.style.MozOpacity=opac/100;
    img.style.KhtmlOpacity=opac/100;
  }

  function changeImage(id,filename,newurl,alt) {
    var div=document.getElementById(id);
    setOpac(id+"_img",100);
    div.style.backgroundImage="url(" + filename +")";
    for (var i=100; i>=0; i=i-10) {
      setTimeout("setOpac('" + id + "_img',"+i+")",(100-i)*10);
      if (i==50) {
        div.getElementsByTagName('a')[0].href=newurl;
        document.getElementById(id + "_img").alt=alt;
      }
    }
    setTimeout("document.getElementById('" + id + "_img').src='" + filename + "'",1000);
  }

   function rotateImages(id,delay) {
     var linkid,image;
     var logodiv=document.getElementById('hiddenlogos');
     if (logodiv) {
       var links=logodiv.getElementsByTagName('a');
       for (var i=0; i<30; i++) {
         linkid=i%links.length;
         image=links[linkid].getElementsByTagName('img')[0];
         setTimeout("changeImage('" + id + "','" + image.src + "','" + links[linkid].href+ "','" + image.alt + "')",(i+1)*delay);         
       }
     }
   }

/* Function to add a listener to an object in the DOM

   Needs two versions so it works on all browsers */

function addEvent(obj, evType, fn){ 
 if (obj.addEventListener){ 
   obj.addEventListener(evType, fn, false); 
   return true; 
 } else if (obj.attachEvent){ 
   var r = obj.attachEvent("on"+evType, fn); 
   return r; 
 } else { 
   return false; 
 } 
}