img_on         = new Image(150,90);
img_on.src     = "img/Arr.gif";
img_off         = new Image(150,90);
img_off.src     = "img/noArr.gif";

function aImg(obj){
	imgOn = eval("img_on.src");
	nome = obj.substr(0, obj.toString().length-1);
	var aux = document.getElementById(obj);
	aux.src = imgOn;
}

function dImg(obj){
	imgOn = eval("img_off.src");
	nome=obj.substr(0, obj.toString().length-1);
	var aux = document.getElementById(obj);
	aux.src = imgOn;
}

function Trim(String){
	var i = 0;
	var j = String.length - 1;

	if (String == null)
		return (false);

	for (i = 0; i < String.length; i++)
	{
		if (String.substr(i, 1) != ' ' &&
			String.substr(i, 1) != '\t')
			break;
	}

	for(j = String.length - 1; j >= 0; j--)
	{
		if (String.substr(j, 1) != ' ' &&
			String.substr(j, 1) != '\t')
		break;
	}

	if (i <= j)
		return (String.substr(i, (j+1)-i));
	else
		return ('');
}

function submitPesquisa() {
	var termo = new String();
	termo = document.frmPesquisaGeral.PESQUISA_termo.value;

	if (termo.indexOf('%') > 0){
		alert('O termo para pesquisa não pode conter o caracter \'%\'');
		document.frmPesquisaGeral.PESQUISA_termo.focus();
		return;
	}
	if (termo == '') {
		alert('Introduza um termo para pesquisa');
		document.frmPesquisaGeral.PESQUISA_termo.focus();
		return false;
	}
	if (termo.length < 3) {
		alert(' Introduza, pelo menos 3 caracteres. ');
		document.frmPesquisaGeral.PESQUISA_termo.focus();
		return false;
	}

	document.frmPesquisaGeral.submit();
}

/* abre um canal e fecha os outros*/
function eXpand2(obj,id){
	//Compatible IE 6, Mozilla 1.4.1 , Firebird 0.6.1+
	for (i=1;i <= 100; i++){
		if(document.getElementById(obj+i) != null){
			if (document.all){
				if(i==id)
					document.getElementById(obj+i).style.display = (document.getElementById(obj+i).style.display == "none" ) ? "inline" : "none";
				else
					document.getElementById(obj+i).style.display = (document.getElementById(obj+i).style.display == "inline" ) ? "none" : "none";
			}else{
				if(i==id)
					document.getElementById(obj+i).style.display = (document.getElementById(obj+i).style.display == "none" ) ? "table-row" : "none";
				else
					document.getElementById(obj+i).style.display = (document.getElementById(obj+i).style.display == "table-row" ) ? "none" : "none";
			}
		} else
			break;
	}
}

function eXpand(obj){
	//Compatible IE 6, Mozilla 1.4.1 , Firebird 0.6.1+
	var aux = document.getElementById(obj);

	if (document.all)
		aux.style.display = (aux.style.display == "none" ) ? "inline" : "none";
	else
		aux.style.display = (aux.style.display == "none" ) ? "table-row" : "none";
}

window.onresize=reDo;

function reDo(){
    thisWidth = windowSize();

    if (winWidth!=thisWidth){
       window.location.reload();
       winWidth=thisWidth;
    };
}

var janela = null;

function openWin(sUrl, w, h) {
	if (janela && !janela.closed) janela.close();
	janela = window.open(sUrl,'','top=0, left=0, location=0, toolbar=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=1');
	if (w != null && h != null) janela.resizeTo(w, h);
}

function openImg(sUrl) {
	if (janela && !janela.closed) janela.close();
	janela = window.open('','','top=0, left=0, location=0, toolbar=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=1');
	janela.document.write('<html><head><title>Imagem</title></head><body leftmargin="2" topmargin="2"><img border="1" style="border-color:#000000" src="' + sUrl + '"></body></html>');

	var iWidth = janela.document.images[0].width + 20;
	var iHeight = janela.document.images[0].height + 40;
	janela.resizeTo(iWidth, iHeight);
	janela.focus();
}

var img_id = 0;
var tmpHTML = '';

