typeTagAttr = function()
{
	this.Name = "";
	this.Data = "";	
};
sXMLTag = function()//sXMLTag structure
{
	this.ID=0;
	this.ParentNodeID = 0;
	this.Level=0;
	this.Name="";
	this.Data="";
	this.Attributes= new Array();
	this.Children = new Array();
	
	this.getAttribute = function(AttName)
	{
		for (j = 0; j < this.Attributes.length; j++)
		{
			if (this.Attributes[j].Name == AttName)
				return this.Attributes[j].Data;								
		}
		return "";		
	}
};

xmlHandler = function()
{
    this.m_strError='';
    this.m_treePath=[];
    this.m_xPath=['']; // stores current path info
    this.m_text=[''];
    this.m_cdata=[''];
    this.m_attr=[''];
    this.m_pi=[''];
    this.cdata=false;
	this.m_inNode=false;
	this.m_curLevel = 0;
	this.m_curNodeID = 0;
	this.m_Nodes = new Array();
	
	this.m_curNode;
	this.m_curNode = new sXMLTag();
	this.m_curNodeNdx = -1;
	this.m_XMLBuf = "";
	this.m_tagList = new Array();
}; // end function xmlHandler

xmlHandler.prototype.initialize = function()
{
    this.m_strError='';
    this.m_treePath=[];
    this.m_xPath=['']; // stores current path info
    this.m_text=[''];
    this.m_cdata=[''];
    this.m_attr=[''];
    this.m_pi=[''];
    this.cdata=false;
	this.m_inNode=false;
	this.m_curLevel = 0;
	this.m_curNodeID = 0;
	
	this.m_curNode = -1;
	this.m_curNodeNdx = -1;
	this.m_XMLBuf = "";
	
	len = this.m_Nodes.length; 
	this.m_Nodes.splice(0, len);
	len = this.m_tagList.length;
	this.m_tagList.splice(0, len);
};
xmlHandler.prototype.createNewXML = function()
{
	len = this.m_Nodes.length; 
	this.m_Nodes.splice(0, len);
	len = this.m_tagList.length;
	this.m_tagList.splice(0, len);
	this.m_XMLBuf = "<?xml version='1.0'?>";
};

