<commit_before>// WFS-Operations
var WFS_GET_CAPABILITIES = "?SERVICE=WFS&REQUEST=GetCapabilities";
var WFS_DESCRIBE_FEATURE_TYPE_WFS = "?SERVICE=WFS&REQUEST=DescribeFeatureType&VERSION=1.0.0&TYPENAME=";
var WFS_GET_FEATURE = "?SERVICE=WFS&REQUEST=GetFeature&VERSION=1.0.0&OUTPUTFORMAT=GML2&TYPENAME=";

// WFS URLs for init
var wfsURLs = new Array();

// WPS-Operations
var WPS_GET_CAPABILITIES = "?SERVICE=WPS&REQUEST=GetCapabilities";
var WPS_DESCRIBE_PROCESS = "?SERVICE=WPS&REQUEST=DescribeProcess&VERSION=1.0.0&IDENTIFIER=";
var WPS_EXECUTE = "?SERVICE=WPS&REQUEST=Execute&VERSION=1.0.0&IDENTIFIER=";

// WPS URLs for init
var wpsURLs = new Array();

// make map available for easy debugging
var map;

// proxy for external data sources
OpenLayers.ProxyHost = "cgi-bin/proxy.py?url="; // saved:
												// /usr/lib/cgi-bin/proxy.py


// Array of layer array (layer, attr1, attr2, ...)
var layers = new Array();


// HTML-Elemente
var selectProcesses;
var selectWPS;
var divInputValues;
var selectLayers = new Array();
var inputLiterals = new Array();
var inputOutputLayers = new Array();
var resultDisplay = document.createTextNode("");


// increase reload attempts
OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3;

// new OpenLayers.Geometry.Point(0, 52).transform(new
// OpenLayers.Projection("EPSG:900913"),new
// OpenLayers.Projection("EPSG:4326"))

function init() {

	// ------------------------------------------------------------------------------------------------------
	// map options
	var options = {
		projection : new OpenLayers.Projection("EPSG:4326")
		// projection : new OpenLayers.Projection("EPSG:900913"),
		// displayProjection : new OpenLayers.Projection("EPSG:4326"),
		// units : "m"
	// numZoomLevels : 18,
	// maxResolution : 156543.0339,
	// maxExtent : new OpenLayers.Bounds(-20037508, -20037508, 20037508,
	// 20037508.34)
	};

	// ------------------------------------------------------------------------------------------------------
	// create map
	map = new OpenLayers.Map('map', options);

	// ------------------------------------------------------------------------------------------------------
	// add wms as basic layer
	var wms = new OpenLayers.Layer.WMS("OpenLayers BASIC",
			"http://labs.metacarta.com/wms/vmap0", {
				layers : 'basic',
				crs : "EPSG:4326"
			});
	map.addLayer(wms);

	// ------------------------------------------------------------------------------------------------------
	// add wms as layer
// var wms2 = new OpenLayers.Layer.WMS("OpenLayers STATE LABEL",
// "http://labs.metacarta.com/wms/vmap0", {
// layers : 'statelabel',
// format : "image/png",
// transparent : "true",
// crs : "EPSG:4326"
// }, {
// isBaseLayer : false,
// visibility : false
// });
// map.addLayer(wms2);

	// ------------------------------------------------------------------------------------------------------
	// add a marker
	// var vectorLayer = new OpenLayers.Layer.Vector("TEST Maker");
	// var feature = new OpenLayers.Feature.Vector(
	// new OpenLayers.Geometry.Point(-0.0014, -0.0024),
	// {
	// some : 'data'
	// },
	// {
	// externalGraphic :
	// 'http://funmap.co.uk/cloudmade-examples/markers/marker.png',
	// graphicHeight : 37,
	// graphicWidth : 24
	// });
	// vectorLayer.addFeatures(feature);
	// map.addLayer(vectorLayer);

	// ------------------------------------------------------------------------------------------------------
	// add gml files as layer (only gml2 without schema)
	// addGMLLayer("GML2 Polygon", "gml/GML2_FeatureCollection_Polygon.xml",
	// "");
	// addGMLLayer("GML2 Buffered Polygon",
	// "gml/GML2_FeatureCollection_Polygon_Buffered.xml", "");

	// ------------------------------------------------------------------------------------------------------
	// add web feature service (only gml2)
	addWFSURL( "http://giv-wps.uni-muenster.de:8080/geoserver/wfs");
	addWFSURL(  "http://www.dge.upd.edu.ph/geoserver/wfs");
	
	addWFSLayer("WFS topp:states", "http://giv-wps.uni-muenster.de:8080/geoserver/wfs","topp:states", true);
	addWFSLayer("WFS ns1:tasmania_roads", "http://giv-wps.uni-muenster.de:8080/geoserver/wfs","ns1:tasmania_roads", false);
	addWFSLayer("WFS tiger:poi", "http://giv-wps.uni-muenster.de:8080/geoserver/wfs","tiger:poi", false);
	addWFSLayer("WFS tiger:tiger_roads", "http://giv-wps.uni-muenster.de:8080/geoserver/wfs","tiger:tiger_roads", false);
	addWFSLayer("WFS tiger:poly_landmarks", "http://giv-wps.uni-muenster.de:8080/geoserver/wfs","tiger:poly_landmarks", false);
	


	
	//
	// ------------------------------------------------------------------------------------------------------
	// add WPS
	addWPSURL( "http://flexigeoweb.lat-lon.de/deegree-wps-demo/services");
	addWPSURL( "http://giv-wps.uni-muenster.de:8080/wps/WebProcessingService");
	
// // centroid algorithm
// var data = new WPSInputData();
// var wfsFeatureURL =
// "http://giv-wps.uni-muenster.de:8080/geoserver/wfs?SERVICE=WFS&REQUEST=GetFeature&VERSION=1.0.0&OUTPUTFORMAT=GML2&TYPENAME=topp:states";
// data.addVectorLayer("LAYER", wfsFeatureURL,
// WPSInputData.VECTOR_LAYER_SCHEMA_GML2);
// data.addOutputVectorLayerFormat("RESULT",
// WPSInputData.VECTOR_LAYER_SCHEMA_GML2);
// addWPSLayer("WPS centroids",
// "http://flexigeoweb.lat-lon.de/deegree-wps-demo/services", "st_centroids",
// data);
//	
// // transform algorithm
// var data2 = new WPSInputData();
// var wfsFeatureURL2 =
// "http://giv-wps.uni-muenster.de:8080/geoserver/wfs?SERVICE=WFS&REQUEST=GetFeature&VERSION=1.0.0&OUTPUTFORMAT=GML2&TYPENAME=topp:states";
// data2.addVectorLayer("LAYER", wfsFeatureURL2,
// WPSInputData.VECTOR_LAYER_SCHEMA_GML2);
// data2.addLiteral("DISTANCEX", WPSInputData.LITERAL_NUMERICAL_VALUE_TYPE,
// "-20");
// data2.addLiteral("DISTANCEY", WPSInputData.LITERAL_NUMERICAL_VALUE_TYPE,
// "40");
// data2.addLiteral("ANGLE", WPSInputData.LITERAL_NUMERICAL_VALUE_TYPE, "90");
// data2.addLiteral("SCALEX", WPSInputData.LITERAL_NUMERICAL_VALUE_TYPE, "0.5");
// data2.addLiteral("SCALEY", WPSInputData.LITERAL_NUMERICAL_VALUE_TYPE, "0.5");
// data2.addLiteral("ANCHORX", WPSInputData.LITERAL_NUMERICAL_VALUE_TYPE,
// "-46");
// data2.addLiteral("ANCHORY", WPSInputData.LITERAL_NUMERICAL_VALUE_TYPE, "35");
// data2.addOutputVectorLayerFormat("RESULT",
// WPSInputData.VECTOR_LAYER_SCHEMA_GML2);
// addWPSLayer("WPS transform",
// "http://flexigeoweb.lat-lon.de/deegree-wps-demo/services", "st_transform",
// data2);
//	
// // fixeddistancebuffer algorithm
// var data3 = new WPSInputData();
// var wfsFeatureURL3 =
// "http://giv-wps.uni-muenster.de:8080/geoserver/wfs?SERVICE=WFS&REQUEST=GetFeature&VERSION=1.0.0&OUTPUTFORMAT=GML2&TYPENAME=ns1:tasmania_roads";
// data3.addVectorLayer("LAYER", wfsFeatureURL3,
// WPSInputData.VECTOR_LAYER_SCHEMA_GML2);
// data3.addLiteral("DISTANCE", WPSInputData.LITERAL_NUMERICAL_VALUE_TYPE,
// "0.05");
// data3.addLiteral("TYPES", WPSInputData.LITERAL_SELECTION_TYPE, "0");
// data3.addLiteral("RINGS", WPSInputData.LITERAL_SELECTION_TYPE, "0");
// data3.addLiteral("NOTROUNDED", WPSInputData.LITERAL_BOOLEAN_TYPE, "false");
// data3.addOutputVectorLayerFormat("RESULT",
// WPSInputData.VECTOR_LAYER_SCHEMA_GML2);
// addWPSLayer("WPS fixeddistancebuffer",
// "http://flexigeoweb.lat-lon.de/deegree-wps-demo/services",
// "st_fixeddistancebuffer", data3);
//
//	
// test =
// determineWPSProcessDescription("http://flexigeoweb.lat-lon.de/deegree-wps-demo/services","st_transform");
	
	// ------------------------------------------------------------------------------------------------------
	// add controls
	map.addControl(new WPSSwitcher());
	map.addControl(new OpenLayers.Control.LayerSwitcher());
	map.addControl(new OpenLayers.Control.MousePosition());

	// ------------------------------------------------------------------------------------------------------
	// set center
	map.setCenter(new OpenLayers.LonLat(-75, 0), 3);
}

