opcion_seleccionada= new Array();
var cod_ant=0;
var nivel_ant=0;

function createRequestObject() {
	var ro;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer") {
		ro = new ActiveXObject("Microsoft.XMLHTTP");	
	} else {
		ro = new XMLHttpRequest();	
	}
	return ro;
}

var http = createRequestObject();

function trim (string) {
	var whitespace = ' nrtvfu00a0u2000u2001u2002u2003u2004u2005u2006u2007u2008u2009u200au200bu2028u2029u3000';
	for (var i = 0; i < string.length; i++) {
		if (whitespace.indexOf(string.charAt(i)) === -1) {
			string = string.substring(i);
			break;
		}
	}
	for (i = string.length; i > 0; i--) {
		if (whitespace.indexOf(string.charAt(i)) === -1) {
			string = string.substring(0, i);
			break;
		}
	}
	return whitespace.indexOf(string.charAt(0)) === -1 ? string : '';
}

function pintarEventos(pagina,busq, cat,pruebas){
	var pruebas= pruebas || 0;
	var debug= debug || 0;
	var ranNum= Math.floor(Math.random()*100000);
	if (pruebas == 1){
		url_envio= 'datos_eventos.php?pruebas=1&pag='+pagina+'&busq='+busq+'&rnd='+ranNum+'&cat='+cat;
	} else {
		url_envio= 'datos_eventos.php?pag='+pagina+'&busq='+busq+'&rnd='+ranNum+'&cat='+cat;
	}
	http.open('get',url_envio,true);
	http.onreadystatechange = handlePintarEventos;
	http.send(null);
}

function handlePintarEventos(){
$('eventos').style.display= 'block';
$('paginacion').style.display= 'block';
$('concurso').style.display= 'none';
$('noticia_ampliada').style.display= 'none';
$('resultados_encuesta').style.display= 'none';

if(http.readyState == 4) {
		var txt = http.responseText;
		if (txt.substr(0,5) == 'ERROR'){
			alert('Se produjo un error:\n'+txt);
		} else {
			var datos= txt.split('##@@');
			document.getElementById('eventos').innerHTML = datos[0];
			document.getElementById('paginacion').innerHTML = datos[1];
		}
	scroll(0,0);
	}
}

function mostrarDerrame(){
	$('derrame').style.display= 'block';	
	$('eventos').style.display= 'none';
	$('paginacion').style.display= 'none';
	$('concurso').style.display= 'none';
	$('noticia_ampliada').style.display= 'none';
	$('resultados_encuesta').style.display= 'none';
}

function comprobarDerrame(off){
	if (off==1){
		$('derrame').style.display= 'none';
		$('eventos').style.display= 'block';
		$('paginacion').style.display= 'block';
	} else if ($('cod').value!="13rockderrame"){
		alert ("contraseña incorrecta")
	} else {
		pintarEventosDerrame(1, '', 0);
		$('cod').value='';
		$('derrame').style.display= 'none';
		$('eventos').style.display= 'block';
		$('paginacion').style.display= 'block';		
	}
}

//pintar eventos 2 saca los resultados de la zona derrame
function pintarEventosDerrame(pagina,busq, cat,pruebas){
	var pruebas= pruebas || 0;
	var debug= debug || 0;
	var ranNum= Math.floor(Math.random()*100000);
	if (pruebas == 1){
		url_envio= 'datos_derrame.php?pruebas=1&pag='+pagina+'&busq='+busq+'&rnd='+ranNum+'&cat='+cat;
	} else {
		url_envio= 'datos_derrame.php?pag='+pagina+'&busq='+busq+'&rnd='+ranNum+'&cat='+cat;
	}
	http.open('get',url_envio,true);
	http.onreadystatechange = handlePintarEventosDerrame;
	http.send(null);
}

