// ########## GENERAL ####################################################

function NavMain(u){
	var w=window.parent;
	while (w.parent!=w){
		w=w.parent;
		}
	w.document.location.href=u;
	}
	
function setRadio(g,i) {
	var r=document.getElementsByName(g)
	if(r[i]){
		if (!r[i].disabled){r[i].checked=true;return true;}else{return false;}
		}else{
		return false;
		}
    }

function getRadio(g,i) {
	var r=document.getElementsByName(g)
	if(r[i]){return r[i].checked;}else{return false;}
	}
	
function Find(id){
	if (document.getElementById(id)){
		return document.getElementById(id);
		}else{
		if (document.getElementsByName(id).length){return document.getElementsByName(id)[0];}
		}
	}

function showjornal(serie,jornal,pagina) {
	windowops = eval("'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=640,height=480'");
	newwindow=window.open("consultarjornal.asp?serie="+ serie +"&jornal=" + jornal + "&pagina=" + pagina, "ConsultarJornal", windowops);
	}

function showidv(fid){
	window.open('consultarid.asp?id='+fid,'','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=600,height=400')
	}

function showeuribor() {
	windowops = eval("'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=420,height=500'");
	newwindow=window.open("euribor.asp", "ConsultarEuribor", windowops);
	}

function updateEuriborPrefs(e){
	var tmp='';var a=new Array('M01','M03','M06','M12');
	for(var i=0;i<4;i++){if(document.getElementById(a[i]).checked) tmp+=a[i]+';';};
	if(tmp==''){
		window.alert('Não pode remover todos os indexantes da tabela de taxas!');
		e.checked=true;
		return;
		}
	switch(e.id){
		case "M01":var o=document.getElementById('euri-row0');break;
		case "M03":var o=document.getElementById('euri-row1');break;
		case "M06":var o=document.getElementById('euri-row2');break;
		case "M12":var o=document.getElementById('euri-row3');break;
		}
	e.checked?o.style.cssText='':Hide(o);
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+60);
	document.cookie='euribor_rates='+escape(tmp)+'; expires='+exdate.toUTCString();
	}

function applyEuriborPrefs(){
	var c_name='euribor_rates';var tmp='M06';
	if (document.cookie.length>0){
		c_start=document.cookie.indexOf(c_name+'=');
		if (c_start!=-1){
			c_start=c_start+c_name.length+1;
			c_end=document.cookie.indexOf(';',c_start);
			if(c_end==-1) c_end=document.cookie.length;
			var tmp=unescape(document.cookie.substring(c_start,c_end));
			}
		}
	if(tmp==''){tmp='M01;M03;M06;M12';}
	var b=new Array;
	b=tmp.split(';');
	for(var i=0;i<b.length;i++){
		var o=null;
		switch(b[i]){
			case "M01":var o=document.getElementById('euri-row0');break;
			case "M03":var o=document.getElementById('euri-row1');break;
			case "M06":var o=document.getElementById('euri-row2');break;
			case "M12":var o=document.getElementById('euri-row3');break;
			}
		if(o){document.getElementById(b[i]).checked=true;o.style.cssText='';}
		}
	}

// ########## CHECK EMAIL ####################################################

function checkEmail(this_email){
	var x=this_email;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)){return true}else{return false}
	}

// ########## PRINT DIV ####################################################

function printDiv(divID){
	var html="";
	if (typeof(divID)=='object'){
		html=divID.innerHTML;
		}else{
		if (document.getElementById(divID)){html=document.getElementById(divID).innerHTML}
		}
	var a = window.open('','','width=10,height=10');
	a.document.open("text/html");
	a.document.write("<html><head><link rel='stylesheet' href='css/oif2008.css'><link rel='stylesheet' href='css/oifcodigos.css'></head><body>");
	a.document.write(html);
	a.document.write("</body></html>");
	a.document.close();
	var h=a.document.getElementById("hide_me");
	if (h){h.style.display="none";}
	var o=a.document.getElementById("show_url");
	if (o){o.style.display='';}
	var i=a.document.getElementById("show_logo");
	if (i){i.style.display='';}
	a.print();
	a.close();
	}

