function cargar_gamma(codigo)
{
  cadena=codigo;
  jsrsExecute("./import/cargar_gamma.php",recibir_gamma,"confirmar",cadena);
}

function recibir_gamma(cadena)
{
  var form = document.forms[0];
  cadena=cadena.split("|");
  coddepc=cadena[0].split(",");
  coddepn=cadena[1].split(",");
  
  cantidad=coddepc.length;
  
  form.cboGamma.options.length=1;
  form.cboEnergia.options.length=1;
  
  opcion=new Option("--- Toutes ---","");
  form.cboGamma.options[0]= opcion;
  
  for(x=1;x<cantidad; x++)
  { 
   
   otraopcion=new Option(coddepn[x-1],coddepc[x-1]);
   form.cboGamma.options[x]= otraopcion;
  }
}

function cargar_energia(codigo)
{
  cadena=codigo;
  jsrsExecute("./import/cargar_energia.php",recibir_energia,"confirmar",cadena);
}

function recibir_energia(cadena)
{
  var form = document.forms[0];
  cadena=cadena.split("|");
  coddepc=cadena[0].split(",");
  coddepn=cadena[1].split(",");
  
  cantidad=coddepc.length;
  
  form.cboEnergia.options.length=1;
  
  opcion=new Option("--- Toutes ---","");
  form.cboEnergia.options[0]= opcion;

  for(x=1;x<cantidad; x++)
  { 
   
   otraopcion=new Option(coddepn[x-1],coddepc[x-1]);
   form.cboEnergia.options[x]= otraopcion;
  }
}

function show_tabs(opcion)
{
	if(opcion=="ficha")
	{
	 if(document.getElementById("id_ft").style.display=='none')
	 {
	  document.getElementById("id_ft").style.display='';
	  document.getElementById("id_es").style.display='none';
	  document.getElementById("id_oc").style.display='none';
	  document.getElementById("id_ftt").innerHTML="<img src=\"images/pestana1.gif\" width=\"113\" height=\"18\" border=\"0\">";
	  document.getElementById("id_est").innerHTML="<img src=\"images/pestana2a.gif\" width=\"143\" height=\"18\" border=\"0\">";
	  document.getElementById("id_oct").innerHTML="<img src=\"images/pestana3a.gif\" width=\"122\" height=\"18\" border=\"0\">";
	 }
	 
	}
	
	if(opcion=="serie")
	{
	 if(document.getElementById("id_es").style.display=='none') {
	  document.getElementById("id_es").style.display='';
	  document.getElementById("id_ft").style.display='none';
  	  document.getElementById("id_oc").style.display='none';
	  document.getElementById("id_est").innerHTML="<img src=\"images/pestana2.gif\" width=\"143\" height=\"18\" border=\"0\">";
	  document.getElementById("id_ftt").innerHTML="<img src=\"images/pestana1a.gif\" width=\"113\" height=\"18\" border=\"0\">";
	  document.getElementById("id_oct").innerHTML="<img src=\"images/pestana3a.gif\" width=\"122\" height=\"18\" border=\"0\">";
	 }
	 
	}
	
	if(opcion=="carte")
	{
	 if(document.getElementById("id_oc").style.display=='none') {
	  document.getElementById("id_oc").style.display='';
	  document.getElementById("id_es").style.display='none';
	  document.getElementById("id_ft").style.display='none';
	  
	  document.getElementById("id_oct").innerHTML="<img src=\"images/pestana3.gif\" width=\"122\" height=\"18\" border=\"0\">";
	  document.getElementById("id_ftt").innerHTML="<img src=\"images/pestana1a.gif\" width=\"113\" height=\"18\" border=\"0\">";
	  document.getElementById("id_est").innerHTML="<img src=\"images/pestana2a.gif\" width=\"143\" height=\"18\" border=\"0\">";
	 }
	 
	}


}

function FormatNumber(num,decimalNum,bolLeadingZero,bolParens,bolCommas)
/**********************************************************************
	IN:
		NUM - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for
										numbers between -1 and 1
		bolParens - true / false - use parenthesis around negative numbers
		bolCommas - put commas as number separators.
 
	RETVAL:
		The formatted number!
 **********************************************************************/
{      
		
		if (isNaN(parseInt(num))) return "NaN";

	var tmpNum = num;
	var iSign = num < 0 ? -1 : 1;		// Get sign of number
	
	// 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;					// Readjust for sign
	
	
	// 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) + ")";
    
	alert(tmpNumStr);

	return tmpNumStr;		// Return our formatted string!
}

function redondear(num)
{
	num *= 100;
    num = Math.round(num);
    num /= 100;
	return num;
}

function formatCurrency(n,d) // n = number, d = delimeter
{
   // round to 2 decimals if cents present
   n = (Math.round(n * 100) / 100).toString().split('.');
   var
  	myNum = n[0].toString(),
	fmat = new Array(),
	len = myNum.length,
	i = 1, deci = (d == ' ') ? ',' : '.';
  for(i; i < len + 1; i++) fmat[i] = myNum.charAt(i-1);

	fmat = fmat.reverse();
	for(i = 1; i < len; i++)
	{
		if(i % 3 == 0) {
		 fmat[i] += d;
		}
	}
	var val = fmat.reverse().join('') +
	 ( n[1] == null ? deci + '00' :
	   (deci + n[1])
	 );
	
	val = val.toString().split(',');
	return val[0];
}
