function CAPACITY() {
	this.mCubic_meter=1e+3
	this.mHectoliter=100
	this.mDecaliter=10
	this.mLiter=1
	this.mMilliliter=1e-3
	this.mCubic_centimeter=1e-3
	this.mCubic_millimeter=1e-6
    this.uslAcre_foot=1.23349E+6
	this.uslCubic_yard=0.765e+3
	this.uslBarrel=1.192405e+2
	this.usBarrelo=1.5897e+2
	this.uslCubic_foot=28.3169
	this.uslGallon=3.785
	this.uslCubic_inch=0.0163871
	this.uslQuart=0.946
	this.uslPint=0.473
	this.uslGill=118.294e-3
	this.uslFluid_ounce=29.573e-3
	this.uslFluid_dram=3.697e-3
	this.uslMinim=0.061610e-3
	this.usdCubic_yard=0.765e+3
	this.usdBarrel=1.192405e+2
	this.usdBushel=0.036e+3
	this.usdCubic_foot=0.028e+3
	this.usdPeck=0.0091e+3
	this.usdGallon=4.546
	this.usdCubic_inch=0.0163871
	this.usdQuart=1.136
	this.usdPint=568.26e-3
	this.usdGill=142.066e-3
	this.usdDry_ounce=28.412e-3
	this.usdDry_dram=3.5516e-3
	this.usdMinim=0.059194e-3
	this.biBushel=0.036e+3
	this.biPeck=0.0091e+3
	this.biGallon=4.546
	this.biQuart=1.136
	this.biPint=568.26e-3
	this.biGill=142.066e-3
	this.biMinim=0.059194e-3
	this.rlVedro=12.3
	this.rlShtoff=1.54
	this.rlQuart=1.23
	this.rlVine_bottle=0.77
	this.rlVodka_bottle=0.624
	this.rlCharka=0.123
	this.rlShkalik=0.0615
	this.rdChetverik=26.238
	this.rdVedro=12.3
	this.rdGarnetz=3.2798
	this.cCup=0.25
	this.cTable_spoon=0.015
	this.cTea_spoon=0.005
}

data = new CAPACITY();

function checkNum(str) {
	for (var i=0; i<str.length; i++) {
	var ch = str.substring(i, i + 1)
	if (ch!="." && ch!="+" && ch!="-" && ch!="e" && ch!="E" && (ch < "0" || ch > "9")) {
		alert("Por favor ingresa un número válido.");
		return false
		}
	}
	return true
}

function normalize(what,digits) {
	var str=""+what;
	var pp=Math.max(str.lastIndexOf("+"),str.lastIndexOf("-"));
	var idot=str.indexOf(".");
	if (idot>=1) {
		var ee=(pp>0)?str.substring(pp-1,str.length):"";
		digits+=idot;
		if (digits>=str.length)
			return str;
		if (pp>0 && digits>=pp)
			digits-=pp;
		var c=eval(str.charAt(digits));
		var ipos=digits-1;
		if (c>=5) {
			while (str.charAt(ipos)=="9") ipos--;
			if (str.charAt(ipos)==".") {
				var nc=eval(str.substring(0,idot))+1;
				if (nc==10 && ee.length>0) {
					nc=1;
					ee="e"+(eval(ee.substring(1,ee.length))+1);
				}
				return ""+nc+ee;
			}
			return str.substring(0,ipos)+(eval(str.charAt(ipos))+1)+ee;
		} else
			var ret=str.substring(0,digits)+ee;
			for (var i=0; i<ret.length; i++)
				if (ret.charAt(i)>"0" && ret.charAt(i)<="9")
					return ret;
			return str;
	 }
	 return str;
}

function compute(obj,val) {
	if (obj[val].value) {
		var uval=0;
		uval = obj[val].value*data[val];
		for (var i in data)
			obj[i].value=normalize(uval/data[i],8);
	}
}