﻿// JScript 文件
var sxmlHttp;
var CandID;


//创建XMLHttpRequest()
function GetHttpRequest()
{
   var ajaxObject;
   try
   {
      request = new XMLHttpRequest();
   }
   catch (trymicrosoft)
   {
      try
      {
         request = new ActiveXObject("Msxml2.XMLHTTP");
      }
      catch (othermicrosoft)
      {
         try
         {
            request = new ActiveXObject("Microsoft.XMLHTTP");
         }
         catch (failed)
         {
            request = false;
         }
      }
   }
   return request;
}

function Search(candId,canditions)
{
    CandID=candId;
    sxmlHttp=sxmlHttp==null?GetHttpRequest():sxmlHttp;
    var url='Ajax/Search.ashx?Candition='+escape(canditions);
	sxmlHttp.open("GET",url,true);
	sxmlHttp.onreadystatechange=SearchCallBack;
    sxmlHttp.send(null);
}

function SearchCallBack()
{
     if(sxmlHttp.readyState==4)
	{   
		if(sxmlHttp.status==200)
		{ 
		  var response =sxmlHttp.responseText;
		  if(response=="")
		  {
		    document.getElementById(CandID).focus();
		    document.getElementById(CandID).select();
		    alert("没有搜索到任何商品!");
		  }
		  else
		  {
		    if(response=="SearchResults.aspx")
		    {
                response="SearchResults.aspx?tmp="+(new Date().getTime().toString(36));
            }
		    document.getElementById(CandID).focus();
		    document.getElementById(CandID).select();
		    window.open(response,"_self");
		  }
		}
	}
}
