﻿function OLAjaxRequest() { var req = new Object(); req.timeout = null; req.generateUniqueUrl = true; req.url = window.location.href; req.method = "GET"; req.async = true; req.username = null; req.password = null; req.parameters = new Object(); req.requestIndex = OLAjaxRequest.numAjaxRequests++; req.responseReceived = false; req.groupName = null; req.queryString = ""; req.responseText = null; req.responseXML = null; req.status = null; req.statusText = null; req.aborted = false; req.xmlHttpRequest = null; req.onTimeout = null; req.onLoading = null; req.onLoaded = null; req.onInteractive = null; req.onComplete = null; req.onSuccess = null; req.onError = null; req.onGroupBegin = null; req.onGroupEnd = null; req.xmlHttpRequest = OLAjaxRequest.getXmlHttpRequest(); if (req.xmlHttpRequest == null) { return null; } req.xmlHttpRequest.onreadystatechange = function() { if (req == null || req.xmlHttpRequest == null) { return; } if (req.xmlHttpRequest.readyState == 1) { req.onLoadingInternal(req); } if (req.xmlHttpRequest.readyState == 2) { req.onLoadedInternal(req); } if (req.xmlHttpRequest.readyState == 3) { req.onInteractiveInternal(req); } if (req.xmlHttpRequest.readyState == 4) { req.onCompleteInternal(req); } }; req.onLoadingInternalHandled = false; req.onLoadedInternalHandled = false; req.onInteractiveInternalHandled = false; req.onCompleteInternalHandled = false; req.onLoadingInternal = function() { if (req.onLoadingInternalHandled) { return; } OLAjaxRequest.numActiveAjaxRequests++; if (OLAjaxRequest.numActiveAjaxRequests == 1 && typeof (window["AjaxRequestBegin"]) == "function") { AjaxRequestBegin(); } if (req.groupName != null) { if (typeof (OLAjaxRequest.numActiveAjaxGroupRequests[req.groupName]) == "undefined") { OLAjaxRequest.numActiveAjaxGroupRequests[req.groupName] = 0; } OLAjaxRequest.numActiveAjaxGroupRequests[req.groupName]++; if (OLAjaxRequest.numActiveAjaxGroupRequests[req.groupName] == 1 && typeof (req.onGroupBegin) == "function") { req.onGroupBegin(req.groupName); } } if (typeof (req.onLoading) == "function") { req.onLoading(req); } req.onLoadingInternalHandled = true; }; req.onLoadedInternal = function() { if (req.onLoadedInternalHandled) { return; } if (typeof (req.onLoaded) == "function") { req.onLoaded(req); } req.onLoadedInternalHandled = true; }; req.onInteractiveInternal = function() { if (req.onInteractiveInternalHandled) { return; } if (typeof (req.onInteractive) == "function") { req.onInteractive(req); } req.onInteractiveInternalHandled = true; }; req.onCompleteInternal = function() { if (req.onCompleteInternalHandled || req.aborted) { return; } req.onCompleteInternalHandled = true; OLAjaxRequest.numActiveAjaxRequests--; if (OLAjaxRequest.numActiveAjaxRequests == 0 && typeof (window["AjaxRequestEnd"]) == "function") { AjaxRequestEnd(req.groupName); } if (req.groupName != null) { OLAjaxRequest.numActiveAjaxGroupRequests[req.groupName]--; if (OLAjaxRequest.numActiveAjaxGroupRequests[req.groupName] == 0 && typeof (req.onGroupEnd) == "function") { req.onGroupEnd(req.groupName); } } req.responseReceived = true; req.status = req.xmlHttpRequest.status; req.statusText = req.xmlHttpRequest.statusText; req.responseText = req.xmlHttpRequest.responseText; req.responseXML = req.xmlHttpRequest.responseXML; if (typeof (req.onComplete) == "function") { req.onComplete(req); } if (req.xmlHttpRequest.status == 200 && typeof (req.onSuccess) == "function") { req.onSuccess(req); } else if (typeof (req.onError) == "function") { req.onError(req); } delete req.xmlHttpRequest["onreadystatechange"]; req.xmlHttpRequest = null; }; req.onTimeoutInternal = function() { if (req != null && req.xmlHttpRequest != null && !req.onCompleteInternalHandled) { req.aborted = true; req.xmlHttpRequest.abort(); OLAjaxRequest.numActiveAjaxRequests--; if (OLAjaxRequest.numActiveAjaxRequests == 0 && typeof (window["AjaxRequestEnd"]) == "function") { AjaxRequestEnd(req.groupName); } if (req.groupName != null) { OLAjaxRequest.numActiveAjaxGroupRequests[req.groupName]--; if (OLAjaxRequest.numActiveAjaxGroupRequests[req.groupName] == 0 && typeof (req.onGroupEnd) == "function") { req.onGroupEnd(req.groupName); } } if (typeof (req.onTimeout) == "function") { req.onTimeout(req); } delete req.xmlHttpRequest["onreadystatechange"]; req.xmlHttpRequest = null; } }; req.process = function() { if (req.xmlHttpRequest != null) { if (req.generateUniqueUrl && req.method == "GET") { req.parameters["AjaxRequestUniqueId"] = new Date().getTime() + "" + req.requestIndex; } var content = null; for (var i in req.parameters) { if (req.queryString.length > 0) { req.queryString += "&"; } req.queryString += encodeURIComponent(i) + "=" + encodeURIComponent(req.parameters[i]); } if (req.method == "GET") { if (req.queryString.length > 0) { req.url += ((req.url.indexOf("?") > -1) ? "&" : "?") + req.queryString; } } req.xmlHttpRequest.open(req.method, req.url, req.async, req.username, req.password); if (req.method == "POST") { if (typeof (req.xmlHttpRequest.setRequestHeader) != "undefined") { req.xmlHttpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); } content = req.queryString; } if (req.timeout > 0) { setTimeout(req.onTimeoutInternal, req.timeout); } req.xmlHttpRequest.send(content); } }; req.handleArguments = function(args) { for (var i in args) { if (typeof (req[i]) == "undefined") { req.parameters[i] = args[i]; } else { req[i] = args[i]; } } }; req.getAllResponseHeaders = function() { if (req.xmlHttpRequest != null) { if (req.responseReceived) { return req.xmlHttpRequest.getAllResponseHeaders(); } alert("Cannot getAllResponseHeaders because a response has not yet been received"); } }; req.getResponseHeader = function(headerName) { if (req.xmlHttpRequest != null) { if (req.responseReceived) { return req.xmlHttpRequest.getResponseHeader(headerName); } alert("Cannot getResponseHeader because a response has not yet been received"); } }; return req; } OLAjaxRequest.getXmlHttpRequest = function() { if (window.XMLHttpRequest) { return new XMLHttpRequest(); } else if (window.ActiveXObject) { try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { return null; } } } else { return null; } }; OLAjaxRequest.isActive = function() { return (OLAjaxRequest.numActiveAjaxRequests > 0); }; OLAjaxRequest.get = function(args) { OLAjaxRequest.doRequest("GET", args); }; OLAjaxRequest.post = function(args) { OLAjaxRequest.doRequest("POST", args); }; OLAjaxRequest.doRequest = function(method, args) { if (typeof (args) != "undefined" && args != null) { var myRequest = new OLAjaxRequest(); myRequest.method = method; myRequest.handleArguments(args); myRequest.process(); } }; OLAjaxRequest.submit = function(theform, args) { var myRequest = new OLAjaxRequest(); if (myRequest == null) { return false; } var serializedForm = OLAjaxRequest.serializeForm(theform); myRequest.method = theform.method.toUpperCase(); myRequest.url = theform.action; myRequest.handleArguments(args); myRequest.queryString = serializedForm; myRequest.process(); return true; }; OLAjaxRequest.serializeForm = function(theform) { var els = theform.elements; var len = els.length; var queryString = ""; this.addField = function(name, value) { if (queryString.length > 0) { queryString += "&"; } queryString += encodeURIComponent(name) + "=" + encodeURIComponent(value); }; for (var i = 0; i < len; i++) { var el = els[i]; if (!el.disabled) { switch (el.type) { case "text": case "password": case "hidden": case "textarea": this.addField(el.name, el.value); break; case "select-one": if (el.selectedIndex >= 0) { this.addField(el.name, el.options[el.selectedIndex].value); } break; case "select-multiple": for (var j = 0; j < el.options.length; j++) { if (el.options[j].selected) { this.addField(el.name, el.options[j].value); } } break; case "checkbox": case "radio": if (el.checked) { this.addField(el.name, el.value); } break; } } } return queryString; };
OLAjaxRequest.numActiveAjaxRequests = 0;
OLAjaxRequest.numActiveAjaxGroupRequests = new Object();
OLAjaxRequest.numAjaxRequests = 0;

