// função genérica para o Flash

function swf(flash,width,height)
{
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+width+'" height="'+height+'" />');
	document.write('<param name="movie" value="'+flash+'" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="menu" value="0" />');
	document.write('<param name="wmode" value="opaque" />');
	document.write('<embed src="'+flash+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'" menu="0" wmode="opaque"></embed>');
	document.write('</object>');
}
	
function Altura()  
{
	window.parent.document.getElementById('metas').style.height = document.getElementById('padrao').clientHeight + "px";
	window.parent.document.getElementById('metas').height = document.getElementById('padrao').clientHeight + "px";
}

// Enviar formulário com enter
function EnviaDadosComEnter(e)
{
	 var key //= (window.event) ? event.keyCode : e.which;
	 if (window.event)
		 key = event.keyCode
	 else
		 key = e.which

	if (key == 13 )
	{
		// validação do formulário
		document.forms[0].submit();
	}
}

function ValidaCadastro()
{
	//cpf
	cpf = document.enviaDados.nr_cpf.value;
	if (cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999")
		return false;
	add = 0;
	for (i=0; i < 9; i ++)
		add += parseInt(cpf.charAt(i)) * (10 - i);
	rev = 11 - (add % 11);
	if (rev == 10 || rev == 11)
		rev = 0;
	if (rev != parseInt(cpf.charAt(9)))
		return false;
	add = 0;
	for (i = 0; i < 10; i ++)
		add += parseInt(cpf.charAt(i)) * (11 - i);
	rev = 11 - (add % 11);
	if (rev == 10 || rev == 11)
		rev = 0;
	if (rev != parseInt(cpf.charAt(10)))
		return false;

	// txt_email
	if (document.enviaDados.txt_email.value == "")
	{
		window.alert("Por favor digite o e-mail.");
		document.enviaDados.txt_email.focus();
		return false;
	}

	var checkcliEmail = "@.";
	var checkStr = document.enviaDados.txt_email.value;
	var cliEmailValid = false;
	var cliEmailAt = false;
	var cliEmailPeriod = false;
	
	for (i = 0;  i < checkStr.length;  i++)
	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkcliEmail.length;  j++)
		{
			if (ch == checkcliEmail.charAt(j) && ch == "@")
				cliEmailAt = true;
			if (ch == checkcliEmail.charAt(j) && ch == ".")
				cliEmailPeriod = true;
			if (cliEmailAt && cliEmailPeriod)
				break;
			if (j == checkcliEmail.length)
				break;
		}
		if (cliEmailAt && cliEmailPeriod)
		{
			cliEmailValid = true
			break;
		}
	}

	if (!cliEmailValid)
	{
		window.alert("Por favor digite um e-mail válido.");
		document.enviaDados.txt_email.focus();
		return false;
	}
		
    else
	{
		document.enviaDados.submit();
	}
}