I have a search field that allows for searching a text file. If the entry is NOT formatted correctly, an alert is displayed. They only get to see the submit button if the field is correctly formatted.

What I want to do is to limit the number of times they can try to 4 attempts.

How can I set a cookie in javascript to get the users IP address, and count the number of times the alert box is triggered by them in that 1 session, and after the 4 triggered attempts, display a message ( TELL THEM TO GO AWAY! ) and disable the input field for users from that IP address for 1 hour.

The input field is like this.

<input type="text" name="codenumber"   maxlength="16" size="16"onMouseOut="checkAlert()";/>
How do I code the cookie etc...etc... OR is there a better way to accomplish this.

Maybe I can hide the input field in a DIV and check to see if that IP is banned before showing it.
I have never set cookies to do any of this before.

I DON'T want to have to go the server route & PHP if I don't have to.