function display_block(id) {
	$("#"+id).show();
};
function hide_block(id) {
	$("#"+id).hide();
};
function changeClassRaitv(id, className)
{
	var object = document.getElementById(id);
	if(object !== null)
	{
		object.className = className;
		object.style.className = className;
	}
};

function SendFriend(idItem) {
	var emailObject = "Invito visita Junior.rai.it";
	var emailBody ="<style type='text/css'> #Header{width:620px;height:360px;text-align:center;background-image: url(http://www.junior.rai.it/dl/junior/image/cartolinajunior.jpg);}</style><div id='Header'><table width='620' height='360' border='0' cellpadding='0' cellspacing='0' align='center' background='cartolina.jpg'><tr><td width='204' height='121' colspan='2' valign='top'><a style='display:block; width:188px; height:78px;' href='http://www.junior.rai.it'></a></td><td width='176' height='121'></td><td width='240' height='121' valign='top'><a style='display:block; width:240px; height:121px;' href='http://www.junior.rai.it/dl/RaiTV/programmi/media/"+idItem+"-junior.html'></a></td></tr><tr><td width='65' height='26'></td><td width='139' height='26' style='font-size: 13px; font-family: Arial; font-weight: bold; color: #fff; padding-top: 2px;'>"+$("#emailFrom").val()+"</td><td width='176' height='26'></td><td width='240' height='26'></td></tr><tr><td width='65' height='26'></td><td width='139' height='26' style='font-size: 13px; font-family: Arial; font-weight: bold; color: #fff; padding-top: 2px;'>"+$("#emailTo").val()+"</td><td width='176' height='26'></td><td width='240' height='26'></td></tr><tr><td width='65' height='187'></td><td width='139' height='167' valign='top' style='font-size: 13px; font-family: Arial; color: #fff; padding-top: 20px;'>"+$("#emailCommento").val()+"</td><td width='176' height='187'></td><td width='240' height='187'></td></tr></table></div>";
	var valori = {emailFrom : $("#emailFrom").val(), emailTo:$("#emailTo").val(),emailBody: emailBody, emailObject :emailObject};
	//var emailBody = "";
	//var valori = {};
	var esito ="";
	$.ajax({
	   url: "http://www.junior.rai.it/services/sendEmail.jsp",
	   type: "POST",
	   dataType: "text",
	   data: valori,
	   success: function(result){
			if(jQuery.trim(result) == "ok") {
				$('#MessageVote').html("Email inviata.Grazie!");
			} else {
				$('#MessageVote').html("Errore! Riprovare");
			}
			$("#Send").fadeOut();
			$('#Thanks').fadeIn(2000).fadeOut(2000);
	   },
	   error : function(result){
			$('#MessageVote').html("Errore! Riprovare");
			$('#Thanks').fadeIn(2000).fadeOut(2000);
		}
	});
};

function replaceMSWord(str) {
	str = str.replace(/…/g,'...');
	str = str.replace(/“/g,'"');
	str = str.replace(/”/g,'"');
	str = str.replace(/’/g,"'");
	return str;
};

function VoteMedia(idItem,vote)
{
	$("#Thanks").hide();
	$("#Send").hide();
	$("#Vote").hide();
	var title = "";
	var tags = "";
	var pathImgStat ="";
	var nomeProgramma ="";
	var duration = "";
	try {title = $('#idMedia').text() != "null" || $('#idMedia').length != 0 ? replaceMSWord($('#idMedia').text()) : "";} catch(e){}
	try {nomeProgramma = $("#nomeProgramma").text() != "null" ? replaceMSWord($("#nomeProgramma").text()) : "";} catch(e){}
	try {tags = $('#myTematiche').text() != "null" ? replaceMSWord($('#myTematiche').text()) : "";} catch(e){}
	try {pathImgStat = $('#pathImgStat').text() != "null" ? $('#pathImgStat').text() : "";} catch(e){}
	nomeProgramma = jQuery.trim(nomeProgramma);
	
	if(nomeProgramma == ""){
		tags = tags.substring(0,tags.length-1);
	} else {nomeProgramma = "NomeProgramma:"+nomeProgramma;}
	tags = tags + nomeProgramma;

	if ($("#timeMedia").text() != '00:00:00' && $("#timeMedia").text() != ''){
		duration = "&duration="+escape($("#timeMedia").text());
	}

	var urlVote = "http://"+document.domain+"/StatisticheProxy/proxy.jsp?action=updateVote&domain=RaiTv&localId="+idItem+"&vote="+vote+"&tags="+escape(tags)+"&title="+escape(title)+"&imagePath="+pathImgStat+duration;
	$.ajax({
	  url: urlVote,
	  cache: false,
	  success: function(html){
		$('#MessageVote').html("Grazi per aver votato!");
		$('#Thanks').fadeIn(2000).fadeOut(2000);
	  }
	});
};
function rewriteHREFMultimedia() {
	$(".Item ul>li a").each(function(){
		$(this).attr("href",$(this).attr("href").replace(/.html/g,"-junior.html"));
	});
};
$(function()
{
	setTimeout("rewriteHREFMultimedia()",600);
	$("#manda").click(function() {
		$("#Vote").hide();
		$("#Thanks").hide();
		$("#Send").show();
	}).mouseover(function(){
		$(this).removeClass("webtv_InviaAmico");
		$(this).addClass("webtv_InviaAmico_on");
	}).mouseout(function(){
		$(this).removeClass("webtv_InviaAmico_on");
		$(this).addClass("webtv_InviaAmico");
	});

	$("#vota").click(function() {
		$("#Thanks").hide();
		$("#Send").hide();
		$("#Vote").show();
	}).mouseover(function(){
		$(this).removeClass("webtv_DaiVoto");
		$(this).addClass("webtv_DaiVoto_on");
	}).mouseout(function(){
		$(this).removeClass("webtv_DaiVoto_on");
		$(this).addClass("webtv_DaiVoto");
	});
	$(".Info").css("visibility","visible");
	
});
