/*
  Popup
  Arg url : Adresse du fichier popup
  Arg type : RC, AC, C (Relative center, Absolute center, Customized : CentrÚ par rapport Ó la fenÛtre, Ó l'Úcran, ou valeurs personnalisÚes)
  Arg target : nom de la fenÛtre
  Arg w : Largeur
  Arg h : Hauteur
  Arg x : Un nombre de coordonnÚes en cas de type=C
  Arg y : Un nombre de coordonnÚes en cas de type=C
*/
function Popup() {
  var args = Popup.arguments;
  var url = args[0];
  var type = args[1];
  var target = args[2];
  var w = args[3];
  var h = args[4];
  var params = args[5];
  switch (type) {
  case "RC" :
    var x = window.pageXOffset + (window.innerWidth-w)/2;
    var y = window.pageYOffset + (window.innerHeight-h)/2;
    window.open(url, target, "width="+w+",height="+h+",screenX="+x+",screenY="+y+params);
    break;
  case "AC" :
    var x = (screen.availWidth-w)/2;
    var y = (screen.availHeight-h)/2;
    window.open(url, target, "width="+w+",height="+h+",screenX="+x+",screenY="+y+params);
    break;
  case "C" :
    var x = args[5];
    var y = args[6];
    window.open(url, target, "width="+w+",height="+h+",screenX="+x+",screenY="+y+params);
    break;
  default :
    window.open(url, target);
    break;
  }

}
function CheckAllBoxes(form, liste_name) {
  var liste = form[liste_name];
	for (var i=0; i<liste.length; i++) {
		liste[i].checked = true;
	}
}
function UncheckAllBoxes(form, liste_name) {
  var liste = form[liste_name];
	for (var i=0; i<liste.length; i++) {
		liste[i].checked = false;
	}
}
function switch_display (identifier, status1, status2) {
	var cible = document.getElementById(identifier);	
	if (cible) {
    if (cible.style.display == status1) {
			cible.style.display = status2;
		} else {
			cible.style.display = status1;
 		}
  }
}
function set_form_value (form, field, type, param) {
  switch (type) {
  case "date" :
    var arr_date = param.split("-");
    var arr_liste = Array(form[field+"_annee"], form[field+"_mois"], form[field+"_jour"]);
    for (var i=0; i<arr_liste.length; i++) {
      var liste = arr_liste[i];
      for (var j=0; j<liste.length; j++) {
        if (liste.options[j].value == arr_date[i]) {
          liste.options[j].selected = true;
        } else {
          liste.options[j].selected = false;
        }
      }
    }
    break;
  case "text" :
    form[field].value = param;
    break;
  }
}
function add_to_favorites (phrase, url) {
  if (navigator.appName != 'Microsoft Internet Explorer') {
    window.sidebar.addPanel(phrase, url, "");
  } else {
    window.external.AddFavorite(url, phrase);
  }
}
function ShowOneHideOthers (elementID, activeID, total) {
  for (var i=1; i<=total; i++) {
  	var cible = document.getElementById(elementID+i);
    if (elementID+i == activeID) {
			cible.style.display = "block";
    } else {
			cible.style.display = "none";
    }
  }	
}


/**
*
*  Javascript trim, ltrim, rtrim
*  http://www.webtoolkit.info/
*
**/

 
function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
