function abre_calendario(frm,name,e,home,admin)
{
	if (e != null && (e.keyCode==9 || e.tabKey)) { return true; }
	
	var form_name = frm;
	if (document.all && frm.attributes)
	{ form_name = frm.attributes('name').value; }
	else if (frm.getAttribute)
	{ form_name = frm.getAttribute('name'); }

	if (home == null) { home = "/"; }
	var argumentos = "form_name=" + form_name + "&name=" + name;
	if(admin != null){argumentos += '&admin=1';}
	var href = home + "common/calendar/calendario.html?" + argumentos;

	var araY=200;
	var araX=200;
	if (e != null)
	{ araX = e.screenX; araY = e.screenY - 150; }	

	var w=window.open(href,"selector","width=170,height=200,left=" + araX + ",top=" + araY);
	w.focus();
	return false;
}


function abre_time_picker(frm,name,e,home,admin)
{
	if (e != null && (e.keyCode==9 || e.tabKey)) { return true; }

	var form_name = frm;
	if (document.all && frm.attributes)
	{ form_name = frm.attributes('name').value; }
	else if (frm.getAttribute)
	{ form_name = frm.getAttribute('name'); }

	if (home == null) { home = "/"; }
	var argumentos = "form_name=" + form_name + "&name=" + name;
	if(admin != null){argumentos += '&admin=1';}
	var href = home + "common/time_picker/time_picker.html?" + argumentos;
	
	var araY=200;
	var araX=200;
	if (e != null)
	{
		if (document.all)
		{ araY=event.y - document.body.scrollTop; araX=event.x - document.body.scrollLeft; }
		else
		{ araX = e.screenX; araY = e.screenY - 150; }
	}	
	
	var w=window.open(href,"selector","width=190,height=140,left=" + araX + ",top=" + araY);
	w.focus();
	return false;
}


function abre_datetime_picker(frm,name,e,home,admin)
{
	if (e != null && (e.keyCode==9 || e.tabKey)) { return true; }

	var form_name = frm;
	if (document.all && frm.attributes)
	{ form_name = frm.attributes('name').value; }
	else if (frm.getAttribute)
	{ form_name = frm.getAttribute('name'); }

	if (home == null) { home = "/"; }
	var argumentos = "form_name=" + form_name + "&name=" + name;
	if(admin != null){argumentos += '&admin=1';}
	var href = home + "common/datetime_picker/datetime_picker.html?" + argumentos;
	
	var araY=200;
	var araX=200;
	if (e != null)
	{
		if (document.all)
		{ araY=event.y - document.body.scrollTop; araX=event.x - document.body.scrollLeft; }
		else
		{ araX = e.screenX; araY = e.screenY - 150; }
	}	

	var w=window.open(href,"selector","width=190,height=240,left=" + araX + ",top=" + araY + ",status=1");
	w.focus();
	return false;
}

function abre_remote_html_editor(frm,name,home,admin)
{
	var form_name = frm;
	if (document.all && frm.attributes)
	{ form_name = frm.attributes('name').value; }
	else if (frm.getAttribute)
	{ form_name = frm.getAttribute('name'); }

	if (home == null) { home = "/"; }
	var argumentos = "form_name=" + form_name + "&name=" + name;
	if(admin != null){argumentos += '&admin=1';}
	var href = home + "common/remote_html/editor.html?" + argumentos;
	var w=window.open(href,"remote_html_editor",
	  			  "width=470,height=235,left=200,top=60");
	w.focus();
	return false;
}

function abre_params_flash(frm,name,atr_params,home,admin)
{
	var form_name = frm;
	if (document.all && frm.attributes)
	{ form_name = frm.attributes('name').value; }
	else if (frm.getAttribute)
	{ form_name = frm.getAttribute('name'); }

	if (home == null) { home = "/"; }
	var argumentos = "form_name=" + form_name + "&name=" + name + "&params="+ atr_params;
	if(admin != null){argumentos += '&admin=1';}
	var href = home + "common/flash/editor.html?" + argumentos;
	var w=window.open(href,"params_flash","width=375,height=400,left=200,top=60");
	w.focus();
	return false;
}

function abre_html_editor(frm,name,ancho,alto,idvista,atributo,source,links,home,admin)
{
	var form_name = frm;
	if (document.all && frm.attributes)
	{ form_name = frm.attributes('name').value; }
	else if (frm.getAttribute)
	{ form_name = frm.getAttribute('name'); }

	if (home == null) { home = "/"; }
	var argumentos = "form_name=" + form_name + "&name=" + name + "&source=" + source +
			"&ebd_links=" + links;
	if(admin != null){argumentos += '&admin=1';}

	if (idvista != null && idvista > 0)
		argumentos += "&usar_vista=" + idvista;
	
	if (atributo != null && atributo.length > 0)
		argumentos += "&usar_atributo=" + atributo;

	var href = home + "common/html_editor/html_editor.html?"
				+ argumentos;
	var width=850;
	var height=600;

//	if (ancho != null && ancho > 100) width=ancho;
//	if (alto != null && alto > 100) height=alto;
	
	var w=window.open(href, "html_editor",
				"width=" + width + ",height=" + height + ",top=50,left=50,resizable=1,status=1");
	w.focus();
	return false;
}

