function validaForm(){


/*
//Procedimento auxiliar para apresentar todos os campos e seus atributos
for(var i=0; i<document.forms[0].length;i++)
{
  alert(i + "-" + document.forms[0][i].getAttribute("name"));

 if (document.forms[0][i].getAttribute("type")=="text")
  {
   alert(i + "-" +document.forms[0][i].getAttribute("name"));   
  }

}
*/


//Contribuicao - valida campo nulo (parte1).
 strcheck = false;
 for (i=0; i<document.f.valorContribuicao.length; i++) {
  if (document.f.valorContribuicao[i].checked) 
   {    
    //alert("Checado"); 
    strcheck = true;
    break;
   }
 }

//Contribuicao - valida campo nulo (parte2) e quando selecionar a opcao que informa um valor de contribuicao, o valor deve ser informado e maior que 12,00.
 if (strcheck)
  {
   //alert("Checado");
   if(document.f.valorContribuicao[3].checked)
    {
     if(document.f.valorMinimo.value==null || document.f.valorMinimo.value=="")
      {
       if (confirm("Deseja informar um valor para contribuição?\n[Ok] para informar um valor\n[cancel] para escolher outra contribuicao"))
        {
         document.f.valorMinimo.focus();
	 return false;
        }
       else
        {
         document.f.valorContribuicao[3].checked=false;
	 document.f.valorContribuicao[0].checked=true;
         //document.f.contribuicao.focus();
	 return false;
        }
       
      }
     else
      {
	if (document.f.valorMinimo.value.substr(0,1)==",")
	 {
 	  alert("Valor de contribuicao invalido!\nPor favor, verifique o valor digitado para contribuicao.");
	  document.f.valorMinimo.focus();
	  return false;
      	 }
	else
	 {
	  if (document.f.valorContribuicao[0].value < 50) {varNum=12} else {varNum=100};

	  if (parseInt(document.f.valorMinimo.value)<varNum)
           {
	    alert("Por favor,\ninforme um valor para contribuição maior que R$" + varNum + ",00");
	    document.f.valorMinimo.focus();
	    return false;
           }
	  else
	   {
	    document.f.valorContribuicao[3].value=document.f.valorMinimo.value;
	    //alert(document.f.valorContribuicao[3].value);
	   }
	 }
      }
    }
  }
 else
  {
   alert("Por favor,\nescolha um valor para contribuição");
   //document.f.contribuicao.focus();
   return false;
  }




//###### INDICE DOS CAMPOS ######
//Validacao dos campos com valores Nulos
//Indice dos campos: 6,7,8,10,12,13,14,15,26,27
//Nome dos campos: nome,sexo,endereco,numero,bairro,cidade,estado,pais,dataNascimento,profissao

var indice = new Array(6,7,8,10,12,13,14,15,26,27);
var msg = "";

 for (var i=0; i<indice.length; i++)
 {
  //alert(indice[i] + " - " + document.forms[0].elements[indice[i]].name);
  //alert(document.forms[0].elements[indice[i]].name);

 if (document.forms[0].elements[indice[i]].value==null || document.forms[0].elements[indice[i]].value=="" || document.forms[0].elements[indice[i]].value==document.forms[0].elements[indice[i]].defaultValue)
  {
   //alert("nulo");
   msg += document.forms[0].elements[indice[i]].name + "\n";
   //alert(msg);
  } 
 }
 if (!msg=="")
 {
  alert("Estes campos sao obrigatorios\nPor favor,informe os valores dos campos:\n\n" + msg);
  return false;
 }



//###### INDICE DOS CAMPOS ######
//Validacao dos campos Telefones com valores nulos
//Pelo menos um Numero de Telefone deve ser preenchido
//Indice dos campos: 17,18,20,21,23,24
//Nome dos campos: DDDres,TelefoneRes,DDDcom,TelefoneCom,DDDcel,TelefoneCel

var indice = new Array(17,18,20,21,23,24);
var conta = 0;

 for (var i=0; i<indice.length; i++)
 {

  if (document.forms[0].elements[indice[i]].value==null || document.forms[0].elements[indice[i]].value=="" || document.forms[0].elements[indice[i]].value==document.forms[0].elements[indice[i]].defaultValue)
   {
    conta++;
   } 
 }
 //alert(conta + "-" + indice.length);
 if (conta==indice.length)
  {
   alert("Por favor,\ninforme pelo menos um Numero de Telefone.");
   document.forms[0].elements[indice[0]].focus();
   return false;
  }




//DDD e Telefones Residencial
//Verifica se os campos DDD e Telefone estão vazios ou preenchidos
//Se os campos estiverem preemchidos, verifica se o campo DDD e igual a 2 e se o campo Telefone e maior que 7
//Insere os valores dos campos DDD e Telefone no campo escondido (Hidden)
 if (document.f.DDDres.value==null || document.f.DDDres.value=="" || document.f.DDDres.value==document.f.DDDres.defaultValue)
  {
    if(!(document.f.telefoneRes.value==null || document.f.telefoneRes.value=="" ))
     {  
      alert("Por favor,\ninforme o valor do campos DDD Residencial");
      document.f.DDDres.focus();
      return false;
     }
  }
 else
  {
   if(document.f.telefoneRes.value==null || document.f.telefoneRes.value=="" )
     {  
      alert("Por favor,\ninforme o valor do campos Telefone Residencial");
      document.f.telefoneRes.focus();
      return false;
     }
    else
     {
      strFoneRes = document.f.telefoneRes.value.toString().replace( "-", "" );
      if ((parseInt(document.f.DDDres.value.length)<2) || (parseInt(strFoneRes.length)<7) )
       {
        alert("Por favor,\no campo DDD deve ter 2 caracteres (exemplo 11)\nno campo Telefone Residencial deve ter pelo menos 7 caracteres (exemplo 3234567)");
        document.f.DDDres.focus();
 	return false;
       }
      else
       {
        //alert(document.f.DDDres.value+strFoneRes);
        document.f.hiddenFoneRes.value=document.f.DDDres.value+"-"+strFoneRes;
        //alert(document.f.hiddenFoneRes.value);
       }
     }
  }


//DDD e Telefones Comercial
//Verifica se os campos DDD e Telefone estão vazios ou preenchidos
//Insere os valores dos campos DDD e Telefone no campo escondido (Hidden)
//Se os campos estiverem preemchidos, verifica se o campo DDD e igual a 2 e se o campo Telefone e maior que 7
 if (document.f.DDDcom.value==null || document.f.DDDcom.value=="" || document.f.DDDcom.value==document.f.DDDcom.defaultValue)
  {
    if(!(document.f.telefoneCom.value==null || document.f.telefoneCom.value=="" ))
     {  
      alert("Por favor,\ninforme o valor do campos DDD Comercial");
      document.f.DDDcom.focus();
      return false;
     }
  }
 else
  {
   if(document.f.telefoneCom.value==null || document.f.telefoneCom.value=="" )
     {  
      alert("Por favor,\ninforme o valor do campos Telefone Comercial");
      document.f.telefoneCom.focus();
      return false;
     }
    else
     {
      strFoneCom = document.f.telefoneCom.value.toString().replace( "-", "" );
      if ((parseInt(document.f.DDDcom.value.length)<2) || (parseInt(strFoneCom.length)<7) )
       {
        alert("Por favor,\no campo DDD Comercial deve ter 2 caracteres (exemplo 11)\nno campo Telefone Comercial deve ter pelo menos 7 caracteres (exemplo 3234567)");
        document.f.DDDcom.focus();
 	return false;
       }
      else
       {
        //alert(document.f.DDDcom.value+document.f.telefoneCom.value.toString().replace( "-", "" ));
        document.f.hiddenFoneCom.value=document.f.DDDcom.value+"-"+document.f.telefoneCom.value.toString().replace( "-", "" );
        //alert(document.f.hiddenFoneCom.value);
       }   
     }
  }


//DDD e Telefones Celular
//Verifica se os campos DDD e Telefone estão vazios ou preenchidos
//Se os campos estiverem preemchidos, verifica se o campo DDD e igual a 2 e se o campo Telefone e maior que 7
//Insere os valores dos campos DDD e Telefone no campo escondido (Hidden)
 if (document.f.DDDcel.value==null || document.f.DDDcel.value=="" || document.f.DDDcel.value==document.f.DDDcel.defaultValue)
  {
    if(!(document.f.telefoneCel.value==null || document.f.telefoneCel.value=="" ))
     {  
      alert("Por favor,\ninforme o valor do campos DDD Celular");
      document.f.DDDcel.focus();
      return false;
     }
  }
 else
  {
   if(document.f.telefoneCel.value==null || document.f.telefoneCel.value=="" )
     {  
      alert("Por favor,\ninforme o valor do campos Telefone Celular");
      document.f.telefoneCel.focus();
      return false;
     }
    else
     {
      strFoneCel = document.f.telefoneCel.value.toString().replace( "-", "" );
      if ((parseInt(document.f.DDDcel.value.length)<2) || (parseInt(strFoneCel.length)<7) )
       {
        alert("Por favor,\no campo DDD Celular deve ter 2 caracteres (exemplo 11)\nno campo Telefone Celular deve ter pelo menos 7 caracteres (exemplo 3234567)");
        document.f.DDDcel.focus();
 	return false;
       }
      else
       {
        //alert(document.f.DDDcel.value+document.f.telefoneCel.value.toString().replace( "-", "" ));
        document.f.hiddenFoneCel.value=document.f.DDDcel.value+"-"+document.f.telefoneCel.value.toString().replace( "-", "" );
        //alert(document.f.hiddenFoneCel.value);
       }
     }   
  }




//DATA - valida data
 if (!(validaData(document.f.dataNascimento.value)))
 {
  alert("Data invalida!\npor favor verifique a data digitada no campo data de nascimento.");
  document.f.dataNascimento.focus();
  return false;
 }




//CEP - verifica se o campo tem 8 caracteres
strCep = document.f.cep.value.toString().replace( "-", "" );
//alert(strCep.length);
 if (!(strCep.length==8))
  {
   alert("Por favor,\no campo CEP deve ter 8 caracteres (exemplo 11045003)");
   document.f.cep.focus();
   return false;
  }



//CPF - Verifica se o campo CPF tem 11 caracter e se é válido.
 strCPF = document.f.cpf.value;
 //alert(strCPF);

 if (!(strCPF==null || strCPF=="" || strCPF==document.f.cpf.defaultValue))
 {

  strCPF = strCPF.toString().replace( ".", "" );
  strCPF = strCPF.toString().replace( ".", "" );
  strCPF = strCPF.toString().replace( "-", "" );
  //alert(strCPF);

  if (strCPF.length==11)
   {
    if (!(isCpf(strCPF)))
     {
      alert("CPF invalido!\nPor favor, verifique o valor digitado no CPF.");
      document.f.cpf.focus();
      return false;
     }
   }
  else
   {
    alert("Por favor,\no campo CPF deve ter 11 caracteres (exemplo 123789456)");
    document.f.cpf.focus();
    return false;
   }
 }




//Email - Validacao do campo email
 if (!(isEmail(document.f.email.value)))
 {
  alert("Email invalido!\nPor favor, verifique o valor digitado no email.");
  document.f.email.focus();
  return false;   
 }



//Receber Informativos
 if (document.f.receberInformacao.checked)
 {
  for (var i=0; i<document.f.periodoInformacao.length; i++)
  {
   if((document.f.periodoInformacao[i].checked))
   {
    strCheck = true;
    break;
   }
  strCheck = false;
  }
 }
 else
 {
  strCheck = true;
 }

 //alert(strCheck);
 if(!(strCheck))
 {
  alert("Por favor,\nescolha um periodo para receber os e-mails informativos do Greenpeace");
  document.f.periodoInformacao[0].focus();
  return false;
 }



//Valida forma de pagamento
//Cartao de credito = 1
//Debito Automatico = 2
 strCheck=false;
 for (var k=0; k<document.f.formaPagamento.length; k++)
 {
  //alert(document.f.formaPagamento[k].value);
  //alert(document.f.formaPagamento[k].checked);

  if (document.f.formaPagamento[k].checked)
  {
   strCheck=true;

    //Forma de Pagamento Cartao de credito
    if(document.f.formaPagamento[k].value==1)
    {
     //alert("Entrou no Cartao de credito");

    //###### INDICE DOS CAMPOS ######
    //Valida campos nulos do Cartao de Credito
    var indice = new Array(35,36,38,39);
    var msg = "";

    for (var i=0; i<indice.length; i++)
    {
     if (document.forms[0].elements[indice[i]].value==null || document.forms[0].elements[indice[i]].value=="" || document.forms[0].elements[indice[i]].value==document.forms[0].elements[indice[i]].defaultValue)
      {
        msg += document.forms[0].elements[indice[i]].name + "\n";
      } 
    }
    if (!msg=="")
     {
      alert("Estes campos sao obrigatorios\nPor favor,informe os valores dos campos:\n\n" + msg);
      document.f.formaPagamento[0].focus();
      return false;
     }

   
   //alert(document.f.numeroCartao.value);
   //alert(document.f.cartao.value);    
   //alert(document.f.cartaoValidadeMes.value);
   //alert(document.f.cartaoValidadeAno.value);

   cardNumber = document.f.numeroCartao.value;
   cardType = document.f.cartao.value;   
   cardMonth = document.f.cartaoValidadeMes.value;
   cardYear = document.f.cartaoValidadeAno.value;

   if (!(validateCard(cardNumber,cardType,cardMonth,cardYear)))
    {
     document.f.formaPagamento[0].focus();
     return false;
    } 
   else
    {
     document.f.hiddenCartao.value = mascaraHiddenCartao();
     //alert(document.f.hiddenCartao.value);
    }

  }//fim da condicao de Pagamento Cartao de Credito


  //Forma de Pagamento Debito Automatico
  if(document.f.formaPagamento[k].value==2)
   {
    //alert("Entrou no Debito Automatico");

     //###### INDICE DOS CAMPOS ######
     //Valida campos nulos do Debito Automatico
     var indice = new Array(42,44,46,48,49);
     var msg = "";

     for (var i=0; i<indice.length; i++)
      {
       if (document.forms[0].elements[indice[i]].value==null || document.forms[0].elements[indice[i]].value=="" || document.forms[0].elements[indice[i]].value==document.forms[0].elements[indice[i]].defaultValue)
	{
	 msg += document.forms[0].elements[indice[i]].name + "\n";
	} 
      }
     if (!msg=="")
      {
       alert("Estes campos sao obrigatorios\nPor favor,informe os valores dos campos:\n\n" + msg);
       document.f.formaPagamento[1].focus();
       return false;
      }

   //alert(document.f.banco.value);    
   //alert(document.f.agencia.value);
   //alert(document.f.digitoAgencia.value);
   //alert(document.f.contaCorrente.value);	
   //alert(document.f.digitoContaCorrente.value);

   objsel = document.f.banco;
   agencia = document.f.agencia.value;
   digAgencia = document.f.digitoAgencia.value;
   conta = document.f.contaCorrente.value;
   digConta = document.f.digitoContaCorrente.value;

   if (validaBanco(objsel,agencia,digAgencia,conta,digConta))
    {
     document.f.banco.focus();
     return false;
    }
   else
    {
     //alert(mascaraHiddenBanco(objsel,agencia,digAgencia,conta,digConta));
     document.f.hiddenBanco.value = mascaraHiddenBanco(objsel,agencia,digAgencia,conta,digConta);
    }

   dia = document.f.diaDebito.value;
   diaAlt = document.f.diaDebitoAlternativo.value;

   if (validaDiaDebito(dia,diaAlt))
   {
    return false;
   }    

   }//fim da condicao de Pagamento Debito Automatico

  }//fim da condicao da forma de pagamento checado
 }// fim loop das formas de pagamentos possiveis

 if(!(strCheck))
 {
  alert("Por favor,\nescolha uma forma de pagamento.");
  document.f.formaPagamento[0].focus();
  return false;
 }



//Valida canal de comunicação

 instanceCanalComunicacao(numInstance);//Chama a funcao que cria os objetos

 numInstance = tamanhoCanalComunicacao();//Chama a funcao que retorna a Quantidade de Objetos
 
 valor = parseInt(document.f.canalPrincipal.value);

 if (document.f.canalPrincipal.value=="")
  {
   alert("Por favor,\ninforme como você ficou sabendo do Greenpeace.");
   document.f.canalPrincipal.focus();
   return false;
  }
 else
  {
   if (!(document.f.canalSecundario.length==0))
    {
     if (document.f.canalSecundario.value=="")
      {
       alert("Por favor,\nespecifique como você ficou sabendo do Greenpeace.");
       document.f.canalSecundario.focus();
       return false;
      }
    }
  }


//AJUSTAR O VALOR DOS CAMPOS PARA ENVIAR

//Letra maiuscula para os campo Nome, Endereco, Complemento, Bairro, Cidade
document.f.nome.value = upperCase(document.f.nome.value);
//document.f.endereco.value = upperCase(document.f.endereco.value);
//document.f.complemento.value = upperCase(document.f.complemento.value);
document.f.bairro.value = upperCase(document.f.bairro.value);
document.f.cidade.value = upperCase(document.f.cidade.value);

//Concatena no campo hiddenEndereco os campos: Endereco+Numero+Complemento
document.f.hiddenEndereco.value = upperCase(document.f.endereco.value) + document.f.numero.value + upperCase(document.f.complemento.value);


//Retirar o hifen do CEP
document.f.cep.value=strCep;


return true;

}
