//2005041 -- TRUE CAR TYPE AVAILABILITY METHODS//

function OnPickupLocationChange(strLocation)
{
   // clear the error message
	var ctlErrorMessage = document.getElementById("res1_lblError");
	if( null != ctlErrorMessage)
	   ctlErrorMessage.innerHTML = "";
	      
	// Load the Car Type Select control and set the selected cartype
	var ctlVehicleSelect = document.getElementById("res1_lstVehicleSelect");
	var SIPP = ctlVehicleSelect.value;
	
	var objAjaxResponse = reservation_expressrates.Populate_VehicleSelectList(strLocation, SIPP);
   if(null != objAjaxResponse.error) // error in AJAX // throw an exception in codebehind to test
   {
      alert(objAjaxResponse.error.description);
      ctlErrorMessage.InnerText = objAjaxResponse.error.description;
      ctlVehicleSelect.InnerHTML = ""; // clear the list
   }  
   else
   {
      var ctlVehicleSelectDIV = document.getElementById("res1_dvVehicleSelect");
      if(objAjaxResponse.value[0])   // AJAX succeeded
      {
         // output the values
         ctlVehicleSelectDIV.innerHTML = objAjaxResponse.value[1];
         SIPP = objAjaxResponse.value[2]; // the CarType selected in the select control
      }
   }    
      // Populate_VehicleSelectList returns no vehicles display error message
	if ( "-1" == SIPP || "" == SIPP)
	{
	   if( null != ctlErrorMessage)
	   {
	      var _selectorCulture = theForm.res1_cultureForLocationSelector
	      if(_selectorCulture != null) 
	      var cultureValue = _selectorCulture.value;
	      
	      if(cultureValue == "fr-FR")
	         ctlErrorMessage.innerHTML = ErrorMessageArray[1];
	      else
	         ctlErrorMessage.innerHTML = ErrorMessageArray[0];
	         // "To rent vehicle from this location please contact the Specialty Desk at 800-800-3665.";
	   }
	   DisplayNoDetails(false); 
	}
	else
	{   
      OnVehicleChange(SIPP); //Display vehicle information
	}	
}
function DisplayNoDetails(bGraphic)
{
   //DISPLAY PHOTO-NOT-AVAILABLE GRAPHIC
   if(bGraphic)
      document.getElementById("res1_imgCar").setAttribute("src","/images/fleet/carunavail.gif");
   else
      document.getElementById("res1_imgCar").style.display = 'none';

   //hide make model
   document.getElementById("res1_dvCarType_MakeModel").style.display = 'none';

   //HIDE MORE-FEATURES LINK, PASSENGER, LUGGAGE AND FUEL GRAPHICS
   document.getElementById("res1_linkMoreFeatures").style.display = 'none';
   document.getElementById("res1_imgCarPassLarge").style.display = 'none';
   document.getElementById("res1_imgCarPassSmall").style.display = 'none';
   document.getElementById("res1_imgCarLuggageLarge").style.display = 'none';
   document.getElementById("res1_imgCarLuggageSmall").style.display = 'none';
   document.getElementById("res1_imgCarFuel").style.display = 'none';
}