function abre_new_html_editor(frm,name,ancho,alto,idvista,atributo,source,links,home,admin)
{
	var form_name = frm;
	if (document.all && frm.attributes)
	{ form_name = frm.attributes('name').value; }
	else if (frm.getAttribute)
	{ form_name = frm.getAttribute('name'); }

	if (home == null) { home = "/"; }
	var argumentos = "form_name=" + form_name + "&name=" + name + "&source=" + source +
			"&ebd_links=" + links;

	if(admin != null){argumentos += '&admin=1';}

	if (idvista != null && idvista > 0)
		argumentos += "&usar_vista=" + idvista;
	
	if (atributo != null && atributo.length > 0)
		argumentos += "&usar_atributo=" + atributo;

	var width=800;
	var height=550;

	if (ancho != null && ancho > 100) width=ancho;
	if (alto != null && alto > 100) height=alto;

	argumentos += "&ancho=" + width;
	argumentos += "&alto=" + height;
	width+=50;
	height+=50;
	var href = home + "common/new_html_editor/new_html_editor.html?"
				+ argumentos;
	
	var w=window.open(href, "html_editor",
				"width=" + width + ",height=" + height + ",top=50,left=50,resizable=1,status=1");
	w.focus();
	return false;
}


function abre_agregar_comentarios (id_objeto,es_relacion)
{
	if (id_objeto != null ){
		var href = "ver_comentarios.html?id="+id_objeto+"&es_relacion="+es_relacion ;
		var w=window.open(href,'opciones_editor','left=200,top=100,width=600,height=450,resizable=no,scrollbars=no');
		w.focus();
	}
	return false;
}


function abre_object_picker(home,type,form_name,name,type_adicional,name_adicional,callback)
{
	var width=320;
	
	var argumentos = 'type='+type+'&form_name='+form_name+'&name='+name;
	if (name_adicional != null && type_adicional != null)
	{
		argumentos += '&type_adicional='+type_adicional+'&name_adicional='+name_adicional;
		width=550;
	}
	if(callback != null)
	{
		argumentos += '&callback='+callback;	
	}
	var w=window.open(home+"common/object_picker/object_picker.html?"+argumentos,"object_picker","width="+width+",height=330,top=200,left=200");
	w.focus();
	return false;
}


function eBD_print(url)
{
	window.open(url,'imprimir','width=1,height=1,toolbar=0,directories=0,menubar=0,status=0,resizable=0,location=0,scrollbars=0,copyhistory=0,top=9000,left=9000');
}


function obrir(pag,amp,alc,dalt,esquerra,nom,toolbar,directories,menubar,status,resizable,location,scrollbars,copyhistory)
{
/*
	pag			PAGINA K HA D'OBRIR, no hay defecto debe pasarse por parametro
	amp			AMPLADA DE LA FINESTRA, defecto => 800
	alc			ALCADA DE LA FINESTRA, defecto => 600
	dalt			DISTANCIA DL TOP, defecto => 0
	esquerra		DISTANCIA D L'ESKERRA, defecto => 0
	nom			NOM DE LA FINESTRA, defecto => finestra
	toolbar		SI VOLS LA BARRA D'EINES, defecto => 1 k es 'si'
	directories		SI VOLS LOS FAVORITOS, defecto => 1 k es 'si'
	menubar		SI VOLS LA BARRA DLS MENUS, defecto => 1 k es 'si'
	status		SI VOLS LA BARRA D'STATUS, defecto => 1 k es 'si'
	resizable		SI VOLS K SIGUI ESCALABLE, defecto => 1 k es 'si'
	location		SI VOLS LA BARRA DE DIRECCIO, defecto => 1 k es 'si'
	scrollbars		SI VOLS SCROLLBARS, defecto => yes
	copyhistory		SI VOLS COPIA EL HISTORY D LA FINESTRA MARE, defecto => 1 k es 'si'
*/

	if(!(amp)){amp=screen.availWidth-15;}
	if(!(alc)){alc=screen.availHeight-25;}
	if(dalt == ''){dalt=0;}
	if(nom == ''){nom='finestra';}
	if(esquerra == ''){esquerra=1;}
	if(toolbar != 0){toolbar=1;}
	if(directories != 0){directories=1;}
	if(menubar != 0){menubar=1;}
	if(status != 0){status=1;}
	if(resizable != 0){resizable=1;}
	if(location != 0){location=1;}
	if(scrollbars != 'no'){scrollbars='yes';}
	if(copyhistory != 0){copyhistory=1;}
	finestra=eval("window.open('"+pag+"','"+nom+"','width="+amp+",height="+alc+",toolbar="+toolbar+",directories="+directories+",menubar="+menubar+",status="+status+",resizable="+resizable+",location="+location+",scrollbars="+scrollbars+",copyhistory="+copyhistory+",top="+dalt+",left="+esquerra+"')");
	finestra.focus();
	return false;
}

