/* v.1.26 bl: Changed AP and ADRAC other resources link to - 'Australian Prescriber (includes Medicines Safety Update)' and 'ADRAC (see also Australian Prescriber for Medicines Safety Update)' */
/* v.1.25 bl: Changed CE other resources link to - Clinical evidence (subscription required) */
/* v.1.24 rwh: Fix PBS buttons in WebKit based browsers */
/* v.1.23 rwh: Add topic and chapter reference functionality */
/* v.1.22 rwh: reduce the width of the submenu slightly to avoid scrollbars. */
/* v.1.21 rwh: comment out conditional in findPos so that menus pop up correctly in tables in IE */
/* v.1.20 rwh: Added space_to_underscore to convert spaces to underscores in the filenames passed to writedruginfomenu and writedruginfomenu2 */
/* v.1.19 Changed writeresource to display references. Displays as a dropdown hyperlink */
/* v.1.18 Changed showsubmenu and added findPos and findLeft. Allows placement of i buttons in tables */
/* v.1.17 Changed 'further reading' to 'Other resources' */
/* v.1.16 Added NPS News and NPS RADAR to the list of further reading resources */
/* v.1.15 Added an exception handler to transforfile - alerts when an include file not found */
/* v.1.14 Added writeresource - creates the Further reading table if needed. uses previous routines to do so. Works in IE and ff (with switch) */
/* v.1.13 Modified writedruginfomenu2 to revert to writedruginfomenu, when there is no 'reg' object */
/* v.1.12 Added writelink, moving the writeap, etc. functions to a generic set */
/* v.1.11 Added writedruginfomenu2, an attempt to allow for different routes, further modifying i button display */
/* v.1.10 Changes to display sub menus under each code type category */
/* v.1.9 Small fix allowing instertion of i buttons in a table - needed to account for the abscence of a drug in a regimen */
/* v.1.8 released 01/2006 */
/* v.1.8 Works in Mac (moz) */
/* v.1.7 Bug fix - when a drug name is not found in a regimen it is not highlighted, but the DI div will still display */
/* v.1.6 Bug fix - allowing multiple re-selections of DI DIVs */
/* v.1.5 Allowed 'compiler instructions' for framed and non-framed versions of the script */
/* v.1.4 Added function for drug resources - search for deployment changes */
/* v.1.3 Added writeap : Australian Prescriber */
/* v.1.2 Assigning td.furtherreading dynamically during writecochrane */
/* v.1.1 Lowercased the /cochrane directory */
/* v.1 Release with eTG15, July 2005. Accomodates PBS and Cochrane links */

bgMOver = '#FFFF99'
bgDisplay = '#E6E6E6'
itemWidth = 290
itemInset = 100
itemDownset = 14
nodeGap = 2
var gbIE5=true
//var gAgent
var gbMac=false

/* For non-framed files, include this segment */
var gAgent=navigator.userAgent.toLowerCase();
var gbMozilla=((gAgent.indexOf('gecko')!=-1) && (gAgent.indexOf('netscape')==-1));
var gbIE6= true
if (gbMozilla)
  gbIE6 = false


/* For framed files, include this segment */
//var gbIE6

  
function showtitle(e)
//appends an elements title to its content
{
  var gbIE6=false

  if (gbIE5)
  { 
    var nPos=gAgent.indexOf("msie")
    var nVersion=parseFloat(gAgent.substring(nPos+5));
    if(nVersion>=6)
      gbIE6=true;
  }

  if (gbIE6)
  {
    sp = event.srcElement
  }
  else if (gbMozilla)
  {
    sp = e.target
  }
 
  if (sp.style.color != 'black')
  { 
    sp.innerHTML = sp.innerHTML+': '+sp.title
    sp.style.color = 'black'
    sp.style.textDecoration = 'none'
  }
}

function showMenu(e,linkname)
{
//Highlight the root, get its pos
  var gbIE6=false

  if (gbIE5)
  { 
    var nPos=gAgent.indexOf("msie")
    var nVersion=parseFloat(gAgent.substring(nPos+5));
    if(nVersion>=6)
      gbIE6=true;
  }

  if (gbIE6)
  {
    sp = document.getElementById(event.srcElement.id+'disp')
    if (sp.style.display != 'block')
    {
      s = transformfile('../../PBS/'+linkname+'.xml', '../../scripts/wholePBS.xsl')
      sp.innerHTML = s
      sp.style.display = 'block'
      sp.parentNode.parentNode.style.display = 'block'
    }
    else
    {
      sp.style.display = 'none'
      sp.parentNode.parentNode.style.display = 'none'
    }
  }
  else if (gbMozilla)
  {
    sp = document.getElementById(e.target.id+'disp')
    if (sp.style.display != 'block')
    {
      mozTransform("../../PBS/"+linkname, e.target.id+'disp', "../../scripts/wholePBS.xsl")
      sp.style.display = 'block'
//      sp.parentNode.parentNode.style.display = 'block'
    }
    else
    {
      sp.style.display = 'none'
//      sp.parentNode.parentNode.style.display = 'none'
    }
  }
  else if (gbMac)
    alert('On Macintosh computers, this information currently only displays on Mozilla and Firefox.')
  else
    alert('You are using an old browser. You will need to upgrade to at least Internet Explorer v.6, Mozilla v.1.6 or Firefox v.1.0 to view PBS information.')
}