function getStyleMap(){

	var color1="#FF8A14";
	
	var styleMap = new OpenLayers.StyleMap({ 
		strokeColor: color1, 
		fillColor : color1, 
		strokeWidth: 2, 
		pointRadius : 2,
		fillOpacity: 0.4
	});
		
	return styleMap;
}

/**
 * This method determines an individual name of layer.
 * 
 * @param name
 *            Raw layer name.
 * 
 * @return Modified layer name.
 */
function determineIndividualLayerName(name){
	var newName = name;
	
	// check whether name available
	if (layers[name] != null)
		newName = determineIndividualLayerName(name + "_1");

	return newName;
}

/**
 * This Method adds a GML file to the map.
 * 
 * @param gmlName
 *            Layer name.
 * @param gmlURL
 *            URL of GML file.
 * @param attr
 *            Optional attribute like absolute URL of GML file.
 */
function addGMLLayer(gmlName, gmlURL, attr) {
	
	gmlName = determineIndividualLayerName(gmlName);

	// create a GML layer
	var layer = new OpenLayers.Layer.GML(gmlName, gmlURL, { styleMap: getStyleMap() });

	// var layerProtocol = new OpenLayers.Protocol.HTTP( {
	// url : url,
	// format : new OpenLayers.Format.GML()
	// });
	//
	// var layer = new OpenLayers.Layer.Vector(name, {
	// strategies : [ new OpenLayers.Strategy.BBOX() ],
	// protocol : layerProtocol
	// });

	// notice layer
	var gmlArray = new Array();
	gmlArray[0] = layer;
	gmlArray[1] = attr;
	layers[gmlName] = gmlArray;
	
	// add layer to map
	map.addLayer(layer);
	
	
	if(gmlArray != null)
		resultDisplay.data = "Added layer '" + gmlName + "'";
	else
		resultDisplay.data = "Execute failed!";
}

/**
 * This method adds a WFS layer to map.
 * 
 * @param wfsURL
 *            URL of WFS.
 * @param wfsName
 *            Name of WFS.
 * @param wfsFeatureTypeWithPrefix
 *            FeatureTypeName with prefix.
 * @param visible
 *            visible=true.
 */
function addWFSLayer(wfsName, wfsURL, wfsFeatureTypeWithPrefix, visible) {
	
	wfsName = determineIndividualLayerName(wfsName);

	// determine namespace
	var ns = determineWFSFeatureTypeNamespace(wfsURL, wfsFeatureTypeWithPrefix);
	
	// check namespace
	if(ns == null)
		return;
	
	// check name
	var ftArray = wfsFeatureTypeWithPrefix.split(":");
	if(ftArray.length != 2){
		var name = new Array();
		name[0] = "";
		name[1] = wfsFeatureTypeWithPrefix;
		ftArray = name;
		// alert("FeatureType isn't in the correct format like 'prefix:name'.");
	}
	
	// create wfs layer
	var wfs = new OpenLayers.Layer.Vector(wfsName, {
		strategies : [ new OpenLayers.Strategy.BBOX() ],
		protocol : new OpenLayers.Protocol.WFS( {
			url : wfsURL,
			featureType : ftArray[1],
			featureNS : ns
		}), visibility : visible, styleMap: getStyleMap()
	});
	
	// add wfs layer to map
	var wfsArray = new Array();
	wfsArray[0] = wfs;
	wfsArray[1] = wfsURL + WFS_GET_FEATURE + wfsFeatureTypeWithPrefix;
	layers[wfsName] = wfsArray;
	map.addLayer(wfs);
}

/**
 * This method adds all layers of a WFS to the map.
 * 
 * @param wfsName
 *            Name of WFS.
 * @param wfsURL
 *            URL of WFS.
 */
function addWFSLayers(wfsName, wfsURL){
	
	// determine feature type names
	var types = determineWFSFeatureTypeNames(wfsURL);
	
	// add all layers
	for ( var i = 0; i < types.length; i++) {	
		addWFSLayer(wfsURL, wfsName +" " + types[i], types[i] , false);
	}
}

function addWFSURL(url){
	wfsURLs[url] = url;
}

function removeWFSURL(url){
	wfsURLs[url] = null;
}

/**
 * This method adds a layer by WPS.
 * 
 * @param wpsURL
 *            URL of WPS.
 * @param wpsProcess
 *            Identifier of process
 * @param data
 *            Process data, use class WPSInputData
 */
function addWPSLayer(wpsName, wpsURL, wpsProcess, data){
	var gmlName = wpsName;
	var attr = wpsURL + WPS_EXECUTE + wpsProcess + data.toString();
	var gmlURL = OpenLayers.ProxyHost + escape(attr);	
	addGMLLayer(gmlName, gmlURL, attr);
}

function addWPSURL(url){
	wpsURLs[url] = url;
}

function removeWPSURL(url){
	wpsURLs[url] = null;
}

/**
 * The method retuns an array of the FeatureTypeNames of the WFS.
 * 
 * @param wfsURL
 *            URL of WFS.
 * 
 * @return Array of FeatureTypeNames (prefix : name).
 */
