var title = document.title;
var num = "";
var lnum = "";
function fixtitle() {
    if (num.length) {
        if (title.length + num.length + 11 <= 95) {
            document.title = title + " [search: " + num + "]";
        } else {
            document.title = "[search: " + num + "] " + title;
        }
    } else {
        document.title = title;
    }
}
function getInnerText(o) {
    var s = "";
    var oo = o;
    while (true) {
        if (o.nodeType == 3) {
            var t = o.nodeValue.replace(/[\xa0\s]+/g, " ");
            if (t.match(/^ /) && s.match(/\s$/)) {
                s += t.substring(1);
            } else {
                s += t;
            }
        } else if (o.nodeType == 1) {
            var t = o.nodeName.toLowerCase();
            if (t == "br" || t == "p") {
                s = s.replace(/ $/, "") + " ";
            }
        }
        if (o.hasChildNodes()) {
            o = o.childNodes.item(0);
        } else if (o.nextSibling) {
            o = o.nextSibling;
        } else if (o == oo) {
            break;
        } else {
            while (true) {
                o = o.parentNode;
                if (!o || o == oo) {
                    break;
                }
                if (o.nextSibling) {
                    o = o.nextSibling;
                    break;
                }
            }
            if (!o || o == oo) {
                break;
            }
        }
    }
    return s;
}
function hot(c) {
    if (c == "/") {
        var a = document.getElementsByTagName("A");
        var ll = a.item(a.length - 1);
        if (getInnerText(ll).substring(0, 7) == "Return ") {
            var t = ll.href;
            location = t == "http://www.toucanet.com/" ? "/menu.html" : t;
        } else {
            location = "/";
        }
    } else {
        return true;
    }
    return false;
}
function k(e) {
    var key;
    if (document.all) {
        key = event.keyCode;
    } else {
        key = e.which;
        if (e.altKey || e.ctrlKey) {
            return true;
        }
    }
    var rv = true;
    var a = document.getElementsByTagName("A");
    var x = String.fromCharCode(key).toLowerCase();
    if (!hot(x)) {
        return false;
    }
    if (key == 8 && lnum.length > 0) {
        lnum = lnum.substring(0, lnum.length - 1);
    } else {
        lnum += x;
    }
    var z1 = -1, z2 = -1, z3 = -1;
    for (var i = a.length - 1; i >= 0; --i) {
        if (!a.item(i).myInnerText) {
            a.item(i).myInnerText = getInnerText(a.item(i));
        }
        var s = a.item(i).myInnerText.toLowerCase();
        if (lnum == s.substring(0, lnum.length)) {
            if (lnum.length == s.length) {
                z1 = i;
            }
            z2 = i;
        }
        if (x == s.charAt(0)) {
            z3 = i;
        }
    }
    if (z1 >= 0) {
        z3 = z1;
    } else if (z2 >= 0) {
        z3 = z2;
    } else if (z3 >= 0) {
        lnum = x;
    } else {
        lnum = "";
    }
    num = "";
    if (z3 >= 0) {
        a.item(z3).focus();
        num = a.item(z3).myInnerText.substring(0, lnum.length);
        rv = false;
    }
    fixtitle();
    return rv;
}
function f() {
    var a = document.getElementsByTagName("A");
    for (var i = a.length - 1; i >= 0; --i) {
        a.item(i).style.color = "blue";
    }
    document.title = title;
}
function g() {
    var a = document.getElementsByTagName("A");
    for (var i = a.length - 1; i >= 0; --i) {
        a.item(i).style.color = "";
    }
    fixtitle();
}
if (document.all) {
    window.onbeforeprint = f;
    window.onafterprint = g;
}
document.onkeypress = k;
