
var form1=new modform();
form1.sel=['PRODUIT.FAMILLECHIMIQUE','PRODUIT.COULEUR','PRODUIT.NomGamme'];
form1.ajax= new Array();

var form2=new modform();
form2.sel=['PRODUIT.Famille','PRODUIT.Couleur_CI','PRODUIT.Indice_CI'];
form2.ajax= new Array();

function getModifProd(id_sel) {
  form1.ModifSelect(id_sel);
  form2.reset();
}
function getColorI(id_sel) {
  form2.ModifSelect(id_sel);
  form1.reset();
}

function modform() {

  this.reset= function () {
    if (this.ajax.length>0) {
      this.ajax.length=0;
      this.ModifSelect();
    } else {
      for (var i = 0; i < this.sel.length; i++) {
	var xxCode =new getObj(this.sel[i]);
	if (xxCode.obj.value) { this.ModifSelect(); break }
      }
    }
  }

  this.ModifSelect= function(id_sel) {
	    var url_param="ajax=ok&";

	    if (id_sel) {
	      var sel=new getObj(id_sel);
	      var selValue = sel.obj.options[sel.obj.selectedIndex].value;
	    
	      var k=0;
	      for (var i = 0; i < this.ajax.length; i++) {
		var xxCode=new getObj(this.ajax[i]);
		var xxCodeValue=xxCode.obj.value;
		if (xxCodeValue) { url_param+=this.ajax[i]+"="+xxCodeValue+"&"; }	
		if (this.ajax[i] == id_sel) {
		  k=1; 
		  this.ajax.length=i+1; 
		  if(selValue.length==0) { this.ajax.length=i; }
		  break; 
		}
	      }  
	      if (k == 0) { 
		this.ajax.push(id_sel);
		url_param+=id_sel+"="+sel.obj.value+"&"; 
	      }
	    }

	    for (var i = 0; i < this.sel.length; i++) {
	      var id_next=this.sel[i];
	      if (this.egrep(id_next)) { continue }

	      var xxCode =new getObj(id_next);

	      xxCode.obj.options.length = 0; 
	      var xx = new sack();
	      xx.method = 'GET';
	      xx.requestFile = '/bin/f/recherche-produit.pl';
	      xx.onCompletion = OuterFunction(xx,id_next);
	      xx.runAJAX(url_param+"type="+id_next);          // Execute AJAX function
	    }
	  }
  this.egrep= function(id_next) {
    for (var k = 0; k < this.ajax.length; k++) {
      if (id_next == this.ajax[k]) { return 1 }
    }	    
    return 0;
  }
}


function OuterFunction(index,id_next){
  return function (){
    createProd(index,id_next);
  }
}
function createProd(index,id_select) {
  var xx = new getObj(id_select);
  var obj=xx.obj;
  eval(index.response);
}


