/**** Ass. Salès ****/
/**** Crédits : DFC-Engineering ****/

$(function(){

	// Remove border, cellspacing, cellpadding on all #blockContent table
	$("#blockContent table").removeAttr("border");
	$("#blockContent table").removeAttr("cellpadding");
	$("#blockContent table").removeAttr("cellspacing");

	// Custom table style : add gray backgrounds on table class : .tabStyle
	$("#blockContent .tabStyle tr:even").css({backgroundColor: "#e4e4e4"});
	$("#blockContent .tabStyle tr:odd").css({backgroundColor: "#f8f8f8"});
	$("#blockContent .tabStyle tr:first").css({backgroundColor: "#ffffff", color: "#000000", textTransformation: "uppercase", fontWeight: "bold"});
	
	// Custom second table Style (technique) : add bag
	$("#blockContent .tabStyle2 tr:even").css({backgroundColor: "#e4e4e4"});
	$("#blockContent .tabStyle2 tr:odd").css({backgroundColor: "#f8f8f8"});
	
	$("#blockContent .tabStyle2 tr:first").css({backgroundColor: "#48bfea"});
	$("#blockContent .tabStyle2 tr:eq(1)").css({backgroundColor: "#bbe2f0"});
	
	if ( $("table.tabStyle2").size() >= 1 ){
		// bloblo
	}

});


function arrondir(resultat,delta) {
      resultat = Math.round(resultat*delta)/delta;
      return resultat;
}

function calculValeur(){

	var debit1 = $("input[name=debit1]").val();
	var debit2 = arrondir(debit1/3600,1000000000);
	$("input[name=debit2]").val(debit2);
	
	var diametre = $("input[name=diametre]").val().replace(",",".");
	var diametre2 = (diametre/1000);
	$("input[name=diametre2]").val(diametre2);
	
	var longueur = $("input[name=longueur]").val();
	var viscosite = $("input[name=viscosite]").val().replace(",",".");
	var section = arrondir( ((3.14)*Math.pow(diametre2,2)/4), 1000000000);
	$("input[name=section]").val(section);
	
	var vitesse = arrondir( (debit2 / section), 100);
	$("input[name=vitesse]").val(vitesse);
	
	var raynolds = Math.round( (3500*debit1)/(diametre*viscosite) );
	$("input[name=raynolds]").val( raynolds );
	
	var l = "";
	if (raynolds > 2000)
		l = (0.316)/(Math.pow(raynolds,0.25)) ;
	else
		l = (64/raynolds);
		
	$("input[name=l]").val(arrondir(l,10000000000));
	
	var perte = arrondir( (l*longueur*vitesse*vitesse)/(diametre2*2*9.81), 100);
	$("input[name=perte]").val(perte);
	$("input[name=perte2]").val(perte);
	
	var hauteur = $("input[name=hauteur]").val();
	
	var hmt = parseFloat(hauteur)+parseFloat(perte);
	$("input[name=hmt]").val(hmt) ;
	
	alert("Caractéristique de la pompe :\nDébit : "+debit1+" m3/h  \nPression : "+hmt+" mètres");
	
}
