// 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);
}
// -------------------------------------------------------
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='#222222';
		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
	{
	parte1 = campo.value.indexOf("@");
	parte3 = campo.value.length;
	teste1	= (parte1)
	teste3	= ((parte3-parte1)-1)
	
	if (!(teste1 >= 2 && teste3 >= 4)) 
	{
        alert ("O campo E-mail deve ser conter um endereço eletronico válido!");
 		campo.style.background='#222222';
		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='#222222';
					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='#222222';
					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='#222222';
						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';
	}
}
function abre_fotos(foto, largura, altura)
{
	document.getElementById('pop_fotos').style.display = 'block';
	document.getElementById('pop_fotos').style.height = (altura+22)+'px';
	document.getElementById('pop_fotos').style.left = ((436-largura)/2)+'px';
	document.getElementById('pop_fotos').style.width = (largura+4)+'px';
	document.getElementById('foto_pop').src = foto;
}
function fecha_fotos()
{
	document.getElementById('foto_pop').src = '../img/noticias/nt.jpg';
	document.getElementById('pop_fotos').style.display = 'none';
}
function ajuste(altura)
{
	parent.document.getElementById('blk_site').style.height = altura+'px';
	parent.document.getElementById('blk_principal').style.height = altura+'px';
	parent.document.getElementById('blk_princ_esq').style.height = (altura-6)+'px';
	parent.document.getElementById('blk_princ_dir').style.height = (altura-6)+'px';
	parent.document.getElementById('canto_esq_inf').style.top = (altura-3)+'px';
	parent.document.getElementById('canto_dir_inf').style.top = (altura-3)+'px';
	parent.document.getElementById('intFrame').height = (altura-365);
	parent.document.getElementById('blk_rodape').style.top = (altura-19)+'px';
}
function abre_letra(id)
{
	document.getElementById('pop_letras').style.display = 'block';
	document.getElementById('intLetra').src = '../site/conteudo.php?pag=letras&id='+id;
}
function fecha_letra()
{
	parent.document.getElementById('intLetra').src = '';
	parent.document.getElementById('pop_letras').style.display = 'none';
}
function abre_recado()
{
	document.getElementById('pop_envia_recado').style.display = 'block';
}
function fecha_recado()
{
	parent.document.getElementById('pop_envia_recado').style.display = 'none';
}
