// JavaScript Document
// -------------------------------------------------------
// -------------------------------------------------------
function enter_tab(primeiro_form)
{
	nextfield = primeiro_form;
	netscape = "";
	ver = navigator.appVersion; len = ver.length;
	for(iln = 0; iln < len; iln++) if (ver.charAt(iln) == "(") break;
		netscape = (ver.charAt(iln+1).toUpperCase() != "C");
	function keyDown(DnEvents) 
		{
			k = (netscape) ? DnEvents.which : window.event.keyCode;
			if (k == 13) 
			{
			if (nextfield == 'done') 
			{
				return false;
			} 
			else 
			{
				eval('document.fmcad.' + nextfield + '.focus()');
				return false;
			}
		}
	}
	document.onkeydown = keyDown;
	if (netscape) document.captureEvents(Event.KEYDOWN|Event.KEYUP);
}
//  PULA DE UM CAMPO AO OUTRO DEPOIS DE PREENCHIDO OS ESPAÇOS -------------------------------------------------------
function pula(campo,maximo,proximo)
{
	if(document.getElementById(campo).value.length >= maximo)
	{
		document.getElementById(proximo).focus();
	}
}
// -------------------------------------------------------
function menu(menu)
{
	parent.document.getElementById('menu_01_selec').style.display = 'none';
	parent.document.getElementById('menu_02_selec').style.display = 'none';
	parent.document.getElementById('menu_03_selec').style.display = 'none';
	parent.document.getElementById('menu_04_selec').style.display = 'none';
	parent.document.getElementById('menu_05_selec').style.display = 'none';
	parent.document.getElementById('menu_06_selec').style.display = 'none';
	parent.document.getElementById('menu_07_selec').style.display = 'none';

	if (menu != '')
		parent.document.getElementById(menu).style.display = 'block';
}
// -------------------------------------------------------
function StatusMsg(msgStr) 
{
  status=msgStr;
  document.MM_returnValue = true;
}
// -------------------------------------------------------
function abre_janela(arquivo, nome_janela, largura, altura, maximiza, menu, barra, status)
{
	vleft=(((screen.availWidth/2)-(largura/2))-10);
  	vtop=(((screen.availHeight/2)-(altura/2))-30);
	janela=window.open(arquivo, nome_janela, 'width='+largura+',height='+altura+',top='+vtop+', left='+vleft+', resizable='+maximiza+',menubar='+menu+',scrollbars='+barra+', status='+status+'');
	janela.focus();
}
function abre_pop(arquivo, nome_janela, top, left, largura, altura, maximiza, menu, barra, status)
{
	vleft=(((screen.availWidth-785)/2)+left);
	
	janela=window.open(arquivo, nome_janela, 'width='+largura+',height='+altura+',top='+top+', left='+vleft+', resizable='+maximiza+',menubar='+menu+',scrollbars='+barra+', status='+status+'');
	janela.focus();
}
// -------------------------------------------------------
function vazio(campo, mensagem)
{
	if (campo.value.length==0)
	{
		alert('O campo '+mensagem+' deve ser preenchido!');
		campo.style.background='#D6D7DA';
		campo.focus();
		return true;
	}
	return false;
}
// -------------------------------------------------------
function vazio_radio(campo, mensagem)
{
	checado = false;
	for(i=0; i<campo.length; i++)
	{
		if (campo[i].checked)
			checado = true;
	}
	if (!checado)
	{
		alert('O campo '+mensagem+' deve ser preenchido!');
		return true;
	}
	else
		return false;
}
// -------------------------------------------------------
function valida_email(campo)
{
	if (campo.value.length==0)
		return true;
	else
	{
		teste1 = campo.value.indexOf("@");
		teste2 = campo.value.substr((teste1+1),20);
		teste3 = campo.value.substr((teste1+1),20).length;
		teste4 = teste2.indexOf(".");
		teste5 = campo.value.substr((teste1 + 1 + teste4 + 1),20).length;

		if (!(teste1 > 2 && teste4 > 2 && teste3 > 4 && teste5 > 1))
		{
			alert ("O campo E-mail deve ser conter um endereço eletronico válido!");
			campo.style.background='#f1f1f1';
			campo.focus();
			return false;
		}
		return true;
	}
}

