
/* - - - - - - Verificação básica de um campo de formulário por caracteres especiais: & < > | \ / - - - - - */

function checarEspeciais(v) {
         
         if ((v.indexOf("&")>=0) || (v.indexOf("<")>=0) || (v.indexOf(">")>=0) ||
            (v.indexOf("|")>=0) || (v.indexOf("\"")>=0) || (v.indexOf("/")>=0) )
		return false;
	 return true;
}

/* - - - - - Fim - - - - - */


/* - - - - - Verifica se um campo está vazio - - - - - */

function checarVazio(v) {
        return ((v == null) || (v.length == 0));
}

/* - - - - - Fim - - - - - */

/* - - - - - Mostra qual o erro cometido numa janela e seleciona o campo no formulário - - - - - */

function mostraMsg3 (texto) {
    alert(texto);
    return false;
}

/* - - - - - Fim - - - - - */



/* - - - - - Mostra qual o erro cometido numa janela e seleciona o campo no formulário - - - - - */

function mostraMsg2 (campo,texto) {
    campo.focus();
    alert(texto);
    return false;
}

/* - - - - - Fim - - - - - */


/* - - - - - Mostra qual o erro cometido numa janela e seleciona o campo no formulário - - - - - */

function mostraMsg (campo,texto) {
    campo.focus();
    campo.select();
	alert(texto);
    return false;
}

/* - - - - - Fim - - - - - */


/* - - - - - Verifica o formato do email - - - - - */

function verificaEmail(email) {
	var s = new String(email);
	// { } ( ) < > [ ] | \ /
	if ((s.indexOf("{")>=0) || (s.indexOf("}")>=0) || (s.indexOf("(")>=0) || (s.indexOf(")")>=0) || (s.indexOf("<")>=0) || (s.indexOf(">")>=0) || (s.indexOf("[")>=0) || (s.indexOf("]")>=0) || (s.indexOf("|")>=0) || (s.indexOf("\"")>=0) || (s.indexOf("/")>=0) )
		return false;
	if (vogalAcentuada(email))
		return false;
	// & * $ % ? ! ^ ~ ` ' "
	if ((s.indexOf("&")>=0) || (s.indexOf("*")>=0) || (s.indexOf("$")>=0) || (s.indexOf("%")>=0) || (s.indexOf("?")>=0) || (s.indexOf("!")>=0) || (s.indexOf("^")>=0) || (s.indexOf("~")>=0) || (s.indexOf("`")>=0) || (s.indexOf("'")>=0) )
		return false;
	// , ; : = #
	if ((s.indexOf(",")>=0) || (s.indexOf(";")>=0) || (s.indexOf(":")>=0) || (s.indexOf("=")>=0) || (s.indexOf("#")>=0) )
		return false;
	// procura se existe apenas um @
	if ( (s.indexOf("@") < 0) || (s.indexOf("@") != s.lastIndexOf("@")) )
		return false;
	// verifica se tem pelo menos um ponto após o @
	if (s.lastIndexOf(".") < s.indexOf("@"))
		return false;
	return true;
}

/* - - - - - Fim - - - - - */


// Verifica se o caracter é um dígito de 0 a 9
function verificaNumero(n)
{ return ((n >= "0") && (n <= "9")) }


// Gera uma string com os caracteres básicos na sequência de códigos ASC
function makeCharsetString(){
	var astr
	astr = ' !"#$%&\'()*+,-./0123456789:;<=>?@'
	astr+= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
	astr+= '[\]^_`abcdefghijklmnopqrstuvwxyz'
	astr+= '{|}~'
	return astr
}

// Verifica se uma string tem vogais acentuadas
function vogalAcentuada(s) {
	ls = s.toLowerCase();
	if ((ls.indexOf("á")>=0) || (ls.indexOf("à")>=0) || (ls.indexOf("ã")>=0) || (ls.indexOf("â")>=0) || (ls.indexOf("é")>=0) || (ls.indexOf("í")>=0) || (ls.indexOf("ó")>=0) || (ls.indexOf("õ")>=0) || (ls.indexOf("ô")>=0) || (ls.indexOf("ú")>=0) || (ls.indexOf("ü")>=0))
		return true;
}


// Retorna o código ASC do caracter passada por parâmetro
function asc(achar){
	var n=0;
	var ascstr = makeCharsetString()
	for(i=0;i<ascstr.length;i++){
		if(achar==ascstr.substring(i,i+1)){
			n=i;
			break;
		}
	}
	return n+32
}


//Remove todos os caracteres excetos 0-9
function trimtodigits(tstring){
  s=""; 
  ts=new String(tstring);
  for (x=0;x<ts.length;x++){
   ch=ts.charAt(x);
    if (asc(ch)>=48 && asc(ch)<=57){
      s=s+ch;
    }
  }
  return s;
}

// Verifica se o caracter pode fazer parte de um número: 0-9 , . ( ) - e espaço
function isNumber (c)
{ return ((c >= "0") && (c <= "9") || (c=="-") || (c=="(") || (c==")") || (c==" ") || (c==".") || (c==",")) }



/* - - - - - - Verifica se um campo é inteiro, 
   inclui dígitos de 0 a 9, vírgula, ponto, espaços e - */

function isInteger(s){
	var i;
	if (isEmpty(s)) 
		return false;
	for (i = 0; i < s.length; i++)
	{   
		var c = s.charAt(i);
		if (!isNumber(c)) return false;
	}
	return true;
}

/*- - - - - fim - - - - -*/


