#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/sf /sv /om /cs=0 /cn=0
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Res_Description=AD User Account Creator adds user accounts from a text file to AD
#AutoIt3Wrapper_Res_Fileversion=0.9.1.0
#AutoIt3Wrapper_Res_Language=1033
#AutoIt3Wrapper_Res_Field=ProductName|AD User Account Creator
#AutoIt3Wrapper_Res_Field=Version|0.91
#AutoIt3Wrapper_Res_Field=Build|2011-09-19 beta
#AutoIt3Wrapper_Res_Field=CompanyName|UEZ Software Production
#AutoIt3Wrapper_Res_Field=Coded by|UEZ
#AutoIt3Wrapper_Res_Field=Compile date|%longdate% %time%
#AutoIt3Wrapper_Res_Field=AutoIt Version|%AutoItVer%
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_UPX_Parameters=--ultra-brute --crp-ms=999999 --all-methods --all-filters
;~ #AutoIt3Wrapper_Run_After=..\..\..\ResourceHacker\ResHacker.exe -delete %out%, %out%, ICON, 1,
;~ #AutoIt3Wrapper_Run_After=..\..\..\ResourceHacker\ResHacker.exe -delete %out%, %out%, ICON, 2,
;~ #AutoIt3Wrapper_Run_After=..\..\..\ResourceHacker\ResHacker.exe -delete %out%, %out%, ICON, 3,
;~ #AutoIt3Wrapper_Run_After=..\..\..\ResourceHacker\ResHacker.exe -delete %out%, %out%, MENU, 166,
;~ #AutoIt3Wrapper_Run_After=..\..\..\ResourceHacker\ResHacker.exe -delete %out%, %out%, DIALOG, 1000,
;~ #AutoIt3Wrapper_Run_After=..\..\..\ResourceHacker\ResHacker.exe -delete %out%, %out%, ICONGROUP, 162,
;~ #AutoIt3Wrapper_Run_After=..\..\..\ResourceHacker\ResHacker.exe -delete %out%, %out%, ICONGROUP, 164,
;~ #AutoIt3Wrapper_Run_After=..\..\..\ResourceHacker\ResHacker.exe -delete %out%, %out%, ICONGROUP, 169,
#AutoIt3Wrapper_Run_After=del /f /q "%scriptdir%\%scriptfile%_Obfuscated.au3"
;~ #AutoIt3Wrapper_Run_After=upx.exe --ultra-brute --crp-ms=999999 --all-methods --all-filters "%out%"
#AutoIt3Wrapper_Run_After=upx.exe --best --lzma "%out%"
;~ #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6


#include <AD.au3>
#include <Array.au3>
#include <EditConstants.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <GuiStatusBar.au3>
#include <ListViewConstants.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

#NoTrayIcon
#RequireAdmin

Opt("MustDeclareVars", 1)

Global Const $ver = "v0.91 "
Global Const $build = "Build 2011-09-19 Beta"
If $CmdLine[0] And ($CmdLine[1] = "/debug" Or $CmdLine[1] = "-debug") Then $iAD_Debug = 2
SplashTextOn("Information", "Please be patient - trying to connect to Active Directory!", 680, 60, -1, -1, 1 + 16 + 32, "Arial", 18, 800)
Global Const $AD_UDF = _AD_Open()
Global $AD_UDF_err = @error
Global $AD_UDF_err_code
SplashOff()

Switch $AD_UDF_err
	Case 1
		$AD_UDF_err_code = "Installation of the custom error handler failed"
	Case 2
		$AD_UDF_err_code = "Creation of the COM object to the AD failed"
	Case 3
		$AD_UDF_err_code = "Open the connection to AD failed (among others generated if the user doesn't has query / modify access)"
	Case 4
		$AD_UDF_err_code = "Creation of the RootDSE object failed (generated when connection to the domain isn't successful)"
	Case 5
		$AD_UDF_err_code = "Creation of the DS object failed"
	Case 6
		$AD_UDF_err_code = "Parameter $sAD_HostServerParam and $sAD_ConfigurationParam are required when $sAD_DNSDomainParam is specified"
	Case 7
		$AD_UDF_err_code = "Parameter $sAD_PasswordParam is required when $sAD_UserIdParam is specified"
	Case 8
		$AD_UDF_err_code = "OpenDSObject method failed (on Windows XP or lower this shows that $sAD_UserIdParam and/or $sAD_PasswordParam are invalid)"
	Case Else
		$AD_UDF_err_code = "Undefined error has occured"
EndSwitch


Global Const $logfile = "AD User Account Creator.log"
If FileExists($logfile) And FileGetSize($logfile) > 10 * 1024 ^ 2 Then FileMove($logfile, FileGetTime($logfile, 0, 1) & "_" & $logfile)
WriteLog("Started by user: " & @LogonDomain & "\" & @UserName)

If Not $AD_UDF Then
	WriteLog("An unexpected error has occured! Error code is: " & $AD_UDF_err & " (" & @extended & ") - " & $AD_UDF_err_code)
	WriteLog("Ended." & @CRLF & @CRLF)
	_AD_Close()
	Exit MsgBox(16, "Error", "An unexpected error has occured! Error code is: " & $AD_UDF_err & " ->" & @CRLF & @CRLF & $AD_UDF_err_code, 30)
EndIf

If @LogonDNSDomain = "" Then
	WriteLog("Script aborted! Not logged in to a domain!")
	WriteLog("Ended." & @CRLF & @CRLF)
	_AD_Close()
	Exit MsgBox(16, "Error", "You must be logged on to the domain!", 30)
EndIf

Global $domain = @LogonDNSDomain
If $domain = "" Then $domain = @LogonDomain

Global Const $width = 1024, $height = 600
Global Const $hGUI = GUICreate("AD User Account Creator " & $ver & $build, $width, $height, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_TABSTOP))
GUISetBkColor(0xF0E0D0)
Global Const $MenuItem = GUICtrlCreateMenu("&?")
Global Const $mAbout = GUICtrlCreateMenuItem("About", $MenuItem)

Global Const $StatusBar = _GUICtrlStatusBar_Create($hGUI)
Global $StatusBar_PartsWidth[4] = [72, 132, 172, 250]
_GUICtrlStatusBar_SetParts($StatusBar, $StatusBar_PartsWidth)
_GUICtrlStatusBar_SetText($StatusBar, "Items found:", 0)
_GUICtrlStatusBar_SetText($StatusBar, 0, 1)
_GUICtrlStatusBar_SetText($StatusBar, "Errors:", 2)
_GUICtrlStatusBar_SetText($StatusBar, "none", 3)

Global Const $Progressbar = GUICtrlCreateProgress(8, 536, 1010, 17, $PBS_SMOOTH)

Global Const $Group = GUICtrlCreateGroup("Domain: " & $domain, 8, 8, 1009, 489)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")

Global Const $ListView = GUICtrlCreateListView("Status|User Account|Destination OU (FQDN Syntax)|First Name|Last Name|Phone No.|City|Street|Country|EMail|Mobile|Comment", 20, 32, 986, 454, _
		BitOR($GUI_SS_DEFAULT_LISTVIEW, $LVS_NOSORTHEADER, $WS_VSCROLL), _
		BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $LVS_EX_DOUBLEBUFFER))
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 60) ;$LVSCW_AUTOSIZE_USEHEADER
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 85)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 200)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 3, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 4, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 5, 80)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 6, 110)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 7, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 8, 80)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 9, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 10, 80)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 11, 85)
;~ _GUICtrlListView_JustifyColumn(GUICtrlGetHandle($ListView), 0, 2)
;~ _GUICtrlListView_JustifyColumn(GUICtrlGetHandle($ListView), 1, 2)
;~ _GUICtrlListView_JustifyColumn(GUICtrlGetHandle($ListView), 2, 2)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_LV_ALTERNATE)

GUICtrlCreateGroup("", -99, -99, 1, 1)

Global Const $bLoad = GUICtrlCreateButton("Load", 8, 504, 75, 25)
Global Const $bAdd = GUICtrlCreateButton("Add to AD", 112, 504, 75, 25)
GUICtrlSetState(-1, $GUI_DISABLE)
Global Const $bExit = GUICtrlCreateButton("Exit", 942, 504, 75, 25)

