function calculTransplanter(resultObj, obj1,val1, obj2,val2, obj3,val3, obj4,val4)
{
	var result = 0;
	if(val1!=null)
	{
		if(isNaN(obj1.value))obj1.value=0;
		result += (obj1.value/val1);
	}
	if(val2!=null)
	{
		if(isNaN(obj1.value))obj1.value=0;
		result += (obj2.value/val1);
	}
	if(val3!=null)
	{
		if(isNaN(obj1.value))obj1.value=0;
		result += (obj3.value/val1);
	}
	if(val4!=null)
	{
		if(isNaN(obj1.value))obj1.value=0;
		result += (obj4.value/val1);
	}
	resultObj.value = Math.ceil(result);
}

function calculSurfaceTerreau(ratios1,ratios2,theForm)
{
	if(ratios1 == null)
	{
		var ratio = (document.getElementById('pied2').checked ? ratios2[0]:ratios2[1]);
		if(isNaN(theForm.txt4.value)) theForm.txt4.value=0;
		if(isNaN(theForm.txt5.value)) theForm.txt5.value=0;
		theForm.txt6.value = Math.ceil((theForm.txt4.value*theForm.txt5.value)/ratio);
	}
	else
	{
		var ratio = (document.getElementById('pied1').checked ? ratios1[0]:ratios1[1]);
		if(isNaN(theForm.txt1.value)) theForm.txt1.value=0;
		if(isNaN(theForm.txt2.value)) theForm.txt2.value=0;
		theForm.txt3.value = Math.ceil((theForm.txt1.value*theForm.txt2.value)/ratio);
	}
}

function calculSurface(ratios,theForm)
{
	var ratio = (document.getElementById('pied').checked ? ratios[0]:ratios[1]);
	if(isNaN(theForm.txt1.value)) theForm.txt1.value=0;
	if(isNaN(theForm.txt2.value)) theForm.txt2.value=0;
	theForm.txt3.value = Math.ceil((theForm.txt1.value*theForm.txt2.value)/ratio);
}

function calculSurfaceDouble(ratios1,ratios2,theForm)
{
	if(ratios1 == null)
	{
		var ratio = (document.getElementById('pied2').checked ? ratios2[0]:ratios2[1]);
		if(isNaN(theForm.txt4.value)) theForm.txt4.value=0;
		if(isNaN(theForm.txt5.value)) theForm.txt5.value=0;
		theForm.txt6.value = Math.ceil((theForm.txt4.value*theForm.txt5.value)/ratio);
	}
	else
	{
		var ratio = (document.getElementById('pied1').checked ? ratios1[0]:ratios1[1]);
		if(isNaN(theForm.txt1.value)) theForm.txt1.value=0;
		if(isNaN(theForm.txt2.value)) theForm.txt2.value=0;
		theForm.txt3.value = Math.ceil((theForm.txt1.value*theForm.txt2.value)/ratio);
	}
}

function calculSurfaceDblNoRatio(amount1,amount2,theForm)
{
	if(amount1 == null)
	{
		if(isNaN(theForm.txt4.value)) theForm.txt4.value=0;
		if(isNaN(theForm.txt5.value)) theForm.txt5.value=0;
		theForm.txt6.value = Math.ceil( (theForm.txt4.value+theForm.txt5.value)*amount2 );
	}
	else
	{
		if(isNaN(theForm.txt1.value)) theForm.txt1.value=0;
		if(isNaN(theForm.txt2.value)) theForm.txt2.value=0;
		theForm.txt3.value = Math.ceil( (theForm.txt1.value*amount1[0])+(theForm.txt2.value*amount1[1]) );
	}
}

