function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function idioma(lg)
{
	var url= ""+window.location+"";
	var pos=url.indexOf("?");
	var cadenaLoging
	cadenaLoging="";
	
	if ((document.getElementById("S").value!="")&&(document.getElementById("C").value!=""))
	{
	cadenaLoging = "&S="+document.getElementById("S").value+"&C="+document.getElementById("C").value;
	}
	
	if ((pos>-1)&&(document.getElementById("txtidVideo").value!=""))
	{
		window.location=url.substring(0,pos)+"?Lang="+lg+"&txtidVideo="+document.getElementById("txtidVideo").value+cadenaLoging;
	}
	else if (pos>-1)
	{
		window.location=url.substring(0,pos)+"?Lang="+lg+cadenaLoging;
	}
	else if (document.getElementById("txtidVideo").value!="")
	{
		window.location=url+"?Lang="+lg+"&txtidVideo="+document.getElementById("txtidVideo").value+cadenaLoging;
	}
	else
	{
		window.location=url+"?Lang="+lg+cadenaLoging;
	}
}
function IrA(pagina)
{
	with(document.frmCuerpo)
	{
		action=pagina+".asp";
		target="";
		submit();
	}
}

function IrA2(pagina,idcat)
{
	with(document.frmCuerpo)
	{
		action=pagina+".asp?idcat="+idcat;
		target="";
		submit();
	}
}

function VerVideo(idVideo)
{
	with(document.frmCuerpo)
	{
		if (document.frmCuerpo.txtidVideo)	
		{
			txtidVideo.value=idVideo;
		}
		action="fichavideo.asp?txtidVideo="+idVideo;
		submit()
	}
}

function VerVideoG(idVideo)
{
	with(document.frmCuerpo)
	{
		if (document.frmCuerpo.txtidVideo)	
		{
			txtidVideo.value=idVideo;
		}
		target="_blank";
		action="../fichavideo.asp?txtidVideo="+idVideo;
		submit()
	}
}

function LogIn()
{
	with(document.frmCuerpo)
	{
		if (txtUsuario.value=='' || txtClave.value==''){
			alert(funcion1)
			if (txtUsuario.value=='') 
				{txtUsuario.focus();}
			else
				{txtClave.focus();}
		} else {
			action="validausuario.asp?URL="+document.URL;
			submit();
		}
	}
}

function VotarVideo(puntos,idVideo,idUsuario)
{
	$.ajax(
	{
		timeout:2000,
        type: "POST",
        url: "Votar.asp",
        data: {puntos:puntos,idUsuario:idUsuario,idVideo:idVideo},
        success: function(datos)
		{
			//alert(datos);
          	result=datos.split("$%$");
		  	RecargarFuncionesVotar(result[1]);
			VotarVideoMouseOut(result[1]);
			$("#Nvotosp").html(result[0]);
			alert("Gracias Por Votar.");//\nNºVotos: "+result[0]+"\nPuntos: "+result[1]);
        },
		error: function(obj1, e, obj2)
		{
			alert("Se produjo un error : "+ e+obj1.status);
		}
	});
}

function RecargarFuncionesVotar(ptos)
{
	for (var a=1;a<=5;a++)
	{
		document.getElementById("star"+a).onmouseover=function () {VotarVideoMouseOver(ptos,a);};
	}
	
	document.getElementById("Votos").onmouseout=function () {VotarVideoMouseOut(ptos);};
	
}

function VotarVideoMouseOut(ptos)
{
	for (var a=1;a<=5;a++)
	{
		if (a>ptos)
		{
			document.getElementById("star"+a).src="img/estrella.gif";
		}
		else
		{
			document.getElementById("star"+a).src="img/star_ama.jpg";
		}
	}
}

