if (typeof(defined_event_handlers)=="undefined") {
	var defined_event_handlers = new Array();
}
function add_event_handler(obj, handler, function_handler) {
	var handler_already_defined = false;
	for (var i=0; i<defined_event_handlers.length; i++) {
		if ((obj+"."+handler+"="+function_handler) == defined_event_handlers[i]) {
			handler_already_defined = true;
			break;
		}
	}
	if (!handler_already_defined) {
		defined_event_handlers[defined_event_handlers.length] = obj+"."+handler+"="+function_handler;
		var old_handler = eval(obj+"."+handler);
		if (typeof(old_handler)=="function") {
			eval(obj+"."+handler+"= function (event){old_handler(event); "+function_handler+"(event);}");
		}
		else {
			eval(obj+"."+handler+"= function (event){"+function_handler+"(event);}");
		}
	}
}


var docom = (document.getElementById);
var docall = (document.all)

if (window.innerHeight) page_height=window.innerHeight;
if (window.innerWidth) page_width=window.innerWidth;
if (screen.availWidth) page_width=screen.availWidth - 30;
if (screen.availHeight) page_height=screen.availHeight - 30;

if (document.layers) {
	document.captureEvents(Event.MOUSEMOVE);
	document.captureEvents(Event.MOUSEDOWN);
	SHOW = "show";
	HIDE = "hide";
}
else {
	SHOW = "visible";
	HIDE = "hidden";
}

var x_loc = 0;
var y_loc = 0;

function locate(e) {
	if (e) {
		x_loc = e.pageX;
        y_loc = e.pageY;
    } else {
        x_loc = window.event.clientX;
        y_loc = window.event.clientY;
	}
}

//get an element by its id
function get_element(layer_name) {
	if (docall) return document.all[layer_name].style;
	else if (docom) return document.getElementById(layer_name).style;
	else if (document.layers) return eval('document.layers["'+layer_name+'"]');
}

//position an element (layer) on the screen
function position_element(theelement, x_pos, y_pos) {
	if (!theelement) return;
	element_width = parseInt(theelement.width);
	if (x_pos < 0) x_pos = 0;
	else if (x_pos + element_width > page_width) x_pos = page_width - element_width;
	if (y_pos < 0) y_pos = 0;
	theelement.left = x_pos;
	theelement.top = y_pos;
}

//change an element's visibility
function visibility_element(theelement, visibility) {
	if (!theelement) return;
	theelement.visibility = visibility;
}

//document.onmousemove=locate;
add_event_handler("document", "onmousemove", "locate");


function trim(str) {
	// Remove from beginning
	while (str.substr(0, 1)==" ") {
		str = str.substr(1, str.length);
	}
	// Remove from end
	while (str.substr((str.length-1), 1)==" ") {
		str = str.substr(0, (str.length-1));
	}
	return str;
}

// Transfers text/value from one select box to another.
// from is the source select box object
// to is the destination select box object
// transfer all is a boolean that tells whether to transfer all of the sources values to the destination
// add_and_remove is a string that accepts the following values
//		add - Adds text/value from source to destination and leaves it in the source
//		remove - Removes the text/value from the source and does not affect destination
//		add_and_remove - Adds text/value to destination and removes the text/value from the source
// 		blank_line - boolean tells whether or not select box has the blank line in zeroth position.
function transfer_select_values(from, to, transfer_all, add_and_remove, blank_line) {
	if (!add_and_remove)
		add_and_remove = "add_and_remove";
	if (blank_line!=0)
		blank_line = true;
	var i;
	if (blank_line)	i=1;
	else i=0;
	for (i; i < from.length; i++) {
		if (transfer_all || from.options[i].selected) {
			if ((add_and_remove == "add") || (add_and_remove == "add_and_remove"))
				add_option(to, from.options[i].text, from.options[i].value);
			if ((add_and_remove == "remove") || (add_and_remove == "add_and_remove")) {
				from.options[i] = null;
				i--;
			}
		}
	}
}

function save_selected_data(select_box, save_to_hidden, blank_line, value_type, delimiter) {
	var data_array = new Array();
	if (blank_line!=0) {
		blank_line = true;
	}
	if (!value_type) {
		value_type="value";
	}
	if (!delimiter)
	{
		delimiter = ";";
	}
	
	var i;
	var j=0;
	if (blank_line)	i=1;
	else i=0;
	data_string = '';
	for (i; i < select_box.length; i++) {
		if (value_type == "text") {
			//data_array[j] = select_box.options[i].text;
			if(!data_string)
				data_string = select_box.options[i].text;
			else
				data_string += delimiter + select_box.options[i].text;
		}
		else {
			//data_array[j] = select_box.options[i].value;
			if(!data_string)
				data_string = select_box.options[i].value;
			else
				data_string += delimiter + select_box.options[i].value;
		}
		j++;
	}
	save_to_hidden.value=data_string;
	//save_to_hidden.value=data_array.join(delimiter);
	//alert(save_to_hidden.value);
	return true;
}


function save_single_box_selected_data(select_box, save_to_hidden, blank_line, value_type, delimiter) {
	var data_array = new Array();
	if (blank_line!=0) { blank_line = true; };
	
	if (!value_type) { value_type="value"; };
	
	if (!delimiter) { delimiter = ";"; };
	
	var i;
	var j=0;
	if (blank_line)	{ i=1; } else { i=0; }
	
	for (i; i < select_box.length; i++) {
		with ( select_box.options[ i ] ) {
			if ( selected) {
				if ( ( value_type == "text" ) && ( -1 != text.search( /\S/ ) ) ){ data_array[ j++ ] = text; }
				else if ( -1 != value.search( /\S/ ) )							{ data_array[ j++ ] = value; };// end if
			};// end if
		};// end with
	};// end for
	save_to_hidden.value=data_array.join(delimiter);
	//alert(save_to_hidden.value);
	return true;
};// end save_single_box_selected_data

function load_hidden_data(select_box, hidden_to_load, clear_data, blank_line) {
	if (clear_data) select_box.length = blank_line+0;
	if (hidden_to_load.value == "") return;
	var values_to_load = hidden_to_load.value.split(";");
	
	for (var i = 0; i < values_to_load.length; i++ ) {
		select_box.options[select_box.length] = new Option(values_to_load[i], values_to_load[i]);
	}
}

