function get_xmlhttp()
{
	var xmlHttp;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	if (!xmlHttp && typeof XMLHttpRequest!='undefined')
	{
		xmlHttp = new XMLHttpRequest();
	}
	return xmlHttp
}

function votar (voto, id, tipo)
{
	var contenedor;
	contenedor = document.getElementById('valoracion');
	contenedor.innerHTML = '<center><img src="../gif/cargando.gif"></center>';
	ajax=get_xmlhttp();
	switch (tipo)
	{
		case 'restaurante':
		ajax.open("GET","../votar_restaurante.php?voto="+voto+"&id="+id,true);
		break;
		case 'pub':
		ajax.open("GET","../votar_pub.php?voto="+voto+"&id="+id,true);
		break;
		case 'discoteca':
		ajax.open("GET","../votar_discoteca.php?voto="+voto+"&id="+id,true);
		break;
		case 'hotel':
		ajax.open("GET","../votar_hotel.php?voto="+voto+"&id="+id,true);
		break;
		case 'hostal':
		ajax.open("GET","../votar_hostal.php?voto="+voto+"&id="+id,true);
		break;
		case 'museo':
		ajax.open("GET","../votar_museo.php?voto="+voto+"&id="+id,true);
		break;
			
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send(null);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4)
		{
			contenedor.innerHTML = ajax.responseText;
		}
	}
}

function changeover(obj, rating)
{
	var imageName = obj.src;
	var id = obj.title;
	var index = imageName.lastIndexOf('/');
	var filename = imageName.substring(index+1);
	var fullId = obj.id;
	var idName = fullId.substr(0, fullId.indexOf('_'));
	var totalRating = rating;
	for(i=0; i<id; i++)
	{
		var num = i+1;
		document.getElementById(idName+'_'+num).src = '../gif/bigstar3.gif';
	}

}

function changeout(obj, rating)
{
	var imageName = obj.src;
	var id = obj.title;
	var index = imageName.lastIndexOf('/');
	var filename = imageName.substring(index+2);
	var fullId = obj.id;
	var idName = fullId.substr(0, fullId.indexOf('_'));
	var totalRating = rating;

	for(i=0; i<id; i++)
	{
		var num = i+1;
		if(i < totalRating)
		{
			document.getElementById(idName+'_'+num).src = '../gif/bigstar.gif';
		}
		else
		{
			document.getElementById(idName+'_'+num).src = '../gif/bigstar2.gif';
		}
	}
}

