function crearObjeto()
{
	var ro;
	var browser = navigator.appName;
	if(browser == 'Microsoft Internet Explorer')
	{
		ro = new ActiveXObject('Microsoft.XMLHTTP');	
	}
	else
	{
		ro = new XMLHttpRequest();	
	}
	return ro;
}
var http1 = crearObjeto();
function daleAjax(id,url,arg,func)
{
	eval("http"+id+".open('get','/"+url+".php?"+arg+"',true);");
	eval("http"+id+".onreadystatechange = "+func+";");
	eval("try { http"+id+".send(null); } catch(e) { alert('Se ha producido un error. Por favor, actualiza la página'); }");
}

///////////////////////////////////////////////////////////////////
// FUNCIONES PARA LA VOTACION

function estrella(id)
{
	var txt;
	if(id == 1)
		txt = "<b>Muy Malo</b>";
	if(id == 2)
		txt = "<b>Malo</b>";
	if(id == 3)
		txt = "<b>Regular</b>";
	if(id == 4)
		txt = "<b>Bueno</b>";
	if(id == 5)
		txt = "<b>Muy Bueno</b>";
	if(id == 0)
		txt = document.getElementById('votacion_inicial').value;		
	document.getElementById('votacion').innerHTML= txt;
}

function vota(id,opc)
{
	document.getElementById('votacion_res').innerHTML = '<img src="/img/pensando.gif">';
	daleAjax(1,'votacion_grabar','id='+id+'&opc='+opc,'votacion_grabar');
}

function votacion_grabar()
{
	if(http1.readyState == 4)
	{
		//alert('eso '+http1.responseText);
		var txt = http1.responseText.split('|');
		if(txt[0] == 'ok')
		{
			document.getElementById('votacion_inicial').value = txt[2];
			document.getElementById('votacion').innerHTML = txt[2];
			document.getElementById('votacion_estrellas').style.width = (txt[1]*20)+'px';
			document.getElementById('votacion_res').innerHTML = '<b>ˇGracias por votar!</b>';
		}
		else
		{
			document.getElementById('votacion_res').innerHTML = '<b>Ya has votado</b>';
		}
		
	}
}
