var contenido1 = "";
var contenido2 = "";
var contenido3 = "";
var contenido4 = "";
var contenido5 = "";
var idg=0;
var usug=0;
var nom;
var scrollAmigos=0;
var totalAmigos=0;
var docXML2;
var desplegado = "ninguno";
//var preparada_pagina = "";

function abrir(pagina){
    var opciones="toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, width=500, height=405, top=85, left=140";
	window.open(pagina,"",opciones); 
}   

function marcarVoto(id, valor){
	contenido1 = document.getElementById(id+"_1").src;
	contenido2 = document.getElementById(id+"_2").src;
	contenido3 = document.getElementById(id+"_3").src;
	contenido4 = document.getElementById(id+"_4").src;
	contenido5 = document.getElementById(id+"_5").src;
	
	if (valor == 1){
		document.getElementById('span_'+id).innerHTML = "Muy Mala";
	}
	if (valor == 2){
		document.getElementById('span_'+id).innerHTML = "Mala";
	}
	if (valor == 3){
		document.getElementById('span_'+id).innerHTML = "Regular";
	}
	if (valor == 4){
		document.getElementById('span_'+id).innerHTML = "Buena";
	}
	if (valor == 5){
		document.getElementById('span_'+id).innerHTML = "Muy Buena";
	}
	
	
	for (i=1;i<= valor; i++){
		document.getElementById(id+'_'+i).src = "/img/estrella1.png";
	}
	
	f = parseInt(valor);
	f +=1;
				
	for (i=f;i<7; i++){
		document.getElementById(id+'_'+i).src = "/img/estrella2.png";
	}
	
}
function noMarcarVoto(id){
	document.getElementById(id+"_1").src =contenido1;
	document.getElementById(id+"_2").src =contenido2;
	document.getElementById(id+"_3").src =contenido3;
	document.getElementById(id+"_4").src =contenido4;
	document.getElementById(id+"_5").src =contenido5;
	document.getElementById('span_'+id).innerHTML = "";
}

function crearMotorAjax(){

	
	if(window.XMLHttpRequest){
		return new XMLHttpRequest(); 
	}else if(window.ActiveXObject){
		var versionesObj = new Array(
		'Msxml2.XMLHTTP.5.0',
		'Msxml2.XMLHTTP.4.0',
		'Msxml2.XMLHTTP.3.0',
		'Msxml2.XMLHTTP',
		'Microsoft.XMLHTTP');
		for (var i = 0; i < versionesObj.length; i++){
			try{
				return new ActiveXObject(versionesObj[i]);
			}catch (errorControlado){
			}
		}
	}
	
	throw new Error("No se pudo crear el objeto XMLHttpRequest");
	
	//otro tipo
/*
	var motorAjax=false;
	try{
		motorAjax = new ActiveXObject("Msxml2.XMLHTTP");
	}catch(e){
		try{
			motorAjax = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(e){
			motorAjax=false;
		}
	}
	if (!motorAjax && typeof XMLHttpRequest!='undefined'){
		motorAjax = new XMLHttpRequest();
	}
	return motorAjax;*/
}

function obtenerDatos(url){
	var objAjax=crearMotorAjax();
	//objAjax.open('GET',url,false);
	objAjax.open('GET',url,false);
	
	objAjax.send(null);
	//objAjax.onreadystatechange = function(){
	
		if(objAjax.readyState==4){
			docXML=objAjax.responseXML.documentElement;
			return true;
		}else{
			return false;
		}
		
	//}
	
	
}



function cargarVotos(valor,id){

	destino = Base64.decode(id);
	
	document.getElementById('span_'+destino).innerHTML = '<img src="/img/loader.gif" />';

	var url="/acciones/votar.php?v="+valor+"&id="+id;
	
	if (obtenerDatos(url)==true){
		mostrarVotos();
	}
	
	
}

function mostrarVotos(){

	
	var listaNodos=docXML.getElementsByTagName("voto");
	
	for(i=0;i<listaNodos.length;i++){
	
		listaAtributos=listaNodos[i].attributes;
		
		mensaje=listaNodos[i].attributes[0].value;
		id = listaNodos[i].attributes[1].value;
		
		document.getElementById('span_'+id).innerHTML = mensaje;
		
		cargarSacarVotos(id);
	}
}

function cargarSacarVotos(id){

var url="/xml/consultaVotos.php?id="+id;
	
	if (obtenerDatos(url)==true){
		mostrarSacarVotos(id);
	}
}

function mostrarSacarVotos(id){

	
	var listaNodos=docXML.getElementsByTagName("voto");
	
	for(i=0;i<listaNodos.length;i++){
	
		listaAtributos=listaNodos[i].attributes;
		
		numero=listaNodos[i].attributes[0].value;
		enteras = listaNodos[i].attributes[1].value;
		medias = listaNodos[i].attributes[2].value;
		vacias = listaNodos[i].attributes[3].value;
		id = listaNodos[i].attributes[4].value;
		
		cadena = " "+numero+" ";
		
		for (i=0;i<enteras; i++){
		  cadena = cadena + '<img src="/img/estrella1.png" />';
		}
		for (i=0;i<medias; i++){
		  cadena = cadena + '<img src="/img/estrella3.png" />';
		}
		for (i=0;i<vacias; i++){
		  cadena = cadena + '<img src="/img/estrella2.png" />';
		}
		
		document.getElementById('spanGeneral_'+id).innerHTML = cadena;
	}
}


function cargarProvincias(id){

	var url="/xml/consultaProvincias.php";
	if (obtenerDatos(url)==true){
		mostrarProvincias(id);
	}	
}