Global Const $lPassword = GUICtrlCreateLabel("Set Default Password", 394, 508, 118, 19)
GUICtrlSetFont(-1, 10, 400, 0, "Times New Roman")
GUICtrlSetTip(-1, "Must be set to proceed! Minimum password length are 8 characters!")
Global Const $iPassword = GUICtrlCreateInput("", 514, 506, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_PASSWORD))
GUICtrlSetBkColor(-1, 0xFF0000)

Global Const $lCounter = GUICtrlCreateLabel("", 475, 536, 74, 16, $SS_CENTER)
GUICtrlSetFont(-1, 10, 800, 0, "Arial")
GUICtrlSetColor(-1, 0xE787FF)
GUICtrlSetBkColor(-1, -2)

_GDIPlus_Startup()

Global $hImage_ok = Load_BMP_From_Mem(OK())
Global $hImage_nok = Load_BMP_From_Mem(NOK())

Local $hBmp_ok = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage_ok)
Local $hBmp_nok = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage_nok)

Global $hIcons = _GUIImageList_Create(16, 16, 5, 3)
_GUIImageList_Add($hIcons, $hBmp_nok)
_GUIImageList_Add($hIcons, $hBmp_ok)
_GUICtrlListView_SetImageList($ListView, $hIcons, 1)

_GDIPlus_ImageDispose($hImage_nok)
_GDIPlus_ImageDispose($hImage_ok)
_WinAPI_DeleteObject($hBmp_nok)
_WinAPI_DeleteObject($hBmp_ok)
_GDIPlus_Shutdown()

GUISetState(@SW_SHOW)

Global $aFileContent, $ad, $error = 0, $nMsg, $file, $msg, $mcursor_old, $aPassword
Global $DefaultPassChar = GUICtrlSendMsg($iPassword, $EM_GETPASSWORDCHAR, 0, 0)
Global $list_loaded = False, $m = False

Global Const $aWS = WinGetPos($hGUI)
Global Const $minwidth = $aWS[2]
Global Const $minheight = $aWS[3]

GUIRegisterMsg($WM_SIZE, "WM_SIZE")
GUIRegisterMsg($WM_GETMINMAXINFO, "WM_GETMINMAXINFO")

While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE, $bExit
			GUIRegisterMsg($WM_SIZE, "")
			GUIRegisterMsg($WM_GETMINMAXINFO, "")
			_AD_Close()
			WriteLog("Ended." & @CRLF & @CRLF)
			GUIDelete($hGUI)
			Exit
		Case $bLoad
			$file = FileOpenDialog("Select a file with appropriate information", "", "Text File (*.txt;*.csv)")
			If Not @error Then
				WriteLog($file & " loaded properly")
				_GUICtrlStatusBar_SetText($StatusBar, 0, 1)
				_GUICtrlStatusBar_SetText($StatusBar, "none", 3)
				_GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($ListView))
				$mcursor_old = MouseGetCursor()
				GUISetCursor(15, 1, $hGUI)
				GUISetState(@SW_DISABLE, $hGUI)
				$error = ParseFile($file)
				GUISetState(@SW_ENABLE, $hGUI)
				GUISetCursor($mcursor_old)
			Else
				WriteLog($file & " could not be loaded!")
				MsgBox(16, "Error", $file & " could not be loaded!", 30, $hGUI)
			EndIf
		Case $bAdd
			$msg = MsgBox(32 + 4 + 256, "Question", "Proceed with creating user ids in AD?", 0, $hGUI)
			If $msg = 6 Then
				$mcursor_old = MouseGetCursor()
				GUISetCursor(15, 1, $hGUI)
				GUISetState(@SW_DISABLE, $hGUI)
				$ad = Add2AD()
				GUISetState(@SW_ENABLE, $hGUI)
				$list_loaded = False
				GUISetCursor($mcursor_old)
				If $error Or $ad Then
					MsgBox(48, "Warning", "One or more errors have occured. Please check log file for more details!", 60, $hGUI)
				Else
					MsgBox(64, "Information", "No errors have occured!", 60, $hGUI)
				EndIf
				GUICtrlSetData($Progressbar, 0)
			EndIf
		Case $mAbout
			MsgBox(64, "About", "AD User Account Creator" & @CRLF & $ver & $build & @CRLF & @CRLF & _
					"Coded by UEZ" & @CRLF & @CRLF & @CRLF & _
					"Thanks to Water for the great AD UDF ;-)" & @CRLF & @CRLF, 60, $hGUI)
	EndSwitch
	$aPassword = GUIGetCursorInfo()
	If Not @error Then
		$mcursor_old = MouseGetCursor()
		If $aPassword[4] = $iPassword Then
			GUICtrlSendMsg($iPassword, $EM_SETPASSWORDCHAR, 0, 0)
			GUISetCursor(16, 1, $hGUI)
			$m = True
			If $list_loaded And Stringlen(GUICtrlRead($iPassword)) > 7 Then
				If BitAND(GUICtrlGetState($bAdd), $GUI_DISABLE) = $GUI_DISABLE Then
					GUICtrlSetState($bAdd, $GUI_ENABLE)
					GUICtrlSetBkColor($iPassword, 0xFFFFFF)
				EndIf
			Else
				If BitAND(GUICtrlGetState($bAdd), $GUI_ENABLE) = $GUI_ENABLE Then
					GUICtrlSetState($bAdd, $GUI_DISABLE)
					GUICtrlSetBkColor($iPassword, 0xFF0000)
				EndIf
			EndIf
		Else
			If $m Then
				GUICtrlSendMsg($iPassword, $EM_SETPASSWORDCHAR, $DefaultPassChar, 0)
;~ 				GUICtrlSetState($iPassword, $GUI_FOCUS)
				ControlFocus("", "", $hGUI)
				$m = False
			EndIf
			GUISetCursor($mcursor_old)
		EndIf
	EndIf
WEnd

Func ParseFile($file)
	Local $j, $k, $sFile, $chk = 0, $sData, $fname = StringRegExpReplace($file, ".*\\(.*)$", "$1")
	$sFile = FileRead($file)
	$aFileContent = StringSplitW($sFile, "|")

	If @error Or UBound($aFileContent, 2) < 4 Then
		WriteLog("Error: Content of " & $file & " is wrong!")
		_GUICtrlStatusBar_SetText($StatusBar, " Wrong content of file " & $fname & " has been detected!", 3)
		GUISetState(@SW_ENABLE, $hGUI)
		Return MsgBox(16, "Error", "Wrong content of text file has been detected!", 30, $hGUI)
	EndIf

	$chk = PlausibilityCheck($aFileContent)
	If $chk Then _GUICtrlStatusBar_SetText($StatusBar, " some warrning/errors occured during file check. Check logfile for details!", 3)

	If Not UBound($aFileContent) Then
		WriteLog("Warning: File list is empty after plausibility check!")
		GUISetState(@SW_ENABLE, $hGUI)
		Return MsgBox(48, "Information", "Warning: List is empty because wrong entries were ignored!", 30, $hGUI)
	EndIf

	_GUICtrlStatusBar_SetText($StatusBar, UBound($aFileContent), 1)

	GUICtrlSetState($ListView, $GUI_HIDE)
	For $j = 0 To UBound($aFileContent) - 1
		For $k = 0 To Min(UBound($aFileContent, 2) - 1, 10)
			$sData &= "|" & $aFileContent[$j][$k]
		Next
		GUICtrlCreateListViewItem($sData, $ListView)
		GUICtrlSetBkColor(-1, 0xE8E8FF) ;RGB
		$sData = ""
	Next
	GUICtrlSetState($ListView, $GUI_SHOW)
	$list_loaded = True
	Return $chk
EndFunc   ;==>ParseFile

