   

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 if (waitMode == 4)
   {
	   	// do nothing
   }
   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, vm)
{
   elem = $(id);
   
   
   if (vm==2)
   {
   	elem.html('<img src="/css/ld2.gif" vspace="2" />');
   }
   else
	   elem.html('<div class="loading"></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, box)
{
	el =$('#recbox_'+calid);
	ajReplaceDiv(el, '?mode=recommend&post_id='+calid+'&box='+box, {}, 2 );
}




function comhere(elem, id)
{
	$('#comformpid').val(id);
	$('#comdiv').show();
	$(elem).append($('#comdiv'))
	$('#tcomment').focus()
	$('#bcomment').attr("disabled", false);
}



cres = null;
function addcom(div, type, id, replyTo)
{

	cres ='#addCommentDiv'+type+'_'+id
        $('#addCommentDiv'+type+'_'+id).slideToggle('fast', function(){$('#cmttxt_'+type+'_'+id).focus()});


}





function submComment(div, type, pid)
{
	ajUpdateDiv($(div), '?is_ajax=1&mode=comments', $('#addCommentForm'+type+'_'+pid).serialize(), 3);
}




function voteAns(id, dir)
{
	ajUpdateDiv('#vdiv'+id, '?is_ajax=1&mode=voteprop&id='+id+'&dir='+dir, {}, 1);
}

_fbinit= 0;
function fbinit()
{
	if (_fbinit<=0)
		 FB.init({ appId:'143011235772632', cookie:true, status:true, xfbml:true });
	_fbinit++
}

function fbcomment(comm, link)
{
	fbinit()
	url = window.location;
	FB.ui({ method: 'feed', message: comm, link:link});
}

function twcomment(comm, lnk)
{
	u = 'http://twitter.com/intent/tweet?url='+lnk+'&text='+encodeURIComponent(comm)
	w = window.open(u, "twwin", "menubar=no,toolbar=no,width=470,height=280")
}


function addthissend(comm, lnk)
{
	u = 'http://api.addthis.com/oexchange/0.8/offer?url='+encodeURIComponent(lnk)+'&title='+encodeURIComponent(comm)
	w = window.open(u, "adtwin", "menubar=no,scrolling=auto,toolbar=no,width=480,height=480")
}




