var wTimeOut;
var bName = navigator.appName;

function videoStop()
{
	document.getElementById("video_flv").SetVariable("player:jsStop", "");
}

function videoPlay()
{
	document.getElementById("video_flv").SetVariable("player:jsPlay", "1");
	//document.getElementById("video_flv").SetVariable("player:jsSetPosition", "1");
}

function setaPaginacaoVideos(pPagina)
{
	wTotalPaginas = document.getElementById("quant_paginas_videos").value;

	for (var i=1;i<=wTotalPaginas;i++)
	{
		if (document.getElementById("VS_" + i) != null)
		{
			document.getElementById("VS_" + i).style.backgroundColor="#FFFFFF";
			document.getElementById("VI_" + i).style.backgroundColor="#FFFFFF";
		}
	}	
	document.getElementById("VS_" + pPagina).style.backgroundColor="#C0C0C0";
	document.getElementById("VI_" + pPagina).style.backgroundColor="#C0C0C0";
	
	if (wTotalPaginas > 1)
	{
		if (pPagina == 1)
		{
			document.getElementById("paginacao_superior").innerHTML = "Anterior | <a href='javascript:mudaPaginaVideos(2);'>Próximo</a>";
			document.getElementById("paginacao_inferior").innerHTML = "Anterior | <a href='javascript:mudaPaginaVideos(2);'>Próximo</a>";
		}
		else
		{			
			if (pPagina == wTotalPaginas)
			{
				document.getElementById("paginacao_superior").innerHTML = "<a href='javascript:mudaPaginaVideos(" + (parseInt(pPagina) - 1) + ");'>Anterior</a> | Próximo";
				document.getElementById("paginacao_inferior").innerHTML = "<a href='javascript:mudaPaginaVideos(" + (parseInt(pPagina) - 1) + ");'>Anterior</a> | Próximo";
			}
			else
			{
				document.getElementById("paginacao_superior").innerHTML = "<a href='javascript:mudaPaginaVideos(" + (parseInt(pPagina) - 1) + ");'>Anterior</a> | <a href='javascript:mudaPaginaVideos(" + (parseInt(pPagina) + 1) + ");'>Próximo</a>";
				document.getElementById("paginacao_inferior").innerHTML = "<a href='javascript:mudaPaginaVideos(" + (parseInt(pPagina) - 1) + ");'>Anterior</a> | <a href='javascript:mudaPaginaVideos(" + (parseInt(pPagina) + 1) + ");'>Próximo</a>";
			}
		}
	}
	else
	{
		document.getElementById("paginacao_superior").innerHTML = "";
		document.getElementById("paginacao_inferior").innerHTML = "";
	}
	//videoPlay();
	//videoStop();
}

function setaPaginacaoSociedade(pPagina)
{
	wTotalPaginas = document.getElementById("quant_paginas_sociedade").value;

	for (var i=1;i<=wTotalPaginas;i++)
	{
		if (document.getElementById("SS_" + i) != null)
		{
			document.getElementById("SS_" + i).style.backgroundColor="#FFFFFF";
		}
	}	
	document.getElementById("SS_" + pPagina).style.backgroundColor="#C0C0C0";

	if (wTotalPaginas > 1)
	{
		if (pPagina == 1)
		{
			document.getElementById("paginacao_sociedade").innerHTML = "Anterior | <a href='javascript:mudaPaginaSociedade(2);'>Próximo</a>";
		}
		else
		{			
			if (pPagina == wTotalPaginas)
			{
				document.getElementById("paginacao_sociedade").innerHTML = "<a href='javascript:mudaPaginaSociedade(" + (parseInt(pPagina) - 1) + ");'>Anterior</a> | Próximo";
			}
			else
			{
				document.getElementById("paginacao_sociedade").innerHTML = "<a href='javascript:mudaPaginaSociedade(" + (parseInt(pPagina) - 1) + ");'>Anterior</a> | <a href='javascript:mudaPaginaSociedade(" + (parseInt(pPagina) + 1) + ");'>Próximo</a>";
			}
		}
	}
	else
	{
		document.getElementById("paginacao_sociedade").innerHTML = "";
	}
}

