// JavaScript Document

/* IE6 fix: background image flickering */
try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}

Event.observe('nome_news', 'focus', function(event){ $('nome_news').value = ''; });
Event.observe('email_news', 'focus', function(event){ $('email_news').value = ''; });

Event.observe('altocontraste', 'click', function(event){ toggleCSS(); return false; });
Event.observe('adicionarfavoritos', 'click', function(event){ addBookmark('INR','http://www.inr.pt'); });
Event.observe('definirpaginainicial', 'click', function(event){ setHomepage(); });
Event.observe('tamanholetra', 'click', function(event){ toogleSize(); return false; });
//($('versaoimpressora') != null)? Event.observe('versaoimpressora', 'click', function(event){ return openPopup('versaoimpressora','width=600,height=480'); }) : false;
//($('recomendaramigo') != null)? Event.observe('recomendaramigo', 'click', function(event){ openPopup('recomendaramigo','width=500,height=400'); return false; }) : false;
//($('readspeaker') != null)? Event.observe('readspeaker', 'click', function(event){ return openPopup('readspeaker','width=200,height=200'); }) : false;


function addBookmark (title, url) {
if (document.all) window.external.AddFavorite(url, title);
else if (window.sidebar) window.sidebar.addPanel(title, url, "")
 }
 
function setHomepage () {

  if (document.all)
    {
     document.body.style.behavior='url(#default#homepage)';
     document.body.setHomePage('http://www.inr.pt');

    }
    else if (window.sidebar)
     {
         if(window.netscape)
         {
          try
          {
          netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
          }
       catch(e)
      {
    alert("Esta funcionalidade está desactivada no seu browser. Se a quiser activar, escreva about:config na barra de endereços e altere o valor de signed.applets.codebase_principal_support para verdadeiro");
}
}
var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
prefs.setCharPref('browser.startup.homepage','http://www.inr.pt');
}

}

function toogleSize () {	
 if (document.body.style.fontSize == '135%') {	
 document.body.style.fontSize = '100%';
 } else {
 document.body.style.fontSize = '135%'; 
 }
}

function openPopup (id, popoptions) {
 url    = document.getElementById(id).getAttribute('href');
 target = id+'_popup';
 var nw = window.open(url, target, popoptions+',scrollbars=yes,resizable=yes,status=yes');
 if (nw) { return false; }
 return false;
}

function printVersion () {
 url    = document.getElementById("versaoimpressora").getAttribute('href');
 target = 'versaoimpressora_popup';
 var nw = window.open(url, target, 'width=600,height=480,scrollbars=yes,resizable=yes,status=yes');
 if (nw) { return false; } 
}

function sendFriend () {
 url    = document.getElementById("recomendaramigo").getAttribute('href');
 target = 'recomendaramigo_popup';
 var nw = window.open(url, target, 'width=500,height=400,scrollbars=yes,resizable=yes,status=yes');
 if (nw) { return false; } 
}

function toggleCSS () {

	var url  = '/includes/ajax_changestyle.inc.php';
	
	var myAjax = new Ajax.Request(
			url, 
			{
				method: 'post', 
				onSuccess: function (res) {
				 var sURL = unescape(window.location.pathname);	
				 if (sURL.length == 1) { sURL = '/content/1/1/bemvindo'; }
                 window.location.replace( sURL );
				 },
				onFailure: reportError
			});	
  
}
function reportError () { alert('error.'); }

/* rel="external" para validação W3C
function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
} 
*/

// syntax: rel="popup type width height noicon" para abrir popup
//         rel="external" para abrir em nova janela
var newWindow = null;
function closeWin(){
	if (newWindow != null){
		if(!newWindow.closed)
			newWindow.close();
	}
}

