var frm;
var barre_resultat;

//initialisation de la page
function init()
{
	frm = document.frm_calcul;
	masqueBlockId("centrales");
	masqueBlockId("ligne_conventionelle");
	masqueBlockId("cassiope_mezzo_forte_piano");
	masqueBlockId("mbasv_mbasvex");
	masqueBlockId("pourcentage");
	//Barre de progression
	barre_resultat = new jt_ProgressBar(document.getElementById("pcent_res"), 250, 15, "progress_bar");
	masqueBlockId("progress_bar");
	masqueBlockId("valif_form");
}

function verif_type_ligne(chk_type_ligne)
{
	if (chk_type_ligne.id == "chk_conventionnelle")
	{
		//Set la case à cocher ligne adressable à false;
		frm.chk_adressable.checked = false;
		//Masque les blocs de type de centrale
		masqueBlockId("centrales");
		//Masque le fieldset piano mezzo forte
		masqueBlockId("cassiope_mezzo_forte_piano");
		if (chk_type_ligne.checked == true)
		{
			 afficheBlockId("ligne_conventionelle");
			//Affichage du bouton de calcul
			 afficheBlockId("valif_form");
		}
		else
		{
			masqueBlockId("ligne_conventionelle");
			masqueBlockId("valif_form");
		}
	}
	if (chk_type_ligne.id == "chk_adressable")
	{
		//Set la case à cocher ligne conventionelle à false;	
		frm.chk_conventionnelle.checked = false;
		//Masque le fieldset ligne conventionelle
		masqueBlockId("ligne_conventionelle");
		if (chk_type_ligne.checked == true) afficheBlockId("centrales");
		else																
		{
			masqueBlockId("centrales");
			masqueBlockId("cassiope_mezzo_forte_piano");
			masqueBlockId("valif_form");
		}
	}
	
	//Piano Mezzo ou forte?
	if (chk_type_ligne.id == "chk_cassiopee_piano")
	{
		//Set la case à cocher chk_cassiopee_mezzo_forte à false;	
		frm.chk_cassiopee_mezzo_forte.checked = false;
		afficheBlockId("cassiope_mezzo_forte_piano");
		//cache le capteur propre au mezzo forte
		masqueBlockId("brgv");
		//change l'intitulé du fieldset
		legend_obj = getEltById("leg_cassiope_mezzo_forte_piano");
		legend_obj.firstChild.nodeValue = "Ligne adressable Cassiopée Piano";
		//Affichage du bouton de calcul
		afficheBlockId("valif_form");
	}
	if (chk_type_ligne.id == "chk_cassiopee_mezzo_forte")
	{
		//Set la case à cocher chk_cassiopee_piano à false;	
		frm.chk_cassiopee_piano.checked = false;
		afficheBlockId("cassiope_mezzo_forte_piano");
		//affiche le capteur propre au mezzo forte
		afficheBlockId("brgv");
		//change l'intitulé du fieldset
		legend_obj = getEltById("leg_cassiope_mezzo_forte_piano");
		legend_obj.firstChild.nodeValue = "Ligne adressable Cassiopée Mezzo / Forte";
		//Affichage du bouton de calcul
		afficheBlockId("valif_form");
	}
}

function calc_resultat()
{
	//Verifie quel type de ligne on doit calculer
	afficheBlockId("pourcentage");
	afficheBlockId("progress_bar");
	if (frm.chk_adressable.checked == true) calc_resultat_ligne_adressable();
	else																		calc_resultat_ligne_conventionelle();	
}

/**
 * jt_ProgressBar.js - Progress Bar widget
 *
 * @version 29 Apr 2005
 * @author  Joseph Oster, wingo.com, Copyright (c) 2005-2006
 */

jt_ProgressBar = function(parent, width, fontSize, barClass) {
  // constructor for Progress Bar object; 'width' and 'fontSize' in pixels
  this.pixels = width;
  this.outerDIV = document.createElement("div");
  this.outerDIV.id = "progress_bar";
  this.outerDIV.style.border = "1px solid #666666";
  this.outerDIV.style.background = "#FFFFFF";
  this.outerDIV.style.fontFamily = "Arial,Verdana";
  this.outerDIV.style.fontSize = fontSize + "px";
  this.outerDIV.style.width = (width + 2) + "px";
  this.outerDIV.style.textAlign = "left";
  parent.appendChild(this.outerDIV);

  this.fillDIV = document.createElement("div");
  this.fillDIV.style.textAlign = "right";
  this.fillDIV.style.overflow = "hidden";
  this.fillDIV.innerHTML = "x";
  this.fillDIV.style.width = "0px";
  if (barClass) this.fillDIV.className = barClass;
  else {
    this.fillDIV.style.background = "#00008b";
    this.fillDIV.style.border = "1px solid #FFFFFF";
    this.fillDIV.style.color = "#FFFFFF";
    }
  this.outerDIV.appendChild(this.fillDIV);
  }

jt_ProgressBar.prototype.setPercent = function(pct) {
  // expects 'pct' values between 0.0 and 1.0
  var fillPixels;
  if (pct < 1.0) fillPixels = Math.round(this.pixels * pct);
  else { // avoid round off error
    pct = 1.0;
    fillPixels = this.pixels;
    }
  this.fillDIV.innerHTML = Math.round(100 * pct) + "%";
  this.fillDIV.style.width = fillPixels + "px";
  }

