//-----------------------------------------------------------------------------------//
function OcultarMenu()
{
	if (document.all)
	{
		if(document.getElementById('divarbol').style.visibility == 'hidden')
		{
			Visibilidad(document.getElementById('divarbol'), true);
			document.getElementById('divcontenido').style.width='74%';
			document.getElementById('divcontenido').style.left='260px';
			document.getElementById('imgocultar').src= 'img/ocultar.gif';
		}
		else
		{
			Visibilidad(document.getElementById('divarbol'), false);
			document.getElementById('divcontenido').style.width='99.5%';
			document.getElementById('divcontenido').style.left='5px';
			document.getElementById('imgocultar').src= 'img/expandir.gif';
		}
	}
	else
	{
		if(document.getElementById('divarbol').style.visibility == 'hidden')
		{
			Visibilidad(document.getElementById('divarbol'), true);
			document.getElementById('divcontenido').style.width='74%';
			document.getElementById('divcontenido').style.left='260px';
			document.getElementById('imgocultar').src= 'img/ocultar.gif';
		}
		else
		{
			Visibilidad(document.getElementById('divarbol'), false);
			document.getElementById('divcontenido').style.width='99.5%';
			document.getElementById('divcontenido').style.left='5px';
			document.getElementById('imgocultar').src= 'img/expandir.gif';
		}
	}
}
//-----------------------------------------------------------------------------------//
function CambiarCapa(nom_capa)
{
	//alert('entroooooo');
        var Divs = document.body.getElementsByTagName("DIV");
        for(var i = 0; i < Divs.length; i++)
        {
        	if(Divs[i].id == 'botones' && nom_capa == 'internet')
             		Divs[i].style.top = '330px';
             	if(Divs[i].id == 'botones' && nom_capa == 'edicion')
             		Divs[i].style.top = '';
             	if(Divs[i].id != nom_capa && Divs[i].id != 'botones')
             	{
               		Divs[i].style.visibility = 'hidden';
             	}
             	else
             	{
               		Divs[i].style.visibility = 'visible';
               		if(Divs[i].id == 'internet')
               			Divs[i].style.top = '120px';
               }
	}
        if(nom_capa == 'internet')
        {
        	document.getElementById('pestanainternet').className='pestanaresaltada';
              	document.getElementById('pestanaedicion').className='pestana';
        }
        else
        {
           	document.getElementById('pestanainternet').className='pestana';
              	document.getElementById('pestanaedicion').className='pestanaresaltada';
        }
}
//-----------------------------------------------------------------------------------//
function EnviarDatos(accion, validar,clase)
{
	if(validar)
	{
		if(ValidarFormulario(document.getElementById('formulario')))
		{
			document.getElementById('accion').value = accion;
			document.getElementById('clase').value=clase;
			document.formulario.submit();
		}
		else
			alert('Debe completar los campos con *');
	}
	else
	{
		document.getElementById('accion').value = accion;
		document.getElementById('clase').value = clase;
		document.formulario.submit();
	}
}
//-----------------------------------------------------------------------------------//
function ComprobarCampos(accion,validar,clase)
{
	var elemento;
        var encontrado = false;
  	for (i = 0; i < document.getElementById('formulario').length && !encontrado; i++)
	{
        	elemento = document.getElementById('formulario').elements[i];
        	
                if ((Trim(elemento.value).length) > 0 && elemento.type != 'hidden')
                {
                  var encontrado = true
                }
	}
        if(encontrado)
		EnviarDatos(accion,validar,clase);
        else
        	alert('Debe introducir algún campo')
}
//-----------------------------------------------------------------------------------//
function reloj()
{
	var Digital=new Date()
	var day=Digital.getDate()
	var month=Digital.getMonth()+1
	var year=Digital.getFullYear()
	var hours=Digital.getHours()
	var minutes=Digital.getMinutes()
	var seconds=Digital.getSeconds()

	if (hours==0)   { hours=12; }
	if (minutes<=9) { minutes="0"+minutes }
	if (seconds<=9) { seconds="0"+seconds }
	if (day<=9)     { day="0"+day }
	if (month<=9)   { month="0"+month }

	var cdate=day+' - '+mes(month)+' - '+year
	var ctime=hours+":"+minutes+":"+seconds
	document.getElementById("reloj").innerHTML=""+cdate+" "+ctime+""
	setTimeout("reloj()",1000)
}
//-----------------------------------------------------------------------------------//
function mes(strMes)
{
	if(strMes==1)  { return "Enero" }
	if(strMes==2)  { return "Febrero" }
	if(strMes==3)  { return "Marzo" }
	if(strMes==4)  { return "Abril" }
	if(strMes==5)  { return "Mayo" }
	if(strMes==6)  { return "Junio" }
	if(strMes==7)  { return "Julio" }
	if(strMes==8)  { return "Agosto" }
	if(strMes==9)  { return "Septiembre" }
	if(strMes==10) { return "Octubre" }
	if(strMes==11) { return "Noviembre" }
	if(strMes==12) { return "Diciembre" }
}
//-----------------------------------------------------------------------------------//
function AdaptarResolucion()
{
	var ancho=screen.width;
      	var alto=screen.height;

	switch (ancho)
	{
		case (640):
			alto = 200;
		break;
		default:
			alto = alto*0.65;
	}
	return alto;
}
//------------------------------------------------------------------------------------------
function MostrarImagen(fra_imagen, fra_texto)
{
  try
  {
        //alert('file imagen ->' + document.getElementById('formulario').files.options[document.getElementById('formulario').files.selectedIndex].text +' ; file texto ->' + document.getElementById('formulario').files.options[document.getElementById('formulario').files.selectedIndex].value );
        //AbrirVentanaTarget(document.getElementById('formulario').files.options[document.getElementById('formulario').files.selectedIndex].text,600,600,fra_texto);
        //AbrirVentanaTarget(document.getElementById('formulario').files.options[document.getElementById('formulario').files.selectedIndex].value,600,600,fra_imagen);
        //var a = document.getElementById(fra_imagen);
        //a.innerHTML = '<iframe id="frameImagen" frameborder="1" name="frameImagen" src="file://c:\\004.jpg" height="350" width="100%"></iframe>';
	document.getElementById(fra_imagen).src = 'file://' +  document.getElementById('formulario').files.options[document.getElementById('formulario').files.selectedIndex].value;
	document.getElementById(fra_texto).src = 'file://' +  document.getElementById('formulario').files.options[document.getElementById('formulario').files.selectedIndex].id;
	//alert('file imagen ->' + document.getElementById(fra_imagen).src +' ; file texto ->' + document.getElementById(fra_texto).src );
        indice = document.getElementById('formulario').files.selectedIndex;
       	document.getElementById('siguiente').href="javascript:SiguienteImagen('frameImagen','frameTexto');";
       	document.getElementById('anterior').href="javascript:AnteriorImagen('frameImagen','frameTexto');";
        Visibilidad(document.getElementById('siguiente'),true);
        Visibilidad(document.getElementById('anterior'),true);
        Visibilidad(document.getElementById('files'),true);
        Visibilidad(document.getElementById('ficheros'),true);
        Visibilidad(document.getElementById('img_descargar'),false);
  }
  catch(e)
  {
    alert(e.message);
  }
}
//------------------------------------------------------------------------------------------
function SiguienteImagen(fra_imagen, fra_texto)
{
	indice++;
	if(indice < document.getElementById('formulario').files.options.length)
	{
		document.getElementById(fra_imagen).src = 'file://' +  document.formulario.files.options[indice].value;
		document.getElementById(fra_texto).src = 'file://' +  document.formulario.files.options[indice].id	;
	}
	else
	{
		alert('Ha llegado al final de la lista');
		indice = 0;
		document.getElementById(fra_imagen).src = 'file://' +  document.getElementById('formulario').files.options[indice].value;
		document.getElementById(fra_texto).src = 'file://' +  document.getElementById('formulario').files.options[indice].id;
	}
	document.getElementById('formulario').files.options[indice].selected = true;
}
//------------------------------------------------------------------------------------------
function AnteriorImagen(fra_imagen, fra_texto)
{
  if(indice > 0)
  {
	indice--;
	if(indice < document.getElementById('formulario').files.options.length)
	{
		document.getElementById(fra_imagen).src = 'file://' +  document.formulario.files.options[indice].value;
		document.getElementById(fra_texto).src = 'file://' +  document.formulario.files.options[indice].id;
	}
	document.getElementById('formulario').files.options[indice].selected = true;
  }
}
//------------------------------------------------------------------------------------------
function addFile(fileImagen,fileTexto)
{
  	//alert('file imagen = ' + fileImagen + ' , file texto = ' + fileTexto + ' , length = ' +document.formulario.files.length);
	document.getElementById('formulario').files.options[document.formulario.files.length] = new Option(fileImagen.substring(fileImagen.lastIndexOf('\\') + 1,fileImagen.length) ,fileImagen,false,true);
      	document.getElementById('formulario').files.options[document.formulario.files.length - 1].id = fileTexto;
	document.getElementById('formulario').files.options[0].selected = true;
}
//------------------------------------------------------------------------------------------
function clearFiles()
{
	Visibilidad(document.getElementById('img_descargar'),true);
	document.getElementById('formulario').files.options.length = 0;
}
//------------------------------------------------------------------------------------------
function numFiles(num)
{
	if(document.getElementById('formulario').files.length <= num)
        {
        	document.getElementById('formulario').files.size = document.formulario.files.length;
        }
	else
	{
		document.getElementById('formulario').files.size = num;
	}
       	document.getElementById('siguiente').href="javascript:SiguienteImagen('frameImagen','frameTexto');";
       	document.getElementById('anterior').href="javascript:AnteriorImagen('frameImagen','frameTexto');";
       // Visibilidad(document.getElementById('siguiente'),true);
        //Visibilidad(document.getElementById('anterior'),true);
}
//------------------------------------------------------------------------------------------
function CambiarTamano(tam_actual)
{
	if(tam_actual == '1%')
	{
		return '25%';
	}
	else
	{
		return '1%';
	}
}

