
// Script Login Registration Popup Start
$(document).ready(function(){
	// Change Phone Number To Adding Number
	$('.back-addingNumber').on('click', function(){
		$('.nextStep-otp').css('display','none');
		$('.step-addingNumber').css('display','block');
	});
});

// FAQ Toggle Start
$(document).ready(function() {
  $('.accordionFaq a').click(function(){
    $(this).toggleClass('active');
    $(this).next('.content').slideToggle(400);
   });
});


/*$(".selectpickerLoggedin").select2({
  allowClear:true        
});*/

// search category
$(document).ready(function(){
    $(".courseCategories").on("keyup", function() {
        var value = $(this).val().toLowerCase();
        $("#courseCategoriesList .tabbableCustom ul li").filter(function() {
        	$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
        });
    });
});




function check_login_another_device()
{
    $.ajax(
	{
       	type: 'get',
        url: $("#check_login_another_device_url").val(),
        data: {},
        success: function (response)
        {
        	if(response.status == 'error')
	        {
	        	window.location.href = response.redirect_url;
        	}
        }
  	});
}

if($("#session_error_msg").length > 0)
{
	if($("#session_error_msg").val() != "")
	{
		swal({
		  title: "Error",
		  text: $("#session_error_msg").val(),
		  icon: "error",
		  button: "Close",
		}).then((value) => 
		{
		    $.ajax(
			{
		       	type: 'get',
		        url: $("#session_unsel_url").val(),
		        data: {'session_key':$("#session_error_msg").attr('session_key_name')},
		        success: function (response)
		        {
		        	if($("#is_redirect_session").val() == 'Yes')
		        	{
			        	if($("#redirect_url_session").length > 0)
			        	{
			        		window.location.href = $("#redirect_url_session").val();
			        	}
			        	else
			        	{
			        		location.reload();
			        	}
			        }
		        }
		  	});
		});
	}
}

if($("#session_sucesss_msg").length > 0)
{
	if($("#session_sucesss_msg").val() != "")
	{
		swal({
		  title: "Success",
		  text: $("#session_sucesss_msg").val(),
		  icon: "success",
		  button: "Close",
		}).then((value) => 
		{
		    $.ajax(
			{
		       	type: 'get',
		        url: $("#session_unsel_url").val(),
		        data: {'session_key':$("#session_sucesss_msg").attr('session_key_name')},
		        success: function (response)
		        {
		        	if($("#is_redirect_session").val() == 'Yes')
		        	{
			        	if($("#redirect_url_session").length > 0)
			        	{
			        		window.location.href = $("#redirect_url_session").val();
			        	}
			        	else
			        	{
			        		location.reload();
			        	}
			       	}
		        }
		  	});
		});
	}
}

jQuery(".otp_phonenumber").keypress(function (e) 
{
    var length = jQuery(this).val().length;
    if(length > 9) 
    {
        return false;
    } 
    else if(e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) 
    {
        return false;
    } 
    else if((length == 0) && (e.which == 48)) 
    {
        return false;
    }
});


jQuery(".digit_with_otp").keyup(function (e) 
{
	var length = jQuery(this).val().length; 
    if(e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57) && (e.which < 96 || e.which > 105)) 
    {
    	return false;
    } 
    else if((length == 0) && (e.which == 48)) 
    {
        return false;
    }
    else
    {
    	if(e.which == 8)
		{
	    	$(this).prev('.required_otp').focus();
		}
		else
		{	
	    	$(this).next('.required_otp').focus();
    		$(this).next('.required_otp').val('');
	    	
    	}
    }
});

//LOGOUT COMMON CODE START

$("body").on('click','.logout',function()
{
	var $this = $(this);
	var redirect_url = $(this).attr('redirect_url'); 
	var url = $(this).attr('url');

	swal(
	{
	  title: 'Are you sure you want to logout from Website?',
	  text: "",
	  icon: "warning",
	  //buttons: true,
	  buttons: ["Cancel","Yes"],
	  dangerMode: true,
	})
	.then((confirmed) => 
	{
	  	if (confirmed)
	  	{
	    	$.ajax(
			{
				type: 'post',
			    url:  url,
			    headers:
			    {
			        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
			    },
			    success: function (response) 
			    {
			    	if(response.status != 'error')
			    	{
			    		$.notify({
				          title: "<b class='notify_success_title'>Logout:</b>",
				          message: response.message
				        },{
				          // settings
				          type: 'success',
				          //showProgressbar: true,
				          placement: {
				            from: "bottom",
				            align: "right"
				          },
				        });
				        window.location.href = redirect_url;
			    	}       	
				},
				error: function()
				{
			    	$.notify({
			          title: "<b class='notify_error_title'>Logout:</b>",
			          message: MSG_SERVER_SIDE_ERROR
			        },{
			          // settings
			          type: 'danger',
			          //showProgressbar: true,
			          placement: {
			            from: "bottom",
			            align: "right"
			          },
			        });
			    }
			});
	  	}
	});
});

//LOGOUT COMMON CODE FOR USER END


//SEND APP LINK COMMON CODE END

function register_login_modelpopup(redirect_url="",course_id="")
{
	reset_login_register_model();
	$("#loginPopupLabel").html('User Login/Registration');
	$("#login_register_user_type").val('User');
	$('#loginRegisterPopup').modal(
	{
	    show: true, 
	    backdrop: 'static',
	    keyboard: true
	});
	if(redirect_url != "")
	{
		$("#redirect_url").val(redirect_url);
	}
	if(course_id > 0)
	{
		$("#course_id").val(course_id);
	}
}


function login_modelpopup(redirect_url="",course_id="")
{
	reset_login_model();
	$("#loginPopupLabel").html('User Login');
	$("#login_register_user_type").val('User');
	$('#registerPopup').modal('hide');
	$('#loginPopup').modal(
	{
	    show: true, 
	    backdrop: 'static',
	    keyboard: true
	});
	if(redirect_url != "")
	{
		$("#redirect_url").val(redirect_url);
	}
	if(course_id > 0)
	{
		$("#course_id").val(course_id);
	}
}

function register_modelpopup(redirect_url="",course_id="")
{
	reset_register_model();
	$("#loginPopupLabel").html('User Register');
	$(".div_select_user_registration").show();
	$("#login_register_user_type").val('User');
	$('#loginPopup').modal('hide');
	$('#registerPopup').modal(
	{
	    show: true, 
	    backdrop: 'static',
	    keyboard: true
	});
	if(redirect_url != "")
	{
		$("#redirect_url").val(redirect_url);
	}
	if(course_id > 0)
	{
		$("#course_id").val(course_id);
	}
}

$(".login_register_menu").click(function()
{
	$("#redirect_url").val('');
	$("#course_id").val('');
	register_login_modelpopup();	
})

$(".login_menu").click(function()
{
	$("#redirect_url").val('');
	$("#course_id").val('');
	login_modelpopup();	
})

$(".register_menu").click(function()
{
	$("#redirect_url").val('');
	$("#course_id").val('');
	register_modelpopup();	
})

$(".login_register_close_btn").click(function()
{
	reset_login_register_model();
	$('#loginPopup').modal('toggle');
})

$(".login_close_btn").click(function()
{
	reset_login_model();
})

$(".register_close_btn").click(function()
{
	reset_register_model();
})


$("#send_otp_btn,#resend_otp_btn").on("click",function(e)
{
	$("#send_otp_btn").html('<i class="fa fa-spinner fa-spin fa-lg"></i>&nbsp; Loading...');
	$("#send_otp_btn").prop('disabled',true);
	$("#resend_otp_btn").prop('disabled',true);
	var $valid = form_valid("#send_otp_div");
    if(!$valid)
    {
    	$("#send_otp_btn").prop('disabled',false);
    	$("#resend_otp_btn").prop('disabled',true);
        $("#send_otp_btn").html('Next');
        return false;
    }
    else
    {
    	
		var inputdata = {
							'v_mobile_number':$("#v_mobile_number").val(),
							'v_email_id':$("#v_email_id").val(),
							'i_country_id':$("#i_country_id").val(),
							'e_frm_type': $("#frm_type").val(),
							'e_login_register_user_type': $("#login_register_user_type").val()
						};
		
		$.ajax(
		{
			type: 'post',
	        url: $("#sendotp_url").val(),
	        data: inputdata,
	        headers: 
	        {
		        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
		    },
	        success: function (response) 
	        {
	        	$("#send_otp_btn").html('Next');
	        	if(response.status != 'error')
	        	{
	        		if(response.is_new_user == 'Yes')
	        		{
	        			if($("#frm_type").val() == 'login_register')
	        			{
	        				$("#verify_otp_btn").html('Verify & Register');
	        			}
	        			if($("#login_register_user_type").val() == 'User')
		        		{
	        				$("#loginPopupLabel").html('User Registration');
	        			}
	        		}
	        		else
	        		{
	        			$("#loginPopupLabel").html('Login');
	        			$("#verify_otp_btn").html('Login');
	        		}

	        		$("#sms_otp_id").val(response.otp_id);
	        		$('.digit_with_otp').each(function()
		            {
		                $(this).val('');
		            });
	        		
	        		$("#send_otp_btn").prop('disabled',false);
					$('.step-addingNumber').css('display','none');
					$('.nextStep-otp').css('display','block');
					$("#verify_otp_mobile_number").val($("#v_mobile_number").val());
					$("#verify_otp_email_id").val($("#v_email_id").val());
					$("#verify_i_country_id").val($("#i_country_id").val());	        		
	        		$.notify({
			          title: "<b class='notify_success_title'>Login/Register:</b>",
			          message: response.message
			        },{
			          // settings
			          delay: 5000,
			          type: 'success',
			          //showProgressbar: true,
			          placement: {
			            from: "bottom",
			            align: "right"
			          },
			        });
	        	}
	        	else
	        	{
	    			$("#send_otp_btn").prop('disabled',false);
	        		$("#v_mobile_number").val('');
	        		$("#v_email_id").val('');
	        		$.notify({
			          title: "<b class='notify_error_title'>Login/Register:</b>",
			          message: response.message
			        },{
			          // settings
			          delay: 5000,
			          type: 'danger',
			          //showProgressbar: true,
			          placement: {
			            from: "bottom",
			            align: "right"
			          },
			        });
	        	}       	
			},
			error: function()
			{
	        	$("#send_otp_btn").html('Next');
            	$("#send_otp_btn").prop('disabled',false);
        		$.notify({
		          title: "<b class='notify_error_title'>Login/Register:</b>",
		          message: MSG_SERVER_SIDE_ERROR
		        },{
		          // settings
		          delay: 5000,
		          type: 'danger',
		          //showProgressbar: true,
		          placement: {
		            from: "bottom",
		            align: "right"
		          },
		        });
            }
	  	});
	  	return false;
	}
});

