var vote_num_answers = new Object();

var VoteCustom = function(obj, textid, max) {
    var votemax = 'Максимум ' + max + ' знаков';

    if ( obj.checked || obj.attr('checked') ) {
        ident = '#poll_custom_' + textid;
        if ($(ident).attr('value') == votemax) {
            $(ident).attr('value', '');
        }
    }
}

var VoteCheckCustom = function(id, max, max_answers) {
    ident = '#check_custom_' + id;

    $('#vote_limit').hide();
    if ($(ident).attr('checked') == '')
    {
        $(ident).attr('checked', 'checked');
        VoteCustom($(ident), id, max);
    }
}

var VoteCheckMax = function(obj, max_answers, id) {
    if (!vote_num_answers[id]) vote_num_answers[id] = 0;

    $('#vote_limit').hide();
    if (obj.checked) {
        if (vote_num_answers[id] == max_answers) {
            $('#vote_limit').css('top', FindPosY(obj)-243).show();
            obj.checked = 0;
        }
        else {
            ++vote_num_answers[id];
        }
    }
    else {
        --vote_num_answers[id];
    }
}

var FindPosY = function(obj) {
   var curtop = 0;
   if(obj.offsetParent)
       while(1)
       {
         curtop += obj.offsetTop;
         if(!obj.offsetParent)
           break;
         obj = obj.offsetParent;
       }
   else if(obj.y)
       curtop += obj.y;
   return curtop;
}
