/***** ROLLOVER SENCILLO QE TE CAGAS *****/

//en la imagen --> onmouseover="this.src=Imagenes[0].src;" onmouseout="this.src=Imagenes[1].src;"

//en onLoad de <body> -->onLoad="Precargar('rutarelativa/imagen-ON', 'rutarelativa/imagen-OFF')"

Imagenes = new Array();

function Precargar() {

	

  for (var i=0; i<Precargar.arguments.length; i++) {    

    Imagenes[i]=new Image; 

    Imagenes[i].src=Precargar.arguments[i];

  }

}







/***** Captura de la posición del ratón *****/

function Browser() {

this.isIE = false; // Internet Explorer

this.isNS = false; // Netscape

this.isOpera = false; // Opera

if (navigator.userAgent.indexOf("Netscape6/") >= 0) {

this.isNS = true;

return;

}

if (navigator.userAgent.indexOf("Gecko") >= 0) {

this.isNS = true;

return;

}

if (navigator.userAgent.indexOf("MSIE") >=0 && navigator.userAgent.indexOf("Opera") <0) {

this.isIE = true;

return;

}

if (navigator.userAgent.indexOf("Opera") >=0) {

this.isOpera = true;

return;

}

}



var browser = new Browser();



function initMovimiento(event){

cancelar();

if (browser.isIE || browser.isOpera) {

document.attachEvent("onmousemove", getposicion);

window.event.cancelBubble = true;

window.event.returnValue = false;

}

if (browser.isNS) {

document.addEventListener("mousemove", getposicion, true);

event.preventDefault();

}

}

function initPulsar(event){

cancelar();

if (browser.isIE || browser.isOpera) {

document.attachEvent("onclick", getposicion);

window.event.cancelBubble = true;

window.event.returnValue = false;

}

if (browser.isNS) {

document.addEventListener("click", getposicion, true);

event.preventDefault();

}

}

function getposicion(event){

if (browser.isIE) {

x = window.event.clientX + document.documentElement.scrollLeft

+ document.body.scrollLeft;

y = window.event.clientY + document.documentElement.scrollTop

+ document.body.scrollTop;

}

if (browser.isNS) {

x = event.clientX + window.scrollX;

y = event.clientY + window.scrollY;

}

if (browser.isOpera) {

x = window.event.clientX + document.documentElement.scrollLeft;

y = window.event.clientY + document.documentElement.scrollTop;

}

document.getElementById("posicion").style.visibility = "visible";

document.getElementById("posicion").style.left= (x - 55) +"px";

document.getElementById("posicion").style.top = y + 20 +"px";

document.getElementById("posicion").innerHTML = "Coordenada x: " + x + "<br>Coordenada y: " + y;

}



function cancelar() {

if (browser.isIE || browser.isOpera) {

document.detachEvent("onmousemove", getposicion);

document.detachEvent("onclick", getposicion);

}

if (browser.isNS ) {

document.removeEventListener("mousemove", getposicion, true);

document.removeEventListener("click", getposicion, true);

}

document.getElementById("posicion").style.visibility= "hidden";

}



//-----------------------------------------



// popups de imágenes de la galería

function popup(ruta_base, ancho, nombre_imagen)

{

	

	var features = "width=" + ancho + ", height=600" + ", resizable=yes";

	

	nueva = window.open(ruta_base + "admin/galeria/ver_imagen.php?nombre=" + nombre_imagen, "imagen", features);

	nueva.focus();

}



// funciones para mostrar/ocultar capas

function mostrar_capa(event, capa)

{

	var flagstyle = document.getElementById('flagstyle');

	if (flagstyle.style.display == 'none') {

		document.getElementById(capa).style.display = "block";

		document.getElementById(capa).style.position = "absolute";



		if (browser.isIE) {

			x = window.event.clientX + document.documentElement.scrollLeft

			+ document.body.scrollLeft;

			y = window.event.clientY + document.documentElement.scrollTop

			+ document.body.scrollTop;

		}

		if (browser.isNS) {

			x = event.clientX + window.scrollX;

			y = event.clientY + window.scrollY;

		}

		if (browser.isOpera) {

			x = window.event.clientX + document.documentElement.scrollLeft;

			y = window.event.clientY + document.documentElement.scrollTop;

		}



		document.getElementById(capa).style.left= (x - (document.getElementById(capa).offsetWidth/2)) +"px";

		document.getElementById(capa).style.top = (y + 20) +"px";

	}

}

