'-----------Key Down ---------------------------------------------
    function KeyD(Co,tabToenter)
    'if  UCase(co.type)="TEXT" and window.event.keyCode=13 and tabToenter then 
    if window.event.keyCode=13 and tabToenter then 
		window.event.keyCode=9
		exit function
    end if
    if UCase(CO.Dir)<>"RTL" then Exit function
    if CO.Lang="" then  CO.Lang="FA" 
    if  window.event.ctrlKey and window.event.altKey then 
    if CO.Lang="EN" then CO.Lang="FA" else CO.Lang="EN"
    END IF
    
    end function 
'-------Key Press Farsi--------------------------------------------
	function keyP(CO)
	if chrw(window.event.keyCode)="ک" then window.event.keyCode=AscW("ك")
	if chrw(window.event.keyCode)="ى" then window.event.keyCode=AscW("ي")
	if chrw(window.event.keyCode)="ك" then window.event.keyCode=AscW("ك")
	if chrw(window.event.keyCode)="ي" then window.event.keyCode=AscW("ي")
	if (window.event.keyCode)=1740 then window.event.keyCode=AscW("ي")
	if ucase(CO.lang)="FA" then 
		ch=chrw(window.event.keyCode)
		if ((ch="H" OR ch="h") or (ch="M" OR ch="m")) and window.event.shiftKey then  
		  if (ch="H" OR ch="h") then window.event.keyCode=AscW("آ")
		  if (ch="M" OR ch="m") then window.event.keyCode=AscW("ء")
		Else
			Stm0="ضصثقفغعهخحجچشسيبلاتنمكگظطزرذدئو./ژپ"
			Stm1="qwertyuiop[]asdfghjkl;'zxcvbnm,./\`"
			Stm2="QWERTYUIOP{}ASDFGHJKL:"+Chr(34)+"ZXCVBNM<>?|~"
			Stm3="ضصثقفغعهخحجچشسيبلاتنمكگظطزرذدئو./ژپ"
			p=InStr(stm0,ch)
			if p<>0 then 
				window.event.keyCode=AscW(mid(stm3,p,1))
				exit function
			end if
			p=InStr(stm1,ch)
			if p<>0 then 
				window.event.keyCode=AscW(mid(stm3,p,1))
				exit function
			end if
			p=InStr(stm2,ch)
			if p<>0 then 
				window.event.keyCode=AscW(mid(stm3,p,1))
				exit function
			end if
		End IF 
	Else 'ucase(CO.lang)="FA" then
		ch=chrw(window.event.keyCode)
		if ch="آ" and window.event.shiftKey then window.event.keyCode=AscW("h")
		Stm0="ضصثقفغعهخحجچشسيبلاتنمكگظطزرذدئو./ژپ"
		Stm1="qwertyuiop[]asdfghjkl;'zxcvbnm,./\`"
		p=InStr(stm0,ch)
		if p<>0 then 
		window.event.keyCode=AscW(mid(stm1,p,1))
		exit function
		end if
	End if 'ucase(CO.lang)="FA" then 
	end function
'-------Key Press Number-------------------------------------------
	function keyN(co)
	Code=window.event.keyCode
	if  not((code>47 and Code <58) or code=46 or code=45 or Code=13) then window.event.keyCode=0
	end function
'-------Key Press Number With Search---------------------------------------
	function keyNS(co,Surl)
	if window.event.keyCode=63 OR window.event.keyCode=1567 then  
		co.value=showModalDialog(Surl)
	end if
	Code=window.event.keyCode
	if  not((code>47 and Code <58) or code=46 or code=45 ) then window.event.keyCode=0
	end function
