$(document).ready(function(){
	$('#login_frm').validate({
		ignore: [], 
		highlight: function(element) {
			$(element).closest('.form-group').removeClass('has-success').addClass('has-error'); 
		},
		success: function(element) {
			element.closest('.form-group').removeClass('has-error').addClass('has-success');
			element.remove();
		},
		submitHandler: function(form){
			var ajax_base_url = $('#h_ajax_base_url').val();
			var form = $('#login_frm');
			var url = ajax_base_url+form.attr('action');
			$.ajax({
				type: "POST",
				url: url,
				data: form.serialize(), // serializes the form's elements.
				beforeSend: function(){
					$('#result_display').html('');
					$('#main_login_btn').html('Please Wait <i class="fa fa-spinner fa-spin"></i>');
					$('#main_login_btn').css('opacity','0.7');
				},
				success: function(result, status, xhr){//alert(result);
					if(result=='success'){
						var chk_active_step = parseInt($('#active_step').val());
						if(chk_active_step==1){
							$('#stepone').hide();
							$('#date_of_birth').addClass('required');
							$('#active_step').val('2');
							$('#steptwo').show();
							$('#main_login_btn').html('<i class="fas fa-sign-in-alt"></i> Login Securely');
							$('#main_login_btn').css('opacity','1');
						}else{
							var h_redirect_url = $('#h_redirect_url').val();
							if(h_redirect_url!=''){
								window.location=h_redirect_url;
							}else{
								var h_base_url = $('#h_base_url').val();
								window.location=h_base_url+'dashboard';
							}
						}
					}else{
						$("html, body").animate({ scrollTop: 0 }, "slow");
						$('#result_display').html('<div class="alert alert-danger">'+result+'</div>');
						$('#main_login_btn').html('<i class="fas fa-sign-in-alt"></i> Login Securely');
						$('#main_login_btn').css('opacity','1');
					}
				},
				error: function(xhr, status, error_desc){				
					$("html, body").animate({ scrollTop: 0 }, "slow");
					$('#result_display').html('<div class="alert alert-danger">'+error_desc+'</div>');
					$('#main_login_btn').html('<i class="fas fa-sign-in-alt"></i> Login Securely');
					$('#main_login_btn').css('opacity','1');
				}
			});		
			return false;
		}
	});
});