function mondoXmlClientClass2()
{
	var Kommunikator;
	this.Kommunikator = Kommunikator;
	var OutFunction;
	this.OutFunction = OutFunction;
	var AttributeArray;
	this.AttributeArray = AttributeArray;
	var xmlType = 'ezobject';
	this.xmlType = xmlType;
	var ImageAliases = new Array();
	this.ImageAliases = ImageAliases;

    function processXmlResponse(xml)
    {
        var doc = this.getXmlHandler(xml);
		
        if( doc.hasChildNodes() )
        {
            var tabResult = Array();
            var allobjects = doc.getElementsByTagName('object');
            for(var o = 0; o < allobjects.length; o++)
            {
                tabResult[o] = Array();
                
                var title = allobjects[o].getElementsByTagName('title');
                tabResult[o]['title'] = title[0].firstChild.nodeValue;
                
                var url = allobjects[o].getElementsByTagName('url');
                tabResult[o]['url'] = url[0].firstChild.nodeValue;
                
                var section_id = allobjects[o].getElementsByTagName('section_id');
                tabResult[o]['section_id'] = section_id[0].firstChild.nodeValue;
    
                var node_id = allobjects[o].getElementsByTagName('node_id');
                tabResult[o]['node_id'] = node_id[0].firstChild.nodeValue;
    
                var parent_node_id = allobjects[o].getElementsByTagName('parent_node_id');
                tabResult[o]['parent_node_id'] = parent_node_id[0].firstChild.nodeValue;

                var short_date = allobjects[o].getElementsByTagName('shortdate');
                tabResult[o]['shortdate'] = short_date[0].firstChild.nodeValue;

                var year = allobjects[o].getElementsByTagName('year');
                tabResult[o]['year'] = year[0].firstChild.nodeValue;

				var attributes = allobjects[o].getElementsByTagName('attribute');
				tabResult[o]['attributes'] = Array();

				for(var at=0; at < attributes.length; at++)
				{
					if( exists( attributes[at].getElementsByTagName('value')[0] ) )
					{
						var key_temp = attributes[at].getElementsByTagName('name')[0].firstChild.nodeValue;
						var valuetemp = attributes[at].getElementsByTagName('value')[0].firstChild;
						
						if(valuetemp)
						{
							tabResult[o]['attributes'][key_temp] = Array();
							tabResult[o]['attributes'][key_temp]['type'] = attributes[at].getElementsByTagName('type')[0].firstChild.nodeValue;
							
							/*
							// TODO : GERER LE DATATYPE EN EXTERNE //
							*/
							
							// Si image :
							if( this.ImageAliases.length > 0 && tabResult[o]['attributes'][key_temp]['type'] == 'ezimage' )
							{
								var Alias = '';
								var nodetemp = attributes[at].getElementsByTagName('value');
								
								tabResult[o]['attributes'][key_temp]['value'] = new Array();
								
								for( var ia = 0; ia < this.ImageAliases.length; ia++ )
								{
									Alias = nodetemp[0].getElementsByTagName( this.ImageAliases[ia] );

									var width = Alias[0].getElementsByTagName('width')[0].firstChild;
									if( width != null )
									{
										width = width.nodeValue
									}
									else
									{
										tabResult[o]['attributes'][key_temp]['value'] = new Array();
										continue;
									}
									var height = Alias[0].getElementsByTagName('height')[0].firstChild;
									if( height != null )
									{
										height = height.nodeValue
									}
									var url = Alias[0].getElementsByTagName('url')[0].firstChild;
									if( url != null )
									{
										url = url.nodeValue
									}
									tabResult[o]['attributes'][key_temp]['value'][this.ImageAliases[ia]] = new Array(width, height, url);									
								}
							}
							// Si geocode
							else if( tabResult[o]['attributes'][key_temp]['type'] == 'ezgmaplocation' )
							{
								var gmapdoc = this.getXmlHandler(valuetemp.nodeValue);

								var gmap = gmapdoc.getElementsByTagName('ezgmaplocation');
								
								tabResult[o]['attributes'][key_temp]['value'] = new Array();
								
								for( var x = 0; x < gmapdoc.childNodes[0].attributes.length; x++ )
								{
									tabResult[o]['attributes'][key_temp]['value'].push(gmapdoc.childNodes[0].attributes[x].nodeValue);
								}
							}
							else
							{
								tabResult[o]['attributes'][key_temp]['value'] = valuetemp.nodeValue;
							}
						}
					}
				}
            }
			this.OutFunction(tabResult);
        }
        else
        {
        }
		return false;
    }
	this.processXmlResponse = processXmlResponse;
	
	function getXmlHandler(xml)
	{
		var doc = null;
        if (window.ActiveXObject)
        {
			doc = new ActiveXObject("Microsoft.XMLDOM");
            doc.async = 'false';
            doc.loadXML(xml);
        }
        else
        {
            var parser=new DOMParser();
            doc = parser.parseFromString(xml,"text/xml");
        }
		return doc;
	}
	this.getXmlHandler = getXmlHandler;

	function processXmlKeyword(xml)
    {
        var doc;
        if (window.ActiveXObject)
        {
			doc = new ActiveXObject("Microsoft.XMLDOM");
            doc.async = 'false';
            doc.loadXML(xml);
        }
        else
        {
            var parser=new DOMParser();
            doc = parser.parseFromString(xml,"text/xml");
        }
		
        if( doc.hasChildNodes() )
        {
            var tabResult = Array();
            var allobjects = doc.getElementsByTagName('object');
            for(var o = 0; o < allobjects.length; o++)
            {
                tabResult[o] = Array();
                
                var objtitle = allobjects[o].getElementsByTagName('name');
                tabResult[o]['name'] = objtitle[0].firstChild.nodeValue;
                
                var objclass = allobjects[o].getElementsByTagName('class');
                tabResult[o]['class'] = objclass[0].firstChild.nodeValue;
                
                var objurl = allobjects[o].getElementsByTagName('url');
                tabResult[o]['url'] = objurl[0].firstChild.nodeValue;
                
                var objsection_name = allobjects[o].getElementsByTagName('section_name');
                tabResult[o]['section_name'] = objsection_name[0].firstChild.nodeValue;
            }
			this.OutFunction(tabResult);
        }
        else
        {
        }
		return false;
    }
	this.processXmlKeyword = processXmlKeyword;

	function LoadResult( req, nextfunc, attributeArray )
	{
		this.Kommunikator = null;
		this.Kommunikator = getXMLHTTP();
		
		this.Kommunikator.onreadystatechange = function()
		{
			if( mondoXmlClient2.Kommunikator.readyState == 4 )
			{
				if( mondoXmlClient2.Kommunikator.status == 200 )
				{
					if( mondoXmlClient2.xmlType == 'ezobject' )
					{
						mondoXmlClient2.processXmlResponse( mondoXmlClient2.Kommunikator.responseText );
					}
					else if( mondoXmlClient2.xmlType == 'ezkeyword' )
					{						
						mondoXmlClient2.processXmlKeyword( mondoXmlClient2.Kommunikator.responseText );
					}
					else
					{
						this.OutFunction(tabResult);
					}
				}
				else 
				{
				}
			} 
		}; 
		if(typeof (attributeArray) != "undefined" && attributeArray != null )
		{
			this.AttributeArray	= attributeArray;
		}
		else
		{
			this.AttributeArray = new Array();	
		}
		this.OutFunction = nextfunc;
		this.Kommunikator.open("POST", req , true);
		this.Kommunikator.send(null);
	}
	this.LoadResult = LoadResult;
	
    function getXMLHTTP()
    {
		var xhr=null;
		if(window.XMLHttpRequest)
		{
			xhr = new XMLHttpRequest();
		}
		else if(window.ActiveXObject)
		{
			try
			{
				xhr = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e)
			{
				try
				{
					xhr = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e1)
				{
					xhr = null; 
					alert('Error creating xmlhttp');
				}
			}
		}
		else
		{
			alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
		}
		return xhr;
	}
	this.getXMLHTTP = getXMLHTTP;
}
var mondoXmlClient2 = new mondoXmlClientClass2();


function exists(input)
{
	if( typeof(input) != "undefined" && input != null )
	{
		return true;
	}	
	return false;
}
