;(function($) {	// noflict for $ jquery
	$(document).ready(function(){
		$(".cnbbr_ids_checkbox input").click(function(){
			var unselectcount=0;
			$(".cnbbr_ids_checkbox input").each(function(i){
				if($(this).attr("checked")==false){
					unselectcount+=1;
				}
			});
			if(unselectcount==0){ $("#selectallbox").attr("checked",true);}else{ $("#selectallbox").attr("checked",false);}
			if($(this).attr("checked")==false){
				$(this).parents("tr").children("td").removeClass("cnbbr_datagrid_checked");
			}else{
				$(this).parents("tr").children("td").addClass("cnbbr_datagrid_checked");
			}
		});
		$(".selectall").click(function(){
			$(".cnbbr_ids_checkbox input").each(function(){
				$(this).attr("checked",true);
				$(this).parents("tr").children("td").addClass("cnbbr_datagrid_checked");
			});
			$("#selectallbox").attr("checked",true);
		});
		$(".unselectall").click(function(){
			$(".cnbbr_ids_checkbox input").each(function(){
				$(this).attr("checked",false);
				$(this).parents("tr").children("td").removeClass("cnbbr_datagrid_checked");
			});
			$("#selectallbox").attr("checked",false);
		});
		$(".chgselectall").click(function(){
			var originalselectcount=0;
			$(".cnbbr_ids_checkbox input").each(function(i){
				if($(this).attr("checked")==true){
					originalselectcount+=1;
					$(this).attr("checked",false);
					$(this).parents("tr").children("td").removeClass("cnbbr_datagrid_checked");
				}else{
					$(this).attr("checked",true);
					$(this).parents("tr").children("td").addClass("cnbbr_datagrid_checked");
				}
			});
			if(originalselectcount==0){ $("#selectallbox").attr("checked",true);}else{ $("#selectallbox").attr("checked",false);}
		});
	});
})(jQuery);