   

function ajUpdateDiv(id, url, params, waitMode, func)
{

   elem = $(id);
   if (waitMode == 1)
   {
		var w = elem.width();
		var h = elem.height();
		elem.html('<div id="xx_load" style=\"width:'+w+'px;height:'+h+'px\"></div>');
   }
   else if (waitMode == 3)
   {
	 	elem.append('<img src="/css/loading3.gif" />');
   }
   else
   {
		el = $('<div id="xx_load" style="padding:8px;display:none" align="center"><img src="/css/loading2.gif" /></div>')
		elem.prepend(el)
		el.show('blind')
		
   }
 
   $.post(url, params, 
		function(data, status)
		{
			if (status == 'success')
			{
				if (func && func != null)
					func(data)

				elem.hide().html(data).show();

			}
			else
			{
				elem.html("<div class=\"warning\">An error occured! Please try again</a>");
			}
			
			
		}
	);
	
 }

 
 
function ajReplaceDiv(id, url, params)
{
   elem = $(id);
   
   elem.html('<div class="loading"><img src="/css/loading3.gif" /></div>');
   $.post(url, params, 
		function(data, status)
		{
			if (status == 'success')
			{
				elem.replaceWith(data);
			}
			else
			{
				elem.html("<div class=\"warning\">An error occured! Please try again</a>");
			}
		}
	);
	
 }

 

function  setuplinks()
{
		/*
		$('.calbookmark').click(
				function(event) 
				{
					var calid = ($(event.target).attr('calid'));
					ajUpdateDiv(this, '?mode=bookmark&calid='+calid, {}, 1);
				}
			);
			
			
			$('.calrecommend').click(
				function(event) 
				{
					var calid = ($(event.target).attr('calid'));
					ajUpdateDiv(this, '?mode=recommend&calid='+calid, {}, 1);
				}
			);
			*/
		
		$("div.cal-item").hover( 
			function() 	{$(this).find("div.opers").css('visibility', 'visible'); } 
			, function() {$(this).find("div.opers").css('visibility', 'hidden'); } 
			); 
		
}


function upd_bookmark(w,calid)
{
	ajUpdateDiv($(w).parent(), '?mode=bookmark&calid='+calid, {}, 3);
}



function upd_recommend(w,calid)
{
	el =$('#recbox_'+calid);
	ajReplaceDiv(el, '?mode=recommend&post_id='+calid, {}, 0);
}




function comhere(elem, id)
{
	$('#comformpid').val(id);
	$('#comdiv').show();
	$(elem).append($('#comdiv'))
	$('#tcomment').focus()
	$('#bcomment').attr("disabled", false);
}

function sendCom(el)
{
	el2 = $('#comdiv').parent();
	$('#bcomment').attr("disabled", true);
	ajUpdateDiv(el2, '?mode=comments', $('#comform').serialize(), 3, function() { 
		$('#tcomment').val('')
		$('#comdiv').hide()
		$('#cpare').append($('#comdiv'));
	});
}

function showAllCom(el, pid)
{
	//$('#bcomment').attr("disabled", true);
	ajUpdateDiv(el, '?mode=comments&all=1&pid='+pid,{}, 3, function() { 
		$('#tcomment').val('')
		$('#comdiv').hide()
		$('#cpare').append($('#comdiv')); 
	});
}

function postHere() 
{ 
	$('#cpare').append($('#comdiv'));
	$('#bpost').attr("disabled", true);
	ajUpdateDiv('#pres', '?mode=channel&id=<?=$channel[id]?>', $('#pform').serialize(), 5, function() { 
		$('#ptext').val('')
		$('#bpost').attr("disabled", false);
		});
	
}