// Adds a new option to the end of the select box
// select_box: object to add new option to
// the_text: string value of text portion of option
// the_value: string value of value portion of option
function add_option(select_box, the_text, the_value) {
	select_box.options[select_box.length] = new Option(the_text, the_value);
}

// Removes all selected items from the select box
// select_box: object to remove selected items from
function remove_selected(select_box, blank_line) {
	if (blank_line!=0)
		blank_line = true;
	var i;
	if (blank_line)	i=1;
	else i=0;
	for(i; i<select_box.options.length; i++) {
		if (select_box.options[i].selected) {
			select_box.options[i]=null;
			i--;
		}
	}
}

function remove_option(select_box, box_value, blank_line) {
	if (select_entry(select_box, box_value, blank_line)) {
		remove_selected(select_box, blank_line);
	}
}


function remove_to_txt(sbox, txt_tgt, val_tgt, blank_line)
{
	if (blank_line != 0)
		blank_line = true;
	if (sbox.selectedIndex == -1) {
		return;
	}
	if (sbox.selectedIndex == 0 && blank_line)
		return;
	else
	{
		txt_tgt.value = sbox.options[sbox.selectedIndex].text;
		val_tgt.value = sbox.options[sbox.selectedIndex].value;
		sbox.options[sbox.selectedIndex] = null;
	}
}
	
	
	

// Swaps the values of a select box
// select_box: object with values to swap
// position1: index of first value
// position2: index of second value
// positonn1 and position2 values will be swapped.
function swap_select_values(select_box, position1, position2)
{
	var position1_text = select_box.options[position1].text;
	var position1_value = select_box.options[position1].value;
	select_box.options[position1].text = select_box.options[position2].text;
	select_box.options[position1].value = select_box.options[position2].value;
	select_box.options[position2].text = position1_text;
	select_box.options[position2].value = position1_value;
}

// Moves values in a select box up or down
// select_box: object with values to sort
// direction: string ('up' or 'down')
// blank_line: boolean tells whether or not select box has the blank line in zeroth position.
function sort_select_values(select_box, direction, blank_line)
{
	var selected_index = select_box.options.selectedIndex;
	if (direction == "up")
	{
		var top_index = 0;
		if (blank_line)
			top_index = 1;
		if (selected_index > top_index) {
			swap_select_values(select_box, selected_index, selected_index-1)
			select_box.options.selectedIndex=selected_index-1;
		}
	}
	else if (direction == "down")
	{
		var top_index = 0;
		if (blank_line==0)
			top_index = -1;
		if (selected_index < select_box.options.length-1 && selected_index > top_index) {
			swap_select_values(select_box, selected_index, selected_index+1)
			select_box.options.selectedIndex=selected_index+1;
		}
	}
}

// Removes all items from the select box
// select_box: object to remove selected items from
function remove_all(select_box, blank_line) {
	if (blank_line!=0)
		blank_line = true;
	if (blank_line)	select_box.length=1;
	else select_box.length=0;
}

// Searches the select box for a value and makes it the selectedIndex if found.
// select_box: object to search
// box_value: value to search for
function select_entry(select_box, box_value, blank_line)
{
	if (blank_line!=0)
		blank_line = true;
	var i;
	if (blank_line) i=1;
	else i=0;
	for (i; i < select_box.options.length; i++)
	{
		if (select_box.options[i].value == box_value)
		{
			select_box.options.selectedIndex=i;
			return true;
		}
	}
	return false;
}

// Open a new browser window and return the handle
function open_new_window(url, window_name, height, width, top, left, location, show_scrollbars, show_toolbar, show_menubar, is_resizeable, always_raised, focused, fullscreen) {
	if (!top) var top = 0;
	if (!left) var left = 0;
	if (!location) var location = 0;
	if (!show_scrollbars && show_scrollbars!=0) var show_scrollbars = 1;
	if (!show_toolbar && show_toolbar!=0) var show_toolbar = 1;
	if (!show_menubar && show_menubar!=0) var show_menubar = 1;
	if (!is_resizeable && is_resizeable!=0) var is_resizeable = 1;
	if (!always_raised && always_raised!=0) var always_raised = 1;
	if (!focused && focused!=0) var focused = 1;
	if (!fullscreen && fullscreen!=0) var fullscreen = 0;
	
	var extras = "top=" + top + ",left=" + left + ",width=" + width + ",height=" + height + ",location=" + location + ",toolbar=" + show_toolbar;
	extras += ",scrollbars=" + show_scrollbars + ",resizable=" + is_resizeable + ",menubar=" + show_menubar + ",alwaysRaised=" + always_raised;
	extras += ",fullscreen=" + fullscreen;
	var win_handle = window.open(url, window_name, extras);
	if (focused) win_handle.focus();
	return win_handle;
}

function open_new_centered_window(url, window_name, height, width, location, show_scrollbars, show_toolbar, show_menubar, is_resizeable, always_raised, focused, fullscreen) {
	var w = 640, h = 480;
	if (document.all || document.layers) {
		w = screen.availWidth;
		h = screen.availHeight;
	}
	var left = (w-width)/2;
	var top = (h-height)/2;
	if (!location) var location = 0;
	if (!show_scrollbars && show_scrollbars!=0) var show_scrollbars = 1;
	if (!show_toolbar && show_toolbar!=0) var show_toolbar = 1;
	if (!show_menubar && show_menubar!=0) var show_menubar = 1;
	if (!is_resizeable && is_resizeable!=0) var is_resizeable = 1;
	if (!always_raised && always_raised!=0) var always_raised = 1;
	if (!focused && focused!=0) var focused = 1;
	if (!fullscreen && fullscreen!=0) var fullscreen = 0;
	
	var extras = "top=" + top + ",left=" + left + ",width=" + width + ",height=" + height + ",location=" + location + ",toolbar=" + show_toolbar;
	extras += ",scrollbars=" + show_scrollbars + ",resizable=" + is_resizeable + ",menubar=" + show_menubar + ",alwaysRaised=" + always_raised;
	extras += ",fullscreen=" + fullscreen;
	var win_handle = window.open(url, window_name, extras);
	if (focused) win_handle.focus();
	return win_handle;
}