var resumen_calendario_activo=null;
function muestra_resumen_calendario(event,id)
{
	if (resumen_calendario_activo != null && resumen_calendario_activo.style != null)
	{ resumen_calendario_activo.style.visibility='hidden'; }
	
	var obj = document.getElementById(id);
	if (obj != null && obj.style != null)
	{
		resumen_calendario_activo=obj;
		obj.style.visibility='visible';
	}
}

function oculta_resumen_calendario(event,id)
{
	if (event == null) { event = window.event; }
	var obj = document.getElementById(id);
	if (obj != null)
	{
		var x = event.clientX;
		var y = event.clientY;
		
		var x0 = obj.offsetLeft - document.body.scrollLeft;
		var y0 = obj.offsetTop - document.body.scrollTop;
		var width = obj.clientWidth;
		var height = obj.clientHeight;		
	
		if ( x <= x0+2 || x >= x0+width || y <= y0+2 || y >= y0+height)
		{
		  obj.style.visibility='hidden';
		  resumen_calendario_activo=null;
		}
	}
}

function ocultaToolTip_formu(id)
{
	var obj = document.getElementById(id);
	if (obj != null)
	{
		obj.style.visibility='hidden';
	}
}

function muestraToolTip_formu(id)
{
	var x = event.x + document.body.scrollLeft + 5;
	var y = event.y + document.body.scrollTop + 5;
	
	var obj = document.getElementById(id);
	if (obj != null)
	{
		obj.style.left=x;
		obj.style.top=y;
		obj.style.visibility='visible';
	}
}

function quitar_div(tabla)
{
	var total_div=eval("total_div_"+tabla);
	eval('document.leyenda.ver_'+tabla+'.checked=false');
	if(total_div>0)
	{
		fer='hidden';
		if(eval('DivFill0_'+tabla+'.style.visibility') == 'hidden')
		{
			fer='visible';
			eval('document.leyenda.ver_'+tabla+'.checked=true');
		}
		else{eval('document.leyenda.ver_'+tabla+'.checked=false');}
		for(i=0;i<total_div;i++){eval('DivFill'+i+'_'+tabla+'.style.visibility = "'+fer+'"');}
	}

}
function canvi_url(query_string){document.location.href=query_string;}

function connect_chatroom(id,intro_nickname,error_nickname,conectando)
{	
	var b=false;
    var frm = document.getElementById("form_chat_"+id);
	if (frm == null) { return; }
	if (eval("document.chat"+id+"_active")) { return; }
	
	var nick = frm.nickname.value;
	if (nick != null && nick.length > 0)
	{ b=true; }
	else
	{
		var salir=false;
		while(!salir)
		{
			if (nick = prompt(intro_nickname))
			{ 
				if (nick.length < 20)
				{ frm.nickname.value=nick; b=true; salir=true; }
				else
				{
					alert(error_nickname);
				}
			}
			else
			{ salir=true; }
		}
	}
	if (b)
	{
		frm.message.value=conectando+'...';
		frm.action="/handlers/chat/login.html";
		frm.submit();
	}
}

function loginError(msg,id,nickname,descontecado,error_conexion)
{
	eval("document.chat"+id+"_active=false;");

    var frm = document.getElementById("form_chat_"+id);
	if (frm == null) { return; }

	frm.nickname.value=nickname;
	frm.message.value='-- '+desconectado+' --';
	alert(error_conexion+'\\n' + msg);
}

function loginOk(id)
{
    var frm = document.getElementById("form_chat_"+id);
	if (frm == null) { return; }
	
	eval("document.chat"+id+"_active=true;");

	frm.action="/handlers/chat/post.html";
	frm.message.disabled=false;
	frm.message.value='';
	frm.submit();
		
	var nickname=frm.nickname.value;
	
    var ifrm = document.getElementById("chatpost_"+id);
	if (ifrm != null)
	{ ifrm.src="/handlers/chat/post.html?id="+id; }

    ifrm = document.getElementById("chatdata_"+id);
	if (ifrm != null)
	{ ifrm.src="/handlers/chat/data.html?id="+id + "&nickname=" + nickname; }

	frm.message.focus();
}

function disconnect_chatroom(id,desconectado,nickname)
{
    var frm = document.getElementById("form_chat_"+id);
	if (frm == null) { return; }

	eval("document.chat"+id+"_active=false;");
	
	frm.message.value='-- '+desconectado+' --';
	frm.nickname.value=nickname;
	frm.message.disabled=true;
}

function go_private(username,id)
{
    var frm = document.getElementById("form_chat_"+id);
	if (frm == null) { return; }
	if (!eval("document.chat"+id+"_active")) { return; }
	
	var nickname = frm.nickname.value;
	var window_name = 'private_room_' + id + '_' + nickname + '_' + username
	
	var href = '/handlers/chat/private_room.html?id=' + id + '&nickname=' + frm.nickname.value + '&private_user=' + username;
	var w = window.open(href,window_name,'width=$pwidth,height=$pheight');
	
	w.focus();
}