$("#send_login_otp_btn").on("click",function(e)
{
	$("#send_login_otp_btn").html('<i class="fa fa-spinner fa-spin fa-lg"></i>&nbsp; Loading...');
	$("#send_login_otp_btn").prop('disabled',true);
	$("#resend_login_otp_btn").prop('disabled',true);
	var inputdata = {
		'send_by':$('#getotp:checked').attr('ref'),
		'v_mobile_number':$("#v_mobile_number").val(),
		'v_email_id':$("#v_email_id_sep").val(),
		'i_country_id':$("#i_country_id").val(),
		'e_frm_type': $("#frm_type").val(),
		'type':'send',
		'e_login_register_user_type': $("#login_register_user_type").val()
	};
	
	$.ajax(
	{
		type: 'post',
        url: $("#send_otp_seprate_login_url").val(),
        data: inputdata,
        headers: 
        {
	        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
	    },
        success: function (response) 
        {
        	$("#send_login_otp_btn").html('Next');
        	if(response.status != 'error')
        	{
        		
        		if($("#v_email_id_sep").val() == '')
        		{
        			$('#double_v_email').hide();
        			$('#double_v_mobile').show();
        		}
        		else
        		{
        			$('#double_v_mobile').hide();
        			$('#double_v_email').show();
        			
        		}
    			$("#loginPopupLabel").html('Login');
    			$("#verify_otp_btn").html('Login');
        		

        		$("#sms_otp_id").val(response.otp_id);
        		$('.digit_with_otp').each(function()
	            {
	                $(this).val('');
	            });
        		//alert($("#v_email_id").val());
        		$("#send_login_otp_btn").prop('disabled',false);
				$('.step-addingNumber').css('display','none');
				$('.nextStep-otp').css('display','block');
				$("#verify_otp_mobile_number").val($("#v_mobile_number").val());
				$("#verify_otp_email_id").val($("#v_email_id_sep").val());
				$("#verify_i_country_id").val($("#i_country_id").val());	        		
        		$.notify({
		          title: "<b class='notify_success_title'>Login:</b>",
		          message: response.message
		        },{
		          // settings
		          delay: 5000,
		          type: 'success',
		          //showProgressbar: true,
		          placement: {
		            from: "bottom",
		            align: "right"
		          },
		        });
        	}
        	else
        	{
    			$("#send_login_otp_btn").prop('disabled',false);
        		$("#v_mobile_number").val('');
        		$("#v_email_id_sep").val('');
        		$.notify({
		          title: "<b class='notify_error_title'>Login:</b>",
		          message: response.message
		        },{
		          // settings
		          delay: 5000,
		          type: 'danger',
		          //showProgressbar: true,
		          placement: {
		            from: "bottom",
		            align: "right"
		          },
		        });
        	}       	
		},
		error: function()
		{
        	$("#send_login_otp_btn").html('Next');
        	$("#send_login_otp_btn").prop('disabled',false);
    		$.notify({
	          title: "<b class='notify_error_title'>Login:</b>",
	          message: MSG_SERVER_SIDE_ERROR
	        },{
	          // settings
	          delay: 5000,
	          type: 'danger',
	          //showProgressbar: true,
	          placement: {
	            from: "bottom",
	            align: "right"
	          },
	        });
        }
  	});
});
$("#resend_login_otp_btn").on("click",function(e)
{
	$("#send_login_otp_btn").html('<i class="fa fa-spinner fa-spin fa-lg"></i>&nbsp; Loading...');
	$("#send_login_otp_btn").prop('disabled',true);
	$("#resend_login_otp_btn").prop('disabled',true);
	var inputdata = {
		'send_by':$('#getotp:checked').attr('ref'),
		'v_mobile_number':$("#v_mobile_number").val(),
		'v_email_id':$("#v_email_id_sep").val(),
		'i_country_id':$("#i_country_id").val(),
		'e_frm_type': $("#frm_type").val(),
		'type':'resend',
		'e_login_register_user_type': $("#login_register_user_type").val()
	};
	
	$.ajax(
	{
		type: 'post',
        url: $("#send_otp_seprate_login_url").val(),
        data: inputdata,
        headers: 
        {
	        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
	    },
        success: function (response) 
        {
        	$("#send_login_otp_btn").html('Next');
        	if(response.status != 'error')
        	{
        		
        		if($("#v_email_id_sep").val() == '')
        		{
        			$('#double_v_email').hide();
        			$('#double_v_mobile').show();
        		}
        		else
        		{
        			$('#double_v_mobile').hide();
        			$('#double_v_email').show();
        			
        		}
    			$("#loginPopupLabel").html('Login');
    			$("#verify_otp_btn").html('Login');
        		

        		$("#sms_otp_id").val(response.otp_id);
        		$('.digit_with_otp').each(function()
	            {
	                $(this).val('');
	            });
        		//alert($("#v_email_id").val());
        		$("#send_login_otp_btn").prop('disabled',false);
				$('.step-addingNumber').css('display','none');
				$('.nextStep-otp').css('display','block');
				$("#verify_otp_mobile_number").val($("#v_mobile_number").val());
				$("#verify_otp_email_id").val($("#v_email_id_sep").val());
				$("#verify_i_country_id").val($("#i_country_id").val());	        		
        		$.notify({
		          title: "<b class='notify_success_title'>Login:</b>",
		          message: response.message
		        },{
		          // settings
		          delay: 5000,
		          type: 'success',
		          //showProgressbar: true,
		          placement: {
		            from: "bottom",
		            align: "right"
		          },
		        });
        	}
        	else
        	{
    			$("#send_login_otp_btn").prop('disabled',false);
        		$("#v_mobile_number").val('');
        		$("#v_email_id_sep").val('');
        		$.notify({
		          title: "<b class='notify_error_title'>Login:</b>",
		          message: response.message
		        },{
		          // settings
		          delay: 5000,
		          type: 'danger',
		          //showProgressbar: true,
		          placement: {
		            from: "bottom",
		            align: "right"
		          },
		        });
        	}       	
		},
		error: function()
		{
        	$("#send_login_otp_btn").html('Next');
        	$("#send_login_otp_btn").prop('disabled',false);
    		$.notify({
	          title: "<b class='notify_error_title'>Login:</b>",
	          message: MSG_SERVER_SIDE_ERROR
	        },{
	          // settings
	          delay: 5000,
	          type: 'danger',
	          //showProgressbar: true,
	          placement: {
	            from: "bottom",
	            align: "right"
	          },
	        });
        }
  	});
});
$("#verify_login_otp_btn").on("click",function(e)
{
	var $this = $(this);
	$($this).html('<i class="fa fa-spinner fa-spin fa-lg"></i>&nbsp; Loading...');
	$($this).prop('disabled',true);


	var regex = /^([0-9])+$/;
	$("#verify_login_otp_btn").prop('disabled',true);	
	if($("#verify_i_country_id").val() == "")
	{
		swal("Verification","Please select country code","error");
	 	$("#verify_login_otp_btn").html("Verify");
	    $("#verify_login_otp_btn").prop('disabled',false);	        
	}
	else
	{
		var otp = "";
		$('.digit_with_otp').each(function()
        {
            otp = otp+$(this).val();
        });
		var inputdata = {'_token':$( "input[name$='_token']" ).val(),'v_email_id':$("#v_email_id_sep").val(),'v_mobile_number':$("#verify_otp_mobile_number").val(),'v_sms_otp_id':$("#sms_otp_id").val(),'v_otp':otp,'i_country_id':$("#verify_i_country_id").val(),'e_frm_type':$("#mobileverify_frm_type").val()};
					
		$.ajax(
		{
			type: 'post',
	        url:  $("#verify_otp_seprate_login_url").val(),
	        data: inputdata,
	        success: function (response) 
	        {
	        	if(response.status != 'error')
	        	{
	        		
	        		if(response.redirect_url != "")
				    {
				        window.location.href = response.redirect_url;
				        
				    }
	        	}
	        	else
	        	{
	        		$('.digit_with_otp').each(function()
			        {
			           $(this).val('');
			        });	 
	        		$("#verify_login_otp_btn").html("Verify");
	        		$("#verify_login_otp_btn").prop('disabled',false);

	    			$(this).prop('disabled',false);
	        		$("#mobile_number_otp").val('');
	 				
	 				swal("Verification",response.message,"error");
	    			$("#verify_login_otp_btn").prop('disabled',false);
	        	}
	        	$("#verify_login_otp_btn").prop('disabled',false);
			}
	  	});
	  	return false;
	}
});

$("#verify_otp_btn").on("click",function(e)
{
	var $this = $(this);
	$($this).html('<i class="fa fa-spinner fa-spin fa-lg"></i>&nbsp; Loading...');
	$($this).prop('disabled',true);



	var regex = /^([0-9])+$/;
	$("#verify_otp_btn").prop('disabled',true);	
	if($("#countrycode").val() == "")
	{
		swal("Verification","Please select country code","error");
	 	$("#verify_otp_btn").html("Verify");
	    $("#verify_otp_btn").prop('disabled',false);	        
	}
	else if($("#mobile_number").val() == "" || $("#mobile_number").val() == "Your mobile number")
	{
		swal("Verification","Please enter mobile number","error");
		$("#verify_otp_btn").html("Verify");
	    $("#verify_otp_btn").prop('disabled',false);
	}
	else if(!regex.test($("#mobile_number").val()))
	{
		swal("Verification","Please enter valid mobile number","error");
		$("#verify_otp_btn").html("Verify");
	    $("#verify_otp_btn").prop('disabled',false);
	}
	else if($("#mobile_number").val().length > 10  || $("#mobile_number").val().length < 7 )
	{
		swal("Verification","Please enter valid mobile number(7,8,9,10 digit allow)","error");
		$("#verify_otp_btn").html("Verify");
	    $("#verify_otp_btn").prop('disabled',false);
	}
	else if($("#mobile_number_otp").val() == "" || $("#mobile_number_otp").val() == "Enter otp")
	{
		swal("Verification","Please enter otp","error");
		$("#verify_otp_btn").html("Verify");
	    $("#verify_otp_btn").prop('disabled',false);
	}
	else
	{
		var inputdata = {'_token':$( "input[name$='_token']" ).val(),'v_email_id':$("#v_email_id").val(),'v_mobile_number':$("#mobile_number").val(),'v_sms_otp_id':$("#otp_id_for_verification").val(),'v_otp':$("#mobile_number_otp").val(),'i_country_id':$("#countrycode").val(),'e_frm_type':$("#mobileverify_frm_type").val()};
					
		$.ajax(
		{
			type: 'post',
	        url: $("#verify_otp_seprate_url").val(),
	        data: inputdata,
	        success: function (response) 
	        {
	        	if(response.status != 'error')
	        	{
	        		$("#is_verification_completed").val("Yes");

	        		$("#verify_otp_btn").html("Verify");
	        		$("#verify_otp_btn").prop('disabled',false);

	        		$("#mobile_number_temp").val($("#mobile_number").val());
	        		$("#countrycode_temp").val($("#countrycode_temp").val());
	        		$("#v_email_id_verify").val($("#v_email_id").val());
	        		
					swal("Verification","Verification successfully.","success");
					$("#is_mobile_number_verified").val('Yes');
					$("#user_register_btn").html('Submit');
            		$("#user_register_btn").prop('disabled',false);
	        		$("#mobile_number").prop('disabled',true);
	        		$("#v_email_id").prop('disabled',true);
	        		$("#countrycode").prop('disabled',true);
	        		$("#otp_and_verify").hide();
	        		$("#verify_otp_btn").hide();
	        		$("#otp_send_for_verification").hide();
	        		$("#otp_div").fadeOut();
	        		$("#verify_otp_send_otp_btn").fadeOut();

	        	}
	        	else
	        	{
	        		$("#verify_otp_btn").html("Verify");
	        		$("#verify_otp_btn").prop('disabled',false);

	    			$(this).prop('disabled',false);
	        		$("#mobile_number_otp").val('');
	 				
	 				swal("Verification",response.message,"error");
	    			$("#verify_otp_btn").prop('disabled',false);
	        	}
	        	$("#verify_otp_btn").prop('disabled',false);
			}
	  	});
	  	return false;
	}
});



