var base_path = "/sk";

function showErrorMsg(msg, el) {
	if (msg == undefined || msg.length < 1)
		$("#error_msg").html('').hide();
	else
		$("#error_msg").html(msg).show();
	if (el != undefined) {
		$('#' + el).select();
		$('#' + el).focus();
	}
}
function keyDownElement(event, object) {
	$("#error_msg").html('').hide();
	if (event.keyCode == 13) {
		if (object.id == 'login_name') {
			document.getElementById('login_pass').focus();
			return;
		}

		if (object.id == 'login_pass') {
			document.getElementById('BtnLogin').focus();
			return;
		}
		object.click();
	}
}
function login() {
	var login_name = $.trim($('#login_name').val());
	var login_pass = $.trim($('#login_pass').val());
	$("#error_msg").html('').hide();
	if (login_name.length < 1) {
		showErrorMsg('请输入正确的登录名称', 'login_name');
		return false;
	}
	if (login_pass < 3) {
		showErrorMsg('登录密码不能少于3位', 'login_pass');
		return false;
	}

	// 所有客户端验证成功,提交服务器验证
	$(":button").attr("disabled", "disabled");


  $.ajax({
    type : 'POST',
	//url : base_path + '/frame/optr/login.htm',
	url : base_path + '/school/school/login.htm',
    data : {
	  school_code : login_name,
      login_pass : login_pass,//md5(login_pass),
      valid_code : '1234'
    },
    dataType : 'json',
    success : function(data) {
      if (data.success == false) {
        // 刷新验证码
        showErrorMsg(data.errorMsg);
        $(":button").removeAttr("disabled");
        return;
      } else {
        window.location = '../../index.html';
      }
      $(":button").removeAttr("disabled");
    },
    error : function() {
      $(":button").removeAttr("disabled");
    }
  });
	return false;
}