function OnVehicleChange(vehicleSIPP)
{
	var strLocation = document.getElementById("res1_pcode").value;
	//var ctlSelectCarType = document.getElementById("res1_resCarType"); // hidden control
	//ctlSelectCarType.Value = vehicleSIPP;
	                                           
   try
	{
		//Retrieve vehicle information for specified sipp-location code
		var response = reservation_expressrates.Populate_VehicleInformation(vehicleSIPP, strLocation);
      var lblmakemodeltrim = document.getElementById("res1_dvCarType_MakeModel");
      lblmakemodeltrim.style.display = 'block';

      // Use the web description if it exists
      if((null != response.value.WebDescription) && (response.value.WebDescription.length > 0 ))
      {
         lblmakemodeltrim.innerHTML = response.value.WebDescription;
      }
		else if( (response.value.Make != null) && (response.value.Make.length > 0) &&
			      (response.value.Model != null) && (response.value.Model.length > 0))
		{
			//MAKE + MODEL + MAKE-MODEL-TRIM
			lblmakemodeltrim.innerHTML = 
				response.value.Make + " " + 
				response.value.Model + " " + 
				response.value.MakeModelTrim + " " +
				response.value.ExtraText;
		}
		else
		{
			// make and model are null
			// Display short description - Domestic   
			if((response.value.CountryCode == 'US') || (response.value.CountryCode == 'CA') ||
				(response.value.CountryCode == 'us') || (response.value.CountryCode == 'ca'))
			{
				lblmakemodeltrim.innerHTML = response.value.ShortDescription;
			}
			else // long description - International 
			{
				lblmakemodeltrim.innerHTML = response.value.LongDescription;
			}
		}
					
		// Display vehicle image
		document.getElementById("res1_imgCar").setAttribute("src", response.value.ImageSmall);
		document.getElementById("res1_imgCar").setAttribute("alt", response.value.AltText);
		document.getElementById("res1_imgCar").style.display = 'block';

		if((response.value.ImagePassengerAdult != null) && (response.value.ImagePassengerAdult.length > 0))
		{
			//Display number of adult passengers graphic
			document.getElementById("res1_imgCarPassLarge").setAttribute("src",response.value.ImagePassengerAdult);
			document.getElementById("res1_imgCarPassLarge").style.display = '';
		}
		else
		{
			//Hide adult passengers graphic if no value returned
			document.getElementById("res1_imgCarPassLarge").style.display = 'none';
		}
		
		if((response.value.ImagePassengerChild != null) && (response.value.ImagePassengerChild.length > 0))
		{
			//DISPLAY NUMBER OF CHILD PASSENGERS GRAPHIC
			document.getElementById("res1_imgCarPassSmall").setAttribute("src",response.value.ImagePassengerChild);
			document.getElementById("res1_imgCarPassSmall").style.display = '';
		}
		else
		{
			//HIDE CHILD PASSENGERS GRAPHIC IF NO VALUE RETURNED
			document.getElementById("res1_imgCarPassSmall").style.display = 'none';
		}
		
		if((response.value.ImageLuggageLargeBags != null) && (response.value.ImageLuggageLargeBags.length > 0))
		{
			//Display number of large bags graphic
			document.getElementById("res1_imgCarLuggageLarge").setAttribute("src",response.value.ImageLuggageLargeBags);
			document.getElementById("res1_imgCarLuggageLarge").style.display = '';
		}
		else
		{
			//Hide number of large bags graphic if no value returned
			document.getElementById("res1_imgCarLuggageLarge").style.display = 'none';
		}
		
		if((response.value.ImageLuggageSmallBags != null) && (response.value.ImageLuggageSmallBags.length > 0))
		{
			//Display number of small bags graphic
			document.getElementById("res1_imgCarLuggageSmall").setAttribute("src",response.value.ImageLuggageSmallBags);
			document.getElementById("res1_imgCarLuggageSmall").style.display = '';
		}
		else
		{
			//Hide number of small bags graphic if no value returned
			document.getElementById("res1_imgCarLuggageSmall").style.display = 'none';
		}
		
		if((response.value.ImageFuelMileage != null) && (response.value.ImageFuelMileage.length > 0))
		{
			//DISPLAY FUEL-PER-GALLON GRAPHIC
			document.getElementById("res1_imgCarFuel").setAttribute("src",response.value.ImageFuelMileage);
			document.getElementById("res1_imgCarFuel").style.display = '';
		}
		else
		{
			//HIDE FUEL-PER-GALLON GRAPHIC IF NO VALUE RETURNED
			document.getElementById("res1_imgCarFuel").style.display = 'none';
		}
		//doMoreFeaturesLink( response.value.FleetStandardVehicle.FleetStandardVehicle);
	}
	catch(Exception)
	{
		DisplayNoDetails(true);
		
	}
}
