
// Functon to Show out Busy Div
function showBusy(){
	$('#busy').show('slow');
}

function processContactForm(html){

		$('#errors').hide('slow');
		
		window.setTimeout( function(){
		 	
			$('#busy').hide('slow');
			
			if(parseFloat(html)){
    		 		$('#successMSG').fadeIn('slow');
    		 		$('#contactForm').fadeOut('slow');
    	}else{
    		 		$('#errors').html(html).show('slow');
    	}
		 	
		 }, 2000);
	
}

function processMemContactForm(html){

		$('#errors').hide('slow');
		
		window.setTimeout( function(){
		 	
			$('#busy').hide('slow');
			
			if(parseFloat(html)){
    		 		$('#successMSG').fadeIn('slow');
    		 		$('#contactMemFormContainer').fadeOut('slow');
    	}else{
    		 		$('#errors').html(html).show('slow');
    	}
		 	
		 }, 2000);
	
}

function processUpgradeForm(html){

		$('#upgradeFormContainer').fadeOut();
		
		
		window.setTimeout( function(){
		 	
			$('#upgradeFormContainer').html(html);
			$('#busy').hide('slow');
	 		$('#upgradeFormContainer').fadeIn('slow');
		 }, 1000);
	
}
function processProfileUpdateForm(html){

		$('#profileUpdateContainer').fadeOut();
		
		
		window.setTimeout( function(){
		 	
			$('#profileUpdateContainer').html(html);
			$('#busy').hide('slow');
	 		$('#profileUpdateContainer').fadeIn('slow');
		 }, 1000);
	
}




$(document).ready(function() {
	
	$("a[rel=images]").fancybox();
	
	
	
//Lower Banner Rotator
    $('#adverts').cycle({
		fx: 'fade',
		timeout: 10000,
		cleartype: true,
		cleartypeNoBg: true 
	  	});
	
		
//Contact Form Submit
	

	$('#contactForm').submit(function(eve){
		eve.preventDefault();
		
		$.ajax({
			url: "/contact/send/",
			type: "POST",
			dataType: "html",
			data: $('#contactForm').serialize(),
			beforeSend: function(){
				showBusy();
			},	
		  	success: function(html) {
		    	processContactForm(html);
		 	}
		});

	});	
//Contact Member
	$('#contactMemForm').submit(function(eve){
		eve.preventDefault();
		
		$.ajax({
			url: "/admin/send_email",
			type: "POST",
			dataType: "html",
			data: $('#contactMemForm').serialize(),
			beforeSend: function(){
				showBusy();
			},	
		  	success: function(html) {
		    	processMemContactForm(html);
		 	}
		});

	});
	

//Membership Renewal	

	$('#upgradeForm').submit(function(eve){
		eve.preventDefault();
		
		$.ajax({
			url: "/members/subscription_upgrade/",
			type: "POST",
			dataType: "html",
			data: $('#upgradeForm').serialize(),
			beforeSend: function(){
				showBusy();
			},	
		  	success: function(html) {
		    	processUpgradeForm(html);
		 	}
		});

	});
	
//Profile Update	

	$('#profileUpdate').submit(function(eve){
		eve.preventDefault();
		
		$.ajax({
			url: "/members/update_profile/",
			type: "POST",
			dataType: "html",
			data: $('#profileUpdate').serialize(),
			beforeSend: function(){
				showBusy();
			},	
		  	success: function(html) {
		    	processProfileUpdateForm(html);
		 	}
		});

	});

		

});



	
	


