// Functon to Show out Busy Div
function showBusy(){
	$('#busy').show('slow');
}



// function to process form response
function processForm(html){
		$('#errors').hide('slow');
		window.setTimeout( function(){
			$('#busy').hide('slow');
			if(parseFloat(html)){
		 		$('#success_message').show('slow');
		 		$('#supplier_contact').hide('slow');
			}else{
		 		alert(html);
		 	}
		 	
		 }, 3000);
}

function processFeedback(html){
		$('#errors').hide('slow');
		window.setTimeout( function(){
			$('#busy').hide('slow');
			if(parseFloat(html)){
		 		$('#fb_success_message').show('slow');
		 		$('#supplier_feedback').hide('slow');
				
			}else{
		 		alert(html);
		 	}
		 	
		 }, 3000);
}


$(document).ready(function() {

	// $.AJAX Example Request
	$('#supplier_contact').submit(function(eve){
		eve.preventDefault();
		
		$.ajax({
			url: "/ajax/ask_question.php",
			type: "POST",
			dataType: "html",
			data: $('#supplier_contact').serialize(),
			beforeSend: function(){
				showBusy();
			},	
		  	success: function(html) {
		    	processForm(html);
		 	}
		});

	});	
	
		$('#supplier_feedback').submit(function(eve){
		eve.preventDefault();
		
		$.ajax({
			url: "/ajax/suppliers/supplier_feedback",
			type: "POST",
			dataType: "html",
			data: $('#supplier_feedback').serialize(),
			beforeSend: function(){
				showBusy();
			},	
		  	success: function(html) {
		    	processFeedback(html);
		 	}
		});

	});	
});