function mostrarProvincias(id){
	

   	var listaNodos = docXML.getElementsByTagName("provincia");
	
	for (i=0;i<listaNodos.length; i++){
			
		listaAtributos=listaNodos[i].attributes;
		
		valorAtrib=listaNodos[i].attributes[0].value;
		
		idAtrib=listaNodos[i].attributes[1].value;
		
		var elemento=document.createElement("option");
		var valorElemento=document.createTextNode(valorAtrib);
		
		elemento.appendChild(valorElemento);
		
		elemento.setAttribute("value",idAtrib);
		
		document.getElementById(id).appendChild(elemento);		
		
	
	}

	//to.innerHTML="";

}


function cargarLocalidades(provincia,id){

	prov=provincia;
	
	var url="/xml/consultaLocalidades.php?id=" + prov;
	
	if (obtenerDatos(url)==true){
		mostrarLocalidades(id,prov);
	}
}

function mostrarLocalidades(id,prov){

	document.getElementById(id).disabled = false;
	document.getElementById(id).options.length=1;
	
	if (prov == 4){
	
	valorAtrib="----------------";
		idAtrib="-";
		
		var elemento=document.createElement("option");
		var valorElemento=document.createTextNode(valorAtrib);
		elemento.appendChild(valorElemento);
		elemento.setAttribute("value",idAtrib);
		document.getElementById(id).appendChild(elemento);	
		
	valorAtrib="Almeria";
	idAtrib="303";
		
		var elemento=document.createElement("option");
		var valorElemento=document.createTextNode(valorAtrib);
		elemento.appendChild(valorElemento);
		elemento.setAttribute("value",idAtrib);
		document.getElementById(id).appendChild(elemento);	
			
    valorAtrib="----------------";
		idAtrib="-";
		
		var elemento=document.createElement("option");
		var valorElemento=document.createTextNode(valorAtrib);
		elemento.appendChild(valorElemento);
		elemento.setAttribute("value",idAtrib);
		document.getElementById(id).appendChild(elemento);	
	
	}
	
	if (prov == 11){
	
	valorAtrib="----------------";
		idAtrib="-";
		
		var elemento=document.createElement("option");
		var valorElemento=document.createTextNode(valorAtrib);
		elemento.appendChild(valorElemento);
		elemento.setAttribute("value",idAtrib);
		document.getElementById(id).appendChild(elemento);	
		
	valorAtrib="Cadiz";
	idAtrib="1785";
		
		var elemento=document.createElement("option");
		var valorElemento=document.createTextNode(valorAtrib);
		elemento.appendChild(valorElemento);
		elemento.setAttribute("value",idAtrib);
		document.getElementById(id).appendChild(elemento);	
			
    valorAtrib="----------------";
		idAtrib="-";
		
		var elemento=document.createElement("option");
		var valorElemento=document.createTextNode(valorAtrib);
		elemento.appendChild(valorElemento);
		elemento.setAttribute("value",idAtrib);
		document.getElementById(id).appendChild(elemento);	
	
	}
	
	if (prov == 14){
	
	valorAtrib="----------------";
		idAtrib="-";
		
		var elemento=document.createElement("option");
		var valorElemento=document.createTextNode(valorAtrib);
		elemento.appendChild(valorElemento);
		elemento.setAttribute("value",idAtrib);
		document.getElementById(id).appendChild(elemento);	
		
	valorAtrib="Cordoba";
	idAtrib="2074";
		
		var elemento=document.createElement("option");
		var valorElemento=document.createTextNode(valorAtrib);
		elemento.appendChild(valorElemento);
		elemento.setAttribute("value",idAtrib);
		document.getElementById(id).appendChild(elemento);	
			
    valorAtrib="----------------";
		idAtrib="-";
		
		var elemento=document.createElement("option");
		var valorElemento=document.createTextNode(valorAtrib);
		elemento.appendChild(valorElemento);
		elemento.setAttribute("value",idAtrib);
		document.getElementById(id).appendChild(elemento);	
	
	}
	
	if (prov == 18){
	
	valorAtrib="----------------";
		idAtrib="-";
		
		var elemento=document.createElement("option");
		var valorElemento=document.createTextNode(valorAtrib);
		elemento.appendChild(valorElemento);
		elemento.setAttribute("value",idAtrib);
		document.getElementById(id).appendChild(elemento);	
		
	valorAtrib="Granada";
	idAtrib="2756";
		
		var elemento=document.createElement("option");
		var valorElemento=document.createTextNode(valorAtrib);
		elemento.appendChild(valorElemento);
		elemento.setAttribute("value",idAtrib);
		document.getElementById(id).appendChild(elemento);	
			
    valorAtrib="----------------";
		idAtrib="-";
		
		var elemento=document.createElement("option");
		var valorElemento=document.createTextNode(valorAtrib);
		elemento.appendChild(valorElemento);
		elemento.setAttribute("value",idAtrib);
		document.getElementById(id).appendChild(elemento);	
	
	}
	
	if (prov == 21){
	
	valorAtrib="----------------";
		idAtrib="-";
		
		var elemento=document.createElement("option");
		var valorElemento=document.createTextNode(valorAtrib);
		elemento.appendChild(valorElemento);
		elemento.setAttribute("value",idAtrib);
		document.getElementById(id).appendChild(elemento);	
		
	valorAtrib="Huelva";
	idAtrib="3266";
		
		var elemento=document.createElement("option");
		var valorElemento=document.createTextNode(valorAtrib);
		elemento.appendChild(valorElemento);
		elemento.setAttribute("value",idAtrib);
		document.getElementById(id).appendChild(elemento);	
			
    valorAtrib="----------------";
		idAtrib="-";
		
		var elemento=document.createElement("option");
		var valorElemento=document.createTextNode(valorAtrib);
		elemento.appendChild(valorElemento);
		elemento.setAttribute("value",idAtrib);
		document.getElementById(id).appendChild(elemento);	
	
	}
	
	if (prov == 23){
	
	valorAtrib="----------------";
		idAtrib="-";
		
		var elemento=document.createElement("option");
		var valorElemento=document.createTextNode(valorAtrib);
		elemento.appendChild(valorElemento);
		elemento.setAttribute("value",idAtrib);
		document.getElementById(id).appendChild(elemento);	
		
	valorAtrib="Jaen";
	idAtrib="3554";
		
		var elemento=document.createElement("option");
		var valorElemento=document.createTextNode(valorAtrib);
		elemento.appendChild(valorElemento);
		elemento.setAttribute("value",idAtrib);
		document.getElementById(id).appendChild(elemento);	
			
    valorAtrib="----------------";
		idAtrib="-";
		
		var elemento=document.createElement("option");
		var valorElemento=document.createTextNode(valorAtrib);
		elemento.appendChild(valorElemento);
		elemento.setAttribute("value",idAtrib);
		document.getElementById(id).appendChild(elemento);	
	
	}
	
	if (prov == 19){
	
	valorAtrib="----------------";
		idAtrib="-";
		
		var elemento=document.createElement("option");
		var valorElemento=document.createTextNode(valorAtrib);
		elemento.appendChild(valorElemento);
		elemento.setAttribute("value",idAtrib);
		document.getElementById(id).appendChild(elemento);	
		
	valorAtrib="Malaga";
	idAtrib="4532";
		
		var elemento=document.createElement("option");
		var valorElemento=document.createTextNode(valorAtrib);
		elemento.appendChild(valorElemento);
		elemento.setAttribute("value",idAtrib);
		document.getElementById(id).appendChild(elemento);	
			
    valorAtrib="----------------";
		idAtrib="-";
		
		var elemento=document.createElement("option");
		var valorElemento=document.createTextNode(valorAtrib);
		elemento.appendChild(valorElemento);
		elemento.setAttribute("value",idAtrib);
		document.getElementById(id).appendChild(elemento);	
	
	}
	
	if (prov == 41){
	
	valorAtrib="----------------";
		idAtrib="-";
		
		var elemento=document.createElement("option");
		var valorElemento=document.createTextNode(valorAtrib);
		elemento.appendChild(valorElemento);
		elemento.setAttribute("value",idAtrib);
		document.getElementById(id).appendChild(elemento);	
		
	valorAtrib="Sevilla";
	idAtrib="6159";
		
		var elemento=document.createElement("option");
		var valorElemento=document.createTextNode(valorAtrib);
		elemento.appendChild(valorElemento);
		elemento.setAttribute("value",idAtrib);
		document.getElementById(id).appendChild(elemento);	
			
    valorAtrib="----------------";
		idAtrib="-";
		
		var elemento=document.createElement("option");
		var valorElemento=document.createTextNode(valorAtrib);
		elemento.appendChild(valorElemento);
		elemento.setAttribute("value",idAtrib);
		document.getElementById(id).appendChild(elemento);	
	
	}
	
	var listaNodos=docXML.getElementsByTagName("localidad");
	
	for(i=0;i<listaNodos.length;i++){
	
		listaAtributos=listaNodos[i].attributes;
		
		valorAtrib=listaNodos[i].attributes[0].value;
		idAtrib=listaNodos[i].attributes[1].value;
		
		var elemento=document.createElement("option");
		var valorElemento=document.createTextNode(valorAtrib);
		elemento.appendChild(valorElemento);
		elemento.setAttribute("value",idAtrib);
		document.getElementById(id).appendChild(elemento);	
	
	}
}


