function openw(link, sx, sy, ev) {
	// Check if there is a keypress event
	if(ev && ev.type=='keypress') {
		var k= (ev.which)?ev.which:ev.keyCode;
		// only process return key
		if(k!=13) return true;
	}

	var url= link?link:'about:blank', w= sx, h= sy,
	    sw= screen.availWidth, sh= screen.availHeight, left=0, top=0;
	var options='toolbar=no,location=no,directories=no,status=yes,'+
	            'menubar=no,scrollbars=yes,resizable=yes,copyhistory=no';
	var page;

	if(sh>0) { if(h<0 || h>sh) h= sh; top= (sh-h)/2;}
	if(sw>0) { if(w<0 || w>sw) w= sw; left= (sw-w)/2;}

	if(window.outerWidth) { // Firefox, Opera
		options+=',top='+top+',left='+left+',outerWidth='+w+',outerHeight='+h;
	} else {
		options+=',top='+top+',left='+left+',width='+w+',heigth='+h;
	}
	var page= open(url,"DisplayWindow",options);
	if(page) page.focus();
	return false;
}
// Aux functions
function createF(url,w,h) {
	return function(event) {return openw(url,w,h,event?event:window.event);}
}
function setOpenWindow(exp,w,h) {
	var el= document.getElementById(exp), f;
	if(el) {
		f= createF(el.href,w,h);
		el.onclick=f;
		el.onkeypress=f;
	} else {
		var els= document.getElementsByTagName('a'), i,
		    rex= new RegExp(exp);
		for(i=0;i<els.length;i++) {
			el= els[i];
			if(el.id && rex.test(el.id)) {
				f= createF(el.href,w,h);
				el.onclick=f;
				el.onkeypress=f;
			}
		}
	}
}
function open_win(link, xSize, ySize) {
	openw(link,xSize,ySize);
}
function setOnLoad(func) {
	if(typeof func == 'string') eval('func=function(){ '+ func +' }');
	if(window.addEventListener) window.addEventListener('load',func,false);
	else if(document.addEventListener) document.addEventListener('load',func,false);
	else if(window.attachEvent) window.attachEvent('onload',func);
	else {
		var _load= window.onload;
		window.onload=_load?function(){_load();func();}:func;
	}
}

//Execute the body of a script tag.
//If name is undefined, execute the last script tag.
function execScriptTag(name) {
	var script;
	if(name) script= document.getElementById(name);
	else {
		script= document.getElementsByTagName("script");
		script= (script.length>0)?script[script.lenght-1]:null;
	}
	if(script) eval(script.innerHTML);
}



function openLastTab(exp) 
{
	document.getElementById(exp).setAttribute('class', 'marge fondocapsa_bottom lastdesplegat');
	document.getElementById(exp + 'Fletxa').setAttribute('src','/portal/images/menuUp.png');
}

function closeLastTab(exp) 
{
	document.getElementById(exp).setAttribute('class', 'marge fondocapsa_bottom lastplegat');
	document.getElementById(exp + 'Fletxa').setAttribute('src','/portal/images/menuDown.png');
}

function openCloseLastTab(exp)
{
	var element = document.getElementById(exp);
	if (element != null)
	{
		var classvalue = element.getAttribute('class');
		if (classvalue == 'marge fondocapsa_bottom lastdesplegat') closeLastTab(exp);
		else if (classvalue == 'marge fondocapsa_bottom lastplegat') openLastTab(exp);
	}
}
