// Rotinas Pronus

// --------------------------------------------------------------------------------------------------------
function habilitaElemento( enable, objDest )
{
	objDest.disabled = !enable;
	if ( objDest.disabled )
		{
		objDest.value = "";
		objDest.blur();
		}
	else
		{
		objDest.focus();
		}
}

// --------------------------------------------------------------------------------------------------------
function checkMail( email )
{
  var re = /^[A-Za-z0-9_\-]+([.][A-Za-z0-9_\-]+)*[@][A-Za-z0-9_\-]+([.][A-Za-z0-9_\-]+)+$/;
  return re.test( email );
}



// --------------------------------------------------------------------------------------------------------
function IsEmailValid( strEmail )
{
   var Cont = 0;
   
   // Precisa conter pelo menos cinco caracteres
   if ( strEmail.length < 6 ) return false;

   // Precisa conter um sinal de arroba
   for ( Cont = 0; Cont < strEmail.length; Cont++ )
		if ( strEmail.charAt( Cont ) == '@' )
			break;
   if ( Cont == strEmail.length ) return false;
			    
   // Precisa conter pelo menos um ponto ap� o sinal de arroba
   for ( Cont++; Cont < strEmail.length; Cont++ )
        if ( strEmail.charAt( Cont ) == '.' )
            break;
   if ( Cont == strEmail.length ) return false;
                   
   return true;
}

// --------------------------------------------------------------------------------------------------------
function isEmpty( s )
{
   return ( ( s == null ) || ( s.length == 0 ) );
}

// --------------------------------------------------------------------------------------------------------
function RemoveSymbols( Texto, Symbols )
{
   var i = 0;
   var TextoFinal = "";
   
   if ( Symbols == null ) 
      Symbols = '.,;-/\|()%!?*#$=:';
	  
   for ( i = 0; i < Texto.length; i++ )
      {
	  if ( Symbols.indexOf( Texto.charAt( i ) ) == -1 )
	     {
		 TextoFinal += Texto.charAt( i );
		 }
      }
   return TextoFinal;
}

// --------------------------------------------------------------------------------------------------------
function isCNPFOrCPFValid( DocNo )
{
   var IsCNPJ = false;
   var DocNoCalculado = "";
   var i = 0;
   var Multiplicador = 0;
   var Soma = 0;
   var Digito = 0;
   var CharNo = 0;

   DocNo = RemoveSymbols( DocNo );
   if ( isNaN( Number( DocNo ) ) )
      {
      return false;
	  }
   
   if ( DocNo.length == 11 )
      {
	  IsCNPJ = false;
	  }
   else if ( DocNo.length == 14 )
      {
	  IsCNPJ = true;
	  }
   else
      {
	  return false;
	  }
   
   DocNoCalculado = DocNo.slice( 0, -2 );
   
   for( i = 0; i < 2; i++ )
      {
	  Multiplicador = 2;
	  Soma = 0;
	  for( CharNo = DocNoCalculado.length - 1; CharNo >= 0; CharNo-- )
	     {
		 Digito = Number( DocNoCalculado.charAt( CharNo ) );
		 Soma  += Digito * Multiplicador;
		 Multiplicador++;
		 if ( ( Multiplicador > 9 ) && IsCNPJ )
		    {
			Multiplicador = 2;
			}
		 }
      Digito = 11 - ( Soma % 11 );
      if ( Digito >= 10 )
         {
	     Digito = 0;
	     }
      DocNoCalculado += Digito;
	  }
   return ( DocNo == DocNoCalculado );
}


// --------------------------------------------------------------------------------------------------------
function checkNumbers( texto )
{
   return !isEmpty( texto ) && !isNaN( Number( RemoveSymbols( texto ) ) );
}

// ---------------------------------------------------------
function checkEnqueteForm( formEnquete ) {
	var aprovado = false;
	for ( var i = 0; i < formEnquete.elements.length; i++ )
		{
		var e=formEnquete.elements[i];
		if (( e.type == 'radio' || e.type=='checkbox' ) && e.checked )
			{
			aprovado = true;
			}
		}
	if ( aprovado )
		{ formEnquete.submit(); }
	else 
		{ alert( 'Escolha uma alternativa antes de enviar seu voto.' ); }
}