function MapCrossSection() {
	this.csCoords = null;
	this.getCsCoords = getCsCoords;
	this.crossUrl = null;
	this.setUrl = setUrl;
	this.getUrl = getUrl;
	this.layerName = null;
	this.setLayerName = setLayerName;
	this.getLayerName = getLayerName;
	this.drawCrossSection = drawCrossSection;
	this.addCoord = addCoord;
	this.removeLastCoord = removeLastCoord;
	this.removeAllCoords = removeAllCoords;
	
	function getCsCoords() {
		if(!this.csCoords) {
			this.csCoords = new Array();
		}
		return this.csCoords;
	}
	
	function setUrl(url) {
		crossUrl = url;
	}
	
	function getUrl() {
		return crossUrl;
	}
	
	function setLayerName(name) {
		layerName = name;
	}

	function getLayerName() {
		return layerName;
	}

	function addCoord(id) {
		var csCoords = getCsCoords();
		csCoords.push(id);
	}
	
	function removeLastCoord() {
		var csCoords = getCsCoords();
		if(csCoords.length > 0) {
			csCoords.splice(csCoords.length - 1, 1);
		}
	}
	
	function removeAllCoords() {
		var csCoords = getCsCoords();
		while(csCoords.length > 0) {
			csCoords.pop();
		}		
	}
	
	function drawCrossSection(activationWarning) {
		var coordString = null;
		var csCoords = getCsCoords();
		if(!csCoords || csCoords.length < 2) {
			alert("Nothing to draw, please draw a cross section line first.");
			return;
		}	
		if (!getLayerName()) {
			alert(activationWarning);
			return;
		}
		var mapFunction = new MapFunction(getLayerName());
		var dataType = mapFunction.findInDinoExtract("dataType");
		
		var xCrds = "";
		var yCrds = "";
		var ids = "";
		for (var i = 0; i < csCoords.length; i++) {
			// the array always contains coordinates of points 
			// but can also contain an id as first value of 
			// the comma-separated string
			var point = csCoords[i].split(",");
			var x = point[0];
			var y = point[1];
			var id = "";
			if (point.length > 2) {
				// in this case the id is the first value
				id = point[0];
				x = point[1];
				y = point[2];
			}
			xCrds = xCrds + x;
			yCrds = yCrds + y;
			ids = ids + id;
			if(i < csCoords.length - 1) {
				xCrds = xCrds + ";";
				yCrds = yCrds + ";";				
				ids = ids + ";";
			}		
		}		
		var url = getUrl() + "?xCrds=" + xCrds + "&yCrds=" + yCrds + 
					"&ids=" + ids + "&dataType=" + dataType;
		
		window.open(url, "DinoMapCrossSection", "");  // NB no spaces in second argument because of IE
	}
}
