/*
 Goosh.org (c) 2008 - Stefan Grothkopp

 This script is a google-interface that behaves similar to a unix-shell.

 goosh is written by Stefan Grothkopp (grothkopp (at) gmail (dot) com)
 it is NOT an official google product!

 If you want to extend goosh.org, please take a look at the load command.
 You can see an example module at http://goosh.org/ext/spon.js

 Uncompressed source of goosh.org will be published soon.
 If you have problems/bug reports/etc please write me an email.

*/
var input;
var output;
var promptel;
var user = "guest";
var host = "mexico.purplecow.org";
var mode = "web";
var pend = ">&nbsp;";
var cmdprompt = user + "@" + host + ":/" + mode + pend;
var start = 0;
var moreobj;
var lastcontext = false;
var lang = "de";
var urls = new Array();
var cmdlines = new Array();
var hist = new Array();
var histpos = 0;
var histtemp = 0;
Array.prototype.in_array = function(B) {
    var A;
    for (A = 0; A < this.length; A++) {
        if (this[A] == B) {
            return true
        }
    }
    return false
};
var languages = {
    arabic: "ar",
    bulgarian: "bg",
    catalan: "ca",
    chinese: "zh",
    chinese_simplified: "zh-cn",
    chinese_traditional: "zh-tw",
    croatian: "hr",
    czech: "cs",
    danish: "da",
    dutch: "nl",
    english: "en",
    estonian: "et",
    filipino: "tl",
    finnish: "fi",
    french: "fr",
    german: "de",
    greek: "el",
    hebrew: "iw",
    hindi: "hi",
    hungarian: "hu",
    indonesian: "id",
    italian: "it",
    japanese: "ja",
    korean: "ko",
    latvian: "lv",
    lithuanian: "lt",
    norwegian: "no",
    persian: "fa",
    polish: "pl",
    portuguese: "pt-pt",
    romanian: "ro",
    russian: "ru",
    serbian: "sr",
    slovak: "sk",
    slovenian: "sl",
    spanish: "es",
    swedish: "sv",
    thai: "th",
    turkish: "tr",
    ukrainian: "uk",
    vietnamese: "vi"
};
var langreverse = new Object();
for (key in languages) {
    langreverse[languages[key]] = key
}
var contexts = new Array();
var contextthreads = new Array();
function deletecontext(A) {
    output.innerHTML += "Error: Operation timed out.<br/>";
    if (!document.all) {
        output.innerHTML += '<span class="less">If you use the noscript firefox-extension, add "ajax.googleapis.com" to the whitelist.</span><br/>'
    }
    output.innerHTML += " <br/>";
    contexts[A] = false;
    var B = document.getElementById(A);
    if (B) {
        document.body.removeChild(B)
    }
    input.style.display = "block";
    focusinput();
    window.scrollBy(0, 122500);
    if (!document.all) {
        stop()
    }
}
function iscontext(A) {
    if (contexts[A]) {
        clearTimeout(contexts[A]);
        contexts[A] = false;
        var B = document.getElementById(A);
        if (B) {
            document.body.removeChild(B)
        }
        return true
    } else {
        return false
    }
}
function getcontext() {
    var B = new Date();
    var A = B.getTime();
    contexts[A] = setTimeout("deletecontext('" + A + "');", 4000);
    return A
}
function ajaxquery(A) {
    var B = getcontext();
    lastcontext = B;
    input.style.display = "none";
    var C = document.createElement("script");
    document.body.appendChild(C);
    C.src = A + "&context=" + B;
    C.id = B
}
var searchers = new Array();
function search_base() {
    this.mode = false;
    this.parameters = "";
    this.help = "no helptext yet.";
    this.helptext = "";
    this.hasmore = false
}
function register_searcher(name, base) {
    if (!base) {
        base = "base"
    }
    eval("search_" + name + ".prototype = new search_" + base + "();searchers_" + name + " = new search_" + name + '();searchers["' + name + '"] = searchers_' + name + ";")
}
function search_web() {
    this.name = "web";
    this.aliases = new Array("web", "search", "s", "w");
    this.mode = true;
    this.start = 0;
    this.args = "";
    this.parameters = "[keywords]";
    this.help = "google web search";
    this.helptext = "<span class='info'>examples:</span><br/><i>web foo bar</i>  - searches the web for &quot;foo bar&quot;<br/>";
    this.query = function(A, B) {
        ajaxquery("http://ajax.googleapis.com/ajax/services/search/" + A + "?v=1.0&start=" + this.start + "&hl=" + lang + "&callback=searchers_" + this.name + ".render&q=" + encodeURIComponent(B) + "&key=ABQIAAAA0cXSEVCNSwf_x74KTtPJMRQP4Q7D8MPck7bhT7upyfJTzVDU2BRxkUdd2AvzlDDF7DNUJI_Y4eB6Ug")
    };
    this.renderResult = function(E, D, G, C, H) {
        var B = "";
        var A = this.start;
        if (iscontext(E)) {
            if (D) {
                B += "<table border='0'>";
                for (i = 0; i < D.results.length; i++) {
                    var F = D.results[i];
                    A++;
                    urls[A] = F.unescapedUrl;
                    B += "<tr>";
                    B += "<td valign='top' class='less'>&nbsp;&nbsp;" + A + ")&nbsp;</td>";
                    B += "<td>";
                    B += "<a href='" + F.unescapedUrl + "' target='_blank' style='color:#bfb;'>" + F.title + "</a>";
                    B += "<br/>";
                    B += F.content;
                    B += "<br/>";
                    B += "<a href='" + F.unescapedUrl + "' target='_blank' style='color:#090; text-decoration:none;'>" + F.unescapedUrl + "</a>";
                    B += "<br/>";
                    if (F.thumb) {
                        B += "<a href='" + F.unescapedUrl + "' target='_blank'>" + F.thumb + "</a><br/>"
                    }
                    B += "&nbsp;</td></tr>"
                }
                output.innerHTML += B + "</table>"
            }
            input.style.display = "block";
            focusinput();
            window.scrollBy(0, 122500)
        }
    };
    this.call = function(A) {
        if (A.length > 0) {
            this.start = 0
        }
        this.args = A.join(" ");
        this.query(this.name, A.join(" "))
    };
    this.more = function() {
        if (this.args) {
            this.start += 4;
            this.query(this.name, this.args)
        }
    };
    this.render = function(C, B, D, A, E) {
        if (B && B.results != "") {
            this.hasmore = true
        } else {
            this.hasmore = false;
            moreobj = false
        }
        this.renderResult(C, B, D, A, E)
    }
}
register_searcher("web");
function search_lucky() {
    this.name = "lucky";
    this.aliases = new Array("lucky", "l");
    this.mode = false;
    this.parameters = "[keywords]";
    this.help = "go directly to first result";
    this.helptext = "<span class='info'>examples:</span><br/><i>lucky foo bar</i>  - goes to first &quot;foo bar&quot; result<br/>";
    this.call = function(A) {
        if (A.length > 0) {
            this.query("web", A.join(" "))
        }
    };
    this.render = function(C, B, D, A, E) {
        if (B.results[0].unescapedUrl) {
            document.location = B.results[0].unescapedUrl
        }
    }
}
register_searcher("lucky", "web");
function search_images() {
    this.name = "images";
    this.aliases = new Array("images", "image", "i");
    this.mode = true;
    this.help = "google image search";
    this.helptext = "<span class='info'>examples:</span><br/><i>images foo bar</i>  - searches for &quot;foo bar&quot; images<br/>";
    this.render = function(C, B, E, A, F) {
        if (B && B.results != "") {
            this.hasmore = true;
            for (i = 0; i < B.results.length; i++) {
                var D = B.results[i];
                B.results[i].thumb = "<img src='" + D.tbUrl + "'  width='" + D.tbWidth + "' height='" + D.tbHeight + "'/>"
            }
            this.renderResult(C, B, E, A, F)
        } else {
            this.hasmore = false;
            moreobj = false;
            this.renderResult(C)
        }
    }
}
register_searcher("images", "web");
function search_wiki() {
    this.name = "wiki";
    this.aliases = new Array("wikipedia", "wiki");
    this.mode = true;
    this.help = "wikipedia search";
    this.helptext = "<span class='info'>examples:</span><br/><i>wiki foo bar</i>  - searches &quot;foo bar&quot; in wikipedia<br/>";
    this.call = function(A) {
        this.start = 0;
        this.args = "site:" + lang + ".wikipedia.org " + A.join(" ");
        this.query("web", this.args)
    };
    this.more = function() {
        this.start += 4;
        if (this.args) {
            this.query("web", this.args)
        }
    };
    this.render = function(C, B, D, A, E) {
        if (B && B.results != "") {
            this.hasmore = true
        } else {
            this.hasmore = false;
            moreobj = false
        }
        this.renderResult(C, B, D, A, E)
    }
}
register_searcher("wiki", "web");
function search_clear() {
    this.name = "clear";
    this.aliases = new Array("clear", "c");
    this.help = "clear the screen";
    this.call = function(A) {
        output.innerHTML = ""
    }
}
register_searcher("clear");
function search_help() {
    this.name = "help";
    this.aliases = new Array("help", "man", "h", "?");
    this.help = "displays help text";
    this.helptext = "";
    this.parameters = "[command]";
    this.call = function(B) {
        var A = "<pre><span class='info'>help";
        if (B[0]) {
            A += ": " + B[0]
        }
        A += "</span><br/> <br/>";
        if (B[0] && !searchers[B[0]]) {
            output.innerHTML += A + "Error: command &quot;" + B[0] + "&quot; not found.</pre>";
            return false
        }
        A += "<table border='0' class='help'>";
        A += "<tr><td class='less'>command</td><td class='less'>aliases</td><td class='less'>parameters</td><td class='less'>function</td></tr>";
        var C;
        for (key in searchers) {
            if (key != "in_array" && (B.length == 0 || key == B[0])) {
                C = searchers[key];
                A += "<tr><td";
                if (C.mode) {
                    A += " class='info'"
                }
                A += ">";
                A += "" + C.name + "</td><td>";
                if (C.aliases.length > 1) {
                    A += "(";
                    for (i = 0; i < C.aliases.length; i++) {
                        if (C.aliases[i] != C.name) {
                            A += C.aliases[i];
                            A += ","
                        }
                    }
                    A = A.substr(0, A.length - 1);
                    A += ")"
                }
                A += "</td><td>";
                if (C.parameters) {
                    A += C.parameters
                }
                A += "</td><td>";
                A += "" + C.help + "\n";
                A += "</td></tr>"
            }
        }
        A += "</table></pre>";
        if (B[0]) {
            A += " <br/>";
            A += C.helptext;
            A += " <br/>"
        } else {
            A += "- Enter light green commands without parameters to change default mode.<br/>";
            A += "- Anything that's not a command will search in current default mode.<br/>";
            A += "- Aliases will expand to commands. Numbers will expand to corresponding search results.<br/>";
            A += "- Use cursor up and down for command history.<br/>";
            A += "- Enter keyword and hit the tab-key for tab-completion.<br/>";
            A += "<br/>"
        }
        output.innerHTML += A
    }
}
register_searcher("help");
function search_news() {
    this.name = "news";
    this.aliases = new Array("news", "n");
    this.mode = true;
    this.parameters = "[keywords]";
    this.help = "google news search";
    this.helptext = "<span class='info'>examples:</span><br/><i>blog foo bar</i>  - searches for &quot;foo bar&quot; news<br/>";
    this.render = function(C, B, D, A, E) {
        if (B && B.results != "") {
            this.hasmore = true;
            this.renderResult(C, B, D, A, E)
        } else {
            this.hasmore = false;
            moreobj = false;
            this.renderResult(C)
        }
    }
}
register_searcher("news", "web");
function search_blogs() {
    this.name = "blogs";
    this.aliases = new Array("blogs", "blog", "b");
    this.mode = true;
    this.parameters = "[keywords]";
    this.help = "google blog search";
    this.helptext = "<span class='info'>examples:</span><br/><i>blog foo bar</i>  - searches for &quot;foo bar&quot; blogs<br/>";
    this.render = function(C, B, E, A, F) {
        if (B && B.results != "") {
            this.hasmore = false;
            for (i = 0; i < B.results.length; i++) {
                var D = B.results[i];
                B.results[i].unescapedUrl = D.postUrl
            }
            this.renderResult(C, B, E, A, F)
        } else {
            this.hasmore = false;
            moreobj = false;
            this.renderResult(C)
        }
    }
}
register_searcher("blogs", "web");
function search_feeds() {
    this.name = "feeds";
    this.aliases = new Array("feeds", "feed", "f");
    this.mode = true;
    this.start = 0;
    this.args = "";
    this.parameters = "[keywords]";
    this.help = "google feed search";
    this.helptext = "<span class='info'>examples:</span><br/><i>feed foo bar</i>  - searches for &quot;foo bar&quot; feeds<br/><i>read 2</i>  - reads second result<br/>";
    this.query = function(A, B) {
        ajaxquery("http://ajax.googleapis.com/ajax/services/feed/find?v=1.0&hl=" + lang + "&callback=searchers_" + this.name + ".render&q=" + encodeURIComponent(B) + "&")
    };
    this.call = function(A) {
        if (A.length > 0) {
            this.start = 0
        }
        this.args = A.join(" ");
        this.query(this.name, A.join(" "))
    };
    this.render = function(C, B, E, A, F) {
        if (B) {
            B.results = new Array();
            for (i = 0; i < 4; i++) {
                if (B.entries[this.start + i]) {
                    B.results[i] = B.entries[this.start + i]
                }
            }
            if (B.results.length == 4) {
                this.hasmore = true
            } else {
                this.hasmore = false;
                moreobj = false
            }
            for (i = 0; i < B.results.length; i++) {
                if (B.results[i]) {
                    var D = B.results[i];
                    B.results[i].unescapedUrl = D.url;
                    B.results[i].content = D.contentSnippet
                }
            }
        }
        this.renderResult(C, B, E, A, F)
    };
    this.more = function() {
        this.start += 4;
        this.query(this.name, this.args)
    }
}
register_searcher("feeds", "web");
function search_open() {
    this.name = "open";
    this.aliases = new Array("open", "o");
    this.parameters = "&lt;url>";
    this.help = "open url in new window";
    this.helptext = "<span class='info'>examples:</span><br/><i>open 1 3</i>  - open first and third result from last search<br/>";
    this.call = function(B) {
        for (i = 0; i < B.length; i++) {
            var A = B[i];
            if (A.indexOf("http://") == -1 && A.indexOf("https://")) {
                A = "http://" + A
            }
            window.open(A, "_blank", "")
        }
    }
}
register_searcher("open");
function search_go() {
    this.name = "go";
    this.aliases = new Array("go", "g");
    this.parameters = "&lt;url>";
    this.help = "open url";
    this.call = function(B) {
        if (B[0]) {
            var A = B[0];
            if (A.indexOf("http://") == -1 && A.indexOf("https://")) {
                A = "http://" + A
            }
            document.location = A
        }
    }
}
register_searcher("go");
function search_more() {
    this.name = "more";
    this.aliases = new Array("more", "m");
    this.help = "get more results";
    this.call = function(A) {
        if (moreobj && moreobj.hasmore) {
            moreobj.more()
        }
    }
}
register_searcher("more");
function search_in() {
    this.name = "in";
    this.aliases = new Array("site", "in");
    this.parameters = "&lt;url> &lt;keywords>";
    this.help = "search in a specific website";
    this.mode = false;
    this.call = function(A) {
        this.start = 0;
        if (A.length > 1) {
            this.args = "site:" + A[0];
            for (i = 1; i < A.length; i++) {
                this.args += " " + A[i]
            }
            this.query("web", this.args)
        }
    };
    this.more = function() {
        this.start += 4;
        if (this.args) {
            this.query("web", this.args)
        }
    };
    this.render = function(C, B, D, A, E) {
        if (B && B.results != "") {
            this.hasmore = true
        } else {
            moreobj = false;
            this.hasmore = false
        }
        this.renderResult(C, B, D, A, E)
    }
}
register_searcher("in", "web");
function search_load() {
    this.name = "load";
    this.aliases = new Array("load");
    this.help = "load an extension";
    this.parameters = "&lt;extension_url>";
    this.call = function(B) {
        if (B[0]) {
            var A = B[0];
            if (A.indexOf("http://") == -1 && A.indexOf("https://")) {
                A = "http://goosh.org/ext/" + A + ".js"
            }
            var C = document.createElement("script");
            document.body.appendChild(C);
            C.src = A
        }
    }
}
register_searcher("load");
function search_video() {
    this.name = "video";
    this.aliases = new Array("videos", "video", "v");
    this.mode = true;
    this.parameters = "[keywords]";
    this.help = "google video search";
    this.helptext = "<span class='info'>examples:</span><br/><i>video foo bar</i>  - searches for &quot;foo bar&quot; videos<br/>";
    this.render = function(C, B, E, A, F) {
        if (B && B.results != "") {
            this.hasmore = true;
            for (i = 0; i < B.results.length; i++) {
                var D = B.results[i];
                B.results[i].thumb = "<img src='" + D.tbUrl + "' width='130' height='97' />";
                B.results[i].unescapedUrl = D.playUrl
            }
            this.renderResult(C, B, E, A, F)
        } else {
            this.hasmore = false;
            moreobj = false;
            this.renderResult(C)
        }
    }
}
register_searcher("video", "web");
function search_read() {
    this.name = "read";
    this.aliases = new Array("read", "rss", "r");
    this.mode = false;
    this.start = 0;
    this.parameters = "&lt;url>";
    this.help = "read feed of url";
    this.helptext = "<span class='info'>examples:</span><br/><i>read reddit.com</i>  - read reddit.com-feed<br/>";
    this.query = function(A, B) {
        ajaxquery("http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&hl=" + lang + "&callback=searchers_" + this.name + ".render&q=" + encodeURIComponent(B))
    };
    this.lookup = function(A, B) {
        ajaxquery("http://ajax.googleapis.com/ajax/services/feed/lookup?v=1.0&hl=" + lang + "&callback=searchers_" + this.name + ".lookupdone&q=" + encodeURIComponent(B))
    };
    this.lookupdone = function(C, B, D, A, E) {
        if (B) {
            if (B.url) {
                if (iscontext(C)) {
                    this.query(this.name, B.url)
                }
            }
        } else {
            output.innerHTML += "Error: feed &quot;" + this.args + "&quot; not found.<br/> Try the &quot;feed&quot;-command to find feeds .<br/> <br/>";
            this.renderResult(C)
        }
    };
    this.call = function(A) {
        if (A.length > 0) {
            this.start = 0;
            this.args = A.join(" ");
            this.lookup(this.name, A.join(" "))
        }
    };
    this.render = function(C, B, E, A, F) {
        if (B) {
            B.results = new Array();
            for (i = 0; i < 4; i++) {
                if (B.feed.entries[this.start + i]) {
                    B.results[i] = B.feed.entries[this.start + i]
                }
            }
            for (i = 0; i < B.results.length; i++) {
                if (B.results[i]) {
                    var D = B.results[i];
                    B.results[i].unescapedUrl = D.link;
                    B.results[i].content = D.contentSnippet
                }
            }
            this.renderResult(C, B, E, A, F)
        } else {
            output.innerHTML += "Error: feed &quot;" + this.args + "&quot; not found.<br/> Try the &quot;feed&quot;-command to find feeds.<br/> <br/>";
            this.renderResult(C)
        }
    };
    this.more = function() {}
}
register_searcher("read", "web");
function search_place() {
    this.name = "place";
    this.aliases = new Array("places", "place", "map", "p");
    this.mode = true;
    this.start = 0;
    this.args = "";
    this.parameters = "[address]";
    this.help = "google maps search";
    this.helptext = "<span class='info'>examples:</span><br/><i>place New York</i>  - show new york in a map<br/>";
    this.query = function(A, B) {
        ajaxquery("http://maps.google.com/maps/geo?q=" + encodeURIComponent(B) + "&output=json&callback=searchers_" + this.name + ".render&key=ABQIAAAA0cXSEVCNSwf_x74KTtPJMRQP4Q7D8MPck7bhT7upyfJTzVDU2BRxkUdd2AvzlDDF7DNUJI_Y4eB6Ug&lang=" + lang)
    };
    this.call = function(A) {
        if (A.length > 0) {
            this.start = 0
        }
        this.args = A.join(" ");
        this.query(this.name, A.join(" "))
    };
    this.render = function(B) {
        if (B && B.Placemark) {
            B.results = new Array();
            for (i = 0; i < 2; i++) {
                if (B.Placemark[i + this.start]) {
                    this.hasmore = true;
                    var C = B.Placemark[i + this.start];
                    var D = C.AddressDetails.Accuracy;
                    var A = 5;
                    if (D >= 4) {
                        A = 10
                    }
                    if (D >= 6) {
                        A = 14
                    }
                    B.results[i] = new Array();
                    B.results[i].title = C.address;
                    B.results[i].unescapedUrl = "http://maps.google.com/maps?f=q&hl=" + lang + "&q=" + encodeURIComponent(C.address) + "&center=" + C.Point.coordinates[1] + "," + C.Point.coordinates[0] + "&zoom=" + (A);
                    B.results[i].content = "";
                    B.results[i].thumb = "<img src='http://maps.google.com/staticmap?center=" + C.Point.coordinates[1] + "," + C.Point.coordinates[0] + "&zoom=" + (A) + "&size=400x250&maptype=roadmap&markers=" + C.Point.coordinates[1] + "," + C.Point.coordinates[0] + ",blue&key=ABQIAAAA0cXSEVCNSwf_x74KTtPJMRQP4Q7D8MPck7bhT7upyfJTzVDU2BRxkUdd2AvzlDDF7DNUJI_Y4eB6Ug' width='400' height='250'/>"
                } else {
                    moreobj = false;
                    this.hasmore = false
                }
            }
            this.renderResult(lastcontext, B)
        } else {
            output.innerHTML += "Error: Place &quot;" + this.args + "&quot; not found.<br/> <br/>";
            this.renderResult(lastcontext)
        }
        return true
    };
    this.more = function() {
        this.start += 2;
        this.query(this.name, this.args)
    }
}
register_searcher("place", "web");
function search_lang() {
    this.name = "lang";
    this.aliases = new Array("lang");
    this.parameters = "&lt;language>";
    this.help = "change language";
    this.helptext = "use the two-letter language codes used by google.<br/>";
    this.call = function(B) {
        if (B[0]) {
            if (languages[B[0]]) {
                B[0] = languages[B[0]]
            }
            if (langreverse[B[0]]) {
                var A = "http://goosh.org/?lang=" + B[0];
                document.location = A
            } else {
                output.innerHTML += "language &quot;" + B[0] + "&quot; not found.<br/> <br/>"
            }
        } else {
            output.innerHTML += "language is: " + langreverse[lang] + " (" + lang + ")<br/> <br/>"
        }
    }
}
register_searcher("lang");
function search_addengine() {
    this.name = "addengine";
    this.aliases = new Array("addengine");
    this.help = "add goosh to firefox search box";
    this.call = function(A) {
        engineURL = "http://goosh.org/goosh.xml";
        if (!document.all && window.external && ("AddSearchProvider" in window.external)) {
            window.external.AddSearchProvider(engineURL)
        } else {
            output.innerHTML += "addengine will only work in Firefox-Browsers.<br/> <br/>"
        }
    }
}
register_searcher("addengine");
function search_translate() {
    this.name = "translate";
    this.aliases = new Array("translate", "trans", "t");
    this.mode = true;
    this.args = "";
    this.parameters = "[lang1] [lang2] &lt;words>";
    this.help = "google translation";
    this.helptext = "<span class='info'>examples:</span><br/><i>translate en de What time is it?</i>  - translate &quot;What time is it?&quot; from english to german<br/><i>translate fr What time is it?</i>  - translate &quot;What time is it?&quot; to french<br/><i>translate Wie sp&auml;t ist es?</i>  - translates &quot;Wie sp&auml;t ist es?&quot; to your default language. language of text will be guessed.<br/>";
    this.query = function(B, A) {
        ajaxquery("http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=" + encodeURIComponent(this.text) + "&langpair=" + this.lang1 + "%7C" + this.lang2 + "&callback=searchers_" + this.name + ".render&key=ABQIAAAA0cXSEVCNSwf_x74KTtPJMRQP4Q7D8MPck7bhT7upyfJTzVDU2BRxkUdd2AvzlDDF7DNUJI_Y4eB6Ug")
    };
    this.guess = function(A) {
        ajaxquery("http://ajax.googleapis.com/ajax/services/language/detect?v=1.0&q=" + encodeURIComponent(A) + "&callback=searchers_" + this.name + ".guessresult&key=ABQIAAAA0cXSEVCNSwf_x74KTtPJMRQP4Q7D8MPck7bhT7upyfJTzVDU2BRxkUdd2AvzlDDF7DNUJI_Y4eB6Ug")
    };
    this.guessresult = function(C, B, D, A, E) {
        if (iscontext(C)) {
            if (B) {
                if (B.language) {
                    this.lang1 = B.language;
                    if (!this.lang2) {
                        this.lang2 = lang
                    }
                    this.query()
                } else {
                    outout.innerHTML += "ERROR: could not guess language.<br/> <br/>"
                }
            }
        }
    };
    this.renderResult = function(E, D, F, C, G) {
        var B = "";
        var A = this.start;
        if (iscontext(E)) {
            if (D) {
                if (D.translatedText) {
                    output.innerHTML += "translating &quot;" + this.text + "&quot; from &quot;" + langreverse[this.lang1] + "&quot; to &quot;" + langreverse[this.lang2] + "&quot;:<br/> <br/>";
                    output.innerHTML += "<span class='info'>&quot;" + D.translatedText + "&quot;</span><br/> <br/>"
                } else {
                    outout.innerHTML += "ERROR: no translation found.<br/> <br/>"
                }
            }
            input.style.display = "block";
            focusinput();
            window.scrollBy(0, 122500)
        }
    };
    this.call = function(A) {
        this.args = A;
        this.lang1 = false;
        this.lang2 = false;
        if (A.length > 2 && (languages[A[0]] || langreverse[A[0]]) && (languages[A[1]] || langreverse[A[1]])) {
            if (languages[A[0]]) {
                this.lang1 = languages[A[0]]
            } else {
                this.lang1 = A[0]
            }
            if (languages[A[1]]) {
                this.lang2 = languages[A[1]]
            } else {
                this.lang2 = A[1]
            }
            this.text = A[2];
            for (i = 3; i < A.length; i++) {
                this.text += " " + A[i]
            }
            this.query(this.name, A)
        } else {
            var B = "";
            if (languages[A[0]] || langreverse[A[0]]) {
                if (languages[A[0]]) {
                    this.lang2 = languages[A[0]]
                } else {
                    this.lang2 = A[0]
                }
                B = A[1];
                for (i = 2; i < A.length; i++) {
                    B += " " + A[i]
                }
            } else {
                B = A.join(" ")
            }
            this.text = B;
            this.guess(B)
        }
    };
    this.render = function(C, B, D, A, E) {
        this.renderResult(C, B, D, A, E)
    }
}
register_searcher("translate");
function search_ls() {
    this.name = "ls";
    this.aliases = new Array("ls");
    this.help = "lists commands";
    this.helptext = "this exists just for convenience. Use <span class='info'>help</span> for help.<br/>";
    this.parameters = "[command]";
    this.call = function(B) {
        var A = "";
        if (B[0] && !searchers[B[0]]) {
            output.innerHTML += A + "Error: command &quot;" + B[0] + "&quot; not found.</pre>";
            return false
        }
        A += "<table border='0' class='help'><tr>";
        var D;
        var C = 0;
        for (key in searchers) {
            if (key != "in_array" && (B.length == 0 || key == B[0])) {
                D = searchers[key];
                A += "<td";
                if (D.mode) {
                    A += " class='info'"
                }
                A += ">" + D.name + "</td><td>";
                if (C == 5) {
                    C = 0;
                    A += "</tr><tr>"
                }
                C++
            }
        }
        A += "</tr></table><br/>";
        output.innerHTML += A
    }
}
register_searcher("ls");
function search_cd() {
    this.name = "cd";
    this.aliases = new Array("cd");
    this.parameters = "&lt;mode>";
    this.help = "change mode";
    this.helptext = "This exists just for convenience. Use &lt;command> without parameters instead.<br/>";
    this.call = function(A) {
        if (!A[0]) {
            A[0] = mode
        }
        if (A[0] && A[0] == "..") {
            A[0] = "web"
        }
        if (A[0] && searchers[A[0]] && searchers[A[0]].mode) {
            var B = searchers[A[0]];
            mode = B.name;
            cmdprompt = user + "@" + host + ":/" + mode + pend;
            promptel.innerHTML = cmdprompt
        } else {
            output.innerHTML += "Error: mode not found. <br/> <br/>"
        }
    }
}
register_searcher("cd");
var suggestions = new Array();
var suggpos = 1;
var suggword = "";
function suggest(B) {
    if (suggpos > suggestions[B].length) {
        suggpos = 1
    }
    if (suggestions[B][suggpos]) {
        document.f.q.value = suggestions[B][suggpos]
    }
    var C = document.f.q;
    if (C.createTextRange) {
        var A = C.createTextRange();
        A.moveStart("character", B.length);
        A.select()
    } else {
        if (C.setSelectionRange) {
            C.setSelectionRange(B.length, C.value.length)
        }
    }
}
function dummyac() {
    this.Suggest_apply = function(C, D, A, B) {
        suggestions[D] = A;
        suggest(D);
        return true
    }
}
window.google = new Array();
window.google.ac = new dummyac();
function keyDownHandler(B) {
    if (!B && window.event) {
        B = window.event
    }
    if (B) {
        _lastKeyCode = B.keyCode
    }
    if (B && B.keyCode == 9) {
        B.cancelBubble = true;
        B.returnValue = false;
        var C = suggword;
        if (C != "") {
            if (!suggestions[C]) {
                suggpos = 1;
                var A = document.createElement("script");
                document.body.appendChild(A);
                A.src = "http://www.google.com/complete/search?hl=" + lang + "&js=true&qu=" + encodeURIComponent(C)
            } else {
                suggpos += 2;
                suggest(C)
            }
        }
        return false
    }
}
function mcursor(B) {
    var A = B.keyCode;
    if (hist.length > 0) {
        if (A == 38 || A == 40) {
            if (hist[histpos]) {
                hist[histpos] = document.f.q.value
            } else {
                histtemp = document.f.q.value
            }
        }
        if (A == 38) {
            histpos--;
            if (histpos < 0) {
                histpos = 0
            }
        } else {
            if (A == 40) {
                histpos++;
                if (histpos > hist.length) {
                    histpos = hist.length
                }
            }
        }
        if (A == 38 || A == 40) {
            if (hist[histpos]) {
                document.f.q.value = hist[histpos]
            } else {
                document.f.q.value = histtemp
            }
        }
    }
    if (A != 9 && A != 13) {
        suggword = document.f.q.value
    }
    if (A == 13) {
        command()
    }
}
function command() {
    var C = document.f.q.value;
    var F = C.split(" ");
    var B = new Array();
    for (i = 0; i < F.length; i++) {
        if (F[i] != "") {
            for (j = 0; j < 29; j++) {
                if ((F[i] == j) && (urls[j])) {
                    F[i] = urls[j];
                    if (i == 0) {
                        B.push("open")
                    }
                }
            }
            B.push(F[i])
        }
    }
    var E;
    for (key in searchers) {
        if (key != "in_array" && searchers[key].aliases.in_array(B[0])) {
            E = searchers[key];
            B[0] = E.name;
            break
        }
    }
    if (B.length == 0 && moreobj && moreobj.hasmore) {
        E = searchers.more;
        B[0] = "more"
    }
    var A = B.join(" ");
    output.innerHTML += "<div class='input'>" + cmdprompt + "<span class='inputb'>" + A + "</span></div>";
    if (A != "") {
        hist[hist.length] = A;
        histpos = hist.length
    }
    var D = "";
    if (!E) {
        E = searchers[mode]
    } else {
        for (i = 0; i < B.length - 1; i++) {
            B[i] = B[i + 1]
        }
        B.pop()
    }
    if (E.more && B.length > 0) {
        moreobj = E
    }
    if (B.length == 0 && E.mode) {
        mode = E.name;
        cmdprompt = user + "@" + host + ":/" + mode + pend;
        promptel.innerHTML = cmdprompt
    } else {
        E.call(B)
    }
    window.scrollBy(0, 500);
    document.f.q.value = "";
    focusinput();
    return false
}
function focusinput(A) {
    document.f.q.value = document.f.q.value;
    if (input.style.display != "none") {
        document.f.q.focus()
    }
}
function OnLoad() {
    input = document.getElementById("input");
    output = document.getElementById("output");
    promptel = document.getElementById("prompt");
    var B = document.getElementById("inputfield");
    var A = document.getElementById("body");
    promptel.innerHTML = cmdprompt;
    if (B.createTextRange) {
        B.onkeyup = new Function("return mcursor(event);");
        A.onfocus = new Function("return focusinput(event);");
        A.onclick = new Function("return focusinput(event);");
        A.onkeydown = new Function("return keyDownHandler(event);")
    } else {
        B.onkeyup = mcursor;
        A.onfocus = focusinput;
        A.onclick = focusinput;
        A.onkeydown = keyDownHandler
    }
    focusinput();
    if (document.f.q.value != "") {
        command()
    }
};

