//allows you to add multiple load events
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

//adds hint boxes to specified input forms
function prepareInputsForHints() {
	var formElements = ["input", "select", "textarea"];
	for(var g=0; g < formElements.length; g++){
	
		var inputs = document.getElementsByTagName(formElements[g]);
	
		for (var i=0; i<inputs.length; i++){
			// test to see if the hint span exists first
			if (inputs[i].parentNode.getElementsByTagName("span")[0]) {
				// the span exists!  on focus, show the hint
				inputs[i].onfocus = function () {
					if(this.type != "button" && this.id != "searchbox"){
						formAreaHighlight(this.parentNode.parentNode.id);
					}
					//formAreaHighlight(this.parentNode.getAttribute(id));
					this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
				}
				// when the cursor moves away from the field, hide the hint
				inputs[i].onblur = function () {
					this.parentNode.getElementsByTagName("span")[0].style.display = "none";
				}
			} else{
				
				inputs[i].onfocus = function () {
					if(this.type != "button" && this.id != "searchbox"){
						formAreaHighlight(this.parentNode.parentNode.id);
					}
				}
			}
		}
	}
}

var currentObj = null;

//highlights the current section of the form you are currently active in
function formAreaHighlight(obj) {
	if (currentObj != null) {
		document.getElementById(currentObj).style.backgroundColor = "#ffffff";
	}
	document.getElementById(obj).style.backgroundColor = "#E6F0F9";
	currentObj = obj;
}

function newWin(WinURL, WinNAME, WinWIDTH, WinHEIGHT, WinRESIZE, WinSCROLL, WinTOOLBAR)
{	
	/*	variables passed by the link calling the function	*/
	var URL = WinURL;
	var WINDOW_NAME = WinNAME;
	var POPUP_WIDTH = WinWIDTH;
	var POPUP_HEIGHT = WinHEIGHT;
	var POPUP_RESIZE = WinRESIZE;
	var POPUP_SCROLL = WinSCROLL;
	var POPUP_TOOLBAR = WinTOOLBAR;

	/*	window properties that determine the window attributes depending on what values are passed by the link calling the function	*/
	var window_toolbar = POPUP_TOOLBAR;
	var window_resize = POPUP_RESIZE;
	var window_scroll = POPUP_SCROLL;
	var window_width = POPUP_WIDTH;
	var window_height = POPUP_HEIGHT;
	var screen_balance_w = ((screen.width)-(window_width))/2;
	var screen_balance_h = ((screen.height)-(window_height))/2;
	var set_top = screen_balance_h;
	var set_left = screen_balance_w;	

	win = window.open(URL,WINDOW_NAME,'resizable=' + window_resize + ',toolbar=' + window_toolbar + ',scrollbars=' + window_scroll + ',width=' + window_width + ',height=' + window_height + ',top=' +  set_top + ',left=' + set_left + '');
	win.focus();
}
