var numeros    = "0123456789";
var moeda      = "0123456789,";
var letras     = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
var acentuacao = "áàãâäéèêëíìîïóòõôöúùûüçÁÀÃÂÄÉÈÊËÍÌÎÏÓÒÕÔÖÚÙÛÜÇ";
var especiais  = "_.,+-=\*/<>;:()%$!?";

var validos = numeros + letras + acentuacao + especiais + " ";

function FormataData( data )
{    var tam = data.value.length;
    if (((event.keyCode) >= 44 ) && ((event.keyCode) <= 57 ))
    {    event.keyCode;
        if ( ( tam == 2 ) || ( tam == 5 ) )
        {    data.value = data.value + "/";    }
    }
    else
    {    event.keyCode = 0;    }
}

function MascaraNumero(campo, evento)
	{
	var tecla = String.fromCharCode(evento.keyCode);
	
	//alert(tecla);
	
 	if (tecla == ".")
 		{
    if(campo.value.indexOf(".") == -1)
    	{
    	return true;
    	}
    else
    	{
    	return false;
    	}
    }
  else if(numeros.indexOf(tecla) == -1)
  	{
  	return false;
  	}
	
	return true;
	}

function formata_moeda(fld, milSep, decSep, e) {
var sep = 0;
var key = '';
var i = j = 0;
var len = len2 = 0;
var strCheck = '0123456789';
var aux = aux2 = '';
var whichCode = (window.Event) ? e.which : e.keyCode;

if (whichCode == 13) return true;  // Enter
key = String.fromCharCode(whichCode);  // Get key value from key code

if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
len = fld.value.length;

for(i = 0; i < len; i++)
	if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;

aux = '';

for(; i < len; i++)
	if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);

aux += key;

len = aux.length;

if (len == 0) fld.value = '';

if (len == 1) fld.value = '0'+ decSep + '0' + aux;

if (len == 2) fld.value = '0'+ decSep + aux;

if (len > 2) {
	aux2 = '';
	for (j = 0, i = len - 3; i >= 0; i--) {
		if (j == 3) {
			aux2 += milSep;
			j = 0;
		}
	aux2 += aux.charAt(i);
	j++;
}

fld.value = '';
len2 = aux2.length;

for (i = len2 - 1; i >= 0; i--)
fld.value += aux2.charAt(i);
fld.value += decSep + aux.substr(len - 2, len);
}
return false;
}

function Limpar(valor, validos) {
// retira caracteres invalidos da string
var result = "";
var aux;
for (var i=0; i < valor.length; i++) {
aux = validos.indexOf(valor.substring(i, i+1));
if (aux>=0) {
result += aux;
}
}
return result;
}

//Formata número tipo moeda usando o evento onKeyDown

function FormataValor(campo,tammax,teclapres) {


if (teclapres.keyCode >= 48 && teclapres.keyCode <=57 )
{
  var tecla = teclapres.keyCode;

vr = Limpar(campo.value,"0123456789");
tam = vr.length;


  if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

  if (tecla == 8 )
     { tam = tam - 1 ; }

  if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )
  {
  dec=2
  if ( tam <= dec )
  { campo.value = vr ; }

  if ( (tam > dec) && (tam <= 5) ){
  campo.value = vr.substr( 0, tam - 2 ) + "," + vr.substr( tam - dec, tam ) ; }
  if ( (tam >= 6) && (tam <= 8) ){
  campo.value = vr.substr( 0, tam - 5 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ;
  }
  if ( (tam >= 9) && (tam <= 11) ){
  campo.value = vr.substr( 0, tam  - 8 ) + "." + vr.substr( tam  - 8, 3 ) +  "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
  if ( (tam >= 12) && (tam <= 14) ){
  campo.value = vr.substr( 0, tam - 11 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
  if ( (tam >= 15) && (tam <= 17) ){
  campo.value = vr.substr( 0, tam - 14 ) + "." + vr.substr( tam - 14, 3 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - 2, tam ) ;}
  }
}
else
{
  teclapres.keyCode=0;
  campo.value = Limpar(campo.value,"0123456789");
  teclapres.keyCode=0;
}
}

function MascaraTelefone(Campo, Mascara)
{
var Tecla = window.event.keyCode;
var ValorCampo = Campo.value;
var Seps = ".-,:;/";
var EstaMascara = Mascara.substring(ValorCampo.length,ValorCampo.length+1);
var ProxMascara = Mascara.substring(ValorCampo.length+1,ValorCampo.length+2);
var Ret=false;
// BackSpace ou TAB
if (Tecla==8 || Tecla==9 || window.event.ctrlKey==true) { return true; }
// Números
if (Tecla>47 && Tecla<58 && (EstaMascara=="#" || EstaMascara=="?")==true) { Ret=true; }
// Letras
if (Tecla>96 && Tecla<123 && (EstaMascara=="@" || EstaMascara=="?")==true) { Ret=true; }
if (Tecla>64 && Tecla<91 && (EstaMascara=="@" || EstaMascara=="?")==true) { Ret=true; }
if (Ret==true)
{
Campo.value=Campo.value+String.fromCharCode(Tecla);
if (Seps.indexOf(ProxMascara)>-1)
{
Campo.value=Campo.value+ProxMascara;
}
}
return false;
}
function checkEmail(nome)
    {
     if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(nome))
     {
       return (true)
     }
       alert("Este e-mail não é válido.")
       return (false)
     
    }

/* Newsletter */
function newsletter() {
	if (document.newsform.nome.value == "" || document.newsform.nome.value == "NOME |") {
		alert("Por favor, digite o seu nome.");
		return false;
	} else if ((document.newsform.email.value == "") || (!valida_mail(document.newsform.email.value))) {
		alert("Por favor, digite um e-mail válido.");
		return false;
	} else
		return true;
}
function valida_mail(valor) {
	prim = valor.indexOf("@")
	if(prim < 2) return false;
	if(valor.indexOf("@",prim + 1) != -1) return false
	if(valor.indexOf(".") < 1) return false;
	if(valor.indexOf("zipmeil.com") > 0) return false;
	if(valor.indexOf("hotmeil.com") > 0) return false;
	if(valor.indexOf(".@") > 0) return false;
	if(valor.indexOf("@.") > 0) return false;
	if(valor.indexOf(".com.br.") > 0) return false;
	if(valor.indexOf("/") > 0) return false;
	if(valor.indexOf("[") > 0) return false;
	if(valor.indexOf("]") > 0) return false;
	if(valor.indexOf("(") > 0) return false;
	if(valor.indexOf(")") > 0) return false;
	if(valor.indexOf("..") > 0) return false;
	if(valor.indexOf(",") > 0) return false;
	if(valor.indexOf("'") > 0) return false;
	return true;
}

function fxHeight() {
	var heights = [];
	for (var i=0;i<arguments.length;i++) heights.unshift(document.getElementById(arguments[i]).offsetHeight);
	hT = heights.sort(function(a,b){ return a - b }).reverse()[0];
	for (var i=0;i<arguments.length;i++) document.getElementById(arguments[i]).style.height = hT+'px';
}