function filter_new_bike_menu(that)
{	
	jQuery(that).toggleClass('selected');
	
	var types = [];
	jQuery('#filter-types a.selected').each(function() 
	{
		types.push(jQuery(this).attr('id').replace('filter-', ''));
	});

	if(types.length > 0)
	{
		var data = {
			action: 'get_brands_by_bike_type',
			bike_types: types
		};
		
		jQuery.post(ajaxurl, data, function(response)
		{
			jQuery('.menu-brand').each(function()
			{
				var thisName = jQuery(this).attr('id');
				
				var found = false;
				for(i in response)
				{
					var itm = response[i];
					if(itm == thisName)
					{
						found = true;
						break;
					}
				}
				
				if(found)
				{
					jQuery(this).fadeTo('fast', 1);
				}
				else
				{
					jQuery(this).fadeTo('fast', 0.3);
				}
			});
			
		}, 'json');
	}
	else
	{
		jQuery('.menu-brand').each(function()
		{
			jQuery(this).fadeTo('fast', 1);
		});
	}
}

// prepare the form when the DOM is ready 
jQuery(document).ready(function() 
{ 	
    var options = { 
        success:    usedBikeResponse,  // post-submit callback 
 		url:       	ajaxurl,           // override for form's 'action' attribute 
        dataType:  'json'        // 'xml', 'script', or 'json' (expected server response type) 
    }; 
 
    // the used bike menu form
    jQuery('#frmUsedBikeFilter').submit(function() 
    { 
        // inside event callbacks 'this' is the DOM element so we first 
        // wrap it in a jQuery object and then invoke ajaxSubmit 
        jQuery(this).ajaxSubmit(options); 
 
        // return false to prevent standard browser submit
        return false; 
    });
    
    // the 'change your search form
    jQuery('#frmSearchUsedBikes').submit(function() 
    { 
        // inside event callbacks 'this' is the DOM element so we first 
        // wrap it in a jQuery object and then invoke ajaxSubmit 
        jQuery(this).ajaxSubmit(options); 
 
        // return false to prevent standard browser submit
        return false; 
    });
    
    // the 'change your search form
    jQuery('#frmEnquire').submit(function() 
    { 
        // inside event callbacks 'this' is the DOM element so we first 
        // wrap it in a jQuery object and then invoke ajaxSubmit 
        jQuery(this).ajaxSubmit(options); 
        
        // return false to prevent standard browser submit
    	return false; 
    });
    

});

// post-submit callback 
function usedBikeResponse(response)  
{ 
   if(response.status == 'success')
   {
   		if(response.text.indexOf("http://") == -1)
   		{
   			alert(response.text);
   			jQuery('.enquiry_form').each(function() 
   			{
   				if(jQuery(this).attr('type') != 'submit')
   				{
   					jQuery(this).val('');
   				}
   			});
   		}
   		else
   		{
   			window.location.href = response.text.replace('-1', '');
   		}
   }
   else
   {
   		alert(response.text);
   }
}