Func PlausibilityCheck(ByRef $array)
	Local $i = 0, $j, $regex, $err = False
	Local $aDupCheck[1], $index

	$i = 0
	While $i < UBound($array) ;search for duplicated entries
		For $j = 0 To UBound($array, 2) - 1
			$array[$i][$j] = StringStripWS(StringStripCR($array[$i][$j]), 3)
		Next
		$index = _ArraySearch($aDupCheck, $array[$i][0])
		If @error Then
			_ArrayAdd($aDupCheck, $array[$i][0])
		Else ;duplicated entries found
			WriteLog("Warning: Duplicated entry '" & $array[$i][0] & "' found. Whole line will be ignored!")
			_ArrayDelete($array, $i)
			$err = True
			$i -= 1
		EndIf
		$i += 1
	WEnd

	$i = 0
	While $i < UBound($array)
		$regex = StringRegExp($array[$i][0], '[\"|\/|\/|\\|\[|\]|\:|\;|\||\=|\,|\+|\*|\?|\<|\>]', 3)
		If Not @error Then
			WriteLog("Warning: User ID " & $array[$i][0] & " has a wrong name convention. Whole line will be ignored!")
			_ArrayDelete($array, $i)
			$err = True
			$i -= 1
		EndIf
		$i += 1
	WEnd

	$i = 0
	While $i < UBound($array)
		If Not _AD_ObjectExists($array[$i][1], "distinguishedName") Then
			WriteLog("Warning: OU " & $array[$i][1] & " doesn't exist in AD. Whole line will be ignored!")
			_ArrayDelete($array, $i)
			$err = True
			$i -= 1
		EndIf
		$i += 1
	WEnd

	$i = 0
	While $i < UBound($array)
		If $array[$i][2] = "" Or $array[$i][3] = "" Then
			WriteLog("Warning: First and/or lastname of user id " & $array[$i][0] & " is missing. Whole line will be ignored!")
			_ArrayDelete($array, $i)
			$err = True
			$i -= 1
		EndIf
		$i += 1
	WEnd

	Return $err
EndFunc   ;==>PlausibilityCheck

Func Min($a, $b)
	If $a > $b Then Return $b
	Return $a
EndFunc

Func Add2AD()
	Local $aCountry[2], $add, $index, $j, $k, $ec, $err_occured = False
	_GUICtrlListView_Scroll($ListView, 0, -0xFFFF)
	$index = UBound($aFileContent)
	$j = 1
	For $i = 0 To UBound($aFileContent) - 1
		GUICtrlSetData($lCounter, $j & "/" & $index)
		$add = _AD_CreateUser($aFileContent[$i][1], $aFileContent[$i][0], $aFileContent[$i][2] & " " & $aFileContent[$i][3])
		$ec = @error
		If Not $ec Then
			For $k = 2 To UBound($aFileContent, 2) - 1
				Switch $k
					Case 2
						_AD_ModifyAttribute($aFileContent[$i][0], "givenName", $aFileContent[$i][$k], 2)
						If @error Then WriteLog("Error: Attribute First Name for user id " & $aFileContent[$i][0] & " could not be set!")
					Case 3
						_AD_ModifyAttribute($aFileContent[$i][0], "sn", $aFileContent[$i][$k], 2)
						If @error Then WriteLog("Error: Attribute Last Name for user id " & $aFileContent[$i][0] & " could not be set!")
						_AD_ModifyAttribute($aFileContent[$i][0], "displayName", $aFileContent[$i][2] & " " & $aFileContent[$i][3], 2)
						If @error Then WriteLog("Error: Attribute Display Name for user id " & $aFileContent[$i][0] & " could not be set!")
					Case 4
						If $aFileContent[$i][$k] <> "" Then _AD_ModifyAttribute($aFileContent[$i][0], "telephoneNumber", $aFileContent[$i][$k], 2)
					Case 5
						If $aFileContent[$i][$k] <> "" Then _AD_ModifyAttribute($aFileContent[$i][0], "l", $aFileContent[$i][$k], 2)
					Case 6
						If $aFileContent[$i][$k] <> "" Then _AD_ModifyAttribute($aFileContent[$i][0], "streetAddress", $aFileContent[$i][$k], 2)
					Case 7
						If $aFileContent[$i][$k] <> "" Then
							$aCountry = GetCountryCodes($aFileContent[$i][$k])
							If not @error Then
								_AD_ModifyAttribute($aFileContent[$i][0], "co", $aFileContent[$i][$k], 2)
								_AD_ModifyAttribute($aFileContent[$i][0], "c", $aCountry[0], 2)
								_AD_ModifyAttribute($aFileContent[$i][0], "countryCode", $aCountry[1], 2)
							EndIf
						EndIf
					Case 8
						If $aFileContent[$i][$k] <> "" Then _AD_ModifyAttribute($aFileContent[$i][0], "mail", $aFileContent[$i][$k], 2)
					Case 9
						If $aFileContent[$i][$k] <> "" Then _AD_ModifyAttribute($aFileContent[$i][0], "mobile", $aFileContent[$i][$k], 2)
					Case 10
						If $aFileContent[$i][$k] <> "" Then _AD_ModifyAttribute($aFileContent[$i][0], "description", $aFileContent[$i][$k], 2)
					EndSwitch
			Next
			_AD_SetPassword($aFileContent[$i][0], GUICtrlRead($iPassword), 1)
			WriteLog("User ID " & $aFileContent[$i][0] & " created successfully")
			_GUICtrlListView_AddSubItem($ListView, $j - 1, "OK", 0, 1)
		Else
			$err_occured = $ec
			Switch $ec
				Case 1
					WriteLog("Error: User ID " & $aFileContent[$i][0] & " already exists in AD!")
				Case 2
					WriteLog("Error: OU " & $aFileContent[$i][1] & " does not exit in AD")
				Case 3
					WriteLog("Error: Common Name not given for user id " &$aFileContent[$i][0] & "!")
				Case 4
					WriteLog("Error: User ID is missing!")
				Case Else
					WriteLog("Error: An unexpected error " & $ec & " has accoured!")
			EndSwitch
			_GUICtrlListView_AddSubItem($ListView, $j - 1, "Error", 0, 0)
			_GUICtrlStatusBar_SetText($StatusBar, " problems occured during creation! Check log file for details!", 3)
		EndIf
		If $i > 15 Then _GUICtrlListView_Scroll($ListView, 0, 16)
		GUICtrlSetData($Progressbar, $j / $index * 100)
		$j += 1
	Next
	GUICtrlSetState($bAdd, $GUI_DISABLE)
	Return $err_occured
EndFunc   ;==>Add2AD

