﻿// MUESTRA/OCULTA EL BUSCADOR DE GOOGLE EN LA CABECERA DE LA PÁGINA
function buscador() {
	miBuscador = document.getElementById('buscador');
	(miBuscador.style.display != 'block')? miBuscador.style.display='block': miBuscador.style.display='none';
}

// ABRE VENTANA PARA MOSTRAR IMAGEN AMPLIADA
function popImg(URL)

{
	window.open('../galeria/cargador.php?imagen='+URL,Math.round(Math.random()*1000000000),'width=980,height=700,scrollbars=yes');
}

// ALTERNA EL SUBMENÚ
function menu(actual) {
	document.getElementById('uno').style.display = 'none';
	document.getElementById('dos').style.display = 'none';
	document.getElementById('tres').style.display = 'none';
	document.getElementById('cuatro').style.display = 'none';
	document.getElementById('cinco').style.display = 'none';
	document.getElementById('ocho').style.display = 'none';
	document.getElementById('nueve').style.display = 'none';
	document.getElementById(actual).style.display = 'block';
}


// ABRE VENTANA PARA MOSTRAR ARCHIVO FLASH
function popSWF(URL,ANCHO,ALTO)

{
	window.open('../galeria/flash.php?src='+URL+'&ancho='+ANCHO+'&alto='+ALTO,Math.round(Math.random()*1000000000),'width='+ANCHO+',height='+ALTO+',scrollbars=no');
}

// MUESTRA EL RESULTADO (ÉXITO/FRACASO) DEL ENVÍO DE UN MENSAJE DE CORREO ELECTRÓNICO MEDIANTE EL FORMULARIO DE CONTACTO
function contacto(resultado) {
	if (resultado == 'exito') {
		window.alert('¡Mensaje enviado con éxito!');
		}
	else if (resultado == 'fracaso') {
		window.alert('Hubo un problema con el envío del mensaje. Por favor, vuelve a intentarlo.');
		}
	else {}
}

// EVALÚA SI EL FORMULARIO DE CONTACTO SE HA RELLENADO CORRECTAMENTE
function evaluaMail() {
		theEntry = document.FormName.tuEmail.value;
		invalidChars = " /:,;"
		badEntry = 'ok';		
		if (theEntry == "") { 
			badEntry = "badEmail";
			}
		for (i=0; i < 5; i++)  {
			badChar = invalidChars.charAt(i)
				if (theEntry.indexOf(badChar,0) > -1) {
				badEntry = "badEmail"
				}
		}	
		atsignLoc = theEntry.indexOf("@",1)
			if (atsignLoc == -1) {
				badEntry = "badEmail"
			}		
			if (theEntry.indexOf("@",atsignLoc+1) > -1) {
			badEntry = "badEmail"
			}
		dotLoc = theEntry.indexOf(".",atsignLoc)
			if (dotLoc == -1) {
			badEntry = "badEmail"
			}
			if (dotLoc+3 > theEntry.length) {
			badEntry = "badEmail"
			}
			if (badEntry == "badEmail") {
			theEntry = 'invalido';
			}
		
	if (document.FormName.tuNombre.value != '' && document.FormName.tuAsunto.value != '' && theEntry != 'invalido' && document.FormName.tuMensaje.value.length > 80) {
		document.FormName.submit();
		} else {
		mensaje = 'El formulario contiene errores. Por favor, corrígelo según las siguientes instrucciones:';
		if (document.FormName.tuNombre.value == '') {
			mensaje += '\n   -Debes escribir tu nombre.';
		}
		if (document.FormName.tuAsunto.value == '') {
			mensaje += '\n   -Debes escribir un asunto para tu mensaje.';
			}
		if (document.FormName.tuMensaje.value.length < 180) {
			mensaje += '\n   -Tu mensaje debe constar de al menos 100 caracteres';
			}
		if (theEntry == 'invalido') {
			mensaje += '\n   -Tu dirección de correo electrónico es incorrecta';
			}
		window.alert(mensaje);
		}
}

function abridor(clave) {
	if (window.opener) {
		this.close();
		window.open('../nubes/?clave='+clave,Math.random()*10000000000000,'scrollbars=yes,location=yes,toolbar=yes,menubar=yes,status=yes,resizable=yes');
		} else {
			window.open('../nubes/?clave='+clave,'_self');
		}
	}
	
	// AQUÍ LOS SCRIPTS, AJAX Y DEMÁS DEL GLOSARIO TIP POP
function cursorPos(e) {
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX+20;
		posy = e.pageY;
		document.getElementById('glosaDiv').style.left=posx+'px';
		document.getElementById('glosaDiv').style.top=posy+'px';
		document.getElementById('glosaDiv').style.display='block';
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft+15;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop+15;
		document.getElementById('glosaDiv').style.left=posx+'px';
		document.getElementById('glosaDiv').style.top=posy+'px';
		document.getElementById('glosaDiv').style.display='block';
	}
	}
	// posx and posy contain the mouse position relative to the document
	// Do something with this information
	
	
	function cierraTip() {
		document.getElementById('glosaDiv').style.display='none';
	}
	
	function ajaxFunction(vocablo)
{
cerrar = "<p class='cerrar-tip'><img onclick='cierraTip()' src='../i/cerrar-tip.png' /></p>";
var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("¡Tu navegador no soporta AJAX!");
      return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==1)
      {
      document.getElementById('glosaDiv').innerHTML= cerrar + 'Cargando. Por favor, espere.';
      }
    if(xmlHttp.readyState==4)
      {
      document.getElementById('glosaDiv').innerHTML= cerrar + xmlHttp.responseText;
      }
    }
  xmlHttp.open("GET","../glosario/get-def.php?vocablo="+vocablo,true);
  xmlHttp.send(null);
  }
  
// COMENTARIOS
function openComments(urlOriginal) {
	window.open('../comentarios/?urlOriginal='+urlOriginal,'miVentanita','width=470,height=580,scrollbars=yes,resizable=yes');
	}
