//Javascript Document

function enviar_form(texto){
 tam = texto.length;
 if (tam == 8){ 
  document.frm_login.submit(); 
 }
}

function ChangeBackground(elemento){
  /*elemento.style.background = '#F8F643'; */
  elemento.style.background = '#E1E1E1';
}
function RecoverBackground(elemento){
  elemento.style.background = '#f5f5f5';
}

function valida(form) {
 var elementos = form.elements;
  for (var i=0; i < elementos.length; i++){
   if (elementos[i].getAttribute("type")=="text") {
    if (elementos[i].getAttribute("obrigatorio")=="sim") {
     if (elementos[i].value=="") {
      alert("O campo "+elementos[i].getAttribute("texto")+" é obrigatório.");
      return false;
     } else {
       if (elementos[i].getAttribute("email")=="sim") {
        if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test((elementos[i].value))))
	    { 
         alert("O campo "+elementos[i].getAttribute("texto")+" possui um endereço e-mail inválido!");
         return false;
        }
       }
      }
    }
   }
  };
  //valida_senha(form);
  return true;
}

function valida_senha(form) {
 var elementos = form.elements;
  for (var i=0; i< elementos.length; i++){
   if (elementos[i].getAttribute("type")=="password") {
    if (elementos[i].getAttribute("obrigatorio")=="sim") {
     if (elementos[i].value=="") {
        alert("O campo "+elementos[i].getAttribute("texto")+" é obrigatório.");
        return false;
     } else {
	    if(elementos[i].length != 8){ 
          alert("O campo "+elementos[i].getAttribute("texto")+" deve ter 8 caracteres!");
          return false;
        } else {
		   if (elementos[i].getAttribute("name")=="nova_senha") {
            var nova_senha = elementos[i].value;
            var existe_senha = true;
           }
           if (elementos[i].getAttribute("name")=="confirma_senha") {
            var confirma_senha = elementos[i].value;
            var existe_conf_senha = true;
           }
		}
	 }
    }
   }
  }
  if ((existe_senha)&&(existe_conf_senha)) {
   if (nova_senha == confirma_senha){
     return true;
   } else {
     alert("A nova senha não foi confirmada corretamente.");
     return false;
   }
  } else {
     return true;  
  }
}
/*Formata CPF*/
function FormataCPF(Campo, teclapres){
	var tecla = teclapres.keyCode;
	
	var vr = new String(Campo.value);
	vr = vr.replace(".", "");
	vr = vr.replace(".", "");
	vr = vr.replace("-", "");

	tam = vr.length + 1;
	
	if (tecla != 9 && tecla != 8){
		if (tam > 3 && tam < 7)
			Campo.value = vr.substr(0, 3) + '.' + vr.substr(3, tam);
		if (tam >= 7 && tam <10)
			Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,tam-6);
		if (tam >= 10 && tam < 12)
			Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,3) + '-' + vr.substr(9,tam-9);
		}
}
/*Formata CPF*/
/*Formata Data*/
function FormataData_Nasc()
{
	if(document.getElementById('data_nasc').value.length == "2")
	{
		document.getElementById('data_nasc').value += "/"
	}
	if(document.getElementById('data_nasc').value.length == "5")
	{
		document.getElementById('data_nasc').value += "/"
	}
	if(document.getElementById('data_nasc').value.length == "10")
	{
		document.getElementById('data_nasc').value
	}
}
function FormataData_Entrada()
{
	if(document.getElementById('data_ent').value.length == "2")
	{
		document.getElementById('data_ent').value += "/"
	}
	if(document.getElementById('data_ent').value.length == "5")
	{
		document.getElementById('data_ent').value += "/"
	}
	if(document.getElementById('data_ent').value.length == "10")
	{
		document.getElementById('data_ent').value
	}
}
function FormataData_Saida()
{
	if(document.getElementById('data_saida').value.length == "2")
	{
		document.getElementById('data_saida').value += "/"
	}
	if(document.getElementById('data_saida').value.length == "5")
	{
		document.getElementById('data_saida').value += "/"
	}
	if(document.getElementById('data_saida').value.length == "10")
	{
		document.getElementById('data_saida').value
	}
}
/*Formata Data*/

NumeroCampo = 0;
function Add() {
    if(NumeroCampo < 4) {
        NumeroCampo++;
        data = "<span id='campo"+NumeroCampo+"'><input type=\"file\" name=\"file[]\" size=\"28\" class=\"input_contact\" onmouseout=\"RecoverBackground(this);\" onmouseover=\"ChangeBackground(this);\">&nbsp;<input type=\"button\" value=\"Remover\" onclick=\"Delcampo('campo"+NumeroCampo+"')\"></span><BR>";
        campo = document.getElementById("campos");
        campo.innerHTML = campo.innerHTML + data;
    }    
}

function Delcampo(IDDiv) {
    var d = document.getElementById('campos');
    var olddiv = document.getElementById(IDDiv);
    d.removeChild(olddiv);
    NumeroCampo--;
}

function verify_password(field_name){
  pass = field_name.value;
  if(pass.length < 8){
   field_name.focus();
   field_name.value = '';
   alert('ERRO: Senha menor do que 8 caracteres!');
  }
}

function confirm_pass(field_pass_confirm, field_pass_id){
 pass_confirm = field_pass_confirm.value;
 pass = document.getElementById(field_pass_id).value;
 if ((pass_confirm.length > 0) && (pass.length > 0)) {  
  if(pass_confirm != pass){
   alert('Erro: Senha e Confirmação de Senha não conferem!'); 
   field_pass_confirm.focus();
   field_pass_confirm.value = '';
  }
 }
}


