// An object-based cross-browser/platform show/hide/move DHTML toolkit
// programmed by Michael Lascarides
// michael@electrotone.com
// Jan 29, 2001

// Modified April 19, 2005

// Setting IE vs NN constants
// n = Netscape ; ie = Internet Explorer ; 
// w3c = new W3C standard compliant browsers (like NN 6.x, IE 6.x)

var show='visible';
var hide='hidden';
var left='left';
var top='top';
var none='none';
var block='block';
var bgcolor='backgroundColor';
var n=false;
var ie=false;
var w3c=false;
var imagePreloadFlag = false;


if (document.getElementById) { // w3c-compliant-esque
    w3c=true;
} else if (document.layers) { // netscape4-esque
    n=true;
    show='show';
    hide='hide';
    bgcolor='bgColor';
} else if (document.all) { // ie4-5-esque
    ie=true;        
    left='pixelLeft';
    top='pixelTop';
    block='';
}

// location of error page
errorPage = 'error.html';
// uncomment this line
// to send non-compliant browsers to bailout location
// if(!(ie||w3c||n)) window.location(errorPage);



// Create browser-specific menu object
function initDhtmlItem(itemName) {
      // create DOM-specific object references for DHTML items

		if (w3c) {
        	itemRef = document.getElementById(itemName).style;
        } else if (n) { // netscape 4 
            WM_layers = new Array();
            with (document) {
              for (i=0; i<layers.length; i++) WM_layers[i]=layers[i]; {
                for (i=0; i<WM_layers.length; i++) {
                  if (WM_layers[i].document && WM_layers[i].document.layers) {
                    for (j=0; j<WM_layers[i].document.layers.length; j++) {
                      WM_layers[WM_layers.length] = WM_layers[i].document.layers[j];
                    }
                    if(WM_layers[i].name == itemName){
                      // So if the code matches the name of the layer, 
                      // return the reference. 
                      itemRef = WM_layers[i];
                    }
                  }
                }
              }
            }
        }
		else if (ie) { 
	        itemRef = document.all[itemName].style;
        }

        return itemRef;
}


function toggleShowHide(itemToShow) {

    theObj = initDhtmlItem(itemToShow);
    
    showOrHide = (theObj.visibility == show) ? hide : show;

    theObj.visibility = showOrHide;

}

function showHideItem(itemToShow,showOrHide) {

    theObj = initDhtmlItem(itemToShow);
    
    showOrHide = (showOrHide == 'hide') ? hide : show;

    theObj.visibility = showOrHide;

}

function changeBGColor(itemToChange, newBGColor) {

	theObj = initDhtmlItem(itemToChange);

    if (typeof(theObj.backgroundColor) != 'undefined') {    
	    theObj.backgroundColor = newBGColor;
	} else {
		return false;
	}
    
}

function changeTypeColor(itemToChange, newColor) {

	theObj = initDhtmlItem(itemToChange);
    theObj.color = newColor;
}

function changeBgImage(itemToChange, newImage) {
	theObj = initDhtmlItem(itemToChange);
    theObj.backgroundImage = newImage;
}

function changeNav(itemToChange, onOrOff, isCurrent) {
	if (onOrOff == 'on') {
		showHideItem( itemToChange + 'Menu','show');
		changeTypeColor(itemToChange,'#fff');
		changeBgImage(itemToChange, 'url(http://www.godfreyglass.com/graphics/linkson.jpg)' );
	} else {
		showHideItem(itemToChange + 'Menu','hide');
		if (isCurrent) {
			changeTypeColor(itemToChange,'#294690');
			changeBgImage(itemToChange, 'url(http://www.godfreyglass.com/graphics/linksoff.jpg)' );
		} else {
			changeTypeColor(itemToChange,'#444');
			changeBgImage(itemToChange, 'url(http://www.godfreyglass.com/graphics/linksoff.jpg)' );
		}
	}	
}
function popUp(URL,height,width) {

	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width="+width+",height="+height+"');");

}

 // this function is needed to work around 
  // a bug in IE related to element attributes
  function hasClass(obj) {
     var result = false;
     if (obj.getAttributeNode("class") != null) {
         result = obj.getAttributeNode("class").value;
     }
     return result;
  }   

 function stripe(id) {

    // the flag we'll use to keep track of 
    // whether the current row is odd or even
    var even = false;
  
    // if arguments are provided to specify the colours
    // of the even & odd rows, then use the them;
    // otherwise use the following defaults:
    var evenColor = arguments[1] ? arguments[1] : "#fff";
    var oddColor = arguments[2] ? arguments[2] : "#eee";
  
    // obtain a reference to the desired table
    // if no such table exists, abort
    var table = document.getElementById(id);
    if (! table) { return; }
    
    // by definition, tables can have more than one tbody
    // element, so we'll have to get the list of child
    // &lt;tbody&gt;s 
    var tbodies = table.getElementsByTagName("tbody");

    // and iterate through them...
    for (var h = 0; h < tbodies.length; h++) {
    
     // find all the &lt;tr&gt; elements... 
      var trs = tbodies[h].getElementsByTagName("tr");
      
      // ... and iterate through them
      for (var i = 0; i < trs.length; i++) {

        // avoid rows that have a class attribute
        // or backgroundColor style
        if (! hasClass(trs[i]) &&
            ! trs[i].style.backgroundColor) {
 		  
          // get all the cells in this row...
          var tds = trs[i].getElementsByTagName("td");
        
          // and iterate through them...
          for (var j = 0; j < tds.length; j++) {
        
            var mytd = tds[j];

            // avoid cells that have a class attribute
            // or backgroundColor style
            if (! hasClass(mytd) &&
                ! mytd.style.backgroundColor) {
        
              mytd.style.backgroundColor =
                even ? evenColor : oddColor;
            
            }
          }
        }
        // flip from odd to even, or vice-versa
        even =  ! even;
      }
    }
  }

