// Explaination of what's going wrong with this code
//while (element) {
//	if (element.id) element.id.startsWith("whatever");
//	
//	// when element is an Element its `id` is a string
//	// when element is a Document its `id` is usually undefined
//	// when a JavaScript framework sets document.id to a function,
//	//     its `id` will not have the `startsWith` method
//	// 
//	// If they used `element.getAttribute('id')` instead, this wouldn't be a problem
//	// If JavaScript frameworks did not set document.id to a function then this wouldn't be a problem
//	
//	element = element.parentNode;
//}


// Complete original source
//     from http://www.infinitezest.com/SourceViewer/AJAXSourceMethod.aspx?Method=_getPostBackSettings(element,%20elementUniqueID)
function Sys$WebForms$PageRequestManager$_getPostBackSettings(element, elementUniqueID) {
  var originalElement = element;
  var proposedSettings = null;
  while (element) {
    if (element.id) {
      if (!proposedSettings && Array.contains(this._asyncPostBackControlClientIDs, element.id)) {
        proposedSettings = this._createPostBackSettings(true, this._scriptManagerID + '|' + elementUniqueID, originalElement);
      }
      else {
        if (!proposedSettings && Array.contains(this._postBackControlClientIDs, element.id)) {
          return this._createPostBackSettings(false, null, null);
        }
        else {
          var indexOfPanel = Array.indexOf(this._updatePanelClientIDs, element.id);
          if (indexOfPanel !== -1) {
            if (this._updatePanelHasChildrenAsTriggers[indexOfPanel]) {
              return this._createPostBackSettings(true, this._updatePanelIDs[indexOfPanel] + '|' + elementUniqueID, originalElement);
            }
            else {
              return this._createPostBackSettings(true, this._scriptManagerID + '|' + elementUniqueID, originalElement);
            }
          }
        }
      }
      if (!proposedSettings && this._matchesParentIDInList(element.id, this._asyncPostBackControlClientIDs)) {
        proposedSettings = this._createPostBackSettings(true, this._scriptManagerID + '|' + elementUniqueID, originalElement);
      }
      else {
        if (!proposedSettings && this._matchesParentIDInList(element.id, this._postBackControlClientIDs)) {
          return this._createPostBackSettings(false, null, null);
        }
      }
    }
    element = element.parentNode;
  }
  if (!proposedSettings) {
    return this._createPostBackSettings(false, null, null);
  }
  else {
    return proposedSettings;
  }
}

