/* -------------------------------------------------------------- */
// xmlobj_onload = action à la fin du chargement des données -> voir popup_xml.js
/* -------------------------------------------------------------- */

// gestion xmldoc
var xmlobj = function() {
	var doc = false;
	if (document.implementation && document.implementation.createDocument)	{

// VERSION SF ou OP
		if (nav.safari || nav.opera) {
			doc = document.implementation.createDocument("", "", null);
			doc.async = false;
			XMLDocument.prototype.load = function(xmlfile)	{
			
				var xmlhttp = new XMLHttpRequest();
				xmlhttp.overrideMimeType('text/xml');
				xmlhttp.onreadystatechange = function () {
					if (xmlhttp.readyState == 4) {
						
						xmldoc = xmlhttp.responseXML;
						if (xmldoc)
							xmlobj_onload();
						else
							alert("Erreur de chargement des données XML");
					}				
				};

				xmlhttp.open("GET", xmlfile, false);
				xmlhttp.setRequestHeader("Content-Type", "text/xml");
				xmlhttp.send(null);
			};
		}

// VERSION FF par défaut
		else {
			doc = document.implementation.createDocument("", "", null);
			doc.async = false;
			doc.onload = xmlobj_onload;
		}
	}

// VERSION IE
	else if (window.ActiveXObject) {
		doc = new ActiveXObject("Microsoft.XMLDOM");
		doc.async = false;
		doc.onreadystatechange = function () {
			if (doc.readyState == 4) xmlobj_onload();
		};
 	}

// GESTION ERREUR
	else {
		alert("Votre navigateur n'implémente pas XML");
	}

	return doc;
};

/* -------------------------------------------------------------- */
// tableau des valeurs des noeuds enfants du noeud xml
var xmlnodeChildrenValue = function(xmlnode) {
	var rec = new Array();
	try {
// VERSION SF ou OP
		if (nav.safari || nav.opera) {
			// SF : élimination des lignes supplémentaires
		    var cpt = 0;
		    for (var n in xmlnode) {
				var node = xmlnode[n];
		        if (node.nodeType == 1) {
		            rec[cpt] = node.textContent;
		            cpt++;
		        }
		    }
	}	

// VERSION IE
		else if (nav.explorer) {
		    // IE : pas de lignes supplémentaires
		    for (cpt = 0; cpt < xmlnode.length; cpt++) {
				rec[cpt] = xmlnode[cpt].text;
			}
		}

// VERSION FF par défaut
	    else {
	        // FF : élimination des lignes supplémentaires
	        var cpt = 0;
	        for (var n in xmlnode) {
				var node = xmlnode[n];
	            if (node.firstChild) {
	                rec[cpt] = node.firstChild.nodeValue;
	                cpt++;
	            }
	        }
	    }
	} catch(e){alert(BrowserDetect.browser + " : erreur de lecture des noeuds enfants\n" + e)}

	// tableau des valeurs
	return rec;
};
