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;
}

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 abre_janela_abstract(link){

	var largura = 402;
	var altura = 509;
	var w = largura;
	var h = altura;
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',title=Sociedade Portuguesa de Alergologia e Imunologia Clínica,status=no,toolbar=no,menubar=no,scrollbars=yes,resizable=no';
	win = window.open(link, 'SPR', winprops);
	if (parseInt(navigator.appVersion) >= 4) win.window.focus();

	//newwindow = window.open (link, "mywindow","location=0,status=0,scrollbars=0,width=512,height=380");
	//newwindow.moveTo(self.screen.width/4,self.screen.height/8);
}

function ver_imagem(path, titulo,imgwidth,imgheight){

	var w = imgwidth;
	var h = imgheight;
	var largura = w;
	var altura = h;
	var screenX = screen.width;
	var screenY = screen.height;
	var winl;
	var wint;

	if (w > screenX){
		largura = screenX;
		if (h > screenY){
			altura = screenY;
			largura = (w * screenY) / (h);
		} else {
			altura = (h * screenX) / (w);
		}
	} else {
		largura = w;
		if (h > screenY){
			altura = screenY;
			largura = (w * screenY) / (h);
		} else {
			altura = h;
		}
	}

	winl = (screenX - largura) / 2;
	wint = (screenY - altura) / 2;

	winprops = 'height='+altura+',width='+largura+',top='+wint+',left='+winl+',status=no,toolbar=no,menubar=no,scrollbars=no,resizable=no,directories=no';
	win = window.open('imagem.php?titulo='+titulo+'&imagem='+path+'&width='+largura+'&height='+altura,'', winprops);
	if (parseInt(navigator.appVersion) >= 4) win.window.focus();
}

function ver_imagem_keyword(raiz,path, titulo,imgwidth,imgheight){

	var w = imgwidth;
	var h = imgheight;
	var largura = w;
	var altura = h;
	var screenX = screen.width;
	var screenY = screen.height;
	var winl;
	var wint;

	if (w > screenX){
		largura = screenX;
		if (h > screenY){
			altura = screenY;
			largura = (w * screenY) / (h);
		} else {
			altura = (h * screenX) / (w);
		}
	} else {
		largura = w;
		if (h > screenY){
			altura = screenY;
			largura = (w * screenY) / (h);
		} else {
			altura = h;
		}
	}

	winl = (screenX - largura) / 2;
	wint = (screenY - altura) / 2;

	winprops = 'height='+altura+',width='+largura+',top='+wint+',left='+winl+',status=no,toolbar=no,menubar=no,scrollbars=no,resizable=no,directories=no';
	win = window.open(raiz+'imagem.php?titulo='+titulo+'&imagem='+path+'&width='+largura+'&height='+altura,'', winprops);
	if (parseInt(navigator.appVersion) >= 4) win.window.focus();
}

//esta funcao serve para alterar a cor do texto de press_realeases ao passar o rato
function changeStyleById(id, color){
	if (document.getElementById){
		var nodeObj = document.getElementById(id);
		nodeObj.style.color = color;
	}
}

function open_calendario(url, form, campo, dataEntrada)
 {
	urlFinal = url + "?form=" + form + "&campo=" + campo;
			if(!dataEntrada == "") {
				urlFinal += "&data_entrada=" + dataEntrada;
			}
			var newWindow;
	newWindow = window.open(urlFinal,'','height=250,width=255,toolbar=no,minimize=no,status=no,menubar=no,location=no,scrollbars=no');
}

function nltobr (str){
	var str=new String(str);
	var primeira_pos=str.search(/<[ ]*table/g);
	var temp_pos;
	var inicio=1;

	var ma_array=str.match(/<[ ]*\/[ ]*table/g);
	if (ma_array) {
			ultima_pos=str.lastIndexOf(ma_array[ma_array.length-1]);
	}
	if (primeira_pos!=-1) {
			var new_str=(str.slice(0,primeira_pos)).replace(/\n/g,"<br>");
			new_str+=(str.slice(primeira_pos,ultima_pos));
			new_str+=(str.slice(ultima_pos)).replace(/\n/g,"<br>");
	}
	else {
			var new_str=str.replace(/\n/g,"<br>");
	}
	return new_str;
}