//USER REGISTER CODE START
$('#user_register_frm').ajaxForm(
{
    beforeSubmit: function() 
    {
    	$("#user_register_btn").html('<i class="fa fa-spinner fa-spin fa-lg"></i>&nbsp; Loading...');
		$("#user_register_btn").prop('disabled',true);
        var $valid = form_valid("#user_register_frm");
        if(!$valid)
        {
        	$("#user_register_btn").html('Submit');
            $("#user_register_btn").prop('disabled',false);
            return false;
        }
        else
        {
        	if($("#is_verification_completed").val() == 'No')
    		{
    			$("#user_register_btn").html('Submit');
            	$("#user_register_btn").prop('disabled',false);
				swal("Register","Please complete verification before register.","error");
				return false;
    		}
        }
    },
    beforeSend:function()
    {
       $('#loader').show();
    },
    success: function(msg) {
    
    },
    complete: function(xhr) 
    {
    	var redirect_url = $("#redirect_url").val();
        $('#loader').hide();
        response = JSON.parse(xhr.responseText);
        if(response.status != 'error')
        {
            swal("Register",response.message,"success");
        	if(redirect_url != ""){
            	window.location.href = redirect_url;
            } else {
            	if(response.redirect_url != "") {
	              	window.location.href = response.redirect_url;
	            }
            }
        }
        else
        {
        	$("#user_register_btn").html('Submit');
            $("#user_register_btn").prop('disabled',false);
            swal("Register",response.message,"error");
        }
    },
    error: function()
    {
    	$("#user_register_btn").html('Submit');
        $("#user_register_btn").prop('disabled',false);
        swal("Register",MSG_SERVER_SIDE_ERROR,"error");
    }
});
//USER REGISTER CODE END

$(document).ready(function() 
{
	$(".upload_image").change(function()
	{
		read_url(this,$(this).attr('showimgclass'));
	});
});

function read_url(input,showimage_element) 
{
    if (input.files && input.files[0]) 
    {
        var reader = new FileReader();
        reader.onload = function (e) 
        {
            $('.'+showimage_element).attr('src', e.target.result);
        }
        reader.readAsDataURL(input.files[0]);
    }
}


function reset_login_register_model()
{
	$("#redirect_url").val('');
	$("#course_id").val('');
	$("#send_otp_btn").html('Next');
	$(".step-addingNumber").show();
	$('.nextStep-otp').hide();
	$(".div_select_user_registration").hide();
	$(".frmreset_field").val('');
	$("#user_profile_pic").val($("#defualt_user_profile_pic").val());
	$("#loginPopupLabel").html('Login/Registration');
	$("#send_otp_btn,#resend_otp_btn,#verify_otp_btn,#user_register_btn").prop('disabled',false);
	$(".add_cart_course_btn").html('Add To Cart');
}

function reset_login_model()
{
	$('#loginPopup').modal('hide');
	$("#redirect_url").val('');
	$("#course_id").val('');
	$("#send_otp_btn").html('Next');
	$(".step-addingNumber").show();
	$('.nextStep-otp').hide();
	$('#registerPopup').modal('hide');
	$('#v_email_id_sep').val('');
	$('#v_mobile_number').val('');
	$("#is_verification_completed").val('No');
	$(".div_select_user_registration").hide();
	$(".frmreset_field").val('');
	$("#getotp").attr('ref','1').prop('checked',true);;
	$("#user_profile_pic").val($("#defualt_user_profile_pic").val());
	$("#loginPopupLabel").html('Login');
	$("#send_otp_btn,#resend_otp_btn,#verify_otp_btn,#user_register_btn").prop('disabled',false);
	$(".add_cart_course_btn").html('Add To Cart');
	
}

function reset_register_model()
{
	$("#redirect_url").val('');
	$("#course_id").val('');
	$("#is_verification_completed").val('No');
	$("#send_otp_btn").html('Next');
	$(".step-addingNumber").show();
	$('.nextStep-otp').hide();
	$('#registerPopup').modal('hide');
	$(".div_select_user_registration").hide();
	$(".frmreset_field").val('');
	$('#otp_and_verify').hide();
	$("#user_profile_pic").val($("#defualt_user_profile_pic").val());
	$("#loginPopupLabel").html('Login');
	$("#send_otp_btn,#resend_otp_btn,#verify_otp_btn,#user_register_btn").prop('disabled',false);
	$(".add_cart_course_btn").html('Add To Cart');
	$('#otp_send_for_verification').html('Send OTP');
	if($("#otp_send_for_verification").hasClass("resend_class")){
		$('#otp_send_for_verification').removeClass('resend_class');
	}
	$('#verify_otp_btn').hide();

}

$(document.body).on('click', '.load_modal, [data-invoke~=modal]', function (e) 
{  
    var loadUrl = $(this).data('href'),
    cacheResult = $(this).data('cache') === 'on',
    $button = $(this);
    $('.modal').remove();
    $('.modal-backdrop').remove();
    $('html').addClass('working');
    $.ajax({
        url: loadUrl,
        data: {},
        localCache: cacheResult,
        dataType: 'html',
        success: function (data) 
        {
            $('body').append(data);
            var $modal = $('.modal');
            $modal.modal({
                'backdrop': 'static'
            });
            $modal.modal('show');
            $modal.on('hidden.bs.modal', function (e) {
                // window
                location.hash = '';
            });
            $('html').removeClass('working');
        }
    }).done().fail(function (data) 
    {
        $('html').removeClass('working');
        $.notify({
          title: "<b class='notify_error_title'>LOAD MODEL POPUP</b>",
          message: MSG_SERVER_SIDE_ERROR
        },{
        	delay: 5000,
          type: 'danger',
          //showProgressbar: true,
          placement: {
            from: "bottom",
            align: "right"
          },
        });
    });
    e.preventDefault();
});


$('form.ajax').ajaxForm(
{
    delegation: true,
    beforeSubmit: function (formData, jqForm, options) 
    {
    	if( typeof(CKEDITOR) !== "undefined" )
      	{
        	for (instance in CKEDITOR.instances) 
        	{
            	CKEDITOR.instances[instance].updateElement();
        	}
      	}          
        $(jqForm[0])
          .find('.error.help-block')
          .remove();
        $(jqForm[0]).find('.has-error')
          .removeClass('has-error');

        var $submitButton = $(jqForm[0]).find('input[type=submit]');
        $($submitButton).html('<i class="fa fa-spinner fa-spin fa-lg"></i>&nbsp; Loading...');
		$($submitButton).prop('disabled',true);
        var $valid = form_valid(jqForm[0]);
        if(!$valid)
        {
        	$($submitButton).html('Submit');
            $($submitButton).prop('disabled',false);
            return false;
        }
    },
    uploadProgress: function (event, position, total, percentComplete) 
    {
        $('.uploadProgress').show().html('Uploading Images - ' + percentComplete + '% Complete...    ');
    },
    error: function (data, statusText, xhr, $form) 
    {
    	if (422 == data.status) 
    	{
	    	$.notify({
	          title: "<b class='notify_error_title'>AJAX FORM SUBMIT</b>",
	          message: $.parseJSON(data.responseText)
	        },{
	        	delay: 5000,
	          type: 'danger',
	          //showProgressbar: true,
	          placement: {
	            from: "bottom",
	            align: "right"
	          },
	        });
	    	return;
	    }

	    if(500 == data.status) 
    	{
	    	$.notify({
	          title: "<b class='notify_error_title'>AJAX FORM SUBMIT</b>",
	          message: MSG_SERVER_SIDE_ERROR
	        },{
	        	delay: 5000,
				type: 'danger',
				//showProgressbar: true,
				placement: {
				from: "bottom",
				align: "right"
	          },
	        });
	    	return;
	    }

        var $submitButton = $form.find('input[type=submit]');
        $($submitButton).prop('disabled',false);
        $('.uploadProgress').hide();
    },
    success: function (data, statusText, xhr, $form) 
    {

        switch (data.status) 
        {
        	
            case 'success':
                
                if ($form.hasClass('reset')) {
                    $form.resetForm();
                }

                if ($form.hasClass('closeModalAfter')) {
                    $('.modal, .modal-backdrop').fadeOut().remove();
                }

                var $submitButton = $form.find('input[type=submit]');
         		$($submitButton).prop('disabled',false);
           
                if (typeof data.message !== 'undefined') {

					$.notify({
			          title: "<b class='notify_error_title'></b>",
			          message:data.message
			        },{
			        	delay: 5000,
						type: 'success',
						placement: {
						from: "bottom",
						align: "right"
			          },
			        });
			        if (typeof data.redirect_url !== 'undefined') 
	                {
						setTimeout(function(){ window.location.href = data.redirect_url; },3500);
	                    return false;
	                }

                }

                if (typeof data.redirect_url !== 'undefined') 
                {

					setTimeout(function(){ window.location.href = data.redirect_url; },3500);
                    return false;
                }
                break;
            case 'error_simple_msg':
           
                $.notify({
		          title: "<b class='notify_error_title'>AJAX FORM SUBMIT</b>",
		          message: data.message
		        },{
		        	delay: 5000,
		          type: 'danger',
		          //showProgressbar: true,
		          placement: {
		            from: "bottom",
		            align: "right"
		          },
		        });
               
                //$($form).reset();
                $($form).trigger("reset");
               
                break;
            case 'search':

                if(data.redirect_url != 'no_redirect') 
                {
					setTimeout(function(){ window.location.href = data.redirect_url; },500);
                    return false;
                }
                else
                {
                	$.notify({
			          title: "<b class='notify_error_title'>Search</b>",
			          message: 'Please enter keyword for search'
			        },{
			        	delay: 5000,
			          type: 'danger',
			          //showProgressbar: true,
			          placement: {
			            from: "bottom",
			            align: "right"
			          },
			        });
                	
                	return false;
                }
                break;
            case 'error':
            	if (typeof data.message !== 'undefined') 
                {
                	if(data.message != "")
                	{
                		var error_msg = data.message;
                	}
                	else
                	{
                		var error_msg = MSG_SERVER_SIDE_ERROR;
                	}
                }
                else
                {
                	var error_msg = MSG_SERVER_SIDE_ERROR;
                }
            	$.notify({
		          title: "<b class='notify_error_title'>AJAX FORM SUBMIT ERROR</b>",
		          message: error_msg
		        },{
		        	delay: 5000,
		          type: 'danger',
		          //showProgressbar: true,
		          placement: {
		            from: "bottom",
		            align: "right"
		          },
		        });
		        
                
                $($form).trigger("reset");
                $('#list').remove();
                $.each(data.messages, function (index, error)
			    {
			        var $input = $(':input[name=' + index + ']', $form);
			        if ($input.prop('type') === 'file') {
			            $('#input-' + $input.prop('name')).append('<div class="help-block error">' + error + '</div>')
			                .parent()
			                .addClass('has-error');
			        } else {
			            $input.after('<div class="help-block error">' + error + '</div>')
			                .parent()
			                .addClass('has-error');
			        }

			    });
			    var $submitButton = $form.find('input[type=submit]');
         		$($submitButton).prop('disabled',false);
			    break;
            default:
                break;
        }
        $('.uploadProgress').hide();
    },
    dataType: 'json'
});

