﻿/**
 * Acessibilidade Brasil - Fabio Issamu Oshiro
 * 28/2/2008
 * Modificado pela BRQ
 * 06/08/2011
 */

try{if(Logger){}}catch(e){ eval("Logger=function(){this.level;this.debug=function(v){};}");}

if(!pastaCss){
	alert('Não foi definido um caminho para as folhas de estilo!');
}
var wrapDefault = 770;
var a_css=new Array("estilo.css","estilop.css","estilob.css");
var a_css_t=new Array("normal","branco_e_preto_acessivel","preto_e_branco_acessivel");
var a_css_b=new Array("","fp","fb");
//var sizeDefault = 1;
var sizeDefault;
if(sizeDefault == null){
	sizeDefault = 0.7;
}

var idMenu = null;
var css_btn = null;
var cookie = null;
var wrapId = null;
var cookie_prefixo = "HoMe";
var id_closeMenu;
var selectVisible=true;
var logger = new Logger();
logger.level="DEBUG";
var DOM2=document.getElementById;
var valorinicial;
var valorminimozoommenos = 0.7;
var valormaximozoommais = 1.0999999999999999;

cookie = get_cookie("style");
var css_title = (cookie != "") ? cookie : getPreferredStyleSheet();
var i;
for (i=0;i<a_css.length;i++){
	if (css_title==a_css_t[i] || css_title=="" || css_title==null){
		css_btn=a_css_b[i];
		css_title=a_css_t[i];
		dw('<link rel="stylesheet" type="text/css" href="'+pastaCss+'/'+a_css[i]+'" media="screen" title="'+a_css_t[i]+'" />');
	}else{
		dw('<link rel="alternate stylesheet" type="text/css" href="'+pastaCss+'/'+a_css[i]+'" media="screen, projection" title="'+a_css_t[i]+'" />');
	}
}

function setBannerFlash(css_title){
	try{
	if(css_title == "normal"){
		document.getElementById("banner-home-flash").style.display = "block";
		document.getElementById("banner-home-flash-preto").style.display = "none";
		document.getElementById("banner-home-flash-branco").style.display = "none";
	}else if(css_title == "branco_e_preto_acessivel"){
		document.getElementById("banner-home-flash-preto").style.display = "block";
		document.getElementById("banner-home-flash").style.display = "none";
		document.getElementById("banner-home-flash-branco").style.display = "none";	
	}else if(css_title == "preto_e_branco_acessivel"){
		document.getElementById("banner-home-flash-branco").style.display = "block";
		document.getElementById("banner-home-flash").style.display = "none";
		document.getElementById("banner-home-flash-preto").style.display = "none";
	}
	}catch(e){
		alert(e);
	}
}

function setBannerFlash(){
	cookie = get_cookie("style");
	var css_title = (cookie != "") ? cookie : getPreferredStyleSheet();
	try{
	if(css_title == "normal"){
		document.getElementById("banner-home-flash").style.display = "block";
		document.getElementById("banner-home-flash-preto").style.display = "none";
		document.getElementById("banner-home-flash-branco").style.display = "none";
	}else if(css_title == "branco_e_preto_acessivel"){
		document.getElementById("banner-home-flash-preto").style.display = "block";
		document.getElementById("banner-home-flash").style.display = "none";
		document.getElementById("banner-home-flash-branco").style.display = "none";	
	}else if(css_title == "preto_e_branco_acessivel"){
		document.getElementById("banner-home-flash-branco").style.display = "block";
		document.getElementById("banner-home-flash").style.display = "none";
		document.getElementById("banner-home-flash-preto").style.display = "none";
	}
	}catch(e){
	}
}


// Menu Drop Down Acessível
// Alexandre Junqueira
// cont...@alexandrejunqueira.com
// http://www.alexandrejunqueira.com/projetos/menu-drop-down-acessivel/
var dropdown_intervalId;
var dropdown_ulId = (!dropdown_ulId) ? 'menu-principal' : dropdown_ulId;
var dropdown_delay = (!dropdown_delay) ? 0 : dropdown_delay;

function dropdown_init()
{
 try
 {
  var as = document.getElementById(dropdown_ulId).getElementsByTagName('a');

  for (var a = 0; a < as.length; a++)
  {
   as[a].onfocus = function() { dropdown_expand(this) }
   as[a].onmouseover = function() { dropdown_expand(this) }
   as[a].onblur = function() { dropdown_colapse(dropdown_delay) }
   as[a].onmouseout = function() { dropdown_colapse(dropdown_delay) }
  }

  dropdown_colapse(0);

 } catch(e){}

}

