function bilan(){
	popW=270;nbW=70;getAllSoldes();Idx=0;if(if1.nm1)if1.bilan();Dtls=new Array()
	bilanActif();ta=tx
	bilanPassif()
	txt=	styles(popW,nbW)+
			"<table border=0>"+
				"<td valign=top width="+(popW+nbW+(if1.nm1?nbW*2:19)+55)+"><div style='position:relative;margin:0px'>"+ta+"</div></td>"+
				"<td valign=top width="+(popW+nbW+(if1.nm1?nbW*2:19)+55)+"><div style='position:relative;margin:0px'>"+tx+"</div></td>"+
			"</table>"
	fnt="bilan()";popUp("<font color=orange><b>BILAN</b></font>",txt)
	//setTimeout("with(document.getElementById('popContent'))style.width=parseInt(offsetWidth+99)+'px'",333)
}

function sectionB(t){titre("&nbsp;"+t)}
function ligneB(t,c,c2){
	getRegSoldes(c);if(if1.nm1){if1.getRegSoldes(c);if1.tv+=if1.w}
	v=w;tv+=parseInt(w);w3=0
	var c3="";if(c2!=undefined){
		if(c2.indexOf("_")!=-1){
			var c1=c;var x=c1.split(/[\+\-]/g);
			for(var i=0;i<x.length;i++){
				y=x[i];
				if(y!=""){
					yl=y.length;if(c1.substr(0,yl)!=y)yl++;
					z=c1.substr(0,yl);c1=c1.substr(yl);
					var u=z.substr(0,1);if(u=="-"||u=="+")z=z.substr(1);else u="+"
					if(c2.indexOf("_8")!=-1)c3+=u+z.substr(0,1)+"8"+z.substr(1)
					if(c2.indexOf("_9")!=-1)c3+=u+z.substr(0,1)+"9"+z.substr(1)
				}
			}
		}else if(c2!="")c3=c2
	}
	dt=new Array();if(c3!=""){// recherche des soldes des _
		var det=dtls;getRegSoldes(c3);dt=dtls;dtls=det
		w3=w;tv+=parseInt(w);tv1+=parseInt(w);//details=det+details
		v+=w;if(if1.nm1){if1.v=if1.w;if1.getRegSoldes(c3);if1.w+=if1.v}
	}
	if(v||w3){
		tx+=	"<div style='position:relative;background-color:#ffffff;margin-top:3px;margin-bottom:5px'>"+
					"<div class=t1>"+
						"<a class=acl id=a"+Idx+" href=\"javascript:showDetail("+Idx+")\">+</a>"+
						t+
					"</div>"+
					"<div class=v1 style='background-color:#eeeeee;border-color:#aaaaaa;border-width:1px 0px 1px 0px;padding-right:3px'>"+nm2ds(v)+"</div>"+
					(if1.w?
						"<div class=v2 style='background-color:#eeeeee;border-color:#aaaaaa;border-width:1px 0px 1px 0px;padding-right:3px'>"+nm2ds(if1.w)+"</div>"+
						(v?"<div style='position:absolute;width:40px;top:1px;left:"+parseInt(popW+3*nbW+10)+"px;text-align:right'>"+ecart(v,if1.w)+"</div>":"")
					:"")+
					(w3?"<div class=v0 style='padding-right:3px'>"+nm2ds(w3)+"</div>":"")+
				"</div>"+
				"<div id=D"+Idx+" class=dn>"
					var x=cleanCompte(dt);		for(var i=0;i<x.length;i++)	tx+=	showOps(x[i][0]).replace(/ \class=v1/g," class=v"+(2+okDecal)+"")
					var x=cleanCompte(dtls);	for(var i=0;i<x.length;i++)	tx+=	showOps(x[i][0])
		if(if1.w){
			var x=",";for(var i=0;i<dtls.length;i++)x+=dtls[i][0]+",";
			if(if1.Dtls[Idx])for(var i=0;i<if1.Dtls[Idx].length;i++)if(x.indexOf(","+if1.Dtls[Idx][i][0]+",")==-1){
				var nov=if1.Dtls[Idx][i][0]
				tx+=	"<div style='position:relative;background-color:#ffffff'>"+	
						"<div class=v3>"+nm2ds(if1.sld[nov])+"</div>"+
						"<div class=t3>"+
							nov+" "+if1.getNomCompte(nov)+
						"</div>"+
					"</div>"
			}
		}
		tx+=	"</div>"
		Idx++
	}
}
function totalB(t,a,b){
	tv1=0;total(t,a,b,"#eeeeee;border-width:1px 0px 1px 0px;border-color:#aaaaaa;margin-top:2px")
	if(if1.nm1){
		var v=eval("if1."+(a!="intermediaire"?a:"tv"))
		var t1="";if(v!=0)t1="<div style='position:absolute;width:40px;top:1px;left:"+parseInt(popW+3*nbW+10)+"px;text-align:right'>"+ecart(a,v)+"</div>"
		if(eval(a)){
			tx=tx.substr(0,tx.length-6)+"<div class=v2>"+nm2ds(v)+"</div>"+t1+"</div>"
		}else{
			//tx+=line2V("",eval(a),v,"#eeeeee;border-width:1px 0px 1px 0px;border-color:#aaaaaa;margin-top:2px")
			//tx=tx.substr(0,tx.length-6)+t1+"</div>"
		}
	}
}
function totalsectionB(t,n,m){
	totalsection(t,eval(n),m,"#cccccc;border-width:1px 0px 1px 0px;border-color:#777777;margin-top:2px")
	if(if1.nm1){
		var v=eval("with(if1)("+n+")")
		tx=	tx.substr(0,tx.length-6)+
				"<div class=v2>"+nm2ds(v)+"</div>"+
				(v&&v!=0?"<div style='position:absolute;width:40px;top:1px;left:"+parseInt(popW+3*nbW+10)+"px;text-align:right'>"+ecart(n,v)+"</div>":"")+
			"</div>"
	}
}