function ocultar_capa(capa)

{

	var flagstyle = document.getElementById('flagstyle');

	if (flagstyle.style.display == 'none') {

		document.getElementById(capa).style.display = "none";

		document.getElementById(capa).style.position = "absolute";



		if (browser.isIE || browser.isOpera) {

			document.detachEvent("onmousemove", getposicion);

			document.detachEvent("onclick", getposicion);

		}

		

		if (browser.isNS ) {

			document.removeEventListener("mousemove", getposicion, true);

			document.removeEventListener("click", getposicion, true);

		}

	}

}



function limpiarTexto(cajaTexto)

{

	if (cajaTexto.defaultValue==cajaTexto.value)

		cajaTexto.value = "";

} 



function CabecerasAleatorias()

{

	var aleat = Math.random() * 7;

  var aleat = Math.round(aleat);

  

  var cabecera = document.getElementById("cabecera");

  

  alert ("entra");

  

  var imagen = cabecera.style.backgroundImage.src = "/proyectos/duse/imagenes/portada/cabecera/fondo_cabecera" + aleat + ".jpg";

  

  return imagen;  

}

// Version Imprimible



// el temita de la impresion

function __poner_cabeceras(ruta_base, idioma, ventana)

{

	var salida_html = "<html>\n";

	salida_html += "\n\t<head>";

	salida_html += "\n\t\t<title>";

	salida_html += "Duse Santa Bárbara - Detalle de noticia";

	salida_html += "</title>";

	salida_html += "<link href=" + ruta_base + "css/otros/popup.css rel='stylesheet' type='text/css'>";

	salida_html += "\n\t</head>\n\t";

	salida_html += __poner_estilos_de_pagina(ruta_base, idioma);

	salida_html += "\n\t<body>";

	

	ventana.document.write(salida_html);

}



function __poner_pie(ventana)

{

	var salida_html = "";

	

	salida_html += "\n\t<div style=\"text-align: center\">";

	salida_html += "\n\t\t<a class='peque' class='link_de_categoria' href='#' onclick='window.print(); window.close();'>Imprimir</a>&nbsp;&nbsp;";

	salida_html += "\n\t&nbsp;&nbsp;<a class='peque' class='link_de_categoria' href='#' onclick='window.close(); window.close();'>Cerrar</a>";

	salida_html += "\n\t</div>";

	salida_html += "\n<br>";

	

	salida_html += "\n</body>";

	salida_html += "\n\n</html>";

	

	ventana.document.write(salida_html);

	

}



function __poner_estilos_de_pagina(ruta_base, idioma)

{

	var salida_html = "<style type='text/css'>";

	//salida_html += "\n@import url(" + ruta_base + "css/otros/portada.css);";

	

	salida_html += "\n</style>";

	

	return salida_html;

}



function print_test(ruta_base, idioma, idcapa)

{

	

	capa = document.getElementById(idcapa);

	alto = capa.offsetHeight + 50;

	nueva = window.open("", "", "width=650, height=" + alto + ", scrollbars=yes");



	__poner_cabeceras(ruta_base, idioma, nueva);

	nueva.document.write("<div id='noticia_individual' align='left'>");

	nueva.document.write(capa.innerHTML);

	nueva.document.write("</div>");

	__poner_pie(nueva);

	nueva.document.close();

	nueva.focus();

	

}

function filtrar(parametro)

{
	termino = document.getElementById('termino');
	inicio = document.getElementById('inicio');
	fin = document.getElementById('fin');	

	if (parametro.value != 0)

	{

		if (parametro.value == 4)

		{

			temino.disabled = true;

			temino.style.background = "#F9FFD3";

			inicio.disabled = false;

			inicio.style.background = "#FFFFFF";

			inicio.focus();

			fin.disabled = false;

			fin.style.background = "#FFFFFF";

			document.getElementById('btn').disabled = false;

		}	

		else

		{

			document.getElementById('inicio').disabled = true;

			document.getElementById('inicio').style.background = "#F9FFD3";

			document.getElementById('fin').disabled = true;

			document.getElementById('fin').style.background = "#F9FFD3";

			document.getElementById('termino').disabled = false;

			document.getElementById('termino').style.background = "#FFFFFF";

			document.getElementById('termino').focus();

			document.getElementById('btn').disabled = false;

			

		}

	}

	else

	{

		document.getElementById('inicio').disabled = true;

		document.getElementById('inicio').style.background = "#F9FFD3";

		document.getElementById('fin').disabled = true;

		document.getElementById('fin').style.background = "#F9FFD3";

		document.getElementById('termino').disabled = true;

		document.getElementById('termino').style.background = "#F9FFD3";

		document.getElementById('btn').disabled = false;

	}

	

}

