﻿' Programmer : Arman Forghani  Email : ArmanForghani@Yahoo.com

Language = "FA"

' Farsi Keyboard map based on Iran Popular Keyboard Layout
Dim FarsiKey
FarsiKey = Array(	&H0020, &H0021, &H061B, &H066B, &H00A4, &H066A, &H060C, &H06AF, _
					&H0029, &H0028, &H002A, &H002B, &H0648, &H002D, &H002E, &H002F, _
					&H06F0, &H06F1, &H06F2, &H06F3, &H06F4, &H06F5, &H06F6, &H06F7, _
					&H06F8, &H06F9, &H003A, &H06A9, &H003E, &H003D, &H003C, &H061F, _
					&H066C, &H0624, &H200C, &H0698, &H064a, &H064D, &H0625, &H0623, _
					&H0622, &H0651, &H0629, &H00BB, &H00AB, &H0621, &H004E, &H005D, _
					&H005B, &H0652, &H064B, &H0626, &H064F, &H064E, &H0056, &H064C, _
					&H0058, &H0650, &H0643, &H062C, &H0698, &H0686, &H00D7, &H0640, _
					&H067E, &H0634, &H0630, &H0632, &H06cc, &H062B, &H0628, &H0644, _
					&H0627, &H0647, &H062A, &H0646, &H0645, &H0626, &H062F, &H062E, _
					&H062D, &H0636, &H0642, &H0633, &H0641, &H0639, &H0631, &H0635, _
					&H0637, &H063A, &H0638, &H007D, &H007C, &H007B, &H007E)
            
Function FarsiKeyPress()
	Dim	Key, strPrompt, strTitle
	Key = window.event.KeyCode
	If (Key = 13) Or (Key = 27) Or (Key = 8) Then : Exit Function
	If (Key < &H0020) Or (Key >= &H00FF) Then
		strPrompt = "لطفا زبان سيستم عامل را به انگليسی تغيير دهيد"
		strTitle = "هشدار"
		Call MsgBox (strPrompt, 48 + 524288 + 1048576, strTitle)
		window.event.KeyCode = ""
		Exit Function
	End If
	If (Language = "FA") Then
		If (Key = &H0020) And (window.event.shIftKey) Then
			window.event.KeyCode = &H200C   ' Zero Width Non-Joiner
		Else
			window.event.KeyCode = FarsiKey(Key - &H0020)
		End If
	End If
End Function

Function ChangeLanguage(objObject, imgEnglish, imgFarsi)
	If (Language = "FA") Then
		If (objObject <> "") Then
			objObject.style.textAlign = "left"
			objObject.style.direction = "ltr"
		End If
		Language = "EN"
	Else
		If (objObject <> "") Then
			objObject.style.textAlign = "right"
			objObject.style.direction = "rtl"
		End If
		Language = "FA"
	End If
	Dim objSelector
	For Each objSelector In window.document.getElementsByTagName("IMG")
		If UCase(objSelector.ID) = "_LANGUAGESELECTOR" Then
			If (Language = "FA") Then
				objSelector.src = imgFarsi
			Else
				objSelector.src = imgEnglish
			End If
		End If
	Next
	If (objObject <> "") Then : Call objObject.focus()
End Function

' Press F8 to change Language. Add to onKeydown
Function HotKeyChangeLanguage(imgEnglish, imgFarsi)          
	If (window.event.KeyCode = 119) Then
		If (Language = "FA") Then
			Language = "EN"
		Else
			Language = "FA" 
		End If
		Dim objSelector
		For Each objSelector In window.document.getElementsByTagName("IMG")
			If UCase(objSelector.ID) = "_LANGUAGESELECTOR" Then
				If (Language = "FA") Then
					objSelector.src = imgFarsi
				Else
					objSelector.src = imgEnglish
				End If
			End If
		Next
	End If	   
End Function

Function ForceToEnglish()
	Dim	Key, strPrompt, strTitle
	Key = window.event.KeyCode
	If (Key = 13) Or (Key = 27) Or (Key = 8) Then : Exit Function
	If (Key < &H0020) Or (Key >= &H00FF) Then
		strPrompt = "لطفا زبان سيستم عامل را به انگليسی تغيير دهيد"
		strTitle = "هشدار"
		Call MsgBox (strPrompt, 48 + 524288 + 1048576, strTitle)
		window.event.KeyCode = ""
		Exit Function
	End If
End Function

' Replace Unallowable Characters
Function RUC(objObject)
Dim Expression
Expression = objObject.Value

If (InStr(1, Expression, ChrW(1609), 0) > 0) Then : Expression = Replace(Expression, ChrW(1609), ChrW(1740), 1, -1, 0)
If (InStr(1, Expression, ChrW(1610), 0) > 0) Then : Expression = Replace(Expression, ChrW(1610), ChrW(1740), 1, -1, 0)
If (InStr(1, Expression, ChrW(1603), 0) > 0) Then : Expression = Replace(Expression, ChrW(1603), ChrW(1705), 1, -1, 0)

If Expression <> objObject.Value Then
	objObject.Value = Expression
End If
End Function






