function OpenTTB(url)  {
	if(url.length != 0) window.location.href = url;
}


function mapResult()
{
	this.type			= "address";

	this.centerX		= 0;
	this.centerY		= 0;
	this.mapName		= "";

	this.placeName		= "";
	this.omc			= 0;
	this.placeID		= 0;

	this.streetName		= "";
	this.streetID		= 0;

	this.stopList		= new Array();
	this.stopNameList	= new Array();
}

var odvMap = null;
var mapUsage = "";
var odvMapResult  = new mapResult();

function setMapInput()
{
	if (odvMapResult && mapUsage)
	{
		if (odvMapResult.type == "address")
		{
			var obj = document.forms[0].elements('placeInfo_'+mapUsage); 
			if (obj) obj.value = odvMapResult.omc + ":" + odvMapResult.placeID;
			
			obj = document.forms[0].elements('placeState_'+mapUsage);
			if (obj) obj.value = "notidentified";

			obj = document.forms[0].elements('type_'+mapUsage);
			if (obj) obj.value = "coord";

			obj = document.forms[0].elements('nameInfo_'+mapUsage);
			if (obj) obj.value = odvMapResult.centerX + ":" + odvMapResult.centerY + ":" + odvMapResult.mapName + ":" + odvMapResult.streetName;

			obj = document.forms[0].elements('nameState_'+mapUsage);
			if (obj) obj.value = "notidentified";

			document.forms[0].submit();
		}
		else if (odvMapResult.type == "stop")
		{
			var obj = document.forms[0].elements('placeInfo_'+mapUsage);
			if (obj) obj.value = "";

			var obj = document.forms[0].elements('place_'+mapUsage);
			if (obj) obj.value= odvMapResult.placeName;
			
			var obj = document.forms[0].elements('nameInfo_'+mapUsage);
			if (obj) obj.value = "stopID:" + odvMapResult.stopList[0];

			var obj = document.forms[0].elements('name_'+mapUsage);
			if (obj) obj.value = odvMapResult.stopNameList[0];

			document.forms[0].submit();
		}
	}
}
////////////////////////////////////////////////////////////////////////////////////////
// set parameter for via location selection
function SetViaTypeValues()
{

	if (document.forms[0] && document.forms[0].itdLPxx_viaType)
	{
		ResetViaTypeValues();
		switch (document.forms[0].itdLPxx_viaType.selectedIndex)
		{
			// no via
			case (0) : break;
			
			// via location
			case (1) : break;
			
			// not via location
			case (2) : 
			{
				if (document.forms[0].notVia_via) 
					document.forms[0].notVia_via.value="1"; 
				break;
			}
			
			// via london centre
			case (3) : 
			{
				if (document.forms[0].placeInfo_via)
					document.forms[0].placeInfo_via.value="";

				if (document.forms[0].typeInfo_via)
					document.forms[0].typeInfo_via.value="stopID";

				if (document.forms[0].nameInfo_via)
					document.forms[0].nameInfo_via.value="1000248:1001171:1001276:1001221:1000254:1001108:1000077:1000145:1000138:1000040:1000045:1000139";
				
				break;
			}
			
			// not via london centre
			case (4) : 
			{
				if (document.forms[0].avoidTariffZoneActive) 
					document.forms[0].avoidTariffZoneActive.value="1"; 
				break;
			}
			default  : break;
		}
		
	}
}

function ResetViaTypeValues()
{
/*	if (document.forms[0].placeInfo_via)
		document.forms[0].placeInfo_via.value="";

	if (document.forms[0].typeInfo_via)
		document.forms[0].typeInfo_via.value="";

	if (document.forms[0].nameInfo_via)
		document.forms[0].nameInfo_via.value="";
	if (document.forms[0].notVia_via)
		document.forms[0].notVia_via.value="1"; */
		
		
	if (document.forms[0])
	{
		if (document.forms[0].placeInfo_via) document.forms[0].placeInfo_via.value="invalid";
		if (document.forms[0].typeInfo_via) document.forms[0].typeInfo_via.value="invalid";
		if (document.forms[0].nameInfo_via) document.forms[0].nameInfo_via.value="invalid";
	
		if (document.forms[0].notVia_via) document.forms[0].notVia_via.value="0";
		if (document.forms[0].avoidTariffZoneActive) document.forms[0].avoidTariffZoneActive.value="0";
	}

}

