// JavaScript Document

function ShowFoto(Arquivo)
{
   window.open("FotoGrande.php?Arquivo=" + Arquivo,"Foto","height=540, width=710, menubar=no, scrollbars=no, status=no, toolbar=no, location=no");
}   

function VerificaExtensao(Campo, Extensao, MensagemErro)
{
   var Retorno = usfw_CheckExtension(Campo,'.' + Extensao);
   if (!Retorno)
     {
       alert(MensagemErro);
	   usfw_Focus(Campo);
	 }
   return Retorno;
}

function CheckCadastroUNT(AllowEmptyPassword)
{
   if (AllowEmptyPassword)
     var Ok = usfw_CheckFields('Nome', 'Sobrenome', 'Sexo', 'AnoNascimento', 'Endereco', 'NumeroEndereco', 'ComplementoEndereco', 'Bairro', 'Cidade', 'UF', 'CEP', 'Telefones', 'Celular', 'Email', 'CodigoAgenciador', 'LoginCadastro', 'Altura','Peso','Sapato','Manequim','Cabelo','Cutis','CorOlhos');   
   else
     var Ok = usfw_CheckFields('Nome', 'Sobrenome', 'Sexo', 'AnoNascimento', 'Endereco', 'NumeroEndereco', 'ComplementoEndereco', 'Bairro', 'Cidade', 'UF', 'CEP', 'Telefones', 'Celular', 'Email', 'CodigoAgenciador', 'LoginCadastro', 'Senha', 'RepitaSenha','Altura','Peso','Sapato','Manequim','Cabelo','Cutis','CorOlhos');
   var x = 0;
   
   if (Ok)
     {
       Ok = Ok && (usfw_GetHTML('NomeAgenciador') != 'Agenciador não encontrado') && (Trim(usfw_GetHTML('NomeAgenciador')) != '');
	   if (!Ok)
	     {
			 alert('Escolha o agenciador');
			 usfw_Focus('CodigoAgenciador');
		 }
	 }

   // Verifica as fotos
   if (Ok)
     Ok = Ok && VerificaExtensao('Foto1','JPG','Escolha um arquivo JPG para a foto 1');

   if (Ok)
     Ok = Ok && VerificaExtensao('Foto2','JPG','Escolha um arquivo JPG para a foto 2');

   if (Ok)
     Ok = Ok && VerificaExtensao('Foto3','JPG','Escolha um arquivo JPG para a foto 3');

   if (Ok)
     Ok = Ok && VerificaExtensao('Foto4','JPG','Escolha um arquivo JPG para a foto 4');

   // Verifica o arquivo FLV
   if (Ok)
     Ok = Ok && VerificaExtensao('FLV','FLV','Escolha um arquivo no formato FLV');

   if (Ok)
     {
       document.getElementById('DataNascimento').value = document.getElementById('AnoNascimento').value + '-' + document.getElementById('MesNascimento').value + '-' + document.getElementById('DiaNascimento').value;
       Ok = Ok && (Trim(usfw_GetHTML('ErroEmail')) == '') && (usfw_GetHTML('ErroSenha') == '');
	   if (!Ok)
	     alert('Corriga os campos em destaque.');
	 }

if (Ok)
     {
       Ok = Ok && (usfw_GetHTML('ErroLogin') == '') && (usfw_GetHTML('ErroEmail') == '') && (usfw_GetHTML('ErroSenha') == '');
	   if (!Ok)
	     alert('Corriga os campos em destaque.');
	 }

  return Ok;
}


function VerificaCadastro(AllowEmptyPassword)
{
   if (AllowEmptyPassword)
     var Ok = usfw_CheckFields('Nome', 'AnoNascimento', 'Bairro', 'Cidade', 'Estado', 'Email');
   else
     var Ok = usfw_CheckFields('Nome', 'AnoNascimento', 'Bairro', 'Cidade', 'Estado', 'Email', 'Senha', 'RepitaSenha');
   var x = 0;
   var Preferencias = '';
   if (Ok)
     Ok = Ok && usfw_CheckDate('DiaNascimento','MesNascimento','AnoNascimento');

   if (Ok)
     {
       Ok = Ok && (usfw_GetHTML('ErroEmail') == '') && (usfw_GetHTML('ErroSenha') == '');
	   if (!Ok)
	     alert('Corriga os campos em destaque.');
	 }

  if (Ok)
  {
    while (document.getElementById('chk_' + x))
	  {
		 if (document.getElementById('chk_' + x).checked) 
		   Preferencias = Preferencias + document.getElementById('chk_' + x).value + '|';
		 x++;
	  }
	document.getElementById('PreferenciasEscolhidas').value = Preferencias;
  }
  
  return Ok;
}


function CheckPasswordOk()
{
   Senha = document.getElementById('Senha').value;	
   RepitaSenha = document.getElementById('RepitaSenha').value;	
   
   Html = '';
   if ((Senha != '') && (RepitaSenha != ''))
     if (Senha != RepitaSenha)
	   Html = '<div class="classErro">As senhas n&atilde;o coincidem. Retifique-as.<div>';
   
   usfw_PutHTML('ErroSenha',Html);
}

function ChangePage(Pagina)
{
    // Invisível
    
	var i=1;
	while (document.getElementById('divPagina_' + i))
    {
  	   usfw_ShowHide('divPagina_' + i,false);
	   i++;
    }


	i=1;
	while (document.getElementById('tbPagina_' + i))
    {
	   usfw_ChangeClass('tbPagina_' + i, 'classAbaNaoSelecionada');
	   i++;
    }


	// Visível
	usfw_ShowHide('divPagina_' + Pagina,true);
	usfw_ChangeClass('tbPagina_' + Pagina, 'classAbaSelecionada');

}

function ComputarVoto(NomeEnquete)
{
   if (usfw_IsEmpty('opcao_' + NomeEnquete))
     alert('Escolha uma alternativa');
   else
     usfw_AjaxWait('votarenquete.php?Acao=SalvarDadosEnquete&Identificador=' + NomeEnquete + '&idItemEnquete=' + document.getElementById('opcao_' + NomeEnquete).value,'div' + NomeEnquete);
   return false;
}

function MostrarResultadoEnquete(NomeEnquete)
{
    var i = 1;
    while (document.getElementById('ResultadoParcial_' + NomeEnquete + '_' + i))
	{
		usfw_Toogle('ResultadoParcial_' + NomeEnquete + '_' + i);
		i++;
	}
	usfw_Toogle('TotalEnquete_' + NomeEnquete);	
}