function twFctFormataCep(cmpCep){ 

	var ftCepTexto = "";
	var ftCepNumero = "";
	var ftRegExpSohNumeros = /^\d$/;

	if(typeof(cmpCep)=="object")
		ftCepTexto = cmpCep.value.toString();
	else
		ftCepTexto = cmpCep.toString();
	
	for(ft_x = 0; ft_x < ftCepTexto.length; ft_x ++)
		if(ftRegExpSohNumeros.test(ftCepTexto.charAt(ft_x)))
			ftCepNumero += ftCepTexto.charAt(ft_x).toString();

	ftCepTexto = "";

	//Coloca "-" nos números
	for(ft_x = 0; ft_x < ftCepNumero.length; ft_x ++){
		if(ft_x < 10){
			switch(ft_x){
				case 5: ftCepTexto += "-"; break;
			}
			ftCepTexto += ftCepNumero.charAt(ft_x).toString();
		}
	}

	if(typeof(cmpCep)=="object")
		cmpCep.value = ftCepTexto;
	else
		return(ftCepTexto);
}

//Formata um texto no padrão de CPF (xxx.xxx.xxx-xx)
//Entradas: (string) ou (object)
//Retorno:
//   Se for (string), retorna o texto formatado.
//   Se for (object), não retorna nenhum valor, sendo o texto formatado ao atributo (object).value
function twFctFormataCpf(fcCpf){ 

	var fcCpfTexto = "";
	var fcCpfNumero = "";
	var fcRegExpSohNumeros = /^\d$/;

	if(typeof(fcCpf)=="object")
		fcCpfTexto = fcCpf.value.toString();
	else
		fcCpfTexto = fcCpf.toString();

	//Deixa apenas os números
	for(fc_x = 0; fc_x < fcCpfTexto.length; fc_x ++)
		if(fcRegExpSohNumeros.test(fcCpfTexto.charAt(fc_x)))
			fcCpfNumero += fcCpfTexto.charAt(fc_x).toString();

	fcCpfTexto = "";

	//Coloca "." e "-" nos números
	for(fc_x = 0; fc_x < fcCpfNumero.length; fc_x ++){
		if(fc_x <= 10){
			fcCpfTexto += fcCpfNumero.charAt(fc_x).toString();
			switch(fc_x){
				case 2: fcCpfTexto += "."; break;
				case 5: fcCpfTexto += "."; break;
				case 8: fcCpfTexto += "-"; break;
			}
		}
	}

	if(typeof(fcCpf)=="object")
		fcCpf.value = fcCpfTexto;
	else
		return(fcCpfTexto);

}

//Formata um texto no padrão de CNPJ (xxx.xxx.xxx/xxxx-xx)
//Entradas: (string) ou (object)
//Retorno:
//   Se for (string), retorna o texto formatado.
//   Se for (object), não retorna nenhum valor, sendo o texto formatado ao atributo (object).value
function twFctFormataCnpj(fcCnpj){ 

	var fcCnpjTexto = "";
	var fcCnpjNumero = "";
	var fcRegExpSohNumeros = /^\d$/;

	if(typeof(fcCnpj)=="object")
		fcCnpjTexto = fcCnpj.value.toString();
	else
		fcCnpjTexto = fcCnpj.toString();

	//Deixa apenas os números
	for(fc_x = 0; fc_x < fcCnpjTexto.length; fc_x ++)
		if(fcRegExpSohNumeros.test(fcCnpjTexto.charAt(fc_x)))
			fcCnpjNumero += fcCnpjTexto.charAt(fc_x).toString();

	fcCnpjTexto = "";

	//Coloca ".", "/" e "-" nos números
	for(fc_x = 0; fc_x < fcCnpjNumero.length; fc_x ++){
		if(fc_x <= 14){
			fcCnpjTexto += fcCnpjNumero.charAt(fc_x).toString();
			switch(fc_x){
				case 2: fcCnpjTexto += "."; break;
				case 5: fcCnpjTexto += "."; break;
				case 8: fcCnpjTexto += "/"; break;
				case 12: fcCnpjTexto += "-"; break;
			}
		}
	}

	if(typeof(fcCnpj)=="object")
		fcCnpj.value = fcCnpjTexto;
	else
		return(fcCnpjTexto);

}

//Formata um texto no padrão de telefone (xx) xxxx-xxxx
//Entradas: (string) ou (object)
//Retorno:
//   Se for (string), retorna o texto formatado.
//   Se for (object), não retorna nenhum valor, sendo o texto formatado ao atributo (object).value
function twFctFormataTelefone(ftTelefone){ 

	var ftTelefoneTexto = "";
	var ftTelefoneNumero = "";
	var ftRegExpSohNumeros = /^\d$/;

	if(typeof(ftTelefone)=="object")
		ftTelefoneTexto = ftTelefone.value.toString();
	else
		ftTelefoneTexto = ftTelefone.toString();
	
	//Verifica se o número é menor que 14 digitos
	//Padrão: (nn) nnnn-nnnn
	//Se for maior pode ser dados relativos a ramal, e não precisam de formatação
	if(ftTelefoneTexto.length <= 14){	
		//Deixa apenas os números
		for(ft_x = 0; ft_x < ftTelefoneTexto.length; ft_x ++)
			if(ftRegExpSohNumeros.test(ftTelefoneTexto.charAt(ft_x)))
				ftTelefoneNumero += ftTelefoneTexto.charAt(ft_x).toString();
	
		ftTelefoneTexto = "";
	
		//Coloca "()" e "-" nos números
		for(ft_x = 0; ft_x < ftTelefoneNumero.length; ft_x ++){
			if(ft_x < 10){
				switch(ft_x){
					case 0: ftTelefoneTexto += "("; break;
					case 2: ftTelefoneTexto += ") "; break;
					case 6: ftTelefoneTexto += "-"; break;
				}
				ftTelefoneTexto += ftTelefoneNumero.charAt(ft_x).toString();
			}
		}
	
	}

	if(typeof(ftTelefone)=="object")
		ftTelefone.value = ftTelefoneTexto;
	else
		return(ftTelefoneTexto);
}

//Limita a digitação para apenas de números e virgula em um campo (Padrão de moeda).
function twFctSoMoeda(smEvento){
	var smCaracteresValidos = '0123456789.,-';	
	var smCodigoCaracter = (window.Event) ? smEvento.which : smEvento.keyCode;
	if (smCodigoCaracter == 13) 
		return true;

	var smCaracter = String.fromCharCode(smCodigoCaracter);
	if (smCaracteresValidos.indexOf(smCaracter) == -1) 
		return false;
}

//Utilizando na hora do cadastro do cliente
function twFctSoLogin(smEvento){
	var smCodigoCaracter = (window.Event) ? smEvento.which : smEvento.keyCode;
	if (smCodigoCaracter == 13) 
		return true;

	var smCaracter = String.fromCharCode(smCodigoCaracter);
	var ieRegExp = /^[a-zA-Z0-9]$/;
	return ieRegExp.test(smCaracter);
}

function twFctNoCache(){
	var d = new Date();
	return(d.getTime().toString());
}
