/* Clsoe window via button without alert */

function closeMe()
{
    window.opener='X'; 
    window.open('','_parent',''); 
    window.close();
}
       

/* Hide Show Div */

function showHideDiv(theId,imageid) 
{
    var theContainer = document.getElementById(theId);
    if (imageid != null)
    {
        theIcon = document.getElementById(imageid);
    }
    
    if (theContainer.style.display == '' ||
        theContainer.style.display == 'block') 
    {
        theContainer.style.display = 'none';
        if (imageid != null)
        {
            theIcon.src = "../images/plus.gif";
        }
    } 
    else if (theContainer.style.display == 'none') 
    {
        theContainer.style.display = '';
        if (imageid != null)
        {
            theIcon.src = "../images/minus.gif";
        }
    } 
}

function setHiddenDiv(theId)
{
    document.getElementById(theId).style.display = "none";
}

/* Scroller */
	var delay = new Array();
	var browser=navigator.appName;

	function beginScroll(elt){
        try{
        	if (elt == 1){
                stopScroll('1');
        		scroll('1','1');
            }
            else if (elt == 2){
                 stopScroll('2');
        		 scroll('1','2');
            }
            else {
                stopScroll('1');
        		scroll('1','1');
                stopScroll('2');
        		scroll('1','2');
            }
        } catch(e) {}
	}
	
	function scroll(direction, elt){
			var topstr = document.getElementById('scroller'+elt).style.top
			if(topstr==""){topstr="0px"}
			topstr = topstr.substring(0, topstr.length-2)
			//alert('topstr: ' + topstr)
			var topint = parseInt(topstr) - parseInt(direction);
			//alert ('topint: ' + topint);
			var scrollContainerHeight = document.getElementById('scrollcontainer'+elt).offsetHeight
			var scrollerHeight = document.getElementById('scroller'+elt).offsetHeight
			if (parseInt(direction)<0)
				if (topint>(scrollContainerHeight + 10)){topint = (scrollerHeight*-1)}
			if (parseInt(direction)>0)
				if (topint<((scrollerHeight*-1) - 10)){topint = scrollContainerHeight }
			document.getElementById('scroller'+elt).style.top = topint + "px";
			//alert('t: ' + document.getElementById('scroller').style.top);//document.getElementById('scroller').style.top = document.getElementById('scroller').style.top + '100px';
			if(browser!="Microsoft Internet Explorer"){
				delay[elt] = setTimeout("scroll("+direction+","+elt+")", 45)
			}
			else {
				delay[elt] = setTimeout("scroll("+direction+","+elt+")", 33)
			}
	}
	
	function stopScroll(elt){
		clearTimeout(delay[elt]);
		timerOn=0;
		//alert(browser)
		//alert("offsetHeight: " + document.getElementById('scroller').offsetHeight);
	}

/* JS Utilities */

