 
//Returns a string of values separated by commas from the nodes selected through the XPath query
function GetNodeNamesInCsvFormat(xmlDoc, xPathQuery) {
    var listOfNames = xmlDoc.GetNodeNamesOfChildren(xPathQuery)
    return listOfNames.join(",")    
}
//Deletes the value node with a specific value specified in the XPath string
function DeleteValueNode(xmlDoc, xPathString, value) {
    xPathString = '/Search/' + xPathString + '/Value[.="' + value + '"]'
    xmlDoc.DeleteNode(xPathString)       
}
//Deletes the all value nodes for a specific value XMLNodeName
function DeleteAllValueNodes(xmlDoc, xPathString) {
    var updatedXpathString = "/Search/" + xPathString
    xmlDoc.DeleteChildren(updatedXpathString)
    // nothing to return
    return true
}
//Inserts a node in the place designated in the XPath string.
function AppendValueNodeForDropdown(objXmlDoc, xPathString, itemIdArr, itemValueArr) {
    if (itemIdArr.length > 0 && itemIdArr.length == itemValueArr.length)  {
        //Create the <Value> node.
        var newValueNode = objXmlDoc.AppendNode(xPathString, "Value", "")        
		for( var i=0; i<itemIdArr.length; i++) {
		    //Create the <Item> node
		    var newItemNode = objXmlDoc.CreateElement("Item", itemValueArr[i], new Array("Id"), new Array(itemIdArr[i]))
            //Append the <Item> node to the <Value> node. Now, it looks like this. 
            //   <Value><Item id="xxx">Blah</Item></Value>
            newValueNode.appendChild(newItemNode)
		}
    }
} 

// Determines if data exists for an xml node
function DoesDataExistForThisXmlNode(xmlDoc, xmlNodeName) {
    //TODO!  NOT CROSSBROWSER COMPLIANT!!
    var dataIsFound = false    
    tempNode = xmlDoc.selectSingleNode("//" + xmlNodeName);        
    var	control = GetFieldObjectAndLoadData(xmlNodeName, tempNode)     
     if (control.IsEmpty() == false) {
     	dataIsFound = true
     }
//     switch (GetControlType(xmlNodeName)) {
//           case "FromTo":
//                control = new FromToControlxx(tempNode)
//                if (control.fromValue != "" || control.toValue != "" || control.duration != "" || control.total != "") { 
//                    dataIsFound = true 
//                }
//                break;
//            default:
//            //throw ("Error: UpdateSearchSummary: " + xmlNodeName + " not found"));
//           alert("DoesDataExistForThisXmlNode: ft attribute not found: " + GetControlType(xmlNodeName))
//            break;    
//         }    
     return dataIsFound
}

// Populate an array object with the values of the children.
function populateArrayWithChildNodes(oNode) {
    var returnArray = new Array
    if (oNode.hasChildNodes) {
        //var valueNodes = oNode.childNodes
        for (var i = 0; i < oNode.childNodes.length; i++) {
            // IE Specific logic since it doesn't know what .textContent is
        	if (document.all) {
        		returnArray.push(oNode.childNodes[i].text)
        	}
        	// Logic for everything else
        	else
        		if (oNode.childNodes[i].textContent.replace(/^\s+|\s+$/g, "").length > 1) {
        		returnArray.push(oNode.childNodes[i].textContent)
        	}
        }
        return returnArray;
    }
}

//Adds children nodes based on an array 
function populateChildNodesWithArray(xmlDoc, arrWithValues, nameOfNodeWithValue, xpathOfParent) {
    //TODO!  NOT CROSSBROSWER COMPLIANT!!
    for (var i=0; i < arrWithValues.length; i++) {
      AppendXmlNode(xmlDoc, xpathOfParent, nameOfNodeWithValue, arrWithValues[i])
    }
}
function IsValueNodeExist(xmlDoc, xPath, value) {
    var node = xmlDoc.SelectFirstNode("/Search/"+xPath+"/Value[.='" + value + "']")
    if (node == null) {
        return false
    } else {
        return true
    }
   }

function getNodeTextValue(node) {
	var returnStr = "";
   	if (!window.DOMParser) {
   		//The ie way
   		if (node != null) {
   			returnStr = node.context.text;
   		}
   	} else {
   		//The W3C way
   		if (node[0]) {
   			returnStr = node[0].textContent;
   		}
   	}
   	return returnStr
}    