function cargarCofradias(municipio, id){

	muni=municipio;
	prov= document.getElementById("listaProvincias").value;

	var url="/xml/consultaCofradias.php?id_municipio=" + muni + "&id_provincia=" + prov;
	
	if (obtenerDatos(url)==true){
		mostrarCofradias(id);
	}
	
	
}

function mostrarCofradias(id){

	
	document.getElementById(id).disabled = false;
	document.getElementById(id).options.length=1;

	var listaNodos=docXML.getElementsByTagName("cofradia");
	
	for(i=0;i<listaNodos.length;i++){
	
		listaAtributos=listaNodos[i].attributes;
		
		valorAtrib=listaNodos[i].attributes[0].value;
		idAtrib=listaNodos[i].attributes[1].value;
		
		var elemento=document.createElement("option");
		var valorElemento=document.createTextNode(valorAtrib);
		elemento.appendChild(valorElemento);
		elemento.setAttribute("value",idAtrib);
		document.getElementById(id).appendChild(elemento);	
	
	}

}




function cargarUsuarios(nick){
document.getElementById('span_nick').innerHTML = '<img src="/img/loader.gif" />';
var url="/xml/consultaUsuarios.php?v=" + nick;
	
	if (obtenerDatos(url)==true){
		mostrarUsuarios();
	}
}

function mostrarUsuarios(){
document.getElementById('span_nick').innerHTML = '';
	var listaNodos=docXML.getElementsByTagName("usuario");
	
	for(i=0;i<listaNodos.length;i++){
	
		listaAtributos=listaNodos[i].attributes;
		existe=listaNodos[i].attributes[0].value;
		usuarioValido = 1;
		
		if (existe=='si'){
			alert("Ya hay alguien con ese nombre de usuario");
			usuarioValido = 0;
		}
	}
}

