function ServiceForm (EventManager, serviceXMLObj, serviceMap) {
	var ServiceFormId = 'ServiceForm-';
	var FormTableId = ServiceFormId+serviceXMLObj.getAttribute('title');

	this.clearForm = function () {
		var rootElement = document.getElementById(FormTableId);
		if(rootElement && rootElement.parentNode) {
			var p = rootElement.parentNode;
			p.removeChild(rootElement);
		}
	}
	
	function createInputArray(tableId) {
		var table = document.getElementById(tableId);
		var inputs = table.getElementsByTagName('input');
		var inputValues = new Array();
		for(var i = 0; i < inputs.length; i++) {
			inputValues[inputs[i].name] = inputs[i].value;
		}
		inputs = null;

		var selects = table.getElementsByTagName('select');
		for(var i = 0; i < selects.length; i++) {
			var options = selects[i].getElementsByTagName('option');
			inputValues[selects[i].name] = options[selects[i].selectedIndex].value;
			options = null; 
		}
		selects = null;
		table = null;

		return inputValues;
	}

	this.setParent = function(p) {
		var formTable = document.createElement('table');
		document.getElementById(p).appendChild(formTable);
		formTable.setAttribute('id', FormTableId);
		
		var formBody = document.createElement('tbody');
		formTable.appendChild(formBody);

		var inputs = serviceXMLObj.getElementsByTagName('input');
		var userInputs = 0;
		for(var i = 0; i < inputs.length; i++) {
			var newInputRow = document.createElement('tr');
			var inputTitleCell = document.createElement('th');
			if(inputs[i].getAttribute('title') && inputs[i].getAttribute('title') != 'null') {
				inputTitleCell.appendChild(document.createTextNode(inputs[i].getAttribute('title')));
			}
			formBody.appendChild(newInputRow);
			var newInputCell = document.createElement('td');
			newInputRow.appendChild(inputTitleCell);
			newInputRow.appendChild(newInputCell);
			if(inputs[i].getAttribute('type').match(/user/i)) {
				var inputObj = document.createElement('input');
				if(inputs[i].getAttribute('value') && inputs[i].getAttribute('value') != 'null') {
					inputObj.value = inputs[i].getAttribute('value');
				}

				inputObj.name = inputs[i].getAttribute('name');
				inputObj.setAttribute('subtype', 'user');

				newInputCell.appendChild(inputObj);
				userInputs++;
			} else if(inputs[i].getAttribute('type').match(/select/i)) {
				var selectObj = document.createElement('select');
				selectObj.name = inputs[i].getAttribute('name');
				selectObj.setAttribute('subtype', 'select');
				var options = inputs[i].getElementsByTagName('option');
				for(var o = 0; o < options.length; o++ ) {
					var option = document.createElement('option');
					option.value = options[o].getAttribute('value');
					option.appendChild(document.createTextNode(options[o].firstChild.nodeValue));
					selectObj.appendChild(option);
				}
				newInputCell.appendChild(selectObj);
				userInputs++;
			} else if(inputs[i].getAttribute('type').match(/hidden/i)) {
				var newInput = document.createElement('input');
				newInput.type = 'hidden';
				newInput.name = inputs[i].getAttribute('name');
				newInput.value = inputs[i].getAttribute('value');
				newInput.setAttribute('subtype','user');
				/*inputsTable.appendChild(newInput);*/
				formBody.appendChild(newInput);
			} else if(inputs[i].getAttribute('type').match(/layers/i)) {
				var layers = serviceMap.getLayerURLs();
				var name = inputs[i].getAttribute('name');
				var delim = inputs[i].getAttribute('delim');
				var value = '';
				for(var layer in layers) {
					value = value + serviceMap.preprocessURL('image',layer) + delim;
				}
				value = value.substring(0,value.length-1);
				var newInput = document.createElement('input');
				newInput.name = name;
				newInput.value = escape(value);
				newInput.type = 'hidden';
				formBody.appendChild(newInput);
			} else if(inputs[i].getAttribute('type').match(/legends/i)) {
				var layers = serviceMap.getLayerURLs();
				var name = inputs[i].getAttribute('name');
				var delim = inputs[i].getAttribute('delim');
				var value = '';
				for(var layer in layers) {
					value = value + serviceMap.preprocessURL('legend',layer) + delim;
				}
				value = value.substring(0,value.length-1);
				var newInput = document.createElement('input');
				newInput.name = name;
				newInput.value = escape(value);
				newInput.type = 'hidden';
				formBody.appendChild(newInput);
			} else if(inputs[i].getAttribute('type').match(/opacity/i)) {
				var layers = serviceMap.getLayerURLs();
				var name = inputs[i].getAttribute('name');
				var delim = inputs[i].getAttribute('delim');
				var value = '';
				for(var layer in layers) {
					value = value + serviceMap.getOpacity(layer) + delim;
				}
				value = value.substring(0,value.length-1);
				var newInput = document.createElement('input');
				newInput.name = name;
				newInput.value = escape(value);
				newInput.type = 'hidden';
				formBody.appendChild(newInput);
			} else if(inputs[i].getAttribute('type').match(/extent/i)) {
				var newInput = document.createElement('input');
				var delim = inputs[i].getAttribute('delim');
				newInput.type = 'hidden';
				newInput.name = inputs[i].getAttribute('name');
				newInput.value = serviceMap.getExtent(delim);
				formBody.appendChild(newInput);
			} else if(inputs[i].getAttribute('type').match(/layertitles/i)) {
				var newInput = document.createElement('input');
				var delim = inputs[i].getAttribute('delim');
				
				newInput.type = 'hidden';
				newInput.name = inputs[i].getAttribute('name');
				var layers = serviceMap.getLayerTitles();
				var str = '';
				for(var l = 0; l < layers.length; l++) {
					if(delim == " ") {
						layers[l] = layers[l].replace(' ','');
					}
					str += delim+layers[l];
				}
				str = str.substring(1);
				newInput.value = str;
				formBody.appendChild(newInput);
			} else if(inputs[i].getAttribute('type').match(/centerpoint/i)) {
				var newInput = document.createElement('input');
				newInput.type = 'hidden';
				newInput.name = inputs[i].getAttribute('name');
				newInput.value = serviceMap.getPointScale().Center.toString(inputs[i].getAttribute('delim'));
				formBody.appendChild(newInput);
			} else if(inputs[i].getAttribute('type').match(/scale/i)) {
				var newInput = document.createElement('input');
				newInput.type = 'hidden';
				newInput.name = inputs[i].getAttribute('name');
				newInput.value = serviceMap.getPointScale().Radius;
				formBody.appendChild(newInput);
			} else if(inputs[i].getAttribute('type').match(/width/i)) {
				var newInput = document.createElement('input');
				newInput.type = 'hidden';
				newInput.name = inputs[i].getAttribute('name');
				newInput.value = serviceMap.getMapSize().x;
				formBody.appendChild(newInput);
			} else if(inputs[i].getAttribute('type').match(/height/i)) {
				var newInput = document.createElement('input');
				newInput.type = 'hidden';
				newInput.name = inputs[i].getAttribute('name');
				newInput.value = serviceMap.getMapSize().y;
				formBody.appendChild(newInput);
			} else if(inputs[i].getAttribute('type').match(/imagesize/i)) {
				var newInput = document.createElement('input');
				newInput.type = 'hidden';
				newInput.name = inputs[i].getAttribute('name');
				var delim = inputs[i].getAttribute('delim');
				if(!delim) { delim = ','; }
				newInput.value = serviceMap.getMapSize().toString(delim);
				formBody.appendChild(newInput);
			} else if(inputs[i].getAttribute('type').match(/title/i)) {
				var newInput = document.createElement('input');
				newInput.name = inputs[i].getAttribute('name');
				var v = inputs[i].getAttribute('value');
				if(v && v != 'null') {
					newInput.value = v;
				}
				newInputCell.appendChild(newInput);
				newInput.onchange = function (event) {
					if(window.event) { event = window.event; }
					var layers = serviceMap.getLayerTitles();
					for(var l = 0; l < layers.length; l++) {
						if(this.value == layers[l]) {
							alert('Already a layer named '+this.value);
							this.value = '';
							return preventDefaultEvent(event);
						}
					}
					return true;
				}
				userInput++;
				newInput = null;

			} else if(inputs[i].getAttribute('type').match(/area/i)) {
				var selectObj = document.createElement('select');
				selectObj.name = inputs[i].getAttribute('name');
				selectObj.setAttribute('subtype', 'select');
				var areas = serviceMap.getDrawingAreas();
				for(var area in areas) {
					var option = document.createElement('option');
					option.value = areas[area];
					option.appendChild(document.createTextNode(area));
					selectObj.appendChild(option);
				}
				newInputCell.appendChild(selectObj);
				userInputs++;
			} else if(inputs[i].getAttribute('type').match(/visiblelayer/i)) {
				var layers = serviceMap.getLayerTitles();
				var selectObj = document.createElement('select');
				selectObj.name = inputs[i].getAttribute('name');
				newInputCell.appendChild(selectObj);

				var nullOpt = document.createElement('option');
				selectObj.appendChild(nullOpt);
				nullOpt = null;

				for(var layer = 0; layer < layers.length; layer++) {
					var option = document.createElement('option');
					option.value = layers[layer];
					selectObj.appendChild(option);
					option.appendChild(document.createTextNode(layers[layer]));
					option = null;
				}

				selectObj = null;
				userInputs++;
			} else if(inputs[i].getAttribute('type').match(/length/i)) {
				var newInput = document.createElement('input');
				newInput.type = 'hidden';
				newInput.name = inputs[i].getAttribute('name');
				newInput.setAttribute('id','ServiceForm-'+newInput.name);
				
				var userInput = document.createElement('input');
				userInput.setAttribute('id', newInput.getAttribute('id')+'-Source');
				userInput.targetObj = newInput.getAttribute('id');
				userInput.onchange = function () {
					var obj = document.getElementById(this.targetObj);
					obj.value = this.value;	
				}
				var v = inputs[i].getAttribute('value');
				if(!v || v == 'null') {
					userInput.setAttribute('value', '0');
				} else {
					userInput.setAttribute('value', v);
				}
				newInput.setAttribute('value', userInput.getAttribute('value'));
			
				newInputCell.appendChild(newInput);
				newInputCell.appendChild(userInput);
				newInputCell.appendChild(document.createElement('br'));

				var groundUnits = document.createElement('select');
				newInputCell.appendChild(groundUnits);
				populateUnitConversionSelection('length', groundUnits);
				
				groundUnits.targetId = newInput.getAttribute('id');
				groundUnits.sourceId = userInput.getAttribute('id'); 
				groundUnits.onchange = function () {
					var src = document.getElementById(this.sourceId);
					var target = document.getElementById(this.targetId);
					var opts = this.getElementsByTagName('option');
					var v = src.value;
					if(this.selectedIndex >= 0) { 
						var selOpt = opts[this.selectedIndex];
						var unitCheck = new String(selOpt.value);
						v = Math.round(v*UNIT_CONVERSION[selOpt.value][MAP_GROUND_UNITS]);
						target.value = v;
					}
				}
				groundUnits = null;
				newInput = null;
				userInput = null;
				userInputs++;
			}
			newInputCell = null;
			newInputRow = null;
		}

		var cancelSubmitRow = document.createElement('tr');

		var cancelButton = document.createElement('button');
		cancelButton.appendChild(document.createTextNode('Cancel'));
		var searchButton = document.createElement('button');
		searchButton.appendChild(document.createTextNode('OK'));

		var cancelCell = document.createElement('td');
		var searchCell = document.createElement('td');
		searchCell.style.textAlign = 'right';
		cancelCell.appendChild(cancelButton);
		searchCell.appendChild(searchButton);
		cancelSubmitRow.appendChild(cancelCell);
		cancelSubmitRow.appendChild(searchCell);
		formBody.appendChild(cancelSubmitRow);

		cancelButton.onclick = function() {
			EventManager.triggerEvent('cancelservice', serviceXMLObj);
		}


		searchButton.onclick = function () {
			var values = createInputArray(FormTableId);
			var inputs = serviceXMLObj.getElementsByTagName('input');
			for(var i = 0; i < inputs.length; i++) {
				inputs[i].setAttribute('value', values[inputs[i].getAttribute('name')]); 
			}
			EventManager.triggerEvent('callservice', serviceXMLObj);
		}

		if(userInputs <= 0) {
			searchButton.onclick();
		}
		searchButton = null;
		cancelButton = null;
		cancelCell = null;
		searchCell = null;
		cancelSubmitRow = null;
		formBody = null;
		formTable = null;

	}
}
