﻿var jobcount = new Object()
var initJobCount = '';
var jobIncrement = '';

jobcount.display = function() {
    //get the initial values
    initJobCount = document.getElementById('initJobCount').value;

    //get the initial values
    jobIncrement = document.getElementById('jobIncrementor').value;

    var jobCountinstance = this
    this.spanid = "jobcountspan";
    document.write('<span id="' + this.spanid + '"></span>')
    this.update()
    setInterval(function() { jobCountinstance.update() }, 1000)
}

jobcount.display.prototype.update = function() {

    var jobFinalCount = parseFloat(initJobCount) + parseFloat(jobIncrement);

    initJobCount = jobFinalCount;

    var tempJobCount = parseInt(initJobCount);

    //format count
    //convert to string
    tempJobCount += '';
    switch (tempJobCount.length) {

        case 4:
            tempJobCount = tempJobCount.substr(0, 1) + ',' + tempJobCount.substr(1, 3);
            break;
        case 5:
            tempJobCount = tempJobCount.substr(0, 2) + ',' + tempJobCount.substr(2, 3);
            break;
        case 6:
            tempJobCount = tempJobCount.substr(0, 3) + ',' + tempJobCount.substr(3, 3);
            break;
        case 7:
            tempJobCount = tempJobCount.substr(0, 1) + ',' + tempJobCount.substr(1, 3) + ',' + tempJobCount.substr(4, 3);
            break;
        case 8:
            tempJobCount = tempJobCount.substr(0, 2) + ',' + tempJobCount.substr(2, 3) + ',' + tempJobCount.substr(5, 3);
            break;
        case 9:
            tempJobCount = tempJobCount.substr(0, 3) + ',' + tempJobCount.substr(3, 3) + ',' + tempJobCount.substr(6, 3);
            break;
        case 10:
            tempJobCount = tempJobCount.substr(0, 1) + ',' + tempJobCount.substr(1, 3) + ',' + tempJobCount.substr(4, 3) + ',' + tempJobCount.substr(7, 3);
            break;
        case 11:
            tempJobCount = tempJobCount.substr(0, 2) + ',' + tempJobCount.substr(2, 3) + ',' + tempJobCount.substr(5, 3) + ',' + tempJobCount.substr(8, 3);
            break;
        case 12:
            tempJobCount = tempJobCount.substr(0, 3) + ',' + tempJobCount.substr(3, 3) + ',' + tempJobCount.substr(6, 3) + ',' + tempJobCount.substr(9, 3);
            break;
    }

    var jobMessage = tempJobCount;

    document.getElementById(this.spanid).innerHTML = jobMessage;
}
