function executeApplet() {
	setTimeout(executeApplet2, 4000);
}

function executeApplet2() {
	document.FirmaFacturae.setBrowser(browserName);
	document.FirmaFacturae.setLocale(locale);
	msg = new String(document.FirmaFacturae.showCertificates());
	checkJavaVersion();
	getUserHome();
	evaluateCertsFound(msg);
	document.getElementById("invoiceSearchId").style.display = "block";
}

function signExistingInvoice() {
	combo = document.appletForm.certCombo;
	
	if (document.appletForm.invoicePath.value != '') {
		if (certSelected) {
			generateSignatureExistingInvoice(combo.selectedIndex);
		}
		else {
			evaluateCertificate();
		}
	}
	else {
		alert(MANDATORY_INVOICE_FILE);
	}
}

function generateSignatureExistingInvoice(index) {
	var invoicePath = new String(document.appletForm.invoicePath.value);
	document.forms[0].disabled = true;
	var msg = new String(document.FirmaFacturae.signDocument(index, invoicePath));
	if (!hasErrors(msg)) {
		signOK();
	}
	else {
		document.forms[0].disabled = false;
		if (msg.indexOf(ERROR_CERTIFICATE_EXPIRED) != -1) {
			
			document.FirmaFacturae.setCertExpired("");
			alertErrors(msg);
		}
		else {
			printErrors(msg);
		}
	}
}

function searchInvoice() {
	var path = new String(document.FirmaFacturae.searchInvoice());
	if (hasErrors(path)) {
		document.getElementById("invoicePath").value = '';
		printErrors(path);
	}
	else {
		printErrors("");
		path = path.substring(9);
		if (path != '') {
			document.getElementById("invoicePath").value = path;
		}
		else {
			document.getElementById("invoicePath").value = '';
		}
	}
}
