﻿// INICIO - FUNÇÃO DE BLOQUEAR
var message = "";
// desativar Botao esquerdo do mouse
function clickIE() {
	if (document.all) {
		(message);
		return true;
	}
}

function clickNS(e) {
	if (document.layers || (document.getElementById && !document.all)) {
		if (e.which == 2 || e.which == 3) {
			(message);
			return true;
		}
	}
}
if (document.layers) {
	document.captureEvents(Event.MOUSEDOWN);
	document.onmousedown = clickNS;
} else {	
	document.onmouseup = clickNS;
	document.oncontextmenu = clickIE;
}
document.oncontextmenu = new Function("return true")
// desativar seleção de texto (IE4+, NS6+)

function click() {
	if (event.button == 2 || event.button == 3)
		oncontextmenu = 'return false';
}

// if IE4+
document.onselectstart = new Function("return true")

// if NS6
if (window.sidebar) {
	// document.onmousedown = new Function ("return false")
	document.onclick = new Function("return true")
}

document.oncontextmenu = new Function('return false;');
document.onmouseup = new Function('return false;');
document.onselectstart = new Function('return true;');
document.onpaste = new Function('return false;');
// FIM - FUNÇÃO DE BLOQUEAR

function openWindow(theURL, winName, features) {
	window.open(theURL, winName, features);
	return false;
}

function dois_pontos(tempo) {
	if (event.keyCode < 48 || event.keyCode > 57) {
		event.returnValue = false;
	}
	if (tempo.value.length == 2) {
		tempo.value += ":";
	}
}

function bloqEnter(objEvent) {
	var iKeyCode;
	iKeyCode = objEvent.keyCode;
	if (iKeyCode == 13)
		return false;
	return true;
}

function mascaraBoleto(event, objeto, tipo) {

	tip = document.getElementById(tipo).value;

	if (tip == "FC") {

		if (mascaraCPF(event, objeto)) {
			return true;
		}
	}

	if (tip == "FM") {
		if (mascaraMatricula(event, objeto)) {
			return true;
		}
	}

	if (tip == "J") {
		if (mascaraCnpj(event, objeto)) {
			return true;
		}
	}
	return false;
}

function validaBoleto(campo, campo2, tipo) {
	var tip = document.getElementById(tipo).value;
	if (tip == "FC") {
		if (!validaCpf(campo)) {
			return false;
		}
		if (!validaData(campo2)) {
			return false;
		}
	}
	if (tip == "FM") {
		if (!validaMatricula(campo)) {
			return false;
		}
	}
	if (tip == "J") {
		if (!validaCnpj(campo))
			return false;
		if (!validaData(campo2))
			return false;
	}
	return true;
}

function validaIr(campo) {
	if (!validaMatricula(campo)) {
		return false;
	}
	return true;
}

function mascaraCredenciamento(event, objeto, tipo) {
	var radio = document.getElementById(tipo).value;

	if (radio == "F") {
		if (mascaraCPF(event, objeto)) {
			return true;
		}
	}
	if (radio == "J") {
		if (mascaraCnpj(event, objeto)) {
			return true;
		}
	}
	return false;
}

function soCaracter(objeto, titulo) {

	var regexTexto = /^[a-z' 'A-ZãÃáÁàÀêÊéÉèÈíÍìÌôÔõÕóÓòÒúÚùÙûÛçÇ.;:,ºª-]+$/;

	// aqui faz o teste usando o método test que compara a sua regex com o value
	// do campo
	if (regexTexto.test(objeto)) {
		// caso ok retorna true
		return true;
	} else {
		alert("O Campo " + titulo + " aceita somente caracteres");
		objeto.value = "";
		objeto.focus();
		return false;
	}
}

function soNumero(event) {
	var tecla = (window.event) ? event.keyCode : event.which;	
	if (tecla > 47 && tecla < 58)
		return true;
	else {
		if (tecla != 8)
			return false;
		else
			return true;
	}
}

function validaCartao(campo, campo2) {
	var cartao = document.getElementById(campo).value;
	var cpf = document.getElementById(campo2).value;

	if (cartao == "") {
		alert("O Cartão é de preenchimento obrigatório !!! ");
		return false;
	}
	if (cartao.length < 6) {
		alert("Cartão Inválido!!!");
		return false;
	}
	if (cpf == "") {
		alert("O CPF é de preenchimento obrigatório !!! ");
		return false;
	}
	if (!validaCpf(campo2)) {
		return false;
	}

	return true;
}