function calculSurfaceTriple(ratios1,ratios2,ratios3,theForm)
{
	if(ratios1 == null)
	{
		if(ratios2 == null)
		{
			var ratio = (document.getElementById('pied3').checked ? ratios3[0]:ratios3[1]);
			if(isNaN(theForm.txt7.value)) theForm.txt7.value=0;
			if(isNaN(theForm.txt8.value)) theForm.txt8.value=0;
			theForm.txt9.value = Math.ceil((theForm.txt7.value*theForm.txt8.value)/ratio);
		}
		else
		{
			var ratio = (document.getElementById('pied2').checked ? ratios2[0]:ratios2[1]);
			if(isNaN(theForm.txt4.value)) theForm.txt4.value=0;
			if(isNaN(theForm.txt5.value)) theForm.txt5.value=0;
			theForm.txt6.value = Math.ceil((theForm.txt4.value*theForm.txt5.value)/ratio);
		}
	}
	else
	{
		var ratio = (document.getElementById('pied1').checked ? ratios1[0]:ratios1[1]);
		if(isNaN(theForm.txt1.value)) theForm.txt1.value=0;
		if(isNaN(theForm.txt2.value)) theForm.txt2.value=0;
		theForm.txt3.value = Math.ceil((theForm.txt1.value*theForm.txt2.value)/ratio);
	}
}

function calculContenant(theForm)
{
//	var theForm = document.frmCalculateur;
	var obj1  = theForm.txt1;
	var obj2  = theForm.txt2;
	var obj3  = theForm.txt3;
	var obj4  = theForm.txt4;
	var obj5  = theForm.txt5;
	var obj6  = theForm.txt6;
	var obj7  = theForm.txt7;
	var obj8  = theForm.txt8;
	var obj9  = theForm.txt9;
	var obj10 = theForm.txt10;
	var obj11 = theForm.txt11;
	var obj12 = theForm.txt12;
	
	var resultObj = theForm.txt13;
	
	if(isNaN(obj1.value)&&obj1.value!='')obj1.value=0;
	if(isNaN(obj2.value)&&obj2.value!='')obj2.value=0;
	if(isNaN(obj3.value)&&obj3.value!='')obj3.value=0;
	if(isNaN(obj4.value)&&obj4.value!='')obj4.value=0;
	if(isNaN(obj5.value)&&obj5.value!='')obj5.value=0;
	if(isNaN(obj6.value)&&obj6.value!='')obj6.value=0;
	if(isNaN(obj7.value)&&obj7.value!='')obj7.value=0;
	if(isNaN(obj8.value)&&obj8.value!='')obj8.value=0;
	if(isNaN(obj9.value)&&obj9.value!='')obj9.value=0;
	if(isNaN(obj10.value)&&obj10.value!='')obj10.value=0;
	if(isNaN(obj11.value)&&obj11.value!='')obj11.value=0;
	if(isNaN(obj12.value)&&obj12.value!='')obj12.value=0;
	
	var val1  = parseInt(obj1.value);
	var val2  = parseInt(obj2.value);
	var val3  = parseInt(obj3.value);
	var val4  = parseInt(obj4.value);
	var val5  = parseInt(obj5.value);
	var val6  = parseInt(obj6.value);
	var val7  = parseInt(obj7.value);
	var val8  = parseInt(obj8.value);
	var val9  = parseInt(obj9.value);
	var val10 = parseInt(obj10.value);
	var val11 = parseInt(obj11.value);
	var val12 = parseInt(obj12.value);
	if(isNaN(val1))val1=0;
	if(isNaN(val2))val2=0;
	if(isNaN(val3))val3=0;
	if(isNaN(val4))val4=0;
	if(isNaN(val5))val5=0;
	if(isNaN(val6))val6=0;
	if(isNaN(val7))val7=0;
	if(isNaN(val8))val8=0;
	if(isNaN(val9))val9=0;
	if(isNaN(val10))val10=0;
	if(isNaN(val11))val11=0;
	if(isNaN(val12))val12=0;
	resultObj.value = Math.ceil(( (parseFloat(val1)*5.5)+(parseFloat(val2)*9)+(parseFloat(val3)*13)+(parseFloat(val4)*3.7)+(parseFloat(val5)*7)+(parseFloat(val6)*11)+(parseFloat(val7)*20)+(parseFloat(val8)*30)+(parseFloat(val9)*44)+(parseFloat(val10)*5.2)+(parseFloat(val11)*13)+(parseFloat(val12)*24) )/30);
	
}