function showrows(e,linkname, dirname)
{
//Highlight the root, get its pos
  var gbIE6=false

  if (gbIE5)
  { 
    if (gAgent = 'undefined')
    {    
      gbIE6 = true
    }
    else
    {
      var nPos=gAgent.indexOf("msie")
      var nVersion=parseFloat(gAgent.substring(nPos+5));
      if(nVersion>=6)
        gbIE6=true;
    }
  }

  if (gbIE6)
  {
    sp = document.getElementById(event.srcElement.id+'disp')
    if (sp.style.display != 'block')
    {
      s = transformfile('../../'+dirname+'/'+linkname+'.xml', '../../scripts/'+dirname+'.xsl')
      sp.innerHTML = s
      sp.style.display = 'block'
      sp.parentNode.parentNode.style.display = 'block'
      if (e.target) im = e.target
      else im = event.srcElement
      im.style.backgroundImage = 'url(../../scripts/dash.png)'
    }
    else
    {
      sp.style.display = 'none'
      //sp.parentNode.parentNode.style.display = 'none'
      if (e.target) im = e.target
      else im = event.srcElement
      im.style.backgroundImage = 'url(../../scripts/plus.png)'
    }
  }
  else if (gbMozilla)
  {
    sp = document.getElementById(e.target.id+'disp')
    if (sp.style.display != 'block')
    {
//      sp.innerHTML = 'hi'
      mozTransform('../../'+dirname+'/'+linkname, e.target.id+'disp', '../../scripts/'+dirname+'.xsl')
      sp.style.display = 'block'
      if (e.target) im = e.target
      else im = event.srcElement
      im.style.backgroundImage = 'url(../../scripts/dash.png)'
    }
    else
    {
      sp.style.display = 'none'
      if (e.target) im = e.target
      else im = event.srcElement
      im.style.backgroundImage = 'url(../../scripts/plus.png)'
    }
  }
  else if (gbMac)
    alert('On Macintosh computers, this information currently only displays on Mozilla and Firefox.')
  else
    alert('You are using an old browser. You will need to upgrade to at least Internet Explorer v.6, Mozilla v.1.6 or Firefox v.1.0 to view PBS information.')
}

function showrows2(e,linkname, dirname)
{
//Highlight the root, get its pos

  var gbIE6

  if ((gbIE5) && (!gbMozilla))
  { 
    if (gAgent = 'undefined')
    {    
      gbIE6 = true
    }
    else
    {
      var nPos=gAgent.indexOf("msie")
      var nVersion=parseFloat(gAgent.substring(nPos+5));
      if(nVersion>=6)
        gbIE6=true;
    }
  }

  if (gbIE6)
  {
    sp = document.getElementById(event.srcElement.id+'disp')
    if (sp.style.display != 'block')
    {
      s = transformfile(linkname, '../../scripts/'+dirname+'.xsl')
      sp.innerHTML = s
      sp.style.display = 'block'
      sp.parentNode.parentNode.style.display = 'block'
      if (e.target) im = e.target
      else im = event.srcElement
      im.style.backgroundImage = 'url(../../scripts/dash.png)'
    }
    else
    {
      sp.style.display = 'none'
      //sp.parentNode.parentNode.style.display = 'none'
      if (e.target) im = e.target
      else im = event.srcElement
      im.style.backgroundImage = 'url(../../scripts/plus.png)'
    }
  }
  else if (gbMozilla)
  {
    sp = document.getElementById(e.target.id+'disp')
    if (sp.style.display != 'block')
    {
//      sp.innerHTML = 'hi'
      mozTransform2(linkname, e.target.id+'disp', '../../scripts/'+dirname+'.xsl')
      sp.style.display = 'block'
      if (e.target) im = e.target
      else im = event.srcElement
      im.style.backgroundImage = 'url(../../scripts/dash.png)'
    }
    else
    {
      sp.style.display = 'none'
      if (e.target) im = e.target
      else im = event.srcElement
      im.style.backgroundImage = 'url(../../scripts/plus.png)'
    }
  }
  else if (gbMac)
    alert('On Macintosh computers, this information currently only displays on Mozilla and Firefox.')
  else
    alert('You are using an old browser. You will need to upgrade to at least Internet Explorer v.6, Mozilla v.1.6 or Firefox v.1.0 to view PBS information.')
}

function mozTransform(xmlFN, elID, xslFN)
{
var xslStylesheet;
var xsltProcessor = new XSLTProcessor();
var myDOM;

var xmlMoz;

  // load the xslt file
  var myXMLHTTPRequest = new XMLHttpRequest();
  myXMLHTTPRequest.open("GET", xslFN, false);
  myXMLHTTPRequest.send(null);
  xslStylesheet = myXMLHTTPRequest.responseXML;
  xsltProcessor.importStylesheet(xslStylesheet);

  // load the xml file
  myXMLHTTPRequest = new XMLHttpRequest();
  myXMLHTTPRequest.open("GET", xmlFN+".xml", false);
  myXMLHTTPRequest.send(null);
  xmlMoz = myXMLHTTPRequest.responseXML;

  var fragment = xsltProcessor.transformToFragment(xmlMoz, document);

  document.getElementById(elID).innerHTML = "";

  myDOM = fragment;
//  document.getElementById(elID).appendChild(fragment.lastChild);
  document.getElementById(elID).appendChild(fragment);
}

function mozTransform2(xmlFN, elID, xslFN)
//Same as 1, except '.xml' is added to the parameter name. Prev version retained for backward compatibility
{
var xslStylesheet;
var xsltProcessor = new XSLTProcessor();
var myDOM;

var xmlMoz;

  // load the xslt file
  var myXMLHTTPRequest = new XMLHttpRequest();
  myXMLHTTPRequest.open("GET", xslFN, false);
  myXMLHTTPRequest.send(null);
  xslStylesheet = myXMLHTTPRequest.responseXML;
  xsltProcessor.importStylesheet(xslStylesheet);

  // load the xml file
  myXMLHTTPRequest = new XMLHttpRequest();
  myXMLHTTPRequest.open("GET", xmlFN, false);
  myXMLHTTPRequest.send(null);
  xmlMoz = myXMLHTTPRequest.responseXML;

  var fragment = xsltProcessor.transformToFragment(xmlMoz, document);

  document.getElementById(elID).innerHTML = "";

  myDOM = fragment;
//  document.getElementById(elID).appendChild(fragment.lastChild);
  document.getElementById(elID).appendChild(fragment);
}

function mozTransformtostr(xmlFN, elID, xslFN)
{
var xslStylesheet;
var xsltProcessor = new XSLTProcessor();
var myDOM;

var xmlMoz;

  // load the xslt file
  var myXMLHTTPRequest = new XMLHttpRequest();
  myXMLHTTPRequest.open("GET", xslFN, false);
  myXMLHTTPRequest.send(null);

  xslStylesheet = myXMLHTTPRequest.responseXML;
  xsltProcessor.importStylesheet(xslStylesheet);

  // load the xml file
  try
  {
	myXMLHTTPRequest = new XMLHttpRequest();
	myXMLHTTPRequest.open("GET", xmlFN, false);
	myXMLHTTPRequest.send(null);
	xmlMoz = myXMLHTTPRequest.responseXML;

	var fragment = xsltProcessor.transformToFragment(xmlMoz, document);
//  document.getElementById(elID).innerHTML = "";

//  myDOM = fragment;
//  document.getElementById(elID).appendChild(fragment.lastChild);
	return fragment.textContent
  }
  catch (e) 
  {
	return 'XML file not found - "'+xmlFN+'"'
  }


}


