function ServiceForm (EventManager, serviceXMLObj, serviceMap) {

	var rootElement = null;

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

		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;
		}
		return inputValues;
	}

	this.setParent = function(p) {
		var formTable = document.createElement('table');
		var formBody = document.createElement('tbody');
		formTable.appendChild(formBody);
//		formTable.width = '100%';

		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')) {
				inputTitleCell.appendChild(document.createTextNode(inputs[i].getAttribute('title')));
			}
			var newInputCell = document.createElement('td');
			newInputRow.appendChild(inputTitleCell);
			newInputRow.appendChild(newInputCell);
			formBody.appendChild(newInputRow);
			if(inputs[i].getAttribute('type').match(/user/i)) {
				var inputObj = document.createElement('input');
				if(inputs[i].getAttribute('value')) {
					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);*/
				formTable.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';
				formTable.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';
				formTable.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';
				formTable.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);
				formTable.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;
				formTable.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'));
				formTable.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;
				formTable.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;
				formTable.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;
				formTable.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);
				formTable.appendChild(newInput);
			} 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++;
			}
		}

		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(formTable);
			var url = serviceXMLObj.getElementsByTagName('url')[0].firstChild.nodeValue;
			url += '?';

			for(var v in values) {
				url+=v+'='+escape(values[v])+'&';
			}
			/*alert(url);*/
			
		}

		searchButton.onclick = function () {
			var values = createInputArray(formTable);
			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);
		}

		rootElement = formTable;
		p.appendChild(formTable);

		if(userInputs <= 0) {
			searchButton.onclick();
		}

	}
}
