//--EXPLICACIÓN:
//*********************************************************************************************
//Nombre archivo: abrir_foto.js
//Accion:
//						-	Funciones a raiz de pulsar el link
//						-  .js activado desde el archivo inc_abierto.php
//*********************************************************************************************

//--CONTENIDO:

function ContainMouseOver(contenedor,valor,previo)
{	document.getElementById(contenedor).innerHTML = previo + "<strong>" + valor + "</strong>";
	
}

function ContainClick(contenedor,valor,ext,estado,down1,down2,down3,down4)
{	if (estado==0)
	{	descarga = down3 + valor + "." + ext + down4;
	}
	else
	{	descarga = down1 +"<strong><a id=\"submenu\" target=\"_blank\" href=\"doc/"+valor+"."+ext+"\">"+valor+"</a></strong> " + down2;
	}
	document.getElementById(contenedor).innerHTML = descarga
	
}

function input_mouseover(a,b) 
{	//a = nombre del campo
	//b = nombre del formulario
 	document.getElementById(a).className="login_a";
}
//Deja de pasar por encima de un campo de formulario.
function input_mouseout(a,b)  //Al salir dela imagen a = id b = texto anterior.
{  //a = nombre del campo
	//b = nombre del formulario
	document.getElementById(a).className="login";
		

}
function text_mouseover(a,b)
{  document.getElementById(a).innerHTML = b;
}
function text_mouseout(a,b)
{  document.getElementById(a).innerHTML = "";
}

function redireccion_login(a,b,c)
{  //a   =  formulario
	
	//b   =	url
	//c   =	extension
	form = document.forms[a];
	form.action = b + c;
	
	form.submit();
}
function redireccion_ingreso(a,b,c,d,e)
{  //a   =  extension

	//b   =	formulario
	//c   =	valor variable
	//d   =  nombre variable
	//e   =  URL.
	
	form = document.forms[b];
	form.action = e + a + "&" + d + "=" + c;

	form.submit();
}


function imagen_mod(k,a,b,c,d)
{  //a = imagen_con
	//b = imagen_sin
	//c = imagen volver
	//d = imagen nueva
	
	document.getElementById(b).style.background="transparent";
	document.getElementById(a).style.background="transparent";
	
	if (k==1)	//Volver
	{	document.getElementById(a).style.display="inline";
		document.getElementById(b).style.display="none";
		document.getElementById(c).style.display="none";
		document.getElementById(d).value = "1";
		
	}
	if (k==2)	//Eliminar
	{
		document.getElementById(a).style.display="none";
		document.getElementById(b).style.display="inline";
		document.getElementById(c).style.display="none";
		document.getElementById(d).value = "2";

 		}
	if (k==3)	//Modificar
	{	
		document.getElementById(a).style.display="none";
		document.getElementById(b).style.display="inline";
		document.getElementById(c).style.display="inline";
		document.getElementById(d).value = "3";
		
		

	}

}
var nav4 = window.Event ? true : false;
function acceptNum(evt)
{// NOTE: Backspace = 8, Enter = 13, '0' = 48, '9' = 57

	var key = nav4 ? evt.which : evt.keyCode;
	
	return (key <= 13 || (key >= 48 && key <= 57));

}

