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 pintarVideos(pagina, busq){
	var ranNum= Math.floor(Math.random()*100000);
	url_envio= 'datos_videos.php?pag='+pagina+'&busq='+busq+'&rnd='+ranNum;
	document.getElementById('fichas_busqueda').innerHTML = '<center><br><br><img src="imagenes/loader_videos.gif"></center>';
	document.getElementById('paginacion').innerHTML = '';	
	http.open('get',url_envio,true);
	http.onreadystatechange = handlePintarVideos;
	http.send(null);
}

function handlePintarVideos(){
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('fichas_busqueda').innerHTML = datos[0];
			document.getElementById('paginacion').innerHTML = datos[1];
		}
	}
}


function mostrarVideo(vid,tipo, titulo, idTexto, tituloTexto, fecha, idVideo){
		if (tipo==1){
			document.getElementById('pantalla').innerHTML= '<object width="425" height="344">'
																												+ '	<param name="movie" value="http://es.youtube.com/v/'+vid+'"></param>'
																												+ '	<param name="wmode" value="transparent"></param>'
																												+ '	<embed src="http://es.youtube.com/v/'+vid+'&autoplay=1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="344"></embed>'
																												+ '</object><br />';
		} else if (tipo==2) {
			document.getElementById('pantalla').innerHTML= '<embed src="http://lads.myspace.com/videos/vplayer.swf" flashvars="m='+vid+'&v=2&type=video&autoplay=1" type="application/x-shockwave-flash" width="425" height="344"></embed><br />';	
		}
		document.getElementById('rep_titulo').innerHTML = titulo;
		document.getElementById('rep_enlaceNoticia').innerHTML= '<a href="texto.php?id_texto='+idTexto+'" class="enlace_azul">ver noticia >></a>';
		document.getElementById('rep_fecha').innerHTML = 'Fecha: '+fecha;
		document.getElementById('rep_descripcion').innerHTML = 'Noticia: '+tituloTexto;
		document.getElementById('rep_enviarAmigo').innerHTML = '<a href="javascript:;" onclick=\'mostrarCapa("enviarAmigo")\'>enviar video a un amigo >></a>';
		document.getElementById('formEnviar').action="javascript:mandaMail("+idVideo+");";
		scroll(0,400);

}
function resaltar(id){	
	document.getElementById('video'+id).className = "ficha_fondo_hover";
}
	
function normalizar(id){
	document.getElementById("video"+id).className = "ficha_fondo";
}

function mostrarCapa (id){
	var capa= document.getElementById(id);
	if (capa.style.display == 'none'){
		capa.style.display= 'block';
	} else {
		capa.style.display= 'none';
	}
}

function mandaMail(id){
	var ranNum= Math.floor(Math.random()*100000);
	var amigo = document.getElementById("amigo").value;
	var comentario = document.getElementById("comentario").value;
	var destino = document.getElementById("destino").value;
	var origen = document.getElementById("origen").value;
	
	if (amigo==''){
		alert("Debes rellenar tu nombre");	
	} else if (origen==''){
		alert("Debes rellenar tu e-mail");	
	} else if (destino==''){
		alert("Debes rellenar el e-mail de destino");				
	} else {
	
		url_envio= 'mail/mail_video.php?id_video='+id+'&amigo='+amigo+'&comentario='+comentario+'&origen='+origen+'&destino='+destino+'&rnd='+ranNum;
		http.open('get',url_envio);
		http.onreadystatechange = handleMandaMail;
		http.send(null);	
	}
}

function handleMandaMail(){
	if(http.readyState == 4) {
		mostrarCapa('enviarAmigo');
		mostrarCapa('accion');
		document.getElementById("comentario").value='';
		document.getElementById("destino").value='';
	}
}
