﻿function checkJobStatus(timer) {
    com.realprosystems.web.stealth.JobService.FindJob(jobid,
                function(arg) { checkJobStatusCompleted(arg, timer); });
}

function checkJobStatusCompleted(arg, timer) {
    if (isJobFinished(arg.Payload)) {
        timer.stop();
        setRedirectLocation(arg.Payload);
        com.realprosystems.web.stealth.JobService.RemoveJob(arg.Payload.id);
        showRedirectingMessage();
    }
}

function isJobFinished(job) {
    try {
        return (job.status == 'Finished') || (job.status == 'Error');
    }
    catch (e) {
        return false;
    }
}

function setRedirectLocation(job) {
    if (job.responsetype == 'None' || job.response == '') {
        loc = 'http://' + window.location.hostname + '/ThankYou';
    }
    else {
        loc = job.response;
    }
}

function showRedirectingMessage() {
    $('#searching').find('p').hide();
    $('#searching').find('h3').show();
    setTimeout('window.location = loc;', 1000);
}