Your indexes are messed up. A zero-indexed array with length x has an index of zero through (index - 1). You're trying to access the tabs array with an index that is out of bounds.
Every place where you are trying to access array[array.length], use array[array.length - 1] and you should be good to go.
Johnny Fuery
President/Principal Engineer
Fuery Solutions -- makers of MerusCase
1736 Franklin Street, Suite 350
Oakland, CA 94612