		function getIndexFromID(eType_id)
		{
			return oElementTypesIndexFromID[eType_id];
		}
		
		function getElementID2Name(eType_id)
		{
			return oElementTypesID2Name[eType_id];
		}
		
		function getElementName2ID(name)
		{
			return oElementTypesName2ID[name];
		}
		
		function getElementIDFromIndex(i)
		{
			return oElementTypesFromIndex[i];
		}
		
		function getElementFromElementTypeID(eType_id)
		{
			return oElementTypes[getIndexFromID(eType_id)];
		}
		
		function toggleHiddenElementFields(section_element_id, fields)
		{
			var newDisp = "";
			function handleLoop(f)
			{
				newDisp = get(section_element_id + "_" + f + "_field").style.display=="" ? "none" : "";
				get(section_element_id + "_" + f + "_field").style.display = newDisp;
				get(section_element_id + "_" + f + "_value").style.display = newDisp;				
			}
			colonLoop(fields, handleLoop);	

			var id = "toggleLink_" + section_element_id;
			var linkText = "";
			
			
			if (newDisp=="")
			{
				get(id).innerHTML = "Hide Less Important Fields";
			}
			else
			{
				get(id).innerHTML = "Show All Fields";
			}			
			jQuery("textarea[class*=expand]").TextAreaExpander();	
			return;
		}	
		
		function saveAddNewElementXML (type, guid, parent)
		{
			var fields = "";
			var is_attach = get("is_attach_" + guid + "_new").value=="1" ? true : false;
			if (!is_attach)
			{
				fields = get("fields_to_save_" + guid + "_new").value;
			}
			var url = "";
			var validated = true;
			
			// validate fields for a non-attach element
			if (!is_attach)
			{
				colonLoop(fields, function (f) 
				{
					if (!validated)
					{
						return;
					}
					
					// get whether this field is required or not
					var fieldRequired = false
					if (get("is_required_" + f + "_" + guid + "_new")!=null)
					{
						fieldRequired = get("is_required_" + f + "_" + guid + "_new").value=="1" ? true : false;
					}
					if (fieldRequired)
					{
						var o = get(f + "_" + guid + "_new");
						if (o.type=="select-one")
						{
							//select box
							if (o.value==-1)
							{
								alert("You must supply a value for all required fields.");
								validated = false;
								return;
							}
						}
						else
						{
							// standard contentEditable div
							if (trim(o.value)=="")
							{
								alert("You must supply a value for all required fields.");
								validated = false;
								return;
							}
						}
					}
					
				});			
				if (!validated)
				{
					return;
				}
			}
			else
			{
				// here we validate an attach which only requires a name
				if (trim(removeHTMLTags(get("name_" + guid + "_new").value))=="")
				{
					alert("You must supply a name for the file you are uploading.");
					return;
				}				
			}
			
			// build url since we're validated now for this non-attach element
			if (!is_attach)
			{
				colonLoop(fields, function (f) 
				{
					var v = "";
					
					if (get(f + "_" + guid + "_new").type=="select-one")
					{
						v = get(f + "_" + guid + "_new").value;
					}
					else
					{
						v = prepareUrl(get(f + "_" + guid + "_new").value);
					}
					url += "&" + f + "=" + v;
				});
			}
			else
			{
				// we're an attach
				var nodePos = getNodePos(get("insertDivDummy_" + guid));
				var indent = get("uniqueSectionId_" + parent).getAttribute("depth_charge");
				get("name_form_" + guid + "_new").value = get("name_" + guid + "_new").value;
				get("notes_form_" + guid + "_new").value = get("notes_" + guid + "_new").value;
				get("nodePos_form_" + guid + "_new").value = nodePos;
				get("indent_form_" + guid + "_new").value = indent;
				get("name_" + guid + "_new").blur();
				get("notes_" + guid + "_new").blur();
				cloud(true);
				eval("document.form_" + guid + "_new.submit();");
				return;
			}

			var nodePos = getNodePos(get("insertDivDummy_" + guid));
			var indent = get("uniqueSectionId_" + parent).getAttribute("depth_charge");			
			url = "actuallyAddXML=1&type=" + type + "&guid=" + guid + "&parent=" + parent + "&indent=" + indent + "&nodePos=" + nodePos + "&colonFields=" + escape(get("fields_to_save_" + guid + "_new").value) + url;		


			function _saveAddNewElementXML(r)
			{		
				session(r);	
				//alert(r);
				type = Number(type);
				if (type==9)
				{
					if (r=="notpublic"  || r=="notvalid")
					{
						cloud(false);
						alert("That public element could not be found.");
						return;
					}
				}
				
				// first part is # of chars of js to execute
				var pos = null;
				var count = 0;
				var elements_id = 0;
				var section_element_id = 0;
				var content = "";
				if (type==8)	// notes are a special case
				{
					// for a notes inserted we have to tet the elements_id and section_elements_id
					// elements_id first, then section_elements_id
					pos = r.indexOf("--");
					elements_id = Number(r.substr(0, pos));		
					
					r = r.substring(pos+2);
					pos = r.indexOf("--");
					section_element_id = Number(r.substr(0, pos));	
					r = r.substring(pos+2);
				}
				else
				{			
					// first thing returned is our section_element_id
					pos = r.indexOf("--");
					section_element_id = r.substr(0, pos);
					r = r.substring(pos+2);
				}
				
				pos = r.indexOf("--");
				count = Number(r.substr(0, pos));
				var js = r.substr(pos+2, count); 
				// do NOT eval this until we add our new element to the DOM				
				// we have our js now truncate r to just be the html			
				r = r.substring(pos+2+count);
				// make a siblign div and set the id to the container of the new element
				cancelAddNewElement(guid);						
				var newEntry = document.createElement("div");
				newEntry.id = "section_element_container_" + section_element_id;
				newEntry.innerHTML = r;
				// we need the section_element_id of THIS current element we're inserting below
				pos = guid.indexOf("_");
				var seid = guid.substring(pos+1);
				var f = null; 			
				if (guid.indexOf("sectionguid")>-1)
				{
					f = get("insertDivDetails_" + guid);
					insertAfter(f, newEntry);
				}
				else
				{
					f = get("section_element_container_" + seid);
					insertAfter(f, newEntry);	
				}
				eval(js);				
				// if we are notes then we ought to show text editor
				if (type==8)
				{
					//alert("about to show editor:" + elements_id + " " + section_element_id);
					showTextEditor(section_element_id, elements_id, true);
					return;
				}
				navigateTo("section_element", section_element_id);
				return;
			
			}		
			cloud(true);
			Aajax(weburl+"outline/ajax.php", url, _saveAddNewElementXML);
		}
		