// ########## SHOW/HIDE ####################################################

function setVisible(e){
	if (typeof(e)=='object'){
		e.style.visibility='';
		}else{
		if (Find(e)){Find(e).style.visibility='';}
		}
	}

function setInvisible(e){
	if (typeof(e)=='object'){
		e.style.visibility='none';
		}else{
		if (Find(e)){Find(e).style.visibility='hidden';}
		}
	}

function setDisplay(e,d){
	if (typeof(e)=='object'){
		e.style.display=d;
		}else{
		if (Find(e)){Find(e).style.display=d;}
		}
	}
	
function Show(e){setDisplay(e,'block');}
function ShowInline(e){setDisplay(e,'inline');}			
function Hide(e){setDisplay(e,'none');}

function toggleDisplay(e) {
	if (typeof(e)!='object'){
		if (Find(e)) e=Find(e);
		}
	if (e){
		if (e.style.display!='none'){e.style.display='none';}else{e.style.display='block';}
		}
	}

function SHPlus(eID,eIndex) {
	var trgID=eID+'_'+eIndex;
	if (document.getElementById(trgID)){
		var st=document.getElementById(trgID).style.display;
		if (!(st=='' || st=='none')){
			Hide(trgID); document.getElementById('bt_'+eID+'_'+eIndex).innerHTML="+";
			}else{
			var i=1;
			while (i>0){
				trgID=eID+'_'+i;
				if (document.getElementById(trgID)){
					if (i==eIndex){
						Show(trgID); document.getElementById('bt_'+eID+'_'+i).innerHTML="&nbsp;-&nbsp;";
						}else{
						Hide(trgID); document.getElementById('bt_'+eID+'_'+i).innerHTML="+";
						}
					}else{
					break;
					}
				i++;
				}
			}
		}
	}

function SHNews(eID,eIndex) {
	var trgID=eID+'_'+eIndex;
	if (document.getElementById(trgID)){
		var st=document.getElementById(trgID).style.display;
		if (!(st=='' || st=='none')){
			Find('lnk_'+eID+'_'+eIndex).className='tit';Hide(trgID);
			}else{
			var i=1;
			while (i>0){
				trgID=eID+'_'+i;
				if (document.getElementById(trgID)){
					if (i==eIndex){
						Show(trgID);Find('lnk_'+eID+'_'+i).className='tit2';
						}else{
						Hide(trgID);Find('lnk_'+eID+'_'+i).className='tit';
						}
					}else{
					break;
					}
				i++;
				}
			}
		}
	}


function SHMenu(eID,eIndex) {
	var trgID=eID+'_'+eIndex;
	if (document.getElementById(trgID)){
		var i=1;
		while (i>0){
			trgID=eID+'_'+i;
			if (document.getElementById(trgID)){
				if (i==eIndex){
					Show(trgID); document.getElementById('lnk_'+eID+'_'+eIndex).className="selected";
					}else{
					Hide(trgID); document.getElementById('lnk_'+eID+'_'+i).className="";
					}
				}else{
				break;
				}
			i++;
			}
		}
	}

function ShowHide(eID,eIndex) {
	var trgID=eID+'_'+eIndex;
	if (document.getElementById(trgID)){
		var i=1;
		while (i>0){
			trgID=eID+'_'+i;
			var e=document.getElementById(trgID);
			if (e){
				if (i==eIndex){
					if (!(e.style.display=='' || e.style.display=='none')){e.style.display='none';}else{e.style.display='block';}
					}else{
					Hide(trgID);
					}
				}else{
				break;
				}
			i++;
			}
		}
	}

// ########## IFRAME LOJA ####################################################

function resizeIFrame(frameid){

//var currentfr=document.getElementById(frameid);
//currentfr.style.display="block";
//currentfr.height=currentfr.contentDocument.body.offsetHeight;
//currentfr.height = currentfr.Document.body.scrollHeight;

//	document.getElementById(frameid).style.display='none';
	//document.getElementById(frameid).height=100;
	document.getElementById(frameid).height=window.frames[0].document.body.scrollHeight+34;
//	obj.style.display='block';
	} 

