I'm writing a page template for a webcomic. The idea is that a dirrectory will contain a bunch of files named, for example, comic001.jpg, comic002.jpg, comic003.jpg, and so on. What I'm trying to do is to have a link that the viewer can click to load the next page (if one is available).
I need to be able to extract the ### part of the file name and increment it by one. To that end I'm using a function to pull out the numbers from the URL as a string, and then another function to convert the string to an int type array and increment them by 1. It's not working though.

Can someone tell me why?
Code:
function forward() {
var url = document.pic.src;
var periodlocation=url.lastIndexOf(".");
var filetype=url.substring(periodlocation);
var number=url.substring((periodlocation - 4), periodlocation);
var urlbase=url.substring(0, (periodlocation - 4));
var number = increment(number);
document.pic.src = (urlbase + number + filetype);
}
function increment(str) {
var numbers = Array(str.length);
var numberlist = "0123456789";
for (var x = 0; x < str.length; x++) {
numbers[x] = numberlist.indexOf(str.charAt(x));
}
var i = 1;
while (i <= numbers.length) {
if (numbers[numbers.length - i] < 9) {
numbers[numbers.length - i] = (numbers[numbers.length - i] + 1);
break;
}
esle {
numbers[numbers.length - i] = 0;
i++;
}
}
var result = "";
for (var a = 0; a < numbers.length; a++) {
result = result + numbers[a];
}
return result;
}
Also, what little background I have is in Java and this is only the second JavaScript that I have ever writen, so be kind to the newb, k?