//#import $owl_mall_region:services/modelService.jsx

var RegionUtil = (function () {
    var f = {
        hasChildren: function (parentId) {
            var searchArgs = {
                parent_id: parentId
            }

            var searchResult = owl_mall_regionService.search('0', searchArgs, null, 0, 1, null);
            if (searchResult.state === 'ok') {
                if (searchResult.list.length > 0) {
                    return true;
                }
            }
            return false;
        },
        getRegionPathName: function (jRegion, spex) {
            var parentPathNames = jRegion.parentPathNames;

            var namePath = "";
            if (parentPathNames) {
                if(parentPathNames.length > 1) {
                    for (var i = parentPathNames.length - 2; i >= 0; i--) {
                        var rid = parentPathNames[i];
                        if (!rid) {
                            continue;
                        }

                        if (namePath != "") {
                            namePath += spex;
                        }
                        namePath += parentPathNames[i];
                    }
                }
            }
            if (namePath != "") {
                namePath += spex;
            }
            namePath += jRegion.name;

            return namePath;
        }
    };
    return f;
})();