// JavaScript Document

var Res=0

function PesMetros(x){
Res=(x*0.3048)
}

function MetrosPes(x){
Res=(x/0.3048)
}

function MilhaKm(x){
Res=(x*1.609344)
}

function NosKm(x){
Res=(x*1.851998)
}

function KmNos(x){
Res=(x/0.539957)
}

function KmMilha(x){
Res=(x/0.621371)
}

function NoBeaufort(x){
if (x>=0)  {Res="Força 0"}
if (x>=1)  {Res="Força 1"}
if (x>=4)  {Res="Força 2"}
if (x>=7)  {Res="Força 3"}
if (x>=11) {Res="Força 4"}
if (x>=17) {Res="Força 5"}
if (x>=22) {Res="Força 6"}
if (x>=28) {Res="Força 7"}
if (x>=34) {Res="Força 8"}
if (x>=41) {Res="Força 9"}
if (x>=48) {Res="Força 10"}
if (x>=56) {Res="Força 11"}
if (x>=63) {Res="Força 12"}
}

function CelciusFar(x){
Res=(212-32)/100 * x + 32
}

function FarCelcius(x){
Res=100/(212-32) * (x - 32 )
}

function PolegadaCm(x){
Res=x * 2.54
}

function CmPolegada(x){
Res=x / 2.54
}

function LeguaMilha(x){
Res=x * 3.2
}

function MilhaLegua(x){
Res=x / 3.2
}

function BracaMt(x){
Res=x * 1.83
}

function MtBraca(x){
Res=x / 1.83
}

function Calc(A1,T1){
var y=0
var t
y=A1
t=T1
if (t==1) {PesMetros (y)};
if (t==2) {MetrosPes (y)};
if (t==3) {MilhaKm   (y)};
if (t==4) {KmMilha   (y)};
if (t==5) {NosKm   (y)};
if (t==6) {KmNos   (y)};
if (t==7) {NoBeaufort(y)};
if (t==8) {CelciusFar(y)};
if (t==9) {FarCelcius(y)};
if (t==10) {PolegadaCm(y)};
if (t==11) {CmPolegada(y)};
if (t==12) {LeguaMilha(y)};
if (t==13) {MilhaLegua(y)};
if (t==14) {BracaMt(y)};
if (t==15) {MtBraca(y)};

document.form.out.value=Res
}

function Troca(Tx){
document.form.inp.value=Tx
document.form.out.value=""
}

function Limpar(){
document.form.inp.value=""
document.form.out.value=""
}


function roundNumber (rnum) {

   return Math.round(rnum*Math.pow(10,2))/Math.pow(10,2);

}


function calc_velocidade(){
 desloc = document.getElementById('deslocamento').value * 2.24;
 pot = document.getElementById('potencia').value - (document.getElementById('potencia').value * 0.05);
 y = desloc/pot;
 raiz = Math.sqrt(y);
 resultado = 190 / raiz;
 document.getElementById('resultado').value = roundNumber(resultado);
 document.getElementById('res_km').value = roundNumber(resultado*1.852);
 document.getElementById('res_milha').value = roundNumber(resultado*1.150778);
}


function valida_email(EMAIL)
{
   var conta_arrobas = 0;
   
   if (EMAIL.value.indexOf('@') != -1 )
   {
	  //TEM ARROBA
	  if (EMAIL.value.indexOf('.') != -1)
	  {
		  //TEM PONTO
		  //QUANTIDADE DE ARROBAS
		 for(var i=0; i< EMAIL.value.length; i++)
		 {
			 if (EMAIL.value.substr(i,1) == '@')
			   conta_arrobas++;
		 }
		 if (conta_arrobas > 1)
		 {
			 alert('Digite seu e-mail corretamente.'); 
		 }
		 else
		 {
			 //EXTREMIDADES
			 if (
				  
				  (EMAIL.value.substr(EMAIL.value.length-1,1) == '@' ) ||
				  (EMAIL.value.substr(0,1) == '@')  ||
  			      (EMAIL.value.substr(EMAIL.value.length-1,1) == '.' ) ||
				  (EMAIL.value.substr(0,1) == '.') 
			      
			     ) 
				 {
					 return false;
				 } 
				 else
				 {
					 document.newsletter.submit();
				 }
		 }
	  }
	  else
	  {
			 alert('Digite seu e-mail corretamente.'); 
	  }
   }
   else
   {
			 alert('Digite seu e-mail corretamente.'); 
    }
}

function validaExtensaoArq(arq){
	var vl = arq.value;
	if (vl == ''){
		alert('Selecione a imagem');
		arq.focus()
	}
	else{
	 var vl2 = vl.substring( vl.length - 4,vl.length );	 
	 if ((vl2.toUpperCase() == '.GIF')||(vl2.toUpperCase() == '.JPG')||(vl2.toUpperCase() == '.PNG')){
	 	document.dados.extensao.value = vl2.toUpperCase();
		document.dados.submit();
	 }
	 else{
		 if ((vl2.toUpperCase() == 'JPEG')){			 
			 document.dados.extensao.value = '.JPEG';
			 document.dados.submit();
		 }
		 else{
			alert('formato de arquivo inválido!');
			arq.focus();
		 }
	}
	}
}
