/////////////////////////////////////////////////////////////////////
// read journey planner application reqeust information
function RemoveAssignedStopSelection()
{
	// check request window
	if (document.mapRequest && document.mapRequest.odvMapRequest)
	{
		var objectList = document.mapRequest.odvMapRequest.objectList;
		if (objectList)
		{
			objectList.length=0;
		}
	}
}

/////////////////////////////////////////////////////////////////////
// read journey planner application reqeust information
function setSelectedStops()
{
	// check request window
	if (document.mapRequest && document.mapRequest.odvMapRequest)
	{
		if (document.forms[0].stopSelector)
		{
			var optionList = document.forms[0].stopSelector.options;

			// check local selector
			if (optionList)
			{
				var type	   = document.mapRequest.odvMapRequest.mapType;
				var objectList = document.mapRequest.odvMapRequest.objectList;

				if (objectList)
				{
					if (type == "stop")
					{
						for (var iSel = 0; iSel < objectList.length; iSel++)
						{
							for (var iOpt = 0; iOpt < optionList.length; iOpt++)
							{
								if (objectList[iSel] == optionList[iOpt].value)
									optionList[iOpt].selected = true;
							}
						}
					}
				}
			}
		}
	}
}


/////////////////////////////////////////////////////////////////////
// send selection result to journey planner application window
function setOdvResult(selector, coord, desc)
{
	if (document.mapRequest)
	{
		var result = document.mapRequest.odvMapResult;
		
		if (result)
		{
			if (selector == "stop")
			{
				result.stopList.length = 0;
				result.stopNameList.length = 0;
				var selIndex = 0;
				for (var iOption = 0; iOption < document.forms[0].stopSelector.options.length; iOption++)
				{
					if (document.forms[0].stopSelector.options[iOption] &&
					    document.forms[0].stopSelector.options[iOption].selected)
					{
						
						/* Don't select more than 4 stops */
						if (selIndex == 4) {
							alert("Bitte nur maximal vier Haltestellen auswählen");
							return;
						}
						result.stopList[selIndex]	  = document.forms[0].stopSelector.options[iOption].value;
						result.stopNameList[selIndex] = document.forms[0].stopSelector.options[iOption].text;
						selIndex++;
					}
				}

				result.type			= "stop";
				result.placeName	= "";

				document.mapRequest.setMapInput();
				document.mapRequest.focus();
				window.close();
			}
			else if (selector == "poi")
			{
				var index = document.forms[0].poiSelector.selectedIndex;
				
				if (index >= 0) {
					var value = document.forms[0].poiSelector.options[index].value;
					var text = document.forms[0].poiSelector.options[index].text;


					var reg = /^([^:]*):([^:]*)$/
					var found = reg.exec(value);

					if (found) {
						result.type = "poi";
						result.placeName = "";
						result.placeID = -1;
						result.desc = text;
						result.omc = found[1];
						result.poiID = found[2];

						document.mapRequest.setMapInput();
						document.mapRequest.focus();
						window.close();
					}
				}
			}
			else if (selector == "mapCenter")
			{
				if (coord == 'noObject')
				{
					alert('No Center Object!');
				}
				else
				{
					result.desc		= desc;
					result.coordValue	= coord;

					document.mapRequest.setMapInput();
					document.mapRequest.focus();
					window.close();
				}
			}
		}
	}
}




function mapResult()
{

	this.type		= "address";

	this.centerX		= 0;
	this.centerY		= 0;
	this.mapName		= "";
	this.coordValue		= "";
	this.desc		= "";

	this.placeName		= "";
	this.omc		= 0;
	this.placeID		= 0;

	this.streetName		= "";
	this.streetID		= 0;
	
	this.poiID		= 0;

	this.stopList		= new Array();
	this.stopNameList	= new Array();
}

function mapRequest()
{
	this.odvMap		= null;
	this.mapUsage	= "unknown";
	this.mapType	= "unknown";
	this.objectList = new Array();
}

var odvMapResult  = new mapResult();
var odvMapRequest = new mapRequest();

function setMapInput()
{


	if (odvMapResult && odvMapRequest.mapUsage)
	{

	
		if (odvMapResult.type == "address")
		{

			obj = document.forms[0].elements['typeInfo_'+odvMapRequest.mapUsage];
			if (obj) obj.value = "coord";
			
			obj = document.forms[0].elements['nameInfo_'+odvMapRequest.mapUsage];
			if (obj) obj.value = odvMapResult.coordValue;

			if (odvMapRequest.mapUsage!='dm'){
				obj = document.forms[0].elements['execInst'];
				if (obj) obj.value = "verifyOnly";
			}

			document.forms[0].submit();
		}
		else if (odvMapResult.type == "poi")
		{
			var obj = document.forms[0].elements['placeInfo_'+odvMapRequest.mapUsage]; 
			if (obj) obj.value = odvMapResult.omc + ":" + odvMapResult.placeID;
			
			obj = document.forms[0].elements['typeInfo_'+odvMapRequest.mapUsage];
			if (obj) obj.value = "poiID";
			
			obj = document.forms[0].elements['nameInfo_'+odvMapRequest.mapUsage];
			if (obj) obj.value = odvMapResult.poiID;

			if (odvMapRequest.mapUsage!='dm'){
				obj = document.forms[0].elements['execInst'];
				if (obj) obj.value = "verifyOnly";
			}

			document.forms[0].submit();
		}
		else if (odvMapResult.type == "stop")
		{
		
			var obj = document.forms['tripRequest'].elements['placeInfo_'+odvMapRequest.mapUsage];
			if (obj) obj.value = "";
		
			obj = document.forms['tripRequest'].elements['typeInfo_'+odvMapRequest.mapUsage];
			if (obj) obj.value = "stopID";
			
			var obj = document.forms['tripRequest'].elements['nameInfo_'+odvMapRequest.mapUsage];
			if (obj) 
			{
				obj.value = "";
				for (var iStop = 0; iStop < odvMapResult.stopList.length; iStop++)
				{

					if (iStop > 0) obj.value += ":";
					obj.value += odvMapResult.stopList[iStop];

				}
			}

			if (odvMapRequest.mapUsage!='dm'){
				obj = document.forms['tripRequest'].elements['execInst'];
				if (obj) obj.value = "verifyOnly";
			}

		//	obj = document.forms[0].elements['deleteAssignedStops_'+odvMapRequest.mapUsage];
		
		
			obj = document.forms['tripRequest'].elements['deleteAssignedStops_'+odvMapRequest.mapUsage];
		
			if (obj) obj.value = '1';


			// document.forms['tripRequest'].submit();
		}
	}
}


