/********************************************************/
/* magDOM-UB-Core                                       */
/*                                                      */
/* writen by Magnum                                     */
/* date 2008/10/5                                       */
/********************************************************/

UB.Core.childNodes = function(node){
 var i,inner,str;
 var array = new Array();
 if(!node){
  return array;
 }
 if(!node.hasChildNodes()){
  return array;
 };
 var children = node.childNodes;
 for(i = 0;i < children.length;i++){
  inner = children.item(i);
  if(inner.nodeType == 3){
   str = inner.nodeValue;
   if(!str.match('/[^\s\t\n\r]/')){
    continue;
   }
  }
  array.push(inner);
 }
 array.item = function(num){
  if(array[num]){
   return array[num];
  }else{
   return null;
  }
 }
 return array;
}

UB.Core.previousNode = function(node){
 var obj,pvs,str;
 if(!node){
  return null;
 }
 obj = node;
 while(pvs = obj.previousSibling){
  if(pvs.nodeType == 3){
   str = pvs.nodeValue;
   if(!str.match('/[^\s\t\n\r]/')){
    obj = pvs;
    continue;
   }
  }
  return pvs;
 }
 return null;
}

UB.Core.nextNode = function(node){
 var obj,nxt,str;
 if(!node){
  return null;
 }
 obj = node;
 while(nxt = obj.nextSibling){
  if(nxt.nodeType == 3){
   str = nxt.nodeValue;
   if(!str.match('/[^\s\t\n\r]/')){
    obj = nxt;
    continue;
   }
  }
  return nxt;
 }
 return null;
}

UB.Core.TextContent = function(node){
 var i,obj;
 var str = '';
 if(!node){
  return str;
 }
 if(typeof node.textContent != 'undefined'){
  str = node.textContent;
 }else if(typeof node.innerText != 'undefined'){
  str = node.innerText;
 }else if(node.hasChildNodes()){
  for(i = node.childNodes.length;i--;){
   obj = node.childNodes.item(i);
   if(obj.nodeType == 3){
    str = obj.nodeValue+str;
   }else{
    str = UB.core.getTextContent(obj)+str;
   }
  }
 }
 return str;
}

UB.Core.removeChilds = function(node){
 while(node.hasChildNodes()){
  node.removeChild(node.lastChild);
 }
}
