/*gestion_galeria.js
Gestion de la galeria.
s = Item Seleccionado
p = Apartado donde nos encontramos
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_galeria(s,p,a,b,c,d,e,f,g,h,i,j,k,l,m)
{	//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("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 bloques.
	blo_nombre = document.getElementById("nombre_blo")
	blo_texto = document.getElementById("texto_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 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
	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 ocultas
	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
//*************************************************************************************
	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_galeria.php"; //Activamos la accion al boton
    	//Activamos los bloques.
	
		if (p == 15)
		{	hid_2.value=l	
			if (l=="alb_tab")	//Insertar Album
			{	blo_nombre.style.display="";
			}
			if (l=="gal_tab") //Insertar Imagen
			{	valorenhidden_albums();
				blo_masimagen.style.display="";
				blo_option_alb.style.display="";
				blo_fieldset.style.display="";
				blo_mensajito.style.display="";
			}
			if (l=="alb_tab_bus") //Insertar Imagen
			{	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_galeria.php";
			hid_1.value = s; //Aņado el valor de id (s) al campo hidden_1
		}
		if (p == 15)
		{	hid_2.value=l	
			if (l=="alb_tab")	//Insertar Album
			{	cam_nombre.value = f
				blo_nombre.style.display="";
				hid_escape.value = s //id de album
				hid_4.value = g //Tipo de Album
			}
			
			if (l=="gal_tab") //Verifico las imagenes que dispone.
			{	blo_mensajito.style.display="";
				if(m=="1")
				{	blo_option_alb_s.style.display="";
					hid_escape.value = "default";
				}
				else
				{	cam_option_alb.options[document.getElementById("alb"+g).value].selected = true;
					blo_option_alb.style.display="";
					hid_escape.value = g // id album
				}
				blo_fechada.style.display="";
				blo_texto.style.display="";
				cam_texto.value = f
				cam_dia.value = c
				cam_mes.value = d
				cam_ano.value = e
				ext_imagen_users(k);
			}
		}
   }
} //Fin de la funcion


function anadir_galeria(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=\"\";}");		
		
		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);		//Entradas
	}		
	if(nav=="OT")
	{	galeria = document.getElementById("galeria");
		galeria.appendChild(form);
	}
}

function anadir_campo_hidden(valor,nombre)
{	
	
	document.getElementById("h"+nombre).value=valor;
}
//******************************************************************************
//******************************************************************************
function borrar(obj)
{	fi = document.getElementById('fiel'); // 1 
  	fi.removeChild(document.getElementById(obj)); // 10
  	num = num-1;
  	hid_imagenes.value = num
  	
  	
}
function valorenhidden_albums()
{	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_albums_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.
				
		}
	}
}
