function addMenu(menu_position, menu_name, table, name_field, menu_add) {

var next_position = menu_position+1;
var prev_position = menu_position-1;
var place_position = next_position;

// alert ("position is " + menu_position);
// alert ("next position is " + next_position);

var allsWell = true;
var lastValue = $F(menu_name + "_last");
var menu_count = (+lastValue) + 1;
var url = '/add_menu.php?menu_name=' + menu_name + '&position=' + next_position + '&name_field=' + name_field + '&table=' + table + '&menu_count=' + menu_count + '&add=' + menu_add;

// alert ("loading ability from url: " + url);

// if we're clearing a row, we need to activate the "add" icon and remove the subtract icon on the previous row
if (menu_add == '') {

// alert ("deleting item: " + menu_position);

// alert("We're deleting DIV " + menu_position);
if (lastValue == menu_position) {
// alert("This is the last active menu.");
var prevAdd = document.getElementById(menu_name + '_add_' + prev_position);
var prevSub = document.getElementById(menu_name + '_subtract_' + prev_position);
if (prevAdd) { prevAdd.style.display = "inline"; }
if (prevSub) { prevSub.style.display = "none"; }
} // end if deleting the last item

place_position = menu_position;
} else {

// alert ("adding new item: " + next_position);

// we don't add a row if the current row is still empty!
var currValue = $F(menu_name + "_" + menu_position);
// alert('Current value of ' + menu_name + '_' + menu_position + ' is ' + currValue);

// alert ("Current position value: " + currValue);

if (currValue != '') {

// alert ("Current position value is greater than 0");

// if we're adding a row, we need to remove the "add" icon on the current row and activate the subtract icon
var currAdd = document.getElementById(menu_name + '_add_' + menu_position);
var currSub = document.getElementById(menu_name + '_subtract_' + menu_position);
currAdd.style.display = "none";
currSub.style.display = "inline";

// we are setting the "last value" for this field so that
// we can determine whether or not a field is the "last"
// one, so we do not end up with more than one "add" icon
// when field rows are removed
var lastValueObject = document.getElementById(menu_name + '_last');
lastValueObject.value = next_position;

} else {

// alert ("It did not work.");
allsWell = false;
}
} // end if adding a new row

// alert ("Place_position is: " + place_position);
// alert ("All's well?: " + allsWell);

var targetDIV = menu_name + '_DIV_' + place_position;

if (allsWell) { var aj = new Ajax.Updater(targetDIV, url, {method: 'get', evalScripts: true} ); }

} // end add menu function

