

		function Inicializar()
		{
			var retval=9;
			mensagem("Verificar o programa do Cartão de Cidadão",0);
			var obj = window.document.getElementById("ccidadao");
			if (obj.instalar=="1") InstalarCCidadao();
			try { retval=window.document.ccApplet.inicializar(); } catch (e) { }

		  if (retval!=0){
	        mensagem("Deve Instalar o programa do Cartão de Cidadão - clique novamente para instalar (Se já instalou verifique se o leitor está connectado)",0);
	        obj.value = "Instalar Cartão de Cidadão";
	        obj.title = "Instalar o programa do Cartão de Cidadão";
	        obj.instalar= "1";
	      } else {
						mensagem("Leitor do Cartão de Cidadão inicializado",0);
						iniciar();
		  }			
		}
		
		function InstalarCCidadao() {
			window.document.execCommand("Refresh");
			window.open("http://www.cartaodecidadao.pt/index.php?option=com_content&task=view&id=102&Itemid=44&lang=pt");
		}
		
		function iniciar() {
			var retval=99;
			mensagem("Iniciar o programa do Cartão de Cidadão",0);
			try { retval=window.document.ccApplet.iniciar(); } catch (e) { }

		  if (retval!=0){
	        mensagem("Erro na inicialização do Cartão de Cidadão",retval);
	      } else {
						mensagem("Programa do Cartão de Cidadão iniciado",0);
						lerRsaPubKey();
		  }				
		}

		function lerRsaPubKey() {
			var retval=99;
			mensagem("A solicitar chave publica RSA no Cartão de Cidadão",0);
			try { retval=window.document.ccApplet.lerRsaPubKey(); } catch (e) { }
			
		  if (retval!=0){
	        mensagem("Erro no pedido de certificados do Cartão de Cidadão",retval);
	      } else {
						getExponent();
						getModulus();
						mensagem("Fim da leitura dos certificados",0);
						lerCertificados();
		  }				
		}

		function lerCertificados() {
			var retval=99;
			mensagem("A solicitar certificados existentes no Cartão de Cidadão",0);
			try { retval=window.document.ccApplet.lerCertificados(); } catch (e) { }
			
		  if (retval!=0){
	        mensagem("Erro no pedido de certificados do Cartão de Cidadão",retval);
	      } else {
						getCertificados();
						mensagem("Fim da leitura dos certificados",0);
						lerIdData();
		  }				
		}

    function lerIdData()
    {
			var retval=0;
			mensagem("A ler dados do Cartão de Cidadão",0);
			try { retval=window.document.ccApplet.lerIDData(); } catch (e) {alert("Excepçãp: "+e,0); }
			
		  if (retval!=0){
	        mensagem("Erro na leitura dos dados do Cartão de Cidadão",retval);
	      } else {
						getIDData();
						mensagem("Fim da leitura dos dados",0);
						lerPins();
		  }		

    }

		function lerPins() {
			var retval=99;
			mensagem("A solicitar os pins existentes no Cartão de Cidadão",0);
			try { retval=window.document.ccApplet.lerPins(); } catch (e) { }
			
		  if (retval!=0){
	        mensagem("Erro no pedido de leitura dos pins do Cartão de Cidadão",retval);
	      } else {
						getPins();
						mensagem("Fim da leitura dos pins",0);
						chamarPin();
		  }				
		}
		
		function chamarPin() {
			window.document.FORM1.login.value='PIN';
		  window.document.FORM1.submit();
		}
	
		function checkPin(pin) {
			var retval=99;
			mensagem("A verificar o pin de autênticação introduzido",0);
			try { retval=window.document.ccApplet.checkPin(pin); } catch (e) { }
			if (retval==-1212) retval=0;
		  if (retval!=3){
					switch(retval) {
						case 0: 
							mensagem("Pin de autênticação do Cartão de Cidadão bloqueado",0);
							break;
						case 1: 
							mensagem("Pin de autênticação incorrecto - Atenção pode bloquear o cartão resta 1 tentativa",0);
							break;		
						case 2: 
							mensagem("Pin de autênticação do Cartão de Cidadão incorrecto - restam 2 tentativas",0);
							break;		
						default: 
							mensagem("Ocorreu um erro no pedido de verificação do PIN",retval);
					}
	        
	    } else {
						mensagem("Pin de autênticação aceite",0);
						var retval=0;
						try { retval=window.document.ccApplet.lerIDData(); } catch (e) {alert("Excepçãp: "+e,0); }
						
					  if (retval!=0){
				        mensagem("Erro na leitura dos dados do Cartão de Cidadão",retval);
				      } else {
									getIDData();
									mensagem("Fim da leitura dos dados",0);
									window.document.FORM1.login.value='pinCC';
								  window.document.FORM1.submit();		
					  }	
		  }						
		}

		function dadosCC() {
				var retval=0;
				try { retval=window.document.ccApplet.lerIDData(); } catch (e) {alert("Excepçãp: "+e,0); }
				
			  if (retval!=0){
		        mensagem("Erro na leitura dos dados do Cartão de Cidadão",retval);
		      } else {
							getIDData();
							mensagem("Fim da leitura dos dados",0);
							window.document.FORM1.login.value='dadosCC';
						  window.document.FORM1.submit();		
			  }	
		}

		function verificaCC() {
				var retval=0;
				try { retval=window.document.ccApplet.inicializar(); } catch (e) { }
				try { retval=window.document.ccApplet.lerIDCard(); } catch (e) { }
				
			  if (retval!=0){
		        //mensagem("Erro na leitura do numero do Cartão de Cidadão",retval);
		        getIDCardNumber(1);
		      } else {
							getIDCardNumber(0);
							//mensagem("Fim da leitura do numero do Cartão de Cidadão",0);
							//window.document.FORM1.login.value='dadosCC';
						  //window.document.FORM1.submit();		
			  }	
		}

		function getIDCardNumber(estado) {
			//alert("Estado do numero do Cartão de Cidadão="+estado);
			if (estado==0) {
				try { window.document.FORM1.cc_idData_cardCheck.value = window.document.ccApplet.getIdData_cardNumber(); } catch (e) { }
			} else {
				try { window.document.FORM1.cc_idData_cardCheck.value = "ERRO"; } catch (e) { }
			}
			//alert("Numero do Cartão de Cidadão="+window.document.FORM1.cc_idData_cardCheck.value);
		}
		
		function ReadAddress()
    {
      var retval=0;
      window.document.getElementById('StatusFieldAD').value = "Reading Card, please wait...";
      
	  
	  
      
		  if (retval==0){
				window.document.getElementById('StatusFieldAD').value = "Reading Address, please wait...";
	      retval = window.document.ccApplet.readAddress();
				if(retval == 0){
					getAddressData();
	      }
		  }
		  
	      
		  if (retval!=0){
	        window.document.getElementById('StatusFieldAD').value = "Error Reading Card";
	      } else {
						window.document.getElementById('StatusFieldAD').value = "Done";
		  }

    }

    function getIDData()
    {
    	try {
						window.document.FORM1.cc_idData_deliveryEntity.value = window.document.ccApplet.getIdData_deliveryEntity();
						window.document.FORM1.cc_idData_country.value = window.document.ccApplet.getIdData_country();
						window.document.FORM1.cc_idData_documentType.value = window.document.ccApplet.getIdData_documentType();
						window.document.FORM1.cc_idData_cardNumber.value = window.document.ccApplet.getIdData_cardNumber();
						window.document.FORM1.cc_idData_cardNumberPAN.value = window.document.ccApplet.getIdData_cardNumberPAN();
						window.document.FORM1.cc_idData_cardVersion.value = window.document.ccApplet.getIdData_cardVersion();
						window.document.FORM1.cc_idData_deliveryDate.value = window.document.ccApplet.getIdData_deliveryDate();
						window.document.FORM1.cc_idData_locale.value = window.document.ccApplet.getIdData_locale();
						window.document.FORM1.cc_idData_validityDate.value = window.document.ccApplet.getIdData_validityDate();
						window.document.FORM1.cc_idData_name.value = window.document.ccApplet.getIdData_name();
						window.document.FORM1.cc_idData_firstname.value = window.document.ccApplet.getIdData_firstname();
						window.document.FORM1.cc_idData_sex.value = window.document.ccApplet.getIdData_sex();
						window.document.FORM1.cc_idData_nationality.value = window.document.ccApplet.getIdData_nationality();
						window.document.FORM1.cc_idData_birthDate.value = window.document.ccApplet.getIdData_birthDate();
						window.document.FORM1.cc_idData_height.value = window.document.ccApplet.getIdData_height();
						window.document.FORM1.cc_idData_numBI.value = window.document.ccApplet.getIdData_numBI();
						window.document.FORM1.cc_idData_nameFather.value = window.document.ccApplet.getIdData_nameFather();
						window.document.FORM1.cc_idData_firstnameFather.value = window.document.ccApplet.getIdData_firstnameFather();
						window.document.FORM1.cc_idData_nameMother.value = window.document.ccApplet.getIdData_nameMother();
						window.document.FORM1.cc_idData_firstnameMother.value = window.document.ccApplet.getIdData_firstnameMother();
						window.document.FORM1.cc_idData_numNIF.value = window.document.ccApplet.getIdData_numNIF();
						window.document.FORM1.cc_idData_numSS.value = window.document.ccApplet.getIdData_numSS();
						window.document.FORM1.cc_idData_numSNS.value = window.document.ccApplet.getIdData_numSNS();
						window.document.FORM1.cc_idData_notes.value = window.document.ccApplet.getIdData_notes();
						window.document.FORM1.cc_idData_mrz1.value = window.document.ccApplet.getIdData_mrz1();
						window.document.FORM1.cc_idData_mrz2.value = window.document.ccApplet.getIdData_mrz2();
						window.document.FORM1.cc_idData_mrz3.value = window.document.ccApplet.getIdData_mrz3();
				} catch (e) { }
    }

    function getAddressData()
    {
    	try {
						window.document.FORM1.cc_adData_country.value = window.document.ccApplet.getAdData_country();
						window.document.FORM1.cc_adData_district.value = window.document.ccApplet.getAdData_district();
						window.document.FORM1.cc_adData_districtDesc.value = window.document.ccApplet.getAdData_districtDesc();
						window.document.FORM1.cc_adData_municipality.value = window.document.ccApplet.getAdData_municipality();
						window.document.FORM1.cc_adData_municipalityDesc.value = window.document.ccApplet.getAdData_municipalityDesc();
						window.document.FORM1.cc_adData_freguesia.value = window.document.ccApplet.getAdData_freguesia();
						window.document.FORM1.cc_adData_freguesiaDesc.value = window.document.ccApplet.getAdData_freguesiaDesc();
						window.document.FORM1.cc_adData_street.value = window.document.ccApplet.getAdData_street();
						window.document.FORM1.cc_adData_streettype.value = window.document.ccApplet.getAdData_streettype();
						window.document.FORM1.cc_adData_streettypeAbbr.value = window.document.ccApplet.getAdData_streettypeAbbr();
						window.document.FORM1.cc_adData_building.value = window.document.ccApplet.getAdData_building();
						window.document.FORM1.cc_adData_buildingAbbr.value = window.document.ccApplet.getAdData_buildingAbbr();
						window.document.FORM1.cc_adData_door.value = window.document.ccApplet.getAdData_door();
						window.document.FORM1.cc_adData_floor.value = window.document.ccApplet.getAdData_floor();
						window.document.FORM1.cc_adData_side.value = window.document.ccApplet.getAdData_side();
						window.document.FORM1.cc_adData_place.value = window.document.ccApplet.getAdData_place();
						window.document.FORM1.cc_adData_locality.value = window.document.ccApplet.getAdData_locality();
						window.document.FORM1.cc_adData_cp3.value = window.document.ccApplet.getAdData_cp3();
						window.document.FORM1.cc_adData_cp4.value = window.document.ccApplet.getAdData_cp4();
						window.document.FORM1.cc_adData_postal.value = window.document.ccApplet.getAdData_postal();
						window.document.FORM1.cc_adData_numMor.value = window.document.ccApplet.getAdData_numMor();
			} catch (e) { }  
    }

    function EmptyScreen()
    {
    	try {
						window.document.FORM1.cc_adData_country.value = "&nbsp;";	
						window.document.FORM1.cc_adData_district.value = "&nbsp;";	
						window.document.FORM1.cc_adData_districtDesc.value = "&nbsp;";	
						window.document.FORM1.cc_adData_municipality.value = "&nbsp;";	
						window.document.FORM1.cc_adData_municipalityDesc.value = "&nbsp;";	
						window.document.FORM1.cc_adData_freguesia.value = "&nbsp;";	
						window.document.FORM1.cc_adData_freguesiaDesc.value = "&nbsp;";	
						window.document.FORM1.cc_adData_street.value = "&nbsp;";	
						window.document.FORM1.cc_adData_streettype.value = "&nbsp;";	
						window.document.FORM1.cc_adData_streettypeAbbr.value = "&nbsp;";	
						window.document.FORM1.cc_adData_building.value = "&nbsp;";	
						window.document.FORM1.cc_adData_buildingAbbr.value = "&nbsp;";	
						window.document.FORM1.cc_adData_door.value = "&nbsp;";	
						window.document.FORM1.cc_adData_floor.value = "&nbsp;";	
						window.document.FORM1.cc_adData_side.value = "&nbsp;";	
						window.document.FORM1.cc_adData_place.value = "&nbsp;";	
						window.document.FORM1.cc_adData_locality.value = "&nbsp;";	
						window.document.FORM1.cc_adData_cp3.value = "&nbsp;";	
						window.document.FORM1.cc_adData_cp4.value = "&nbsp;";	
						window.document.FORM1.cc_adData_postal.value = "&nbsp;";	
						window.document.FORM1.cc_adData_numMor.value = "&nbsp;";	
							
							
						window.document.FORM1.cc_idData_deliveryEntity.value = "&nbsp;";	
						window.document.FORM1.cc_idData_country.value = "&nbsp;";	
						window.document.FORM1.cc_idData_documentType.value = "&nbsp;";	
						window.document.FORM1.cc_idData_cardNumber.value = "&nbsp;";	
						window.document.FORM1.cc_idData_cardNumberPAN.value = "&nbsp;";	
						window.document.FORM1.cc_idData_cardVersion.value = "&nbsp;";	
						window.document.FORM1.cc_idData_deliveryDate.value = "&nbsp;";	
						window.document.FORM1.cc_idData_locale.value = "&nbsp;";	
						window.document.FORM1.cc_idData_validityDate.value = "&nbsp;";	
						window.document.FORM1.cc_idData_name.value = "&nbsp;";	
						window.document.FORM1.cc_idData_firstname.value = "&nbsp;";	
						window.document.FORM1.cc_idData_sex.value = "&nbsp;";	
						window.document.FORM1.cc_idData_nationality.value = "&nbsp;";	
						window.document.FORM1.cc_idData_birthDate.value = "&nbsp;";	
						window.document.FORM1.cc_idData_height.value = "&nbsp;";	
						window.document.FORM1.cc_idData_numBI.value = "&nbsp;";	
						window.document.FORM1.cc_idData_nameFather.value = "&nbsp;";	
						window.document.FORM1.cc_idData_firstnameFather.value = "&nbsp;";	
						window.document.FORM1.cc_idData_nameMother.value = "&nbsp;";	
						window.document.FORM1.cc_idData_firstnameMother.value = "&nbsp;";	
						window.document.FORM1.cc_idData_numNIF.value = "&nbsp;";	
						window.document.FORM1.cc_idData_numSS.value = "&nbsp;";	
						window.document.FORM1.cc_idData_numSNS.value = "&nbsp;";	
						window.document.FORM1.cc_idData_notes.value = "&nbsp;";	
						window.document.FORM1.cc_idData_mrz1.value = "&nbsp;";	
						window.document.FORM1.cc_idData_mrz2.value = "&nbsp;";	
						window.document.FORM1.cc_idData_mrz3.value = "&nbsp;";	
				} catch (e) { }
    }

		function getCertificados() {
			var certifLabel = "";
			var certif = "";
			var certificados = "";
			var i=0;
			try {
				for (i=0;i<10;i++) {
						certifLabel = window.document.ccApplet.getCertifLabel(i);
						//alert(" certifLabel: "+i+" - "+certifLabel);
						
						if (certifLabel=="FIM") { 
							break;
						} else certificados = certificados+(i+1)+"|"+certifLabel+"|";
						certif = window.document.ccApplet.getCertif(i);
						certificados = certificados+certif+"|";
						//alert(" certif     : "+i+" - "+certif);
				}
				//alert(" certificados: "+certificados);
				window.document.FORM1.cc_certif.value = certificados;
			} catch (e) {
				 alert("Certificados Excepção: "+e);
			}
		}

		
		function getExponent() {
			var rsaPubKey_exponent="";
			try {
				rsaPubKey_exponent = window.document.ccApplet.getExponent();
				//alert(" rsaPubKey_exponent: "+rsaPubKey_exponent);
				window.document.FORM1.cc_rsaPK_exponent.value = rsaPubKey_exponent;
			} catch (e) {
				 alert("RSA Exponent Excepção: "+e);
			}
		}

		function getModulus() {
			var rsaPubKey_exponent="";
			try {
				rsaPubKey_modulus = window.document.ccApplet.getModulus();
				//alert(" rsaPubKey_modulus: "+rsaPubKey_modulus);
				window.document.FORM1.cc_rsaPK_modulus.value = rsaPubKey_modulus;
			} catch (e) {
				 alert("RSA Modulus Excepção: "+e);
			}
		}

		function getPins() {
			var pins = "";
			var pin = "";
			var i=0;
			try {
				for (i=0;i<10;i++) {
						pin = window.document.ccApplet.getPins(i);
						if (pin=="FIM") { 
							break;
						}
						pins = pins+pin;
				}
				//alert("pins: "+pins);
				window.document.FORM1.cc_pins.value = pins;
			} catch (e) {
				 alert("Pins Excepção: "+e);
			}
		}
		
		function mensagem(msg_in,retval) {
			var msg = "";
			switch(retval) {
				case 0: /* Function succeeded */
					msg = msg_in;
					break;
				case 1: /* Invalid parameter (NULL pointer, out of bound, etc.) */
					msg = msg_in+" - ("+retval+") Parametro inválido";
					break;
				case 2: /* An internal consistency check failed */
					msg = msg_in+" - ("+retval+") Inconsistência interna";
					break;
				case 3: /* The data buffer to receive returned data is too small */
					msg = msg_in+" - ("+retval+") Dados recebidos truncados";
					break;
				case 4: /* Input on pinpad cancelled */
					msg = msg_in+" - ("+retval+") Introdução de dados ou PIN cancelados";
					break;
				case 5: /* Timout returned from pinpad */
					msg = msg_in+" - ("+retval+") O tempo de introdução do PIN expirou";
					break;
				case 6: /* The two PINs did not match */
					msg = msg_in+" - ("+retval+") Os 2 PIN introduzidos não são iguais";
					break;
				case 7: /* Message too long on pinpad */
					msg = msg_in+" - ("+retval+") Mensagem muito grande para o leitor";
					break;
				case 8: /* Invalid PIN length */
					msg = msg_in+" - ("+retval+") Tamanho do PIN inválido";
					break;
				case 9: /* Library not initialized */
					msg = msg_in+" - ("+retval+") Libraria não incializada - encerre a janela e volte a entrar";
					break;
				case 10: /* An internal error has been detected, but the source is unknown */
					msg = msg_in+" - ("+retval+") Erro interno de origem desconhecida";
					break;
				case 99: /* An internal error has been detected, but the source is unknown */
					msg = msg_in;
					break;					

/* Return codes da biblioteca open-source subjacente pteidlibopensc - Licença LGPL: */
/* Erros relativos a operações do leitor */
				case -1100: /* SC_ERROR_READER */
					msg = msg_in+" - ("+retval+") Erro do leitor de cartões";
					break;
				case -1101: /* SC_ERROR_NO_READERS_FOUND */
					msg = msg_in+" - ("+retval+") Leitor de cartões não encontrado";
					break;
				case -1102: /* SC_ERROR_SLOT_NOT_FOUND */
					msg = msg_in+" - ("+retval+") Slot do leitor não encontrada";
					break;
				case -1103: /* SC_ERROR_SLOT_ALREADY_CONNECTED */
					msg = msg_in+" - ("+retval+") Slot do leitor já se encontra connectada";
					break;
				case -1104: /* SC_ERROR_CARD_NOT_PRESENT */
					msg = msg_in+" - ("+retval+") Cartão não está presente no leitor";
					break;
				case -1105: /* SC_ERROR_CARD_REMOVED */
					msg = msg_in+" - ("+retval+") Cartão retirado do leitor";
					break;
				case -1106: /* SC_ERROR_CARD_RESET */
					msg = msg_in+" - ("+retval+") Cartão em reinicialização";
					break;
				case -1107: /* SC_ERROR_TRANSMIT_FAILED */
					msg = msg_in+" - ("+retval+") Erro na transmissão";
					break;
				case -1108: /* SC_ERROR_KEYPAD_TIMEOUT */
					msg = msg_in+" - ("+retval+") Acabou o tempo de introdução";
					break;
				case -1109: /* SC_ERROR_KEYPAD_CANCELLED */
					msg = msg_in+" - ("+retval+") Introdução cancelada";
					break;
				case -1110: /* SC_ERROR_KEYPAD_PIN_MISMATCH */
					msg = msg_in+" - ("+retval+") Erro interno de origem desconhecida";
					break;
				case -1111: /* SC_ERROR_KEYPAD_MSG_TOO_LONG */
					msg = msg_in+" - ("+retval+") Mensagem introduzida muito grande";
					break;
				case -1112: /* SC_ERROR_EVENT_TIMEOUT */
					msg = msg_in+" - ("+retval+") Acabou o tempo de execução";
					break;
				case -1113: /* SC_ERROR_CARD_UNRESPONSIVE */
					msg = msg_in+" - ("+retval+") Não há resposta do cartão";
					break;
				case -1114: /* SC_ERROR_READER_DETACHED */
					msg = msg_in+" - ("+retval+") O leitor foi desligado";
					break;
				case -1115: /* SC_ERROR_READER_REATTACHED */
					msg = msg_in+" - ("+retval+") O leitor voltou a ser ligado";
					break;
/* Resultantes de um comando de cartão ou relacionado com o cartão */
				case -1200: /* SC_ERROR_CARD_CMD_FAILED */
					msg = msg_in+" - ("+retval+") Erro do cartão, o comando falhou";
					break;
				case -1201: /* SC_ERROR_FILE_NOT_FOUND */
					msg = msg_in+" - ("+retval+") Ficheiro não encontrado";
					break;
				case -1202: /* SC_ERROR_RECORD_NOT_FOUND */
					msg = msg_in+" - ("+retval+") Registo não encontrado";
					break;
				case -1203: /* SC_ERROR_CLASS_NOT_SUPPORTED */
					msg = msg_in+" - ("+retval+") Programa não suportado";
					break;
				case -1204: /* SC_ERROR_INS_NOT_SUPPORTED */
					msg = msg_in+" - ("+retval+") Erro inserção não suportada";
					break;
				case -1205: /* SC_ERROR_INCORRECT_PARAMETERS */
					msg = msg_in+" - ("+retval+") Parametros incorrectos";
					break;
				case -1206: /* SC_ERROR_WRONG_LENGTH */
					msg = msg_in+" - ("+retval+") Tamanho incorrecto";
					break;
				case -1207: /* SC_ERROR_MEMORY_FAILURE */
					msg = msg_in+" - ("+retval+") Falha na memória do cartão";
					break;
				case -1208: /* SC_ERROR_NO_CARD_SUPPORT */
					msg = msg_in+" - ("+retval+") Cartão não suportado";
					break;
				case -1209: /* SC_ERROR_NOT_ALLOWED */
					msg = msg_in+" - ("+retval+") Operação não permitida";
					break;
				case -1210: /* SC_ERROR_INVALID_CARD */
					msg = msg_in+" - ("+retval+") Cartão inválido, não é Cartão de Cidadão";
					break;
				case -1211: /* SC_ERROR_SECURITY_STATUS_NOT_SATISFIED */
					msg = msg_in+" - ("+retval+") Segurança não satisfeita";
					break;
				case -1212: /* SC_ERROR_AUTH_METHOD_BLOCKED */
					msg = msg_in+" - ("+retval+") Método de autorização bloqueado";
					break;
/* Technical manual for the Portuguese */
/* eID Middleware 1.0 */
/* 35/35 May 2007 */
				case -1213: /* SC_ERROR_UNKNOWN_DATA_RECEIVED */
					msg = msg_in+" - ("+retval+") Dados recebidos desconhecidos";
					break;
				case -1214: /* SC_ERROR_PIN_CODE_INCORRECT */
					msg = msg_in+" - ("+retval+") PIN incorrecto";
					break;
				case -1215: /* SC_ERROR_FILE_ALREADY_EXISTS */
					msg = msg_in+" - ("+retval+") Ficheiro já existente";
					break;
/* Devolvidos pela biblioteca OpenSC quando invocada com argumentos inválidos */
				case -1300: /* SC_ERROR_INVALID_ARGUMENTS */
					msg = msg_in+" - ("+retval+") Argumentos inválidos";
					break;
				case -1301: /* SC_ERROR_CMD_TOO_SHORT */
					msg = msg_in+" - ("+retval+") Comando muito curto";
					break;
				case -1302: /* SC_ERROR_CMD_TOO_LONG */
					msg = msg_in+" - ("+retval+") Comendo muito longo";
					break;
				case -1303: /* SC_ERROR_BUFFER_TOO_SMALL */
					msg = msg_in+" - ("+retval+") Espaço (buffer) insuficiente";
					break;
				case -1304: /* SC_ERROR_INVALID_PIN_LENGTH */
					msg = msg_in+" - ("+retval+") PIN de tamanho irregular";
					break;
/* Resultantes de operações internas da biblioteca OpenSC */
				case -1400: /* SC_ERROR_INTERNAL */
					msg = msg_in+" - ("+retval+") Erro interno de origem desconhecida";
					break;
				case -1401: /* SC_ERROR_INVALID_ASN1_OBJECT */
					msg = msg_in+" - ("+retval+") Objecto ASN1 inválido";
					break;
				case -1402: /* SC_ERROR_ASN1_OBJECT_NOT_FOUND */
					msg = msg_in+" - ("+retval+") Objecto ASN1 não encontrado";
					break;
				case -1403: /* SC_ERROR_ASN1_END_OF_CONTENTS */
					msg = msg_in+" - ("+retval+") Objecto ASN1 acabou antes do tempo";
					break;
				case -1404: /* SC_ERROR_OUT_OF_MEMORY */
					msg = msg_in+" - ("+retval+") A memória do cartão foi ultrapassada";
					break;
				case -1405: /* SC_ERROR_TOO_MANY_OBJECTS */
					msg = msg_in+" - ("+retval+") Demasiados objectos";
					break;
				case -1406: /* SC_ERROR_OBJECT_NOT_VALID */
					msg = msg_in+" - ("+retval+") Objecto inválido";
					break;
				case -1407: /* SC_ERROR_OBJECT_NOT_FOUND */
					msg = msg_in+" - ("+retval+") Objecto não encontrado";
					break;
				case -1408: /* SC_ERROR_NOT_SUPPORTED */
					msg = msg_in+" - ("+retval+") Operação não suportada";
					break;
				case -1409: /* SC_ERROR_PASSPHRASE_REQUIRED */
					msg = msg_in+" - ("+retval+") Frase de passe obrigatória";
					break;
				case -1410: /* SC_ERROR_EXTRACTABLE_KEY */
					msg = msg_in+" - ("+retval+") Erro na chave de extracção";
					break;
				case -1411: /* SC_ERROR_DECRYPT_FAILED */
					msg = msg_in+" - ("+retval+") A descriptação falhou";
					break;
				case -1412: /* SC_ERROR_WRONG_PADDING */
					msg = msg_in+" - ("+retval+") Separador incorrecto";
					break;
				case -1413: /* SC_ERROR_WRONG_CARD */
					msg = msg_in+" - ("+retval+") Cartão incorrecto";
					break;
/* Relacionados com o PKCS #15 init */
				case -1500: /* SC_ERROR_PKCS15INIT */
					msg = msg_in+" - ("+retval+") Erro na inicialização PKCS15";
					break;
				case -1501: /* SC_ERROR_SYNTAX_ERROR */
					msg = msg_in+" - ("+retval+") Erro de sintase";
					break;
				case -1502: /* SC_ERROR_INCONSISTENT_PROFILE */
					msg = msg_in+" - ("+retval+") Perfil inconsistente";
					break;
				case -1503: /* SC_ERROR_INCOMPATIBLE_KEY */
					msg = msg_in+" - ("+retval+") Chave incompatível";
					break;
				case -1504: /* SC_ERROR_NO_DEFAULT_KEY */
					msg = msg_in+" - ("+retval+") Não existe chave por defeito";
					break;
				case -1505: /* SC_ERROR_ID_NOT_UNIQUE */
					msg = msg_in+" - ("+retval+") A identificação não é unica";
					break;
				case -1006: /* SC_ERROR_CANNOT_LOAD_KEY */
					msg = msg_in+" - ("+retval+") Não foi possivel carregar a chave";
					break;
/* Erros que não se enquadram nas categorias acima */
				case -1900: /* SC_ERROR_UNKNOWN */
					msg = msg_in+" - ("+retval+") Erro desconhecido";
					break;
				case -1901: /* SC_ERROR_PKCS15_APP_NOT_FOUND */
					msg = msg_in+" - ("+retval+") Aplicação PKCS15 não encontrada";
					break;
				default:
					msg = msg_in+" - ("+retval+") Erro desconhecido";
			}
			window.document.getElementById('mensagem').innerHTML = msg;
		}
