Timeshit

by masterhead

HTML

<link rel="stylesheet" href="http://bootswatch.com/cosmo/bootstrap.min.css">
<script src="http://bootswatch.com/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<table class="table table-striped table-hover" id="tab_logic">
    <thead>
        <tr>
            <th colspan="33" style="text-align: center;">February 2015</th>
        </tr>
        <tr>
            <th colspan="2" style="vertical-align: middle;"></th>
            <th>
                <input type="checkbox" name="chk-col" id="col-1">
            </th>
            <th>
                <input type="checkbox" name="chk-col" id="col-2">
            </th>
            <th>
                <input type="checkbox" name="chk-col" id="col-3">
            </th>
            <th>
                <input type="checkbox" name="chk-col" id="col-4">
            </th>
            <th>
                <input type="checkbox" name="chk-col" id="col-5">
            </th>
            <th>
                <input type="checkbox" name="chk-col" id="col-6">
            </th>
            <th>
                <input type="checkbox" name="chk-col" id="col-7">
            </th>
            <th>
                <input type="checkbox" name="chk-col" id="col-8">
            </th>
            <th>
                <input type="checkbox" name="chk-col" id="col-9">
            </th>
            <th>
                <input type="checkbox" name="chk-col" id="col-10">
            </th>
            <th>
                <input type="checkbox" name="chk-col" id="col-11">
            </th>
            <th>
                <input type="checkbox" name="chk-col" id="col-12">
            </th>
            <th>
                <input type="checkbox" name="chk-col" id="col-13">
            </th>
            <th>
                <input type="checkbox" name="chk-col" id="col-14">
            </th>
            <th>
                <input type="checkbox" name="chk-col" id="col-15">
            </th>
            <th>
                <input...

JavaScript

$(document).ready(function () {
    var i = 1;
    $("#add_row").click(function () {
        $('#row-' + i).html('<td><input type="checkbox" name="chk" id="row-' + i + '"></td> <td><input type="text" name="txt" id="row-' + i + '"></td> <td id="col-1"></td> <td id="col-2"></td> <td id="col-3"></td> <td id="col-4"></td> <td id="col-5"></td> <td id="col-6"></td> <td id="col-7"></td> <td id="col-8"></td> <td id="col-9"></td> <td id="col-10"></td> <td id="col-11"></td> <td id="col-12"></td> <td id="col-13"></td> <td id="col-14"></td> <td id="col-15"></td> <td id="col-16"></td> <td id="col-17"></td> <td id="col-18"></td> <td id="col-19"></td> <td id="col-20"></td> <td id="col-21"></td> <td id="col-22"></td> <td id="col-23"></td> <td id="col-24"></td> <td id="col-25"></td> <td id="col-26"></td> <td id="col-27"></td> <td id="col-28"></td> <td id="col-29"></td> <td id="col-30"></td> <td id="col-31"></td>');

        $('#tab_logic').append('<tr id="row-' + (i + 1) + '"></tr>');
        i++;
    });
    $("#delete_row").click(function () {
        if (i > 1) {
            $("#row-" + (i - 1)).html('');
            i--;
        }
    });

});

function randomizer() {

    var max_int = 8;
    var int_remains = max_int;
    var arr = [];
    var arrlen = $('[name="chk"]:checked').length;
    var arrrows = $('[name="chk"]:checked').map(function() {
        return this.id;
    }).get();
    var arrcols = $('[name="chk-col"]:checked').map(function() {
        return this.id;
    }).get();
    var number = 0;
    for (i = 0; i < arrlen - 1; i++) {
        if (int_remains == max_int) {
            number = Math.floor(Math.random() * max_int) + 1;
            arr[i] = number;
        } else {
            number = Math.floor(Math.random() * (int_remains));
            arr[i] = number;
        }
        if (int_remains > 0) {
            int_remains = int_remains - number;
        } else {
            int_remains = 0;
        }
    };
    arr[arrlen - 1] = int_remains;
   ...