Func GetCountryCodes($country)
#region Country Codes according to http://en.wikipedia.org/wiki/ISO_3166-1
	Local $aCountries[248][3]
	$aCountries[0][0] = "Afghanistan"
	$aCountries[0][1] = "AF"
	$aCountries[0][2] = "4"
	$aCountries[1][0] = "Åland Islands"
	$aCountries[1][1] = "AX"
	$aCountries[1][2] = "248"
	$aCountries[2][0] = "Albania"
	$aCountries[2][1] = "AL"
	$aCountries[2][2] = "8"
	$aCountries[3][0] = "Algeria"
	$aCountries[3][1] = "DZ"
	$aCountries[3][2] = "12"
	$aCountries[4][0] = "American Samoa"
	$aCountries[4][1] = "AS"
	$aCountries[4][2] = "16"
	$aCountries[5][0] = "Andorra"
	$aCountries[5][1] = "AD"
	$aCountries[5][2] = "20"
	$aCountries[6][0] = "Angola"
	$aCountries[6][1] = "AO"
	$aCountries[6][2] = "24"
	$aCountries[7][0] = "Anguilla"
	$aCountries[7][1] = "AI"
	$aCountries[7][2] = "660"
	$aCountries[8][0] = "Antarctica"
	$aCountries[8][1] = "AQ"
	$aCountries[8][2] = "10"
	$aCountries[9][0] = "Antigua and Barbuda"
	$aCountries[9][1] = "AG"
	$aCountries[9][2] = "28"
	$aCountries[10][0] = "Argentina"
	$aCountries[10][1] = "AR"
	$aCountries[10][2] = "32"
	$aCountries[11][0] = "Armenia"
	$aCountries[11][1] = "AM"
	$aCountries[11][2] = "51"
	$aCountries[12][0] = "Aruba"
	$aCountries[12][1] = "AW"
	$aCountries[12][2] = "533"
	$aCountries[13][0] = "Australia"
	$aCountries[13][1] = "AU"
	$aCountries[13][2] = "36"
	$aCountries[14][0] = "Austria"
	$aCountries[14][1] = "AT"
	$aCountries[14][2] = "40"
	$aCountries[15][0] = "Azerbaijan"
	$aCountries[15][1] = "AZ"
	$aCountries[15][2] = "31"
	$aCountries[16][0] = "Bahamas"
	$aCountries[16][1] = "BS"
	$aCountries[16][2] = "44"
	$aCountries[17][0] = "Bahrain"
	$aCountries[17][1] = "BH"
	$aCountries[17][2] = "48"
	$aCountries[18][0] = "Bangladesh"
	$aCountries[18][1] = "BD"
	$aCountries[18][2] = "50"
	$aCountries[19][0] = "Barbados"
	$aCountries[19][1] = "BB"
	$aCountries[19][2] = "52"
	$aCountries[20][0] = "Belarus"
	$aCountries[20][1] = "BY"
	$aCountries[20][2] = "112"
	$aCountries[21][0] = "Belgium"
	$aCountries[21][1] = "BE"
	$aCountries[21][2] = "56"
	$aCountries[22][0] = "Belize"
	$aCountries[22][1] = "BZ"
	$aCountries[22][2] = "84"
	$aCountries[23][0] = "Benin"
	$aCountries[23][1] = "BJ"
	$aCountries[23][2] = "204"
	$aCountries[24][0] = "Bermuda"
	$aCountries[24][1] = "BM"
	$aCountries[24][2] = "60"
	$aCountries[25][0] = "Bhutan"
	$aCountries[25][1] = "BT"
	$aCountries[25][2] = "64"
	$aCountries[26][0] = "Bolivia"
	$aCountries[26][1] = "BO"
	$aCountries[26][2] = "68"
	$aCountries[27][0] = "Bonaire, Saint Eustatius and Saba"
	$aCountries[27][1] = "BQ"
	$aCountries[27][2] = "535"
	$aCountries[28][0] = "Bosnia and Herzegovina"
	$aCountries[28][1] = "BA"
	$aCountries[28][2] = "70"
	$aCountries[29][0] = "Botswana"
	$aCountries[29][1] = "BW"
	$aCountries[29][2] = "72"
	$aCountries[30][0] = "Bouvet Island"
	$aCountries[30][1] = "BV"
	$aCountries[30][2] = "74"
	$aCountries[31][0] = "Brazil"
	$aCountries[31][1] = "BR"
	$aCountries[31][2] = "76"
	$aCountries[32][0] = "British Indian Ocean Territory"
	$aCountries[32][1] = "IO"
	$aCountries[32][2] = "86"
	$aCountries[33][0] = "Brunei Darussalam"
	$aCountries[33][1] = "BN"
	$aCountries[33][2] = "96"
	$aCountries[34][0] = "Bulgaria"
	$aCountries[34][1] = "BG"
	$aCountries[34][2] = "100"
	$aCountries[35][0] = "Burkina Faso"
	$aCountries[35][1] = "BF"
	$aCountries[35][2] = "854"
	$aCountries[36][0] = "Burundi"
	$aCountries[36][1] = "BI"
	$aCountries[36][2] = "108"
	$aCountries[37][0] = "Cambodia"
	$aCountries[37][1] = "KH"
	$aCountries[37][2] = "116"
	$aCountries[38][0] = "Cameroon"
	$aCountries[38][1] = "CM"
	$aCountries[38][2] = "120"
	$aCountries[39][0] = "Canada"
	$aCountries[39][1] = "CA"
	$aCountries[39][2] = "124"
	$aCountries[40][0] = "Cape Verde"
	$aCountries[40][1] = "CV"
	$aCountries[40][2] = "132"
	$aCountries[41][0] = "Cayman Islands"
	$aCountries[41][1] = "KY"
	$aCountries[41][2] = "136"
	$aCountries[42][0] = "Central African Republic"
	$aCountries[42][1] = "CF"
	$aCountries[42][2] = "140"
	$aCountries[43][0] = "Chad"
	$aCountries[43][1] = "TD"
	$aCountries[43][2] = "148"
	$aCountries[44][0] = "Chile"
	$aCountries[44][1] = "CL"
	$aCountries[44][2] = "152"
	$aCountries[45][0] = "China"
	$aCountries[45][1] = "CN"
	$aCountries[45][2] = "156"
	$aCountries[46][0] = "Christmas Island"
	$aCountries[46][1] = "CX"
	$aCountries[46][2] = "162"
	$aCountries[47][0] = "Cocos (Keeling) Islands"
	$aCountries[47][1] = "CC"
	$aCountries[47][2] = "166"
	$aCountries[48][0] = "Colombia"
	$aCountries[48][1] = "CO"
	$aCountries[48][2] = "170"
	$aCountries[49][0] = "Comoros"
	$aCountries[49][1] = "KM"
	$aCountries[49][2] = "174"
	$aCountries[50][0] = "Congo"
	$aCountries[50][1] = "CG"
	$aCountries[50][2] = "178"
	$aCountries[51][0] = "Congo (DRC)"
	$aCountries[51][1] = "CD"
	$aCountries[51][2] = "180"
	$aCountries[52][0] = "Cook Islands"
	$aCountries[52][1] = "CK"
	$aCountries[52][2] = "184"
	$aCountries[53][0] = "Costa Rica"
	$aCountries[53][1] = "CR"
	$aCountries[53][2] = "188"
	$aCountries[54][0] = "Côte d'Ivoire"
	$aCountries[54][1] = "CI"
	$aCountries[54][2] = "384"
	$aCountries[55][0] = "Croatia"
	$aCountries[55][1] = "HR"
	$aCountries[55][2] = "191"
	$aCountries[56][0] = "Cuba"
	$aCountries[56][1] = "CU"
	$aCountries[56][2] = "192"
	$aCountries[57][0] = "Curaçao"
	$aCountries[57][1] = "CW"
	$aCountries[57][2] = "531"
	$aCountries[58][0] = "Cyprus"
	$aCountries[58][1] = "CY"
	$aCountries[58][2] = "196"
	$aCountries[59][0] = "Czech Republic"
	$aCountries[59][1] = "CZ"
	$aCountries[59][2] = "203"
	$aCountries[60][0] = "Denmark"
	$aCountries[60][1] = "DK"
	$aCountries[60][2] = "208"
	$aCountries[61][0] = "Djibouti"
	$aCountries[61][1] = "DJ"
	$aCountries[61][2] = "262"
	$aCountries[62][0] = "Dominica"
	$aCountries[62][1] = "DM"
	$aCountries[62][2] = "212"
	$aCountries[63][0] = "Dominican Republic"
	$aCountries[63][1] = "DO"
	$aCountries[63][2] = "214"
	$aCountries[64][0] = "Ecuador"
	$aCountries[64][1] = "EC"
	$aCountries[64][2] = "218"
	$aCountries[65][0] = "Egypt"
	$aCountries[65][1] = "EG"
	$aCountries[65][2] = "818"
	$aCountries[66][0] = "El Salvador"
	$aCountries[66][1] = "SV"
	$aCountries[66][2] = "222"
	$aCountries[67][0] = "Equatorial Guinea"
	$aCountries[67][1] = "GQ"
	$aCountries[67][2] = "226"
	$aCountries[68][0] = "Eritrea"
	$aCountries[68][1] = "ER"
	$aCountries[68][2] = "232"
	$aCountries[69][0] = "Estonia"
	$aCountries[69][1] = "EE"
	$aCountries[69][2] = "233"
	$aCountries[70][0] = "Ethiopia"
	$aCountries[70][1] = "ET"
	$aCountries[70][2] = "231"
	$aCountries[71][0] = "Falkland Islands (Malvinas)"
	$aCountries[71][1] = "FK"
	$aCountries[71][2] = "238"
	$aCountries[72][0] = "Faroe Islands"
	$aCountries[72][1] = "FO"
	$aCountries[72][2] = "234"
	$aCountries[73][0] = "Fiji"
	$aCountries[73][1] = "FJ"
	$aCountries[73][2] = "242"
	$aCountries[74][0] = "Finland"
	$aCountries[74][1] = "FI"
	$aCountries[74][2] = "246"
	$aCountries[75][0] = "France"
	$aCountries[75][1] = "FR"
	$aCountries[75][2] = "250"
	$aCountries[76][0] = "French Guiana"
	$aCountries[76][1] = "GF"
	$aCountries[76][2] = "254"
	$aCountries[77][0] = "French Polynesia"
	$aCountries[77][1] = "PF"
	$aCountries[77][2] = "258"
	$aCountries[78][0] = "French Southern Territories"
	$aCountries[78][1] = "TF"
	$aCountries[78][2] = "260"
	$aCountries[79][0] = "Gabon"
	$aCountries[79][1] = "GA"
	$aCountries[79][2] = "266"
	$aCountries[80][0] = "Gambia"
	$aCountries[80][1] = "GM"
	$aCountries[80][2] = "270"
	$aCountries[81][0] = "Georgia"
	$aCountries[81][1] = "GE"
	$aCountries[81][2] = "268"
	$aCountries[82][0] = "Germany"
	$aCountries[82][1] = "DE"
	$aCountries[82][2] = "276"
	$aCountries[83][0] = "Ghana"
	$aCountries[83][1] = "GH"
	$aCountries[83][2] = "288"
	$aCountries[84][0] = "Gibraltar"
	$aCountries[84][1] = "GI"
	$aCountries[84][2] = "292"
	$aCountries[85][0] = "Greece"
	$aCountries[85][1] = "GR"
	$aCountries[85][2] = "300"
	$aCountries[86][0] = "Greenland"
	$aCountries[86][1] = "GL"
	$aCountries[86][2] = "304"
	$aCountries[87][0] = "Grenada"
	$aCountries[87][1] = "GD"
	$aCountries[87][2] = "308"
	$aCountries[88][0] = "Guadeloupe"
	$aCountries[88][1] = "GP"
	$aCountries[88][2] = "312"
	$aCountries[89][0] = "Guam"
	$aCountries[89][1] = "GU"
	$aCountries[89][2] = "316"
	$aCountries[90][0] = "Guatemala"
	$aCountries[90][1] = "GT"
	$aCountries[90][2] = "320"
	$aCountries[91][0] = "Guernsey"
	$aCountries[91][1] = "GG"
	$aCountries[91][2] = "831"
	$aCountries[92][0] = "Guinea"
	$aCountries[92][1] = "GN"
	$aCountries[92][2] = "324"
	$aCountries[93][0] = "Guinea-Bissau"
	$aCountries[93][1] = "GW"
	$aCountries[93][2] = "624"
	$aCountries[94][0] = "Guyana"
	$aCountries[94][1] = "GY"
	$aCountries[94][2] = "328"
	$aCountries[95][0] = "Haiti"
	$aCountries[95][1] = "HT"
	$aCountries[95][2] = "332"
	$aCountries[96][0] = "Heard Island and McDonald Islands"
	$aCountries[96][1] = "HM"
	$aCountries[96][2] = "334"
	$aCountries[97][0] = "Holy See (Vatican City State)"
	$aCountries[97][1] = "VA"
	$aCountries[97][2] = "336"
	$aCountries[98][0] = "Honduras"
	$aCountries[98][1] = "HN"
	$aCountries[98][2] = "340"
	$aCountries[99][0] = "Hong Kong"
	$aCountries[99][1] = "HK"
	$aCountries[99][2] = "344"
	$aCountries[100][0] = "Hungary"
	$aCountries[100][1] = "HU"
	$aCountries[100][2] = "348"
	$aCountries[101][0] = "Iceland"
	$aCountries[101][1] = "IS"
	$aCountries[101][2] = "352"
	$aCountries[102][0] = "India"
	$aCountries[102][1] = "IN"
	$aCountries[102][2] = "356"
	$aCountries[103][0] = "Indonesia"
	$aCountries[103][1] = "ID"
	$aCountries[103][2] = "360"
	$aCountries[104][0] = "Iran"
	$aCountries[104][1] = "IR"
	$aCountries[104][2] = "364"
	$aCountries[105][0] = "Iraq"
	$aCountries[105][1] = "IQ"
	$aCountries[105][2] = "368"
	$aCountries[106][0] = "Ireland"
	$aCountries[106][1] = "IE"
	$aCountries[106][2] = "372"
	$aCountries[107][0] = "Isle of Man"
	$aCountries[107][1] = "IM"
	$aCountries[107][2] = "833"
	$aCountries[108][0] = "Israel"
	$aCountries[108][1] = "IL"
	$aCountries[108][2] = "376"
	$aCountries[109][0] = "Italy"
	$aCountries[109][1] = "IT"
	$aCountries[109][2] = "380"
	$aCountries[110][0] = "Jamaica"
	$aCountries[110][1] = "JM"
	$aCountries[110][2] = "388"
	$aCountries[111][0] = "Japan"
	$aCountries[111][1] = "JP"
	$aCountries[111][2] = "392"
	$aCountries[112][0] = "Jersey"
	$aCountries[112][1] = "JE"
	$aCountries[112][2] = "832"
	$aCountries[113][0] = "Jordan"
	$aCountries[113][1] = "JO"
	$aCountries[113][2] = "400"
	$aCountries[114][0] = "Kazakhstan"
	$aCountries[114][1] = "KZ"
	$aCountries[114][2] = "398"
	$aCountries[115][0] = "Kenya"
	$aCountries[115][1] = "KE"
	$aCountries[115][2] = "404"
	$aCountries[116][0] = "Kiribati"
	$aCountries[116][1] = "KI"
	$aCountries[116][2] = "296"
	$aCountries[117][0] = "Korea (North)"
	$aCountries[117][1] = "KP"
	$aCountries[117][2] = "408"
	$aCountries[118][0] = "Korea (South)"
	$aCountries[118][1] = "KR"
	$aCountries[118][2] = "410"
	$aCountries[119][0] = "Kuwait"
	$aCountries[119][1] = "KW"
	$aCountries[119][2] = "414"
	$aCountries[120][0] = "Kyrgyzstan"
	$aCountries[120][1] = "KG"
	$aCountries[120][2] = "417"
	$aCountries[121][0] = "Lao People's Democratic Republic"
	$aCountries[121][1] = "LA"
	$aCountries[121][2] = "418"
	$aCountries[122][0] = "Latvia"
	$aCountries[122][1] = "LV"
	$aCountries[122][2] = "428"
	$aCountries[123][0] = "Lebanon"
	$aCountries[123][1] = "LB"
	$aCountries[123][2] = "422"
	$aCountries[124][0] = "Lesotho"
	$aCountries[124][1] = "LS"
	$aCountries[124][2] = "426"
	$aCountries[125][0] = "Liberia"
	$aCountries[125][1] = "LR"
	$aCountries[125][2] = "430"
	$aCountries[126][0] = "Libyan Arab Jamahiriya"
	$aCountries[126][1] = "LY"
	$aCountries[126][2] = "434"
	$aCountries[127][0] = "Liechtenstein"
	$aCountries[127][1] = "LI"
	$aCountries[127][2] = "438"
	$aCountries[128][0] = "Lithuania"
	$aCountries[128][1] = "LT"
	$aCountries[128][2] = "440"
	$aCountries[129][0] = "Luxembourg"
	$aCountries[129][1] = "LU"
	$aCountries[129][2] = "442"
	$aCountries[130][0] = "Macao"
	$aCountries[130][1] = "MO"
	$aCountries[130][2] = "446"
	$aCountries[131][0] = "Macedonia"
	$aCountries[131][1] = "MK"
	$aCountries[131][2] = "807"
	$aCountries[132][0] = "Madagascar"
	$aCountries[132][1] = "MG"
	$aCountries[132][2] = "450"
	$aCountries[133][0] = "Malawi"
	$aCountries[133][1] = "MW"
	$aCountries[133][2] = "454"
	$aCountries[134][0] = "Malaysia"
	$aCountries[134][1] = "MY"
	$aCountries[134][2] = "458"
	$aCountries[135][0] = "Maldives"
	$aCountries[135][1] = "MV"
	$aCountries[135][2] = "462"
	$aCountries[136][0] = "Mali"
	$aCountries[136][1] = "ML"
	$aCountries[136][2] = "466"
	$aCountries[137][0] = "Malta"
	$aCountries[137][1] = "MT"
	$aCountries[137][2] = "470"
	$aCountries[138][0] = "Marshall Islands"
	$aCountries[138][1] = "MH"
	$aCountries[138][2] = "584"
	$aCountries[139][0] = "Martinique"
	$aCountries[139][1] = "MQ"
	$aCountries[139][2] = "474"
	$aCountries[140][0] = "Mauritania"
	$aCountries[140][1] = "MR"
	$aCountries[140][2] = "478"
	$aCountries[141][0] = "Mauritius"
	$aCountries[141][1] = "MU"
	$aCountries[141][2] = "480"
	$aCountries[142][0] = "Mayotte"
	$aCountries[142][1] = "YT"
	$aCountries[142][2] = "175"
	$aCountries[143][0] = "Mexico"
	$aCountries[143][1] = "MX"
	$aCountries[143][2] = "484"
	$aCountries[144][0] = "Micronesia"
	$aCountries[144][1] = "FM"
	$aCountries[144][2] = "583"
	$aCountries[145][0] = "Moldova"
	$aCountries[145][1] = "MD"
	$aCountries[145][2] = "498"
	$aCountries[146][0] = "Monaco"
	$aCountries[146][1] = "MC"
	$aCountries[146][2] = "492"
	$aCountries[147][0] = "Mongolia"
	$aCountries[147][1] = "MN"
	$aCountries[147][2] = "496"
	$aCountries[148][0] = "Montenegro"
	$aCountries[148][1] = "ME"
	$aCountries[148][2] = "499"
	$aCountries[149][0] = "Montserrat"
	$aCountries[149][1] = "MS"
	$aCountries[149][2] = "500"
	$aCountries[150][0] = "Morocco"
	$aCountries[150][1] = "MA"
	$aCountries[150][2] = "504"
	$aCountries[151][0] = "Mozambique"
	$aCountries[151][1] = "MZ"
	$aCountries[151][2] = "508"
	$aCountries[152][0] = "Myanmar"
	$aCountries[152][1] = "MM"
	$aCountries[152][2] = "104"
	$aCountries[153][0] = "Namibia"
	$aCountries[153][1] = "NA"
	$aCountries[153][2] = "516"
	$aCountries[154][0] = "Nauru"
	$aCountries[154][1] = "NR"
	$aCountries[154][2] = "520"
	$aCountries[155][0] = "Nepal"
	$aCountries[155][1] = "NP"
	$aCountries[155][2] = "524"
	$aCountries[156][0] = "Netherlands"
	$aCountries[156][1] = "NL"
	$aCountries[156][2] = "528"
	$aCountries[157][0] = "New Caledonia"
	$aCountries[157][1] = "NC"
	$aCountries[157][2] = "540"
	$aCountries[158][0] = "New Zealand"
	$aCountries[158][1] = "NZ"
	$aCountries[158][2] = "554"
	$aCountries[159][0] = "Nicaragua"
	$aCountries[159][1] = "NI"
	$aCountries[159][2] = "558"
	$aCountries[160][0] = "Niger"
	$aCountries[160][1] = "NE"
	$aCountries[160][2] = "562"
	$aCountries[161][0] = "Nigeria"
	$aCountries[161][1] = "NG"
	$aCountries[161][2] = "566"
	$aCountries[162][0] = "Niue"
	$aCountries[162][1] = "NU"
	$aCountries[162][2] = "570"
	$aCountries[163][0] = "Norfolk Island"
	$aCountries[163][1] = "NF"
	$aCountries[163][2] = "574"
	$aCountries[164][0] = "Northern Mariana Islands"
	$aCountries[164][1] = "MP"
	$aCountries[164][2] = "580"
	$aCountries[165][0] = "Norway"
	$aCountries[165][1] = "NO"
	$aCountries[165][2] = "578"
	$aCountries[166][0] = "Oman"
	$aCountries[166][1] = "OM"
	$aCountries[166][2] = "512"
	$aCountries[167][0] = "Pakistan"
	$aCountries[167][1] = "PK"
	$aCountries[167][2] = "586"
	$aCountries[168][0] = "Palau"
	$aCountries[168][1] = "PW"
	$aCountries[168][2] = "585"
	$aCountries[169][0] = "Palestinian"
	$aCountries[169][1] = "PS"
	$aCountries[169][2] = "275"
	$aCountries[170][0] = "Panama"
	$aCountries[170][1] = "PA"
	$aCountries[170][2] = "591"
	$aCountries[171][0] = "Papua New Guinea"
	$aCountries[171][1] = "PG"
	$aCountries[171][2] = "598"
	$aCountries[172][0] = "Paraguay"
	$aCountries[172][1] = "PY"
	$aCountries[172][2] = "600"
	$aCountries[173][0] = "Peru"
	$aCountries[173][1] = "PE"
	$aCountries[173][2] = "604"
	$aCountries[174][0] = "Philippines"
	$aCountries[174][1] = "PH"
	$aCountries[174][2] = "608"
	$aCountries[175][0] = "Pitcairn"
	$aCountries[175][1] = "PN"
	$aCountries[175][2] = "612"
	$aCountries[176][0] = "Poland"
	$aCountries[176][1] = "PL"
	$aCountries[176][2] = "616"
	$aCountries[177][0] = "Portugal"
	$aCountries[177][1] = "PT"
	$aCountries[177][2] = "620"
	$aCountries[178][0] = "Puerto Rico"
	$aCountries[178][1] = "PR"
	$aCountries[178][2] = "630"
	$aCountries[179][0] = "Qatar"
	$aCountries[179][1] = "QA"
	$aCountries[179][2] = "634"
	$aCountries[180][0] = "Réunion"
	$aCountries[180][1] = "RE"
	$aCountries[180][2] = "638"
	$aCountries[181][0] = "Romania"
	$aCountries[181][1] = "RO"
	$aCountries[181][2] = "642"
	$aCountries[182][0] = "Russian Federation"
	$aCountries[182][1] = "RU"
	$aCountries[182][2] = "643"
	$aCountries[183][0] = "Rwanda"
	$aCountries[183][1] = "RW"
	$aCountries[183][2] = "646"
	$aCountries[184][0] = "Saint Barthélemy"
	$aCountries[184][1] = "BL"
	$aCountries[184][2] = "652"
	$aCountries[185][0] = "Saint Helena, Ascension and Tristan da Cunha"
	$aCountries[185][1] = "SH"
	$aCountries[185][2] = "654"
	$aCountries[186][0] = "Saint Kitts and Nevis"
	$aCountries[186][1] = "KN"
	$aCountries[186][2] = "659"
	$aCountries[187][0] = "Saint Lucia"
	$aCountries[187][1] = "LC"
	$aCountries[187][2] = "662"
	$aCountries[188][0] = "Saint Martin (French part)"
	$aCountries[188][1] = "MF"
	$aCountries[188][2] = "663"
	$aCountries[189][0] = "Saint Pierre and Miquelon"
	$aCountries[189][1] = "PM"
	$aCountries[189][2] = "666"
	$aCountries[190][0] = "Saint Vincent and the Grenadines"
	$aCountries[190][1] = "VC"
	$aCountries[190][2] = "670"
	$aCountries[191][0] = "Samoa"
	$aCountries[191][1] = "WS"
	$aCountries[191][2] = "882"
	$aCountries[192][0] = "San Marino"
	$aCountries[192][1] = "SM"
	$aCountries[192][2] = "674"
	$aCountries[193][0] = "Sao Tome and Principe"
	$aCountries[193][1] = "ST"
	$aCountries[193][2] = "678"
	$aCountries[194][0] = "Saudi Arabia"
	$aCountries[194][1] = "SA"
	$aCountries[194][2] = "682"
	$aCountries[195][0] = "Senegal"
	$aCountries[195][1] = "SN"
	$aCountries[195][2] = "686"
	$aCountries[196][0] = "Serbia"
	$aCountries[196][1] = "RS"
	$aCountries[196][2] = "688"
	$aCountries[197][0] = "Seychelles"
	$aCountries[197][1] = "SC"
	$aCountries[197][2] = "690"
	$aCountries[198][0] = "Sierra Leone"
	$aCountries[198][1] = "SL"
	$aCountries[198][2] = "694"
	$aCountries[199][0] = "Singapore"
	$aCountries[199][1] = "SG"
	$aCountries[199][2] = "702"
	$aCountries[200][0] = "Sint Maarten (Dutch part)"
	$aCountries[200][1] = "SX"
	$aCountries[200][2] = "534"
	$aCountries[201][0] = "Slovakia"
	$aCountries[201][1] = "SK"
	$aCountries[201][2] = "703"
	$aCountries[202][0] = "Slovenia"
	$aCountries[202][1] = "SI"
	$aCountries[202][2] = "705"
	$aCountries[203][0] = "Solomon Islands"
	$aCountries[203][1] = "SB"
	$aCountries[203][2] = "90"
	$aCountries[204][0] = "Somalia"
	$aCountries[204][1] = "SO"
	$aCountries[204][2] = "706"
	$aCountries[205][0] = "South Africa"
	$aCountries[205][1] = "ZA"
	$aCountries[205][2] = "710"
	$aCountries[206][0] = "South Georgia and the South Sandwich Islands"
	$aCountries[206][1] = "GS"
	$aCountries[206][2] = "239"
	$aCountries[207][0] = "Spain"
	$aCountries[207][1] = "ES"
	$aCountries[207][2] = "724"
	$aCountries[208][0] = "Sri Lanka"
	$aCountries[208][1] = "LK"
	$aCountries[208][2] = "144"
	$aCountries[209][0] = "Sudan"
	$aCountries[209][1] = "SD"
	$aCountries[209][2] = "736"
	$aCountries[210][0] = "Suriname"
	$aCountries[210][1] = "SR"
	$aCountries[210][2] = "740"
	$aCountries[211][0] = "Svalbard and Jan Mayen"
	$aCountries[211][1] = "SJ"
	$aCountries[211][2] = "744"
	$aCountries[212][0] = "Swaziland"
	$aCountries[212][1] = "SZ"
	$aCountries[212][2] = "748"
	$aCountries[213][0] = "Sweden"
	$aCountries[213][1] = "SE"
	$aCountries[213][2] = "752"
	$aCountries[214][0] = "Switzerland"
	$aCountries[214][1] = "CH"
	$aCountries[214][2] = "756"
	$aCountries[215][0] = "Syrian Arab Republic"
	$aCountries[215][1] = "SY"
	$aCountries[215][2] = "760"
	$aCountries[216][0] = "Taiwan"
	$aCountries[216][1] = "TW"
	$aCountries[216][2] = "158"
	$aCountries[217][0] = "Tajikistan"
	$aCountries[217][1] = "TJ"
	$aCountries[217][2] = "762"
	$aCountries[218][0] = "Tanzania"
	$aCountries[218][1] = "TZ"
	$aCountries[218][2] = "834"
	$aCountries[219][0] = "Thailand"
	$aCountries[219][1] = "TH"
	$aCountries[219][2] = "764"
	$aCountries[220][0] = "Timor-Leste"
	$aCountries[220][1] = "TL"
	$aCountries[220][2] = "626"
	$aCountries[221][0] = "Togo"
	$aCountries[221][1] = "TG"
	$aCountries[221][2] = "768"
	$aCountries[222][0] = "Tokelau"
	$aCountries[222][1] = "TK"
	$aCountries[222][2] = "772"
	$aCountries[223][0] = "Tonga"
	$aCountries[223][1] = "TO"
	$aCountries[223][2] = "776"
	$aCountries[224][0] = "Trinidad and Tobago"
	$aCountries[224][1] = "TT"
	$aCountries[224][2] = "780"
	$aCountries[225][0] = "Tunisia"
	$aCountries[225][1] = "TN"
	$aCountries[225][2] = "788"
	$aCountries[226][0] = "Turkey"
	$aCountries[226][1] = "TR"
	$aCountries[226][2] = "792"
	$aCountries[227][0] = "Turkmenistan"
	$aCountries[227][1] = "TM"
	$aCountries[227][2] = "795"
	$aCountries[228][0] = "Turks and Caicos Islands"
	$aCountries[228][1] = "TC"
	$aCountries[228][2] = "796"
	$aCountries[229][0] = "Tuvalu"
	$aCountries[229][1] = "TV"
	$aCountries[229][2] = "798"
	$aCountries[230][0] = "Uganda"
	$aCountries[230][1] = "UG"
	$aCountries[230][2] = "800"
	$aCountries[231][0] = "Ukraine"
	$aCountries[231][1] = "UA"
	$aCountries[231][2] = "804"
	$aCountries[232][0] = "United Arab Emirates"
	$aCountries[232][1] = "AE"
	$aCountries[232][2] = "784"
	$aCountries[233][0] = "United Kingdom"
	$aCountries[233][1] = "GB"
	$aCountries[233][2] = "826"
	$aCountries[234][0] = "United States"
	$aCountries[234][1] = "US"
	$aCountries[234][2] = "840"
	$aCountries[235][0] = "United States Minor Outlying Islands"
	$aCountries[235][1] = "UM"
	$aCountries[235][2] = "581"
	$aCountries[236][0] = "Uruguay"
	$aCountries[236][1] = "UY"
	$aCountries[236][2] = "858"
	$aCountries[237][0] = "Uzbekistan"
	$aCountries[237][1] = "UZ"
	$aCountries[237][2] = "860"
	$aCountries[238][0] = "Vanuatu"
	$aCountries[238][1] = "VU"
	$aCountries[238][2] = "548"
	$aCountries[239][0] = "Venezuela"
	$aCountries[239][1] = "VE"
	$aCountries[239][2] = "862"
	$aCountries[240][0] = "Viet Nam"
	$aCountries[240][1] = "VN"
	$aCountries[240][2] = "704"
	$aCountries[241][0] = "Virgin Islands, British"
	$aCountries[241][1] = "VG"
	$aCountries[241][2] = "92"
	$aCountries[242][0] = "Virgin Islands, U.S."
	$aCountries[242][1] = "VI"
	$aCountries[242][2] = "850"
	$aCountries[243][0] = "Wallis and Futuna"
	$aCountries[243][1] = "WF"
	$aCountries[243][2] = "876"
	$aCountries[244][0] = "Western Sahara"
	$aCountries[244][1] = "EH"
	$aCountries[244][2] = "732"
	$aCountries[245][0] = "Yemen"
	$aCountries[245][1] = "YE"
	$aCountries[245][2] = "887"
	$aCountries[246][0] = "Zambia"
	$aCountries[246][1] = "ZM"
	$aCountries[246][2] = "894"
	$aCountries[247][0] = "Zimbabwe"
	$aCountries[247][1] = "ZW"
	$aCountries[247][2] = "716"