function cargarEmails(nick){
document.getElementById('span_email').innerHTML = '<img src="/img/loader.gif" />';
var url="/xml/consultaEmail.php?v=" + nick;
	
	if (obtenerDatos(url)==true){
		mostrarEmails();
	}
}

function mostrarEmails(){
document.getElementById('span_email').innerHTML = '';
	var listaNodos=docXML.getElementsByTagName("usuario");
	
	for(i=0;i<listaNodos.length;i++){
	
		listaAtributos=listaNodos[i].attributes;
		existe=listaNodos[i].attributes[0].value;
		emailValido = 1;
		
		if (existe=='si'){
			alert("Ya hay alguien con ese email en uso");
			emailValido = 0;
		}
	}
}

function cargarAmigos(nombre2,e){

	if(window.event){
		keyCode=window.event.keyCode;
	}else if(e){
		keyCode=e.which;
	}
	
	if (keyCode != 40 && keyCode != 38 && keyCode != 13 && keyCode != 37 && keyCode != 39){
		nom=nombre2;
		interval = setTimeout("cargarAmigos2()",20);
	}else{
		if (keyCode == 38){
			arribaAmigos();
		}
		if (keyCode == 40){
			abajoAmigos();
		}
		if (keyCode == 13){
			//if (scrollAmigos > 0){
				t= scrollAmigos - 1;
				//document.getElementById("nick").value = document.getElementById("nick_" + t).value;
				//document.getElementById("nick").value = document.getElementById("nick_" + t).value;
				seleccionaAmigo(document.getElementById("hd_" + t).value,document.getElementById("nick_" + t).value);	
			//}else{
				window.location="/" + document.getElementById("nick").value;
			//}
		}
	}
}

function irAmigo(){
	window.location="/" + document.getElementById("nick").value;
}

function iniciaAmigos(){
	if (document.getElementById("busqueda_gente").value == "Amigos..."){
		document.getElementById("busqueda_gente").value = "";
	}
}

function arribaAmigos(){
	scrollAmigos = scrollAmigos - 1;
	
	if (scrollAmigos < 1){
		scrollAmigos = 1;
	}
	
	t= scrollAmigos - 1;
	h= scrollAmigos;
	document.getElementById("tr_" + t).className = "auth";
	document.getElementById("tr_" + h).className = "autr";
}

function abajoAmigos(){
	scrollAmigos = scrollAmigos + 1;
	
	if (scrollAmigos > (totalAmigos+1)){
		scrollAmigos = totalAmigos + 1;
	}
	
	t= scrollAmigos - 1;
	h= scrollAmigos-2;
	document.getElementById("tr_" + t).className = "auth";
	if (scrollAmigos >1){
		document.getElementById("tr_" + h).className = "autr";
	}
}

function cargarAmigos2(){
	
	clearTimeout(interval);
	
	if (nom != "" && nom.length > 1){
		var url="/xml/consultaAmigos.php?v=" + Base64.encode(nom);
		
		oXML = crearMotorAjax();
		oXML.open('GET',url, true);
		oXML.onreadystatechange = function(){
			if (oXML.readyState == 4) {
				docXML2 = oXML.responseXML.documentElement;
				mostrarAmigos(nom);
			}
		}
		oXML.send(null);
		/*
		if (obtenerDatos(url)==true){
			mostrarAmigos(nom);
		}*/
		
	}else{
		document.getElementById('lista_gente').innerHTML = "";	
		scrollAmigos = 0;
		totalAmigos = 0;
	}
}

function mostrarAmigos(nombre){
	
	var listaNodos=docXML2.getElementsByTagName("amigo");
	scrollAmigos = 0;
	totalAmigos = 0;

	var html='<table cellspacing="0" cellpadding="0" border="0" width="180px">';
	
	host = 1;
	totalAmigos = listaNodos.length-1;
	
	texto=Base64.decode(listaNodos[0].attributes[0].value);
	if (texto != ""){
		document.getElementById('lista_gente').style.display = "block";
	}
	
	for(i=0;i<listaNodos.length;i++){
	
		texto=Base64.decode(listaNodos[i].attributes[0].value);
		avatar=listaNodos[i].attributes[1].value;
		nick_id=listaNodos[i].attributes[2].value;
		
		comparacion = texto.toLowerCase();
		comparacion2 = nombre.toLowerCase();
		
		comparacion = comparacion.replace(comparacion2,'<b>'+comparacion2+'</b>');
		comparacion = ucWords(comparacion);
				
		if (texto != ""){
		
			html += '<tr id="tr_' + i + '" name="'+ texto +'" class="autr" onMouseOut="desactivaAmigo('+i+')" onMouseOver="activaAmigo('+i+')"  onMouseDown="seleccionaAmigo(\''+ texto +'\',\''+ nick_id +'\')" >';
			html += '<td width="25px"><img src="http://img'+host+'.pasionenjaen.com/avatars/' + avatar + '" width=25 height=25 /></td><td align="top" width="190px" >'+comparacion+'<input type="hidden" id="hd_'+i+'" value="'+texto+'" /><input type="hidden" id="nick_'+i+'" value="'+nick_id+'" /></td></tr>';
			
			host = host + 1;
			if (host > 4){
				host = 1;
			}
		}
	
	}
	
	html += '</table>';
	document.getElementById('lista_gente').innerHTML = html;
	
}

function activaAmigo(id){
	document.getElementById("tr_" + id).className = "auth";
	document.body.style.cursor = "hand";
}