function set_date_box(form_name, field_name, hidden_date, year, month, day, allow_dates_out_of_range, blank_line)
{
	var year_selected;
	var month_selected;
	var day_selected;
	if (blank_line!=0)
		blank_line=true;

	if (!(year_selected=select_entry(eval("document."+form_name+"."+field_name+"_year"), year, blank_line)) && !allow_dates_out_of_range )
		alert ("The year you chose was not valid");
	else {
		if (!year_selected) add_option(eval("document."+form_name+"."+field_name+"_year"), year, year);
		select_entry(eval("document."+form_name+"."+field_name+"_year"), year, blank_line);
	}
	if (!(month_selected=select_entry(eval("document."+form_name+"."+field_name+"_month"), month, blank_line)) && !allow_dates_out_of_range )
		alert ("The month you chose was not valid");
	else {
		if (!month_selected) add_option(eval("document."+form_name+"."+field_name+"_month"), month, month);
		select_entry(eval("document."+form_name+"."+field_name+"_month"), month, blank_line);
	}
	if (!(day_selected=select_entry(eval("document."+form_name+"."+field_name+"_day"), day, blank_line)) && !allow_dates_out_of_range )
		alert ("The day you chose was not valid");
	else {
		if (!day_selected) add_option(eval("document."+form_name+"."+field_name+"_day"), day, day);
		select_entry(eval("document."+form_name+"."+field_name+"_day"), day, blank_line);
	}
	changeDate(eval("document."+form_name+"."+field_name+"_year"), eval("document."+form_name+"."+field_name+"_month"), eval("document."+form_name+"."+field_name+"_day"), eval("document."+form_name+"."+hidden_date), blank_line);
}


function changeDate(yearbox, monthbox, daybox, thedate, blank_line) {
	year = parseInt(yearbox.options[yearbox.options.selectedIndex].value);
	month = monthbox.options[monthbox.options.selectedIndex].value;
	day = daybox.options[daybox.options.selectedIndex].value;
	
	if(month == '01'||month == '03'||month == '05'||month == '07'||
						month == '08'||month == '10'||month == '12') {
		maxday = 31;
	}
	else if(month == '04'||month == '06'||month == '09'||month == '11') {
		maxday = 30;
	}
	else if(month == '02' && year%4 == 0) {
		maxday = 29;			
	}
	else {
		maxday = 28;
	}
	
	//alert ("Maxday: " + maxday + "\nlength: " + daybox.length);
	remove_all(daybox, blank_line);
	for (i=1; i<=maxday; i++) {
		if (i < 10)
			add_option(daybox, "0"+i, "0"+i);
		else
			add_option(daybox, i, i);
	}
	select_entry(daybox, day, blank_line);

	// get new day value
	day = daybox[daybox.selectedIndex].value;
	
	if((year != '') && (!isNaN(year)) && (month != '') && (day != '')) {
		thedate.value = year + '-' + month + '-' + day;
	}
	else {
		thedate.value = '0000-00-00';
	}
	
//	alert(thedate.value);	
}


function select_date(include_path, form_name, date_box_name, blank_line)
{
	var year_select = eval('document.'+form_name+'.'+date_box_name+'_year');
	var month_select = eval('document.'+form_name+'.'+date_box_name+'_month');
	var current_date = new Date();
	var chosen_year = current_date.getYear();
	var chosen_month = current_date.getMonth();
	if (year_select.options[year_select.selectedIndex].value > 0) chosen_year = year_select.options[year_select.selectedIndex].value;
	if (month_select.options[month_select.selectedIndex].value > 0) chosen_month = month_select.options[month_select.selectedIndex].value;
	open_new_window(include_path+'components/select_date.php?include_path='+escape('../'+include_path)+'&hidden_date='+date_box_name+'&form_name='+form_name+'&name='+date_box_name+'&chosen_year='+chosen_year+'&chosen_month='+chosen_month+'&blank_line='+blank_line,'date_window',200,200,300,300,0,1,0,0,1,1);
}

function check_from_to_date_range(from_date, to_date, description)
{
	if (from_date.value=='0000-00-00' || to_date.value=='0000-00-00' || from_date.value > to_date.value) {
		alert("Invalid date range for "+description);
		return false;
	}
	else 
		return true;
}

function percent_completed(theobject,pbar_name) {
	percent=theobject.value;
	if (document.layers) document.embeds[pbar_name].GotoFrame(parseInt(percent)+1);
	else document.all[pbar_name].GotoFrame(parseInt(percent)+1);
}

function copy_to_clipboard(txt_area, span_id)
{
	txt_area.innerText = span_id.innerText;
	Copied   	       = txt_area.createTextRange();
	Copied.execCommand("RemoveFormat");
	Copied.execCommand("Copy");
}




// **********************
// Tabbed Group Functions
// **********************

// Changes the tab 
function change_tab(tab_id,group_name,styleName,callback) {	
	
	var new_active_pane = document.getElementById(tab_id.replace(/_tab_/, "_pane_"));
	var active_pane_id = group_name+"_active_pane";
	var old_active_tab = document.getElementById(eval(active_pane_id).id.replace(/_pane_/, "_tab_"));
	var active_callback = group_name+"_active_callback";
	
	if(eval(active_pane_id) != new_active_pane) {
		if(eval(active_callback)) {
			var callback_func = eval(active_callback);
			if(!eval(callback_func+"()")) return;	
		}
	
		// Change Display Styles
		eval(active_pane_id+".style.display = 'none'");
		new_active_pane.style.display = "block";
		
		// Update Tab Classes
		old_active_tab.className = styleName+"-inactive-tab";
		document.getElementById(tab_id).className = styleName+"-active-tab";
		
		// Update Global Vars
		eval(active_pane_id+" = new_active_pane");
		eval(active_callback+" = callback");
	}
}
// Sets the initial global var
function set_active_pane(var_prefix, pane, callback) {
	eval(var_prefix + "_pane = document.getElementById(pane)");
	eval(var_prefix + "_callback = '" + callback + "'");
}