function showItem(item, posLeft, posTop, root, itemNum)
{
  removeItem(item)
  var childpos
  var spnew = document.createElement("span")
  var itemHeight

  spnew.id = item.getAttributeNode("id").value;
//  if (item.childNodes.length != 1)
    spnew.className="PBSNode"
//  else
//    spnew.className="pbsnodeleaf"
  spnew.title = 'Click to copy text'
  
 // try
  {
    if (item.getAttributeNode("DRUG_TYPE_CODE"))
    {      
      if (item.getAttributeNode("DRUG_TYPE_CODE").value == 'GE')
      {
        spnew.className = spnew.className+'GE'
        spnew.title = 'General'+' - '+spnew.title
      }
      else if (item.getAttributeNode("DRUG_TYPE_CODE").value == 'DB')
      {
        spnew.className = spnew.className+'DB'
        spnew.title = "Doctor's bag"+' - '+spnew.title
      }
      else if (item.getAttributeNode("DRUG_TYPE_CODE").value == 'HS')
      {
        spnew.className = spnew.className+'HS'
        spnew.title = 'Highly specialised'+' - '+spnew.title
      }
      else if (item.getAttributeNode("DRUG_TYPE_CODE").value == 'R1')
      {
        spnew.className = spnew.className+'R1'
        spnew.title = 'Repatriation'+' - '+spnew.title
      }
      else if (item.getAttributeNode("DRUG_TYPE_CODE").value == 'DT')
      {
        spnew.className = spnew.className+'DT'
        spnew.title = 'Dental'+' - '+spnew.title
      }
      
      
      //      spnew.className = spnew.className+item.getAttributeNode("DRUG_TYPE_CODE").value
//      spnew.title = spnew.className
    }
  }
  //catch (e) {alert('hi')}
  
//  if ((posLeft+itemWidth) > (document.body.offsetWidth))
//    posLeft  = posLeft - 200

  spnew.style.left = posLeft;
  itemHeight = getNodeHeight(item.childNodes.item(0).text)
//  spnew.innerText = itemNum+':'+posTop+'-'+itemHeight+'-'+(itemHeight+posTop)+item.childNodes.item(0).text
  spnew.innerText = spnew.innerText+item.childNodes.item(0).text

//  alert(spnew.innerText)
  spnew.style.top = posTop;

  spnew.height = itemHeight
//  alert(spnew.height)
  document.body.appendChild(spnew)  
//  alert(spnew.height)

  if (root)
  {
    spnew.style.display = 'block'
    createClear(posTop+spnew.height, posLeft+itemWidth, spnew.innerText)
    createHelp(posTop+spnew.height+spnew.height, posLeft)
  }
  else
    spnew.style.display = 'none'
  
  spnew.style.zIndex = 1
  spnew.onmouseover = showChildren
  spnew.onmouseout = hideChildren
  spnew.onmousedown = copytext
  //posTop = posTop+getNodeHeight(spnew.innerText)+(itemNum*20)
  
  childpos = 0
  //Downset the child nodes
  posTop = posTop+getNodeHeight('one line')

  //create children
  for (var i=0; i < item.childNodes.length; i++)
  {    
    if (item.childNodes.item(i).nodeType == 1)
    {
      sibHeight = showItem(item.childNodes.item(i), posLeft-itemInset, posTop, false, childpos)
      posTop = posTop+sibHeight
//      alert(posTop+'-'+itemHeight+'-'+(itemHeight+posTop))
      childpos = childpos+1
    }
  }
  
  //Hide all except root
  if (root)
  {
    for (var i=0; i < item.childNodes.length; i++)
    {
      hideMe(item.childNodes.item(i))
    }
  }
  
  return itemHeight
}

function createClear(posTop, posLeft, name)
{
    //create clear button
  removeElement('close')
  var spclr = document.createElement("span")
  spclr.style.display = 'block'
  spclr.id = 'clear';
  spclr.name = name;
  spclr.style.top = posTop;
  spclr.style.left = posLeft-90;
  spclr.style.width = 70;
  spclr.innerText = 'Full PBS listing'
  spclr.height = getNodeHeight(spclr.innerText)
  spclr.title = 'Click to display full PBS listing'
  spclr.className="pbsclear"
  spclr.onmousedown = fulllisting
  document.body.appendChild(spclr)
}

function createHelp(posTop, posLeft)
{
    //create clear button
  removeElement('help')
  var spclr = document.createElement("span")
  spclr.style.display = 'block'
  spclr.id = 'help';
  spclr.style.top = posTop;
  spclr.style.left = posLeft;
  spclr.style.width = 80;
  spclr.innerText = "What's this?"
  spclr.height = getNodeHeight(spclr.innerText)
  spclr.className="pbsclear"
  spclr.onmousedown = clearMenu
  document.body.appendChild(spclr)
}

function copytext()
{
  sp = document.getElementById(event.srcElement.id)
  window.clipboardData.setData("Text",sp.innerText)
  window.status="'"+sp.innerText+ "' copied to clipboard."
}

function clearMenu()
{
  removeElement('spDisp');
  removeElement('clear')
  removeElement('help')
  removeMe(xmlMenu.documentElement.childNodes.item(0))
//  hideMe(xmlMenu.documentElement.childNodes.item(0))
}

function fulllisting()
{
  clearMenu()
  try
  {
    removeElement('full')
  }
  catch(e) {}

  alert('sp'+event.srcElement.id)
  sp = document.getElementById('sp'+event.srcElement.id)
//  sp.style.backgroundColor = 'red'

/*  var sp = document.createElement("span")
  sp.style.display = 'block'
  sp.id = 'full';
  sp.style.top = document.body.scrollTop + 5;

  sp.style.left = 50;
  sp.innerText = "full list"
  sp.className="pbsfull"
  sp.name = event.srcElement.name
  sp.onmousedown = clearMenu
  document.body.appendChild(sp)


  s = transformfile(sp.name+'.xml', '../xsl/wholePBS.xsl')
  sp.innerHTML = s
  document.body.appendChild(sp) */
}