//------------------------------------------------------------------------------------------
function AnadirDatoDefecto (nom_campo, codigoDato)
{
  AbrirVentana2('../dato_defecto.jsp?clase=es.intecna.xml.estructura.DatoDefecto&cod_dato=' +codigoDato + '&nom_campo=' + nom_campo +'&accion=&emergente=true', 500, 150);
}
//------------------------------------------------------------------------------------------
function SeleccionarDatoDefecto (nom_campo, codigoDato)
{
  AbrirVentana2('../lista_datos_defecto.jsp?clase=es.intecna.xml.estructura.Dato&cod_dato=' +codigoDato + '&nom_campo=' + nom_campo +'&accion=leer&emergente=true', 600, 500);
}
//------------------------------------------------------------------------------------------
function FuncionLista(valor, nom_campo)
{
  window.opener.RellenarCampo(nom_campo,valor);
  Cerrar();
}
//------------------------------------------------------------------------------------------
function seleccionarTodos(nom_checkbox)
{
	for (var i=0; i < document.getElementById('formulario').length; i++)
        {
          	var elemento = document.getElementById('formulario').elements[i];
                if(elemento.type == 'checkbox' && elemento.name.toString().indexOf(nom_checkbox) >= 0)
                {
                	elemento.checked = true;
        	}
	}
}
//------------------------------------------------------------------------------------------
function desseleccionarTodos(nom_checkbox)
{
	for (var i=0; i < document.getElementById('formulario').length; i++)
        {
          	var elemento = document.getElementById('formulario').elements[i];
                if(elemento.type == 'checkbox' && elemento.name.toString().indexOf(nom_checkbox) >= 0)
                {
                	elemento.checked = false;
        	}
	}
}
//------------------------------------------------------------------------------------------
function Selector(nom_checkbox)
{
	if(document.getElementById('selector').checked)
        	seleccionarTodos(nom_checkbox);
        else
        	desseleccionarTodos(nom_checkbox);
}
//------------------------------------------------------------------------------------------
function CambiaPermiso(imagen, hast, tipoOperacion, codigoTipoOperacionEnte)
{
  var permisosTipoEnte = hast.get(tipoOperacion);
  if(permisosTipoEnte[2] == '1')
  	permisosTipoEnte[2] = '0'
  else
	permisosTipoEnte[2] = '1'
  permisosTipoEnte[3] = codigoTipoOperacionEnte;
  if(permisosTipoEnte[0] == '0')
  {
    permisosTipoEnte[0] = '1';
    hast.put(tipoOperacion, permisosTipoEnte);
    imagen.src = 'img/ok.gif';
    imagen.alt = 'Permiso concedido';
  }
  else
  {
    permisosTipoEnte[0] = '0';
    hast.put(tipoOperacion, permisosTipoEnte);
    imagen.src = 'img/denegar.gif';
    imagen.alt = 'Permiso denegado';
  }
  //alert(hast.toString());
  return hash;
}
//------------------------------------------------------------------------------------------
function GuardarPermisos(hash, accion)
{
  var codigoUsuario = document.getElementById('cod_usuario').value;
  var codigoGrupo = document.getElementById('cod_grupo').value;
  var codigosTiposOperaciones = hash.keys();
  var numeroAlteraciones = 0;
  document.getElementById('cod_tip_operacion').value = '';
  document.getElementById('cod_usu_tip_ope_ente').value = '';
  document.getElementById('cod_tip_ente').value = '';
  document.getElementById('cod_ente').value = '';
  document.getElementById('per_denegados').value = '';
  document.getElementById('cod_usuario').value = '';
  document.getElementById('cod_grupo').value = '';

  for(var i = 0; i < codigosTiposOperaciones.length; i++)
  {
    var permisoTipoEnte = hash.get(codigosTiposOperaciones[i])
    if(permisoTipoEnte[2] == '1')
    {
      numeroAlteraciones++;
      document.getElementById('cod_tip_operacion').value += codigosTiposOperaciones[i] + '/~/'
      document.getElementById('cod_tip_ente').value += permisoTipoEnte[1] + '/~/'
      document.getElementById('cod_ente').value += permisoTipoEnte[4] + '/~/'
      document.getElementById('cod_usu_tip_ope_ente').value += permisoTipoEnte[3] + '/~/'
      document.getElementById('cod_gru_tip_ope_ente').value += permisoTipoEnte[3] + '/~/'
      document.getElementById('cod_usuario').value += codigoUsuario + '/~/';
      document.getElementById('cod_grupo').value += codigoGrupo + '/~/';
    }
  }
  if(numeroAlteraciones > 0)
  {
    if (codigoUsuario > 0)
    {
	document.getElementById('clase').value = 'es.intecna.administracion.estructura.UsuarioTipoOperacionEnte';
	document.getElementById('cla_padre').value = 'es.intecna.administracion.estructura.UsuarioTipoOperacionEnte';
    }
    else
    {
      	document.getElementById('clase').value = 'es.intecna.administracion.estructura.GrupoTipoOperacionEnte';
	document.getElementById('cla_padre').value = 'es.intecna.administracion.estructura.GrupoTipoOperacionEnte';
    }

    document.getElementById('accion').value = accion;

  /*alert('TipoOperacion: ' + document.getElementById('cod_tip_operacion').value);
  alert('TipoEnte: ' + document.getElementById('cod_tip_ente').value);
  alert('CodigoEnte: ' + document.getElementById('cod_ente').value);
  alert('Id_USU: ' + document.getElementById('cod_usu_tip_ope_ente').value);
  alert('Id_gru: ' + document.getElementById('cod_usu_tip_ope_ente').value);
  alert('CodigoUsuario: ' + document.getElementById('cod_usuario').value);
  alert('Codigogrupo: ' + document.getElementById('cod_grupo').value);*/


    document.getElementById('formulario').submit();
  }
  else
  {
    document.getElementById('cod_usuario').value = codigoUsuario;
    document.getElementById('cod_grupo').value = codigoGrupo;
    alert('No se ha alterado ningún permiso');
  }
}
//------------------------------------------------------------------------------------------
function CambiaPermisoEnte(imagen, hast, tipoOperacion, codigoTipoOperacionEnte, condigoEnte)
{
  var permisosTipoEnte = hast.get(tipoOperacion+'-'+condigoEnte);
  if(permisosTipoEnte[2] == '1')
  	permisosTipoEnte[2] = '0'
  else
	permisosTipoEnte[2] = '1'
  permisosTipoEnte[3] = codigoTipoOperacionEnte;
  if(permisosTipoEnte[0] == '0')
  {
    permisosTipoEnte[0] = '1';
    hast.put(tipoOperacion+'-'+condigoEnte, permisosTipoEnte);
    imagen.src = 'img/ok.gif';
    imagen.alt = 'Permiso concedido';
  }
  else
  {
    permisosTipoEnte[0] = '0';
    hast.put(tipoOperacion+'-'+condigoEnte, permisosTipoEnte);
    imagen.src = 'img/denegar.gif';
    imagen.alt = 'Permiso denegado';
  }
  //alert(hast.toString());
  return hash;
}
//------------------------------------------------------------------------------------------
function GuardarPermisosEnte(hash, accion)
{
  var codigoUsuario = document.getElementById('cod_usuario').value;
  var codigoGrupo = document.getElementById('cod_grupo').value;
  var codigosTiposOperaciones = hash.keys();
  var numeroAlteraciones = 0;
  document.getElementById('cod_tip_operacion').value = '';
  document.getElementById('cod_usu_tip_ope_ente').value = '';
  document.getElementById('cod_tip_ente').value = '';
  document.getElementById('cod_ente').value = '';
  document.getElementById('per_denegados').value = '';
  document.getElementById('cod_usuario').value = '';
  document.getElementById('cod_grupo').value = '';

  for(var i = 0; i < codigosTiposOperaciones.length; i++)
  {
    var permisoTipoEnte = hash.get(codigosTiposOperaciones[i])
    if(permisoTipoEnte[2] == '1')
    {
      numeroAlteraciones++;
      document.getElementById('cod_tip_operacion').value += codigosTiposOperaciones[i].split('-')[0] + '/~/'
      document.getElementById('cod_tip_ente').value += permisoTipoEnte[1] + '/~/'
      document.getElementById('cod_ente').value += permisoTipoEnte[4] + '/~/'
      document.getElementById('cod_usu_tip_ope_ente').value += permisoTipoEnte[3] + '/~/'
      document.getElementById('cod_gru_tip_ope_ente').value += permisoTipoEnte[3] + '/~/'
      document.getElementById('cod_usuario').value += codigoUsuario + '/~/';
      document.getElementById('cod_grupo').value += codigoGrupo + '/~/';
    }
  }
  if(numeroAlteraciones > 0)
  {
    if (codigoUsuario > 0)
    {
	document.getElementById('clase').value = 'es.intecna.administracion.estructura.UsuarioTipoOperacionEnte';
	document.getElementById('cla_padre').value = 'es.intecna.administracion.estructura.UsuarioTipoOperacionEnte';
    }
    else
    {
      	document.getElementById('clase').value = 'es.intecna.administracion.estructura.GrupoTipoOperacionEnte';
	document.getElementById('cla_padre').value = 'es.intecna.administracion.estructura.GrupoTipoOperacionEnte';
    }

    document.getElementById('accion').value = accion;
    document.getElementById('formulario').submit();
  }
  else
  {
    document.getElementById('cod_usuario').value = codigoUsuario;
    document.getElementById('cod_grupo').value = codigoGrupo;
    alert('No se ha alterado ningún permiso');
  }
}
//------------------------------------------------------------------------------------------
function RellenarIdioma(nom_input)
{

  var idiomas = '';
  var campo = eval("document.getElementById('"+nom_input+"')");
  campo.value = '';
  for(var i = 0; i < campo.options.length; i++)
  {
    //alert('entro->' + campo.options[i].text + ', selected ->' + campo.options[i].selected);
    if(campo.options[i].selected == true)
    {
	    idiomas += campo.options[i].value + ',';
            campo.options[i].selected = true;
    }
  }
  if(idiomas.length > 0)
  	idiomas = idiomas.substring(0,idiomas.length -1);
  document.getElementById('idiomas').value = idiomas;
  //alert(document.getElementById('idiomas').value);

}
//------------------------------------------------------------------------------------------
function Seleccionar (id, nombre, apellidos, nom_cam_nombre, nom_cam_codigo)
{

  if(window.opener != null)
  {
    if(window.opener.document.getElementById(nom_cam_nombre) != null && window.opener.document.getElementById(nom_cam_codigo) != null)
    {
      if(Trim(window.opener.document.getElementById(nom_cam_nombre).value).length > 0)
      {
      	window.opener.document.getElementById(nom_cam_nombre).value += '; ' + nombre + ' ' + apellidos;
      }
      else
      {
        window.opener.document.getElementById(nom_cam_nombre).value = nombre + ' ' + apellidos;
      }
      window.opener.document.getElementById(nom_cam_codigo).value += '/~/ ' + id;
    }
  }
}
//------------------------------------------------------------------------------------------
function SeleccionarDestinatario(email, nom_cam_email)
{
 if(window.opener != null)
  {
    if(window.opener.document.getElementById(nom_cam_email) != null)
    {
      if(Trim(window.opener.document.getElementById(nom_cam_email).value).length > 0)
      {
      	if(email != 'null')
      		window.opener.document.getElementById(nom_cam_email).value += '; ' + email;
      }
      else
      {
      	if(email != 'null')
        	window.opener.document.getElementById(nom_cam_email).value = email;
      }
    }
  }
}
//------------------------------------------------------------------------------------------
function NextFile()
{

	var coll = document.getElementsByName("file"+indice);
      	indice++;
      	var LatestFile = coll[coll.length - 1];
      	var objBr = document.createElement("<br>");
      	LatestFile.insertAdjacentElement("afterEnd", objBr);
      	var objFile = document.createElement('<input type="file" name="file'+indice+'" onchange="NextFile()" size="63" ID="file'+indice+'">');
      	objBr.insertAdjacentElement("afterEnd", objFile);
      	document.getElementById("num_adjuntos").value = indice;
}
//------------------------------------------------------------------------------------------
function Responder(cod_mensaje, receptor, cod_receptor, asunto)
{
    	AbrirVentana2('mensaje.jsp?accion=&cla_padre=es.intecna.mensajeria.estructura.Mensaje&mos_formulario=true&relacion=cod_mensaje&clase=es.intecna.mensajeria.estructura.Mensaje&cod_mensaje=0&id_padre='+ cod_mensaje + '&noms_usuarios=' + receptor + '&cod_receptores=' + cod_receptor + '&asunto=RE: ' + asunto ,600,600);
}
//-----------------------------------------------------------------------------------//
function OcultarMostrarRecurso(n_idiomas, new_idioma, cod_idioma)
{

		// Establecemos pestaña resaltada junto a visibilidad del formulario
		for(var i=0; i<=n_idiomas; i++){
			Visibilidad(document.getElementById('div'+i), false);
			document.getElementById('pestana'+i).className = "pestana";
			document.getElementById('pestana'+i).style.cursor = "pointer";
		}
		Visibilidad(document.getElementById('div'+new_idioma), true);
		document.formulario.cod_idioma_aux.value = cod_idioma;
		document.getElementById('pestana'+new_idioma).className = "pestanaresaltada";
		document.getElementById('pestana'+new_idioma).style.cursor = "default";


		// Establecimiento de campos obligatorios
		if (cod_idioma == 0){
			document.getElementById('nom_recurso_aux_0').etiqueta="*Nombre";
			document.getElementById('ruta_aux_0').etiqueta="*Ruta";
			document.getElementById('cod_tip_recurso_aux_0').etiqueta="*Tipo de recurso";

			for(var i=1; i<=n_idiomas; i++){
				document.getElementById('nom_recurso_aux_'+i).etiqueta="Nombre";
				document.getElementById('ruta_aux_'+i).etiqueta="Ruta";
				document.getElementById('cod_tip_recurso_aux_'+i).etiqueta="Tipo de recurso";
			}
		}
		else if  (cod_idioma>0){
			document.getElementById('nom_recurso_aux_0').etiqueta="Nombre";
			document.getElementById('ruta_aux_0').etiqueta="Ruta";
			document.getElementById('cod_tip_recurso_aux_0').etiqueta="Tipo de recurso";
			for(var i=1; i<=n_idiomas; i++){
				document.getElementById('nom_recurso_aux_'+i).etiqueta="*Nombre";
				document.getElementById('ruta_aux_'+i).etiqueta="*Ruta";
				document.getElementById('cod_tip_recurso_aux_'+i).etiqueta="*Tipo de recurso";
			}
		}
}
//-----------------------------------------------------------------------------------//
function CopiarEntradas(n_idiomas, cod_idiomas) {

    	// Declaraciones
    	var temp = new Array();
        var cod_recurso;
	var id_recurso;
    	var fec_alta;
    	var cod_estado;

	// Compruebo si anteriormente se ha producido una concatenacion
        temp = (document.getElementById('cod_recurso').value).split('/~/');

    	// Si no se ha producido concatenacion anterior la realizo para los campos no introducidos en formulario
    	if(temp.length==1)
        {
    		cod_recurso = document.getElementById('cod_recurso').value;
    		id_recurso = document.getElementById('id_recurso').value;
    		fec_alta = document.getElementById('fec_alta').value;
    		cod_estado = document.getElementById('cod_estado').value;

    		for (var i=2; i<=n_idiomas; i++)
                {
    			document.getElementById('cod_recurso').value=document.getElementById('cod_recurso').value+"/~/"+cod_recurso;
    			document.getElementById('id_recurso').value=document.getElementById('id_recurso').value+"/~/"+id_recurso;
    			document.getElementById('fec_alta').value=document.getElementById('fec_alta').value+"/~/"+fec_alta;
    			document.getElementById('cod_estado').value=document.getElementById('cod_estado').value+"/~/"+cod_estado;
    		}
    	}
    	document.getElementById('cod_idioma').value = cod_idiomas;

    	// Concateno los campos introducidos dependiendo del idioma
    	if(document.formulario.cod_idioma_aux.value==0)
        {
    		// Seleccionada la pestaña 'Todos'
    		document.getElementById('nom_recurso').value=document.getElementById('nom_recurso_aux_0').value;
    		document.getElementById('ruta').value=document.getElementById('ruta_aux_0').value;
    		document.getElementById('cod_tip_recurso').value=document.getElementById('cod_tip_recurso_aux_0').value;

    		for (var i=2; i<=n_idiomas; i++)
                {
    			document.getElementById('nom_recurso').value=document.getElementById('nom_recurso').value+"/~/"+
    			document.getElementById('nom_recurso_aux_0').value;
    			document.getElementById('ruta').value=document.getElementById('ruta').value+"/~/"+
    			document.getElementById('ruta_aux_0').value;
    			document.getElementById('cod_tip_recurso').value=document.getElementById('cod_tip_recurso').value+"/~/"+
    			document.getElementById('cod_tip_recurso_aux_0').value;
    		}
    	}
    	else
        {
    		// Seleccionada la pestaña de un idioma
    		document.getElementById('nom_recurso').value=document.getElementById('nom_recurso_aux_1').value;
    		document.getElementById('ruta').value=document.getElementById('ruta_aux_1').value;
    		document.getElementById('cod_tip_recurso').value=document.getElementById('cod_tip_recurso_aux_1').value;

    		for (var i=2; i<=n_idiomas; i++)
                {
    			document.getElementById('nom_recurso').value=document.getElementById('nom_recurso').value+"/~/"+
    			document.getElementById('nom_recurso_aux_'+i).value;
    			document.getElementById('ruta').value=document.getElementById('ruta').value+"/~/"+
    			document.getElementById('ruta_aux_'+i).value;
    			document.getElementById('cod_tip_recurso').value=document.getElementById('cod_tip_recurso').value+"/~/"+
    			document.getElementById('cod_tip_recurso_aux_'+i).value;
    		}
    	}
}
//-----------------------------------------------------------------------------------//

