/*
	map.dom.js
	
	functions for DOM manipulation and traversal
	
*/

// DEFINE DOM CLASS
domClass = function() {}; // empty class constructor


//*****************************************************************************
// BEGIN DOM METHODS
//*****************************************************************************


//*****************************************************************************
// CLEARNODE
//*****************************************************************************

/*
 * This function clears the contents of thisNode by replacing thisNode with an empty node
 * of the same tag or if thisNode has no tag with an empty text node. Use this method to "delete" a node.
 */

domClass.prototype.clearNode = function(thisNodeId) {
	var emptyNode;
	var thisNode=document.getElementById(thisNodeId);
	if(thisNode == null) { 
		alert ("map.dom Error\n\nmap.url.clearNode(): The node you requested could not be found.");
	}
	if(thisNode.tagName == null)//assumes text nodes are the only HTMLElements without a tagName
	{
	   emptyNode=document.createTextNode("");
	} 
	else {
	  var tag=thisNode.tagName;
	  emptyNode=document.createElement(tag);  
	}
	emptyNode.setAttribute("id",thisNodeId);
	if (emptyNode.name) {
	  emptyNode.setAttribute("name",thisNodeId);
	}
	thisNode.parentNode.replaceChild(emptyNode,thisNode);//replaces itself with an empty copy    
}
// END CLEARNODE
//*****************************************************************************


//*****************************************************************************
// COPYNODE
//*****************************************************************************

/* 
* This function copies the contents (all child nodes) of the fromNode to the toNode
* You will often use this method in conjunction with map.dom.clearNode()
*/

domClass.prototype.copyNode = function(fromNodeId,toNodeId) {
	var fromNode=document.getElementById(fromNodeId);
	var toNode=document.getElementById(toNodeId);
	for(var i=0;i<fromNode.childNodes.length;i++) {
		var clonedNode=fromNode.childNodes.item(i).cloneNode(true);
		toNode.appendChild(clonedNode);
	}
}

// END COPYNODE
//*****************************************************************************


//*****************************************************************************
// FIELDCHANGE
//*****************************************************************************

/*
 *  This function changes the value of an input or other named element anywhere in the current document.
 */
	
domClass.prototype.fieldChange = function(strObject, strValue) {
	var objField = new Object();
	try {
  		objField = document.getElementById(strObject);
  		objField.value = strValue;
	} catch(e) {
  		alert("map.dom Error\n\nmap.dom.fieldChange(): The form object requested could not be found.");
	}
}

// END FIELDCHANGE
//*****************************************************************************


//*****************************************************************************
// FIELDCOPY
//*****************************************************************************
  
/* 
 * This function copies the value of one field to another
 */
 
domClass.prototype.fieldCopy = function(strField1, strField2) {
  var strVal = new String();
  strVal = document.getElementById(strField1).value;
  document.getElementById(strField2).value = strVal;
}

// END FIELDCOPY
//*****************************************************************************


// END DOM METHODS
//*****************************************************************************


//*****************************************************************************
// ADD DOM CLASS TO MAPCLASS
//*****************************************************************************
mapClass.prototype.dom = new domClass();
