// JavaScript Document

// ADD A FUNCTION TO THE ONLOAD EVENT
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
	
}


//
//Create an array of all the elements that have a particular class
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

// Switch off all objects with class "hide_first" and Switch on all objects with class "show_first"
function hide_and_show(hide_this_class, show_this_class) {
	var el_hide = getElementsByClass(hide_this_class, document, '*');
	 for ( i=0;i<el_hide.length;i++ ) {
		el_hide[i].style.display = "none" 
	}
	var el_show = getElementsByClass(show_this_class, document, '*');
	 for ( i=0;i<el_show.length;i++ ) {
		el_show[i].style.display = "block" 
	}
}
//


//
// 	Toggle an area on and shut off the calling button at the same time. Once it's turned on, it's on and the only way to hide it again would be to refresh the page.
function toggle(id, btn_id) {
  if (document.getElementById) {
    var e = document.getElementById(id);
	var b = document.getElementById(btn_id);
    if (e) {
      if (e.style.display != "block") e.style.display = "block" 
      else e.style.display = "none" 
    } 
	if (b) {
      if (b.style.display != "none") b.style.display = "none" 
      else b.style.display = "block" 
    }  
  }
}
//-->

//
//
// FORM ONFOCUS FUNCTIONS	 FORM ONFOCUS FUNCTIONS 	FORM ONFOCUS FUNCTIONS 	 FORM ONFOCUS FUNCTIONS
//
// Clear the form field on onfocus
function clearForm(field) {
	field.value = "";
}
// Highlight the text on onfocus
function selectFormText(field) {
	field.select();
}
//-->

// ADD FIELDS TO FORMS. THIS DUPLICATES A SECTION OF A FORM, BASED ON A TEMPLATE IN THE PAGE, AND ADDS IT TO THE OVERALL FORM
var counter = 0;
function moreFields(readroot, writeroot) {
	counter++;
	var newFields = document.getElementById(readroot).cloneNode(true);
	newFields.id = '';
	newFields.style.display = 'block';
	var newField = newFields.childNodes;
	for (var i=0;i<newField.length;i++) {
		var theName = newField[i].name
		if (theName)
			newField[i].name = theName + counter;
	}
	var insertHere = document.getElementById(writeroot);
	insertHere.parentNode.insertBefore(newFields,insertHere);
}

// ALTERNATING ROWS

function colorRows() {
	if(document.getElementById('zebra_list')){
	   var myTR =  document.getElementById('zebra_list').getElementsByTagName('p');
       for (var i=0;i<myTR.length;i++) {
               if (!(i%2)) {
                       myTR[i].className = 'rowTint';
               }
       }
       }
}
addLoadEvent(colorRows);

