﻿/******************************************************************************
* filename: Common.js
* Ajax Modul Scripting
* (C) MasterLi(masterlijf#hotmail.com),Oran Day(likecode#qq.com)
* (C) NSW(http://www.nsw88.com)
*******************************************************************************/
/********************
* 初始化头部信息，如购物车产品总数，登录状态等
* 回应 : XML对象
********************/
function initCommonHeader() {
    $.get("/ajax.ashx?action=initcommonheader&t=" + Math.random(), function(rsp) {
        $j("headerCartCount").html(gav(rsp, "prod_count"));
        var kwds = gav(rsp, "kwd");
        //var IM = gav(rsp, "showIM");
        initHeaderKeywords(kwds);
        //showIM(IM);
        var username = gav(rsp, "username");
        if (username.length > 0) {
            $j("commonHeaderGuest").hide();
            $j("commonHeaderUsername").html(username);
            $j("commonHeaderUser").fadeIn(80);
        }
    });
}


//是否显示在线客服
function showIM(res) {
    if ($("#bodd").html() != "") {
        if (res == "True") {
            $("#bodd").show();
            $("#kefubtn").hide();
            $("#divOranIm").show();
        }
        else {
            $("#bodd").hide();
            $("#kefubtn").show();
            $("#divOranIm").hide();
        }
    }
}


//初始化头部热门关键字
function initHeaderKeywords(kwds) {
    var jCntr = $j("headerKwds");
    if (jCntr.length == 0) {
        return;
    }
    var sHtml = "";
    var arrKwd = kwds.split("||");
    for (var i = 0; i < arrKwd.length; ++i) {
        var kwdCrumb = arrKwd[i].split("$$");
        sHtml += "<a href='" + kwdCrumb[1] + "'>" + kwdCrumb[0] + "</a>";
    }
    jCntr.html(sHtml);
}
/********************
* 添加产品到购物车
* src : 触发事件的源对象
* _pid : 产品ID
* qutiElmId : 数量（重载：number购买数量、string数量的文本框元素ID）
* atts : 附加属性
* reloadCartPage : (可选)是否询问重新刷新购物车首页
* redirectUrl : (可选)当产品添加成功后，跳转到的页面（优先权高）
* 回应 : XML对象
********************/
function addToCart(src, _pid, qutiElmId, _atts, reloadCartPage, redirectUrl) {
    showProc(src);
    if (reloadCartPage == null) {
        reloadCartPage = false;
    }
    _atts = $j(_atts).html();
    var _quti;
    if (qutiElmId == null) {
        _quti = 1;
    } else if (typeof (qutiElmId) == "number") {
        _quti = qutiElmId;
    } else {
        _quti = $tv(qutiElmId);
    }
    $.post("/ajax.ashx?action=addtocart&t=" + Math.random(), {
        pid: _pid,
        quti: _quti,
        atts: _atts
    }, function(msg) {
        var sMsg = gav(msg, "msg");
        var sCount = gav(msg, "count");
        var sta = gav(msg, "state");
        if (redirectUrl != null) {
            location.href = redirectUrl;
            return;
        }
        if (sta != "1") {
            $a(sMsg);
            showProc(src, false);
            return;
        }
        $confirm(sMsg, { title: "Go to settlement", toDo: "/paycenter/cart.aspx" }, { title: "To make another purchase", toDo: function() {
            hideConfirm();
        }
        });
        $j("headerCartCount").html(sCount);
        if (reloadCartPage && (gav(msg, "state") == 1) && confirm("Add to cart successfully, but is immediately refresh the page shopping cart page?\r\n\r\nYes - refresh the page to view the latest results\r\nNo - to retain the current page status")) {
            location.href = "cart.aspx?t=" + Math.random();
            return;
        }
        showProc(src, false);
    });
}
/********************
* 清空购物车
* src : 触发事件的源对象
* 回应 : string
*       1 - 成功
*       0 - 失败
********************/
function emptyCart(src) {
    showBgProc();
    $.get("/ajax.ashx?action=emptycart&t=" + Math.random(), function(msg) {
        if (msg == "1") {
            $a("Empty shopping cart successful, click to confirm return to production center.", 1, false, null, "Msg", function() {
                location.href = "/product";
            });
        } else {
        $a("Empty shopping cart fails, please try again later.");
        }
        showBgProc(false);
    });
}
/********************
* 清空购物车
* src : 触发事件的源对象
* _pid : 产品ID
* 回应 : xml
********************/
function changeQuantity(src, _pid) {
    var newVal = $(src).parent().find("input").attr("value");
    if (!/^\d+$/.test(newVal)) {
        $a("Number must be an integer.");
        return;
    }
    if (parseInt(newVal) == 0) {
        $a("Quantity must be greater than 0, to delete products, please point of operation of the 'Delete'.");
        return;
    }
    showBgProc();
    $.post("/ajax.ashx?action=addtocart&t=" + Math.random(), {
        pid: _pid,
        quti: newVal
    }, function(msg) {
        if (gav(msg, "state") == "1") {
            if (confirm("The number of changes successfully, but is immediately refresh the page to view the results of shopping cart？\n\nYes - refresh the page view results\nNo - to retain the current page status")) {
                location.href = "cart.aspx?t=" + Math.random();
            } else {
                showBgProc(false);
                $(src).hide();
            }
        } else {
            $a(msg);
            showBgProc(false);
        }
    });
}
function delCartProduct(src, _pid, _atts) {
    showBgProc();
    var _quti = 0;
    $.post("/ajax.ashx?action=addtocart&t=" + Math.random(), {
        pid: _pid,
        atts: _atts
    }, function(msg) {
        if (gav(msg, "state") == "1") {
            if (confirm("Goods have been removed, it immediately refresh the page view the results?\n\n\r\nYes - refresh the page view results\nNo - to retain the current page status")) {
                location.href = "cart.aspx?t=" + Math.random();
            }
        } else {
            $a(gav(msg, "msg"));
        }
        showBgProc(false);
    });
}

