$(document).ready(function(){
	load_admission_details_data();
});	
function load_admission_details_data(){
	$("#admission_details_data_to_show").load("module/admission/admission_details_datatable.php");
}

function insert_admission_details_entry(){
	var master_id = $("#master_id_for_admission_details").val();
	var institute_id = $("#institute_id_for_admission_details").val();
	var branch_id = $("#branch_id_for_admission_details").val();
	var no_of_students = parseInt($("#no_of_std_for_admission_details").val());
	var admission_fee = parseInt($("#fee_for_admission_details").val());
	var admission_process_fee = parseInt($("#proccess_fee_for_admission_details").val());
	var age_limit = parseInt($("#age_limit_for_admission_details").val());
	var datastr="master_id="+master_id+"&institute_id="+institute_id+"&branch_id="+branch_id ;
	var shift_id = $('#shift_id').val();
	
	if(isNaN(no_of_students)){
		alert('Please enter a number');
		$("#no_of_std_for_admission_details").focus();
		return false;
	}
	if(isNaN(admission_fee)){
		alert('Please enter a number');
		$("#fee_for_admission_details").focus();
		return false;
	}
	if(isNaN(admission_process_fee)){
		alert('Please enter a number');
		$("#proccess_fee_for_admission_details").focus();
		return false;
	}
	if(isNaN(age_limit)){
		alert('Please enter a number');
		$("#age_limit_for_admission_details").focus();
		return false;
	}
	if(master_id==""){
		alert("Please select a session");
		$('#master_id_for_admission_details').focus();
		return false;
	}
	if(no_of_students<=0){
		alert("Please enter a valid number for number of students");
		$('#no_of_std_for_admission_details').focus();
		return false;
	}
	if(admission_fee<=0){
		alert("Please enter a valid number for admission fee");
		$('#fee_for_admission_details').focus();
		return false;
	}
	if(admission_process_fee<=0){
		alert("Please enter a valid number for admission process fee");
		$('#proccess_fee_for_admission_details').focus();
		return false;
	}
	if(age_limit<=0){
		alert("Please enter a valid number for maxium age of student");
		$('#age_limit_for_admission_details').focus();
		return false;
	}
	if(shift_id){
		datastr=datastr+"&shift_id="+shift_id ; 
	}
	var medium_id = $('#medium_id').val();
	if(medium_id){
		datastr=datastr+"&medium_id="+medium_id ; 
	}
	var class_id = $('#class_id').val();
	if(class_id){
		datastr=datastr+"&class_id="+class_id ; 
	}
	var department_id = $('#department_id').val();
	if(department_id){
		datastr=datastr+"&department_id="+department_id ; 
	}
	
	var operation = "insert_admission_details";
	var datastr=datastr+"&no_of_students="+no_of_students+"&admission_fee="+admission_fee+
				"&admission_process_fee="+admission_process_fee+"&age_limit="+age_limit+"&operation="+operation; 
	
	//alert(datastr);
	
	$.ajax({
		type:"post",
		url:"module/admission/admission_details_ajax.php",
		data:datastr,
		success:function(st){
			alert(st);
			load_admission_details_data();
		}
	});
}

function show_edit_admission_details_view(id){
	var datastr="details_id="+id;
	$("#admission_details_table_value").load("module/admission/admission_details_edit_view.php",datastr)
}
function perform_update_admission_details_info(){
	var edit_admission_details_id  = $("#selected_admission_details_id_to_edit").val();
	var edit_admission_fee_details = $("#fee_for_edit_details").val();
	var edit_no_of_students_details = $("#no_of_std_for_edit_details").val();
	var edit_process_fee_details = $("#proccess_fee_for_edit_details").val();
	var edit_age_limit_details = $("#age_limit_for_edit_details").val();

	var operation="update_admission_details_info";
	var dataStr="edit_admission_details_id="+edit_admission_details_id+"&edit_admission_fee_details="+edit_admission_fee_details+"&edit_no_of_students_details="+edit_no_of_students_details+"&edit_process_fee_details="+edit_process_fee_details+"&edit_age_limit_details="+edit_age_limit_details+"&operation="+operation;
	
	/*if(isNaN(edit_no_of_students_details)){
		alert('Please enter a number');
		$("#no_of_std_for_edit_details").focus();
	}
	else if(isNaN(edit_admission_fee_details)){
		alert('Please enter a number');
		$("#fee_for_edit_details").focus();
	}
	else if(isNaN(edit_process_fee_details)){
		alert('Please enter a number');
		$("#proccess_fee_for_edit_details").focus();
	}
	else if(edit_no_of_students_details<=0){
		alert("Please enter a valid number for number of students");
		$('#no_of_std_for_edit_details').focus();
	}
	else if(edit_admission_fee_details<=0){
		alert("Please enter a valid number for admission fee");
		$('#fee_for_edit_details').focus();
	}
	else if(edit_process_fee_details<=0){
		alert("Please enter a valid number for admission process fee");
		$('#proccess_fee_for_edit_details').focus();
	}*/
	//else{		
		$.ajax({
			type:"post",
			url:"module/admission/admission_details_ajax.php",
			data:dataStr ,
			success:function(st){
					alert(st);
					load_admission_details_data();
			}
		});
	//}
}
function delete_admission_details_data(id){
	var datastr="details_id="+id;
	$("#delete_admission_details_table_value").load("module/admission/admission_details_delete_view.php",datastr)
}
function perform_delete_admission_details_info(){
	var delete_admission_details_id = $("#selected_admission_details_id_to_delete").val();
	var operation="delete_admission_details_info";
	var datastr="delete_admission_details_id="+delete_admission_details_id+"&operation="+operation;
	$.ajax({
		type:"post",
		url:"module/admission/admission_details_ajax.php",
		data:datastr,
		success:function(st){
				alert(st);
				load_admission_details_data();
		}
	});
}
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);
}*/