function AnadirDocumentoRelacionado(cod_documento, url)
{
	AbrirEnVentana(url+'&id_relacion=&accion=crear&clase=es.intecna.documento.estructura.DocumentoRelacionado&id_doc_relacionado='+cod_documento);
}
//------------------------------------------------------------------------------
function AnadirParticipanteRelacionado(parametros, url)
{
	var parametrosResultantes = parametros.split('/~/');
	if(parametrosResultantes[4]=='null')
		parametrosResultantes[4] = '';
	if(parametrosResultantes[1]=='null')
		parametrosResultantes[1] = '';
	if(parametrosResultantes[2]=='null')
		parametrosResultantes[2] = '';
	if(parametrosResultantes[3]=='null')
		parametrosResultantes[3] = '';
	if(parametrosResultantes[5] =='null')
		parametrosResultantes[5]='';
	AbrirEnVentana(url+'&clase=es.intecna.proyecto.estructura.Participante&nom_participante='+parametrosResultantes[1]+'&ape_participante='+parametrosResultantes[2]+'&entidad='+parametrosResultantes[3]+'&email='+parametrosResultantes[4]+'&telefono='+parametrosResultantes[5]);
	//AbrirEnVentana(url+'&cod_gru_tra_participante=&accion=crear&clase=es.intecna.proyecto.estructura.GrupoTrabajoParticipante&cod_participante='+cod_participante);
}
//------------------------------------------------------------------------------
function AnadirTareaIntegrante(cod_tarea, url)
{
	AbrirEnVentana(url+'&accion=crear&cod_tar_integrante=&clase=es.intecna.proyecto.estructura.TareaIntegrante&cod_tarea='+cod_tarea);
}
//------------------------------------------------------------------------------
function AnadirTareaPredecesora(cod_tarea, url)
{
	AbrirEnVentana(url+'&accion=crear&cod_rel_tar_predecesora=&clase=es.intecna.proyecto.estructura.TareaPredecesora&cod_tar_predecesora='+cod_tarea);
}
//------------------------------------------------------------------------------
function AnadirIntegranteRelacionado(parametros, url)
{
	var parametrosResultantes = parametros.split('/~/');
	if(parametrosResultantes[0]=='null')
		parametrosResultantes[0] = '';
	if(parametrosResultantes[1]=='null')
		parametrosResultantes[1] = '';
	if(parametrosResultantes[2]=='null')
		parametrosResultantes[2] = '';
	AbrirEnVentana(url+'&clase=es.intecna.proyecto.estructura.Integrante&cod_participante='+parametrosResultantes[0]+'&nombre='+parametrosResultantes[1]+'&apellidos='+parametrosResultantes[2]+'&entidad='+parametrosResultantes[3]);
}
//--------------------------------------------------------------------------------
function AnadirParticipanteLdap(parametros)
{
	var parametrosResultantes = parametros.split('/~/');
	window.opener.document.formulario.nom_participante.value=parametrosResultantes[0];
	if(parametrosResultantes[1]!='null')
		window.opener.document.formulario.ape_participante.value=parametrosResultantes[1];
	if(parametrosResultantes[2]!='null')
		window.opener.document.formulario.telefono.value=parametrosResultantes[2];
	if(parametrosResultantes[3] !='null')
		window.opener.document.formulario.email.value=parametrosResultantes[3];
	window.opener.document.formulario.nom_participante.focus();
/*	if(parametrosResultantes[1].length > 0)
	{
		var cadena = parametrosResultantes[0].toLowerCase()+'.'+parametrosResultantes[1].toLowerCase();
		cadena = ReplaceAll(cadena," ",".");
		window.opener.document.formulario.usu_ldap.value=cadena;
	}
	else
	{
		var cadena = parametrosResultantes[0].toLowerCase();
		cadena = ReplaceAll(cadena," ",".");
		window.opener.document.formulario.usu_ldap.value=cadena;
	}*/
	self.close();
}

