/* Hotjar */
(function(h,o,t,j,a,r){
    h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};
    h._hjSettings={hjid:807847,hjsv:6};
    a=o.getElementsByTagName('head')[0];
    r=o.createElement('script');r.async=1;
    r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;
    a.appendChild(r);
})(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');


/* Drift */
!function() {
    var t;
    if (t = window.driftt = window.drift = window.driftt || [], !t.init) return t.invoked ? void (window.console && console.error && console.error("Drift snippet included twice.")) : (t.invoked = !0, 
    t.methods = [ "identify", "config", "track", "reset", "debug", "show", "ping", "page", "hide", "off", "on" ], 
    t.factory = function(e) {
      return function() {
        var n;
        return n = Array.prototype.slice.call(arguments), n.unshift(e), t.push(n), t;
      };
    }, t.methods.forEach(function(e) {
      t[e] = t.factory(e);
    }), t.load = function(t) {
      var e, n, o, i;
      e = 3e5, i = Math.ceil(new Date() / e) * e, o = document.createElement("script"), 
      o.type = "text/javascript", o.async = !0, o.crossorigin = "anonymous", o.src = "https://js.driftt.com/include/" + i + "/" + t + ".js", 
      n = document.getElementsByTagName("script")[0], n.parentNode.insertBefore(o, n);
    });
  }();
  drift.SNIPPET_VERSION = '0.3.1';
  drift.load('c9twm4i9hgxa');

$.urlParam = function(name){
    var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
    if (results==null){
       return null;
    }
    else{
       return decodeURI(results[1]) || 0;
    }
}

var Script = function () {
    $.validator.setDefaults({
        submitHandler: function() { 
           var password=$("#password").val();
           var confirm_password=$("#confirm-password").val();
           var reset_token= $.urlParam('reset-token');
           var dataString = 'password=' + password + '&confirm_password=' + confirm_password + '&reset_token=' +reset_token;
           console.log(dataString);
           if ($.trim(password).length > 0){
             $.ajax({
                type: "POST",
                url: "/reset-password/reset",
                data: dataString,
                cache: false,
                beforeSend: function(){ 
                    $("#status").html('<p>Connecting to server....</p>');
                },
                complete: function(e, xhr, settings){
                    if(e.status === 200){
                        $("#status").html("<span style='color: #00CC96;'>Success:</span> Redirecting to login.");
                        setTimeout(function () {
                            window.location.href = "/dashboard"; // The URL that will be redirected too.
                        }, 3000);
                    }else{
                        //Shake animation effect.
                        $('form').shake();
                        $("#status").html("<span style='color:#cc0000'>Error:</span> Please contact support. ");
                    }
                }
                
            }); 
		}
        return false;
        }
    });
	
    $().ready(function() {
        $("#register-form").validate({
			doNotHideMessage: true,
			errorElement: 'span', //default input error message container
			errorClass: 'help-block help-block-error', // default input error message class
			focusInvalid: false,
            rules: {
                password: {
                    required: true
                },
                
            },
            messages: {
                
                password: {
					required: 'password field is required!',
                },
                
            }
        });

		              // checks form for validity
	
        // propose username by combining first- and lastname
       
    });
	
	
	

}();