function cancelOrder(src, _orderNo) {
    showBgProc();
    $.post("/ajax.ashx?action=cancelorder&t=" + Math.random(), {
        no: _orderNo
    }, function(msg) {
        if (gav(msg, "state") == "1") {
            $(src).parent().parent().parent().find("td[name=orderstate]").html("Canceled");
            $(src).hide();
        } else {
        $a("<p>Cancel the order operation failed.</p><p>Non 'Pending' status, has been locked so orders can not be canceled.</p>");
        }
        showBgProc(false);
    });
}
function delFavColumn(src, _oid) {
    showBgProc();
    $.post("/ajax.ashx?action=delfavfolumn&t=" + Math.random(), {
        oid: _oid
    }, function(msg) {
        if (gav(msg, "state") == "1") {
            $(src).parent().parent().fadeOut(80).remove();
        } else {
        $a("Operation failed, please try again later.");
        }
        showBgProc(false);
    });
}
function delMyWish(src, itemTabId) {
    var _ids = getCheckedVal(itemTabId);
    if (_ids.length == 0) {
        $a("No selected items.");
        return;
    }
    showBgProc();
    $.post("/ajax.ashx?action=delMyWishs&t=" + Math.random(), {
        ids: _ids
    }, function(msg) {
        if (gav(msg, "state") == "1") {
            var chks = $j(itemTabId).find("input[name=item]:checked");
            chks.each(function(i) {
                $(this).parent().parent().remove();
            });
        } else {
            $a(gav(msg, "msg"));
        }
        showBgProc(false);
    });
}
function addFav(src, _title, _url, _cat_id) {
    if (_url == null) {
        _url = location.pathname;
    }
    if (_title == null) {
        _title = document.title;
    }
    $.post("/ajax.ashx?action=fav&t=" + Math.random(), {
        url: _url,
        ptitle: _title,
        column_id: _cat_id
    }, function(msg) {
        var sta = gav(msg, "state");
        var sMsg = gav(msg, "msg");
        if (sta == "1") {
            closeTopLayer('div_fav_cntr');
        } else {
            top.$a(sMsg, "2");
            closeTopLayer('div_fav_cntr');
        }
    });
}
function delFav(src, itemTabId) {
    var _ids = getCheckedVal(itemTabId);
    if (_ids.length == 0) {
        $a("No selected items.");
        return;
    }
    showBgProc();
    $.post("/ajax.ashx?action=delfav&t=" + Math.random(), {
        ids: _ids
    }, function(msg) {
        if (gav(msg, "state") == "1") {
            var chks = $j(itemTabId).find("input[name=item]:checked");
            chks.each(function(i) {
                $(this).parent().parent().remove();
            });
        } else {
            $a(gav(msg, "msg"));
        }
        showBgProc(false);
    });
}
function hits(_oid, _mark) {
    $.post("/ajax.ashx?action=hits&t=" + Math.random(), {
        oid: _oid,
        mark: _mark
    })
}
function postComment(src, _oid, _mark) {
    showProc(src);
    var _content = $tv("txtCmtContent");
    var _verCode = $tv("txtCmtVerCode");
    if (_content == "") {
        $a("The content required.");
        showProc(src, false);
        return;
    }
    if ($g("txtVerCode") != null && s_verCode == "") {
        $a("Code can not be empty.");
        showProc(src, false);
        return;
    }
    $.post("/ajax.ashx?action=postcomment&t=" + Math.random(), {
        content: _content,
        oid: _oid,
        verCode: _verCode,
        mark: _mark
    }, function(msg) {
        var sta = gav(msg, "state");
        var sMsg = gav(msg, "msg");
        if (sta == "") {
            $a(msg, -1);
        } else if (sta == "2") {
            $a(sMsg, 1);
            emptyText('tbCmt');
        } else if (sta == "1") {
            var sTime = gav(msg, "time");
            var sUsername = gav(msg, "username");
            var sIp = gav(msg, "ip");
            var sComment = gav(msg, "comment");

            var htmlFmt = "<dl>"
						+ "<dd>{$username$}<span class='ip'>IP：{$ip$}</span>Time：{$time$}</dd>"
						+ "<dd class='con'>{$content$}</dd>"
					+ "</dl>";
            var sHtml = htmlFmt
                .replace("{$username$}", sUsername)
                .replace("{$ip$}", sIp)
                .replace("{$time$}", sTime)
                .replace("{$content$}", sComment);
            $j("divComments").html(sHtml + $j("divComments").html());
            if ($j("spCommentCount").html() == "0") {
                $j("spCommentCount").html("1");
                $j("comment_no").remove();
            }
            $a(sMsg, 1);
            emptyText('tbCmt')

        } else {
            $a(sMsg);
        }
        showProc(src, false);
    });
}
function writeComment(_oid, _mark) {
    $.post("/ajax.ashx?action=getcomment&t=" + Math.random(), {
        oid: _oid,
        mark: _mark
    }, function(msg) {
        var iCount = $(msg).find("count").text();
        $j("spCommentCount").html(iCount);
        var commtns = $(msg).find("comment");
        var sHtml = "";
        var htmlFmt = "<dl>"
						+ "<dd>{$username$}<span class='ip'>IP：{$ip$}</span>Time：{$time$}</dd>"
						+ "<dd class='c666 con mt8 mb10'>{$content$}</dd>"
						+ "<dd class='huifu'><h5>Administrator Reply：</h5><div>{$feedback$}</div></dd>"
					+ "</dl>";
        for (var i = 0; i < commtns.length; ++i) {
            var jCmt = $(commtns[i]);
            var sUsername = jCmt.find("username").text();
            var sContent = jCmt.find("content").text();
            var sIp = jCmt.find("ip").text();
            var sTime = jCmt.find("inputTime").text();
            var sfeedback = jCmt.find("feedback").text();
            sHtml += htmlFmt
                .replace("{$username$}", sUsername)
                .replace("{$ip$}", sIp)
                .replace("{$time$}", sTime)
                .replace("{$content$}", sContent)
                 .replace("{$feedback$}", sfeedback);
        }
        if (sHtml.length > 0) {
            $j("divComments").html(sHtml);
        } else {
        $j("divComments").html("No comment");
        }
    });
}
function addHistory(_oid, _mark) {
    $.get("/ajax.ashx?action=addhistory&t=" + Math.random(), {
        oid: _oid,
        mark: _mark
    })
}
function getAd(_keyname, cntrElmId) {
    $.post("/ajax.ashx?action=getadd", {
        keyname: _keyname
    }, function(msg) {
        $j(cntrElmId).html(msg);
    })
}
function getVideo(_videoKey) {
    $.post("/ajax.ashx?action=getvideo", {
        videoKey: _videoKey
    }, function(msg) {
        var jDiv = $j("divVideo");
        if (msg.length == 0) {
            jDiv.slideUp(80);
        } else {
            jDiv.html(msg);
            $(".prod_attrs").toggleClass("prod_attrs").toggleClass("prod_attrs_b");
        }
    })
}
function getOrderAnns() {
    $.get("/ajax.ashx?action=getorderanns", function(msg) {
        $j("divOrderAnns").html(msg);
    });
}
function getEndingRemark() {
    $.get("/ajax.ashx?action=getendingremark", function(msg) {
        $j("divEndingRemark").html(msg);
    });
}
function getHistory(_mark) {
    $.post("/ajax.ashx?action=gethistory&t=" + Math.random(), {
        mark: _mark
    }, function(msg) {
        if (msg.length == 0) {
            msg = "<li>无浏览历史</li>";
        }
        $j("divHistoryCntr").html(msg);
    });
}
function getHits(_oid, _mark) {
    $.post("/ajax.ashx?action=gethits", {
        mark: _mark,
        oid: _oid
    }, function(msg) {
        $j("cntrHits").html(msg);
    });
}
function getHelpStatic(_oid) {
    $.post("/ajax.ashx?action=helpsatisfaction&t=" + Math.random(), {
        oid: _oid
    }, function(msg) {
        var arrI = [parseInt(gav(msg, "1")), parseInt(gav(msg, "2")), parseInt(gav(msg, "3"))];
        var total = arrI[0] + arrI[1] + arrI[2];
        if (total == 0) {
            total = 1;
        }
        var maxHeight = 100;
        for (var i = 0; i < arrI.length; ++i) {
            var percent = (arrI[i] / total).toFixed(2);
            var h = maxHeight * percent;
            if (h == 0) {
                h = 1;
            }
            var sHtml = "<div class='static_graph' style='height:" + h + "px;'></div><div class='static_w'>"
                    + (percent * 100).toFixed(2) + "%</div>";
            $j("cntrStatic_" + i).html(sHtml);
        }
    });
}
function submitHelpUse(src, _oid) {
    showProc(src);
    var _notice = $("input[name=use]:checked").val();
    $.post("/ajax.ashx?action=helpuseful&t=" + Math.random(), {
        oid: _oid,
        notion: _notice
    }, function(msg) {
        if (gav(msg, "state") == "0") {
            $a(gav(msg, "msg"));
        } else {
            $a(gav(msg, "msg"), 1);
            getHelpStatic(_oid);
        }
        showProc(src, false);
    });
}
function getSimilarArticle(_sid) {
    $.post("/ajax.ashx?action=getsmilararticle&t=" + Math.random(), {
        sid: _sid
    }, function(msg) {
        $j("cntrSimilarArticle").html(msg);
    });
}
function getLastArticle() {
    $.post("/ajax.ashx?action=getlastarticle", function(msg) {
        $j("cntrLastArticle").html(msg);
    });
}
function cleanHistory(_mark, key) {
    $.post("/ajax.ashx?action=cleanhistory", {
        mark: _mark
    }, function(msg) {
        $j("divHistoryCntr").html("<h4 class=\"t05\"><a class=\"clr\" onclick=\"cleanHistory('product','__oran__product_history')\" href=\"javascript:void(0)\">清除</a>最近浏览过的产品</h4><div id=\"divHistoryItems\" class=\"t05_con\">无浏览历史<div class=\"clear\"/></div>");
    });
}
function subscription(src, elmId) {
    if (elmId == null) {
        elmId = "txtSubscriptionEmail";
    }
    var _email = $.trim($j(elmId).val());
    var ptn = /\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
    if (_email.length == 0) {
        $a("E-Mail NO Null");
        $j(elmId).focus();
        return false;
    }
    if (!ptn.test(_email)) {
        $a("E-Mail Err。");
        $j(elmId).focus();
        return false;
    }
    showProc(src);
    $.post("/ajax.ashx?action=subscription&t=" + Math.random(), {
        email: _email
    }, function(msg) {
        var sta = gav(msg, "state");
        var sMsg = gav(msg, "msg");
        if (sta == "1") {
            $a(sMsg, 1);
        } else {
            $a(sMsg);
        }
        showProc(src, false);
    });
}
function userFeedback(src) {
    var _title = $tv("txtFdTitle");
    var _shortDesc = $tv("txtFdShortDesc");
    if (_title.length == 0 || _shortDesc.length == 0) {
        $a("The content or title can not be empty.")
        return false;
    }

    showBgProc(true, "Is being submitted to ...");
    $.post("/ajax.ashx?action=userfeedback&t=" + Math.random(), {
        title: _title,
        shortDesc: _shortDesc
    }, function(msg) {
        var sta = gav(msg, "state");
        var sMsg = gav(msg, "msg");
        if (sta == "1") {
            showMsgPage("<li>Your views to the success, thank you for your comments, with your support, we will do better.</li>", 1, "/user/faq.aspx", "Comments / Feedback", "/user/faq.aspx");
            return;
        } else if (sMsg.length > 0) {
            $a(sMsg);
        } else {
            $a(msg);
        }
        showBgProc(false);
    });
}
function checkAuthority(_authIDs, _title) {
    $.post("/ajax.ashx?action=checkauthority&t=" + Math.random(), {
        authIDs: _authIDs
    }, function(msg) {
        if (msg == "1") {
            $j("div___________Perm").hide();
            document.oncontextmenu = function() { return true; }
            document.onselectstart = function() { return true; }
        } else {
        showMsgPage("You do not have a view " + _title + " Permissions。");
            return;
        }
    });
}
function changeFavColumn(src, itemTabId) {
    var _ids = getCheckedVal(itemTabId);
    if (_ids.length == 0) {
        $a("No selected items.");
        return;
    }
    showProc(src);
    $.post("/ajax.ashx?action=changefavcolumn&t=" + Math.random(), {
        ids: _ids,
        targetId: src.value
    }, function(msg) {
        var sta = gav(msg, "state");
        var sMsg = gav(msg, "msg");
        if (sta == "1") {
            location.reload();
        } else {
            //alert(sMsg);
        }
    });
    showProc(src, false);
}
function getRecommentProductByHistory(_oid) {
    $.post("/ajax.ashx?action=GetRecommentProductByHistory&t=" + Math.random(), {
        oid: _oid
    }, function(msg) {
        var jO = $j("divHistoryRecommentCntr");
        if (msg.length == 0) {
            jO.remove();
        } else {
            jO.html(msg);
        }
    });
}
function getRelevantSales(_oid) {
    $.post("/ajax.ashx?action=GetRelevantSales&t=" + Math.random(), {
        oid: _oid
    }, function(msg) {
        var jO = $j("divRelevantSalesCntr");
        if (msg.length == 0) {
            jO.remove();
        } else {
            jO.html(msg);
        }
    });
}
function getRelevantViewed(_oid) {
    $.post("/ajax.ashx?action=GetRelevantViewed&t=" + Math.random(), {
        oid: _oid
    }, function(msg) {
        var jO = $j("divRelevantViewedCntr");
        if (msg.length == 0) {
            jO.remove();
        } else {
            jO.html(msg);
        }
    });
}

