function DOMUtil() {
}

DOMUtil.prototype.getElementsByTagName = function(tagName, root) {
	return (root || document).getElementsByTagName(tagName) ;
}

DOMUtil.prototype.getAncestorByClassName = function(element, className) {
	while(true) {
		var parent = element.parentNode ;
		if(parent && parent.className == className) return parent ;
	}
	return null ;
}

DOMUtil.prototype.getDescendantsByClassName = function(root, tagName, className) {
	var descendants = this.getElementsByTagName(tagName, root) ;
	var list = new Array() ;
	if(descendants && (descendants.length > 0)) {
		for( var i = 0; i < descendants.length; i++) {
			var child = descendants[i] ;
			if(child.className == className) {
				list.push(child) ;
			} else {
				if(child.className.indexOf(" ") >= 0) {
					var childName = child.className.split(" ") ;
					for( var j = 0; j < childName.length; j++) {
						if(childName[j] == className) list.push(child) ;
					}
				}
			}
		}
	}
	if(list.length > 0) return list ;
	return null ;
}

DOMUtil.prototype.findAncestorByClass = function(element, clazz) {
  var parent = element.parentNode ;
  while(parent != null) {
    if(parent.className == null) {
    } else  if(parent.className.indexOf(" ") >= 0) {
      var classes = parent.className.split(" ");
      for(var j = 0;j < classes.length; j++) {
        if(classes[j] == clazz)  return parent ;
      }
    } else if(parent.className == clazz)  {
      return parent ;
    }
    parent =  parent.parentNode ;
  }
  return null ;
} ;

DOMUtil.prototype.findAncestorById = function(element,  id) {
  var parent = element.parentNode ;
  while(parent != null) {
    if(parent.id == id)  return parent ;
    parent = parent.parentNode ;
  }
  return null ;
} ;

DOMUtil = new DOMUtil() ;
