// Surbrillance
function fctSurbrillance(element) {

	// Annuler tout
	document.getElementById("DescriptionPuissanceCourant").className='description-inactive';
	document.getElementById("DescriptionFilsGaine").className='description-inactive';
	document.getElementById("DescriptionFilsProtections").className='description-inactive';

	// Surbrillance
	if (element!="Aucun") {
	document.getElementById(element).className='description-active';
	}
}
// Afficher / Masquer les outils
function fctMontrerCacher(element) {

	// Masquer tout
	document.getElementById("Introduction").className='outil-cache';
	document.getElementById("PuissanceCourant").className='outil-cache';
	document.getElementById("FilsGaine").className='outil-cache';
	document.getElementById("FilsProtections").className='outil-cache';

	// Afficher
	document.getElementById(element).className='outil-utilise';
}

// Formater un nombre
function format_number(nombre,precision)
{

chaine=nombre.toString(10);

if (precision<=0) {precision=-1;}
if (chaine.indexOf('.')>-1) {indice=chaine.indexOf('.')+1+precision;}
else if (chaine.indexOf(',')>-1) {indice=chaine.indexOf(',')+1+precision;}
else {indice=chaine.length;}

return chaine.slice(0,indice);

}

// Calcul du courant
function calculer_1()
{

if (isNaN(document.form1.puissance_1.value)|document.form1.puissance_1.value=='') document.form1.puissance_1.value=0;

puissance=document.form1.puissance_1.value;

courant_mono=puissance/(230*0.9);
courant_tri=puissance/(400*Math.sqrt(3*0.9));

document.form1.courant_1_mono.value=format_number(courant_mono,2);
document.form1.courant_1_tri.value=format_number(courant_tri,2);

}

// Calcul de la puissance
function calculer_2()
{

if (isNaN(document.form2.courant_2.value)|document.form2.courant_2.value=='') document.form2.courant_2.value=0;
if (isNaN(document.form2.tension_2.value)|document.form2.tension_2.value=='') document.form2.tension_2.value=0;
if (isNaN(document.form2.phi_2.value)|document.form2.phi_2.value=='') document.form2.phi_2.value=0;

courant=document.form2.courant_2.value;
tension=document.form2.tension_2.value;
phi=document.form2.phi_2.value;

puissance_mono=tension*courant*phi;
puissance_tri=tension*courant*Math.sqrt(phi*3);

document.form2.puissance_2_mono.value=format_number(puissance_mono,0);
document.form2.puissance_2_tri.value=format_number(puissance_tri,0);

}

// Tableau des surfaces interieures des gaines ict
function type_gaines_ict()
	{
	this[0] = 30;		// 16 mm
	this[1] = 52;		// 20 mm
	this[2] = 88;		// 25 mm
	this[3] = 155;		// 32 mm
	this[4] = 255;		// 40 mm
	this[5] = 411;		// 50 mm
	this[6] = 724;		// 63 mm
	}

// Tableau des surfaces interieures des gaines iro
function type_gaines_iro()
	{
	this[0] = 44;		// 16 mm
	this[1] = 75;		// 20 mm
	this[2] = 120;		// 25 mm
	this[3] = 202;		// 32 mm
	this[4] = 328;		// 40 mm
	this[5] = 514;		// 50 mm
	this[6] = 860;		// 63 mm
	}

// Tableau des surfaces des fils
function type_fils()
	{
	this[0] = 8.55;		// 1.5 mm²
	this[1] = 11.9;		// 2.5 mm²
	this[2] = 15.2;		// 4 mm²
	this[3] = 22.9;		// 6 mm²
	this[4] = 36.3;		// 10 mm²
	this[5] = 50.3;		// 16 mm²
	}

