<!--
  '-- VSSKBEGIN Global/Mode#29#manualauth#1.0.0.0#512 --
   Dim hostName
   hostName = "https://<DOMAIN>"
  '-- VSSKEND Global/Mode#29 --

  Dim Win2KErrorUrl
  Win2KErrorUrl = hostName & "win2k.htm"

  ' get the various interfaces
  Dim IVSProfMgmt
  Dim IVSUIPrefs
  Dim IVSCertPrefs
  Dim IVSSrchCrit
  Dim IVSSelectedID
  Dim IVSRoamPrefs

  On Error Resume Next
  Set IVSProfMgmt = IVSPTA.IVSProfMgmt
  If (Hex(err.number) = "1B6") Then
         window.location = Win2KErrorUrl
  End if
  Set IVSUIPrefs = IVSPTA.IVSUIPrefs
  Set IVSCertPrefs = IVSPTA.IVSCertPrefs
  Set IVSSrchCrit = IVSPTA.IVSSrchCrit
  Set IVSSelectedID = IVSPTA.IVSSelectedDigID
  Set IVSRoamPrefs = IVSPTA.IVSRoamPrefs

'--------------------------------------------------------

  
  Sub RenewDigitalID
    Dim RenewUrl

    RenewUrl = "digitalidCenter.htm"
    window.navigate RenewUrl
  End Sub
  
  Function SignUp
    Dim EnrollUrl

    '-- VSSKBEGIN Apps/KeyManager#10#no#1.0.0.0#1025 --
            Dim EnrollPage
            EnrollPage= "digitalidCenter.htm"
    '-- VSSKEND Apps/KeyManager#10 --
    
    EnrollUrl = EnrollPage
    window.navigate EnrollUrl
  End Function

  ' This sub will call the close method for the PTA 
  Function CloseObjects (ErrorCode, Operation, WinErrorCode)
    On Error Resume Next
    IVSPTA.Close
    if ( ErrorCode <> 0 ) then
       Call SetErrorInfo ("", CheckErrorCodeMS(ErrorCode), WinErrorCode, Operation)
       Exit Function
    end if 
    If ( err.number <> 0 ) then
        Call SetErrorInfo("", 00000001, Hex(err.number), "IVSPTA.Close")
        Exit Function
    End If
  End Function

Sub pressedSignItNew(byval dialogType)
 Dim Choice
 Dim SelExpDate
 Dim ShortSelExpDate

    '-- VSSKBEGIN Apps/PTAv2#1#yes#1.0.0.2#29416 --