function popUpWin(url, type, strWidth, strHeight){
	closeWin();
		
	type = type.toLowerCase();
	
	if (type == "fullscreen"){
		strWidth = screen.availWidth;
		strHeight = screen.availHeight;
	}
	var tools="";
	if (type == "standard") tools = "resizable,toolbar=yes,location=yes,scrollbars=yes,menubar=yes,width="+strWidth+",height="+strHeight+",top=0,left=0";
	if (type == "console" || type == "fullscreen") tools = "resizable,toolbar=no,location=no,scrollbars=no,width="+strWidth+",height="+strHeight+",left=0,top=0";
	newWindow = window.open(url, 'newWin', tools);
	newWindow.focus();
}
function doPopUp(e)
{
//set defaults - if nothing in rel attrib, these will be used
var t = "standard";
var w = "600";
var h = "480";
//look for parameters
attribs = this.rel.split(" ");
if (attribs[1]!=null) {t = attribs[1];}
if (attribs[2]!=null) {w = attribs[2];}
if (attribs[3]!=null) {h = attribs[3];}
//call the popup script
popUpWin(this.href,t,w,h);
//cancel the default link action if pop-up activated
if (window.event) 
	{
	window.event.returnValue = false;
	window.event.cancelBubble = true;
	} 
else if (e) 
	{
	e.stopPropagation();
	e.preventDefault();
	}
}
function findPopUps() {
var popups = document.getElementsByTagName("a");
for (i=0;i<popups.length;i++)
 {
 if (popups[i].rel.indexOf("popup")!=-1) {
  // attach popup behaviour
  popups[i].onclick = doPopUp;
  // add popup indicator

/*
  if (popups[i].rel.indexOf("noicon")==-1)
  //more of the 'no icon' thing in a moment ...
   {
   popups[i].style.backgroundImage = "url(pop-up.gif)";
   popups[i].style.backgroundPosition = "0 center";
   popups[i].style.backgroundRepeat = "no-repeat";
   popups[i].style.paddingLeft = "15px";
   }
*/

// add info to title attribute to alert fact that it's a pop-up window
  popups[i].title = popups[i].title + " [Abre em nova janela]";
  
 } else if (popups[i].rel.indexOf("external")!=-1) { 
   popups[i].target = '_blank';
   popups[i].title = popups[i].title + " [Abre em nova janela]";
 }
 }
}

function addEvent(elm, evType, fn, useCapture){if(elm.addEventListener){elm.addEventListener(evType, fn, useCapture);return true;}else if (elm.attachEvent){var r = elm.attachEvent('on' + evType, fn);return r;}else{elm['on' + evType] = fn;}}

sfFocus = function() {     
var sfEls = document.getElementsByTagName("INPUT");     
for (var i=0; i<sfEls.length; i++) {         
 sfEls[i].onfocus=function() { this.className+=" sffocus"; }         
 sfEls[i].onblur=function() { this.className=this.className.replace(new RegExp(" sffocus\\b"), "");         
  }     
 } 
} 
if (window.attachEvent) window.attachEvent("onload", sfFocus); 
addEvent(window, 'load', findPopUps, false);

Event.observe(window, "load", function(){
	
	$$("input.ctrlVal").each(
		function(s){

			s.setAttribute('valueIni', s.value)
			Event.observe(s, "click", function(){if(s.value==s.getAttribute("valueIni")) s.value= ""})
			Event.observe(s, "blur", function(){if(s.value=="") s.value= s.getAttribute("valueIni")})
		}
	);
	$$("form.ctrlValF").each(
		function(s){
			Event.observe(s, "submit",
				function(){
					document.getElementsByClassName("ctrlVal").each(
						function(s, index) {if(s.value==s.getAttribute("valueIni")){s.value= "";}}
					);
				}
			)
		}
	);
});
Event.observe('button_pesquisa', 'click', function(event){
	if($('q').value!='&sect;' && $('q').value!='') document.form_search.submit();
	else {
		$('q').value= ''; window.setTimeout('pesquise_aqui()', 500);
	}
});
function pesquise_aqui() {$('q').value= '&sect;'}

function BrailleText() {
var message = document.getElementById("Textbox1").value;
document.getElementById('myBraille').innerHTML=Braille(message,"/");
}