'------- KeyDate ---------------------------------------

	function KeyDate(obj)
	Code=window.event.keyCode
	if obj.dataFld="" then
		Dtype=0
	else
		if IsNumeric(obj.dataFld) then
			Dtype=obj.dataFld
		else
			select Case Ucase(obj.dataFld)
			case "YYMMDD"
				Dtype=0
			case "YYYYMMDD"
				Dtype=1
			case "YY/MM/DD"
				Dtype=2
			case "YYYY/MM/DD"
				Dtype=3
			case "MMDD"
				Dtype=4
			case "MM/DD"
				Dtype=5
			case "YYYY"
				Dtype=6
			case "YYYY/MM"
				Dtype=7
			case "YY/MM"
				Dtype=8
			default
			  Dtype=0
			end select
		end if
	end if
	obj.dataFld=Cstr(DType)
	
	obj.Dir="LTR"
	if  not((code>47 and Code <58)) then window.event.keyCode=0
	if Dtype=0 then '0:YYMMDD
	    obj.maxlength=6
	    obj.Title="YYMMDD"
	    if len(obj.value)=2 and (code<48 or code>49)   then window.event.keyCode=0
	    if len(obj.value)=3 and (Mid(obj.value,3,1)="1" and (code<48 or code>50)) then window.event.keyCode=0
	    if len(obj.value)=4 and (code<48 or code>51)   then window.event.keyCode=0
	    if len(obj.value)=5 and (Mid(obj.value,5,1)="3" and (code<48 or code>49)) then window.event.keyCode=0
	End if 'Dtype=0 then
	if Dtype=1 then '1:YYYYMMDD
		obj.maxlength=8
	    obj.Title="YYYYMMDD"
	    if len(obj.value)=0 and (code<49 or code>49)   then window.event.keyCode=0
	    if len(obj.value)=1 and (code<50 or code>52)   then window.event.keyCode=0
	    if len(obj.value)=4 and (code<48 or code>49)   then window.event.keyCode=0
	    if len(obj.value)=5 and (Mid(obj.value,5,1)="1" and (code<48 or code>50)) then window.event.keyCode=0
	    if len(obj.value)=6 and (code<48 or code>51)   then window.event.keyCode=0
	    if len(obj.value)=7 and (Mid(obj.value,7,1)="3" and (code<48 or code>49)) then window.event.keyCode=0
	End if 'obj.Dtype=1 then
	if Dtype=2 then '2:YY/MM/DD
		obj.maxlength=8
	    obj.Title="YY/MM/DD"
		if len(obj.value)=2 or len(obj.value)=5 then obj.value=obj.value&"/"
	    if len(obj.value)=3 and (code<48 or code>49)   then window.event.keyCode=0
	    if len(obj.value)=4 and (Mid(obj.value,4,1)="1" and (code<48 or code>50)) then window.event.keyCode=0
	    if len(obj.value)=6 and (code<48 or code>51)   then window.event.keyCode=0
	    if len(obj.value)=7 and (Mid(obj.value,7,1)="3" and (code<48 or code>49)) then window.event.keyCode=0
	End if 'obj.Dtype=0 then
	if Dtype=3 then '3:YYYY/MM/DD
        obj.maxlength=10
	    obj.Title="YYYY/MM/DD"
		if len(obj.value)=4 or len(obj.value)=7 then obj.value=obj.value&"/"
	    if len(obj.value)=0 and (code<49 or code>49)   then window.event.keyCode=0
	    if len(obj.value)=1 and (code<50 or code>52)   then window.event.keyCode=0
	    if len(obj.value)=5 and (code<48 or code>49)   then window.event.keyCode=0
	    if len(obj.value)=6 and (Mid(obj.value,6,1)="1" and (code<48 or code>50)) then window.event.keyCode=0
	    if len(obj.value)=8 and (code<48 or code>51)   then window.event.keyCode=0
	    if len(obj.value)=9 and (Mid(obj.value,9,1)="3" and (code<48 or code>49)) then window.event.keyCode=0
	End if 'obj.Dtype=0 then
	if Dtype=4 then '4:MMDD
		obj.maxlength=4
	    obj.Title="MMDD"
	    if len(obj.value)=0 and (code<48 or code>49)   then window.event.keyCode=0
	    if len(obj.value)=1 and (Mid(obj.value,1,1)="1" and (code<48 or code>50)) then window.event.keyCode=0
	    if len(obj.value)=2 and (code<48 or code>51)   then window.event.keyCode=0
	    if len(obj.value)=3 and (Mid(obj.value,3,1)="3" and (code<48 or code>49)) then window.event.keyCode=0
	End if 'obj.Dtype=0 then
	if Dtype=5 then '5:MM/DD
		obj.maxlength=5
	    obj.Title="MM/DD"
		if len(obj.value)=2 or len(obj.value)=5 then obj.value=obj.value&"/"
	    if len(obj.value)=0 and (code<48 or code>49)   then window.event.keyCode=0
	    if len(obj.value)=1 and (Mid(obj.value,1,1)="1" and (code<48 or code>50)) then window.event.keyCode=0
	    if len(obj.value)=3 and (code<48 or code>51)   then window.event.keyCode=0
	    if len(obj.value)=4 and (Mid(obj.value,4,1)="3" and (code<48 or code>49)) then window.event.keyCode=0
	End if 'obj.Dtype=0 then
	
	if Dtype=6 then '6:YYYY
		obj.maxlength=4
	    obj.Title="YYYY"
	    if len(obj.value)=0 and (code<49 or code>49)   then window.event.keyCode=0
	    if len(obj.value)=1 and (code<50 or code>52)   then window.event.keyCode=0
	End if 'obj.Dtype=0 then
	if Dtype=7 then '7:YYYY/MM
		obj.maxlength=7
	    obj.Title="YYYY/MM"
		if len(obj.value)=4  then obj.value=obj.value&"/"
	    if len(obj.value)=0 and (code<49 or code>49)   then window.event.keyCode=0
	    if len(obj.value)=1 and (code<50 or code>52)   then window.event.keyCode=0
	    if len(obj.value)=5 and (code<48 or code>49)   then window.event.keyCode=0
	    if len(obj.value)=6 and (Mid(obj.value,6,1)="1" and (code<48 or code>50)) then window.event.keyCode=0
	End if 'obj.Dtype=0 then
	if Dtype=8 then '8:YY/MM
		obj.maxlength=5
	    obj.Title="YY/MM"
		if len(obj.value)=2 then obj.value=obj.value&"/"
	    if len(obj.value)=3 and (code<48 or code>49)   then window.event.keyCode=0
	    if len(obj.value)=4 and (Mid(obj.value,4,1)="1" and (code<48 or code>50)) then window.event.keyCode=0
	End if 'obj.Dtype=0 then
	end function
