EDIT-2: None of the answers seem to work. Not even the one I previously marked as the answer of this question. Any help is appreciated. Thanks.
Added a new answer to display the code formatted:
The thing is that you were checking for document.referer, because you were in ff it was returning always true, then it was navigating to http://mysite.com. Try the following:
function backAway(){
if (document.referrer) {
//firefox, chrome, etc..
i = 0;
} else {
// under ie
i = 1;
}
if (history.length>i)
{
// there are items in history property
history.back();
} else {
window.location = 'http://www.mysite.com/';
}
return false;
}