amadeus.js
3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
function campoNumerico(campo, evento){
var codTecla;
var tamanho;
if( document.all ) {// Internet Explorer
codTecla = evento.keyCode;
} else if( document.layers ) { // Nestcape
codTecla = evento.which;
}
else if( evento) { // Firefox
codTecla = evento.which;
}
if( (codTecla > 47 && codTecla < 58) || codTecla==8 || codTecla == 0){
return true;
} else {
evento.returnValue = false;
return false;
}
}
function formatarCpf(campo, evento){
var codTecla;
var tamanho;
if( document.all ) { // Internet Explorer
codTecla = evento.keyCode;
} else if( document.layers ) { // Nestcape
codTecla = evento.which;
}
else if( evento ) { // Firefox
codTecla = evento.which;
}
tamanho = campo.value.length;
if( (codTecla > 47 && codTecla < 58) || codTecla== 8 || codTecla == 0){
if(tamanho < 14 ){
if( tamanho == 3 && codTecla != 8 && codTecla != 0){
campo.value = campo.value + ".";
}else if( tamanho == 7 && codTecla != 8 && codTecla != 0){
campo.value = campo.value + ".";
}else if( tamanho == 11 && codTecla != 8 && codTecla != 0){
campo.value = campo.value + "-";
}
}else{
evento.returnValue = false;
}
return true;
} else {
return false;
}
return false;
}
function validarCpfSemAlert(campo,nome,idElementoMensagemErro){
//alert("teste");
cpf = campo.value;
cpf = cpf.replace(".","");
cpf = cpf.replace("-","");
cpf = cpf.replace(".","");
retorno = true;
if(trim(cpf).length > 0){
//alert("teste2");
cpfstr= '';
temp = cpf + '';
cpfstr = temp.substring(0,3);
cpfstr = cpfstr + temp.substring(3,6);
cpfstr = cpfstr + temp.substring(6,9);
cpfstr = cpfstr + temp.substring(9,11);
retorno = false;
if(cpf != null){
//alert("teste3");
soma = 0;
digito1 = 0;
digito2 = 0;
for(i = 0; i < 9; i = i + 1) {
soma = soma + ((parseInt(cpf.substring(i,i+1)))*(11-(i+1)));
}
soma = soma % 11;
if (soma == 0 || soma == 1) {
digito1 = 0;
} else {
digito1 = 11 - soma;
}
soma = 0;
for(i = 0; i < 9; i = i + 1) {
soma = soma + ((parseInt(cpf.substring(i,i+1)))*(12-(i+1)));
}
soma = soma + (digito1*2);
soma = soma % 11;
if (soma == 0 || soma == 1) {
digito2 = 0;
}
else{
digito2 = 11 - soma;
}
digito = digito1 +''+ digito2;
//alert(cpfstr.substring(9,11));
if(digito == (cpfstr.substring(9,11))){
retorno = true;
} else{
//alert("teste4");
retorno = false;
}
} else {
retorno = false;
}
}else{
retorno = false;
}
//alert(retorno);
if(retorno == false){
//alert('E-mail informado invalido! Por favor, especifique um E-mail válido para o campo \"' + nome + '\".');
document.getElementById(idElementoMensagemErro).style.display = '';
campo.focus();
return false;
}else{
document.getElementById(idElementoMensagemErro).style.display = 'none';
return true;
}
return retorno;
}
/*
This functions get the next 5 notifications from the user given a "step"(an amount) of previous notifications
*/
function getNotifications(step){
$.get('/getNotifications',
{'steps':step, 'amount': 5}, function(data){
console.log(data);
});
}