var calendars = [];

function tablepopup(obj_target, obj_target1, obj_page) {

	// assigning methods
	this.popup    = cal_popup2;
	this.vider    = cal_vider1;

	// validate input parameters
	if (!obj_target)
		return cal_error("Error calling the popup: no target control specified");
	if (obj_target.value == null)
		return cal_error("Error calling the popup: parameter specified is not valid target control");
	this.target = obj_target;
	this.target1 = obj_target1;
	this.page = obj_page;
	
	// register in global collections
	this.id = calendars.length;
	calendars[this.id] = this;
}

function cal_popup2 (str_datetime) {

	var obj_calwindow = window.open(
		this.page + '?id=' + this.id,
		'Selection', 'width=415,height=500,status=no,resizable=no,top=20,left=20,dependent=yes,alwaysRaised=yes,scrollbars=yes'
	);
	obj_calwindow.opener = window;
	obj_calwindow.focus();
}

function cal_error (str_message) {
	alert (str_message);
	return null;
}

function cal_vider1 (str_message) {
	this.target.value = '';
	this.target1.value = '';
}

function fichierpopup(obj_target, obj_page) {

	// assigning methods
	this.popup    = cal_popup3;
	this.vider    = cal_vider3;

	// validate input parameters
	if (!obj_target)
		return cal_error("Error calling the popup: no target control specified");
	if (obj_target.value == null)
		return cal_error("Error calling the popup: parameter specified is not valid target control");
	this.target = obj_target;
	this.page = obj_page;
	
	// register in global collections
	this.id = calendars.length;
	calendars[this.id] = this;
}

function cal_popup3 (str_datetime) {

	var obj_calwindow = window.open(
		this.page + '?id=' + this.id,
		'Selection', 'width=800,height=600,status=no,resizable=no,top=20,left=20,dependent=yes,alwaysRaised=yes,scrollbars=yes'
	);
	obj_calwindow.opener = window;
	obj_calwindow.focus();
}

function cal_vider3 (str_message) {
	this.target.value = '';
}

function gereSaisieDetail(nomChamps, valeurGroup, nomTR) {
  
  var valeurChamp = document.getElementById(nomChamps).value;
  var disp = "none";
  while (valeurGroup) {
   var temp = valeurGroup.indexOf(";");
   var groupeActuel = valeurGroup.substring(0,temp);
   var groupeVisible = groupeActuel.indexOf("_" + valeurChamp + "_");
   if (groupeVisible > -1) disp = ""; else disp = "none";
   var i = 1;
   var continuer = 1; 	
   while (continuer) {
    var nomId = "TRSaisieDetail" + nomTR + groupeActuel + i;
    if (document.getElementById(nomId) != null) {	
     document.getElementById(nomId).style.display=disp;
     i++;
    } else continuer = 0;
   }	
   valeurGroup = valeurGroup.substring(temp+1);
   while (valeurGroup && valeurGroup.substring(0,1) != '_') valeurGroup = valeurGroup.substring(temp+1);
  }  
 }
