var appVer = navigator.appVersion.toLowerCase();
var iePos  = appVer.indexOf('msie');
var ieVer = 0;
var podefscommand = "nao";
var iebug = false;

if (iePos !=-1) {
	ieVer = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)));
	if(ieVer < 7) iebug = true;
	if(ieVer > 5.5) podefscommand = "sim";
}

if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat') obody = document.documentElement;
else obody = document.body;
	
function form(campo){
	if(window.navigator.appName.toLowerCase().indexOf("microsoft") > -1){
		return document.formulario.item(campo);
	}
	else {
		return document.formulario[campo];
	}
}

function $(id)
{
	return document.all? document.all[id] : document.getElementById(id);
}

function soNumeros(obj) {

	tecla = event.keyCode;
	
	if(tecla == 8 || tecla == 9 || tecla == 46 || (tecla >= 37 && tecla <= 40) || (tecla >= 48 && tecla <= 57) || (tecla >= 96 && tecla <= 105) || tecla == 109 || tecla == 189){
		return true;
	}
	else return false;

}

function validaCPF(pcpf){

 if (pcpf.length != 11) {sim=false}
 else {sim=true}

  if (sim)
  {
  for (i=0;((i<=(pcpf.length-1))&& sim); i++)
  {
   val = pcpf.charAt(i)
   if((val!="9")&&(val!="0")&&(val!="1")&&(val!="2")&&(val!="3")&&(val!="4")&&(val!="5")&&(val!="6")&&(val!="7")&&(val!="8")) {sim=false}
   }

   if (sim)
  {
    soma = 0
    for (i=0;i<=8;i++)
    {
     val = eval(pcpf.charAt(i))
     soma = soma + (val*(i+1))
    }

    resto = soma % 11
    if (resto>9) dig = resto - 10;
    else  dig = resto;
    if (dig != eval(pcpf.charAt(9))) { sim=false }
   else
    {

     soma = 0
    for (i=0;i<=7;i++)
     {
     val = eval(pcpf.charAt(i+1))
      soma = soma + (val*(i+1))
    }

     soma = soma + (dig * 9)
    resto = soma % 11
     if (resto>9) dig = resto -10
     else  dig = resto
   if (dig != eval(pcpf.charAt(10))) { sim = false }
    else sim = true
   }
   }
  }

  if(sim){
	  if(pcpf=="11111111111"||pcpf=="22222222222"||pcpf=="33333333333"||pcpf=="44444444444"||pcpf=="55555555555"||pcpf=="66666666666"||pcpf=="77777777777"||pcpf=="88888888888"||pcpf=="99999999999"||pcpf=="00000000000") sim=false;
	  else sim=true;
  }
  
  if(sim) return true;
  else return false;

}
function validaCNPJ(pcgc){

 if (pcgc.length != 14) {
  sim=false;
  return false;
  }
 else {sim=true}

  if (sim)
  {
  for (i=0;((i<=(pcgc.length-1))&&sim); i++)
  {
   val = pcgc.charAt(i)

   if((val!="9")&&(val!="0")&&(val!="1")&&(val!="2")&&(val!="3")&&(val!="4")&&(val!="5")&&(val!="6")&&(val!="7")&&(val!="8")) {sim=false}
   }
   if (sim)
   {
    m2 = 2
    soma1 = 0
    soma2 = 0
    for (i=11;i>=0;i--)
    {
     val = eval(pcgc.charAt(i))

     m1 = m2
  if (m2<9) { m2 = m2+1}
  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}

    if ((d1==pcgc.charAt(12)) && (d2==pcgc.charAt(13)))
   { return true; }
   else return false;
   }
 }

}
function validaData(dia, mes, ano){
	if(parseInt(mes, 10)==2&&parseInt(dia, 10)==29) return (parseInt(ano, 10) % 4)? 0 : 1;
	else return (/^((0?[1-9]|[12]\d)\/(0?[1-9]|1[0-2])|30\/(0?[13-9]|1[0-2])|31\/(0?[13578]|1[02]))\/(19|20)?\d{2}$/.test(dia + "/" + mes + "/" + ano));
}

function pula(campo, pode){
	if(pode) form(campo).focus();
}

function validaEmail(email){
	return (/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/.test(email));
}

