 // Rollover  v2.0.1
// documentation: http://www.dithered.com/javascript/rollover/index.html
// license: http://creativecommons.org/licenses/by/1.0/
// code by Chris Nott (chris[at]dithered[dot]com)


function clearExampleField(elem, text) {
	if (elem.value == text) {
		elem.value = "";
	}
}

function isDefined(property) {
  return (typeof property != 'undefined');
}

var rolloverInitialized = false;
function rolloverInit() {
   if (!rolloverInitialized && isDefined(document.images)) {
      
      // get all images (including all <input type="image">s)
      // use getElementsByTagName() if supported
      var images = new Array();
      if (isDefined(document.getElementsByTagName)) {
         images = document.getElementsByTagName('img');
         var inputs = document.getElementsByTagName('input');
         for (var i = 0; i < inputs.length; i++) {
            if (inputs[i].type == 'image') {
               images[images.length] = inputs[i];
            }
         }
      }
      
      // otherwise, use document.images and document.forms collections
      // remove if not supporting IE4, Opera 4-5
      else {
         images = document.images;
         inputs = new Array();
         for (var formIndex = 0; formIndex < document.forms.length; formIndex++) {
            for (var elementIndex = 0; elementIndex < document.forms.elements.length; elementIndex++) {
               if (isDefined(document.forms.elements[i].src)) {
                  inputs[inputs.length] = document.forms.elements[i];
               }
            }
         }
      }
      
      // get all images with '_off.' in src value
      for (var i = 0; i < images.length; i++) {
         if (images[i].src.indexOf('_off.') != -1) {
            var image = images[i];
            
            // store the off state filename in a property of the image object
            image.offImage = new Image();
            image.offImage.src = image.src;
            
            // store the on state filename in a property of the image object
            // (also preloads the on state image)
            image.onImage = new Image();
            image.onImage.imageElement = image;
            
            // add onmouseover and onmouseout event handlers once the on state image has loaded
            // Safari's onload is screwed up for off-screen images; temporary fix
            if (navigator.userAgent.toLowerCase().indexOf('safari') != - 1) {
               image.onmouseover = function() {
                  this.src = this.onImage.src;
               };
               image.onmouseout = function() {
                  this.src = this.offImage.src;
               };
            }
            else {
               image.onImage.onload = function() {
                  this.imageElement.onmouseover = function() {
                     this.src = this.onImage.src;
                  };
                  this.imageElement.onmouseout = function() {
                     this.src = this.offImage.src;
                  };
               };
            }
            
            // set src of on state image after defining onload event handler
            // so cached images (that load instantly in IE) will trigger onload
            image.onImage.src = image.src.replace(/_off\./, '_on.');
         }
      }
   }
   rolloverInitialized = true;
}

// call rolloverInit when document finishes loading
if (isDefined(window.addEventListener)) {
   window.addEventListener('load', rolloverInit, false);
}
else if (isDefined(window.attachEvent)) {
   window.attachEvent('onload', rolloverInit);
}


// Image Preloader  v1.0.1
// documentation: http://www.dithered.com/javascript/image_preloader/index.html
// license: http://creativecommons.org/licenses/by/1.0/
// code by Chris Nott (chris[at]dithered[dot]com)


function preloadImages() {
	if (document.images) {
		for (var i = 0; i < preloadImages.arguments.length; i++) {
			(new Image()).src = preloadImages.arguments[i];
		}
	}
}


// function to show & hide content
function hidedivs(id) { 
	if (document.getElementById) { // DOM3 = IE5, NS6 
		document.getElementById(id).style.display = 'none'; 
	} 
} 

function showdivs(id) { 
	if (document.getElementById) { // DOM3 = IE5, NS6 
		document.getElementById(id).style.display = 'block';
	} 
}
// end function to show & hide content
 
 
 // this function is needed to work around 
  // a bug in IE related to element attributes
  function hasClass(obj) {
     var result = false;
     if (obj.getAttribute("class") != null) {
         result = obj.getAttribute("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;
      }
    }
  }
  

/* function for jump menus */
function openURL()
{ 

// grab index number of the selected option
selInd = document.theForm.jumpMenu.selectedIndex; 

// get value of the selected option
goURL = document.theForm.jumpMenu.options[selInd].value;

// redirect browser to the grabbed value (hopefully a URL)
top.location.href = goURL; 

}


function isBlank(str) 
{

	var c, undef;
	if (str==undef)  return true; 
	if (str==null || str=="")  return true; 
	for (var i=0; i<str.length; i++) {
		c = str.charAt(i);
		if ((c != " ") && (c != "\\n") && (c != "\\t")) {
			return false;
		}
	}
	if (str==null || str=='') return true; 
	return false;
}

function checkIntegerKeyDown(elem) {
	window[elem.name+"_value"] = elem.value;
}

function checkIntegerKeyUp(elem) {
	if (!elem.value.match(/^\d*$/)) {
		elem.value = window[elem.name+"_value"];
	}
}




function getSelect(select) {
	var undef, options = select.options;
	for (var i=0; i<options.length; i++) {
		if (options[i].selected == true) {
			return options[i].value;
		}
	}
	return undef;
}

function setSelect(select, value) {
	var opts = select.options;
	for (var i=0; i<opts.length; i++) {
		if (opts[i].value == value) {
			opts[i].selected = true;
			return i;
		}
	}
	return -1;
}

function clearSelect(select) {
	select.options.length = 0;
}

function setRootSelect(rootSelect, rootArray, babySelects) {
	var i, pos=0, form=rootSelect.form;

	var opts = rootSelect.options;
	opts.length = 0;

	for (i=0; i<rootArray.length; i+=3) {
		opts[opts.length]
			= new Option(rootArray[i+1], rootArray[i], false, false);
	}
	if (form["_"+rootSelect.name]) {
		pos = setSelect(rootSelect, form["_"+rootSelect.name].value);
		if (pos < 0) { pos=0; }
	} else {
		opts[0].selected = true;
	}

	if (babySelects != null) {
		var parentArray = rootArray;
		var select;

		for (i=0; (i<babySelects.length && parentArray != null); i++) {
			setChildSelect(babySelects[i], parentArray, pos, null);

			parentArray = parentArray[(pos*3)+2];

			if (form["_"+babySelects[i].name]) {
				pos = setSelect(babySelects[i],
					form["_"+babySelects[i].name].value);
				if (pos < 0) { pos = 0; }
			} else {
				pos = 0;
			}
		}
	}
}

function setChildSelect(childSelect, parentArray, pos, babySelects) {
	var i, form=childSelect.form;

	var childArray = parentArray[(pos*3)+2];

	if (childArray == null) {
		clearSelect(childSelect);
		childSelect.style.visibility = "hidden";

	} else {
		var opts = childSelect.options;
		opts.length = 0;

		for (i=0; i<childArray.length; i+=3) {
			opts[opts.length]
				= new Option(childArray[i+1], childArray[i], false, false);
		}
		if (form["_"+childSelect.name]) {
			setSelect(childSelect, form["_"+childSelect.name].value);
		} else {
			opts[0].selected = true;
		}

		childSelect.style.visibility="visible";
	}

	if (babySelects != null) {
		parentArray = childArray;
		for (i=0; i<babySelects.length; i++) {
			if (parentArray == null) {
				clearSelect(babySelects[i]);
				babySelects[i].style.visibility="hidden";
			} else {
				setChildSelect(babySelects[i], parentArray, 0, null);
				parentArray = parentArray[2];
			}
		}
	}

	return;
}