/*------------------------------------------------------------------------------
Filename:       jsUtilities Library
Author:         Aaron Gustafson (aaron at easy-designs dot net)
                unless otherwise noted
Creation Date:  4 June 2005
Version:        2.1
Homepage:       http://www.easy-designs.net/code/jsUtilities/
License:        Creative Commons Attribution-ShareAlike 2.0 License
                http://creativecommons.org/licenses/by-sa/2.0/
Note:           If you change or improve on this script, please let us know by 
                emailing the author (above) with a link to your demo page.
------------------------------------------------------------------------------*/
// ---------------------------------------------------------------------
//                      array.push (if unsupported)
// ---------------------------------------------------------------------
if(Array.prototype.push == null) { Array.prototype.push = function(item) { this[this.length] = item; return this.length; }; };
// ---------------------------------------------------------------------
//                      array.shift (if unsupported)
// ---------------------------------------------------------------------
if (Array.prototype.shift == null) { Array.prototype.shift = function() { var response = this[0]; for (var i=0; i < this.length-1; i++) { this[i] = this[i + 1]; }; this.length--; return response; }; };
// ---------------------------------------------------------------------
//                  function.apply (if unsupported)
//           Courtesy of Aaron Boodman - http://youngpup.net
// ---------------------------------------------------------------------
if (!Function.prototype.apply) { Function.prototype.apply = function(oScope, args) { var sarg = []; var rtrn, call; if (!oScope) oScope = window; if (!args) args = []; for (var i = 0; i < args.length; i++) { sarg[i] = "args["+i+"]";}; call = "oScope.__applyTemp__(" + sarg.join(",") + ");"; oScope.__applyTemp__ = this; rtrn = eval(call); oScope.__applyTemp__ = null; return rtrn;};}; 
// ---------------------------------------------------------------------
//                               inArray()
//                           [Port from PHP]
//               Hunts for a value in the specified array
// ---------------------------------------------------------------------
function inArray(needle) { for (var i=0; i < this.length; i++) { if (this[i] === needle) { return i; } } return false; } Array.prototype.inArray = inArray;
// ---------------------------------------------------------------------
//                               isArray()
//                           [Port from PHP]
//                  verifies if something is an array
// ---------------------------------------------------------------------
function isArray() { return (typeof(this.length)=="undefined") ? false : true; }; Array.prototype.isArray = isArray;
// ---------------------------------------------------------------------
//                               ksort()
//                           [Port from PHP]
//                     sorts an array by key names
// ---------------------------------------------------------------------
function ksort() { var sArr = []; var tArr = []; var n = 0; for (i in this) tArr[n++] = i+"|"+this[i]; tArr = tArr.sort(); for (var i=0; i<tArr.length; i++) { var x = tArr[i].split("|"); sArr[x[0]] = x[1]; } return sArr; } Array.prototype.ksort = ksort;
// ---------------------------------------------------------------------
//                             addClass()
//                 appends the specified class to the object
// ---------------------------------------------------------------------
function addClass(theClass) { if (this.className != '') { this.className += ' ' + theClass; } else { this.className = theClass; } } Object.prototype.addClass = addClass;
// ---------------------------------------------------------------------
//                           removeClass()
//                 removes the specified class to the object
// ---------------------------------------------------------------------
function removeClass(theClass) { var oldClass = this.className; var regExp = new RegExp('\\s?'+theClass+'\\b'); if (oldClass.indexOf(theClass) != -1) { this.className = oldClass.replace(regExp,''); } } Object.prototype.removeClass = removeClass;
// ---------------------------------------------------------------------
//                      lastChildContainingText()
//  finds the last block-level text-containing element within an object
// ---------------------------------------------------------------------
function lastChildContainingText() { var testChild = this.lastChild; var contentCntnr = ['p','li','dd']; while (testChild.nodeType != 1) { testChild = testChild.previousSibling; }  var tag = testChild.tagName.toLowerCase(); var tagInArr = inArray.apply(contentCntnr, [tag]); if (!tagInArr && tagInArr!==0) { testChild = lastChildContainingText.apply(testChild); } return testChild; } Object.prototype.lastChildContainingText = lastChildContainingText;


/* footnoteLinks */    

/*------------------------------------------------------------------------------
Function:       footnoteLinks()
Author:         Aaron Gustafson (aaron at easy-designs dot net)
Creation Date:  8 May 2005
Version:        1.3
Homepage:       http://www.easy-designs.net/code/footnoteLinks/
License:        Creative Commons Attribution-ShareAlike 2.0 License
                http://creativecommons.org/licenses/by-sa/2.0/
Note:           If you change or improve on this script, please let us know by 
                emailing the author (above) with a link to your demo page.
------------------------------------------------------------------------------*/
function footnoteLinks(containerID,targetID) {
//alert(containerID+','+targetID);
  if (!document.getElementById || 
      !document.getElementsByTagName ||
      !document.createElement) 
      {
        //alert('false');
        return false;
      }
  if (!document.getElementById(containerID) ||
      !document.getElementById(targetID))
      {
        //alert('false');
        return false;
      }
  try {
      var container = document.getElementById(containerID);
      var target    = document.getElementById(targetID);
      var h2        = document.createElement('h2');
      addClass.apply(h2,['printOnly']);
      var h2_txt    = document.createTextNode('Hyperlink References');
      h2.appendChild(h2_txt);
      var coll = container.getElementsByTagName('*');
      var ol   = document.createElement('ol');
      addClass.apply(ol,['printOnly']);
      var myArr = [];
      var thisLink;
      var num = 1;
      for (var i=0; i<coll.length; i++) {
        var thisClass = coll[i].className;
        var thisTag = coll[i].tagName;
        if ( (coll[i].getAttribute('href') ||
              coll[i].getAttribute('cite')) &&
              (thisClass == '' ||
               thisClass.indexOf('ignore') == -1)) { 
          thisLink = coll[i].getAttribute('href') ? coll[i].href : coll[i].cite;
          
          if (thisLink == "javascript: return false;" || 
              thisLink == "javascript:%20return%20false;"||
              thisTag == "img" ||
              thisTag == "IMG" )
          {//alert(thisTag + ' caught!');
          }
          else
          {
              var note = document.createElement('sup');
              addClass.apply(note,['printOnly']);
              var note_txt;
              var j = inArray.apply(myArr,[thisLink]);
              if ( j || j===0 ) {
                note_txt = document.createTextNode(j+1);
              } else {
                var li     = document.createElement('li');
                
                var li_txt = document.createTextNode(thisLink);
                li.appendChild(li_txt);
                ol.appendChild(li);
                myArr.push(thisLink);
                note_txt = document.createTextNode(num);
                num++;
              }
              note.appendChild(note_txt);
              if (coll[i].tagName.toLowerCase() == 'blockquote') {
                var lastChild = lastChildContainingText.apply(coll[i]);
                lastChild.appendChild(note);
              } else {
                coll[i].parentNode.insertBefore(note, coll[i].nextSibling);
              }
          }
        }
      }
      target.appendChild(h2);
      target.appendChild(ol);
      addClass.apply(document.getElementsByTagName('html')[0],['noted']);
      return true;
  } catch (e) {}
}