#endregion
	Local $index = _ArraySearch($aCountries, $country, 0, 0, 0, 0, 1, 0)
	If @error Then Return SetError(1, 0, 0)
	Local $aCodes[2] = [$aCountries[$index][1], $aCountries[$index][2]]
	Return $aCodes
EndFunc

Func WriteLog($text)
	Local $hFile = FileOpen($logfile, 1)
	If $hFile = -1 Then Return MsgBox(16, "Error", "Unable to create log file!", 30, $hGUI)
	Local $TimeStamp = @YEAR & "-" & @MON & "-" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & @TAB
	FileWriteLine($hFile, $TimeStamp & $text)
	FileClose($hFile)
EndFunc   ;==>WriteLog

Func WM_SIZE($hWnd, $iMsg, $iwParam, $ilParam)
    _GUICtrlStatusBar_Resize($StatusBar)
    Return "GUI_RUNDEFMSG"
EndFunc   ;==>WM_SIZE

Func WM_GETMINMAXINFO($hWnd, $Msg, $wParam, $lParam)
    Local $minmaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
    DllStructSetData($minmaxinfo, 7, $minwidth) ;min width
    DllStructSetData($minmaxinfo, 8, $minheight) ;min height
    Return "GUI_RUNDEFMSG"
EndFunc   ;==>WM_GETMINMAXINFO

