function tira_acento(palavra)
{
 tam = palavra.length;
 array = new Array('à','á','â','ã','ä','è','é','ê','ë','ì','í','î','ï','ò','ó','ô','õ','ö','ù','ú','û','ü','ç','ñ','-','+','=',' ');
 novo_array = new Array('a','a','a','a','a','e','e','e','e','i','i','i','i','o','o','o','o','o','u','u','u','u','c','n','_','_','_','_');
 tam_array = array.length;
 
 for(j = 0; j < tam_array; j++)
  for(i = 0; i < tam; i++)
   palavra = palavra.replace(array[j],novo_array[j]);
  
 return palavra;
}

// Não permite digitar letras em um input type=text
function evita_letra(tecla) {
	if (tecla.keyCode < 48 || tecla.keyCode > 57) 
		tecla.returnValue = false;
}

function FormataData(campo,formname,teclapres) { // Máscara para os campos de data
	var tecla = teclapres.keyCode;
	vr = document[formname][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 )
			document[formname][campo].value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 10 )
			document[formname][campo].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); 
	}
}


//Utilização: onkeypress="evita_letra(event)" onKeydown="FormataHora(this,event)" maxlength="5"
function FormataHora(campo,formname,teclapres){
	var tecla = teclapres.keyCode;
	vr = document[formname][campo].value;
	vr = vr.replace( ":", "" );
	tam = vr.length + 1;
	
	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 ){
			document[formname][campo].value = vr.substr( 0, tam - 2  ) + ':' + vr.substr( tam - 2, tam );
		}
	}
}


//formata cnpj
function FormataCNPJ(Campo, teclapres){

	var tecla = teclapres.keyCode;

	var vr = new String(Campo.value);
	vr = vr.replace(".", "");
	vr = vr.replace(".", "");
	vr = vr.replace("/", "");
	vr = vr.replace("-", "");

	tam = vr.length + 1 ;

	
	if (tecla != 9 && tecla != 8){
		if (tam > 2 && tam < 6)
			Campo.value = vr.substr(0, 2) + '.' + vr.substr(2, tam);
		if (tam >= 6 && tam < 9)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,tam-5);
		if (tam >= 9 && tam < 13)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,tam-8);
		if (tam >= 13 && tam < 15)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,4)+ '-' + vr.substr(12,tam-12);
		}
}

//Valida o cpf 
function val_cpf(numero2) {
  dig_1 = 0;
  dig_2 = 0;
  controle_1 = 10;
  controle_2 = 11;
  lsucesso = 1;
  
  var numero = numero2.substr(0,3) + numero2.substr(4,3) + numero2.substr(8,3) + numero2.substr(12,2);
  
  if (numero == "00000000000" || numero == "11111111111" || numero == "22222222222" || numero == "33333333333" || numero == "44444444444" || numero == "55555555555" || numero == "66666666666" || numero == "77777777777" || numero == "88888888888" || numero == "99999999999") {
  	return false;
  }
  
  if ((numero.length != 11) && (numero.length != 0)) {
     return false;
  }
  else {
     for ( i=0 ; i < 9 ; i++) {
        dig_1 = dig_1 + parseInt(numero.substring(i, i+1) * controle_1);
          controle_1 = controle_1 - 1;
     }
    
     resto = dig_1 % 11;
     dig_1 = 11 - resto;
     if ((resto == 0) || (resto == 1)) {
          dig_1 = 0;
     }
     for ( i=0 ; i < 9 ; i++) {
          dig_2 = dig_2 + parseInt(numero.substring(i, i + 1) * controle_2);
        controle_2 = controle_2 - 1;
     }
     dig_2 = dig_2 + 2 * dig_1;
     resto = dig_2 % 11;
     dig_2 = 11 - resto;
     if ((resto == 0) || (resto == 1)) {
        dig_2 = 0;
     }
     dig_ver = (dig_1 * 10) + dig_2;
     if (dig_ver != parseFloat(numero.substring(numero.length-2,numero.length))) {
          return false;
        }
  }

return true;
}

