/**gestion_documentos.js
Realiza el control de gestion de documentos.
s = Item Seleccionado
p = Apartado actual
a = Accion a realizar (1 = Insertar, 2 = Editar, 3 = Ver.)
b = id del formulario oculto (Nuestro numero id de usuario)
c = Dia de Imagen
d = Mes de Imagen
e = Año de Imagen
f = Texto
g = id_album
h = Campo Libre
i = Campo Libre
j = Campo Libre
k = Imagen
l = Opcion Icono seleccionada
m = Campo Libre
*/
function gestion_documentos(s,p,a,b,c,d,e,f,g,h,i,j,k,l,m,n)
{	//Visualizamos el formulario
	document.getElementById(b).style.display ="inline";
	//Incluismos los campos como No visibles.
	document.getElementById("nombre_blo").style.display = "none"
	document.getElementById("texto_blo").style.display = "none"
	document.getElementById("descripcion_blo").style.display = "none"
	document.getElementById("imagen_blo").style.display = "none"
	document.getElementById("imagen_ext_blo").style.display = "none"
	document.getElementById("masimagen_blo").style.display = "none"
	document.getElementById("fieldset").style.display = "none"
	document.getElementById("option_alb_blo").style.display = "none"
	document.getElementById("option_alb_s_blo").style.display = "none"
	document.getElementById("fechada_blo").style.display = "none"
	document.getElementById("mensajito_blo").style.display = "none"
	 
	//variables de los bloques.
	blo_nombre = document.getElementById("nombre_blo")
	blo_texto = document.getElementById("texto_blo")
	blo_descripcion = document.getElementById("descripcion_blo")
	blo_imagen = document.getElementById("imagen_blo")
	blo_imagen_ext = document.getElementById("imagen_ext_blo")
	blo_masimagen = document.getElementById("masimagen_blo")
	blo_fieldset = document.getElementById("fieldset")
	blo_option_alb = document.getElementById("option_alb_blo")
	blo_option_alb_s = document.getElementById("option_alb_s_blo")
	blo_fechada = document.getElementById("fechada_blo")
	blo_mensajito = document.getElementById("mensajito_blo")
	
	//Botones = No Visibles (No son bloques, son campos)
	document.forms[0].insertar.style.display="none";
	document.forms[0].actualizar.style.display="none";
	document.forms[0].buscar.style.display="none";

	//Variables de botones
	bot_insertar = document.forms[0].insertar
	bot_actualizar = document.forms[0].actualizar
	bot_buscar = document.forms[0].buscar
	bot_volver = document.forms[0].imagen_volver
	
 	//Variables de los campos
	cam_nombre = document.forms[0].nombre
	cam_dia = document.forms[0].dia
	cam_mes = document.forms[0].mes
	cam_ano = document.forms[0].ano
	cam_texto = document.forms[0].texto_f
	cam_descripcion = document.forms[0].descripcion
	cam_option_alb = document.forms[0].option_alb
	cam_option_alb_s = document.forms[0].option_alb_s
	cam_imagen_ext = document.forms[0].imagen_ext //Campo txt
	cam_imagen_ext_b = document.forms[0].imagen_ext_b //Boton Nueva Imagen
	cam_imagen_ext_eliminar = document.forms[0].imagen_ext_eliminar //Boton Eliminar Imagen
	
	//Inicializacion Campo Imagen
	cam_imagen_ext.value="0";
	
	//Variables campos ocultos.
	hid_1 = document.forms[0].id
	hid_2 = document.forms[0].iden_type
	hid_3 = document.forms[0].identificador_men
	hid_4 = document.forms[0].iden_men
	hid_5 = document.forms[0].iden_apa
	hid_6 = document.forms[0].iden_blo
	hid_7 = document.forms[0].nuevo_apartado
	hid_8 = document.forms[0].name_men
	hid_9 = document.forms[0].name_apa
	hid_10 = document.forms[0].name_apa
	hid_11 = document.forms[0].opt
	hid_12 = document.forms[0].c_bloques
	hid_13 = document.forms[0].imagen_anterior	//Campo oculto nombre de imagen
	hid_14 = document.forms[0].imagen_update	//Campo oculto nombre de imagen
	hid_menu_real = document.forms[0].menu_real //Campo oculto nombre de imagen
	hid_apa_real = document.forms[0].apa_real	//Campo oculto nombre de imagen
	hid_vincul = document.forms[0].vincul	//Campo oculto nombre de imagen
	hid_escape = document.forms[0].escape	//Campo oculto Tipo de Usuario
	hid_imagenes = document.forms[0].imagenes	//Campo oculto Tipo de Usuario
	hid_tamano = document.forms[0].tamano	//Campo oculto Tipo de Usuario
	hid_tipo = document.forms[0].tipo	//Campo oculto Tipo de Usuario
	
//*************************************************************************************	
	if (a == 1) //Accion Insertar
	{  espacio_vacio="";
		document.forms[0].reset(); //Reseteamos el formulario
   	document.forms[0].insertar.style.display=""; //Activamos el boton Insertar
     	document.forms[0].action = "inc/inc_ingresar_documento.php"; //Activamos la accion al boton

		if (p == 23)
		{	hid_2.value=h	
			if (h=="doc_car_tab")	//Insertar Carpeta
			{	blo_nombre.style.display="";
			}
			if (h=="doc_tab") //Insertar Documento
			{	valorenhidden_documentos();
				blo_masimagen.style.display="";
				blo_option_alb.style.display="";
				blo_fieldset.style.display="";
				blo_mensajito.style.display="";
			}
			if (h=="bus_doc_tab") //Buscar Documentoo
			{	blo_nombre.style.display="";
				bot_buscar.style.display="";	
				bot_insertar.style.display="none";
				document.forms[0].action = "inc/inc_buscar_users.php";
			}
		}
   }
//*************************************************************************************
	if ((a == 2) || (a == 3)) //Editar y Ver
	{	if (a == 2) //Editar
		{	bot_actualizar.style.display ="";
			document.forms[0].action = "inc/inc_actualizar_documentos.php";
			hid_1.value = s; //Añado el valor de id (s) al campo hidden_1
		}
		if (p == 23)
		{	hid_2.value=h	
			if (h=="doc_car_tab")	//Editar carpeta
			{	cam_nombre.value = c
				blo_nombre.style.display="";
				hid_escape.value = s //id_carpeta
				hid_4.value = j //tipo de carpeta
			}
			
			if (h=="doc_tab") //Verifico las imagenes que dispone.
			{	blo_mensajito.style.display="";
				if(n=="1")
				{	blo_option_alb_s.style.display="";
					hid_escape.value = "default"; 
				}
				else
				{	cam_option_alb.options[document.getElementById("car"+d).value].selected = true;
					blo_option_alb.style.display="";
					hid_escape.value = d
				}
				blo_fechada.style.display="";
				blo_texto.style.display="";
				blo_descripcion.style.display="";
				cam_texto.value = c
				cam_descripcion.value = e
				cam_dia.value = i
				cam_mes.value = l
				cam_ano.value = m
				hid_tamano.value = g 
				hid_tipo.value = j
				ext_imagen_users(f);
			}
		}
   }
} //Fin de la funcion


