function borrar_todo(){
	document.forms["calculadora"].reset();
	document.getElementById('resultado').innerHTML = 0;	
}

function calcular_todo()
{
	total = 0;
	
	for (i=1; i<=4; i++){
		//Calculo las tiras necesarias de cada pared 
		tir_nes = Number(document.getElementById('pared_a'+i).value.replace(/,/g, '.')) / 0.53;
		
		aux1 = Number(document.getElementById('rapp').value.replace(/,/g, '.')) / 200;
		
		aux = aux1 + Number(document.getElementById('pared_alt'+i).value.replace(/,/g, '.'))
		
		//Calculo las tiras x rollo
		tir_rol = 10.05 / aux;
		
		total_pared = tir_nes / tir_rol;
		
		total = total + total_pared;
	}
	total = Math.ceil(total);
	document.getElementById('resultado').innerHTML = total.toFixed(0).toString().replace(/\./g, ',');	
}


function cambiar_si_cero(obj){
	valor = obj.value;
	if ( (valor != "") )
	{
		var numPosPunto = valor.indexOf(",");
		
		if ( (numPosPunto) != -1) 
			{	strParteEntera = valor.substr(0,(numPosPunto));
				if ( strParteEntera == 0 )
					obj.value = 0;
			}
	}

}

function fieldNumber(objeto, numeroDecimales, e) 
{ 
	var valorCampo; 
	var evento_key = (document.all) ? e.keyCode : e.which; 
	var numPosPunto = 0; 
	var strParteEntera = ""; 
	var strParteDecimal = ""; 
	var NUM_DECIMALES = numeroDecimales; 
	//alert(evento_key);

	switch (evento_key) 
	{ 
	
		case 48: 
		case 49: 
		case 50: 
		case 51: 
		case 52: 
		case 53: 
		case 54: 
		case 55: 
		case 56: 
		case 57: 
		break; 
		default: 
			if (((evento_key != 44) || (NUM_DECIMALES == 0)) && (evento_key != 8))
			{
				if (document.all) 
					e.keyCode = 0;
				else 
					e.stopPropagation();
				return false; 
			}
	} 

	valorCampo = objeto.value; 	
	if (evento_key == 44) 
	{
		if (valorCampo == '')
		{
			if (document.all) 
				e.keyCode = 0;
			else 
				e.stopPropagation();
			return false; 
		}
		else if (valorCampo.indexOf(",") != -1)
		{ 
			if (document.all) 
				e.keyCode = 0;
			else 
				e.stopPropagation();
			return false; 
		} 
	}
	/* Sólo puede teclear el número de decimales indicado en NUM_DECIMALES */ 
	if ((numPosPunto = valorCampo.indexOf(",")) != -1) 
	{ 
		strParteEntera = valorCampo.substr(0,(numPosPunto - 1)); 
		strParteDecimal = valorCampo.substr((numPosPunto + 1), valorCampo.length) 
		
		if (strParteDecimal.length > (NUM_DECIMALES - 1)) 
		{ 
			if (document.all) 
				e.keyCode = 0;
			else 
				e.stopPropagation();
			return false; 
		} 
	} 
	
	return true; 
} 

/*Devuelve verdadero para números >= 1 falso caso contrario*/

function fieldNumberSinCero(objeto, numeroDecimales, e) 
{ 
	var valorCampo; 
	var evento_key = (document.all) ? e.keyCode : e.which; 
	var numPosPunto = 0; 
	var strParteEntera = ""; 
	var strParteDecimal = ""; 
	var NUM_DECIMALES = numeroDecimales; 
	

	switch (evento_key) 
	{ 
	
		case 48: 
		case 49: 
		case 50: 
		case 51: 
		case 52: 
		case 53: 
		case 54: 
		case 55: 
		case 56: 
		case 57: 
		break; 
		default: 
			if (((evento_key != 44) || (NUM_DECIMALES == 0)) && (evento_key != 8))
			{
				if (document.all) 
					e.keyCode = 0;
				else 
					e.stopPropagation();
				return false; 
			}
	} 

	valorCampo = objeto.value; 	

	/*if (valorCampo == '' && evento_key == 48)
		{
			return false;
		}*/
	if (evento_key == 44) 
	{	
		if (valorCampo == '')
		{
			if (document.all) 
				e.keyCode = 0;
			else 
				e.stopPropagation();
			return false; 
		}
		else if (valorCampo.indexOf(",") != -1)
		{ 
			if (document.all) 
				e.keyCode = 0;
			else 
				e.stopPropagation();
			return false; 
		}else if(valorCampo == 0)
		{
			if (document.all) 
				e.keyCode = 0;
			else 
				e.stopPropagation();
			return false; 
		}
	}
	/* Sólo puede teclear el número de decimales indicado en NUM_DECIMALES */ 
	if ((numPosPunto = valorCampo.indexOf(",")) != -1) 
	{ 
			strParteEntera = valorCampo.substr(0,(numPosPunto)); 
		
			strParteDecimal = valorCampo.substr((numPosPunto + 1), valorCampo.length) 
			
			if (strParteDecimal.length > (NUM_DECIMALES - 1)) 
			{ 
				if (document.all) 
					e.keyCode = 0;
				else 
					e.stopPropagation();
				return false; 
			} 
		
	
	} 
	
	return true; 
}