function table_edit(edit_form,maint_form) {
	var edit_hash = $H({ });
	var edit_inputs = $A(Form.getElements(edit_form));

	edit_inputs.each( function(edit_input) {
		var edit_name = edit_input.id.replace(/_edit$/,'');
		edit_hash[edit_name] = edit_input.value;  
	});
	
	var maint_inputs = $A(Form.getElements(maint_form));
	
	var on_off = false;
	maint_inputs.each( function(maint_input) {
		if (maint_input.id.match(/^modify_\d+/)) {
			if (maint_input.checked == true) {
				on_off = true;
			}
			else {
				on_off = false
			}
		}
		else {
			if (on_off && !(maint_input.id.match(/^id_\d+$/)) && !(maint_input.name.match(/^Save Changes$/)) && !(maint_input.name.match(/^Cancel$/))) {
				var maint_name = maint_input.id.replace(/_\d+$/,'');
				if (edit_hash[maint_name] != "No_Edit") {
					//alert(maint_input.id+"--"+maint_name+"--"+edit_hash[maint_name]);
					maint_input.value = edit_hash[maint_name];
					if ($(maint_input).onChange) {
						$(maint_input).onChange();
					}
				}
			}
		}		
	});
	
	return false;
}


function serialize_table(table_form,filter_form,all_false) {
	var form_string = '';
	var form_test = true;
	var inputs = $A(Form.getElements(table_form));
	inputs.each( function(theInput) {
		//alert(theInput.name);
		if (theInput.id.match(/^modify_\d+$/)) {
			if ((theInput.checked == true) && !(all_false)) {
				form_test = true;
			}
			else {
				form_test = false;
			}
		}
		if (form_test) {
			form_string += '&' + Form.Element.serialize(theInput);
		}
		else if ((theInput.id.match(/^delete_\d+$/)) && (theInput.checked == true)) {
			form_string += '&' + Form.Element.serialize(theInput);
		}
	});
	return form_string + '&' + $(filter_form).serialize();
}

function sort_table(key_name) {
	var sort_count = parseInt($('sort_count').value);
	var sort_order = $('sort_order_'+key_name);
	var sort_direction = $('sort_direction_'+key_name);
	
	if (sort_direction.value == 0) {
		sort_direction.value = 1;
		$('sort_count').value = sort_count + 1;
		sort_order.value = $('sort_count').value;
	}
	else if (sort_direction.value == 1) {
		sort_direction.value = 2;
		$('sort_count').value = sort_count + 1;
		sort_order.value = $('sort_count').value;
	}
	else {
		sort_order.value = 0;
		sort_direction.value = 0;
	}
}


function toggle_modify(form) {
	var confirmation = confirm("Toggle Modify for all visible lines?");
	if (confirmation) {
		var modifys = $A(Form.getInputs(form,'checkbox'));
		modifys.each( function(theInput) {
			if (theInput.id.match(/^modify_\d+$/)) {
				if (theInput.checked == true) {
					theInput.checked = false;
				}
				else {
					theInput.checked = true;
				}
				rowHighlight(theInput.up(1),'row_blue',theInput.checked);
			}
		});
	}
}

function toggle_delete(form) {
	var confirmation = confirm("Toggle Delete for all visible lines?");
	if (confirmation) {
		var modifys = $A(Form.getInputs(form,'checkbox'));
		modifys.each( function(theInput) {
			if (theInput.id.match(/^delete_\d+$/)) {
				if (theInput.checked == true) {
					theInput.checked = false;
				}
				else {
					theInput.checked = true;
				}
				rowHighlight(theInput.up(1),'row_yellow',theInput.checked);
			}
		});
	}
}

function rowHighlight(rowId, row_class, value) {
	var myTDs = $(rowId).childNodes;
	myTDs = $A(myTDs);
	var myChecked = $(value).checked;
	myTDs.each(function(theTD) {
		if (theTD.innerHTML) {
			if (value) {
				Element.addClassName(theTD,row_class);
			}
			else {
				Element.removeClassName(theTD,row_class)
			}
		}
	});
}

