$(document).ready(function(){
	load();
});

function call_btn_all(dpt_type){
	//alert(dpt_type);
	$('.btn_only').css("display","none");
	$('.btn_all').css("display","block");
	$('.dpt2').css("display","none");
}
	
function call_btn_only(dpt_type){
	//alert(dpt_type);
	$('.btn_all').css("display","none");
	$('.btn_only').css("display","block");
	$('.dpt2').css("display","block");
	
}


	
function call_save(type){
//alert(type);
	if(type=='only'){
		
		
			var shift_id = $("#shift_id").val();
			var medium_id = $("#medium_id").val();
			var class_id = $("#class_id").val();
			var comment = $("#comment").val();
			var operation = "only";
			var department_id=$("#department_id").val();
			var late_fine=$("#late_fine").val();
			var date=$("#date").val();
			//alert(date);
			//alert(stydent_type);
			var dataStr="comment="+comment+"&operation="+operation+"&department_id="+department_id+"&late_fine="+late_fine+"&date="+date;
			if(shift_id==""){
				alert("Select Shift Name");
				$('#shift_id').focus();
				return false;
			}
			else if(medium_id==""){
				alert("Select Medium Name");
				$('#medium_id').focus();
				return false;
			}
			else if(class_id==""){
				alert("Select Class Name");
				$('#class_id').focus();
				return false;
			}
			else if(department_id==""){
				alert("Select Department Name");
				$('#department_id').focus();
				return false;
			}
			else if(late_fine==""){
				alert("Enter Late Fine");
				$('#late_fine').focus();
				return false;
			}
			else if(date==""){
				alert("Enter Late Date");
				$('#date').focus();
				return false;
			}
			else{
				
			 $.ajax({
				type:"post",
				url:"module/fees/late_fine_create_ajax.php",
				data:dataStr ,
				success:function(st){
					alert(st);
					load();
				}
			}); 
			}
		
	}
//====================================================================
	else if(type=='all'){
		
			var shift_id = $("#shift_id").val();
			var medium_id = $("#medium_id").val();
			//var class_id = $("#class_id").val();
			var comment = $("#comment").val();
			var operation = "all";
			//var department_id=$("#department_id").val();
			var late_fine=$("#late_fine").val();
			var date=$("#date").val();
			//alert(date);
			//alert(stydent_type);
			var dataStr="comment="+comment+"&operation="+operation+"&shift_id="+shift_id+"&medium_id="+medium_id+"&late_fine="+late_fine+"&date="+date;
			if(shift_id==""){
				alert("Select Shift Name");
				$('#shift_id').focus();
				return false;
			}
			else if(medium_id==""){
				alert("Select Medium Name");
				$('#medium_id').focus();
				return false;
			}
			/* else if(class_id==""){
				alert("Select Class Name");
				$('#class_id').focus();
				return false;
			}
			else if(department_id==""){
				alert("Select Department Name");
				$('#department_id').focus();
				return false;
			} */
			else if(late_fine==""){
				alert("Enter Late Fine");
				$('#late_fine').focus();
				return false;
			}
			else if(date==""){
				alert("Enter Late Date");
				$('#date').focus();
				return false;
			}
			else{
				
			 $.ajax({
				type:"post",
				url:"module/fees/late_fine_create_ajax.php",
				data:dataStr ,
				success:function(st){
					alert(st);
					load();
				}
			}); 
			}
		
	}
	
	
}
//===========================================================
$("#btn_update").click(function(){
		//alert("asd");
			var shift_id = $("#edit_medium_shift_id").val();
			var medium_id = $("#edit_class_medium_id").val();
			var class_id = $("#edit_dept_class_id").val();
			var edit_student_type_dept_id = $("#edit_student_type_dept_id").val();
			var edit_student_type_name = $("#edit_student_type_name").val();
			
			if(shift_id==""){
				alert("Select Shift Name");
				$('#edit_medium_shift_id').focus();
				return false;
			}
			else if(medium_id==""){
				alert("Select Medium Name");
				$('#edit_class_medium_id').focus();
				return false;
			}
			else if(class_id==""){
				alert("Select Class Name");
				$('#edit_dept_class_id').focus();
				return false;
			}
			else if(edit_student_type_dept_id==""){
				alert("Select Department Name");
				$('#edit_student_type_dept_id').focus();
				return false;
			}
			else if(edit_late_fine_amount==""){
				alert("Enter Student Late Amount");
				$('#edit_late_fine_amount').focus();
				return false;
			}
			else if(edit_late_date==""){
				alert("Enter Student Late Amount");
				$('#edit_late_date').focus();
				return false;
			}
			else{
			
				var edit_late_fine_id  = $("#edit_late_fine_id").val();
				var edit_late_fine_amount  = $("#edit_late_fine_amount").val();
				
				var edit_late_date = $("#edit_late_date").val();
				var edit_student_type_status = $("#edit_student_type_status").val();
				var operation="update";
				var dataStr="edit_late_fine_id="+edit_late_fine_id+"&edit_late_fine_amount="+edit_late_fine_amount+"&edit_late_date="+edit_late_date+"&edit_student_type_dept_id="+edit_student_type_dept_id+"&status="+edit_student_type_status+"&operation="+operation;
			
				//alert(dataStr);
				
				$.ajax({
					type:"post",
					url:"module/fees/late_fine_create_ajax.php",
					data:dataStr ,
					success:function(st){
						alert(st);
						load();
					}
				}); 
			}
			
		});

//===========================================================
function show_edit_view(id){
	/* alert(id);
	exit(); */
	var datastr="late_fine_id="+id;
	
	$("#model_table_value").load("module/fees/late_fine_edit_view.php",datastr);
}

//==========================================================
	function delete_data(id){
//	alert(id);
	 var datastr="delete_id="+id+"&operation="+"delete";
	// alert(datastr);
		 $.ajax({
				type:"post",
				url:"module/fees/late_fine_create_ajax.php",
				data:datastr ,
				success:function(st){
					alert(st);
					load();
				}
			}); 
	
}
function call_child(id,id2){
	var id_to_load="#"+id2;
	if(id != ''){
		var datastr="parent_id="+id +"&select_id="+id2;
		//$(id_to_load).load("module/settings/get_child_list_for_form.php",datastr);
		 $.ajax({
					type:"get",
					url:"module/settings/get_child_list_for_form.php",
					data:datastr ,
					success:function(st){
					
						$(id_to_load).html(st);
					}
				}); 
	}else{
		$(id_to_load).html('');
		}
}
//===========================================================
function call_shift(id){
	if(id != ''){
		var datastr="branch_id="+id;
		$("#shift_control").load("module/settings/get_shift_list_for_form.php",datastr);
	}
}
function call_medium(id){
	if(id != ''){
		var datastr="shift_id="+id;
		$("#medium_control").load("module/settings/get_medium_list_for_form.php",datastr);
	}
}
function call_class(id){
	if(id != ''){
		var datastr="medium_id="+id;
		$("#class_control").load("module/settings/get_class_list_for_form.php",datastr);
	}
}
function call_department(id){
	if(id != ''){
		var datastr="class_id="+id;
		$("#department_control").load("module/settings/get_department_list_for_form.php",datastr);
	}
}
function call_student_type(id){
	
}
function call_branch(id){
	if(id != ''){
		var datastr="institute_id="+id;
		$("#branch_control").load("module/settings/get_branch_list_for_form.php",datastr);
	}
}
//===========================================================
function load(){
	$("#data_to_show").load("module/fees/late_fine_datatable.php");
	
}	