//************************************************************************
// troncature à 2 décimale apres la virgule - ACO - fiche 618 -
// cette methode corrige le bug lié à javascript concernant les arrondis
// voir : http://www.taylor.org/~patrick/javascript/lib/decimal_parse/
//************************************************************************
var offset = 0;
function parseDec(val,places,sep) {

	// This function takes two arguments:
	//   (string || number)  val
	//            (integer)  places
	//             (string)  sep
	// val is the numeric string or number to parse
	// places represents the number of decimal
	// places to return at the end of the parse.
	// sep is an optional string to be used to separate
	// the whole units from the decimal units (default: '.')

	val = '' + val;
		// Implicitly cast val to (string)

	if (!sep) {
		sep = '.';
		// If separator isn't specified, then use a decimal point '.'
	}

	if (!places) { places = 0; }
	places = parseInt(places);
		// Make sure places is an integer

	if (val == 'NaN' || parseInt(val) == NaN || parseInt(val) == null) {
		// If val is null, zero, NaN, or not specified, then
		// assume val to be zero.  Add 'places' number of zeros after
		// the separator 'sep', and then return the value.  We're done here.
		val = '0';
		if (places > 0) {
			val += sep;
			while (val.substring((val.indexOf(sep))).length <= places) {
				val += '0';
			}
		}
		return val;
	}

	if ((val.indexOf('.') > -1) && (sep != '.')) {
		val = val.substring(0,val.indexOf('.')) + sep + val.substring(val.indexOf('.')+1);
			// If we're using a separator other than '.' then convert now.
	}

	if (val.indexOf(sep) > -1) {
		// If our val has a separator, then cut our value
		// into pre and post 'decimal' based upon the separator.
		pre = val.substring(0,val.indexOf(sep));
		post = val.substring(val.indexOf(sep)+1);
	} else {
		// Otherwise pre gets everything and post gets nothing.
		pre = val;
		post = '';
	}

	if (places > 0) {
		// If we're dealing with a decimal then...

		post = post.substring(0,(places+1));
			// We care most about the digit after 'places'

		if (post.length > places) {
			// If we have trailing decimal places then...

			//alert (parseInt(post.substring(post.length - 1)));

			if ( parseInt(post.substring(post.length - 1)) > 4 ) {
				post = '' + Math.round(parseInt(post) / 10);
				//post = '' + post.substring(0,post.length - 2) + (1/Math.pow(10,places));
				//post = ('' + post.substring(0,post.length - 2)) + (parseInt(post.substring(post.length - 1)) + 1);
			} else {
				post = '' + Math.round(parseInt(post));
			}
		}

		if (post.length > places) {
			post = '' + Math.round(parseInt(post.substring(0,places)));
		} else if (post.length < places) {
			while (post.length < places) {
				post += '0';
			}
		}

	} else {

		if (parseInt((post.substring(0,1))) > 4) {
			pre = '' + (parseInt(pre) + 1);
		} else {
			pre = '' + (parseInt(pre));
		}
		post = '';
	}

	sep = (post.length > 0) ? sep : '';
		// Should we use a separator?

	val = pre + sep + post;
		// Rebuild val

	return val;
}

