// Início do código de Aumentar/ Diminuir a letra
 
function menu_onchange( el ) {
	var opt = el.options[el.selectedIndex];
	if ( opt.value == '#' ) {
		return;
	}
	document.location = opt.value;
}

function menu( el ) {
	el.blur();
	var pa = el.parentNode;
	if ( pa.className.indexOf("expand") != -1 ) {
		pa.className = "colapse";
	} else {
		pa.className = "expand";
	}
	var submenu = pa.nextSibling;
	if ( submenu.nodeType != 1 ) {
		submenu = submenu.nextSibling;
	}
	if ( submenu.className.indexOf("submenu") == -1 ) {
		return;
	}
	submenu.style.display = ( pa.className.indexOf("expand") != -1 )?'none':'';
}

function abre(newwindow) {
	var desktop = window.open(newwindow,'new_window','toolbar=yes,location=yes,directories=yes,status=yes,scrollbars=yes,menubar=yes,resizable=yes');
}

function check_form_email( f ) {
	return false;
}

var Email = {
	//seta-caixa-email.gif
	open:function( el, endereco ) {
		this.endereco = endereco;
		var a = new Element(el);
		this._top = a.getTop();
		this._left = a.getLeft();
		
		var el = document.getElementById('enviar-email');
		//console.debug(el);
		if ( el == null ) {
			new Ajax('/opencms/opencms/enviar_email.jsp', {onComplete:this.onLoad.bind(this)}).request();
		}
	},
	onLoad:function( el ) {
		var d = new Element('div');
		d.innerHTML = el
		var wnd = new Element(d.firstChild);
		var fx = new Fx.Opacity(wnd, {});
		wnd.setOpacity(0);
		document.body.appendChild(wnd);
		wnd.style.left = (this._left - wnd.offsetWidth - 10) + 'px';
		wnd.style.top = (this._top - 100) + 'px';
		var s = document.getElementById('setinha');
		//s.style.left = (this._left - 5 ) + 'px';
		//s.style.top = (this._top - 5 ) + 'px';
//		alert(wnd.offsetWidth);
		fx.custom(0, 1);
		delete d;
		
		var f = new Element($('enviar_amigo'));
		f.endereco.value = this.endereco;
		
		f.toemail.onblur = function() {
			if ( this.value.length == 0 || !Email.isValidEmail(this.value) ) {
				Email.setErro(this.name);
			} else {
				Email.setOk(this.name);
			}
		}
		f.seuemail.onblur = f.toemail.onblur;
		
		f.nome.onblur = function() {
			if ( this.value.length == 0  ) {
				Email.setErro(this.name);
			} else {
				Email.setOk(this.name);
			}
		}		
		f.mensagem.onblur = f.nome.onblur;
						
		
	},
	isValidEmail:function() {
		return true;
	},
	setErro:function( el ) {
		this.setNone(el);
		$(el).addClassName('erro');
	},
	setOk:function( el ) {
		this.setNone(el);
		$(el).addClassName('ok');
	},
	setNone:function( el ) {
		$(el).removeClassName('ok');
		$(el).removeClassName('erro');
	},
	close:function() {
		new Fx.Opacity('enviar-email', {onComplete:this.onClose.bind(this)}).custom(1,0);
	},
	onClose:function() {
		new Element($('enviar-email')).remove();
	},
	send:function( el ) {
		var f = new Element(el);

		if ( f.toemail.value.length == 0 || !this.isValidEmail(f.toemail.value) ) {
			f.toemail.focus();
			Email.setErro('toemail');			
			return false;
		} else if ( f.nome.value.length == 0 ) {
			f.nome.focus();
			Email.setErro('nome');
			return false;		
		} else if ( f.seuemail.value.length == 0  || !this.isValidEmail(f.seuemail.value) ) {
			f.seuemail.focus();
			Email.setErro('seuemail');
			return false;
		} else if ( f.mensagem.value.length == 0 ) {
			f.mensagem.focus();
			Email.setErro('mensagem');			
			return false;
		}		
		new Fx.Opacity('email-conteudo', {}).custom(1,0.3);
		setTimeout(this.onTimeout.bind(this), 1000);
	},
	onTimeout:function() {
		var f = new Element($('enviar_amigo'));
		f.send({onComplete:this.onSendCallback.bind(this)});
	},
	onSendCallback:function() {
		new Fx.Opacity('email-conteudo', {onComplete:this.showSucesso.bind(this)}).custom(0.3, 1);
	},
	showSucesso:function() {
		if ( parseInt($('email-sucesso').style.height) == 0 ) {
			new Fx.Height('email-sucesso', {}).toggle();
		}
		this.setNone('toemail');
		var f = new Element($('enviar_amigo'));
		f.toemail.value = '';
		f.toemail.focus();				
	}
};