function validaNum(numero, quantidade){
	return (/^\d+$/.test(numero)&&numero.length>=quantidade);
}
function ValorRadio(radio){
	tempValorRadio = false;
	for(VR_x = 0; VR_x < radio.length; VR_x++){
		if(radio[VR_x].checked){ tempValorRadio = radio[VR_x].value; break; }
	}
	return tempValorRadio;
}

function MostraApaga(objeto, display){
	document.getElementById(objeto).style.display = display;
}

function enviar_pagina(){
	MostraApaga("enviar_pagina", "block");
}

function topo(){
	window.scrollTo(0,0);
}

function janela(url, W, H){
	try {
		jan = window.open(url, "", "width=" + W + ",height=" + H + ",left=" + ((screen.availWidth - W) / 2) + ",top=" + ((screen.availHeight - H) / 2));
		jan.focus();
	}
	catch(e){
		alert("Por favor desabilite seu anti-popup para visualizar este website.");
	}
}

function hotsite(idioma){
	janela("../../" + idioma, 650, 435)
}

function MostraEvento(id)
{
	Shadowbox.open({
			content:    '../eventos/eventos_pop.asp?id=' + id,
			player:     "iframe",
			title:      "",
			height:     280,
			width:      456
		});
}

function eventos_alertar_mostra(){
	MostraApaga("eventos_descricao","none");
	MostraApaga("eventos_alerta_data","block");
	document.getElementById("eventos_alerta").innerHTML = flash("../imagens/voltar.swf", "link=javascript:MostraEvento(" + document.form_eventos_alerta.eventoid.value + ");", 57, 24);
}



function contador(pagina){
	AjaxRequest.get({ "url" : "../../includes/contador.asp?pagina=" + pagina });
	urchinTracker(pagina);
}


if(podefscommand) document.write('<scr' + 'ipt for="menu_interna" event="FSCommand(funcao)">eval(funcao);</sc' + 'ript>');

function $(id){
	return document.all? document.all[id] : document.getElementById(id);
}

	
/*////////  FLASH   //////////// */

function flash(movie, flashvars, width, height, retorna){
	swfid = movie.split("/");
	swfid = swfid[swfid.length-1].replace(".swf", "");
	flashvars += "&podefscommand=" + podefscommand;
	if(podefscommand=="sim" && !retorna) document.write('<scr' + 'ipt for="' + swfid + '" event="FSCommand(funcao)">eval(funcao);</sc' + 'ript>');
	strSWF= '<object id="' + swfid + '" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="' + width + '" height="' + height + '">'+
			'<param name="movie" value="' + movie + '">'+
			'<param name="quality" value="high">'+
			'<param name="wmode" value="transparent">'+
			'<param name="scale" value="noborder">'+
			'<param name="salign" value="LT">'+
			'<param name="FlashVars" value="' + flashvars + '">'+
			'<embed name="' + swfid + '" src="' + movie + '" width="' + width + '" height="' + height + '" salign="LT" scale="noborder" flashvars="' + flashvars + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent"></embed>'+
			'</object>';
	if(!retorna) this.document.write(strSWF);
	else return(strSWF);
}

function TheFlash(moviename) {
    if(document.all) return document.all[moviename];
	else return document.embeds[moviename];
}

function limpaChar(oform){
	chars = String("8364,euro,8482,trade,8240,permil,8226,bull,8230,hellip,8242,prime,8243,Prime,8249,lsaquo,8250,rsaquo,8216,lsquo,8217,rsquo,8220,ldquo,8221,rdquo,8218,sbquo,8222,bdquo,8804,le,8805,ge,8211,ndash,8212,mdash,8254,oline,710,circ,732,tilde,8722,minus,8260,frasl,402,fnof,8747,int,8721,sum,8734,infin,8730,radic,8776,asymp,8800,ne,8801,equiv,8224,dagger,8225,Dagger,914,Beta,915,Gamma,916,Delta,917,Epsilon,918,Zeta,919,Eta,920,Theta,921,Iota,922,Kappa,923,Lambda,924,Mu,925,Nu,926,Xi,927,Omicron,928,Pi,929,Rho,931,Sigma,932,Tau,933,Upsilon,934,Phi,935,Chi,936,Psi,937,Omega,945,alpha,946,beta,947,gamma,948,delta,949,epsilon,950,zeta,951,eta,952,theta,953,iota,954,kappa,955,lambda,956,mu,957,nu,958,xi,959,omicron,960,pi,961,rho,962,sigmaf,963,sigma,964,tau,965,upsilon,966,phi,967,chi,968,psi,969,omega,8592,larr,8593,uarr,8594,rarr,8595,darr,8596,harr,9674,loz,9824,spades,9827,clubs,9829,hearts,9830,diams,8204,zwnj,8205,zwj,8206,lrm,8207,rlm").split(",");
	for(x = 0; x < oform.elements.length; x++){
		for(y = 0; y < chars.length; y++){
			oform.elements[x].value = oform.elements[x].value.replace(new RegExp(String.fromCharCode(chars[y]), "gi"), "&" + chars[y+1] + ";");
			y++;
		}
	}
}