//ajaxer应用
//根据购买记录推荐
function showAlsoBuy(shownum) {
    //alert("/app_ajax/AlsoBuy.ashx?cartid=" + getCartID() + "&shownum=" + shownum);
    OLAjaxRequest.get({
        "url": "/app_ajax/AlsoBuy.ashx?cartid=" + getCartID() + "&shownum=" + shownum,
        "onSuccess": function(res) {
            var str = eval('(' + res.responseText + ')');
            var len = str.Rows.length;
            var html = "";
            var fornum = "";
            if (len < shownum) {
                fornum = len;
            } else {
                fornum = shownum;
            }
            if (len > 0) {
                for (var i = 0; i < fornum; i++) {
                    if (i == 0) {
                        html += "<div class=\"andbuy\"><p>根据您挑选的商品，惟有爱为您推荐</p><ul>";
                    }
                    html += "<li>";
                    var propic = "";
                    if (str.Rows[i].picurl == null) {
                        propic = "nopic.gif";
                    } else {
                        propic = str.Rows[i].picurl;
                    }
                    html += "<a href=\"http://www.onlylove.hk/Shop/" + str.Rows[i].productid + ".html\" target=\"_blank\"><img src=\"http://img.onlylove.hk/" + propic + "\" width=160 height=120 /></a>";
                    html += "<div class=\"browse_price1\">原价:" + str.Rows[i].marketprice + "元</div><div class=\"browse_price2\">会员价:" + str.Rows[i].memberprice + "元</div>";
                    html += "<div class=\"browse_proname\">" + str.Rows[i].productname + "</div>";
                    html += "<a class=\"abuy\" href=\"http://www.onlylove.hk/Shop/" + str.Rows[i].productid + ".html\" target=\"_blank\">查看</a>";
                    html += "<a class=\"bbuy\" href=\"/Shop/Shopping.aspx?Action=AddToCart&ID=" + str.Rows[i].productid + "&Num=1\">购买</a>";
                    html += "</li>";
                }
            }
            html += "</ul></div>";
            //alert(html);
            $get("AlsoBuy").innerHTML = html;
        }
    });
}

