function getTimeoutAndCheckNextStepFunction(timeout, then, methodName, defaultTimeout, isThenRequired) {
    if (isThenRequired || then) {
        var isFunction = utils.isFunction(then); // Optimization to perform "isFunction" check only once.

        if (isThenRequired && !isFunction) {
            throw new CasperError(methodName + "() needs a step function");
        } else if (then && !isFunction) {
            throw new CasperError(methodName + "() next step definition must be a function");
        }
    }

    timeout = ~~timeout || ~~defaultTimeout;
    if (timeout < 0) {
        throw new CasperError(methodName + "() only accepts an integer >= 0 as a timeout value");
    }

    return timeout;
}
Helper functions needed in wait*() methods. Casts timeout argument to integer and checks if next step
function is really a function and if it has been given (if required - depending on isThenRequired flag).

@param   Number   timeout        The max amount of time to wait, in milliseconds
@param   Function then           Next step to process (optional or required, depending on isThenRequired flag)
@param   String   methodName     Name of the method, inside of which the helper has been called
@param   Number   defaultTimeout The default max amount of time to wait, in milliseconds (optional)
@param   Boolean  isThenRequired Determines if the next step function should be considered as required
@returns Number