﻿/*********************************************************************
This code is meant to fix the problem of pages going back to top when
clicking on a button that causes validation.  This only happens when
there is a validation summary on the page.  gotoActiveSummary() will
cause the page to focus on the validation summary saved with the
saveLocalValidationSummary method.
**********************************************************************/

var _obj_activevalidationsummary=null;
function saveLocalValidationSummary(validationsummaryid)
{
    _obj_activevalidationsummary = document.getElementById(validationsummaryid);
}
function gotoActiveSummary()
{
    if (_obj_activevalidationsummary != null)
    {
        var coors = findPos(_obj_activevalidationsummary);
        window.scrollTo(coors[0],coors[1]);
        _obj_activevalidationsummary = null;
    }
}
function scrolltoValidationSummaryScript()
{
    if (typeof(ValidatorOnSubmit) == "function") 
    {
        var isValidated = ValidatorOnSubmit();
        if (!isValidated)
        {
            gotoActiveSummary();
            return false;
        }
        return true;
    }
}
function findPos(obj) 
{
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        do {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
        } while (obj = obj.offsetParent);
    }
    return [curleft,curtop];
}