function anadir_documento(cantidad,nav)
{	
	//Cantidad de documentos a insertar
	hid_imagenes.value=cantidad;
	form = document.getElementById("fiel");
	if (nav == "OT")
	{	form = document.getElementById("fiel_o");
	}
	form.innerHTML="";
 	blo_mensajito.style.display="";
	for (var num=0;num<cantidad;num++)
	{ 	InputDia = document.createElement('input'); 
	  		form.appendChild(InputDia);
	  			InputDia.setAttribute("TYPE","text");
	  			InputDia.setAttribute("NAME","dia"+num);	
	  			InputDia.setAttribute("id","fecha2");
	  			InputDia.setAttribute("value","dd");
	  			InputDia.setAttribute("maxlength","2");
	  			InputDia.setAttribute("onFocus","javascript:{this.value=\"\";}");
	  			
		InputMes = document.createElement('input'); 
	  		form.appendChild(InputMes);
	  			InputMes.setAttribute("TYPE","text");
	  			InputMes.setAttribute("NAME","mes"+num);	
	  			InputMes.setAttribute("id","fecha2");
	  			InputMes.setAttribute("value","mm");
	  			InputMes.setAttribute("maxlength","2");
	  			InputMes.setAttribute("onFocus","javascript:{this.value=\"\";}");
	  		
	  	InputAno = document.createElement('input'); 
	  		form.appendChild(InputAno);
	  			InputAno.setAttribute("TYPE","text");
	  			InputAno.setAttribute("NAME","ano"+num);	
	  			InputAno.setAttribute("id","fecha2");
	  			InputAno.setAttribute("value","aa");
	  			InputAno.setAttribute("maxlength","2");
	  			InputAno.setAttribute("onFocus","javascript:{this.value=\"\";}");
	  		
		InputTexto = document.createElement('input'); 
			form.appendChild(InputTexto);
				InputTexto.setAttribute("TYPE","text");
	  			InputTexto.setAttribute("NAME","texto"+num);	
	  			InputTexto.setAttribute("id","entrada3");
	  			InputTexto.setAttribute("value","Titulo");
	  			InputTexto.setAttribute("onFocus","javascript:{this.value=\"\";}");
				    		
		InputDescripcion = document.createElement('input'); 
			form.appendChild(InputDescripcion);
	  			InputDescripcion.setAttribute("TYPE","text");
	  			InputDescripcion.setAttribute("NAME","descripcion"+num);	
	  			InputDescripcion.setAttribute("id","entrada6");
	  			InputDescripcion.setAttribute("value","Breve descripción");
	  			InputDescripcion.setAttribute("onFocus","javascript:{this.value=\"\";}");
	  				  	
	  	InputFile = document.createElement('input'); 
	  		form.innerHTML= form.innerHTML + "<input type='file' size='60'name='file"+num+"' id='file2'>";
	  			    		
		Linea = document.createElement('hr'); 
			form.appendChild(Linea);
		
		if(nav=="OT")
		{	documentos = document.getElementById("documentos");
			documentos.appendChild(form);
		}
	}
 		
 	
	
}
function anadir_campo_hidden(valor,nombre)
{	document.getElementById("h"+nombre).setAttribute("value",valor)
	alert(document.etElementById("h"+nombre).value)
}
//******************************************************************************
//******************************************************************************
function borrar(obj)
{	fi = document.getElementById('fiel'); // 1 
  	fi.removeChild(document.getElementById(obj)); // 10
  	num = num-1;
  	hid_imagenes.value = num
  	
  	
}
function valorenhidden_documentos()
{	option_seleccionado = document.forms[0].option_alb.selectedIndex;
	hid_escape_v = document.forms[0].option_alb.options[option_seleccionado].id
	hid_escape.value = hid_escape_v.substring(3)

}

