//función para abrir videos pop-up
function abrir_vid(cod){
var ruta="http://multimedia.local.terra.es/viewer/portada.cfm?cod_media="+cod+unescape('%26')+"mapnivel1=WWE";
window.open(ruta,'','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=0,width=572,height=320,left=0,top=0');
}

//función para abrir videos pop-up en formato panoramico 480x270
function abrir_vid480(cod){
var ruta="http://multimedia.local.terra.es/viewer480x270/portada.cfm?cod_media="+cod+unescape('%26')+"mapnivel1=WWE";
window.open(ruta,'','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=0,width=840,height=440,left=0,top=0');
}

var num=10;
function muestra(id_num){
document.getElementById('img_video_'+id_num).style.display="block";
for (i=1;i<=num;i++){
if (i!=id_num){document.getElementById('img_video_'+i).style.display="none";}
}
}

//buscador noticias
function sub_busq(formulario)
{

if(formulario.pkcadena.value == '')
{alert("Debes introducir una cadena para la búsqueda");return false;}

else
{if(formulario.pkcadena.value.length < 2 ){alert("La cadena de búsqueda debe ser mayor de 2 caracteres");return false;}}
formulario.action  = "/buscador/" +'portada.cfm';
formulario.submit()
}

//buscador videos
function sub_busq_vid(formulario)
{

if(formulario.pkcadena.value == '')
{alert("Debes introducir una cadena para la búsqueda");return false;}

else
{if(formulario.pkcadena.value.length < 2 ){alert("La cadena de búsqueda debe ser mayor de 2 caracteres");return false;}}
formulario.action  = "/buscadorvideos/" +'portada.cfm';
formulario.submit()
}

//función para album de fotos columna derecha
var n=1;
var num_old=1;
function escribeDivThumbs2(cadenita) {
num_act=cadenita;
document.getElementById('album_'+num_old).className='imgalbumhidden';
document.getElementById('albumtxt_'+num_old).className='txtalbumhidden';
document.getElementById('album_'+num_act).className='imgalbum';
document.getElementById('albumtxt_'+num_act).className='txtalbum';
num_old=num_act;
}
function cambio_foto(q){
if (q==1){
n++;
if (n > 10) n=1;
}
else {
n--;
if ( n <= 0 ) n=10;
}
escribeDivThumbs2(n);
}
function escribeDivThumbs2(cadenita) {
num_act=cadenita;
document.getElementById('album_'+num_old).className='imgalbumhidden';
document.getElementById('albumtxt_'+num_old).className='txtalbumhidden';
document.getElementById('album_'+num_act).className='imgalbum';
document.getElementById('albumtxt_'+num_act).className='txtalbum';
num_old=num_act;
}
function cambio_foto(q){
if (q==1){
n++;
if (n > 10) n=1;
}
else {
n--;
if ( n <= 0 ) n=10;
}
escribeDivThumbs2(n);
}

//encuesta del día
function votar(valor){
document.frm_pregunta_dia.frm_voto[valor].checked=true;
v=valor+1;
url_preg='/encuesta_deldia/votar.cfm?r='+v+unescape('%26')+'id=14214'+unescape('%26')+'nivel=WWEAAAAAAAAAAAAAAA';
window.open(url_preg,'Preg','toolbar=no,location=no,directories=no,status=no, menubar=no,scrollbars=no,resizable=yes,width=535,height=519,screenX=50,screenY=50');
}
function ver_resultados(){
window.open('/encuesta_deldia/votar.cfm?id=14214'+unescape('%26')+'nivel=WWEAAAAAAAAAAAAAAA','Preg','toolbar=no,location=no,directories=no,status=no, menubar=no,scrollbars=no,resizable=yes,width=535,height=515,screenX=50,screenY=50');
}

//apertura de ventanas en pop-up
function abrir_ventana(pagina,titulo,tamano){

		ventana=window.open(pagina, titulo, tamano+',scrollbars=no, status=no');

		ventana.focus();

		}

//funcion que llama a la librería jquery para la carga de capas
var capa_com;
capa_com=$(document);
capa_com.ready(inicializarEventos);

function inicializarEventos()
{
 var capa_com=$("#mostrar");
 capa_com.click(ocultarMostrarRecuadro);
}

function ocultarMostrarRecuadro()
{
 var capa_com=$("#form_coment");
 capa_com.toggle("slow");
}