function desactivaAmigo(id){
	document.getElementById("tr_" + id).className = "autr";
	document.body.style.cursor = "default";
}


function seleccionaAmigo(texto,nick){
	document.getElementById("nick").value = nick;
	scrollAmigos = 0;
	document.getElementById('busqueda_gente').value = texto;
	document.getElementById('lista_gente').innerHTML = "";
	document.getElementById('lista_gente').style.display = "none";
}


function ucWords(string){
	
	var arrayWords;
	var returnString = "";
	var len;
	arrayWords = string.split(" ");
	len = arrayWords.length;

	for(f=0;f < len ;f++){
		returnString = returnString + ucFirst(arrayWords[f])+" ";	
	}
	
	return returnString;
}

function ucFirst(string){
	if (string.substr(0,1) != "<"){
		return string.substr(0,1).toUpperCase()+string.substr(1,string.length).toLowerCase();
	}else{
		return string.substr(0,3)+string.substr(3,1).toUpperCase()+string.substr(4,string.length).toLowerCase();
	}
}




function cargarComentarios(id,donde){
	
	document.getElementById('divComentarios_'+id).innerHTML = '<img src="/img/cargandocomentarios.gif" />';
	var url="/xml/consultaComentarios.php?v=" + id + "&d=" + donde;
	
	if (obtenerDatos(url)==true){
		mostrarComentarios(id,donde);
	}
}

function mostrarComentarios(id,donde){

	document.getElementById('divComentarios_'+id).innerHTML = '';
	var listaNodos=docXML.getElementsByTagName("comentario");
	
	fi = document.getElementById('divComentarios_'+ id); 
	
	cadena = "";
		
	for(i=0;i<listaNodos.length;i++){
	
		texto=Base64.decode(listaNodos[i].attributes[0].value);
		usuario=listaNodos[i].attributes[1].value;
		fecha=listaNodos[i].attributes[2].value;
		usu_id=listaNodos[i].attributes[3].value;
		com_id=listaNodos[i].attributes[4].value;
		borra=listaNodos[i].attributes[5].value;
		ni=listaNodos[i].attributes[6].value;
		respuesta=listaNodos[i].attributes[7].value;
		ide=listaNodos[i].attributes[8].value;
		denun=listaNodos[i].attributes[9].value;
		
		host = 1;
		
		if (respuesta == "no"){
			imagen = '<img src="http://img'+host+'.pasionenjaen.com/avatars/' + usu_id + '" width=30 height=30 />';
		}else{
			imagen = '<img src="http://img'+host+'.pasionenjaen.com/avatars/' + usu_id + '" width=20 height=20 />';
		}
		
		host = host + 1;
		if (host > 4){
			host = 1;
		}
				
		if (texto != "No Hay Comentarios"){
			
			if (denun == "si"){
     			texto = "Este mensaje no cumple los requisitos de publicaci&oacute;n...";
	    	}
			
			if (respuesta == "no"){
			
					  contenedor = document.createElement('div'); 
					  contenedor.setAttribute ('className','com_comentario');
					  contenedor.setAttribute ('class','com_comentario');
					  fi.appendChild(contenedor);
					  					 		  
					  contenido =  document.createElement('div');
					  contenido.setAttribute ('className','com_contenido');
					  contenido.setAttribute ('class','com_contenido');
					  contenedor.appendChild(contenido);
					 
					  avatar =  document.createElement('div');
					  avatar.setAttribute ('className','com_avatar');
					  avatar.setAttribute ('class','com_avatar');
					  avatar.innerHTML = imagen;
					  contenido.appendChild(avatar);
					 
					  cabecera =  document.createElement('div');
					  cabecera.setAttribute ('className','com_cabe');
					  cabecera.setAttribute ('class','com_cabe');
					  					  
					  if (borra == "si"){

							if (donde == 'per'){
								cabecera.innerHTML = '<a href="/'+ ni +'">'  + usuario + '</a> - ' + fecha + ' - <a href="#static" onclick="cargarBorrarComentario('+id+',' + com_id +',\'' + donde +'\')">borrar</a> - <a href="#static" onclick="responderComentario('+ com_id +',\''+ni+'\',\''+usuario+'\',\''+usu_id+'\','+ide+')">responder</a>';
							}else{
								cabecera.innerHTML = '<a href="/'+ ni +'">'  + usuario + '</a> - ' + fecha + ' - <a href="#static" onclick="cargarBorrarComentario('+id+',' + com_id +',\'' + donde +'\')">borrar</a>';
							}
					  
					  }else{
						  	cabecera.innerHTML = '<a href="/'+ ni +'">'  + usuario + '</a> - ' + fecha;
					  }
					  
					  					  
					  contenido.appendChild(cabecera);
					  
					  text =  document.createElement('div');
					  text.setAttribute ('className','com_texto');
					  text.setAttribute ('class','com_texto');
					  
					  
					  text.innerHTML = texto;
					  contenedor.appendChild(text);
					  
					  cadena = '';
			
			}else{
				
					  contenedor = document.createElement('div'); 
					  contenedor.setAttribute ('className','com_comentario_res');
					  contenedor.setAttribute ('class','com_comentario_res');
					  fi.appendChild(contenedor);
					 		  
					  contenido =  document.createElement('div');
					  contenido.setAttribute ('className','com_contenido_res');
					  contenido.setAttribute ('class','com_contenido_res');
					  contenedor.appendChild(contenido);
					 
					  avatar =  document.createElement('div');
					  avatar.setAttribute ('className','com_avatar');
					  avatar.setAttribute ('class','com_avatar');
					  avatar.innerHTML = imagen;
					  contenido.appendChild(avatar);
					 
					  cabecera =  document.createElement('div');
					  cabecera.setAttribute ('className','com_cabe_res');
					  cabecera.setAttribute ('class','com_cabe_res');
					  
					  
					  if (borra == "si"){
					  		cabecera.innerHTML = '<a href="/'+ ni +'">'  + usuario + '</a> - ' + fecha + ' - <a href="#static" onclick="cargarBorrarComentario('+id+',' + com_id +',\'' + donde +'\')">borrar</a>';
					  
					  }else{
						  	cabecera.innerHTML = '<a href="/'+ ni +'">'  + usuario + '</a> - ' + fecha;
					  }
					  
					  					  
					  contenido.appendChild(cabecera);
					  
					  text =  document.createElement('div');
					  text.setAttribute ('className','com_texto_res');
					  text.setAttribute ('class','com_texto_res');
					  text.innerHTML = texto;
					  contenedor.appendChild(text);
					  
					  cadena = '';
				
			}
			
		}else{
			
					  contenedor = document.createElement('div'); 
					  contenedor.setAttribute ('className','com_comentario');
					  contenedor.setAttribute ('class','com_comentario');
					  fi.appendChild(contenedor);
					 		  
					  contenido =  document.createElement('div');
					  contenido.setAttribute ('className','com_contenido');
					  contenido.setAttribute ('class','com_contenido');
					  contenedor.appendChild(contenido);
					 					 
					  cabecera =  document.createElement('div');
					  cabecera.setAttribute ('className','com_cabe');
					  cabecera.setAttribute ('class','com_cabe');
					  cabecera.innerHTML = 'No hay comentarios, an&iacute;mate y s&eacute; el primero en comentar';
					  contenido.appendChild(cabecera);
					  
		}
		
		
	}
		
}

