function isNull (valor) {
   return (valor == "");
}
function isNullRadio (valor) {
   return (valor == "");
}
function isSelected (valor) {
   return (valor != "%");
}
function isNumber(valor)
{
  if (isNaN(Math.abs(valor)) && (valor.charAt(0) != "#"))
  {
      if ( typeof theElementname == "undefined" )
      {
         return false;
      } 
      else 
      { 
         for (var i=0; (i <= valor.length && valor.charAt(i) != "."); )
         {
          if (((valor.charAt(i) >= 0) && (valor.charAt(i) <= 9)) ||
               (valor.charAt(i) == "," && i != 0 && i != valor.length-1) || (valor.charAt(i) == ".") )
                 i++;
          else 
           { 
             return false;
           } 
         } 
        if (valor.charAt(i) == ".")
         { 
	     for (i++;i <= valor.length; )
           { 
            if (((valor.charAt(i) >= 0) && (valor.charAt(i) <= 9)))
              i++; 
            else 
            { 
             return false;
            } 
           } 
         } 
       }
  } 
  return true;
}
function isCpf(theElement){
   var mycpf = theElement;
   d1 = 0;
   d2 = 0;
   xx = 1;
   for (var i = 0 ; i <= mycpf.length - 1 ; i++) {
   if (mycpf.charAt(i) != "-") {
      caract = mycpf.charAt(i)
      parseInt(caract)
      d1 = d1 + ((11 - xx)*caract)
      d2 = d2 + ((11 - xx)*caract)
      xx = xx + 1
      }
   }
   resto = d1 - (Math.floor(d1/11)*11)
   if (resto < 2){
      digito = 0
   }
   else {
      digito = 11 - resto
   }
   d2 = d2 + (2 * digito)
   resto = d2 - (Math.floor(d2/11)*11)
   str_digito = "" + digito
   len_digito = str_digito.length - 1
   a = str_digito.charAt(len_digito)
   b = str_digito.charAt(len_digito + 1)
   parseInt(a)
   parseInt(b)
   digito = a + b
   tocompare1 = str_digito.charAt(len_digito)
   if (resto < 2){
      var tocompare2 = 0
   }
   else {
      var tocompare2 = (11 - resto)
   }
   parseInt(tocompare1)
   parseInt(tocompare2)
   tocompare = (tocompare1 - (-tocompare2));
	 if (digito == tocompare) {
      return true;
   }
   else {
      return false;
   }
}
function isEmail(valor){
//  if (window.RegExp) {
//    var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
//    var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$";
//    var reg1 = new RegExp(reg1str);
//    var reg2 = new RegExp(reg2str);
//    if (!(!reg1.test(valor) && reg2.test(valor))) {
//      return false; 
//    }
//  } else {
    if((valor.indexOf("@") <= 0)||(valor.indexOf("@")>=(valor.length-6)))
      return false;
//  }
  return true;
} 

function isDate (valor)
{
data = valor.split("/");
if (data.length != 3){
   return false;
   }
dia = data[0];
mes = data[1];
ano = data[2];
iano = parseFloat(ano-0);
imes = parseInt(mes-0);
idia = parseInt(dia-0);
if (isNaN(idia)||(dia!=idia)) {
   return false;
}
if (isNaN(imes)||(mes!=imes)) {
   return false;
}
if (isNaN(iano)||(ano!=iano)) {
   return false;
}
   if ((dia < 1) || (dia > 31)){
      return false;
      }
   if ((mes < 1) || (mes > 12)){
      return false;
      }
   if (ano == 0){
      return false;
      }
   if ((mes == 1) || (mes == 3) || (mes == 5) || (mes == 7) || (mes == 8) || (mes == 10) || (mes == 12)) {
      if (dia > 31){
         return false;
         }
      }
   if ((mes == 4) || (mes == 6) || (mes == 9) || (mes == 11)) {
      if (dia > 30){
         return false;
         }
      }
   if (mes == 2){
      if (ano % 4 == 0){
         if (dia > 29){
            return false;
            }
         } else {
         if (dia > 28){
            return false;
            }
         }
      }
  return true;
}
function parseDate (valor)
{
   data = valor.split("/");
   dia = data[0];
   mes = data[1];
   ano = data[2];
	 if (dia.charAt(0) == "0") dia = dia.substring(1);
	 if (mes.charAt(0) == "0") mes = mes.substring(1);
   iano = parseFloat(ano-0);
   imes = parseInt(mes)-1;
   idia = parseInt(dia-0);
   var dataRet=new Date(iano,imes,idia)
   return dataRet
}
qtd=0;
function validaTecla(filtro){
   var tecla = String.fromCharCode(event.keyCode);
   var retorno = false;
   for (a=0;a<filtro.length;a++){
      if (filtro.substr(a,1)==tecla){
	     retorno = true;
          }
   }
   if (!retorno) {
      qtd++;
      if (qtd==3) {
         alert('Digitação inválida!\nEste campo aceita apenas os seguintes caracteres:\n'+filtro);
         qtd=0;
      }
   }
   return retorno;
}
function FormataData(Campo) 
{
	var tecla = String.fromCharCode(event.keyCode);
	vr = Campo.value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;
	if ( tecla != 9 && tecla != 8 )
	{
		if ( tam > 2 && tam < 5 )
			Campo.value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 10 )
			Campo.value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 );
	}
}
