	$(document).ready(function() {
		// 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);
			
			return false;
		});
		
		// blog pagination
		$('#blogpagination a').livequery('click', function() {
			var varMethod = "get";			
			var varUrl  = 'inc/functions/ajax_get_blog.php';
			var varParam = 'x=0&paramID=' + $(this).attr('id') + '&slid=' + $("#hiddentabid").attr("title") + '&blogtypeid=' + $("#hiddentabtype").attr("title");
			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('').slideUp("slow"); $(varAjaxWait).slideDown('slow',function(){ if(jQuery.browser.msie) this.style.removeAttribute('filter');});},
			complete: function(){ $(varAjaxWait).slideUp("slow");},
			error: function(){ $(varAjaxContent).html('error').slideDown('slow',function(){ if(jQuery.browser.msie) this.style.removeAttribute('filter');});},
			success: function(html){ $(varAjaxContent).html(html).slideDown('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="http://static.pooltoto.com/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="http://static.pooltoto.com/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="http://static.pooltoto.com/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="http://static.pooltoto.com/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