//FILTER RECORD FOR USER START

$(".filter_record").change(function(){
	window.location.href = $(this).data('url')+'?e_filter='+$(this).val();	
})

//FILTER RECORD FOR USER END


//KEYWORD FILTER RECORD FOR USER START

$(".search_record").click(function(){
	if($("#search_keyword").val() != "")
	{
		window.location.href = $(this).data('url')+'?v_search_keyword='+$("#search_keyword").val();	
	}
	else
	{
		$.notify({
          title: "<b class='notify_error_title'>Search By Keyword:</b>",
          message: 'Please enter keyword for search'
        },{
          // settings
          delay: 5000,
          type: 'danger',
          placement: {
            from: "bottom",
            align: "right"
          },
        });
	}
})

//KEYWORD FILTER RECORD FOR USER END


$(".select_all_checkbox").click(function(event) 
{
	if ($(this).is(':checked')) 
    {
        $('.'+$(this).attr('child_checkbox_class')).not(':checked').each(function () 
        {
           $(this).prop('checked', true);
        });
    } 
    else
    {
        $('.'+$(this).attr('child_checkbox_class')).each(function () 
        {
           $(this).prop('checked', false);
        });
    }
    //jQuery.uniform.update('.'+$(this).attr('child_checkbox_class'));
});

$(".child_checkbox_class").click(function(event) 
{
    if ($(this).is(':checked')) 
    {
 		if ($('.'+$(this).attr('other_checkbox_class')+':checkbox:checked').length == $('.'+$(this).attr('other_checkbox_class')+':checkbox').length) 
    	{
	        $('.'+$(this).attr('parent_checkbox_class')).prop('checked', true);
    	}
    	else
    	{
    		$('.'+$(this).attr('parent_checkbox_class')).prop('checked', false);
    	}
    }
    else
    {
       $('#'+$(this).attr('parent_checkbox_id')).prop('checked', false);
    }

    //jQuery.uniform.update('.'+$(this).attr('parent_checkbox_class'));
});
$(".child_checkbox_classs").click(function(event) 
{
    if ($(this).is(':checked')) 
    {
 		if ($('.'+$(this).attr('other_checkbox_classs')+':checkbox:checked').length == $('.'+$(this).attr('other_checkbox_classs')+':checkbox').length) 
    	{
	        $('.'+$(this).attr('parent_checkbox_classs')).prop('checked', true);
    	}
    	else
    	{
    		$('.'+$(this).attr('parent_checkbox_classs')).prop('checked', false);
    	}
    }
    else
    {
       $('#'+$(this).attr('parent_checkbox_ids')).prop('checked', false);
    }

    //jQuery.uniform.update('.'+$(this).attr('parent_checkbox_class'));
});
$(".select_all_checkboxs").click(function(event) 
{
	if ($(this).is(':checked')) 
    {
        $('.'+$(this).attr('child_checkbox_classs')).not(':checked').each(function () 
        {
           $(this).prop('checked', true);
        });
    } 
    else
    {
        $('.'+$(this).attr('child_checkbox_classs')).each(function () 
        {
           $(this).prop('checked', false);
        });
    }
    //jQuery.uniform.update('.'+$(this).attr('child_checkbox_class'));
});
//COURSE UNFAVOURITE CODE START
$("body").on('click','.course_favourite_unfavourite',function()
{
	var $this = $(this);
	var url = $(this).attr('url');
	var status = $(this).attr('status');

	swal(
	{
	  title: 'Are you sure you want to favourite/unfavourite course?',
	  text: "",
	  icon: "warning",
	  //buttons: true,
	  buttons: ["Cancel","Yes"],
	  dangerMode: true,
	})
	.then((confirmed) => 
	{
	  	if (confirmed)
	  	{
	    	$.ajax(
			{
				type: 'post',
			    url:  url,
			    data: {'e_status':status},
			    headers:
			    {
			        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
			    },
			    success: function (response) 
			    {
			    	if(response.status != 'error')
			    	{
			    		$.notify({
				          title: "<b class='notify_success_title'>Course Favourite/Unfavourite:</b>",
				          message: response.message
				        },{
				          // settings
				          delay: 5000,
				          type: 'success',
				          //showProgressbar: true,
				          placement: {
				            from: "bottom",
				            align: "right"
				          },
				        });

			    		if($this.attr('ishide') == 'Yes')
			    		{
			    			$("#"+$this.attr('course_div_id')).fadeOut();
			    		}
			    		else
			    		{
					        if(status == 'Favourite')
					        {
					        	$this.removeClass('fa fa-heart-o fa-lg course_favourite_unfavourite').addClass('fa fa-heart fa-lg course_favourite_unfavourite');
					        	$this.attr('status','UnFavourite');
					        }
					        else
					        {
					        	$this.removeClass('fa fa-heart fa-lg course_favourite_unfavourite').addClass('fa fa-heart-o fa-lg course_favourite_unfavourite');
					        	$this.attr('status','Favourite');
					        }
					    }
			    	}       	
				},
				error: function()
				{
			    	$.notify({
			          title: "<b class='notify_error_title'>Course Favourite/Unfavourite:</b>",
			          message: MSG_SERVER_SIDE_ERROR
			        },{
			          // settings
			          delay: 5000,
			          type: 'danger',
			          //showProgressbar: true,
			          placement: {
			            from: "bottom",
			            align: "right"
			          },
			        });
			    }
			});
	  	}
	});
});
//COURSE UNFAVOURITE CODE END


$("#quiz_sort").change(function(){
	quiz_list();
})

$("#quiz_data_per_page_limit").change(function(){
	quiz_list();
})

$(".mydashboard_category_quiz").click(function(){
	if($(this).attr('catid') != '') {
		$("#quiz_category").val($(this).attr('catid'));
		$("#quiz_category_subject").val('');
		quiz_list();
	}
})

$(".mydashboard_subject_quiz").click(function(){
	if($(this).attr('subjectid') != '') {
		$("#quiz_category_subject").val($(this).attr('subjectid'));
		quiz_list();
	}
})


function quiz_list(){
	var search_query = [];
	
	if($("#search_keyword").length)
	{
		if($("#search_keyword").val() != "")
		{
			search_query.push('v_search_keyword='+$("#search_keyword").val());
		}
	}

	var selectedcat  =  [];
	var selectedsubject = [];
	if($(".select_all_checkbox:checked").length == 0)
	{
		$.each($("input[name='category_filter']:checked"), function()
		{
	        selectedcat.push($(this).val());
	    });
	}


	if($("#quiz_category").length > 0)
	{
		if($("#quiz_category").val() != '')
		{
			selectedcat.push($("#quiz_category").val());
		}
	}

	if(selectedcat.length > 0)
	{
		search_query.push('category='+selectedcat.join(","));
	}
	if($(".select_all_checkboxs:checked").length == 0)
	{
		$.each($("input[name='subject_filter']:checked"), function()
		{
	        selectedsubject.push($(this).val());
	    });
	}


	if($("#quiz_category_subject").length > 0)
	{
		if($("#quiz_category_subject").val() != '' && $("#quiz_category_subject").val() != 0)
		{
			selectedsubject.push($("#quiz_category_subject").val());
		}
	}


	if(selectedsubject.length > 0)
	{
		search_query.push('subject='+selectedsubject.join(","));
	}
	

	if($("input[name='quiz_level']").length)
	{
		if($("input[name='quiz_level']:checked").val() != "")
		{
			search_query.push('e_quiz_level='+$("input[name='quiz_level']:checked").val());
		}
	}

	if($("input[name='quiz_type']").length)
	{
		if($("input[name='quiz_type']:checked").val() != "")
		{
			search_query.push('e_quiz_type='+$("input[name='quiz_type']:checked").val());
		}
	}

	if($("#amount").length)
	{
		if($("#amount").val() > 0 || $("#amount").val() != "")
		{
			search_query.push('amount='+$("#amount").val());
		}
	}

	if($("#quiz_sort").length)
	{
		if($("#quiz_sort").val() > 0 || $("#quiz_sort").val() != "")
		{
			search_query.push('e_sort_type='+$("#quiz_sort").val());
		}
	}


	if($("#quiz_purchased").length > 0)
	{
		if($("#quiz_purchased").val() != '')
		{
			search_query.push('e_quiz_purchased='+$("#quiz_purchased").val());
		}
	}


	if($("#quiz_attended").length > 0)
	{
		if($("#quiz_attended").val() != '')
		{
			search_query.push('e_quiz_attended='+$("#quiz_attended").val());
		}
	}


	if($("#quiz_data_per_page_limit").length)
	{
		if($("#quiz_data_per_page_limit").val() > 0 || $("#quiz_data_per_page_limit").val() != "")
		{
			search_query.push('i_per_page_record_limit='+$("#quiz_data_per_page_limit").val());
		}
	}

	if(search_query.length > 0)
	{
		window.location.href = $("#quiz_list_url").val()+'?'+search_query.join("&");
	}
	else
	{
		window.location.href = $("#quiz_list_url").val();	
	}
}

$(".search_filter").click(function(){
	quiz_list();
})

$(".reset_search_filter").click(function(){
	window.location.href = $("#quiz_list_url").val();
})