function determineWFSFeatureTypeNames(wfsURL) {

	// url of xml file
	var url = OpenLayers.ProxyHost + wfsURL;
	url += escape(WFS_GET_CAPABILITIES);

	// parse xml file
	var request = getXMLHttpRequest('text/xml');
	request.open('GET', url, false);
	request.send();
	var xmlDoc = request.responseXML;
		
	// determine FeatureTypes
	var collectionOfFeatureTypes = xmlDoc.getElementsByTagName("FeatureType");
	var arrayOfFeatureTypes = new Array();
	if (collectionOfFeatureTypes.length > 0)
		for ( var int = 0; int < collectionOfFeatureTypes.length; int++) {
			arrayOfFeatureTypes[int] = collectionOfFeatureTypes[int].childNodes[0].firstChild.nodeValue;
		}
	else
		alert("Can't determine feature type names of the WFS.");

	// for debugging
	determineWFSFeatureTypeNames_XML = xmlDoc;
	determineWFSFeatureTypeNames_ARRAY = arrayOfFeatureTypes;
	
	return arrayOfFeatureTypes;
}


/**
 * This methode returns the namespace of a feature.
 * 
 * @param wfsURL
 *            URL of the WFS.
 * 
 * @param featureTypeName
 *            Name of a feature.
 * 
 * @return Namespace of feature.
 */
function determineWFSFeatureTypeNamespace(wfsURL, featureTypeName) {

	// url of xml file
	var url = OpenLayers.ProxyHost + wfsURL;
	url += escape(WFS_DESCRIBE_FEATURE_TYPE_WFS + featureTypeName);

	// parse xml file
	var request = getXMLHttpRequest('text/xml');
	request.open('GET', url, false);
	request.send();
	var xmlDoc = request.responseXML;

	// for debugging
	determineWFSFeatureTypeNS_XML = xmlDoc;
		
	// determine namespace and return
	var atts = xmlDoc.childNodes[0].attributes;
	for ( var int = 0; int < atts.length; int++) {
		if (atts[int].nodeName == "targetNamespace") {
			return atts[int].nodeValue;
		}
	}
	
	// namespace not found
	alert("Namspace of feature type '" + featureTypeName + "' wasn't found.");
	return null;
}


/**
 * This method returns all processes of a WPS.
 * 
 * @param wpsURL
 *            URL of WPS.
 * 
 * @return Array of Processes with names, titles and abstracts.
 */
function determineWPSProcesses(wpsURL) {

	// url of xml file
	var url = OpenLayers.ProxyHost + wpsURL;
	url += escape(WPS_GET_CAPABILITIES);

	// parse xml file
	var request = getXMLHttpRequest('text/xml');
	request.open('GET', url, false);
	request.send();
	var xmlDoc = request.responseXML;
	

	// determine Processes
	var collectionOfProcesses = xmlDoc.getElementsByTagName("wps:Process");
	var arrayOfProcesses = new Array();
	if (collectionOfProcesses.length > 0)
		for ( var int = 0; int < collectionOfProcesses.length; int++) {
			
			// process (identifier, title, abstract)
			var process = new Array();
			
			// determine process properties
			var processProperties = collectionOfProcesses[int].childNodes;

			for ( var i = 0; i < processProperties.length; i++) {
				
				var prob = processProperties[i];
				// alert(prob.localName + " " + prob.textContent);
				if(prob.localName == "Identifier")
					process[0] = prob.textContent;
				else if(prob.localName == "Title")
					process[1] = prob.textContent;
				else if(prob.localName == "Abstract")
					process[2] = prob.textContent;
			}
			
			// notice process
			arrayOfProcesses[int] = process;
		}
	else
		 alert("Can't determine Processes of the WPS.");
	
	return arrayOfProcesses;
}


/**
 * This method returns an array of all input and output parameter of the
 * process.
 * 
 * @param wpsURL
 *            URL of WPS.
 * @param identifier
 *            Identifier of process.
 * 
 * @return Array with all input and output parameters. [0]: input parameter, [1]
 *         output parameter with identifier, title, abstract and format.
 */
function determineWPSProcessDescription(wpsURL, identifier){
	
	// url of xml file
	var url = OpenLayers.ProxyHost + wpsURL;
	url += escape(WPS_DESCRIBE_PROCESS + identifier);

	// parse xml file
	var request = getXMLHttpRequest('text/xml');
	request.open('GET', url, false);
	request.send();
	var xmlDoc = request.responseXML;

	// determine input parameter
	var collectionOfInputs = xmlDoc.getElementsByTagName("Input");
	var arrayOfInputs = new Array();
	if (collectionOfInputs.length > 0)
		for ( var k = 0; k < collectionOfInputs.length; k++) {
			
			// input (identifier, title, abstract)
			var input = new Array();
			
			// determine input properties
			var inputProperties = collectionOfInputs[k].childNodes;
			var j = 0;
			for ( var i = 0; i < inputProperties.length; i++) {
				var prob = inputProperties[i];
				if(prob.localName != null){
					
					// input formats
					if(prob.tagName == "ComplexData"){

						// TODO support only this format
						input[3] = WPSInputData.VECTOR_LAYER_SCHEMA_GML2;

					}else{
						if(prob.tagName == "LiteralData"){
							input[3] = prob.textContent.replace(/^\s*|\s*$/g,''); // remove
																				// whitespace
						}else{
							// identifier, title, abstract
							input[j++] = prob.textContent;
						}
					}
				}
			}
			
		
			
			// notice process
			arrayOfInputs[k] = input;
		}
	else
		 alert("Can't determine input parameter of the WPS.");
	
	// determine output parameter
	var collectionOfOutputs = xmlDoc.getElementsByTagName("Output");
	var arrayOfOutputs = new Array();
	if (collectionOfOutputs.length > 0)
		for ( var k = 0; k < collectionOfOutputs.length; k++) {
			
			// output (identifier, title, abstract)
			var output = new Array();
			
			// determine output properties
			var outputProperties = collectionOfOutputs[k].childNodes;
			var j = 0;
			for ( var i = 0; i < outputProperties.length; i++) {
				var prob = outputProperties[i];
				if(prob.localName != null){
					
					// output formats
					if(prob.tagName == "ComplexOutput"){

						// TODO support only this format
						output[3] = WPSInputData.VECTOR_LAYER_SCHEMA_GML2;

					}else{
						// identifier, title, abstract
						output[j++] = prob.textContent;
					}
					
				}
			}
			
	
			
			// notice process
			arrayOfOutputs[k] = output;
		}
	else
		 alert("Can't determine output parameter of the WPS.");

	// create array with input and output parameters
	var inputOutput = new Array();
	inputOutput[0] = arrayOfInputs;
	inputOutput[1] = arrayOfOutputs;
	
	// only for debuging
	arraysOfinputOutput = inputOutput;
	
	return inputOutput;
}


/**
 * This method removes a GML file form the map.
 * 
 * @param layerName
 *            Layer name.
 */
function removeLayerByName(layerName) {

	// get layer by name
	var layer = layers[layerName];

	// check whether layer is available
	if (layer != null) {
		map.removeLayer(layer[0]); // remove layer from map
		layers[layerName] = null; // remove layer from array
	}
}


/**
 * This method creates the XMLHttpRequests for the use of Ajax.
 * 
 * @param mimeType
 *            Mime type like 'text/xml' oder 'text/plain'.
 * 
 * @return XMLHttpRequest.
 */
function getXMLHttpRequest(mimeType) {
	var request = null;
	if (window.ActiveXObject) {
		// IE:
		try {
			request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
			}
		}
	} else {
		// other browsers:
		request = new XMLHttpRequest();
		if (request.overrideMimeType) {
			request.overrideMimeType(mimeType);
		}
	}

	return request;
}

