// FUNÇÃO PARA EXIBIÇÃO DE FLASHS
// ----------------------------------------------------------------------------
function ExibeFlash(w,h,wmode,movie) {
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+w+'" height="'+h+'">');
	document.write('<param name="wmode" value="'+wmode+'"/>');
	document.write('<param name="quality" value="high"/>');
	document.write('<param name="movie" value="'+movie+'"/>');
	document.write('<embed src="'+movie+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="'+wmode+'" width="'+w+'" height="'+h+'"></embed>');
	document.write('</object>');
}
// ----------------------------------------------------------------------------

function VerificaInscricao() {
  if (!document.form1.nome.value) { alert("Por favor, informe seu nome."); document.form1.nome.focus(); return false; };
  if (!document.form1.endereco.value) { alert("Por favor, informe seu endereço."); document.form1.endereco.focus(); return false; };
  if (!document.form1.bairro.value) { alert("Por favor, informe o bairro."); document.form1.bairro.focus(); return false; };
  if (!document.form1.cep.value) { alert("Por favor, informe o CEP."); document.form1.cep.focus(); return false; };
  if (!document.form1.cidade.value) { alert("Por favor, informe a cidade."); document.form1.cidade.focus(); return false; };
  if (!document.form1.estado.value) { alert("Por favor, selecione um estado."); document.form1.estado.focus(); return false; };
  if (!document.form1.telres.value) { alert("Por favor, informe o telefone para contato."); document.form1.telres.focus(); return false; };
  if (!VEmail( document.form1.email.value)) { alert("O e-mail informado não é válido!\nVerifique-o novamente."); document.form1.email.focus(); return false; };
  if (!document.form1.cpf.value) { alert("Por favor, informe seu cpf."); document.form1.cpf.focus(); return false; };
  
  return true;   
}

/* 
	Mascara para Campos.
	"#" - Numeros
	"A" - Letras UpperCase
	"a" - Letras LowerCase
	"Z" - Letras
	"*" - Qualquer Caracter
	"/", ".", "-", " ", ":" - Caracteres Fixos
*/
function Mascara(objeto, evt, mask) {
		
	var LetrasU = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
	var LetrasL = 'abcdefghijklmnopqrstuvwxyz';
	var Letras 	= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
	var Numeros = '0123456789';
	var Fixos 	= '().-:/ '; 
	var Charset = " !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_/`abcdefghijklmnopqrstuvwxyz{|}~";
	
	evt = (evt) ? evt : (window.event) ? window.event : "";
	var value = objeto.value;
	if (evt) {
		var ntecla = (evt.which) ? evt.which : evt.keyCode;
		tecla = Charset.substr(ntecla - 32, 1);
		if (ntecla < 32) return true;

		var tamanho = value.length;
		if (tamanho >= mask.length) return false;

		var pos = mask.substr(tamanho,1); 
		while (Fixos.indexOf(pos) != -1) {
			value += pos;
			tamanho = value.length;
			if (tamanho >= mask.length) return false;
			pos = mask.substr(tamanho,1);
		}

		switch (pos) {
				case '#' : if (Numeros.indexOf(tecla) == -1) return false; break;
				case 'A' : if (LetrasU.indexOf(tecla) == -1) return false; break;
				case 'a' : if (LetrasL.indexOf(tecla) == -1) return false; break;
				case 'Z' : if (Letras.indexOf(tecla) == -1) return false; break;
				case '*' : objeto.value = value; return true; break;
				default : return false; break;
		}
	}
	objeto.value = value; 
	return true;
}

// Deixa a string apenas com os numeros, eliminando o restante.
function trimToDigits(string) {
	s = "";
	var Numeros = /\d/;
	for (i = 0; i <= string.length; i++) 
		if (Numeros.test(string.substr(i,1))) s += string.substr(i,1);
	return s;	
}

function VEmail( strEmail ) {
     var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
     return (filter.test(strEmail));
}

function VAno(ano) {
	ano = trimToDigits(ano);
	return ((parseInt(ano) < 1900) || (ano.length != 4) || (parseInt(ano) > 2050)) ? false : true; 
}