function cargarComentarios2(id,donde){
	
	document.getElementById('spanEstado').innerHTML = '<img src="/img/publicando.gif" />';
	
	cadena = document.getElementById('comentario').value;
	cadena = encodeURI(cadena);
	
	var url="/acciones/insertaComentario.php?v=" + cadena + '&id=' +id + '&d=' + donde;
		
	if (obtenerDatos(url)==true){
		mostrarComentarios2(id,donde);
	}
	
	
}

function mostrarComentarios2(id,donde){


	var listaNodos=docXML.getElementsByTagName("comentario");
	
	for(i=0;i<listaNodos.length;i++){
	
		listaAtributos=listaNodos[i].attributes;
		
		mensaje=listaNodos[i].attributes[0].value;
		id = listaNodos[i].attributes[1].value;
		
		if (mensaje != "" ){
			document.getElementById('spanEstado').innerHTML = mensaje + "<br /><br />";
		}else{
			document.getElementById('spanEstado').innerHTML = "";
			document.getElementById('comentario').value = "";
		}		
		
		cargarComentarios(id,donde);
	}
}

function responderComentario(id_com,ni,nom,av,id){
				
	document.getElementById('quote').innerHTML = "";
	document.getElementById('comentario_responder').value = "";
	document.getElementById('ni_res').value = ni;
	document.getElementById('res').value = id_com;
	document.getElementById('id_res').value = id;
	document.getElementById('boton_responder').value ="Responder";

	document.getElementById('light').style.display='block';
	document.getElementById('fade').style.display='block';
	
	document.getElementById('quote').innerHTML = '<div style="float:left;"><img border="0" width="30" height="30" src="/avatars/' + av + '" /></div><div style="float:left; padding:5px 5px 5px 5px;">Responder a ' + nom + '</div>';
  
}

function cerrarResponder(){
  
	document.getElementById('quote').innerHTML = "";
	document.getElementById('light').style.display='none';
	document.getElementById('fade').style.display='none';
	document.getElementById('res').value = "";
	document.getElementById('id_res').value = "";
	document.getElementById('ni_res').value = "";
  
}

function cargarComentarios3(id,donde,id_com){
	
	cadena = document.getElementById('comentario_responder').value;
	//id_com = document.getElementById('res').value;
	cadena = encodeURI(cadena);
	
	id_res = document.getElementById('id_res').value;
		
	var url="/acciones/insertaComentario.php?v=" + cadena + '&id=' +id_res + '&r='+ id_com +'&d=' + donde;
		
	if (obtenerDatos(url)==true){
		mostrarComentarios3(id,donde,ni);
	}
}

function mostrarComentarios3(id,donde,ni){
	document.getElementById('spanEstado').innerHTML = "Mensaje respondido";
	cerrarResponder();
}


function cargarEstado(){
	
	//document.getElementById('spanEstado').innerHTML = '<img src="/img/loader.gif" />';
	cadena = document.getElementById('estado').value;
	cadena = encodeURI(cadena);
		
	var url="/acciones/actualizaEstado.php?v=" + cadena;
		
	if (obtenerDatos(url)==true){
		mostrarEstado();
	}
}

function mostrarEstado(){
	
	var listaNodos=docXML.getElementsByTagName("estado");
	
	for(i=0;i<listaNodos.length;i++){
		listaAtributos=listaNodos[i].attributes;
		mensaje=Base64.decode(listaNodos[i].attributes[0].value);
		document.getElementById('estado').value = mensaje;
	}
}