function setaPaginacaoClassificados(pPagina)
{
	wTotalPaginas = document.getElementById("quant_paginas_classificados").value;

	for (var i=1;i<=wTotalPaginas;i++)
	{
		if (document.getElementById("CS_" + i) != null)
		{
			document.getElementById("CS_" + i).style.backgroundColor="#FFFFFF";
			document.getElementById("CI_" + i).style.backgroundColor="#FFFFFF";
		}
	}	
	document.getElementById("CS_" + pPagina).style.backgroundColor="#C0C0C0";
	document.getElementById("CI_" + pPagina).style.backgroundColor="#C0C0C0";
	
	if (wTotalPaginas > 1)
	{
		if (pPagina == 1)
		{
			document.getElementById("paginacao_superior").innerHTML = "Anterior | <a href='javascript:mudaPaginaClassificados(2);'>Próximo</a>";
			document.getElementById("paginacao_inferior").innerHTML = "Anterior | <a href='javascript:mudaPaginaClassificados(2);'>Próximo</a>";
		}
		else
		{			
			if (pPagina == wTotalPaginas)
			{
				document.getElementById("paginacao_superior").innerHTML = "<a href='javascript:mudaPaginaClassificados(" + (parseInt(pPagina) - 1) + ");'>Anterior</a> | Próximo";
				document.getElementById("paginacao_inferior").innerHTML = "<a href='javascript:mudaPaginaClassificados(" + (parseInt(pPagina) - 1) + ");'>Anterior</a> | Próximo";
			}
			else
			{
				document.getElementById("paginacao_superior").innerHTML = "<a href='javascript:mudaPaginaClassificados(" + (parseInt(pPagina) - 1) + ");'>Anterior</a> | <a href='javascript:mudaPaginaClassificados(" + (parseInt(pPagina) + 1) + ");'>Próximo</a>";
				document.getElementById("paginacao_inferior").innerHTML = "<a href='javascript:mudaPaginaClassificados(" + (parseInt(pPagina) - 1) + ");'>Anterior</a> | <a href='javascript:mudaPaginaClassificados(" + (parseInt(pPagina) + 1) + ");'>Próximo</a>";
			}
		}
	}
	else
	{
		document.getElementById("paginacao_superior").innerHTML = "";
		document.getElementById("paginacao_inferior").innerHTML = "";
	}
	videoPlay();
	//videoStop();
}

function setaPaginacaoClassificadosAberto(pPagina)
{
	wTotalPaginas = document.getElementById("quant_paginas_classificados").value;

	for (var i=1;i<=wTotalPaginas;i++)
	{
		if (document.getElementById("CS_" + i) != null)
		{
			document.getElementById("CS_" + i).style.backgroundColor="#FFFFFF";
		}			
	}	
	document.getElementById("CS_" + pPagina).style.backgroundColor="#C0C0C0";

	if (wTotalPaginas > 1)
	{
		if (pPagina == 1)
		{
			document.getElementById("paginacao_classificados").innerHTML = "Anterior | <a href='javascript:mudaPaginaClassificados(2);'>Próximo</a>";
		}
		else
		{			
			if (pPagina == wTotalPaginas)
			{
				document.getElementById("paginacao_classificados").innerHTML = "<a href='javascript:mudaPaginaClassificados(" + (pPagina - 1) + ");'>Anterior</a> | Próximo";
			}
			else
			{
				document.getElementById("paginacao_classificados").innerHTML = "<a href='javascript:mudaPaginaClassificados(" + (pPagina - 1) + ");'>Anterior</a> | <a href='javascript:mudaPaginaClassificados(" + (pPagina + 1) + ");'>Próximo</a>";
			}
		}
	}
	else
	{
		document.getElementById("paginacao_classificados").innerHTML = "";
	}
}

function setaPaginacaoComentarios(pPagina)
{
	wTotalPaginas = document.getElementById("quant_paginas_comentarios").value;
	
	if (wTotalPaginas > 0)
	{
		document.getElementById("div_com").style.display = "block";
		for (var i=1;i<=wTotalPaginas;i++)
		{
			if (document.getElementById("OS_" + i) != null)
			{
				document.getElementById("OS_" + i).style.backgroundColor="#FFFFFF";
			}
		}	
		document.getElementById("OS_" + pPagina).style.backgroundColor="#C0C0C0";
	
		if (wTotalPaginas >= 1)
		{
			if (pPagina == 1)
			{
				document.getElementById("paginacao_comentarios").innerHTML = "Anterior | <a href='javascript:mudaPaginaComentarios(2);'>Próximo</a>";
			}
			else
			{			
				if (pPagina == wTotalPaginas)
				{
					document.getElementById("paginacao_comentarios").innerHTML = "<a href='javascript:mudaPaginaComentarios(" + (parseInt(pPagina) - 1) + ");'>Anterior</a> | Próximo";
				}
				else
				{
					document.getElementById("paginacao_comentarios").innerHTML = "<a href='javascript:mudaPaginaComentarios(" + (parseInt(pPagina) - 1) + ");'>Anterior</a> | <a href='javascript:mudaPaginaComentarios(" + (parseInt(pPagina) + 1) + ");'>Próximo</a>";
				}
			}
		}
		else
		{
			document.getElementById("div_com").style.display = "none";
			document.getElementById("paginacao_comentarios").innerHTML = "";
		}
	}
}