function clearfull()
{
  removeElement('full')
}

function getNodeHeight(str)
{
  if (str.length < 44)
    r = 13
  else if (str.length < 88)
    r = 26
  else if (str.length < 132)
    r = 39
  else if (str.length < 186)
    r = 52
  else if (str.length < 220)
    r = 65
  else if (str.length < 264)
    r = 78
  else if (str.length < 308)
    r = 91
  else 
    r = 104
//  alert(str+'-'+r)
  return r+nodeGap
}

function removeMe(item)
{
  for (var i=0; i < item.childNodes.length; i++)
  {
    if (item.childNodes.item(i).nodeType == 1)
      removeMe(item.childNodes.item(i))
  }
  removeItem(item)
}

function removeItem(item)
{
  removeElement(item.getAttributeNode("id").value)
}

function removeElement(name)
{
  try
  {
    el = document.getElementById(name)
    document.body.removeChild(eval(name))
  }
  catch (e) {}
}

function showChildren()
{
  var curXItem
  sp = document.getElementById(event.srcElement.id)
  sp.style.backgroundColor = bgMOver
  strCurr = sp.innerText
  pZindex = sp.style.zIndex

  //currXItem = getXMLItemById(xmlMenu.documentElement.childNodes.item(0), event.srcElement.id)
  nodes = xmlMenu.getElementsByTagName('item')
  for (var i=0; i < nodes.length; i++)
  {
//    alert(event.srcElement.id +'-'+ nodes.item(i).getAttributeNode("id").value)
    if (event.srcElement.id == nodes.item(i).getAttributeNode("id").value)
      currXItem = nodes.item(i)
  }


//display the child items
  for (var i=0; i < currXItem.childNodes.length; i++)
  {
    if (currXItem.childNodes.item(i).nodeType == 1)
    {
      sp = document.getElementById(currXItem.childNodes.item(i).getAttributeNode("id").value)
      sp.style.zIndex = pZindex+1
      sp.style.display = 'block'
      sp.style.backgroundColor = bgMOver
      }
  }

//hide cousins
  for (var i=0; i < currXItem.parentNode.childNodes.length; i++)
  {
    if (currXItem.parentNode.childNodes.item(i).nodeType == 1)
    {
      uncle = currXItem.parentNode.childNodes.item(i)
      //alert(uncle.getAttributeNode("id").value +'-'+ currXItem.getAttributeNode("id").value)
      if (uncle.getAttributeNode("id").value != currXItem.getAttributeNode("id").value)
      {
        for (var j=0; j < uncle.childNodes.length; j++)
        {
          hideMe(uncle.childNodes.item(j))
          sp = document.getElementById(uncle.getAttributeNode("id").value)
          sp.style.backgroundColor = bgDisplay  
        }
      }
    }
  }

//display text in temp span
  dispTempSpan(strCurr)  
}

function dispTempSpan (text)
{
//create a display span
  removeElement('spDisp')
  var spdisp = document.createElement("span")

  spdisp.id = 'spDisp'
  spdisp.className="pbsdisplay"
  spdisp.style.top = posTop-(40+(getNodeHeight(text)));
  spdisp.innerText = ''
  spdisp.style.left = posLeft-100
  //spdisp.style.display = 'block'
  
  spdisp.style.zIndex = 0
  document.body.appendChild(spdisp)
  spdisp = document.getElementById('spDisp')
  spdisp.innerText = strCurr

}

function hideMe(me)
{
  /*Hide me and my children */
  if (me.nodeType == 1)
  {
    sp = document.getElementById(me.getAttributeNode("id").value)
    sp.style.display = 'none'
    for (var i=0; i < me.childNodes.length; i++)
    {
      hideMe(me.childNodes.item(i))
    }
  }
}

function hideChildren()
{
  var i
  sp = document.getElementById(event.srcElement.id)
  sp.style.backgroundColor = bgDisplay
/*  nodes = xmlMenu.getElementsByTagName('item')
  for (var i=0; i < nodes.length; i++)
  {
    if (event.srcElement.id == nodes.item(i).getAttributeNode("id").value)
      currXItem = nodes.item(i)
  }

  for (var i=0; i < currXItem.childNodes.length; i++)
  {
    //alert(currXItem.childNodes.item(i).nodeType)
    if ((currXItem.childNodes.item(i).nodeType == 1))
      if (noChildDisplay(currXItem))
      {
        sp = document.getElementById(currXItem.childNodes.item(i).getAttributeNode("id").value)
//      sp.style.display = 'block'
        sp.style.backgroundColor = 'green'
      }
        
  }*/
}

function newWindow(win_url,win_name,win_features,set_parent, strDisplay) {
       if (navigator.appName.indexOf("Microsoft")>=0) {
          win_features+=',left=200,top=200'
        }else{
          win_features+=',screenX=200,screenY=200'
        }

  var new_win
  
  new_win=window.open(win_url, win_name, win_features)
  new_win.focus()
  if (set_parent==1) {
    new_win.par=self
  }
  new_win.document.write(strDisplay)
  return new_win
}

function transformfile(xmlF, xslF)
{
// Load XML 
  if (!gbMozilla)
  {
  var xml = new ActiveXObject("Microsoft.XMLDOM")
  xml.async = false
  xml.load(xmlF)
  if (xml.childNodes.length != 0)
  {
// Load XSL
    var xsl = new ActiveXObject("Microsoft.XMLDOM")
    xsl.async = false
    xsl.load(xslF)

// Transform
    try
    {
    	str = xml.transformNode(xsl)
    }
    catch(e) {
      alert(e.message)
      str = 'Error - an include file not found when using: '+xslF
    }
	
  }
  else
  {
    str = 'XML file not found - "'+xmlF+'"'
  }
  }
  else
  {
    str = mozTransformtostr(xmlF, 'tdcochrane', xslF)
  }
  return str;
}

function max() 
{
  s = transformfile(full.name+'.xml', '../xsl/wholePBS.xsl')
  newWindow('','new_frame', 'width=700,height=800,menubar=0,toolbar=0,scrollbars=1,status=0,location=0,resizable=1',0, s)
  clearMenu()
}

function fullheight(sp)
{
//  sp = event.srcElement
  if (gbMozilla)
    sp.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.height = '100%'
  else
  {
    disp = sp.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode
    disp.style.height = '100%'
  }
}