function delInitationlog(src, itemTabId) {
    var _ids = getCheckedVal(itemTabId);
    if (_ids.length == 0) {
        $a("无选中项。");
        return;
    }
    showBgProc();
    $.post("/ajax.ashx?action=DelInitationlog&t=" + Math.random(), {
        ids: _ids
    }, function(msg) {
        if (gav(msg, "state") == "1") {
            var chks = $j(itemTabId).find("input[name=item]:checked");
            chks.each(function(i) {
                $(this).parent().parent().remove();
            });
        } else {
            $a(gav(msg, "msg"));
        }
        showBgProc(false);
    });
}
function sendInvitation(src) {
    var jSrc = $j(src);
    var sEmail = $j("txtEmail").val();
    if (sEmail == null || sEmail.length == 0) {
        $a("E-mail address can not be empty.");
        return;
    }
    if (!PTN_EMAIL.test(sEmail)) {
        $a("E-mail address format is incorrect.");
        return;
    }
    showProc(src);
    $.post("/ajax.ashx?action=SendInvitation&t=" + Math.random(), {
        _email: sEmail
    }, function(msg) {
        var sta = gav(msg, "state");
        var sMsg = gav(msg, "msg");
        if (sta == "1") {
            showMsgPage(sMsg, 1, "/user/InviteUserList.aspx", "Invitation List", "/user/InviteUserList.aspx");
        } else {
            $a(sMsg);
            showProc(src, false);
        }
    });
}
//填充报告分类
function fillReportCategories() {
    $.get("/ajax.ashx?action=GetReportCategories&t=" + Math.random(), function(msg) {
        var arrCat = msg.split("$$");
        var sOptHtml = "<option value=\"\">Please select ...</option>";
        for (var i = 0; i < arrCat.length; ++i) {
            sOptHtml += "<option value=\"" + arrCat[i] + "\">" + arrCat[i] + "</option>";
        }
        $j("RPT_tdCats").html("<select id=\"RPT_cats\">" + sOptHtml + "</select>");
    });
}
//填充留言分类
function fillLeavewordCategories() {
    $.get("/ajax.ashx?action=GetLeavewordCategories&t=" + Math.random(), function(msg) {
        var arrCat = msg.split("$$");
        var sOptHtml = "<option value=\"\">Please select ...</option>";
        for (var i = 0; i < arrCat.length; ++i) {
            sOptHtml += "<option value=\"" + arrCat[i] + "\">" + arrCat[i] + "</option>";
        }
        $j("LEAVEWORD_tdCats").html("<select id=\"LEAVEWORD_cats\">" + sOptHtml + "</select>");
    });
}
//发送留言
function sendLeaveword(src) {
    var sCat = $j("LEAVEWORD_cats").val();
    var sTitle = $v("LEAVEWORD_txtTitle");
    var sTel = $v("LEAVEWORD_txtTel");
    var sMobile = $v("LEAVEWORD_txtMobile");
    var sContact = $v("LEAVEWORD_txtContact");
    var sEmail = $v("LEAVEWORD_txtEmail");
    var sShortDesc = $v("LEAVEWORD_txtShortDesc");
    var err = "";
    if (sTitle == "") {
        err += "<li>The title can not be empty</li>";
    }
    if (sContact == "") {
        err += "<li>Contacts can not be empty</li>";
    }
    if (sEmail == "") {
        err += "<li>E-mail address can not be empty</li>";
    }
    else if (!PTN_EMAIL.test(sEmail)) {
    err += "<li>E-mail address format error</li>";
    }
    if (sCat == "") {
        err += "<li>Message Type Required</li>";
    }
    if (err.length > 0) {
        $a(err);
        return;
    }
    showProc(src);
    $.post("/ajax.ashx?action=SendLeaveword&t=" + Math.random(), {
        title: sTitle,
        cat: sCat,
        contact: sContact,
        email: sEmail,
        shortDesc: sShortDesc,
        tel: sTel,
        mobile: sMobile

    }, function(msg) {
        var sta = gav(msg, "state");
        var sMsg = gav(msg, "msg");
        if (sta == "1") {
            $a(sMsg, 1);
        } else {
            $a(sMsg);
        }
        showProc(src, false);
    });
}
//发送报告
function sendReprots(src) {
    var sCat = $j("RPT_cats").val();
    var sTitle = document.title;
    var sUrl = document.URL;
    var sContact = $v("RPT_txtContact");
    var sEmail = $v("RPT_txtEmail");
    var sShortDesc = $v("RPT_txtShortDesc");
    if (sCat.length == 0) {
        $a("Please select the report category。");
        return;
    }
    showProc(src);
    $.post("/ajax.ashx?action=SendReports&t=" + Math.random(), {
        title: sTitle,
        url: sUrl,
        cat: sCat,
        contact: sContact,
        email: sEmail,
        shortDesc: sShortDesc

    }, function(msg) {
        var sta = gav(msg, "state");
        var sMsg = gav(msg, "msg");
        if (sta == "1") {
            $a(sMsg, 1);
        } else {
            $a(sMsg);
        }
        showProc(src, false);
    });
}
//提交直接付款
function directPay(src) {
    var sPayer = $v("DIR_PAY_txtPayer");
    var sEmail = $v("DIR_PAY_txtEmail");
    var sTel = $v("DIR_PAY_txtTel");
    var sMobile = $v("DIR_PAY_txtMobile");
    var sSalesMan = $v("DIR_PAY_txtSalesManName");
    var sMoney = $v("DIR_PAY_txtMoney");
    var sUse = $v("DIR_PAY_txtUse");
    var sPayment = $v("DIR_PAY_ddlPayment");
    var err = "";
    if (sPayer.length == 0) {
        err += "<li>Payer can not be empty.</li>"
    }
    if (sEmail == "") {
        err += "<li>E-mail address can not be empty</li>";
    }
    else if (!PTN_EMAIL.test(sEmail)) {
    err += "<li>E-mail address format error</li>";
    }
    if (sMoney.length == 0) {
        err += "<li>The payment amount can not be empty.</li>"
    }
    else if (!PTN_FLOAT.test(sMoney)) {
    err += "<li>Payment amount must be a number, such as 89.00.</li>"
    }
    if (sUse.length == 0) {
        err += "<li>Use the money can not be empty.</li>"
    }
    if (sPayment.length == 0) {
        err += "<li>Please select payment method.</li>"
    }
    if (err.length > 0) {
        $a(err);
        return;
    }
    showProc(src);
    $.post("/ajax.ashx?action=DirectPay&t=" + Math.random(), {
        payer: sPayer,
        email: sEmail,
        tel: sTel,
        mobile: sMobile,
        salesMan: sSalesMan,
        _money: sMoney,
        _use: sUse,
        payment: sPayment

    }, function(msg) {
        var sta = gav(msg, "state");
        var sMsg = gav(msg, "msg");
        if (sta == "1") {
            location.href = "/Paycenter/PayDirectConfirm.aspx";
            return;
        } else {
            $a(sMsg);
        }
        showProc(src, false);
    });
}
function submitOrder(src, _oid) {
    showProc(src);
    var _contact = $j("txtContact").val();
    var _compName = $j("txtCompName").val();
    var _tel = $j("txtTel").val();
    var _mobile = $j("txtMobile").val();
    var _email = $j("txtEmail").val();
    var _addr = $j("txtAddr").val();
    var _content = $j("txtContent").val();
    var errorMsg = "";
    if (_contact.length == 0) {
        errorMsg += "<p>Contacts can not be empty</p>";
    }
    if (_mobile.length == 0) {
        errorMsg += "<p>Phone can not be empty</p>";
    }
    if (_content.length == 0) {
        errorMsg += "<p>Describe the intent to purchase non-empty</p>";
    }
    if (errorMsg.length > 0) {
        $a(errorMsg);
        showProc(src, false);
        return;
    }
    $.post("/ajax.ashx?action=submitorder&t=" + Math.random(), {
        oid: _oid,
        contact: _contact,
        compName: _compName,
        tel: _tel,
        mobile: _mobile,
        email: _email,
        addr: _addr,
        content: _content
    }, function(msg) {
        var sta = gav(msg, "state");
        var sMsg = gav(msg, "msg");
        if (sta == "1") {
            $a(sMsg, 1);
            emptyText('tbForm1');
        } else {
            $a(msg);
            emptyText('tbForm1');
        }
    });
    showProc(src, false);
}
/********************************************* 代理加盟:start *********************************/
function getAgentHelpStatic(_oid) {
    $.post("/ajax.ashx?action=agenthelpsatisfaction&t=" + Math.random(), {
        oid: _oid
    }, function(msg) {
        var arrI = [parseInt(gav(msg, "1")), parseInt(gav(msg, "2")), parseInt(gav(msg, "3"))];
        var total = arrI[0] + arrI[1] + arrI[2];
        if (total == 0) {
            total = 1;
        }
        var maxHeight = 100;
        for (var i = 0; i < arrI.length; ++i) {
            var percent = (arrI[i] / total).toFixed(2);
            var h = maxHeight * percent;
            if (h == 0) {
                h = 1;
            }
            var sHtml = "<div class='static_graph' style='height:" + h + "px;'></div><div class='static_w'>"
                    + (percent * 100).toFixed(2) + "%</div>";
            $j("cntrStatic_" + i).html(sHtml);
        }
    });
}
function submitAgentHelpUse(src, _oid) {
    showProc(src);
    var _notice = $("input[name=use]:checked").val();
    $.post("/ajax.ashx?action=agenthelpuseful&t=" + Math.random(), {
        oid: _oid,
        notion: _notice
    }, function(msg) {
        if (gav(msg, "state") == "0") {
            $a(gav(msg, "msg"));
        } else {
            $a(gav(msg, "msg"), 1);
            getAgentHelpStatic(_oid);
        }
        showProc(src, false);
    });
}
/********************************************* 代理加盟:end *********************************/
/*显示产品的简介（一排四个的显示模式）*/
function showProductInfo(src, _oid, _index) {
    var time1 = null;
    var time2 = null;
    var ID = null;
    var time = null;

    //鼠标移到图片上的事件
    $(src).hover(function() { time1 = new Date(); showTime(); }, function() { window.clearInterval(ID); });

    //js定时器
    function showTime() {
        ID = window.setInterval(function() {
            time2 = new Date();
            time = time2 - time1;

            //时间差，停留200毫秒时触发ajax请求
            if (time > 400) {
                if ($(src).parent().parent().next().attr("class") == "mesbook4" || $(src).parent().parent().next().attr("class") == "mesbook40") {
                    if ($(src).parent().parent().next().is(":visible")) {
                        return;
                    }
                    else {
                        $(src).parent().parent().next().show();
                    }
                }
                else {
                    $.post("/ajax.ashx?action=showProductInfo&t=" + Math.random(), {
                        oid: _oid,
                        index: _index
                    }, function(msg) {
                        if ($(src).parent().parent().next().attr("class") == "mesbook4" || $(src).parent().parent().next().attr("class") == "mesbook40") {
                            return;
                        }
                        else {
                            $(src).parent().parent().after(msg);
                            return;
                        }

                    });
                }
            }
        }, 450);
    }
}
/*显示产品的简介（竖排显示模式）*/
function showProductInfos(src, _oid) {

    var time1 = null;
    var time2 = null;
    var ID = null;
    var time = null;

    //鼠标移到图片上的事件
    $(src).hover(function() { time1 = new Date(); showTime(); }, function() { window.clearInterval(ID); });

    //js定时器
    function showTime() {
        ID = window.setInterval(function() {
            time2 = new Date();
            time = time2 - time1;

            //时间差，停留200毫秒时触发ajax请求
            if (time > 400) {
                if ($(src).parent().parent().next().attr("class") == "mesbook44") {
                    if ($(src).parent().parent().next().is(":visible")) {
                        return;
                    }
                    else {
                        $(src).parent().parent().next().show();
                    }
                }
                else {
                    $.post("/ajax.ashx?action=showProductInfos&t=" + Math.random(), {
                        oid: _oid
                    }, function(msg) {
                        if ($(src).parent().parent().next().attr("class") == "mesbook44") {
                            return;
                        }
                        else {
                            $(src).parent().parent().after(msg);
                            return;
                        }

                    });
                }
            }
        }, 450);
    }

}