function quiz_played_quiz_list(){
	var search_query = [];
	
	
	var selectedcat  =  [];
	var selectedsubject = [];
	


	if($("#quiz_category").length > 0)
	{
		if($("#quiz_category").val() != '')
		{
			selectedcat.push($("#quiz_category").val());
		}
	}

	if(selectedcat.length > 0)
	{
		search_query.push('category='+selectedcat.join(","));
	}
	

	if($("#quiz_category_subject").length > 0)
	{
		if($("#quiz_category_subject").val() != '')
		{
			selectedsubject.push($("#quiz_category_subject").val());
		}
	}


	if(selectedsubject.length > 0)
	{
		search_query.push('subject='+selectedsubject.join(","));
	}
	
	if($("#quiz").length)
	{
		if($("#quiz").val() > 0 || $("#quiz").val() != "")
		{
			search_query.push('i_quiz_id='+$("#quiz").val());
		}
	}

	if($("#start_date_filter").length)
	{
		if($("#start_date_filter").val() != "")
		{
			search_query.push('d_start_date_filters='+$("#start_date_filter").val());
		}
	}

	if($("#end_date_filter").length)
	{
		if($("#end_date_filter").val() != "")
		{
			search_query.push('d_end_date_filters='+$("#end_date_filter").val());
		}
	}


	


	if($("#quiz_data_per_page_limit").length)
	{
		if($("#quiz_data_per_page_limit").val() > 0 || $("#quiz_data_per_page_limit").val() != "")
		{
			search_query.push('i_per_page_record_limit='+$("#quiz_data_per_page_limit").val());
		}
	}

	if(search_query.length > 0)
	{
		window.location.href = $("#quiz_list_url").val()+'?'+search_query.join("&");
	}
	else
	{
		window.location.href = $("#quiz_list_url").val();	
	}
}

$(".quiz_played_search_filter").click(function(){
	quiz_played_quiz_list();
})

$(".quiz_played_reset_search_filter").click(function(){
	window.location.href = $("#quiz_list_url").val();
})


function mock_quiz_played_quiz_list(){
	var search_query = [];
	
	if($("#quiz").length)
	{
		if($("#quiz").val() > 0 || $("#quiz").val() != "")
		{
			search_query.push('i_quiz_id='+$("#quiz").val());
		}
	}

	if($("#start_date_filter").length)
	{
		if($("#start_date_filter").val() != "")
		{
			search_query.push('d_start_date_filters='+$("#start_date_filter").val());
		}
	}

	if($("#end_date_filter").length)
	{
		if($("#end_date_filter").val() != "")
		{
			search_query.push('d_end_date_filters='+$("#end_date_filter").val());
		}
	}


	


	if($("#quiz_data_per_page_limit").length)
	{
		if($("#quiz_data_per_page_limit").val() > 0 || $("#quiz_data_per_page_limit").val() != "")
		{
			search_query.push('i_per_page_record_limit='+$("#quiz_data_per_page_limit").val());
		}
	}

	if(search_query.length > 0)
	{
		window.location.href = $("#quiz_list_url").val()+'?'+search_query.join("&");
	}
	else
	{
		window.location.href = $("#quiz_list_url").val();	
	}
}

$(".mock_quiz_played_search_filter").click(function(){
	mock_quiz_played_quiz_list();
})

$(".mock_quiz_played_reset_search_filter").click(function(){
	window.location.href = $("#quiz_list_url").val();
})


$(".search_text_filter").click(function(){
	if($("#search_keyword").val() != "")
	{
		quiz_list();
	}
	else
	{
		$.notify({
	      title: "<b class='notify_success_title'>Search Course:</b>",
	      message: 'Please enter search text'
	    },{
	      delay: 5000,
	      type: 'danger',
	      placement: {
	        from: "bottom",
	        align: "right"
	      },
	    });
	}
})
//MOCK Quiz 
$("#mock_quiz_sort").change(function(){
	mock_quiz_list();
})

$("#mock_quiz_data_per_page_limit").change(function(){
	mock_quiz_list();
})

function mock_quiz_list(){
	var search_query = [];

	if($("#search_keyword").length > 0)
	{
		if($("#search_keyword").val() != "")
		{
			search_query.push('v_search_keyword='+$("#search_keyword").val());
		}
	}

	var selectedcat  =  [];
	var selectedsubject = [];
	
	if($("input[name='category_filter']").length > 0)
	{
		if($(".select_all_checkbox:checked").length == 0)
		{
			$.each($("input[name='category_filter']:checked"), function()
			{
		        selectedcat.push($(this).val());
		    });
		}
	}

	

	if(selectedcat.length > 0)
	{
		search_query.push('category='+selectedcat.join(","));
	}

	if($("input[name='subject_filter']").length > 0)
	{
		if($(".select_all_checkboxs:checked").length == 0)
		{
			$.each($("input[name='subject_filter']:checked"), function()
			{
		        selectedsubject.push($(this).val());
		    });
		}
	}

	if(selectedsubject.length > 0)
	{
		search_query.push('subject='+selectedsubject.join(","));
	}
	
	
	if($("input[name='mock_quiz_level']").length > 0)
	{
		if($("input[name='mock_quiz_level']:checked").val() != "")
		{
			search_query.push('e_quiz_level='+$("input[name='mock_quiz_level']:checked").val());
		}
	}

	if($("input[name='quiz_type']").length > 0)
	{
		if($("input[name='quiz_type']:checked").val() != "")
		{
			search_query.push('e_quiz_type='+$("input[name='quiz_type']:checked").val());
		}
	}


	if($("#amount").length > 0)
	{
		if($("#amount").val() > 0 || $("#amount").val() != "")
		{
			search_query.push('amount='+$("#amount").val());
		}
	}

	if($("#quiz_purchased").length > 0)
	{
		if($("#quiz_purchased").val() != '')
		{
			search_query.push('e_quiz_purchased='+$("#quiz_purchased").val());
		}
	}


	if($("#quiz_attended").length > 0)
	{
		if($("#quiz_attended").val() != '')
		{
			search_query.push('e_quiz_attended='+$("#quiz_attended").val());
		}
	}


	if($("#mock_quiz_sort").length > 0)
	{
		if($("#mock_quiz_sort").val() > 0 || $("#mock_quiz_sort").val() != "")
		{
			search_query.push('e_sort_type='+$("#mock_quiz_sort").val());
		}
	}

	
	if($("#mock_quiz_data_per_page_limit").length > 0)
	{	
		if($("#mock_quiz_data_per_page_limit").val() > 0 || $("#mock_quiz_data_per_page_limit").val() != "")
		{
			search_query.push('i_per_page_record_limit='+$("#mock_quiz_data_per_page_limit").val());
		}
	}


	if(search_query.length > 0)
	{
		window.location.href = $("#mock_quiz_list_url").val()+'?'+search_query.join("&");
	}
	else
	{
		window.location.href = $("#mock_quiz_list_url").val();	
	}
}

$(".mock_search_filter").click(function(){
	mock_quiz_list();
})

$(".mock_reset_search_filter").click(function(){
	window.location.href = $("#mock_quiz_list_url").val();
})

$(".mock_search_text_filter").click(function(){
	if($("#search_keyword").val() != "")
	{
		mock_quiz_list();
	}
	else
	{
		$.notify({
	      title: "<b class='notify_success_title'>Search Course:</b>",
	      message: 'Please enter search text'
	    },{
	      delay: 5000,
	      type: 'danger',
	      placement: {
	        from: "bottom",
	        align: "right"
	      },
	    });
	}
})

//Notes

$("#notes_sort").change(function(){
	note_list();
})

$("#note_data_per_page_limit").change(function(){
	note_list();
})

$(".mydashboard_category_note").click(function(){
	if($(this).attr('catid') != '') {
		$("#note_category").val($(this).attr('catid'));
		$("#note_category_subject").val('');
		note_list();
	}
})

$(".mydashboard_subject_note").click(function(){
	if($(this).attr('subjectid') != '') {
		$("#note_category_subject").val($(this).attr('subjectid'));
		note_list();
	}
})


function note_list(){

	var search_query = [];
	if($("#search_keyword").length > 0)
	{
		if($("#search_keyword").val() != "")
		{
			search_query.push('v_search_keyword='+$("#search_keyword").val());
		}
	}

	var selectedcat  =  [];
	var selectedsubject = [];
	if($(".select_all_checkbox:checked").length == 0)
	{
		$.each($("input[name='category_filter']:checked"), function()
		{
	        selectedcat.push($(this).val());
	    });
	}

	if($("#note_category").length > 0)
	{
		if($("#note_category").length > 0)
		{
			if($("#note_category").val() != '')
			{
				selectedcat.push($("#note_category").val());
			}
		}
	}


	if(selectedcat.length > 0)
	{
		search_query.push('category='+selectedcat.join(","));
	}
	if($(".select_all_checkboxs:checked").length == 0)
	{
		$.each($("input[name='subject_filter']:checked"), function()
		{
	        selectedsubject.push($(this).val());
	    });
	}


	if($("#note_category_subject").length > 0)
	{
		if($("#note_category_subject").val() != '' && $("#note_category_subject").val() != 0)
		{
			selectedsubject.push($("#note_category_subject").val());
		}
	}

	if(selectedsubject.length > 0)
	{
		search_query.push('subject='+selectedsubject.join(","));
	}
	
	
	if($("input[name='access_type']:checked").val() != "")
	{
		search_query.push('e_access_type='+$("input[name='access_type']:checked").val());
	}
	if($("input[name='type']:checked").val() != "")
	{
		search_query.push('e_type='+$("input[name='type']:checked").val());
	}


	if($("#amount").length > 0)
	{
		if($("#amount").val() > 0 || $("#amount").val() != "")
		{
			search_query.push('amount='+$("#amount").val());
		}
	}

	if($("#notes_sort").length > 0)
	{
		if($("#notes_sort").val() > 0 || $("#notes_sort").val() != "")
		{
			search_query.push('e_sort_type='+$("#notes_sort").val());
		}
	}

	if($("#note_data_per_page_limit").length > 0)
	{
		if($("#note_data_per_page_limit").val() > 0 || $("#note_data_per_page_limit").val() != "")
		{
			search_query.push('i_per_page_record_limit='+$("#note_data_per_page_limit").val());
		}
	}
	
	if(search_query.length > 0)
	{
		window.location.href = $("#note_quiz_list_url").val()+'?'+search_query.join("&");
	}
	else
	{
		window.location.href = $("#note_quiz_list_url").val();	
	}
}

$(".note_search_filter").click(function(){
	note_list();
})

$(".note_reset_search_filter").click(function(){
	window.location.href = $("#note_quiz_list_url").val();
})

$(".note_search_text_filter").click(function(){
	if($("#search_keyword").val() != "")
	{
		note_list();
	}
	else
	{
		$.notify({
	      title: "<b class='notify_success_title'>Search Course:</b>",
	      message: 'Please enter search text'
	    },{
	      delay: 5000,
	      type: 'danger',
	      placement: {
	        from: "bottom",
	        align: "right"
	      },
	    });
	}
})
//DELETE RECORD FOR USER START
$("body").on('click','.delete_record',function()
{
	var $this = $(this);
	var redirect_url = $(this).attr('redirect_url'); 
	var url = $(this).data('href');
	swal(
	{
	  title: 'Are you sure you want to delete record?',
	  text: "",
	  icon: "warning",
	  //buttons: true,
	  buttons: ["Cancel","Yes"],
	  dangerMode: true,
	})
	.then((confirmed) => 
	{
	  	if (confirmed)
	  	{
	    	$.ajax(
			{
				type: 'delete',
			    url:  url,
			    headers:
			    {
			        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
			    },
			    success: function (response) 
			    {
			    	if(response.status != 'error')
			    	{
			    		$.notify({
				          title: "<b class='notify_success_title'>Delete Record:</b>",
				          message: response.message
				        },{
				          // settings
				          delay: 5000,
				          type: 'success',
				          //showProgressbar: true,
				          placement: {
				            from: "bottom",
				            align: "right"
				          },
				        });
				        window.location.href = redirect_url;
			    	}       	
				},
				error: function()
				{
			    	$.notify({
			          title: "<b class='notify_error_title'>Delete Record:</b>",
			          message: MSG_SERVER_SIDE_ERROR
			        },{
			          // settings
			          delay: 5000,
			          type: 'danger',
			          //showProgressbar: true,
			          placement: {
			            from: "bottom",
			            align: "right"
			          },
			        });
			    }
			});
	  	}
	});
});

