/*  ### GENERALES ###  */

///	 Para evitar copiar y pegar texto.

function Seg()
{
	document.onselectstart = function() {return false;} // ie
	document.onmousedown = function() {return false;} // mozilla
}

///	 Función para el cambio de hojas de estilo

function setActiveStyleSheet(title)
{
	var i, a, main;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++)
	{
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title"))
		{
			a.disabled = true;
			if(a.getAttribute("title") == title) a.disabled = false;
		}
     }
}

///	 Funciones para controlar el botón de vover.

var vNumPaginas = -1;

function retroceder() {  vNumPaginas --; }
function volver() { history.go(vNumPaginas); }

///	 Función para imprimir.

function AbreVentana(pDestino, pAncho, pAlto)
{
	var vCaracteristicas='scrollbars=2, resizable=no, width='+ pAncho +', height='+ pAlto +', top=50, left=50';
	var ventana = window.open("", "", vCaracteristicas);
	ventana.location = pDestino;
}

function VerFoto(pDestino)
{
	var vCaracteristicas='scrollbars=2, resizable=no, width=820, height=620, top=50, left=50';
	var ventana = window.open("", "", vCaracteristicas);
	ventana.location = pDestino;
}

/*  ### FORMULARIOS ###  */

/// Función que sólo permite introducir números en un formulario.

function SoloNum()
{
	if ( event.keyCode >= 58 || event.keyCode <= 47)
		event.keyCode=0;
}

///	 Funciones de insercción de texto en los formularios.

function DepuraBuscador()
{
	if (document.formulario.pregunta.value.length == 0)
		return false;
	else
		return true;
}

function DepuraAcceso()
{
	if (document.acceso.fUsuario.value.length == 0)
	{
		document.acceso.fUsuario.style.backgroundColor = "#EFCBCB";
		return false;
	}
	if (document.acceso.fClave.value.length == 0)
	{
		document.acceso.fClave.style.backgroundColor = "#EFCBCB";
		return false;
	}

	return true;
}

///	 Funciones para controlar el número de caracteres de un textarea.

function ContarTexto(pCampo, pBarraContador, pLimiteCar, pLineas)
{
	//	Ancho del texto
	var vAnchoCampo =  parseInt(pCampo.style.width);
	var vContCar = pCampo.value.length;        
	//	Quitar el texto sobrante
	if (vContCar > pLimiteCar)
	{ 
		pCampo.value = pCampo.value.substring(0, pLimiteCar);
	}
	else
	{ 
		// progress bar percentage
		var vPorcentaje = parseInt(100 - ((pLimiteCar - vContCar) * 100)/pLimiteCar) ;
		document.getElementById(pBarraContador).style.width =  parseInt((vAnchoCampo*vPorcentaje)/100)+"px";
		// color correction on style from CCFFF -> CC0000
		PonerColor(document.getElementById(pBarraContador), vPorcentaje, "background-color");
	}
}

function PonerColor(obj, percentage, prop)
{
	obj.style[prop] = "rgb(80%,"+(100-percentage)+"%,"+(100-percentage)+"%)";
}

///	 Función que depura el formulario de contacto.

function Depura_Contactar()
{
	if (document.formulario.fNombre.value.length == 0)
	{
		alert("Por favor rellene la casilla 'mi nombre'.");
		document.formulario.fNombre.focus();
		return false;
	}
	if (document.formulario.fApellidos.value.length == 0)
	{
		alert("Por favor rellene la casilla 'mis apellidos'.");
		document.formulario.fApellidos.focus();
		return false;
	}
	if (document.formulario.fEmail.value.length == 0)
	{
		alert("Por favor rellene la casilla 'mi e-Mail'.");
		document.formulario.fEmail.focus();
		return false;
	}
	if (document.formulario.fConsulta.value.length == 0)
	{
		alert("Por favor, rellene la casilla 'mi consulta'.");
		document.formulario.fConsulta.focus();
		return false;
	}

	return true;
}

/*  ### MISCELANOUS ###  */

///	 Función que muestra u oculta capas.

function Activar(pCapa)
{
	var vCapa = document.getElementById(pCapa);

	if (!vCapa) return true;

	if (vCapa.style.display == 'block')
		vCapa.style.display="none";
	else
		vCapa.style.display="block";

	return true;
}

///	 Función para escribir una dirección de correo sin SPAM

function PonerCorreo(pNombre, pDominio, pSufijo)
{
	document.write('<a href="' + 'mailto:' + pNombre + '@' + pDominio + '.' + pSufijo + '">' + pNombre + '@' + pDominio + '.' + pSufijo + '</a>');
}

///	 Scroll de la barra de estado

var data = "AVCRKIFLST";
var done = 1;

function statusIn(text)
{
	decrypt(text, 2, 20);
}

function decrypt(text, max, delay)
{
	if (done)
	{
		done = 0;
		decrypt_helper(text, max, delay,  0, max);
   }
}

function decrypt_helper(text, runs_left, delay, charvar, max)
{
	if (!done)
	{
		runs_left = runs_left - 1;
		var status = text.substring(0, charvar);
		for (var current_char = charvar; current_char < text.length; current_char++)
		{
			status += data.charAt(Math.round(Math.random()*data.length));
		}
		
		window.status = status;
		var rerun = "decrypt_helper('" + text + "'," + runs_left + "," + delay + "," + charvar + "," + max + ");"
		var new_char = charvar + 1;
		var next_char = "decrypt_helper('" + text + "'," + max + "," + delay + "," + new_char + "," + max + ");"
		if(runs_left > 0)
		{
			setTimeout(rerun, delay);
		}
		else
		{
			if (charvar < text.length)
			{
				setTimeout(next_char, Math.round(delay*(charvar+3)/(charvar+1)));
			}
			else
			{
				done = 1;
	         }
		}
	}
}

// Función que cambia imágenes

var bannerImg = new Array();
  // Enter the names of the images below
  bannerImg[0]="../graficos/portada/bebes.jpg";
  bannerImg[1]="../graficos/portada/matro.jpg";
  bannerImg[2]="../graficos/portada/aquagym.jpg";

var newBanner = 0;
var totalBan = bannerImg.length;

function cycleBan() 
{
	newBanner ++;
	if (newBanner == totalBan) 
	{
		newBanner = 0;
	}
  
	document.IMAGENPORTADA.src=bannerImg[newBanner];
	// set the time below for length of image display
	// i.e., "4*1000" is 4 seconds
	setTimeout("cycleBan()", 4*1000);
}