function validaCorretor() {

	var razao = document.getElementById("form1:txtusuario").value;
	var cnpj = document.getElementById("form1:txtdocs").value;
	var abertura = document.getElementById("form1:txtdata").value;
	var iss = document.getElementById("form1:txtiss").value;
	var endereco = document.getElementById("form1:txtend").value;
	var bairro = document.getElementById("form1:txtbairro").value;
	var cidade = document.getElementById("form1:txtcidade").value;
	var uf = document.getElementById("form1:txtuf").value;
	var cep = document.getElementById("form1:txtcep").value;
	var ddd = document.getElementById("form1:txtddd").value;
	var telefone = document.getElementById("form1:txttel").value;
	var banco = document.getElementById("form1:txtbanco").value;
	var agencia = document.getElementById("form1:txtagencia").value;
	var conta = document.getElementById("form1:txtconta").value;
	var nome = document.getElementById("form1:txtnomerepre").value;
	var email = document.getElementById("form1:txtemail").value;
	var cpf = document.getElementById("form1:txtcpfrepre").value;
	var rg = document.getElementById("form1:txtrg").value;
	var cargo = document.getElementById("form1:txtcargo").value;

	if (razao == "") {
		alert("Por favor, preencha o campo Razão Social");
		razao.focus();
		return false;
	}
	if (cnpj == "") {
		alert("Por favor, preencha o campo C.N.P.J");
		cnpj.focus();
		return false;
	} else if (cnpj.length < 18) {
		alert("C.N.P.J inválido... !!! Ex: 11.111.111/1111-11");
		cnpj.focus();
		return false;
	}
	if (abertura == "") {
		alert("Por favor, preencha o campo Data Abertura");
		abertura.focus();
		return false;
	} else if (abertura.length < 10) {
		alert("Data inválida... !!! Ex: 11/11/1111");
		abertura.focus();
		return false;
	}
	if (iss == "") {
		alert("Por favor, preencha o campo I.S.S/C.C.M");
		iss.focus();
		return false;
	}
	if (endereco == "") {
		alert("Por favor, preencha o campo Endereço");
		endereco.focus();
		return false;
	}
	if (bairro == "") {
		alert("Por favor, preencha o campo Bairro");
		bairro.focus();
		return false;
	}
	if (cidade == "") {
		alert("Por favor, preencha o campo Cidade");
		cidade.focus();
		return false;
	}
	if (uf == "") {
		alert("Por favor, preencha o campo U.F.");
		uf.focus();
		return false;
	}
	if (cep == "") {
		alert("Por favor, preencha o campo CEP");
		cep.focus();
		return false;
	} else if (cep.length < 9) {
		alert("CEP inválido... !!! Ex: 11111-111");
		cep.focus();
		return false;
	}
	if (ddd == "") {
		alert("Por favor, preencha o campo DDD");
		ddd.focus();
		return false;
	}
	if (telefone == "") {
		alert("Por favor, preencha o campo Telefone");
		telefone.focus();
		return false;
	} else if (telefone.length < 9) {
		alert("Telefone inválido... !!! Ex: 1111-1111");
		telefone.focus();
		return false;
	}
	if (banco == "") {
		alert("Por favor, preencha o campo Banco");
		banco.focus();
		return false;
	}
	if (agencia == "") {
		alert("Por favor, preencha o campo Agência");
		agencia.focus();
		return false;
	}
	if (conta == "") {
		alert("Por favor, preencha o campo C/C");
		conta.focus();
		return false;
	}
	if (nome == "") {
		alert("Por favor, preencha o campo Nome");
		nome.focus();
		return false;
	}
	if (email == "") {
		alert("Por favor, preencha o campo E-mail p/ contato");
		email.focus();
		return false;
	} else if (email.length < 10) {
		alert("Digite um endereço de E-mail válido");
		email.focus();
		return false;
	}
	if (cpf == "") {
		alert("Por favor, preencha o campo C.P.F");
		cpf.focus();
		return false;
	} else if (cpf.length < 14) {
		alert("C.P.F inválido... !!! Ex: 111.111.111-11");
		cpf.focus();
		return false;
	}
	if (rg == "") {
		alert("Por favor, preencha o campo R.G.");
		rg.focus();
		return false;
	} else if (rg.length < 12) {
		alert("R.G. inválido... !!! Ex: 11.111.111-1");
		rg.focus();
		return false;
	}
	if (cargo == "") {
		alert("Por favor, preencha o campo Cargo");
		rg.focus();
		return false;
	}
	return true;
}

