function pesq_jan(url, x, y, nome_janela) {
	dimx = (window.screen.width-x)/2;
	dimy = (window.screen.height-y)/2;
	if (nome_janela == '') nome_janela = 'pesqjan';
	return window.open(url,nome_janela,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,top='+ dimy +',left='+ dimx +',width='+ x +',height='+ y);
}

function formata_form(valor,evento,mascara) {
//alert(mascara.charAt(valor.value.length));
	if ((mascara == '##/##/####' || mascara == '##/##/#### ##:##') && String.fromCharCode(evento.keyCode) == 'h') {
		var hoje = new Date();
		dia = hoje.getDate();
		dia = (dia < 10) ? '0'+dia : dia;
		mes = hoje.getMonth()+1;
		mes = (mes < 10) ? '0'+mes : mes;
		hora = hoje.getHours();
		hora = (hora < 10) ? '0'+hora : hora;
		minuto = hoje.getMinutes();
		minuto = (minuto < 10) ? '0'+minuto : minuto;
		if (mascara == '##/##/####') {
			valor.value = dia+'/'+mes+'/'+hoje.getYear();
		} else {
			valor.value = dia+'/'+mes+'/'+hoje.getYear()+' '+hora+':'+minuto;
		}
	} else {
		if (mascara.length == valor.value.length || (!(String.fromCharCode(evento.keyCode) >= 0 && String.fromCharCode(evento.keyCode) <= 9 && evento.keyCode != 32) && (mascara.charAt(valor.value.length)=='#' || (mascara.charAt(valor.value.length)!='*' && mascara.charAt(valor.value.length)!='#' && mascara.charAt(valor.value.length+1)=='#')))) {
			if (document.all) {
				evento.keyCode = 0;
			} else {
				evento.which = 0;
			}
		} else if (evento.keyCode==8) {
		} else {
			var resultado = '';
			j = valor.value.length+1;
			for(var i=0; j > i; i++) {
				if (valor.value.charAt(i) >= 0 && valor.value.charAt(i) <= 9 && mascara.charAt(i) == '#') {
					resultado += valor.value.charAt(i);
				} else if (mascara.charAt(i) == '*') {
					resultado += valor.value.charAt(i);
				}
				if (mascara.charAt(i) != '*' && mascara.charAt(i) != '#') {
						resultado += mascara.charAt(i);
				}
			}
			valor.value = resultado;
		}
	}
}

function formata_data(valor,evento,tamanho) {
	if (!(String.fromCharCode(evento.keyCode) >= 0 && String.fromCharCode(evento.keyCode) <= 9)) {
		if (document.all) {
			evento.keyCode = 0;
		} else {
			evento.which = 0;
		}
	} else {
		//var tk = ((document.all) ? event.keyCode : event.which);
		tamanho = tamanho ? tamanho : 19;
		var resultado = '';
		for(var i=0; valor.value.length > i; i++) {
			if (valor.value.charAt(i).match(/[0-9]/) != null) {
				if (i == 1 || i == 4) {
					resultado = resultado + valor.value.charAt(i) + '/';
				} else if (i == 9) {
					resultado = resultado + valor.value.charAt(i) + ' ';
				} else if (i == 12 || (i == 15 && tamanho > 16)) {
					resultado = resultado + valor.value.charAt(i) + ':';
				} else {
					resultado = resultado + valor.value.charAt(i);
				}
			}
		}
		re = /$/gi;
		valor.value = resultado.replace(re, "");
	}
}

function formata_moeda(valor,evento) {
	re = /\./gi;
	valor.value=valor.value.replace(re, "");
	re = /,/gi;
	valor.value=valor.value.replace(re, "");
	if (!(String.fromCharCode(evento.keyCode) >= 0 && String.fromCharCode(evento.keyCode) <= 9)) {
		if (document.all) {
			evento.keyCode = 0;
		} else {
			evento.which = 0;
		}
	} else {
		//var tk = ((document.all) ? event.keyCode : event.which);
		var resultado = '';
		for(var i=0; valor.value.length > i; i++) {
			if (valor.value.charAt(i).match(/[0-9]/) != null) {
				if (valor.value.length - i == 5 || valor.value.length - i == 8 || valor.value.length - i == 11) {
					resultado = resultado + valor.value.charAt(i) + '.';
				} else if (valor.value.length - i == 2) {
					resultado = resultado + valor.value.charAt(i) + ',';
				} else {
					resultado = resultado + valor.value.charAt(i);
				}
			}
		}
		valor.value = resultado;
	}
}

function formata_num(valor,evento) {
	if (!(String.fromCharCode(evento.keyCode) >= 0 && String.fromCharCode(evento.keyCode) <= 9)) {
		if (document.all) {
			evento.keyCode = 0;
		} else {
			evento.which = 0;
		}
	} else {
		return valor;
	}
}

function formata_letra(valor,evento) {
	if ((evento.keyCode >= 48 && evento.keyCode <= 57)) {
		if (document.all) {
			evento.keyCode = 0;
		} else {
			evento.which = 0;
		}
	} else {
		return valor;
	}
}

function escreve_layer(nome, texto) {
	if (document.layers) {
		document.layers[nome].document.close();
		document.layers[nome].document.write(texto);
		document.layers[nome].document.close();
	} else if (document.all) {
		eval("document.all." + nome + ".innerHTML='" + texto + "'");
	} else {
		document.getElementById(nome).innerHTML = texto;
	}
}

function layer_exec(nome, acao) {
    if (document.layers) {
		if (acao == 1) {
			acao = 'show';
		} else if (acao == 0) {
			acao = 'hide';
		}
		if (!acao) acao = document.layers[nome].style.visibility == 'hide' ? 'show' : 'hide';
        document.layers[nome].style.visibility = acao;
    } else {
		if (acao == 1) {
			acao = 'block';
		} else if (acao == 0) {
			acao = 'none';
		}
        if (document.all && false) {
			if (!acao) acao = eval("document.all." + nome + ".style.display") == 'none' ? 'block' : 'none';
            eval("document.all." + nome + ".style.display='"+acao+"'");
        } else {
			if (!acao) acao = document.getElementById(nome).style.display == 'none' ? 'block' : 'none';
            document.getElementById(nome).style.display = acao;
        }
    }
	return acao;
}

function valida_email(email) {
	if (email.match(/^((\"[^\"\f\n\r\t\v\b]+\")|([\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+(\.[\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+)*))@((\[(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))\])|(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))|((([A-Za-z0-9\-])+\.)+[A-Za-z\-]+))$/) == null) {
		return true;
	} else {
		return false;
	}
}
