jQuery.extend({
	/**
	 * Intercepts downloads to show capture form
	 */

	capture : function(object) {
		
		$.get('/trial/quick_quote_form.php',function(data){
			
			var captureForm = data;
			var clickedLink = object;
		
			var config = {
				'title'			:	"",
				'content'		:	captureForm,
				'closeable'		:	false,
				'height'		:	548,
				'onLoad'		:	function() {
					setupTooltips();	
				}
			};
			
			$.popup(config, [{
				'label'			:	'Quote Me!',
				'action'		:	function() {
				
					var formData = $('form[name=quick_quote_form]').serialize();
					
					$.post("/trial/quick_quote_validate.php", formData, function(data){
						// Remove any errors
						$('.form_row').removeClass('invalid_row');
						$('form[name=quick_quote_form]').find('p.error').remove();
						
						if(data.status == "error") {
	
							$.each(data.errors, function(key){
								$('form[name=quick_quote_form] input[name=' + key + ']').parents('.form_row').addClass('invalid_row');
							});
	
							$('form[name=quick_quote_form]').prepend(data.feedback);
						
						}else{

							window.location = "/quote?token=" + data.quote_token;
						
						}
						
					}, "json");
					
				},
				'closePopup'	:	false	
				},
				{'label'		:	'Cancel',
				'buttonClass'	:	'cancel_form'}]
			);														   
		
		
		});


		return false;					
		
	}
});