function loadProcessList(){
	
 // remove options
	
	for ( var opt in selectProcesses.options) {
		selectProcesses.remove(opt.index);
	}

 // determine and load WPS processes
 var processes = determineWPSProcesses(selectWPS.value);
 for ( var i = 0; i < processes.length; i++) {
	var option = document.createElement("option");
 	option.text = processes[i][1];
 	option.value = processes[i][0];
 	// option.style.width = "400px";
 	// select.appendChild( option );
 	 	
 	try
 	  {
 		selectProcesses.add(option,null); // standards compliant
 	  }
 	catch(ex)
 	  {
 		selectProcesses.add(option); // IE only
 	  }
 }
}

// function loadLayerList(){
//	
// // remove options
// for ( var opt in selectLayers.options) {
// selectLayers.remove(opt.index);
// }
//
// // determine and load WPS processes
// for ( var i in layers) {
//		
//	
// var option = document.createElement("option");
// option.text = i;
// option.value = layers[i][1];
//	 	 	
// try
// {
// selectLayers.add(option,null); // standards compliant
// }
// catch(ex)
// {
// selectLayers.add(option); // IE only
// }
// }
// }


/**
 * 
 * @param identifier
 * @param title
 * @param abstr
 * @param type
 * @return
 */
function createLiteralHTMLElement(identifier, title, abstr, type){
	
	
	var p = document.createElement("p");
	p.innerHTML = title + " (" + type + "): ";
	
	
	var input = null;
	if(type != "boolean"){// others
		input = document.createElement("input");
		input.type = "text";
		input.id = identifier;
		input.className = type;
		input.onclick = function(){
			input.focus();
	    }
	}else{// boolean
		input = document.createElement("select");
		input.id = identifier;
		input.className = type;
		
		var yes = document.createElement("option");
	 	yes.text = "yes";
	 	yes.value = "true";
	 	
		var no = document.createElement("option");
	 	no.text = "no";
	 	no.value = "false";
	 	 	
	 	try
	 	  {
	 		input.add(yes,null); // standards compliant
	 		input.add(no,null); // standards compliant
	 	  }
	 	catch(ex)
	 	  {
	 		input.add(yes); // IE only
	 		input.add(no); // IE only
	 	  }
		
	 	 	
	}

	
	inputLiterals[identifier] = input;
	p.appendChild(input);
	
	
	return p;
}

/**
 * 
 * @param identifier
 * @param title
 * @param abstr
 * @param schema
 * @return
 */
function createVectorLayerHTMLElement(identifier, title, abstr, schema){
	
	var p = document.createElement("p");
	p.innerHTML = title + ": ";
	var select = document.createElement("select");
	select.id = identifier;
	select.className = schema;
	select.style.width = "400px";
	selectLayers[identifier] = select;
	p.appendChild(select);
	
	// determine and load WPS processes
	for ( var i in layers) {
	
	var option = document.createElement("option");
 	option.text = i;
 	option.value = layers[i][1];
 	 	
 	try
 	  {
 		select.add(option,null); // standards compliant
 	  }
 	catch(ex)
 	  {
 		select.add(option); // IE only
 	  }
	}
		
	return p;
}

/**
 * 
 * @param identifier
 * @param title
 * @param abstr
 * @param schema
 * @return
 */
function createOutputVectorLayerHTMLElement(identifier, title, abstr, schema){
	var input = document.createElement("input");
	input.type = "hidden";
	input.id = identifier;
	input.value = schema;
	inputOutputLayers[identifier] = input;
	return input;
}


/**
 * This method load all input parameter as HTML form of the selected process.
 */
function loadProcessInputForms(){
	
	// determine process description
    var processDesc = determineWPSProcessDescription(selectWPS.value, selectProcesses.value);
    
    // remove old input forms
    divInputValues.innerHTML="";
    inputLiterals = new Array();
    selectLayers = new Array();
    inputOutputLayers = new Array();
    
    // add input forms
    for ( var i = 0; i < processDesc[0].length; i++) {
		var inputParam = processDesc[0][i];		
		if(inputParam[3] == WPSInputData.VECTOR_LAYER_SCHEMA_GML2)
			divInputValues.appendChild(createVectorLayerHTMLElement(inputParam[0],inputParam[1],inputParam[2],inputParam[3]));
		else
			divInputValues.appendChild(createLiteralHTMLElement(inputParam[0],inputParam[1],inputParam[2],inputParam[3]));
	}
       
    // add hidden output formats
    for ( var i = 0; i < processDesc[1].length; i++) {
		var outputParam = processDesc[1][i];		
		if(outputParam[3] == WPSInputData.VECTOR_LAYER_SCHEMA_GML2)
			divInputValues.appendChild(createOutputVectorLayerHTMLElement(outputParam[0],outputParam[1],outputParam[2],outputParam[3]));
   }
        
}

function createWPSInputData(){
	var data = new WPSInputData();
	
	// add input vector layers to data object
	for ( var i in selectLayers) {
		data.addVectorLayer(selectLayers[i].id, selectLayers[i].value, selectLayers[i].className);
	}
	
	// add input literals to data object
	for ( var i in inputLiterals) {	
		data.addLiteral(inputLiterals[i].id, inputLiterals[i].className, inputLiterals[i].value);
	}
	
	// add output vector layer schemas to data object
	for ( var i in inputOutputLayers) {	
		outputLayer = inputOutputLayers[i];
		data.addOutputVectorLayerFormat(inputOutputLayers[i].id, inputOutputLayers[i].defaultValue);
	}
		
	return data;
}

/**
 * This class manage all input parameter for execute a process of a WPS.
 */
function WPSInputData() {
	this.firstInputValue = true;
	this.firstOutputValue = true;
	this.inputData = "DataInputs=";
	this.outputData = "RawDataOutput=";
}

// literal types
WPSInputData.LITERAL_BOOLEAN_TYPE = "boolean";
WPSInputData.LITERAL_SELECTION_TYPE = "integer";
WPSInputData.LITERAL_STRING_TYPE = "string";
WPSInputData.LITERAL_NUMERICAL_VALUE_TYPE = "double";

// vector layer schemas
WPSInputData.VECTOR_LAYER_SCHEMA_GML2 = "http://schemas.opengis.net/gml/2.1.2/feature.xsd";

