/* Required for: all files */
/* Function: Show hidden blocks */
function setSpiegazione(spiegazione){document.getElementById("showMe").style.display="block";document.getElementById("con").innerHTML=spiegazione}
function removeSpiegazione(){document.getElementById("con").innerHTML="";document.getElementById("showMe").style.display="none"}
function spiegazione (elemento) {
	switch (elemento) {
		case 'sendimg':
			setSpiegazione ("SendIMG e' un servizio creato da InformArts che permette di uppare con tranquillita' le proprie immagini.");
			break;
		case 'ret':
			setSpiegazione ("RET (sigla di Roberto's Encryption Tool) &egrave; un servizio che permette di criptare e decriptare in Base64, Codici ASCII, Binario, Hex e molto altro.");
			break;
		case 'nopaste':
			setSpiegazione ("Il NoPaste di InformArts serve per poter colorare i propri codici in modo da far comprendere meglio all'utente che visiona il codice. Il NoPaste supporta numerosi linguaggi di programmazione come il C.");
			break;
		case 'prc':
			setSpiegazione ("PRC (sigla di PageRank Checker) e' un servizio offerto da InformArts che permette di controllare in modo semplice il proprio pagerank. Inoltre offre banner da inserire nel proprio sito.");
			break;
		case 'mg':
			setSpiegazione ("L'InformArts MegaGenerator e' un servizio creato precedentemente da Bronsa, successivamente modificato da InformArts. Permette di generare link premium per MegaUpload e MegaVideo gratuitamente in modo totalmente legale.");
			break;
	}
}

/* Required for: single.php */
/* Function: Send a comment */
function sendComment (nickname, site, message, post, name, response) {
	hash = "1a18981bb15b25ed6f28108a79ecd22d";
	if (!site) site = "NULL";
	if (!nickname || !message || !response) { alert ("Non hai inserito tutti i campi necessari!"); return false; }
	$("div.loading").ajaxSend (
		function (a,b) {
			// Testing fix: jQuery 1.4.1 update
			// $("div.loading").html ("<img src=\"images/loading.gif\" alt=\"Caricamento..\" title=\"Caricamento..\" />");
			$(this).fadeIn ("slow");
			// Okay, it works. 12/02/10
		}
	);
	$.post ("./post-"+name+"-"+post+".html", {name: nickname, site: site, message: message, post: post, ajax: 1, hash: hash, response: response}, function (data) {
		if (data.success == 0 && data.html == "NULL") {
			alert ("Impossibile inviare il commento, è stato riscontrato il seguente errore: " + data.message);
			$("div.loading").fadeOut ("slow");
		} else if (data.success == 1 && data.html != "NULL") {
			$("div.loading").hide ();
			$("div.loading").text (data.message);
			$("div.loading").fadeIn ("slow");
			$('html,body').animate({scrollTop: 1200}, 1000);
			setTimeout ("$('div#loading').fadeOut('slow')", 5000);
			document.getElementById("comm").innerHTML = document.getElementById("comm").innerHTML.replace ("Nessun commento!", "");
			$("div#comm").append ("<div id='newcomment"+data.id+"' style='display:none'>"+data.html+"</div>");
			divId = "newcomment"+data.id;
			$("div#"+divId).fadeIn ("slow");
		}
	}, "json");
	
}

/* Required for: all */
/* Function: extend the block */
function cur () {
	if (document.getElementById ("ot").style.display == "none") {
		$("div#ot").slideDown ("slow");
		$("div#tt").html ("<a href=\"javascript:void(0)\" onclick=\"cur();\">< Nascondi</a>");
	}
	else
	{
		$("div#ot").slideUp ("slow");
		$("div#tt").html ("<a href=\"javascript:void(0)\" onclick=\"cur();\">> Mostra altro</a>");
	}
}

/* Required for: all pages */
/* Function: extend categories */

function extendCats () {
	if (document.getElementById ("catsToExtend").style.display == "none") {
		$("div#catsToExtend").slideDown ("slow");
		$("div#catsExtender").html ("<a href=\"javascript:void(0);\" onclick=\"extendCats();return;\">< Nascondi</a>");
	} else {
		$("div#catsToExtend").slideUp ("slow");
		$("div#catsExtender").html ("<a href=\"javascript:void(0);\" onclick=\"extendCats();return;\">> Mostra altre categorie</a>");
	}
}

function checkPR (site, post) {
	$("div#loading").ajaxSend (
		function (a,b) {
			$("div#loading").hide ();
			$("div#loading").html ("<img src=\"images/loading.gif\" alt=\"Caricamento..\" title=\"Caricamento..\" />");
			$("div#loading").fadeIn ("slow");
		}
	);
		$.post ("pagerank.php", {siteToCheck: site, ajax: 1}, function (data) {
			$("div#loading").fadeOut ("slow");
			$("div#loadObject").html(data);
		});
	
}

