﻿$(function () {
    $('#Publish').click(function () {
        var voteLinks = $('.vote a, .poll-vote');
        if ($('#Publish').is(':checked')) {
            voteLinks.each(function () {
                $(this).attr('href', $(this).attr('href') + '?publish=true');
            });
        }
        else {
            voteLinks.each(function () {
                $(this).attr('href', $(this).attr('href').replace('?publish=true', ''));
            });
        }
    });

    $('input[maxlength], textarea[maxlength]').keyup(function () {
        return ismaxlength($(this)); 
    });
});

function getPublish() {
    return $('#Publish').is(':checked') ? '?publish=true' : '';
}

function ismaxlength(obj) {
    var mlength = obj.attr('maxlength') ? parseInt(obj.attr('maxlength')) : '';
    if (obj.attr('maxlength') && obj.val().length > mlength) {
        obj.val(obj.val().substring(0, mlength));
    }
}
