function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }    
}

function getStyle(oElm, strCssRule){
    var strValue = "";
    if(document.defaultView && document.defaultView.getComputedStyle){
        strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
    }
    else if(oElm.currentStyle){
        strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
            return p1.toUpperCase();
        });
        strValue = oElm.currentStyle[strCssRule];
    }
    return strValue;
}

function largura() {
	var largura = 0;
	
	if( typeof( window.innerWidth ) == 'number' ) {
    	largura = window.innerWidth;
  	} else if( document.documentElement && document.documentElement.clientWidth ) {
    	largura = document.documentElement.clientWidth;
  	} else if( document.body && document.body.clientWidth ) {
    	largura = document.body.clientWidth;
  	}
	
	return largura;
}

function altura() {
	var altura = 0;
  	if( typeof( window.innerHeight ) == 'number' ) {
    	//Non-IE
    	altura = window.innerHeight;
  	} else if( document.documentElement && document.documentElement.clientHeight ) {
    	//IE 6+ in 'standards compliant mode'
    	altura = document.documentElement.clientHeight;
  	} else if( document.body && document.body.clientHeight ) {
    	//IE 4 compatible
    	altura = document.body.clientHeight;
  	}
	
	return altura;
}

var ids = new Array('imprensa', 'apresentacoes', 'newsletters', 'market_report');
var link_activo = false;
var id_link_activo = -1;
var ultimo_id = -1;

function muda_altura(id, altura_ocupada) {  
  	document.getElementById(id).style.height = (altura() - altura_ocupada) + "px";
}

function muda_largura(id, largura_ocupada) {  
  	document.getElementById(id).style.width = (largura() - largura_ocupada) + "px";
}

function posicao_topo(id, posicao) {
	document.getElementById(id).style.top = posicao + "px";
}

function posicao_fundo(id, posicao) {
	document.getElementById(id).style.bottom = posicao + "px";
}

function posicao_esquerda(id, posicao) {
	document.getElementById(id).style.left = posicao + "px";
}

function posicao_direita(id, posicao) {
	document.getElementById(id).style.right = posicao + "px";
}

function muda_largura_imagem(id, largura) {
	document.getElementById(id).width = largura;
}

function muda_altura_imagem(id, altura) {
	document.getElementById(id).height = altura;
}

function muda_largura_imagem(id, largura) {
	document.getElementById(id).width = largura;
}

function muda_altura_imagem(id, altura) {
	document.getElementById(id).height = altura;
}

function mostra_seta(id, click) {	
	if(click) {
		link_activo = click;
		id_link_activo = id;
		//document.getElementById(ids[id]).style.fontWeight = "bold";
		
		//if(ultimo_id > -1 && ultimo_id != id)
		//	document.getElementById(ids[ultimo_id]).style.fontWeight = "normal";
	
		ultimo_id = id;
	}
	
	if(!link_activo || id == id_link_activo) {
		document.getElementById('seta').style.visibility = "visible";
		document.getElementById('seta').style.top = (55 + 20 * id) + 'px';
	}
}

function mostra_seta_2(id, click) {	
	if(click) {
		link_activo = click;
		id_link_activo = id;
		//document.getElementById(ids[id]).style.fontWeight = "bold";
		
		//if(ultimo_id > -1 && ultimo_id != id)
		//	document.getElementById(ids[ultimo_id]).style.fontWeight = "normal";
	
		ultimo_id = id;
	}
	
	if(!link_activo || id == id_link_activo) {
		document.getElementById('seta').style.visibility = "visible";
		document.getElementById('seta').style.top = (65 + 25 * id) + 'px';
	}
}	

function mostra_seta_3(id, click) {	
	if(click) {
		link_activo = click;
		id_link_activo = id;
		//document.getElementById(ids[id]).style.fontWeight = "bold";
		
		//if(ultimo_id > -1 && ultimo_id != id)
		//	document.getElementById(ids[ultimo_id]).style.fontWeight = "normal";
	
		ultimo_id = id;
	}
	
	if(!link_activo || id == id_link_activo) {
		document.getElementById('seta').style.visibility = "visible";
		document.getElementById('seta').style.top = (60 + 55 * id) + 'px';
	}
}	

function mostra_seta_4(id, click) {	
	if(click) {
		link_activo = click;
		id_link_activo = id;
		//document.getElementById(ids[id]).style.fontWeight = "bold";
		
		//if(ultimo_id > -1 && ultimo_id != id)
		//	document.getElementById(ids[ultimo_id]).style.fontWeight = "normal";
	
		ultimo_id = id;
	}
	
	if(!link_activo || id == id_link_activo) {
		document.getElementById('seta').style.visibility = "visible";
		document.getElementById('seta').style.top = (65 + 90 * id) + 'px';
	}
}	

function esconde_seta() {
	if(!link_activo)
		document.getElementById('seta').style.visibility = "hidden";
}

function copia_dimensoes(id_origem, id_destino) {
	var altura_origem = getStyle(document.getElementById(id_origem), "height");
	var largura_origem = getStyle(document.getElementById(id_origem), "width");
	
	document.getElementById(id_destino).style.height = altura_origem;
	document.getElementById(id_destino).style.width = largura_origem;
}

function comprimento(id, propriedade) {
	var valor_str = getStyle(document.getElementById(id), propriedade);
	var valor = parseInt(valor_str.substring(0, valor_str.length - 2));
	
	return valor;
}

function login() {
	if(event.keyCode == 13)
		document.getElementById('login').submit();
}

function mostra_galeria(num_imagens) {	
	for(var i = 0; i != num_imagens; ++i) {
		document.getElementById("div_img" + (i + 1)).style.visibility = "visible";
	}
		
	for(var i = 0; i != (6 - num_imagens); ++i) {
		document.getElementById("div_img" + (i + num_imagens + 1)).style.visibility = "hidden";
	}
}

function mostra_imagem(img_num, tipo_projecto, projecto) {
	document['imagem'].src = "../../images/" + tipo_projecto + projecto  + "img" + img_num + ".jpg";
}

function DoPrinting(){
	if (!window.print){
		alert("Use o Netscape ou Internet Explorer \n nas versões 4.0 ou superior!")
		return
	}
	window.print()
}

function confirmBox() {
	if (confirm("Quer mesmo abandonar o formulário?")) {
		top.window.close();
	}
}



