//<Script language="Javascript">
var idxParentObj = 0;
/*
	Fonction showProps
	v1.0 - Pierric PERMEZEL   03/06/02
	
	Affiche dans une fenêtre les propriétés d'un objet Javascript et permet de naviguer au sein de celles-ci.
	
	Syntaxe :
		showProps(objetAInspecter, [nom d'affichage], [fenêtre d'affichage]);	
*/
function showProps(object, name, w) {

    if (!name)
        name="sansNom";

	if (!w)
	{
		w = window.open("about:blank","debugp","dependent=yes,directories=no,height=400,width=600,location=no,menubar=no,personalbar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no");
	}

	var oname;
	var i=0;
	var tmp = "";
	tmp += "<html><head><title>Objet "+name+"</title></head><body>";
	tmp += "<H1>Objet "+name+"</H1>";
	tmp += "<a href=\"javascript:window.opener.idxParentObj-=1;window.opener.showProps(window.opener.parentObj"+(idxParentObj+1)+", window.opener.parentName"+(idxParentObj+1)+", window)\">";
	tmp += "actualiser";
	tmp += "</a>";

	if (idxParentObj > 0)
	{
		tmp += "&nbsp;&nbsp;|&nbsp;&nbsp;<a href=\"javascript:window.opener.idxParentObj-=2;window.opener.showProps(window.opener.parentObj"+idxParentObj+", window.opener.parentName"+idxParentObj+", window)\">";
		tmp += "Retour à l'objet père (";
		tmp += eval("window.parentName"+idxParentObj);
		tmp += ")</a>";
	}
	
	tmp += "<hr>";
	
	idxParentObj++;
	eval("window.parentObj"+idxParentObj+" = object;");
	eval("window.parentName"+idxParentObj+" = name;");	
	
	tmp += "<table border=1>";
	for (var prop in object)
	{			
		tmp += "<tr><td><b>";
		tmp += prop;
		tmp+= "</b></td><td>";
		if ((typeof(object[prop])=="object") && (object[prop]!=null))
		{
			eval("window.dobj"+i+"=object[prop];");
			tmp += "<a href=\"javascript:window.opener.showProps(window.opener.dobj"+i+", '"+name+"."+prop+"',window)\">";
			tmp += object[prop];
			tmp += "</a>";
		}
		else
			tmp += object[prop];

		tmp += "</td><td><i>"+typeof(object[prop])+"</i>";
		tmp += "</td></tr>";
		i++;
	}
	tmp += "</table>";
	tmp += "</body></html>";
	
	w.document.clear();
	w.document.open();
	w.document.write(tmp);
	w.document.close();
	w.focus();
}



function getObjectProps(object, objName, showNullOrEmpty) {
    if (!objName)
        objName="?";
    var val, val2;
	var tmp = "INSPECTION DE : "+objName+" (type="+typeof(object)+")\n\n";
	if (typeof(object)!="undefined")
	{
	    if (object==null)
	        tmp += "null";
	    else {
			var props = new Array();
			var i=0;
			for (var prop in object)
				props[i++] = prop;

			Quicksort(props);
	    
			var prop;
        	for (i=0; i<props.length; i++) {			
        		prop = props[i];

        	    if (prop=="innerHTML" || prop=="innerText" || prop=="outerHTML" || prop=="outerText")
        	        val = "(masque)";
        	    else
        	        val = object[prop];        	     

        	    if (!showNullOrEmpty) {
        			val2 = val+"";
        			
        			if (val2=="" || (val==null && val2=="null"))
        				continue;        	    
        	    }
    		    tmp += prop + " = " + val + "\n";
    		 }
		}
	}
	return tmp;
}


function liteShowProps(object, objName, showNullOrEmpty) {
	alert(getObjectProps(object, objName, showNullOrEmpty));
}


function traceShowProps(object, objName, showNullOrEmpty, color) {
	trace(getObjectProps(object, objName, showNullOrEmpty), color);
}



function Quicksort(vec, loBound, hiBound)
/**************************************************************
	This function adapted from the algorithm given in:
		Data Abstractions & Structures Using C++, by
		Mark Headington and David Riley, pg. 586.

	Quicksort is the fastest array sorting routine for
	unordered arrays.  Its big O is n log n.
 **************************************************************/
{
	if (vec==null || vec.length==0)
		return;

	if (typeof(loBound)=="undefined")
		loBound = 0;

	if (typeof(hiBound)=="undefined")
		hiBound = vec.length-1;

	if (loBound<0 || hiBound>vec.length)
		return;

		

	var pivot, loSwap, hiSwap, temp;

	// Two items to sort
	if (hiBound - loBound == 1)
	{
		if (vec[loBound] > vec[hiBound])
		{
			temp = vec[loBound];
			vec[loBound] = vec[hiBound];
			vec[hiBound] = temp;
		}
		return;
	}

	// Three or more items to sort
	pivot = vec[parseInt((loBound + hiBound) / 2)];
	vec[parseInt((loBound + hiBound) / 2)] = vec[loBound];
	vec[loBound] = pivot;
	loSwap = loBound + 1;
	hiSwap = hiBound;

	do {
		// Find the right loSwap
		while (loSwap <= hiSwap && vec[loSwap] <= pivot)
			loSwap++;

		// Find the right hiSwap
		while (vec[hiSwap] > pivot)
			hiSwap--;

		// Swap values if loSwap is less than hiSwap
		if (loSwap < hiSwap)
		{
			temp = vec[loSwap];
			vec[loSwap] = vec[hiSwap];
			vec[hiSwap] = temp;
		}
	} while (loSwap < hiSwap);

	vec[loBound] = vec[hiSwap];
	vec[hiSwap] = pivot;


	// Recursively call function...  the beauty of quicksort

	// 2 or more items in first section		
	if (loBound < hiSwap - 1)
		Quicksort(vec, loBound, hiSwap - 1);


	// 2 or more items in second section
	if (hiSwap + 1 < hiBound)
		Quicksort(vec, hiSwap + 1, hiBound);
}
