function getParentElementByTagName( root, tagName ) {
  var currentTagName = root.tagName;
  
  while( currentTagName != undefined && currentTagName != tagName ) {
    root = root.parentNode;
    currentTagName = root.tagName;
  }
  
  return root;
}

function getChildElementByTag( root, tagName ) {
  for ( var child in root.childNodes ) {
    if( root.childNodes[child].tagName == tagName ) {
      return root.childNodes[child];
    }
    retval = getChildElementByTag( root.childNodes[child], tagName );
    if( retval != null )
      return retval;
  }
  
  return null;
}