//获取浏览过的商品列表
function showBrowsePro(shownum, deleteparam) {
    var temp = getOLCookie("ViewProductLog");
    //alert(temp);
    if (temp != null || temp != "" || typeof (temp) != "undefined") {
        //alert("/app_ajax/BrowsePro.ashx?proidlist=" + temp);
        OLAjaxRequest.get({
            "url": "/app_ajax/BrowsePro.ashx?proidlist=" + temp,
            "onSuccess": function(res) {
                var str = eval('(' + res.responseText + ')');
                var len = str.Rows.length;
                var html = "";
                var fornum = "";
                if (len < shownum) {
                    fornum = len;
                } else {
                    fornum = shownum;
                }
                if (len > 0) {
                    for (var i = 0; i < fornum; i++) {
                        html += "<li>"
                        var propic = "";
                        if (str.Rows[i].picurl == null) {
                            propic = "nopic.gif";
                        } else {
                            propic = str.Rows[i].picurl;
                        }
                        html += "<a href=\"http://www.onlylove.hk/Shop/" + str.Rows[i].productid + ".html\"><img src=\"http://img.onlylove.hk/" + propic + "\" border=0 /></a>";
                        html += "<div class=\"browseProname\">" + str.Rows[i].productname + "</div>";
                        html += "<div class=\"browsePrice1\">市场价：" + str.Rows[i].marketprice + "元</div><div class=\"browsePrice2\">会员价：" + str.Rows[i].memberprice + "元</div>";
                        html += "<a class=\"browseBuybtn\" href=\"/Shop/Shopping.aspx?Action=AddToCart&ID=" + str.Rows[i].productid + "&Num=1\">加入购物车</a>";
                        html += "</li>";
                    }
                    if (deleteparam == 1) {
                        html += "<a class=\"deleteCookie\" onclick=\"deleteCookie('ViewProductLog')\">清除浏览记录</a>";
                    }
                } else {
                    html += "<li class=\"clearView\">没有浏览过的商品！</li>";
                }
                $get("ProductLog").innerHTML = html;
            }
        });
    } else {
        $get("ProductLog").innerHTML = "没有浏览过的商品！";
    }
}
//获取订单支付方式
function getPaymentType(orderid) {
    //alert("/app_ajax/GetPaymentType.ashx?orderid=" + orderid);
    OLAjaxRequest.get({
        "url": "/app_ajax/GetPaymentType.ashx?orderid=" + orderid,
        "onSuccess": function(res) {
            var strPaymentType = res.responseText;
            if (strPaymentType == 1) {
                $get("olPaymentType").innerHTML = "* 请点击在线支付进入支付确认，如出现跳转错误请点击右上角“在线客服”联系我们，祝您购物愉快！";
            }
            else if (strPaymentType == 2) {
                $get("olPaymentType").innerHTML = "* 请点击“使用余额支付”进入会员中心使用会员帐号余额支付订单，祝您购物愉快！";
            }
            else if (strPaymentType == 3) {
                $get("olPaymentType").innerHTML = "* 请在转账后及时联系我们进行确认，祝您购物愉快！";
            }
            else if (strPaymentType == 4) {
                $get("olPaymentType").innerHTML = "* 请在汇款后及时将汇款存根以扫描件、照片或传真（0755-86358127）方式为凭证通知我们您已汇款，祝您购物愉快！";
            }
            else if (strPaymentType == 5) {
                $get("olPaymentType").innerHTML = "* 请您在收货时向送货员支付您的订单款项，祝您购物愉快！";
            }
            else if (strPaymentType == 6) {
                $get("olPaymentType").innerHTML = "* 填写汇单时候请正确填写惟有爱商汇号（6191123），汇款后请及时联系我们进行确认，祝您购物愉快！";
            }
        }
    });
}

