var ie=(document.all || window.opera) && document.getElementById
var iebody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body
var IE4 = (document.all && !document.getElementById) ? true : false;
var NS4 = (document.layers) ? true : false;
var IE5 = (document.all && document.getElementById) ? true : false;
var N6 = (document.getElementById && !document.all) ? true : false;
if(IE4==true||NS4==true){top.location="/redirect.html";}

function addOption(w_form,w_campo,w_texto,w_valor){
	v_form = document.forms[w_form];newoption = new Option(w_texto,w_valor, false, false);
	v_form.elements[w_campo].options[v_form.elements[w_campo].length] = newoption;
}

function delOptions(w_campo,w_form){v_form = document.forms[w_form];
	for(j=v_form.elements[w_campo].length;j>-1;j--){v_form.elements[w_campo].options[j]=null;}
}

function imprim(){
	window.print();
	return;
var v_ponto="?"
var v_variaveis = "";
if(v_variaveis.length>0){
v_variaveis=v_variaveis+"&"
}

v_myExp=self.location.href;

if (v_myExp.indexOf("?")== -1){
	Abrew(self.location.href+"?pagesize=50000&num_registos=totil&pagina=sim&" + v_variaveis + "fazer=imprimir", "imprime", 780, 500, 1)
}else{
	Abrew(self.location.href+"&pagina=sim&pagesize=50000&num_registos=totil&" + v_variaveis + "fazer=imprimir", "imprime", 780, 500, 1)
}

}
function abreURL(w_url){AbrewXP(w_url);}
function envia_amigo(){Abrew("/prog/envia_mail.php?url="+escape(self.location.href),"amigo",450,270,0);}
function retiraAtributos(w){return}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
  document.getElementById('Label_menu').innerHTML = '';
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MostraLabel(w_qual){document.getElementById('Label_menu').innerHTML = "&nbsp;&nbsp;" + w_qual;}
function muda_idioma(w_form){
        v_form=document.forms[w_form];
        alert(self.location.href)
        v_form.action=self.location.href;
        v_form.submit();
}

//****Codigo para as mensagens de alerta****
//depois temos que fazer um if para naum escrever quando for fazer=imprimir.... DPEREIRA
document.write("<div id=\"teste_div\" style=\"POSITION: absolute;Z-INDEX: 2000; VISIBILITY: visible; TOP: 15px; LEFT: 15px;width: 1; height:1;filter:alpha(opacity=1););-moz-opacity:1\"></div>");
document.write("<div id=\"mascara\" style=\"POSITION: absolute;Z-INDEX: 1900; VISIBILITY: hidden; TOP: 15px; LEFT: 15px;width: 1; height:1;filter:alpha(opacity=1););-moz-opacity:1\"><table><tr><td id=masc>&nbsp;</td></tr></table></div>");

var tags = new Array("applet", "iframe", "select");
var curpos=0;
var v_timmer_id=null;
var v_interv_id=null;

function teste(w_id){
	v_fade_id=w_id;
	if (v_fade_id=="tbl"){
		var opc=10;
	}else{
		var opc=0;
	}
	v_divs = document.getElementById(v_fade_id);
	if (N6){
		opac_teste_moz=eval(v_divs.style.MozOpacity-0.5);
		if (v_divs.style.MozOpacity>0){
			v_divs.style.MozOpacity=opac_teste_moz
			setTimeout("teste(v_fade_id)",10)
		}
	}else{
		if (ie){
			opac_teste=eval(v_divs.filters.alpha.opacity-10);
		   if (v_divs.filters.alpha.opacity>opc){
				v_divs.filters.alpha.opacity=opac_teste;
				setTimeout("teste(v_fade_id)",10)
		   }
		}
	}

}

function transicaoout(w_id){
//alert(w_id)
v_div = document.getElementById(w_id);
v_id = w_id;
	if (v_id=="tbl"){
		var opac=30;
	}else{
		var opac=10;
	}
	if (N6){
		opac_teste_moz=eval(v_divs.style.MozOpacity+1);
		if (v_div.style.MozOpacity<1){
			v_div.style.MozOpacity=opac_teste_moz
			setTimeout("transicaoout(v_id)",10)
		}
	}else{
		if (ie){
			opac_trans=eval(v_div.filters.alpha.opacity+opac);
			if (v_div.filters.alpha.opacity<100){
				v_div.filters.alpha.opacity=opac_trans;
				setTimeout("transicaoout(v_id)",50)
			}
		 }
	}
}

