
var jscomCurrentAjax = null;

function jscomAjaxRequest(type, pars, funcOnComplete) {
    if (UrlBase == null) {
        UrlBase = "../";
    }
    var url = UrlBase + "Service/AjaxService.aspx";
    //alert(url);
    var params = "type=" + type;
    if (pars != null) {
        params = params + "&" + pars
    }
    jscomCurrentAjax = new Ajax.Request(url, { method: "post", parameters: params, onComplete: function(req) { funcOnComplete(req); } });
}

function jscomAjaxRequestHTML(type, pars, htmlID) {
    if (UrlBase == null) {
        UrlBase = "../";
    }
    var url = UrlBase + "Service/AjaxService.aspx";
    //alert(url);
    var params = "type=" + type;
    if (pars != null) {
        params = params + "&" + pars;
    }
    //alert(params);
    jscomCurrentAjax = new Ajax.Request(url, { method: "post", parameters: params,
        onComplete: function(req) {
            //alert(req.responseText);
            $(htmlID).innerHTML = req.responseText;
        }
    });
}

/*检查个人会员注册账号*/
function checkRegisterAccount(account, htmlID) {
    if (account.trim().length < 3
        || account.trim().length > 30
        || !jscomIsStrInLimitChars(account, '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_')) {
        $(htmlID).innerHTML = "<font color=\"#ff0000\">请输入用户名,只能由数字,字母及下划线组成,3-20位</font>";
    }
    else {
        jscomAjaxRequestHTML("checkAccount", "account=" + account, htmlID);
    }
}

/*检查个人会员注册邮箱是否存在账号*/
function checkRegisterEmail(email, htmlID) {

    if ((/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)) == false) {
        $(htmlID).innerHTML = "<font color=\"#ff0000\">请检查您的信箱地址填写是否有误</font>";
    }
    else {
        jscomAjaxRequestHTML("checkEmail", "email=" + email, htmlID);
    }
}

/*加载产品分类数据*/
function loadProductCategoryData(preCode, categoryListID) {
    jscomAjaxRequest("loadCategory", "preCode=" + preCode,
        function(req) {
            //alert(req.responseText);
            eval(req.responseText);

            //清除产品类别选择框
            var selectCategory = document.getElementById("categorylist");
            selectCategory.innerHTML = "";
            selectCategory.options.add(new Option("-选择类别-", "-1"));

            //清除产品选择框
            var selectCategory = $(categoryListID);
            selectCategory.innerHTML = "";
            selectCategory.options.add(new Option("-选择产品-", "-1"));

            for (var j = 0; j < arrCategoryOptions.length; j++) {
                selectCategory.options.add(new Option(arrCategoryOptions[j][1], arrCategoryOptions[j][0]));
            }
        });
}

/*加载产品数据*/
function loadProductData(categoryCode, productListID) {
    jscomAjaxRequest("loadProduct", "category=" + categoryCode,
        function(req) {
            //alert(req.responseText);
            eval(req.responseText);

            //清除产品选择框
            var selectProduct = $(productListID);
            selectProduct.innerHTML = "";
            selectProduct.options.add(new Option("-选择产品-", "-1"));
            for (var j = 0; j < arrProductOptions.length; j++) {
                selectProduct.options.add(new Option(arrProductOptions[j][1], arrProductOptions[j][0] + ',' + arrProductOptions[j][2]));
            }
        });
}