function dropdown_expand(caller)
{
 try
 {
  clearInterval(dropdown_intervalId);

  var uls = caller.parentNode.parentNode.getElementsByTagName('ul');

  for (var ul = 0; ul < uls.length; ul++)
   uls[ul].style.left = "-1000em";

  caller.parentNode.getElementsByTagName('ul')[0].style.left = "auto";

 } catch(e){}

}

function dropdown_colapse(milliseconds)
{
 try
 {
  clearInterval(dropdown_intervalId);

  dropdown_intervalId = setInterval(function()
  {    
   var uls = document.getElementById(dropdown_ulId).getElementsByTagName('ul');

   for (var ul = 0; ul < uls.length; ul++)
    uls[ul].style.left = "-1000em";

   clearInterval(dropdown_intervalId);

  }, milliseconds, null);

 } catch(e){}

}

window.onload = dropdown_init;


//iniFull(null);

/*function acessibilidadeInit(pastaCss2,wrapDefault2,aCss2,sizeDefault2,idMenu2,wrapId2,cook_pref){
	pastaCss = pastaCss2;
	wrapDefault = wrapDefault2;
	a_css = aCss2;
	sizeDefault = sizeDefault2;
	idMenu = idMenu2;
	logger.debug("cook_pref='"+cook_pref+"'");
	if(cook_pref){
		cookie_prefixo = cook_pref;
	}
	cookie = get_cookie("style");
	var css_title = (cookie != "") ? cookie : getPreferredStyleSheet();
	var i;
	for (i=0;i<a_css.length;i++){
		if (css_title==a_css_t[i] || css_title=="" || css_title==null){
			css_btn=a_css_b[i];
			css_title=a_css_t[i];
			dw('<link rel="stylesheet" type="text/css" href="'+pastaCss+'/'+a_css[i]+'" media="screen" title="'+a_css_t[i]+'" />');
		}else{
			dw('<link rel="alternate stylesheet" type="text/css" href="'+pastaCss+'/'+a_css[i]+'" media="screen, projection" title="'+a_css_t[i]+'" />');
		}
	}
	if(wrapId2){
		wrapId = wrapId2;
	}
	if(wrapId2=="N/A"){
		wrapId=null;
	}
	iniFull(wrapId);
}*/
function makeLink(u,l){
	document.write('<a href="'+u+'">'+l+'</a>');
}

function selectHidden(){
	if(selectVisible){
		var sels=document.getElementsByTagName("select");
		for(var i=0;sels[i];i++){
			sels[i].style.visibility="hidden";
		}
		selectVisible=false;
	}
}
function selectShow(){
	if(!selectVisible){
		var sels=document.getElementsByTagName("select");
		for(var i=0;sels[i];i++){
			sels[i].style.visibility="visible";
		}
		selectVisible=true;
	}
}
function closeSub(v){
	var p=v.parentNode.parentNode;
	var uls = p.getElementsByTagName("ul");
	for( var x = 0; uls[x]; x++ ){
		uls[x].style.visibility="hidden";
		uls[x].style.display="none";
	}
}

function openMenu(){
	selectHidden();
	if (id_closeMenu!=null && id_closeMenu!=undefined){
		clearTimeout(id_closeMenu);
	}
	closeSub(this);
	var p=this.parentNode;
	for( var x = 0; p.childNodes[x]; x++ ){
		if(p.childNodes[x].nodeType ==1 && p.childNodes[x].tagName!="SCRIPT"){
			p.childNodes[x].style.display="block";
			p.childNodes[x].style.visibility="visible";
		}
	}
	// ini IE6 bug
	for( var x = 0; p.childNodes[x]; x++ ){
		if(p.childNodes[x].nodeType ==1){
			var uls=p.childNodes[x].getElementsByTagName("ul");
			for(var j=0;uls[j];j++){
				uls[j].style.visibility = "visible";
				uls[j].style.display = "block";
				uls[j].style.visibility = "hidden";
				uls[j].style.display = "none";
			}
		}
	}// fim IE6 bug
}




   function CVabre(v){
	   var op = MM_findObj(v+"_open");
	   var cl = MM_findObj(v+"_close");
	   if (op.style.display=="none"){
			op.style.display="";
			cl.style.display="none";
	   }else{
			op.style.display="none";
			cl.style.display="";
	   }
   }

/**
* Script que gerencia cookies.
*/

/** Funcao que recupera valores no cookie */
function get_cookie(nome) {
   var search = cookie_prefixo + nome + "=";
   var returnvalue = "";
   if (document.cookie.length > 0) {
	   var cookieStr = document.cookie + "";
       offset = cookieStr.indexOf(search);
       if (offset != -1) {
           offset += search.length;
           end = cookieStr.indexOf(";", offset);
           if (end == -1) {
			   end = document.cookie.length;
		   }
           returnvalue = unescape(cookieStr.substring(offset, end));
      }
   }
   logger.debug(nome+"="+returnvalue);
   return returnvalue;
}

