function check()
{
    with (document.f)
    {
        var s       = elements["book"].value;
        var bRecord = 1;
        s = s.replace("请填写书名","");
        s = s.replace(/[\[\]\)'",\|\\\?\(\*&]/g,'');
        elements["book"].value = s;

        if (elements["book"].value == "")
        {
            document.getElementById("tips").innerHTML = "请输入书名并选择城市";
            elements["book"].focus();
            return false;
        }

        if (elements["lib"].value == "")
        {
            document.getElementById("tips").innerHTML = "请选择城市";
            return false;
        }

        var foundLatest = document.getElementById("latest").value.match("#" + s + "#");
        if (foundLatest != null)
        {
            bRecord = 0;
        }
        else
        {
            setTimeout("updatelatest()", 2000);
        }
        elements["record"].value = bRecord;
    }
    document.getElementById("tips").innerHTML = '';
    return true;
}

function g(key, s)
{
    with (document.f)
    {
        document.getElementById("lib").value = key;
        document.getElementById("city").value = s;
        if (check())
        {
            submit();
        }
    }
}

function setgrey()
{
    document.getElementById("book").className = "class_tip"; 
}

function cleartip(box)
{
    box.value = "";
    box.className = "class_book";
}

/*
 * fill book name with URL arguments 
 */
function loadname()
{
    var sbook = location.search.match("b=([^=]*)");
    if (sbook && sbook[1])
    {
        document.getElementById("book").value = decodeURI(sbook[1]);
        check();
        return true;
    }
    return false;
}

function loadevent()
{
    if (!loadname()) setgrey();
}

function updatelatest()
{
   document.getElementById("latestSearch").src = "/cgi-bin/latestspy.php"; 
}

window.onload = loadevent;
