String.prototype.at = function(str) {
var tl = this.length, sl = str.length;
for(var i=j=0; i<tl; i++) {
if(this[i] == str[j] && sl == ++j) return ++i-j;
}
return -1;
}
var s1 = 'aababababaO_o', l1 = 'ababaO', l2 = 'abac', l3 = 'aa', l4 = 'O_o';
alert([
[s1.at(l1), s1.indexOf(l1)],
[s1.at(l2), s1.indexOf(l2)],
[s1.at(l3), s1.indexOf(l3)],
[s1.at(l4), s1.indexOf(l4)]
].join('\n') );