//联动绑定地区
var tempObj = '';
var tempNeedBind=false;
function PrepareRegion(regionID,regionObj,needBind) {
    var url = "/admin/ShippingRegionAdd.aspx";
    var postData = "RegionID=" + regionID + "&Action=Read";    
    tempObj = regionObj;
    tempNeedBind=needBind;
    Ajax.postURL(url, postData, DealPrepareRegion);  
}
function DealPrepareRegion(data) {
    var obj = o(tempObj);
    obj.length = 0;
    if (tempObj == "Province") {
        o("City").length = 0;
        o("District").length = 0;
    }
    if (tempObj == "City") {
        o("District").length = 0;
    }
    if (data != "") {
        var regionList = data.split('|');
        if(needSelect)        {
            obj.add(new Option("请选择", "-1"));
        }
        for (var i = 0; i < regionList.length; i++) {
            obj.add(new Option(regionList[i].split(",")[1], regionList[i].split(",")[0]));
        }
    }
    if(tempNeedBind){
        BindValue();
    }
}
//添加配货地区
function AddRegion() {
    var regionID = '';
    var name = '';
    district =o("District");
    city=o("City");
    province=o("Province");
    country = o("Country");
    if (district.selectedIndex >= 0) {
        regionID = district.value;
        name=district[district.selectedIndex].text;
    }
    else if (city.selectedIndex >= 0) {
        regionID = city.value;
        name = city[city.selectedIndex].text;
    }
    else if (province.selectedIndex >= 0) {
        regionID = province.value;
        name = province[province.selectedIndex].text; 
    }
    else if (country.selectedIndex >= 0) {
        regionID = country.value;
        name = country[country.selectedIndex].text;
    }
    if(name!="")
    {
        if (o('Region' + regionID) != null) {
            alertMessage("该地区已经存在");
        }
        else {
            var obj = o("Area-Box");
            var newElement = document.createElement("span");
            with (newElement) {
                id = "Region" + regionID;
            }
            newElement.innerHTML = "<input type='checkbox' value='" + regionID + "' name='RegionNameList' checked='checked' onclick='DeleteRegion(" + regionID + ")'/>" + name + "    ";
            obj.appendChild(newElement);
        }
    }
    else    {
        alertMessage("请选择地区");
    }
}
//删除配货地区
function DeleteRegion(regionID) {
    var obj = o("Region" + regionID);
    if (obj != null) {
        obj.parentNode.removeChild(obj);
    }
}

