dim validation

Function CheckVIN(sVIN)
	'sVIN = document.All.item("serverHeaderControl_txtSearchField").value
	sVIN = UCase(sVIN)
	sVIN = trim(sVIN)
	If (Len(sVIN) <> 17 Or InStr(1, sVIN, "I") > 0 Or InStr(1, sVIN, "O") > 0 Or InStr(1, sVIN, "Q") > 0) and sVIN <> "OPTIONAL" Then
	   MsgBox("You have entered an invalid VIN.")		  
	    CheckVIN = False
	    Exit Function
	End If

	dim i

	For i = 1 To 17
	    If IsNumeric(Mid(sVIN, i, 1)) = False Then
	        tmpNum = Asc(Mid(sVIN, i, 1)) - 64
	        If tmpNum >= 19 Then
	            tmpNum = tmpNum Mod 9 + 1
	        Else
	            tmpNum = tmpNum Mod 9
	            If tmpNum = 0 Then tmpNum = 9
	        End If
	    Else
	        tmpNum = CInt(Mid(sVIN, i, 1))
	    End If
	    
	    If i <= 7 Then
	        tmpNum = tmpNum * (9 - i)
	    ElseIf i = 8 Then
	        tmpNum = tmpNum * 10
	    ElseIf i >= 10 Then
	        tmpNum = tmpNum * (19 - i)
	    Else
	        tmpNum = 0
	    End If
	    
	    tmpTotal = tmpTotal + tmpNum
	Next
	tmpCheckDigit = CStr(tmpTotal Mod 11)
	If tmpCheckDigit = "10" Then
	    tmpCheckDigit = "X"
	End If

	If Mid(sVIN, 9, 1) = tmpCheckDigit and sVIN <> "OPTIONAL" Then
	    CheckVIN = True
	Else
                  MsgBox("You have entered an invalid VIN.")                
	    CheckVIN = False
	End If
End Function

Function CheckVINNew()
	sVIN = document.All.item("serverHeaderControl_txtSearchField").value
	sVIN = UCase(sVIN)
	sVIN = trim(sVIN)
	If (Len(sVIN) <> 17 Or InStr(1, sVIN, "I") > 0 Or InStr(1, sVIN, "O") > 0 Or InStr(1, sVIN, "Q") > 0) and sVIN <> "OPTIONAL" Then
	   MsgBox("You have entered an invalid VIN.")	
	   msgbox(sVIN)
	    CheckVINNew = False
	    Exit Function
	End If

	dim i

	For i = 1 To 17
	    If IsNumeric(Mid(sVIN, i, 1)) = False Then
	        tmpNum = Asc(Mid(sVIN, i, 1)) - 64
	        If tmpNum >= 19 Then
	            tmpNum = tmpNum Mod 9 + 1
	        Else
	            tmpNum = tmpNum Mod 9
	            If tmpNum = 0 Then tmpNum = 9
	        End If
	    Else
	        tmpNum = CInt(Mid(sVIN, i, 1))
	    End If
	    
	    If i <= 7 Then
	        tmpNum = tmpNum * (9 - i)
	    ElseIf i = 8 Then
	        tmpNum = tmpNum * 10
	    ElseIf i >= 10 Then
	        tmpNum = tmpNum * (19 - i)
	    Else
	        tmpNum = 0
	    End If
	    
	    tmpTotal = tmpTotal + tmpNum
	Next
	tmpCheckDigit = CStr(tmpTotal Mod 11)
	If tmpCheckDigit = "10" Then
	    tmpCheckDigit = "X"
	End If

	If Mid(sVIN, 9, 1) = tmpCheckDigit and sVIN <> "OPTIONAL" Then
	    CheckVINNew = True
	Else
                  MsgBox("You have entered an invalid VIN.")
	    CheckVINNew = False
	End If
End Function