function validaCredenciamento() {
	var nome = document.getElementById("form1:txtusuario").value;
	var cnes = document.getElementById("form1:txtcnes").value;
	var docs = document.getElementById("form1:txtdocs").value;
	var rg = document.getElementById("form1:txtrg").value;
	var crm = document.getElementById("form1:txtcrm").value;
	var exp = document.getElementById("form1:txtexp").value;
	var dtn = document.getElementById("form1:txtdatnas").value;
	var end = document.getElementById("form1:txtend").value;
	var bai = document.getElementById("form1:txtbairro").value;
	var cid = document.getElementById("form1:txtcidade").value;
	var uf = document.getElementById("form1:txtuf").value;
	var cep = document.getElementById("form1:txtcep").value;
	var ddd = document.getElementById("form1:txtddd").value;
	var tel = document.getElementById("form1:txttel").value;
	var bco = document.getElementById("form1:txtbanco").value;
	var ag = document.getElementById("form1:txtagencia").value;
	var cta = document.getElementById("form1:txtconta").value;
	var esp = document.getElementById("form1:cb_espec").value;
	var mail = document.getElementById("form1:txtemail").value;
	var nrep = document.getElementById("form1:txtnomerepre").value;
	var crep = document.getElementById("form1:txtcpfrepre").value;
	var grep = document.getElementById("form1:txtcargo").value;
	
	if (nome == "") {
		alert("Preencha o Nome/Razão Social! ");
		return false;
	} else if (cnes == "") {
		alert("Preencha o CNES! ");
		return false;
	}else if (Trim(esp) == "") {
		alert("Preencha a Especialidade! ");		
		return false;
	}else if (docs == "") {
		alert("Preencha o CPF / CNPJ! ");
		return false;
	} else if (rg == "") {
		alert("Preencha o RG! ");
		return false;
	} else if (crm == "") {
		alert("Preencha o CRM! ");
		return false;
	} else if (exp == "") {
		alert("Preencha a Expedição! ");
		return false;
	} else if (dtn == "") {
		alert("Preencha a Data de Nascimento! ");
		return false;
	} else if (end == "") {
		alert("Preencha o Endereço! ");
		return false;
	} else if (bai == "") {
		alert("Preencha o Bairro! ");
		return false;
	} else if (cid == "") {
		alert("Preencha a Cidade! ");
		return false;
	} else if (uf == "") {
		alert("Preencha o UF! ");
		return false;
	} else if (cep == "") {
		alert("Preencha o Cep! ");
		return false;
	} else if (ddd == "") {
		alert("Preencha o DDD! ");
		return false;
	} else if (tel == "") {
		alert("Preencha o Telefone! ");
		return false;
	}else if (mail == "") {
		alert("Preencha o E-mail! ");
		return false;
	}else if (nrep == "") {
		alert("Preencha o Nome do Responsável! ");
		return false;
	}  else if (crep == "") {
		alert("Preencha o CPF do Responsável! ");
		return false;
	} else if (grep == "") {
		alert("Preencha o Cargo do Responsável! ");
		return false;
	}else if (bco == "") {
		alert("Preencha o Banco! ");
		return false;
	} else if (ag == "") {
		alert("Preencha a Agência! ");
		return false;
	} else if (cta == "") {
		alert("Preencha a Conta! ");
		return false;
	} 
	return true;
}

function logimp() {
	if (navigator.appName == 'Microsoft Internet Explorer') {
		document.getElementById("form1:logimp").click();
	} else {
		var target = document.getElementById("form1:logimp");
		if (document.dispatchEvent) { // W3C
			var oEvent = document.createEvent("MouseEvents");
			oEvent.initMouseEvent("click", true, true, window, 1, 1, 1, 1, 1,
					false, false, false, false, 0, target);
			target.dispatchEvent(oEvent);
		}
	}
}