window.onload =
function()
{	
	var allForms = document.getElementsByTagName('FORM');
	for(var i=0;i<allForms.length;i++)
	{
		var theForm = allForms[i];
		var calcId = (theForm.name.indexOf('frmCalculateur')>-1?theForm.name.substr(14,theForm.name.length-14):0);
		switch(parseInt(calcId))
		{
			case 9:
			{
				// ok
				theForm.txt1.onkeyup = function(){calculContenant(theForm);}
				theForm.txt2.onkeyup = function(){calculContenant(theForm);}
				theForm.txt3.onkeyup = function(){calculContenant(theForm);}
				theForm.txt4.onkeyup = function(){calculContenant(theForm);}
				theForm.txt5.onkeyup = function(){calculContenant(theForm);}
				theForm.txt6.onkeyup = function(){calculContenant(theForm);}
				theForm.txt7.onkeyup = function(){calculContenant(theForm);}
				theForm.txt8.onkeyup = function(){calculContenant(theForm);}
				theForm.txt9.onkeyup = function(){calculContenant(theForm);}
				theForm.txt10.onkeyup = function(){calculContenant(theForm);}
				theForm.txt11.onkeyup = function(){calculContenant(theForm);}
				theForm.txt12.onkeyup = function(){calculContenant(theForm);}
				theForm.txt13.readOnly = true;
				break;
			}
			case 12:
			{
				// ok
				theForm.txt1.onkeyup = function(){calculTransplanter(theForm.txt5,theForm.txt1,7,theForm.txt2,2.25,theForm.txt3,1,theForm.txt4,0.4);}
				theForm.txt2.onkeyup = function(){calculTransplanter(theForm.txt5,theForm.txt1,7,theForm.txt2,2.25,theForm.txt3,1,theForm.txt4,0.4);}
				theForm.txt3.onkeyup = function(){calculTransplanter(theForm.txt5,theForm.txt1,7,theForm.txt2,2.25,theForm.txt3,1,theForm.txt4,0.4);}
				theForm.txt4.onkeyup = function(){calculTransplanter(theForm.txt5,theForm.txt1,7,theForm.txt2,2.25,theForm.txt3,1,theForm.txt4,0.4);}
				theForm.txt5.readonly = true;
				break;
			}
			case 13:
			{
				// ok
				theForm.txt1.onkeyup = function(){calculTransplanter(theForm.txt4,theForm.txt1,7,theForm.txt2,2.25,theForm.txt3,1);}
				theForm.txt2.onkeyup = function(){calculTransplanter(theForm.txt4,theForm.txt1,7,theForm.txt2,2.25,theForm.txt3,1);}
				theForm.txt3.onkeyup = function(){calculTransplanter(theForm.txt4,theForm.txt1,7,theForm.txt2,2.25,theForm.txt3,1);}
				theForm.txt4.readonly = true;
				break;
			}
			case 14:
			{
				// ok
				theForm.txt1.onkeyup = function(){calculTransplanter(theForm.txt5,theForm.txt1,9,theForm.txt2,3,theForm.txt3,1.25,theForm.txt4,0.6);}
				theForm.txt2.onkeyup = function(){calculTransplanter(theForm.txt5,theForm.txt1,9,theForm.txt2,3,theForm.txt3,1.25,theForm.txt4,0.6);}
				theForm.txt3.onkeyup = function(){calculTransplanter(theForm.txt5,theForm.txt1,9,theForm.txt2,3,theForm.txt3,1.25,theForm.txt4,0.6);}
				theForm.txt4.onkeyup = function(){calculTransplanter(theForm.txt5,theForm.txt1,9,theForm.txt2,3,theForm.txt3,1.25,theForm.txt4,0.6);}
				theForm.txt5.readonly = true;
				break;
			}
			case 15:
			{
				// ok
				theForm.txt1.onkeyup = function(){calculTransplanter(theForm.txt3,theForm.txt1,1.8,theForm.txt2,0.75);}
				theForm.txt2.onkeyup = function(){calculTransplanter(theForm.txt3,theForm.txt1,1.8,theForm.txt2,0.75);}
				theForm.txt3.readonly = true;
				break;
			}
			case 16:
			{
				// ok
				theForm.txt1.onkeyup = function(){calculTransplanter(theForm.txt4,theForm.txt1,1.8,theForm.txt2,0.75,theForm.txt3,0.35);}
				theForm.txt2.onkeyup = function(){calculTransplanter(theForm.txt4,theForm.txt1,1.8,theForm.txt2,0.75,theForm.txt3,0.35);}
				theForm.txt3.onkeyup = function(){calculTransplanter(theForm.txt4,theForm.txt1,1.8,theForm.txt2,0.75,theForm.txt3,0.35);}
				theForm.txt4.readonly = true;
				break;
			}
			case 17:
			{
				// ok
				theForm.txt1.onkeyup = function(){calculTransplanter(theForm.txt3,theForm.txt1,10,theForm.txt2,5);}
				theForm.txt2.onkeyup = function(){calculTransplanter(theForm.txt3,theForm.txt1,10,theForm.txt2,5);}
				theForm.txt3.readonly=true;
				break;
			}
			case 18:
			{
				// ok
				theForm.txt1.onkeyup = function(){calculSurface(Array(55,5),theForm);}
				theForm.txt2.onkeyup = function(){calculSurface(Array(55,5),theForm);}
				theForm.txt3.onkeyup = function(){calculSurface(Array(55,5),theForm);}
				document.getElementById('metre').onclick = function(){calculSurface(Array(55,5),theForm);}
				document.getElementById('pied').onclick = function(){calculSurface(Array(55,5),theForm);}
				break;
			}
			case 19:
			{
				// ok
				theForm.txt1.onkeyup = function(){calculSurface(Array(10,1),theForm);}
				theForm.txt2.onkeyup = function(){calculSurface(Array(10,1),theForm);}
				theForm.txt3.onkeyup = function(){calculSurface(Array(10,1),theForm);}
				document.getElementById('metre').onclick = function(){calculSurface(Array(10,1),theForm);}
				document.getElementById('pied').onclick = function(){calculSurface(Array(10,1),theForm);}
				break;
			}
			case 20:
			{
				// ok
				theForm.txt1.onkeyup = function(){calculSurface(Array(65,6),theForm);}
				theForm.txt2.onkeyup = function(){calculSurface(Array(65,6),theForm);}
				theForm.txt3.onkeyup = function(){calculSurface(Array(65,6),theForm);}
				document.getElementById('metre').onclick = function(){calculSurface(Array(65,6),theForm);}
				document.getElementById('pied').onclick = function(){calculSurface(Array(65,6),theForm);}
				break;
			}
			case 21:
			{
				// ok
				theForm.txt1.onkeyup = function(){calculSurface(Array(12,1.1),theForm);}
				theForm.txt2.onkeyup = function(){calculSurface(Array(12,1.1),theForm);}
				theForm.txt3.onkeyup = function(){calculSurface(Array(12,1.1),theForm);}
				document.getElementById('metre').onclick = function(){calculSurface(Array(12,1.1),theForm);}
				document.getElementById('pied').onclick = function(){calculSurface(Array(12,1.1),theForm);}
				break;
			}
			case 22:
			{
				// ok
				theForm.txt1.onkeyup = function(){calculSurface(Array(100,10),theForm);}
				theForm.txt2.onkeyup = function(){calculSurface(Array(100,10),theForm);}
				theForm.txt3.onkeyup = function(){calculSurface(Array(100,10),theForm);}
				document.getElementById('metre').onclick = function(){calculSurface(Array(100,10),theForm);}
				document.getElementById('pied').onclick = function(){calculSurface(Array(100,10),theForm);}
				break;
			}
			case 23:
			{
				// ok
				theForm.txt1.onkeyup = function(){calculSurface(Array(40,4),theForm);}
				theForm.txt2.onkeyup = function(){calculSurface(Array(40,4),theForm);}
				theForm.txt3.onkeyup = function(){calculSurface(Array(40,4),theForm);}
				document.getElementById('metre').onclick = function(){calculSurface(Array(40,4),theForm);}
				document.getElementById('pied').onclick = function(){calculSurface(Array(40,4),theForm);}
				break;
			}
			case 24:
			{
				// ok
				theForm.txt1.onkeyup = function(){calculSurface(Array(135,12.5),theForm);}
				theForm.txt2.onkeyup = function(){calculSurface(Array(135,12.5),theForm);}
				theForm.txt3.onkeyup = function(){calculSurface(Array(135,12.5),theForm);}
				document.getElementById('metre').onclick = function(){calculSurface(Array(135,12.5),theForm);}
				document.getElementById('pied').onclick = function(){calculSurface(Array(135,12.5),theForm);}
				break;
			}
			case 25:
			{
				// ok
				theForm.txt1.onkeyup = function(){calculSurface(Array(110,11),theForm);}
				theForm.txt2.onkeyup = function(){calculSurface(Array(110,11),theForm);}
				theForm.txt3.onkeyup = function(){calculSurface(Array(110,11),theForm);}
				document.getElementById('metre').onclick = function(){calculSurface(Array(110,11),theForm);}
				document.getElementById('pied').onclick = function(){calculSurface(Array(110,11),theForm);}
				break;
			}
			case 26:
			{
				// ok
				theForm.txt1.onkeyup = function(){calculSurface(Array(14.8,1.37),theForm);}
				theForm.txt2.onkeyup = function(){calculSurface(Array(14.8,1.37),theForm);}
				theForm.txt3.onkeyup = function(){calculSurface(Array(14.8,1.37),theForm);}
				document.getElementById('metre').onclick = function(){calculSurface(Array(14.8,1.37),theForm);}
				document.getElementById('pied').onclick = function(){calculSurface(Array(14.8,1.37),theForm);}
				break;
			}
			case 27:
			{
				// ok
				theForm.txt1.onkeyup = function(){calculSurface(Array(1400,130),theForm);}
				theForm.txt2.onkeyup = function(){calculSurface(Array(1400,130),theForm);}
				document.getElementById('metre').onclick = function(){calculSurface(Array(1400,130),theForm);}
				document.getElementById('pied').onclick = function(){calculSurface(Array(1400,130),theForm);}
				break;
			}
			case 28:
			{
				// ok
				theForm.txt1.onkeyup = function(){calculSurface(Array(24,2.2),theForm);}
				theForm.txt2.onkeyup = function(){calculSurface(Array(24,2.2),theForm);}
				document.getElementById('metre').onclick = function(){calculSurface(Array(24,2.2),theForm);}
				document.getElementById('pied').onclick = function(){calculSurface(Array(24,2.2),theForm);}
				break;
			}
			case 29:
			{
				// ok
				theForm.txt1.onkeyup = function(){calculSurface(Array(22,2),theForm);}
				theForm.txt2.onkeyup = function(){calculSurface(Array(22,2),theForm);}
				document.getElementById('metre').onclick = function(){calculSurface(Array(22,2),theForm);}
				document.getElementById('pied').onclick = function(){calculSurface(Array(22,2),theForm);}
				break;
			}
			case 30:
			{
				// ok
				theForm.txt1.onkeyup = function(){calculSurfaceTriple(Array(18,1.7),null,null,theForm);}
				theForm.txt2.onkeyup = function(){calculSurfaceTriple(Array(18,1.7),null,null,theForm);}
				theForm.txt4.onkeyup = function(){calculSurfaceTriple(null,Array(12,1.1),null,theForm);}
				theForm.txt5.onkeyup = function(){calculSurfaceTriple(null,Array(12,1.1),null,theForm);}
				theForm.txt7.onkeyup = function(){calculSurfaceTriple(null,null,Array(162,15),theForm);}
				theForm.txt8.onkeyup = function(){calculSurfaceTriple(null,null,Array(162,15),theForm);}
				document.getElementById('metre1').onclick = function(){calculSurfaceTriple(Array(18,1.7),null,null,theForm);}
				document.getElementById('pied1').onclick = function(){calculSurfaceTriple(Array(18,1.7),null,null,theForm);}
				document.getElementById('metre2').onclick = function(){calculSurfaceTriple(null,Array(12,1.1),null,theForm);}
				document.getElementById('pied2').onclick = function(){calculSurfaceTriple(null,Array(12,1.1),null,theForm);}
				document.getElementById('metre3').onclick = function(){calculSurfaceTriple(null,null,Array(162,15),theForm);}
				document.getElementById('pied3').onclick = function(){calculSurfaceTriple(null,null,Array(162,15),theForm);}
				break;
			}
			case 31:
			{
				// ok
				theForm.txt1.onkeyup = function(){calculSurfaceDouble(Array(18,1.7),null,theForm);}
				theForm.txt2.onkeyup = function(){calculSurfaceDouble(Array(18,1.7),null,theForm);}
				theForm.txt4.onkeyup = function(){calculSurfaceDouble(null,Array(12,1.1),theForm);}
				theForm.txt5.onkeyup = function(){calculSurfaceDouble(null,Array(12,1.1),theForm);}
				document.getElementById('metre1').onclick = function(){calculSurfaceDouble(Array(18,1.7),null,theForm);}
				document.getElementById('pied1').onclick = function(){calculSurfaceDouble(Array(18,1.7),null,theForm);}
				document.getElementById('metre2').onclick = function(){calculSurfaceDouble(null,Array(12,1.1),theForm);}
				document.getElementById('pied2').onclick = function(){calculSurfaceDouble(null,Array(12,1.1),theForm);}
				break;
			}
			case 32:
			{
				// ok
				theForm.txt1.onkeyup = function(){calculSurface(Array(9,0.9),theForm);}
				theForm.txt2.onkeyup = function(){calculSurface(Array(9,0.9),theForm);}
				document.getElementById('metre').onclick = function(){calculSurface(Array(9,0.9),theForm);}
				document.getElementById('pied').onclick = function(){calculSurface(Array(9,0.9),theForm);}
				break;
			}
			case 34:
			{
				// ok
				theForm.txt1.onkeyup = function(){calculSurface(Array(1,1),theForm);}
				theForm.txt2.onkeyup = function(){calculSurface(Array(1,1),theForm);}
				theForm.txt4.onkeyup = function(){calculSurface(Array(1,1),theForm);}
				theForm.txt5.onkeyup = function(){calculSurface(Array(1,1),theForm);}
				document.getElementById('metre1').onclick = function(){calculSurface(Array(1,1),theForm);}
				document.getElementById('pied1').onclick = function(){calculSurface(Array(1,1),theForm);}
				document.getElementById('metre2').onclick = function(){calculSurface(Array(1,1),theForm);}
				document.getElementById('pied2').onclick = function(){calculSurface(Array(1,1),theForm);}
				break;
			}
			case 35:
			{
				// ok
				theForm.txt1.onkeyup = function(){calculSurfaceTerreau(Array(110,10),null,theForm);}
				theForm.txt2.onkeyup = function(){calculSurfaceTerreau(Array(110,10),null,theForm);}
				theForm.txt4.onkeyup = function(){calculSurfaceTerreau(null,Array(14.8,1.37),theForm);}
				theForm.txt5.onkeyup = function(){calculSurfaceTerreau(null,Array(14.8,1.37),theForm);}
				document.getElementById('metre1').onclick = function(){calculSurfaceTerreau(Array(110,10),null,theForm);}
				document.getElementById('pied1').onclick = function(){calculSurfaceTerreau(Array(110,10),null,theForm);}
				document.getElementById('metre2').onclick = function(){calculSurfaceTerreau(null,Array(14.8,1.37),theForm);}
				document.getElementById('pied2').onclick = function(){calculSurfaceTerreau(null,Array(14.8,1.37),theForm);}
				break;
			}
			case 36:
			{
				// ok
				theForm.txt1.onkeyup = function(){calculSurfaceTerreau(Array(100,10),null,theForm);}
				theForm.txt2.onkeyup = function(){calculSurfaceTerreau(Array(100,10),null,theForm);}
				theForm.txt4.onkeyup = function(){calculSurfaceTerreau(null,Array(10,1),theForm);}
				theForm.txt5.onkeyup = function(){calculSurfaceTerreau(null,Array(10,1),theForm);}
				document.getElementById('metre1').onclick = function(){calculSurfaceTerreau(Array(100,10),null,theForm);}
				document.getElementById('pied1').onclick = function(){calculSurfaceTerreau(Array(100,10),null,theForm);}
				document.getElementById('metre2').onclick = function(){calculSurfaceTerreau(null,Array(10,1),theForm);}
				document.getElementById('pied2').onclick = function(){calculSurfaceTerreau(null,Array(10,1),theForm);}
				break;
			}
			default:
			{
				//alert(calcId + ' is not a valid calcId');
				break;
			}
		}
	}
}
