var DEBUG_FLAG = 1;
/*
debugAlert() - utility function for displaying js alerts when the DEBUG_FLAG is on
*/
function debugAlert(str)
{
	if(DEBUG_FLAG)
		alert(str);
}

/*
getXMLDocument() - attempts to return xml document object from a XMLHttpRequest
*/
function getXMLDocument(req)
{
	var xmlDoc;

	if(!req) {
		debugAlert("No XMLHttpRequest object found in getXMLDocument()");
		return false;
	}

	if(!req.responseXML) {
		debugAlert("No responseXML property found in getXMLDocument()");
		return false;
	}
	if(req.responseXML.documentElement)
	{ // firefox
		xmlDoc = req.responseXML.documentElement;
	}
	else
	{ // IE
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async="false";
/*
		xmlDoc.appendChild(xmlDoc.createElement('root'));
		var foo = xmlDoc.createElement('foo');
		foo.appendChild(xmlDoc.createTextNode('bar'));
		xmlDoc.documentElement.appendChild(foo);
*/
		xmlDoc.loadXML(req.responseText);
	}

	return xmlDoc;
}

/*
getNodeValueByTagName() attempts to obtain a value within a tag such as <tag>value</tag>,
if tag is not found or if there is no value, this function returns false
*/
function getNodeValueByTagName(xmlDoc, tag)
{
	if(!xmlDoc) {
		debugAlert("No valid xmlDoc object found in getNodeValueByTagName()");
		return false;
	}

	var node = xmlDoc.getElementsByTagName(tag);

	if(node && node.length > 0) {
		return node[0].firstChild ? node[0].firstChild.nodeValue : '';
	}

	return false;
}

function jsEscapeSingleQuote(str)
{
	return str.replace("'", "\'");
}