function mostra_esconde(w_modo){
//alert(w_modo)
        for (n=0;n<tags.length;n++){
                v_ele=document.getElementsByTagName(tags[n]);
                //alert(tags[n]+"||"+v_ele.length)
                for(z=0;z<v_ele.length;z++){
                        v_ele.item(z).style.display=w_modo;
                }
        }
}
function reverte_proc(w_div1,w_div2,w_modo,w_refresca){
        v_cont=0;
        v_div1=w_div1;
        v_div2=w_div2;
        v_modo=w_modo;
        setTimeout("teste(v_div2)",50);
        setTimeout("transicaoout(v_div1)",50)
        v_div_esconde = document.getElementById(v_div2);
        v_div_mascara=document.getElementById('mascara');
        mostra_esconde(v_modo);
        v_div_esconde.innerHTML="";
        v_div_esconde.style.top=0
        v_div_esconde.style.left=0
        v_div_mascara.style.display="none";
        v_div_mascara.style.display="none";
	   if(w_refresca!=""){document.write(w_refresca);};
}

function faz_tabela_alert(w_msg,w_refresca){
       v_html="<table align=\"center\" width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\" class=\"alerta\">";
       v_html+="<tr>";
       v_html+="<td align=\"center\">&nbsp;</td>";
       v_html+="</tr>";
       v_html+="<tr>";
       v_html+="<td align=\"center\">"+w_msg+"</td>";
       v_html+="</tr>";
       v_html+="<tr>";
       v_html+="<td align=\"center\">&nbsp;</td>";
       v_html+="</tr>";
       v_html+="<tr>";
       v_html+="<td align=\"center\"><input type=\"button\" name=\"fecha\" class=\"button_peq\" value=\"OK\" onclick=\"reverte_proc(\'tbl\',\'teste_div\',\'block\',\'"+w_refresca+"\')\"></td>";
       v_html+="</tr>";
       v_html+="<tr>";
       v_html+="<td align=\"center\">&nbsp;</td>";
       v_html+="</tr>";
       v_html+="</table>";
       return v_html;
}


function faz_msg_div(w_html,w_modo,w,h,w_refresca){

        mostra_esconde(w_modo);
        v_div=document.getElementById('teste_div');
	   v_div_mascara=document.getElementById('mascara');
        v_div_masc=document.getElementById('masc');

        v_div.style.width=w;
        v_div.style.height=h;

        v_div_mascara.style.width=screen.width-50;
	   v_div_mascara.style.height=screen.height;
        v_div_masc.style.width=screen.width;
        v_div_masc.style.height=screen.height;

        var divl = (document.body.clientWidth-w) / 2;
        var divt = (document.body.clientHeight) / 2;

	   divt = (document.all ? document.body.scrollTop : window.pageYOffset)+divt;

        v_div.style.top = divt
        v_div.style.left= divl

        setTimeout("teste('tbl')",50)
        setTimeout("transicaoout('teste_div')",50)
	   if(w_refresca==1){
        	v_refresca = "<scr"+"ipt>self.close(0);window.opener.location.href=window.opener.location.href</scr"+"ipt>";
	   }else{
        	v_refresca = ""
	   }
        v_div.innerHTML=faz_tabela_alert(w_html,v_refresca);

        setTimeout("reverte_proc('tbl','teste_div','block','"+v_refresca+"');",2500);

}

function openChat(w_quem){
	var jetiJabber;
     if (!jetiJabber || jetiJabber.closed){
          jw = window.open('/IM/applet/jetiJabber.php', 'jetiJabber', 'width=200, height=400, left=50,top=50');
     }else{
          jw = window.open('', 'jetiJabber');
     }
	v_comando = "jw.document.jeti.openChat('"+w_quem+"');";
	setTimeout(v_comando,1000);
	jw.focus();
}