/**
 * domready.js
 * 
 * Cross browser mozilla's 'onDOMContentLoaded' implementation.
 * Executes a function when the dom tree is loaded without waiting for images.
 * 
 * Based on +Element.Events.domready+ from Mootools open source project, 
 * this tiny javascript library adds the emulated 'DOMContentLoaded' functionality.
 * 
 * Features:
 *   - No dependency on external libraries
 *   - Compatible with Prototype.js 
 * 
 * Tested browsers (Windows):
 *   - IE 7 (XP standalone)
 *   - IE 6 SP2
 *   - Firefox 2.0.0.4
 *   - Opera 9.21
 * 
 * Tested browsers (Mac OS X):
 *   - Safari 2.0.4
 *   - Firefox 2.0.0.4
 *   - Mac Opera 9.21
 *   - Mac IE 5.2.3
 *
 * Copyright (c) 2007 Takanori Ishikawa.
 * License: MIT-style license.
 * 
 * MooTools Copyright:
 * copyright (c) 2007 Valerio Proietti, <http://mad4milk.net>
 *
 *
 * See Also:
 *
 *   mootools 
 *   http://mootools.net/
 *   
 *   The window.onload Problem - Solved!
 *   http://dean.edwards.name/weblog/2005/09/busted/
 *   
 *   [PATCH] Faster onload for Event.onload
 *   http://dev.rubyonrails.org/ticket/5414
 *   Changeset 6596: Support for "DOMContentLoaded" event handling (prototype.js event branch)
 *   http://dev.rubyonrails.org/changeset/6596
 *
 */

if (typeof Event == 'undefined') Event = new Object();

/*
 * Registers function +fn+ will be executed when the dom 
 * tree is loaded without waiting for images. 
 * 
 * Example:
 *
 *  Event.domReady.add(function() {
 *    ...
 *  });
 *
 */
Event.domReady = {
  add: function(fn) {
    
    //-----------------------------------------------------------
    // Already loaded?
    //-----------------------------------------------------------
    if (Event.domReady.loaded) return fn();
    
    //-----------------------------------------------------------
    // Observers
    //-----------------------------------------------------------
    var observers = Event.domReady.observers;
    if (!observers) observers = Event.domReady.observers = [];
    // Array#push is not supported by Mac IE 5
    observers[observers.length] = fn;
    
    //-----------------------------------------------------------
    // domReady function
    //-----------------------------------------------------------
    if (Event.domReady.callback) return;
    Event.domReady.callback = function() {
      if (Event.domReady.loaded) return;
      
      Event.domReady.loaded = true;
      if (Event.domReady.timer) {
        clearInterval(Event.domReady.timer);
        Event.domReady.timer = null;
      }
      
      var observers = Event.domReady.observers;
      for (var i = 0, length = observers.length; i < length; i++) {
        var fn = observers[i];
        observers[i] = null;
        fn(); // make 'this' as window
      }
      Event.domReady.callback = Event.domReady.observers = null;
    };
    
    //-----------------------------------------------------------
    // Emulates 'onDOMContentLoaded'
    //-----------------------------------------------------------
    var ie = !!(window.attachEvent && !window.opera);
    var webkit = navigator.userAgent.indexOf('AppleWebKit/') > -1;
    
    if (document.readyState && webkit) {
      
      // Apple WebKit (Safari, OmniWeb, ...)
      Event.domReady.timer = setInterval(function() {
        var state = document.readyState;
        if (state == 'loaded' || state == 'complete') {
          Event.domReady.callback();
        }
      }, 50);
      
    } else if (document.readyState && ie) {
      
      // Windows IE 
      var src = (window.location.protocol == 'https:') ? '://0' : 'javascript:void(0)';
      document.write(
        '<script type="text/javascript" defer="defer" src="' + src + '" ' + 
        'onreadystatechange="if (this.readyState == \'complete\') Event.domReady.callback();"' + 
        '><\/script>');
      
    } else {
      
      if (window.addEventListener) {
        // for Mozilla browsers, Opera 9
        document.addEventListener("DOMContentLoaded", Event.domReady.callback, false);
        // Fail safe 
        window.addEventListener("load", Event.domReady.callback, false);
      } else if (window.attachEvent) {
        window.attachEvent('onload', Event.domReady.callback);
      } else {
        // Legacy browsers (e.g. Mac IE 5)
        var fn = window.onload;
        window.onload = function() {
          Event.domReady.callback();
          if (fn) fn();
        }
      }
      
    }
    
  }
}