// -------------------------------------------------------
function mask(objForm, strField, sMask, evtKeyPress)
{
	var i, nCount, sValue, fldLen, mskLen, bolMask, sCod, nTecla;

		sValue = objForm[strField].value;
		// Limpa todos os caracteres de formatação que
		// já estiverem no campo.
		while (sValue.indexOf('-')>=0)
			sValue = sValue.toString().replace( "-", "" );
		while (sValue.indexOf(':')>=0)
			sValue = sValue.toString().replace( ":", "" );
		while (sValue.indexOf('.')>=0)
			sValue = sValue.toString().replace( ".", "" );
		while (sValue.indexOf('/')>=0)
			sValue = sValue.toString().replace( "/", "" );
		while (sValue.indexOf("(")>=0)
			sValue = sValue.toString().replace( "(", "" );
		while (sValue.indexOf(")")>=0)
			sValue = sValue.toString().replace( ")", "" );
		while (sValue.indexOf(' ')>=0)
			sValue = sValue.toString().replace( " ", "" );
		fldLen = sValue.length;
		mskLen = sMask.length;
		
		i = 0;
		nCount = 0;
		sCod = "";
		mskLen = fldLen;
		
		while (i <= mskLen)
		{
			bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".")|| (sMask.charAt(i) == ":") || (sMask.charAt(i) == "/"))
			
			bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))
		
			if (bolMask)
			{
				sCod += sMask.charAt(i);
				mskLen++;
			}
			else
			{
				sCod += sValue.charAt(nCount);
				nCount++;
			}
			i++;
		}
		
		objForm[strField].value = sCod;

	if (isNaN(sValue.substr((sValue.length-1),1)))
	{
		alert('O campo deve conter apenas numeros');
		return false;
	}
}
// -------------------------------------------------------
function teste_img(campo, local, mensagem)
{
	if (campo.value.length==0) return false;

			// testa tipo imagem
				caminho = campo.value.substr(1,1)
				var tipo = campo.value.substr(((campo.value.length)-4),4);
				tipo = tipo.toLowerCase()
			
				if (caminho != ":")
				{
					alert('O campo '+mensagem+' contem um CAMINHO INVÁLIDO !');
					campo.style.background='#F1F1F1';
					campo.focus();
					return true;
				}
				if ((tipo != ".jpg") && (tipo != "jpeg"))
				{
					alert('O campo '+mensagem+' contem um arquivo INVÁLIDO \r        O formato deve ser JPG ou JPEG!');
					campo.style.background='#F1F1F1';
					campo.focus();
					return true;
				}
			// teste se tem campo localizacao
			if (local=="") return false;

			else
			{
				if (local.value.length==0)
					{
						alert('O campo de Localização - '+mensagem+' deve ser preenchido!');
						local.style.background='#F1F1F1';
						local.focus();
						return true;
					}
			}
return false;
}
// ---------------- Teste Enquete
function vazio_enquete(campo, mensagem)
{
	checado = false;
	for(i=0; i<campo.length; i++)
	{
		if (campo[i].checked)
			checado = true;
	}
	if (!checado)
	{
		alert('Você deve escolher uma opção !');
		return true;
	}
	else
		return false;
}
// ---------------- Funcoes DIV
function abre_div(id, metodo)
{
	obj = document.getElementById(id);
	if(metodo == 'display')
	{
		obj.style.display = 'block';
	}
	else
	{
		obj.style.visibility = 'visible';
	}
}
function fecha_div(id, metodo)
{
	obj = document.getElementById(id);
	if(metodo == 'display')
	{
		obj.style.display = 'none';
	}
	else
	{
		obj.style.visibility = 'hidden';
	}
}
/* =============== maiusculas */
function conv_maiusc(valor, campo)
{
	$conv = valor.toUpperCase();
	campo.value = $conv;
}
/* =============== minusculas */
function conv_minusc(valor, campo)
{
	$conv = valor.toLowerCase();
	campo.value = $conv;
}
/* limpa formularios */
function limpa01()
{
	if (document.fmcad_01.email.value == 'Email')			document.fmcad_01.email.value = '';
}
/* POP UP GALERIAS DE FOTOS  */
function abre_galeria(id,tp)	{
	
	if (tp == 'foto')	{
		parent.document.getElementById('fundo_site').style.display = 'block';
		parent.document.getElementById('blk_fotos').style.display = 'block';
		parent.document.getElementById('intGal').src = 'site/galeria.php?tp=foto&id='+id;
	}
	if (tp == 'noticia')	{
		parent.document.getElementById('fundo_site').style.display = 'block';
		parent.document.getElementById('blk_fotos').style.display = 'block';
		parent.document.getElementById('intGal').src = 'site/galeria.php?tp=noticia&id='+id;
	}
	else if (tp == 'video')	{
		parent.document.getElementById('fundo_site').style.display = 'block';
		parent.document.getElementById('blk_videos').style.display = 'block';
		parent.document.getElementById('intVid').src = 'site/galeria.php?tp=video&id='+id;
	}
	else if (tp == 'artigos')	{
		parent.document.getElementById('fundo_site').style.display = 'block';
		parent.document.getElementById('blk_ampliar').style.display = 'block';
		parent.document.getElementById('intFot').src = 'site/galeria.php?tp=artigos&id='+id;
	}
	else if (tp == 'midia')	{
		parent.document.getElementById('fundo_site').style.display = 'block';
		parent.document.getElementById('blk_midia').style.display = 'block';
		parent.document.getElementById('intMid').src = 'site/galeria.php?tp=midia&id='+id;
	}
}
function fechar_galeria()	{
	document.getElementById('fundo_site').style.display = 'none';
	parent.document.getElementById('blk_fotos').style.display = 'none';
	parent.document.getElementById('intGal').src = '';
}
function fechar_video()	{
	document.getElementById('fundo_site').style.display = 'none';
	parent.document.getElementById('blk_videos').style.display = 'none';
	parent.document.getElementById('intVid').src = '';
}
function fechar_ampliar()	{
	document.getElementById('fundo_site').style.display = 'none';
	parent.document.getElementById('blk_ampliar').style.display = 'none';
	parent.document.getElementById('intFot').src = ''
}
function fechar_midia()	{
	document.getElementById('fundo_site').style.display = 'none';
	parent.document.getElementById('blk_midia').style.display = 'none';
	parent.document.getElementById('intMid').src = ''
}
function fecha_pop()
{
	parent.document.getElementById('fundo_site').style.display = 'none';
	parent.document.getElementById('div_001').style.display = 'none';
}

