
$('.spinner1').ace_spinner({value:0,min:0,max:80,step:1, btn_up_class:'btn-info' , btn_down_class:'btn-info'})
.on('change', function(){
});



$('.timepicker1').timepicker({
	minuteStep: 1,
	showSeconds: false,
	showMeridian: false
});



// for checked and uncheck
    $('#check_all').change(function() {
		if(this.checked){
			  $(".checked_home_topics").each(function(){
				this.checked=true;
			  })              
			}else{
			  $(".checked_home_topics").each(function(){
				this.checked=false;
			  })              
		}
		
    });
// for topics .topics_specific  #topics_default
 /*  $("#topics_default").keyup(function () {
      var value = $(this).val();
	//  alert(value);
    //  var length = parseInt(value.length); 
	  
	
	  $(".topics_specific").val(value);
     
	}).keyup();*/
 
//$("#topics_default").onkeyup(function(){
function deft_val(value){
	//var value = $(this).val();
	 $(".topics_specific").text(value);
	 var charLength = value.length;
	// var messageNum = Math.round(charLength / 160);
	 var messageNum = parseInt(charLength / 160) +1 ;
	 $(".char-length").text(charLength);
	 $(".message-number").text(messageNum);	 
}


 $(".topics_specific").keypress(function(){
	var value = $(this).val();
	 var charLength = value.length;
	// var messageNum = Math.round(charLength / 160);
	 var messageNum = parseInt(charLength / 160) + 1 ;
	 $(this).parent().parent().find(".char-length").text(charLength);
	 $(this).parent().parent().find(".message-number").text(messageNum);
	 
 });
$("#btn_save_homework").click(function(){
	var module_id = '';//$('#module_id').val();
	var shift_id = $('input[name="shift_id"]').val();
	var homework_status_id = $('input[name="homework_status_id"]').val();	
	var medium_id = $('input[name="medium_id"]').val();
	var section_id = $('input[name="section_id"]').val();
	var class_id = $('input[name="class_id"]').val();
	//var remarks = $('input[name="remarks"]').val();
	
	var applied_date = $('#applied_date').val();
	var applied_by = $('#teacher_id').val();
	var from_date = $('#date').val();
	var to_date = $('#date2').val();
	
	var _homework_topics_subject = $('#topics_subject').val();
	var _homework_topics = $('#topics').val();
	var operation = 'save_atd';
	var operation2 = 'up_status';

	var datastr = "operation="+operation+"&section_id="+section_id+"&subject_id="+homework_status_id+"&applied_by="+applied_by+"&applied_date="+applied_date+"&from_date="+from_date+"&to_date="+to_date+"&homework_topics_subject="+encodeURI(_homework_topics_subject)+"&homework_topics="+encodeURI(_homework_topics); 
	
	var dataStr3="medium_id="+medium_id+"&shift_id="+shift_id+"&module_id="+module_id+'&class_id='+class_id+'&section_id='+section_id;
	//insert homework	
	
	if(applied_date==""){
		alert("Select Applied Date");
		$('#applied_date').focus();
		return false;
	}
	else if(applied_by==""){
		alert("Select Teacher");
		$('#teacher_id').focus();
		return false;
	}	
	else if(from_date==""){
		alert("Select Duration From");
		$('#date').focus();
		return false;
	}		
	else if(to_date==""){
		alert("Select Duration To");
		$('#date2').focus();
		return false;
	}
	else if(_homework_topics_subject==""){
		alert("Enter Topics Subject");
		$('#topics_subject').focus();
		return false;
	}
	else if(_homework_topics==""){
		alert("Enter Topics");
		$('#topics').focus();
		return false;
	}
	
	$.ajax({
		type:"post",
		url:"module/homework/save_homework_data_subject.php",
		data:datastr,
		success:function(result){
			alert("Homework Submitted Successfully!");
			$(".data_to_show_atd").load("module/homework/daily_homework_subject_status_view.php",dataStr3);

			$('#first_part').remove();
			$('#second_part').css("display","block");
		}
	});
});



// =================================



$("#btn_save_atd").click(function(){
	var module_id = $('#module_id').val();
	var homework_status_id = $('input[name="homework_status_id"]').val();
	var medium_id = $('input[name="medium_id"]').val();
	var remarks = $('input[name="remarks"]').val();
	var home_work_time = $('input[name="home_work_time"]').val();
	var operation2 = 'up_status';

	var dataStr4="operation2="+operation2+"&homework_status_id="+homework_status_id+"&home_work_time="+home_work_time+"&remarks="+remarks;

	var dataStr5="medium_id="+medium_id;


	$.ajax({
		type:"post",
		url:"module/homework/save_homework_data_subject.php",
		data:dataStr4 ,
		success:function(st){
			$(".data_to_show_atd").load("module/homework/daily_homework_subject_status_view.php",dataStr5);
			$('#first_part').remove();
			$('#second_part').css("display","block");
		}
	});

});
// Edit 
$("#btn_edit_save").click(function(){
    var module_id = $('#module_id').val();
	var homework_status_id = $('input[name="homework_status_id"]').val();	
	var medium_id = $('input[name="medium_id"]').val();
	var shift_id = $("#shift_id").val();
	var shipt_name = $("#shipt_name").val();
	var medium_id = $("#medium_id").val();	
	var medium_name = $("#medium_name").val();	
	
	var section_id = $('input[name="section_id"]').val();
	var remarks = $('input[name="remarks"]').val();
	var home_work_time = $('input[name="home_work_time"]').val();
	var total_row = $('input[name="total_row"]').val();
	var _homework_common_topics = $('#_homework_common_topics').val();
	var operation = 'save_atd';
	var operation2 = 'up_status';
	//var rs = false;

	for (i = 1; i <= total_row; i++) {
		var homework_send_status = 0;
		var std_id = $('input[name="std_id_'+i+'"]').val();
		//var homework_send_status = $('input:checkbox[name="home_status_'+i+'"]:checked').val();
		var homework_message_status = $("#home_status_"+i+"").is(':checked') ? 1 : 0;
		var homework_topics = $('#topics_'+i+'').val();

		var dataStr="operation="+operation+"&section_id="+section_id+"&std_id="+std_id+"&homework_message_status="+homework_message_status+"&homework_topics="+homework_topics+"&_homework_common_topics="+_homework_common_topics;
		
		
		//alert(late_time);

		$.ajax({
			type:"post",
			url:"module/homework/edit_homework_data_subject.php",
			data:dataStr ,
			success:function(result){
				}
		});
	}
var dataStr2="operation2="+operation2+"&homework_status_id="+homework_status_id+"&home_work_time="+home_work_time+"&remarks="+remarks;

		
  		var dataStr3="operation="+operation+"&medium_id="+medium_id+"&shift_id="+shift_id+"&shipt_name="+shipt_name+"&medium_name="+medium_name+"&module_id="+module_id;
	$.ajax({
		type:"post",
		url:"module/homework/edit_homework_data_subject.php",
		data:dataStr2 ,
		success:function(st){
			//alert(st);
			$("#view-part").load("module/homework/final_view_homework.php",dataStr3);

			$('#first_part').remove();
			$('#second_part').css("display","block");
		}
	});

});