/* Required for: stats page */
function getStats (forWhat, from, to) {
	if (forWhat == "visits") {
		$("div#loading").ajaxSend (
			function (a,b) {
				$(this).fadeIn ("slow");
				$("div#result").text ("");
			}
		);
		$.getJSON ("stats.php?api=visitors&from=" + from + "&to=" + to, function (data) {
			$("div#loading").fadeOut ("slow");
			var total = data[0].totalnum;
			//alert (total);
			if (to != total && to < total) {
				var cosa;
				var nextTo = parseInt (to) + 10;
				if (nextTo > total) {
					cosa = total;
				} else {
					cosa = nextTo;
				}
				
				$("div#result").append ("<div style='text-align:right;'><a href='javascript:void(0);' onclick='getStats(\"" + forWhat + "\", " + (parseInt (from) + 10) + ", " + cosa + "); return false;'>>> Pagina successiva</a></div>");
			}
			var loltemp = from;
			if (loltemp == 0)
				loltemp = 1;
			for (i = 1; i < (data.length); i++) {
				if (from != 0) {
					loltemp++;
				}
				var dat = new Date(data[i].time * 1000);
				$("div#result").append ("Visitatore numero " + format (loltemp) + "<br />");
				$("div#result").append ("Browser: " + format (data[i].browser) + "<br />");
				$("div#result").append ("Referer: " + format (data[i].referer) + "<br />");
				$("div#result").append ("O.S.: " + format (data[i].os) + "<br />");
				$("div#result").append ("Pagina richiesta: " + format (data[i].page) + "<br />");
				$("div#result").append ("Ha visitato il sito il/alle ore: " + format (dat.toLocaleString()) + "<br />");
				$("div#result").append ("Con l'IP: " + format (data[i].ip) + "<br />");
				if (i != (data.length - 1)) {
					$("div#result").append ("<div class='newsSep'></div>");
				}
				if (from == 0) {
					loltemp++;
				}
			}
			if (to != total && to < total) {
				var cosa;
				var nextTo = parseInt (to) + 10;
				if (nextTo > total) {
					cosa = total;
				} else {
					cosa = nextTo;
				}
				
				$("div#result").append ("<div style='text-align:right;'><a href='javascript:void(0);' onclick='getStats(\"" + forWhat + "\", " + (parseInt (from) + 10) + ", " + cosa + "); return false;'>>> Pagina successiva</a></div>");
			}
			/*
			//if (to != 10) {
				var cosa;
				var nextTo = parseInt (to) - 10;
				//alert (nextTo);
				if (nextTo > total) {
					//alert ("nextTo = 10");
					cosa = 10;
				} else {
					//alert ("no");
					cosa = parseInt (to) - 10;
				}
				$("div#result").append ("<div  onclick='getStats(\"" + forWhat + "\", " + (parseInt (from) - 10) + ", " + cosa + "); return false;'>>> Pagina precedente</div>");
		//	} */
		});
	} else if (forWhat == "keywords") {
		$("div#loading").ajaxSend (
			function (a,b) {
				$(this).fadeIn ("slow");
				$("div#result").text ("");
			}
		);
		$.getJSON ("stats.php?api=keywords", function (data) {
			$("div#loading").fadeOut ("slow");
			if (data.length == 0) {
				$("div#result").append ("Nessuna keyword");
			} else {
				for (i = 0; i < data.length; i++) {
					$("div#result").append ("Nome keyword: " + data[i]);
					if (i != (data.length - 1)) {
						$("div#result").append ("<div class='newsSep'></div>");
					}
				}
			}
		});
	}
}


function format (str) {
	return "<strong>" + str + "</strong>";
}
		
// So .. bye bye Mega Generator
// 12/02/10
/*
function premiumLink (links) {
	$().ajaxSend (
		function (a, b) {
			$("div#loading").hide ();
			$("div#tlinks").hide ();
			$("div#loading").html ("<img src=\"images/loading.gif\" alt=\"Caricamento..\" title=\"Caricamento..\" />");
			$("div#loading").fadeIn ("slow");
		}
	);
	$.post ("./megagenerator/index.php", {links: links, ajax: 1}, function (data) {
		if (!data.success && data.html == "NULL") {
			$("div#loading").fadeOut ("slow");
			$("div#loading").text (data.message);
			$("div#loading").fadeIn ("slow");
			setTimeout ("$('div#loading').fadeOut('slow')", 5000);
		} else if (data.success && data.html != "NULL") {
			$("div#loading").fadeOut ("slow");
			$("div#loading").text (data.message);
			$("div#loading").fadeIn ("slow");
			setTimeout ("$('div#loading').fadeOut('slow')", 5000);
			$("div#tlinks").hide ();
			$("div#tlinks").html (data.html);
			$("div#tlinks").fadeIn ("slow");
		}
	}, "json");
}
*/

// Old sendcommend (without jQuery)
/*
function sendComment (nickname, site, message, post, name) {
	debug = 1;
	if (!site) {site = "NULL";}
	if (!nickname || !message) {
		alert ("Non hai riempito tutti i campi necessari");
		return false;
	}
	requestReturn ("./post-"+name+"-"+post+".html", "post", "loading", "name="+escape(nickname)+"&site="+escape(site)+"&message="+escape(message)+"&post="+post+"&ajax=1");
	x=setInterval ('if (document.getElementById("loading").innerHTML.indexOf("img") == -1) {d=document.getElementById("loading").innerHTML; if (d.indexOf ("span") != -1) {alert("Commento inserito con successo");if(document.getElementById("comm").innerHTML.indexOf("Nessun commento!")!=-1){document.getElementById("comm").innerHTML=document.getElementById("comm").innerHTML.replace("<br /><br />A","A");}document.getElementById("comm").innerHTML=document.getElementById("comm").innerHTML.replace("Nessun commento!","");document.getElementById("comm").innerHTML=document.getElementById("comm").innerHTML+d;document.getElementById("name").value="";document.getElementById("site").value="";document.getElementById("message").value="";}else if (d.indexOf("div")==-1&&d.indexOf("img")==-1){alert(d);}clearInterval(x);}', 5);
}
*/
