
    $(document).on("change", "#ansopt", function() {
			
				var ansopt = $('#ansopt').val();
				if(ansopt==5)
				{
					$('.ansoption5').css("display","block");
				}else{
					$('.ansoption5').css("display","none");
				}
				});
//*********************************************//
//              To get Paper scheduling        //
//********************************************//
	$(document).ready(function(){
		    $('#testtitle').change(function(){
				var testtitle = $('#testtitle').val();
				//alert(testtitle);
				$.ajax({
					type:"POST",
					url:"http://sedi.co.in/Admin/get_pps",
					data:{testtitle:testtitle},
					dataType:'JSON',
					success:function(data)
					{
						//alert(data.stdname);
						$('#branchid').val(data.branchid);
						$('#branchname').val(data.branchname);
						$('#stdid').val(data.stdid);
						$('#stdname').val(data.stdname);
						$('#topicid').val(data.topicid);
						$('#topicname').val(data.topicname);
						$('#subjectid').val(data.subjectid);
						$('#subjectname').val(data.subjectname);
						$('#startdt').val(data.startdt);
						$('#enddt').val(data.enddt);
						$('#testtime').val(data.time);
					}
					
				});
			});
		});			
//*********************************************//
//              Test paper Preview            //
//********************************************//
$(document).ready(function(){
   $('#sample_3').on("click",".testpaperspreview",function(){
       var tpuid = $(this).attr("data-tpuid"); 
      // alert(tpuid);
        $.ajax({
                		  type: "POST",
                                  url: "http://sedi.co.in/Admin/get_testpapers",
                                  data:{tpuid:tpuid},
                                  dataType:"json",
                                  success: function(data)
                				  {
                				   // alert(data.hvalues['tpuid']);
                				    $('#testuid').val(data.hvalues['tpuid']);
                				    $('#testbranch').val(data.hvalues['branch']);
                				    $('#teststd').val(data.hvalues['std']);
                				    $('#testsubject').val(data.hvalues['subject']);
                				    $('#testtopic').val(data.hvalues['topic']);
                				    $('#testtitle').val(data.hvalues['testtitle']);
                				    $('#teststartdt').val(data.hvalues['startdt']);
                				    $('#testenddt').val(data.hvalues['enddt']);
                				    $('#testtime').val(data.hvalues['testtime']);
                				    $('.testinfo').html(data.testinfo);
                				    $('.questionsets').html(data.questions);
                				   
                				  }
                	
            });
   });
});

//*********************************************//
//             update Test paper              //
//********************************************//
 $(document).ready(function () {
            $("#addtestfrm").submit(function(e) {
            e.preventDefault();
            $('.addmore').hide();
            $.ajax({
                url: "http://sedi.co.in/Admin/updatetestpaper", 
                type: "POST",             
                data: new FormData(this),
                contentType: false,       
                cache: false,             
                processData:false, 
                dataType:"JSON",
                beforeSend:function(){
                    $('.saving').show();
                },
                success: function(data)  
                {
                   //alert(data.success);
                   if(data.success==1)
                   {   $('.saving').hide();
                       $('.addmore').show();
                       //$("#addquestion")[0].reset();
                       $('#addquestion').modal('hide');
                       refreshcontent(data.tpuid);
                       toastr.success('Successfully Saved', 'Test Question')
                   }
                }
            });
            });
            
});
//*********************************************//
//             Delete Test paper              //
//********************************************//
$(document).on("click", ".testpaperid", function() {
          var datatpid = $(this).attr("data-tpid"); 
          var datatpuid = $(this).attr("data-tpuid"); 
          //alert(datatpid);
          
          $.ajax({
             type:"POST",
             url : "http://sedi.co.in/Admin/ajaxdeletetp",
             data:{datatpid:datatpid},
             dataType:"JSON",
             success:function(data){
                
                if(data.success==1)
                {
                   refreshcontent(datatpuid);
                  toastr.success('Successfully Deleted', 'Test Question')
                }
             }
          });  
});
function refreshcontent(datatpuid)
{
     $.ajax({
                		  type: "POST",
                                  url: "http://sedi.co.in/Admin/get_testpapers",
                                  data:{tpuid:datatpuid},
                                  dataType:"json",
                                  success: function(data)
                				  {
                				    //alert(data.hvalues['tpuid']);
                				    $('#testuid').val(data.hvalues['tpuid']);
                				    $('#testbranch').val(data.hvalues['branch']);
                				    $('#teststd').val(data.hvalues['std']);
                				    $('#testsubject').val(data.hvalues['subject']);
                				    $('#testtopic').val(data.hvalues['topic']);
                				    $('#testtitle').val(data.hvalues['testtitle']);
                				    $('#teststartdt').val(data.hvalues['startdt']);
                				    $('#testenddt').val(data.hvalues['enddt']);
                				    $('#testtime').val(data.hvalues['testtime']);
                				    $('.testinfo').html(data.testinfo);
                				    $('.questionsets').html(data.questions);
                				   
                				  }
                	
            });
}
//*********************************************//
//             Delete Test paper              //
//********************************************//
$(document).on("click", ".questiondelbtn", function() {
          var questionid = $(this).attr("data-index"); 
          
          $.ajax({
             type:"POST",
             url : "http://sedi.co.in/Admin/deletequestion",
             data:{questionid:questionid},
             dataType:"JSON",
             success:function(data){
                
                if(data.success==1)
                {
                  $('.newtestarr').html(data.newtestarr);
                  toastr.success('Successfully Deleted', 'Test Question')
                }
             }
          });  
});

//*********************************************//
//            New Test paper              //
//********************************************//
$(document).ready(function() {
            $("#newtestpaperfrm").submit(function(e) {
                
            e.preventDefault();
            $('.addmorebtn').hide();
            $.ajax({
                url: "http://sedi.co.in/Admin/testpaperinsert", 
                type: "POST",             
                data: new FormData(this),
                contentType: false,       
                cache: false,             
                processData:false, 
                dataType:"JSON",
                beforeSend:function(){
                   // $('.saving').show();
                    $.blockUI({ message: '<h5><img src="../assets/global/img/loading-spinner-grey.gif" alt=""> Just a moment...</h5>',css: { 
                    border: 'none', 
                    padding: '5px', 
                    backgroundColor: '#fff', 
                    '-webkit-border-radius': '10px', 
                    '-moz-border-radius': '10px',
                    color: '#000',
                    
                }  });
                },
                success: function(data)  
                {
                   
                   if(data.success==1)
                   {   
                       $.unblockUI();
                       $('.close').click();
                       $('.addmorebtn').show();
                       $('.newtestarr').html(data.newtestarr);
                       $('textarea[name=question]').val("");
                       $('#quserfile').val("");
                       $('#ans1').val("");
                       $('#ans2').val("");
                       $('#ans3').val("");
                       $('#ans4').val("");
                       $('#ans5').val("");
                       $('#ansopt option:first').prop('selected',false);
                       
                       //$("#newtestpaperfrm")[0].reset();
                       toastr.success('Successfully Saved', 'Test Paper')
                      
                   }
                   if(data.errormsg)
                   {   
                       $.unblockUI();
                       $('.addmorebtn').show();
                       $.each(data.errormsg,function(key,value){
                           
                           var element = $('.form-group #'+key);
                           element.after('<div class="error">'+ value +'</div>');
                       });
                       
                   }
                }
            });
            });
            
});