; #FUNCTION# ======================================================================================
; Name ................:    StringSplitW()
; Version .............:    v0.80 build 2011-05-05 beta
; Description .......:    Splits  a string into columns instead of rows as it is done by SplitString(), like a csv file to a 2d array ;-)
; Syntax ..............:    StringSplitW($string, $delimiter, $max_width)
; Parameters ........:    $string - string to split
;                                $delimiter - the delimter how to split the string
; Return values ....:    Success - 2d array
;                                 Failure 1 - either $string or $delimter is not set
;                                 Failure 2 - array width exceeded
;                                 Failure 3 - 2D array memory exceeded -> width + height > 0x5EFA
; Author ..............:    UEZ
; Modified ............:
; Remarks ............:
; Related ..............:    StringSplit()
; =================================================================================================
Func StringSplitW($string, $delimiter)
    If $string = "" Or $delimiter = "" Then Return SetError(1, 0, 0)
    Local $chk, $width, $i, $j, $k, $len, $max = 1, $max_width
    Local $aPos[1], $l = 0
    Local $aSplit =  StringSplit($string, @LF)
	$max_width = 0x5EFA - $aSplit[0]
	If $max_width < 1 Then Return SetError(3, 0, 0)
    Local $aVertical[$aSplit[0]][$max_width]
    For $k = 1 To $aSplit[0]
        $len = StringLen($aSplit[$k])
        If $len > 1 Then
            $chk = StringReplace($aSplit[$k], $delimiter, $delimiter)
            $width = @extended
            If $width > $max_width Then Return SetError(2, 0, 0)
            If $width > $max Then $max = $width + 1
            Switch $width
                Case 0
                    $aVertical[$l][0] = $aSplit[$k]
                Case Else
                    Dim $aPos[$width * 2 + 2]
                    $j = 1
                    $aPos[0] = 1
                    For $i = 0 To $width - 1
                        $aPos[$j] = StringInStr($aSplit[$k], $delimiter, 0, $i + 1) - 1
                        $aPos[$j + 1] = $aPos[$j] + 2
                        $j += 2
                    Next
                    $aPos[UBound($aPos) - 1] = StringLen($aSplit[$k])
                    $j = 0
                    For $i = 0 To UBound($aPos) - 1 Step 2
                        $aVertical[$l][$j] = StringMid($aSplit[$k], $aPos[$i], $aPos[$i + 1] - $aPos[$i] + 1)
                        $j += 1
                    Next
                EndSwitch
                $l += 1
        EndIf
    Next
    ReDim $aVertical[$l][$max]
    Return $aVertical
