function nuevoAjax() {
  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;
}

//ajax -----------------------------------------------------------------
var req;
function freq() {
	req = false;		
	// Intenta crear el objeto para Mozilla/Safari
	objAjax = nuevoAjax();
	if(window.XMLHttpRequest) 
	{
		try 
		{
			req = new XMLHttpRequest();
		}//Fin try 
		catch(e) 
		{
			req = false;
		}//Fin catch						
	}//Fin if 
	else if(window.ActiveXObject) 
	{
		try 
		{
			req = new ActiveXObject("Msxml2.XMLHTTP");
		}//Fin Try 
		catch(e) 
		{
			try 
			{
				req = new ActiveXObject("Microsoft.XMLHTTP");
			}//Fin Try 
			catch(e) 
			{
				req = false;
			}//Fin catch
		}//Fin catch
	}//Fin else	
}//Fin Funcion	



function devolver_descargas(id) 
{
	freq();
	if(req) 
	{	
		req.onreadystatechange = procesar_respuesta;
		url = 'ajax/frm_getDescargas.php?cat=' + id;		
		req.open('GET', url, true);
		req.send(null);
	}//Fin if		
}


function devolver_contenido(id) 
{
	freq();
	if(req) 
	{	
		req.onreadystatechange = procesar_respuesta;
		url = 'ajax/frm_getContenido.php?cat=' + id;		
		req.open('GET', url, true);
		req.send(null);
	}//Fin if		
}


function procesar_respuesta() 
{	
	if (req.readyState == 4) 
	{	
		if (req.status == 200) 
		{
			arr = req.responseText.split("|");
			opciones = arr[0].split("*");
			document.getElementById('titulo_texto').innerHTML ='<h1>'+opciones[0]+'</h1>';
			document.getElementById('contenido_medio').innerHTML =opciones[1];
			if(opciones[2] != ''){
				document.getElementById('contenido_derecha').innerHTML =opciones[2]+'<div><b>'+opciones[3]+'</b></div>';
			}
			else if(opciones[3] != ''){
				document.getElementById('contenido_derecha').innerHTML ='<div><b>'+opciones[3]+'</b></div>';
			}
			else{
				document.getElementById('contenido_derecha').innerHTML ='';
			}
		}//Fin if 
		else 
		{
			alert("¬error¬:\n" + req.statusText);
		}//Fin else
	}//Fin if
}//Fin procedar_respuesta


function devolver_contenido_sub(id) 
{
	freq();
	if(req) 
	{	
		req.onreadystatechange = procesar_respuesta2;
		url = 'ajax/frm_getContenidoSub.php?sub=' + id;		
		req.open('GET', url, true);
		req.send(null);
	}//Fin if		
}


function procesar_respuesta2() 
{	
	if (req.readyState == 4) 
	{	
		if (req.status == 200) 
		{
			arr = req.responseText.split("|");
			opciones = arr[0].split("*");
			document.getElementById('titulo_texto').innerHTML ='<h1>'+opciones[0]+'</h1>';
			document.getElementById('contenido_medio').innerHTML =opciones[1];
			if(opciones[2] != ''){
				idiomas(opciones[3]);
			
			}
			else if((opciones[4] != '') && (opciones[4] != 0)){
				archivos(opciones[5]);
				document.getElementById('contenido_medio').innerHTML +='<table>'+opciones[6]+'</table>';
			}
			else{
				document.getElementById('contenido_derecha').innerHTML ='';
			}
		}//Fin if 
		else 
		{
			alert("¬error¬:\n" + req.statusText);
		}//Fin else
	}//Fin if
}//Fin procedar_respuesta


function idiomas(id){
	freq();
	if(req) 
	{	
		req.onreadystatechange = fecha_hora;
		url = 'ajax/frm_getContenidoSubFechas.php?sub=' + id;		
		req.open('GET', url, true);
		req.send(null);
	}//Fin if			
}


function fecha_hora(){
	if (req.readyState == 4) 
	{	
		if (req.status == 200) 
		{
			arr = req.responseText.split("|");
			document.getElementById('contenido_derecha').innerHTML = arr[0];
		}
	}
}