function handlePintarEventosDerrame(){

	if(http.readyState == 4) {
		var txt = http.responseText;
		if (txt.substr(0,5) == 'ERROR'){
			alert('Se produjo un error:\n'+txt);
		} else {
			var datos= txt.split('##@@');
			document.getElementById('eventos').innerHTML = datos[0];
			document.getElementById('paginacion').innerHTML = datos[1];
		}
	scroll(0,0);
	}
}
// Función que muestra los productos. Todas las operaciones se realizan en la función handlerVerProductos(). Desde aquí se llama
// a la página PHP de la que se extraen los resultados;
function verProductos (cat){
	http.open('get','datos_productos.php?cat='+cat);
	http.onreadystatechange = handleVerProductos;
	http.send(null);
}
// Función con todas las operaciones necesarias para mostrar los productos. Recibe con el http.responseText el resultado de la llamada
// a la página PHP, que contiene el código HTML maquetado con los datos de productos.
function handleVerProductos(){
	// Comprobamos que el estado de la llamada al PHP sea finalizada.
	if(http.readyState == 4) {
		// Creamos la variable txt, que tiene en su interior la respuesta del PHP. Cada uno d elos registros está maquetado
		// y separado por un delimitador, en este caso la cadena de texto |||###.
		var txt = http.responseText;
		// Si hemos encontrado un error a la hora de relizar la query en el PHP mostramos que ha habido error.
		if (txt.substr(0,5) == 'ERROR'){
			alert('Se produjo un error:\n'+txt);
		} else {
			var content2= trim(txt);
			if (content2 != ''){
				$('noticias').innerHTML= txt;
			} else {
				$('noticias').innerHTML= '<center style="padding-top:200px;">'+pintarLogo(cod_ant)+'</center>';
			}
		} //if2
	} // if1

//Pendiente de rellenar
}

function salir_detalle(){
	$('noticias').innerHTML= $('contenido_temporal').innerHTML;
	$('contenido_temporal').innerHTML= '';
}

function ver_detalle (id,familia){
 $('contenido_temporal').innerHTML= $('noticias').innerHTML;
 http.open('get','datos_detalle.php?id='+id+'&fam='+familia);
 http.onreadystatechange = handleVerDetalle;
 http.send(null);
}

function handleVerDetalle(){
 if(http.readyState == 4) {
  var txt = http.responseText;
  if (txt.substr(0,5) == 'ERROR'){
   alert('Se produjo un error:\n'+txt);
  }  //if2
  $('noticias').innerHTML= txt;
 } // if1

//Pendiente de rellenar
}

function verNoticiaAmpliada(id){
	var id= id || 0;
	http.open('get','texto3.php?id_texto='+id);
 	http.onreadystatechange = handleVerNoticiaAmpliada;
 	http.send(null);
}

function handleVerNoticiaAmpliada(){
	if(http.readyState == 4) {
	  var txt = http.responseText;
	  if (txt.substr(0,5) == 'ERROR'){
	   alert('Se produjo un error:\n'+txt);
	  }
	  $('noticia_ampliada_temp').style.display= 'block';
	  $('noticia_ampliada_temp').innerHTML= txt;
	 }
}

function mostrarSeccion(capa,off){
	var off= off || 0;
	if ($(capa)){
		$('resultados_encuesta').style.display= 'none';
		$('concurso').style.display= 'none';
		$('noticia_ampliada').style.display= 'none';
		if (off == 0){
			$('paginacion').style.display= 'none';
			$('eventos').style.display= 'none';
			$(capa).style.display= 'block';
		} else {
			$('paginacion').style.display= 'block';
			$('eventos').style.display= 'block';
		}
	}
}

function verConcurso(off){
	var off= off || 0;
	if (off == 0){
		$('eventos').style.display= 'none';
		$('paginacion').style.display= 'none';
		$('resultados_encuesta').style.display= 'none';
		$('noticia_ampliada').style.display= 'none';
		$('concurso').style.display= 'block';
		//document.getElementById('iframe_concurso').src= 'concurso3.php';
		document.getElementById('iframe_concurso').src= 'concurso/ver_concurso2.php';
	} else {
		$('concurso').style.display= 'none';
		$('eventos').style.display= 'block';
		$('paginacion').style.display= 'block';
		scroll(0,0);
	}
}

function verSorteo(off){
	var off= off || 0;
	if (off == 0){
		$('eventos').style.display= 'none';
		$('paginacion').style.display= 'none';
		$('resultados_encuesta').style.display= 'none';
		$('noticia_ampliada').style.display= 'none';
		$('concurso').style.display= 'block';
		//document.getElementById('iframe_concurso').src= 'concurso3.php';
		document.getElementById('iframe_concurso').src= 'concurso/ver_concurso.php?id=31';
	} else {
		$('concurso').style.display= 'none';
		$('eventos').style.display= 'block';
		$('paginacion').style.display= 'block';
		scroll(0,0);
	}
}
