/**
 * Additional Dom Control Function
 */
document.getElementsByAttribute = function (attrName,attrValue)
{
        var re;
        var foundels;
        var iFound;
        var sAttrValue;

        checkels = document.getElementsByTagName('*');
        foundels = new Array();

        for (el = 0; el < checkels.length; el++) {
                sAttrValue = checkels[el].getAttribute(attrName, 2);
                re = new RegExp(attrValue, "ig");
                if (re.test(sAttrValue) != 0) {
                        iFound = foundels.push(checkels[el]);
                }
        }
        return foundels;
}


if(self.Node&&self.Node.prototype) 
{	
    Node.prototype.removeNode=remove_Node;	 
    Node.prototype.replaceNode=replace_Node;
}


function replace_Node(a1) // Node 를 삭제 한다. node.removeNode(true);
{
	var p=this.parentNode;
     p.insertBefore(a1,this);
	return p?p.removeChild(this):this;
}


function remove_Node(a1) // Node 를 삭제 한다. node.removeNode(true);
{
	var p=this.parentNode;
	if(p&&!a1)	
	{
		var df=document.createDocumentFragment();
		for(var a=0;a<this.childNodes.length;a++) df.appendChild(this.childNodes[a])
		p.insertBefore(df,this)
	}
	return p?p.removeChild(this):this;
}


function insertAfter(node, referenceNode) // node 를 referenceNode 다음 노드에 추가  
{
  var p = referenceNode.parentNode;
  p.insertBefore(node, referenceNode.nextSibling);
}


var DOM =
{
	getRealChildNode : function (Node) // 각 노드의 자식 노드를 배열로 반환
	{
			
			if(!Node) return false;
			
			var CNodes = [];
			var CNum = 0;
			for(var i=0; i < Node.childNodes.length; i++)
			{
					var Cnode = Node.childNodes[i];
					if(Cnode.nodeType == 1)
					{ 
						CNodes[CNum] = Cnode;
						CNum++;
					}
			}
			
			return (CNum > 0) ? CNodes : false;
	},
	
	setAttributes : function (From, To) // From 의 Attribute 를 To에 셋팅함
	{
		var Att = From.attributes;
		for(var i=0; i < Att.length; i++)
		{
			var Value = From.getAttribute(Att[i].nodeName);
			To.setAttribute(Att[i].nodeName, Value );
		}
	},
	
	remove : function (Obj)
	{
	   if(IE_)
       {
           purge(Obj);
           Obj.outerHTML ="";
       }
       else   Obj.removeNode(true);
	},
	
    
	removeChilds : function (Obj)
	{
	   
	    while(Obj.childNodes.length)
	    {
	        var Node = Obj.childNodes[0];
	        
	        if(IE_)
    	    {
    	           purge(Node);
    	           if(Node.outerHTML)    	           Node.outerHTML ="";
    	           else Node.removeNode(true);
    	    }
    	    else  Node.removeNode(true);
	    }
	    
	    return;
	},
	
	
	/**
	 * Node 의 Attribute 를 Object 로 반환
	 * Javascript 는 연관배열과 Object 의 구분이 없음
	 */
	getAttributes : function (Node)
	{
		
		if(Node)
		{
    		var Att = Node.attributes;
    		var Obj =[];
    		
    		for(var i=0; i < Att.length; i++)
    		{
    			var nodeName = Att[i].nodeName;
    			var nodeValue = Node.getAttribute(nodeName);
    			Obj[nodeName] = nodeValue;
    		}
    		
    		return Obj;
		}
		return false;
		
	
    },
	
	/**
	 * @param Object Node.
	 * @return Object DIV Element.
	 * Node 의 Attribute 를 포팅한 DIV Element 를 반환함.
	 */
	getDivNode :  function (Node)
	{
		var DIV = document.createElement('DIV');
		DOM.setAttributes(Node, DIV);
		return DIV;
	},
	
	objToAttribute : function (Obj, El)
	{
		
		for(var Key in Obj)
		{
			var Value = Obj[Key];
			
			if(isFunction(Value)) continue;
			else El.setAttribute(Key, Value);
			
		}	
		
	},
	
	getElementsByObj : function (El, Obj)
	{
		var Elements = document.createElement(El);
		
		for(var Key in Obj)
		{
				var Value = Obj[Key];
				if(isFunction(Value)) continue;
				else Elements[Key] = Obj[Key];
		}	
		
		return Elements;
	},
	
	showAttributes : function (Node)
	{
		var Att = Node.attributes;
		
		for(var i=0; i < Att.length; i++)
		{
			var Value =Node.getAttribute( Att[i].nodeName );
			alert(Att[i].nodeName + ' : ' + Value);
			
		}
	}
}