function setaPaginacaoNoticias(pPagina)
{
	wTotalPaginas = document.getElementById("quant_paginas_noticias").value;

		for (var i=1;i<=wTotalPaginas;i++)
		{
			if (document.getElementById("NS_" + i) != null)
			{
				document.getElementById("NS_" + i).style.backgroundColor="#FFFFFF";
				document.getElementById("NI_" + i).style.backgroundColor="#FFFFFF";
			}
		}	
		document.getElementById("NS_" + pPagina).style.backgroundColor="#C0C0C0";
		document.getElementById("NI_" + pPagina).style.backgroundColor="#C0C0C0";
	
		if (wTotalPaginas > 1)
		{
			if (pPagina == 1)
			{
				document.getElementById("paginacao_superior").innerHTML = "Anterior | <a href='javascript:mudaPaginaNoticias(2);'>Próximo</a>";
				document.getElementById("paginacao_inferior").innerHTML = "Anterior | <a href='javascript:mudaPaginaNoticias(2);'>Próximo</a>";
			}
			else
			{			
				if (pPagina == wTotalPaginas)
				{
					document.getElementById("paginacao_superior").innerHTML = "<a href='javascript:mudaPaginaNoticias(" + (parseInt(pPagina) - 1) + ");'>Anterior</a> | Próximo";
					document.getElementById("paginacao_inferior").innerHTML = "<a href='javascript:mudaPaginaNoticias(" + (parseInt(pPagina) - 1) + ");'>Anterior</a> | Próximo";
				}
				else
				{
					document.getElementById("paginacao_superior").innerHTML = "<a href='javascript:mudaPaginaNoticias(" + (parseInt(pPagina) - 1) + ");'>Anterior</a> | <a href='javascript:mudaPaginaNoticias(" + (parseInt(pPagina) + 1) + ");'>Próximo</a>";
					document.getElementById("paginacao_inferior").innerHTML = "<a href='javascript:mudaPaginaNoticias(" + (parseInt(pPagina) - 1) + ");'>Anterior</a> | <a href='javascript:mudaPaginaNoticias(" + (parseInt(pPagina) + 1) + ");'>Próximo</a>";
				}
			}
		}
		else
		{
			document.getElementById("paginacao_superior").innerHTML = "";
			document.getElementById("paginacao_inferior").innerHTML = "";
		}
}

function setaPaginacaoBusca(pPagina)
{
	wTotalPaginas = document.getElementById("pags_busca").value;

	for (var i=1;i<=wTotalPaginas;i++)
	{
		if (document.getElementById("BS_" + i) != null)
		{
			document.getElementById("BS_" + i).style.backgroundColor="#FFFFFF";
			document.getElementById("BI_" + i).style.backgroundColor="#FFFFFF";
		}
	}	
	document.getElementById("BS_" + pPagina).style.backgroundColor="#C0C0C0";
	document.getElementById("BI_" + pPagina).style.backgroundColor="#C0C0C0";
	
	if (wTotalPaginas > 1)
	{
		if (pPagina == 1)
		{
			document.getElementById("paginacao_superior").innerHTML = "Anterior | <a href='javascript:validaBusca(2);'>Próximo</a>";
			document.getElementById("paginacao_inferior").innerHTML = "Anterior | <a href='javascript:validaBusca(2);'>Próximo</a>";
		}
		else
		{			
			if (pPagina == wTotalPaginas)
			{
				document.getElementById("paginacao_superior").innerHTML = "<a href='javascript:validaBusca(" + (parseInt(pPagina) - 1) + ");'>Anterior</a> | Próximo";
				document.getElementById("paginacao_inferior").innerHTML = "<a href='javascript:validaBusca(" + (parseInt(pPagina) - 1) + ");'>Anterior</a> | Próximo";
			}
			else
			{
				document.getElementById("paginacao_superior").innerHTML = "<a href='javascript:validaBusca(" + (parseInt(pPagina) - 1) + ");'>Anterior</a> | <a href='javascript:validaBusca(" + (parseInt(pPagina) + 1) + ");'>Próximo</a>";
				document.getElementById("paginacao_inferior").innerHTML = "<a href='javascript:validaBusca(" + (parseInt(pPagina) - 1) + ");'>Anterior</a> | <a href='javascript:validaBusca(" + (parseInt(pPagina) + 1) + ");'>Próximo</a>";
			}
		}
	}
	else
	{
		document.getElementById("paginacao_superior").innerHTML = "";
		document.getElementById("paginacao_inferior").innerHTML = "";
	}
	//videoPlay();
	//videoStop();
}

function getCheckedValue(radioObj) 
{
	var found_it;

	for (var i=0; i<document.form_busca.filtro_busca.length; i++)  
	{ 
		if (document.form_busca.filtro_busca[i].checked)  
		{
			found_it = document.form_busca.filtro_busca[i].value;
		}
	} 
	
	return found_it;
}