function cargarBorrarComentario(id_foto,id,donde){
	
	document.getElementById('spanEstado').innerHTML = '<img src="/img/loader.gif" />';
	var url="/acciones/eliminarComentario.php?v=" + id_foto + '&id=' +id;

	confirmacion = confirm("seguro que deseas borrar este comentario??");

	if(confirmacion == true) {
		if (obtenerDatos(url)==true){
			mostrarBorrarComentario(donde);
		}
	}else{
		document.getElementById('spanEstado').innerHTML = '';	
	}
}

function mostrarBorrarComentario(donde){

	var listaNodos=docXML.getElementsByTagName("comentario");
	
	for(i=0;i<listaNodos.length;i++){
	
		listaAtributos=listaNodos[i].attributes;
		
		mensaje=listaNodos[i].attributes[0].value;
		id = listaNodos[i].attributes[1].value;
		
		document.getElementById('spanEstado').innerHTML = mensaje + "<br /><br />";
		document.getElementById('comentario').value = "";
		
		cargarComentarios(id,donde);
	}
}

function divamigos(e,id,nombre,avatar){

	// capture the mouse position
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY)
	{
	posx = e.pageX;
	posy = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{
	posx = e.clientX;
	posy = e.clientY;
	}
	
	posx = document.getElementById('amigo_'+id).offsetLeft;
	posy = document.getElementById('amigo_'+id).offsetTop ;

	posx = posx +50;
	posy = posy +40;
			
	id = id + '';
	
	id_amigo = Base64.encode(id);
	
	document.getElementById('enlaceeliminar').href = '/acciones/eliminarAmigo.php?v=' + id_amigo + '&a=' + Base64.encode('e');
	document.getElementById('enlacebloquear').href = '/acciones/eliminarAmigo.php?v=' + id_amigo + '&a=' + Base64.encode('b');
	
	document.getElementById('editaramigo').style.top = posy + 'px';
	document.getElementById('editaramigo').style.left = posx + 'px';
	document.getElementById('editaramigo').style.display = 'block';
	
	document.getElementById('nombreamigo').innerHTML = '<img src="/avatars/'+avatar+'" width="40" height= "40"  align="top" />&nbsp;&nbsp;'+nombre;

}

function hideamigos(){
	document.getElementById('editaramigo').style.display = 'none';
}
	
function confirmar(mensaje){
	return confirm( mensaje );
}

function eventos(v,seg){
	compruebaEventos(v);
	setInterval("compruebaEventos("+v+")",seg);	
}

function compruebaEventos(v){
	
	mi_fecha=new Date();
	r = mi_fecha.getTime();
	
	var url="/xml/consultaEventos.php?ww="+ r +"&v=" + v;
		
	oXML = crearMotorAjax();
	oXML.open('GET',url, true);
	oXML.onreadystatechange = function(){
		if (oXML.readyState == 4) {
			docXML2 = oXML.responseXML.documentElement;
			mostrarEventos();
		}
	}
	oXML.send(null);
		/*
	if (obtenerDatos(url)==true){
		mostrarEventos();
	}	*/
}

function mostrarEventos(){
	
	var listaNodos=docXML2.getElementsByTagName("evento");
	
	var html='<table cellspacing="0" cellpadding="0" border="0" width="180px">';
	
	if (listaNodos.length != 0){
		document.getElementById('lista_eventos').style.left = "0px";
		document.getElementById('lista_eventos').style.display = "block";
		
	}else{
		document.getElementById('lista_eventos').style.display = "none";
	}
	
	for(i=0;i<listaNodos.length;i++){
	
		texto=Base64.decode(listaNodos[i].attributes[1].value);
		url=Base64.decode(listaNodos[i].attributes[0].value);
		
		if (texto != ""){
			html += '<a href="'+url+'"><img border="0" align="absmiddle" src="/img/alerta.png" />&nbsp;'+texto+'</a>';
		}
	
	}
	
	html += '</table>';
	document.getElementById('lista_eventos').innerHTML = html;
}


function ocultaUsuactividad(v,i,e){
	
	//document.getElementById('ocu_'+ e).style.filter = 'Alpha(Opacity=50)';
	//document.getElementById('ocu_'+ e).style.opacity = '0.5';
	//document.getElementById('img_ocu2_'+ e).style.display = 'block';
	
	jQuery("#ocu_" + e ).fadeTo(300, 0.5);
	jQuery("#img_ocu2_" + e ).show();
		
	var url="/xml/ocultaUsuactividad.php?usu=" + i + "&id=" + v;
		
	oXML = crearMotorAjax();
	oXML.open('GET',url, true);
	oXML.onreadystatechange = function(){
		if (oXML.readyState == 4) {
			docXML2 = oXML.responseXML.documentElement;
			ocultaActividad(e);
		}
	}
	oXML.send(null);
}

function ocultaActividad(v){
	jQuery("#act_int_" + v ).hide();
	jQuery("#ocu_" + v ).fadeTo(300, 1);
	//document.getElementById("act_int_"+v).style.display = "none";	
	//document.getElementById('ocu_'+ v).style.filter = 'Alpha(Opacity=100)';
	//document.getElementById('ocu_'+ v).style.opacity = '1';	
	document.getElementById('ocu_'+v).innerHTML = "";
	document.getElementById('ocu_'+v).innerHTML = '<div class="ocu_sub2">Ha sido ocultado(a) de tus &Uacute;ltimas noticias. Para controlar quien aparece en &Uacute;ltimas noticias, <a href="#static" onclick="mostrarAlertBox(300,50,\'/ventanas/conf_ultimasnoticias.php?close=cerrarAlertBox(1)\')">Editar opciones.</a></div>';
	
}

