function ConfirmDelete(rowName) {
   	if(confirm("Really delete " + rowName + "?")) {
		return true;	  
	} else {
	    return false;
    }
}

function ConfirmDeleteWithCat(category, categories, itemContainedInCategory, itemsContainedInCategory, numItems) {
   	if (numItems == 1) {
		itemStr = itemContainedInCategory;
	} else {
		itemStr = itemsContainedInCategory;
	}
   	if (numItems > 0) {
		alert("Cannot delete " + category + ". It contains " + numItems + " " + itemStr + ".\n"
			  + "First move the " + itemStr + " from this " + category + " into a different " + category + ".\n"
			  + "Then you can delete this " + category + ".");
		return false;
	}
	return ConfirmDelete();
}


function GetStyleObject(element_id) {
  // checkW3C DOM, then MSIE 4, then NN 4.
  if(document.getElementById && document.getElementById(element_id)) {
	return document.getElementById(element_id).style;
   }
   else if (document.all && document.all(element_id)) {  
	return document.all(element_id).style;
   } 
   else if (document.layers && document.layers[element_id]) { 
	return document.layers[element_id];
   } else {
	return false;
   }
}

// ShowHideDiv. toggles the display value between '' and 'none' for the div with the id given.
// NOTE: We intentionally do not use "block" as a value for style.display, because Firefox doesn't support it
// when the element type is TR. 
function ShowHideDiv(div_id) {
    var style = GetStyleObject(div_id);
    if (style) {
       curDisplayValue = style.display;
       if (curDisplayValue == '') {
		   nextDisplayValue = 'none';
	   } else {
		   nextDisplayValue = '';
       }
	   ChangeElementDisplay(div_id, nextDisplayValue);
	}
}

// ShowHideDivs. toggles the display value between 'block' and 'none' for 
// ALL HTML tags of type tagName, belonging to object with ID given by mainObjectID
// whose ID begins with prefix given.
function ShowHideDivs(mainObjectID, tagName, divIDPrefix) {
	mainObject = document.getElementById(mainObjectID);
	if (mainObject) {
		regexp = '/^' + divIDPrefix + '.*/';
		elements = mainObject.getElementsByTagName(tagName);
		for(var i = 0; i < elements.length; i++)   {
			element = elements[i];
			id = element.id;
			if (id != '' && (id.indexOf(divIDPrefix) == 0) ) {
				ShowHideDiv(id);
			}
		}
	}
}

// NOTE: We intentionally do not use "block" as a value for style.display, because Firefox doesn't support it
// when the element type is TR. 
function ShowDiv(div_id) {
   ChangeElementDisplay(div_id, '');
}
function HideDiv(div_id) {
   ChangeElementDisplay(div_id, 'none');
}

function ChangeElementDisplay(element_id, value) {
    var style = GetStyleObject(element_id);
    if (style) {
       style.display = value;
	   return true;
    } else {
	// alert("Cannot find style for div with id = " + element_id);
	   return false;
    }
}
