
function set_liens_actifs() {
    var current_file_name = location.pathname.split('/').pop();
    var toc_file_name = check_recurse_list(
            document.getElementById('nav_toc'), 
            "navigation_lien_actif", current_file_name, false, false);
    var nav_file_name = check_recurse_list(
            document.getElementById('nav_header'), 
            "actif", current_file_name, toc_file_name, true);
}
function check_recurse_list(list_obj, css_class, current_file_name, top_file_name, either) {
    var list_items = list_obj.getElementsByTagName('li');
    for (var i = 0; i < list_items.length; i++) {
        var li = list_items[i];
        var children = li.childNodes;
        for (var j = 0; j < children.length; j++) {
            var child = children[j];
            if (child.nodeName == 'A') {
                var a_file_name = child.getAttribute('href').split('/').pop();
                if ((a_file_name==current_file_name)||((either)&&(a_file_name==top_file_name))) {
                    // hack, as application/ ends with ""
                    if (!((a_file_name=='')&&(css_class=='navigation_lien_actif'))) {
                        child.setAttribute("class", css_class);
                        child.setAttribute("className", css_class);
                        return a_file_name;
                    }
                }
            } 
            else if (child.nodeName == 'UL') {
                var file_name = check_recurse_list(child, css_class, current_file_name, a_file_name, either);
                if (file_name) {
                    return a_file_name;
                }
            }
        }
    }
    return false; 
}

function popup(lien, largeur, hauteur) {
	window.open(lien, 'Image',
		'location=no,toolbar=no,directories=no,menubar=no,status=no,resizable,scrollbars=yes,screenY=100,screenX=100,width='+largeur+',height='+hauteur);
}

function popup_image(lien, largeur, hauteur) {
	window.open(lien, 'Image',
		'location=no,toolbar=no,directories=no,menubar=no,status=no,screenY=100,screenX=100,width='+largeur+',height='+hauteur);
}

function externalLinks() { 
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") &&
			anchor.getAttribute("rel") == "external") {
			anchor.target = "_blank";
			anchor.className = anchor.className + " relexternal";
		}
	}
}

function LTrim(str) {
   var whitespace = new String(" \t\n\r.");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(0)) != -1) {
      // We have a string with leading blank(s)...
      var j=0, i = s.length;
      // Iterate from the far left of string until we
      // don't have any more whitespace...
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;
      // Get the substring from the first non-whitespace
      // character to the end of the string...
      s = s.substring(j, i);
   }
   return s;
}

function RTrim(str) {
   var whitespace = new String(" \t\n\r.");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      // We have a string with trailing blank(s)...
      var i = s.length - 1;       // Get length of string
      // Iterate from the far right of string until we
      // don't have any more whitespace...
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;
      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
   }
   return s;
}

function Trim(str) {
   return RTrim(LTrim(str));
}

function FormatNumber(num, decimalNum, bolLeadingZero, bolParens, bolCommas) {

	if (isNaN(parseInt(num))) return "NaN";

	var tmpNum = num;
	var iSign = num < 0 ? -1 : 1;
	
	// Adjust number so only the specified number of numbers after
	// the decimal point are shown.
	tmpNum *= Math.pow(10,decimalNum);
	tmpNum = Math.round(Math.abs(tmpNum))
	tmpNum /= Math.pow(10,decimalNum);
	tmpNum *= iSign;
	
	// Create a string object to do our formatting on
	var tmpNumStr = new String(tmpNum);

	// See if we need to strip out the leading zero or not.
	if (!bolLeadingZero && num < 1 && num > -1 && num != 0)
		if (num > 0)
			tmpNumStr = tmpNumStr.substring(1,tmpNumStr.length);
		else
			tmpNumStr = "-" + tmpNumStr.substring(2,tmpNumStr.length);
		
	// See if we need to put in the commas
	if (bolCommas && (num >= 1000 || num <= -1000)) {
		var iStart = tmpNumStr.indexOf(".");
		if (iStart < 0)
			iStart = tmpNumStr.length;

		iStart -= 3;
		while (iStart >= 1) {
			tmpNumStr = tmpNumStr.substring(0,iStart) + "," + tmpNumStr.substring(iStart,tmpNumStr.length)
			iStart -= 3;
		}		
	}

	// See if we need to use parenthesis
	if (bolParens && num < 0)
		tmpNumStr = "(" + tmpNumStr.substring(1,tmpNumStr.length) + ")";

	return tmpNumStr;
}

function TestRegExp(re, str)
{
	if (re.test(str))
		return true;
	else
		return false;
}

function affichecache(id, nb) {	
	if (id == 'toutes') {
		var wLoc = window.location.toString();
		var wLocS = wLoc.split("#");
		for (i = 1; i <= nb; i++) {
			if ("switch"+i != wLocS[1]) {				
				affichecache(i, nb);
			}
		}
		return(false);
	} else {
		element = document.getElementById("switch"+id);
		if (element.style.display != 'none') {
			element.style.display = 'none';
		} else {
			element.style.display = 'block';
		}
		return(false);
	}
}

function affiche(id) {	
	element = document.getElementById("switch"+id);
	if (element.style.display != 'block') {
		affichecache(id);
	}
	return(false);
	
}

window.onload = externalLinks; 