//隐藏产品预览的层
function hideProductInfo(src) {

    if ($(src).parent().parent().next().attr("class") == "mesbook4" || $(src).parent().parent().next().attr("class") == "mesbook40" || $(src).parent().parent().next().attr("class") == "mesbook44") {
            // $(src).parent().parent().next().hide();
            $(src).parent().parent().next().mouseover(function() {
            $(src).parent().parent().next().show();
                return;
            });

            $(src).parent().parent().next().mouseout(function() {
                $(src).parent().parent().next().hide();
                return;
            });
            $(src).parent().parent().next().hide();
        }
}
//显示购买小Tips
function showProductTips(oid) {
    var jLayer = $j("div_nsw_tips");
    if (jLayer.length == 0) {
        var sHtml = "<div class='mesbook5' id='div_nsw_tips'><h1><a href='javascript:void(0)' onclick=\"$(this).parent().parent().fadeOut(80);hideFullBg('div_nsw_tips_bg')\"><img src='" + SKIN_PATH + "img/ico9_close.gif' /></a>Products Book</h1>"
	            + "<h4>Tell me the good news of the product</h4>"
                + "<div class='con'>You need to wait for the product on store shelves do? Once the price of the product price reductions, we will lose no time in the commodity price list sent to your email.</div>"
                + " <h5>If the discount is to send an e-mail to me</h5>"
                + "<div class='inp'><input id='rdoTip1' type='radio' name='rdoTips' value='0' checked='true' /><label for='rdoTip1'>The product is only currently...</label></div>"
                + "<div class='inp'><input id='rdoTip2' type='radio' name='rdoTips' value='1' /><label for='rdoTip2'>Current product belongs Classification</label></div>"
                + "<div class='inp'><input  id='rdoTip3' type='radio' name='rdoTips' value='2' /><label for='rdoTip3'>A list of all discount</label></div>"
                + "<div class='inp'><span>Email:</span><input type='text' id='txtEmail' name='txtEmail'  class='text' /><input id='txtHide' name='txtHide' type='hidden' value='" + oid + "' /></div>"
                + "<div class='inp'><span>Description:</span><textarea id='txtContent' name='txtContent'class='textarea'></textarea></div>"
                +"<div class='mes_btn'>"
    	        + "<input type='button' class='b61' value='Submit' onclick=\"submitProductTips('txtHide','txtEmail','txtContent','rdoTips')\" />"
		        + "<input type='button' class='b62' value='Cancel' onclick=\"$(this).parent().parent().fadeOut(80);hideFullBg('div_nsw_tips_bg')\" />"
                +"</div></div>"
        $(document.body).append(sHtml);
    }
    setCM("div_nsw_tips")
    showFullBg("div_nsw_tips_bg");
    relocation("div_nsw_tips");
    
}