/** Funcao que armazena valores no cookie */
function set_cookie(nome, valor) {
	logger.debug("set_cookie("+nome+","+valor+")");
  	var date = new Date();
  	date.setTime(date.getTime() + 2592000000/*3600000*/);
  	document.cookie = cookie_prefixo+nome + "=" + valor + ";expires=" + date.toGMTString();
}

function clearDefault(el,ini) {
  if (ini==el.value) el.value = "";
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_setTextOfLayer(objName,x,newText) { //v4.01
  if ((obj=MM_findObj(objName))!=null) with (obj)
    if (document.layers) {document.write(unescape(newText)); document.close();}
    else innerHTML = unescape(newText);
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; 
  document.MM_sr=new Array; 
  for(i=0;i<(a.length-2);i+=3){
	  if(a[i] != null){
		  if ((x=MM_findObj(a[i]))!=null){
			   document.MM_sr[j++]=x; 
			   if(!x.oSrc) {
				   x.oSrc=x.src; 
			   }		   
			   x.src=a[i+2];
		   }
	  }
	   
  }
}




function zoom(v){

	if (v.indexOf('mais')==0 && valorinicial != valormaximozoommais){
		valorinicial=valorinicial+0.1;
	}
	if (v.indexOf('menos')==0 && valorinicial != valorminimozoommenos){
		valorinicial=valorinicial-0.1;
	}
	if (v.indexOf('padrao')==0){
		// verificar se o zoom j� est� como default
		if (valorinicial==sizeDefault){
			// j� est� com 1, ver o estilo de cor
			var title=get_cookie("style");
			if (title!="normal"){
				// mudar os estilos para o normal
				setActiveStyleSheet("normal");
			}
		}else{
			// mudar primeiro o zoom
			valorinicial=sizeDefault;
		}
	}
	if (DOM2){
		mudarTamanho(valorinicial);
		set_cookie("mudaL",valorinicial);
	}
}
function initzoom(valor){
	logger.debug("initzoom("+valor+")");
	var v=get_cookie("mudaL");
	if(v){
		if (v!="" && v!="NaN" && v!=null){
			valor=v*1;
		}
	}
	mudarTamanho(valor);
	valorinicial = valor;
	if(css_btn!="")MM_swapImage(css_btn,'','fc.gif',1);
	MM_preloadImages('fc.gif');	
}

function elemento(elemento , valor){
	try{
		if (DOM2){
			document.getElementById(elemento).style.fontSize=valor+"em";
		}
	}catch(e){
	}
}
function FontTag(v,valor){
	var arr=document.getElementsByTagName(v);
	var i;
	for(i=0;i<arr.length;i++){
		arr[i].style.fontSize=valor+"em";
	}
}
function mudarTamanho(valor){
	if (DOM2){
		// elemento("borda_c" , (valor));
		FontTag("body",valor);
		try{
			if(fontSizeListener!=undefined){
				fontSizeListener.mudou(valor);
			}
		}catch(e){}
			
		// parabola cresce depois diminui :-)
		// FontTag("h3",(valor*3)+0.15-(valor*valor+1));
	 }
}

function dinamico(node,bg,color){
	var i,child = node.childNodes;
    for(i=0;i<child.length;i++){
    	try{
    		child[i].style.background=bg;
    		child[i].style.color=color;
    	}catch(e){
    	
    	}
    	dinamico(child[i],bg,color);
    }
}
/**
 * Script que troca o estilo do site.
 */
function setActiveStyleSheet(title) {
    var i;
     /*if (title==get_cookie("style")){
		title="normal";
    }*/
    
   var CSSs=document.getElementsByTagName("link");
	
	
    for (i=0; i<CSSs.length; i++) {
	CSSs[i].disabled = true;
    	//if(CSSs[i].getAttribute("title")){
    		if (CSSs[i].getAttribute("title") == title) {
    			CSSs[i].disabled = false;
    			set_cookie("style", title);
    			//break;
    		}
    	//}
    }
	for (i=0;i<a_css.length;i++){
		if (title==a_css_t[i] && title!="normal" && title!=null){
			MM_swapImage(a_css_b[i],'','include/script/fc.gif',1);
		}else if(a_css_b[i]!=""){
			MM_swapImage(a_css_b[i],'','' + a_css_b[i] + '.gif',1);
		}
	}
	/*if(document.all){//IE bug
		setTimeout("document.location.href=document.location.href",250);
	}*/
	setBannerFlash(title);
}

function setFull(){
	try{
		var el=document.getElementById(wrapId);
		if(document.all){
			if(el.style.width!="100%" && get_cookie("size"+wrapId)!="100%"){
				set_cookie("size"+wrapId,"100%");
			}else{
				var val=get_cookie("Osz"+wrapId);
				if(val){
					if (val!="" && val!=null){
						set_cookie("size"+wrapId,val);
					}
				}
			}
			setTimeout("document.location.href=document.location.href",250);
		}else{
			if(el.style.width!="100%" && get_cookie("size"+wrapId)!="100%"){
				set_cookie("size"+wrapId,"100%");
				el.style.width="100%";
			}else{
				var val=get_cookie("Osz"+wrapId);
				if(val){
					if (val!="" && val!=null){
						set_cookie("size"+wrapId,val);
						el.style.width=val;
					}
				}
			}
		}
	}catch(e){
		alert("wrapId " + wrapId + "\n"+ e);
	}
}

/* Define recupera o estilo ativo */
function getActiveStyleSheet() {
    var i, a;
    for (i=0; (a = document.getElementsByTagName("link")[i]); i++) {
        if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) {
			return a.getAttribute("title");
		}
    }
    return null;
}

