﻿function search(baseUrl){
    var searchBox = document.getElementById("searchBox");
    var pattern = document.getElementById("pattern");
    var keyword = document.getElementById("keyword");
    var btn =document.getElementById("btnSearch");
    var queryID = document.getElementById("queryID");
    var btnQuery = document.getElementById("btnQuery");
    keyword.onfocus=function(){this.select();this.style.color="#000"}
    btn.onclick = function(){
        var p = pattern.selectedIndex;
        var q = keyword.value;
        if(q=="关键字"){q=""}else{q=escape(q);}
        if(q){window.location.href = baseUrl + "search.aspx?p="+p+"&q="+q;}else{alert("请输入关键字");keyword.focus(); return false;}
    };
    queryID.onfocus=function(){this.select();this.style.color="#000"}
    btnQuery.onmouseover=function(){this.style.color="#f00"}
    btnQuery.onmouseout=function(){this.style.color="#000"}
    btnQuery.onclick=function(){
        var q=queryID.value;
        if(q == "输入线路编号") q = "";
        if(!q){alert("请输入线路编号！");return false;}
        if(/^1\d{6}$/.test(q)){
            q = parseInt(q)-1000000;
            window.location.href=baseUrl + "tour/show/"+q+".htm";
        }else{
            alert("请输入正确的线路编号！");
            return false;
        }
    }
    this.setSearchBox = function()
    {
        var url = window.location.href.toString();
        var p = ""; var q = "";
        if(url.indexOf("search.aspx")>0)
        {
            p = url.match(/p\=\w+(?=\&)/i).toString().replace("p=","");
            if(!p) p = "0";
            q = url.match(/q\=.*/).toString().replace("q=","");
            q = unescape(q);
            q = q.replace("+"," ");
            pattern.selectedIndex = parseInt(p);
            keyword.value = q;
        }
    }
}
