function gera_lista( nome )
{
	var html="";
	html+="<select class=\"sel-moeda-conv\" id=\""+nome+"\" name=\""+nome+"\">";
	html+="<option value=\"\" selected>escolha uma moeda</option>";
	if(nome=="de")	
	{
		for(i=0;i<nMoeda.length;i++)
		{
			html+="<option value=\""+ vMoeda[i] +"\">"+nMoeda[i]+" - "+tMoeda[i]+"</option>";
		}
	} 
	else if(nome=="para")
	{
		for(i=0;i<nMoeda.length;i++)
		{
			html+="<option value=\""+ vMoeda[i] +"-"+ tMoeda[i] +"-"+pMoeda[i]+"\">"+nMoeda[i]+" - "+tMoeda[i]+"</option>";
		}		
	}	
	html+="</select>";
	document.write( html );
}

function conversor() {
/*var v1 = o1.value;
var v2 = o2.value;
var v3 = o3.value;*/
var v1 = document.getElementById('de').value;
var v2 = document.getElementById('para').value;
var v3 = document.getElementById('valor').value.replace(/\./g,"");
var resp = document.getElementById('resultado');
var com = 0;
var com1 = 0;

//Mensagens
if (v1 =='') {alert('Escolha uma moeda no campo "DE" para realizar a conversão.')} else {
	v1a = v1.split("|");
	v1 = v1a[0];
	tpMoedaV1 = v1a[1];
}
 if (v2 =='') {alert('Escolha uma moeda no campo "PARA" a fim de realizar a conversão.')} else {
	v2a = v2.split("|");
	v2 = v2a[0];
	tpMoedaV2a = v2a[1].split("-");
	tpMoedaV2 = tpMoedaV2a[0];

	//compara moedas
	com = v2+'|'+tpMoedaV2;
	com1 = v1+'|'+tpMoedaV1;
}
if (v3 == '') {alert('Digite um valor para realizar a conversão.')}
else if (com == com1) { alert('Escolher moedas diferentes para realizar a conversão.')}
else {
	//checa se tem virgula (centavos)
	v3a = v3.split(",");
	if (v3a[1] != null) {v3 = v3a[0]+'.'+v3a[1];}

	//realiza o cálculo
	if (tpMoedaV1==1 && tpMoedaV2==1) {
		vtotal = (v2/v1)*v3;
	}
	else if (tpMoedaV1==2 || tpMoedaV2==2) {
		if (tpMoedaV1==2 && tpMoedaV2==3) {
			if (tpMoedaV1==3) {v1 = v1/v1;}
			if (tpMoedaV2==3) {v2 = v2/v2;}
			vtotal = v1*v3;
		} else if (tpMoedaV1==3 && tpMoedaV2==2) {
			if (tpMoedaV1==3) {v1 = v1/v1;}
			if (tpMoedaV2==3) {v2 = v2/v2;}
			vtotal = (1/v2)*v3;
		} else {
			if (tpMoedaV1==2) {v1 = 1/v1;}
			if (tpMoedaV2==2) {v2 = 1/v2;}
			vtotal = (v2/v1)*v3;
		}
	} 
	else if (tpMoedaV1==3 || tpMoedaV2==3) {
		if (tpMoedaV1==3) {v1 = v1/v1;}
		if (tpMoedaV2==3) {v2 = v2/v2;}
		vtotal = (v2/v1)*v3;
	} 

	aux = vtotal;
	aux1 = new String(aux);
	aux1 = aux1.indexOf('.');

	//printa na tela o resultado
	vtotal = vtotal.toString().split(".");
	danilo = vtotal[1];

	if (aux1 > 0) {vtotal = vtotal[0]+','+vtotal[1].substring(0,3);}
	if (aux < 2){resp.value = vtotal+' '+tpMoedaV2a[1];} else {resp.value = vtotal+' '+tpMoedaV2a[2];}
		
}}
////////////////////////CALCULADORA //