' the VBSCript variables made available on PTA login and transaction pages
 Dim strCertStore
 Dim strAppCtxtName
 Dim strCertIssuerDN
 Dim strLoginWizardTitle
 Dim strLoginChooseTitle 
 Dim strLoginChooseText
 Dim strLoginTitle
 Dim strLoginText
 Dim strAppLogoUrl
 Dim strAffiliateLogoUrl
 Dim AbtToExpWindow
 Dim strSignWizardTitle
 Dim strSignChooseTitle
 Dim strSignChooseText
 Dim strSignTitle
 Dim strSignText
 Dim strReviewTitle
 Dim strReviewText
 Dim saveLocal 
 Dim strClientInfo
 Dim strClientInfoSig

 Dim strLoginChooseHelpUrl 
 Dim strLoginHelpUrl
 Dim strSignHelpUrl 
 Dim strReviewHelpUrl
 Dim strSignChooseHelpUrl
 Dim strUnLockHelpUrl

 strCertStore = "2"
 strAppCtxtName = "Test Application"
 'strCertIssuerDN = "O=mySecureSign Pilot; CN=PSO Test CA"
 'strCertIssuerDN = "O= mySecureSign, Inc.; OU = VeriSign Trust Network; OU = Terms of use at https://www.mysecuresign.com/rpa (c)01; CN = mySecureSign Class 2 OnSite Individual Subscriber CA"
 'strCertIssuerDN = "CN=PSO Test CA"
 strCertIssuerDN = "CN=UNIONBANK Class 2 CA"
 'strCertIssuerDN = "CN=mySecureSign Class 2 OnSite Individual Subscriber Test CA"
 'strCertIssuerDN = "O=Philippine Stock Exchange, Inc."
 strLoginWizardTitle = "User Authentication"
 strLoginChooseTitle = "Enter Username And Password"
 strLoginChooseText = "Enter you account name and password"
 strLoginTitle = "Select Digital ID"
 strLoginText = "Select the Digital ID that you like to present to login to the website."
 strAppLogoUrl = "https://inting.mysecuresign.com/UBPLogo.bmp"
 strAffiliateLogoUrl = ""
 strSignWizardTitle = "Sign Message"
 strSignChooseTitle = "Enter Username And Password"
 strSignChooseText = "Enter you account name and password"
 strSignTitle = "Digital ID"
 strSignText = "Select the Digital ID that you would like to present to the website."
 strReviewTitle = "Review Message"
 strReviewText = "Review the following message before signing it." 
 saveLocal = "disabled"
 strClientInfo = ""
 strClientInfoSig = ""

 AbtToExpWindow = 31

 '-- VSSKBEGIN Global/Mode#35#manualauth#1.0.0.0#512 --
   Dim helpHostName
   helpHostName = "https://inting.mysecuresign.com"
 '-- VSSKEND Global/Mode#35 --

 strLoginHelpUrl = helpHostName & "ptalogin.htm"
 strSignHelpUrl = helpHostName & "sign.htm"
 strReviewHelpUrl = helpHostName & "review.htm"
 strSignChooseHelpUrl = helpHostName & "signchoose.htm"
    '-- VSSKEND Apps/PTAv2#1 --

 setMessage()

 ' Initialize the PTA Object
 On Error Resume Next
    
 if (strCertStore = "1") then 
    IVSPTA.Initialize strAppCtxtName,0
 else
    IVSPTA.Initialize strAppCtxtName,1
 End If
 If ( err.number <> 0 ) then
    Call CloseObjects(Hex(err.number), "Transaction Signing::IVSPTA.Initialize", Hex(err.number))
    Exit Sub
 End If

 ' Initialize the Search Criteria
 On Error Resume Next
 If (Len(strCertIssuerDN) <> 0) then
     IVSSrchCrit.IssuerDN = strCertIssuerDN
     If ( err.number <> 0 ) then
        Call CloseObjects(Hex(err.number), "Transaction Signing::IVSSrchCrit.IssuerDN", Hex(err.number))
        Exit Sub
     End If
 End If
    
 EXP_DATE_GREATER_THAN = &h20
 EXP_DATE_EQUALTO      = &h10
 EXP_DATE_LESS_THAN    = &h08
 EFF_DATE_GREATER_THAN = &h04
 EFF_DATE_EQUALTO      = &h02
 EFF_DATE_LESS_THAN    = &h01

 'Initialize the Certificate Search Criterion "Date Equality"
 On Error Resume Next
 IVSSrchCrit.DateEquality = EXP_DATE_GREATER_THAN
 If ( err.number <> 0 ) then
	Call CloseObjects(Hex(err.number), "Transaction Signing::IVSSrchCrit.DateEquality", Hex(err.number))
    Exit Sub
 End If

 ' Initialize the Certificate Search Criterion "Expiry Date"
 ' to the CURRENT DATE.
 StartDate = CDate(Date)
 ShortStartDate = CDate(StartDate)

 
 On Error Resume Next
 IVSSrchCrit.ExpDate = ShortStartDate
 If ( err.number <> 0 ) then
	Call CloseObjects(Hex(err.number), "Transaction Signing::IVSSrchCrit.ExpDate", Hex(err.number))
    Exit Sub
 End If
    
 Dim boolRenewed 
 boolRenewed = CBool(0)
 ' Set flag to show only certs that have NOT been marked as RENEWED
 On Error Resume Next
 IVSSrchCrit.Renewed = boolRenewed
 If ( err.number <> 0 ) then
    Call CloseObjects(Hex(err.number), "Transaction Signing::IVSSrchCrit.Renewed", Hex(err.number))
    Exit Sub
 End If
  ' Initialize the open profile preferences
 if (strCertStore = "1") then
     On Error Resume Next
     If (Len(strSignChooseTitle) <> 0) then
        IVSUIPrefs.OpenProf_Title = strSignChooseTitle
        If ( err.number <> 0 ) then
            Call CloseObjects(Hex(err.number), "Transaction Signing::IVSUIPrefs.OpenProf_Title", Hex(err.number))
            Exit Sub
        End If
     End If

     On Error Resume Next
     If (Len(strSignChooseText) <> 0) then
       IVSUIPrefs.OpenProf_Text = strSignChooseText
       If ( err.number <> 0 ) then
           Call CloseObjects(Hex(err.number), "Transaction Signing::IVSUIPrefs.OpenProf_Text", Hex(err.number))
           Exit Sub
       End If
     End If
		
     On Error Resume Next
     If (Len(strLoginChooseHelpUrl) <> 0) then
        IVSUIPrefs.OpenProf_HelpUrl = strLoginChooseHelpUrl
        If ( err.number <> 0 ) then
          Call CloseObjects(Hex(err.number), "Transaction Signing::IVSUIPrefs.OpenProf_HelpUrl", Hex(err.number))
          Exit Sub
        End If
     End If

     On Error Resume Next
     If (Len(strUnLockHelpUrl) <> 0) then
        IVSUIPrefs.Timeout_HelpUrl = strUnLockHelpUrl
        If ( err.number <> 0 ) then
          Call CloseObjects(Hex(err.number), "Transaction Signing::IVSUIPrefs.Timeout_HelpUrl", Hex(err.number))
          Exit Sub
        End If
     End If
		
     'Flags
     OPENPROF_OPEN_ONLY = CInt(529)
     On Error Resume Next
     IVSProfMgmt.OpenProfFlags = OPENPROF_OPEN_ONLY
     If ((err.number <> 0) And (Hex(err.number) <> "8000102F") ) Then
       Call CloseObjects(Hex(err.number), "Transaction Signing::IVSProfMgmt.OpenProfFlags", Hex(err.number))
       Exit Sub
     End If

    
     '-- VSSKBEGIN Apps/PTAv2/Roaming#3#disabled#1.0.0.0#1025 --
                ' set roaming disabled 
                On Error Resume Next
                IVSProfMgmt.RoamProfile = CBool(0) 
                If ((err.number <> 0) And (Hex(err.number) <> "8000102F") ) Then
                   Call CloseObjects(Hex(err.number), "IVSProfMgmt.RoamProfile", Hex(err.number))
                   Exit Sub 
                End If
     '-- VSSKEND Apps/PTAv2/Roaming#3 --
 End If
 
