function soNumero(campo)
{
	var valorTemp=document.getElementById(campo).value;
	var valor='';
	
	for(var i=0;i<valorTemp.length;i++)
	{
		switch(valorTemp.substr(i,1))
		{
			case '0':
			case '1':
			case '2':
			case '3':
			case '4':
			case '5':
			case '6':
			case '7':
			case '8':
			case '9':
			{
				valor+=valorTemp.substr(i,1); // aceita somente considera os numeros
			}break;
		}
	}
	
	document.getElementById(campo).value=valor;
}
//-------------------------------------------------------------------------------------------
function mascaraTelefone(telefone)
{
	soNumero(telefone);
	var valor=document.getElementById(telefone).value;
		
	if(4<valor.length)
	{
		valor=valor.substr(0,4)+"-"+valor.substr(4,4)
	}
	
	document.getElementById(telefone).value=valor;
}
//-------------------------------------------------------------------------------------------
function mascaraData(data)
{
	soNumero(data);
	var valor=document.getElementById(data).value;
		
	if(2<valor.length)
	{
		valor=valor.substr(0,2)+"/"+valor.substr(2,9)
	}
	
	if(5<valor.length)
	{
		valor=valor.substr(0,5)+"/"+valor.substr(5,9)
	}
	valor=valor.substr(0,10);
	
	document.getElementById(data).value=valor;
}
//-------------------------------------------------------------------------------------------
function mascaraCEP(cep)
{
	soNumero(cep);
	var valor=document.getElementById(cep).value;
	
	if(2<valor.length)
	{
		valor=valor.substr(0,2)+"."+valor.substr(2,6)
	}
	
	if(6<valor.length)
	{
		valor=valor.substr(0,6)+"-"+valor.substr(6,3)
	}
	document.getElementById(cep).value=valor;
}
//-------------------------------------------------------------------------------------------
function verifica_ddd(valor) // aceita somente "true" ou "false" (formanto string)
{
	var retorno=true;
	
	for(var i=0;i<valor.length;i++)
	{
		switch(valor.substr(i,1))
		{
			case '0':
			case '1':
			case '2':
			case '3':
			case '4':
			case '5':
			case '6':
			case '7':
			case '8':
			case '9':
			{
				retorno=(retorno&&true);
			}break;
			default:
			{
				retorno=(retorno&&false);
			}
		}
	}		
	
	return retorno;
}
//-------------------------------------------------------------------------------------------
function verifica_Tel(valor)
{
	var retorno=true;
	var valoInicio=valor.substr(0,4);
	
	for(var i=0;i<valorInicio.length;i++)
	{
		switch(valor.substr(i,1))
		{
			case '0':
			case '1':
			case '2':
			case '3':
			case '4':
			case '5':
			case '6':
			case '7':
			case '8':
			case '9':
			{
				retorno=(retorno&&true);
			}break;
			default:
			{
				retorno=(retorno&&false);
			}
		}
	}
	
	if(5<=valor.length)
	{
		var valoMeio=valor.substr(4,1);
		if(valorMeio=='-')
		{
			retorno=(retorno&&true);
		}
		else
		{
			retorno=(retorno&&false);
		}
	}
	
	if(5<valor.length)
	{
		var valoFim=valor.substr(5,4);
		for(var i=0;i<valorFim.length;i++)
		{
			switch(valor.substr(i,1))
			{
				case '0':
				case '1':
				case '2':
				case '3':
				case '4':
				case '5':
				case '6':
				case '7':
				case '8':
				case '9':
				{
					retorno=(retorno&&true);
				}break;
				default:
				{
					retorno=(retorno&&false);
				}
			}
		}
	}
	
	return retorno;
}
//-------------------------------------------------------------------------------------------
function valida_ddd(ddd, obrigatorio) // aceita somente "true" ou "false" (formanto string)
{
	var ddd    = document.getElementById(ddd);
	var strddd = ddd.value;
	
	if((obrigatorio == "true") || (obrigatorio == "false" && strddd != ""))
	{
		if((strddd.length != 2)||(strddd == ""))
		{
			alert("DDD informado inválido.");
			return false
		}
	}
}
//-------------------------------------------------------------------------------------------
function valida_tel(ddd, telefone, obrigatorio) // aceita somente "true" ou "false" (formanto string)
{
	var tel    = document.getElementById(telefone);
	var ddd    = document.getElementById(ddd);
	var strtel = ddd.value+"|"+tel.value;

	if((obrigatorio == "true") || (obrigatorio == "false" && strtel != "|"))
	{
		if(ddd.value.length != 2)
		{
			if (tel.value.length != 9)
			{
				alert("DDD e Telefone informado inv&aacute;lido.");
			}
			else
			{
				alert("DDD informado inv&aacute;lido.");
			}
			return false
		}
		else if (tel.value.length != 9)
		{
			alert("Telefone informado inv&aacute;lido.");
			return false
		}
		else 
		{
			if((strtel.indexOf("|") != 2)&&(strtel.indexOf("-") != 7))
			{
				if((strtel.indexOf("|") != 2))
				{
					alert(" Formato do DDD informado inv&aacute;lido.");
				}
				else
				{
					alert(" Formato do Telefone informado inv&aacute;lido.");
				}
				
				return false
			}
			else
			{
				if (isNaN(strtel.replace("|","0").replace("-","0")))
				{
					alert("Telefone informado inv&aacute;lido.");
					return false
				}
			}
		}
	}
}
//-------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------
function valida_dtExpiracao(data, obrigatorio) // aceita somente "true" ou "false" (formanto string)
{
	var strdata = document.getElementById(data).value;

	if((obrigatorio == "true") || (obrigatorio == "false" && strdata != ""))
	{
		if(strdata.length != 10)
		{
			//alert("Data de Expira&ccedil;&atilde;o informada inv&aacute;lida.");
			alert("Data de Expiração informada inválida.");
			return false;
		}
		else 
		{
			if((strdata.indexOf("/") != 2)&&(strdata.lastIndexOf("/") != 5))
			{
				//alert("Formato da Data de Expira&ccedil;&atilde;o informada inv&aacute;lida.");
				alert("Formato da Data de Expiração informada inválida.");
				return false;
			}
			else
			{
				if (isNaN(strdata.replace("\/","0").replace("\/","1")))
				{
					//alert("Data de Expira&ccedil;&atilde;o informada inv&aacute;lida.");
					alert("Data de Expiração informada inválida.");
					return false;
				}
			}
		}
	}
}
//-------------------------------------------------------------------------------------------
function valida_cep(CEP, obrigatorio) // aceita somente "true" ou "false" (formanto string)
{
	var cep    = document.getElementById(CEP);
	var strcep = cep.value;
	
	if((obrigatorio == "true") || (obrigatorio == "false" && strcep != ""))
	{
		if (strcep.length != 10)
		{
			alert("CEP informado inválido.");
			return false
		}
		else
		{
			if((strcep.indexOf(".") != 2)||(strcep.indexOf("-") != 6))
			{
				alert("Formato de CEP informado inválido.");
				return false
			}
			else
			{
				if(isNaN(strcep.replace("-","0").replace(".","0"))) // verifica se o capo cep somente possui numeros
				{
					alert("CEP informado inválido.");
					return false
				}
			}
		}
	}
}
//-------------------------------------------------------------------------------------------