// Calcul du nombre de fils par conduit
function fct_calculer()
{
var gaines_ict=new type_gaines_ict();
var gaines_iro=new type_gaines_iro();
var fils=new type_fils();

if (isNaN(document.form3.fil_15.value)|document.form3.fil_15.value=='') document.form3.fil_15.value=0;
if (isNaN(document.form3.fil_25.value)|document.form3.fil_25.value=='') document.form3.fil_25.value=0;
if (isNaN(document.form3.fil_40.value)|document.form3.fil_40.value=='') document.form3.fil_40.value=0;
if (isNaN(document.form3.fil_60.value)|document.form3.fil_60.value=='') document.form3.fil_60.value=0;
if (isNaN(document.form3.fil_10.value)|document.form3.fil_10.value=='') document.form3.fil_10.value=0;
if (isNaN(document.form3.fil_16.value)|document.form3.fil_16.value=='') document.form3.fil_16.value=0;

nb_fil_15=document.form3.fil_15.value;
nb_fil_25=document.form3.fil_25.value;
nb_fil_40=document.form3.fil_40.value;
nb_fil_60=document.form3.fil_60.value;
nb_fil_10=document.form3.fil_10.value;
nb_fil_16=document.form3.fil_16.value;

total=nb_fil_15*fils[0]+nb_fil_25*fils[1]+nb_fil_40*fils[2]+nb_fil_60*fils[3]+nb_fil_10*fils[4]+nb_fil_16*fils[5];

if (total<gaines_ict[0]) choix_ict=16;
if (total>=gaines_ict[0]&total<gaines_ict[1]) choix_ict=20;
if (total>=gaines_ict[1]&total<gaines_ict[2]) choix_ict=25;
if (total>=gaines_ict[2]&total<gaines_ict[3]) choix_ict=32;
if (total>=gaines_ict[3]&total<gaines_ict[4]) choix_ict=40;
if (total>=gaines_ict[4]&total<gaines_ict[5]) choix_ict=50;
if (total>=gaines_ict[5]&total<gaines_ict[6]) choix_ict=63;

if (total<gaines_iro[0]) choix_iro=16;
if (total>=gaines_iro[0]&total<gaines_iro[1]) choix_iro=20;
if (total>=gaines_iro[1]&total<gaines_iro[2]) choix_iro=25;
if (total>=gaines_iro[2]&total<gaines_iro[3]) choix_iro=32;
if (total>=gaines_iro[3]&total<gaines_iro[4]) choix_iro=40;
if (total>=gaines_iro[4]&total<gaines_iro[5]) choix_iro=50;
if (total>=gaines_iro[5]&total<gaines_iro[6]) choix_iro=63;

document.form3.resultat_ict.value=choix_ict;
document.form3.resultat_iro.value=choix_iro;

}

// Choix des circuits
function choix_circuit(num_choix) {

document.getElementById('choix1.1').style.border='none';
document.getElementById('choix1.2').className='outil-cache';

document.getElementById('choix2.1').style.border='none';
document.getElementById('choix2.2').className='outil-cache';

document.getElementById('choix3.1').style.border='none';
document.getElementById('choix3.2').className='outil-cache';

document.getElementById('choix4.1').style.border='none';
document.getElementById('choix4.2').className='outil-cache';

document.getElementById('choix11.3').className='outil-cache';
document.getElementById('choix21.3').className='outil-cache';
document.getElementById('choix22.3').className='outil-cache';
document.getElementById('choix31.3').className='outil-cache';
document.getElementById('choix32.3').className='outil-cache';
document.getElementById('choix33.3').className='outil-cache';
document.getElementById('choix34.3').className='outil-cache';
document.getElementById('choix41.3').className='outil-cache';
document.getElementById('choix42.3').className='outil-cache';
document.getElementById('choix43.3').className='outil-cache';
document.getElementById('choix44.3').className='outil-cache';

document.getElementById('choix'+num_choix+'.1').style.border='solid 2px #FF0000';
document.getElementById('choix'+num_choix+'.2').className='outil-utilise';

}

// Choix secondaire
function second_choix(num_choix) {

document.getElementById('choix21.2').style.border='none';
document.getElementById('choix21.3').className='outil-cache';
document.getElementById('choix22.2').style.border='none';
document.getElementById('choix22.3').className='outil-cache';

document.getElementById('choix31.2').style.border='none';
document.getElementById('choix31.3').className='outil-cache';
document.getElementById('choix32.2').style.border='none';
document.getElementById('choix32.3').className='outil-cache';
document.getElementById('choix33.2').style.border='none';
document.getElementById('choix33.3').className='outil-cache';
document.getElementById('choix34.2').style.border='none';
document.getElementById('choix34.3').className='outil-cache';

document.getElementById('choix41.2').style.border='none';
document.getElementById('choix41.3').className='outil-cache';
document.getElementById('choix42.2').style.border='none';
document.getElementById('choix42.3').className='outil-cache';
document.getElementById('choix43.2').style.border='none';
document.getElementById('choix43.3').className='outil-cache';
document.getElementById('choix44.2').style.border='none';
document.getElementById('choix44.3').className='outil-cache';

// document.getElementById('choix'+num_choix).style.border='solid 2px #FF0000';
document.getElementById('choix'+num_choix+'.2').style.border='solid 2px #FF0000';
document.getElementById('choix'+num_choix+'.3').className='outil-utilise';

}
