var gDebug = 0;

/*
 *  CGCAPIATL ��������ѼƩw�q
 */
var CGCAPI_FLAG_SELCERT_MANUAL = 0x00000001;
var CGCAPI_FLAG_SELCERT_AUTO = 0x00000002;
var CG_KU_DIGITAL_SIGNATURE = 0x0080;
var CG_KU_KEY_ENCIPHERMENT = 0x0020;
var CG_KU_DATA_ENCIPHERMENT = 0x0010;

var CG_FLAG_SUBJECT_PARTIALMATCH = 0x00080000;
var CGCAPI_FLAG_SELCERT_AFTER = 0x00000004;
var CGCAPI_FLAG_SELCERT_CHECKVALID = 0x00000010;
var CGCAPI_FLAG_SELCERT_AUTO = 0x00000002;

var CG_FLAG_VERIFY_CONTENT_ONLY = 0x00000000;
var CG_FLAG_VERIFY_CERTCHAIN = 0x00000001;
var CG_FLAG_VERIFY_CRL = 0x00000002;
var CG_FLAG_VERIFY_FULL = 0x00000003;

var CG_FLAG_DETACHMSG = 0x00004000;
var CG_FLAG_BASE64_ENCODE = 0x00001000;

function fnJSLanguageVer(sWordC, sWordE) {
	return sWordC;
}