'------- Chake Date ---------------------------------------
	
	function CheckDate(obj)
	Dim v,SwCanzero,SwB
        IF obj.Title=""  THEN sW=KeyDate(obj)
    SwOk=True
	if Trim(obj.Value)<>"" then
		if  len(obj.Value)<>obj.maxlength then SwOk=False
		if SwOk Then
			if InStr(obj.Title,"YYYY")<>0 then
				if (Cint("0"&Mid(obj.value,InStr(obj.Title,"YYYY"),4))<1200) or (Cint("0"&Mid(obj.value,InStr(obj.Title,"YYYY"),4))>1400) then SwOk=False
			else
				if InStr(obj.Title,"YY")<>0 then
				end if
			end if
		End if 
		if SwOk Then
		  if InStr(obj.Title,"MM")<>0 then if Mid(obj.value,InStr(obj.Title,"MM"),2)="" or Cint("0"&Mid(obj.value,InStr(obj.Title,"MM"),2))<0 or Cint("0"&Mid(obj.value,InStr(obj.Title,"MM"),2))>12 then SwOk=False
		End if 
		if SwOk Then
		  if InStr(obj.Title,"DD")<>0 then if Mid(obj.value,InStr(obj.Title,"DD"),2)="" or Cint("0"&Mid(obj.value,InStr(obj.Title,"DD"),2))<0 or Cint("0"&Mid(obj.value,InStr(obj.Title,"DD"),2))>31 then SwOk=False
		End if 
		if SwOk Then
		  if InStr(obj.Title,"/")<>0 then 
		    if Mid(obj.value,InStr(obj.Title,"/"),1)<>"/" then SwOk=False
			if InStr(1+InStr(obj.Title,"/"),obj.Title,"/")<>0 then 
			  if Mid(obj.value,InStr(1+InStr(obj.Title,"/"),obj.Title,"/"),1)<>"/" then SwOk=False
		    end if   
		  end if   
		End if 
		if not SwOk then
			CheckDate=False
			alert("فرمت تاريخ صحيح نمي باشد"&chr(13)&obj.title)
			obj.select()
			obj.focus()
		End if' not SwOk then
	end if    
	end function
	
