// JavaScript Document
var objectId;
var ownerIdId;
var vehicleIdId;
var vehicleStateId;
var vehicleCountyId;
var vehicleCityId;

var anyArray = new Array()
anyArray[0] = 'Any';
var contentArray = new Array()

var progressBarHeader1 = ''
var progressBarHeader2 = ''

	
	function getVehicleByLocationDir()
	{		
			locationDir = '<%= request.getParameter("locationDir")  %>'
			
			if( locationDir != 'headquarters' && locationDir != 'null' && locationDir != '' )
			{
				VehicleService.getVehicleByLocationDir(locationDir, addContent);
			}		
				
	}

	function getAccountVehicleLocations()
	{		
			VehicleService.getAccountVehicleLocationsBy('state',			
			function(data)
			{	
				dwr.util.addOptions('vehicleStateId', data)
			});
	}

	function getAccountVehicleState()
	{
			dwr.util.removeAllOptions('vehiclesAvailableId' )
			
			vehicleStateId = dwr.util.getValue('vehicleStateId')
			vehicleCountyId = dwr.util.getValue('vehicleCountyId')
			vehicleCityId = dwr.util.getValue('vehicleCityId')

			VehicleService.getAccountVehicleLocationCountiesByState(vehicleStateId,
			function(data)
			{	
				dwr.util.removeAllOptions('vehicleCountyId' )
				dwr.util.addOptions('vehicleCountyId', data, 'vehicleLocation' )	
			}
		
		);		
				
	}

	function getVehicleCountyLocationsByState()
	{			
			dwr.util.removeAllOptions('vehicleCountyId' )
			dwr.util.removeAllOptions('vehicleCityId' )
			dwr.util.removeAllOptions('vehiclesAvailableId' )
						
			vehicleStateId = dwr.util.getValue('vehicleStateId')
			vehicleCountyId = dwr.util.getValue('vehicleCountyId')
		
			VehicleService.getVehicleCountyLocationsByState(vehicleStateId, 
			function(data)
			{	
				progressBarHeader1 = 'The Instant RV Rental SearchBot has been activated.'
				progressBarHeader2 = 'Please select a County to continue.'

				dwr.util.removeAllOptions('vehicleCountyId' )
				//dwr.util.addOptions('vehicleCountyId', anyArray )
				dwr.util.addOptions('vehicleCountyId', data )
				
				VehicleService.getVehicleByStateCounty(vehicleStateId,vehicleCountyId, addContent)	
			}
		
		);		
				
	}	

	function getVehicleCityLocationsByStateCounty()
	{
			dwr.util.removeAllOptions('vehicleCityId' )
			dwr.util.removeAllOptions('vehiclesAvailableId' )		
		
			vehicleStateId = dwr.util.getValue('vehicleStateId')
			vehicleCountyId = dwr.util.getValue('vehicleCountyId')
			vehicleCountyText = dwr.util.getText('vehicleCountyId')
			vehicleCityId = dwr.util.getValue('vehicleCityId')	

			VehicleService.getVehicleCityLocationsByStateCounty(vehicleStateId, vehicleCountyId, 
			function(data)
			{
				if( data == 'None' )
				{
					progressBarHeader1 = 'No Vehicles Found in ' + vehicleCountyText 
					progressBarHeader2 = '...please select another County to continue.'				
				}
				else
				{
					dwr.util.removeAllOptions('vehicleCityId' )
					dwr.util.addOptions('vehicleCityId', anyArray )
					dwr.util.addOptions('vehicleCityId', data )
					
					document.getElementById('vehicleCityId').options[0].selected = true;				
				}
								
				VehicleService.getVehicleByStateCounty(vehicleStateId,vehicleCountyId, addContent)
	
			}
		
		);					
	}

	function refineSearch() 
	{
			var txtDate1 = document.ReservationCalendar.date1.value 
			var txtDate2 = document.ReservationCalendar.date2.value 

			vehicleState = dwr.util.getValue('vehicleStateId')
			vehicleCounty = dwr.util.getValue('vehicleCountyId')
			vehicleCity = dwr.util.getValue('vehicleCityId')
	
			sleeps = dwr.util.getValue('sleepsId')
			seatBelts = dwr.util.getValue('seatBeltsId')
			petsAllowed = dwr.util.getValue('petsAllowedId')
			smokingAllowed = dwr.util.getValue('smokingAllowedId')
			
			VehicleService.locateAvailableVehicleByCriteria(vehicleState, vehicleCounty, vehicleCity, sleeps, seatBelts, petsAllowed, smokingAllowed, txtDate1, txtDate2, addContent );
			
	}

	function addContent(data) 
	{
		
		vehiclesAvailableInfo = new Array()
		dwr.util.removeAllOptions('vehiclesAvailableId' )		
		
		content = "";
		contentArray = new Array()
		contentArray = data;		
		
		if( contentArray.length != 0 )
		{
		
			for(i=0; i < contentArray.length; i++)
			{
	
				  if( contentArray[i].advertisingNetwork == '0' ) //No Image - Free Account
				  {
							content = content + 
							'<div align="center"><h1>' + contentArray[i].year + ' ' + contentArray[i].model + ' by ' + contentArray[i].make + '</h1></div>' +
							//'<img src="rv_rental_locations/rv_rental_vehicles/' + contentArray[i].vehicleId + '/' + contentArray[i].vehicleMainImage + '" border="0" style="float:left;" alt"RV Rental: " + contentArray[i].getModel "" >' + 
							'<p align="center">' + contentArray[i].vehicleListingDescription + '</b> <strong>Contact:</strong> ' + contentArray[i].ownerBean.email + '</strong></p>' +
							'<br><img src="images/spacer.gif" alt="" width="1" height="9" /><br><br><br>'
				  }
				  else if( contentArray[i].advertisingNetwork == 'NA' )//Image - Free Account
				  {
							content = content + 
							'<div align="center"><h1>' + contentArray[i].year + ' ' + contentArray[i].model + ' by ' + contentArray[i].make + '</h1></div>' +
							'<div align="center"><img src="rv_rental_locations/rv_rental_vehicles/' + contentArray[i].vehicleId + '/' + contentArray[i].vehicleMainImage + '" border="0" style="float:left;" alt"RV Rental: " + contentArray[i].getModel "" ></div>' + 
							'<p align="center">' + contentArray[i].vehicleListingDescription + '</b> <strong>Contact:</strong> ' + contentArray[i].ownerBean.email + '</strong></p>' +
							'<br><img src="images/spacer.gif" alt="" width="1" height="9" /><br><br><br>'
				  }
				  else if( contentArray[i].advertisingNetwork == '1' | contentArray[i].advertisingNetwork == '2' | contentArray[i].advertisingNetwork == '3' ) //No different from 4 as of het
				  {		
							content = content + 
							'<div align="center"><h1><a href="rv_rental_locations/rv_rental_vehicles/' + contentArray[i].vehicleId + '.jsp" title="RV Rental">' + contentArray[i].year + ' ' + contentArray[i].model + ' by ' + contentArray[i].make + '</a></h1></div>' +
							'<a href="rv_rental_locations/rv_rental_vehicles/' + contentArray[i].vehicleId + '.jsp" title="RV Rental">' +
							'<div align="center"><img src="rv_rental_locations/rv_rental_vehicles/' + contentArray[i].vehicleId + '/' + contentArray[i].vehicleMainImage + '" border="0" style="float:left;" alt"RV Rental: " + contentArray[i].getModel "" ></a></div>' + 
							'<p align="center">' + contentArray[i].vehicleListingDescription + '</b> <a href="rv_rental_locations/rv_rental_vehicles/' + contentArray[i].vehicleId + '.jsp" title="RV Rental"> Get details... </a></p>' +
							'<br><img src="images/spacer.gif" alt="" width="1" height="9" /><br><br><br>'
				  }
				  else
				  {		
							content = content + 
							'<div align="center"><h1><a href="rv_rental_locations/rv_rental_vehicles/' + contentArray[i].vehicleId + '.jsp" title="RV Rental">' + contentArray[i].year + ' ' + contentArray[i].model + ' by ' + contentArray[i].make + '</a></h1></div>' +
							'<a href="rv_rental_locations/rv_rental_vehicles/' + contentArray[i].vehicleId + '.jsp" title="RV Rental">' +
							'<div align="center"><img src="rv_rental_locations/rv_rental_vehicles/' + contentArray[i].vehicleId + '/' + contentArray[i].vehicleMainImage + '" border="0" style="float:left;" alt"RV Rental: " + contentArray[i].getModel "" ></a></div>' + 
							'<p align="center">' + contentArray[i].vehicleListingDescription + '</b> <a href="rv_rental_locations/rv_rental_vehicles/' + contentArray[i].vehicleId + '.jsp" title="RV Rental"> Get details... </a></p>' +
							'<br><img src="images/spacer.gif" alt="" width="1" height="9" /><br><br><br>'
				   }
	
			
					vehiclesAvailableInfo[i] = "" + contentArray[i].year + " " + contentArray[i].style + " Sleeps " + contentArray[i].vehicleDetailsBean.sleeps + ""
			
			}
		}
		else
		{
							content = content + 
							'<div align="center">' +
							'<br><br><strong>' +  progressBarHeader1 + '</strong><br>' +
							'<br><img src="images/imgSearchBot.jpg"/><br>' +
							'<strong><em>"' + progressBarHeader2 + '"</em></strong></div>'		
		}
		
		
		document.getElementById('vehicleResults').innerHTML = content;
		dwr.util.addOptions('vehiclesAvailableId', vehiclesAvailableInfo)
		 
	}


	function resetCheckBox()
	{
		document.ReservationCalendar.reset();
	}

	function validate()
	{		
		currentDate = new Date();
		currentDate.setDate(currentDate.getDate()+2)
		
		requestedDate = new Date(document.ReservationCalendar.date1.value);
		
		if(requestedDate < currentDate)
		{
			alert("Reservations are only available after Pick-up Date" )
			return false;
		}
		else
		document.ReservationCalendar.submit();
	}

function validate_required(field,alerttxt)
{

		currentDate = new Date();
		currentDate.setDate(currentDate.getDate()+2)
		
			requestedDate = new Date(document.ReservationCalendar.date1.value);
		
			if(requestedDate < currentDate)
			{
				alert("That date is not valid: " + requestedDate)
				return false;
			}
			else
			{
				return true;
			}

}

function validate_form(thisform)
{
	with (thisform)
	{
		if ( validate_required(date1,"Email must be filled out!") == false )
		{
			date1.focus();
			return false
		}
	}
}

