//Ajax manager
var voteManager = new AjaxManager("voteManager", false);

function VoteMedia(id,tipo,vote) {
	var messageVote = document.getElementById("MessageVote");
	var idVote = document.getElementById("VoteInvisible");
	if (!getCookie("vote_"+id+"_"+tipo)) {
	    this.url = '/mpVoteMedia/0,,'+id+'-'+tipo+'-'+vote+',00.html';
		idVote.value = id+"_"+tipo;
		// Creates a new ajax item
		voteManager.Add(url, AjaxVote_Parse, null, null, null, null, null);
	} else {
		hide_block('More');
		hide_block('Send');
		hide_block('Vote');
		messageVote.innerHTML = "Hai gi&agrave; votato!";
		display_block('Thanks');
		display_block('MediaVotiInvisible');
	}
}

function MediaVoti(id,tipo) {
    this.url = '/mpVoteMedia/0,,'+id+'-'+tipo+',00.html';
	// Creates a new ajax item
	voteManager.Add(url, AjaxMediaVoti_Parse, null, null, null, null, null);
}

function VoteMediaWebTV(tipo,vote) {
	var messageVote = document.getElementById("MessageVote");
	var idVote = document.getElementById("VoteInvisible");
	var idMedia = document.getElementById("idMediaWebtv");
	
	if (!getCookie("vote_"+idMedia.value+"_"+tipo)) {
	    this.url = '/mpVoteMedia/0,,'+idMedia.value+'-'+tipo+'-'+vote+',00.html';
		idVote.value = idMedia.value+"_"+tipo;
		// Creates a new ajax item
		voteManager.Add(url, AjaxVote_Parse, null, null, null, null, null);
	} else {
		hide_block('More');
		hide_block('Send');
		hide_block('Vote');
		messageVote.innerHTML = "Hai gi&agrave; votato!";
		display_block('Thanks');
		display_block('MediaVotiInvisible');
	}
}

function MediaVotiWebTV(tipo) {
	var idMedia = document.getElementById("idMediaWebtv");
    this.url = '/mpVoteMedia/0,,'+idMedia.value+'-'+tipo+',00.html';
	// Creates a new ajax item
	voteManager.Add(url, AjaxMediaVoti_Parse, null, null, null, null, null);
}

// Parses the return of the medias XML
function AjaxMediaVoti_Parse()
{
	var mediaVotiID = document.getElementById("MediaVoti");
	if(this.httpRequest.status == 200)
	{
		var mediaVoti = this.httpRequest.responseText;
		if(!isNaN(mediaVoti)){
			mediaVotiID.innerHTML = "Media : "+mediaVoti;
		}
	}
}
// Parses the return of the medias XML
function AjaxVote_Parse()
{
	var HOST = '';
	var messageVote = document.getElementById("MessageVote");
	var idVote = document.getElementById("VoteInvisible");
	var mediaVotiInvisibleID = document.getElementById("MediaVotiInvisible");
	
	if(this.httpRequest.status == 200)
	{
		var mediaVoti = this.httpRequest.responseText;
		if(!isNaN(mediaVoti)){
			setCookie("vote_"+idVote.value,'ok','1','/',HOST,'');
			hide_block('More');
			hide_block('Send');
			hide_block('Vote');
			messageVote.innerHTML = "Grazie per aver votato!";
			mediaVotiInvisibleID.innerHTML = "Media : "+mediaVoti;
			display_block('Thanks');
			display_block('MediaVotiInvisible');			
		}
	}
}