﻿// JScript File
function AppendSearchForm() {
    if (document.getElementById("SearchForm") == null) {
        var oForm = document.createElement('form');
        oForm.id = 'SearchForm';
        var oFromBox = document.createElement('input');
        oFromBox.type = 'hidden';
        oFromBox.name = 'f';
        oFromBox.id = 'f';
        var oQueryBox = document.createElement('input');
        oQueryBox.type = 'hidden';
        oQueryBox.name = 'q';
        oQueryBox.id = 'q';
        oForm.appendChild(oFromBox);
        oForm.appendChild(oQueryBox);
        document.body.appendChild(oForm);
    }
}

function DoSearch(query, from, resultPageUrl, target, otherParaArray) {
    AppendSearchForm(); //searchForm = document.all["SearchForm"];//firefox 不能识别
    searchForm = document.getElementById("SearchForm");
    if (searchForm) {
        if (resultPageUrl) searchForm.action = resultPageUrl;
        if (target) searchForm.target = target;
        if (searchForm.q) {
            if (resultPageUrl.indexOf("q=") != -1) //处理wf_qk,wf_xw,wf_hy
            {
                searchForm.q.value = query + " " + resultPageUrl.substring(resultPageUrl.indexOf("q=") + 2, resultPageUrl.length);
            } else {
                searchForm.q.value = query;
            }
        }
        if (searchForm.f) searchForm.f.value = from; // 其他参数
        if (otherParaArray && otherParaArray.length > 0) {
            for (var i = 0; i < otherParaArray.length; i++) {
                if (otherParaArray[i] && otherParaArray[i].length >= 2) {
                    var oParmBox = document.createElement('input');
                    oParmBox.type = 'hidden';
                    oParmBox.name = otherParaArray[i][0];
                    oParmBox.value = otherParaArray[i][1];
                    searchForm.appendChild(oParmBox);
                }
            }
        }
        searchForm.submit();
    }
}