function SubmitWithoutDefaultText()
{
	var nameOrigin=document.getElementById('name_origin');
	var nameDest=document.getElementById('name_destination');
	var nameVia=document.getElementById('name_via');
	
	if (nameOrigin || nameDest || nameVia)
	{
		document.forms[0].onsubmit=SubmitForm;
	}
}

function SubmitForm()
{
	var nameOrigin=document.getElementById('name_origin');
	var nameDest=document.getElementById('name_destination');
	var nameVia=document.getElementById('name_via');

	if (nameOrigin && nameOrigin.value=='enter postcode, address, stop, station or POI')
	{
		nameOrigin.value='';
	}
	
	if (nameDest && nameDest.value=='enter postcode, address, stop, station or POI')
	{
		nameDest.value='';
	}

	if (nameVia && nameVia.value=='Enter specified stop or station such as \'Tesco\', \'High Street\', \'Rail Station\'')
	{
		nameVia.value='';
	}
}



function updateVia(viaType)
{
	if (document.forms[0].avoidTariffZoneActive) document.forms[0].avoidTariffZoneActive.value="0";
	if (document.forms[0].placeInfo_via) document.forms[0].placeInfo_via.value="invalid";
	if (document.forms[0].typeInfo_via) document.forms[0].typeInfo_via.value="invalid";
	if (document.forms[0].nameInfo_via) document.forms[0].nameInfo_via.value="invalid";
	
	
	
	//alert(viaType);

	switch (viaType)
	{
		// via location
		case 1 : 
		{
			var obj3 = document.getElementById("viaType3");
			if (obj3) obj3.disabled=true;
			
			var obj4 = document.getElementById("viaType4");
			if (obj4) obj4.disabled=true;
			
			if (document.forms[0].itdLPxx_viaType) document.forms[0].itdLPxx_viaType.value="1";
			
			break;
		}
		// avoid location
		case 2 :		
		{
			//alert("2");
			break;
		}
		// via london centre
		case 3 : 
		{
			var obj = document.getElementById("locationInput_via");
			if (obj)  obj.disabled=true;
			if (document.forms[0].itdLPxx_viaType) document.forms[0].itdLPxx_viaType.value="3";
			
			if (document.forms[0].placeInfo_via)
				document.forms[0].placeInfo_via.value="";

			if (document.forms[0].typeInfo_via)
				document.forms[0].typeInfo_via.value="stopID";

			if (document.forms[0].nameInfo_via)
				document.forms[0].nameInfo_via.value="1000248:1001171:1001276:1001221:1000254:1001108:1000077:1000145:1000138:1000040:1000045:1000139";
			
			break;
		}
		// aviod london centre
		case 4 : 
		{
			var obj = document.getElementById("locationInput_via");
			if (obj)  obj.disabled=true; 
			
			
	
			if (document.forms[0].itdLPxx_viaType) document.forms[0].itdLPxx_viaType.value="4";
			if (document.forms[0].avoidTariffZoneActive) document.forms[0].avoidTariffZoneActive.value="1";
			
			
			//alert(document.forms[0].viaType4.checked)
			
			if(document.forms[0].viaType4.checked == false)
			
			{
			document.forms[0].itdLPxx_viaType.value="3";
			
			}
			
			
			break;
		}
	}
}



function disableCycle()
{						
if(document.forms[0]){

	if(document.forms[0].cyclingActive)
		{

			if ( document.forms[0].cyclingActive.checked == false ) 
			{

			  document.getElementById('speedFactorBicycle').disabled=true;

			  document.getElementById('cycleType107').disabled=true;
			  document.getElementById('cycleType101').disabled=true;
			  document.getElementById('cycleType102').disabled=true;
			}

			else
				{
				  document.getElementById('speedFactorBicycle').disabled=false;

				  document.getElementById('cycleType101').disabled=false;


					  document.getElementById('cycleType107').disabled=false;
					  document.getElementById('cycleType102').disabled=false;


				}
			}
		}
	}


////////////////////////////////////////////////////////////////////////////////////////
// MOT Synchronisation

function MotChange(bChecked)
{
	var motType5 = document.forms[0].inclMOT_5;

	if(motType5)
	{
		motType5.checked=bChecked.checked;
	}
}
	

function checkTram(obj){
	document.getElementById('inclMOT_1').checked=obj;
}
	
	
function useProxFootSearchChange(obj){

	if(obj.checked==true){
		document.forms[0].useProxFootSearch.value='0';
	}
	else{
		document.forms[0].useProxFootSearch.value='1';
	}
}
	
	