function check_all(the_form, on_off) {
	if (!on_off) on_off=false;
	
	for (var i=0; i<the_form.elements.length; i++) {
		if (the_form.elements[i].type=="checkbox") the_form.elements[i].checked=on_off;
	}
}

// ***********************
// SSN Fuction
// ***********************
function save_ssn_component(pf, hidden_name) {
	hidden = eval("pf. " + hidden_name);
	area_num = eval("pf." + hidden_name + "_area_num.value");
	group_num = eval("pf." + hidden_name + "_group_num.value");
	serial_num = eval("pf." + hidden_name + "_serial_num.value");
	hidden.value = area_num + '-' + group_num + '-' + serial_num;
}

// ***********************
// Phone Fuction
// ***********************
function save_phone_component(pf, hidden_name) {
	hidden = eval("pf. " + hidden_name);
	area = eval("pf." + hidden_name + "_area.value");
	prefix = eval("pf." + hidden_name + "_prefix.value");
	suffix = eval("pf." + hidden_name + "_suffix.value");
	hidden.value = area + '-' + prefix + '-' + suffix;
}

// ***********************
// Drop Down Entry Function
// ***********************
function init_drop_down_entry(prefix) {
	
	var entry = document.getElementById(prefix+"_entry");
	var btn = document.getElementById(prefix+"_dd_btn");
	var box = document.getElementById(prefix+"_box");
	var dd_div = document.getElementById(prefix+"_dd_div");
	
	// Complete init after page has finished loading	
	setTimeout(function() {init_drop_down_entry2(entry,btn,box,dd_div)}, 10);
}

function init_drop_down_entry2(entry,btn,box,dd_div) {
	// Loop until page is loaded
	if(box.getBoundingClientRect().bottom == 0) {
		setTimeout(function() {init_drop_down_entry2(entry,btn,box,dd_div)}, 10);
		return;
	}

	// Set size of whole widget
	box.style.pixelWidth = entry.offsetWidth + btn.offsetWidth + 4;
	
	// Position drop down div
	dd_div.style.pixelLeft = box.getBoundingClientRect().left - 2;
	dd_div.style.pixelTop = box.getBoundingClientRect().bottom - 2;

	// Set height of drop down div
	if(dd_div.offsetHeight > 150) {
		dd_div.style.pixelHeight = 150;
	}

	
	// Size Divs
	var thewidth = dd_div.offsetWidth + 2*parseInt(dd_div.style.borderWidth);
	var i;
	for(i=0;i<dd_div.children.length;i++) {
		dd_div.children(i).style.pixelWidth = thewidth;
	}	
		
		
	// setup event handlers	
	btn.onclick = function() {drop_down_click(entry,btn,dd_div,box)}
	entry.onclick = function() {dd_open_close(btn,dd_div,'close')}
	btn.onblur = function() { 
						var dd_div_rect = dd_div.getBoundingClientRect();
						if(event.x < dd_div_rect.left || event.x > dd_div_rect.right || event.y < dd_div_rect.top || event.y > dd_div_rect.bottom) {
							dd_open_close(btn,dd_div,'close') 
						}
				  }
	dd_div.onfocus = function() {btn.focus()}
}

function drop_down_click(entry,btn,dd_div,box) {
	var cur_text = entry.value;
	var i;


	// Highlight Selected Item before showing dd_div
	for(i=0;i<dd_div.children.length && dd_div.children(i).innerText != cur_text;i++);
	if(i<dd_div.children.length) {
		dd_highlight(dd_div.children(i),"on");
	}
	else {
		dd_highlight(dd_div.children(0),"off");
	}
	
	// Toggle dd_div
	dd_open_close(btn,dd_div,'toggle');
}

// Open/Close/Toggle dd_div
function dd_open_close(btn,dd_div,flag) {
	var prefix = btn.style.backgroundImage.substring(4, btn.style.backgroundImage.length-1);
	prefix = prefix.substring(0,prefix.lastIndexOf("/")+1);
	
	if(flag=='open') {
		btn.style.backgroundImage = "url("+prefix+"dd_arrow_pressed.png)";
		dd_div.style.visibility = "visible";
	}
	else if(flag=='close') {
		btn.style.backgroundImage = "url("+prefix+"dd_arrow.png)";
		dd_div.style.visibility = "hidden";
	}
	else {
		btn.style.backgroundImage = (/pressed/.test(btn.style.backgroundImage)) ? "url("+prefix+"dd_arrow.png)" : "url("+prefix+"dd_arrow_pressed.png)";
		dd_div.style.visibility = (dd_div.style.visibility == 'visible') ? "hidden" : "visible";
	}
}

// Called on selection of item
function dd_select(txt, prefix) {
	var entry = document.getElementById(prefix+"_entry");
	var dd_div = document.getElementById(prefix+"_dd_div");
	var btn = document.getElementById(prefix+"_dd_btn");
	entry.value = txt;

	dd_open_close(btn,dd_div,'close');
	if(entry.onchange) {
		entry.onchange();
	}
}


// Hightlight row -- allows only one row to be highlighted
function dd_highlight(row, flag) {
	var dd_div = row.offsetParent;
	var prefix = dd_div.id.substr(0,dd_div.id.length-7);
	var entry = document.getElementById(prefix+"_entry");
	var row_background = get_style(entry,'background');
	var row_color = get_style(entry,'color');
	
	dd_div.style.background = get_style(entry,'background');
	
	for(i=0;i<dd_div.children.length;i++) {
		if(flag=='on' && dd_div.children(i) == row) {
			dd_div.children(i).style.background = 'highlight';
			dd_div.children(i).style.color = 'highlighttext';
		}
		else {
			dd_div.children(i).style.background = row_background;
			dd_div.children(i).style.color = row_color;
		}
	}
}


function get_style(element, style_name) {
	// Get in-line style
	var style_value = eval("element.style."+style_name);
	
	// Get style from class
	var class_name = "."+element.className;
	if(class_name && !style_value) {
		// Get style obj
		for(j=0;j<document.styleSheets.length;j++) {
			var all_rules = document.styleSheets(j).rules;
			var i = 0;
			for(i=0;i<all_rules.length && all_rules(i).selectorText != class_name;i++);
			if(i<all_rules.length) {
				style_value = eval("all_rules(i).style."+style_name);
			}
		}
	}

	return style_value;	
}

