function sxCallback(data){
	if(data.sessionsx==''){
		$('#init_auth').hide();
		$('#form_auth').show();
		return false;
	}else{
		parent.location = SITE_URL + 'auth/post_login/?sessionsx=' + data.sessionsx;
	}
}

jQuery(document).ready(function($) {
	$(".day_listing a").tooltip({ 
			effect: "slide",
			onShow: function() {
					var time = this.getTrigger().attr("rel");
					$tip = this.getTip();
					$.ajax({
						url:SITE_URL+"calendar/ajax.html?time="+time,
						success: function(response) {
							$tip.html(response);
						}
					});
			}
	});
	
	$(".confirm").click(function (e) {
		e.preventDefault();
		if (confirm('Apakah Anda yakin ingin menghapus data ini?')) {
			window.location = jQuery(this).attr("href");
		}
	});
	
	$('.login').click(function() {
		var attr='';
		var title='';
		if($(this).attr('login_attibute'))
		{
			attr = $(this).attr('login_attibute');
		}
		else
		{
			attr = '#TB_inline?height=330&width=400&inlineId=loginbox&modal=true';
		}

		if($(this).attr('title'))
		{
			title = $(this).attr('title');
		}
		if(IS_AUTH)
		{
			$('#init_auth').show();
			$('#form_auth').hide();
			dotb(title,attr);
			$.getJSON(AUTH_PARAMS + "&jsoncallback=?", 	
				function(data) {
						var d = eval(data);
						if(d.sessionsx==''){
							$('#init_auth').hide();
							$('#form_auth').show();
							return false;
						}else{
							parent.location = SITE_URL + 'auth/post_login/?sessionsx=' + d.sessionsx;
						}
					}
			);
		}
		else
		{
			dotb(title,attr);
		}
		return false;
	});

	$(".wrap_img").hover(function() {
		$(this).children("img").fadeTo(200, 0.25)
			   .end().children(".hover").show();
	}, function() {
		$(this).children("img").fadeTo(200, 1)
			   .end().children(".hover").hide();
	});


	$(".closable").append('<a href="#" class="close">close</a>');

	// Close the notifications when the close link is clicked
	$("a.close").live('click', function () {
		$(this).fadeTo(200, 0); // This is a hack so that the close link fades out in IE
		$(this).parent().fadeTo(200, 0);
		$(this).parent().slideUp(400);
		return false;
	});

	// Fade in the notifications
	$(".warning").fadeIn("slow");

	$('#column-mood .mood-item').mouseover(function() {
		$(this).children('div.mood-l').addClass('mood-lhover');
	}).mouseout(function() {
		$(this).children('div.mood-l').removeClass('mood-lhover');
	});

	$(".show_tags_del").live('click', function () {
			$(this).parent().find('.tags').toggle();
		});

	// Check all checkboxes in table
	$(".check-all").live('click', function () {
		$(this).parents("table").find("tbody input[type='checkbox']").each(function () {
			if($(".check-all").is(":checked") && !$(this).is(':checked'))
			{
				$(this).click();
			}
			else if(!$(".check-all").is(":checked") && $(this).is(':checked'))
			{
				$(this).click();
			}
		});
	});
});
function limitChars(textarea, limit, infodiv)
{
	var text = textarea.value;
	var textlength = text.length;
	var info = document.getElementById(infodiv);

	if(textlength > limit)
	{
		info.innerHTML = 'You cannot write more then '+limit+' characters!';
		textarea.value = text.substr(0,limit);
		return false;
	}
	else
	{
		info.innerHTML = (limit - textlength);
		return true;
	}
}
