

function populateDroplists(dropList)
{
	// Also in phpinc/Constant.php
	var FAREOFFICE_LINK =  "/FareofficeLink";

	var dynaURL = FAREOFFICE_LINK + "/ContentManager/Components/portalsearchcar_alamo/Criterion/listUpdate.php"

	dynaURL = dynaURL + "?company_id=" + $('#company_id').val();
	dynaURL = dynaURL + "&formTrackNo=" + $('#formTrackNo').val();

	// Pickup
	if (dropList.id == "pickup_location_type_city" || dropList.id == "pickup_location_type_airport")
	{
		if (dropList.id == "pickup_location_type_city")
			dynaURL = dynaURL + "&pickup_location_type=CITY";
		else if (dropList.id == "pickup_location_type_airport")
			dynaURL = dynaURL + "&pickup_location_type=AIRPORT";

		dynaURL = dynaURL + "&update_pickup_stations=true";
	}
	else
	{
		if ($('#pickup_location_type_airport').is(':checked'))
			dynaURL = dynaURL + "&pickup_location_type=AIRPORT";
		else
			dynaURL = dynaURL + "&pickup_location_type=CITY";
	}

	// Dropoff
	if (dropList.id == "dropoff_location_type_city" || dropList.id == "dropoff_location_type_airport")
	{
		if (dropList.id == "dropoff_location_type_city")
			dynaURL = dynaURL + "&dropoff_location_type=CITY";
		else if (dropList.id == "dropoff_location_type_airport")
			dynaURL = dynaURL + "&dropoff_location_type=AIRPORT";

		dynaURL = dynaURL + "&update_dropoff_stations=true";
	}
	else
	{
		if ($('#dropoff_location_type_airport').is(':checked'))
			dynaURL = dynaURL + "&dropoff_location_type=AIRPORT";
		else
			dynaURL = dynaURL + "&dropoff_location_type=CITY";
	}


	dynaURL = dynaURL + "&pickup_country_code=" + $('#pickup_country').val();

	if (dropList != "pickup_country")
	{
		dynaURL = dynaURL + "&pickup_station_code=" + $('#pickup_station').val();

		if (dropList != "pickup_station")
		{
			dynaURL = dynaURL + "&dropoff_country_code=" + $('#dropoff_country').val();
			if (dropList != "dropoff_country")
			{
				dynaURL = dynaURL + "&dropoff_station_code=" + $('#dropoff_station').val();
			}
		}
	}

	dynaURL = encodeURI(dynaURL);
	document.getElementById("dynaFrame").src = dynaURL;
}

//

function addOption(droplist, name, value)
{
	droplist.options[droplist.options.length] = new Option(name, value);
}

//

function alterDropoffTime(pickupYear1, pickupDay)
{
	pickupYear = pickupYear1.options[pickupYear1.selectedIndex].value;
	pickupMonthIndex = pickupYear1.selectedIndex;

	var currentDate = new Date();
	var currentMonth = currentDate.getMonth();
	var pickupDate = new Date();
	var dropoffDate = new Date();

	//pickupMonth can be 14 - then March next year is intended
	var pickupMonth = pickupMonthIndex + currentMonth;

	// Set dateobject to selected pickup date
	dropoffDate.setFullYear(pickupYear.substr(3), pickupMonth, (pickupDay + 8));

	var dropoffMonth = dropoffDate.getMonth();

	var dropoffDay 	 = dropoffDate.getDate();

	dropoffMonthIndex =  dropoffMonth - currentMonth;

	var dropoffYear = dropoffDate.getFullYear();//ex2010
	var currentYear = currentDate.getFullYear();//ex2009

	if (dropoffYear != currentYear)
	{
		// Example: dropoff is next year, February (1), current Month is November (10).
		// Dropoffmonth index = 1 - 10 = -9. Add 12 to get the correct 3 month offset, from current month.
		if (dropoffMonthIndex <= 0)
		{
			dropoffMonthIndex = dropoffMonthIndex + 12;
		}

		if (dropoffMonthIndex >	(document.getElementById('dropoff-month').length - 1))
		{
			// Dropoff is greater than the max display range. Show latest possible date.
			dropoffMonthIndex = pickupMonthIndex;
			dropoffDay = document.getElementById('dropoff-day').length - 1;
		}
	}

	document.getElementById('dropoff-day').options[dropoffDay-1].selected = true;
	document.getElementById('dropoff-month').options[dropoffMonthIndex].selected = true;
}

function checkStationOpenHrs1()
{
	var pickup_time_allowed = false;
	var dropoff_time_allowed = false;
	try
	{
		var monthArr = {"jan":0, "feb":1, "mar":2, "apr":3, "may":4, "jun":5, "jul":6, "aug":7, "sep":8, "oct":9, "nov":10, "dec":11};
		var weekArr  = {1:"mo", 2:"tu" , 3:"we", 4:"th", 5:"fr", 6:"sa", 0:"su" };

		// pickup time
		pm = document.getElementById("pickup-month");
		pd = document.getElementById("pickup-day");
		pt = document.getElementById("pickup-time");

		pd1 = pd.options[pd.selectedIndex].value;
		pm1 = pm.options[pm.selectedIndex].value;
		pt1 = pt.options[pt.selectedIndex].value;

		y = pm1.substr(3);
		m = pm1.substr(0,3);

		day = new Date(y,monthArr[m],pd1).getDay();
		day = weekArr[day];

		pt1 = pt1.replace(":", "");
		if (pt1.substr(0,1) == '0')
		{
			pt1 = pt1.substr(1,3);
		}

		time_range = week_pickup[day];
		for (j = 0; j < time_range.length; j++)
		{
			if (pt1 >= time_range[j]['open'] && pt1 <= time_range[j]['close'])
			{
				pickup_time_allowed = true;
				break;
			}
		}

		var errorBox = $('#pickup-content .message-error:last');
		if (pickup_time_allowed == false)
		{
			errorBox.show();
			errorBox.append('<ul><li>Pickup Station closed at this day/time.<br/>Please get the info from the info (i) button.</li></ul>');
			return false;
		}
		else
		{
			errorBox.hide();
		}
	}
	catch (e)
	{

	}

	$('#search-loader').show();
	return submitWithProgress();
}

