J(document).ready(
	function() 
	{
		//default value for captcha
		//J('#captcha').defaultvalue('Please enter text you see on left');
		
		fillCountriesSC();
		fillStates(226);
		J('#countries').change(	function() { 
									fillStates( J('#countries option[selected]').attr('value') ) 
								});
		
		fillSeries('series1');
		J('#series1').change( function() { 
									fillModels('models1', J('#series1 option[selected]').attr('value') ) 
								});
								
		fillSeries('series2');
		J('#series2').change( function() { 
									fillModels('models2', J('#series2 option[selected]').attr('value') ) 
								});
		
		J('#submit').click(
			function() 
			{
				J('#test_drive_form').ajaxSubmit(
				{
					success:  processResponse,
					dataType: 'json'
				});
				
				return false;
			}
		);
		
		J('#outside_uscan').click(
			function() 
			{
				if(J('#outside_uscan').attr('checked') == true)
				{
					fillCountries();
					J('#states').empty();
					J('#postal_req').empty();
					J('#state_req').empty();
				}
				else
				{
					fillCountriesSC();
					fillStates(226);
					J('#postal_req').append('*');
					J('#state_req').append('*');
				}
			}
		);
	}
)

function processResponse( response ) 
{ 
	if ( response.show_dealers ) 
	{
		window.location = '/site_forms/show_dealers/';
	}
	
	if ( response.success ) 
	{
		window.location = '/site_forms/form_thnks/testdrive';
	}
	else 
	{
		setErrors( response.errors );
	}
}
