﻿function addselect(str,id,mtype) {
    var searchkey = "";
    //截取
    var kk = str.substring(0, str.length - 1);
    //分割
    var keys = kk.split(',');
    for (var i = 0; i < keys.length; i++) {
        var k = keys[i];
        searchkey += keys[i] + ":";
        var onekey = "";
        $("input:checkbox[id^=chk_"+k+"]").each(function() {
        if ($(this).attr("checked") == true) {
            onekey+= $(this).val() + ",";
           }
       });
       if (onekey == "") {
           onekey = "全部";
       }
       else {
           onekey = onekey.substring(0, onekey.length - 1);
       }
       searchkey += onekey+ "|";
   }
   searchkey = searchkey.substring(0, searchkey.length - 1);
   showProductList(id, searchkey,mtype);}



//随机数
var number = Math.random();


//XmlHttpRequest 对象
function GetHttpObject() {
    if (typeof XMLHttpRequest != "undefined") return new XMLHttpRequest();

    try {
        return new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
        try {
            return new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (e) { }
    }

    return false;
}


//ajax请求
function CreateCallback(url, calling, callback) {
    var http = GetHttpObject();
    http.open("GET", url, true);
    http.onreadystatechange = function() {
        //成功
        if (http.readyState == 1) {
            if (calling != undefined) {
                calling();
            }
        }
        if (http.readyState == 4) {
            if (callback != undefined) {
                if (http.responseText.length > 0) {
                    callback(http.responseText);
                }
            }
        }
    };
    http.send(null);
}

function showProductList(id, keys,mtype) {
    number++;
    CreateCallback("/webservice/ajaxproduct.aspx?id=" + id + "&keylist="+URLencode(keylist)+"&keys="+URLencode(keys)+"&mtype="+mtype+"&num="+number,showProductListCalling,showProductListCalled);
}

function showProductListCalling() {
    var html = "<DIV style=\"DISPLAY: block; width:677px;text-align:center;\" class=prCd>";
    html += "<img src=\"/picimages/loading.gif\"/>";
    html += "</DIV>";
    $("#productcontent").html(html);
}

function showProductListCalled(response) {
//document.write(response);
document.getElementById("productcontent").innerHTML=response;
   // $("#productcontent").html(response);
}


function URLencode(sStr) {  
  return escape(sStr).replace(/\+/g, '%2B').replace(/\"/g,'%22').replace(/\'/g, '%27').replace(/\//g,'%2F');
  }