xmlHandler.prototype.putTag = function(name, data, attribs)
{
	attList = "";
	if (attribs)
	{
		for (yy=0; yy < attribs.length; yy++)
			attList += " " + attribs;
	}		
	newEntry = "";
	newEntry = "<" + name + attList + ">" + data + "</" + name + ">";
	this.m_XMLBuf += newEntry;
};
xmlHandler.prototype.openTag = function(name, attribs)
{
	this.m_tagList.push(name);
	attList = "";
	if (attribs)
	{	
		for (yy=0; yy < attribs.length; yy++)
			attList += " " + attribs[yy];
	}
			
	newEntry = "";
	newEntry = "<" + name + attList + ">";
//	alert (newEntry);
	this.m_XMLBuf += newEntry;
};
xmlHandler.prototype.closeTag = function()
{
	len = this.m_tagList.length; 
	name = this.m_tagList[len-1];
	this.m_tagList.splice(len-1, 1);
	newEntry = "";
	newEntry = "</" + name + ">";
	this.m_XMLBuf += newEntry;
};
xmlHandler.prototype.getBuffer = function()
{
	return this.m_XMLBuf;	
};
//getLeafCount will return the number of child nodes that "nodeNdx" has
xmlHandler.prototype.getLeafCount = function(nodeNdx)
{
	count = 0;
	for (xyy = 0; xyy < this.m_Nodes.length; xyy++)
		if (this.m_Nodes[xyy].ParentNodeID == this.m_Nodes[nodeNdx].ID)
			count++;
	return count;
};
//getLeafNode will return the index of the leaf node, not the actual node.
//a -1 is returned on failure
xmlHandler.prototype.getLeafNode = function(nodeNdx, ndx)
{
	count = -1;
	for (xyy = 0; xyy < this.m_Nodes.length; xyy++)
	{
		if (this.m_Nodes[xyy].ParentNodeID == this.m_Nodes[nodeNdx].ID)
			count += 1;
		if (count == ndx)
			return xyy; 
	}
	return -1;
};
//getLeafNode will return the index of the child node of "nodeNdx" width the given "childName"
//a -1 is returned on failure
xmlHandler.prototype.getChildTag= function(nodeNdx, childName)
{
	for (tyi = 0; tyi < this.m_Nodes.length; tyi++)
	{
		if (this.m_Nodes[tyi].ParentNodeID == this.m_Nodes[nodeNdx].ID &&
			this.m_Nodes[tyi].Name == childName)
			return tyi; 
	}
	return -1;
};
xmlHandler.prototype.resetCurrentNode = function()
{
	this.m_curNodeNdx = 0;
};
xmlHandler.prototype.getCurrentTag = function()
{
	return this.m_curNodeNdx;
};
xmlHandler.prototype.startElement = function(name, atts)
{
	this.m_inNode=true;
	this.m_curNodeID += 1;
	this.m_curLevel += 1;
	
	Node = new sXMLTag();
	Node.ID = this.m_curNodeID;
	Node.Level = this.m_curLevel;
	Node.Name = name;
	
	if (this.m_tagList.length > 0)
		Node.ParentNodeID = this.m_tagList[this.m_tagList.length-1];
	else
		Node.ParentNodeID = 0;
	this.m_Nodes.push(Node);
	this.m_curNodeNdx = this.m_Nodes.length-1;
	this.m_tagList.push(this.m_curNodeID);
		
	att_count=atts.getLength();
    for (i=0;i<att_count;i++)
	{
		Att = new typeTagAttr();
		Att.Name = atts.getName(i);
		Att.Data = atts.getValue(i);
        this.m_Nodes[this.m_curNodeNdx].Attributes.push(Att);
	}
};
xmlHandler.prototype.characters = function(data, start, length)
{
	text=data.substr(start, length);

	if (this.m_curNodeNdx >= 0 && this.m_curNodeNdx < this.m_Nodes.length)
	{
		if (this.m_Nodes[this.m_curNodeNdx].Data == "")
			this.m_Nodes[this.m_curNodeNdx].Data = text;
	}
};
xmlHandler.prototype.endElement = function(name)
{
	this.m_tagList.splice(this.m_tagList.length-1, 1);
	this.m_inNode=false;
	this.m_curLevel -= 1;	
};


xmlHandler.prototype.comment = function(data, start, length) {
    var comment=data.substr(start, length)
}; // end function comment


xmlHandler.prototype.endCDATA = function() {
    // end of CDATA entity
    this.cdata=false

}; // end function endCDATA

xmlHandler.prototype.endDocument = function()
{
}; // end function end Document

xmlHandler.prototype.error = function(exception) {
    this.m_strError+='Error:'+exception.getMessage()+'\n'

}; // end function error


xmlHandler.prototype.fatalError = function(exception) {
    this.m_strError+='fata error:'+exception.getMessage()+'\n'

}; // end function fatalError


xmlHandler.prototype.getAttr_Array= function() {
    return this.m_attr;

};   // end function getAttr_Array


xmlHandler.prototype.getCDATA_Array= function() {
    return this.m_cdata;

};  // end function getCDATA_Array


xmlHandler.prototype.getError = function() {
    return this.m_strError;

};  // end function getError


xmlHandler.prototype.getPath_Array = function() {
	return this.m_treePath;
};  // end function getPath_Array


xmlHandler.prototype.getText_Array = function() {
    return this.m_text;

}; // getTextArray


xmlHandler.prototype.processingInstruction = function(target, data) {
}; // end function processingInstruction


xmlHandler.prototype.setDocumentLocator = function(locator) {
    this.m_locator = locator;

};  // end function setDocumentLocator


xmlHandler.prototype.startCDATA = function() {
    this.cdata=true

}; // end function startCDATA


xmlHandler.prototype.startDocument = function() {
}; // end function startDocument

xmlHandler.prototype.warning = function(exception) {
    this.m_strError+='Warning:'+exception.getMessage()+'\n'

}; // end function warning