function set_time(time_hidden) {
	var the_form = time_hidden.form;
	var time_arr = new Array();
	hour_object = eval("the_form." + time_hidden.name + "_hour");
	time_arr[0] = hour_object.options[hour_object.selectedIndex].value;
	minute_object = eval("the_form." + time_hidden.name + "_minute");
	time_arr[1] = minute_object.options[minute_object.selectedIndex].value;
	am_pm_object = eval("the_form." + time_hidden.name + "_am_pm");
	if (am_pm_object) time_arr[2] = am_pm_object.options[am_pm_object.selectedIndex].value;
	time_hidden.value = time_arr.join(':');
}

function url_decode(the_string) {
	the_string = unescape(the_string);

	var codes = new Array("\\+");//"%3A", "%2F", "%3F", "%3D", "%20", "%22", "%3C", "%3E", "%25", "%7B", "%7D", "%7C", "%5C", "%5E", "%7E", "%5B", "%5D", "%60");
	var code_replacements = new Array(" ");//":", "/", "?", "=", " ", "\"", "<", ">", "%", "{", "}", "|", "\\", "^", "~", "", "", "`");
	var eval_string="";
	for (var i=0; i < codes.length; i++) {
		eval_string = "the_string = the_string.replace(/"+codes[i]+"/gi, code_replacements[i]);";
		eval(eval_string);
	}
	return the_string;
}

function ereg_replace(what,with_what,str,global) {
	global = ((typeof(global)!="undefined") ? global : false);
	if (global) {
		var reg = new RegExp(what, "g");
		new_str = str.replace(reg, with_what);
	}
	else {
		if (-1==str.indexOf(what)) return str;
		str_start=str.indexOf(what);
		str_end=str_start+what.length-1;
		
		new_str=str.substr(0,str_start)+with_what+str.substr(str_end+1);
	}
	return new_str;
}

function swapButtonImages(prefix, on, image_path) {
	document.getElementById(prefix+"-left").style.backgroundImage =   ((on) ? "url("+image_path+"black-button-left.gif)"   : "url("+image_path+"gray-button-left.gif)");
	document.getElementById(prefix+"-middle").style.backgroundImage = ((on) ? "url("+image_path+"black-button-middle.gif)" : "url("+image_path+"gray-button-middle.gif)");
	document.getElementById(prefix+"-right").style.backgroundImage =  ((on) ? "url("+image_path+"black-button-right.gif)"  : "url("+image_path+"gray-button-right.gif)");
}

function swapButtonImages2(imagePath, flag, left, middle, right) {
	var image_prefix = imagePath + ((flag) ? "black" : "gray");
	var left_image   = "url("+image_prefix+"-button-left.gif)";
	var middle_image = "url("+image_prefix+"-button-middle.gif)";
	var right_image  = "url("+image_prefix+"-button-right.gif)";
	
	if (((left.imageState == "off") && flag) || ((left.imageState == "on") && !flag)) {
		left.style.backgroundImage = left_image;
		left.imageState = ((left.imageState == "off") ? "on" : "off");
	}

	if (((middle.imageState == "off") && flag) || ((middle.imageState == "on") && !flag)) {
		middle.style.backgroundImage = middle_image;
		middle.imageState = ((middle.imageState == "off") ? "on" : "off");
	}

	if (((right.imageState == "off") && flag) || ((right.imageState == "on") && !flag)) {
		right.style.backgroundImage = right_image;
		right.imageState = ((right.imageState == "off") ? "on" : "off");
	}
}

function submit_image_button(the_form) {
//	alert(the_form.onsubmit() != false);
	if(typeof(the_form.onsubmit) != 'function' || the_form.onsubmit() != false) {
		the_form.submit();
	}
}

// -------------------------------------------------------------------
// TabNext()
// Function to auto-tab phone field
// Arguments:
//   obj :  The input object (this)
//   event: Either 'up' or 'down' depending on the keypress event
//   len  : Max length of field - tab when input reaches this length
//   next_field: input object to get focus after this one
// -------------------------------------------------------------------
var phone_field_length=0;
function TabNext(obj, event, len, next_field, select_text) {
	if (event == "down") {
		field_length=obj.value.length;
	}
	else if (event == "up") {
		if (obj.value.length != field_length) {
			field_length=obj.value.length;
			if (field_length == len) {
				next_field.focus();
				if (select_text) {
					next_field.select();
				}
			}
		}
	}
}


// below simply animates the loading message
// begin load message animation
var load_animation = false;
var load_animation_counter = 0;
var load_animation_max_counter = 15;
function run_load_animation(id) {
	if (load_animation) {
		// we cannot allow the string to get too long
		// begin correcting code
		load_animation_counter++;
		if (load_animation_counter > load_animation_max_counter) { // load the initial string to reset the dots
			var dots_style = "color:#1030a0; font-family:webdings;";
			document.getElementById(id).innerHTML = "&nbsp;Loading&nbsp;<span style='"+dots_style+"' id='"+id+"-dots'></span>";
			load_animation_counter = 0;
		}
		// end correcting code

		if (document.getElementById(id+'-dots')) {
			document.getElementById(id+'-dots').innerHTML = document.getElementById(id+'-dots').innerHTML + "&lt;";
			setTimeout("run_load_animation('"+id+"')", 100);
		}
	}
}

function start_load_animation(id) {
	//alert("stopping other animations and starting a new one");
	stop_load_animation();
	if (document.getElementById(id)) {
		load_animation = true;
		load_animation_counter = load_animation_max_counter+1; // to ensure the initial string will be loaded
		run_load_animation(id);
	}
}

function stop_load_animation() {
	clearTimeout();
	load_animation = false;
}
// end load message animation

//External content component function to move content within a layers clip region
//Only used by netscape
function move_dc_layer(ele_id, direction) {
	if (document.layers) {
		var the_layer = document.layers[ele_id+"_NS4"];
		the_layer.top -= direction;
		the_layer.clip.top += direction;
		the_layer.clip.bottom += direction;
	}
}