function validaBeneficiario(tipo, campo, campo2) {
	var tip = document.getElementById(tipo).value;
	var busca = document.getElementById(campo).value;
	var data = document.getElementById(campo2).value;

	if (!validaVazioQtde(campo, 'Busca', 3)) {
		return false;
	}
	if (tip == "CPF") {
		if (!validaCpf(campo))
			return false;
	} else if (tip == "MTN") {
		if (!validaMatricula(campo))
			return false;
	} else if (tip == "MTA") {
		if (busca.length < 10) {
			alert("Matrícula inválida!!!");
			return false;
		}
	} else if (tip == "NPN") {
		if (data.length == "") {
			alert('Na busca por "Nome" ou "parte do Nome" é obrigatório preencher a Data de Nascimento');
			return false;
		} else {
			if (!validaData(campo2))
				return false;
		}
	}
	return true;
}

function mascaraBeneficiario(event, objeto, tipo, campo) {

	var tip = document.getElementById(tipo).value;

	document.getElementById(campo).maxLength = 100;

	if (tip == "CPF") {

		document.getElementById(campo).maxLength = 14;
		if (mascaraCPF(event, objeto)) {
			return true;
		}

	} else if (tip == "MTN") {

		document.getElementById(campo).maxLength = 21;
		if (mascaraMatricula(event, objeto)) {
			return true;
		}

	} else {
		return true;
	}
	return false;
}

function filtroBeneficiario(tipo, campo, campo2) {
	var tip = document.getElementById(tipo).value;
	var busca = document.getElementById(campo).value;	
	if (tip == "CPF") {
		if (busca.substring(3, 4) != '.') {
			document.getElementById(campo).value = "";
			document.getElementById(campo2).value = "";			
		}
	} else if (tip == "MTN") {
		if (busca.substring(4, 5) != '.') {
			document.getElementById(campo).value = "";
			document.getElementById(campo).value = "";			
		}
	} else {
		document.getElementById(campo2).value = "";
		if (busca.substring(4, 5) == '.' || busca.substring(3, 4) == '.') {
			document.getElementById(campo).value = "";			
		}
	}
}

function mensagemcalculo() {

	var combo1 = parseFloat(document.getElementById("form1:cb_ano1").value);
	var combo2 = parseFloat(document.getElementById("form1:cb_ano2").value);
	var combo3 = parseFloat(document.getElementById("form1:cb_ano3").value);
	var combo4 = parseFloat(document.getElementById("form1:cb_ano4").value);
	var combo5 = parseFloat(document.getElementById("form1:cb_ano5").value);
	var combo6 = parseFloat(document.getElementById("form1:cb_ano6").value);
	var combo7 = parseFloat(document.getElementById("form1:cb_ano7").value);
	var combo8 = parseFloat(document.getElementById("form1:cb_ano8").value);
	var combo9 = parseFloat(document.getElementById("form1:cb_ano9").value);
	var combo10 = parseFloat(document.getElementById("form1:cb_ano10").value);

	var qtde = combo1 += combo2 += combo3 += combo4 += combo5 += combo6 += combo7 += combo8 += combo9 += combo10;

	if (combo1 == 0 && combo2 == 0 && combo3 == 0 && combo4 == 0 && combo5 == 0
			&& combo6 == 0 && combo7 == 0 && combo8 == 0 && combo9 == 0
			&& combo10 == 0) {

		alert("Atenção!!! Para Cálculo Familiar, informe a quantidade de usuários por faixa etária diferente de 0 (Zero)");
	} else if (qtde == 1) {

		alert("Atenção!!! Para Cálculo Familiar, informe a quantidade de usuários por faixa etária diferente de 1 (Um)");
	}
	return true;
}

function alterasenha() {
	var oldpass = document
			.getElementById("form1:OldPasswordDecorate:oldPassword").value;
	var pass = document.getElementById("form1:PasswordDecorate:password").value;
	var repass = document.getElementById("form1:VerifyDecorate:verify").value;

	if (oldpass == "") {
		alert("Digite a senha Atual!");
		return false;
	} else if (pass == "") {
		alert("Digite a nova senha!");
		return false;
	} else if (repass == "") {
		alert("Repita a nova senha!");
		return false;
	} else if (repass != pass) {
		alert("Nova senha não confere!");
		return false;
	}
	return true;
}

function validaDataAgenda() {

	var visita = document.getElementById("form1:txtdatavis").value;
	
	if (visita.length != 10){
		alert("Informe a data da visita!");
		return false;
	}
	
	var data = new Date();
	var dia = data.getDate();
	var mes = data.getMonth() + 1;
	var ano = data.getFullYear();
	if (dia < 10) {
		dia = '0' + dia;
	}
	if (mes < 10) {
		mes = '0' + mes;
	}
	var atual = dia + "/" + mes + "/" + ano;
	
    if	(!comparaData(visita, atual)){
    	alert("A Data da Visita informada é menor do que a data " + (atual));
		return false;
    }
	return true;
}