' Initialize the login wizard title 
 On Error Resume Next
 If (Len(strSignWizardTitle) <> 0) then 
    IVSUIPrefs.SgnDlg_Title = strSignWizardTitle
    If ( err.number <> 0 ) then
      Call CloseObjects(Hex(err.number), "Transaction Signing::IVSUIPrefs.SgnDlg_Title", Hex(err.number))
      Exit Sub
    End If
 End If
 
 On Error Resume Next
 If (Len(strAppLogoUrl) <> 0) then
     IVSUIPrefs.UILogoUrl = strAppLogoUrl
     If ( err.number <> 0 ) then
        Call CloseObjects(Hex(err.number), "Transaction Signing::IVSUIPrefs.LogoUrl", Hex(err.number))
        Exit Sub
     End If 
 End If
	

 On Error Resume Next
 If (Len(strAffiliateLogoUrl) <> 0 And strAffiliateLogoUrl <> "VeriSign") then
     IVSPTA.AffLogoUrl = strAffiliateLogoUrl
     If ( err.number <> 0 And err.number <> &h800010c4 ) then
           Call CloseObjects(Hex(err.number), "Transaction Signing::IVSPTA.AffLogoUrl", Hex(err.number))
		   Exit Sub
     End If
 End If
 
 On Error Resume Next
 If (Len(strSignHelpUrl) <> 0) then
    IVSUIPrefs.SelID_HelpUrl = strSignChooseHelpUrl
    If ( err.number <> 0 ) then
       Call CloseObjects(Hex(err.number), "Transaction Signing::IVSUIPrefs.SelID_HelpUrl", Hex(err.number))
       Exit Sub
    End If
 End If

 On Error Resume Next
 If (Len(strReviewHelpUrl) <> 0) then
    IVSUIPrefs.RvwMsg_HelpUrl = strReviewHelpUrl
    If ( err.number <> 0 ) then
       Call CloseObjects(Hex(err.number), "Transaction Signing::IVSUIPrefs.RvwMsg_HelpUrl", Hex(err.number))
       Exit Sub
    End If
 End If
    
' set the 2 dialog texts and titles.
' set the select id preferences
On Error Resume Next
If (Len(strSignTitle) <> 0) then 
    IVSUIPrefs.SelID_Title = strSignTitle
    If ( err.number <> 0 ) then
       Call CloseObjects(Hex(err.number), "Transaction Signing::IVSUIPrefs.SelID_Title", Hex(err.number))
       Exit Sub
    End If 
End If
 
On Error Resume Next
If (Len(strSignText) <> 0) then 
    IVSUIPrefs.SelID_Text = strSignText
    If ( err.number <> 0 ) then
        Call CloseObjects(Hex(err.number), "Transaction Signing::IVSUIPrefs.SelID_Text", Hex(err.number))             
        Exit Sub
    End If
End If

' set the review message preferences
On Error Resume Next
If (Len(strReviewTitle) <> 0) then 
    IVSUIPrefs.RvwMsg_Title = strReviewTitle
    If ( err.number <> 0 ) then
       Call CloseObjects(Hex(err.number), "Transaction Signing::IVSUIPrefs.RvwMsg_Title", Hex(err.number))
       Exit Sub
    End If 
End If