function bilanActif(){
	tx="";tv=0;tv1=0;okDecal=1;v=0

	//sectionB("<font color=orange></font>");//20+21+22+23+24+25+26+27				-269-279		-229+109

	sectionB("IMMOBILISATIONS INCORPORELLES");													//109+20								+232+237
	ligneB("Capital souscrit non appelé", "d109", "");												//109?
	ligneB("Frais d'établissement", "201", "");														//201
	ligneB("Frais de recherche et développement", "203", "_8 _9");									//203
	ligneB("Concessions, brevets et droits similaires", "205", "_8 _9");							//205
	ligneB("Fonds commercial", "206+207", "_8 _9");													//206+207
	is2033[10]=v;is2033[10]=w3;
	ligneB("Autres immobilisations incorporelles", "20-201-203-205-206-207+232", "_8 _9");			//200+202+204+208+209+232
	ligneB("Avances et acomptes sur immobilisations incorporelles", "237", "_8 _9");				//237
	is2033[14]=tv-is2033[10];is2033[14]=tv1-is2033[10];

	sectionB("IMMOBILISATIONS CORPORELLES");													//21+22+23+24+25-229					-232-237
	ligneB("Terrains", "211+212", "_8 _9");															//211+212
	ligneB("Constructions", "213+214", "_8 _9");													//213+214
	ligneB("Installations techniques matériel et outillage industriels", "215", "_8 _9");			//215
	ligneB("Autres immobilisations corporelles", "21-211-212-213-214-215+22-229+24+25", "_8 _9");	//210+216+217+218+219+22-229+24+25
	is2033[28]=w3
	is2033[30]=tv;
	ligneB("Immobilisations en cours", "23-232-237-238", "_8 _9");									//23-232-237-238
	ligneB("Avances et acomptes", "238", "_8 _9");													//238
	is2033[30]=tv

	sectionB("IMMOBILISATIONS FINANCIERES");													//26+27-269-279
	ligneB("Participations évaluées selon la méthode de mise en équivalence", "263", "_9");			//263
	ligneB("Autres participations", "26-263-267-268-269", "_9");									//260+261+262+264+265+266
	ligneB("Créances rattachées à des participations", "267+268", "_9");							//267+268
	ligneB("Autres titres immobilisés", "271+272+273+27682", "_9");									//271+272+273+27682
	ligneB("Prêts", "274+27684", "_9");																//274+27684
	ligneB("Autres immobilisations financières", "27-271-272-273-274-27682-27684-279", "_9");		//270+275+276+277-27682-27684+278
	is2033[40]=tv-is2033[10]-is2033[14]-is2033[28];is2033[40]=tv1-is2033[10]-is2033[14]-is2033[28];
	totalB("TOTAL I", "totalIB", "totalIA");
	is2033[48]=tv;//is2033[44]=tv1;

	sectionB("STOCKS ET EN COURS");																//30-39
	ligneB("Matières premières, approvisionnements", "3-33-34-35-37-39", "_9");						//30+31+32+36+38
	ligneB("En cours de production de biens", "33", "_9");											//33
	ligneB("En cours de production de services", "34", "_9");										//34
	ligneB("Produits intermédiaires et finis", "35", "_9");											//35
	is2033[50]=tv;is2033[50]=tv1;
	ligneB("Marchandises", "37", "_9");																//37
	is2033[60]=tv-is2033[50];is2033[60]=tv1-is2033[50];

	ligneB("Avances et acomptes versés sur commandes", "d4091", "");									//4091
	is2033[64]=v;

	sectionB("CREANCES");																		//18+4-49+41199999-40199999-4091+5-59	-48+486-476-477
	ligneB("Clients et comptes rattachés", "+0-c08+d41+c41199999", "49-495-496");							//41+41199999
	is2033[68]=v;
	ligneB("Autres créances", "+d40-d40199999-d4091-d4562-d476-d477+d42+d43+d44+d45+d46+d47+d18", "495+496");		//18+40+42+43+44+45+46+47-40199999-4091-4562-476-477
	is2033[72]=v;
	ligneB("Capital souscrit et appelé, non versé", "d4562", "");									//4562
	//is2033[72]=tv-is2033[50]-is2033[60]-is2033[64]-is2033[68];is2033[72]=tv1-is2033[50]-is2033[60]-is2033[64]-is2033[68];

	ligneB("Valeurs mobilières de placement", "d50", "590");											//50
	is2033[80]=v;
	ligneB("Disponibilités", "d51+d52+53+d54+d55+d56+d57+d58", "59-590");									//5-50-59
	is2033[84]=v;is2033[86]=v;
	ligneB("Charges constatées d'avance", "486", "");												//486
	is2033[92]=v;is2033[92]=w3;
	totalB("TOTAL II", "totalIIB", "totalIIA");
	is2033[96]=totalIIB;//is2033[96]=totalIIA;
																								//169-487								+48-486+476+477
	ligneB("Charges à répartir sur plusieurs exercices (III)", "d480+481+d482+d483+d484+d485+d488+d489", "");//48-486-487
	ligneB("Primes de remboursement des obligations (IV)", "169", "");								//169
	ligneB("Ecart de conversion Actif (V)", "d476+d477", "");											//476+477

	is2033[112]=totalIB+totalIIB+tv//;is2033[110]=totalIA+totalIIA+tv;
	totalsectionB("TOTAL GENERAL (I+II+III+IV+V)", "totalIB+totalIIB");
	makeFrame("ACTIF",1)
}

