function abre(ref,oque) {
	changeOpac(0, ref);
	opacity(ref, 0, 100, 1000);
	show(ref);
	acerta(ref);
	metedentro(ref,'');
	metedentro(ref,'<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"><tr><td onClick="fecha(\'janela\');" class="mao" valign="middle" width="140px" align="center"><img src="./imagens/fechar.jpg"></td><td align="center" valign="middle"><iframe width="950" height="600" src="' + oque + '" id="' + ref + '_interior" frameborder="0"></iframe></td></tr></table>');
	noscroll(ref);
	noscroll('corpo');
}
function metedentro(ref,txt) {
	document.getElementById(ref).innerHTML=txt;
}
function fecha(ref) {
	opacity(ref, 100, 0, 1000);
	//changeOpac(0, ref);
    setTimeout("scroll('corpo')",(1000)); 
    setTimeout("metedentro('" + ref + "','')",(1100)); 
    setTimeout("hide('" + ref + "')",(1500)); 
}


function blendimage(divid, imageid, imagefile, millisec) { 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 
     
    //set the current image as background 
    document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")"; 
     
    //make image transparent 
    changeOpac(0, imageid); 
     
    //make new image 
    document.getElementById(imageid).src = imagefile; 

    //fade in image 
    for(i = 0; i <= 100; i++) { 
        setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed)); 
        timer++; 
    } 
} 

function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
	//window.alert(timer);
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
} 
function tamanho(isto) {
	winW = new Number();
	winH = new Number();


	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName.indexOf("Microsoft")!=-1) {
			winW = document.body.offsetWidth;
			winH = document.body.offsetHeight;
			document.getElementById(isto).style.width=winW;
			document.getElementById(isto).style.height=winH;
		}
	}
}
function sincroniza(disto,naquilo) {
	document.getElementById(disto).innerHTML=document.getElementById(naquilo).innerHTML;
}
function ajusta(layer_ref) {
	esta = document.getElementById(layer_ref);
	
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
			winW = window.innerWidth;
			winH = window.innerHeight;
			esta.style.left=(Math.floor(winW-950)/2);
		}
		if (navigator.appName.indexOf("Microsoft")!=-1) {
			winW = document.body.offsetWidth;
			winH = document.body.offsetHeight;
			esta.style.left=(Math.floor((winW-950)/2)-9);
		}
	}
		
	window.setTimeout("ajusta('" + layer_ref + "')", 10); 

}
function overflow(layer_ref) {


//window.alert winW;
//window.alert winH;


//telaconteudo.style.width='100%';


	esta = document.getElementById(layer_ref);
	switch (esta.style.overflow)
		{
			case '': { esta.style.overflow='auto'; break }
			case 'auto': { esta.style.overflow=''; break }
		}
}
function show(layer_ref) {
			   document.getElementById(layer_ref).style.visibility='visible';
			   document.getElementById(layer_ref).style.display='block';
			   //document.getElementById(layer_ref).style.height='auto';
			}
function hide(layer_ref) {
   document.getElementById(layer_ref).style.visibility='hidden';
   document.getElementById(layer_ref).style.display='none';
   //document.getElementById(layer_ref).style.height='0px';
}
function fechar(layer_ref) {
   document.getElementById(layer_ref).style.display='none';
   document.getElementById(layer_ref).style.height='0px';
   document.getElementById(layer_ref).innerHTML=' ';
}
function noscroll(ref) {
   document.getElementById(ref).style.overflow='hidden';
}
function scroll(ref) {
   document.getElementById(ref).style.overflow='';
}
function getFlashMovieObject(movieName)
{
   if (window.document[movieName]) 
   {
	  return window.document[movieName];
   }

   if (navigator.appName.indexOf("Microsoft Internet")==-1)
   {
	  if (document.embeds && document.embeds[movieName])
		 return document.embeds[movieName]; 
   }
   else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
   {
	  return document.getElementById(movieName);
   }
}
			
			

function StopFlashMovie(myFlashMovie)
{
   var flashMovie=getFlashMovieObject(myFlashMovie);
   if (navigator.appName.indexOf("Microsoft Internet")==-1)
	   {
		  flashMovie.StopPlay;
	  }
	  else 
	  {
		  flashMovie.StopPlay();
	  }
}

function PlayFlashMovie(myFlashMovie)
{
   var flashMovie=getFlashMovieObject(myFlashMovie);
   if (navigator.appName.indexOf("Microsoft Internet")==-1)
	   {
		  flashMovie.Play;
	  }
	  else 
	  {
		  flashMovie.Play();
	  }
}
(document.getElementById) ? dom = true : dom = false;

function acerta(esta) {
	if (dom && !document.all) {
		document.getElementById(esta).style.top = window.pageYOffset + (window.innerHeight - (window.innerHeight));
		window.setTimeout("acerta('" + esta + "')", 10); 
		}
   if (document.layers) {
   		document.layers[esta].top = window.pageYOffset + (window.innerHeight - (window.innerHeight));
		window.setTimeout("acerta('" + esta + "')", 10); 
		}
   if (document.all) {
   		document.all[esta].style.top = document.body.scrollTop + (document.body.clientHeight - (document.body.clientHeight));
		window.setTimeout("acerta('" + esta + "')", 10); 
		}
}