function addquot (str){
	var str=new String(str);
	var new_str=str.replace(/["]/g,"&quot;");
	return new_str;
}

function mostra_imagem(strFile,file_dir) {
	var file_dir = file_dir || '/';
	if (strFile != '')
			preview3(file_dir+strFile, 600, 400);

}

function checkEnterPage(nform, evt)
{
	evt = (evt) ? evt : event
	var charCode = (evt.wich) ? evt.wich : evt.keyCode
	if (charCode == 13)
	{
		 nform.submit();
		 return false
	}
	return true
}

function sub_caract_esq(str)
{
	var str_sub=String(str);
	var regexp=/€/g;
	str_sub=str_sub.replace(regexp,'&euro;');
	regexp=/[”“]/g;
	str_sub=str_sub.replace(regexp,'"');
	regexp=/…/g;
	str_sub=str_sub.replace(regexp,'...');
	regexp=/–/g;
	str_sub=str_sub.replace(regexp,'-');
	return str_sub;
}

function ComandoSelected(nome,accao)
{
	document.forms[nome].action=accao;
	document.forms[nome].submit();
}

function preview_nome(accao,w,h,nome)
{
	window.open('<?=$_SERVER[HTTPS]==on?$base:$URL?>'+accao,nome,toolbar=no,width='+w+',height='+h+',directories=no,status=no,scrollbars=yes,resizable=no,menubar=no,location=no);
}

function preview(accao,w,h)
{
	window.open('<?=$_SERVER[HTTPS]==on?$base:$URL?>'+accao,'<?=$LOGIN_USER?>',toolbar=no,width='+w+',height='+h+',directories=no,status=no,scrollbars=yes,resizable=no,menubar=no,location=no);
}

function nova(accao,w,h)
{
	window.open('<?=$_SERVER[HTTPS]==on?$base:$URL?>'+accao,'<?=$LOGIN_USER?>',toolbar=no,width='+w+',height='+h+',directories=no,status=no,scrollbars=no,resizable=no,menubar=no,location=no);
}

function preview2(accao,w,h)
{
	window.open('<?=$_SERVER[HTTPS]==on?$base:$URL?>'+accao,'Imagem_<?=$LOGIN_USER?>',toolbar=no,width='+w+',height='+h+',directories=no,status=no,resizable=yes,menubar=yes,location=no);

}

function preview3(accao,w,h)
{
	window.open(accao,'Imagem_<?=$LOGIN_USER?>',toolbar=no,width='+w+',height='+h+',directories=no,status=no,resizable=yes,menubar=yes,location=no);

}

function ver_header(id_ficheiro, w, h){

	var largura = w;
	var altura = h;
	var screenX = screen.width;
	var screenY = screen.height;
	var winl;
	var wint;

	if (w > screenX){
		largura = screenX;
		if (h > screenY){
			altura = screenY;
			largura = (w * screenY) / (h);
		} else {
			altura = (h * screenX) / (w);
		}
	} else {
		largura = w;
		if (h > screenY){
			altura = screenY;
			largura = (w * screenY) / (h);
		} else {
			altura = h;
		}
	}

	winl = (screenX - largura) / 2;
	wint = (screenY - altura) / 2;

	winprops = 'height='+altura+',width='+largura+',top='+wint+',left='+winl+',status=no,toolbar=no,menubar=no,scrollbars=no,resizable=no,directories=no';
	win = window.open('imagem.php?imagem='+id_ficheiro+'&width='+w+'&height='+h,'', winprops);
	if (parseInt(navigator.appVersion) >= 4) win.window.focus();
}

function attachNewFile() {
	var targetDiv = document.getElementById('files_to_attach') ;
	anotherInputFile = document.createElement("input");
	anotherInputFile.setAttribute("type","file");
	anotherInputFile.setAttribute("class","campo_w380");
	anotherInputFile.setAttribute("name","filesToAttach[]");
	
	anotherSpace = document.createTextNode(" ");
	
	anotherInputText = document.createElement("input");
	anotherInputText.setAttribute("type","text");
	anotherInputText.setAttribute("class","campo_w380");
	anotherInputText.setAttribute("name","filesToAttachDescrition[]");
	
	anotherLine = document.createElement("br");
	
	targetDiv.appendChild( anotherInputFile ) ;
	targetDiv.appendChild( anotherSpace ) ;
	targetDiv.appendChild( anotherInputText ) ;
	targetDiv.appendChild( anotherLine ) ;
}

function MultiSelector( list_target){
	this.list_target = list_target;
	this.count = 0;
	this.id = 0;
	this.addElement = function( element ){
		if( element.tagName == 'INPUT' && element.type == 'file' ){
			element.name = 'file[]';
			element.className= 'bo_gestao_fich_file';
			element.multi_selector = this;element.onchange = function(){
				var new_element = document.createElement( 'input' );
				new_element.type = 'file';
				this.parentNode.insertBefore( new_element, this );
				this.multi_selector.addElement( new_element );
				this.multi_selector.addListRow( this );
				this.style.position = 'absolute';
				this.style.left = '-1000px';
			};
			this.count++;
			this.current_element = element;
		} else {
			alert( 'Error: not a file input element' );
		};
	};
	this.addListRow = function( element ){
		var new_row = document.createElement( 'div' );
		var new_row_button = document.createElement( 'input' );
		new_row_button.type = 'button';
		new_row_button.value = 'remover';
		new_row_button.className = 'bo_gestao_fich_texto';
		new_row.element = element;
		new_row_button.onclick= function(){
			this.parentNode.element.parentNode.removeChild(
			this.parentNode.element );
			this.parentNode.parentNode.removeChild( this.parentNode );
			this.parentNode.element.multi_selector.count--;
			this.parentNode.element.multi_selector.current_element.disabled = false;
			return false;
		};
		new_row.innerHTML = '<b>' + element.value + '</b>  ';
		new_row.appendChild( new_row_button );
		this.list_target.appendChild( new_row );
	};
};

function ver_cartao(){

	with (document.form_cartao) {
			method = "POST";
			action="cartao.php";
			jan = displayWindow('','cartao','241', '165','');
			target='cartao';
			submit();
		}

}

function displayWindow(theURL,winName,width,height,features) {

	var window_width = width;
    var window_height = height;
    var newfeatures= features;
    var window_top = (screen.height-window_height)/2;
    var window_left = (screen.width-window_width)/2;
    newWindow=window.open(''+ theURL + '',''+ winName + '','width=' + window_width + ',height=' + window_height + ',top=' + window_top + ',left=' + window_left + ',features=' + newfeatures + ',status=no,toolbar=no,menubar=no,scrollbars=no,resizable=no,directories=no');
    newWindow.focus();
}

function muda_seta(){
	obj = document.getElementById('seta');
	div = document.getElementById('texto');
	if(obj.value==0){
		obj.value=1;
		obj.src='../../ficheiro/interface/setas/seta_baixo.gif';
		div.style.display='block';
		window.resizeTo(250,420);
	}else{
		if(obj.value==1){
			obj.value=0;
			obj.src='../../ficheiro/interface/setas/seta_cima.gif';
			div.style.display='none';
			window.resizeTo(250,225);
		}
	}

}

function ver_comentario(id_coment){

	var screenX = screen.width;
	var screenY = screen.height;

	winl = (screenX - 500) / 2;
	wint = (screenY - 260) / 2;

	winprops = 'height=260,width=500,top='+wint+',left='+winl+',status=no,toolbar=no,menubar=no,scrollbars=no,resizable=no,directories=no';
	win = window.open('coment.php?coment='+id_coment,'', winprops);
	if (parseInt(navigator.appVersion) >= 4) win.window.focus();
}

function go(url){
	document.location.href=url;
}

function go_blank(url){
	newWindow=window.open(url);
    newWindow.focus();
}

function prepare_divs() {
	
	var data = document.getElementById("data");
	var navigation = document.getElementById("navigation");
	var dataHeight = data.offsetHeight;
	//alert(data.offsetHeight);

	navigation.style.height = (dataHeight-32) + "px";
		
}
