// BEGIN $Id: docketfix.js,v 1.1 2008/11/05 21:29:09 peterw Exp peterw $
// $Revision: 1.1 $

// Javascript library to fix links in Domino "dockets" pages that 
// refer to unreachable IP address URLs

function coa_docket_addLoadEvent(func) {
//alert("adding an onload sub");
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

// http://invisibleblocks.wordpress.com/2006/01/18/hacking-the-browsers-dom-for-fun/
function coa_docket_getElements (evalFunc, node) {
   if (!node) node = document.documentElement;
   var matches = new Array();  // storage space
   if (evalFunc(node))         // if it's a match...
       matches.push(node);     // store it

   var child = node.firstChild;
   while (child) {                // search thru each child
       matches = matches.concat(coa_docket_getElements(evalFunc, child));
       child = child.nextSibling;
   }
   return matches;
}

function coa_docket_fixlinks() {

    var badURL = "http://207.192.134.164/";
    var goodURL = "http://dockets.alexandriava.gov/";

    // find all the hyperlinks
    var links = coa_docket_getElements(
     function(node) {
         return node.nodeName == 'A';
     });
    for (var i = 0; i < links.length; ++i) {
      // the link is always absolute, already
      // calculated by the browser
      if ( 
	  (links[i].href != null) && 
          (links[i].href.indexOf(badURL) == 0) ) {
		// fix link
		links[i].href = goodURL + links[i].href.substring(badURL.length);
      } 
      //alert("link " + i + ": " + links[i].text + " - " + links[i].className);
    }
}

coa_docket_addLoadEvent(function(){
  coa_docket_fixlinks();
});

// END $Id: docketfix.js,v 1.1 2008/11/05 21:29:09 peterw Exp peterw $

