function updateRank(id, type) {
	var id = id;
	var type = type;
	if (xmlHttp.readyState == 4) {
		var response = xmlHttp.responseText;

		var strEntryArray = response.split('|');
		status = strEntryArray[0];
		newrank = strEntryArray[1];

		if (status == "E") {
			$('thisrlink-'+id).innerHTML = '<font class=disabled>---</font>';
			advice(id,3);
		} else {
			$('thisrlink-'+id).innerHTML = '<font class=disabled>---</font>';
			advice(id,2);

			if (type == 1) {
				if (newrank.length == 1) {
					$('thisrank-'+id).innerHTML = '<p id=standingc>' + newrank + '</p>';
				} else if (newrank.length == 2) {
					$('thisrank-'+id).innerHTML = '<p id=standinga>' + newrank + '</p>';
				} else if (newrank.length == 4) {
					$('thisrank-'+id).innerHTML = '<p id=standingd>' + newrank + '</p>';
				} else {
					$('thisrank-'+id).innerHTML = '<p id=standingb>' + newrank + '</p>';
				}
			}

		}
	}
}

var flood = false;

function tflood() {
	flood = false;
}

function rateup(token,id,type) {
	
	if (flood) {
		advice(id,4);
		return false;
	} else {
		flood = true;
		setTimeout('tflood()',5000);
	}
	
	if (type != 2) {
		if (browser != "Internet Explorer" && version != "7") {
			Effect.Pulsate('jumpborder-'+id, { duration: 1.0 });
		}
	}

	$('thisrlink-'+id).innerHTML = '<font class=disabled>...</font>';

	var url = "call/rateup/?id=" + id + "&token=" + token;
	if (xmlHttp)
	{
		xmlHttp.onreadystatechange = function () {}
		xmlHttp.abort();
	}
	xmlHttp.open("GET", url, true);
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState==4)
		if (xmlHttp.status==200)
		setTimeout('updateRank(\''+id+'\',\''+type+'\')',1000);

	}
	xmlHttp.send(null);
}

// topics *********************************
var topic_1 = null;
var topic_2 = null;
var topic_3 = null;
var topic_4 = null;
var topic_5 = null;

function GetTopic(wich) {
	var tema = 'topic_'+wich;

	if (tema != null) {
		var move = document.getElementById(tema).innerHTML;
		$('temasa').innerHTML = move;
		document.getElementById('temas').style.backgroundImage = 'url(images/temas/index_' + wich + '.gif);';
		tema = move;
	} else {
		$('temasa').innerHTML = tema.value;
	}
}

var friend = false;
function tfriend() {

	if (!friend) {
		friend = true;
		new Effect.BlindDown('tellafriend', { duration: 0.3 });
	} else {
		friend = false;
		new Effect.BlindUp('tellafriend', { duration: 0.3 });
	}


}

function updateTell() {
	if (xmlHttp.readyState == 4) {
		var response = xmlHttp.responseText;

		var strEntryArray = response.split('|');
		status = strEntryArray[0];
		code = strEntryArray[1];

		if (status == "E") {
			$('tellafriend').innerHTML = 'Hubo un error al procesar tu recomendación (' + code + ').';
		} else {
			$('tellafriend').innerHTML = 'Listo! Tu amigo ha sido notificado.';
			setTimeout('tfriend()',2500);
		}
	}
}

function tell() {

	if (document.amigo.email.value == "") {
		alert("Debes especificar un correo");
		document.amigo.from.focus();
		return false;
	}

	if (document.amigo.dest.value == "") {
		alert("Debes especificar el correo de tu amigo");
		document.amigo.dest.focus();
		return false;
	}

	$('tellafriend').innerHTML = 'Enviando...';

	var token = document.amigo.token.value;
	var nid = document.amigo.nid.value;
	var email = document.amigo.email.value;
	var dest = document.amigo.dest.value;

	var url = "call/friend/?nid=" + escape(nid) + '&token=' + escape(token) + '&email=' + escape(email) + '&dest=' + escape(dest);
	if (xmlHttp) {
		xmlHttp.onreadystatechange = function () {}
		xmlHttp.abort();
	}
	xmlHttp.open("GET", url, true);
	xmlHttp.onreadystatechange = updateTell;
	xmlHttp.send(null);

	return false;
}

var advicepop = false;

function advice(itemid,tippo) {

	if (advicepop) {
		nuevoDiv = $("advicepop");
		nuevoDiv.parentNode.removeChild(nuevoDiv);
		advicepop = false;
	}

	if (!advicepop) {
		if (tippo == "1") {
			$("advice-"+itemid).innerHTML+='<div id=advicepop>Para votar o agregar noticias, debes <a href=login/>Iniciar sesión</a> o <a href=registro/>Crear una cuenta</a></div>';
		} else if (tippo == "2") {
			$("advice-"+itemid).innerHTML+='<div id=advicepop>Gracias! Se han sumado los puntos correspondientes a esta noticia</div>';
		} else if (tippo == "3") {
			$("advice-"+itemid).innerHTML+='<div id=advicepop>Lo sentimos, hubo un error al procesar el voto de esta noticia</div>';
		} else if (tippo == "4") {
			$("advice-"+itemid).innerHTML+='<div id=advicepop>Debes esperar un momento antes de volver a votar</div>';
		}
		advicepop = $("advicepop");
	}

	//fix para lightbox
	initialize();
	return false;
}