//DELETE RECORD COMMON CODE FOR USER END


//UPDATE STATUS RECORD FOR USER START

$("body").on('click','.update_status',function()
{
	var $this = $(this);
	var redirect_url = $(this).attr('redirect_url'); 
	var url = $(this).data('href');

	swal(
	{
	  title: 'Are you sure you want to update status?',
	  text: "",
	  icon: "warning",
	  //buttons: true,
	  buttons: ["Cancel","Yes"],
	  dangerMode: true,
	})
	.then((confirmed) => 
	{
	  	if (confirmed)
	  	{
	    	$.ajax(
			{
				type: 'put',
			    url:  url,
			    headers:
			    {
			        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
			    },
			    success: function (response) 
			    {
			    	if(response.status != 'error')
			    	{
			    		$.notify({
				          title: "<b class='notify_success_title'>Update Status:</b>",
				          message: response.message
				        },{
				          // settings
				          delay: 5000,
				          type: 'success',
				          //showProgressbar: true,
				          placement: {
				            from: "bottom",
				            align: "right"
				          },
				        });
				        window.location.href = redirect_url;
			    	}       	
				},
				error: function()
				{
			    	$.notify({
			          title: "<b class='notify_error_title'>Update Status:</b>",
			          message: MSG_SERVER_SIDE_ERROR
			        },{
			          // settings
			          delay: 5000,
			          type: 'danger',
			          //showProgressbar: true,
			          placement: {
			            from: "bottom",
			            align: "right"
			          },
			        });
			    }
			});
	  	}
	});
});

//UPDATE STATUS RECORD COMMON CODE FOR USER END

function list_records()
{
    if($("#list_records").length)
    {
        $('.list-ajax-loading').hide();
        var page = 1;
        var is_ajax_request_completed = "No";
        $(window).scroll(function() 
        { 
        	var position = $(window).scrollTop();
		    var bottom = $(document).height() - $(window).height();
		    if (position > $("#list_records").height()) 
		    {
		    	if (Number(page*$("#per_page_record").val()) <= $("#total_record").val()) 
		    	{
        			page++; //page number increment
	                load_more_record(page); //load content   
            	}
        	}
        });
    }
}




$(".mobile_numberwithtext").keypress(function (e) 
{
    var length = jQuery(this).val().length;
    if(length > 9) 
    {
        return false;
    } 
    else if(e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) 
    {
        return false;
    } 
    else if((length == 0) && (e.which == 48)) 
    {
        return false;
    }
});

$(".otp_numberwithtext").keypress(function (e) 
{
    var length = jQuery(this).val().length;
    if(length > 9) 
    {
        return false;
    } 
    else if(e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) 
    {
        return false;
    } 
});


$("#otp_send_for_mobile_verification").on("click",function(e)
{
	var $this = $(this);
	$($this).html('<i class="fa fa-spinner fa-spin fa-lg"></i>&nbsp; Loading...');
	$($this).prop('disabled',true);

	var regex = /^([0-9])+$/;
	$("#otp_send_for_mobile_verification").prop('disabled',true);
	if($("#countrycode").val() == "")
	{
		swal("Verification","Please select country code","error");
	    $("#verify_mobile_number_otp_btn").prop('disabled',false);
	    $("#otp_send_for_mobile_verification").html("Send OTP");
		$("#otp_send_for_mobile_verification").prop('disabled',false);
	}
	else if($("#mobile_number").val() == "" || $("#mobile_number").val() == "Your mobile number")
	{
		swal("Verification","Please enter mobile number","error");
		$("#otp_send_for_mobile_verification").html("Send OTP");
	    $("#otp_send_for_mobile_verification").prop('disabled',false);
	}
	else if(!regex.test($("#mobile_number").val()))
	{
		swal("Verification","Please enter valid mobile number","error");
		$("#otp_send_for_mobile_verification").html("Send OTP");
		$("#otp_send_for_mobile_verification").prop('disabled',false);
	}
	else if($("#mobile_number").val().length > 10  || $("#mobile_number").val().length < 7 )
	{
		//Allow 7 || 8 || 9 || 10 Digit Contact Number
		swal("Verification","Please enter valid mobile number(7,8,9,10 digit allow)","error");
	    $("#otp_send_for_mobile_verification").html("Send OTP");
	    $("#otp_send_for_mobile_verification").prop('disabled',false);
	}
	else
	{
		$.ajax(
		{
			type: 'post',
	        url: $("#sent_otp").val(),
	        data: {'_token':$( "input[name$='_token']" ).val(),'v_mobile_number':$("#mobile_number").val(),'i_country_id':$("#countrycode").val(),'e_frm_type':$("#mobileverify_frm_type").val()},
	        success: function (response) 
	        {
	        	$("#otp_send_for_mobile_verification").prop('disabled',false);
	        	if(response.status != 'error')
	        	{
	        		$($this).prop('disabled',false);

	        		$("#otp_id_for_mobile_verification").val(response.otp_id);	
	        		$("#verify_mobile_number_otp_btn").show();
	        		$("#mobile_number_otp").val('');
	        		$("#otp_send_for_mobile_verification").attr('customtext','resend');
	        		$("#otp_div").show();
	        		$("#otp_send_for_mobile_verification").html("Resend OTP");
	        		
	        		$.notify({
			          title: "<b class='notify_success_title'>Verification:</b>",
			          message: response.message
			        },{
			          // settings
			          delay: 5000,
			          type: 'success',
			          //showProgressbar: true,
			          placement: {
			            from: "bottom",
			            align: "right"
			          },
			        });

	        	}
	        	else
	        	{
	        		$("#otp_send_for_mobile_verification").html("Send OTP");
	        		$("#otp_send_for_mobile_verification").prop('disabled',false);
	 				swal("Verification",response.message,"error");
	        		$("#otp_send_for_mobile_verification").prop('disabled',false);
	        	}
	        	$("#otp_send_for_mobile_verification").prop('disabled',false);
			}
	  	});
	  	return false;
	}
});

$("#otp_send_for_verification").on("click",function(e)
{
	//alert($("#send_otp_seprate_url").val());
	if($("#otp_send_for_verification").hasClass("resend_class")){
		var type = 'resend';
	} else {
		var type = 'send';
	}
	var $this = $(this);
	$($this).html('<i class="fa fa-spinner fa-spin fa-lg"></i>&nbsp; Loading...');
	$($this).prop('disabled',true);

	var regex = /^([0-9])+$/;

	$("#otp_send_for_verification").prop('disabled',true);
	if($("#countrycode").val() == "")
	{
		swal("Verification","Please select country code","error");
	    $("#verify_otp_btn").prop('disabled',false);
	    $("#otp_send_for_verification").html("Send OTP");
		$("#otp_send_for_verification").prop('disabled',false);
	}
	else if($("#mobile_number").val() == "" || $("#mobile_number").val() == "Phone No.")
	{
		swal("Verification","Please enter mobile number","error");
		$("#otp_send_for_verification").html("Send OTP");
	    $("#otp_send_for_verification").prop('disabled',false);
	}
	else if($("#v_email_id").val() == "" || $("#v_email_id").val() == "Email")
	{
		swal("Verify Email","Please enter email","error");
		$("#otp_send_for_verification").html("Send OTP");
	    $("#otp_send_for_verification").prop('disabled',false);
	}
	// else if(!regex.test($("#mobile_number").val()))
	// {
	// 	swal("Verification","Please enter valid mobile number","error");
	// 	$("#otp_send_for_verification").html("Send OTP");
	// 	$("#otp_send_for_verification").prop('disabled',false);
	// }
	else if($("#mobile_number").val().length > 10  || $("#mobile_number").val().length < 7 )
	{
		swal("Verification","Please enter valid mobile number(7,8,9,10 digit allow)","error");
	    $("#otp_send_for_verification").html("Send OTP");
	    $("#otp_send_for_verification").prop('disabled',false);
	}
	else
	{
		
		$.ajax(
		{

			type: 'post',
	        url:  $("#send_otp_seprate_url").val(),
	        data: {'_token':$( "input[name$='_token']" ).val(),'type':type,'v_mobile_number':$("#mobile_number").val(),'v_email_id':$("#v_email_id").val(),'i_country_id':$("#countrycode").val(),'e_frm_type':$("#frm_type").val()},
	        success: function (response) 
	        {
	        	$("#otp_send_for_verification").prop('disabled',false);
	        	if(response.status != 'error')
	        	{
	        		$($this).prop('disabled',false);

	        		$("#otp_id_for_verification").val(response.otp_id);
	        		$("#sms_otp_id").val(response.otp_id);	
	        		$("#otp_send_for_verification").addClass('resend_class');
	        		if(!$("#otp_send_for_verification").hasClass("resend_class")){
						$("#otp_send_for_verification").addClass('resend_class');
					}	
	        		$("#verify_otp_btn").show();
	        		$("#otp_div").show();
	        		$("#mobile_number_otp").val('');
	        		$('#mobile_number').val($("#mobile_number").val());
	        		$('#user_hidden_phone_number').val($("#mobile_number").val());
	        		$('#email_temp').val($("#v_email_id").val());
	        		$('#user_country_id').val($("#countrycode").val());
	        		$("#otp_send_for_verification").attr('customtext','resend');
	        		$("#otp_and_verify").show();
	        		$("#otp_send_for_verification").html("Resend OTP");
	        		
	        		
			        swal("Verification",response.message,"success");


	        	}
	        	else
	        	{
	        		$("#otp_send_for_verification").html("Send OTP");
	        		$("#otp_send_for_verification").prop('disabled',false);
	 				swal("Verification",response.message,"error");
	        		$("#otp_send_for_verification").prop('disabled',false);
	        	}
	        	$("#otp_send_for_verification").prop('disabled',false);
			}
	  	});
	  	return false;
	}
});