function validaBusca(pPag)
{
	if (document.getElementById("text_busca").value == "")
	{
		alert("Favor informar o texto para pesquisa!");
		document.getElementById("text_busca").focus();
	}
	else
	{
		var wOpcao     = getCheckedValue(document.getElementById("filtro_busca"));
		var wTexto     = document.getElementById("text_busca").value;
		var wOrdenacao = document.getElementById("ordenacao_busca").value;

		var grupo_atual = parseInt((parseInt(document.getElementById('pag_busca_atual').value) - 1) / 7);
		var grupo_novo  = parseInt((pPag - 1) / 7);
		var continua = "S";
		
		if (grupo_atual > grupo_novo)
		{
			mudaGrupoSuperiorBusca(grupo_atual, "-");
			continua = "N"
		}
		else
		{
			if (grupo_atual < grupo_novo)
			{
				mudaGrupoSuperiorBusca(grupo_novo + 1, "+");
				continua = "N"
			}
		}
		
		if (continua == "S")
		{
			if (pPag == 0)
			{
				wPag = document.getElementById('pag_busca_atual').value;
			}
			else
			{
				wPag = pPag;
			}
			
			document.getElementById('pag_busca_atual').value = wPag;		

			ctrl = getBusyOverlay(document.getElementById('div_resultado'), {color:'#D3D3D3',opacity:0.50, text:'Aguarde ... efetuando a consulta'});
		
			new Ajax.Updater("div_resultado", "busca.php", 
			{ 
				parameters: 
				{ 
					pag: pPag , 
					texto: escape(wTexto), 
					opcao: wOpcao, 
					ordena: wOrdenacao
				} ,
				onComplete: function() 
				{
					if (document.getElementById("tem_conteudo") != null)
					{
						document.getElementById("paginacao_superior").style.display = "block";
						document.getElementById("paginacao_inferior").style.display = "block";
						if (document.getElementById('pag_busca_atual').value == 1)
						{
							document.getElementById("pagina_superior").innerHTML = "Páginas: " + document.getElementById("pag_superior").value;
							document.getElementById("pagina_inferior").innerHTML = "Páginas: " + document.getElementById("pag_inferior").value;
							document.getElementById("pagina_superior").innerHTML = "Páginas: " + document.getElementById("pag_superior").value;
						}
						document.getElementById("data").style.display = "none";
						document.getElementById("data_busca").style.display = "block";
						document.getElementById("img_todos").innerHTML = "<BR><img src='img/resultado.jpg' />";
					
						setaPaginacaoBusca(pPag);
					}
					else
					{
						document.getElementById("paginacao_superior").style.display = "none";
						document.getElementById("paginacao_inferior").style.display = "none";
						if (document.getElementById('pag_busca_atual').value == 1)
						{
							document.getElementById("pagina_inferior").innerHTML = "";
							document.getElementById("pagina_superior").innerHTML = "";
						}
						document.getElementById("data").style.display = "none";
						document.getElementById("data_busca").style.display = "block";
						document.getElementById("img_todos").innerHTML = "<BR><img src='img/resultado.jpg' />";
					}

					if (Ajax.activeRequestCount === 0) 
					{
						ctrl.remove();
					}
				}
			}); 
		}
	}
}


function mudaGrupoSuperiorBusca(pGrupo, pSinal)
{
	var wPag;
	var wOrdem = document.getElementById('ordenacao').value;		
		
	wPag = ((pGrupo - 1) * 7) + 1;
		
	document.getElementById('pag_busca_atual').value = wPag;		
		
	acionaAjaxBusca("ajax_paginacao.php", wPag, wOrdem, "S");
}	
	
function mudaGrupoInferiorBusca(pGrupo, pSinal)
{
	var wPag;
	var wOrdem = document.getElementById('ordenacao').value;		
		
	wPag = ((pGrupo - 1) * 7) + 1;
		
	document.getElementById('pag_busca_atual').value = wPag;		
		
	acionaAjaxBusca("ajax_paginacao.php", wPag, wOrdem, "I");
}	

var ajaxBusca;
var ctrlBusca;
	
function ajaxStateBusca()
{ 
	if ( (ajaxBusca.readyState == 4) && (ajaxBusca.status==200) )
	{
		ctrlBusca.remove();
		var resultado_ajax = ajaxBusca.responseText;
		document.getElementById('pagina_superior').innerHTML = resultado_ajax.replace(/BI_/g, "BS_");
		document.getElementById('pagina_inferior').innerHTML = resultado_ajax.replace(/BS_/g, "BI_");
		validaBusca(document.getElementById('pag_busca_atual').value);
		setaPaginacaoBusca(document.getElementById('pag_busca_atual').value);
	}
} 
	
function acionaAjaxBusca(url, pPag, pOrdem, pPosicao) 
{ 
	var hoje;
	var ident;
		
	hoje = new Date();
	ident = hoje.getUTCMilliseconds();
	
	ctrlBusca = getBusyOverlay(document.getElementById('div_resultado'), {color:'#D3D3D3',opacity:0.50, text:'Aguarde ... carregando itens'});
	ajaxBusca = openAjax(); 
	ajaxBusca.onreadystatechange = ajaxStateBusca;
	ajaxBusca.open("GET", url + "?ident="+ident+"&pag="+pPag+"&ordem="+pOrdem+"&posicao="+pPosicao+"&tipo=B", true); 
	ajaxBusca.send(null) 
} 

