/* ---------------------------------------------------- */
/* JQuery												*/
/* ---------------------------------------------------- */
$jQuery(document).ready(function() 
{

	$jQuery('#rental_header').hide();

	/* Set the global Ajax defaults */
	$jQuery.ajaxSetup( {
	   timeout: 0,
	   global: true,
	   type: "POST"
 	});

	
	/* Runs when the rental period drop-down is changed */
	$jQuery("select.form_element2").change(function()
	{
		var model = $jQuery("#rental_vehicle").val();
		var period = $jQuery("#rental_period").val();
		
		if ( model != 0 && period != "" )
		{
			/* Run the AJAX Request */
			$jQuery.ajax({
				url: 'index.php?action=ajax.getRentalAmounts', 
				type: 'POST', 
				dataType: 'xml', 
				data: "model=" + model + "&period=" + period,
				
				success: function( xml ){

					/* Define the basic function vars */
					var output = "";
					var rate = "#";
					var excess = "#";
										
					/* Loop through the return result and populate the form values */
					$jQuery("/root/display", xml ).each(function(){
						/* Define the page values to use */
						var rate_amount = $jQuery("rate", this).text();
						var excess_amount = $jQuery("excess", this).text();		
						/* append the current options to the options var */
						rate_display = rate_amount;
						excess_display = excess_amount;
					});
					
					/* show the div */
					$jQuery("#messages").hide();
					$jQuery('#rental_header').show('100');
					/* Lets now populate the select box */
					$jQuery("#rental_rate").html( '&pound;' + rate_display );
					$jQuery("#rental_excess").html( '&pound;' + excess_display );
				}
			});
		}
		else
		{
			$jQuery('#rental_header').hide();
			$jQuery("#messages").show('100');
			$jQuery("#messages").html( '<strong>Please ensure you select both a vehicle and a rental period.</strong>' );
			$jQuery("#rental_excess").html( '' );
			return false;
		}
		
		return false;
	 
	});
	
});
