	$(document).ready(function() {
		// Tab add blog item
		$('#mysubleague_form_addblog').livequery('submit', function() { 
			
			// Check for emptiness
			if ($("#blogentry").val() == '') {
				$("#blogentry").focus();
				return false;
			}
			
			var varMethod = "post";
			var varUrl = 'inc/functions/ajax_save_blog.php';
			var varParam = $('#mysubleague_form_addblog').serialize();
			var varContent = "#ajax_blog_form";
			var varWait = "#blogloading";
			AjaxMainHandler(varMethod, varUrl, varParam, varContent, varWait);
			
			var varUrl  = 'inc/functions/ajax_get_blog.php';	
		  var varMethod = "get";
		  var varContent = "#tabcontent";
			var varWait = "#tabloading";
			
			AjaxMainHandler(varMethod, varUrl, varParam, varContent, varWait);				
			
			return false;
		}); 
	});
	
	function AjaxMainHandler(varRequestMethod, varPostTo, frmParams, varAjaxContent, varAjaxWait) {

		$.ajax({
			method: varRequestMethod, url: varPostTo, data: frmParams,   
			beforeSend: function(){$(varAjaxContent).html('').hide("slow"); $(varAjaxWait).show('slow',function(){ if(jQuery.browser.msie) this.style.removeAttribute('filter');});},
			complete: function(){ $(varAjaxWait).hide("slow");},
			error: function(){ $(varAjaxContent).html('error').show('slow',function(){ if(jQuery.browser.msie) this.style.removeAttribute('filter');});},
			success: function(html){ $(varAjaxContent).html(html).show('slow',function(){ if(jQuery.browser.msie) this.style.removeAttribute('filter');}); }   
		});

		return false;			
	}
	
	function CheckInput(varPostTo, frmParams, varAjaxContent, varAjaxWait) {
	
		$(varAjaxWait).removeClass().addClass('ajaxok').html('<img src="img/loading_red_small.gif" width="15" height="15"> Checking...').fadeIn("fast");
		$.post(varPostTo,{ data: frmParams 
		} 
		,function(data) {
	  	if(data=='no') {
	  		$(varAjaxWait).fadeTo(200,0.1,
	  			function() {
		  			$(this).removeClass().addClass('ajaxerror').html('<img class="iconpng" src="img/icons/cross.png" width="15" height="15"> Incorrect e-mail address.').fadeTo(900,1,
			  			function(){ 
			  				if(jQuery.browser.msie) this.style.removeAttribute('filter');
			  			});	
		  			$(varAjaxContent).val('');
		  			$(varAjaxContent).focus();
					});		
			} else if(data=='yes') {
				$(varAjaxWait).fadeTo(200,0.1,
					function() {
		  			$(this).removeClass().addClass('ajaxok').html('<img class="iconpng" src="img/icons/accept.png" width="15" height="15"> OK.').fadeTo(900,1,
			  			function(){ 
			  				if(jQuery.browser.msie) this.style.removeAttribute('filter');
			  			});	
					});
			} else {
				$(varAjaxWait).fadeTo(200,0.1,
	  			function() {
		  			$(this).removeClass().addClass('ajaxerror').html('<img class="iconpng" src="img/icons/cross.png" width="15" height="15"> An error occured.').fadeTo(900,1,
			  			function(){ 
			  				if(jQuery.browser.msie) this.style.removeAttribute('filter');
			  			});	
		  			$(varAjaxContent).val('');
		  			$(varAjaxContent).focus();
					});	
	  	}
		});

		} // end function