//------------------------------------------------------------------------------
function AnadirResponsableDocumento(url, nom_input)
{

	var elemento;
	var campo;
	campo = eval('document.formulario.' + nom_input);
	campo.value = '';

	for (i = 0; i < document.getElementById('formulario').length; i++)
	{
			elemento = document.getElementById('formulario').elements[i];
			if (elemento.name.length > campo.name.length)
			{
				if (elemento.name.substring(0, campo.name.length) == campo.name && elemento.checked)
					campo.value = campo.value + '/~/' + elemento.value;
			}
   }
   if (campo.value.length > 0)
   {
		campo.value = campo.value.substring(3, campo.value.length);
		AbrirEnVentana(url+'&id_relacion=&accion=crear&clase=es.intecna.documento.estructura.DocumentoResponsable&id_responsable=&id_usuario='+campo.value);
   }
   else
   {
      alert('Debe seleccionar un usuario');
   }

}
//------------------------------------------------------------------------------
function EliminarParticipante(nom_ente, nom_input, cla_padre, paginacion)
{
	var elemento;
	var campo;
	var confirmar;
	campo = eval('document.formulario.' + nom_input);
	campo.value = '';

	for (i = 0; i < document.getElementById('formulario').length; i++)
	{
		elemento = document.getElementById('formulario').elements[i];
		//alert(elemento.name+' '+campo.name);
		if (elemento.name.length > campo.name.length)
		{
			if (elemento.name.substring(0, campo.name.length) == campo.name && elemento.checked)
				campo.value = campo.value + '/~/' + elemento.value;
		}
    }
    if (campo.value.length > 0)
    {
         var mensaje;
		mensaje = '¿Está seguro de eliminar el(los) objeto(s)?';
		confirmar = confirm(mensaje);
		if (confirmar == true)
		{
			mensaje = '¿Desea eliminar el participante de todos los grupos de trabajo?'
			confirmar = confirm(mensaje);
			if(confirmar == true)
				document.getElementById('eli_completo').value = true;
			else
				document.getElementById('eli_completo').value = false;
			campo.value = campo.value.substring(3, campo.value.length);
			document.getElementById('accion').value = 'eliminar';
            document.getElementById('clase').value = nom_ente;
            document.getElementById('cla_padre').value = cla_padre;
			document.getElementById(nom_input).value = campo.value;
            document.getElementById(paginacion).value = 0;
			document.formulario.submit();
		}
    }
    else
    {
        alert('Debe seleccionar un objeto');
    }


}
//------------------------------------------------------------------------------
function EliminarDocumento(nom_ente, nom_input, cla_padre, paginacion)
{
	var elemento;
	var campo;
	var confirmar;
	campo = eval('document.formulario.' + nom_input);
	campo.value = '';

	for (i = 0; i < document.getElementById('formulario').length; i++)
	{
		elemento = document.getElementById('formulario').elements[i];
		//alert(elemento.name+' '+campo.name);
		if (elemento.name.length > campo.name.length)
		{
			if (elemento.name.substring(0, campo.name.length) == campo.name && elemento.checked)
				campo.value = campo.value + '/~/' + elemento.value;
		}
    }
    if (campo.value.length > 0)
    {
         var mensaje;
		mensaje = '¿Está seguro de eliminar el(los) objeto(s)?';
		confirmar = confirm(mensaje);
		if (confirmar == true)
		{
			mensaje = '¿Desea eliminar el documento de todos los grupos de trabajo?'
			confirmar = confirm(mensaje);
			if(confirmar == true)
				document.getElementById('eli_completo').value = true;
			else
				document.getElementById('eli_completo').value = false;
			campo.value = campo.value.substring(3, campo.value.length);
			document.getElementById('accion').value = 'eliminar';
            document.getElementById('clase').value = nom_ente;
            document.getElementById('cla_padre').value = cla_padre;
			document.getElementById(nom_input).value = campo.value;
            document.getElementById(paginacion).value = 0;
			document.formulario.submit();
		}
    }
    else
    {
        alert('Debe seleccionar un objeto');
    }


}
//------------------------------------------------------------------------------
function IconoTipoElemento(tipoElemento)
{
  if(tipoElemento.value == 3)
  	document.getElementById('img_tip_elemento').src = './img/carpeta.gif';
  else
  	document.getElementById('img_tip_elemento').src = './img/page.gif';
}
//------------------------------------------------------------------------------
function RecargarArbol()
{
	var ventana = eval('window');
        if(ventana.name == 'contenido')
        {
            for(var i = 0; i < ventana.parent.frames.length; i++)
            {
              if(ventana.parent.frames[i].name == 'arbol')
              	ventana.parent.frames[i].location.reload();
            }
        }
        else
        {
	        while (ventana != null && ventana != undefined)
        	{
	          if (ventana.name == 'contenido')
        	  {
	            for(var i = 0; i < ventana.parent.frames.length; i++)
        	    {
	              if(ventana.parent.frames[i].name == 'arbol')
        	      	ventana.parent.frames[i].location.reload();
	            }
        	  }
	          ventana = ventana.opener;
        	}
        }
}
//------------------------------------------------------------------------------
function GuardarDirectorioUsuario(directorio)
{
 	document.getElementById('dir_ficheros').value = directorio;
 	if(window.opener != null && window.opener.document.getElementById('mi_directorio') != null)
	{
    	window.opener.document.getElementById('mi_directorio').alt = 'Mi directorio: ' + directorio + '\\' + window.opener.document.getElementById('dir_contenido').value + '\\';
    }
}
//------------------------------------------------------------------------------
function IrAConfiguracion()
{
	document.location.href = '/fundacionpabloiglesias/fpi/configuracion.jsp?clase=es.intecna.fpi.estructura.ConfiguracionFpi&accion=buscar&cod_usuario=&cod_configuracion=&dir_ficheros=&emergente=true';
	/*var ventana = eval('window');
    while (ventana != null && ventana != undefined)
  	{
     	if (ventana.opener == null)
      	{
      		ventana.parent.document.location.href = '/fundacionpabloiglesias/fpi/configuracion.jsp?clase=es.intecna.fpi.estructura.ConfiguracionFpi&accion=buscar&cod_usuario=&cod_configuracion=&dir_ficheros=';
        }
	    ventana = ventana.opener;
    }
    if(window.document.getElementById('emergente').value = 'true')
	    self.close();*/
}
//------------------------------------------------------------------------------
function AbrirSelector()
{
	AbrirVentana2('/fundacionpabloiglesias/fpi/selector.jsp?clase=es.intecna.fpi.estructura.ConfiguracionFpi&accion=buscar&cod_usuario=&cod_configuracion=&dir_ficheros=&dir_contenido='+ document.getElementById('dir_contenido').value,600,200);
}
//------------------------------------------------------------------------------
function AbrirImagen()
{
	if(document.getElementById('pathlocalimagen').value.length > 0)
		AbrirVentanaRedimensionable('file://' + document.getElementById('mi_directorio').alt.substring(document.getElementById('mi_directorio').alt.indexOf(':',0)+ 2,document.getElementById('mi_directorio').alt.length) + document.getElementById('pathlocalimagen').value, 600,600);
	else
		alert('No hay ningún archivo seleccionado');
}