function multistate_checkbox_toggle_state(state, image, bin_path, h_value, h_value_holder, state_value) {
	if (parseInt(state_value)==state_value){
		if (state_value == 0) {
			image.src = bin_path+"checkbox_unchecked.jpg";
			state.value = 0;
			h_value.value = "";
		}
		else if (state_value == 1) {
			image.src = bin_path+"checkbox_checked.jpg";
			state.value = 1;
			h_value.value= h_value_holder.value;
		}
		else {
			image.src = bin_path+"checkbox_grayed.jpg";
			state.value = 2;
			h_value.value="";
		}
	}
	else {
		if (state.value == 0) {
			image.src = bin_path+"checkbox_checked.jpg";
			state.value = 1;
			h_value.value = h_value_holder.value;
		}
		else {
			image.src = bin_path+"checkbox_unchecked.jpg";
			state.value = 0;
			h_value.value="";
		}
	}
}

function get_contents(field_to_eval) {
	return eval(field_to_eval);
}


function reset_the_form(the_form, hidden_vars_to_reset) {
	for (var i=0; i < the_form.elements.length; i++) {
		switch (the_form.elements[i].tagName.toUpperCase()) {
			case "INPUT":
				switch (the_form.elements[i].type.toLowerCase()) {
					case "text" :
						the_form.elements[i].value = "";
					break;
					case "radio": case "checkbox":
						the_form.elements[i].checked = false;
					break;
					/*case "hidden":
						alert(the_form.elements[i].name);
						if (hidden_vars_to_reset && hidden_vars_to_reset[the_form.elements[i].name]) {
							alert("hidden: "+the_form.elements[i].name+" reset");
							the_form.elements[i].value = "";
						}*/
					break;
				}
				break;
			case "SELECT":
				the_form.elements[i].selectedIndex=0;
				break;
			case "TEXTAREA":
				the_form.elements[i].value = "";
				break;
		}
		if (the_form.elements[i].onchange) {
			the_form.elements[i].onchange();
		}
	}
}


// *** Progress Bar
function progress_bar(form_name, progress_bar_name, include_path, percent_complete, show_elapsed_time, show_remaining_time) {
	this.form_name = form_name;
	this.progress_bar_name = progress_bar_name;
	this.percent_complete = parseInt(percent_complete, 10);
	this.include_path = include_path;
	this.prev_percent = 0;
	this.show_elapsed_time = show_elapsed_time;
	this.show_remaining_time = show_remaining_time;
	this.elapsed_time_interval;
	if (this.show_elapsed_time) { this.elapsed_time_interval = setInterval(this.progress_bar_name+"_progress_bar_instance.update_progress_bar_elapsed_time()", 1000); }
	
	var d = new Date();
	this.start_time = d.getTime();
	
	this.update_progress_bar = function(percent_complete) {
		this.percent_complete = parseInt(percent_complete, 10);
		if (this.percent_complete>0) {
			if (this.percent_complete < this.prev_percent) {
				for (var i=this.percent_complete; i < this.prev_percent; i++) {
					eval("document."+this.progress_bar_name+"_image_"+i).src=this.include_path+'components/component_bin/progress_bar_white.jpg';
				}
			}
			for (var i=this.prev_percent; i < this.percent_complete; i++) {
				eval("document."+this.progress_bar_name+"_image_"+i).src=this.include_path+'components/component_bin/progress_bar_blue.jpg';
			}
			eval("document."+this.form_name+"."+this.progress_bar_name+"_progress_bar_percent_complete").value=""+this.percent_complete+"%";
			if (this.show_remaining_time) { eval("document."+this.form_name+"."+this.progress_bar_name+"_progress_bar_time_remaining").value=this.format_time(this.get_estimated_time_remaining(), false); }
			this.prev_percent = this.percent_complete;
		}
	}
	
	this.update_progress_bar_elapsed_time = function () {
		var est_time_hidden = eval("document."+this.form_name+"."+this.progress_bar_name+"_progress_bar_elapsed_time_hidden");
		est_time_hidden.value = parseInt(est_time_hidden.value, 10)+1000;
		var est_time = this.format_time(eval("document."+this.form_name+"."+this.progress_bar_name+"_progress_bar_elapsed_time_hidden").value, true);
		if (est_time == "Complete") {
			clearInterval(this.elapsed_time_interval);
		}
		else {
			eval("document."+this.form_name+"."+this.progress_bar_name+"_progress_bar_elapsed_time").value = est_time;
		}
	}


	this.get_elapsed_time = function () {
		var new_date = new Date();
		return (new_date.getTime() - this.start_time);
	}
	
	this.get_estimated_time_remaining = function () {
		if (this.percent_complete <= 0) {
			return 0;
		}
		var elapsed_time = this.get_elapsed_time();
		var remaining = (((elapsed_time/this.percent_complete)*100) - elapsed_time);
		return ((remaining > 0) ? remaining : 0);
	}
	
	this.format_time = function (the_time, show_seconds) {
		var seconds = the_time/1000;
		var display_h;
		var display_m;
		var display_s;
		if (seconds < 60) {
			display_s = Math.floor(seconds);
		}
		else {
			var minutes = Math.floor(seconds / 60);
			seconds = seconds - (minutes * 60);
			if (minutes < 60 ) {
				display_m = minutes
				display_s = Math.floor(seconds);
			}
			else {
				display_h = Math.floor(minutes / 60);
				display_m = minutes - (display_h * 60);
				display_s = Math.floor(seconds);
			}
		}
		var display_time = ((display_h) ? display_h+" hr " : "");
		display_time +=((display_m || display_h) ? display_m+" min " : "");
		display_time +=(((display_h && show_seconds) || (!display_h && (display_m || display_s))) ? display_s+" sec" : "");
		if (!display_time && this.percent_complete < 100) {
			display_time = "";
		}
		else if (!display_time || (this.percent_complete >= 100)) {
			display_time = "Complete";
		}
		return display_time;
	}
}
// *** End Progress Bar