function shortheight(sp)
{
//  sp = event.srcElement
  if (gbMozilla)
    sp.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.height = 200
  else
  {
    disp = sp.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode
    disp.style.height = 200
  }
}

function closedisp(e, direction)
{
  if (e.target) sp = e.target
  else sp = event.srcElement
  if ((direction == undefined) || (direction ==1))
  {
    if (gbMozilla)
      sp.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.display = 'none'
    else
    {
      sp.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.display = 'none'
      table = sp.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode
      table.childNodes[0].childNodes[1].childNodes[0].childNodes[0].style.backgroundColor = '#f0f0f0'
    }
  }
  else if (direction == -1)
  {
    sp = event.srcElement
    disp = sp.parentNode.parentNode.parentNode.parentNode.parentNode.previousSibling
    disp.style.display = 'block'
  }
}

function aresize(e)
//DONT rename this to 'resize'
{
  var im;
  if (!e) var e = window.event;
  if (e.target) im = e.target;
  else if (e.srcElement) im = e.srcElement;

  if (im.src.indexOf('expand') != -1)
  {
    fullheight(im)
    nodes = document.getElementsByTagName('img')
    for (var i=0; i < nodes.length; i++)
    {
      if (nodes.item(i).getAttributeNode("class").value == 'pbsexpand')
      {
        nodes.item(i).src = '../../scripts/collapse.png'
      }
    }
    im.src = '../../scripts/collapse_hi.png'
  }
  else
  {
    shortheight(im)
    nodes = document.getElementsByTagName('img')
    for (var i=0; i < nodes.length; i++)
    {
      if (nodes.item(i).getAttributeNode("class").value == 'pbsexpand')
      {
        nodes.item(i).src = '../../scripts/expand.png'
      }
    }
    im.src = '../../scripts/expand_hi.png'
  }
}

function hlightresize(e)
{
  if (e.target) im = e.target
  else im = event.srcElement
  if (im.src.indexOf('expand') != -1)
    im.src = '../../scripts/expand_hi.png'
  else
    im.src = '../../scripts/collapse_hi.png'
}
			    
function unhlightresize(e)
{
  if (e.target) im = e.target
  else im = event.srcElement
  if (im.src.indexOf('expand') != -1)
  {
    im.src = '../../scripts/expand.png'
  }
  else
    im.src = '../../scripts/collapse.png'
}
			    
function hlightclose(e)
{
  var targ;
  if (!e) var e = window.event;
  if (e.target) targ = e.target;
  else if (e.srcElement) targ = e.srcElement;

  targ.src = '../../scripts/icons/close_over.png'
}

function unhlightclose(e)
{
  if (e.target) im = e.target
  else im = event.srcElement
  /* im.src = '../../scripts/close.png' */
  im.src = '../../scripts/icons/close.png'
}

function unhlPBS(e)
{
  if (e.target) im = e.target
  else im = event.srcElement
  im.style.backgroundImage = 'url(../../scripts/pbs.png)'
}

function hlPBS(e)
{
  if (e.target) im = e.target
  else im = event.srcElement
  im.style.backgroundImage = 'url(../../scripts/PBS_hi.png)'
}

function hlightnext()
{
  im  = event.srcElement
  im.src = '../../scripts/next_hi.png'
}

function unhlightnext()
{
  im  = event.srcElement
  im.src = '../../scripts/next.png'
}

function hlightprev()
{
  im  = event.srcElement
  im.src = '../../scripts/previous_hi.png'
}

function unhlightprev()
{
  im  = event.srcElement
  im.src = '../../scripts/previous.png'
}

/*-------------
Functions writing direct to render as HTML
--------------*/

function writelink(label, filename)
/* Generic external linking function - should replace all specific functions in time */
{
  dir="'"+label+"'"
  s = transformfile(filename, '../../scripts/countcochrane.xsl')
  dv = document.getElementById('td'+label)
  dv.parentNode.className = 'furtherreading'

  if (label == 'ap') 
    title = 'Australian Prescriber (includes Medicines Safety Update)'
  else if (label == 'ce') 
    title = 'Clinical Evidence'
  else if (label == 'cochrane') 
    title = 'Cochrane reviews'
  else if (label == 'adrac') 
    title = 'ADRAC (<i>see also</i> Australian Prescriber <i>for</i> Medicines Safety Update)'
  else 
    title = 'References'

  if (s == '0') 
    dv.innerHTML = ''
  else if (s == 'XML file not found - "'+filename+'"') 
    dv.innerHTML = '<div id="sp'+label+'" class="droprow">'+title+' - error in xml or file not found</div>'
//DUPLICATE this code option in writecochrane
//To display only multiple entries as a drop down
//  else if (s >= '1') 
//To display ALL entries as a drop down
  else if (s >= '1') 
  {
    dv.innerHTML = '<div id="sp'+label+'" class="droprow" onclick="showrows2(event'+", '"+filename+"'" +','+dir+')">'+title+'</div>'
    dv.innerHTML = dv.innerHTML+'<div id=sp'+label+'disp class=ep'+label+'invisible></div></td>'
  }
  else if (s=='1')
  {
    s = transformfile('../../'+label+'/'+filename+'.xml', '../../scripts/single'+label+'.xsl')
    dv.innerHTML = '<p class=eptopictopics>'+s+'</p>'
  }
}

function writecochrane(filename)
{
  dir="'cochrane'"
  s = transformfile('../../cochrane/'+filename+'.xml', '../../scripts/countcochrane.xsl')
  dv = document.getElementById('tdcochrane')
  dv.parentNode.className = 'furtherreading'

  if (s == '0') 
    dv.innerHTML = ''
  else if (s == 'XML file not found - "../../cochrane/'+filename+'.xml"') 
    dv.innerHTML = ''
  else if (s >= '1') 
  {
    dv.innerHTML = '<div id="spcochrane" class="droprow" onclick="showrows(event'+", '"+filename+"'" +','+dir+')">Cochrane reviews</div>'
    dv.innerHTML = dv.innerHTML+'<div id=spcochranedisp class=epcochraneinvisible></div></td>'
  }
  else if (s=='1')
  {
    s = transformfile('../../cochrane/'+filename+'.xml', '../../scripts/singlecochrane.xsl')
    dv.innerHTML = '<p class=eptopictopics>'+s+'</p>'
  }
}