//获取购物车商品列表内容
function showCart(groupid) {
    //alert("/app_ajax/ListCart.ashx?cartid=" + getCartID() + "&usergroup=" + groupid);
    OLAjaxRequest.get({
        "url": "/app_ajax/ListCart.ashx?cartid=" + getCartID() + "&usergroup=" + groupid,
        "onSuccess": function(res) {
            var str = eval('(' + res.responseText + ')');
            var len = str.Rows.length;
            var totalprice = 0;
            var totalquantity = 0;
            var html = "";
            if (len > 0) {
                html += "<div class=\"OLCartTop\"></div><div class=\"OLCartCenter\"><div class='CartContHead'><div class='CartProPicTitle'>商品图片</div><div class='CartProNameTitle'>商品名称</div><div class='CartProUnitTitle'>单位</div><div class='CartProNumTitle'>数量</div><div class='CartProPriceTitle'>实价</div><div class='CartProSumTitle'>金额</div><div class='CartBtnTitle'>操作</div></div>";
                for (var i = 0; i < len; i++) {
                    html += "<div class='CartContList'><div class='CartProPic'><a href=\"/Shop/" + str.Rows[i].productid + ".html\" target=\"_blank\"><img src='http:\/\/img.onlylove.hk\/" + str.Rows[i].picurl + "' width=88 height=66 border=0 /></a></div>";
                    html += "<div class='CartProName'><a href=\"/Shop/" + str.Rows[i].productid + ".html\" target=\"_blank\">" + str.Rows[i].productname;
                    if (str.Rows[i].property != "") {
                        html += str.Rows[i].productnum + str.Rows[i].property + "</a></div>";
                    } else {
                        str.Rows[i].property = "noproperty";
                        html += "</a></div>";
                    }
                    html += "<div class='CartProUnit'>" + str.Rows[i].unit + "</div>";
                    html += "<div class='CartProNum'><input type='text' id='input_" + str.Rows[i].productid + str.Rows[i].property + "' onclick='this.select()' value='" + str.Rows[i].quantity + "' /></div>";
                    html += "<div class='CartProPrice'>￥" + str.Rows[i].price + "</div>";
                    html += "<div class='CartProSum'>￥" + str.Rows[i].price * str.Rows[i].quantity + "</div>"
                    html += "<div class='CartBtn'><a href='#' class='CartBtnChange' onclick='changeCart(" + str.Rows[i].productid + ",\"" + str.Rows[i].property + "\");return false;'>修改</a><br /><a href='#' class='CartBtnDel' onclick='deleteCart(" + str.Rows[i].productid + ",\"" + str.Rows[i].property + "\");return false;'>删除</a></div></div>";
                }
                for (var j = 0; j < str.Rows.length; j++) {
                    totalprice = parseFloat(totalprice) + parseFloat(str.Rows[j].price * str.Rows[j].quantity);
                    totalquantity = parseInt(totalquantity) + parseInt(str.Rows[j].quantity);
                }
                html += "<div class='CartContBot'><a href=\"/Shop/Shopping.aspx\" class=\"CartPay\">去结算</a><div class='CartPriceTotalSum'>￥" + totalprice + "</div><div class='CartPriceTotalSumName'>合计：</div>";
                html += "<div class='CartUnitSum'>" + totalquantity + "</div><div class='CartUnitSumName'>合计：</div></div>";
                html += "</div><div class=\"OLCartBot\"></div>";
            } else {
                html = "<div class=\"OLCartTop\"></div><div class=\"OLCartCenter\"><div class='CartNothing'>您的购物车暂无商品，请选择惟有爱创意非凡的礼品。</div></div><div class=\"OLCartBot\"></div>";
            }
            //alert(html);
            $get("cart_cont").innerHTML = html;
        }
    });
}
//获取购物车商品总数量
function getCartTotalPro() {
    //alert("/app_ajax/CartTotalPro.ashx?cartid=" + getCartID() + "&usergroup=" + groupid);
    OLAjaxRequest.get({
        "url": "/app_ajax/CartTotalPro.ashx?cartid=" + getCartID(),
        "onSuccess": function(res) {
            var str = eval('(' + res.responseText + ')');
            var len = str.Rows.length;
            var totalquantity = 0;
            if (len > 0) {
                for (var i = 0; i < len; i++) {
                    totalquantity = parseInt(totalquantity) + parseInt(str.Rows[i].quantity);
                }
                $get("cart_total_pro").innerHTML = totalquantity;
            } else {
                $get("cart_total_pro").innerHTML = "0";
            }
        }
    });
}
//去结算
function gotoPay() {
    var str = $get("cart_total_pro").innerHTML;
    if (str == "0") {
        alert("很抱歉！当前您的购物车暂无商品可进行结算！\n\n请选择您喜欢的商品再进行结算，谢谢！");
    } else {
    window.open("/Shop/ShoppingCheckOut.aspx");
    }
}
//删除购物车商品
function deleteCart(productid, property) {
    if (confirm("确定要删除？") == true) {
        OLAjaxRequest.get({
            "url": "/app_ajax/DeleteCart.ashx?cartid=" + getCartID() + "&productid=" + productid + "&property=" + property,
            "onSuccess": function(res) {
                if (res.responseText == "1") {
                    getUserGroupID();
                    getCartTotalPro();
                }
            }
        });
    }
}
//修改购物车
function changeCart(productid, property) {
    OLAjaxRequest.get({
        "url": "/app_ajax/ChangeCart.ashx?cartid=" + getCartID() + "&productid=" + productid + "&num=" + $get("input_" + productid + property).value + "&property=" + property,
        "onSuccess": function(res) {
            if (res.responseText == "1") {
                getUserGroupID();
                getCartTotalPro();
            }
        }
    });
}
//获取购物车ID
function getCartID() {
    var sUrla = window.location.host;
    var sUrlb = "/";
    if (sUrlb == "/") {
        sUrlb = "/";
    } else {
        sUrlb = sUrlb.substring(0, sUrlb.length - 1);
    }
    var sUrlc = "Cart" + sUrla + sUrlb;
    var cartid = getCookies(sUrlc, "CartID");
    return cartid;
}
function getCookies(ck, name) {
    var cookieValue = "";
    var gt = "";
    var search = ck + "=";
    offset1 = document.cookie.indexOf(search);
    if (offset1 != -1) {
        offset1 += search.length;
        end1 = document.cookie.indexOf(";", offset1);
        if (end1 == -1) end1 = document.cookie.length;
        cookieValue = unescape(document.cookie.substring(offset1, end1))
        var search = name + "=";
        offset2 = cookieValue.indexOf(search);
        if (offset2 != -1) {
            offset2 += search.length;
            end2 = cookieValue.indexOf("&", offset2);
            if (end2 == -1) end2 = cookieValue.length;
            cookieValue = unescape(cookieValue.substring(offset2, end2));
        } else {
            cookieValue = "";
        }
    }
    return unescape(cookieValue);
}
//获取当前用户的用户组别
function getUserGroupID() {
    var groupid = -2;
    var x = new AjaxRequest('XML', '');
    x.labelname = "取得当前用户组ID";
    x.post('updatelabel', '/ajax.aspx', function(s) {
        var xml = x.createXmlDom(s);
        //alert(xml.getElementsByTagName("body")[0].firstChild.data);
        if (xml.getElementsByTagName("body")[0].firstChild != null) {
            if (xml.getElementsByTagName("body")[0].firstChild.data != '') {
                groupid = xml.getElementsByTagName("body")[0].firstChild.data;
                showCart(groupid);
            } else {
                showCart(groupid);
            }
        } else {
            showCart(groupid);
        }
    });
}
//获取浏览数
function getViewDegree(generalid, targetid) {
    OLAjaxRequest.get({
        "url": "/app_ajax/GetViewDegree.ashx?generalid=" + generalid,
        "onSuccess": function(res) {
            $get(targetid).innerHTML = res.responseText;
        }
    });
}
//获取最新顶次数
function Digg(ItemID) {
    var targetid = "digg_" + ItemID;
    OLAjaxRequest.get({
        "url": "/app_ajax/GetDiggOrDealDegree.ashx?type=1&itemid=" + ItemID,
        "onSuccess": function(res) {
            $get(targetid).innerHTML = res.responseText;
        }
    });
}
//获取最新踩次数
function Deal(ItemID) {
    var targetid = "deal_" + ItemID;
    OLAjaxRequest.get({
        "url": "/app_ajax/GetDiggOrDealDegree.ashx?type=2&itemid=" + ItemID,
        "onSuccess": function(res) {
            $get(targetid).innerHTML = res.responseText;
        }
    });
}
//获取促销品库存
function getPreStocks(presentid) {
    OLAjaxRequest.get({
        "url": "/app_ajax/ProPresentStocks.ashx?presentid=" + presentid,
        "onSuccess": function(res) {
            var stocks = new Array();
            stocks = res.responseText.split("|");
            $get("given").innerHTML = parseInt(stocks[1]);
            $get("give_stocks").innerHTML = stocks[0];
        }
    });
}
//获取商品库存
function getProStocks(proid) {
    OLAjaxRequest.get({
        "url": "/app_ajax/GetProStocks.ashx?proid=" + proid,
        "onSuccess": function(res) {
            var stocks = new Array();
            stocks = res.responseText.split("|");
            var intStocks = stocks[0] - stocks[1];
            if (intStocks > 0) {
                $get("proStocks").innerHTML = "<font color=\"green\">@现在有货</font>";
            } else {
                $get("proStocks").innerHTML = "<font color=\"red\">@现在缺货</font>";
            }
        }
    });
}
//获取商品代理价格
function getProPrice(proid) {
    var userGroupID = -2;
    var x = new AjaxRequest('XML', '');
    x.labelname = "取得当前用户组ID";
    x.post('updatelabel', '/ajax.aspx', function(s) {
        var xml = x.createXmlDom(s);
        if (xml.getElementsByTagName("body")[0].firstChild != null) {
            if (xml.getElementsByTagName("body")[0].firstChild.data != '') {
                userGroupID = xml.getElementsByTagName("body")[0].firstChild.data;
                OLAjaxRequest.get({
                    "url": "/app_ajax/GetProAgentPrice.ashx?proid=" + proid + "&usergroupid=" + userGroupID,
                    "onSuccess": function(res) {
                        var str = eval('(' + res.responseText + ')');
                        var memberPrice = 0;
                        var agentPrice = 0;
                        //会员价
                        (str.Pro[0].memberprice == 0) ? (memberPrice = (str.Pro[0].price * str.User[0].discount / 100)) : (memberPrice = str.Pro[0].memberprice);
                        //代理价
                        (str.Pro[0].agentprice == 0) ? (agentPrice = (str.Pro[0].price * str.User[0].discount / 100)) : (agentPrice = str.Pro[0].agentprice);
                        //游客
                        if (userGroupID == -2) {
                            $get("newPrice").innerHTML = "会员价：<span id=\"gPrice2\">" + str.Pro[0].price + "</span>&nbsp;元";
                        }
                        //代理商
                        else if (str.User[0].grouptype == 1) {
                            $get("newPrice").innerHTML = "会员价：<span id=\"gPrice2\">" + str.Pro[0].price + "</span>&nbsp;元";
                            $get("agentPrice").innerHTML = str.User[0].groupname + "价：" + agentPrice + "&nbsp;元";
                        }
                        //会员
                        else if (str.User[0].grouptype == 0) {
                            $get("newPrice").innerHTML = str.User[0].groupname + "：<span id=\"gPrice2\">" + memberPrice + "</span>&nbsp;元";
                        }
                    }
                });
            }
        }
    });
}
//获取商品套餐价格
function getGroupPrice(mProId, aProId) {
    var userGroupID = -2;
    var x = new AjaxRequest('XML', '');
    x.labelname = "取得当前用户组ID";
    x.post('updatelabel', '/ajax.aspx', function(s) {
        var xml = x.createXmlDom(s);
        if (xml.getElementsByTagName("body")[0].firstChild != null) {
            if (xml.getElementsByTagName("body")[0].firstChild.data != '') {
                userGroupID = xml.getElementsByTagName("body")[0].firstChild.data;
                OLAjaxRequest.get({
                    "url": "/app_ajax/GetProGroupPrice.ashx?mainproid=" + mProId + "&assitproid=" + aProId + "&usergroupid=" + userGroupID,
                    "onSuccess": function(res) {
                        var str = eval('(' + res.responseText + ')');
                        var vistorGroupPrice = str.Prices[0].price;
                        var memberGroupPrice = (str.Prices[0].memberprice = "0" ? str.Prices[0].price : str.Prices[0].memberprice);
                        var agentGroupPrice = (str.Prices[0].agentprice = "0" ? str.Prices[0].price : str.Prices[0].agentprice);
                        if (userGroupID == -2) {
                            $get("groupPrice").innerHTML = formatNumber(vistorGroupPrice, 2);
                        } else {
                            if (str.Prices[0].grouptype == 0) { $get("groupPrice").innerHTML = formatNumber(memberGroupPrice, 2); }
                            else { $get("groupPrice").innerHTML = formatNumber(agentGroupPrice, 2); }
                        }
                    }
                });
            }
        }
    });
}
//获取个性定制图片
function insertTailorPicName(orderID) {
    var picName = getOLCookie("OLCustomizationPicUrl");
    if (picName.indexOf("@1") != -1) {
        OLAjaxRequest.get({
            "url": "/app_ajax/InsertTailorPicName.ashx?picname=" + picName + "&orderid=" + orderID,
            "onSuccess": function(res) {
                var pid = getOLCookie("OLCustomizationPicUrl").replace("@1", "@0");
                setOLCookie("OLCustomizationPicUrl", pid, 30, "/Shop/", "", false);
                return;
            }
        });
    }
}

