function contest_vote(id) {
    $.get("/ajax", { action: 'photocontest_vote', vote_id: id }, function(data) {
        if (data.length) $('#votes'+id).html(data);
    } );
}

function contest_postComment(goodID) {
    if ($('#commentName').attr("value") == '' || $('#commentText').attr("value") == '') return;
    
    $.each($(':input'),function(){ 
        $(this).attr("disabled","disabled");
    });

     $.ajax({
       type: "GET",
       url: "ajax?action=contest_addComment&name="+encodeURIComponent($('#commentName').attr("value"))+"&msg="+encodeURIComponent($('#commentText').attr("value"))+"&email="+encodeURIComponent($('#commentEmail').attr("value"))+"&subscribe="+encodeURIComponent($('#commentSubscribe').attr("checked"))+'&g='+goodID,
       data: '',
       success: function(msg){
//        $('#TRaddComment').hide();
        $('#infDiv').fadeIn("slow");
        $.each($(':input'),function(){ 
            $(this).attr("disabled","");
        });
        my$('commentName').value = my$('commentText').value = my$('commentEmail').value = ''; 
        my$('commentSubscribe').checked = false;
        setTimeout(function(){$('#infDiv').fadeOut("slow")}, 5000);
        
        contest_loadComments(goodID);
       },
       error: function(obj,msg){
        alert(msg);
       }
     });
}

function contest_postReply(goodID, comment_id) {
    if ($('#replyFormName'+comment_id).attr("value") == '' || $('#replyFormText'+comment_id).attr("value") == '') return;
    
    $.each($(':input'),function(){ 
        $(this).attr("disabled","disabled");
    });

     $.ajax({
       type: "GET",
       url: "ajax?action=contest_addReply&name="+encodeURIComponent($('#replyFormName'+comment_id).attr("value"))+"&msg="+encodeURIComponent($('#replyFormText'+comment_id).attr("value"))+'&g='+goodID+'&p='+comment_id,
       data: '',
       success: function(msg){
        $('#replyForm'+comment_id).detach()
       
        $('#infDiv').fadeIn("slow");
        $.each($(':input'),function(){ 
            $(this).attr("disabled","");
        });
        $('#replyFormName'+comment_id).attr("value",'');
        $('#replyFormText'+comment_id).attr("value",'');
        setTimeout(function(){$('#infDiv').fadeOut("slow")}, 5000);
        
        
        contest_loadComments(goodID);
       },
       error: function(obj,msg){
        alert(msg);
       }
     });
}

function contest_loadComments(goodID) {
    $.get("ajax?action=contest_getComments&g="+goodID,
        function(data){
            $('#comments').html(data);
    });
}

function contest_showReplyForm(goodID, obj, comment_id) {
    if ( (form = $('#replyForm'+comment_id)).length ) {
        form.detach();
    } else {
        form = $('#replyForm').clone(1).appendTo($(obj.parentNode));
        form.attr('id', 'replyForm'+comment_id);
        $('#replyForm'+comment_id+' .replyFormName').attr('id', 'replyFormName'+comment_id);
        $('#replyForm'+comment_id+' .replyFormText').attr('id', 'replyFormText'+comment_id);
        $('#replyForm'+comment_id+' .replyFormBtn').bind('click', function() { contest_postReply(goodID, comment_id) } );
        form.show();
    }
}