/**
 * This method adds a vector layer (gml feature collection).<commit_msg>Implemented execution of deegree WPS.<commit_after>// WFS-Operations
var WFS_GET_CAPABILITIES = "?SERVICE=WFS&REQUEST=GetCapabilities";
var WFS_DESCRIBE_FEATURE_TYPE_WFS = "?SERVICE=WFS&REQUEST=DescribeFeatureType&VERSION=1.0.0&TYPENAME=";
var WFS_GET_FEATURE = "?SERVICE=WFS&REQUEST=GetFeature&VERSION=1.0.0&OUTPUTFORMAT=GML2&TYPENAME=";

// WFS URLs for init
var wfsURLs = new Array();

// WPS-Operations
var WPS_GET_CAPABILITIES = "?SERVICE=WPS&REQUEST=GetCapabilities";
var WPS_DESCRIBE_PROCESS = "?SERVICE=WPS&REQUEST=DescribeProcess&VERSION=1.0.0&IDENTIFIER=";
var WPS_EXECUTE = "?SERVICE=WPS&REQUEST=Execute&VERSION=1.0.0&IDENTIFIER=";

// WPS URLs for init
var wpsURLs = new Array();

// make map available for easy debugging
var map;

// proxy for external data sources
OpenLayers.ProxyHost = "cgi-bin/proxy.py?url="; // saved:
												// /usr/lib/cgi-bin/proxy.py


// Array of layer array (layer, attr1, attr2, ...)
var layers = new Array();


// HTML-Elemente
var selectProcesses;
var selectWPS;
var divInputValues;
var selectLayers = new Array();
var inputLiterals = new Array();
var inputOutputLayers = new Array();
var resultDisplay = document.createTextNode("");


// increase reload attempts
OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3;

// new OpenLayers.Geometry.Point(0, 52).transform(new
// OpenLayers.Projection("EPSG:900913"),new
// OpenLayers.Projection("EPSG:4326"))

function init() {
	
	// ------------------------------------------------------------------------------------------------------
	// map options
	var options = {
		projection : new OpenLayers.Projection("EPSG:4326")
		// projection : new OpenLayers.Projection("EPSG:900913"),
		// displayProjection : new OpenLayers.Projection("EPSG:4326"),
		// units : "m"
	// numZoomLevels : 18,
	// maxResolution : 156543.0339,
	// maxExtent : new OpenLayers.Bounds(-20037508, -20037508, 20037508,
	// 20037508.34)
	};

	// ------------------------------------------------------------------------------------------------------
	// create map
	map = new OpenLayers.Map('map', options);

	// ------------------------------------------------------------------------------------------------------
	// add wms as basic layer
	var wms = new OpenLayers.Layer.WMS("OpenLayers BASIC",
			"http://labs.metacarta.com/wms/vmap0", {
				layers : 'basic',
				crs : "EPSG:4326"
			});
	map.addLayer(wms);

	// ------------------------------------------------------------------------------------------------------
	// add wms as layer
// var wms2 = new OpenLayers.Layer.WMS("OpenLayers STATE LABEL",
// "http://labs.metacarta.com/wms/vmap0", {
// layers : 'statelabel',
// format : "image/png",
// transparent : "true",
// crs : "EPSG:4326"
// }, {
// isBaseLayer : false,
// visibility : false
// });
// map.addLayer(wms2);

	// ------------------------------------------------------------------------------------------------------
	// add a marker
	// var vectorLayer = new OpenLayers.Layer.Vector("<NAME>");
	// var feature = new OpenLayers.Feature.Vector(
	// new OpenLayers.Geometry.Point(-0.0014, -0.0024),
	// {
	// some : 'data'
	// },
	// {
	// externalGraphic :
	// 'http://funmap.co.uk/cloudmade-examples/markers/marker.png',
	// graphicHeight : 37,
	// graphicWidth : 24
	// });
	// vectorLayer.addFeatures(feature);
	// map.addLayer(vectorLayer);

	// ------------------------------------------------------------------------------------------------------
	// add gml files as layer (only gml2 without schema)
	// addGMLLayer("GML2 Polygon", "gml/GML2_FeatureCollection_Polygon.xml",
	// "");
	// addGMLLayer("GML2 Buffered Polygon",
	// "gml/GML2_FeatureCollection_Polygon_Buffered.xml", "");

	// ------------------------------------------------------------------------------------------------------
	// add web feature service (only gml2)
	addWFSURL( "http://giv-wps.uni-muenster.de:8080/geoserver/wfs");
	addWFSURL(  "http://www.dge.upd.edu.ph/geoserver/wfs");
	
	addWFSLayer("WFS topp:states", "http://giv-wps.uni-muenster.de:8080/geoserver/wfs","topp:states", true);
	addWFSLayer("WFS ns1:tasmania_roads", "http://giv-wps.uni-muenster.de:8080/geoserver/wfs","ns1:tasmania_roads", false);
	addWFSLayer("WFS tiger:poi", "http://giv-wps.uni-muenster.de:8080/geoserver/wfs","tiger:poi", false);
	addWFSLayer("WFS tiger:tiger_roads", "http://giv-wps.uni-muenster.de:8080/geoserver/wfs","tiger:tiger_roads", false);
	addWFSLayer("WFS tiger:poly_landmarks", "http://giv-wps.uni-muenster.de:8080/geoserver/wfs","tiger:poly_landmarks", false);
	


	
	//
	// ------------------------------------------------------------------------------------------------------
	// add WPS
	addWPSURL( "http://flexigeoweb.lat-lon.de/deegree-wps-demo/services");
	addWPSURL( "http://giv-wps.uni-muenster.de:8080/wps/WebProcessingService");
	
// // centroid algorithm
// var data = new WPSInputData();
// var wfsFeatureURL =
// "http://giv-wps.uni-muenster.de:8080/geoserver/wfs?SERVICE=WFS&REQUEST=GetFeature&VERSION=1.0.0&OUTPUTFORMAT=GML2&TYPENAME=topp:states";
// data.addVectorLayer("LAYER", wfsFeatureURL,
// WPSInputData.VECTOR_LAYER_SCHEMA_GML2);
// data.addOutputVectorLayerFormat("RESULT",
// WPSInputData.VECTOR_LAYER_SCHEMA_GML2);
// addWPSLayer("WPS centroids",
// "http://flexigeoweb.lat-lon.de/deegree-wps-demo/services", "st_centroids",
// data);
//	
// // transform algorithm
// var data2 = new WPSInputData();
// var wfsFeatureURL2 =
// "http://giv-wps.uni-muenster.de:8080/geoserver/wfs?SERVICE=WFS&REQUEST=GetFeature&VERSION=1.0.0&OUTPUTFORMAT=GML2&TYPENAME=topp:states";
// data2.addVectorLayer("LAYER", wfsFeatureURL2,
// WPSInputData.VECTOR_LAYER_SCHEMA_GML2);
// data2.addLiteral("DISTANCEX", WPSInputData.LITERAL_NUMERICAL_VALUE_TYPE,
// "-20");
// data2.addLiteral("DISTANCEY", WPSInputData.LITERAL_NUMERICAL_VALUE_TYPE,
// "40");
// data2.addLiteral("ANGLE", WPSInputData.LITERAL_NUMERICAL_VALUE_TYPE, "90");
// data2.addLiteral("SCALEX", WPSInputData.LITERAL_NUMERICAL_VALUE_TYPE, "0.5");
// data2.addLiteral("SCALEY", WPSInputData.LITERAL_NUMERICAL_VALUE_TYPE, "0.5");
// data2.addLiteral("ANCHORX", WPSInputData.LITERAL_NUMERICAL_VALUE_TYPE,
// "-46");
// data2.addLiteral("ANCHORY", WPSInputData.LITERAL_NUMERICAL_VALUE_TYPE, "35");
// data2.addOutputVectorLayerFormat("RESULT",
// WPSInputData.VECTOR_LAYER_SCHEMA_GML2);
// addWPSLayer("WPS transform",
// "http://flexigeoweb.lat-lon.de/deegree-wps-demo/services", "st_transform",
// data2);
//	
// // fixeddistancebuffer algorithm
// var data3 = new WPSInputData();
// var wfsFeatureURL3 =
// "http://giv-wps.uni-muenster.de:8080/geoserver/wfs?SERVICE=WFS&REQUEST=GetFeature&VERSION=1.0.0&OUTPUTFORMAT=GML2&TYPENAME=ns1:tasmania_roads";
// data3.addVectorLayer("LAYER", wfsFeatureURL3,
// WPSInputData.VECTOR_LAYER_SCHEMA_GML2);
// data3.addLiteral("DISTANCE", WPSInputData.LITERAL_NUMERICAL_VALUE_TYPE,
// "0.05");
// data3.addLiteral("TYPES", WPSInputData.LITERAL_SELECTION_TYPE, "0");
// data3.addLiteral("RINGS", WPSInputData.LITERAL_SELECTION_TYPE, "0");
// data3.addLiteral("NOTROUNDED", WPSInputData.LITERAL_BOOLEAN_TYPE, "false");
// data3.addOutputVectorLayerFormat("RESULT",
// WPSInputData.VECTOR_LAYER_SCHEMA_GML2);
// addWPSLayer("WPS fixeddistancebuffer",
// "http://flexigeoweb.lat-lon.de/deegree-wps-demo/services",
// "st_fixeddistancebuffer", data3);
//
//	
// test =
// determineWPSProcessDescription("http://flexigeoweb.lat-lon.de/deegree-wps-demo/services","st_transform");
	
	// ------------------------------------------------------------------------------------------------------
	// add controls
	map.addControl(new WPSSwitcher());
	map.addControl(new OpenLayers.Control.LayerSwitcher());
	map.addControl(new OpenLayers.Control.MousePosition());

	// ------------------------------------------------------------------------------------------------------
	// set center
	map.setCenter(new OpenLayers.LonLat(-75, 0), 3);
}

function getStyleMap(){

	var color1="#FF8A14";
	
	var styleMap = new OpenLayers.StyleMap({ 
		strokeColor: color1, 
		fillColor : color1, 
		strokeWidth: 2, 
		pointRadius : 2,
		fillOpacity: 0.4
	});
		
	return styleMap;
}

/**
 * This method determines an individual name of layer.
 * 
 * @param name
 *            Raw layer name.
 * 
 * @return Modified layer name.
 */
