/* 
Desenvolvido por Engenharia de Web
www.engenhariadeweb.com.br
*/
	 
function calcular_barra(frm) {
	var constante = 25.4;
	
	var valor;
	var frac;
	var fraco;
	var frac1;
	var frac2;
	var frac3;
	var x1;
	var x2;
	var x3;
	var y1;
	var y2;
	var y3;
	

	if(frm.pol.options[frm.pol.selectedIndex].value != "") {
		valor = frm.pol.options[frm.pol.selectedIndex].value;

		frac = valor; 
		frac = frac.replace("."," "); 
		part1 = frac.split(" ");
		
		if (part1[1]) {
			part2 = part1[1].split("/");
			frac3 = (part2[0]/part2[1]);
			frac3 = frac3*1;
			part1[0] = part1[0]*1;
			frac3 += part1[0];
		} else {
			part2 = part1[0].split("/"); 
			if (part2[1]) {
				frac3 = part2[0]/part2[1];
			} else {
				frac3 = part2[0];
			}
		}

		x = frac3*constante; x = x*x;	x = x*100; x1 = x*0.006159;	x2 = x*0.007843; x3 = x*0.006801; y1 = Math.round(x1); y1=y1/100; y2 = Math.round(x2); y2=y2/100;	y3 = Math.round(x3); y3=y3/100; 
		frm.resultado1.value = y1;
		frm.resultado2.value = y2; 
		frm.resultado3.value = y3;
		return;

	} else if (frm.mil.options[frm.mil.selectedIndex].value != "") {
		valor = frm.mil.options[frm.mil.selectedIndex].value;
		valor = valor.replace(",",".");
		x = valor; x = x*x; x = x*100; x1 = x*0.006159;	x2 = x*0.007843; x3 = x*0.006801;	y1 = Math.round(x1); y1=y1/100;	y2 = Math.round(x2); y2=y2/100;	y3 = Math.round(x3); y3=y3/100;
		frm.resultado1.value = y1; 
		frm.resultado2.value = y2;
		frm.resultado3.value = y3;
		return;
	} else {
		frm.resultado1.value = "";
		frm.resultado2.value = "";
		frm.resultado3.value = "";
		alert("Por favor escolha o valor de polegadas ou milímetros ŕ serem convertidos.");
	}
	


}

function calcular_pol(frm) {
	var constante = 25.4;

	var polegada=0;
	var frac=0;
	var frac1=0;
	var frac2=0;
	var frac3;
	
	//if (frm.polegadas.options[frm.polegadas.selectedIndex].value) {
		polegada = frm.polegadas.options[frm.polegadas.selectedIndex].value;
	//}
	frac = frm.fracionado.options[frm.fracionado.selectedIndex].text;

	frac1 = parseInt(frac.substr(0,frac.indexOf("/")));
	frac2 = parseInt(frac.substr(frac.indexOf("/")+1,frac.length));
	if (isNaN(frac1)){
		frac1 = 0;
	}
	if (isNaN(frac2)){
		frac2 = 0;
	}
	frac3 = frac1/frac2;
	if (isNaN(frac3)){
		frac3 = 0;
	}
	var x = ((frac3*constante)*10)+((polegada*constante)*10);
	var y = Math.round(x);
	y=y/10; 
	frm.resultado12.value = y;

}


function zera_pol(frm) {
		frm.pol.value = "";
}
function zera_mil(frm) {
		frm.mil.value = "";
}