// VBScript Document

sub fieldchk(a,b,c)    
	kcode=window.event.keyCode
	select case (cint(b))
	  case 1 //Name Validation
    	if not((ucase(chr(kcode))>="A") and (ucase(chr(kcode))<="Z") or (kcode=32) or (kcode=8)) then
			window.event.keyCode=0
		end if
	  case 2 //Address Validation
		if not((ucase(chr(kcode))>="A") and (ucase(chr(kcode))<="Z") or (chr(kcode)="(") or (chr(kcode)=")") or (chr(kcode)="/") or (chr(kcode)=".") or (chr(kcode)="-") or (chr(kcode)="_") or (chr(kcode)=",") or (chr(kcode)=":") or (chr(kcode)="#") or (kcode=32) or (chr(kcode)>="0" and chr(kcode)<="9") or (kcode=13) or (kcode=8)) then    
			window.event.keyCode=0
		end if
	  case 3 //Number Validation
		if not((chr(kcode)>="0" and chr(kcode)<="9") or (kcode=8)) then
			window.event.keyCode=0
		end if
	  case 4 //Decimal Validation
		if not((chr(kcode)>="0" and chr(kcode)<="9") or (chr(kcode)=".") or (kcode=8)) then
			window.event.keyCode=0
		end if
	  case 5 //Signed Decimal Validation
	    if not((chr(kcode)>="0" and chr(kcode)<="9") or (chr(kcode)="-") or (chr(kcode)="+") or (chr(kcode)=".") or (kcode=8)) then
			window.event.keyCode=0
		end if
      case 6 //Not allowing single quotes
	    if (chr(kcode)="'") then
		   window.event.keycode=0
		 end if		
	  case 7 //Space Validation for email,..
    	if not((ucase(chr(kcode))>="A") and (ucase(chr(kcode))<="Z") or (chr(kcode)>="0" and chr(kcode)<="9") or (chr(kcode)=".") or (chr(kcode)="_") or (chr(kcode)="-") or (chr(kcode)="@") or (kcode=8)) then
			window.event.keyCode=0
		end if		 
	  case 8 //Getting Time Validation
		if not((chr(kcode)>="0" and chr(kcode)<="9") or (kcode=8) or (chr(kcode)=":") ) then
			window.event.keyCode=0
		end if		
	  case 9 //Only Alphanumeric
		if not((chr(kcode)>="0" and chr(kcode)<="9") or (kcode=8) or (ucase(chr(kcode))>="A") and (ucase(chr(kcode))<="Z") or (kcode=32) or (kcode=8)) then
			window.event.keyCode=0
		end if			
	  case else
    	alert("Plz pass the valid argument for validation")		
end select
	if cint(c) <>0 then	
		if len(a.value)>c-1 then
			window.event.keyCode=0
		end if
	end if	
end sub

'-----------ENCODE/DECODE
Function Encode(sIn)
	dim x, y, abfrom, abto
    Encode="": ABFrom = ""

    For x = 0 To 25: ABFrom = ABFrom & Chr(65 + x): Next 
    For x = 0 To 25: ABFrom = ABFrom & Chr(97 + x): Next 
    For x = 0 To 9: ABFrom = ABFrom & CStr(x): Next 

    abto = Mid(abfrom, 14, Len(abfrom) - 13) & Left(abfrom, 13)
    For x=1 to Len(sin): y = InStr(abfrom, Mid(sin, x, 1))
        If y = 0 Then
             Encode = Encode & Mid(sin, x, 1)
        Else
             Encode = Encode & Mid(abto, y, 1)
        End If
    Next
End Function

Function Decode(sIn)
    dim x, y, abfrom, abto
    Decode="": ABFrom = ""

    For x = 0 To 25: ABFrom = ABFrom & Chr(65 + x): Next 
    For x = 0 To 25: ABFrom = ABFrom & Chr(97 + x): Next 
    For x = 0 To 9: ABFrom = ABFrom & CStr(x): Next 

    abto = Mid(abfrom, 14, Len(abfrom) - 13) & Left(abfrom, 13)
    For x=1 to Len(sin): y=InStr(abto, Mid(sin, x, 1))
        If y = 0 then
            Decode = Decode & Mid(sin, x, 1)
        Else
            Decode = Decode & Mid(abfrom, y, 1)
        End If
    Next
End Function

'TITLE CASE FUNCTION
Function TitleCase(Txt)	
	If txt <> "" Then		
		Txt=LCase(CStr(Txt))		
		x=Instr(1,Txt,chr(32),vbTextCompare)		
		If x = 0 Then			
			TitleCase=UCase(Left(Txt,1)) & Mid(Txt,2,len(Txt)-1)		
		ElseIf x > 0 Then			
			tmp = Split(Txt,chr(32))			
			For I = LBound(tmp) To Ubound(tmp)				
				newStr = newStr & (UCase(Left(tmp(i),1)) & Mid(tmp(i),2,len(tmp(i))-1)) & " "			
			Next			
			newStr=Left(newStr,Len(newStr)-1)			
			TitleCase=newStr		
		End If		
		Set tmp = Nothing	
	End If
End Function 