/*
Array Format: Text, URL, SID, Childs?
*/
function menuWiz(sid, a, level) {
	tmpHTML += (
		'<div id="' + sid + 'Container" style="z-index: ' + level + ';">' +
		'	<div id="' + sid + 'Content" style="position: relative; z-index: ' + level + '; left: 50; filter:alpha(opacity=90); text-align: left;">'
	);

	var tam, tam2;
	if (level==4){
		tam = 120;
		tam2 = 155;
	} else {
		tam = 200;
		tam2 = 220;
	}

	tmpHTML += (
		'<div id=navlist style="width:' + tam2 + 'px;">'
	);

	for(var i=0; i<a.length; i++) {
		var txt = a[i][0];
		var url = a[i][1];
		var childSid = a[i][2];
		var childs = a[i][3];

		if (level==4) {
			tmpHTML += (
				'<a ' +
				'onmouseover="ypSlideOutMenu.showMenu(\'' + childSid + '\');ypSlideOutMenu2.showMenu(\'' + sid + '\');"' +
				'onmouseout="ypSlideOutMenu.hideMenu(\'' + childSid + '\');ypSlideOutMenu2.hideMenu(\'' + sid + '\');"' +
				'href="' + (childs==true?'javascript:void(0);':url) + '" target="_blank">' + txt +  '</a>' +
				(childs==true? '<img align="right" src="img/redArr.gif">':'') +
				(i == (a.length-1) ? '':'<div onmouseover="ypSlideOutMenu.showMenu(\'' + childSid + '\');ypSlideOutMenu2.showMenu(\'' + sid + '\');"></div>')
			);
		} else {
			tmpHTML += (
				'<a ' +
				'onmouseover="ypSlideOutMenu.showMenu(\'' + sid + '\');' + (childs==true?'ypSlideOutMenu2.showMenu(\'' + childSid + '\');' : '') +
				'" onmouseout="ypSlideOutMenu.hideMenu(\'' + sid + '\');' + (childs==true?'ypSlideOutMenu2.hideMenu(\'' + childSid + '\');' : '') +
				'" href="' + (childs==true?'javascript:void(0);':url) + '" target="_blank">' + txt +  '</a>' +
				(childs==true? '<img align="right" src="img/redArr.gif">':'') +
				(i == (a.length-1) ? '':'<div onmouseover="ypSlideOutMenu.showMenu(\'' + sid + '\');"></div>')
			);
		}
	}

	tmpHTML += (
	'	</div>' +
	'  </div>' +
	'</div>'
	);
}

/*
Array Format: Text, URL, SID, Childs?
*/
function menuWiz2(sid, a, level) {
	tmpHTML += (
		'<div id="' + sid + 'Container" style="z-index: ' + level + ';">' +
		'	<div id="' + sid + 'Content" style="position: relative; z-index: ' + level + '; left: 50; filter:alpha(opacity=90); text-align: left;">'
	);

	var tam, tam2;
	if (level==4){
		tam = 120;
		tam2 = 155;
	} else {
		tam = 200;
		tam2 = 220;
	}

	tmpHTML += (
		'<div id=navlist style="width:' + tam2 + 'px;">'
	);

	for(var i=0; i<a.length; i++) {
		var txt = a[i][0];
		var url = a[i][1];
		var childSid = a[i][2];
		var childs = a[i][3];

		if (level==4) {
			tmpHTML += (
				'<a ' +
				'onmouseover="ypSlideOutMenu.showMenu(\'' + childSid + '\');ypSlideOutMenu2.showMenu(\'' + sid + '\');"' +
				'onmouseout="ypSlideOutMenu.hideMenu(\'' + childSid + '\');ypSlideOutMenu2.hideMenu(\'' + sid + '\');"' +
				'href="' + (childs==true?'javascript:void(0);':url) + '">' + txt +  '</a>' +
				(childs==true? '<img align="right" src="img/redArr.gif">':'') +
				(i == (a.length-1) ? '':'<div onmouseover="ypSlideOutMenu.showMenu(\'' + childSid + '\');ypSlideOutMenu2.showMenu(\'' + sid + '\');"></div>')
			);
		} else {
			tmpHTML += (
				'<a ' +
				'onmouseover="ypSlideOutMenu.showMenu(\'' + sid + '\');' + (childs==true?'ypSlideOutMenu2.showMenu(\'' + childSid + '\');' : '') +
				'" onmouseout="ypSlideOutMenu.hideMenu(\'' + sid + '\');' + (childs==true?'ypSlideOutMenu2.hideMenu(\'' + childSid + '\');' : '') +
				'" href="' + (childs==true?'javascript:void(0);':url) + '">' + txt +  '</a>' +
				(childs==true? '<img align="right" src="img/redArr.gif">':'') +
				(i == (a.length-1) ? '':'<div onmouseover="ypSlideOutMenu.showMenu(\'' + sid + '\');"></div>')
			);
		}
	}

	tmpHTML += (
	'	</div>' +
	'  </div>' +
	'</div>'
	);
}


function menuFlush() {
	document.write(tmpHTML);
}