On Error Resume Next
If (Len(strReviewText) <> 0) then 
    IVSUIPrefs.RvwMsg_Text = strReviewText
    If ( err.number <> 0 ) then
        Call CloseObjects(Hex(err.number), "Transaction Signing::IVSUIPrefs.RvwMsg_Text", Hex(err.number))
        Exit Sub
    End If
End If

On Error Resume Next
IVSUIPrefs.SelID_OKBtnText = CInt(122)
if (err.number <> 0) then
    Call CloseObjects(Hex(err.number), "Transaction Signing::IVSUIPrefs.SelID_OKBtnText", Hex(err.number))
    Exit Sub
End If
    
On Error Resume Next
IVSUIPrefs.RvwMsg_OKBtnText = CInt(123)
if (err.number <> 0) then
    Call CloseObjects(Hex(err.number), "Transaction Signing::IVSUIPrefs.RvwMsg_OKBtnText", Hex(err.number))
    Exit Sub
End If


Dim boolShowDef
boolShowDef = CBool(0)
On Error Resume Next
IVSUIPrefs.SelID_ShowDefChkBox = boolShowDef
If ( err.number <> 0 ) then
    Call CloseObjects(Hex(err.number), "Transaction Signing::IVSUIPrefs.SelID_ShowDefChkBox", Hex(err.number))
    Exit Sub
End If

MD5 = 3
SHA1 = 4 
		
' Some special error codes returned by the Sign function
'VS_DEFAULT_SELECTED	=	&h80000003
'VS_NO_MATCHES	=	&h80000004
'VS_NO_CERT_SEL	=	&h80000005
'VS_CERT_SELECTED	=	&h80000006
VS_CERTNOMATCHCRIT = &h80001095
VS_CERTMATCHBUTEXP = &h80001096
VS_PROFDOESNOTEXIST = &h8000102B
VS_SUCCESS = &h00000000
VS_USER_CANCELLED = &h80001067
VS_CERTNOTFOUND = &h80001091
VS_HTMLMSG_DEF_COLORDIFF = &h8000110C


On Error Resume Next
if dialogType = "login" then
	Signature = IVSPTA.SignChallenge(Msgg, CInt(MD5))
else
	Signature = IVSPTA.SignTransaction(Msgg, CInt(MD5))
end if
'If (err.number <> 0) then
'  Call CloseObjects(Hex(err.number), "Transaction Signing::IVSPTA.SignTransaction", Hex(err.number))
'  Exit Sub
'End If
		
' some special handling needs to be done.
If ( err.number <> 0 )then
   If (err.number = VS_HTMLMSG_DEF_COLORDIFF ) then 
       errString = "Your browser settings prevent us from displaying your transaction" & vbCRLF & _
                   "Please change your default color settings for Internet Explorer" & vbCRLF & _
                   "try again."
       Call MsgBox (errString, 48, "Transaction Signing Error")
       Call CloseObjects(0, "", 0)
       Exit Sub
   End If 

   If (err.number = VS_CERTMATCHBUTEXP) then
       errString = "You do not have a valid Digital ID." &vbCRLF &_
                   "Now the PTA will try to renew your expired Digital IDs."
       Call MsgBox (errString, 48, "Transaction Signing Error")
       Call CloseObjects(0, "", 0)
       RenewDigitalID()       
       Exit Sub
   Else
       If ((err.number = VS_CERTNOMATCHCRIT) Or (err.number = VS_PROFDOESNOTEXIST)Or (err.number = VS_CERTNOTFOUND)) then
          Call CloseObjects(0, "", 0)
          errString = "You do not have a valid Digital ID." &vbCRLF & _
                      "Would you like to enroll for a Digital ID at this time?"
          Choice = MsgBox (errString, 52, "Transaction Signing")
          if ( 6 = Choice ) then
              SignUp()
          end if 
          Exit Sub 
       Else 
           If (err.number = VS_USER_CANCELLED) then 				
               errString = "You have cancelled the operation." & vbCRLF & _
                           "Please click submit again to continue"                    
               Call MsgBox (errString, 48, "Transaction Signing Error")
               Call CloseObjects(0, "", 0)
               Exit Sub
              
           Else        
               Call CloseObjects(Hex(err.number), "Transaction Signing::IVSPTA.SignTransaction", Hex(err.number))
               Exit Sub
           End If
       End If
   End If
End If 
 
Call CloseObjects(0, "", 0)
document.frmSign.dataToSign.value = Msgg
'msgbox Msgg
document.frmSign.dataSignature.value = Signature
'msgbox Signature
document.frmSign.submit
End Sub

Function CancelSign()
	document.frmSign.dataSignature.value = "CANCEL"
	frmSign.submit
End function
'-->