function GetErrorMessage(ErrCode, Debug, SN) {
	var msg = "";

	switch (ErrCode) {
		case 0:
			msg += fnJSLanguageVer("����", "Success ");
			break;
		case 5001:
			msg += fnJSLanguageVer(
				"[" + ErrCode + "] �@��ʿ��~",
				"[" + ErrCode + "] general error ",
			);
			break;
		case 5002:
			msg += fnJSLanguageVer(
				"[" + ErrCode + "] �O����t�m���~",
				"[" + ErrCode + "] Memory Allocation Error",
			);
			break;
		case 5003:
			msg += fnJSLanguageVer(
				"[" + ErrCode + "] Buffer too small",
				"[" + ErrCode + "] Buffer too small",
			);
			break;
		case 5005:
			msg += fnJSLanguageVer(
				"[" + ErrCode + "] �Ѽƿ��~",
				"[" + ErrCode + "] Invalid parameter",
			);
			break;
		case 5006:
			msg += fnJSLanguageVer(
				"[" + ErrCode + "] Invalid handle",
				"[" + ErrCode + "] Invalid handle",
			);
			break;
		case 5007:
			msg += fnJSLanguageVer(
				"[" + ErrCode + "] ����w�L��",
				"[" + ErrCode + "] TrialVersion Library is expired",
			);
			break;
		case 5008:
			msg += fnJSLanguageVer(
				"[" + ErrCode + "] Base64 Encoding/Decoding Error",
				"[" + ErrCode + "] Base64 Encoding/Decoding Error",
			);
			break;

		case 5010:
			msg += fnJSLanguageVer(
				"[" + ErrCode + "] �䤣��ŦX����",
				"[" + ErrCode + "] certificate not found",
			);
			break;
		case 5011:
			msg += fnJSLanguageVer(
				"[" + ErrCode + "] ���Ҥw�L��",
				"[" + ErrCode + "] Certicate Expired",
			);
			break;
		case 5012:
			msg += fnJSLanguageVer(
				"[" + ErrCode + "] ���ҩ|������",
				"[" + ErrCode + "] Certificate can not be used now",
			);
			break;

		case 5014:
			msg += fnJSLanguageVer(
				"[" + ErrCode + "] ���ҥD�������~",
				"[" + ErrCode + "] Certificate subject not match",
			);
			break;

		case 5015:
			msg += fnJSLanguageVer(
				"[" + ErrCode + "] �䤣����ҵo���",
				"[" + ErrCode + "] Unable to find certificate issuer",
			);
			break;

		case 5016:
			msg += fnJSLanguageVer(
				"[" + ErrCode + "] ����ñ���ȵL��",
				"[" + ErrCode + "] Certificate signature is invalid",
			);
			break;

		case 5017:
			msg += fnJSLanguageVer(
				"[" + ErrCode + "] ���~�����_�ϥΤ覡",
				"[" + ErrCode + "] Invalid ertificate keyusage",
			);
			break;

		case 5020:
		case 5021:
		case 5022:
		case 5023:
		case 5024:
		case 5025:
		case 5026:
		case 5028:
			msg += fnJSLanguageVer(
				"[" + ErrCode + "] ���Ҥw�M�P",
				"[" + ErrCode + "] Certificate is revoked",
			);
			break;

		case 5030:
			msg += fnJSLanguageVer(
				"[" + ErrCode + "] CRL �w�L��",
				"[" + ErrCode + "] CRL expired.",
			);
			break;
		case 5031:
			msg += fnJSLanguageVer(
				"[" + ErrCode + "] CRL �|������",
				"[" + ErrCode + "] CRL not yet valid.",
			);
			break;
		case 5032:
			msg += fnJSLanguageVer(
				"[" + ErrCode + "] �䤣�� CRL ",
				"[" + ErrCode + "] CRL not found.",
			);
			break;
		case 5034:
			msg += fnJSLanguageVer(
				"[" + ErrCode + "] CRL ��ñ���ȿ��~ ",
				"[" + ErrCode + "] CRL signature invalid.",
			);
			break;
		case 5036:
			msg += fnJSLanguageVer(
				"[" + ErrCode + "] ��ƪ�ñ���ȿ��~ ",
				"[" + ErrCode + "] Invalid data signature.",
			);
			break;
		case 5037:
			msg += fnJSLanguageVer(
				"[" + ErrCode + "] ñ���������~ ",
				"[" + ErrCode + "] Content not match.",
			);
			break;

		case 5040:
			msg += fnJSLanguageVer(
				"[" + ErrCode + "] ���~�����Ү榡 ",
				"[" + ErrCode + "] Incorrect Certificate format.",
			);
			break;

		case 5041:
			msg += fnJSLanguageVer(
				"[" + ErrCode + "] ���~�� CRL �榡 ",
				"[" + ErrCode + "] Incorrect CRL format.",
			);
			break;

		case 5042:
			msg += fnJSLanguageVer(
				"[" + ErrCode + "] ���~�� PKCS#7 �榡 ",
				"[" + ErrCode + "] Incorrect PKCS7 format.",
			);
			break;

		case 5050:
			msg += fnJSLanguageVer(
				"[" + ErrCode + "] �䤣����w���� ",
				"[" + ErrCode + "] CG_RTN_OBJ_NOT_FOUND.",
			);
			break;

		case 5204:
			msg += fnJSLanguageVer(
				"[" + ErrCode + "] �䤣��p�K���_ ",
				"[" + ErrCode + "] CG_RTN_OBJ_NOT_FOUND.",
			);
			break;

		// PKCS#11 return code
		case 9005:
			msg += fnJSLanguageVer(
				"[" + ErrCode + "] �� PKCS#11 ���䴩�� Function ",
				"[" + ErrCode + "] CGP11_RTN_OBJECT_NOT_EXIST.",
			);
			break;
		case 9006:
			msg += fnJSLanguageVer(
				"[" + ErrCode + "] PKCS#11 �Ѽƿ��~ ",
				"[" + ErrCode + "] CGP11_RTN_ARGUMENTS_BAD.",
			);
			break;
		case 9039:
		case 9040:
			msg += fnJSLanguageVer(
				"[" + ErrCode + "] PKCS#11 Pin �X���~ ",
				"[" + ErrCode + "] CGP11_RTN_PIN_INCORRECT.",
			);
			break;
		case 9043:
			msg += fnJSLanguageVer(
				"[" + ErrCode + "] PKCS#11 Pin Lock ",
				"[" + ErrCode + "] CGP11_RTN_PIN_INCORRECT.",
			);
			break;

		case 9056:
			msg += fnJSLanguageVer(
				"[" + ErrCode + "] Token ���s�b ",
				"[" + ErrCode + "] CGP11_RTN_TOKEN_NOT_PRESENT.",
			);
			break;

		case 9100:
			msg += fnJSLanguageVer(
				"[" + ErrCode + "] ���󤣦s�b ",
				"[" + ErrCode + "] CGP11_RTN_OBJECT_NOT_EXIST.",
			);
			break;

		case 9100:
			msg += fnJSLanguageVer(
				"[" + ErrCode + "] ���󤣦s�b ",
				"[" + ErrCode + "] CGP11_RTN_OBJECT_NOT_EXIST.",
			);
			break;
		case 9101:
			msg += fnJSLanguageVer(
				"[" + ErrCode + "] ����w�s�b ",
				"[" + ErrCode + "] CGP11_RTN_OBJECT_EXIST.",
			);
			break;
		case 9102:
			msg += fnJSLanguageVer(
				"[" + ErrCode + "] ����o�Ͱ��D(�i��O�]���@�ӥH�W) ",
				"[" + ErrCode + "] CGP11_RTN_OBJECT_HAS_PROBLEM.",
			);
			break;

		case 9110:
		case 9111:
			msg += fnJSLanguageVer(
				"[" + ErrCode + "] Load Library ���� ",
				"[" + ErrCode + "] CGP11_RTN_LIBRARY_NOT_LOAD.",
			);
			break;

		case 9112:
			msg += fnJSLanguageVer(
				"[" + ErrCode + "] �䤣�� slot ",
				"[" + ErrCode + "] CGP11_RTN_SLOT_NOT_FOUND.",
			);
			break;

		default:
			msg +=
				fnJSLanguageVer(
					"��L���~,�аѦҤ����U: (",
					"Unknown Error, please reference document: (",
				) +
				ErrCode +
				") ";
			return msg;
	}

	return msg;
}
