function ServiceManager(EventManager, ServiceMap) {
	var ServiceFormParent = null;
	var ServiceChildren = new Array();
	
	var knownServices = new Array();

	this.addService = function(servXMLobj) {
		var title = servXMLobj.getAttribute('title');
		knownServices[title] = servXMLobj;
	}

	this.removeService = function(servTitle) {
		if(knownServices[servTitle]) {
			delete knownServices[servTitle];
		}
	}

	/* set the spawn parent function to do something other than this default 
	 * for specific interfaces
	 */
	this.spawnParent = function(title) {
		return ServiceFormParent;
	}

	/* set if a parent from a custom spawn function needs to be removed
	*/
	this.clearParent = function(title) {
		return false;
	}

	var MySelf = this;

	function renderServiceForm(serviceXMLObj) {
		var servTitle = serviceXMLObj.getAttribute('title');
		var serviceForm = new ServiceForm(EventManager, serviceXMLObj, ServiceMap);
		var formParent = MySelf.spawnParent(servTitle);
		if(formParent) {
			ServiceChildren[servTitle] = serviceForm;
			serviceForm.setParent(formParent);
		} else {
			alert('Service Form Parent not set! Unable to render service object!');
		}
	}

	this.serviceForm = function(serviceXMLObj) {
		var servTitle = serviceXMLObj.getAttribute('title');
		if(serviceXMLObj.getAttribute('type') && serviceXMLObj.getAttribute('type').match(/inspect/i)) {

			var specificType = serviceXMLObj.getAttribute('type').split('-');
			if(!specificType[1]) {
				specificType[1] = 'default';
			}
			if(ServiceFormParent) {
				ServiceFormParent.innerHTML = '<b>'+'Please Choose a Point on the Map'+'</b>';
			}
			EventManager.addEventListener('changetool','ServInspect', function () {
				EventManager.removeEventListener('changetool','ServInspect');
				EventManager.removeEventListener('finishdrawing', 'ServInspect');

			});
			EventManager.addEventListener('finishdrawing','ServInspect', function (p) {
					var serviceXML = document.createElement('service');
					serviceXML.setAttribute('title', serviceXMLObj.getAttribute('title'));
					var url = document.createElement('url');
					url.appendChild(document.createTextNode(serviceXMLObj.getElementsByTagName('url')[0].firstChild.nodeValue));
					serviceXML.appendChild(url);

					var inputs = serviceXMLObj.getElementsByTagName('input');
					var copyAttributes = ['name','title','value','delim'];
					for(var i = 0; i < inputs.length; i++) {
						var newInput = document.createElement('input');
						for(var attr = 0; attr < copyAttributes.length; attr++) {
							newInput.setAttribute(copyAttributes[attr], inputs[i].getAttribute(copyAttributes[attr]));
						}
						if(inputs[i].getAttribute('type').match(/point/)) {
							var delim = inputs[i].getAttribute('delim');
							if(!delim) { delim = ','; }
							var pValue = p[0].toString(delim);
							newInput.setAttribute('type','hidden');
							newInput.setAttribute('value', pValue);
						} else {
							newInput.setAttribute('type', inputs[i].getAttribute('type'));
						}
						serviceXML.appendChild(newInput);
					}
					//serviceXML.setAttribute('type', 'default');
					serviceXML.setAttribute('type', specificType[1]);
					EventManager.removeEventListener('changetool','ServInspect');
					EventManager.removeEventListener('finishdrawing', 'ServInspect');
//					EventManager.triggerEvent('serviceform',serviceXML);
					renderServiceForm(serviceXML);
			});
			ServiceMap.pointDrawTool();
			if(serviceXMLObj.getAttribute('cursor')) {
				ServiceMap.setMapCursor(serviceXMLObj.getAttribute('cursor'));
			}
			return false;
		}
		renderServiceForm(serviceXMLObj);

	}

	this.clearServiceForm = function(serviceXMLObj) {
		var servTitle = serviceXMLObj.getAttribute('title');
		if(ServiceChildren[servTitle]) {
			ServiceChildren[servTitle].clearForm();
		}
		MySelf.clearParent(serviceXMLObj);
	}

	this.setParent = function(p) {
		ServiceFormParent = p;
	}

	this.serviceCount = function() {
		var i = 0;
		for(var l in knownServices) {
			i++;
		}
		alert(i+' known services.');
	}
}