$("#verify_mobile_number_otp_btn").on("click",function(e)
{
	var $this = $(this);
	$($this).html('<i class="fa fa-spinner fa-spin fa-lg"></i>&nbsp; Loading...');
	$($this).prop('disabled',true);

					
	if($('#otp_id_for_mobile_verification').val() == $('#mobile_number_otp').val())
    {
		$("#verify_mobile_number_otp_btn").html("Verify");
		$("#verify_mobile_number_otp_btn").prop('disabled',false);

		$("#mobile_number_temp").val($("#mobile_number").val());
		$("#countrycode_temp").val($("#countrycode_temp").val());

		$.notify({
          title: "<b class='notify_success_title'>Verification:</b>",
          message: "Mobile number verification successfully."
        },{
          // settings
          delay: 5000,
          type: 'success',
          //showProgressbar: true,
          placement: {
            from: "bottom",
            align: "right"
          },
        });
		
		$("#is_mobile_number_verified").val('Yes');
		$("#mobile_number").prop('disabled',true);
		$("#countrycode").prop('disabled',true);
		$("#otp_div").fadeOut();
		$("#verify_otp_send_otp_btn").fadeOut();

	}
	else
	{
		$("#verify_mobile_number_otp_btn").html("Verify");
		$("#verify_mobile_number_otp_btn").prop('disabled',false);

		$(this).prop('disabled',false);
		$("#mobile_number_otp").val('');
			
			swal("Verification",response.message,"error");
		$("#verify_mobile_number_otp_btn").prop('disabled',false);
	}
	$("#verify_mobile_number_otp_btn").prop('disabled',false);
			
	
});
$("#verify_otp_btn").on("click",function(e)
{
	var $this = $(this);
	$($this).html('<i class="fa fa-spinner fa-spin fa-lg"></i>&nbsp; Loading...');
	$($this).prop('disabled',true);



	var regex = /^([0-9])+$/;
	$("#verify_otp_btn").prop('disabled',true);	
	if($("#countrycode").val() == "")
	{
		swal("Verification","Please select country code","error");
	 	$("#verify_otp_btn").html("Verify");
	    $("#verify_otp_btn").prop('disabled',false);	        
	}
	else if($("#mobile_number").val() == "" || $("#mobile_number").val() == "Your mobile number")
	{
		swal("Verification","Please enter mobile number","error");
		$("#verify_otp_btn").html("Verify");
	    $("#verify_otp_btn").prop('disabled',false);
	}
	else if(!regex.test($("#mobile_number").val()))
	{
		swal("Verification","Please enter valid mobile number","error");
		$("#verify_otp_btn").html("Verify");
	    $("#verify_otp_btn").prop('disabled',false);
	}
	else if($("#mobile_number").val().length > 10  || $("#mobile_number").val().length < 7 )
	{
		swal("Verification","Please enter valid mobile number(7,8,9,10 digit allow)","error");
		$("#verify_otp_btn").html("Verify");
	    $("#verify_otp_btn").prop('disabled',false);
	}
	else if($("#mobile_number_otp").val() == "" || $("#mobile_number_otp").val() == "Enter otp")
	{
		swal("Verification","Please enter otp","error");
		$("#verify_otp_btn").html("Verify");
	    $("#verify_otp_btn").prop('disabled',false);
	}
	else
	{
		var inputdata = {'_token':$( "input[name$='_token']" ).val(),'v_email_id':$("#v_email_id").val(),'v_mobile_number':$("#mobile_number").val(),'v_sms_otp_id':$("#otp_id_for_verification").val(),'v_otp':$("#mobile_number_otp").val(),'i_country_id':$("#countrycode").val(),'e_frm_type':$("#mobileverify_frm_type").val()};
					
		$.ajax(
		{
			type: 'post',
	        url: $("#verify_otp_seprate_url").val(),
	        data: inputdata,
	        success: function (response) 
	        {
	        	if(response.status != 'error')
	        	{
	        		$("#is_verification_completed").val("Yes");

	        		$("#verify_otp_btn").html("Verify");
	        		$("#verify_otp_btn").prop('disabled',false);

	        		$("#mobile_number_temp").val($("#mobile_number").val());
	        		$("#countrycode_temp").val($("#countrycode_temp").val());
	        		$("#v_email_id_verify").val($("#v_email_id").val());
	        		
	        		
					swal("Verification","Verification Success","success");
					$("#is_mobile_number_verified").val('Yes');
					$("#user_register_btn").html('Submit');
            		$("#user_register_btn").prop('disabled',false);
	        		$("#mobile_number").prop('disabled',true);
	        		$("#v_email_id").prop('disabled',true);
	        		$("#countrycode").prop('disabled',true);
	        		$("#otp_and_verify").hide();
	        		$("#verify_otp_btn").hide();
	        		$("#otp_send_for_verification").hide();
	        		$("#otp_div").fadeOut();
	        		$("#verify_otp_send_otp_btn").fadeOut();

	        	}
	        	else
	        	{
	        		$("#verify_otp_btn").html("Verify");
	        		$("#verify_otp_btn").prop('disabled',false);

	    			$(this).prop('disabled',false);
	        		$("#mobile_number_otp").val('');
	 				
	 				swal("Verification",response.message,"error");
	    			$("#verify_otp_btn").prop('disabled',false);
	        	}
	        	$("#verify_otp_btn").prop('disabled',false);
			}
	  	});
	  	return false;
	}
});


$("#submit_btn_contactus").on("click",function()
{	
	var $this = $(this);
	$($this).html('<i class="fa fa-spinner fa-spin fa-lg"></i>&nbsp; Loading...');
	$($this).prop('disabled',true);
	var msg = "";
	if($("#is_mobile_number_verified").val() == 'Yes')
	{
		if($("#contactus_name").val() != "" && $("#contactus_name").val() != 'Your Name*')
		{
			if($("#contactus_email").val() != "" && $("#contactus_email").val() != 'Email Address*')
			{
				if($("#contactus_title").val() != "" && $("#contactus_title").val() != 'Title*')
				{
					if($("#contactus_message").val() != "" && $("#contactus_message").val() != 'Message')
					{
						$.ajax(
						{
							//contentType: "application/json",
				            type: 'post',
				            url: $("#contactus-form").attr('action'),
				            data: $("#contactus-form").serialize(),
				            success: function (response) 
				            {
				            	if(response.status != 'error')
				            	{
				            		$.notify({
								      title: "<b class='notify_error_title'>Contact Us:</b>",
								      message: response.message
								    },{
								      // settings
								      delay: 5000,
								      type: 'success',
								      placement: {
								        from: "bottom",
								        align: "right"
								      },
								    });
								    location.reload();
								}
				            	else
				            	{
				            		try
				            		{
				            			$.notify({
									      title: "<b class='notify_error_title'>Contact Us:</b>",
									      message: response.messages.email
									    },{
									      // settings
									      delay: 5000,
									      type: 'danger',
									      placement: {
									        from: "bottom",
									        align: "right"
									      },
									    });
				            		}
				            		catch(err)
				            		{
				            			$("#contactus-form").trigger("reset");
										$.notify({
									      title: "<b class='notify_error_title'>Contact Us:</b>",
									      message: response.message
									    },{
									      // settings
									      delay: 5000,
									      type: 'danger',
									      placement: {
									        from: "bottom",
									        align: "right"
									      },
									    });
									}
				            	}
				            }
			          	});
			          	return false;

					}
					else
					{
						msg = "Please enter your message.";
					}
				}
				else
				{
					msg = "Please enter title.";
				}
			}
			else
			{
				msg = "Please enter your email address.";
			}
		}
		else
		{
			msg = "Please enter your name.";
		}
	}
	else
	{
		msg = "Please complete verification before submit contact us request.";
	}
	if(msg != "")
	{
		$($this).html('Send Message >');
		$($this).prop('disabled',false);

		$.notify({
	      title: "<b class='notify_error_title'>Contact Us:</b>",
	      message: msg
	    },{
	      // settings
	      delay: 5000,
	      type: 'danger',
	      placement: {
	        from: "bottom",
	        align: "right"
	      },
	    });
	}

});

//ORDER FILTER RECORD FOR USER START

$(".search_order_btn").click(function()
{
	if($("#search_keyword").val() != "" || $("#order_date_filter").val() != "")
	{
		var search_query = [];
		if($("#search_keyword").val() != "")
		{
			search_query.push('v_search_keyword='+$("#search_keyword").val());
		}
		if($("#start_date_filter").val() != "")
		{
			search_query.push('start_date_filter='+$("#start_date_filter").val());
		}
		if($("#end_date_filter").val() != "")
		{
			search_query.push('end_date_filter='+$("#end_date_filter").val());
		}
		window.location.href = $("#order_url").val()+'?'+search_query.join("&");;
	}
	else
	{
		$.notify({
          title: "<b class='notify_error_title'>Search By Keyword/Date Filter:</b>",
          message: 'Please enter keyword for search or select date'
        },{
          // settings
          delay: 5000,
          type: 'danger',
          placement: {
            from: "bottom",
            align: "right"
          },
        });
	}
})

$(".reset_order_btn").click(function()
{
	window.location.href = $("#order_url").val();
})

//ORDER FILTER RECORD FOR USER END

$(".video_content").click(function()
{
	
    if ($("#video_iframe").length)
    {
    	$('.video_fa_icons').removeClass('fa-pause-circle').addClass('fa-play-circle');	
    	$('#videofaicon_content_'+$(this).attr('contentid')).addClass('fa-pause-circle');
    	$('.textcolor').css("color", "#1a1f22");
    	$('#textcolor_subject_'+$(this).attr('subjectid')).css("color", "#28a745");
    	$('#textcolor_content_'+$(this).attr('contentid')).css("color", "#28a745");
        $("#video_iframe").attr('src',$(this).attr('video_url'));

        $("#subject_content_description").text('""'+$(this).attr('subjectdescription')+'""');
        $("#subject_content_title").text($(this).attr('subjectcontenttitle'));	
        return false;
    }
    return true;
})


$(".pdf_content").click(function()
{
    if($("#course_view_pdf_url").val() != "")
    {
    	$("#subject_content_description").text('""'+$(this).attr('subjectdescription')+'""');
        $("#subject_content_title").text($(this).attr('subjectcontenttitle'));

    	$('.textcolor').css("color", "#1a1f22");
    	$('#textcolor_subject_'+$(this).attr('subjectid')).css("color", "#28a745");
    	$('#textcolor_content_'+$(this).attr('contentid')).css("color", "#28a745");	
        var course_pdf = PDFObject.embed($(this).attr('pdf_url'), "#pdf", options);
        var el = document.querySelector("#results");
        el.innerHTML = (course_pdf);
        return false;
    }
    return true;
})


$(".image_content").click(function()
{
    if ($(this).attr('content_images') != "")
    {
    	$("#subject_content_description").text('""'+$(this).attr('subjectdescription')+'""');
        $("#subject_content_title").text($(this).attr('subjectcontenttitle'));
        
    	subject_content_img_slider.destroy();
    	$('.subject_content_img').empty();
		$("#total_img_content_count").html($(this).attr('content_images_count'));
		subject_content_img_slider = $('.subject_content_img').lightSlider({
            gallery: true,
            item: 1,
            loop: true,
            slideMargin: 0,
            thumbItem: $(this).attr('content_images_count'),
            onBeforeSlide: function (el) 
            {
                $('#counter').text(el.getCurrentSlideCount());
            }
        });  

		content_images = $.parseJSON($(this).attr('content_images'));

		$.each(content_images, function(index, value)
    	{
            var image_html = '<li style="width:169px !important" data-thumb="'+value+'" class="lslide"> <a href="javascript:void(0)"><img src="'+value+'" /></a> </li>';
	        $('.subject_content_img').prepend(image_html);
    	});
    	subject_content_img_slider.refresh();
        

    	$('.textcolor').css("color", "#1a1f22");
    	$('#textcolor_subject_'+$(this).attr('subjectid')).css("color", "#28a745");
    	$('#textcolor_content_'+$(this).attr('contentid')).css("color", "#28a745");

        return false;
    }
    return true;
})