function determineIndividualLayerName(name){
	var newName = name;
	
	// check whether name available
	if (layers[name] != null)
		newName = determineIndividualLayerName(name + "_1");

	return newName;
}

/**
 * This Method adds a GML file to the map.
 * 
 * @param gmlName
 *            Layer name.
 * @param gmlURL
 *            URL of GML file.
 * @param attr
 *            Optional attribute like absolute URL of GML file.
 */
function addGMLLayer(gmlName, gmlURL, attr) {
	
	gmlName = determineIndividualLayerName(gmlName);

	// create a GML layer
	var layer = new OpenLayers.Layer.GML(gmlName, gmlURL, { styleMap: getStyleMap() });

	// var layerProtocol = new OpenLayers.Protocol.HTTP( {
	// url : url,
	// format : new OpenLayers.Format.GML()
	// });
	//
	// var layer = new OpenLayers.Layer.Vector(name, {
	// strategies : [ new OpenLayers.Strategy.BBOX() ],
	// protocol : layerProtocol
	// });

	// notice layer
	var gmlArray = new Array();
	gmlArray[0] = layer;
	gmlArray[1] = attr;
	layers[gmlName] = gmlArray;
	
	// add layer to map
	map.addLayer(layer);
	
	resultDisplay.data = "Added layer '" + gmlName + "'";

}

/**
 * This method adds a WFS layer to map.
 * 
 * @param wfsURL
 *            URL of WFS.
 * @param wfsName
 *            Name of WFS.
 * @param wfsFeatureTypeWithPrefix
 *            FeatureTypeName with prefix.
 * @param visible
 *            visible=true.
 */
function addWFSLayer(wfsName, wfsURL, wfsFeatureTypeWithPrefix, visible) {
	
	wfsName = determineIndividualLayerName(wfsName);

	// determine namespace
	var ns = determineWFSFeatureTypeNamespace(wfsURL, wfsFeatureTypeWithPrefix);
	
	// check namespace
	if(ns == null)
		return;
	
	// check name
	var ftArray = wfsFeatureTypeWithPrefix.split(":");
	if(ftArray.length != 2){
		var name = new Array();
		name[0] = "";
		name[1] = wfsFeatureTypeWithPrefix;
		ftArray = name;
		// alert("FeatureType isn't in the correct format like 'prefix:name'.");
	}
	
	// create wfs layer
	var wfs = new OpenLayers.Layer.Vector(wfsName, {
		strategies : [ new OpenLayers.Strategy.BBOX() ],
		protocol : new OpenLayers.Protocol.WFS( {
			url : wfsURL,
			featureType : ftArray[1],
			featureNS : ns
		}), visibility : visible, styleMap: getStyleMap()
	});
	
	// add wfs layer to map
	var wfsArray = new Array();
	wfsArray[0] = wfs;
	wfsArray[1] = wfsURL + WFS_GET_FEATURE + wfsFeatureTypeWithPrefix;
	layers[wfsName] = wfsArray;
	map.addLayer(wfs);
}

/**
 * This method adds all layers of a WFS to the map.
 * 
 * @param wfsName
 *            Name of WFS.
 * @param wfsURL
 *            URL of WFS.
 */
function addWFSLayers(wfsName, wfsURL){
	
	// determine feature type names
	var types = determineWFSFeatureTypeNames(wfsURL);
	
	// add all layers
	for ( var i = 0; i < types.length; i++) {	
		addWFSLayer(wfsURL, wfsName +" " + types[i], types[i] , false);
	}
}


/**
 * This method adds a WFS URL.
 * 
 * @param url
 *            WFS URL.
 */
function addWFSURL(url){
	wfsURLs[url] = url;
}

/**
 * This method removes a WFS URL.
 * 
 * @param url
 *            WFS URL.
 */
function removeWFSURL(url){
	wfsURLs[url] = null;
}

/**
 * This method adds a layer by WPS.
 * 
 * @param wpsURL
 *            URL of WPS.
 * @param wpsProcess
 *            Identifier of process
 * @param data
 *            Process data, use class WPSInputData
 */
function addWPSLayer(wpsName, wpsURL, wpsProcess, data){
	resultDisplay.data = "Processing...";
	
	var gmlName = wpsName;
	var attr = wpsURL + WPS_EXECUTE + wpsProcess + data.toString();
	var gmlURL = OpenLayers.ProxyHost + escape(attr);	
	
	
	// check gml file for errors
	var request = getXMLHttpRequest('text/xml');
	request.open('GET', gmlURL, false);
	request.send();
	var xmlDoc = request.responseXML;
	

	if(xmlDoc.childNodes[0].localName == "ExceptionReport"){
		var errorMsg = xmlDoc.childNodes[0].textContent.replace(/^\s*|\s*$/g,'');
		
		if(errorMsg == "")
			resultDisplay.data = "Execution failed!";
		else
			resultDisplay.data = errorMsg;
		
	}else{
		addGMLLayer(gmlName, gmlURL, attr);
	}

}

/**
 * This method adds a new WPS URL.
 * 
 * @param url
 *            WPS URL.
 */
function addWPSURL(url){
	wpsURLs[url] = url;
}

/**
 * This method removes a WPS URL:
 * 
 * @param url
 *            WPS URL.
 */
function removeWPSURL(url){
	wpsURLs[url] = null;
}

/**
 * The method retuns an array of the FeatureTypeNames of the WFS.
 * 
 * @param wfsURL
 *            URL of WFS.
 * 
 * @return Array of FeatureTypeNames (prefix : name).
 */
function determineWFSFeatureTypeNames(wfsURL) {

	// url of xml file
	var url = OpenLayers.ProxyHost + wfsURL;
	url += escape(WFS_GET_CAPABILITIES);

	// parse xml file
	var request = getXMLHttpRequest('text/xml');
	request.open('GET', url, false);
	request.send();
	var xmlDoc = request.responseXML;
		
	// determine FeatureTypes
	var collectionOfFeatureTypes = xmlDoc.getElementsByTagName("FeatureType");
	var arrayOfFeatureTypes = new Array();
	if (collectionOfFeatureTypes.length > 0)
		for ( var int = 0; int < collectionOfFeatureTypes.length; int++) {
			arrayOfFeatureTypes[int] = collectionOfFeatureTypes[int].childNodes[0].firstChild.nodeValue;
		}
	else
		alert("Can't determine feature type names of the WFS.");

	// for debugging
	determineWFSFeatureTypeNames_XML = xmlDoc;
	determineWFSFeatureTypeNames_ARRAY = arrayOfFeatureTypes;
	
	return arrayOfFeatureTypes;
}