/* CARGO LOS ARCHIVOS EN LA PARTE DERECHA DE LA PANTALLA */
function archivos(id){
	freq();
	if(req) 
	{	
		req.onreadystatechange = imagen_video;
		url = 'ajax/frm_getContenidoSubArchivos.php?archivo=' + id;		
		req.open('GET', url, true);
		req.send(null);
	}//Fin if			
}

function imagen_video(){
	if (req.readyState == 4) 
	{	
		if (req.status == 200) 
		{
			arr = req.responseText.split("|");
			document.getElementById('contenido_derecha').innerHTML = arr[0];
		}
	}
}


/* CARGO LAS NOTICIAS EN EL DIV DE LA DERECHA */
function noticias(id){
	freq();
	if(req) 
	{	
		req.onreadystatechange = ver_noticia;
		url = 'ajax/frm_getNoticias.php?id=' + id;		
		req.open('GET', url, true);
		req.send(null);
	}//Fin if			
}


function ver_noticia(){
	if (req.readyState == 4) 
	{	
		if (req.status == 200) 
		{
			arr = req.responseText.split("|");
			document.getElementById('noticias_derecha').innerHTML = arr[0];
			
			var el = document.getElementById("noticias_izquierda");
			// Ahora obtenemos todos los elementos con tag A que hay
			// dentro del elemento 'el'
			var as = el.getElementsByTagName("div");
			// Y finalmente recorremos el array de elementos para
			// cambiarles el color a cada uno
			for (var i=0; i<as.length; i++) {
				  as[i].style.backgroundColor = '#fff'; // negro
			}

			document.getElementById('marcar'+arr[1]).style.backgroundColor = '#ECECEC';
			el = document.getElementById('marcar'+arr[1]);
			var as = el.getElementsByTagName("div");
			for (var i=0; i<as.length; i++) {
				  as[i].style.backgroundColor = '#ECECEC'; // negro
			}
			
		}
	}
}




/* VERIFICAR QUE EL EMAIL DEL USUARIO QUE SE REGISTRA NO EXISTA EN LA B.D */
function emails(email){
	freq();
	if(req) 
	{	
		req.onreadystatechange = ver_email;
		url = 'ajax/frm_getEmail.php?email=' + email;		
		req.open('GET', url, true);
		req.send(null);
	}//Fin if			
}


function ver_email(){
	if (req.readyState == 4) 
	{	
		if (req.status == 200) 
		{
			arr = req.responseText.split("|");
			//return arr[0];
			if(arr[0] == 'no'){
				document.getElementById('info_email').innerHTML = "";
			}
			else if(arr[0] == 'si'){
				document.getElementById('info_email').innerHTML = "El email ya existe";
			}
		}
	}
}

/* VERIFICAR QUE EL USUARIO  NO EXISTA EN LA B.D */
function usuarios_reg(usuario){
	freq();
	if(req) 
	{	
		req.onreadystatechange = ver_usuario;
		url = 'ajax/frm_getUsuario.php?usuario=' + usuario;		
		req.open('GET', url, true);
		req.send(null);
	}//Fin if			
}


function ver_usuario(){
	if (req.readyState == 4) 
	{	
		if (req.status == 200) 
		{
			arr = req.responseText.split("|");
			if(arr[0] == 'no'){
				document.getElementById('info_usuario').innerHTML = "";
			}
			else if(arr[0] == 'si'){
				document.getElementById('info_usuario').innerHTML = "El usuario ya existe, favor ingresar otro nombre de usuario";
			}
		}
	}
}



/* CARGO LOS VIDEOS GRATIS EN EL DIV DE LA DERECHA */
function videos_gratis(id){
	freq();
	if(req) 
	{	
		req.onreadystatechange = ver_noticia;
		url = 'ajax/frm_getVideosGratis.php?id=' + id;		
		req.open('GET', url, true);
		req.send(null);
	}//Fin if			
}


function ver_videos_gratis(){
	if (req.readyState == 4) 
	{	
		if (req.status == 200) 
		{
			arr = req.responseText.split("|");
			document.getElementById('marcar'+arr[1]).style.backgroundColor = '#ECECEC';
			document.getElementById('noticias_derecha').innerHTML = arr[0];
		}
	}
}