function carga_inicial()
{
		termino = document.getElementById('termino');
		inicio = document.getElementById('inicio');
		fin = document.getElementById('fin');	
		
		inicio.disabled = true;

		inicio.style.background = "#F9FFD3";

		fin.disabled = true;

		fin.style.background = "#F9FFD3";

		termino.disabled = true;

		termino.style.background = "#F9FFD3";

		document.getElementById('btn').disabled = true;

}

function validar_busqueda(fnoticias)

{

	if (document.getElementById('terminos').value == 4)

	{

		if (fnoticias.inicio.value == null || fnoticias.inicio.value == "" || fnoticias.inicio.value == " " || fnoticias.fin.value == null || fnoticias.fin.value == "" || fnoticias.fin.value == " " || fnoticias.inicio.value == "desde" || fnoticias.inicio.value == "since" || fnoticias.fin.value == "hasta" || fnoticias.fin.value == "to")

		{

			alert("Los campos fecha de inicio y fin no son correctos");

			return false;

		}

		else

		{

			return true;

		}

	}

	if (document.getElementById('terminos').value < 4)

	{

		if (fnoticias.termino.value == null || fnoticias.termino.value == "término" || fnoticias.termino.value == "term" || fnoticias.termino.value == "" || fnoticias.termino.value == " ")

		{

			alert("Debe introducir un término válido");

			return false;

		}

		else

		{

			return true;

		}

	}

}

function validar_usuario(fUsuario)

{

	

	var datos = "";

			

	if (document.fUsuario.nombre.value == "")

	{

		var datos = datos + "\n>> Nombre incompleto";

	}

	

	if (document.fUsuario.apellidos.value == "")

	{

		var datos=datos + "\n>> Apellidos incompleto";

	}

	if (document.fUsuario.email.value == "")

	{

		var datos=datos + "\n>> Email incompleto";

	}

	else

	{

			if (!isValidEmail(document.fUsuario.email.value))

			{

				var datos = datos + "\n>> Email incorrecto";

			}

	}

	

	if (datos != "")

	{

		alert(datos);

		return (false);

	}

	else

	{

		return (true);

	}

	

}

	

//Funcion para validar un email

function isValidEmail(email, required) {

    if (required==undefined) {   // if not specified, assume it's required

        required=true;

    }

    

    email = trim(email);

    

    if (email==null) {

        if (required) {

            return false;

        }

        return true;

    }

    if (email.length==0) {  

        if (required) {

            return false;

        }

        return true;

    }

    if (! allValidChars(email)) {  // check to make sure all characters are valid

        return false;

    }

    if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character

        return false;

    } else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @

        return false;

    } else if (email.indexOf("@") == email.length) {  // @ must not be the last character

        return false;

    } else if (email.indexOf("..") >=0) { // two periods in a row is not valid

	return false;

    } else if (email.indexOf(".") == email.length) {  // . must not be the last character

	return false;

    }

    return true;

}



function allValidChars(email) {

  var parsed = true;

  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";

  for (var i=0; i < email.length; i++) {

    var letter = email.charAt(i).toLowerCase();

    if (validchars.indexOf(letter) != -1)

      continue;

    parsed = false;

    break;

  }

  return parsed;

}



function ltrim(cadena) { 

    return cadena.replace(/^\s+/, ""); 

} 

 

function rtrim(cadena) { 

    return cadena.replace(/\s+$/, ""); 

} 

 

function trim(cadena) { 

    return rtrim(ltrim(cadena)); 

}
function mostrar_capa2(capa)
{
	
	var flagstyle = document.getElementById(capa);
	if (flagstyle.style.display == 'none') 
	{
		flagstyle.style.display = "block";
	}
	else if (flagstyle.style.display == 'block') 
	{
		flagstyle.style.display = "none";
	}
}