$(".user_speciality").change(function(e) 
    {
        if ($(this).is(':checked')) 
        {
            var current_selected_speciality = parseInt($("#current_user_selected_speciality_count").val()) + 1;
            $("#user_selected_speciality_count").html(current_selected_speciality);
            $("#current_user_selected_speciality_count").val(parseInt(current_selected_speciality));
        } 
        else 
        {
            var current_selected_speciality = parseInt($("#current_user_selected_speciality_count").val()) - 1;
            $("#user_selected_speciality_count").html(current_selected_speciality);
            $("#current_user_selected_speciality_count").val(parseInt(current_selected_speciality));
        }
    });
$("input[type='radio'].radioBtnClass").click(function()
{
    if($("input[type='radio'].radioBtnClass").is(':checked')) 
    {
    	var radioValue = $("input[type='radio'].radioBtnClass:checked").val();
    	if(radioValue == 'Get OTP On Mobile')
    	{
    		$('#login_email').hide(1000);
    		$('#login_mobile').show(1000);
    	}
    	else
    	{
    		$('#login_mobile').hide(1000);
    		$('#login_email').show(1000);
    	}
	}
});
function bootstrapTabControl(){
var i, items = $('.nav-item'), pane = $('.tab-pane');
var preloaderHTML = '<div class="tab-preloader"><div class="preload"></div></div>';


// tab preloader
$('button[data-toggle="tab"]').on('shown.bs.tab', function (e) {
$('.tab-content>.active .coursetype-slider').css({'opacity': 0});
$('.tab-content>.active').append(preloaderHTML);
setTimeout(function() {
    $('.tab-preloader').remove();
    $('.tab-content>.active .coursetype-slider').css({'opacity': 1});
}, 1000);
});
}
bootstrapTabControl();

$(function() {
	var minimum =  parseInt($('#quiz_min').val());
	var maximum = parseInt($('#quiz_max').val());
    $("#slider-range-price" ).slider({
        range: true,
        min: minimum,
        max: maximum,
        values: [ minimum, maximum ],
        slide: function( event, ui ) {
        $( "#amount" ).val( "" + ui.values[ 0 ] + "-" + ui.values[ 1 ] );
        }
    });
        $( "#amount" ).val( "" + $( "#slider-range-price" ).slider( "values", 0 ) +
    "-" + $( "#slider-range-price" ).slider( "values", 1 ) );
});

var _token = $('meta[name="csrf-token"]').attr('content');
var mockUrl = $('#mock_quiz_favourite_unfavourite_url').val();
var notesFavUrl = $('#notes_favourite_unfavourite_url').val();
var quizFavUrl = $('#quiz_favourite_unfavourite_url').val();

$(document).on('click','.FavMockQuiz', function() {
    var ref_id = $(this).attr('ref_id');
    var i_quiz_id = $('#i_quiz_id_'+ref_id).val();
    var e_status = $('#e_status_'+ref_id).val();
	$.ajax({
        headers: {
            'x-csrf-token': _token
        },
        method: 'POST',
        url: mockUrl,
        dataType: "json",
        data: {
            _method: 'POST',
            i_quiz_id:i_quiz_id,
            e_status:e_status
        }
    })
    .done(function(result) {
        if(result.success != true){
            $.notify({title: "",message: result.message},{
              type: 'error',placement: {from: "bottom",align: "right"},
            });
        }
        else{
            if(e_status == 'Yes'){
                $('#e_status_'+ref_id).val('No');
                $('#fav_unfav_'+ref_id).addClass('fa-heart');
                $('#fav_unfav_'+ref_id).removeClass('fa-heart-o');
                
            } else {
                $('#e_status_'+ref_id).val('Yes');
                $('#fav_unfav_'+ref_id).removeClass('fa-heart');
                $('#fav_unfav_'+ref_id).addClass('fa-heart-o');
            }
            $.notify({title: "",message: result.message},{
                type: 'success',placement: {from: "bottom",align: "right"},
            });
        }
    })
});

$(document).on('click','.FavNotes', function() {
    var ref_id = $(this).attr('ref_id');
    var i_note_id = $('#i_note_id_'+ref_id).val();
    var e_status = $('#e_note_status_'+ref_id).val();
    $.ajax({
        headers: {
            'x-csrf-token': _token
        },
        method: 'POST',
        url: notesFavUrl,
        dataType: "json",
        data: {
            _method: 'POST',
            i_note_id:i_note_id,
            e_status:e_status
        }
    })
    .done(function(result) {
        if(result.success != true){
            $.notify({title: "",message: result.message},{
              type: 'error',placement: {from: "bottom",align: "right"},
            });
        }
        else{
            if(e_status == 'Yes'){
                $('#e_note_status_'+ref_id).val('No');
                $('#fav_unfav_note_'+ref_id).addClass('fa-heart');
                $('#fav_unfav_note_'+ref_id).removeClass('fa-heart-o');
                
            } else {
                $('#e_note_status_'+ref_id).val('Yes');
                $('#fav_unfav_note_'+ref_id).removeClass('fa-heart');
                $('#fav_unfav_note_'+ref_id).addClass('fa-heart-o');
            }
            $.notify({title: "",message: result.message},{
                type: 'success',placement: {from: "bottom",align: "right"},
            });
        }
    })
});

$(document).on('click','.FavQuiz', function() {
    var ref_id = $(this).attr('ref_id');
    var i_quiz_id = $('#i_quizs_id_'+ref_id).val();
    var e_status = $('#e_status_quiz_'+ref_id).val();
    $.ajax({
        headers: {
            'x-csrf-token': _token
        },
        method: 'POST',
        url: quizFavUrl,
        dataType: "json",
        data: {
            _method: 'POST',
            i_quiz_id:i_quiz_id,
            e_status:e_status
        }
    })
    .done(function(result) {
        if(result.success != true){
            $.notify({title: "",message: result.message},{
              type: 'error',placement: {from: "bottom",align: "right"},
            });
        }
        else{
            if(e_status == 'Yes'){
                $('#e_status_quiz_'+ref_id).val('No');
                $('#fav_unfav_quiz_'+ref_id).addClass('fa-heart');
                $('#fav_unfav_quiz_'+ref_id).removeClass('fa-heart-o');
                
            } else {
                $('#e_status_quiz_'+ref_id).val('Yes');
                $('#fav_unfav_quiz_'+ref_id).removeClass('fa-heart');
                $('#fav_unfav_quiz_'+ref_id).addClass('fa-heart-o');
            }
            $.notify({title: "",message: result.message},{
                type: 'success',placement: {from: "bottom",align: "right"},
            });
        }
    })
});


$(document).on('click', '.modal_popup', function(e){
    e.preventDefault();
    var url = $(this).data('url');
    var modalpopup = $(this).data('modalpopup');
    $('.modal-content').html(''); 
    
    $('#status').fadeOut();
    $('#preloader').delay(350).fadeOut('slow');
   	
    $.ajax({
        url: url,
        type: 'GET',
        dataType: 'html'
    })
    .done(function(data){
        $('.modal-content').html('').html(data); // load response 
        $('#status').fadeOut();
    	$('#preloader').delay(350).fadeOut('slow');
        $("#"+modalpopup).modal('show');
    })
    .fail(function(){
        $('#dynamic-content').html('<i class="glyphicon glyphicon-info-sign"></i> Something went wrong, Please try again...');
        $('#status').fadeOut();
    	$('#preloader').delay(350).fadeOut('slow');
    });
});
$(document).on('click','.place_order', function() {
    var $this = $(this);
    if($('.checkbox_order_place_termscondition').is(":checked"))
    {
        swal(
        {
          title: 'Are you sure you want to place order ?',
          text: "",
          icon: "warning",
          buttons: ["Cancel","Yes"],
          dangerMode: true,
        })
        .then((confirmed) => 
        {
            if (confirmed)
            {
                $($this).html('<i class="fa fa-spinner fa-spin fa-lg"></i>&nbsp; Loading...');
                $($this).prop('disabled',true);

                $.ajax(
                {
                    type: 'post',
                    url:  $("#order_place").val(),
                    data: {
                        'id':$("#send_data_id").val(),
                        'type':$("#send_data_type").val(),
                        'total_original_amount':$("#total_original_amount").val(),
                        'total_discounted_amount':$("#total_discounted_amount").val(),
                        'total_final_amount':$("#total_final_amount").val(),
                        'total_gst_amount':$("#total_gst_amount").val(),
                        'gst_percentage':$("#gst_percentage").val(),
                        't_notes':$("#t_notes").val()},
                    headers:
                    {
                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    },
                    success: function (response) 
                    {
                        if(response.status != 'error')
                        {
                            if(response.is_free_course_order == "Yes")
                            {
                                $.notify({
                                  title: "<b class='notify_success_title'>Order Place:</b>",
                                  message: response.message
                                },{
                                  delay: 5000,
                                  type: 'success',
                                  placement: {
                                    from: "bottom",
                                    align: "right"
                                  },
                                });
                                window.location.href = response.redirect_url;
                            }
                            else
                            {
                                $.notify({
                                  title: "<b class='notify_success_title'>Order Place:</b>",
                                  message: response.message
                                },{
                                  delay: 5000,
                                  type: 'success',
                                  placement: {
                                    from: "bottom",
                                    align: "right"
                                  },
                                });
                                window.location.href = response.redirect_url;
                            }
                        }
                        else
                        {
                            $.notify({
                              title: "<b class='notify_success_title'>Order Place:</b>",
                              message: response.message
                            },{
                              delay: 5000,
                              type: 'danger',
                              placement: {
                                from: "bottom",
                                align: "right"
                              },
                            });
                            $($this).prop('disabled',false);
                        }
                    },
                    error: function()
                    {
                        $.notify({
                          title: "<b class='notify_error_title'>Order Place:</b>",
                          message: MSG_SERVER_SIDE_ERROR
                        },{
                          delay: 5000,
                          type: 'danger',
                          placement: {
                            from: "bottom",
                            align: "right"
                          },
                        });
                        $($this).prop('disabled',false);
                    }
                });
            }
        });
    }
    else
    {
        $.notify({
          title: "<b class='notify_error_title'>Order Place:</b>",
          message: "Please agree terms condition before order place"
        },{
          delay: 5000,
          type: 'danger',
          placement: {
            from: "bottom",
            align: "right"
          },
        });
    }
})
$('.filterToggle-btn').click(function(){
 $('.filterToggle').toggle();
});

$('.closeBtn-toggle').click(function(){
    $('.filterToggle').hide();
});


$(function () {
  $('[data-toggle="tooltip"]').tooltip()
})
$("[data-toggle=popover]")
.popover({html:true})