//购买产品小Tips
function submitProductTips(_oid, _email, _content, _rdoTips) {
    var _oid = $j("txtHide").val();
    var _email = $j("txtEmail").val();
    var _content = $j("txtContent").val();
    var _state = $("input[name=rdoTips]:checked").val();
    if (_content.length > 500) {
        $a('Description is too long, not more than 500 bytes, please fill out a brief description of');
    }
    var ptn = /\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
    if (_email.length == 0) {
        $a('E-Mail No Null');
        return false;
    }
    if (!ptn.test(_email)) {
        $a('E-Mail Malformed');
        return false;
    }
    $.post("/ajax.ashx?action=postProductTips&t=" + Math.random(), {
        oid: _oid,
        email: _email,
        content: _content,
        state: _state
    }, function(msg) {
        if (gav(msg, "state") == "1") {
            $a(gav(msg, "msg"),1);
        } else {
            $a(gav(msg, "msg"));
        }
    });
    $j("div_nsw_tips").hide();
    hideFullBg('div_nsw_tips_bg');
}


//产品预览（愿望夹）
function showMyWish(_oid) {
    var jLayer = $j("div_nsw_wishs");
    if (jLayer.length == 0) {
        var sHtml = "<div class=\"mesbook6\" id=\"div_nsw_wishs\"></div>"
        $(document.body).append(sHtml);
    }
    $.post("/ajax.ashx?action=showMyWish&t=" + Math.random(), {
        oid: _oid
    }, function(msg) {
        $j("div_nsw_wishs").html(msg);
    });
    setCM("div_nsw_wishs")
    showFullBg("div_nsw_wishs_bg");
    relocation("div_nsw_wishs");
}

