/* function for sidebar newsletter subscription */

function ajaxSubscribeNewsletter(){
	$.ajax(
		{
			url: "/xml/<$tom::lng>/newsletter/subscribe",
			data: { email: $('#newsletter_email').val() },
			dataType: 'xml',
			success: function(data){
				try{
					var responsemsg = $(data).find("response").find("message").text();
					$.fancybox(responsemsg);
					$('#newsletter_email').val('');
				}catch(e){
					//alert(e);
				}
			}
		}
	);
}

function userDialog(setup){
	var uri;
	if(setup.type=='login'){
		uri=cyclone3.domain+"/"+cyclone3.lng+"/user/login";
	}
	if(setup.type=='user_profile'){
		uri=cyclone3.domain+"/"+cyclone3.lng+"/user/profile";
	}
	$.fancybox(
		{
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut': 'none',
			'title'			: setup.title,
			'width'			: 700,
			'height'			: 495,
			'href'			: uri,
			'type'			: 'iframe'
		}
	);

	return false;
}

function pollVote(ID_poll, ID_vote){
	$.ajax(
		{
			url: "/xml/"+cyclone3.lng+"/poll/vote",
			data: { ID: ID_vote },
			dataType: 'xml',
			success: function(data){
				try
				{
					if($(data).find("response").find("result").text()==0)
					{
						$("#poll_"+ID_poll).find('.description').hide();
						$("#poll_"+ID_poll).find('.already_voted').show();
					}
					$(data).find("response").find("answer").each(
						function()
						{
							$("#poll_answer_"+$(this).attr("id")).find('.votevalue').html($(this).attr("votes_percent")+"%");
							if($(this).attr("highest")){
								$("#poll_answer_"+$(this).attr("id")).addClass('highest');
							}
							$("#poll_answer_"+$(this).attr("id")).find('.votevalue').html($(this).attr("votes_percent")+"%");
							$("#poll_answer_"+$(this).attr("id")).addClass('poll_answer_voted');
						}
					);
				}catch(e){
					alert(e);
				}
			}
		}
	);	
	
	return true;
}