function borrarComentario(id_foto,id,donde){
	
	var url="/acciones/eliminarComentario.php?v=" + id_foto + '&id=' +id;

	//confirmacion = confirm("seguro que deseas borrar este comentario??");

	//if(confirmacion == true) {
		
		div = "com_" + id;
		
		cerrarAlertBox();
		//document.getElementById('com_'+ id).style.filter = 'Alpha(Opacity=50)';
		//document.getElementById('com_'+ id).style.opacity = '0.5';
		
		jQuery("#" + div ).fadeTo(300, 0.5);
		
		//document.getElementById('img_com_'+ id).style.display = 'block';	
		jQuery("#img_com_" + id ).show();

		oXML = crearMotorAjax();
		oXML.open('GET',url, true);
		oXML.onreadystatechange = function(){
			if (oXML.readyState == 4) {
				docXML2 = oXML.responseXML.documentElement;
				mborrarComentario(id);
			}
		}
		oXML.send(null);
	
	//}
}

function mborrarComentario(v){
	nombre = 'com_'+ v;
	jQuery("#" + nombre ).slideUp("fast");
}



/*
function nuevoChat(u1,u2){
	
	var url="/xml/nuevoChat.php?u1=" + u1 + "&u2=" + u2;
			
	if (obtenerDatos(url)==true){
		mostrarnuevoChat(u1);
	}	
	
}

function mostrarnuevoChat(u1){
	
	var listaNodos=docXML.getElementsByTagName("chat");
	
	for(i=0;i<listaNodos.length;i++){
		listaAtributos=listaNodos[i].attributes;
		id=Base64.decode(listaNodos[i].attributes[0].value);
	}
	
	inicializaChat(id,u1);
	
	setInterval("cargarChat("+ id +","+usu_id+")",2000);	
	
}

function inicializaChat(id,usu_id){
		
			
	  setInterval("cargarChat("+id+","+usu_id+")",5000);
	
	  fi = document.getElementById('contenedor'); 
	  
	  contenedor = document.createElement('div'); 
	  contenedor.setAttribute ('id','chatcont');
	  
	  x = screen.width - 300;
	  y= screen.height - 350;
	  	  
	  contenedor.setAttribute ('style','position:absolute; width:250px; height:300px; background:#fefefe; bottom:2%; right:0%;');
      fi.appendChild(contenedor);

	  ele = document.createElement('div');
	  ele.setAttribute ('id','chat');
	  ele.setAttribute ('style','width:200px; height:200px; overflow-y:auto; overflow-x:hidden; border:#999 solid 1px');
	  contenedor.appendChild(ele); 
	  
	  ele2 = document.createElement('textarea');
	  ele2.id = 'chates'; 
	  ele2.name = 'chates'; 
	  ele2.cols = '23'; 
	  ele2.rows = '2'; 
	  ele2.setAttribute ('onKeyPress','pulsada(event,'+id+','+usu_id+')');
	  contenedor.appendChild(ele2); 
	  
	  ele3 = document.createElement('span');
	  ele3.setAttribute('id','enviar');
	  ele3.innerHTML = '<br /><a href="#" onclick="enviarChat('+id+','+usu_id+')">Enviar</a>';
	  contenedor.appendChild(ele3); 
	
	
	  cargarChat(id,usu_id);
	//idg = id;
	//usug = usu_id;
}

function enviarChat(id,usu_id){
	
	document.getElementById('chat').innerHTML = document.getElementById('chat').innerHTML + "<b>yo:</b> " + document.getElementById('chates').value + "<br />";
	mensaje = Base64.encode(document.getElementById("chates").value);
			
	document.getElementById('chates').value = "";
	document.getElementById('chates').setSelectionRange(1,1);
	document.getElementById('chates').focus();
	
	var url="/xml/enviarChat.php?v=" + id + "&m=" + mensaje;

	if (obtenerDatos(url)==true){
		//mostrarenviarChat(id);
		document.getElementById('chates').value = "";
		document.getElementById('chates').setSelectionRange(1,1);
		document.getElementById('chates').focus();
	}

}

function compruebaChat(usu_id){
	
	var url="/xml/compruebaChat.php?v=" + usu_id;
		
	if (obtenerDatos(url)==true){
		mostrarcompruebaChat(usu_id);
	}	
}

function mostrarcompruebaChat(usu_id){
	
	var listaNodos=docXML.getElementsByTagName("chat");
	
	for(i=0;i<listaNodos.length;i++){
		listaAtributos=listaNodos[i].attributes;
		id=Base64.decode(listaNodos[i].attributes[0].value);
	}

	if (id != "0"){
		 inicializaChat(id,usu_id);
	}
	
}


function pulsada(e, id, usu_id) {
	
	//var charCode = (e.which) ? e.which : event.keyCode
	
  if (e.keyCode ==13){
	  document.getElementById('chates').blur();
	  enviarChat(id,usu_id);  
  }
  
  if (e.keyCode ==27){
	  //alert("si");
	  alert(id);
	  alert(usu_id);
	  cerrarChat(id,usu_id);  
  }
	  
}

function cargarChat(id,usu_id){
	
	var url="/xml/cargarChat.php?v=" + id + "&u=" + usu_id;
	
	if (obtenerDatos(url)==true){
		mostrarChat(id);
	}	
}

function mostrarChat(id){
	
	var listaNodos=docXML.getElementsByTagName("chat");
	
	for(i=0;i<listaNodos.length;i++){
	
		listaAtributos=listaNodos[i].attributes;
		mensaje=Base64.decode(listaNodos[i].attributes[0].value);
		
		document.getElementById('chat').innerHTML = document.getElementById('chat').innerHTML + mensaje + "<br />";
				
	}
}*/
