/* -------------------------------------------------------------- */
// document xml
var htmldoc;

/* -------------------------------------------------------------- */
// gestion htmldoc
var htmlobj = function(dest_id, after_onload) {
	var doc = false;
	if (window.ActiveXObject)
		doc = new ActiveXObject("Microsoft.XMLHTTP");
	else if (XMLHttpRequest)
		doc = new XMLHttpRequest();

 	if (doc) {
		doc.onreadystatechange = function () {
			if (doc.readyState == 4)
				htmlobj_onload(doc, dest_id, after_onload);
		};
 	}
	return doc;
};

// chargement des données html
var load_htmldoc = function(htmlfile, data, dest_id, after_onload) {
	if (htmldoc = htmlobj(dest_id, after_onload)) {
		// début de chargement -> voir waitwhileloading.js()
		if (show_waitwhileloading) show_waitwhileloading();
		htmldoc.open("GET", htmlfile, true);
		htmldoc.send(null);
	}
	else {
		alert("Erreur de chargement des données HTML");
	}
};

var htmlobj_onload = function(doc, dest_id, after_onload) {
	// extraction javascript
	var tag_start = "<script>";
	var start = doc.responseText.indexOf(tag_start);
	
	if (start >= 0) {
		// mise à jour de la destination
		getById(dest_id).innerHTML = doc.responseText.substr(0, start);

		// tag de fin
		var tag_end = "</script>";
		var end = doc.responseText.indexOf(tag_end);

		if (end >= 0) {
			// début du script
			start += tag_start.length;
			
			// fin de script
			end -= start;

			// évaluation de chaque ligne javascript
			var command = doc.responseText.substr(start, end);
			command = command.split(";");
			for (line = 0; line < command.length; line++) eval(command[line] + ";");
		}
	}
	else {
		// pas de script
		getById(dest_id).innerHTML = doc.responseText;	
	}
	
	// action quand chargé
	if (after_onload) after_onload();

	// fin de chargement -> voir waitwhileloading.js()
	if (hide_waitwhileloading) hide_waitwhileloading();
};
