var post_id = 0;
var fav_id = 0;
var blocked = 0;
var prob = 0;
st =new Array(6);

function current_rating(id, rating)
{
	post_id = id;
// 	alert(id+rating);
	for(i = 1; i <= rating; i++)
	{
	document.images['rating_' + post_id + '_' + i].style.backgroundPosition="0 0px";
	}
	for(i=rating +1; i<=5; i++ )
	{
		document.images['rating_' + post_id + '_' + i].style.backgroundPosition="0 24px";
// 		alert('rating_' + post_id + '_' + i);
	}
}

function ratings_off()
{

	for(i=1; i<=5; i++ )
	{
		if (st[i] == 0)
		{
			document.images['rating_' + post_id + '_' + i].style.backgroundPosition="0 24px";
		}
		if (st[i] == 1)
		{
			document.images['rating_' + post_id + '_' + i].style.backgroundPosition="0 -24px";
		}
		if (st[i] == 2)
		{
 			document.images['rating_' + post_id + '_' + i].style.backgroundPosition="0 0px";
		}
	}
}

function set_values(a,b,c,d,e)
{
	st[1] = a;
	st[2] = b;
	st[3] = c;
	st[4] = d;
	st[5] = e;
}


 //inicializamos la libreria
 var myConn = new XHConn();


 //si no existe da error
 if (!myConn) alert("XMLHTTP no disponible. Intenta un mejor browser.");


 //funcion que se llama luego del include
var include_terminado = function (oXML)
{
	document.getElementById('post-ratings-' + post_id).innerHTML = oXML.responseText;
};

function rate_post(valor) {

		document.getElementById('texto-votos-' + post_id).innerHTML = "<small><small>Procesando tu voto...</small></small>";
		myConn.connect("/proc/procesa_voto.php", "GET", "voto="+valor+"&vid="+post_id, include_terminado);
}



var nula = function (oXML)
{ if (oXML.responseText ==" ") {} }



function favorito(video)
{
		blocked = 1;
		myConn.connect("/proc/procesa_fav.php", "GET", "vid="+video, fav_terminado);
}

function borrafav(video)
{
		blocked = 1;
		myConn.connect("/proc/procesa_borrar_fav.php", "GET", "vid="+video, borrafav_terminado);
}

var fav_terminado = function (oXML)
{
// 	alert('fav-' + fav_id);
	document.getElementById('fav-' + fav_id).innerHTML = '<small>'+oXML.responseText+'</small>';
	blocked = 0;
};

var borrafav_terminado = function (oXML)
{
// 	alert('fav-' + fav_id);
	document.getElementById('fav-' + fav_id).innerHTML = '<small>'+oXML.responseText+'</small>';
	blocked = 0;
};

function current_fav(id)
{
   if (blocked == 0)
   {
	fav_id = id;
   }
}

function avisar_problema(problema, video)
{
	if (problema.problema.value == 0)
	return;

	if (! confirm("Seguro que desea reportarlo?") ) {
		problema.problema.selectedIndex=0;
		return false;
	}


	valor_prob = problema.problema.value;

	document.getElementById('problema'+video).innerHTML = '<small>Enviando problema...</small>';

	prob = video;
	myConn.connect("/proc/procesa_prob.php", "GET", "vid="+video+"&prob="+valor_prob, problema_avisado);

}

var problema_avisado = function (oXML)
{
// 	alert('fav-' + fav_id);
	document.getElementById('problema'+prob).innerHTML = '<small>'+oXML.responseText+'</small>';
};