EndFunc

Func Load_BMP_From_Mem($mem_image) ;coded by UEZ - thanks to progandy for the MemGlobalAlloc and tVARIANT lines
	Local $memBitmap, $len, $tMem, $hImage, $hData, $pData, $hStream, $hBitmapFromStream
	$memBitmap = Binary($mem_image) ;load image  saved in variable (memory) and convert it to binary
    $len = BinaryLen($memBitmap) ;get length of image
    $hData = _MemGlobalAlloc($len, $GMEM_MOVEABLE) ;allocates movable memory  ($GMEM_MOVEABLE = 0x0002)
    $pData = _MemGlobalLock($hData)  ;translate the handle into a pointer
    $tMem = DllStructCreate("byte[" & $len & "]", $pData) ;create struct
     DllStructSetData($tMem, 1, $memBitmap) ;fill struct with image data
    _MemGlobalUnlock($hData) ;decrements the lock count  associated with a memory object that was allocated with GMEM_MOVEABLE
	$hStream = _WinAPI_CreateStreamOnHGlobal($pData) ;Creates a stream object that uses an HGLOBAL memory handle to store the stream contents
	$hBitmapFromStream = _GDIPlus_BitmapCreateFromStream($hStream) ;Creates a Bitmap object based on an IStream COM interface
	Local $tVARIANT = DllStructCreate("word vt;word r1;word r2;word r3;ptr data; ptr")
    Local $aCall = DllCall("oleaut32.dll", "long", "DispCallFunc", "ptr", $hStream, "dword", 8 + 8 * @AutoItX64, "dword", 4, "dword", 23, "dword", 0, "ptr", 0, "ptr", 0, "ptr", DllStructGetPtr($tVARIANT))
	$tMem = 0
	Return $hBitmapFromStream