function VotarVideoMouseOver(ptos,Nptos)
{
	for (var a=1;a<=5;a++)
	{
		//alert(Nptos+" "+ptos+" "+a);
		if (Nptos>=a)
		{
			document.getElementById("star"+a).src="img/star_roja.jpg";
		}
		else if (ptos>=a)
		{
			document.getElementById("star"+a).src="img/star_ama.jpg";
		}
		else
		{
			document.getElementById("star"+a).src="img/estrella.gif";
		}
	}	
}

function LogOut()
{
	with(document.frmCuerpo)
		{
		action="validausuario.asp?URL="+document.URL;
		submit();
		//location.href="validausuario.asp?txtUsuario=&txtClave=&URL="+document.URL
		}
}

function VerCateg(idCategoria){
	location.href="categorias.asp?idCategoria="+idCategoria+"&Lang="+document.getElementById("Lang").value+"&S="+document.getElementById("S").value+"&C="+document.getElementById("C").value;
}

function Busquedas(a)
{
	with(document)
	{
		if (a!=2)
		{
			
			if (getElementById("txtBusqueda").value!="")
			{
				frmCuerpo.action="busqueda.asp";
				frmCuerpo.submit();
				//getElementById("txtBusqueda2").value="";
			}
			else
			{
				alert(funcion3);
			}
		}
		else
		{
			
			if (getElementById("txtBusqueda2").value!="")
			{
				frmCuerpo.action="busqueda.asp";
				frmCuerpo.submit();
				getElementById("txtBusqueda").value="";
			}
			else
			{
				alert(funcion3);
			}
		}
	}
}

function enter(evento,pag) 
{
	if ((evento.which == 13) || (evento.keyCode == 13))
	{
		Busquedas(pag);
	}
}

function ListarPagina(i)
{
	with(document.frmCuerpo)
	{
		txtPaginaListado.value=i;
		action=document.location.href;
		submit()
	}
}

function validarCaracteres(fil)
{
	if(!(/^[\w?\.\-:\\\sñÑáÁéÉíÍóÓúÚ]{1,}$/.test(fil)))
	{
		alert(funcion4+" "+fil);
	}
	
}
$=jQuery;
//Variable que almacena la posición del scroll, por defecto tiene valor 0.
scrollCachePosition = 0;
function popupCssShow (URL,data, width, height) { //Parámetros: URL (URL, Anchura de la capa, Altura de la capa)
    if (typeof document.body.style.maxHeight === "undefined") {//Añade la propiedad maxHeight para IE6.
        $("body","html").css({height: "100%", width: "100%"});
    }
    //La capa 'cssBackground' ocupa toda la pantalla para darle una opacidad.
    //La capa 'cssPopupContainer' es la capa madre del PopUp.
    if (!$("#cssBackground").length>0) {
        $("body").append("<div id=\"cssBackground\"></div><div id=\"cssPopupContainer\"><div id=\"cssPopup\"></div></div>"); //Añade las capas en la página.
    }
    if (width!=undefined) {
        $("#cssPopup").css("width",width);
    }
    if (height!=undefined) {
        $("#cssPopup").css("height",height);
        $("#cssPopup").css("overflow","auto");
    }
	$("embed").css("visibility","hidden");
    $("#cssBackground").slideDown("slow"); //Efecto jQuery
    scrollCachePosition = $(window).scrollTop();
    window.top.scroll(0,0);
    $("#cssPopup").load(URL,data,function(a,b,c){
	//$("#cssPopupContainer").center(); //Si activamos esta línea y desactivamos la de abajo nos centrará el PopUp en el medio de la pantalla.
        $("#cssPopupContainer").css("top",50);
        ancho=$(window).width();
        $("#cssPopupContainer").slideDown("fast", function () {
            anchopopup=$("#cssPopup").width();
            $("#cssPopupContainer").css("width",ancho);
        });
    });
	
}
 