//funcion para la validación del formulario de los comentarios
var RL = "";
		function enviar_formulario(ok) {
			var formulario = null;
			var msg = "";
			if (document.all)
			{
				formulario = document.getElementById("fComenta");
			}
			else {
				formulario = document.fComenta;
			}
			
			formulario.goto.value = new String(location.href);
			
			if (formulario.nombre.value.length==0) {
				msg = "Debes introducir tu nombre";
			}
			else if (!bValidaMail(formulario.email.value)) {
				msg = "La dirección de correo introducida no es correcta: ";
				}
			else if (formulario.comentario.value.length==0) {
				msg = "Debes introducir el texto en el campo \"comentario\"";
			}
			else if (buscarHTMLTags(formulario)) {
				msg = "No puedes escribir código HTML en el formulario";
			}
			else if (buscarPalabrasLargas(formulario)) {
				msg = "No puedes escribir palabras tan largas en el formulario";
			}
			//else if ((formulario.urlblog.value!="")&&(!bValidaURL(formulario.urlblog.value))) {
				//msg = "Debes introducir una URL válida";
			//}
			else if(!ok) {
				msg = "Los caracteres introducidos no coinciden con la imagen";
			}
			else {
				formulario.submit();
			};
			
			if (msg!="") alert(msg);			
		}

		function buscarHTMLTags(formulario) {
			if (formulario.comentario.value.search(/(<([^>]+)>)/ig,"")==-1) {
				formulario.comentario.value = formulario.comentario.value.replace(/</ig,"&lt;");
				formulario.comentario.value = formulario.comentario.value.replace(/>/ig,"&gt;");
				/* Añadir que los retornos de carro múltiples sean 1 y no dejar cadenas de más de 70 caracteres */ 
				return false;
			}
			else return true;
		}
		
		function buscarPalabrasLargas(formulario) {
			if (formulario.comentario.value.search(/[A-Za-z0-9]{70,}/ig,"")==-1)  {
				return false;
			}
			return true;
		}
		
		function bValidaMail (Email)
		{
		  var Reason = "";
		  var checkStr = Email;
		  var ix = (checkStr.length - 4);
		  var RC = true;
		  var x = AtSignValid = DoublePeriod = PeriodValid = SpaceValid = ExtValid = RL = 0;
		  for (i = 0;  i < checkStr.length;  i++)
		  {
		    if (checkStr.charAt(i) == '@')
		      AtSignValid++;
		    else if (checkStr.charAt(i) == '.')
		    {
		      if (x == (i-1))
		        DoublePeriod++;
		      else
		      {
		        x = i;
		        PeriodValid++;
		      }
		    }
		    else if (checkStr.charAt(i) == ' ')
		      SpaceValid ++;
		  }
		  RL = Reason.length;
		  if (AtSignValid != 1)
		    Reason += "Debe existir un signo @ único en la dirección del E-mail.  ";
		  if (PeriodValid == 0)
		    Reason += "La dirección del E-mail debe contener al menos un punto.  ";
		  if (SpaceValid > 0)
		    Reason += "No se deben introducir espacios en el E-Mail  ";
		  if (DoublePeriod > 0)
		    Reason += "La dirección de E-Mail contiene múltiples puntos sucesivos.  ";
		  if (RL != Reason.length)
		  {
		    RC= false;
		  }
		  else
		  {
		    RC= true;
		  }
		  return RC;
		}
		
		function bValidaURL(sURL) {
			/* VALIDACIÓN DE MI URL */
		    var http = "http://";
			var es_url;

			if (sURL.length!=0) 
			{
			     if(sURL.length <= 7) {
	       		     es_url = false;
				 }
	 			 else {
				     es_url = (http.indexOf(sURL.substring(0, 7)) != - 1); /* lee "http://*" */
				 }
				 
				 if (es_url == false) {
				 	return false;
				 }
				 else {
				 	return true;
				 }
			 }
			 else {
			 	return false;
			 }
		}
		//función para mostrar y ocultar las pestañas de la página de vídeos
		function mostrar(id){
	if (id=="pestanas_videos1"){
		document.getElementById("pestanas_videos1").style["display"]='block';
		document.getElementById("pestanas_videos2").style["display"]='none';
		document.getElementById("pestanas_videos3").style["display"]='none';
		document.getElementById("pestanas_videos4").style["display"]='none';
		document.getElementById("pestanas_videos5").style["display"]='none';
		document.getElementById("pestanas_videos6").style["display"]='none';
	}
	if (id=="pestanas_videos2"){
		document.getElementById("pestanas_videos1").style["display"]='none';
		document.getElementById("pestanas_videos2").style["display"]='block';
		document.getElementById("pestanas_videos3").style["display"]='none';
		document.getElementById("pestanas_videos4").style["display"]='none';
		document.getElementById("pestanas_videos5").style["display"]='none';
		document.getElementById("pestanas_videos6").style["display"]='none';
	}
	if (id=="pestanas_videos3"){
		document.getElementById("pestanas_videos1").style["display"]='none';
		document.getElementById("pestanas_videos2").style["display"]='none';
		document.getElementById("pestanas_videos3").style["display"]='block';
		document.getElementById("pestanas_videos4").style["display"]='none';
		document.getElementById("pestanas_videos5").style["display"]='none';
		document.getElementById("pestanas_videos6").style["display"]='none';
	}
	if (id=="pestanas_videos4"){
		document.getElementById("pestanas_videos1").style["display"]='none';
		document.getElementById("pestanas_videos2").style["display"]='none';
		document.getElementById("pestanas_videos3").style["display"]='none';
		document.getElementById("pestanas_videos4").style["display"]='block';
		document.getElementById("pestanas_videos5").style["display"]='none';
		document.getElementById("pestanas_videos6").style["display"]='none';
	}
	if (id=="pestanas_videos5"){
		document.getElementById("pestanas_videos1").style["display"]='none';
		document.getElementById("pestanas_videos2").style["display"]='none';
		document.getElementById("pestanas_videos3").style["display"]='none';
		document.getElementById("pestanas_videos4").style["display"]='none';
		document.getElementById("pestanas_videos5").style["display"]='block';
		document.getElementById("pestanas_videos6").style["display"]='none';
	}
	if (id=="pestanas_videos6"){
		document.getElementById("pestanas_videos1").style["display"]='none';
		document.getElementById("pestanas_videos2").style["display"]='none';
		document.getElementById("pestanas_videos3").style["display"]='none';
		document.getElementById("pestanas_videos4").style["display"]='none';
		document.getElementById("pestanas_videos5").style["display"]='none';
		document.getElementById("pestanas_videos6").style["display"]='block';
	}
}
