/*
function isNumber(obj){
var numeros = "0123456789";	//Numeros validos
var tamanho = obj.length;	//Quantidade de caracteres

  for (var i=0; i<tamanho; i++)
  {
   var caracter = obj.charAt(i)	//Caracteres separados
   //Testa se não foram digitados números
   if (numeros.indexOf(caracter)==-1)	//Condicao para o caracter nao estar nos numeros validos
    {
     //alert('Não Digitou números!'); 
     return false;
    }
  }
 return true;
}
*/


function addZero(valor,tamanho){

 for (var i = valor.length; i<tamanho; i++)
 {
  valor = "0" + valor;  
 
 }
return valor;
}



function upperCase(valor){

valorMaiusculo = valor.toUpperCase();

return valorMaiusculo

}



function isNumber(tecla){
//alert(tecla.keyCode);
 if ( (!(tecla.keyCode >= '48' && tecla.keyCode <= '57')) && (!(tecla.keyCode == '127' || tecla.keyCode== '13')) )
  {
   tecla.keyCode = '127';
   return false;
  }
return true;
}



function isNumberDecimal(tecla){
//alert(tecla.keyCode);
 if ( (!(tecla.keyCode >= '48' && tecla.keyCode <= '57')) && (!(tecla.keyCode == '127' || tecla.keyCode== '44' || tecla.keyCode== '13')) )
  {
   tecla.keyCode = '127';
   return false;
  }
return true;
}



function isUpper(tecla){

//alert(tecla.keyCode);

 if ( (!(tecla.keyCode >= '65' && tecla.keyCode <= '90')) && (!(tecla.keyCode >= '195' && tecla.keyCode <= '221')) && (!(tecla.keyCode == '32' || tecla.keyCode== '13')) )
  {
   tecla.keyCode = '127';
   return false;
  }
return true;
}


//digite apenas letras minúsculas com ou sem acento ou espaco.
function isLower(tecla){

//alert(tecla.keyCode);

 if ( (!(tecla.keyCode >= '97' && tecla.keyCode <= '122')) && (!(tecla.keyCode >= '224' && tecla.keyCode <= '253')) && (!(tecla.keyCode == '32' || tecla.keyCode== '13')) )
  {
   tecla.keyCode = '127';
   return false;
  }
return true;
}

//digite apenas letras minúsculas ou os caracteres: @ e ponto.
function isLowerEmail(tecla){

//alert(tecla.keyCode);

 if ( (!(tecla.keyCode >= '97' && tecla.keyCode <= '122')) && (!(tecla.keyCode >= '48' && tecla.keyCode <= '57')) && (!(tecla.keyCode == '46' || tecla.keyCode == '64' || tecla.keyCode== '13')) )
  {
   tecla.keyCode = '127';
   return false;
  }
return true;
}




function isChar(tecla){

//alert(tecla.keyCode);

 if ( (!(tecla.keyCode >= '65' && tecla.keyCode <= '90')) && (!(tecla.keyCode >= '97' && tecla.keyCode <= '122')) && (!(tecla.keyCode >= '195' && tecla.keyCode <= '253')) && (!(tecla.keyCode==13 || tecla.keyCode==32)) )
  {
   tecla.keyCode = '127';
   return false;
  }
return true;
}



function isCharUsual(tecla){

//alert(tecla.keyCode);

 if ( (!(tecla.keyCode >= '65' && tecla.keyCode <= '90')) && (!(tecla.keyCode >= '97' && tecla.keyCode <= '122')) && (!(tecla.keyCode >= '195' && tecla.keyCode <= '253')) && (!(tecla.keyCode==13 || tecla.keyCode==32 || tecla.keyCode==45 || tecla.keyCode==40 || tecla.keyCode==41)) )
  {
   tecla.keyCode = '127';
   return false;
  }
return true;
}



function isCharNumber(tecla){

//alert(tecla.keyCode);

 if ( (!(tecla.keyCode >= '48' && tecla.keyCode <= '57')) && (!(tecla.keyCode >= '65' && tecla.keyCode <= '90')) && (!(tecla.keyCode >= '97' && tecla.keyCode <= '122')) && (!(tecla.keyCode >= '195' && tecla.keyCode <= '253')) && (!(tecla.keyCode==13 || tecla.keyCode==32 || tecla.keyCode==44 || tecla.keyCode==45 || tecla.keyCode==40 || tecla.keyCode==41)) )
  {
   tecla.keyCode = '127';
   return false;
  }
return true;
}




//Valida email
function isEmail(str)
{
	var supported = 0;
	if (window.RegExp) {
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) supported = 1;
	}
	if (!supported) 
		return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	return (!r1.test(str) && r2.test(str));
}




function isCpf(valor){
 
 //alert(valor.length);
 if (valor.length==11)
  {var aux = 0;
   for (var i=0; i<9; i++)
   {
    aux = aux + parseInt(valor.substr(i,1)) * parseInt(i+1);
   } 

   var resto = aux%11
   if (resto==10) resto=0;
   if(resto==valor.substr(9,1))
   {
     //alert("Ok - Check 01");
     var aux = 0;
     for (var i=1; i<10; i++)
     {
      aux = aux + parseInt(valor.substr(i,1)) * parseInt(i);
     } 

     var resto = aux%11
     if (resto==10) resto=0;
     if(resto==valor.substr(10,1))
     {
      //alert("Ok - Check 02");
      return true;
     }
     else
     {
      return false;
     }

   }
   else
   {
    return false;
   }
  }

}




function isMod10(valor) { // LUHN Formula for validation of credit card numbers.
 var ar = new Array( valor.length );
 var i = 0,sum = 0;

 for( i = 0; i < valor.length; ++i ) {
  ar[i] = parseInt(valor.charAt(i));
  }
 
 for( i = ar.length -2; i >= 0; i-=2 ) { // you have to start from the right, and work back.
  ar[i] *= 2;			// every second digit starting with the right most (check digit)
  if( ar[i] > 9 ) ar[i]-=9; 	// will be doubled, and summed with the skipped digits.
  }					// if the double digit is > 9, add those individual digits together 

 for( i = 0; i < ar.length; ++i ) {
  sum += ar[i];			// if the sum is divisible by 10 mod10 succeeds
  }
  
 return (((sum%10)==0)?true:false);	 	
}



function expired( month, year ) {
 
 var now = new Date();		// this function is designed to be Y2K compliant.
 var expiresIn = new Date(year,month,0,0,0); // create an expired on date object with valid thru expiration date
 
 expiresIn.setMonth(expiresIn.getMonth()+1); // adjust the month, to first day, hour, minute & second of expired month
 
 if( now.getTime() < expiresIn.getTime() ) return false;
  return true;		// then we get the miliseconds, and do a long integer comparison
}




/*
function isModulo10(valor){

//alert(valor.length);
 if (valor.length==10)
  {var aux = 0;
   for (var i=0; i<9; i++)
   {
    aux = aux + parseInt(valor.substr(i,1)) * parseInt(i+1);
   } 

   var resto = aux%11
   if(resto==valor.substr(9,1))
   {
    return true;
   }
   else
   {
    return false;
   }
  }
}


function isModulo11(valor){

//alert(valor.length);
 if (valor.length==10)
  {var aux = 0;
   for (var i=0; i<9; i++)
   {
    aux = aux + parseInt(valor.substr(i,1)) * parseInt(i+1);
   }

   var resto = aux%11
   if(resto==valor.substr(9,1))
   {
    return true;
   }
   else
   {
    return false;
   }
  }
}
*/