//保存数据到愿望夹
function submitProductWishs(_oid, _attr, _num) {
    var _oid = $j("txtHide").val();
    var _attr = $j("txtAttr").html();
    var _num = $j("txtNum").val();
    $.post("/ajax.ashx?action=postProductWishs&t=" + Math.random(), {
        oid: _oid,
        attr: _attr,
        num: _num
    }, function(msg) {
        if (gav(msg, "state") == "1") {
            $a(gav(msg, "msg"), 1);
        } else {
            $a(gav(msg, "msg"));
        }
    });
    $j("div_nsw_wishs").hide();
    hideFullBg('div_nsw_wishs_bg');
}

/*加盟商在线下单*/
function sendGetProductsNotify(src) {
    var _productColumn = $j("ddlProductsColumns").val();
    var _searchText = $j("txtSearch").val();
    if (_searchText == "关键字") { _searchText = ""; }
    //showProc(src);
    $.post("/ajax.ashx?action=sendGetProductsByColumn&t=" + Math.random(), {
        columnID: _productColumn,
        searchText: _searchText
    }, function(msg) {

        //创建下拉表单
    InitDropdownlist(document.getElementById("PackageSelectList"), "Please select the associated information", "0", msg);
    });
}

//设置产品数据源
function InitDropdownlist(sel, defaulttext, defaultvalue, arry) {
    //1\清除所有的数据源
    var len = sel.options.length;
    for (i = 0; i < len; i++) {
        sel.remove(0);
    }

    //2\设置一个默认值
    //sel.add(new Option(defaulttext, defaultvalue));

    //3\制作数据源，键值对中间用$$分开，||作为键值对之间的分割符

    var ary = arry.split("||");
    len = ary.length;
    if (len) {
        for (i = 0; i < len-1; i++) {
            text_value = ary[i].split("$$");
            text = text_value[1];
            value = text_value[0];
            sel.add(new Option(text, value));
        }
    }
}


   /**定单提交
   ********************/