function sendTab() {

	if (event.keyCode == 13) {

		var e = window.event.keyCode = 9
		var key = (window.event) ? event.keyCode : e.which;

		if (window.event)
			key = event.keyCode
		else
			key = e.which

		if (navigator.appName == 'Microsoft Internet Explorer') {
			window.event.returnValue = 9;
		} else {
			e.preventDefault(9);
		}
	}
}

function sac() {
	var msg = "Telefones Assistência São Lucas: \n\n "
			+ "De segunda a sexta das 08:00hrs às 18:00hrs: \n\n"
			+ " S.A.C. \n " + "SAC Lins: (14)3533-4508  \n\n "
			+ "SAC Bauru: (14)3235-9895  \n\n "
			+ "SAC Marilia: (14)3311-4500 \n\n\n "
			+ "Em outros dias e horários: \n\n " + "Hospitais \n "
			+ "Hospital Lins: (14)3533-4401 \n\n "
			+ "Hospital Bauru: (14)3235-4500 \n\n";

	alert(msg);
	return false;
}

function qtdeZero(campo) {
	var qtde = document.getElementById(campo).value;

	if (qtde == '0') {
		alert("A quantidade não pode ser 0");
		return false;
	}
	return false;
}

function mascaraMatricula(event, objeto) {
	var tecla = (window.event) ? event.keyCode : event.which;
	campo = eval(objeto);
	if (tecla == 9 || tecla == 8 || (tecla >= 48 && tecla <= 57)) {
		if (tecla != 9
				&& tecla != 8
				&& (campo.value.length == 4 || campo.value.length == 9 || campo.value.length == 16)) {
			campo.value = campo.value + '.';
		}
		if (tecla != 9 && tecla != 8 && (campo.value.length == 19)) {
			campo.value = campo.value + '-';
		}
		return true;
	}
	return false;
}

function mascaraCnpj(event, objeto) {
	var tecla = (window.event) ? event.keyCode : event.which;
	campo = eval(objeto);
	if (tecla == 8 || (tecla >= 48 && tecla <= 57)) {
		if (tecla != 8 && (campo.value.length == 2 || campo.value.length == 6)) {
			campo.value = campo.value + '.';
		}
		if (tecla != 8 && (campo.value.length == 10)) {
			campo.value = campo.value + '/';
		}
		if (tecla != 8 && (campo.value.length == 15)) {
			campo.value = campo.value + '-';
		}
		return true;
	}
	return false;
}

function mascaraCPF(event, objeto) {
	var tecla = (window.event) ? event.keyCode : event.which;
	campo = eval(objeto);

	if (tecla == 8 || (tecla >= 48 && tecla <= 57)) {

		if (tecla != 8 && (campo.value.length == 3 || campo.value.length == 7)) {
			campo.value = campo.value + '.';
		}

		if (tecla != 8 && (campo.value.length == 11)) {
			campo.value = campo.value + '-';
		}

		return true;
	}
	return false;
}

function mascaraData(event, objeto) {
	var tecla = (window.event) ? event.keyCode : event.which;
	campo = eval(objeto);

		if (campo.value == '00/00/0000') {
			campo.value = "";
		}
		if (tecla == 8 || (tecla >= 48 && tecla <= 57)) {
			if (tecla != 8
					&& (campo.value.length == 2 || campo.value.length == 5)) {
				campo.value = campo.value + '/';
			}
			return true;
		} else {
			return false;
		}	
}

function mascaraRG(event, objeto) {
	var tecla = (window.event) ? event.keyCode : event.which;
	campo = eval(objeto);

	// Verifica se é número, ou se é 'X'.
	if (tecla == 8 || tecla == 88 || tecla == 120
			|| (tecla >= 48 && tecla <= 57)) {

		if (tecla != 8 && (campo.value.length == 2 || campo.value.length == 6)) {
			campo.value = campo.value + '.';
		}

		if (tecla != 8 && (campo.value.length == 10)) {
			campo.value = campo.value + '-';
		}
		return true;
	}
	return false;
}

