function FastXML (commander, ajaxParent) {
this.commander=commander;
this.ajaxParent=ajaxParent; //facultatif
this.watchBaliseList=[];

this.startAnalyzeThisXml=function (xml) {
	this.xml=xml;
	this.dig(0,this.xml);
	if (this.commander['onAnalyzedDone']) this.commander['onAnalyzedDone'](this.ajaxParent);
}

this.dig = function (prof, xmlContenu) {
	for( var i=0; i<xmlContenu.childNodes.length; i++) {
		var ref=xmlContenu.childNodes[i];
		if (ref.nodeType==1)
		{
			this.shallWeSendEventStart(ref);
			this.dig(prof+1,ref);
			this.shallWeSendEventEnd(ref);
		}
	}
}

this.shallWeSendEventStart =function (ref) {
	var bal=ref.nodeName.toLowerCase();
	if (this.findBal(bal) >-1 && this.commander['onBalise_'+bal]) this.commander['onBalise_'+bal](ref);
}
this.shallWeSendEventEnd =function (ref) {
	var bal=ref.nodeName.toLowerCase();
	if (this.findBal(bal) >-1 && this.commander['onBaliseEnd_'+bal]) this.commander['onBaliseEnd_'+bal](ref);			
}
this.addWatchBalise=function (bal) {
	bal=bal.toLowerCase();
	if (this.findBal(bal)==-1) this.watchBaliseList.push(bal);
}

this.findBal=function (bal) {
	for (var i=0; i<this.watchBaliseList.length; i++)
		if (this.watchBaliseList[i]==bal) return i;
	return -1;
}

}


function FastAjax (url, commander) {

	this.url=url;
	this.commander=commander;
	this.ajaxEnabled=false;
	this.xmlRequest=null;
	this.fastXML=new FastXML(commander,this);

	this.init=function () {
		this.xmlRequest = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Msxml2.XMLHTTP");
		if (this.xmlRequest == null) return;
		this.ajaxEnabled=true;

		this.xmlRequest.open("POST", this.url, true);

		
//		this.xmlRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;  charset=utf-8;");
		this.xmlRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
		//this.xmlRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); 

		var me=this;
		this.xmlRequest.onreadystatechange = function(){ me.handleAjaxResponse();};
		
	}

	this.send=function (s) {
		this.init();
		if(!this.ajaxEnabled) {
			alert ("Votre navigateur ne prend pas en compte Ajax. Cette application ne peut pas fonctionner."); 
			return;
		}

		this.xmlRequest.send(s);
	}


	this.handleAjaxResponse=function (){
		if (this.xmlRequest.readyState === 4 ) {
			if (this.xmlRequest.status==200) this.processResponse();
			else alert ("erreur Ajax ("+this.xmlRequest.status +")");
		}
	}

	this.processResponse=function () {
		this.fastXML.startAnalyzeThisXml(this.xmlRequest.responseXML);
	}


	this.addWatchBalise=function (bal) { 
		this.fastXML.addWatchBalise(bal);
	}

	// this.init();
}

/*
//usage

var commander=new Object();
var a=new FastAjax('http://localhost/cinecineblog2/php/a.php', commander);
a.send(null);
a.addWatchBalise('b');

commander.onBalise_b=function (ref) {
alert ('start '+ref.firstChild.nodeValue);
}
commander.onBaliseEnd_b=function (ref) {
alert ('fin '+ref.firstChild.nodeValue);
}

commander.onAnalyzedDone=function () {
alert ('fin');
}

*/