function FormataCEP(Campo, teclapres){

	var tecla = teclapres.keyCode;

	var vr = new String(Campo.value);
	vr = vr.replace("-", "");
	tam = vr.length + 1 ;
    
	if (tecla != 9 && tecla != 8)
	 if(tam > 5)
	  Campo.value = vr.substr(0, 5) + '-' + vr.substr(5, tam);
}

function FormataFone(Campo, teclapres){

	var tecla = teclapres.keyCode;

	var vr = new String(Campo.value);
	vr = vr.replace("-", "");
	tam = vr.length + 1 ;
    
	if (tecla != 9 && tecla != 8)
	 if(tam > 4)
	  Campo.value = vr.substr(0, 4) + '-' + vr.substr(4, tam);
}

function FormataCPF(Campo, teclapres){

	var tecla = teclapres.keyCode;

	var vr = new String(Campo.value);
	vr = vr.replace(".", "");
	vr = vr.replace(".", "");
	vr = vr.replace(".", "");
	vr = vr.replace("/", "");
	vr = vr.replace("-", "");

	tam = vr.length + 1 ;

	
	if (tecla != 9 && tecla != 8){
		if (tam >= 10 && tam < 12) {
			Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,3) + '-' + vr.substr(9,tam-9);
		} else if (tam >= 7 && tam < 10) {
			Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,tam-6);
		} else if (tam > 3 && tam < 7) {
			Campo.value = vr.substr(0, 3) + '.' + vr.substr(3, tam);
		}
		
	}
		
}

function testa_data(data)
{
 tipo = /^((0?[1-9]|[12]\d)\/(0?[1-9]|1[0-2])|30\/(0?[13-9]|1[0-2])|31\/(0?[13578]|1[02]))\/(19|20)?\d{2}$/;
 return tipo.test(data);
}

function testa_hora(hora)
{
 tipo = /^([0-1]\d|2[0-3]):[0-5]\d$/;
 return tipo.test(hora);
}

function testa_email(email)
{
 tipo = /^[\w-]+(\.[\w-]+)*@(([\w-]{2,63}\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
 return tipo.test(email);
}

//------------------------------------------ cookie.js ------------------------------------------
//by bamboo, lindau & szilard



//     * GetCookie(<cookie-name>)
//        - Description: Returns the value of <cookie-name>
//        - Returns: value of <cookie-name>
function GetCookie(name)
{
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen)
  {
    var offset = i + alen;
    if (document.cookie.substring(i, offset) == arg)
    {
      var endstr = document.cookie.indexOf (";", offset);
      if (endstr == -1) endstr = document.cookie.length;
      return unescape(document.cookie.substring(offset, endstr));
    }
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
  }
  return null;
}


//     * SetCookie(<cookie-name>, <cookie-data>, [expires-date], [path], [domain], [secure])
//        - Description: Stores the cookie <cookie-name> with <cookie-data>.
//        - Returns: nothing
function SetCookie(name, value)
{
  var argv        = SetCookie.arguments;
  var argc        = SetCookie.arguments.length;
  var expires     = (argc > 2) ? argv[2] : null;
  var path        = (argc > 3) ? argv[3] : null;
  var domain      = (argc > 4) ? argv[4] : null;
  var secure      = (argc > 5) ? argv[5] : false;
  document.cookie = name + "=" + escape (value) +
    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
    ((path == null) ? "" : ("; path=" + path)) +
    ((domain == null) ? "" : ("; domain=" + domain)) +
    ((secure == true) ? "; secure" : "");
}


//     * DeleteCookie(<cookie-name>)
//        - Description: Deletes the cookie <cookie-name>
//        - Returns: nothing
function DeleteCookie(name)
{
  var exp = new Date();
  exp.setTime (exp.getTime() - 1);
  var cval = GetCookie (name);
  document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function FormataValorMonetario(num)
{
 var centsSeparator = ',';
 var thousandSeparator = '.';
 num = num.toFixed(2).replace('.', centsSeparator);
  while (thousandSeparator && num.search(/[0-9]{4}/) > -1) {
    num = num.replace(/([0-9])([0-9]{3})([^0-9])/,'$1'+thousandSeparator+'$2$3');
	}
	return num;
}

function FormataValor(num)
{
 while(num.indexOf('.') != -1) 
  num = num.replace('.','');

 num = num.replace(',', '.');
 
 return num;
}
