function CheckorNo(str)
{
str = 'chk_'+str
var Mychechbox = document.getElementById(str)
Mychechbox.checked = !Mychechbox.checked;
}

function GetCheckedboxes()
{
		var view_coche;
		var view_ob_t2in,view_ob_t2s;
		view_ob_t2in=document.getElementsByTagName("input");
		str_users='';
		aumoinyenaun = 0;
		for (var i=0; i<view_ob_t2in.length; i++) 
		{
			view_ob_t2s=view_ob_t2in[i].id;
			if ((view_ob_t2s.substr(0,4)=='chk_'))
			{
				if(document.getElementById(view_ob_t2s).checked)
				{
					v = 1;
					aumoinyenaun = 1;
				}
				else
					v=0
				if(v==1)
					str_users = str_users + document.getElementById(view_ob_t2s).id.substr(4)+',';
			}
		}
		if(aumoinyenaun != 0)
		{
			str_users = str_users.substr(0,(str_users.length - 1));
			//alert(str_users);
			return str_users;
			//ShowWorks(str_users);

		}
		else
		{
			str_users = '1,2,3,4';
			//alert(str_users);
			return str_users;
			//ShowWorks(str_users);
		}


}

$(document).ready(function(){
		//References
		var sections = $("#menu div");
		var loading = $("#loading");
		var content = $("#content");
	
		//Manage click events
		sections.click(function(){
		str = 'chk_'+this.id
		var Mychechbox = document.getElementById(str)
		Mychechbox.checked = !Mychechbox.checked;							
							
		//show the loading bar
		showLoading();

		//CheckorNo(this.id);
		str_users = GetCheckedboxes();
		//load selected section
		switch(this.id){
			case "1":
				content.slideUp();
				content.load("external.php?q="+str_users, hideLoading);
				content.slideDown();
				break;
			case "2":
				content.slideUp();
				content.load("external.php?q="+str_users, hideLoading);
				content.slideDown();
				break;
			case "3":
				content.slideUp();
				content.load("external.php?q="+str_users, hideLoading);
				content.slideDown();
				break;
			case "4":
				content.slideUp();
				content.load("external.php?q="+str_users, hideLoading);
				content.slideDown();
				break;
			default:
				//hide loading bar if there is no selected section
				hideLoading();
				break;
		}
	});

	//show loading bar
	function showLoading(){
		/*.css({visibility:"visible"})*/
		loading
			.css({visibility:"hidden"})
			.css({opacity:"0.5"})
			.css({display:"block"})
		;
	}
	//hide loading bar
	function hideLoading(){
		loading.fadeTo(1000, 0);
		loading
			.css({visibility:"hidden"})
	};
});