/* Recupera o estilo default */
function getPreferredStyleSheet() {
    var i, a;
    for (i=0; (a = document.getElementsByTagName("link")[i]); i++) {
        if (a.getAttribute("rel").indexOf("style") != -1
            && a.getAttribute("rel").indexOf("alt") == -1
            && a.getAttribute("title")) {
		    return a.getAttribute("title");
	    }
    }
    return null;
}

function dw(v){
	document.write(v);
}

function iniFull(v){
	try{
		if(v==null) return;
		var Osz = 776;
		if(wrapDefault){
			Osz = wrapDefault;
		}else{//quando nao ha default definido
			if(screen.width>810) Osz = 990;
		}
		set_cookie("Osz"+v,Osz+"px");
		var val=get_cookie("size"+v);
		if(val){
			if (val!="" && val !=null){
				dw("<style type=\"text/css\">#"+v+"{width:"+val+"}</style>");
			}else{
				dw("<style type=\"text/css\">#"+v+"{width:"+Osz+"px}</style>");
			}
		}
	}catch(e){
		alert(e.message);
	}
}

function acbrPageLoad(){
	initzoom(sizeDefault);
}

function criarBtnZoom(pastaCss){
	var btns="<a href=\"javascript:zoom('mais');\"><img src=\""+ pastaCss + "/include/script/Amais.gif\" alt=\"Aumenta o texto\" border=\"0\"/></a> ";
	btns+=" <a href=\"javascript:zoom('menos');\"><img src=\""+ pastaCss + "/include/script/Amenos.gif\" alt=\"Diminui o texto\" border=\"0\"/></a>";
	btns+=" <a href=\"javascript:zoom('padrao');\"><img src=\""+ pastaCss + "/include/script/Anormal.gif\" alt=\"Texto Normal\" border=\"0\"/></a>";
	btns+=" <a href=\"javascript:setActiveStyleSheet('branco_e_preto_acessivel');\"><img id=\"Obp\" src=\""+ pastaCss + "/include/script/Obp.gif\" alt=\"Auto-Contraste 1\" border=\"0\"/></a>";
	btns+=" <a href=\"javascript:setActiveStyleSheet('preto_e_branco_acessivel');\"><img id=\"Opb\" src=\""+ pastaCss + "/include/script/Opb.gif\" alt=\"Auto-Contraste 2\" border=\"0\"/></a>";
	if(wrapId!=null){
		if(get_cookie("sizewrap") && get_cookie("sizewrap")!="100%")
			btns+=" <a href=\"#\" onkeypress=\"void(0);\" onclick=\"setFull();return false;\"><img id=\"include/script/Ofull\" src=\"full.gif\" alt=\"Expandir a tela\"border=\"0\" /></a>";
		else
			btns+=" <a href=\"#\" onkeypress=\"void(0);\" onclick=\"setFull();return false;\"><img id=\"include/script/Ofull\" src=\"full.gif\" alt=\"Diminuir a tela\"border=\"0\" /></a>";
	}
	dw(btns);
}
try{
	document.captureEvents(Event.KEYDOWN);
}catch(e){
}



function verificaEstado(f){
	var estados = document.getElementById("bloco_estado");
	if(f.value!=1){
		estados.style.display="none";
	}else{
		estados.style.display="";
	}
}

function addFuncOnLoad(novaFuncao) {
	var onloadAntigo = window.onload;
	if (typeof onloadAntigo != 'function') {
		window.onload = novaFuncao;
		//window.onload = function() {acbrPageLoad()};
	} else {
		window.onload = function() {
			if (onloadAntigo) {
				onloadAntigo();
			}
			novaFuncao();
			//function() {acbrPageLoad()};
		}
	}
	
	//Validar se eh chamado acbrPageLoad();
}


addFuncOnLoad(function() {acbrPageLoad()});