/* Australian Prescriber */

function writeap(filename)
{
  dir="'ap'"
  s = transformfile('../../ap/'+filename+'.xml', '../../scripts/countcochrane.xsl')
  dv = document.getElementById('tdap')
  dv.parentNode.className = 'furtherreading'

  if (s == '0') 
    dv.innerHTML = ''
  else if (s == 'XML file not found - "../../ap/'+filename+'.xml"') 
    dv.innerHTML = '<div id="spap" class="droprow">Australian Prescriber - error in xml</div>'
//DUPLICATE this code option in writecochrane
//To display only multiple entries as a drop down
//  else if (s >= '1') 
//To display ALL entries as a drop down
  else if (s >= '1') 
  {
    dv.innerHTML = '<div id="spap" class="droprow" onclick="showrows(event'+", '"+filename+"'" +','+dir+')">Australian Prescriber</div>'
    dv.innerHTML = dv.innerHTML+'<div id=spapdisp class=epapinvisible></div></td>'
  }
  else if (s=='1')
  {
    s = transformfile('../../ap/'+filename+'.xml', '../../scripts/singleap.xsl')
    dv.innerHTML = '<p class=eptopictopics>'+s+'</p>'
  }
}

/* Clinical Evidence */

function writece(filename)
{
  dir="'ce'"
  s = transformfile('../../ce/'+filename+'.xml', '../../scripts/countcochrane.xsl')
  dv = document.getElementById('tdce')
  dv.parentNode.className = 'furtherreading'

  if (s == '0') 
    dv.innerHTML = ''
  else if (s == 'XML file not found - "../../ce/'+filename+'.xml"') 
    dv.innerHTML = '<div id="spce" class="droprow">Australian Prescriber - error in xml</div>'
//DUPLICATE this code option in writecochrane
//To display only multiple entries as a drop down
//  else if (s >= '1') 
//To display ALL entries as a drop down
  else if (s >= '1') 
  {
    dv.innerHTML = '<div id="spce" class="droprow" onclick="showrows(event'+", '"+filename+"'" +','+dir+')">Clinical Evidence</div>'
    dv.innerHTML = dv.innerHTML+'<div id=spcedisp class=epceinvisible></div></td>'
  }
  else if (s=='1')
  {
    s = transformfile('../../ce/'+filename+'.xml', '../../scripts/singlece.xsl')
    dv.innerHTML = '<p class=eptopictopics>'+s+'</p>'
  }
}


/* Drug resources - Generic */

function writedruginfomenu(filename,id)
{
  filename=space_to_underscore(filename);

  el = document.getElementById(id)

  if (!gbMozilla)
  {
    s = transformfile('../../drugcodes/'+filename+'.xml', '../../scripts/drugcodes.xsl')
    el.innerHTML = s
  }
  else
    mozTransform('../../drugcodes/'+filename, id, '../../scripts/drugcodes.xsl')
}

/** Looks for a route inside a <dosage /> element */
/** If found, tries to add the route to the xmlfilename path */
/** If the rout+path is found, that file is used. If not, the original path is used */

function writedruginfomenu2(filename,id, regid)
{
  filename=space_to_underscore(filename);

  reg = document.getElementById(regid)

  if (reg != null)
  {
  route = ''
    for (i = 0; i < reg.childNodes.item(0).attributes.length; i++)
    {
        oAttr = reg.childNodes.item(0).attributes.item(i);
	sName = oAttr.nodeName;        
        bSpecified = oAttr.specified;
        if (sName == 'ROUTE')
        {
          route = oAttr.nodeValue;
        }
    }

    el = document.getElementById(id)
  
    if (!gbMozilla)
    {
      xmlF = '../../drugcodes/'+route+'/'+filename+'.xml'
      s = transformfile(xmlF, '../../scripts/drugcodes.xsl')
      if (s == 'XML file not found - "'+xmlF+'"')
      {
        xmlF = '../../drugcodes/'+filename+'.xml'
        s = transformfile(xmlF, '../../scripts/drugcodes.xsl')
      }

      el.innerHTML = s
    }
    else
      mozTransform('../../drugcodes/'+filename, id, '../../scripts/drugcodes.xsl')
  }
  else
  {
    writedruginfomenu(filename, id)
  }
}