function fixflash(containerID){
	
	if (document.getElementById(containerID)) {
		var flashContainer = document.getElementById(containerID);
		var flashMovie = document.createElement("div");
		flashMovie.innerHTML = flashContainer.innerHTML.replace(/</g, "<").replace(/>/g, ">");
		flashContainer.parentNode.insertBefore(flashMovie, flashContainer);
		flashContainer.parentNode.removeChild(flashContainer);
		flashMovie.setAttribute("id",containerID);
	}
}

function showhide_ie(layerref) {

//SE FOR IE...
	var caixa = document.getElementById(layerref);
	var caixaint= new String(caixa.innerHTML);
	var esconde = new String('visibility: hidden; display: none; height: 0px');
	var mostra = new String('visibility: visible; display: block; height: auto');
	//visibility:hidden;display:none;height:auto;
	var a = new Number(caixaint.search('hidden'));
	//alert(document.getElementById(layerref).innerHTML);
	if (a>0) {
	//esconde
		caixa.innerHTML=caixaint.replace(esconde,mostra);
		//alert(caixa.innerHTML);
		//alert(a + " MAIOR");
	} else {
	//mostra
		caixa.innerHTML=caixaint.replace(mostra,esconde);
		//alert(caixa.innerHTML);
		//alert(a);
	}
}

function jumpMenu(targ,selObj,restore){ 
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function altera_tamanho(esta_imagem) {

	var imagem=document.getElementById(esta_imagem);

	if (imagem.width=="45") {
		imagem.width="375";
		imagem.alt="Clique para minimizar";
		imagem.title="Clique para minimizar";
	} else {
		imagem.width="45";
		imagem.alt="Clique para maximizar";
		imagem.title="Clique para maximizar";
	}
}

function congela(estadiv) {
	var div=document.getElementById(estadiv);
	div.disabled=true;
}

var myimages=new Array();
function preloadimages() {
	for (i=0;i<preloadimages.arguments.length;i++) {
		myimages[i]=new Image()
		myimages[i].src=preloadimages.arguments[i]
	}
}

// Pfad und Name der Images.
preloadimages("http://www.publibranco.pt/imagens/carregar.gif");
//-->


function altera_tamanho(esta_imagem) 
{

var imagem=document.getElementById(esta_imagem);

	if (imagem.width=="45") 
	{
		imagem.width="375";
		imagem.alt="Clique para minimizar";
		imagem.title="Clique para minimizar";
		} else {
		imagem.width="45";
		imagem.alt="Clique para maximizar";
		imagem.title="Clique para maximizar";
		}
}

function congela(estadiv) {
	var div=document.getElementById(estadiv);
div.disabled=true;
}

function altera_imagem(img_nome,img_src,img_titulo,img_input) {
	var div=document.getElementById(img_input);
	document.getElementById(img_nome).src="http://www.publibranco.pt/imagens/carregar.gif";
	document.getElementById(img_nome).src=img_src;
	//window.alert("img_nome "+img_nome+" img_src "+img_src+" img_titulo "+img_titulo+" img_input "+img_input);
	div.value=img_titulo;
	div.disabled=false;
}

function altera_so_imagem(img_id,img_src) {
	document.getElementById(img_id).src="http://www.publibranco.pt/imagens/carregar.gif";
	document.getElementById(img_id).src=img_src;
}

function altera_link(img_nome,img_src) {
//document.getElementById(img_nome).href=img_src;
}

function marca(esta_img_div) {
	document.getElementById(esta_img_div).style.borderColor = "#990000";
}

function desmarca(esta_img_div) {
	document.getElementById(esta_img_div).style.borderColor = "#4B7B92";
}

function sublinha(esta_img_div) {
	document.getElementById(esta_img_div).style.backgroundColor = "#4B7B92";
}

function hidestatus(){
window.status='www.publibranco.pt'
return true
}

if (document.layers)
document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT | Event.MOUSEDOWN)

document.onmouseover=hidestatus
document.onmouseout=hidestatus
document.onmousedown=hidestatus

var state = 'hidden';

function showhide(layer_ref) {

if (state == 'visible') {
state = 'hidden';
}
else {
state = 'visible';
}
if (document.all) { //IS IE 4 or 5 (or 6 beta)
eval( "document.all." + layer_ref + ".style.visibility = state");
}
if (document.layers) { //IS NETSCAPE 4 or below
document.layers[layer_ref].visibility = state;
}
if (document.getElementById && !document.all) {
maxwell_smart = document.getElementById(layer_ref);
maxwell_smart.style.visibility = state;
}
}


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_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' tem que conter um email válido.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' tem que conter um número.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' tem que conter um número entre '+min+' e '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' de preenchimento obrigatório.\n'; }
  } if (errors) alert('Ocorreram os seguintes erros:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function fadeOut(id, time) {
	target = document.getElementById(id);
	alpha = 100;
	timer = (time*1000)/50;
	var i = setInterval(
			function() {
				if (alpha <= 0)
					clearInterval(i);
				setAlpha(target, alpha);
				alpha -= 2;
			}, timer);
}

function fadeIn(id, time) {
	target = document.getElementById(id);
	alpha = 0;
	timer = (time*1000)/50;
	var i = setInterval(
			function() {
				if (alpha >= 100)
					clearInterval(i);
				setAlpha(target, alpha);
				alpha += 2;
			}, timer);
}

function setAlpha(target, alpha) {
	target.style.filter = "alpha(opacity="+ alpha +")";
	target.style.opacity = alpha/100;
}
function daAlpha(target, alpha) {
	document.getElementById(target).style.filter = "alpha(opacity="+ alpha +")";
	document.getElementById(target).style.opacity = alpha/100;
}