function addEvent(obj, evType, fn, useCapture){
	if(obj.addEventListener){
		obj.addEventListener(evType, fn, useCapture);
		return true;
	} 
	else if (obj.attachEvent){
		var r = obj.attachEvent("on"+evType, fn);
		return r;
	}
}

String.prototype.htmlEntities = function()
{
  var chars = new Array ('&','à','á','â','ã','ä','å',
						 'æ','ç','è','é','ê','ë','ì','í',
						 'î','ï','ð','ñ','ò','ó','ô',
                         'õ','ö','ø','ù','ú','û',
						 'ü','ý','þ','ÿ','À','Á','Â',
						 'Ã','Ä','Å','Æ','Ç','È','É',
						 'Ê','Ë','Ì','Í','Î','Ï','Ð','Ñ',
						 'Ò','Ó','Ô','Õ','Ö','Ø','Ù',
						 'Ú','Û','Ü','Ý','Þ','€','ß',
                         '¢','£','¤','¥','¦','§','¨',
						 '©','ª','«','¬','­','®','¯','°','±',
						 '²','³','´','µ','¶','·','¸',
						 '¹','º','»','¼','½','¾','–');

  var entities = new Array ('amp','agrave','aacute','acirc','atilde','auml','aring',
                            'aelig','ccedil','egrave','eacute','ecirc','euml','igrave',
                            'iacute','icirc','iuml','eth','ntilde','ograve','oacute',
                            'ocirc','otilde','ouml','oslash','ugrave','uacute','ucirc',
                            'uuml','yacute','thorn','yuml','Agrave','Aacute','Acirc',
                            'Atilde','Auml','Aring','AElig','Ccedil','Egrave','Eacute',
                            'Ecirc','Euml','Igrave','Iacute','Icirc','Iuml','ETH','Ntilde',
                            'Ograve','Oacute','Ocirc','Otilde','Ouml','Oslash','Ugrave',
                            'Uacute','Ucirc','Uuml','Yacute','THORN','euro','szlig',
                            'cent','pound','curren','yen','brvbar','sect','uml',
                            'copy','ordf','laquo','not','shy','reg','macr','deg','plusmn',
                            'sup2','sup3','acute','micro','para','middot','cedil','sup1',
                            'ordm','raquo','frac14','frac12','frac34','ndash');

  newString = this;
  for (var i = 0; i < chars.length; i++)
  {
    myRegExp = new RegExp();
    myRegExp.compile(chars[i],'g')
    newString = newString.replace (myRegExp, '&' + entities[i] + ';');
  }
  return newString;
}


addEvent(window, "load", function(){
	try 
	{
		c = document.getElementById("conteudo");
		m = document.getElementById("div_menu");
		b = document.getElementById("banners_laterais");
		
		mbh = Math.max(Math.max(m.offsetHeight, 700), document.documentElement.clientHeight - 128);
		
		if(mbh > (c.offsetHeight + 204))
		{
			c.style.height = (mbh - (home=="sim"? 184 : 204)) + "px";
			b.style.height = (mbh - 184) + "px";			
		}
	} 
	catch(e){}
}, false);


function bannerSWF(id, swf){
	document.write(flash("../eventos/banners/banner_loader.swf", "banner=../eventos/banners/" + swf + "&bannerid=" + id, 1, 1));
}
function banner(id, swf, w, h){
	alert(id)
	document.getElementById(id).innerHTML = "<div style='background-color:#ffffff; width: " + w + "px; height: " + h + "px'>" + flash(swf, "", w, h) + "</div><BR>";
}

function chIEPNGfix()
{
	img = document.getElementsByTagName("img");
	
	for(x = 0; x < img.length; x++)
	{
			
		if(img[x].src.indexOf(".png") > 0)
		{
			img[x].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + img[x].src + "',sizingMethod='scale')";
			img[x].src = "../../imagens/px.gi";
		}
	}
}

