J(document).ready(
	
	function() {
		J('#thanks').hide();
		//fillCountries();
		fillCountriesSC();
		fillStates('226');
		J('#countries').change( function() { fillStates( J('#countries option[selected]').attr('value') ) });
		
		J('#phone-1').autotab({ target: 'phone-2', format: 'numeric' });
		J('#phone-2').autotab({ target: 'phone-3', format: 'numeric', previous: 'phone-1' });
		J('#phone-3').autotab({ previous: 'phone-2', format: 'numeric' });
		
		J('#submit-button').click(
			function() {
				J('#contact-us-form').ajaxSubmit({
					success:  processResponse,
					dataType: 'json'
				});
				
				return false;
			}
		);
		
		J('#reset-button').click(
			function() {
				J('.error').html('');
			}
		) 
		
		J('#outside-uscan').click(
			function() {
				if ( J('#outside-uscan').attr('checked') == true ) {
					fillCountries();
					J('#states').empty();
					J('#state-label').html('State/Province:');
					J('#postal-label').html('Postal Code:');
				} else {
					fillCountriesSC();
					fillStates('226');
					J('#state-label').html('* State/Province:');
					J('#postal-label').html('* Postal Code:');
				}
			}
		)
		
	}
	
)

function processResponse( response ) { 
	if ( response.success ) {
		J('#form_contact_us').hide();
		J('#contact-us-text').hide();
		J('#thanks').show();
	} else {
		setErrors( response.errors );
		//alert(response);
	}
}