var Ac = {
	size:16,
	letraMaior:function() {
		if ( this.size < 20 ) {
			this.size++;
createCookie("fs", this.size, 365);
			document.body.style.fontSize = this.size+'px';
		}
	},
	letraMenor:function() {
		if ( this.size > 11 ) {
			this.size--;
createCookie("fs", this.size, 365);
			document.body.style.fontSize = this.size+'px';
		}
	},
	contraste:function() {
		setActiveStyleSheet('Acessível')
	},
	normal:function() {
		setActiveStyleSheet('Padrão');

	},
	impressao:function() {
		setActiveStyleSheet('Impressão');
		var print = document.getElementById("print_preview_aviso");
		if ( print != null ) {
			print.innerHTML = "";
			var aviso = document.createElement("div");
			aviso.className = "aviso";
			var strong = document.createElement("strong");
			strong.appendChild(document.createTextNode("Atenção, esta é uma versão para impressão da página que você estava."));
			aviso.appendChild(strong);
			aviso.appendChild(document.createElement("br"));
			aviso.appendChild(document.createTextNode("O que será impresso é o documento a partir do tracejado abaixo."));
			aviso.appendChild(document.createElement("br"));
			var a = document.createElement("a");
			a.appendChild(document.createTextNode("Após a impressão, clique aqui para voltar a página anterior."));
			a.onclick = function(){setActiveStyleSheet('Padrão'); this.parentNode.parentNode.removeChild(this.parentNode); return false;};
			a.href = "javascript:;";
			aviso.appendChild(a);
			print.appendChild(aviso);
			print.appendChild(document.createElement("hr"));
var img = document.createElement("img");
img.src = "/opencms/export/system/modules/br.gov.capes.portal/resources/logo_print.gif";
document.getElementById("logo_print").appendChild(img);

		}
	}

}


function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

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;
}

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 createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

function goanchor(an) {document.location = (document.location+"").split("#")[0]+"#"+an;}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
/*
shortcut("Alt+A",function() {Ac.letraMaior();});
shortcut("Alt+D",function() {Ac.letraMenor();});
shortcut("Alt+I",function() {goanchor("inicio");});
shortcut("Alt+M",function() {goanchor("menu");});
shortcut("Alt+C",function() {goanchor("conteudo");});
shortcut("Alt+F",function() {goanchor("rodape");});
*/

  var fs = readCookie("fs");
  if ( !isNaN(parseInt(fs)) ) {
    document.body.style.fontSize = parseInt(fs)+"px";
    Ac.size = parseInt(fs);
  }
}


if ( document.body ) {
  var fs = readCookie("fs");
  if ( !isNaN(parseInt(fs)) ) {
    document.body.style.fontSize = parseInt(fs)+"px";
    Ac.size = parseInt(fs);
  }
}



window.onunload = function(e) {
  var title = getActiveStyleSheet();
  if (title != 'Impressão') {
	  createCookie("style", title, 365);
  }
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

// Fim do código de Aumentar/ Diminuir a letra



window.onunload = function(e) {
  var title = getActiveStyleSheet();
  if (title != 'Impressão') {
	  createCookie("style", title, 365);
  }
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);


function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function nova_jan(newwindow)
{
  var desktop = window.open(newwindow,'new_window','toolbar=yes,location=yes,directories=yes,status=yes,scrollbars=yes,menubar=yes,resizable=yes');
}
function imgChange( id, img ) { window.document.all(id).src = img; } 