function AbrirImagen2(){

	var ancho;
	var alto;
	var factor_alto;
	var factor_ancho;
	var nombre;

	nombre = document.getElementById('fotonombre').value;

	if(nombre.length > 0){
		if(nombre.toLowerCase().indexOf(".jpg")>=0){
			ancho = document.getElementById('fotoancho').value;
			alto = document.getElementById('fotoalto').value

			factor_alto = 600 / alto;
			factor_ancho = 600 / ancho;

			if((factor_alto < 1) || (factor_ancho < 1)) {
				// alto o ancho mayor que 600 --> redimensionar
				if(factor_alto < factor_ancho){
					// Mas alta que ancha
					alto = 600;
					ancho = ancho * factor_alto;
				}
				else {
					// Mas ancha que alta
					ancho = 600;
					alto = alto * factor_ancho;
				}
			}

			AbrirVentanaRedimensionable('file://' + document.getElementById('archivonombre').value, ancho, alto);
		}
		else
			AbrirVentanaRedimensionable('file://' + document.getElementById('archivonombre').value, 600, 600);
	}
	else
		alert('No hay ningún archivo seleccionado');
}

//------------------------------------------------------------------------------
function GuardarPathFichero(nombre)
{
	var ini = nombre.indexOf(document.getElementById('dir_contenido').value, 0) + document.getElementById('dir_contenido').value.length + 1;
	var width = 0;
	var img_obj = new Image();
	var nombre2;

	var cadena = nombre.substring(ini, nombre.length);
	window.opener.document.getElementById('pathlocalimagen').value = cadena;
	window.opener.document.getElementById('pathservidorimagen').value = cadena;

	//window.document.getElementById('accion').value = 'crear';
       	//window.document.getElementById('clase').value = 'es.intecna.dinainf.estructura.Recurso';

        window.document.getElementById('nom_recurso').setAttribute('value', cadena);


        nombre2=nombre.toLowerCase();
	if (nombre2.indexOf(".jpg")>=0){

        	do {
        		img_obj.src = nombre;
        		window.opener.window.parent.document.getElementById('fotoancho').value=img_obj.width;
        		window.opener.window.parent.document.getElementById('fotoalto').value=img_obj.height;
        		window.opener.window.parent.document.getElementById('archivonombre').value=nombre;
        		window.opener.window.parent.document.getElementById('frameImagen').src="/fundacionpabloiglesias/fpi/include/fotopdffpi.jsp?nombre=" + nombre + "&ancho=" + img_obj.width + "&alto=" + img_obj.height;
       		}
       		while(img_obj.width==0)
       	}
       	else if (nombre2.indexOf(".pdf")>=0){
		window.opener.window.parent.document.getElementById('fotoancho').value=0;
       		window.opener.window.parent.document.getElementById('fotoalto').value=0;
      		window.opener.window.parent.document.getElementById('archivonombre').value=nombre;
        	window.opener.window.parent.document.getElementById('frameImagen').src=nombre;
       	}
       	else {
       		window.opener.window.parent.document.getElementById('fotoancho').value=0;
       		window.opener.window.parent.document.getElementById('fotoalto').value=0;
       		window.opener.window.parent.document.getElementById('archivonombre').value="";
        	window.opener.window.parent.document.getElementById('frameImagen').src="";
       		alert("Formato de archivo incorrecto");

       	}
	/*var coll = document.getElementsByName("ruta1");
      	var LatestFile = coll[coll.length - 1];
      	var objBr = document.createElement("<br>");
      	LatestFile.insertAdjacentElement("afterEnd", objBr);
      	var objFile = document.createElement('<input type="file" name="ruta" size="63" id="ruta" value="' + nombre +'">');
      	objBr.insertAdjacentElement("afterEnd", objFile);     */


        //window.document.getElementById('formulario').submit();

//	self.close();
}
//------------------------------------------------------------------------------
function AbrirDocumento(documento)
{
        if(document.getElementById('dir_contenido') != null)
        {
		AbrirVentana2('visualizar_descargar_doc.jsp?directorio='+document.getElementById('directorio').value+'&nom_documento=' + document.getElementById('dir_contenido').value + documento,500,400);
        }
        else
        {
		AbrirVentana2('visualizar_descargar_doc.jsp?nom_documento=' + documento,500,400);
        }
}
//------------------------------------------------------------------------------