function validaTag(pTag)
{
	ctrl = getBusyOverlay(document.getElementById('div_resultado'), {color:'#D3D3D3',opacity:0.50, text:'Aguarde ... efetuando a consulta'});
		
	new Ajax.Updater("div_resultado", "busca.php", 
	{ 
		parameters: 
		{ 
			pag: 1 , 
			texto: escape(pTag), 
			opcao: "V" 
		} ,
		onComplete: function() 
		{
			document.getElementById("data").style.display = "none";
			document.getElementById("data_busca").style.display = "block";
			document.getElementById("img_todos").innerHTML = "<BR><img src='img/resultado.jpg' />";
			document.getElementById("text_busca").value = pTag;
			
			if (Ajax.activeRequestCount === 0) 
			{
				ctrl.remove();
			}
			setaPaginacaoBusca(1);
		}
	}); 
}

function trocaImagem(pSentido)
{
    window.clearTimeout(wTimeOut);
    if (pSentido != "")
    {
		if (pSentido == "+")
		{
			imagem_atual++;
		    if (imagem_atual > qtdImagens)
			{
 				imagem_atual = 1;
			}
		}
		else
		{
			imagem_atual--;
		    if (imagem_atual == 0)
			{
 				imagem_atual = qtdImagens;
			}
		}
		document.getElementById("img_slide").src             = document.getElementById("imagem_"    + imagensArray[imagem_atual - 1]).value;
		document.getElementById("slide_titulo").innerHTML    = document.getElementById("titulo_"    + imagensArray[imagem_atual - 1]).value;
		document.getElementById("slide_data").innerHTML      = document.getElementById("data_"      + imagensArray[imagem_atual - 1]).value;
		document.getElementById("slide_exibicoes").innerHTML = document.getElementById("exibicoes_" + imagensArray[imagem_atual - 1]).value + " exibições";
		document.getElementById("slide_duracao").innerHTML   = document.getElementById("duracao_"   + imagensArray[imagem_atual - 1]).value;
		//document.getElementById("slide_link").href           = document.getElementById("link_"      + imagensArray[imagem_atual - 1]).value;
		document.getElementById("slide_link_titulo").href    = document.getElementById("link_"      + imagensArray[imagem_atual - 1]).value;
	}
    wTimeOut = window.setTimeout('trocaImagem("+")',cTempoExibicaoSlide);   
}
   
function trocaBanners()
{
    BSE_atual++;
    if (BSE_atual > qtdBSE)
    {
 	   BSE_atual = 1;
    }

    BSD_atual++;
    if (BSD_atual > qtdBSD)
    {
 	   BSD_atual = 1;
    }

    BIE_atual++;
    if (BIE_atual > qtdBIE)
    {
 	   BIE_atual = 1;
    }

    BID_atual++;
    if (BID_atual > qtdBID)
    {
 	   BID_atual = 1;
    }

    
    if (BSEArray[BSE_atual - 1] == "")
    {
		document.getElementById("img_BSE").src = "img/banner.jpg";
	}
	else
	{
	    document.getElementById("img_BSE").src = BSEArray[BSE_atual - 1];
	}
	
    if (BSDArray[BSD_atual - 1] == "")
    {
		document.getElementById("img_BSD").src = "img/banner.jpg";
	}
	else
	{
	    document.getElementById("img_BSD").src = BSDArray[BSD_atual - 1];
	}

    if (BIEArray[BIE_atual - 1] == "")
    {
		document.getElementById("img_BIE").src = "img/banner.jpg";
	}
	else
	{
	    document.getElementById("img_BIE").src = BIEArray[BIE_atual - 1];
	}

    if (BIDArray[BID_atual - 1] == "")
    {
		document.getElementById("img_BID").src = "img/banner.jpg";
	}
	else
	{
	    document.getElementById("img_BID").src = BIDArray[BID_atual - 1];
	}

    if (Href_BSEArray[BSE_atual - 1] == undefined)
    {
		Href_BSEArray[BSE_atual - 1] = "0";
    }

    if (Href_BSDArray[BSD_atual - 1] == undefined)
    {
		Href_BSDArray[BSD_atual - 1] = "0";
    }

    if (Href_BIEArray[BIE_atual - 1] == undefined)
    {
		Href_BIEArray[BIE_atual - 1] = "0";
    }

    if (Href_BIDArray[BID_atual - 1] == undefined)
    {
		Href_BIDArray[BID_atual - 1] = "0";
    }

    document.getElementById("href_BSE").href = "banner.php?cod=" + Href_BSEArray[BSE_atual - 1];
    document.getElementById("href_BSD").href = "banner.php?cod=" + Href_BSDArray[BSD_atual - 1];
    document.getElementById("href_BIE").href = "banner.php?cod=" + Href_BIEArray[BIE_atual - 1];
    document.getElementById("href_BID").href = "banner.php?cod=" + Href_BIDArray[BID_atual - 1];

    window.setTimeout('trocaBanners()', cTempoExibicaoBanner);   
}

function validaFormatoEmail(pEmail)
{
	if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(pEmail))) 
	{
		return false;
	}
	else
	{
		return true;
	}
	
}

