﻿// JScript 文件
function search()
{
if(document.getElementById("input_search_text"))
    var search_text = document.getElementById("input_search_text").value;
    search_text=search_text.replace(/[\ |\~|\`|\!|\@|\#|\$|\%|\^|\&|\*|\(|\)|\-|\_|\+|\=|\||\\|\[|\]|\{|\}|\;|\:|\"|\'|\,|\<|\.|\>|\/|\?]/g,"");
    if(search_text == "" || search_text == "请输入关键字")
    {
        alert('请输入关键字');
        return false;
    }
    else
    {
    		var is_IE =("\v"=="v");
         if(document.getElementById("select_type_2").checked)
          {
          		
               location.href = "/buy/search-list.html?By=KeyWord&key="+search_text;
            
          }
          else
          {
            
               location.href = "/sell/search-list.html?By=KeyWord&key="+search_text;
            
          }  
       // Controls_Control_Head.GetEncodeText(search_text,GetEncodeText_callback)
//        Search_key=search_text;
//        search_Info();
        
    }
}

function GetEncodeText_callback(res)
{
    var search_type = document.getElementById("select_type");
    if(res)
    {
//        for(var i = 0;i<search_type.options.length;i++)
//        {
//            if(search_type.options[i].selected)
//            {
//                switch(search_type.options[i].text)
//                {
//                    case "找买家":
//                        location.href = "/buy/BuyRecordList.aspx?By=KeyWord&key="+res.value+"&page=1";
//                        break;
//                    case "找卖家":
//                        location.href = "/sell/SellRecordList.aspx?By=KeyWord&key="+res.value+"&page=1";
//                        break;
//                }
//            }
//        }
         
            
         if(document.getElementById("select_type_2").checked)
          {
               location.href = "/buy/search-0-"+escape(res.value)+"-list.html";
          }
          else
          {
               location.href = "/sell/search-0-"+escape(res.value)+"-list.html";
          }  
          
    }
}

function CleanText()
{
    if(document.getElementById("input_search_text").value=='请输入关键字')
    {
        document.getElementById("input_search_text").value = "";
    }
}

function txtkey_out()
{
	if(document.getElementById("input_search_text").value == "")
	{
		document.getElementById("input_search_text").value="请输入关键字";
	}
}


//new Ajax Search By wby at 2008-4-24
var is_Run=false;
var i=0;
var Search_key="";
var toPage="/buy/BuyRecordList.aspx";
var counts=0;
function msg_search_DivHid()
{
    document.getElementById("div_Msg_Search").style.display="none";
    document.getElementById("msg_Page_Search").style.display="none";
}

function search_MsgShow(msgString,sTime)
{
    document.getElementById("msg_Page_Search").style.width=document.documentElement.scrollWidth;
    document.getElementById("msg_Page_Search").style.height=document.documentElement.scrollHeight;     
    document.getElementById("msg_Page_Search").style.display="block";
                    
    document.getElementById("div_Msg_Search").style.display="block";		        
    document.getElementById("div_Msg_Search").innerHTML=msgString;
    if(sTime!=0)
    {
        window.setTimeout("msg_DivHid();",sTime);
    }
}

function search_Info()
{   
    var s_tp=1;
    var search_type = document.getElementById("select_type");
//    if(GetPageName().toLowerCase()=="sellrecordlist.aspx" || GetPageName().toLowerCase()=="sell_offer.aspx")
//    {
//        toPage="/sell/SellRecordList.aspx";
//        s_tp=2;
//    }

    if(search_type.options[1].selected)
    {
        toPage="/sell/SellRecordList.aspx";
        s_tp=2;
    }
    
    if(Search_key=="")
    {        
        location.href=toPage;
    }
    else
    {    
        if(is_Run)
        {   
            search_MsgShow("暂停搜索 <br><br><a href='JavaScript:is_Run=false;search();' style='color:Red;'>继续搜索</a> <a href='JavaScript:location.href=\""+toPage+"\";' style='color:Red;'>显示结果</a>",0);
        }
        else
        {   
                     
            i++;
            search_MsgShow("<img src='/img/mlImg.gif' /><br><br><a href=''JavaScript:is_Run=true;' style='color:Red;'>取消搜索</a>  <a href='JavaScript:location.href=\""+toPage+"\";' style='color:Red;'>显示结果</a>",0);                        
            var Cbo = new CallBackObject();
            Cbo.OnComplete = Cbo_Complete_Search;
            Cbo.OnError = Cbo_Error_Search;                                    
            
            Cbo.DoCallGet("/AjaxPage/SearchAjax.aspx?sKey="+escape(Search_key)+"&tp="+s_tp);
        }
    }
}

function Cbo_Complete_Search(responseText, responseXML)
{        
    var tmpArry=responseText.split("|");    
    msg_search_DivHid();
    
    if(tmpArry[1].toLowerCase()=="true")
    {
        is_Run=false;
        if(tmpArry[0]=="0")
        {
            //search_MsgShow("对不起,暂未搜索到 \""+Search_key+"\" 的相关信息,请您选择其他关键词再次搜索!<br><input type='button' value='确定' onclick='JavaScript:msg_search_DivHid();' />",5000);
            location.href=toPage+"?By=KeyWord&key="+escape(Search_key);
        }
        else
        {
            location.href=toPage+"?By=KeyWord&key="+escape(Search_key);
        }
    }
    else if(is_Run)
    {   
        counts=tmpArry[0];
        search_MsgShow("<img src='/img/mlImg.gif' /><br><br>暂停搜索  <br><a href='JavaScript:is_Run=false;search();' style='color:Red;'>继续搜索</a> <a href='JavaScript:location.href=\""+toPage+"\";' style='color:Red;'>显示结果</a>",0);
    }
    else
    {   
        counts=tmpArry[0];      
        search_MsgShow("<img src='/img/mlImg.gif' /><br><br><a href='JavaScript:is_Run=true;' style='color:Red;'>取消搜索</a> <a href='JavaScript:location.href=\""+toPage+"\";' style='color:Red;'>显示结果</a>",0);
        search_Info();
    }
}



//获得页面参数
function GetPagePrmValue(prm)
{
    var url = location.href.replace('http://','').replace('#','');
    url = url.split('/');
    var index = url[url.length-1].indexOf(prm);
    
    if(index>0)
    {
        var tmpStr=url[url.length-1];
        tmpStr=tmpStr.substring(index,tmpStr.length);
        var indexEnd=tmpStr.indexOf('&');
        
        if(indexEnd==-1)
        {
            return tmpStr.substring(prm.length+1);
        }
        else
        {                
            return tmpStr.substring(prm.length+1,tmpStr.length-tmpStr.substring(indexEnd).length);
        }
    }
    else
        return "";
}

function GetPageName()
{
    var url = location.href.replace('http://','').replace('#','');
    url = url.split('/');
    var index = url[url.length-1].indexOf('.');
    url = url[url.length-1].substring(0,index);
    return url+".aspx";
}

 function Cbo_Error_Search(status, statusText, responseText)
{
    location.href=toPage;//document.write(responseText);
}    

document.write('<div id="msg_Page_Search" style="display: none; position: absolute; height: 100%;');
document.write('width: 100%; left: 0px; top: 0px; background-color: #6B6B6B; filter: alpha(Opacity=20);"></div>');
document.write('<div id="div_Msg_Search" style="position: absolute; left:35%;  top:35%;  width:300px; height:200px;');
document.write('border: #000000 1px solid; background-color: White; text-align: justify; display: none;');
document.write('"><div align="center">操作中请稍后!</div></div>');