function mascaraCEP(event, objeto) {
	var tecla = (window.event) ? event.keyCode : event.which;
	campo = eval(objeto);

	// Verifica se é número.
	if (tecla == 8 || (tecla >= 48 && tecla <= 57)) {

		if (tecla != 8 && (campo.value.length == 5)) {
			campo.value = campo.value + '-';
		}
		return true;
	}
	return false;
}

function mascaraTelefone(event, objeto) {
	var tecla = (window.event) ? event.keyCode : event.which;
	campo = eval(objeto);

	// Verifica se é número.
	if (tecla == 8 || (tecla >= 48 && tecla <= 57)) {

		if (tecla != 8 && (campo.value.length == 1)) {
			campo.value = '(' + campo.value;
		}
		if (tecla != 8 && (campo.value.length == 3)) {
			campo.value = campo.value + ')';
		}
		if (tecla != 8 && (campo.value.length == 8)) {
			campo.value = campo.value + '-';
		}
		return true;
	}
	return false;
}

function mascaraTelefoneSemDDD(event, objeto) {
	var tecla = (window.event) ? event.keyCode : event.which;
	campo = eval(objeto);

	// Verifica se é número.
	if (tecla == 8 || (tecla >= 48 && tecla <= 57)) {
		if (tecla != 8 && (campo.value.length == 4)) {
			campo.value = campo.value + '-';
		}
		return true;
	}
	return false;
}

function mascaraOrgaoUFRG(event, objeto) {
	var tecla = (window.event) ? event.keyCode : event.which;
	campo = eval(objeto);

	// Se não é '/' ou caracter inválido
	if (!(tecla >= 33 && tecla <= 64)) {
		if (tecla != 8 && (campo.value.length == 3)) {
			campo.value = campo.value + '/';
		}
		return true;
	}
	return false;
}

function formatarMoeda(objeto, separador_milhar, separador_decimal, event) {
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '0123456789';
	var aux = aux2 = '';
	var whichCode = (window.event) ? event.keyCode : event.which;

	if (whichCode == 13)
		return true; // Tecla Enter
	if (whichCode == 8)
		return true; // Tecla Delete
	key = String.fromCharCode(whichCode); // Pegando o valor digitado
	if (strCheck.indexOf(key) == -1)
		return false; // Valor inválido (não inteiro)
	len = objeto.value.length;
	for (i = 0; i < len; i++)
		if ((objeto.value.charAt(i) != '0')
				&& (objeto.value.charAt(i) != separador_decimal))
			break;
	aux = '';
	for (; i < len; i++)
		if (strCheck.indexOf(objeto.value.charAt(i)) != -1)
			aux += objeto.value.charAt(i);
	aux += key;
	len = aux.length;
	if (len == 0)
		objeto.value = '';
	if (len == 1)
		objeto.value = '0' + separador_decimal + '0' + aux;
	if (len == 2)
		objeto.value = '0' + separador_decimal + aux;

	if (len > 2) {
		aux2 = '';

		for (j = 0, i = len - 3; i >= 0; i--) {
			if (j == 3) {
				aux2 += separador_milhar;
				j = 0;
			}
			aux2 += aux.charAt(i);
			j++;
		}

		objeto.value = '';
		len2 = aux2.length;
		for (i = len2 - 1; i >= 0; i--)
			objeto.value += aux2.charAt(i);
		objeto.value += separador_decimal + aux.substr(len - 2, len);
	}

	return false;
}

function Trim(str) {
	return str.replace(/^\s+|\s+$/g, "");
}

function JanelaCentralizada(mypage, myname, w, h, scroll, pos) {
	var win = null;

	if (pos == "random") {
		LeftPosition = (screen.width) ? Math.floor(Math.random()
				* (screen.width - w)) : 100;
		TopPosition = (screen.height) ? Math.floor(Math.random()
				* ((screen.height - h) - 75)) : 100;
	}
	if (pos == "center") {
		LeftPosition = (screen.width) ? (screen.width - w) / 2 : 100;
		TopPosition = (screen.height) ? (screen.height - h) / 2 : 100;
	} else if ((pos != "center" && pos != "random") || pos == null) {
		LeftPosition = 0;
		TopPosition = 20
	}
	settings = 'width='
			+ w
			+ ',height='
			+ h
			+ ',top='
			+ TopPosition
			+ ',left='
			+ LeftPosition
			+ ',scrollbars='
			+ scroll
			+ ',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
	win = window.open(mypage, myname, settings);

}