// *** text_dependency
var cur_text_dependency_box = false;
var cur_text_dependency_hidden = false;

function popup_select_box(select_box_name, text_box, text_hidden, form_name, dependent_name) {
	if (dependent_name) {
		var dependent = eval("document."+form_name+"."+dependent_name);
	}
	
	if (dependent && !dependent.value) {
		alert("The field you are trying to select is dependent upon another field.\r\nPlease select a value for that field first.");
		var dependent_text = eval("document."+form_name+"."+dependent_name+"_text");
		dependent_text.focus();
	}
	else {
		cur_text_dependency_box = text_box;
		cur_text_dependency_hidden = text_hidden;
		var popup_url = the_include_path+"components/text_dependency_popup.php?title="+escape(eval(select_box_name+"_title"))+"&name="+eval(select_box_name+"_name")+"&opener_form_name="+eval(select_box_name+"_form")+"&dependent="+((dependent) ? dependent.name : "")+"&the_include_path="+UrlEncode("../"+the_include_path);
		var the_width = eval(select_box_name+"_width");
		var the_height = eval(select_box_name+"_height");
		var top_pos = y_loc + 50;
		var left_pos = x_loc - Math.floor(the_width/2);
		if ((parseInt(left_pos) + parseInt(the_width)) > parseInt(page_width)) {
			left_pos = parseInt(page_width) - parseInt(the_width);
		}
		if ((parseInt(top_pos) + parseInt(the_height)) > parseInt(page_height)) {
			top_pos = parseInt(page_height) - parseInt(the_height);
		}
		// Possible Make IE work with a ModalDialog Box in the future.  Not sure if it is possible with current setup though.
		if (0) {
			var features = "dialogWidth:"+the_width+"px;dialogHeight:"+the_height+"px;dialogLeft:"+left_pos+";dialogTop:"+top_pos+";help:no;status:no;";
			var the_win = window.showModalDialog(popup_url, null, features);
		}
		else {
			var the_win = open_new_window(popup_url, eval(select_box_name+"_win"), the_height, the_width, top_pos, left_pos, 0, 0, 0, 0, 1, 1, 1, 0);
		}
	}
}

function save_popup_select_box_value(select_box) {
	var text_text = select_box.options[select_box.options.selectedIndex].text;
	var text_val = select_box.options[select_box.options.selectedIndex].value;
	if ((cur_text_dependency_box.value != text_text) && (cur_text_dependency_hidden.value != text_val)) {
		reset_dependents(cur_text_dependency_box, cur_text_dependency_hidden);
	}
	cur_text_dependency_box.value = text_text;
	cur_text_dependency_hidden.value = text_val;
	cur_text_dependency_box = false;
	cur_text_dependency_hidden = false;
}

function reset_dependents(text_box, text_hidden) {
	if (!text_box || !text_hidden) {
		return;
	}
	var temp = "typeof("+text_hidden.name+"_dependents)!='undefined'";
	var passed = eval(temp);
	var dependents = ((passed) ? eval(text_hidden.name+"_dependents") : new Array());
	for (var i=0; i < dependents.length; i+=2) {
		var next_text = dependents[i];
		var next_text_hidden = dependents[i+1];
		reset_dependents(next_text, next_text_hidden);
		next_text.value="";
		next_text_hidden.value="";
	}
}

function text_dependency_box_get_key(the_arr, the_val) {
	var key = "";
	for (key in the_arr) {
		if (the_val == the_arr[key]) {
			return key;
		}
	}
	return "";
}
// *** End text_dependency

//used for keyboard events, when a user hits a combination, the system will do the actions specified by the developer
function key_event_register(e){
	if (!e) e = window.event;
	for(var key in key_combo){
		var control_keys = new Array();
		control_keys["CTRL"] = 0;
		control_keys["SHIFT"] = 0;
		control_keys["ALT"] = 0;
		var key_pressed = new Array();

		var curr_combo = key.split(" ");
		for(var j = 0; j < curr_combo.length - 1; j++){
			if(eval("e['"+curr_combo[j].toLowerCase()+"Key']")){
				key_pressed[j] = 1;
				control_keys[curr_combo[j].toUpperCase()] = 1;
			}
			else{
				key_pressed[j] = 0;
				control_keys[curr_combo[j].toUpperCase()] = 0;
			}
		}
		for (var i in control_keys) {
			if (!control_keys[i]) {
				key_pressed[(key_pressed.length)] = ((eval("e['"+i.toLowerCase()+"Key']")) ? 0 : 1);
			}
		}
		var special_string = key_pressed.join("&&");
		if(eval(special_string) && (e['keyCode'] == symbol_array[curr_combo[curr_combo.length-1].toUpperCase()])){
			eval(base64_decode(key_combo[key]));
		}
	}
}

function getHexDigit(decimal) {
	var hexArray = Array("A", "B", "C", "D", "E", "F");
	var hexVal = parseInt(0 + decimal, 10);
	if ((hexVal) > 15) {
		hexVal = false;
	}
	else {
		hexVal = hexVal < 10 ? hexVal : hexArray[hexVal-10];
	}
	return hexVal;
}


function decToHex(decimal) {
	var temp = parseInt(decimal,10);
	if (isNaN(temp)) { 
		//alert("That's not a decimal number!");
		return false;
	}
	var hex = "";
	while (temp > 15) {
		remainder = temp % 16;
		hex = getHexDigit(remainder) + "" + hex
		temp = parseInt(temp / 16);
	}
	if (temp >= 0) {
		hex =  getHexDigit(temp) + "" + hex
	}
	else {
		return false;
	}
	return hex;
}

