Option Explicit

' The path of the Skype program files
Const SkypePath = "C:\Program Files\Skype\Phone\Skype.exe"

' Use Windows Dialer for local numbers?
Const UseWindowsDialerForLocalNumbers = True

' finPOWER constants
Const iseContactMethodPhone = 2
Const iseContactMethodFacsimile = 5
Const iseContactMethodMobile = 6
Const iseContactMethodMobileSMS = 7
Const iseContactMethodPager = 8
Const iseContactMethodInternetPhone = 9

Function Main(ByVal finBL, ByVal PhoneNumber, ByVal OtherPartyName, ByVal Comment, ByVal ContactMethod, ByVal ContactMethodDescription, ByVal SourceObject) 'VBScript
'VBA Function Main(ByVal finBL As ISfinSupport, ByVal PhoneNumber As String, ByVal OtherPartyName As String, ByVal Comment As String, ByVal ContactMethod As Integer, ByVal ContactMethodDescription As String, ByVal SourceObject As Object)

' Function should return a boolean value depending on its success
Main = True

Dim UseSkype

' Initialise
finBL.ISValidate.PhoneNumberSet PhoneNumber

' This Script assumes that if a special 'Internet Phone' Contact Method named 'Skype' is set up then this contains the SkypeId E.g. p_smith and therefore we should always use Skype
If ContactMethod = iseContactMethodInternetPhone And ContactMethodDescription = "Skype" Then
  UseSkype = True
ElseIf UseWindowsDialerForLocalNumbers Then
  ' Determine if this is a Local Number
  If finBL.ISValidate.PhoneAreaCode = finBL.Settings.TelephoneAreaCode And Len(finBL.ISValidate.PhoneNumberFull) <> 0 Then
    UseSkype = False
  Else
    UseSkype = True
  End If
Else
  UseSkype = True
End If

' Format phone number to include Country Code if using Skype
If UseSkype Then
  If Len(finBL.ISValidate.PhoneNumberFull) <> 0 Then
    PhoneNumber = finBL.ISValidate.PhoneNumberFull
  End If
End If

' Dial
If UseSkype Then
  If Not finBL.ISRuntime.OpenAssociatedApplication(0, SkypePath & "?/nospash /minimized /callto:" & Chr(34) & PhoneNumber & Chr(34)) Then
    Main = False
    finBL.ErrorMessageSet "Failed to launch Skype (" & SkypePath & ")."
  End If
Else
  Main = finBL.PhoneDialWindowsDialer(PhoneNumber, OtherParty, Comment)
End If

' Write a Client Log
If Main Then
  If TypeName(SourceObject) = "finClient" Then

  End If
End If

End Function


