$(function(){
	var host = document.domain.split('.');
	var vote_to = '';
	// send sn
	$('a[name="vote"]').click(function(){
		vote_to = this.id;
		//alert('活動已結束');
		
		if(login == false){
			alert("請先登入優學網");
			location.href='http://tw.portal.urlifelinks.com/?_from='+host[0]+'.events.urlifelinks.com/2010_mediawatch/?mode=voting';					
		}
		else if(voted == false){
			alert("今天已經投票過囉");
		}
		else{
			var ad_left = ($(window).width() - 700) /2 + 'px'
			var ad_top = ($(window).height() - 400) /2 + 'px';
			
			$.blockUI({ 
				message: $('#box_info'),
				css: { 
					padding:        10, 
					margin:         0, 
					width:         '700', 
					//height:         '400', 
					top:  ad_top, 
					left: ad_left, 
					textAlign:      'center', 
					color:          '', 
					border:         '', 
					backgroundColor:'',
					cursor:         null 
				},
				overlayCSS:  { 
					backgroundColor: ''
				}
			});	
			
			$('a[name="close"]').click(function(){
				$.unblockUI();
				return false;
			});
		}
		
		return false;
	});
	
	// send vote
	$('#send_vote').click(function(){
		//alert('活動已結束');
		
		var data = $('#form_info input').serialize()+'&vote_to='+vote_to;
		
		if(vote_to == '') alert('請選擇節目投票');
		else{
			$.ajax({
				type: "POST",
				url: '?mode=ajax&id=vote',
				data: data,
				dataType: 'json',
				async: false,
				beforeSend: function(){
					//$(button).hide().after('<img src="images/ajax-loader.gif">');
				},
				success: function(data){					
					if(data.success == false){
						alert(data.msg);
						if(data.doing == 'login') location.href='http://tw.portal.urlifelinks.com/?_from='+host[0]+'.events.urlifelinks.com/2010_mediawatch/?mode=voting';					
					}
					else if(data.success == true){
						alert(data.msg);
						location.reload();
					}
				}
			});
		}
		
		return false;
	});
	
	$('#no_mem').click(function(){
		alert('12月3日公布得獎名單喔! 請準時上來看看自己有沒有得獎吧!!');
		return false;
	});
});