function validaEmail(pCampoEmail)
{
	var pEmail = document.getElementById(pCampoEmail).value;
			
	if (pEmail == '') 
	{
		alert('Favor informar o e-mail!');
		document.getElementById(pCampoEmail).focus();
		return false;

	}
	else
	{
		if (!validaFormatoEmail(pEmail))
		{
			alert('Formato inválido para e-mail!');
			document.getElementById(pCampoEmail).focus();
			return false;
		}
		else
		{
			return true;
		}
	}
}

function limitarTexto(Event, Object, MaxLen)
{        
	return (Object.value.length <= MaxLen)||(Event.keyCode == 8 ||Event.keyCode==46||(Event.keyCode>=35&&Event.keyCode<=40))
}

function validaConteudoData(dia, mes, ano_r)
{
	var ano = ano_r;
	var bissexto;
			
	switch (mes)
	{
		case '01':
		case '03':
		case '05':
		case '07':
		case '08':
		case '10':
		case '12':
			if (dia <= 31)
			{
				return true;
			}
			break;
					
		case '04':
		case '06':
		case '09':
		case '11':
			if (dia <= 30)
			{
				return true;
			}
			break;
					
		case '02':
			if ((ano % 4 == 0) || (ano % 100 == 0) || (ano % 400 == 0))
			{
				bissexto = 1;
			}
					
			if ((bissexto == 1) && (dia <= 29))
			{
				return true;
			}

			if ((bissexto != 1) && (dia <= 28))
			{
				return true;
			}
			break;
	}
	return false;
}

function validaData(pCampoData)
{
	var pData = document.getElementById(pCampoData).value;
			
	if (pData == "") 
	{
		if (document.getElementById(pCampoData).getAttribute("req") == "S")
		{
			alert('Favor informar a data !');
			document.getElementById(pCampoData).style.backgroundColor = '#FFCC00';
			return false;
		}
		else
		{
			document.getElementById(pCampoData).style.backgroundColor = '';
			return true;
		}
	}
	else
	{
		if (pData.length != 10) 
		{
			alert('Favor informar a data no formato DD/MM/AAAA!');;
			document.getElementById(pCampoData).style.backgroundColor = '#FFCC00';
			return false;
		}
		else
		{
			if ( (pData.substr(2, 1) != "/") || (pData.substr(5, 1) != "/") )
			{
				alert('Favor informar a data no formato DD/MM/AAAA!');
				document.getElementById(pCampoData).style.backgroundColor = '#FFCC00';
				return false;
			}
			else
			{
				if ( (isNaN(pData.substr(0, 2))) || (isNaN(pData.substr(3, 2))) || (isNaN(pData.substr(6, 4))) )
				{
					alert('Favor informar somente números e barras na data (DD/MM/AAAA)!');
					document.getElementById(pCampoData).style.backgroundColor = '#FFCC00';
					return false;
				}
				else
				{
					if (!validaConteudoData(pData.substr(0, 2), pData.substr(3, 2), pData.substr(6, 4)))
					{
						alert('Data inválida!');
						document.getElementById(pCampoData).style.backgroundColor = '#FFCC00';
						return false;
					}
					else
					{
						document.getElementById(pCampoData).style.backgroundColor = '';
						return true;
					}
				}
			}
		}
	}
}

function validaAno(pCampoAno)
{
	var pAno = document.getElementById(pCampoAno).value;
	var Data = new Date();
	var wAnoAtual = Math.abs(Data.getFullYear()) + 1;
		
	if (pAno == '')
	{
		if (document.getElementById(pCampoAno).getAttribute("req") == "S")
		{
			alert('Favor informar o Ano!');
			document.getElementById(pCampoAno).style.backgroundColor = '#FFCC00';
			return false;
		}
		else
		{
			document.getElementById(pCampoAno).style.backgroundColor = '';
			return true;
		}
	}
	else
	{
		if (isNaN(pAno))
		{
			alert('Ano deve ser numérico!');
			document.getElementById(pCampoAno).style.backgroundColor = '#FFCC00';
			return false;
		}
		else
		{
			if ((pAno < 1900) || (pAno > wAnoAtual))
			{
				alert('Ano deve estar entre 1900 e ' + wAnoAtual + '!');
				document.getElementById(pCampoAno).style.backgroundColor = '#FFCC00';
				return false;
			}
			else
			{
				document.getElementById(pCampoAno).style.backgroundColor = '';
				return true;
			}
		}
	}
}
	
function validaList(pCampoList)
{
	var pValor = document.getElementById(pCampoList).value;
			
	if (pValor == '') 
	{
		if (document.getElementById(pCampoList).getAttribute("req") == "S")
		{
			alert('Favor informar um item!');
			document.getElementById(pCampoList).style.backgroundColor = '#FFCC00';
			return false;
		}
		else
		{
			document.getElementById(pCampoList).style.backgroundColor = '';
			return true;
		}
	}
	else
	{
		document.getElementById(pCampoList).style.backgroundColor = '';
		return true;
	}
}

