// AquÃ­ es donde se indica el path de la URL donde estÃ¡n situados estos mismos
// scripts
//var path_firma = "/cgi-bin/firma2/";
/*var cad = new String(document.location);
this.ind=cad.indexOf('idioma=en');
//ind!=1 Para el idioma ingles porque ha encontrado esta indicación en el location
if(this.ind!=-1){
	var path_firma= "/cgi-bin/firma2/lang_en/";
}
else{
	var path_firma= "/cgi-bin/firma2/lang_es/";
}*/
path_firma="/cgi-bin/firma2/";

try {
if (licencia===undefined || licencia=="") {
}
} catch (e) {
  licencia='licencia_www_xolido_com.js';

}

document.write("<script type='text/javascript' src='"+window.path_firma+"firma_wrapper.js'></script>");
document.write('<script type="text/javascript" src="'+window.path_firma+'version.js" >alert("No JS file");</script>');
//document.write('<script type="text/javascript" src="'+window.path_firma+licencia+'" >alert("No encontrado JS");</script>');
document.write('<script type="text/javascript" src="'+window.path_firma+licencia+'" >alert("No JS file");</script>');
document.write('<script type="text/javascript" src="'+window.path_firma+'firma_lang.js" >alert("No JS file");</script>');


var NOT_TIME_VALID=2;
var SELF_SIGNED=4;
var UNTRUSTED_ROOT=8;
var PARTIAL_CHAIN=16;
var NOT_SIGNATURE_VALID=32;
var UNKNOWN_STATUS=64;
var REVOKED_STATUS=128;
var OFFLINE_REVOCATION=256;
var ALL = NOT_TIME_VALID|SELF_SIGNED|UNTRUSTED_ROOT|PARTIAL_CHAIN|NOT_SIGNATURE_VALID|UNKNOWN_STATUS|REVOKED_STATUS|OFFLINE_REVOCATION;
var NONE = 0;

function Firma() {
  this.inicia=iniciaCriptografia;
  this.escogerCert=escogerCert;
  this.comprobar=comprobarCert;
  this.escogerProv=escogerProv;
  this.mostrar=mostrarCert;
  this.getStatus=getStatus;
  this.firmar=firmar;
  this.onstart=null;
  this.onsign=null;
  this.onBC=null;
  this.onNSS=null;
  this.onAXFail=null;
  this.mapsrc="blank.html";
  this.checkCertificate=checkC;  
  
  this.pasarPagina = pasarP;
  this.ejecutarX = ejecAX;
  this.enviaLicenc= enviaLic;
  this.recLanguage = recLangCOM;
}

function iniciaCriptografia(contenedor,tipo,id) {
    
	//alert("Entra en inicia criptografia");	
    
	this.contenedor=contenedor;
    this.tipo=tipo;
	this.id=id || ('firma_'+Math.floor(Math.random()*100000));	
 	//alert("Hasta conocer el idioma en COM usamos: " + lang.split('-')[0]);	
	IE=(navigator.appName=="Microsoft Internet Explorer");
		
	if(!IE){
		if(tipo==".NET"){
				//if(this.ind!=-1){
				if(lang.split('-')[0]=="es"){
					alert("Puede tener problemas al ejecutar ActiveX fuera de Internet Explorer. Requerirá extensiones en su navegador");
                    if(!confirm("¿Desea continuar?")){
                    return;
                    }
				}else{
					 alert("You could have problems executing ActiveX not under Internet Explorer. It requires extensions on your browser");
                    if(!confirm("Do you want to continue?")){
                    return;
                    }
				}
			}
		}

	

	window["crypto_"+this.id]= new Criptografia(contenedor,this.id,tipo);
		//alert("Hizo new criptografia");

    	if (this.onstart) {
      	window["crypto_"+this.id].onstart=this.onstart;
    }	
	if (this.onload) {
      window["crypto_"+this.id].onload=this.onload;
    }
	if(this.onBC){
      window["crypto_"+this.id].onBC=this.onBC;
    }
	if(this.onNSS){
      window["crypto_"+this.id].onNSS=this.onNSS;
    }
	if(this.onAXFail){
      window["crypto_"+this.id].onAXFail=this.onAXFail;
    }

	if(tipo=='Java'){
		window["crypto_"+this.id].previo();
	}

	if(tipo=='.NET'){
			window["crypto_"+this.id].lanzar();
	}				   
}
					

function getStatus() {
	return window["crypto_"+this.id].status;
}

function escogerCert() {
	return window["crypto_"+this.id].escogerCert();
}

function escogerProv() {
	
		IE=(navigator.appName=="Microsoft Internet Explorer");
		if(!IE){
			return window["crypto_"+this.id].escogerProv(1);//Escoger por defecto el almacÃ©n del propio navegador
		}else{
			return window["crypto_"+this.id].escogerProv();
		}
   
}

function checkC(critical, warning, checkRevoc){
	return window["crypto_"+this.id].checkCert(critical, warning, checkRevoc);
}

function comprobarCert() {
	   	
		return window["crypto_"+this.id].comprobarCert();

}
function mostrarCert() {
		return window["crypto_"+this.id].mostrarCert();
}
function firmar(hash,tipo) {
		
		var resultadoFirma = new String;
		
		if (this.onsign) {
			window["crypto_"+this.id].onsign=this.onsign;
		}
	
			resultadoFirma = window["crypto_"+this.id].firmar(hash, tipo);
		
		
		return resultadoFirma;

		//Para pruebas con archivo pequeñi±o
		//window["crypto_"+this.id].firmar("639E7EF4CDBE8D6AC59AB6C3F34283EB2986B6DF", "SHA1");
		//window["crypto_"+this.id].firmar("D0662A5AD4B87ED3C2889D893D4EEF85", "MD5");

		//Para pruebas archivo grande
		//window["crypto_"+this.id].firmar("7DAD55DD110567B81C93B45DB2E6BEFA4585ADDA", "SHA1");
		//window["crypto_"+this.id].firmar("ECC1C984EFB8E10F19723A04391E4104", "MD5");
		
		//window["crypto_"+this.id].firmar("D066-2A5A-D4B8-7ED3-C288-9D89-3D4E-EF85", "MD5");
		//window["crypto_"+this.id].firmar("639E-7EF4-CDBE-8D6A-C59A-B6C3-F342-83EB-2986-B6DF", "SHA1");
}

function pasarP(a){
	window["crypto_"+this.id].pasarPag(a);
}

function ejecAX(){
	window["crypto_"+this.id].llamarScript();
}
function enviaLic(){
			//alert("Vamos a enviar la licencia y recibimos el idioma predefinido para el sistema");
	window["crypto_"+this.id].enviaL();
	window["crypto_"+this.id].recLang();
}
function recLangCOM(){
			window["crypto_"+this.id].recLang();
}


