// JNS

function show( hp, h, v, sc ) {
    x = eval(screen.width);
    y = eval(screen.height);
    d = x / 2;
    t = y / 2;
    mh = h / 2;
    mv = v / 2;
    r = d - mh;
    s = t - mv;
    if ( x <= 800 ) { s = 0; }
    window.open(hp,"","top="+s+",left="+r+",resizable=no,location=no,toolbar=no,status=no,menubar=no,copyhistory=no,scrollbars="+sc+",width="+h+",height="+v+"")
}

function mOvr(src,clrOver) {
     if (!src.contains(event.fromElement)) {
     src.style.cursor = 'default';
     src.bgColor = clrOver;
     }
}

function mOut(src,clrIn) {
    if (!src.contains(event.toElement)) {
    src.style.cursor = 'default';
    src.bgColor = clrIn;
    }
}

function mClk(src) {
    if(event.srcElement.tagName=='TD'){
    src.children.tags('A')[0].click();
    }
}

function valid_date(l,dd,mm,yy)
{
	z='err';
	if (l == 6 || l == 8)
	{
		xx=yy;
		if (dd >= 1 && dd <= 31)
		{
			if (mm == 2 || mm == 4 || mm == 6 || mm == 9 || mm == 11)
			{
				if (dd <= 30)
				{
					if (mm == 2)
					{
						if (dd <= 28)
						{
							z='ok';
						}
						else
						{
							if (dd == 29)
							{
								bb=xx%4;	// 4 by 4
								if (bb == 0)
								{
									cc=xx%100;	// 100 by 100
									if (cc == 0)
									{
										qq=xx%400;	// 400 by 400
										if (qq == 0)
										{
											z='ok';
										};
									}
									else
									{
										z='ok';
									};
								};
							};
						};
					}
					else
					{
						z='ok';
					};
				};
			}
			else
			{
				if (mm >= 1 && mm <= 12) { z='ok'; };
			};
		};
	};
	ii=200;		// inner parameter
	if (xx < 1600 || xx > 2400 || xx < 2005 - ii || xx > 2005 + ii) { z='err'; };
	return z;
};

function consist_date(dat)
{
	n='0123456789';
	d=dat.value;
	l=d.length;
	s='';
	for (i=0; i<l; i++)
	{
		c=d.charAt(i);
		if (n.indexOf(c) >= 0)
		{
			s+=c;
		};
	};
	l=s.length;
	xx='0000';
	r=s;
	if (l > 8)
	{
		r=s.substr(0,8);
		s=r;
		l=8;
	};
	if (l == 6)
	{
		dd=s.substr(0,2);
		mm=s.substr(2,2);
		yy=s.substr(4,2);
		if (yy < 50)
		{
			xx='20'+yy;
		}
		else
		{
			xx='19'+yy;
		};
		ww=dd+'/'+mm+'/'+yy;
	};
	if (l == 8)
	{
		dd=s.substr(0,2);
		mm=s.substr(2,2);
		yy=s.substr(4,4);
		xx=yy;
		ww=dd+'/'+mm+'/'+yy;
	};
	if (l == 6 || l == 8)
	{
		z=valid_date(l,dd,mm,xx);
		if (z == 'ok') { r=ww; };
	};
	dat.value=r;
	return 'ok';
};

function update_date(dat)
{
	n='0123456789';
	d=dat.value;
	l=d.length;
	s='';
	for (i=0; i<l; i++)
	{
		c=d.charAt(i);
		if (n.indexOf(c) >= 0)
		{
			s+=c;
		};
	};
	l=s.length;
	if (l == 6)
	{
		dd=s.substr(0,2);
		mm=s.substr(2,2);
		yy=s.substr(4,2);
		if (yy < 50)
		{
			yy='20'+yy;
		}
		else
		{
			yy='19'+yy;
		};
		ww=dd+'/'+mm+'/'+yy;
	};
	if (l == 8)
	{
		dd=s.substr(0,2);
		mm=s.substr(2,2);
		yy=s.substr(4,4);
		ww=dd+'/'+mm+'/'+yy;
	};
	rr='';
	if (l == 6 || l == 8)
	{
		z=valid_date(l,dd,mm,yy);
		if (z == 'ok')
		{
			rr=ww;
		};
	};
	dat.value=rr;
	return 'ok';
};

