// JavaScript Document

/*******************
Funções de cookies recicladas de várias fontes, principalmente
dyn-web.com
*********************/
function setCookie(name,value,days,path,domain,secure) {
  var expires, date;
  if (typeof days == "number") {
    date = new Date();
    date.setTime( date.getTime() + (days*24*60*60*1000) );
		expires = date.toGMTString();
  }
  document.cookie = name + "=" + escape(value) +
    ((expires) ? "; expires=" + expires : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}


function getCookie(name) {
  var nameq = name + "=";
  var c_ar = document.cookie.split(';');
  for (var i=0; i<c_ar.length; i++) {
    var c = c_ar[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameq) == 0) return unescape( c.substring(nameq.length, c.length) );
  }
  return null;
}

function deleteCookie(name,path,domain) {
  if ( getCookie(name) ) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}


/*** FUNCOES DE CONTROLE DE TAMANHO DE FONTE ***/

var min=10;
var max=18;
var default_size = 12;
																		
function changeFontSize(option, e) {
	var p = document.getElementsByTagName('body')[0];
	
	var tecla = window.event ? e.keyCode : e.which;
	
	if (e.type == "keypress" && tecla == 13) return false;
	if (e.type == "keypress" && tecla == 0) return false;
	
	if(p.style.fontSize) {
		var s = parseInt(p.style.fontSize.replace("px",""));
	}else{
		var s = default_size;
	}
	
	if (!option){
		if(s != max){
			s += 1;
		}
	}else{
		if(s != min){
			s -= 1;
		}
	}
	p.style.fontSize = s + "px";
	
	setCookie("fontSize", s, 1, "/");
}

function restoreFontSize(fontSize) {
	var p = document.getElementsByTagName('body')[0];
	if (fontSize == ""){
		fontSize = default_size;
		deleteCookie("fontSize", "/");
	}
	
	p.style.fontSize = fontSize + "px";
}





/*****  FUNCOES DE MUDANCA DE ESTILO *************************************************
do site da Fundação Oswaldo Cruz
*/

	var DOM2=document.getElementById
	var valorinicial;

	function mudaContraste(estilo){
		document.getElementsByTagName('body')[0].className=estilo;
		//alert(document.getElementsByTagName('body')[0].className);
		setCookie("estilo", estilo, 1, "/");
	}
	
	function restoreContraste(estilo) {
		var p = document.getElementsByTagName('body')[0];
		if (estilo == ""){
			estilo = '';
			deleteCookie("estilo", "/");
		}
	
		p.className = estilo;
	}
	
	function initzoom(valor){
		mudarTamanho(valor);
		valorinicial = valor;
	}

	function mudarTamanho(valor){
	
		 if (DOM2){
			document.getElementsByTagName('body')[0].style.fontSize=valor+"px";
			}
	}


	
/*****  FUNCOES DE MUDANCA DO TEXTO DA ACESSIBILIDADE **************************************************/

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);

}