/**
 * This methode returns the namespace of a feature.
 * 
 * @param wfsURL
 *            URL of the WFS.
 * 
 * @param featureTypeName
 *            Name of a feature.
 * 
 * @return Namespace of feature.
 */
function determineWFSFeatureTypeNamespace(wfsURL, featureTypeName) {

	// url of xml file
	var url = OpenLayers.ProxyHost + wfsURL;
	url += escape(WFS_DESCRIBE_FEATURE_TYPE_WFS + featureTypeName);

	// parse xml file
	var request = getXMLHttpRequest('text/xml');
	request.open('GET', url, false);
	request.send();
	var xmlDoc = request.responseXML;

	// for debugging
	determineWFSFeatureTypeNS_XML = xmlDoc;
		
	// determine namespace and return
	var atts = xmlDoc.childNodes[0].attributes;
	for ( var int = 0; int < atts.length; int++) {
		if (atts[int].nodeName == "targetNamespace") {
			return atts[int].nodeValue;
		}
	}
	
	// namespace not found
	alert("Namspace of feature type '" + featureTypeName + "' wasn't found.");
	return null;
}


/**
 * This method returns all processes of a WPS.
 * 
 * @param wpsURL
 *            URL of WPS.
 * 
 * @return Array of Processes with names, titles and abstracts.
 */
function determineWPSProcesses(wpsURL) {

	// url of xml file
	var url = OpenLayers.ProxyHost + wpsURL;
	url += escape(WPS_GET_CAPABILITIES);

	// parse xml file
	var request = getXMLHttpRequest('text/xml');
	request.open('GET', url, false);
	request.send();
	var xmlDoc = request.responseXML;
	

	// determine Processes
	var collectionOfProcesses = xmlDoc.getElementsByTagName("wps:Process");
	var arrayOfProcesses = new Array();
	if (collectionOfProcesses.length > 0)
		for ( var int = 0; int < collectionOfProcesses.length; int++) {
			
			// process (identifier, title, abstract)
			var process = new Array();
			
			// determine process properties
			var processProperties = collectionOfProcesses[int].childNodes;

			for ( var i = 0; i < processProperties.length; i++) {
				
				var prob = processProperties[i];
				// alert(prob.localName + " " + prob.textContent);
				if(prob.localName == "Identifier")
					process[0] = prob.textContent;
				else if(prob.localName == "Title")
					process[1] = prob.textContent;
				else if(prob.localName == "Abstract")
					process[2] = prob.textContent;
			}
			
			// notice process
			arrayOfProcesses[int] = process;
		}
	else
		 alert("Can't determine Processes of the WPS.");
	
	
	// sort processes
	arrayOfProcesses.sort(function sortByFirstName(a, b) {
	    	var x = a[1].toLowerCase();
	    	var y = b[1].toLowerCase();
	    	return ((x < y) ? -1 : ((x > y) ? 1 : 0));
		}
	);
	
	return arrayOfProcesses;
}


/**
 * This method returns an array of all input and output parameter of the
 * process.
 * 
 * @param wpsURL
 *            URL of WPS.
 * @param identifier
 *            Identifier of process.
 * 
 * @return Array with all input and output parameters. [0]: input parameter, [1]
 *         output parameter with identifier, title, abstract and format.
 */
function determineWPSProcessDescription(wpsURL, identifier){
	
	// url of xml file
	var url = OpenLayers.ProxyHost + wpsURL;
	url += escape(WPS_DESCRIBE_PROCESS + identifier);

	// parse xml file
	var request = getXMLHttpRequest('text/xml');
	request.open('GET', url, false);
	request.send();
	var xmlDoc = request.responseXML;

	// determine input parameter
	var collectionOfInputs = xmlDoc.getElementsByTagName("Input");
	var arrayOfInputs = new Array();
	if (collectionOfInputs.length > 0)
		for ( var k = 0; k < collectionOfInputs.length; k++) {
			
			// input (identifier, title, abstract)
			var input = new Array();
			
			// determine input properties
			var inputProperties = collectionOfInputs[k].childNodes;
			var j = 0;
			for ( var i = 0; i < inputProperties.length; i++) {
				var prob = inputProperties[i];
				if(prob.localName != null){
					
					// input formats
					if(prob.tagName == "ComplexData"){

						// TODO support only this format
						input[3] = WPSInputData.VECTOR_LAYER_SCHEMA_GML2;

					}else{
						if(prob.tagName == "LiteralData"){
							input[3] = prob.textContent.replace(/^\s*|\s*$/g,''); // remove
																				// whitespace
						}else{
							// identifier, title, abstract
							input[j++] = prob.textContent;
						}
					}
				}
			}
			
		
			
			// notice process
			arrayOfInputs[k] = input;
		}
	else
		 alert("Can't determine input parameter of the WPS.");
	
	// determine output parameter
	var collectionOfOutputs = xmlDoc.getElementsByTagName("Output");
	var arrayOfOutputs = new Array();
	if (collectionOfOutputs.length > 0)
		for ( var k = 0; k < collectionOfOutputs.length; k++) {
			
			// output (identifier, title, abstract)
			var output = new Array();
			
			// determine output properties
			var outputProperties = collectionOfOutputs[k].childNodes;
			var j = 0;
			for ( var i = 0; i < outputProperties.length; i++) {
				var prob = outputProperties[i];
				if(prob.localName != null){
					
					// output formats
					if(prob.tagName == "ComplexOutput"){

						// TODO support only this format
						output[3] = WPSInputData.VECTOR_LAYER_SCHEMA_GML2;

					}else{
						// identifier, title, abstract
						output[j++] = prob.textContent;
					}
					
				}
			}
			
	
			
			// notice process
			arrayOfOutputs[k] = output;
		}
	else
		 alert("Can't determine output parameter of the WPS.");

	// create array with input and output parameters
	var inputOutput = new Array();
	inputOutput[0] = arrayOfInputs;
	inputOutput[1] = arrayOfOutputs;
	
	// only for debuging
	arraysOfinputOutput = inputOutput;
	
	return inputOutput;
}


/**
 * This method removes a GML file form the map.
 * 
 * @param layerName
 *            Layer name.
 */
function removeLayerByName(layerName) {

	// get layer by name
	var layer = layers[layerName];

	// check whether layer is available
	if (layer != null) {
		map.removeLayer(layer[0]); // remove layer from map
		layers[layerName] = null; // remove layer from array
	}
}


/**
 * This method creates the XMLHttpRequests for the use of Ajax.
 * 
 * @param mimeType
 *            Mime type like 'text/xml' oder 'text/plain'.
 * 
 * @return XMLHttpRequest.
 */
function getXMLHttpRequest(mimeType) {
	var request = null;
	if (window.ActiveXObject) {
		// IE:
		try {
			request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
			}
		}
	} else {
		// other browsers:
		request = new XMLHttpRequest();
		if (request.overrideMimeType) {
			request.overrideMimeType(mimeType);
		}
	}

	return request;
}