function mask( formato, keypress, objeto )
{
		campo = eval(objeto);

		// CPF
		if (formato ==  'CPF')
		{
			var s = limpa_string(campo.value);
			if (s.length == 3)
				campo.value = s.substr(0, 3) + '.';
			else if (s.length == 6)
				campo.value = s.substr(0, 3) + '.' + s.substr(3, 3) + '.';
			else if (s.length == 9)
				campo.value = s.substr(0, 3) + '.' + s.substr(3, 3) + '.' + s.substr(6, 3) + '-';
		}

		// CEP
		if (formato ==  'CEP')
		{
			var s = limpa_string(campo.value);
			if (s.length == 2)
				campo.value = s.substr(0, 2) + '.';
			else if (s.length == 5)
				campo.value = s.substr(0, 2) + '.' + s.substr(2, 3) + '-';
		}

		// DATA
		if (formato ==  'DATA')
		{
			var s = limpa_string(campo.value);
			if (s.length == 2)
				campo.value = s.substr(0, 2) + '/';
			else if (s.length == 4)
				campo.value = s.substr(0, 2) + '/' + s.substr(2, 4) + '/';
		}

		// TELEFONE
		if (formato ==  'FONEGERAL')
		{
			var s = limpa_string(campo.value);
			if (s.length == 2)
				campo.value = s.substr(0, 2) + '.';
			else if (s.length == 6)
				campo.value = s.substr(0, 2) + '.' + s.substr(2, 6) + '-';
		}

		var c = String.fromCharCode(keypress);
		if (isNaN(c) || keypress == 32) return false;
}

function verificar(theForm)
{
    var nome_site = "Igreja em Rondonópolis - Cadastro      \n\nAviso: ";

    if (theForm.nome.value == "") {
    alert(nome_site+"- Informar o seu Nome.");
    theForm.nome.focus();
    return (false);
    }

    if (theForm.email.value.indexOf("@",0) == -1) {
    alert(nome_site+"- Informe o seu Email corretamente.");
    theForm.email.focus();
    return (false);
    }

    x = theForm.email.value.length;
    x = x - 1;

    if (theForm.email.value.indexOf("@",0) == x) {
    alert(nome_site+"- Informe o seu Email corretamente.");
    theForm.email.focus();
    return (false);
    }

    if (theForm.email.value.indexOf("@",0) == 0) {
    alert(nome_site+"- Informe o seu Email corretamente.");
    theForm.email.focus();
    return (false);
    }

    if (theForm.email.value.indexOf(".@",0) != -1) {
    alert(nome_site+"- Informe o seu Email corretamente.");
    theForm.email.focus();
    return (false);
    }

    if (theForm.email.value.indexOf("@.",0) != -1) {
    alert(nome_site+"- Informe o seu Email corretamente.");
    theForm.email.focus();
    return (false);
    }

    if (theForm.senha.value == "") {
    alert(nome_site+"- Informar a sua Senha.");
    theForm.senha.focus();
    return (false);
    }

    if (theForm.senha.value != theForm.csenha.value) {
    alert(nome_site+"- Confirme a sua Senha corretamente.");
    theForm.senha.focus();
    return (false);
    }

    if (theForm.listEstados.value == 0) {
    alert(nome_site+"- Favor selecione um Estado.");
    theForm.listEstados.focus();
    return (false);
    }

    if (theForm.listCidades.value == 0) {
    alert(nome_site+"- Favor selecione uma Cidade.");
    theForm.listCidades.focus();
    return (false);
    }

    if (theForm.data_nascimento.value == "") {
    alert(nome_site+"- Informar a sua Data de Nascimento.");
    theForm.data_nascimento.focus();
    return (false);
    }
    
    theForm.submit;
}

function verificar_contato(theForm)
{
    var nome_site = "Igreja em Rondonópolis - Contato      \n\nAviso: ";

    if (theForm.nome.value == "") {
    alert(nome_site+"- Informar o seu Nome.");
    theForm.nome.focus();
    return (false);
    }

    if (theForm.email.value.indexOf("@",0) == -1) {
    alert(nome_site+"- Informe o seu Email corretamente.");
    theForm.email.focus();
    return (false);
    }

    x = theForm.email.value.length;
    x = x - 1;

    if (theForm.email.value.indexOf("@",0) == x) {
    alert(nome_site+"- Informe o seu Email corretamente.");
    theForm.email.focus();
    return (false);
    }

    if (theForm.email.value.indexOf("@",0) == 0) {
    alert(nome_site+"- Informe o seu Email corretamente.");
    theForm.email.focus();
    return (false);
    }

    if (theForm.email.value.indexOf(".@",0) != -1) {
    alert(nome_site+"- Informe o seu Email corretamente.");
    theForm.email.focus();
    return (false);
    }

    if (theForm.email.value.indexOf("@.",0) != -1) {
    alert(nome_site+"- Informe o seu Email corretamente.");
    theForm.email.focus();
    return (false);
    }

    theForm.submit;
}

function check(theForm)
{
    var nome_site = "Igreja em Rondonópolis         \n\nAviso: ";

    if (theForm.mensagem.value == "") {
    alert(nome_site+"- Digite a sua Mensagem.");
    theForm.mensagem.focus();
    return (false);
    }

    theForm.submit;
}

