function validarData(data) { 
	dia = (data.substring(0,2)); 
	mes = (data.substring(3,5)); 
	ano = (data.substring(6,10));
	situacao = ""; 
	
	if (data == "") { 
		situacao = "falsa"; 
	} else if(data.length < 10) { 
		return false; 
	} else if(dia < 01 || dia > 31) {
		return false; 
	} else if(dia == 31 && (  mes == 4 || mes == 6 || mes == 9 || mes == 11 ) ) { 
		// verifica o dia valido para cada mes 
		situacao = "falsa"; 
	}else if (mes < 1 || mes > 12 ) { 	
		// verifica se o mes e valido 
		situacao = "falsa"; 
	} else if (mes == 2 && ( dia < 1 || dia > 29 || ( dia > 28 && (parseInt(ano / 4) != ano / 4)))) { 
		// verifica se e ano bissexto 
		situacao = "falsa"; 
	} else {
		return true;
	}
} 

function validarHora(hora){ 

	hrs = (Number(hora.substring(0,2))); 
	mins = (Number(hora.substring(3,5))); 
	
	// verifica data e hora 
	if ((hrs < 0 ) || (hrs > 23) || ( mins < 00) ||( mins > 59)){ 
		return false;
	} else if (hora == "") { 
		return false;
	} else {
		return true;
	}
} 

function validarExtensaoJPG(path_imagem) {
	extensao_arquivo_3chars = path_imagem.substr(path_imagem.length-3).toLowerCase();
	extensao_arquivo_4chars = path_imagem.substr(path_imagem.length-4).toLowerCase();
	if(extensao_arquivo_3chars == 'jpg' || extensao_arquivo_4chars == 'jpeg'){
		return true;
	} else {
		return false;
	}
}


// FUNÇÃO UTILIZADA PELO validarEmail():
function Validate_String(string, return_invalid_chars) {
  valid_chars = '1234567890-_.^~abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  invalid_chars = '';
  if(string == null || string == '')
     return(true);
  //For every character on the string.   
  for(index = 0; index < string.length; index++) {
    char = string.substr(index, 1);                        
    //Is it a valid character?
    if(valid_chars.indexOf(char) == -1) {
      //If not, is it already on the list of invalid characters?
      if(invalid_chars.indexOf(char) == -1) {
        //If it’s not, add it.
        if(invalid_chars == '')
          invalid_chars += char;
        else
          invalid_chars += ', ' + char;
      }
    }
  }
  //If the string does not contain invalid characters, the function will return true.
  //If it does, it will either return false or a list of the invalid characters used
  //in the string, depending on the value of the second parameter.
  if(return_invalid_chars == true && invalid_chars != '') {
    last_comma = invalid_chars.lastIndexOf(',');
    if(last_comma != -1)
      invalid_chars = invalid_chars.substr(0, $last_comma) + 
      ' and ' + invalid_chars.substr(last_comma + 1, invalid_chars.length);
    return(invalid_chars);
    }
  else
    return(invalid_chars == ''); 
}


function validarEmail(email_address) {
  //Assumes that valid email addresses consist of user_name@domain.tld
  at = email_address.indexOf('@');
  depois_do_arroba = email_address.substr(at+1);
  ponto1 = email_address.indexOf('.');
  ponto2 = depois_do_arroba.indexOf('.');
  depois_do_ponto2 = depois_do_arroba.substr(ponto2+1);
  ponto3 = depois_do_ponto2.indexOf('.');
  depois_do_ponto3 = depois_do_ponto2.substr(ponto3+1);
  ponto4 = depois_do_ponto3.indexOf('.');


  _fim = (ponto3 != -1 ? ponto3 : depois_do_ponto2.length);
  depois_do_ponto2 = depois_do_ponto2.substr(0, _fim);
  _fim = (ponto4 != -1 ? ponto4 : depois_do_ponto3.length);
  depois_do_ponto3 = depois_do_ponto3.substr(0, _fim);

  if(at == -1 || 							// sem arroba
	ponto1 == 0 ||							// com ponto no início
	ponto1 == at-1 ||						// com ponto logo antes do arroba
	ponto2 == -1 ||							// sem ponto depois do arroba
	ponto2 == 0 ||  						// com ponto logo depois do arroba
	ponto2 == depois_do_arroba.length ||	// com ponto no final
	ponto3 == 0 ||  						// com ponto logo depois do arroba
	ponto3 == depois_do_arroba.length ||	// com ponto no final
	ponto4 != -1 ||							// mais de dois pontos depois do arroba
	(depois_do_ponto3.length != 2 && depois_do_ponto3.length != 0 && ponto3 != -1) // o trecho ".br" só pode ter 2 caracteres
	)
    return(false);
  user_name = email_address.substr(0, at);
  domain_name = email_address.substr(at + 1, email_address.length);                  

  if(Validate_String(user_name) === false || 
    Validate_String(domain_name) === false)
    return(false);                     

  return(true);
}





function validarCPF(cpf) {
	cpf = cpf.replace(/\./g, '');
	cpf = cpf.replace(/\//g, '');
	cpf = cpf.replace(/-/g, '');

	erro = new String;
	if (cpf.length < 11) erro += "Sao necessarios 11 digitos para verificacao do CPF! \n\n"; 
	var nonNumbers = /\D/;
	if (nonNumbers.test(cpf)) erro += "A verificacao de CPF suporta apenas numeros! \n\n"; 
	if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999"){
		 erro += "Numero de CPF invalido!"
	}
	var a = [];
	var b = new Number;
	var c = 11;
	for (i=0; i<11; i++){
		   a[i] = cpf.charAt(i);
		   if (i < 9) b += (a[i] * --c);
	}
	if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }
	b = 0;
	c = 11;
	for (y=0; y<10; y++) b += (a[y] * c--); 
	if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }
	if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])){
		   erro +="Digito verificador com problema!";
	}
	if (erro.length > 0){
		   // alert(erro);
		   return false;
	}
	return true;
}

function validarNumero(str) {
	str = str.replace(/,/g, '');
	str = str.replace(/\./g, '');
	if(isNaN(str)) {
		return false;
	} else {
		return true;
	}
}

function validarNomeSistema(texto) {
	nao_permitidos = Array(' ', '-', 'á', 'à', 'â', 'ã', 'ä', 'é', 'è', 'ê', 'ë', 'ë', 'í', 'ì', 'î', 'ï', 'ó', 'ò', 'ô', 'õ', 'ö', 'ú', 'ù', 'û', 'ü', 'ç', '~', '´', '`', '^', '¨', '\!', '\?', '\.', ':', ',', '"', '\'', '&', '\(', '\)', '\+', '\%', '\$', '\=', '@', '__', '___', '____')
	for(i=0; i<nao_permitidos.length; i++) {
		if(texto.indexOf(nao_permitidos[i]) != -1) {
			return false;
		}
	}
	return true;
}
