function addToFav(o){
	var link = o;
	$.post(link.attr('href'), {ajax: 'update'}, function(resp) {
		if(resp.status=='success') {
			var r = new RegExp(/a=(add|remove)/);
			var match = r.exec(link.attr('href'));
			var new_link = '', label = '';
	
			if(match[1] == 'add') {
				new_link = link.attr('href').replace(/a=add/, 'a=remove');
				label = 'Remove from favorites';
			}
			else if(match[1] == 'remove') {
				//Handle the case wehre we're on the favorites page
				if(typeof(fav_page) != 'undefined' && fav_page) {
					//Wanted to just remove the block originally, but it interferes with the paging.
					//link.closest("div.sort-result").remove();
					location.reload();
					return;
				} else {
					new_link = link.attr('href').replace(/a=remove/, 'a=add');
					label = 'Add to favorites';
				}
			}
			link.attr('href', new_link);
			link.find('span').html(label);
		} else if(resp.status == 'fail') {
			if(resp.error == 'login') {
				openLoginBox(link.attr('href'));
			}
		}
	}, "json");
	return false;	
}
