/*
  Nombre: funcao.js
  
  Desenvolvedor: Uanderson dos Santos

  Data: 12/05/2009
  
*/

function validacampos(op){
 var frm = document.contato;
 var vnome = frm.nome.value;
 var vtelefone = frm.telefone.value;
 var vemail = frm.email.value;
 var vtitulo = frm.titulo.value;
 var vtexto = frm.texto.value;
 if (op == "1"){
   if ((vnome == "") || (vtelefone == "") || (vemail == "") || (vtitulo == "") || (vtexto == ""))
   { frm.exec.value = "N"; }else{ frm.exec.value = "S"; }
 }
}

function pegavalor(valor){
 var form = document.doacao;
 if (valor != ""){
  form.xvalorselecionado.value = valor;
 }
}

function pegaqtd(valor){
      var frm1 = document.frmcod001;
      var frm2 = document.frmcod002;
      var frm3 = document.frmcod003;
 if (valor != ""){
  frm1.xvalorselecionado.value = valor;
  frm2.xvalorselecionado.value = valor;
  frm3.xvalorselecionado.value = valor;
 }
}

function qtd(valor){
 frm = document.validavalor;
 frm2 = document.confirm;
 if (valor != ""){
   frm.xvalortotal.value = "$ " + valor * frm2.xvalorreal.value + ".00";
 }

}


function teste(op){
   var frm = document.frmcod001;
   var valor = frm.xvalor.value;
   radioidioma = frm.idioma;
   if (op == "1"){
      for (var i=0; i<radioidioma.length; i++) {
        if (radioidioma[i].checked) {
          var selidioma = radioidioma[i].id;
        }
      }
      var vqtd = frm.xvalorselecionado.value;
      if (vqtd != ""){
         frm.xqtd.value = vqtd;
      }else{frm.xqtd.value= "1";}

      frm.xtotal.value = vqtd * valor;
      
      if (selidioma == "1") {
         frm.xidioma.value = "English";
      }
      if (selidioma == "2") {
         frm.xidioma.value = "Español";
      }
      if (selidioma == "3") {
         frm.xidioma.value = "Português";
      }
   }
}

function teste1(op){

   if (op == "1"){
      var frm = document.frmcod001;
   }
   if (op == "2"){
      var frm = document.frmcod002;
   }
   if (op == "3"){
      var frm = document.frmcod003;
   }

   var valor = frm.xvalor.value;
   radioidioma = frm.idioma;

      for (var i=0; i<radioidioma.length; i++) {
        if (radioidioma[i].checked) {
          var selidioma = radioidioma[i].id;
        }
      }
      var vqtd = frm.xvalorselecionado.value;
      if (vqtd != ""){
         frm.xqtd.value = vqtd;
      }else{frm.xqtd.value= "1";}

      frm.xtotal.value = vqtd * valor;

      if (selidioma == "1") {
         frm.xidioma.value = "English";
      }
      if (selidioma == "2") {
         frm.xidioma.value = "Español";
      }
      if (selidioma == "3") {
         frm.xidioma.value = "Português";
      }

}

function verifica(op) {
   var form = document.doacao;
   var radio = null;
   var vdinheiro;
   var vpag;
   var url;
   radiovalores = form.ativo;
   radioformapag = form.formapag;
   if (op = 1){
      for (var i=0; i<radiovalores.length; i++) {
        if (radiovalores[i].checked) {
           var selvalores = radiovalores[i].id;
        }
      }
      for (var i=0; i<radioformapag.length; i++) {
        if (radioformapag[i].checked) {
           var selformapag = radioformapag[i].id;
        }
      }
      if (selvalores == "1"){
         var xvalida = form.xvalorselecionado.value;
         if (xvalida != ""){
            form.xdinheiro.value = xvalida;
         }else{form.xdinheiro.value= "100.00";}
      }
      if (selvalores != ""){
         if (selvalores == "0"){
            form.xdinheiro.value = form.outros.value;
         }
         if (selformapag == "2"){
            form.xforma.value = "W";
         }
         if (selformapag == "3"){
            form.xforma.value = "M";
         }
         if (selformapag == "4"){
            form.xforma.value = "Y";
         }
         if (selformapag == "5"){
            form.xforma.value = "D";
         }
      }else{alert("Please enter the amount");}
   }
}

function Limpar(valor, validos) {
   // retira caracteres invalidos da string
   var result = "";
   var aux;
   for (var i=0; i < valor.length; i++) {
      aux = validos.indexOf(valor.substring(i, i+1));
      if (aux>=0) {
         result += aux;
      }
   }
   return result;
}

//Formata número tipo moeda usando o evento onKeyDown
function Formata(campo,tammax,teclapres,decimal) {
   var tecla = teclapres.keyCode;
   vr = Limpar(campo.value,"0123456789");
   tam = vr.length;
   dec=decimal

   if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

   if (tecla == 8 ){ tam = tam - 1 ; }

   if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ) {
      if ( tam <= dec ){ campo.value = vr ; }
      if ( (tam > dec) && (tam <= 5) ){
         campo.value = vr.substr( 0, tam - 2 ) + "." + vr.substr( tam - dec, tam ) ;
      }
      if ( (tam >= 6) && (tam <= 8) ){
         campo.value = vr.substr( 0, tam - 5 ) + "," + vr.substr( tam - 5, 3 ) + "." + vr.substr( tam - dec, tam ) ;
      }
      if ( (tam >= 9) && (tam <= 11) ){
         campo.value = vr.substr( 0, tam - 8 ) + "," + vr.substr( tam - 8, 3 ) + "," + vr.substr( tam - 5, 3 ) + "." + vr.substr( tam - dec, tam ) ;
      }
      if ( (tam >= 12) && (tam <= 14) ){
         campo.value = vr.substr( 0, tam - 11 ) + "," + vr.substr( tam - 11, 3 ) + "," + vr.substr( tam - 8, 3 ) + "," + vr.substr( tam - 5, 3 ) + "." + vr.substr( tam - dec, tam ) ;
      }
      if ( (tam >= 15) && (tam <= 17) ){
         campo.value = vr.substr( 0, tam - 14 ) + "," + vr.substr( tam - 14, 3 ) + "," + vr.substr( tam - 11, 3 ) + "," + vr.substr( tam - 8, 3 ) + "," + vr.substr( tam - 5, 3 ) + "." + vr.substr( tam - 2, tam ) ;
      }
   }
}

