// private - user XmlScripts.inc
// for NN6 and other non-IE

function parseXmlImpl(s)
{
	var originalS = s;
	var xml = createElement(s);

	if ((s.charAt(s.indexOf(">") + 1) == "<"))// hasChildren
	{
		var children = separateChildren(s);
		for(var i=0; i<children.length; i++)
		{
			xml.add( parseXmlImpl(children[i]) );
		}
	}

	return xml;
}

function separateChildren(s)
{
	var children = new Array();
	s = s.substring(s.indexOf(">") + 1, s.lastIndexOf("<"));

	while(s)
	{
      var count = 0;
      var done = false;
      var curPos = 0;

      while(!done)
      {
      	if (s.charAt(curPos)=="<")
      	{
      		count++;
            var countChanged = true;
         }
         else if ((s.charAt(curPos)=="/")  && (s.charAt(curPos-1) == "<"))
         {
            count-=2;
         }

      	if (count==0 && countChanged)
         {
            done = true;
            curPos = s.indexOf(">",curPos);
         }

         curPos++;
      }

      child = s.substring(0,curPos);
      children[children.length] = child;
      s = s.substring(child.length, s.length);
   }

   return children;
}

function createElement(s)
{
	element = new XmlElement();
	var start = s.indexOf("<");
	var end;

	if((s.indexOf(" ") != -1) && (s.indexOf(" ") < s.indexOf(">")))
	{
		var ha = true;
		end = s.indexOf(" ");
	}
	else
	{
		end = s.indexOf(">");
	}

	element.name = s.substring(start+1, end);

	if (ha)
	{
		var attribString = s.substring(s.indexOf(" ") + 1,s.indexOf(">") - 1);
		var attribs = attribString.split("' ");
		for(var i=0; i<attribs.length; i++)
		{
			var thisAttrib = attribs[i].split("='");
			element.addAttribute(thisAttrib[0],thisAttrib[1]);
		}
	}

   // set text
	start = s.indexOf(">");
   end = s.indexOf("<",start);
	if(s.charAt(start+1) != "<")
		element.text = s.substring(start+1,end);
	else
      element.text = "";

	return element;
}