img_vote = webroot+'images/sao_vote.gif';
img_vote_empty = webroot+'images/sao_vote_empty.gif';
var is_voting_allowed = true;
var is_login = true;
$(document).ready(function(){	
	$('.vote').click(function(){
		alert('Cuộc thi ảnh đã kết thúc. Xin cảm ơn bạn đã quan tâm đến chương trình này.');
		return;
		
		if(!is_login){
			alert('Bạn phải đăng nhập để thực hiện chức năng bình chọn cho bài thi ảnh.');
			for(i = 0; i <=5; i++){
				$('#star_'+i).children('img').attr('src',img_vote_empty);
			}
			return;
		}
		if(!is_voting_allowed){
			return;
		}
		
		id = $(this).attr('id');			
		id = id.split('_');
		id = id[1];	
		$('#vote_form').children('#point').val(id);
		
		url = $('#vote_form').attr('action')+ "/"+id;
		
		var options = { 
			target:        '.show-diem',   // target element(s) to be updated with server response 
			beforeSubmit:  showRequest,  // pre-submit callback 
			success:       showResponse, // post-submit callback 
	 
			// other available options: 
			url:       url        // override for form's 'action' attribute 
			//type:      type        // 'get' or 'post', override for form's 'method' attribute 
			//dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
			//clearForm: true        // clear all form fields after successful submit 
			//resetForm: true        // reset the form after successful submit 
	 
			// $.ajax options can be used here too, for example: 
			//timeout:   3000 
		}; 
			// inside event callbacks 'this' is the DOM element so we first 
			// wrap it in a jQuery object and then invoke ajaxSubmit 
			$('#vote_form').ajaxSubmit(options); 
	 
			// !!! Important !!! 
			// always return false to prevent standard browser submit and page navigation 
	});

	$('.vote').hover(
		function(){
			/*if(is_login && !is_voting_allowed){
				return;
			}*/
		
			$(this).css('cursor','pointer');
			id = $(this).attr('id');			
			
			id = id.split('_');
			id = id[1];			
			
			for(i = id; i <=5; i++){
				$('#star_'+i).children('img').attr('src',img_vote_empty);
			}
			
			for(i = id; i >= 1; i--){
				$('#star_'+i).children('img').attr('src',img_vote);
			}
		}
	)
});

function showRequest(formData, jqForm, options) {
    var queryString = $.param(formData);
    $('.show-diem').hide();
	$('.ajax-loader').show();
    return true; 
} 

function showResponse(responseText, statusText)  {  
    $('.show-diem').show();
	$('.ajax-loader').hide();
	is_voting_allowed = false;
} 

