/**
 * @author taochengzhou
 */
var S = {};
S.submitfrm = function(e, err_id){
	var idObj = $('#txt_passportid');
	var pwdObj = $('#txt_passwd');
	
	if(e.keyCode == 13){
		var id = idObj.val();
		var pswd = pwdObj.val();
		
		if( id && pswd ){
			S.validate( err_id );
		}else if( id ){
			pwdObj.focus();
			T.error(err_id, getLang('empty_login_password'));
		}else{
			idObj.focus();
			T.error(err_id, getLang('empty_login_passport_id'));
		}
	}
};
S.validateToggle = 0;
S.validate = function(err_id){
	if(S.validateToggle){
		T.error(err_id, getLang('wait_for_login_submit'));
		return;
	}
	S.validateToggle = 1;
	var id = $('#txt_passportid').val();
	var pswd = $('#txt_passwd').val();
	
	if(id && pswd){
        $.ajax({
            type: "POST",
            url: ui_service + "ui_validate.php",
            dataType: 'json',
            data: { name:id, pswd: pswd },
            timeout: 30000,
            success: function(json){
				S.validateToggle = 0;
                if (json.code === RETURN_CODE.SUCCESS) {
                	SSO.LoginActivateFunction();
                }
                else {
                    T.error(err_id, json.msg);
                }
            },
			error:function(){
				S.validateToggle = 0;
				T.error(err_id, getLang('http_request_faild'));
			}
        });
	}else if( id ){
		S.validateToggle = 0;
		$('#txt_passwd').focus();
		T.error(err_id, getLang('empty_login_password'));
	}else{
		S.validateToggle = 0;
		$('#txt_passportid').focus();
		T.error(err_id, getLang('empty_login_passport_id'));
	}
};
SSO.LoginActivateFunction = function(){
	var refererUrl = SSO.Referer();
	if(refererUrl){
		redirect( refererUrl );
	}else{
		redirect( ui_main );
	}
};