function AmpliarReducirFoto(accion)
{
	var factor;
	var ancho;
	var alto;
	var nombre;
	var nombre2;

	nombre=window.document.getElementById('archivonombre').value;
	nombre2=nombre.toLowerCase();

	if(nombre2.indexOf(".jpg")>=0){

		if (accion == 0)
			factor = 0.7;
		else if (accion == 1)
			factor = 1.3;

		ancho = window.document.getElementById('fotoancho').value;
        	alto = window.document.getElementById('fotoalto').value;

       		ancho = ancho * factor;
       		alto = alto * factor;

       		window.document.getElementById('fotoancho').value=ancho;
        	window.document.getElementById('fotoalto').value=alto;

        	window.document.getElementById('frameImagen').src="/fundacionpabloiglesias/fpi/include/fotopdffpi.jsp?nombre=" + nombre + "&ancho=" + ancho + "&alto=" + alto;
	}
}

//------------------------------------------------------------------------------
function FormatoFechas()
{
	if(document.getElementById('mes') != null && document.getElementById('mes').value.length > 0)
        {
        	if(document.getElementById('mes').value.length == 1)
                {
                	document.getElementById('mes').value = '0' + document.getElementById('mes').value;
                }
                else
                {
                	if(document.getElementById('mes').value.length > 2)
                        {
                      		document.getElementById('mes').value = document.getElementById('mes').value.substring(0,2);
                        }
                }
                if(parseInt(document.getElementById('mes').value) < 1 || parseInt(document.getElementById('mes').value) > 12)
                {
                	document.getElementById('mes').value = '1';
		}
        }
        if(document.getElementById('dia') != null && document.getElementById('dia').value.length > 0)
        {
        	if(document.getElementById('dia').value.length == 1)
                {
                	document.getElementById('dia').value = '0' + document.getElementById('dia').value;
		}
                else
                {
                	if(document.getElementById('dia').value.length > 2)
                        {
                        	document.getElementById('dia').value = document.getElementById('dia').value.substring(0,2);
                        }
                }
                if(parseInt(document.getElementById('dia').value) < 1 || parseInt(document.getElementById('dia').value) > 31)
                {
                	document.getElementById('dia').value = '1';
                }
        }
}
//------------------------------------------------------------------------------
function Comprar()
{
  if(document.getElementById('id_producto') != null && document.getElementById('id_producto').value.length > 0 && document.getElementById('id_producto').value != '0')
  	AbrirVentana2('http://www2.fpabloiglesias.es/shopAlt/detail.aspx?id=' + document.getElementById('id_producto').value,800,500);
  else
  	alert('El producto aun no está disponible');
}
//------------------------------------------------------------------------------
function AbrirFicha(url)
{
  if(document.getElementById('cod_tip_contenido').value == '2')
  {
  	AbrirEnVentana(url);
  }
  else
  {
    window.parent.AbrirEnVentana(url);
  }
}
//------------------------------------------------------------------------------
function ListarEventos(fecha)
{
  window.parent.document.getElementById('eventos').src = 'eventos.jsp?publicable=1&cod_rel_eve_tema=&cod_rel_eve_categoria=&cod_rel_eve_recurso=&eventosdia=true&titulo=&precio1=&precio2=&cod_continente=&fec_fin=&cod_tema=&datos=&direccion=&descripcion=&inf_inscripcion=&pla_inscripcion=&calendario=true&accion=buscar&cod_evento=&fec_inicio=' + fecha +'&cod_tip_evento=&clase=es.intecna.fpi.estructura.Evento&cod_categoria=';
}
//------------------------------------------------------------------------------
function ObtenerChecked(campo)
{
	var elemento;
  	for (i = 0; i < document.getElementById('formulario').length; i++)
	{
			elemento = document.getElementById('formulario').elements[i];
//			alert(elemento.name+' '+campo.name);
			if (elemento.name.length > campo.name.length)
			{
				if (elemento.name.substring(0, campo.name.length) == campo.name && elemento.checked)
					campo.value = campo.value + '/~/' + elemento.value;
			}
        }
}
//------------------------------------------------------------------------------
