/* ABE FLEETLIST */

// Populates & activates country list [id="abe_fleet_countryList"]
function abe_fleet_country_list (list)
{
	var ca = list.getElementsByTagName ("Country"), o = abe_option ("fleet_countryList"), e, id, c;
	for (var i = new Number (0); i < ca.length; i++)
	{
		e = ca [i];
		id = e.getAttribute ("CountryId");
		abeCountryArray [id] = new Array ();
		abeCountryArray [id]["Name"] = e.firstChild.nodeValue;
		abe_add_option ("fleet_countryList", i + 1, abeCountryArray [id]["Name"], id);
	}
	if (typeof (abeCountry) == "undefined" || abeCountry == "")
	{
		clearInterval (abeWaitInterval);
		o [0].text = abeAction ["select"];
	}
	else
	{
		while (o [i].value != abeCountry && i > 0)
		{
			i--;
		}
		if (i > 0)
		{
			o [i].selected = true;
			clearInterval (abeWaitInterval);
			abe_fleet_list ();
			abe_rem_option ("fleet_countryList", 0);
		}
		else
		{
			clearInterval (abeWaitInterval);
			o [0].text = abeAction ["select"];
		}
	}
	abe_disable ("fleet_countryList", false);
}
// Creates and sorts array of fleet list cars
function abe_fleet_car_list (list)
{
	var vehicle = list.getElementsByTagName ("FleetGroup"), v, t, p, s, c;
	car.length = 0;
	for (var i = new Number (0); i < vehicle.length; i++)
	{
		v = vehicle [i].getElementsByTagName ("Vehicle") [0];
		t = v.getElementsByTagName ("VehType");
		p = v.getElementsByTagName ("PictureURL");
		s = vehicle [i].getElementsByTagName ("SimilarVehicle");
		c = car.length;
		car [c] = new Array ();
		c = car [c];
		c ["Code"] = v.getAttribute ("Code");
		c ["Name"] = v.getElementsByTagName ("VehMakeModel") [0].getAttribute ("Name").replace (" or ", "<br>or&nbsp;");
		c ["Picture"] = p.length ? p [0].firstChild.nodeValue : "/common/abe/image/noimage.gif";
		c ["AirCondition"] = v.getAttribute ("AirConditionInd");
		c ["Transmission"] = v.getAttribute ("TransmissionType");
		c ["Fuel"] = v.getAttribute ("FuelType");
		c ["Passenger"] = parseInt (v.getAttribute ("PassengerQuantity"), 10) ? v.getAttribute ("PassengerQuantity") : null;
		c ["Baggage"] = parseInt (v.getAttribute ("BaggageQuantity"), 10) ? v.getAttribute ("BaggageQuantity") : null;
		c ["Door"] = t.length && parseInt (t [0].getAttribute ("DoorCount"), 10) ? t [0].getAttribute ("DoorCount") : null;
		s.length ? c ["Similar"] = vehicle [i].getElementsByTagName ("SimilarVehicle") : null;
	}
	abe_fleet_cars (car.sort (abe_fleet_sort));
}
// Sorts fleet list cars list by code
function abe_fleet_sort (a, b)
{
	return a ["Code"] > b ["Code"] ? 1 : a ["Code"] < b ["Code"] ? -1 : 0;
}
// Populates fleet list cars list
function abe_fleet_cars (list)
{
	var r, c;
	for (var i = new Number (0); i < list.length; i++)
	{
		r = abe_ID ("cars").insertRow (-1);
		typeof (abe_sColRowBg) == "undefined" ? null : abeBG ["row"] = "#" + abe_sColRowBg;
		typeof (abe_sColAltRowBg) == "undefined" ? null : abeBG ["row_alternative"] = "#" + abe_sColAltRowBg;
		r.style.backgroundColor = i % 2 ? abeBG ["row"] : abeBG ["row_alternative"];
		for (var j = new Number (0); j < 8; j++)
		{
			switch (j.valueOf ())
			{
				case 0:
					c = "code";
					break;
				case 1:
					c = "name";
					break;
				case 7:
					c = "duration";
					break;
				default:
					c = "default";
					break;
			}
			r.insertCell (-1);
			r.cells [r.cells.length - 1].className = "abe_cars_" + c;
		}
		with (r)
		{
			cells [0].innerHTML = list [i]["Code"];
			cells [1].innerHTML = "<span onmouseover=\"abe_mousePosition (event); abe_fleet_similar_cars ('" + i + "'); this.style.cursor='pointer'; this.style.textDecoration='underline';\" onmouseout=\"abe_display ('popup_car', 'none'); abe_ID ('car_picture_src').src='/common/abe/image/loadimage.gif'; this.style.textDecoration='none';\">" + list [i]["Name"] + "</span>";
			cells [2].innerHTML = list [i]["AirCondition"] == "true" ? "<img src=\"/common/abe/image/icon/aircondition.gif\" width=\"16\" height=\"16\" title=\"Air Conditioning\">" : "&nbsp;";
			cells [3].innerHTML = list [i]["Transmission"] == "Automatic" ? "<img src=\"/common/abe/image/icon/transmission.gif\" width=\"16\" height=\"16\" title=\"Automatic Vehicle\">" : "&nbsp;";
			cells [4].innerHTML = list [i]["Fuel"] == "Diesel" ? "<img src=\"/common/abe/image/icon/fuel.gif\" width=\"16\" height=\"16\" title=\"Diesel Vehicle\">" : "&nbsp;";
			c = list [i]["Passenger"];
			cells [5].innerHTML = c ? "<img src=\"/common/abe/image/icon/passenger.gif\" width=\"16\" height=\"16\" title=\"Passengers Quantity\"><br>" + c : "&nbsp;";
			c = list [i]["Baggage"];
			cells [6].innerHTML = c ? "<img src=\"/common/abe/image/icon/baggage.gif\" width=\"16\" height=\"16\" title=\"Baggage Quantity\"><br>" + c : "&nbsp;";
			c = list [i]["Door"];
			cells [7].innerHTML = c ? c + "&nbsp;doors" : "&nbsp;";
		}
	}
	abe_load ();
	abeFleetCountriesList ? abe_display ("quote", "inline") : null;
	abe_display ("cars", "block");
	abe_display ("legend", "inline");
}
// Shows similar cars list
function  abe_fleet_similar_cars (i)
{
	var c = car [i], s = c ["Similar"], l = new String ();
	abe_display ("popup_car", "none");
	abe_ID ("car_picture_src").src = c ["Picture"];
	if (typeof (s) != "undefined")
	{
		for (var i = new Number (0); i < s.length; i++)
		{
			l += "<br>&bull;&nbsp;" + s [i].firstChild.nodeValue;
		}
		l = "<span class=\"abe_popup_title\">" + abeText ["popUp"]["similar_cars"] + "</span>" + l;
	}
	else
	{
		l = "";
	}
	abe_inner ("similar", l);
	abe_inner ("description", (c ["AirCondition"] == "true" ? "<img src=\"/common/abe/image/icon/aircondition.gif\" width=\"16\" height=\"16\" border=\"0\">&nbsp;Air&nbsp;Conditioning<br>" : "") +
							(c ["Transmission"] == "Automatic" ? "<img src=\"/common/abe/image/icon/transmission.gif\" width=\"16\" height=\"16\" border=\"0\">&nbsp;Automatic&nbsp;Vehicle<br>" : "") +
							(c ["Fuel"] == "Diesel" ? "<img src=\"/common/abe/image/icon/fuel.gif\" width=\"16\" height=\"16\" border=\"0\">&nbsp;Diesel&nbsp;Vehicle<br>" : "") +
							(c ["Passenger"] ? "<img src=\"/common/abe/image/icon/passenger.gif\" width=\"16\" height=\"16\" border=\"0\">&nbsp;Passengers&nbsp;Quantity:&nbsp;" + c ["Passenger"] + "<br>" : "") +
							(c ["Baggage"] ? "<img src=\"/common/abe/image/icon/baggage.gif\" width=\"16\" height=\"16\" border=\"0\">&nbsp;Baggage&nbsp;Quantity:&nbsp;" + c ["Baggage"] + "<br>" : "") +
							(c ["Door"] ? "<img width=\"16\" height=\"16\" style=\"visibility:hidden;\">&nbsp;Doors&nbsp;Quantity:&nbsp;" + c ["Door"] : ""));
	with (abe_ID ("popup_car").style)
	{
		left = abe_X;
		top = abe_Y;
	}
	abe_display ("popup_car", "block");
}
// Requests fleet list cars
function abe_fleet_list ()
{
	abe_display ("quote", "none");
	abe_display ("cars", "none");
	abe_display ("legend", "none");
	abe_load ("car_fleet_list");
	var e = abe_ID ("fleet_countryList");
	e.options [0].text == abeAction ["select"] ? abe_rem_option ("fleet_countryList", 0) : null;
	abeCountryID = e.value;
	abe_delete ("cars", 1);
	abe_request ("fleetList");
}
abe_inner ("popup_car_description", abeText ["popUp"]["car_desription"]);
abe_ID ("fleet_countryList").onchange = abe_fleet_list;
abe_load ();
if (abeFleetCountriesList)
{
	abe_display ("quote", "inline");
	abe_request ("fleet_countryList");
}
else
{
	abe_load ("car_fleet_list");
	abeCountryID = abeCountry;
	abe_request ("fleetList");
}
