// see http://www.sitepoint.com/print/scroll-smoothly-javascript/ for details
function ScrollToAnchor(anchorName)
{
    ScrollToAnchor(anchorName, false);
}
function ScrollToAnchor(anchorName, bScrollAlways)
{
    destinationLink = GetAnchor(anchorName);
    if (destinationLink == null)
        window.scrollTo(0, 0);
    else
    {
          var destx = destinationLink.offsetLeft;  
         var desty = destinationLink.offsetTop;
         var thisNode = destinationLink;
         while (thisNode.offsetParent &&  
               (thisNode.offsetParent != document.body)) {
           thisNode = thisNode.offsetParent;
           destx += thisNode.offsetLeft;
           desty += thisNode.offsetTop;
        }
        
        cypos = ss_getCurrentYPos(); 
        
        if (bScrollAlways == true || cypos > desty)    
            window.scrollTo(0, desty);
    }
}

function ss_getCurrentYPos() {
 if (document.body && document.body.scrollTop)
   return document.body.scrollTop;
 if (document.documentElement && document.documentElement.scrollTop)
   return document.documentElement.scrollTop;
 if (window.pageYOffset)
   return window.pageYOffset;
 return 0;
}


function GetAnchor(anchorName)
{
  var allLinks = document.getElementsByTagName('a');
  for (var i=0;i<allLinks.length;i++) {
   var lnk = allLinks[i];
   if (lnk.hash && lnk.hash.length > 1 && (lnk.hash.substr(1) == anchorName)) {
     return lnk;
   }
 } 
}