
$(document).ready(function() {
	
	$("#checkboxall").click(function() {
		var checked_status = this.checked;
		$("input[type=checkbox]").each(function() {
			this.checked = checked_status;
		});
	});
	$(":checkbox[name='chk1[]']").bind("click", function(e) {
		chkall_flag=1; //assume all checkboxes are checked
		$(":checkbox[name='chk1[]']").each(function() {
			if(this.checked == false) {
				$("#checkboxall").removeAttr('checked');
				chkall_flag=0; //if any one checkbox is not checked, make flag false
			}
		});
		if(chkall_flag==1) { //if flag is still true, then last one checked makes all chkbox checked
			$("#checkboxall").attr("checked","checked");
		}
	}); 
	
});