function showresource(e,codetype, codevalue)
{
  closesubmenu(e)
  if (e.target) el = e.target
  else el = event.srcElement

//alert(el.id)
  if (el.className == 'drugmenuitem')
    el = el.parentNode.parentNode

//Highlight the root, get its pos

//SWITCH TO FALSE on deployment

  if (gbIE5)
  { 
/* ENABLE on deployment - removed gAgent
    var nPos=gAgent.indexOf("msie")
    var nVersion=parseFloat(gAgent.substring(nPos+5));
    if(nVersion>=6)
      gbIE6=true;  */
  }

  if (gbIE6)
  {
    if (el.tagName == 'DIV')
    {
      elID = el.parentNode.parentNode.parentNode.parentNode.id
      rowID = elID+codetype
      row = el.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode
    }
    else
    {
      elID = el.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.id  
      rowID = elID+codetype
      row = el.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode
    }

  //Highlight the drug name
    drugname = row.childNodes[1].childNodes[0].childNodes[0]
    if (drugname.style == undefined)
    {
      drugname = row.childNodes[1].childNodes[0].childNodes[1]
//      alert(row.childNodes[1].childNodes[0].childNodes[1].innerHTML)
    }

    if (drugname != undefined)
      if (drugname.style != undefined)
      {
        drugname.style.padding = '3px'
        drugname.style.backgroundColor = '#e6e6e6'
      }

  //See if the row has been created - only necessary if the submenu is being used as a toggle
    bCont = true
/*    newDIV = document.getElementById(rowID)
    if (newDIV != null)
    {
      sp = newDIV  
      if (sp.style.display == 'block')
        bCont = false    
      sp.id = 'asdf'
      sp.style.display = 'none'      
      el.style.backgroundImage = 'url(../../scripts/icons/bar_normal.png)'
    }
*/
    if (bCont)
    {
    //Adds a new row after the current row
      var nextRow = row.nextSibling

    //See if the next row is a previously opened DI row
      if (nextRow != null)
        if (nextRow.childNodes[0].className == 'druginfo')
		nextRow.style.display = 'none'


      var newNode = document.createElement('TR')
      row.parentNode.insertBefore(newNode, nextRow)
      var newCell = document.createElement('TD')
      newNode.appendChild(newCell)

      var newAtt = document.createAttribute("colspan");
      newAtt.value = '3';
      newCell.setAttributeNode(newAtt);

      var newAtt = document.createAttribute("class");
      newAtt.value = 'druginfo';
      newCell.setAttributeNode(newAtt);

      var newDIV = document.createElement('DIV')
      newCell.appendChild(newDIV)

      var newID = document.createAttribute("id");
      newID.value = elID+codetype;
      newDIV.setAttributeNode(newID);
      if (codetype=='PBS')
      {
        var newAtt = document.createAttribute("class");
        newAtt.value = 'epinvisible';
        newDIV.setAttributeNode(newAtt);
      }

      sp = newDIV
//      el.style.border = '2px inset lightgrey'
// disable all bg images      el.style.backgroundImage = 'url(../../scripts/icons/bar_clicked.png)'
      //el.style.backgroundColor = '#000000';
      s = transformfile('../../'+codetype+'/'+codevalue+'.xml', '../../scripts/'+codetype+'.xsl')
      sp.style.display = 'block'
      sp.innerHTML = s
    }
  }
  else if (gbMozilla)
  {
    if (el.tagName == 'DIV')
    {
      elID = el.parentNode.parentNode.parentNode.parentNode.id
      rowID = elID+codetype
      row = el.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode
    }
    else
    {
      elID = el.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.id  
      rowID = elID+codetype
      row = el.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode
    }

  //Highlight the drug name - this code is invalid for moz
//    row.childNodes[1].childNodes[0].childNodes[0].style.padding = '3px'
//    row.childNodes[1].childNodes[0].childNodes[0].style.backgroundColor = '#e6e6e6'

  //See if the row has been created - only necessary if the submenu is being used as a toggle
      bCont = true
      newDIV = document.getElementById(rowID)
      if (newDIV != null)
      {
        sp = newDIV  
//      if (sp.style.display == 'block')
//        bCont = false    
//This must happen so that that a redisplay can occur (i.e., toss the previous DIV)
        sp.id = 'asdf'
//      sp.style.display = 'none'      
      }


    if (bCont)
    {
      var nextRow = row.nextSibling
    //See if the next row is a previously opened DI row
      if (nextRow != null)
        if (nextRow.childNodes.length > 0)
          if (nextRow.childNodes[0].className == 'druginfo')
	  {
            nextRow.style.display = 'none'
//alert('hidden')
          }


      var newNode = document.createElement('TR')
      row.parentNode.insertBefore(newNode, nextRow)
      var newCell = document.createElement('TD')
      newNode.appendChild(newCell)

      var newAtt = document.createAttribute("colspan");
      newAtt.value = '3';
      newCell.setAttributeNode(newAtt);

      var newAtt = document.createAttribute("class");
      newAtt.value = 'druginfo';
      newCell.setAttributeNode(newAtt);

      var newDIV = document.createElement('DIV')
      newCell.appendChild(newDIV)

      var newID = document.createAttribute("id");
      newID.value = elID+codetype;
      newDIV.setAttributeNode(newID);
      var newAtt = document.createAttribute("class");
      if (codetype=='PBS')
      {
        newAtt.value = 'epinvisible';
      }
      else
      {
      }
      newDIV.setAttributeNode(newAtt);

      sp = newDIV
      mozTransform("../../"+codetype+"/"+codevalue, sp.id, "../../scripts/"+codetype+".xsl")
      sp.style.display = 'block'
      //disable background images el.style.backgroundImage = 'url(../../scripts/icons/bar_clicked.png)'
      //el.style.backgroundColor = '#ffffff';
      //sp.parentNode.style.display = 'block'
      //sp.parentNode.parentNode.style.display = 'block'
      //sp.parentNode.parentNode.parentNode.style.display = 'block'
    }


  }
  else if (gbMac)
    alert('On Macintosh computers, this information currently only displays on Mozilla and Firefox.')
  else
    alert('You are using an old browser. You will need to upgrade to at least Internet Explorer v.6, Mozilla v.1.6 or Firefox v.1.0 to view PBS information.')
}

function showitems(e)
{
  if (e.target) el = e.target
  else el = event.srcElement
  submenu = el.parentNode.childNodes.item(1)
  showsubmenu(submenu)
}

function showsubmenu(e)
{

  if (e.target) el = e.target
  else el = event.srcElement

  for (var i=1; i < el.parentNode.childNodes.length; i++)
  {
    var submenu = el.parentNode.childNodes.item(i)
    //alert(submenu);
    //alert(submenu.nodeName);
    if(submenu.nodeName=='DIV')
    {
      break;
    }
  }

    if (submenu.style.display != 'block')
    {
      submenu.style.display = 'block'	
//        el.style.backgroundImage = 'url(../../scripts/icons/bar_clicked.png)'
    }
    else if (submenu.style.display = 'block')
    {
      submenu.style.display = 'none'	
//        el.style.backgroundImage = 'url(../../scripts/icons/bar_clicked.png)'
    }

//alert(findLeft(el)+'-'+findLeft(submenu))
  //if (findLeft(submenu) > findLeft(el)) //comment this out and it works in IE
    submenu.style.left = findLeft(el) + 20;
    submenu.style.width = 124; // submenu slightly narrower to avoid scrollbar
}

