﻿//所有搜索的方法

var offerlistmodel = "ProductId=productid&PlaceId=areaid&TimeRange=timerange";
//搜索供求列表
function SearchOfferArg(searchArgs) {
    this.productid = -1;
    this.areaid = -1;
    this.timerange = "AllTime";
    if (searchArgs != null) {
        this.productid = searchArgs[0];
        this.areaid = searchArgs[1];
        this.timerange = searchArgs[2];
    }
    this.GetSearch = function() {

        var result = offerlistmodel.replace("productid", this.productid);
        result = result.replace("areaid", document.getElementById("hid_place").value);
        result = result.replace("timerange", this.timerange);

        return result;
    }
}

function searchofferlist() {
   var argObject = new SearchOfferArg();
   
   argObject.productid = productid;

   argObject.areaid = document.getElementById("hid_place").value;
   
    var obj = document.getElementById("timerange");

    var index = obj.selectedIndex;

     argObject.timerange = obj.options[index].value;
       var search = argObject.GetSearch();
   
      window.location.target = "_blank";
      window.location.href = "/offer/list.aspx?" + search;
    
}



//查询产品列表
function SearchEnterPriseProductArg(searchArgs) {
    this.ProductId = -1;
    this.KeyWord;
    this.PlaceId;
    this.TimeRange = "AllTime";
    if (searchArgs != null) {
        this.ProductId = searchArgs[0];
        this.KeyWord = searchArgs[1];
        this.PlaceId = searchArgs[2];
        this.TimeRange = searchArgs[3];
    }
}

function SearchEnterPriseProductList() {

    
    var argObject = new SearchEnterPriseProductArg();
    
    var keystr = document.getElementById("txt_keyword").value;
    if (keystr != "") {
        argObject.KeyWord = keystr;
    }
    
    var hidstr=document.getElementById("hid_place").value;
    if(hidstr!="")
    {
        argObject.PlaceId = hidstr;
    }

    var obj = document.getElementById("seltimerange");
    var index = obj.selectedIndex;
    argObject.TimeRange = obj.options[index].value;
        
    var EnterPrise_drop = document.getElementById("Drop_EnterPriseList");
    var aindex = EnterPrise_drop.selectedIndex;
    if (aindex != -1) {
        argObject.ProductId = EnterPrise_drop.options[aindex].value;
    }
   
    Redirect("/product/List.aspx?", argObject);
}
 
 //查询企业列表
 function SearchEnterPriseArg(searchArgs) {
     this.PlaceId=-1;
     this.EnterPriseItemID = -1;
     this.YearRange = "AllYear";
     if (searchArgs != null) {
         this.PlaceId = searchArgs[0];
         this.ItemID = searchArgs[1];
         this.YearRange = searchArgs[2];
     }
 }
 
 function SearchEnterPriseList() {

     var argObject = new SearchEnterPriseArg();
    

     var hidstr = document.getElementById("hid_place").value;
     if (hidstr != "") {
         argObject.PlaceId = hidstr;
     }

     var obj = document.getElementById("yearrange");
     var index = obj.selectedIndex;
     argObject.YearRange = obj.options[index].value;

     var Item_drop = document.getElementById("EnterpriseTypeDDL1");
     var aindex = Item_drop.selectedIndex;
     if (aindex != -1) {
         argObject.EnterPriseItemID = Item_drop.options[aindex].value;
     }
     Redirect("/enterprise/list.aspx?", argObject);
 }

 //查询报价


 function SearchPriceArg(args) {
     this.PlaceId = 0;
     this.ProductId = 0;
     this.PriceProduct = "0";
     if (args != null) {
         this.PlaceId = args[0];
         this.ProductId = args[1];
         this.PriceProduct = args[2];
     }
    
     
 }

 function searchPrice(pid,pd) {
     var argObject = new SearchPriceArg();
     var hidstr = document.getElementById("hid_place").value;
     if (hidstr != "") {
         argObject.PlaceId = hidstr;
         argObject.ProductId = pid;
         argObject.PriceProduct = pd;
     }

     Redirect("/price/list.aspx?", argObject);
 }
 

 function Redirect(url, searcobject) {

     var search = asfman.dict.items(searcobject).join("&");
     
     while (search.indexOf(",") > 0) {
         search = search.replace(",", "=");
     }
     var jsurl = url + search;
   
     window.location.target = "_blank";
     window.location.href = jsurl;
//       window.open(jsurl);
 }
 
 //head search

 function SearchAll(args) {
     this.tablefrom = 0;
     this.KeyWord;
     if (args != null) {
         this.KeyWord = args;
     }
 }

 function searchAllPage(tablefrom, inputId) {
     
     var keys = escape(document.getElementById(inputId).value);
     var sa = new SearchAll();
     sa.tablefrom = tablefrom;
     sa.KeyWord = keys;
     Redirect("/search/?",sa);
 }
 
 var asfman = {};
 asfman.dict = {
     "keys": function(obj) {
         var b = [];
         for (var i in obj) {
             b.push(i);
         }
         return b;
     },
     "values": function(obj) {
         var b = [];
         for (var i in obj) {
             b.push(obj[i]);
         }
         return b;
     },
     "items": function(obj) {
         var b = [];
         for (var i in obj) {
             b.push([i, obj[i]]);
         }
         return b;
     }
 };