//获取推广商品销售量和会员价
function getProSaleStat(strType) {
    var idList1 = "1194,1228,449,1229,3191,410,506,2640,7055,10155,7185,956,1289,1263,1669,1710";
    var idList2 = "1228,315,2755,1194,1669,449,623,1346,959,3013,956,1263";
    var idList = "";
    if (strType != 0) {
        idList = strType == 1 ? idList1 : idList2;
    }
    if (strType != 0) {
        OLAjaxRequest.get({
            "url": "/app_ajax/GetProSaleStat.ashx?proidlist=" + idList,
            "onSuccess": function(res) {
                var str = eval('(' + res.responseText + ')');
                for (var i = 0; i < str.Rows.length; i++) {
                    $get("stat" + str.Rows[i].ProductID).innerHTML = "已售" + str.Rows[i].SumAmount + str.Rows[i].Unit;
                    $get("price" + str.Rows[i].ProductID).innerHTML = str.Rows[i].Price;
                }
            }
        });
    }
}


function CreateMD5() {
    var sVersion = document.getElementById("Version").value;
    var sAmount = document.getElementById("Amount").value;
    var sOrderNo = document.getElementById("OrderNo").value;
    var sMerchantNo = document.getElementById("MerchantNo").value;
    var sPayChannel = document.getElementById("PayChannel").value;
    var sPostBackUrl = document.getElementById("PostBackUrl").value;
    var sNotifyUrl = document.getElementById("NotifyUrl").value;
    var sOrderTime = document.getElementById("OrderTime").value;
    var sCurrencyType = document.getElementById("CurrencyType").value;
    var sNotifyUrlType = document.getElementById("NotifyUrlType").value;
    var sSignType = document.getElementById("SignType").value;
    var sRemark1 = document.getElementById("Remark1").value;

    var arrBankCode = document.getElementsByName("rdoBankCode");
    var sBankCode = "ICBC";
    for (var i = 0; i < arrBankCode.length; i++) {
        if (arrBankCode[i].checked == true) {
            sBankCode = arrBankCode[i].value;
            break;
        }
    }
    document.getElementById("BankCode").value = sBankCode;

    OLAjaxRequest.get({
        "url": "/App_Ajax/CreateMD5.ashx?Version=" + sVersion + "&Amount=" + sAmount + "&OrderNo=" + sOrderNo + "&MerchantNo=" + sMerchantNo + "&PayChannel=" + sPayChannel + "&PostBackUrl=" + sPostBackUrl + "&NotifyUrl=" + sNotifyUrl + "&OrderTime=" + sOrderTime + "&CurrencyType=" + sCurrencyType + "&NotifyUrlType=" + sNotifyUrlType + "&SignType=" + sSignType + "&BankCode=" + sBankCode + "&Remark1=" + sRemark1,
        "onSuccess": function (res) {
            document.getElementById("MAC").value = res.responseText;
            document.getElementById('submit').disabled = false;
        },
        "onError": function (res) {
            alert(res.responseText);
        }
    });
}


function getQueryStringRegExp(name) {
    var reg = new RegExp("(^|\\?|&)" + name + "=([^&]*)(\\s|&|$)", "i");
    if (reg.test(location.href))
        return unescape(RegExp.$2.replace(/\+/g, " "));
    else
        return "";
}

