﻿// JScript 文件

function searchB()
{
   
   var svalue=document.getElementById("textfield").value;
   if(svalue!="")
   {
       //window.location.href = "search.shtml?svalue=" + svalue;
       //window.location.href = window.location.protocol + "//" + window.location.host + "/" + window.location.pathname.split("/")[1] + "search.shtml?svalue=" + svalue;
       window.location.href = window.location.protocol + "//" + window.location.host + "/"  + "search.shtml?svalue=" + svalue;


   }
   else 
   {
       alert(' Pls enter product item No. or name.！');
        document.getElementById("textfield").focus();
        return false;
        
   }
    
}


function searchProduct()
{
    var obj=getArgs();//获取参数对象
    for(var j in obj)
    {
        var url = "ashxfiles/SearchProducts.ashx?svalue=" + escape(obj[j]) + "";
       send_request("POST", url, null, "text", searchProductBack);
    }
}

function searchProductBack()
{
 if (http_request.readyState == 4) {
        if (http_request.status == 200) {
            var param = http_request.responseText;
            document.getElementById("searchList").innerHTML=param;
        }
    }
}


function getArgs()
{
  var pars=location.search;//获取当前url
  var pos=pars.indexOf('?');//查找第一个?
  if(pos==-1)
  {
    alert('Empty parameter!');
    return;
  }
  else
   pars=pars.substring(pos+1);//获取参数部分
  var ps=pars.split("&");
  var args=new Object();
  var temp;
  var name,value,index;
  for(var i=0;i<ps.length;i++)
  {
    temp=ps[i]; 
    index=temp.indexOf("=");
    if(index==-1) continue;//如果参数中未包含=则继续
    name=temp.substring(0,index);//参数名称
    value=temp.substring(index+1);//参数的值
    args[name]=value;
  }
  return args;
}