function userorder(src) {

    var s_name = $tv("txtname");
    var s_title = $tv("txttitle");
    var s_email = $tv("txtemail");
    var s_tel = $tv("txttel");
    var s_content = $tv("txtcontent");
    var s_address = $tv("txtaddress");
    var s_enddate = $tv("txtenddate");
    var s_IDList = $("#PackagePickList").val();
    
    //alert(s_IDList);
    if (s_title == "") {
        $a("Order name can not be empty", "txttitle");
        return;
    }
    if (s_name == "") {
        $a("Under a single name can not be empty", "txtname");
        return;
    }
    if (s_tel == "") {
        $a("Phone can not be empty", "txttel");
        return;
    }
    if (s_address == "") {
        $a("Address can not be empty", "txtaddress");
        return;
    }
    if (s_enddate == "") {
        $a("Arrival time can not be empty", "txtenddate");
        return;
    }
    if (s_content == "" || s_content.length > 1000) {
        $a("A detailed description can not be empty or greater than 1000 characters", "txtcontent");
        return;
    }
    else {
        var _email = $.trim($(src).attr("value"));
        var ptn = /\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
        if (!ptn.test(s_email)) {
            $a("Online Order...");
            return false;
        }
    }
    $.post("/ajax.ashx?action=agentorder&t=" + Math.random(), {
        s_name: s_name,
        s_title: s_title,
        s_email: s_email,
        s_tel: s_tel,
        s_content: s_content,
        s_address: s_address,
        s_enddate: s_enddate,
        s_IDList: s_IDList
    }, function(msg) {
        var sta = gav(msg, "state");
        var sMsg = gav(msg, "msg");
        if (sta == "1") {
            showMsgPage("<li>Order to submit successful, we will contact you as soon as possible, thank you!</li>", 1, "/User/UserOrder.aspx", "Online Order", "/User/UserOrder.aspx");
            return;
        } else if (sMsg.length > 0) {
            $a(sMsg);
        } else {
            $a(msg);
        }
    });
}


