
function RTfrom1(obj, inType)
{
	if (inType != 'Multi') {
		if (roundtrip == 'M' || roundtrip == 'L') {
			BuildDestinationPorts(obj.options[obj.options.selectedIndex].value,'Leg1ii');
		} else if (roundtrip == 'R' ) {
			BuildDestinationPorts(obj.options[obj.options.selectedIndex].value,'Leg1ii');
			BuildRoundTrip(obj.options[obj.options.selectedIndex].value,'Leg2ii');
		}
	} else {
		BuildDestinationPorts(obj.options[obj.options.selectedIndex].value,'Leg1ii');
	}
}

function RTto1(obj, inType)
{
	if (inType != 'Multi') {
		if (roundtrip == 'M') {
			BuildMultiLegTrip(obj.options[obj.options.selectedIndex].value, 'Leg2i', 'Leg2ii');
		} else {
			BuildRoundTrip(obj.options[obj.options.selectedIndex].value,'Leg2i');
		}	
		if (roundtrip == 'L') {
			BuildDestinationPorts(obj.options[obj.options.selectedIndex].value,'Leg2ii');	
		}
	} else {
		BuildMultiLegTrip(obj.options[obj.options.selectedIndex].value, 'Leg2i', 'Leg2ii');
	}
}

function RTfrom2(obj, inType)
{
	if (inType != 'Multi') {
		if (roundtrip == 'M') {
			BuildDestinationPorts(obj.options[obj.options.selectedIndex].value,'Leg2ii');
		} else {
			CheckMatch(this,'Leg2ii','Leg1ii');
		}
	} else {
		BuildDestinationPorts(obj.options[obj.options.selectedIndex].value,'Leg2ii');
	}
}

function RTto2(obj, inType)
{
	if (inType != 'Multi') {
		if (roundtrip == 'M') {
			CheckMatch(obj,'Leg2i','Leg1i');
		}
	} else {
		BuildMultiLegTrip(obj.options[obj.options.selectedIndex].value, 'Leg3i', 'Leg3ii');
	}
}

function RTfrom3(obj, inType)
{
	BuildDestinationPorts(obj.options[obj.options.selectedIndex].value,'Leg3ii');
}

function RTto3(obj, inType)
{
	BuildMultiLegTrip(obj.options[obj.options.selectedIndex].value, 'Leg4i', 'Leg4ii');	
}

function RTfrom4(obj, inType)
{
	BuildDestinationPorts(obj.options[obj.options.selectedIndex].value,'Leg4ii');
}


function fillPassengers()
{
	document.forms[0].TotalPassengers.options.clear;
	for (i=1; i<=totPass; i++)
	{
		document.forms[0].TotalPassengers.options[i-1] = new Option(i,i);
	}
	document.forms[0].TotalPassengers.selectedIndex = defPass-1;
}

function fillVehicles()
{
	document.forms[0].TotalVehicles.options.length = 0;
	for (i=0; i<=totVeh; i++)
	{
		document.forms[0].TotalVehicles.options[i] = new Option(i,i);
	}
	document.forms[0].TotalVehicles.selectedIndex = defVeh;
}

function getTotPass()
{
	document.write ( totPass );
}

function getTotVeh()
{
	document.write ( totVeh );
}

function CheckMatch(Element,CompareThis,ChangeThis) 
{
	if (Element.options[Element.options.selectedIndex].value == document.getElementById('CompareThis').options[document.getElementById('CompareThis').options.selectedIndex].value) 
	{
		alert("Please Select Different Departure And Arrival Port!");
		Element.options[0].selected = true;
	} else {
			document.getElementById('ChangeThis').options[Element.options.selectedIndex].selected = true;
	}
}


function validateDateToday (selectedDate)
{
	var startDate = dateFromF;
	<!-- var errorMessage = 'Cannot procceed past date ' + dateFromF; -->
	var errorMessage = 'There is a ' + rvDaysGap + ' days limit before an itenerary\'s reservation occurs. Cannot procceed past date ' + dateFromF;
	

	if ( compareDates(startDate, 'dd/MM/yyyy', selectedDate, 'dd/MM/yyyy') == 0 || compareDates(startDate, 'dd/MM/yyyy', selectedDate, 'dd/MM/yyyy') == 2 ) {
		return true;
	} else {
		alert (errorMessage);
		return false;
	}
}

function validateDates(Date1, Date2, errorMessage)
{
	// basic "compareDates function" from date.js
	

	if (! validateDateToday(Date1) ) {
		return false;
	}
	
	if (! validateDateToday(Date2) ) {
		return false;
	}
	
	
	var tmpCompareResult = compareDates(Date1, 'dd/MM/yyyy', Date2, 'dd/MM/yyyy');	
	if (dtValidation == 'GTE') {
		if ( tmpCompareResult == 1 ) {
			alert (errorMessage);
			return false;
		} else {
			return true;
		}
	} else {
		if ( tmpCompareResult != 0 ) {
			alert (errorMessage);
			return false;
		} else {
			return true;
		}
	}	
}

// Send form
function FormValidated() 
{
	// IFRAME is taken by var on .html page
	MM_showHideLayers('MB_Routes','','show');
	document.getElementById("MB_Routes").style.height = IFrameHeight + 'px';
}

function setIFrameDims()
{
	var iframe=document.getElementById("RouteFrame");
	iframe.style.width=IFrameWidth;
	iframe.style.height=IFrameHeight;
}

function putReturnDate()
{
	if (document.forms[0].Leg2Date.value != '') {
		document.forms[0].Leg2Date.value = document.forms[0].Leg1Date.value;		
	}
}