public static JSWindow jWaitNewWindow(String name, int timeout) {
        int curr = 0;
        if (timeout == 0) timeout = 10000;
        while (curr < timeout) {
            if (JSBotUtils.lastCreatedWindow != null &&
                    JSBotUtils.lastCreatedWindow.cap.text != null &&
                    JSBotUtils.lastCreatedWindow.cap.text.equals(name)) {

                int rid = UI.instance.getId(JSBotUtils.lastCreatedWindow);
                if (!(UI.instance.getWidget(rid) instanceof Window)) continue;
                JSWindow ret = new JSWindow(rid);
                JSBotUtils.lastCreatedWindow = null;
                return ret;
            }
            if (!JSBot.Sleep(25)) return null;
            curr += 25;
        }
        return null;
    }