function validaInteiro(pCampoValor)
{
	var pValor = document.getElementById(pCampoValor).value.replace(',', '.');
			
	if (pValor == '')
	{
		if (document.getElementById(pCampoValor).getAttribute("req") == "S")
		{
			alert('Favor informar um valor!');
			document.getElementById(pCampoValor).style.backgroundColor = '#FFCC00';
			return false;
		}
		else
		{
			document.getElementById(pCampoValor).style.backgroundColor = '';
			return true;
		}
	}
	else
	{
		if (isNaN(pValor))
		{
			alert('Favor informar um número válido!');
			document.getElementById(pCampoValor).style.backgroundColor = '#FFCC00';
			return false;
		}
		else
		{
			if (Math.abs(pValor) != pValor)
			{
				alert('Favor informar um número positivo!');
				document.getElementById(pCampoValor).style.backgroundColor = '#FFCC00';
				return false;
			}
			else
			{
				if (Math.floor(pValor) != pValor)
				{
					alert('Favor informar um número inteiro!');
					document.getElementById(pCampoValor).style.backgroundColor = '#FFCC00';
					return false;
				}
				else
				{
					document.getElementById(pCampoValor).style.backgroundColor = '';
					return true;
				}
			}
					
		}
	}
}

function validaFloat(pCampoValor)
{
	var pValor = document.getElementById(pCampoValor).value.replace(',', '.');
			
	if (pValor == '')
	{
		if (document.getElementById(pCampoValor).getAttribute("req") == "S")
		{
			alert('Favor informar um valor!');
			document.getElementById(pCampoValor).style.backgroundColor = '#FFCC00';
			return false;
		}
		else
		{
			document.getElementById(pCampoValor).style.backgroundColor = '';
			return true;
		}
	}
	else
	{
		if (isNaN(pValor))
		{
			alert('Favor informar um número válido!');
			document.getElementById(pCampoValor).style.backgroundColor = '#FFCC00';
			return false;
		}
		else
		{
			if (Math.abs(pValor) != pValor)
			{
				alert('Favor informar um número positivo!');
				document.getElementById(pCampoValor).style.backgroundColor = '#FFCC00';
				return false;
			}
			else
			{
				document.getElementById(pCampoValor).style.backgroundColor = '';
				return true;
			}
		}
	}
}

	
function validaTexto(pCampoTexto)
{
	var pTexto = document.getElementById(pCampoTexto).value;
			
	if (pTexto == '') 
	{
		if (document.getElementById(pCampoTexto).getAttribute("req") == "S")
		{
			alert('Favor informar o conteúdo!');
			document.getElementById(pCampoTexto).style.backgroundColor = '#FFCC00';
			return false;

		}
		else
		{
			document.getElementById(pCampoTexto).style.backgroundColor = '';
			return true;
		}
	}
	else
	{
		document.getElementById(pCampoTexto).style.backgroundColor = '';
		return true;
	}
}

function validaFormatoEmail(pEmail)
{
	if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(pEmail))) 
	{
		return false;
	}
	else
	{
		return true;
	}
	
}

function validaEmail(pCampoEmail)
{
	var pEmail = document.getElementById(pCampoEmail).value;
			
	if (pEmail == '') 
	{
		if (document.getElementById(pCampoEmail).getAttribute("req") == "S")
		{
			alert('Favor informar o e-mail!');
			document.getElementById(pCampoEmail).style.backgroundColor = '#FFCC00';
			return false;

		}
	}
	else
	{
		if (!validaFormatoEmail(pEmail))
		{
			alert('Formato inválido para e-mail!');
			document.getElementById(pCampoEmail).style.backgroundColor = '#FFCC00';
			return false;
		}
		else
		{
			document.getElementById(pCampoEmail).style.backgroundColor = '';
			return true;
		}
	}
}

function validaFormatoCPF(pCPF)
{
	var POSICAO, I, SOMA, DV, DV_INFORMADO;
	var DIGITO = new Array(10);
	var TAMANHO = pCPF.length;
	
	for (I=1; I<=(11-TAMANHO); I++) 
	{
	  pCPF = "0" + pCPF;
	}
	
	DV_INFORMADO = parseInt(pCPF.substr(9, 2));

	for (I=0; I<=8; I++) 
	{
	  DIGITO[I] = pCPF.substr( I, 1);
	}

	POSICAO = 10;
	SOMA = 0;
	for (I=0; I<=8; I++) 
	{
	   SOMA = SOMA + DIGITO[I] * POSICAO;
	   POSICAO = POSICAO - 1;
	}
	DIGITO[9] = SOMA % 11;
	if (DIGITO[9] < 2) 
	{
	        DIGITO[9] = 0;
	}
	else
	{
	       DIGITO[9] = 11 - DIGITO[9];
	}

	POSICAO = 11;
	SOMA = 0;
	for (I=0; I<=9; I++) 
	{
	   SOMA = SOMA + DIGITO[I] * POSICAO;
	   POSICAO = POSICAO - 1;
	}
	DIGITO[10] = SOMA % 11;
	if (DIGITO[10] < 2) 
	{
	     DIGITO[10] = 0;
	}
	else 
	{
	     DIGITO[10] = 11 - DIGITO[10];
	}

	DV = DIGITO[9] * 10 + DIGITO[10];
	if (DV != DV_INFORMADO) 
	{
	   return false;
	}
	else
	{
		return true;
	}
}

