window.onload = function (ev) {
    init();
}

init = function () {
    getOrderInfo();
}

getOrderInfo = function () {
    var pid = getUrlParam("pid");
    var parameter = urlEncode(["SelectProduct",pid]);
    $.ajax({
        type: "post",
        url: "/malai/php/index.php",
        data: {mode: parameter},
        dataType: "json",
        success: function (data) {
            printOrderInfo(data);
        }
    });
}

printOrderInfo = function (data) {

    var input = $('input[type="text"]'),
        id,
        value = data[0][0],
        img = data[1];

    /*打印基本信息*/
    for (var i = 0; i < input.length; i++) {
        id = input.eq(i).attr("id");
        input.eq(i).attr("value", value[id]);
    }

    $("#ProductIntroduce").html(value.ProductIntroduce);


    /*打印颜色*/
    for(var i =0;i<data[1].length;i++){
        $("#Productcolor")[0].value +=data[1][i].ProductAttrbuteName+",";
    }

    /*打印预览图*/
    for (var i = 0; i < data[2].length; i++) {
        $(".filelist").append($('<li><p class="imgWrap"><img src="' + data[2][i].ProductAttrbuteName + '"></p></li>'));
    }
    $("#PageProductInfo").html(value.ProductInfo);
    $("#PageProductInfo").html(value.ProductInfo);
    $("#PageProductInfo #ProductInfo div").remove();


    $("#loading").css({"display": "none"});
    $(".form").css({"display": "block"});
}


getUrlParam = function (name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg);  //匹配目标参数
    if (r != null) return unescape(r[2]);
    return null; //返回参数值
}

urlEncode = function (arr) {
    var i; //循环初始化
    for (i = 0; i < arr.length; i++) {
        arr[i] = encodeURIComponent(encodeURIComponent(arr[i]));
    }
    return arr.join();
}