function findPos(obj) {
//Find top and left of an element
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function findLeft(obj) {
//Finds left of an element
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return curleft;
}

function showdrugsubmenu(e, subid)
{

  if (e.target) el = e.target
  else el = event.srcElement

  var submenu = el.childNodes.item(1)
  if (submenu.style.display != 'block')
  {
    submenu.style.display = 'block'
    submenu.style.top = el.offsetTop
  }


  menu = el.parentNode
  for (var i=0; i < menu.childNodes.length; i++)
  {
    if (menu.childNodes.item(i).childNodes.length > 1)
    {
      var sub = menu.childNodes.item(i).childNodes.item(1)

      if (sub != submenu)
      {
        sub.style.display = 'none'	      
        //sub.parentNode.style.backgroundColor = '#000000'
        //sub.parentNode.style.backgroundColor = 'white'
      }
    }
  }
  el.style.backgroundColor = '#e0e0e0'
}

function hideminimenu(minimenu)
{
  document.getElementById('minimenu').style.display = 'none'
}

function hidesubmenu(e)
{
// Triggered on a mouseout
  if (e.target) el = e.target
  else el = event.srcElement
  var submenu = el.parentNode.childNodes.item(1)


  if (!e) var e = window.event;
  var tg = (window.event) ? e.srcElement : e.target;
  var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
  var bClose = false

  if (tg.id == 'menuroot' && reltg.id == '')
  {
    bClose = true
//    alert('gone top'+reltg.id)
  }

  if (tg.id == 'submenu' && reltg.parentNode.id != 'submenu' && reltg.parentNode.id != 'menuroot')
  {
    bClose = true
//    alert('gone side'+reltg.id)
  }

  if (bClose)
  {
//alert(tg.id+' - '+reltg.id)
    if (submenu.style.display == 'block')
    {
      submenu.style.display = 'none'
//      var minimenu = el.parentNode.childNodes.item(0).childNodes.item(0)
//      minimenu.style.display = 'block'
    }
  }
}

function closesubmenu(e)
{
// Called by showresource
  if (e.target) el = e.target
  else el = event.srcElement

  if (el.className == 'drugmenuitem')
    el = el.parentNode.parentNode

  var submenu = el.parentNode
//alert(el.parentNode.id)

  if (!e) var e = window.event;
  var tg = (window.event) ? e.srcElement : e.target;
  var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
  if (submenu.style.display == 'block')
  {
    submenu.style.display = 'none'
  }
}

function writeresource(restype,filestem,chapref)
{
	var s=''
	var srefs=''

//References
	sub = getresline('topicrefs',filestem)
	if (sub.indexOf('error in xml or file not found') < 0)
	{
		srefs += sub
	}
	sub = getresline('chapterrefs',filestem)
	if (sub.indexOf('error in xml or file not found') < 0)
	{
		srefs += sub
	}

//Other resources
    	div = document.getElementById(restype)

	sub = getresline('adrac',filestem)
	if (sub.indexOf('error in xml or file not found') < 0)
		s = s+sub

	sub = getresline('ap',filestem)
	if (sub.indexOf('error in xml or file not found') < 0)
		s = s+sub

	sub = getresline('ce',filestem)
	if (sub.indexOf('error in xml or file not found') < 0)
		s = s+sub

	sub = getresline('cochrane',filestem)
	if (sub.indexOf('error in xml or file not found') < 0)
		s = s+sub

	sub = getresline('npsnews',filestem)
	if (sub.indexOf('error in xml or file not found') < 0)
		s = s+sub

	sub = getresline('npsradar',filestem)
	if (sub.indexOf('error in xml or file not found') < 0)
		s = s+sub


	if (srefs != '')
	 	srefs = '<p class=epseeninrelated>Key references for this topic</p>'+srefs

    if ((typeof(chapref)!="undefined") && chapref != '')
	 	srefs = srefs+'<p class=epseeninrelated style="padding-bottom: 2pt;"><a href="'+chapref+'">Key references for this chapter</a></p>'

	if (s != '')
	 	s = '<div style="background-color: #ffffff; position: relative; left: -5.4pt; width: 102%;">&nbsp;</div><p class=epseeninrelated>Other resources: </p>'+s


 	s = srefs+s


	div.innerHTML = s
	if (s != '')
		div.className = restype


}

function getresline(reslabel,filestem)
{
	res = '<div class=fr id=td'+reslabel+'>'
	//alert("getlink("+reslabel+",../../"+reslabel+"/"+filestem+".xml)");
	res = res+getlink(reslabel,'../../'+reslabel+'/'+filestem+'.xml')
	res = res+'</div>'
	return res
}

function getlink(label, filename)
/* Generic external linking function - should replace all specific functions in time */
{
  dir="'"+label+"'"
  s = transformfile(filename, '../../scripts/countcochrane.xsl')
//  dv = document.getElementById('td'+label)
//  dv.parentNode.className = 'furtherreading'

  if (label == 'ap') 
    title = 'Australian Prescriber'
  else if (label == 'ce') 
    title = 'Clinical Evidence (subscription required)'
  else if (label == 'cochrane') 
    title = 'Cochrane reviews'
  else if (label == 'adrac') 
    title = 'ADRAC bulletin'
  else if (label == 'npsnews') 
    title = 'NPS News'
  else if (label == 'npsradar') 
    title = 'NPS RADAR'
  else if (label == 'topicrefs') 
    title = 'Topic'
  else if (label == 'chapterrefs') 
    title = 'Chapter'
  else 
    title = 'Other resources'

  if (s == '0') 
    res = ''
  else if (s == 'XML file not found - "'+filename+'"') 
  {
    res = '<div id="sp'+label+'" class="droprow">'+title+' - error in xml or file not found</div>'
  }
//DUPLICATE this code option in writecochrane
//To display only multiple entries as a drop down
//  else if (s >= '1') 
//To display ALL entries as a drop down
  else if (s >= '1') 
  {
    //if (label == 'references') 
    //  res = '<p id="sp'+label+'" class="droprowrefs" onclick="showrows2(event'+", '"+filename+"'" +','+dir+')">'+title+'</p>'
    //else
      res = '<div id="sp'+label+'" class="droprow" onclick="showrows2(event'+", '"+filename+"'" +','+dir+')">'+title+'</div>'
    res = res+'<div id=sp'+label+'disp class=ep'+label+'invisible></div></td>'
  }
  else if (s=='1')
  {
    s = transformfile('../../'+label+'/'+filename+'.xml', '../../scripts/single'+label+'.xsl')
    res = '<p class=eptopictopics>'+s+'</p>'
  }
  return res
}

// convert spaces in filenames to underscores
function space_to_underscore(filename) {
    var a = new Array();
    a = filename.split(' ');

    var filename_underscore = a[0];
    for( ii=1 ; ii < a.length ; ii++ ) {
        filename_underscore+="_"+a[ii];
    }
    return filename_underscore;
}

function highlight(item) {
    item.style.backgroundColor = '#ffffff'
}

function unhighlight(item) {
    item.style.backgroundColor = '#e0e0e0'
}