/*招商加盟:删除定单end*/
function delAgentOrder(src, itemTabId) {
    var _ids = getCheckedVal(itemTabId);
    if (_ids.length == 0) {
        $a("No selected items.");
        return;
    }
    showBgProc();
    $.post("/ajax.ashx?action=delAgentOrder&t=" + Math.random(), {
        ids: _ids
    }, function(msg) {
        if (gav(msg, "state") == "1") {
            var chks = $j(itemTabId).find("input[name=item]:checked");
            chks.each(function(i) {
                $(this).parent().parent().remove();
            });
        } else {
            $a(gav(msg, "msg"));
        }
        showBgProc(false);
    });
}

//填加友情连接
function AddApply(src) {
    var s_Type = document.getElementById("TxtType").selectedIndex;
    var s_Url = $tv("TxtUrl");
    var s_Name = $tv("TxtName");
    var s_PhotoPath = $tv("TxtPhotoPath");
    var s_Content = $tv("TxtMsg");
    var s_UserName = $tv("TxtUserName");
    var s_Phone = $tv("TxtTel");
    var s_Email = $tv("TxtEmail");
    var s_QQ = $tv("TxtQQ");

    if (s_Url == "" || s_Url == "http://") {
        $a("Please enter the URL!", "TxtUrl");
        return;
    }
    if (s_Name == "") {
        $a("Please enter the name of the site!", "TxtName");
        return;
    }
    if (s_Content.length > 400) {
        $a("Site profiles can not be greater than 400 characters!", "txtUsername");
        return;
    }
    $.post("/ajax.ashx?action=apply&t=" + Math.random(), {
        Type: s_Type,
        Url: s_Url,
        Name: s_Name,
        PhotoPath: s_PhotoPath,
        Content: s_Content,
        UserName: s_UserName,
        Phone: s_Phone,
        Email: s_Email,
        QQ: s_QQ
    },
       function(msg) {
           if (gav(msg, "state") == "1") {
               $a(gav(msg, "msg"));
               
           }
           else {
               $a(gav(msg, "msg"));
           }
           ;
       });
   }

//产品的对比车
   function AddCompare(src) {
       var _flag = false;
       if(src.checked)
       {
           _flag = true;
           $(src).next().next().next().show();
       }
       else
       {
           _flag = false;
           $(src).next().next().next().hide();
       }
       var _ids = $(src).val();

       $.post("/ajax.ashx?action=addCompare&t=" + Math.random(), {
           ids: _ids,
           flag: _flag
       }, function(msg) {
           if (gav(msg, "state") == "1") {
               var newcookie = gav(msg, "newcookie");
               var arr = new Array();
               arr = newcookie.split(',');
                  if (arr.length > 0) {
                      for (var i = 0; i < arr.length; i++) {
                        if (i == arr.length-1)
                        {
                            $(".pro_main").find("input[id=" + arr[i] + "]").show();
                        }
                        else
                        {
                            $(".pro_main").find("input[id=" + arr[i] + "]").hide();
                        }
                      }
                  }
           }
       });

   }

   //产品对比车，移除该产品
   function DelOneCompare(src) {
       var _ids = $(src).attr("id");
       $.post("/ajax.ashx?action=delOneCompare&t=" + Math.random(), {
           ids: _ids
       }, function(msg) {
           if (gav(msg, "state") == "1") {
               window.location = "/product/Compare.aspx";

           }
           else {
               showMsgPage("<li>Product Comparison cars do not exist in contrast to the product record, please select the products need to compare</li>", 0, "/", "Home", "/");
           }
       });
   }

   //产品对比车，移除该产品
   function DelAllCompare() {
       $.post("/ajax.ashx?action=delAllCompare&t=" + Math.random(), {
       }, function(msg) {
       showMsgPage("<li>Product comparison car all the products have been removed, you can continue to compare selected products</li>", 1, "/", "Home", "/");
       });
   }
