<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="TestXSign.aspx.vb" Inherits="TestWebApp.TestXSign"
    ValidateRequest="false" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Lizard Labs</title>
</head>
<body>
    <form id="form1" runat="server">
    <object id="oXSignXmlSignatureComponent" classid="clsid:D39FCCD2-5187-4272-BC9C-3ABDF0D4660F" style="display: none;"
        style="display: none;" codebase="LizardLabsXSignLite.cab">
        An error occured during ActiveX installation. Please verify that:
        <ul>
            <li>your browser supports ActiveX.</li>
            <li>the ActiveX support in your browser has been enabled.</li>
            <li>that the path to proXSign cab within object tag is correct.</li>
        </ul>
    </object>
    <script language="javascript">
        function IsAxComponentInstalled(Class) {
            try {
                var tmpo = new ActiveXObject(Class);
            }
            catch (e) {
            }

            if (tmpo == null) {
                return false;
            }
            else {
                tmpo = null;
                return true;
            }
        }

        function sign() {
            try {
                if (IsAxComponentInstalled("LizardLabs.XSignLiteCtrl.1")) {
                    alert("Installed");
                }
                else {
                    alert("Not installed");
                    return false;
                }

                var oXSignXmlSignatureComponent = document.getElementById("oXSignXmlSignatureComponent")

                // oXSignXmlSignatureComponent.Test("Test"); // For DEBUG test if control is loaded

                alert(document.getElementById("hiddenXml").value);

                oXSignXmlSignatureComponent.SelectCertificate();
                //oSignComponent.SelectCertificateByThumbprint("ae 3c 32 52 79 a8 eb 1d fd 8c ae 90 80 0f e2 57 7a d4 f2 6f");

                if (!oXSignXmlSignatureComponent.IsCertificateSelected) {
                    alert("Please select valid certificate.");
                    return false;
                }
                else {
                    if (oXSignXmlSignatureComponent.Sign(document.getElementById("hiddenXml").value)) {
                        alert(oXSignXmlSignatureComponent.SignedXml);
                        // alert(oXSignXmlSignatureComponent.Signature);
                        // alert(oXSignXmlSignatureComponent.SignatureWithoutKeyInfo);

                        document.getElementById("hiddenSignedXml").value = oXSignXmlSignatureComponent.SignedXml;
                        return true;
                    }
                    else alert("Error");
                }

            }
            catch (e) {
                alert("JavaScript Error: " + e.message);
                return false;
            }
            return false;
        }
    </script>

        <h1>
            Lizard Labs: Test for XSign XML signature component)</h1>
        <asp:Button ID="Button1" runat="server" Text="Test" OnClientClick="return sign();" />
        <input id="hiddenXml" type="hidden" runat="server" />
        <input id="hiddenSignedXml" type="hidden" runat="server" />
        <br />
        <br />
        <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~\Default.aspx">Back</asp:HyperLink>
        <p>
            If your browser settings support ActiveX installation, the XEnc Lite should be installed
            when opening this page in the Internet Explorer.</p>
        <p>
            <strong>XML:</strong></p>
        <asp:Label ID="lblXml" runat="server"></asp:Label>
        <p>
            <strong>Signed XML:</strong>
        </p>
        <asp:Label ID="lblSignedXml" runat="server"></asp:Label>
        <p>
            <strong>Validation results:</strong></p>
        <asp:Label ID="lblsignatureValidation" runat="server"></asp:Label>
    </form>
</body>
</html>
