var x = document.getElementsByTagName('a');
for (var i=0;i<x.length;i++) {
    if (x[i].href == location.href) x[i].className += " onstate";
}