function valorenhidden_documentos_s()
{	option_seleccionado = document.forms[0].option_alb_s.selectedIndex;
	hid_escape_v = document.forms[0].option_alb_s.options[option_seleccionado].id
	hid_escape.value = hid_escape_v.substring(3)
	
}
function ext_imagen_users(k)
{ 
	//Inicializacion Campo Imagen
	if ((k != 0)&&(k != 1)&&(k != 2)&&(k != 3))
	{	  
		hid_13.value = k; // imagen_anterior
		blo_imagen.style.display="none"
		blo_imagen_ext.style.display=""
		cam_imagen_ext.value=k;
		hid_14.value = k  // imagen_update
		//alert(hid_14.value)
		//alert(document.forms[0].imagen_update.value)
	}
	else
	{	if (k==0)	//Campo Vacio
		{	blo_imagen.style.display=""
			blo_imagen_ext.style.display="none"
			cam_imagen_ext.value="0"
			bot_volver.style.display="none";
			hid_14.value="0"
			 
		}
		if (k==1)	//Volver
		{	blo_imagen.style.display="none"
			blo_imagen_ext.style.display=""
			cam_imagen_ext.value=hid_13.value;
			bot_volver.style.display="none";
			hid_14.value = hid_13.value;
			bot_volver.display="";
			
			
		}
		if (k==2)	//Eliminar
		{	blo_imagen.style.display=""
			blo_imagen_ext.style.display="none"
			bot_volver.style.display="none";
			hid_14.value="0";
				
 		}
 		if (k==3)	//Campo Modificar
		{  
			blo_imagen.style.display=""
			blo_imagen_ext.style.display="none"
			cam_imagen_ext.value="0"
			bot_volver.style.display="";
			hid_14.value="1" // Indico que se ha de recoger o comprobar de $_FILE.
				
		}
	}
}
function anadir_documento_2(cantidad,nav)
{	alert(nav)
	hid_imagenes.value=cantidad;
	form = document.getElementById("fiel");
	if (nav == "OT")
	{    form = document.forms[0];
  	}
	
	
	
	var a=0;
	for (var a=0;a<cantidad;a++)
	{		var Input = document.createElement("input");
			form.appendChild(Input);
				Input.setAttribute("type","text");
				Input.setAttribute("id","htexto"+a);
				Input.setAttribute("name","htexto"+a);
				
				

		
	} 
	
}
/*	if (a==0)	
		{	contenedor.innerHTML = '<input type="text" maxlength="2" class="fecha"  id="dia'+a+'" name="hdia'+a+'" value="dd" onFocus="javascript:{this.value=\"\";}">'; 
					
		}
		else
		{
			contenedor.innerHTML = contenedor.innerHTML + '<input type="text" maxlength="2" class="fecha" id="dia'+a+'"  name="hdia'+a+'" value="dd" onFocus="javascript:{this.value=\"\";}">';
		} 
			contenedor.innerHTML = contenedor.innerHTML + '<input type="text" maxlength="2" class="fecha" name="hmes'+a+'" id="mes'+a+'" value="mm" onFocus="javascript:{this.value=\"\";}">';
			contenedor.innerHTML = contenedor.innerHTML + '<input type="text" maxlength="2" class="fecha" name="hano'+a+'" id="ano'+a+'" value="aa" onFocus="javascript:{this.value=\"\";}">';
			contenedor.innerHTML = contenedor.innerHTML + '<input type="text" class="entrada2" name="htexto'+a+'" id="texto" value="Escriba el titulo del documento" onFocus="javascript:{this.value=\"\";}"></p>';
			contenedor.innerHTML = contenedor.innerHTML + '<p><input type="text" class="entrada" name="hdescripcion'+a+'" id="descripcion'+a+'" value="Breve descripción" onFocus="javascript:{this.value=\"\";}"></p>';
			contenedor.innerHTML = contenedor.innerHTML + '<p><input type="file" class="file" size="60" name="hfile'+a+'" id="file'+a+'" value=""></p>';
			contenedor.innerHTML = contenedor.innerHTML + '<hr>';
			alert(document.getElementById("texto"+a).name)
	*/	
