/**
 *
 * =======================================
 * 2exVia - 14/09/2007 00:23:34
 * Surbrillance v0.1
 * ======================================= 
 * Nécessite:
 * 	- sprintf();
 *  - surbrillance(sRecherche, sRemplace); 
 *  - addLoadEvent(func);   
 *  
 *  
 * Function: sprintf
 * 
 * Parameters:
 *  - Array arguments, ou [0] = la chaine, [1], [2], etc les "%s"
 *
 * Exemple : sprintf("Il est {0} heure {1} minutes", "0", "et 20")
 */  
sprintf = function() { 
	var nArgs = arguments.length; 
	var sRetour = arguments[0];   
	for (var i = 1; i < nArgs; i++) { 
		var sReg = "\\{" + (i-1) + "\\}"; 
    	var reg = new RegExp(sReg, "g"); 
		sRetour = sRetour.replace(reg, arguments[i]);
 	} 
	return sRetour; 
}  
/**
 * Function: surbrillance
 *
 * Parameters:
 * 	- String sRecherche, la chaîne recerchée
 * 	- String sStyle, la chaîne de substitution
 * 	  
 * Exemple : surbrillance("mot recherché", "background:yellow;"); 
 */ 
surbrillance = function(sRecherche, sStyle) {
	if (document.body.innerHTML) {
		var sReg = "(>[^<>]*)("+sRecherche+")";
		//var sReg = "([^<]"+sRecherche+"[.+^>])";
		var reg = new RegExp(sReg, "gi");
		var sTampon = document.body.innerHTML;
		var sSortie = sTampon.replace(reg, "$1<span style=\""+sStyle+"\">$2</span>");
		document.body.innerHTML = sSortie;
		return true;
	} else {
		// Non supporté
		return false;
	}
}
/**
 * Function: addLoadEvent
 *  (simonwillison)
 *  
 * Parameters:
 * 	- Function func, la fonction a empiler dans le gestionnaire onload
 */  
addLoadEvent = function(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}
