function objetoAjax(){
	var xmlhttp=false;
	try{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}catch(e){
		try{
		   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(E){
			xmlhttp = false;
  		}
	}
	if(!xmlhttp && typeof XMLHttpRequest!='undefined'){
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

function listaVideos(pag)
{
	var ajax;
	ajax=objetoAjax();
	ajax.open("POST", "listaVideos.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) 
		{
			document.getElementById('listado').innerHTML=ajax.responseText;
			ajax2=objetoAjax();
			ajax2.open("POST", "formBuscar.php",true);
			ajax2.onreadystatechange=function() {
				if (ajax2.readyState==4) 
				{
					document.getElementById('formulario').innerHTML=ajax2.responseText;
				}
			}
			ajax2.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			ajax2.send("NULL");		
		}
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.send("pag="+pag);
}
function ultimosVideos()
{
	var ajax;
	ajax=objetoAjax();
	ajax.open("POST", "listaVideos.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) 
		{
			document.getElementById('listado').innerHTML=ajax.responseText;
			ajax2=objetoAjax();
			ajax2.open("POST", "formBuscar.php",true);
			ajax2.onreadystatechange=function() {
				if (ajax2.readyState==4) 
				{
					document.getElementById('formulario').innerHTML=ajax2.responseText;
				}
			}
			ajax2.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			ajax2.send("NULL");		
		}
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.send("ultimosVideos=si");
}
function ultimosInterpretes()
{
	var ajax;
	ajax=objetoAjax();
	ajax.open("POST", "listaInterpretes.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) 
		{
			document.getElementById('listado').innerHTML=ajax.responseText;
			ajax2=objetoAjax();
			ajax2.open("POST", "formBuscar.php",true);
			ajax2.onreadystatechange=function() {
				if (ajax2.readyState==4) 
				{
					document.getElementById('formulario').innerHTML=ajax2.responseText;
				}
			}
			ajax2.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			ajax2.send("NULL");		
		}
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.send("ultimosInterpretes=si");
}

function filtroLista(id, texto){
	if(texto=="")texto="filtroVideosNormal.php"
	var ajax;
	ajax=objetoAjax();
	ajax.open("POST", texto,true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) 
		{
			document.getElementById('listado').innerHTML=ajax.responseText;				
			ajax2=objetoAjax();
			ajax2.open("POST", "formBuscar.php",true);
			ajax2.onreadystatechange=function() {
				if (ajax2.readyState==4) 
				{
					document.getElementById('formulario').innerHTML=ajax2.responseText;
				}
			}
			ajax2.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			ajax2.send("NULL");		
		}
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.send("id_interprete="+id+"&texto="+texto);
}

function addContenido(ruta, param){
	var ajax;
	ajax=objetoAjax();
	ajax.open("POST", ruta,true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) 
		{
			document.getElementById('listado').innerHTML=ajax.responseText;
		}
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.send(param);
}

function cambioDireccion()
{
	texto = document.getElementById('cRuta2').value;
	if(texto !="")
	{
		textoFin = texto.replace("watch?v=","v/");
		document.getElementById('cRuta').value=textoFin;		
	}
}


function cargoVideo(id){
	var ajax;
	ajax=objetoAjax();
	ajax.open("POST", "cargoVideo.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) 
		{
			document.getElementById('contenedorVideo').innerHTML=ajax.responseText;
		}
		else
		{
			document.getElementById('contenedorVideo').innerHTML="<img src='../imagenes/cargando.gif'>";			
		}
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.send("id="+id);
}

function gestionVideos(pag)
{
	var ajax;
	ajax=objetoAjax();
	ajax.open("POST", "gestionVideos.php");
	ajax.onreadystatechange=function() {	
		if (ajax.readyState==4) 
		{
			document.getElementById('listado').innerHTML=ajax.responseText;	
			ajax2=objetoAjax();
			ajax2.open("POST", "formBuscarAdmin.php",true);
			ajax2.onreadystatechange=function() {
				if (ajax2.readyState==4) 
				{
					document.getElementById('formulario').innerHTML=ajax2.responseText;
				}
			}
			ajax2.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			ajax2.send("NULL");		
		}
		else
		{
			document.getElementById('listado').innerHTML="<img src='../imagenes/cargando.gif'>";			
		}

	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.send("pag="+pag);	
}

function buscadorVideos(interprete, titulo, estilo, tema, destino, registros ,pag, pais)
{
	var ajax;
	ajax=objetoAjax();
	if(!pag)pag=1;
	ajax.open("POST", destino,true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) 
		{
			document.getElementById('listado').innerHTML=ajax.responseText;
		}
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.send("interprete="+interprete + "&titulo="+titulo+"&tema="+tema+"&estilo="+estilo+"&pag="+pag+"&limiteReg="+ registros+"&pais="+pais);
}

function borroVideo(id, pag)
{
	if(confirm("seguro que quieres borrar el video ?"))
	{
		var ajax;
		ajax=objetoAjax();

		ajax.open("POST", "gestionVideos.php",true);
		ajax.onreadystatechange=function() {
			if (ajax.readyState==4) 
			{
				document.getElementById('listado').innerHTML=ajax.responseText;
			}
		}
		ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		ajax.send("idVideo="+id+"&borrar=si&pag="+pag);		
	}
}


function tecla(tipo)
{

	destino 	= "filtroVideos" + tipo +".php"
	autor 		= document.getElementById('cAutor').value;
	titulo 		= document.getElementById('cTitulo').value;
	estilo 		= document.getElementById('cEstilo').value;	
	tema 		= document.getElementById('cTema').value;
	registros   = document.getElementById('limiteReg').value;
	pais		= document.getElementById('cPais').value;	
//	alert("pais" + pais);
	buscadorVideos(autor, titulo, estilo, tema, destino, registros, 0,pais);				
}

function envioDatosVideo()
{
	// defino los campos a enviar
	ruta   		= document.getElementById('cRuta').value;
	titulo 		= document.getElementById('cTitAdd').value;
	estilo 		= document.getElementById('cEstiloAdd').value;
	proveedor 	= document.getElementById('cProveedor').value;
	boton  		= document.getElementById('bEnviar').value;		
	interprete 	= document.getElementById('id_interprete').value;
//	alert("estilo" + estilo + "titulo"+ titulo);
	if(ruta!="" && estilo!="" && titulo!="")
	{
		var ajax;
		ajax=objetoAjax();
		ajax.open("POST", "addVideo.php",true);
		ajax.onreadystatechange=function() {
			if (ajax.readyState==4) 
			{
				document.getElementById('listado').innerHTML=ajax.responseText;
			}
		}
		ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		ajax.send("cProveedor="+proveedor+"&cRuta="+ruta + "&cTitAdd="+titulo+"&cEstiloAdd="+estilo+"&id_interprete="+interprete+"&bEnviar="+boton);
	}
}

function modificoDatosVideo()
{
	// defino los campos a enviar
	estilo 		= document.getElementById('cEst').value;
	ruta   		= document.getElementById('cRuta').value;
	titulo 		= document.getElementById('cTit').value;
	boton  		= document.getElementById('bEnviar').value;		
	interprete	= document.getElementById('idInterprete').value;
	video 		= document.getElementById('idVideo').value; 
	proveedor   = document.getElementById('cProveedor').value;
	if(ruta!="" && estilo!="" && titulo!="")
	{
		var ajax;
		ajax=objetoAjax();	
		ajax.open("POST", "modificoVideo.php",true);
		ajax.onreadystatechange=function() {
			if (ajax.readyState==4) 
			{
				document.getElementById('listado').innerHTML=ajax.responseText;
				guardoTema('',video);
			}
		}
		ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		ajax.send("idVideo="+video+"&cRuta="+ruta + "&cTit="+titulo+"&cEst="+estilo+"&idInterprete="+interprete+"&cProveedor="+proveedor+"&bEnviar="+boton);
	}
}

function guardoTema(idTema, idVideo, operacion)
{
		var ajax;
		ajax=objetoAjax();
		ajax.open("POST", "addTema.php",true);
		ajax.onreadystatechange=function() {
			if (ajax.readyState==4) 
			{
				document.getElementById('divTemas').innerHTML=ajax.responseText;
			}
		}
		ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		ajax.send("idVideo=" + idVideo + "&idTema=" + idTema+"&operacion="+operacion);
}

function listadoVacio()
{
		var ajax;
		ajax=objetoAjax();
		ajax.open("POST", "listadoVacio.php",true);
		ajax.onreadystatechange=function() {
			if (ajax.readyState==4) 
			{
				document.getElementById('contenedorVideo').innerHTML=ajax.responseText;
			}
		}
		ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		ajax.send("NULL");
	
}
/////////////////////contacto////////////////////
function contacto()
{
	window.open('contacto.php','contacto','width=350px, height=440px')
}
function foro()
{
	window.open('foro.php','foro','width=350px, height=440px')
}
