
$(document).ready(function(){
	
		$("#date" ).datepicker();
		$('#date').on('changeDate', function(ev){
    $(this).datepicker('hide');
});
	$("#btn_search").click(function(){
		/* $('#first_part').css('display','none'); */
		//alert("asd");
		//window.alert( $('[name=foo]').val() );
		
		$div = $(this).parents('#first_part');
		var branch_id = $('#branch_id').val();
			var datastr="branch_id="+branch_id ;
			
			var shift_id = $('#shift_id').val();
			if(shift_id){
				var datastr=datastr+"&shift_id="+shift_id ; 
				}
			var medium_id = $('#medium_id').val();
			if(medium_id){
				var datastr=datastr+"&medium_id="+medium_id ; 
				}
			var class_id = $('#class_id').val();
			if(class_id){
				var datastr=datastr+"&class_id="+class_id ; 
				}
			var department_id = $('#department_id').val();
			if(department_id){
				var datastr=datastr+"&department_id="+department_id ;
				}


        var std_month = $('#std_month').val();
        if(std_month){
            var datastr=datastr+"&std_month="+std_month ;
        }
			
			var session = $("#session").val();

			var datastr=datastr+"&session="+session;
			//alert(datastr);
			if(std_month=="" || session=="")
			{
				alert("Please select month or session!"); return;
			}
	//		var datastr="branch_id="+branch_id+"&shift_id="+ shift_id+"&medium_id="+medium_id+"&class_id="+class_id+"&department_id="+department_id+"&student_type_id="+student_type_id+"&section_id="+section_id+"&ss="+ss;
			/* alert(department_id);
			exit(); */
			
			$('#first_part').css('display','none');
	      $('#data_load').load('module/fees/monthly_fee_rollback_information.php',datastr,function(data){
				//alert(datastr);
				
			
			});
			
			
			 /* $.ajax({
				type:"post",
				$('#data_load').load('module/profile/student/search_student.php',datastr,function(data));
				alert(st);
				$('#first_part').css('display','none');
						
			}); */ 
			
		});

	

	
});


function reload_btn_search(){
	/* $('#first_part').css('display','none'); */
    //alert("asd");
    //window.alert( $('[name=foo]').val() );

    $div = $(this).parents('#first_part');
    var branch_id = $('#branch_id').val();
    var datastr="branch_id="+branch_id ;

    var shift_id = $('#shift_id').val();
    if(shift_id){
        var datastr=datastr+"&shift_id="+shift_id ;
    }
    var medium_id = $('#medium_id').val();
    if(medium_id){
        var datastr=datastr+"&medium_id="+medium_id ;
    }
    var class_id = $('#class_id').val();
    if(class_id){
        var datastr=datastr+"&class_id="+class_id ;
    }
    var department_id = $('#department_id').val();
    if(department_id){
        var datastr=datastr+"&department_id="+department_id ;
    }


    var std_month = $('#std_month').val();
    if(std_month){
        var datastr=datastr+"&std_month="+std_month ;
    }

    var session = $("#session").val();

    var datastr=datastr+"&session="+session;
    //alert(datastr);
    if(std_month=="" || session=="")
    {
        alert("Please select month or session!"); return;
    }
    //		var datastr="branch_id="+branch_id+"&shift_id="+ shift_id+"&medium_id="+medium_id+"&class_id="+class_id+"&department_id="+department_id+"&student_type_id="+student_type_id+"&section_id="+section_id+"&ss="+ss;
	/* alert(department_id);
	 exit(); */

    $('#first_part').css('display','none');
    $('#data_load').load('module/fees/monthly_fee_rollback_information.php',datastr,function(data){
        //alert(datastr);
        $('#myModal').modal('hide');

    });


	/* $.ajax({
	 type:"post",
	 $('#data_load').load('module/profile/student/search_student.php',datastr,function(data));
	 alert(st);
	 $('#first_part').css('display','none');

	 }); */

}


function call_medium(id){
	var datastr="shift_id="+id;
	$("#medium_control").load("module/settings/get_medium_list_for_form.php",datastr);
}


function call_class(id){
	var datastr="medium_id="+id;
	$("#class_control").load("module/settings/get_class_list_for_form.php",datastr);
}
function call_department(id){
	var datastr="class_id="+id;
	$("#department_control").load("module/settings/get_department_list_for_form.php",datastr);
}
function call_student_type(id){
		var datastr="department_id="+id;
	$("#student_type_control").load("module/settings/get_student_type_list_for_form.php",datastr);

}
function call_section(id){

	var datastr="student_type_id="+id;
	$("#section_control").load("module/settings/get_section_list_for_form.php",datastr);
	//alert(datastr);
}
function call_child(id,id2){
	var id_to_load="#"+id2;
	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);
				}
			}); 
}



////////
 function call_child(parent_id,child_view_id){
	var child="#" + child_view_id;
	var datastr="parent_id="+ parent_id ;
	$(child).load("module/profile/student/get_child.php",datastr);
}





function call_more_child(id_to_append,child_counter,child_info){

	var counter_id="#" + child_counter;
	var counter=$(counter_id).val();

	//var dept_id=$.trim($('#dept_id').val());
	var dept_id = $('#dept_id').val();
	var stdid = $('#p_id').val();

	
	var new_counter=parseInt(counter) + 1;
	var id_to_appendd="#" + id_to_append;
	 var inpu_box_id="input_button_"+ child_info + counter;
	 var datastr="id="+ inpu_box_id+"&name="+counter + "&child_info=" + child_info+"&dept_id="+dept_id+"&std_id="+stdid;
	  //alert(datastr);
	  
	  $.ajax({
				type:"post",
				url:"module/fees/student_fee_edit.php",
				data:datastr ,
				success:function(st){
					//alert(st);
					$(id_to_appendd).append(st);
					$(counter_id).val(new_counter);
				}
				
			});  
}



/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function fee_rollback(id){

    //alert(id);
    var datastr="function=fee_rollback&id="+id ;
    //$('#form_data').css('display','none');

    $.ajax({
        type:"post",
        url:"module/fees/monthly_fee_rollback_js.php",
        data:datastr ,
        success:function(st){
//alert(st);
            $("#resultDiv").html(st);
            //form_data.load()

        }

    });
}
function fee_monthly_edit(id){

    //alert(id);
    var datastr="function=fee_monthly_edit&id="+id ;
    //$('#form_data').css('display','none');

    $.ajax({
        type:"post",
        url:"module/fees/monthly_fee_rollback_js.php",
        data:datastr ,
        success:function(st){
//alert(st);
            $("#resultDiv").html(st);
            //form_data.load()

        }

    });
}

function fee_rollback_confirm(id,due){


    var discount=$("#discount_input_"+id).val();

if( parseInt(discount)>parseInt(due))
{
	alert("Discount amount must be less then due amount");
	return;
}
    var datastr="function=fee_rollback_confirm&id="+id+"&discount="+discount ;
    //$('#form_data').css('display','none');

    $.ajax({
        type:"post",
        url:"module/fees/monthly_fee_rollback_js.php",
        data:datastr ,
        success:function(st){
//alert(st);
            $("#resultDiv").html(st);
            //form_data.load()
            reload_btn_search();

        }

    });
}

function opendiscountinputbox(id) {


    $("#discount_"+id).css("display", "none");
    $("#discount_input_div_"+id).css("display", "block");

}