// ########## TOOLTIP ####################################################

var ToolTipID = "MyToolTip"; // estilo definido no CSS
var marginX = 10;
var marginY = 5;
var boxWidth=200;
var _x = -10;
var _y = -10;
var opacity=90;
var ovr_bgc='';
var ovr_fgc='';
var ovr_tbc='';
var ovr_tfc='';

function setPos(event) {
	var pWidth=0;
	pWidth=document.documentElement.clientWidth;
	if (document.all) {//IE
		_x = (document.documentElement && document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
		_y = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
		_x += (window.event.clientX+marginX); _y += (window.event.clientY+marginY);
		} else {//Good Browsers
		_x = (event.pageX+marginX); _y = (event.pageY+marginY);
		}
	if (_x+boxWidth+marginX>pWidth){_x-=boxWidth;}
	}

function showTip(title,text) {
	var tmp=""; var t = document.getElementById(ToolTipID);
	if (ovr_bgc){t.style.backgroundColor=ovr_bgc;}
	if (ovr_fgc){t.style.backgroundColor=ovr_fgc;}
	if (title){
		tmp="<span class='Title' id='TipTitleBlock'"
		if (ovr_tbc || ovr_tfc){
			tmp+=" style='"
			if (ovr_tbc){tmp+="backgound-color:"+ovr_tbc+";"}
			if (ovr_tfc){tmp+="color:"+ovr_tfc+";"}
			tmp+="'"
			}
		tmp+=">"+title+"</span>";
		}
	if (text){tmp+=text;}
	t.innerHTML = tmp;
	t.style.display = "block";
	document.onmousemove = function(event) {
		setPos(event); t.style.left = _x+"px"; t.style.top = _y+"px";
		}
	}

function hideTip() {document.getElementById(ToolTipID).style.display = "none";}

function tooltip() {
	//var body = document.getElementsByTagName("body");
	//body = body[0];	body.innerHTML += "<div id='"+ToolTipID+"'></div>";
	//*** This must exist on main page <div id="MyToolTip" style="display:none"></div>
	if (document.getElementById(ToolTipID)){
		var t = document.getElementById(ToolTipID).style;
		t.opacity=opacity/100; t.filter="alpha(opacity="+opacity+")"; t.display="none"; t.width=boxWidth+"px";
		var all = document.all || document.getElementsByTagName('*'); 
		for (var i=0, elm; elm=all[i++];) {
			var title=""; var txt="";
			var tmp = elm.getAttribute("tip_title");
			if (tmp) {title=tmp;}
			var tmp = elm.getAttribute("tip_text");
			if (tmp) {txt=tmp;}
			if (title || txt){
				elm.onmouseover = function() { showTip(this.getAttribute("tip_title"),this.getAttribute("tip_text"));}
				elm.onmouseout = function() { hideTip(); }
				}		
			}
		}
	}

function updateTip(bc,fc,tbc,tfc){
	ovr_bgc=bc;
	ovr_fgc=fc;
	ovr_tbc=tbc;
	ovr_tfc=tfc;
	}
	
// ########## HOVER BACKGROUND ####################################################

function hovercolors() {
	var all = document.all || document.getElementsByTagName('*'); 
	for (var i=0, elm; elm=all[i++];) {
		var h_in=""; var h_out="";
		var tmp = elm.getAttribute("hover_in");
		if (tmp) {h_in=tmp;}
		var tmp = elm.getAttribute("hover_out");
		if (tmp) {h_out=tmp;}
		if (h_in){elm.onmouseover = function() {this.style.backgroundColor=this.getAttribute("hover_in");}}
		if (h_out){elm.onmouseout = function() {
			this.style.backgroundColor=this.getAttribute("hover_out");}
			}else{
			if (h_in){elm.onmouseout = function() {this.style.backgroundColor='';}}
			}
		}
	}

// ########## ONLOAD ####################################################

var onLoadMsg='';

function checkOnLoadMsg(){
	if (onLoadMsg){
		window.alert(onLoadMsg);
		onLoadMsg='';
		}
	}

window.onload = function() {tooltip();hovercolors();checkOnLoadMsg();}
