$(document).ready(function(){
	$('table.table.rows tr').each(function(n,v){
		$(v).removeClass('tr'+(n%2?2:1)).addClass('tr'+(n%2?1:2));
	});
	
	$('#service select:first').html($('#service select:first').html());
	
	$('#service select:first').change(function(){
		
		$('#submit').hide();
		$('#result').slideUp();
		$.ajax({
			data: {id:$(this).val()},
		    url: '/calculate_service/engine/',
		    dataType: "html",
		    type: 'POST',
		    success: function (data) {
		        $('#service #engine').html(data);
		        
		        $('#service #engine select:first').change(function(){
		        
		        	$('#result').slideUp();
		        	
		        	if ($(this).val()>0) 
		        		$('#submit').show(); 
		        	else 
		        		$('#submit').hide(); 
		        	
		        });
		    }
		});
	});
	
	$('#service_form').submit(function(){
		
		
		$.ajax({
			data: $(this).serializeArray(),
		    url: '/calculate_service/result/',
		    dataType: "html",
		    type: 'POST',
		    success: function (data) {
		    	res = $('#result');
		    	res.hide();
		        res.html(data);
		        res.slideDown();
		        
				$('#result table tr').each(function(n,v){
					if (n%2) $(v).toggleClass('white');
				});
		    }
		});
	
		return false;
		
	});
	
	
});
