function mostraAvaliacao(base_url, c, cid, titulo_link, avaliacoes, media) {
	var media = media * 1;
	var mediapc = media * 20;
	document.write("<span class='inline-rating'><ul class='star-rating small-star'>" +
		"<li class='current-rating' style='width:"+ mediapc +"%;'>Atualmente " + media + "/5 estrelas.</li>" +
		"<li><a href='" +
		base_url + "/" + c + "/avaliar.php?cid=" +
		cid +"&nota=1&titulo=" +
		titulo_link +"' onclick='registrarVoto(this, 1); return false;' title='1 estrela de 5 (" + media + " atualmente)' class='one-star'>1</a></li>" +
		"<li><a href='" +
		base_url + "/" + c + "/avaliar.php?cid=" +
		cid +"&nota=2&titulo=" +
		titulo_link +"' onclick='registrarVoto(this, 2); return false;' title='2 estrelas de 5 (" + media + " atualmente)' class='two-stars'>2</a></li>" +
		"<li><a href='" +
		base_url + "/" + c + "/avaliar.php?cid=" +
		cid +"&nota=3&titulo=" +
		titulo_link +"' onclick='registrarVoto(this, 3); return false;' title='3 estrelas de 5 (" + media + " atualmente)' class='three-stars'>3</a></li>" +
		"<li><a href='" +
		base_url + "/" + c + "/avaliar.php?cid=" +
		cid +"&nota=4&titulo=" +
		titulo_link +"' onclick='registrarVoto(this, 4); return false;' title='4 estrelas de 5 (" + media + " atualmente)' class='four-stars'>4</a></li>" +
		"<li><a href='" +
		base_url + "/" + c + "/avaliar.php?cid=" +
		cid +"&nota=5&titulo=" +
		titulo_link +"' onclick='registrarVoto(this, 5); return false;' title='5 estrelas de 5 (" + media + " atualmente)' class='five-stars'>5</a></li>" +
		"</ul></span>");
}

function mostraTags(b,t,s,d) {
	var a = t.split(',');
	
	document.write('<span class=tags>'+d);
	/*if (s) {
		document.write(' | nota: ');
		var ss = s.split(',');
		mostraAvaliacao(b,ss[0],ss[1],ss[2],ss[3],ss[4]);
	}*/

	document.write(' | tags: ');
	for (i=0;i<a.length;i++) {
		document.write(' <a href="'+b+"/"+a[i]+'/">'+a[i]+'</a>');

		if (i < a.length - 1) {
			document.write(',');
		}
	}
	document.write('</span>');
}

function registrarVoto(obj, nota) {
	var mediapc = nota * 20;
	sendRequest(obj.href+'&x='+nota);
	obj.parentNode.parentNode.innerHTML="<li class='current-rating' style='width:"+ mediapc +"%;'>Voto efetuado</li>";
}

function confirmaExclui(redir) {
	var confirma = prompt("ATENÇÃO!\nO ITEM SERÁ EXCLUIDO!\nESSA AÇÃO NÃO PODERÁ SER DESFEITA\n\nDigite SIM para confirmar", "");
	if (confirma === "SIM") {
		location.href=redir+"&cf=1";
		return true;
	}
	return false;
}

function dumpProps(obj, parent) {
   // Go through all the properties of the passed-in object 
document.write("<dt>");
   for (var i in obj) {
document.write("<dl>");
      // if a parent (2nd parameter) was passed in, then use that to 
      // build the message. Message includes i (the object's property name) 
      // then the object's property value on a new line 
      if (parent) { var msg = parent + "." + i + "\n" + obj[i]; } else { var msg = i + "\n" + obj[i]; }
      // Display the message. If the user clicks "OK", then continue. If they 
      // click "CANCEL" then quit this level of recursion 
//       if (!confirm(msg)) { return; }
document.write(msg);

      // If this property (i) is an object, then recursively process the object 
      if (typeof obj[i] == "object") { 
         if (parent) { dumpProps(obj[i], parent + "." + i); } else { dumpProps(obj[i], i); }
      }
document.write("</dl>");

   }
document.write("</dt>");

}

function setHoje(label) {
	var hoje = new Date();
	var ano = hoje.getYear();
	var mes = hoje.getMonth() + 1;
	var dia = hoje.getDate();
	var hora = hoje.getHours();
	var minuto = hoje.getMinutes();
	if (ano<100) {
		ano = "19"+ano;
	} else if (ano>99 && ano<2000) {
		ano = "20"+String(ano).substring(1, 3);
	}
 	if (mes<10) {
 		mes = "0"+mes;
 	}
// 	if (dia<10) {
// 		dia = "0"+dia;
// 	}
	document.getElementsByName(label+'[Date_Day]')[0].value = dia;
	document.getElementsByName(label+'[Date_Month]')[0].value = mes;
	document.getElementsByName(label+'[Date_Year]')[0].value = ano;
	if (document.getElementsByName(label+'[Time_Hour]')[0]) {
		document.getElementsByName(label+'[Time_Hour]')[0].value = hora;
		document.getElementsByName(label+'[Time_Minute]')[0].value = minuto;
	}
}


/* Ajax simplificado */
function sendRequest(url,callback,postData) {
	var req = createXMLHTTPObject();
	if (!req) return;
	var method = (postData) ? "POST" : "GET";
	req.open(method,url,true);
	req.setRequestHeader('User-Agent','XMLHTTP/1.0');
	if (postData)
		req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	req.onreadystatechange = function () {
		if (req.readyState != 4) return;
		if (req.status != 200 && req.status != 304) {
//			alert('HTTP error ' + req.status);
			return;
		}
		if (callback)
			callback(req);
// 		alert(req.responseText);
	}
	if (req.readyState == 4) return;
	req.send(postData);
}

var XMLHttpFactories = [
	function () {return new XMLHttpRequest()},
	function () {return new ActiveXObject("Msxml2.XMLHTTP")},
	function () {return new ActiveXObject("Msxml3.XMLHTTP")},
	function () {return new ActiveXObject("Microsoft.XMLHTTP")}
];

function createXMLHTTPObject() {
	var xmlhttp = false;
	for (var i=0;i<XMLHttpFactories.length;i++) {
		try {
			xmlhttp = XMLHttpFactories[i]();
		}
		catch (e) {
			continue;
		}
		break;
	}
	return xmlhttp;
}

Array.prototype.getUniqueValues = function () {
	var hash = new Object();
	for (j = 0; j < this.length; j++) {hash[this[j]] = true}
	var array = new Array();
	for (value in hash) {array.push(value)};
	return array;
}