function validaCPF(pCampoCPF)
{
	var pCPF = document.getElementById(pCampoCPF).value;
	
	var TAMANHO = pCPF.length;
			
	if (pCPF == '') 
	{
		if (document.getElementById(pCampoCPF).getAttribute("req") == "S")
		{
			alert('Favor informar o CPF!');
			document.getElementById(pCampoCPF).style.backgroundColor = '#FFCC00';
			return false;

		}
	}
	else
	{
		if (!validaFormatoCPF(pCPF))
		{
			alert('CPF inválido!');
			document.getElementById(pCampoCPF).style.backgroundColor = '#FFCC00';
			return false;
		}
		else
		{
			document.getElementById(pCampoCPF).style.backgroundColor = '';
			for (I=1; I<=(11-TAMANHO); I++) 
			{
			  pCPF = "0" + pCPF;
			}
			document.getElementById(pCampoCPF).value = pCPF;

			return true;
		}
	}
}

function validaDummy()
{
	return true;
}


function taLimit(taObj,taMaxL) 
{

	if (taObj.value.length==taMaxL) 
	{
		return false;
	}	
	return true;
}

function taCount(taObj,Cnt,taMaxL) 
{ 
	objCnt=createObject(Cnt);
	objVal=taObj.value;
	if (objVal.length>taMaxL) 
	{	objVal=objVal.substring(0,taMaxL);
	}
	if (objCnt) 
	{
		if(bName == "Netscape")
		{	
			objCnt.textContent=taMaxL-objVal.length;
		}
		else
		{
			objCnt.innerText=taMaxL-objVal.length;
		}
	}
	return true;
}
function createObject(objId) 
{
	if (document.getElementById) 
	{	
		return document.getElementById(objId);
	}
	else 
	{	
		if (document.layers) 
		{
			return eval("document." + objId);
		}
		else 
		{
			if (document.all) 
			{
				return eval("document.all." + objId);
			}
			else 
			{
				return eval("document." + objId);
			}
		}
	}
}

function impedirTeclas( e )
{
	var wTecla;
	var wKey;
	var wSimbolos

    if ( window.event ) 
    {
	e = window.event;
	wTecla = e.keyCode;
    }
    else
    {
	wTecla = e.which;
    }

    wKey = String.fromCharCode(wTecla);

    wSimbolos = "'";

    if ((wKey == '"') || (wSimbolos.indexOf(wKey) != -1))
    {
		// Firefox, ou DOM compliant browser
		if (e.preventDefault)
			e.preventDefault();
		// IE
		e.returnValue=false;
    }
}

function limitaTamanhoMax(pNomeCampo, pLabel, pTamanho, e)
{
	var wTecla;

    if ( window.event ) 
    {
		e = window.event;
		wTecla = e.keyCode;
	}
	else 
	{
		if (e == '') 
		{
		    wTecla = ""
		}
		else
		{
			wTecla = e.which;
		}
	}
	
    var wObj = document.getElementById(pNomeCampo);
    //alert(wTecla);

	if (wObj.value.length > (pTamanho - 1))
	{
		if ((wTecla == 8) || (wTecla == 0)) 
		{
		    return true;
		}
		else
		{
		    alert("O campo " + pLabel + " deve ter, no máximo, " + pTamanho + " caracteres!");
		    return false;		
		}
	}
	else
	{
		return true;
	}
}


function impedirTeclasSaida(pCampo)
{
    wCampo 		= pCampo.value;
    wCampoFinal 	= "";
    wSimbolos 	= "'";

	if (wCampo != undefined)
	{
		for (wI=0; wI<wCampo.length; wI++)
		{
			wCaracter = wCampo.substring(wI, wI+1);
	
			if ((wCaracter != '"') && (wSimbolos.indexOf(wCaracter) == -1))
			{
				wCampoFinal = wCampoFinal + wCaracter;
			}
		}
	    pCampo.value = wCampoFinal;
	}
	
}

function atualizaTotal(pCampo, pMaximo)
{
	var pNomeCampo = pCampo.name;
    var wObj = document.getElementById(pNomeCampo);
	document.getElementById("conta_" + pNomeCampo).innerHTML = pMaximo - wObj.value.length
}

function openAjax() 
{ 
	var ajax; 
	try 
	{
		ajax = new XMLHttpRequest();
	} // Para Firefox, Safari, dentre outros. 
	catch(ee) 
	{ 
		try 
		{
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		} // Para o IE da MS 
		catch(e) 
		{ 
			try 
			{
				ajax = new ActiveXObject("Microsoft.XMLHTTP");
			} // Para o IE da MS 
			catch(E) 
			{
				ajax = false;
			} 
		} 
	} 
	return ajax; 
}	