function VMes(mes) {
	mes = trimToDigits(mes);
	return ((mes.length != 2) || (parseInt(mes) < 1) || (parseInt(mes) > 12)) ? false : true; 
}

function VMesAno(data) {
	data = trimToDigits(data);
	if (data.length < 6) return false;
	mes = data.substr(0,2);
	ano = data.substr(2,4);
	return (!VAno(ano) || !VMes(mes)) ? false : true;
}
//Verifica se a data é valida
function VData(data) {
	data = trimToDigits(data);
	if (data.length < 8) return false;
	dia = data.substr(0,2);
	mes = data.substr(2,2);
	ano = data.substr(4,4);
	
	if(ano >= 0 && ano < 1900) return false; 
	if(ano > 2100 || ano < 0 || mes > 12 || mes < 1) return false; 
	numero = ((parseInt(ano) - 1884) / 4) 
	dias = (numero == Math.floor(numero)) ? "312931303130313130313031" : "312831303130313130313031"; 
	diamax = parseInt(dias.substring((mes - 1) * 2, ((mes - 1) * 2) + 2)); 
	if(dia < 1 || dia > diamax) return false; 	
	
	return true;
}

// Verifica a autenticidade do CPF
function VCPF(cpf) {
	cpf = trimToDigits(cpf);
	if (cpf.length < 11) return false;
	valor = true;
	if (cpf == "00000000000" || cpf == "11111111111" || 
			cpf == "22222222222" || cpf == "33333333333" || 
			cpf == "44444444444" || cpf == "55555555555" || 
			cpf == "66666666666" || cpf == "77777777777" || 
			cpf == "88888888888" || cpf == "99999999999") return false;

	var a = [];
	var b = new Number;
	var c = 11;
	for (i = 0; i < 11; i++) {
		a[i] = cpf.charAt(i);
		b = (i < 9) ? b + (a[i] *  --c) : b;
	}
	
	a[9] = ((x = b % 11) < 2) ? 0 : 11 - x;

	b = 0;
	c = 11;
	for (y = 0; y < 10; y++) b += (a[y] *  c--); 
	a[10] = ((x = b % 11) < 2) ? 0 : 11 - x;

	return (cpf.charAt(9) == a[9]) && (cpf.charAt(10) == a[10]);
}	

function VCNPJ(cnpj) {
	cnpj = trimToDigits(cnpj);
	if (cnpj.length < 14) return false;
	m2 = 2;		
	soma1 = 0;
	soma2 = 0;
	for ( i = 11; i >= 0; i--) {
		val = eval(cnpj.charAt(i));
		m1 = m2;
		if (m2 < 9) { m2++ }
	 	else { m2 = 2 }
		soma1 = soma1 + (val * m1)
		soma2 = soma2 + (val * m2)
  }
	soma1 = soma1 % 11
	if (soma1 < 2) { d1 = 0 }
  else { d1 = 11 - soma1}
	soma2 = (soma2 + (2 * d1)) % 11
	if (soma2 < 2) { d2 = 0 }
  else { d2 = 11 - soma2}
	return (cnpj.charAt(12) == d1) && (cnpj.charAt(13) == d2);
}

function MaskAno(objeto, evt) { 
	return Mascara(objeto, evt, '####');
}

function MaskMesAno(objeto, evt) { 
	return Mascara(objeto, evt, '##/####');
}

function MaskCEP(objeto, evt) { 
	return Mascara(objeto, evt, '##.###-###');
}

function MaskTelefone(objeto, evt) { 
	return Mascara(objeto, evt, '(##) ####-####');
}

function MaskCPF(objeto, evt) { 
	return Mascara(objeto, evt, '###.###.###-##');
}

function MaskCNPJ(objeto, evt) { 
	return Mascara(objeto, evt, '##.###.###/####-##');
}

function MaskData(objeto, evt) { 
	return Mascara(objeto, evt, '##/##/####');
}

function MaskHora(objeto, evt) { 
	return Mascara(objeto, evt, '##:##');
}

function MaskHora2(objeto, evt) { 
	return Mascara(objeto, evt, '##:##:##');
}