/*
** $Id: footnotes.js,v 1.2 2006/08/08 23:45:11 psy Exp $
**
** Adapted from:
** Format Footnotes with Javascript & CSS
** <http://www.brandspankingnew.net/archive/2005/07/format_footnote.html>
*/

function footnotes(contID,noteID)
{
  var cont = document.getElementById(contID);
  var noteholder = document.getElementById(noteID);
  var spans = cont.getElementsByTagName("span");
  var notes = 0;
  
  for (i=0;i<spans.length;i++) {
    if (spans[i].className == "footnote") {
      notes++;
      noteholder.innerHTML += "<li class='footnote' id='note" + notes + "'>" 
	+ spans[i].innerHTML 
	+ "&nbsp;<a href='#nlink" + notes + "' title='return to text'>&#8617;</a></li>";
      spans[i].innerHTML = "<a name='nlink" + notes  + "' href='#note" + notes 
	+ "' title='view footnote' class='footnote'>" + notes + "</a>";
      spans[i].style.content = "foo";
    }
  }

  if (notes > 0 ) {
    noteholder.innerHTML = "<ol>" + noteholder.innerHTML + "</ol>";
  }

  modCSS('.footnote:before', 'content', '""');
  modCSS('.footnote:after', 'content', '""');
}

/* Taken from <news:1106074475.278572.158540@c13g2000cwb.googlegroups.com> */

function modCSS(selector /* [attribute/value pairs] */)
{
  if ('undefined' != typeof document.styleSheets)
    {
      var nsheets = document.styleSheets.length,
	re = new RegExp('\\b' + selector + '\\b', 'i'),
	SS,
	rtype,
	rule,
	rules,
	nrules;
      for (var nsheet = 0; nsheet < nsheets; ++nsheet)
	{
	  SS = document.styleSheets.item(nsheet);
	  rtype = ('undefined' != typeof SS.rules) ? 'rules' : 'cssRules';
	  if ('undefined' != typeof SS[rtype])
	    {
	      rules = SS[rtype];
	      nrules = rules.length;
	      for (nrule = 0; nrule < nrules; ++nrule)
		{
		  rule = rules.item(nrule);
		  if (re.test(rule.selectorText))
		    {
		      for (var a = 1; a < arguments.length; a += 2)
			rule.style[arguments[a]] = arguments[a + 1];
		      return;
		      
		    }
		}
	    }
	}
    }
}