function loadProcessList(){
	
	// remove options
	for ( var opt in selectProcesses.options) {
		selectProcesses.remove(opt.index);
	}

	// determine and load WPS processes
	var processes = determineWPSProcesses(selectWPS.value);
 
	// add processes
	for ( var i = 0; i < processes.length; i++) {
		var option = document.createElement("option");
		
		// modify SEXTANTE process names
		var text = processes[i][1];
		var value = processes[i][0];
		if(value.startsWith("st_"))
			text += " (SEXTANTE)";
		
		option.text = text;
		option.value = value;	
		
		try
		{
			selectProcesses.add(option,null); // standards compliant
		}
		catch(ex)
		{
			selectProcesses.add(option); // IE only
		}
 }
 

 
}



// function loadLayerList(){
//	
// // remove options
// for ( var opt in selectLayers.options) {
// selectLayers.remove(opt.index);
// }
//
// // determine and load WPS processes
// for ( var i in layers) {
//		
//	
// var option = document.createElement("option");
// option.text = i;
// option.value = layers[i][1];
//	 	 	
// try
// {
// selectLayers.add(option,null); // standards compliant
// }
// catch(ex)
// {
// selectLayers.add(option); // IE only
// }
// }
// }


/**
 * 
 * @param identifier
 * @param title
 * @param abstr
 * @param type
 * @return
 */
function createLiteralHTMLElement(identifier, title, abstr, type){
		
	var p = document.createElement("p");
	p.innerHTML = title + " (" + type + "): ";
		
	
	var input = null;
	if(type != "boolean"){// others
		input = document.createElement("input");
		input.type = "text";
		input.id = identifier;
		input.className = type;
		input.onclick = function(){
			input.focus();
	    }
	}else{// boolean
		input = document.createElement("select");
		input.id = identifier;
		input.className = type;
		
		var yes = document.createElement("option");
	 	yes.text = "yes";
	 	yes.value = "true";
	 	
		var no = document.createElement("option");
	 	no.text = "no";
	 	no.value = "false";
	 	 	
	 	try
	 	  {
	 		input.add(yes,null); // standards compliant
	 		input.add(no,null); // standards compliant
	 	  }
	 	catch(ex)
	 	  {
	 		input.add(yes); // IE only
	 		input.add(no); // IE only
	 	  }
		
	 	 	
	}

	
	inputLiterals[identifier] = input;
	p.appendChild(input);
	
	// popup with abstract
	var info = document.createElement("a");
	info.innerHTML = "(i)";
	info.style.color = "white";
	info.href = "#";
	info.onclick = function(){
		showInputDataDescription(title, abstr, type);
	};
	p.appendChild(info);
	
	
	return p;
}

/**
 * 
 * @param identifier
 * @param title
 * @param abstr
 * @param schema
 * @return
 */
function createVectorLayerHTMLElement(identifier, title, abstr, schema){
	
	var p = document.createElement("p");
	p.innerHTML = title + ": ";
	var select = document.createElement("select");
	select.id = identifier;
	select.className = schema;
	select.style.width = "400px";
	select.onchange = function(){resultDisplay.data = ""};
	selectLayers[identifier] = select;
	p.appendChild(select);
	
	// determine and load WPS processes
	for ( var i in layers) {
	
	var option = document.createElement("option");
 	option.text = i;
 	option.value = layers[i][1];
 	 	
 	try
 	  {
 		select.add(option,null); // standards compliant
 	  }
 	catch(ex)
 	  {
 		select.add(option); // IE only
 	  }
	}
		
	// popup with abstract
	var info = document.createElement("a");
	info.innerHTML = "(i)";
	info.style.color = "white";
	info.href = "#";
	info.onclick = function(){
		showInputDataDescription(title, abstr, schema);
	};
	p.appendChild(info);
	
	return p;
}

/**
 * 
 * @param identifier
 * @param title
 * @param abstr
 * @param schema
 * @return
 */
function createOutputVectorLayerHTMLElement(identifier, title, abstr, schema){
	var input = document.createElement("input");
	input.type = "hidden";
	input.id = identifier;
	input.value = schema;
	inputOutputLayers[identifier] = input;
	return input;
}


/**
 * This method load all input parameter as HTML form of the selected process.
 */
function loadProcessInputForms(){
	
	// determine process description
    var processDesc = determineWPSProcessDescription(selectWPS.value, selectProcesses.value);
    
    // remove old input forms
    divInputValues.innerHTML="";
    inputLiterals = new Array();
    selectLayers = new Array();
    inputOutputLayers = new Array();
    
    // add input forms
    for ( var i = 0; i < processDesc[0].length; i++) {
		var inputParam = processDesc[0][i];		
		if(inputParam[3] == WPSInputData.VECTOR_LAYER_SCHEMA_GML2)
			divInputValues.appendChild(createVectorLayerHTMLElement(inputParam[0],inputParam[1],inputParam[2],inputParam[3]));
		else
			divInputValues.appendChild(createLiteralHTMLElement(inputParam[0],inputParam[1],inputParam[2],inputParam[3]));
	}
       
    // add hidden output formats
    for ( var i = 0; i < processDesc[1].length; i++) {
		var outputParam = processDesc[1][i];		
		if(outputParam[3] == WPSInputData.VECTOR_LAYER_SCHEMA_GML2)
			divInputValues.appendChild(createOutputVectorLayerHTMLElement(outputParam[0],outputParam[1],outputParam[2],outputParam[3]));
   }
        
}

function createWPSInputData(){
	var data = new WPSInputData();
	
	// add input vector layers to data object
	for ( var i in selectLayers) {
		data.addVectorLayer(selectLayers[i].id, selectLayers[i].value, selectLayers[i].className);
	}
	
	// add input literals to data object
	for ( var i in inputLiterals) {	
		data.addLiteral(inputLiterals[i].id, inputLiterals[i].className, inputLiterals[i].value);
	}
	
	// add output vector layer schemas to data object
	for ( var i in inputOutputLayers) {	
		outputLayer = inputOutputLayers[i];
		data.addOutputVectorLayerFormat(inputOutputLayers[i].id, inputOutputLayers[i].defaultValue);
	}
		
	return data;
}

function showInputDataDescription(title, abstr, type) {

	
	var htmlMsg = "<h3>" + title + "</h3><hr />";
	htmlMsg += "<h4>" + abstr + "</h4>";
	
	 var win = window.open("", "win", "width=360,height=270");
	 win.document.open("text/html", "replace");
	 win.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title></title></head><body>' + htmlMsg + '</body></html>');
	 win.focus();
	 win.document.close();
}

/**
 * This class manage all input parameter for execute a process of a WPS.
 */
function WPSInputData() {
	this.firstInputValue = true;
	this.firstOutputValue = true;
	this.inputData = "DataInputs=";
	this.outputData = "RawDataOutput=";
}

// literal types
WPSInputData.LITERAL_BOOLEAN_TYPE = "boolean";
WPSInputData.LITERAL_SELECTION_TYPE = "integer";
WPSInputData.LITERAL_STRING_TYPE = "string";
WPSInputData.LITERAL_NUMERICAL_VALUE_TYPE = "double";

// vector layer schemas
WPSInputData.VECTOR_LAYER_SCHEMA_GML2 = "http://schemas.opengis.net/gml/2.1.2/feature.xsd";

/**
 * This method adds a vector layer (gml feature collection).
{'fraction_non_alphanumeric': 0.1781923076923077, 'fraction_numerical': 0.012596153846153845, 'mean_word_length': 2.965304254994662, 'pattern_counts': {'":': 4, '<': 43, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 59}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2497259', 'n_tokens_mistral': 18937, 'n_tokens_neox': 17245, 'n_words': 3698}