var regionID = 0;
var dep = 0;
function PrepareRegion(action,id,depth) {    
    var url = "RegionAdd.aspx?Action=" + action + "&ID=" + id+"&Depth="+depth;
    var step="";
    switch (depth) {
        case 0:
            step = "一";
            break;
        case 1:
            step = "二";
            break;
        case 2:
            step = "三";
            break;
        case 3:
            step = "四";
        default:
            break;
    }
    o("Depth").innerHTML = step;
    regionID = id;
    dep = depth;
    Ajax.requestURL(url, DealRegion);
}
function DealRegion(data) {
    if (data != '0') {
        var divObj = o("Region-Ajax");
        divObj.innerHTML = data;
    }
    else {
        alertMessage('不允许删除该类别');
    }
}
//添加新地区
function AddRegion() {
    var regionNameObj = o("ctl00_ContentPlaceHolder_RegionName");
    var regionNameValue = regionNameObj.value;
    if (regionNameValue.length < 1) {
        alertMessage("请输入地区名称");
        return;
    }
    var url = "RegionAdd.aspx?Action=Add&RegionName=" + encodeURI(regionNameValue) + "&FatherID=" + regionID;    
    Ajax.requestURL(url,DealAddRegion);
}
function DealAddRegion() {
    alertMessage('增加成功');
    PrepareRegion('Read', regionID,dep);
}
//修改地区
function UpdateRegion(obj, newValue, oldValue, id) {
    if (newValue.length > 0 && newValue!=oldValue) {
        var url = "RegionAdd.aspx?Action=Update&ID=" + id + "&Name=" + encodeURI(newValue);         
         obj.innerHTML =newValue;
        Ajax.requestURL(url,DealUpdateRegion);       
    }
    else {
        obj.innerHTML = oldValue;
    }
}
function DealUpdateRegion() {
    alertMessage('更新成功');
}