function popupCssHide () {
	
    $("#cssPopupContainer").slideUp("fast", function () {
        $("#cssBackground").fadeOut("fast",function () {
            $("#cssBackground").remove(); //Elimina la capa 'cssBackground'.
            $("#cssPopupContainer").remove(); //Elimina la capa 'cssPopupContainer'.
			$("embed").css("visibility","visible");
        });
    });
    if (scrollCachePosition > 0) {
        window.top.scroll(0,scrollCachePosition); //Vuelve a la posición donde estaba el scroll.
        //Reseteamos la variable scrollCachePosition a 0 para poder ejecutar el script tantas veces como sea necesario.
        scrollCachePosition = 0;
    }
	
}

function MiCuenta(C,S)
{
	popupCssShow ("EditarCuenta.asp",{C:C,S:S}, 450);
}

function EditaryVolver(IdUsuario)
{
	var d=document;
	var Nombre_Ed = d.getElementById("Nombre_Ed").value;
	var Apellidos_Ed = d.getElementById("Apellidos_Ed").value;
	var Nick_Ed = d.getElementById("Nick_Ed").value;
	var Email_Ed = d.getElementById("Email_Ed").value;
	var Usuario_Ed = d.getElementById("Usuario_Ed").value;
	var Clave_Ed = d.getElementById("Clave_Ed").value;
	
	if((Nombre_Ed=="")||(Apellidos_Ed=="")||(Nick_Ed=="")||(Email_Ed=="")||(Usuario_Ed=="")||(Clave_Ed==""))
	{
		alert("obli");
	}
	else if (!validateEmail(Email_Ed))
	{
		alert("El email no es valido.");
		d.getElementById("Email_Ed").focus();
	}
	else
	{
		$.ajax({
		   type: "POST",
		   timeout: 1800,
		   url: "Gestor/Ajax_Function/ActualizarUsuario.asp",
		   data: {Nombre_Ed:Nombre_Ed,Apellidos_Ed:Apellidos_Ed,Nick_Ed:Nick_Ed,Email_Ed:Email_Ed,Usuario_Ed:Usuario_Ed,Clave_Ed:Clave_Ed,IdUsuario:IdUsuario,C:C,S:S},
		   error: function(msg){alert(msg.status+" "+msg.statusText)},
		   success: function(msg){
			 if (msg=="0")
			 {
				alert("Error de bbdd.");
			 }
			 else if (msg=="2")
			 {
				alert("Usuario no autorizado.");
			 }
			 else if (msg=="3")
			 {
				alert("Usuario en uso.");
			 }
			 else if (msg=="4")
			 {
				alert("Email en uso.");
			 }
			 else if (msg=="1")
			 {
				$("#NickBienvenida").html(Nick_Ed);
				popupCssHide ();
				alert("Su cuenta ha sido actualizada.");
			 }
			 else
			 {
				alert(msg);
			 }
		   }
		});
	}
}

function validateEmail(elementValue){      
   var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
   return emailPattern.test(elementValue); 
 }
 
 function recordarPass()
 {
	popupCssShow ("RecordarPass.asp",null, 450);	 
 }
 
function EnviarPass()
{
	var d=document;
	var Email_Rec = d.getElementById("Email_Rec").value;
	
	
	if(Email_Rec=="")
	{
		alert("obli");
	}
	else if (!validateEmail(Email_Rec))
	{
		alert("El email no es valido.");
		d.getElementById("Email_Rec").focus();
	}
	else
	{
		$.ajax({
		   type: "POST",
		   timeout: 3600,
		   url: "EnviarPass.asp",
		   data: {Email_Rec:Email_Rec},
		   error: function(msg){try {alert(msg.status+" "+msg.statusText)}catch(e){alert("Por un error puede que no se haya enviado su email. Vuelva a intentarlo.")}},
		   success: function(msg){
			 if (msg=="0")
			 {
				alert("Error de Envio.");
			 }
			 else if (msg=="2")
			 {
				alert("Email no esta registrado.");
			 }
			 else if (msg=="1")
			 {
				popupCssHide ();
				alert("Su contraseña a sido enviado a su Email.");
			 }
			 else
			 {
				alert(msg);
			 }
		   }
		});
	}
}