function validaVazio(campo, titulo) {
	var dado = document.getElementById(campo).value;
	if (dado == "") {
		alert("O campo " + titulo + " não pode ser vazio!")
		return false;
	}
	return true;
}

function validaVazioQtde(campo, titulo, qtde) {
	var filtro = document.getElementById(campo).value;

	if (filtro == "") {
		alert("O campo " + titulo + " não pode ser vazio!");
		return false;
	} else if (filtro.length < qtde) {
		alert("Digite no mínimo " + qtde + " letras... !!! ");
		return false;
	}
	return true;
}

function validaCEP(campo) {
	var dado = document.getElementById(campo).value;

	if (dado.length < 9) {
		alert("Preencher o CEP.")
		return false;
	}
	return true;
}

function validaCpf(campo) {
	var i;

	x = document.getElementById(campo).value;
	if (x == "000.000.000-00" || x == "111.111.111-11" || x == "222.222.222-22"
			|| x == "333.333.333-33" || x == "444.444.444-44"
			|| x == "555.555.555-55" || x == "666.666.666-66"
			|| x == "777.777.777-77" || x == "888.888.888-88"
			|| x == "999.999.999-99") {
		alert("C.P.F Inválido!");
		return false;
	}

	s = x.replace('.', '').replace('.', '').replace('.', '').replace('-', '');

	var c = s.substr(0, 9);
	var dv = s.substr(9, 2);
	var d1 = 0;
	for (i = 0; i < 9; i++) {
		d1 += c.charAt(i) * (10 - i);
	}
	if (d1 == 0) {
		alert("CPF Inválido!")
		return false;
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9)
		d1 = 0;
	if (dv.charAt(0) != d1) {
		alert("CPF Inválido!")
		return false;
	}
	d1 *= 2;
	for (i = 0; i < 9; i++) {
		d1 += c.charAt(i) * (11 - i);
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9)
		d1 = 0;
	if (dv.charAt(1) != d1) {
		alert("CPF Inválido!")
		return false;
	}

	return true;
}

function validaCnpj(campo) {
	cpf = document.getElementById(campo).value;

	if (cpf.length != 18) {
		alert("C.N.P.J. Inválido!");
		return false;
	}
	if (cpf.length > 0 && cpf.length < 18 || cpf == "00.000.000/0000-00"
			|| cpf == "11.111.111/1111-11" || cpf == "22.222.222/2222-22"
			|| cpf == "33.333.333/3333-33" || cpf == "44.444.444/4444-44"
			|| cpf == "55.555.555/5555-55" || cpf == "66.666.666/6666-66"
			|| cpf == "77.777.777/7777-77" || cpf == "88.888.888/8888-88"
			|| cpf == "99.999.999/9999-99") {
		alert("C.N.P.J. Inválido!");
		return false;
	}
	return true;
}

function validaData(campo) {
	var data = document.getElementById(campo).value;
	var dia = (document.getElementById(campo)).value.substring(0, 2);
	var mes = (document.getElementById(campo)).value.substring(3, 5);
	var ano = (document.getElementById(campo)).value.substring(6, 10);
	var i;

	if (data.length != 10) {
		alert("Data Inválida!");
		return false;
	}
	if (data.length > 0 && data.length < 10 || data == "00/00/0000"
			|| data == "11/11/1111" || data == "22/22/2222"
			|| data == "33/33/3333" || data == "44/44/4444"
			|| data == "55/55/5555" || data == "66/66/6666"
			|| data == "77/77/7777" || data == "88/88/8888"
			|| data == "99/99/9999") {
		alert("Data Inválida!");
		return false;
	}
	if (dia < "01" || dia > "31") {
		alert("Dia inválido!");
		return false;
	}

	if (mes < "01" || mes > "12") {
		alert("Mês inválido!");
		return false;
	}
	if (ano.length != 4) {
		alert("O ano deve ser com 4 dígitos. DD/MM/AAAA !!!");
		return false;
	}
	return true;
}

function BloquearCTRL_V()
{
	var ctrl=window.event.ctrlKey;
	var tecla=window.event.keyCode;
	if (ctrl && tecla==86) {event.keyCode=0; event.returnValue=false;}
}