function comprobar_campos_form(a)
{ 	var ok = true;
	error = "";
	
	if ((a == "agregar_mensaje") || (a == "responder_mensaje"))
	{	form = document.getElementById("form_mensajes");
		if (form.asunto.value.length < 1)
	   {  var ok = false;
	      error += "- Agregue el Asunto al mensaje\n";
	   }
	   
	   if (ok == false)
	   {  alert(error);
	   }
	   return ok;
	}
	if (a == "actualizar_misdatos")
	{	form = document.getElementById("form_misdatos");
		if (form.f_nombre.value.length < 1)
	   {  var ok = false;
	      error += "- Agregue el nombre de usuario\n";
	   }
	   if (form.f_telefono.value.length < 9)
	   {  var ok = false;
	      error += "- Agregue el telefono correctamente\n";
	   }
	   if ((form.f_contrasena.value.length < 6) || (form.f_contrasena.value.length > 12))
	   {  var ok = false;
	      error += "- La contraseña ha de tener de 6 a 12 caracteres\n";
	   }
	   if (ok == false)
	   {  alert(error);
	   }
	   return ok;
	}
	if ((a == "agregar_usuarios") || (a == "editar_usuarios"))
	{  form = document.getElementById("form_usuarios");
	   if (form.name_usuario.value.length < 1)
	   {  var ok = false;
	      error += "- Agregue el nombre de usuario\n";
	   }
	   if (form.telefono_usuario.value.length < 9)
	   {  var ok = false;
	      error += "- Agregue el telefono correctamente\n";
	   }
	   if (form.user_usuario.value.length < 6)
	   {  var ok = false;
	      error += "- El usuario ha de incluir 6 caracteres como mínimo\n";
	   }
      if ((form.password_usuario.value.length < 6) || (form.password_usuario.value.length > 12))
	   {  var ok = false;
	      error += "- La contraseña ha de tener de 6 a 12 caracteres\n";
	   }
	   if (ok == false)
	   {  alert(error);
	   }
	   return ok;


	}
	if ((a == "agregar_noticias") || (a == "editar_noticias"))
	{  form = document.getElementById("form_noticias");
		fechai = form.ano_noticia.value+form.mes_noticia.value+form.dia_noticia.value;
		if (fechai.length == 6)
		{ 	ano = fechai.substring(0,2)
			mes = fechai.substring(2,4)
			if ((mes>12) || (mes < 01))
			{  error +="- Escriba un mes correcto\n";
			   ok = false
			}
	 		dia = fechai.substring(4,6)
	 		if ((dia>31) || (dia<01))
	 		{  error +="- Escriba un dia correcto.\n";
			   ok = false
			}
			else
			{  if ((mes == "04") || (mes == "06") || (mes == "09") || (mes == "11"))
				{	if (dia>30)
					{	error +="- El mes no puede tener mas de 30 dias.\n"
					   ok = false;
					}
				}
				if (mes == "02")
				{  valor = ano/4;
				   valor=valor.toString();
					res = valor.indexOf(".");
					res = valor.indexOf(",");
					if (res != -1)
					{  if (dia>29)
					   {  error +="- El mes no puede tener mas de 29 dias.\n"
					   	ok = false;
					   }
					}
					else
					{  //Año no bisiesto
					   if (dia>28)
					   {  error +="- El mes no puede tener mas de 28 dias.\n"
					   	ok = false;
					   }
					}
				}
			}
		}
		else
		{  ok = false
		   error += "- Escriba la fecha tal como se indica\n";
		}
	   if (form.titulo_espanol_noticia.value.length < 1)
	   {  var ok = false;
	      error += "- Agregue el titulo en español\n";
	   }
	   if (form.titulo_ingles_noticia.value.length < 1)
	   {  var ok = false;
	      error += "- Agregue el titulo en inglés\n";
	   }
	   if (ok == false)
	   {  alert(error);
	   }
	   return ok;


	}
}
	
function poner_imagen(a,b,c,d,e,f,g,h,i)
{  //a = formulario
	//b = numero de imagnes
	//c = imagen pulsada
	//d = id del colocador de imagen
	//e = ruta grande.
	//f = nombre ruta de imagen
	//g = TEXT "de"
	//h = TEXT "imagenes"

	
	form = document.forms[a];
	
	if ((c != "num_posterior_HIDDEN") && (c != "num_anterior_HIDDEN"))
	{  c++;
		//incluimos la foto en colocador.
		document.getElementById(d).src = e+f
		document.getElementById("num_mostrada").value = c
		document.getElementById("contador").innerHTML = eval(c) + g + b + h
		document.getElementById("texto_colocador").innerHTML = i
	}
	else
	{
		if (c== "num_posterior_HIDDEN")
		{  c_mostrada = form.num_mostrada.value;
			
		   if (c_mostrada<=b)
			{  c = eval(c_mostrada)+1;
				valor_a = c-1;
			
				
			   f = document.getElementById("imagen_"+valor_a).value;
			   i = document.getElementById("texto_imagen_"+valor_a).value;
				

			}
			else
			{  f="default.gif";
			}
		}
		if (c== "num_anterior_HIDDEN")
		{  c_mostrada = form.num_mostrada.value;
			
		   if (c_mostrada>="0")
			{  c = eval(c_mostrada)-1;
				valor_a = c-1;
				f = document.getElementById("imagen_"+valor_a).value;
			   i = document.getElementById("texto_imagen_"+valor_a).value;

			}
			else
			{  f="default.gif";
			}

		}

		//incluimos la foto en colocador.
		document.getElementById(d).src = e+f
		document.getElementById("num_mostrada").value = c
		document.getElementById("contador").innerHTML = eval(c) + g + b + h
		document.getElementById("texto_colocador").innerHTML = i
	}
 }
	