EndFunc

Func _WinAPI_CreateStreamOnHGlobal($hGlobal = 0, $fDeleteOnRelease = True)
	Local $aResult = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", "hwnd", $hGlobal, "int", $fDeleteOnRelease, "ptr*", 0)
	If @error Then Return SetError(@error, @extended, 0)
	Return $aResult[3]
EndFunc   ;==>_WinAPI_CreateStreamOnHGlobal

Func _GDIPlus_BitmapCreateFromStream($pStream)
	Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromStream", "ptr", $pStream, "int*", 0)
	If @error Then Return SetError(@error, @extended, 0)
	Return $aResult[2]
EndFunc   ;==>_GDIPlus_BitmapCreateFromStream

Func OK()
	Local _
	$OK = '0x89504E470D0A1A0A0000000D49484452000000100000001008060000001FF3FF61000002624944415478DA63FCFFFF3F032940B94D8AF9EFBBBF820F7A5EBE01F11949314038988F43CD477615AF00B7D9C589B74B5F1DFCB08624034C266ACC50D2914D67E36361D85F7776C1B31DAF7B893640BB4D31DEC85E7B01271F1BC399C557CE9FEFBEDD0B14E624CA00992C610DDB28E3135C22ECFCF7CF3F7DBD3FEE7C07C31F0656A0143F41030422B958CC63B4F6C8EB48DA7FFBFEE3FF5A97437D3F9EFE7A0A0A1220FE48D000B3396AE59681061D6CDCAC0CEB120E6CBDB7F2D956A0B008107F06E26B780D902B12D6F12B753C2124CECF7D76F5B547DB224EF401857981F81B10DF00E22B60035CB6984EE36267D73A5E7FA5F5CDF18F0780127F81E2FF824ED8EDD03454767FF7F6C3FF05C65BFB7EBCF8FD0A28C702C47780F822103F021B90F130F0BF84BC30C3BB379F7EAD09D95FFAFCE09BC55ABD322EAE0996AB18D8181876141F3B7073D6D375400D8240FC0CAAF936107F021B206E2514E23BDF7AAE989210DFFB579FFE6D483DD8615AA1E123A52EA6F7F0FCD30F3B7CCE7430FC0519C5F015E46C20BE0CC4AF817AFF800D60646464E79466F3F65E63394F489E8FFFCBD76F0C7FBEFF61F8CDF48B615FCC85C51F2F7CBF00D4C005C47781F83C103F04EAFB0E4FCA400398816C210E69D6708715BA3D4C6C'
    $OK &= '4CEC3FFFFD6478B4EDE5B3DBCDAF6600E59880F815D4E9A0C0FB000A23B80160062323C889A2BCFAEC599AFD52553FBFFD64B812FB7CFBDFF7FF6F02C5DF409D0D32E03950CF2F584CA14423D01050EA12E5D4622964F8CFA0F7FDFA9FFB403E48F175203E090DB82FFF913461A403A84BA440790788F58118E4D4B3407C06885F02D5FF45560F0094401C0EBF687F2D0000000049454E44AE426082'
	Return Binary($OK)
EndFunc

Func NOK()
	Local _
	$NOK = '0x89504E470D0A1A0A0000000D49484452000000100000001008060000001FF3FF61000003314944415478DAA5926B48536118C7DFF7B4CD4DE7DC20AFA9790953038B301925445214857EB014BA2B59A41F824A4A29342A52D2AE1059505452B42E445F4A29C42EA2ADBC2C74F3522E9D9BBA8B9B73677ACECECE7ADE710AFBDC81DF87F3BECFF37F9FE7F93F381008A0FFF9F0A747F78B72161CD75DD393717EB9D2D6AE3334B568BB6F3ED20FBBE0DE1F58F482B1A25CA654CA4B788A3FD2DCF661EEA14E7F0D9FD8B6E5F0DEE4A88655ABB322289E479C670E75F7E83AABDABE567758ADDD90E7050D7EBCF4C086A8C8D08621379D75FE4DDB953726CBFD0584784CAAC85BB932BB2023A56A577A7241A4DB2AE21C76D4FFCB34D968A22B9F5BA65A8C45F9E591F691DAD733ECAFAB8689CA6E9635405E18200D0A003220215BA5DC7F28397A5F3E9E5D1EE271A27E4E6A655431A3B1D671B5CE87BE7D66F98B771D8C5948A60006931631C622F85101CBC5186794C6C7EE3C2C766E5722245E60596414C98D5D0BBEC64B53DE11880921890099910DFF9911888805E5A55736E616655806CE24602E4C21C6A8CB4B99CA273C77667CDC14DCDB810901175E6C2388E01FBB0B2B687D4743842C4476D74CF7F9FC9CB42646927E799A315C30BBEF40583FA027AF432EF78F80F968699955DB7A4BC9CD4B34B4EC4BF5E8E4'
    $NOK &= '6D384E3A9518595C1523C9CC1F743577B8E97B703600CC1077FE0AB4EE29DE9A621D7C816C66790FBD64FCE04F7B2D8302A4DF700954762935BA24571A88DF6CB0977BFCFEAFA405C89D0F0A68D4EA8454157A1F6E35A6B959C4958ECCD60F308C85D8444A25C1326A89A2354DD5F4C446773639E61BC95E91790405A677E4D5D3D4DC69649B425A273BFE6A867EF9CC4E3B20605A287714E0D78787ED3A17157AB6D0E838E9E1F9EF4418EB37E52AA4518A77126A3E8771B850D798455B67726AFBBDEC2404F4013A4188F4AAAC4F8CBBDDEBF2D8356EF703F837E11BEBD644A85397B5A78A7C6B260C06BE6ECCF95863F790D789E79DC03054490B2E8952E461EA1C91A8E8A96BB6990C32D8424DE68AE3659989F51F8786C7CAF496B70C1F60E1B207E81286E55B6475482845257A799EEC8D3F28B0562A8D4E0A951E6B737BD0ACDF4F96C9097400BD825D81C5BB22ACBE0290FF065C149BF6DD07A3F30000000049454E44AE426082'
	Return Binary($NOK)
EndFunc