If lasIndexOf cant find the value it's looking for it'll return -1.
So use a if statement for the substring if steps > 0 use str.substring(slashPos+1, steps);
else str.substring(slashPos+1);
The code in the .js file is jquery http://jquery.com/ it is a framework for javascript to make things like animations easier. look at http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery...
If you have each "search" on a line or comma-separated you could count the inputs in the file.
If it's 50 or above, delete the first line and append the new one at the end.