
function SearchBackValue()
{
    var pagename = location.pathname.toLowerCase();
    if(pagename.indexOf("companyprofile/")>0)
    {
        SetSerachValue('enter','公司库');
    }
    else if(pagename.indexOf("merchants/")>0)
    {
        SetSerachValue('merchants','招商');
    }
    else if(pagename.indexOf("merchantslist/")>0)
    {
        SetSerachValue('merchants','招商');
    }
    else if(pagename.indexOf("procurement/")>0)
    {
        SetSerachValue('procurement','求购');
    }
    else if(pagename.indexOf("procurementlist/")>0)
    {
        SetSerachValue('procurement','求购');
    }
    else if(pagename.indexOf("process/")>0)
    {
        SetSerachValue('process','加工');
    }
    else if(pagename.indexOf("processlist/")>0)
    {
        SetSerachValue('process','加工');
    }
    else if(pagename.indexOf("service/")>0)
    {
        SetSerachValue('service','服务');
    }
    else if(pagename.indexOf("servicelist/")>0)
    {
        SetSerachValue('service','服务');
    }
    else
    {
        SetSerachValue('product','供应');
    }
}

function SearchBankKey(val)
{
    var nowkey = document.getElementById("txtKeywords").value;
    if(nowkey == "请输入搜索关键字！" || nowkey == "")
    {
        document.getElementById("txtKeywords").value = val;
    }
}

function funcSearch(MGUID) 
{
    var type = window.document.getElementById("SearchSelectValue").value;
    var keywords = document.getElementById("txtKeywords").value;
    if (keywords == null || Trim(keywords) == "" || keywords == "请输入搜索关键字！") 
    {
        alert("请输入搜索关键字！");
        return false;
    }
    else if(type == "enter")
    {
        allSearch();
    }
    else
    {
        var url = "/"+MGUID+"/"+type+"/search.xhtml?keywords=" + escape(keywords);
        window.location.href = url;
    }
    
}

function SetSerachValue(val,text)
{
    window.document.getElementById("SearchSelectText").innerText = text;
    window.document.getElementById("SearchSelectValue").value = val;
    document.getElementById('SearchDivP2F').style.display='none';
}

function funcEnter() 
{
    if(event.keyCode == 13) 
    {
        funcSearch();
    }
}

function funcFocus(text) 
{
    if (text.value=="请输入搜索关键字！" || Trim(text.value)=="")
    {
        text.value="";
    }
}

function funconmouseup(obj)
{
    if (Trim(obj.value)=="")
    {
        obj.value="请输入搜索关键字！";
    }
}

function Trim(str)
{
    if(str.charAt(0) == " ")
    {
        str = str.slice(1);
        str = Trim(str);
    }
    return str;
}

function allSearch()
{
    var strKeywords  = window.document.getElementById("txtKeywords").value;
    var objTypeValue = window.document.getElementById("SearchSelectValue").value;
    var strUrl = "";
    
    if (strKeywords == null || Trim(strKeywords) == "" || strKeywords == "请输入搜索关键字！") 
    {
        alert("请输入搜索关键字！");
        return;
    }
    strKeywords = encodeURI(strKeywords);
    strKeywords = strKeywords.replace("%20","+");
        
    var arrArea = [""];
    switch(objTypeValue)
    {
        case "product":
        {
            strUrl = "http://sou.wjw.cn/gongying/_"+strKeywords+"____________.xhtml";
            break;
        }
        case "procurement":
        {
            strUrl = "http://sou.wjw.cn/qiugou/_"+strKeywords+"________.xhtml";
            break;
        }
        case "merchants":
        {
            strUrl = "http://sou.wjw.cn/zhaoshang/_"+strKeywords+"_________.xhtml";
            break;
        }
        case "process":
        {
            strUrl = "http://sou.wjw.cn/jiagong/_"+strKeywords+"________1__.xhtml";
            break;
        }
        case "service":
        {
            strUrl = "http://sou.wjw.cn/fuwu/_"+strKeywords+"_______1__.xhtml";
            break;
        }
        case "enter":
        {
            strUrl = "http://sou.wjw.cn/qiye/_"+strKeywords+"__________.xhtml";
            break;
        }

    }
    window.location.href = strUrl;
    
}