function reverse_string(str) {
	var new_str = "";
	for (var i=str.length-1; i>=0; i--) {
		new_str += str.charAt(i);
	}
	return new_str;
}
// created for use in IEP, designed for the onclick of a button to populate a select box from multiple elements
function populate_select_box(select_box, form_elements, display_separator, value_separator, cb_string_yes, cb_string_no){
	var i;
	var mark = "";
	var vmark = "";
	var display_bit = "";
	var value_bit = "";
	var display_str = "";
	var value_str = "";
	for(i=0;i<form_elements.length;i++){
		if(typeof(form_elements[i].checked)!="undefined"){
			if(form_elements[i].checked){
				display_bit = cb_string_yes;
				value_bit = 1;
			}
			else{
				display_bit = cb_string_no;
				value_bit = 0;
			}
			form_elements[i].checked=false;
		}
		else if(typeof(form_elements[i].selectedIndex)!="undefined"){
			display_bit = form_elements[i].options[form_elements[i].selectedIndex].text;
			value_bit = form_elements[i].options[form_elements[i].selectedIndex].value;
			form_elements[i].selectedIndex=0;
		}
		else if(typeof(form_elements[i].value)!="undefined"){
			display_bit = form_elements[i].value;
			value_bit = form_elements[i].value;
			form_elements[i].value='';
		}
		else{
			alert("form element "+i+" not handled, component_actions line ~1206");
			display_bit = '';
			value_bit = '';
		}
		if(display_bit!=""){
			display_str += mark+display_bit;
			mark = display_separator;
		}
		value_str += vmark+value_bit;
		vmark = value_separator;
	}
	select_box.options[select_box.options.length] = new Option(display_str, value_str);
}
function depopulate_select_box(select_box, form_elements, display_separator, value_separator){
	if(select_box.selectedIndex > -1){
		var value_arr = select_box.options[select_box.selectedIndex].value.split(value_separator);
		for(i=0;i<form_elements.length;i++){
			if(typeof(form_elements[i].checked)!="undefined"){
				if(value_arr[i] > 0)
					form_elements[i].checked=true;
				else
					form_elements[i].checked=false;
			}
			else if(typeof(form_elements[i].value)!="undefined"){
				form_elements[i].value=value_arr[i];
			}
			else
				alert("form element "+i+" not handled, component_actions line ~1206");
		}
		select_box.options[select_box.selectedIndex]=null;
	}
}

function search_combo_filter(select_box, text_box, search_on, name) {
	var string = text_box.value;
	var reg_exp = new RegExp(string, "i");
	var filtered_ids = new Array();
	var text_array = eval(name+'_text_array');
	var data_array = eval(name+'_data_array');
	var j = 0;
	if(search_on == 'text') {
		for(i=0; i<text_array.length; i++) {
			if(text_array[i].match(reg_exp)) {
				filtered_ids[j] = i;
				j++;
			}	
		}
	}
	else {
		for(i=0; i<data_array.length; i++) {
			if(data_array[i].match(reg_exp)) {
				filtered_ids[j] = i;
				j++;
			}	
		}
	}
	remove_all(select_box, 0);
	for(i=0; i<filtered_ids.length; i++) {
		add_option(select_box, text_array[filtered_ids[i]], data_array[filtered_ids[i]]);
	}
}


// ****************************************************************************************
// These functions are used with the select_box_dependency component
function select_box_dependency_changer(dep_name, sb_changed, blank_line) {
	var core_name = select_box_dependency_get_core_name(sb_changed);
	var selected_value = "";
	var dependency_info = eval(dep_name+"_dp_info");
	if (sb_changed.options.selectedIndex > ((blank_line) ? 0 : -1)) {
		selected_value = sb_changed.options[sb_changed.options.selectedIndex].value;
		// Set the hidden variable to be the value to be passed.
		select_box_dependency_set_hidden(sb_changed, core_name, selected_value);
		if (typeof(dependency_info[core_name])!="undefined") {
			for (var i=0; i<dependency_info[core_name].length; i++) {
				// Reset all the select boxes that are dependent on the one being changed
				select_box_dependency_reset_children(dep_name, sb_changed.form, dependency_info[core_name][i], blank_line);
				// Populate all the children of the select box with the values related to the one currently chosen.
				select_box_dependency_popuplate_sb(sb_changed.form, selected_value, dependency_info[core_name][i], blank_line);
			}
		}
	}
	else {
		var hidden_var = select_box_dependency_get_hidden(sb_changed, core_name);
		hidden_var.value = "";
		// Reset all the select boxes that are dependent on the one being changed
		if (typeof(dependency_info[core_name])!="undefined") {
			for (var i=0; i<dependency_info[core_name].length; i++) {
				select_box_dependency_reset_children(dep_name, sb_changed.form, dependency_info[core_name][i], blank_line);
			}
		}
	}
}

function select_box_dependency_get_core_name(sb_changed) {
	var core_name_parts = sb_changed.name.split("_");
	core_name_parts.length = core_name_parts.length-1;
	var core_name = core_name_parts.join("_");
	return core_name;
}

function select_box_dependency_get_hidden(sb_changed, core_name) {
	var hidden_var = eval("sb_changed.form."+core_name);
	return hidden_var;
}

function select_box_dependency_set_hidden(sb_changed, core_name, tree_num) {
	var hidden_var = select_box_dependency_get_hidden(sb_changed, core_name);
	var data_array = eval(core_name+"_data");
	hidden_var.value = data_array[tree_num][1];
}

function select_box_dependency_popuplate_sb(the_form, source_tree_num, dest_core_name, blank_line) {
	var dest_data = eval(dest_core_name+"_data");
	var dest_sb = eval("the_form."+dest_core_name+"_sb");
	remove_all(dest_sb, blank_line);
	for(var tree_num in dest_data) {
		if (source_tree_num == tree_num.substr(0, source_tree_num.length)) {
			add_option(dest_sb, dest_data[tree_num][0], tree_num);
		}
	}
}

function select_box_dependency_reset_children(dep_name, the_form, core_name, blank_line) {
	if (typeof(core_name)=="undefined" || typeof(eval("the_form."+core_name+"_sb"))=="undefined") {
		//alert("returning");
		return;
	}
	var select_box = eval("the_form."+core_name+"_sb");
	var sb_hidden = eval("the_form."+core_name);
	sb_hidden.value = "";
	
	remove_all(select_box, blank_line);
	var dependency_info = eval(dep_name+"_dp_info");
	if (typeof(dependency_info[core_name])!="undefined") {
		for (var i=0; i<dependency_info[core_name].length; i++) {
			select_box_dependency_reset_children(dep_name, the_form, dependency_info[core_name][i], blank_line);
		}
	}
}
// ****************************************************************************************