var ovXMLspool = new Array();
function ovXMLobj( id, url, caller ) {
	this.id = id;
	this.url = url;
	this.caller = caller;
	this.state = 0;
  if (window.XMLHttpRequest) {
    this.xmlObj = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
    this.xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
	}
	this.init();
}

ovXMLobj.prototype = {
	init : function()	{
	  this.xmlObj.onreadystatechange = ovXMLevent;
    this.xmlObj.open("GET", this.url, true);
    this.xmlObj.send(null);
	},

	checkEvent : function()	{
		var i;
		if( this.xmlObj.readyState != this.state ) {
			this.state = this.xmlObj.readyState;
			if( this.state == 4 ) {
				if( this.xmlObj.status == 200 ) {
					this.xmlData = this.xmlObj.responseXML
					this.log = "";
					this.xml = this.parseXML( this.xmlData.documentElement, 0 );
					if( typeof( this.xml.data ) == "undefined" ) {
						alert("XML Communication ERROR: can't parse "+this.url+"\n\n"+this.xmlObj.responseText);
					} else
						this.caller.data(this.xml.data);
					
				} else {
					alert("XML Communication Error");
				}
			}
		}
	},

	parseXML : function( node, ebene ) {
		var hash = new Array();
		var hashed = new Array();
		var i,daten,cnode,cnodeold,spacer="",newline="\n";
		for( i=0; i<node.childNodes.length; i++ ) {
			var cnode = node.childNodes[i];
			var cname = cnode.nodeName;
			if( cname.substr(0,1) == "#" )
				continue;

			// Knoten oder Daten?
			if( cnode.childNodes.length > 1 )
				daten = this.parseXML(cnode,ebene+1);
			else
				daten = cnode.childNodes[0].data;

			if( hashed[cname] == 1 ) {
				hash[cname] = new Array( hash[cname] );
				hash[cname][1] = daten;;
				hashed[cname] = 2;
			} else if( hashed[cname] == 2 ) {
				hash[cname][hash[cname].length] = daten;
			} else {
				hashed[cname] = 1;
				hash[cname] = daten;
			}
		}
		return hash;
	}
}

function ovXMLevent() {
	var i;
	for ( i=0; i<ovXMLspool.length; i++ )
		ovXMLspool[i].checkEvent();
}

function ovXML(url,caller) {
	ovXMLspool[ovXMLspool.length] = new ovXMLobj( ovXMLspool.length, url, caller );
}