function bilanPassif(){
	tx="";tv=0;tv1=0;okDecal=0;totalI=0;totalII=0;totalIII=0;totalIV=0;

	//sectionB("<font color=orange></font>");

	getRegSoldes("1014+1013+1018")
	ligneB("Capital (Dont versé: "+ parseInt(w/100) +" )", "100+101+102+103+108+c109");//101capSoc 109actionnairCapSouscNonAppelé
	is2033[120]=v
	ligneB("Primes d'émission, de fusion, d'apport", "104");
	ligneB("Ecart de réévaluation", "105+107");//105ecartRéévaluation 107écartEquivalence
	is2033[124]=tv-v
	//100-106
	sectionB("RESERVES");
	ligneB("Réserve légale", "1061");
	is2033[126]=v
	ligneB("Réserves statutaires ou contractuelles", "1063");
	is2033[129]=v
	ligneB("Réserves réglementées", "1062+1064");
	is2033[130]=v+is2033[129]
	ligneB("Autres réserves", "106-1061-1062-1063-1064");
	is2033[132]=v
	//106
//10
	ligneB("Report à nouveau", "11+12+19");//11reportNouveau 110Crédi 119débit
	is2033[134]=v
//11+12+19
	ligneB("RESULTAT DE L'EXERCICE (bénéfice ou perte)", "-0-1-2-3-4-5");//12
	is2033[136]=v

	ligneB("Subventions d'investissement", "13");
	is2033[140]=v
	ligneB("Provisions réglementées", "14");
	is2033[140]+=v
//13+14
	totalB("TOTAL I", "totalI");
	is2033[142]=totalI

	ligneB("Produit des émissions de titres participatifs", "1671");
	ligneB("Avances conditionnées", "1672+1674+1676+229");
//1671+229						+1672+1674+1676
	totalB("TOTAL II", "totalII");
	is2033[154]=totalII

	ligneB("Provisions pour risques", "151");
	is2033[154]=v
	ligneB("Provisions pour charges", "15-151");
	is2033[154]+=v
//15
	totalB("TOTAL III", "totalIII");

	sectionB("DETTES FINANCIERES");//16
	ligneB("Emprunts obligataires convertibles", "161+16881");//161
	ligneB("Autres emprunts obligataires", "163+16883");//163
	ligneB("Emprunts et dettes auprès des établissements de crédit", "164+16884+c51+c52+c54+c55+c56+c57+c58");//164
	ligneB("Emprunts et dettes financières divers", "16+17+18+c426+c45-c457-161-163-164-1671-1672-1674-1676-16881-16883-16884-169");
	is2033[169]=v
//16+17+18+5-50-53-1671-169		-1672-1674-1676
	ligneB("Avances et acomptes reçus sur commandes en cours", "c4191");
	is2033[164]=v
//4191
	sectionB("DETTES D'EXPLOITATION");
	ligneB("Dettes fournisseurs et comptes rattachés", "c08+c40+d40199999-c404-c405-c4084");
	is2033[166]=v
	ligneB("Dettes fiscales et sociales", "c42+c43+c44+c457-c426");
	is2033[166]+=v
//40+42+43+44+457-426+40199999-4084			-404-405
	ligneB("Dettes sur immobilisations et comptes rattachés", "269+279+c404+c405+c4084");
	is2033[166]+=v
	ligneB("Autres dettes", "c41+c452+c453+c454+c46+c47+c50-c41199999-c4191-c476-c477");
	//is2033[172]=v
//269+279+4084+41+452+453+454+46+47+50-41199999-4191-476-477		+404+405
	ligneB("Produits constatés d'avance", "c480+c482+c483+c484+c485+c487+c488+c489");//48-481-486
	is2033[174]=v
	totalB("TOTAL IV", "totalIV");
	is2033[176]=totalIV;is2033[172]=totalIV
//480+482+483+484+485+487+488+489
	ligneB("Ecarts de conversion passif (V)", "c476+c477");
	is2033[174]+=v
	is2033[180]=totalI+totalII+totalIII+totalIV
	totalsectionB("TOTAL GENERAL (I+II+III+IV+V)", "totalI+totalII+totalIII+totalIV");
	makeFrame("PASSIF",1)
}
/*
	private double getSumCompte(int sum, String like) throws SQLException, Exception {

		request1 = "select sum(Montant_D) as debit, sum(Montant_C) as credit from "+ base + ".COMPTE c,"+ base +".OPERATION o where c.Numero_Compte=o.Numero_Compte and  o.Date_Op>="+ debutPeriode +" and o.Date_Op<="+ finPeriode +" and"
		request  = request1 +"  c.Numero_Compte<>'41100000' and c.Numero_Compte<>'40100000' and c.Numero_Compte like '"+ like +"' group by c.Numero_Compte";

			if (sum==0)
				val += this.titre.equalsIgnoreCase("Passif")?credit-debit:debit-credit;
			else if (sum==-1)
				val += debit>credit?debit-credit:0;
			else if (sum==1)
				val += credit>debit?credit-debit:0;

		if (like.startsWith("401%") || like.startsWith("40%") || like.startsWith("4%")) {
			if (exo_complet) {
				request = request1 +" (c.Compte_Gen='F' or c.Numero_Compte='40100000') and  ( or Date_Op<"+ debutPeriode +") group by c.Numero_Compte";
			}
			else {
				request = request1 +" (c.Compte_Gen='F' or c.Numero_Compte='40100000')  group by c.Numero_Compte";
			}
				if (sum==0)
					val += this.titre.equalsIgnoreCase("Passif")?credit-debit:debit-credit;
				else if (sum==-1)
					val += debit>credit?debit-credit:0;
				else if (sum==1)
					val += credit>debit?credit-debit:0;

		if (like.startsWith("411%") || like.startsWith("41%") || like.startsWith("4%")) {
			if (exo_complet) {
				request = request1 +" (c.Compte_Gen='C' or c.Numero_Compte='41100000') and ( or Date_Op<"+ debutPeriode +") group by c.Numero_Compte";
			}
			else {
				request  = request1 +" (c.Compte_Gen='C' or c.Numero_Compte='41100000') " group by c.Numero_Compte";
			}
				if (sum==0)
					val += this.titre.equalsIgnoreCase("Passif")?credit-debit:debit-credit;
				else if (sum==-1)
					val += debit>credit?debit-credit:0;
				else if (sum==1)
					val += credit>debit?credit-debit:0;

	}
*/