//************************************************************************
// ACO fiche 646
//  Methode mise en forme de chaine de caracteres numérique
//  3000000 ->  3 000 000,00
//************************************************************************

  function ajusteMontantString(Montant)
  {
    //if (Montant.indexOf(',')!=-1) return Montant;

    nouveauMontant="";
    i=1;
    for (cpt=Montant.length-1; cpt>=0; cpt--)
    {
      nouveauMontant=Montant.charAt(cpt)+nouveauMontant;
      if (i>4 && i%3==0)
      {
        nouveauMontant=" "+nouveauMontant;
      }
      i++;
    }

    return nouveauMontant;
  }

  //************************************************************************
  //   floatToString(fvalue)
  //************************************************************************
  function floatToString(fvalue)
  {

    var svalue = fvalue.toString();
    var newSvalue= "";
    var entierValue = svalue;
    var decimalValue = "0";

    if (svalue.indexOf(".")>0)
    {
      entierValue = svalue.substring(0, svalue.indexOf("."));
      decimalValue = "0" + svalue.substring(svalue.indexOf("."),255);
    }

    var pos = 1;
    for(i=entierValue.length-1; i>=0; i--)
    {
      newSvalue = entierValue.charAt(i) + newSvalue;
      if ((pos % 3)==0)
      	newSvalue = " " + newSvalue;
      pos++;
    }

    if (parseFloat(decimalValue) < 0.10) {
      newSvalue = newSvalue + ".0" + Math.round(parseFloat(decimalValue)*100);
    }
    else {
      newSvalue = newSvalue + "."  + Math.round(parseFloat(decimalValue)*100);
    }
    return newSvalue;
  }

  //************************************************************************
  //   parseMontant(svalue)
  //************************************************************************
  function parseMontant(svalue)
  {
    var newSvalue = "";
    for(i=0; i<svalue.length; i++)
    {
      switch (svalue.charAt(i))
      {
        case '0':
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':
        case '+':
        case '-':
        case '.':
        case ',': newSvalue = newSvalue + svalue.charAt(i);
       }
    }

    return parseFloat(newSvalue.replace(',', '.'));

  }

  //************************************************************************
  //   remplacePointVirgule(svalue)
  //************************************************************************
  function remplacePointVirgule(svalue)
  {
    var newSvalue = "";
    for(i=0; i<svalue.length; i++)
    {
      if(svalue.charAt(i) == '.')
      {
        newSvalue = newSvalue + ',';
      }
      else
      {
         newSvalue = newSvalue + svalue.charAt(i);
      }
    }
    return newSvalue;
  }

  //************************************************************************
  //   remplaceVirgulePoint(svalue)
  //************************************************************************
  function remplaceVirgulePoint(svalue)
  {
    var newSvalue = "";
    for(i=0; i<svalue.length; i++)
    {
      if(svalue.charAt(i) == ',')
      {
        newSvalue = newSvalue + '.';
      }
      else
      {
         newSvalue = newSvalue + svalue.charAt(i);
      }
    }
    return newSvalue;
  }

  //*****************************************************************************
  // function calculTotDesinv()
  // document.forms.formrepart.length-5 = Total montant / 6 = 1er champs montant saisie
  // 48 (42+6) = 2e champs saisie ...
  //******************************************************************************
  function calculTotDesinv()
  {
    var longValue = document.forms.formrepart.length-5;
    if (!parseMontant(document.forms.formrepart[longValue].value))
      document.forms.formrepart[longValue].value = '0,00';
    var totalMt=0;
    var chaine="";

    for(y=6+offset; y<longValue; y=y+48)
    {
      if (!parseMontant(document.forms.formrepart[y].value))
          document.forms.formrepart[y].value = '0,00';
      totalMt = totalMt + parseMontant(document.forms.formrepart[y].value);
    }

    document.forms.formrepart[longValue].value  = floatToString(totalMt);
    return totalMt;
  }


  //************************************************************************
  //   function calculTotalRi()
  //************************************************************************
  function calculTotalRi()
  {

    var longValue = document.forms.formreinv.length-5;
    if (!parseMontant(document.forms.formreinv[longValue].value))
      document.forms.formreinv[longValue].value = '0,00';
    var totalMt=0;
    for(y=11+offset; y<longValue; y=y+30)
    {
      if (!parseMontant(document.forms.formreinv[y].value))
          document.forms.formreinv[y].value = '0,00';
      totalMt = totalMt + parseMontant(document.forms.formreinv[y].value);
    }
    document.forms.formreinv[longValue].value  = floatToString(totalMt);
    return totalMt;
  }

  //************************************************************************
  //   function calculMontantRi(lenom, ftotal)
  //************************************************************************
  function calculMontantRi(lenom, ftotal)
  {
   var i = recupLigneReinv(lenom);
  	
   var totalMt = 0;

   // correction des saisies des pourcentages
   var strSaisie = document.forms.formreinv[i].value;
   strSaisie = remplaceVirgulePoint(strSaisie);
   strSaisie = String(parseDec(parseFloat(strSaisie)*100)/100, 2);  // troncature à 2 décimale apres la virgule - ACO - fiche 618 -
   strSaisie = remplacePointVirgule(strSaisie);
   document.forms.formreinv[i].value = strSaisie;
   
   var stSaisie = document.forms.formreinv[i].value;
  
   stSaisie = stSaisie.replace(",", ".");
	
   if (isNaN(stSaisie))
   {
       alert('Valeur non num\u00E9rique.\nVous ne pouvez saisir que des chiffres.');
       document.forms.formreinv[i].value = '0,00';
       document.forms.formreinv[i+6].value = '0,00';
       document.forms.formreinv[i].focus();

       // recalcul du total
       totalMt= calculTotalRi();
   }
   else    // C est numérique
   {
   	   
       var fl = parseMontant(document.forms.formreinv[i].value)*parseMontant(document.forms.formreinv[0].value)/100;
       // ACT 24/09/2001
       // document.forms.formreinv[i+6].value = floatToString(fl).replace('.', ',');

       var strf1 = floatToString(fl);
       strf1 = remplacePointVirgule(strf1);
       document.forms.formreinv[i+6].value = strf1;
       
     if (parseMontant(document.forms.formreinv[i].value) < 0)
      {
      	
          alert('Vous ne pouvez pas investir un pourcentage n\u00E9gatif.');
          document.forms.formreinv[i].value = '0,00';
          document.forms.formreinv[i+6].value = '0,00';
          document.forms.formreinv[i].focus();

          // recalcul du total
          totalMt= calculTotalRi();
      }
      else if ( parseMontant(document.forms.formreinv[i+6].value) < parseMontant(document.forms.formreinv[i+12].value)
          && parseMontant(document.forms.formreinv[i+6].value) != 0 && (parseMontant(document.forms.formreinv[i].value) != 100))
       {
       	
          alert('Le minimum \u00E0 investir pour ce fonds est de '+document.forms.formreinv[i+12].value+' euros');
          document.forms.formreinv[i].value = '0,00';
          document.forms.formreinv[i+6].value = '0,00';
          document.forms.formreinv[i].focus();

          // recalcul du total
          totalMt= calculTotalRi();
      }
      else // c est bien superieur au mini dinvestissment pour le fonds
      {
      	  
          // recalcul du total
          totalMt= calculTotalRi();

          //vérifie si total = 100%
          var totalPourc=0;
          var longValue = document.forms.formreinv.length-5;
          var nbChampPourcent = document.forms.formreinv.length-6;
          for(y=5+offset; y<nbChampPourcent; y=y+30)
          {
            if (!parseMontant(document.forms.formreinv[y].value))
                 document.forms.formreinv[y].value = '0,00';

             totalPourc = totalPourc + parseMontant(document.forms.formreinv[y].value);
             totalPourc = parseDec(parseFloat(totalPourc)*100)/100; // troncature à 2 décimale apres la virgule - ACO - fiche 618 -
          }
          
           if (totalPourc > 100 )
          {
          	 
            alert('La somme ne doit pas d\u00E9passer 100% : ' + totalPourc);
            document.forms.formreinv[i].value = '0,00';
            document.forms.formreinv[i+6].value = '0,00';
            document.forms.formreinv[i].focus();
            totalMt= calculTotalRi();
            recalculPourcentageRestant(nbChampPourcent);
          }
          else if (totalPourc < 100)
          {
            // ACT 24/09/2001
            // document.forms.formreinv[longValue].value  = floatToString(totalMt).replace('.', ',');
            var strTotalMt = floatToString(totalMt);
            
            strTotalMt = remplacePointVirgule(strTotalMt);
            document.forms.formreinv[longValue].value  = strTotalMt;
	     document.forms.formreinv.totalPourcentage.value=Math.round((100-totalPourc)*100)/100;
            
            testLimitreinv=testMontantLimitReinv(lenom, totalMt);
            if(testLimitreinv>0)
            {
            	alert('La somme des réinvestissements pour le gestionnaire '+ document.forms.formreinv[i+24].value +' ne doit pas d\u00E9passer '+ testLimitreinv+'% du montant total de votre versement');
                document.forms.formreinv[i].value = '0,00';
            	document.forms.formreinv[i+6].value = '0,00';
            	document.forms.formreinv[i].focus();
            	totalMt= calculTotalRi();
            	recalculPourcentageRestant(nbChampPourcent);
           	
            }
          }
          else
          {
          	 
            // ACT 24/09/2001
            // document.forms.formreinv[longValue].value  = floatToString(ftotal).replace('.', ',');
            // document.forms.formreinv[i+6].value = floatToString(ftotal-totalMt+parseMontant(document.forms.formreinv[i+6].value)).replace('.', ',');
	      var strftotal = floatToString(ftotal);
            strftotal = remplacePointVirgule(strftotal);
            document.forms.formreinv[longValue].value = strftotal;
	   var total = ftotal-totalMt+parseMontant(document.forms.formreinv[i+6].value);
            var strTotal = floatToString(total);
            strTotal = remplacePointVirgule(strTotal);
            document.forms.formreinv[i+6].value = strTotal;
	 
            document.forms.formreinv.totalPourcentage.value=100-totalPourc;
            
            testLimitreinv=testMontantLimitReinv(lenom, ftotal);
            if(testLimitreinv>0)
            {
            	alert('La somme des réinvestissements pour le gestionnaire '+ document.forms.formreinv[i+24].value +' ne doit pas d\u00E9passer '+ testLimitreinv+'% du montant total de votre versement');
                document.forms.formreinv[i].value = '0,00';
            	document.forms.formreinv[i+6].value = '0,00';
            	document.forms.formreinv[i].focus();
            	totalMt= calculTotalRi();
            	recalculPourcentageRestant(nbChampPourcent);
           	
            }
            
          }
      }
   }
   // fiche 643, (TraArbRep le OnChange devient Onblur -> !! plus de réatribution de focus permanente)
   // document.forms.formreinv[i].focus();
  }
  
  function testMontantLimitReinv(lenom, ftotal)
  {
  	
  	var nbEtablissementInvesLimit=etablissementInvestLimit.length;
   	
   	var pourcent=0;
   	var testInvesLimit=true;
   	var unEtablissementInvesLimit="";
   	if (nbEtablissementInvesLimit>0)
   	{
   		var i = recupLigneReinv(lenom);
   		
   		unEtablissementInvesLimit=(document.forms.formreinv[i+24].value).toUpperCase();
   		
   		for(j=0; j<nbEtablissementInvesLimit; j++){
   			if (etablissementInvestLimit[j]==unEtablissementInvesLimit){
   				pourcent=pourcentInvestLimit[j];
   					
   	   		}
   		}
   		
   	}
   	
   	if (pourcent>0){
   		
      		var totalPourc=0;
          	var nbChampPourcent = document.forms.formreinv.length-6;
          	for(y=5+offset; y<nbChampPourcent; y=y+30)
          	{
          		
          		var etablissement=(document.forms.formreinv[y+24].value).toUpperCase();
          		
          		
          		if (unEtablissementInvesLimit==etablissement)
          		{
            			var unPourcent=parseMontant(document.forms.formreinv[y].value);
             			totalPourc = totalPourc + unPourcent;
             			
             			totalPourc = parseDec(parseFloat(totalPourc)*100)/100; // troncature à 2 décimale apres la virgule - ACO - fiche 618 -
          		}
          	}
          	
    		if (totalPourc>pourcent) {
      			testInvesLimit=false;
      		}
      			
      	}
      	
        if (testInvesLimit) {
      		return 0;
        }
      	else {
      		return pourcent;
	}
     		
 }
  
  
  

  //************************************************************************
  //   function testCombo(lenom)
  //************************************************************************
  function testCombo(lenom)
  {
   var i = recupLigneRepart(lenom);
   while (document.forms.formrepart[i].name != lenom.name)
     {
      i++; // on récupère la ligne
     }

   if (lenom.selectedIndex == 1) // Totalité
     {
      document.forms.formrepart[i+6].value = document.forms.formrepart[i+12].value;
      document.forms.formrepart[i+6].focus();
      // document.forms.formrepart[i+6].style.backgroundColor='gray';
     }
   else
     {
      document.forms.formrepart[i+6].style.backgroundColor='white';
     }
  }


  //************************************************************************
  //   function testFocus(lenom)
  //************************************************************************
  function testFocus(lenom)
  {

   var i = recupLigneRepart(lenom);
   if (document.forms.formrepart[i-6].selectedIndex == 1) // Totalité
       document.forms.formrepart[i-6].focus();
  }


  //************************************************************************
  //   function testFocusTotal(lenom)
  //************************************************************************
  function testFocusTotal(lenom)
  {

   var i = recupLigneReinv(lenom);
   document.forms.formreinv[i-30].focus();
  }


  //************************************************************************
  //   function griseOnLoad()
  //************************************************************************
   function griseOnLoad()
   {

    alert('grise on load ');
    var longValue = document.forms.formreinv.length-5;
    document.forms.formreinv[longValue].style.backgroundColor='gray';
   }


  //************************************************************************
  //   function testFocusReinv(lenom)
  //************************************************************************
  function testFocusReinv(lenom)
  {

   var i = recupLigneReinv(lenom);
   document.forms.formreinv[i+24].focus();
  }

  //************************************************************************
  //   function testTotDesinvFocus()
  //************************************************************************
  function testTotDesinvFocus()
  {
   var longValue = document.forms.formrepart.length-5;
   document.forms.formrepart[longValue-42].focus();
  }


  //************************************************************************
  //   function testValDesinv(lenom)
  //************************************************************************
  function testValDesinv(lenom)
  {


   var i = recupLigneRepart(lenom);
   var totalMt = 0;
   var longValue = document.forms.formrepart.length-5;


   //FLE 01/06/2001 Anomalie n° 254 :
   //if (isNaN(document.forms.formrepart[i].value))
   //document.forms.formrepart[i].value = document.forms.formrepart[i].value.replace('.', ',');

   var strSaisie = document.forms.formrepart[i].value;
   strSaisie = remplacePointVirgule(strSaisie);
   document.forms.formrepart[i].value = strSaisie;

   var stSaisie = document.forms.formrepart[i].value;
   stSaisie = stSaisie.replace(",", ".");

   // ACO anomalie 656 ( si montant désinv = montant -> combo = totalité)
    if (parseMontant(document.forms.formrepart[i].value)==parseMontant(document.forms.formrepart[i+6].value))
    {
      // On teste si l'option "En totalité existe"
      if ( (document.forms.formrepart[i-6].options.length>1)
         && ( (document.forms.formrepart[i-6].options[0].value == "|02")
           || (document.forms.formrepart[i-6].options[1].value == "|02")))
      {
      	document.forms.formrepart[i-6].value="|02";
      }
    }

   var reliq= (parseMontant(document.forms.formrepart[i+6].value) - parseMontant(document.forms.formrepart[i].value));

      if (isNaN(stSaisie))
      {
        alert('Valeur non num\u00E9rique.\nVous ne pouvez saisir que des chiffres.');
        document.forms.formrepart[i].value = '0,00';
        document.forms.formrepart[i].focus();

        // recalcul du total
        totalMt= calculTotDesinv();
      }
      else if (parseMontant(document.forms.formrepart[i].value) < 0)
      {
        alert('Le montant de d\u00E9sinvestissement doit \u00EAtre positif.' );
        document.forms.formrepart[i].value = '0,00';
        document.forms.formrepart[i].focus();

        // recalcul du total
        totalMt= calculTotDesinv();
      }
      else if (stSaisie == "")// ACO si blanc pas de message d'erreur
      {
        document.forms.formrepart[i].value = '0,00';
        document.forms.formrepart[i].focus();

        // recalcul du total
        totalMt= calculTotDesinv();
      }
      else if ((stSaisie == null)) // DEBUT ACT 05/07/01 fiche 287
      {
        var montant=document.forms.formrepart[i+12].value;
        montant=ajusteMontantString(montant);
        alert('Le d\u00E9sinvestissement doit \u00EAtre sup\u00E9rieur \u00E0 ' + montant + ' euros pour ce fonds');
        document.forms.formrepart[i].value = '0,00';
        document.forms.formrepart[i].focus();

        // recalcul du total
        totalMt= calculTotDesinv();
      }	
      // FIN ACT 05/07/01 fiche 287
      else if (parseMontant(document.forms.formrepart[i].value) > parseMontant(document.forms.formrepart[i+6].value))
      {
        alert('Le montant \u00E0 d\u00E9sinvestir ne peut pas \u00EAtre sup\u00E9rieur au montant initial');
        document.forms.formrepart[i].value = '0,00';
        document.forms.formrepart[i].focus();

        // recalcul du total
        //totalMt= calculTotDesinv();
      }
      // Cas perp avec desinvest en totalité, le montant dispo est inférieur au montant minimum restant autorisé
      else if ( isContratPerp 
       && parseMontant(document.forms.formrepart[i+6].value) < parseMontant(document.forms.formrepart[i+18].value) 
       && parseMontant(document.forms.formrepart[i].value) != 0 
       && document.forms.formrepart[i-6].value=="|01"){
        alert("Compte tenu du profil de gestion de votre contrat, le d\u00E9sinvestissement n'est pas possible pour ce fonds");
        document.forms.formrepart[i].value = '0,00';
        document.forms.formrepart[i].focus();
        totalMt= calculTotDesinv();
      } 
      // Modif CB, dans certains cas l'option "En totalité" n'est pas dispo
      else if (reliq < (parseMontant(document.forms.formrepart[i+18].value)) && (reliq != 0) 
       && parseMontant(document.forms.formrepart[i+6].value) > parseMontant(document.forms.formrepart[i+18].value) 
       && document.forms.formrepart[i-6].value=="|02"
       && parseMontant(document.forms.formrepart[i].value) != 0
       )
      { // Ici désinvest en totalité, on peut accepter 0

	var montant=document.forms.formrepart[i+18].value;
        montant=ajusteMontantString(montant);
        alert('Le reste apr\u00E8s d\u00E9sinvestissement doit \u00EAtre sup\u00E9rieur \u00E0 ' + montant + ' euros pour ce fonds');
        document.forms.formrepart[i].value = '0,00';
        document.forms.formrepart[i].focus();

        // recalcul du total
        totalMt= calculTotDesinv();
      }
      else if (reliq < (parseMontant(document.forms.formrepart[i+18].value)) 
       && document.forms.formrepart[i-6].value=="|01"
       && parseMontant(document.forms.formrepart[i].value) != 0)
      { // Mais ici, le désinvest est en euros; le désinvest en totalité n'est pas autorisé, reliq ne peut pas être à 0

	var montant=document.forms.formrepart[i+18].value;
        montant=ajusteMontantString(montant);
        alert('Le reste apr\u00E8s d\u00E9sinvestissement doit \u00EAtre sup\u00E9rieur \u00E0 ' + montant + ' euros pour ce fonds');
        document.forms.formrepart[i].value = '0,00';
        document.forms.formrepart[i].focus();

        // recalcul du total
        totalMt= calculTotDesinv();
      }
      else if (parseMontant(document.forms.formrepart[i].value) < parseMontant(document.forms.formrepart[i+12].value)
       && parseMontant(document.forms.formrepart[i].value)!= 0
       && document.forms.formrepart[i-6].value!="|02")
      {
        var montant=document.forms.formrepart[i+12].value;
        montant=ajusteMontantString(montant);
        alert('Le d\u00E9sinvestissement doit \u00EAtre sup\u00E9rieur \u00E0 ' + montant + ' euros pour ce fonds');
        document.forms.formrepart[i].value = '0,00';
        document.forms.formrepart[i].focus();

        // recalcul du total
        totalMt= calculTotDesinv();
      }
      else
      {
        // recalcul du total
        totalMt= calculTotDesinv();

        var strTotalMt = floatToString(totalMt);
        strTotalMt = remplacePointVirgule(strTotalMt);
        document.forms.formrepart[longValue].value  = strTotalMt;
      }
  }


  //************************************************************************
  //   function recupLigneRepart(obj)
  //************************************************************************
  function recupLigneRepart(obj)
  {

   // récupération de la sous-chaine du nom pour obtenir le numero de ligne
   var chaine = obj.name;
   chaine = chaine.replace(".","_");
   chaine = chaine.replace(".","_");
   var index = chaine.search("_");
   chaine = chaine.replace("_",".");
   var index1 = chaine.search("_");
   var numlgn = chaine.substring(index+1,index1);

   var i = 0;
   while (document.forms.formrepart[i].name != obj.name)
    {
     i++; // on récupère la ligne
    }
   return i;
  }

  //************************************************************************
  //   function recupLigneReinv(obj)
  //************************************************************************
  function recupLigneReinv(obj)
  {

   // récupération de la sous-chaine du nom pour obtenir le numero de ligne
   var chaine = obj.name;
   chaine = chaine.replace(".","_");
   chaine = chaine.replace(".","_");
   var index = chaine.search("_");
   chaine = chaine.replace("_",".");
   var index1 = chaine.search("_");
   var numlgn = chaine.substring(index+1,index1);

   var i = 0;
   while (document.forms.formreinv[i].name != obj.name)
     {
      i++; // on récupère la ligne
     }
   return i;
  }
  
 

  //************************************************************************
  //   function ouvrirPopup(fichier, width, height)
  //************************************************************************
  function ouvrirPopup(fichier, width, height)
  {
    if (typeof(width) == 'undefined') width=550;
    if (typeof(height) == 'undefined') height=400;
    param='toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=1,width=' + width + ',height=' + height +',left=100,top=100';
    window.open(fichier,'popup', param);
  }

  //************************************************************************
  //   function ouvrirSousPopup(fichier, width, height)
  //************************************************************************
  function ouvrirSousPopup(fichier, width, height)
  {
	if (typeof(width) == 'undefined') width=550;
    if (typeof(height) == 'undefined') height=400;
    param='toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=1,width=' + width + ',height=' + height +',left=100,top=100';
    window.open(fichier,'sous_popup', param);
  }

  //************************************************************************
  //   function ouvrirPopupFixe(fichier, width, height)
  //************************************************************************
  function ouvrirPopupFixe(fichier, width, height)
  {
    if (typeof(width) == 'undefined') width=550;
    if (typeof(height) == 'undefined') height=400;
    param='toolbar=0,location=0,directories=0,menuBar=0,scrollbars=0,resizable=0,width=' + width + ',height=' + height +',left=100,top=100';
    window.open(fichier,'popupfixe', param);
  }

  //************************************************************************
  //   function permettant de valider la selection des fonds (TraselFond2.jsp)
  //************************************************************************
  function ValideFormulaireSelectionnner(form)
  {
    form.submit();
    return;
  }

  //************************************************************************
  //   function permettant de traiter le lancement à partir de TRaselFond.jsp
  //************************************************************************
  function lancerLaSelectionCombo(nomformulaire,combo)
  {
    var URL=getURLCombo(combo);
    if (URL!="#") setSubmitSousFamille(nomformulaire,URL);
  }

  //************************************************************************
  //   function permettant le lancement à partir d'une combo (TraselFond.jsp)
  //************************************************************************
   function getURLCombo(combo)
  {
    var URL=combo.options[combo.selectedIndex].value;
    URL=URL.substring(1,URL.length);
    return URL;
  }

  //************************************************************************
  // fonction de sousmission d'accès à la page sous famille
  // @param query <string> la partie query de la requete + param
  //************************************************************************
  function setSubmitSousFamille(nomform,query)
  {
          var frm = document.forms[nomform];
          frm.action=query;
          frm.submit();
  }

  //************************************************************************
  //   function de demande de confirmation avant validation pour TraArbDes
  //   etape de l'arbitrage desinvestissement
  //************************************************************************
  function comfirmValidation()
  {
      var a = false;
      a= confirm ('La validation annulera toutes les étapes effectuées ultérieurement');
      if (a)
        javascript:document.formrepart.submit();
  }

  //**********************************************************
  //   fonction de demande de confirmation avant de quitter
  //*********************************************************
  function confirmQuitter(url)
  {
      var a = false;
      a= confirm ('Confirmez l\'abandon de votre transaction');
      if (a)
        window.location = url;
  }


  //**********************************************************
  //   fonction de demande de confirmation avant de quitter
  //*********************************************************
  function confirmQuitterOpe(url)
  {
      var a = false;
      a= confirm ('Confirmez l\'abandon de l\'opération');
      if (a)
        window.location = url;
  }

  //***************************************************************
  //   fonction de lancement de la signature en utilisant Baltimore
  //***************************************************************
  function DoValiderArbitrage(query,demo, msgAlert)
  {
    var frm=document.formPARTIE_A_VALIDER;
    var check= frm.checkVerification;
    
    //ajout d'une verification des cases à cocher avant de tester la validite de l'avenant
    if (! check.checked) {
    	alert(msgAlert);
    } else {
    
    	if (isValideAvenantForArbitrage()){
    		frm.submit();
    	}
    }
  }
  
  //******************************************************************************************************
  //   fonction de valiation de l'avenant lors d'un arbitrage 
  //   -> verifie uniquement les periodes d'invest sur les fonds.
  //*****************************************************************************************************
  function isValideAvenantForArbitrage(){
		valide=true;
		
		avenantPlusCommercialisable=jq14('.classFondAvenantWarning');
		if (avenantPlusCommercialisable.length>0) {
			valide = false;
			
			alert("La période d'investissement sur le(s) fonds sélectionné(s) a expiré. Vous ne pouvez plus investir sur ce(s) fonds.");
		} 
		return valide;
	}

   //*************************
  //   fonction d'impression
  //*************************
  var win;

  function DoPrint()
  {
	var frm=document.A_IMPRIMER;
	
	if (win) {win.close();}
	
	
	var fichier='<head>';
	fichier+='<title>Impression de votre preuve</title>';
	fichier+='<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">';
	fichier+='<meta http-equiv="Cache-Control" content="no-cache">';
	fichier+='<meta http-equiv="Pragma" content="no-cache">';
	fichier+='<link REL="StyleSheet" TYPE="text/css" HREF="/b2b2c/commun/theme/contenu.css">';
	fichier+='<link REL="StyleSheet" TYPE="text/css" HREF="/b2b2c/commun/theme/tableaux.css">';
	fichier+='<STYLE type="text/css">';
	fichier+='.titre2 { color : #000000; font-family : Arial; font-weight : bold; font-style : normal; text-align : left; vertical-align : top; height : 1;}';
	fichier+='.titre4 { color : #A6A6A6; font-family : Arial; font-weight : bold; font-style : normal; text-align : left; vertical-align  : bottom; }';
	fichier+='.barre { background-color : #CCCCCC; height : 1; }';
	fichier+='.enteteTableau { color : #FFFFFF; background-color : #000000; font-weight : bold; font-family : Tahoma, Helvetica, Arial, sans-serif; font-size : 11px; font-style : normal;}';
	fichier+='.lpTableau { color : black; background-color : #EDEDED; font-family : Tahoma, Helvetica, Arial, sans-serif; font-size : 11px;}';
	fichier+='.liTableau { color : black; background-color : #CCCCCC; font-family : Tahoma, Helvetica, Arial, sans-serif; font-size : 11px;}';
	fichier+='.libelle-petit { color : #000000; font-family : Arial; font-size : 9px; font-weight : bold; font-style : normal; text-align : left; vertical-align : top; height : 1;}';
	fichier+='.libelle-graspetit { color : #000000; font-family : Arial; font-size : 11px;	font-weight : bold; font-style : normal; text-align : left; vertical-align : top; height : 1;}';
	fichier+='.libelle-droit { color : #000000; font-family : Arial; font-size : 12px; font-style : normal; text-align : right; vertical-align : top; height : 1;}';
	fichier+='.libelle-gras { color : #000000; font-family : Arial; font-size : 12px; font-weight : bold; font-style : normal; vertical-align : top; height : 1;}';
	fichier+='</STYLE>';
	fichier+='</head>';
	fichier +="<body><table border=0>"+document.forms['A_IMPRIMER'].innerHTML+"</table></body></html>";
	var param='toolbar=0,location=0,directories=0,menuBar=1,scrollbars=1,resizable=1,width=' + 700 + ',height=' + 500 +',left=100,top=100';
	win=window.open('vide','Fenetre_Imprimer', param);
	win.document.open();
	win.document.write(fichier);
	win.document.close() 
  }

  //*************************
  //   recalcul 100%
  //*************************
  function recalculPourcentageRestant(nbChampPourcent)
  {
        var totalPourc=0;

        for(y=5+offset; y<nbChampPourcent; y=y+30)
        {
          if (!parseMontant(document.forms.formreinv[y].value))
               document.forms.formreinv[y].value = '0,00';
            totalPourc = totalPourc + parseMontant(document.forms.formreinv[y].value);
        }
        val=parseDec(parseFloat(100-totalPourc)*100)/100; // troncature à 2 décimale apres la virgule - ACO - fiche 618 -
        document.forms.formreinv.totalPourcentage.value=val;
  }


  //*************************
  //   recalcul 100%
  //*************************
  function installLibraryNetscape(ref)
  {
      <!-- Hide from other browsers
        trigger = netscape.softupdate.Trigger

        if ( !trigger.UpdateEnabled() )
        {
            document.write("<H2>La librairie FormSecure ne peut pas être installée.</H2><H3> Veuillez activer SmartUpdate (menu Edition/Préférence/Avancées/SmartUpdate) et recommencer. ");
        }
        else
        {
            version_no = new netscape.softupdate.VersionInfo(4,3,0,0);
            trigger.ConditionalSoftwareUpdate("LibraryInstall.jar", "java/classes/Library", version_no, trigger.DEFAULT_MODE);
            alert('Installation termin\u00E9e');
        }
        // Stop hiding from other browsers -->
  }
  
   