function validaMatricula(mat) {

	var campo = document.getElementById(mat).value;

	if (campo.length != 21) {
		alert("Matrícula Inválida!");
		return false;
	}

	if (campo.length > 0 && campo.length < 21) {
		alert("Matrícula Inválida!");
		return false;
	} else {
		if (campo == "0000.0000.000000.00-0"
				|| campo == "1111.1111.111111.11-1"
				|| campo == "2222.2222.222222.22-2"
				|| campo == "3333.3333.333333.33-3"
				|| campo == "4444.4444.444444.44-4"
				|| campo == "5555.5555.555555.55-5"
				|| campo == "6666.6666.666666.66-6"
				|| campo == "7777.7777.777777.77-7"
				|| campo == "8888.8888.888888.88-8"
				|| campo == "9999.9999.999999.99-9") {
			alert("Matrícula Inválida!");
			return false;
		}
	}
	return true;
}

function mascaraLogin(event, objeto, tipo){
	var tip = document.getElementById(tipo).value;
	
	if (tip == "B") {
		if (mascaraMatricula(event, objeto)){
			return true;
		}else{
			return false;
		}
	}else{
		return true;
	}	
}

function validaLogin(login, senha, tipo) {
	var username = document.getElementById(login).value;
	var password = document.getElementById(senha).value;
	var tip = document.getElementById(tipo).value;
	
	if (tip == "B") {
		if (!validaMatricula(login)) {
			return false;
		}		
	}else{
		if (username == ""){
			alert("Digite o Login!");
			return false;
		}
	}
		if (password == "") {
			alert("Digite a Senha!");
			return false;
	}	
	return true;
}

function validaUsuario(){
	if (!document.getElementById("form1:txtlogin").disabled){
		if (!validaVazio("form1:txtlogin", "Login")){
			return false;
		}
		if (!validaVazio("form1:txtsenha", "Senha")){
			return false;
		}
	}else{ 
		if (Trim(document.getElementById("form1:txtsenha").value) != ""){
			if (!confirm("Confirma alteração da senha?")){
				return false;
			}
		}
	}
	if (!validaVazio("form1:txtnome", "Nome")){
		return false;
	}
	return true;	
}

function comparaData(dataIni, dataFin){
	var data1 = dataIni;
	var data2 = dataFin;
	if ( parseInt( data2.split( "/" )[2].toString() + data2.split( "/" )[1].toString() + data2.split( "/" )[0].toString() ) > parseInt( data1.split( "/" )[2].toString() + data1.split( "/" )[1].toString() + data1.split( "/" )[0].toString() ) ){
		return false;
	}	
	return true;
}


function validaDataBoleto(campo, tipo) {
	var data1 = document.getElementById(campo).value;
	var tip = document.getElementById(tipo).value;
	
	alert(tip);
	
	if (data1.length != 10){
		alert("Informe a Data!");
		return false;
	}
	
	var data = new Date();
	var dia = data.getDate();
	var mes = data.getMonth() + 1;
	var ano = data.getFullYear();
	if (dia < 10) {
		dia = '0' + dia;
	}
	if (mes < 10) {
		mes = '0' + mes;
	}
	var atual = dia + "/" + mes + "/" + ano;
	
	if	(!comparaData(data1, atual)){
    	alert("A nova data do Vencimento não pode ser menor que Hoje(" + (atual) + ")");
		return false;
    }
	return true;
}

function validaVazioQtdeNaoObrigatorio(campo, titulo, qtde) {
	var filtro = document.getElementById(campo).value;

	if (filtro.length > 0 && filtro.length < 4) {
		alert("Digite no mínimo " + qtde + " letras no campo " + titulo + "! ");
		return false;	
	}
	return true;
}

function validaExtrato(campo, campo2) {
		
	if (!validaMatricula(campo)) {
		document.getElementById(campo).focus();
		return false;
	}
	if (!validaCpf(campo2)) {
		document.getElementById(campo2).focus();
			return false;
	}	
	return true;
}

function msgBoletoVencido(){
	var msg;
	msg = "''ATENÇÃO'' \n\n" +
			"SUA MENSALIDADE ESTÁ VENCIDA, E FOI CALCULADA COM JUROS E MULTA DIÁRIA. \n\n" +
			"DEVERÁ SER LIQUIDADO PREFERENCIALMENTE NA REDE BANCÁRIA OU EM CASAS LOTÉRICAS. \n\n" +
			"EM CASO DE DUVIDA, ENTRE EM CONTATO COM NOSSA CENTRAL DE RELACIONAMENTO AO CLIENTE \n\n";			
	alert(msg);	
}