/* =============== Destaque HOME */
function dest(valor, formato)
{
	// habilita blocos TEXTO
	document.getElementById('dest1_txt').style.display = 'block';
	document.getElementById('dest2_txt').style.display = 'block';
	document.getElementById('dest3_txt').style.display = 'block';
	document.getElementById('dest4_txt').style.display = 'block';
	document.getElementById('dest5_txt').style.display = 'block';
	// desabilita blocos OVER
	document.getElementById('dest1_over').style.display = 'none';
	document.getElementById('dest2_over').style.display = 'none';
	document.getElementById('dest3_over').style.display = 'none';
	document.getElementById('dest4_over').style.display = 'none';
	document.getElementById('dest5_over').style.display = 'none';
	// desabilita blocos IMG
	document.getElementById('dest1_img').style.display = 'none';
	document.getElementById('dest2_img').style.display = 'none';
	document.getElementById('dest3_img').style.display = 'none';
	document.getElementById('dest4_img').style.display = 'none';
	document.getElementById('dest5_img').style.display = 'none';
	// habilita SELECIONADO
	document.getElementById('dest'+valor+'_txt').style.display = 'none';
	document.getElementById('dest'+valor+'_over').style.display = 'block';
	document.getElementById('dest'+valor+'_img').style.display = 'block';

	// calculo do PROXIMO BLOCO
	if (formato == 'aut')
	{
		var proximo = (eval(valor) + 1);
		if (proximo == 6)		proximo = 1;
		intervalo = window.setTimeout("dest("+proximo+", 'aut')", 2500);
	}
	else
	{
		clearInterval(intervalo);
	}
}
