/**
* @author Administrator
*/

/*
*
*产品系统属性和自定义属性
*/


AE.widget.treeData = function (dataSrc, dataType) {
    this.init(dataSrc, dataType);
};
AE.widget.treeData.prototype = {
    dataSrc: null,
    _TYPE: {
        'ARRAY': 'ARRAY'
    },
    dataType: null,
    root: null,
    _nodes: null,
    init: function (dataSrc, dataType) {
        this._nodes = [];
        this.dataSrc = dataSrc;
        this.dataType = dataType || this._TYPE.ARRAY;
        this.dataType = this.dataType.toUpperCase();
        this.initData();
    },
    initData: function () {
        this.root = new AE.widget.dataRootNode(this);
        switch (this.dataType) {
            case this._TYPE.ARRAY:
            default:
                {
                    this.build['ARRAY'].buildTree(this.dataSrc, this.root, this);
                }
        };
    },
    _formatInitData: function (o) {
        var _r = [];
        for (var i = 0, l = o.length; i < l; i++) {
            if (o[i].children.length > 0) {
                _r.push({
                    'data': o[i].data,
                    'nodes': this._formatInitData(o[i].children)
                });
            }
            else {
                _r.push({
                    'data': o[i].data
                });
            }
        }
        return _r;
    },
    getInitData: function () {
        return this._formatInitData(this.root.children);
    },
    regNode: function (node) {
        this._nodes[node.index] = node;
    },
    getRoot: function () {
        return this.root;
    },
    getNodeByIndex: function (nodeIndex) {
        var n = this._nodes[nodeIndex];
        return (n) ? n : null;
    },
    getNodeByProperty: function (property, value) {
        for (var i in this._nodes) {
            if (this._nodes.hasOwnProperty(i)) {
                var n = this._nodes[i];
                if (n.data && value == n.data[property]) {
                    return n;
                }
            }
        }
        return null;
    },
    getNodesByProperty: function (property, value) {
        var values = [];
        for (var i in this._nodes) {
            if (this._nodes.hasOwnProperty(i)) {
                var n = this._nodes[i];
                if (n.data && value == n.data[property]) {
                    values.push(n);
                }
            }
        };
        return (values.length) ? values : null;
    },
    build: {
        'ARRAY': {
            buildTree: function (dataSrc, oParent, scope) {
                try {
                    for (var i = 0, j = dataSrc.length; i < j; i++) {
                        if (dataSrc[i] && dataSrc[i].data) {
                            var oNode = new AE.widget.dataNode(dataSrc[i].data, oParent);
                        }
                        if (dataSrc[i].nodes && dataSrc[i].nodes.length > 0) {
                            this.buildTree(dataSrc[i].nodes, oNode);
                        };
                    }
                }
                catch (e) {
                    log(e);
                }
            }
        }
    }
};
AE.widget.treeData.nodeCount = 0;
AE.widget.dataNode = function (oData, oParent) {
    this.init(oData, oParent);
};
AE.widget.dataNode.prototype = {
    index: 0,
    children: null,
    tree: null,
    el: null,
    data: null,
    parent: null,
    depth: -1,
    childrenRendered: false,
    previousSibling: null,
    nextSibling: null,
    init: function (oData, oParent) {
        this.data = oData;
        this.children = [];
        this.index = AE.widget.treeData.nodeCount;
        ++AE.widget.treeData.nodeCount;
        if (oParent) {
            oParent.appendChild(this);
        }
    },
    appendChild: function (childNode) {
        if (this.hasChildren()) {
            var sib = this.children[this.children.length - 1];
            sib.nextSibling = childNode;
            childNode.previousSibling = sib;
        };
        this.children[this.children.length] = childNode;
        childNode.applyParent(this);
        return childNode;
    },
    applyParent: function (parentNode) {
        if (!parentNode) {
            return false;
        }
        this.tree = parentNode.tree;
        this.parent = parentNode;
        this.depth = parentNode.depth + 1;
        this.tree.regNode(this);
        parentNode.childrenRendered = false;
        for (var i = 0, len = this.children.length; i < len; ++i) {
            this.children[i].applyParent(this);
        };
        return true;
    },
    hasChildren: function (checkForLazyLoad) {
        return this.children.length > 0
    },
    getAncestorByProperty: function (property, val) {
        var p = this.parent;
        while (p) {
            if (p.data && p.data.hasOwnProperty(property) && p.data[property] == val) {
                return p;
            };
            p = p.parent;
        };
        return null;
    },
    getChildNodeByProperty: function (property, value) {
        for (var i = 0, j = this.children.length; i < j; i++) {
            if (this.children[i] && this.children[i].data.hasOwnProperty(property)) {
                var n = this.children[i];
                if (n.data && value == n.data[property]) {
                    return n;
                }
            }
        };
        return null;
    },
    getChildNodesByProperty: function (property, value) {
        var nodes = [];
        for (var i = 0, j = this.children.length; i < j; i++) {
            if (this.children[i] && this.children[i].data.hasOwnProperty(property)) {
                var n = this.children[i];
                if (n.data && value == n.data[property]) {
                    nodes.push(n);
                }
            }
        };
        return (nodes.length > 0 ? nodes : null);
    },
    getUpLayerNodesByProperty: function (property, val) {
        var aResult = [];
        this._searchNodesByProperty(property, val, this.parent, aResult, 'up');
        return (aResult.length) ? aResult : null;
    },
    getNodesByProperty: function (property, val) {
        var aResult = [];
        this._searchNodesByProperty(property, val, this, aResult, 'down');
        return (aResult.length) ? aResult : null;
    },
    _searchNodesByProperty: function (property, val, parentNode, aResult, direction) {
        if (!parentNode) {
            return;
        }
        var node = null;
        for (var i = 0, j = parentNode.children.length; i < j; i++) {
            node = parentNode.children[i];
            if (node && node.data && val == node.data[property]) {
                aResult.push(node);
            };
            if (direction != 'up') {
                if (node.children && node.children.length > 0) {
                    this._searchNodesByProperty(property, val, node, aResult, direction);
                }
            };
        };
        if (direction == 'up' && parentNode.parent) {
            this._searchNodesByProperty(property, val, parentNode.parent, aResult, direction);
        }
    }
};
AE.widget.dataRootNode = function (oTree) {
    this.init(null, null);
    this.tree = oTree;
};
YAHOO.extend(AE.widget.dataRootNode, AE.widget.dataNode, {});
AE.widget.attributeCombo = function () {
    this._defConfig = {
        containerId: '',
        dataSrc: [],
        dataType: null,
        showTypeConfig: {},
        showTypePool: {}
    };
};
AE.widget.attributeCombo.prototype = {
    _config: null,
    treeData: null,
    _dContainerEl: null,
    NODE_TYPE: {
        attrValue: 'value',
        attrName: 'name'
    },
    _defTagName: 'TAG:main',
    _prevAttrRow: null,
    events: null,
    init: function (oConfig) {
        this._config = YL.merge(this._defConfig, oConfig || {});
        this.treeData = new AE.widget.treeData(this._config.dataSrc, this._config.dataType);
        this.showTypePool = YL.merge(this.showTypePool, this._config.showTypePool || {});
        this.funcPool = YL.merge(this.funcPool, {
            _scope: this
        });
        this._dContainerEl = get(this._config.containerId);
        this._initEvents();
    },
    _initEvents: function () {
        var arrEventName = ['drawAttrName', 'drawAttrValue', 'drawAttr', 'drawCompleteAll', 'createElement', 'removeElement', 'removeRow', 'beforeRemoveAttrView', 'removeAttrView', 'beforDestroy', 'destroy'];
        this.events = {};
        for (var i = 0, j = arrEventName.length; i < j; i++) {
            this.events[arrEventName[i]] = new YAHOO.util.CustomEvent(arrEventName[i] + 'Event', this);
        };
    },
    _clearAllEvent: function () {
        for (var ev in this.events) {
            this.events[ev].unsubscribeAll();
            this.events[ev] = null;
        };
    },
    builder: function () {
        var rootNode = this.treeData.getRoot();
        for (var i = 0, j = rootNode.children.length; i < j; i++) {
            var oNode = rootNode.children[i], dTable = this.createViewByName('table', rootNode), tBodyEl = dTable.getElementsByTagName('TBODY')[0];
            this._dContainerEl.appendChild(dTable);
            this._builderBranch(oNode, tBodyEl);
        };
        this._prevAttrRow = null;
        this.events['drawCompleteAll'].fire();
    },
    _builderBranch: function (parentNode, tBodyEl) {
        if (!parentNode) {
            return;
        };
        if (parentNode.data) {
            switch (parentNode.data.showType) {
                case 'province':
                case 'other':
                case 'unit':
                case 'group_item':
                case 'other_country': 
                    {
                        this._builderBranchAttrInline(parentNode, tBodyEl);
                        break;
                    }
                case 'group_table':
                default:
                    {
                        this._builderBranchAttr(parentNode, tBodyEl);
                        break;
                    }
            };
        };
        if (parentNode.data.showType == 'group_table') {
            var nodes = parentNode.children;
        }
        else {
            var nodes = parentNode.getChildNodesByProperty('selected', 'true');
        }
        if (nodes) {
            for (var i = 0, j = nodes.length; i < j; i++) {
                this._builderBranchByValue(nodes[i], tBodyEl, nodes[i]);
            }
        };
    },
    _builderBranchByValue: function (oAttrValueNode, tBodyEl) {
        if (oAttrValueNode.data['nodeType'] != this.NODE_TYPE.attrValue) {
            return false;
        };
        for (var i = 0, j = oAttrValueNode.children.length; i < j; i++) {
            var oNode = oAttrValueNode.children[i];
            if (oNode.children.length > 0) {
                this._builderBranch(oNode, tBodyEl);
            };
        };
        return true;
    },
    execCommandBuilderBranchByVlaue: function (oAttrValueNode, tBodyEl) {
        this._builderBranchByValue(oAttrValueNode, tBodyEl);
        this._prevAttrRow = null;
    },
    _builderBranchAttrInline: function (oAttrNameNode, tBodyEl) {
        var pNode = oAttrNameNode.parent;
        if (!pNode || !pNode.el) {
            return false;
        };
        var pTagName = null;
        if (pNode.data['nodeType'] != this.NODE_TYPE.attrName) {
            pTagName = 'TD';
        }
        else {
            pTagName = 'TH';
        };
        var containerEl = YUD.getAncestorByTagName(pNode.el, pTagName);
        if (oAttrNameNode.data.showType == 'group_item') {
            this._builderAttrName(oAttrNameNode, containerEl);
        }
        this._builderAttrValue(oAttrNameNode, containerEl);
        this.events['drawAttr'].fire({
            'node': oAttrNameNode
        });
        return true;
    },
    _builderBranchAttr: function (oAttrNameNode, tBodyEl) {
        var dTr = this.createViewByName('table_tr', oAttrNameNode), dTh = this.createViewByName('table_th', oAttrNameNode), dTd = this.createViewByName('table_td', oAttrNameNode);
        this._builderAttrName(oAttrNameNode, dTh), this._builderAttrValue(oAttrNameNode, dTd);
        dTr.appendChild(dTh);
        dTr.appendChild(dTd);
        if (tBodyEl) {
            tBodyEl.appendChild(dTr);
        }
        else
            if (this._prevAttrRow) {
                YUD.insertAfter(dTr, this._prevAttrRow);
            }
            else {
                var localAttrName = oAttrNameNode.getAncestorByProperty('nodeType', 'name');
                var tTr = this.getRowByEl(localAttrName.el);
                YUD.insertAfter(dTr, tTr);
            };
        this._prevAttrRow = dTr;
        this.events['drawAttr'].fire({
            'node': oAttrNameNode
        });
    },
    _builderAttrName: function (oAttrNameNode, containerEl) {
        if (oAttrNameNode.data['nodeType'] != this.NODE_TYPE.attrName) {
            return null;
        };
        var els = this.execShowTypeFunc('label', oAttrNameNode, containerEl);
        this.appendChildByEls(els, containerEl);
        var sShowStyle = oAttrNameNode['data']['showStyles'];
        if (sShowStyle && sShowStyle.length > 0) {
            els = this.execShowStyleFunc(sShowStyle, oAttrNameNode, els);
        }
        this.events['drawAttrName'].fire({
            'node': oAttrNameNode
        });
    },
    _builderAttrValue: function (oAttrNameNode, containerEl) {
        if (oAttrNameNode.data['nodeType'] != this.NODE_TYPE.attrName) {
            return false;
        };
        var sShowType = oAttrNameNode.data.showType;
        if (this.showTypePool[sShowType]) {
            var els = this.execShowTypeFunc(sShowType, oAttrNameNode, containerEl);
            this.appendChildByEls(els, containerEl);
        };
        this.events['drawAttrValue'].fire({
            'node': oAttrNameNode,
            'nodeType': sShowType,
            'els': els
        });
        return true;
    },
    appendChildByEls: function (els, parentEl) {
        YUD.batch(els, function (el) {
            parentEl.appendChild(el);
        });
        return true;
    },
    createViewByName: function (sShowType, oNode, oConfig) {
        if (!sShowType) {
            sShowType = oData.showType;
        };
        var oData = oNode.data, fn = this.viewPool[sShowType], el = null;
        if (fn && YL.isFunction(fn)) {
            el = fn.call(this, oData, oNode, oConfig);
        };
        this.events['createElement'].fire({
            'node': oNode,
            'showType': sShowType,
            'el': el
        });
        return el;
    },
    generateId: function (oNode, sPrefix) {
        if (sPrefix == null) {
            sPrefix = 'atuo-id';
        }
        return sPrefix + '-' + oNode.index;
    },
    generateName: function (oNode, sPrefix) {
        if (sPrefix == null) {
            sPrefix = '';
        };
        var n = oNode;
        while (n && n.data['nodeType'] != this.NODE_TYPE.attrName) {
            n = n.parent;
        };
        if (n) {
            return sPrefix + n.data.id;
        };
        return '';
    },
    getRowByEl: function (dEl) {
        return (dEl == null ? null : YUD.getAncestorByTagName(dEl, 'TR'));
    },
    bindViewByNode: function (el, oNode) {
        oNode.el = el;
    },
    removeChildNodeView: function (oNode) {
        var nodes = oNode.children;
        for (var i = 0, j = nodes.length; i < j; i++) {
            if (nodes[i].data['nodeType'] == this.NODE_TYPE.attrValue) {
                if (nodes[i].data.hasOwnProperty('selected') && nodes[i].data['selected'] == 'true') {
                    this.removeChildNodeView(nodes[i]);
                }
            }
            else {
                this.removeChildNodeView(nodes[i]);
                this._removeNodeAttrView(nodes[i]);
            };
        };
    },
    _removeNodeAttrView: function (oAttrNameNode) {
        if (oAttrNameNode.data['nodeType'] != this.NODE_TYPE.attrName) {
            return;
        };
        this.events['beforeRemoveAttrView'].fire({
            'node': oAttrNameNode
        });
        var nodes = oAttrNameNode.children;
        var els = this.getTagElsByAttrNameNode(oAttrNameNode);
        YUD.batch(els, function (el) {
            YUE.removeListener(el);
        });
        if (nodes.length > 0 && nodes[0].el && nodes[0].el.tagName == 'OPTION') {
            var dSelect = nodes[0].el.parentNode;
            if (dSelect && dSelect.parentNode) {
                YUE.removeListener(dSelect);
                dSelect.parentNode.removeChild(dSelect);
                this.setNodesAttrValue(nodes, 'el', null);
                this.events['removeElement'].fire({
                    'el': dSelect,
                    'node': oAttrNameNode
                });
            }
        }
        else {
            YUD.batch(nodes, function (oNode) {
                if (oNode.el) {
                    if (oNode.el.parentNode) {
                        oNode.el.parentNode.removeChild(oNode.el);
                        this.events['removeElement'].fire({
                            'el': oNode.el,
                            'node': oAttrNameNode
                        });
                    };
                };
                oNode.el = null;
            }, this, true);
        };
        if (oAttrNameNode.el) {
            var row = this.getRowByEl(oAttrNameNode.el);
            if (row && row.parentNode) {
                row.parentNode.removeChild(row);
                this.events['removeRow'].fire({
                    'el': row,
                    'node': oAttrNameNode
                });
            };
            oAttrNameNode.el = null;
        };
        this.events['removeAttrView'].fire({
            'node': oAttrNameNode
        });
    },
    destroy: function () {
        this.events['beforDestroy'].fire();
        this.removeChildNodeView(this.treeData.getRoot());
        this.treeData = null;
        this.events['destroy'].fire();
        this._clearAllEvent();
    },
    setNodesAttrValue: function (nodes, property, val) {
        if (!YL.isArray(nodes)) {
            this.setNodeAttrValue(nodes, property, val);
        }
        else {
            YUD.batch(nodes, function (oNode) {
                this.setNodeAttrValue(oNode, property, val);
            }, this, true);
        };
    },
    setNodeAttrValue: function (oNode, property, val) {
        if (oNode.hasOwnProperty(property)) {
            oNode[property] = val;
        };
    },
    getTagElsByAttrNameNode: function (oAttrNameNode) {
        var els = [], nodes = oAttrNameNode.children;
        if (nodes.length > 0 && nodes[0].el && nodes[0].el.tagName == 'OPTION') {
            els.push(nodes[0].el.parentNode);
        }
        else {
            for (var i = 0, j = nodes.length; i < j; i++) {
                var viewEl = nodes[i].el;
                if (viewEl) {
                    var aEl = this.getTagEls(viewEl);
                    if (aEl && aEl.length > 0) {
                        els = els.concat(aEl);
                    };
                };
            };
        };
        return els;
    },
    getNodeByEl: function (el) {
        if (el.id && el.id != '') {
            var a = el.id.split('-');
            if (a.length > 0) {
                var nIndex = parseInt(a[a.length - 1]);
                if (nIndex != null) {
                    return this.treeData.getNodeByIndex(nIndex);
                };
            };
        };
        return null;
    },
    getAttrNameByEl: function (el) {
        var oNode = this.getNodeByEl(el);
        if (!oNode) {
            return null;
        }
        if (oNode.data['nodeType'] == this.NODE_TYPE.attrName) {
            return oNode;
        }
        else {
            return oNode.parent;
        };
    },
    addElTag: function (el, sTagName) {
        if (!sTagName) {
            sTagName = this._defTagName;
        };
        if (el) {
            YUD.addClass(el, sTagName);
        };
    },
    getTagEls: function (containerEl, sTagName) {
        if (!containerEl) {
            containerEl = this._dContainerEl;
        }
        if (!sTagName) {
            sTagName = this._defTagName;
        };
        if (YUD.hasClass(containerEl, sTagName)) {
            return [containerEl];
        }
        else {
            return YUD.getElementsByClassName(this._defTagName, '*', containerEl);
        }
    },
    getTagEl: function (containerEl, sTagName) {
        if (!sTagName) {
            sTagName = this._defTagName;
        };
        if (YUD.hasClass(containerEl, sTagName)) {
            return containerEl;
        }
        else {
            var els = YUD.getElementsByClassName(this._defTagName, '*', containerEl);
            if (els.length > 0) {
                return els[0];
            };
        };
        return null;
    },
    execShowTypeFunc: function (sShowType, oNode, containerEl) {
        var fn = this.showTypePool[sShowType];
        if (fn) {
            return fn.call(this, oNode, containerEl, this.readShowTypeConfig(sShowType));
        };
        return null;
    },
    execShowStyleFunc: function (sShowStyle, oNode, els) {
        var returnEls;
        if (YL.isArray(sShowStyle) && sShowStyle.length > 0) {
            for (var i = 0, len = sShowStyle.length; i < len; i++) {
                var fn = this.showStylePool[sShowStyle[i]];
                if (fn) {
                    returnEls = fn.call(this, oNode, els);
                }
                else {
                    returnEls = this.showStylePool['default'].call(this, oNode, els, sShowStyle[i]);
                }
            }
            return returnEls;
        }
        else {
            return els;
        }
    },
    readShowTypeConfig: function (sShowType) {
        if (this._config.showTypeConfig[sShowType]) {
            return this._config.showTypeConfig[sShowType];
        };
        return null;
    },
    viewPool: {
        'table': function (oData, oNode, viewConfig) {
            var el = document.createElement('TABLE'), dTBody = document.createElement('TBODY');
            el.appendChild(dTBody);
            el.cellPadding = '2';
            el.cellSpacing = '0';
            el.className = 'attribute-table';
            return el;
        },
        'table_tr': function (oData, oNode, viewConfig) {
            var el = document.createElement('TR');
            return el;
        },
        'table_th': function (oData, oNode, viewConfig) {
            var el = document.createElement('TH');
            el.className = 'attribute-table-th';
            return el;
        },
        'table_td': function (oData, oNode, viewConfig) {
            var el = document.createElement('TD');
            el.className = 'attribute-table-td';
            return el;
        },
        'select': function (oData, oNode, viewConfig) {
            var defConfig = {
                'id': this.generateId(oNode, 'auto-id-select'),
                'name': this.generateName(oNode, 'sysAttrValueIdAndValue')
            };
            var el = this.createElement('SELECT', YL.merge(defConfig, viewConfig || {}));
            this.addElTag(el);
            return el;
        },
        'input': function (oData, oNode, viewConfig) {
            var defConfig = {
                'id': this.generateId(oNode),
                'name': this.generateName(oNode, 'sysAttrValueIdAndValue'),
                'type': 'text',
                'value': oData.value ? oData.value : ''
            };
            var el = this.createElement('INPUT', YL.merge(defConfig, viewConfig || {}));
            this.addElTag(el);
            this.bindViewByNode(el, oNode);
            el.onchange = function () {
                oData.value = this.value;
            };
            return el;
        },
        'textarea': function (oData, oNode, viewConfig) {
            var defConfig = {
                'id': this.generateId(oNode),
                'name': this.generateName(oNode, 'sysAttrValueIdAndValue'),
                'value': oData.value ? oData.value : ''
            };
            var el = this.createElement('TEXTAREA', YL.merge(defConfig, viewConfig || {}));
            this.addElTag(el);
            this.bindViewByNode(el, oNode);
            el.onchange = function () {
                oData.value = this.value;
            };
            return el;
        },
        'option': function (oData, oNode, viewConfig) {
            var defConfig = {
                'id': this.generateId(oNode),
                'value': oData['id'] ? oData['id'] + '-' + oData['value'] : oData['value'],
                'text': oData['value'] ? oData['value'] : '',
                'title': oData['value'] ? oData['value'] : ''
            };
            var config = YL.merge(defConfig, viewConfig || {});
            var el = this.createElement('option', config);
            this.bindViewByNode(el, oNode);
            return el;
        },
        'label': function (oData, oNode, viewConfig) {
            var defConfig = {
                'label': {},
                'titleText': {
                    'innerHTML': oData['value'],
                    'className': 'attr-title'
                },
                'input': {
                    'id': this.generateId(oNode),
                    'type': 'hidden',
                    'value': oData['id'] + '-' + oData['value'],
                    'name': 'sysAttrIdAndName'
                },
                'input-showType': {
                    'type': 'hidden',
                    'value': oData['showType'],
                    'name': 'sysAttrShowType' + oData['id']
                }
            };
            var config = AE.tools.depthMerge(defConfig, viewConfig || {});
            var el = this.createElement('label', config.label), dText = this.createElement('SPAN', config.titleText);
            if (oData.showType != 'fix_value') {
                var dInput = this.createElement('INPUT', config['input']), dShowType = this.createElement('INPUT', config['input-showType']);
                el.appendChild(dInput);
                el.appendChild(dShowType);
            };
            el.appendChild(dText);
            this.bindViewByNode(el, oNode);
            return el;
        },
        'inputGroup': function (oData, oNode, viewConfig) {
            var defConfig = {
                'label': {},
                'titleText': {
                    'innerHTML': oData['value']
                },
                'input': {
                    'id': this.generateId(oNode),
                    'type': 'hidden',
                    'value': oData['id'] + '-' + oData['value'],
                    'name': 'sysAttrValueIdAndValue'
                }
            };
            var config = AE.tools.depthMerge(defConfig, viewConfig || {});
            if (oData['selected'] == 'true') {
                config.input['checked'] = true;
            };
            var el = this.createElement('label', config.label), dText = this.createElement('SPAN', config.titleText), dInput = this.createElement('INPUT', config.input);
            el['for'] = dInput.id;
            el.appendChild(dInput);
            el.appendChild(dText);
            this.addElTag(dInput);
            this.bindViewByNode(el, oNode);
            return el;
        }
    },
    showTypePool: {
        'group_table': function (oAttrNameNode, containerEl, oConfig) {
            var childNodes = oAttrNameNode.children, els = [];
            var noticeDiv = document.createElement('div');
            noticeDiv.id = 'auto-id-' + oAttrNameNode.index + '-notice';
            noticeDiv.className = 'board noticeB';
            var currentNum = 0, currentNumId = 'current-' + oAttrNameNode.index;
            var totalNum = 0, totalNumId = 'total-' + oAttrNameNode.index;
            var currentNumEl = '<span id="' + currentNumId + '" class="red AE:current">' + currentNum + '</span>';
            var totalNumEl = '<span id="' + totalNumId + '" class="red AE:max">' + totalNum + '</span>';
            var noticeStr = oConfig['notice'].replace(/\{currentNum\}/g, currentNumEl);
            noticeDiv.innerHTML = noticeStr.replace(/\{totalNum\}/g, totalNumEl);
            els.push(noticeDiv);
            var createErrorMsgElement = function (id) {
                var sId = id + '-advice-error';
                if (get(sId)) {
                    return get(sId);
                };
                var div = document.createElement('DIV');
                div.id = sId;
                div.className = 'board errorB';
                YUD.setStyle(div, 'display', 'none');
                YUD.setStyle(div, 'position', 'relative');
                YUD.setStyle(div, 'top', '-38px');
                YUD.setStyle(div, 'margin-bottom', '-38px');
                return div;
            }
            if (oAttrNameNode.data.rules.length != 0) {
                els.push(createErrorMsgElement('atuo-id-' + childNodes[0].index));
            }
            var lastChildren = childNodes[childNodes.length - 1].children[0];
            if (lastChildren.data && lastChildren.data.rules && lastChildren.data.rules.length != 0) {
                els.push(createErrorMsgElement('atuo-id-' + lastChildren.children[0].index));
            }
            for (var i = 0, j = childNodes.length; i < j; i++) {
                var oNode = childNodes[i], dInputId = this.generateId(oNode);
                var defConfig = {
                    'id': dInputId,
                    'name': this.generateName(oNode, 'sysAttrValueIdAndValue'),
                    'type': 'CHECKBOX',
                    'className': 'type-check-box-input',
                    'value': this.funcPool['spellValueByNode'](oNode),
                    'checked': oNode.data.selected && oNode.data.selected == 'true',
                    'style': {
                        'display': 'none'
                    }
                };
                var groupTabDiv = document.createElement('div');
                groupTabDiv.className = 'groupTab';
                var groupTabStatusdiv = document.createElement('img');
                groupTabStatusdiv.className = 'groupTabCheckBox';
                if (oNode.data.selected && oNode.data.selected == 'true') {
                    groupTabStatusdiv.src = 'http://img.alibaba.com/images/eng/style/css_images/myalibaba/checkbox_in.gif';
                }
                else {
                    groupTabStatusdiv.src = 'http://img.alibaba.com/images/eng/style/css_images/myalibaba/checkbox_off.gif';
                }
                groupTabDiv.appendChild(groupTabStatusdiv);
                var valueSpan = document.createElement('span');
                valueSpan.className = 'groupTabValue';
                valueSpan.innerHTML = oNode.data.value;
                groupTabDiv.appendChild(valueSpan);
                var elInput = this.createViewByName('input', oNode, defConfig);
                groupTabDiv.appendChild(elInput);
                els.push(groupTabDiv);
                YUE.on(groupTabStatusdiv, 'click', function (ev, o) {
                    var currentEl = YUE.getTarget(ev);
                    var oNode = o.oNode;
                    var validator = o.oConfig.validator;
                    if (oNode.data.selected && oNode.data.selected != 'true') {
                        return;
                    }
                    else {
                        currentEl.src = 'http://img.alibaba.com/images/eng/style/css_images/myalibaba/checkbox_off.gif';
                        oNode.data.selected == 'false';
                        oNode.el.checked = false;
                        var childNodes = oNode.children[0].children;
                        for (var i = 0, len = childNodes.length; i < len; i++) {
                            var checkEl = childNodes[i].el.getElementsByTagName('INPUT')[0];
                            checkEl.checked = false;
                            childNodes[i].data.selected = false;
                        }
                        var rulesEl = lastChildren.children[0]['el'].getElementsByTagName('INPUT')[0];
                        if (rulesEl && validator) {
                            validator.configData.fields[rulesEl.id].isInValidateProcess = true;
                            validator.eventFuncPool['default_blur'](null, rulesEl);
                        }
                        var statusEl = YUD.getNextSibling(currentEl);
                        var statusStr = statusEl.innerHTML;
                        var status = statusStr.match(/\(\d+\)/g);
                        statusEl.innerHTML = statusStr.replace(status[0], '(0)');
                        var statusNum = parseInt(status[0].match(/\d+/));
                        if (get(currentNumId)) {
                            get(currentNumId).innerHTML = parseInt(get(currentNumId).innerHTML) - statusNum;
                        }
                    }
                }, {
                    'oNode': oNode,
                    'oConfig': oConfig
                }, true)
            };
            return els;
        },
        'group_item': function (oAttrNameNode, containerEl, oConfig) {
            var childNodes = oAttrNameNode.children, els = [];
            var div = document.createElement('div');
            div.className = 'groupItem';
            div.style.display = 'none';
            for (var i = 0, j = childNodes.length; i < j; i++) {
                var oNode = childNodes[i], dInputId = this.generateId(oNode);
                var defConfig = {
                    'label': {
                        'className': 'type-check-box-label',
                        'for': dInputId
                    },
                    'input': {
                        'id': dInputId,
                        'name': this.generateName(oNode, 'sysAttrValueIdAndValue'),
                        'type': 'CHECKBOX',
                        'className': 'type-check-box-input',
                        'value': this.funcPool['spellValueByNode'](oNode)
                    }
                };
                var el = this.createViewByName('inputGroup', oNode, defConfig);
                div.appendChild(el);
                var dCheckbox = el.getElementsByTagName('INPUT')[0];
                YUE.on(dCheckbox, 'click', function (ev, o) {
                    if (!o) {
                        return null;
                    }
                    this.funcPool['checkBoxClick'](o.el);
                    ShowCheckStatus(o.el, oAttrNameNode.parent, false, oConfig);
                }, {
                    'el': dCheckbox
                }, this, true);
            };
            var ShowCheckStatus = function (el, oAttrNodeParent, isInit, oConfig) {
                var n = 0;
                var parentId = YUD.getPreviousSibling(oAttrNodeParent['el']);
                var parentDiv = YUD.getAncestorByClassName(el, 'groupItem');
                var nNode = YUD.getElementsBy(function (el) {
                    return el.type.toLowerCase() == 'checkbox'
                }, 'input', parentDiv);
                for (var i = 0, len = nNode.length; i < len; i++) {
                    if (nNode[i].checked) {
                        n++;
                    }
                }
                var status = parentId.innerHTML;
                var statusStr = status.replace(/\(\d+\)/g, '');
                parentId.innerHTML = statusStr + '(' + n + ')';
                var checkboxStatus = YUD.getPreviousSibling(parentId);
                if (n == 0) {
                    if (!isInit) {
                        oAttrNodeParent.data.selected = 'false';
                        oAttrNodeParent.el.checked = false;
                        checkboxStatus.src = 'http://img.alibaba.com/images/eng/style/css_images/myalibaba/checkbox_off.gif';
                    }
                }
                else {
                    oAttrNodeParent.data.selected = 'true';
                    oAttrNodeParent.el.checked = true;
                    checkboxStatus.src = 'http://img.alibaba.com/images/eng/style/css_images/myalibaba/checkbox_in.gif';
                }
                if (isInit && oAttrNodeParent.nextSibling) {
                    return;
                }
                var currentNum = 0;
                var totalNum = 15;
                pTD = YUD.getAncestorByTagName(el, 'td');
                var totalNode = YUD.getElementsBy(function (childEl) {
                    return childEl.name == el.name;
                }, 'input', pTD);
                for (var i = 0, len = totalNode.length; i < len; i++) {
                    if (totalNode[i].checked) {
                        currentNum++;
                    }
                }
                var currentNumId = 'current-' + oAttrNodeParent.parent.index;
                var totalNumId = 'total-' + oAttrNodeParent.parent.index;
                if (get(currentNumId)) {
                    get(currentNumId).innerHTML = currentNum;
                }
                if (get(totalNumId)) {
                    get(totalNumId).innerHTML = totalNum;
                }
                if (!isInit && YAHOO.env.ua.ie != 0) {
                    setTimeout(function () {
                        var validator = oConfig.validator;
                        var rulesEl = oAttrNodeParent.parent.children[oAttrNodeParent.parent.children.length - 1].children[0].children[0]['el'].getElementsByTagName('INPUT')[0];
                        if (rulesEl && validator) {
                            validator.configData.fields[rulesEl.id].isInValidateProcess = true;
                            validator.eventFuncPool['default_blur'](null, rulesEl);
                        }
                    }, 0);
                }
            };
            this.events['drawCompleteAll'].subscribe(function () {
                var oAttrNodeParent = oAttrNameNode.parent;
                ShowCheckStatus(dCheckbox, oAttrNodeParent, true, oConfig);
                var targetId = YUD.getAncestorByTagName(oAttrNodeParent.el, 'div');
                var overkShowInstance = new AE.widget.overShow();
                var left = YUD.getX(containerEl) - YUD.getX(targetId) - 175;
                var isIE6 = (YAHOO.env.ua.ie == 6) ? true : false;
                overkShowInstance.init({
                    'targetId': targetId,
                    'contentId': div,
                    'showDelayTime': 200,
                    'hiddenDelayTime': 200,
                    'excursion': [left, 20],
                    'needMask': isIE6
                });
                overkShowInstance.afterShowDelay.subscribe(function () {
                    YUD.addClass(targetId, 'groupTabHover');
                });
                overkShowInstance.afterHiddenDelay.subscribe(function () {
                    YUD.removeClass(targetId, 'groupTabHover');
                });
            }, this, true);
            return div;
        },
        'tree': function (oAttrNameNode, containerEl, oConfig) {
            var treeDiv = document.createElement('div');
            treeDiv.id = "tree";
            var tree = new YAHOO.widget.TreeView(treeDiv);
            tree.setNodesProperty('propagateHighlightUp', true);
            tree.setNodesProperty('propagateHighlightDown', true);
            var makeBranch = function (parent, node) {
                if (node && node.children) {
                    for (var i = 0; i < node.children.length; i++) {
                        var tmpNode = new YAHOO.widget.TextNode(node.children[i].data.value, parent);
                        makeBranch(tmpNode, node.children[i]);
                    }
                }
                else {
                    return;
                }
            }
            makeBranch(tree.getRoot(), YL.merge({}, oAttrNameNode));
            tree.render();
            return treeDiv;
        },
        'interval': function (oAttrNameNode, containerEl, oConfig) {
            var els = [];
            var defConfig = {
                'maxLength': 9,
                'className': 'type-input-int',
                'style': {
                    'width': '90px'
                }
            };
            YUD.batch(oAttrNameNode.children, function (oNode) {
                var el = this.createViewByName('input', oNode, defConfig);
                var s = document.createElement('span');
                s.innerHTML = '-';
                YUD.setStyle(s, 'float', 'left');
                YUD.setStyle(s, 'margin-right', '5px');
                els.push(el);
                els.push(s);
            }, this, true);
            els.pop();
            return els;
        },
        'unit': function (oAttrNameNode, containerEl, oConfig) {
            if (oAttrNameNode.children.length > 1) {
                var defConfig = {
                    'name': this.generateName(oAttrNameNode, 'sysAttrIdAndUnit'),
                    'className': 'type-list-box',
                    'style': {
                        'width': '135px'
                    }
                };
                var dSelect = this.funcPool['createSelect'](oAttrNameNode, {
                    'select': defConfig
                });
                YUE.on(dSelect, 'change', function () {
                    this.funcPool['selectChange'](dSelect, oAttrNameNode);
                }, null, this);
                return [dSelect];
            }
            else {
                var oNode = oAttrNameNode.children[0];
                var oData = oAttrNameNode.children[0].data;
                var oNodeData = oAttrNameNode.data;
                var unitConfig = {
                    'label': {},
                    'titleText': {
                        'innerHTML': oData['value'],
                        'className': 'attr-title'
                    },
                    'input': {
                        'id': this.generateId(oNode),
                        'type': 'hidden',
                        'value': oData['value'],
                        'name': 'sysAttrIdAndUnit' + oNodeData['id']
                    },
                    'input-showType': {
                        'type': 'hidden',
                        'value': oNodeData['showType'],
                        'name': 'sysAttrShowType' + oNodeData['id']
                    }
                };
                var dLabel = this.createViewByName('label', oNode, unitConfig);
                return [dLabel];
            }
        },
        'label': function (oAttrNameNode, containerEl, oConfig) {
            var dLabel = this.createViewByName('label', oAttrNameNode);
            if (oConfig && oConfig['titleSuffix']) {
                var dSpan = dLabel.getElementsByTagName('span')[0];
                dSpan.innerHTML += oConfig['titleSuffix'];
            };
            return [dLabel];
        },
        'fix_value': function (oAttrNameNode, containerEl, oConfig) {
            var els = [];
            YUD.batch(oAttrNameNode.children, function (oNode) {
                els.push(this.createElement('SPAN', {
                    'innerHTML': oNode.data.value
                }));
            }, this, true);
            return els;
        },
        'list_box': function (oAttrNameNode, containerEl, oConfig) {
            var dSelect = this.funcPool['createSelect'](oAttrNameNode, {
                'select': {
                    'className': 'type-list-box'
                }
            });
            YUE.on(dSelect, 'change', function () {
                this.funcPool['selectChange'](dSelect, oAttrNameNode);
            }, null, this);
            return [dSelect];
        },
        'country': function (oAttrNameNode, containerEl, oConfig) {
            var defConfig = {
                'select': {
                    'name': 'contryValue',
                    'className': 'type-country'
                }
            };
            var dSelect = this.funcPool['createSelect'](oAttrNameNode, defConfig);
            var provinceRequestUrl = '';
            if (oConfig && oConfig.provinceRequestUrl) {
                provinceRequestUrl = oConfig.provinceRequestUrl;
            };
            YUE.on(dSelect, 'change', function () {
                var dOption = dSelect.options[dSelect.selectedIndex], oNode = this.getNodeByEl(dOption);
                this.funcPool['selectChange'](dSelect);
                if (oNode && oNode.children.length == 0) {
                    this.funcPool['requestProvinceData'](provinceRequestUrl, oNode);
                };
            }, null, this);
            return [dSelect];
        },
        'province': function (oAttrNameNode, containerEl, oConfig) {
            var defConfig = {
                'select': {
                    'name': 'provinceValue',
                    'className': 'attr-inline type-province'
                }
            };
            var dSelect = this.funcPool['createSelect'](oAttrNameNode, defConfig);
            YUE.on(dSelect, 'change', function () {
                this.funcPool['selectChange'](dSelect, oAttrNameNode);
            }, null, this);
            return [dSelect];
        },
        'check_box': function (oAttrNameNode, containerEl, oConfig) {
            var childNodes = oAttrNameNode.children, els = [];
            for (var i = 0, j = childNodes.length; i < j; i++) {
                var oNode = childNodes[i], dInputId = this.generateId(oNode);
                var defConfig = {
                    'label': {
                        'className': 'type-check-box-label',
                        'for': dInputId
                    },
                    'input': {
                        'id': dInputId,
                        'name': this.generateName(oNode, 'sysAttrValueIdAndValue'),
                        'type': 'CHECKBOX',
                        'className': 'type-check-box-input',
                        'value': this.funcPool['spellValueByNode'](oNode)
                    }
                };
                defConfig = YL.merge(defConfig, oConfig || {});
                var el = this.createViewByName('inputGroup', oNode, defConfig);
                els.push(el);
                var dCheckbox = el.getElementsByTagName('INPUT')[0];
                if (oAttrNameNode.parent && oAttrNameNode.parent.data) {
                    var group = 'group' + oAttrNameNode.parent.data.id;
                    dCheckbox.setAttribute('group', group);
                }
                YUE.on(dCheckbox, 'click', function (ev, o) {
                    if (!o) {
                        return null;
                    }
                    this.funcPool['checkBoxClick'](o.el);
                }, {
                    'el': dCheckbox
                }, this);
            };
            return els;
        },
        'input_int': function (oAttrNameNode, containerEl, oConfig) {
            var els = [];
            var defConfig = {
                'maxLength': 9,
                'className': 'type-input-int',
                'style': {
                    'width': '180px'
                }
            };
            YUD.batch(oAttrNameNode.children, function (oNode) {
                var el = this.createViewByName('input', oNode, defConfig);
                els.push(el);
            }, this, true);
            return els;
        },
        'input_string': function (oAttrNameNode, containerEl, oConfig) {
            var els = [];
            var defConfig = {
                'maxLength': 70,
                'className': 'type-input-string',
                'style': {
                    'width': '180px'
                }
            };
            YUD.batch(oAttrNameNode.children, function (oNode) {
                var el = this.createViewByName('input', oNode, defConfig);
                els.push(el);
            }, this, true);
            return els;
        },
        'model_numbers': function (oAttrNameNode, containerEl, oConfig) {
            var els = [];
            var defConfig = {
                'className': 'type-model-numbers',
                'style': {
                    'width': '327px',
                    'height': '65px'
                }
            };
            YUD.batch(oAttrNameNode.children, function (oNode) {
                var el = this.createViewByName('textarea', oNode, defConfig);
                els.push(el);
            }, this, true);
            return els;
        },
        'other': function (oAttrNameNode, containerEl, oConfig) {
            var els = [];
            YUD.batch(oAttrNameNode.children, function (oNode) {
                var el = this.createViewByName('input', oNode, {
                    'type': 'text',
                    'id': this.generateId(oNode),
                    'name': this.generateName(oNode, 'otherAttrContext'),
                    'value': oNode.data.value ? oNode.data.value : '',
                    'className': 'attr-inline type-other',
                    'maxLength': 70,
                    'style': {
                        'width': '180px'
                    }
                });
                els.push(el);
            }, this, true);
            return els;
        },
        'other_country': function (oAttrNameNode, containerEl, oConfig) {
            var els = [];
            YUD.batch(oAttrNameNode.children, function (oNode) {
                var el = this.createViewByName('input', oNode, {
                    'type': 'text',
                    'id': this.generateId(oNode),
                    'name': this.generateName(oNode, 'otherAttrContext'),
                    'value': oNode.data.value,
                    'className': 'attr-inline type-other-country',
                    'maxlength': 128,
                    'style': {
                        'width': '180px'
                    }
                });
                els.push(el);
            }, this, true);
            return els;
        }
    },
    showStylePool: {
        'parent_name': function (oNode, els) {
            var spanEl = YUD.getChildrenBy(els[0], function (el) {
                return (el.tagName == 'SPAN') ? true : false;
            })[0];
            var innerValue = oNode.parent.data.value;
            oNode.data.value = innerValue;
            spanEl.innerHTML = innerValue;
            return els;
        },
        'default': function (oNode, els, showStyle) {
            var spanEl = YUD.getChildrenBy(els[0], function (el) {
                return (el.tagName == 'SPAN') ? true : false;
            })[0];
            YUD.addClass(spanEl, showStyle);
            return els;
        }
    },
    funcPool: {
        _scope: null,
        createSelect: function (oAttrNameNode, oConfig) {
            var defConfig = {
                'select': {},
                'option': {}
            };
            var config = YL.merge(defConfig, oConfig || {});
            var _self = this._scope, childNodes = oAttrNameNode.children, dSelect = _self.createViewByName('select', oAttrNameNode, config['select']);
            for (var i = 0, j = childNodes.length; i < j; i++) {
                var dOption = _self.createViewByName('option', childNodes[i], config['option']);
                dSelect.options.add(dOption);
                if (childNodes[i].data['selected'] == 'true') {
                    dSelect.selectedIndex = dSelect.options.length - 1;
                };
            };
            return dSelect;
        },
        selectChange: function (dSelect) {
            var _self = this._scope, oAttrNameNode = _self.getNodeByEl(dSelect), dOption = dSelect.options[dSelect.selectedIndex], oNode = _self.getNodeByEl(dOption);
            if (!oAttrNameNode) {
                return;
            }
            var lastSelected = oAttrNameNode.getChildNodeByProperty('selected', 'true');
            if (lastSelected) {
                lastSelected.data['selected'] = 'false';
                if (lastSelected.children.length > 0) {
                    _self.removeChildNodeView(lastSelected);
                }
            };
            if (oNode) {
                oNode.data['selected'] = 'true';
                if (oNode.children.length > 0) {
                    _self.execCommandBuilderBranchByVlaue(oNode);
                }
            };
        },
        requestCountryData: function (sUrl, oNode) {
            var _self = this._scope;
            var assembleData = function (tData, oData) {
                for (var i = 0, len = oData.length; i < len; i++) {
                    if (oData[i].data.id == tData.data.id) {
                        oData[i].data.selected = tData.data.selected;
                        break;
                    }
                }
                if (tData.data.errorMsg && tData.data.errorMsg != '') {
                    oData[0].data.errorMsg = tData.data.errorMsg;
                }
                return oData;
            };
            var requestSuccess = function (o) {
                if (o.responseText) {
                    try {
                        var countryData = eval(o.responseText);
                        assembleData(oNode, countryData);
                        if (oNodeData && oNodeData.data) {
                            var o = new AE.widget.dataNode(oNodeData.data, oNode);
                            for (var i = 0, j = oNodeData.nodes.length; i < j; i++) {
                                new AE.widget.dataNode(oNodeData.nodes[i].data, o);
                            };
                            _self.execCommandBuilderBranchByVlaue(oNode);
                        };
                    }
                    catch (e) {
                    }
                }
            };
            var requestFailure = function (o) {
            };
            var callbackFunction = {
                timeout: 20000,
                success: requestSuccess,
                failure: requestFailure
            };
            if (sUrl != null) {
                if (sUrl.indexOf('?') != -1) {
                    sUrl += '&__updateTime=' + new Date().getTime();
                }
                else {
                    sUrl += '?__updateTime=' + new Date().getTime();
                }
            }
            var test = window.external.GetCountryData('POST', sUrl, "countryValueId=" + oNode.data.id);
            if (test) {
                var obj = {};
                obj.responseText = test;
                requestSuccess(obj);
            }
            //YAHOO.util.Connect.asyncRequest('POST', sUrl, callbackFunction, "countryValueId=" + oNode.data.id);
        },
        requestProvinceData: function (sUrl, oNode) {
            var _self = this._scope;
            var requestSuccess = function (o) {
                if (o.responseText) {
                    if (_self._config.MIME == 'json') {
                        var oNodeData = YAHOO.lang.JSON.parse(o.responseText);
                    }
                    else {
                        try {
                            var oNodeData = eval(o.responseText);
                        }
                        catch (e) {
                        }
                    }
                    if (oNodeData && oNodeData.data) {
                        var o = new AE.widget.dataNode(oNodeData.data, oNode);
                        var attrNameNode = oNode.parent;
                        if (attrNameNode && attrNameNode.data.rules && attrNameNode.data.rules.indexOf('required_country') != -1) {
                            if (YL.isArray(oNodeData.data.rules)) {
                                if (oNodeData.data.rules.indexOf('required_province') == -1) {
                                    oNodeData.data.rules.push('required_province');
                                };
                            }
                            else {
                                oNodeData.data.rules = ['required_province'];
                            };
                        };
                        for (var i = 0, j = oNodeData.nodes.length; i < j; i++) {
                            new AE.widget.dataNode(oNodeData.nodes[i].data, o);
                        };
                        _self.execCommandBuilderBranchByVlaue(oNode);
                    };
                }
            };
            var requestFailure = function (o) {
            };
            var callbackFunction = {
                timeout: 20000,
                success: requestSuccess,
                failure: requestFailure
            };
            if (sUrl != null) {
                if (sUrl.indexOf('?') != -1) {
                    sUrl += '&__updateTime=' + new Date().getTime();
                }
                else {
                    sUrl += '?__updateTime=' + new Date().getTime();
                }
            }
            var test = window.external.GetCountryData('POST', sUrl, "countryValueId=" + oNode.data.id);
            if (test) {
                var obj = {};
                obj.responseText = test;
                requestSuccess(obj);
            }
            //sUrl = sUrl + "&countryValueId=" + oNode.data.id;
            //YAHOO.util.Connect.asyncRequest('POST', sUrl, callbackFunction);
        },
        spellValueByNode: function (oNode) {
            return oNode.data['id'] + '-' + oNode.data['value'];
        },
        checkBoxClick: function (dCheckbox) {
            var _self = this._scope, oNode = _self.getNodeByEl(dCheckbox);
            if (oNode) {
                oNode.data['selected'] = dCheckbox.checked.toString();
                if (oNode.children.length > 0) {
                    if (oNode.data['selected'] != 'true') {
                        _self.removeChildNodeView(oNode);
                    }
                    else {
                        _self.execCommandBuilderBranchByVlaue(oNode);
                    };
                };
            };
        }
    }
};
if (AE.bom.isIE && YAHOO.env.ua.ie < 9) {
    AE.widget.attributeCombo.prototype.createElement = function (sTagName, elConfig) {
        var s = '';
        var elAttrs = ['name', 'type', 'selected', 'checked', 'for'];
        var el;
        sTagName = sTagName.toLowerCase();
        if (sTagName != 'option') {
            for (var i = 0, len = elAttrs.length; i < len; i++) {
                if (elConfig && elConfig[elAttrs[i]] != null) {
                    s += ' ' + elAttrs[i] + '="' + elConfig[elAttrs[i]] + '"';
                    delete elConfig[elAttrs[i]];
                }
            }
            if (s != '') {
                sTagName = '<' + sTagName + s + '>';
            }
            el = document.createElement(sTagName);
        }
        else
            if (elConfig && elConfig['text'] != null && elConfig['value'] != null) {
                el = new Option(elConfig['text'], elConfig['value']);
                delete elConfig['text'];
                delete elConfig['value'];
            }
        if (!el) {
            return el
        };
        if (elConfig['style']) {
            for (var fs in elConfig['style']) {
                el['style'][fs] = elConfig['style'][fs];
            };
            delete elConfig['style'];
        }
        for (var f in elConfig) {
            el[f] = elConfig[f];
        }
        return el;
    };
}
else {
    AE.widget.attributeCombo.prototype.createElement = function (sTagName, elConfig) {
        var el = document.createElement(sTagName);
        if (!el) {
            return el
        };
        if (elConfig) {
            for (var f in elConfig) {
                if (f == 'style') {
                    for (var fs in elConfig[f]) {
                        el['style'][fs] = elConfig[f][fs];
                    };
                }
                else {
                    if (elConfig[f]) {
                        el[f] = elConfig[f];
                    }
                };
            };
        };
        return el;
    }
};
AE.widget.attributeCombo.validate = function () {
    this._defConfig = {
        validator: null,
        attributeCombo: null,
        formId: '',
        ruleMaps: {}
    };
};
AE.widget.attributeCombo.validate.prototype = {
    _config: null,
    validator: null,
    comboView: null,
    _dForm: null,
    allFields: null,
    init: function (oConfig) {
        this._config = YL.merge(this._defConfig, oConfig || {});
        this._dForm = get(this._config.formId);
        this.comboView = this._config.attributeCombo;
        this.allFields = {};
        this._initValidator();
    },
    _initValidator: function (oConfig) {
        var _self = this;
        this.validator = this._config.validator;
        var validatorsPool = {
            'requiredSelect': function (val, el, params) {
                return (el.selectedIndex == 0 ? false : true);
            },
            'requiredCheckBox': function (val, el, params) {
                var dForm = _self._dForm;
                sName = el.name;
                if (!dForm) {
                    dForm = YUD.getAncestorByTagName(el, 'FORM');
                };
                if (!dForm || !dForm[sName]) {
                    return true;
                }
                var attr = el.getAttribute('group');
                if (attr) {
                    var arr = YUD.getElementsBy(function (e) {
                        return e.type.toUpperCase() == 'CHECKBOX' && e.getAttribute('group') == attr;
                    }, 'input', dForm);
                }
                else {
                    var arr = dForm[sName];
                }
                if (arr.length != null) {
                    for (var i = 0, j = arr.length; i < j; i++) {
                        if (arr[i].checked == true) {
                            return true;
                        }
                    };
                }
                else
                    if (YL.isObject(arr) && arr.checked == true) {
                        return true;
                    };
                return false;
            },
            'requiredCheckBoxGroup': function (val, el, params) {
                var dForm = _self._dForm;
                var sName = el.name;
                var flag = false, flag2 = false;
                if (!dForm) {
                    dForm = YUD.getAncestorByTagName(el, 'FORM');
                };
                if (!dForm || !dForm[sName]) {
                    return true;
                }
                var attr = el.getAttribute('group');
                if (attr) {
                    var arr = YUD.getElementsBy(function (e) {
                        return e.type.toUpperCase() == 'CHECKBOX' && e.getAttribute('group') == attr;
                    }, 'input', dForm);
                }
                else {
                    var arr = dForm[sName];
                }
                if (arr.length != null) {
                    for (var i = 0, j = arr.length; i < j; i++) {
                        if (arr[i].checked == true) {
                            flag = true;
                        }
                    };
                }
                else {
                    if (YL.isObject(arr) && arr.checked == true) {
                        flag = true;
                    };
                }
                var root = YUD.getAncestorByTagName(el, 'TD');
                arr = YUD.getElementsBy(function (e) {
                    return e.type.toUpperCase() == 'CHECKBOX' && e.name != el.name;
                }, 'input', root);
                if (arr.length != null) {
                    for (var i = 0, j = arr.length; i < j; i++) {
                        if (arr[i].checked == true) {
                            flag2 = true;
                        }
                    };
                }
                else {
                    if (YL.isObject(arr) && arr.checked == true) {
                        flag2 = true;
                    };
                }
                if (flag2) {
                    if (!flag) {
                        return false;
                    }
                    else {
                        return true;
                    }
                }
                else {
                    return true;
                }
            },
            'checkboxMax': function (val, el, params) {
                var dForm = _self._dForm;
                var num = 0;
                var sName = el.name;
                var flag = true;
                if (!dForm) {
                    dForm = YUD.getAncestorByTagName(el, 'FORM');
                };
                if (!dForm || !dForm[sName]) {
                    return flag;
                }
                var attr = el.getAttribute('group');
                if (attr) {
                    var arr = YUD.getElementsBy(function (e) {
                        return e.type.toUpperCase() == 'CHECKBOX' && e.getAttribute('group') == attr;
                    }, 'input', dForm);
                }
                else {
                    var arr = dForm[sName];
                }
                if (arr.length != null && arr.length > 0) {
                    for (var i = 0, j = arr.length; i < j; i++) {
                        if (arr[i].checked == true) {
                            num++;
                        }
                    };
                    if (parseInt(params) < num) {
                        flag = false;
                    }
                }
                return flag;
            },
            'boundLength': function (val, el, params) {
                if (val.length >= params[0] && val.length <= params[1]) {
                    return true;
                };
                return false;
            },
            'notHasHTML': function (val, el, params) {
                var re = /\<[^>]*\>/i;
                return !re.test(val);
            },
            'notHasEmail': function (val, el, params) {
                var re = /\w+(?:[-+.]\w+)*@\w+(?:[-.]\w+)*\.\w+(?:[-.]\w+)*/;
                return !re.test(val);
            },
            'notHasSemicolon': function (val, el, params) {
                if (val.indexOf(';') == -1) {
                    return true;
                }
                return false;
            },
            'notTailCharts': function (val, el, params) {
                if (val.trim() == '') {
                    return true;
                };
                var re = /[\x00-\x80]/;
                return re.test(val);
            },
            'onlyNumeric': function (val, el, params) {
                var re = /^[\d\.\+\-\u0025\u2030]*$/;
                return re.test(val);
            },
            'inEffectNumeric': function (val, el, params) {
                var re = /^([\+\-]?\d+(\.\d+)?[\u0025\u2030]?)?$/;
                return re.test(val);
            },
            'onlyEnglish': function (val, el, params) {
                var re = /^[\x00-\x7F\u2264\u2265\u2030\u00b1\u33a1\u2103\u2109\u00b0\u03bc\u03a9\u00e9\u00b3]*$/;
                return re.test(val);
            },
            'unit': function (val, el, params) {
                var flag = false;
                for (var i = 0, len = params.length; i < len; i++) {
                    var pEl = get(params[i]);
                    if (pEl && pEl.value.trim() != '' && (!YUD.hasClass(pEl, 'inputHint') || pEl.value !== pEl.title)) {
                        flag = true;
                    }
                }
                if (flag && el.value == '') {
                    return false;
                }
                else {
                    return true;
                }
            }
        };
        this._batchAddValidator(validatorsPool, this.validator);
    },
    _batchAddValidator: function (oValidatorsPool, oValidator) {
        for (var key in oValidatorsPool) {
            oValidator.addValidator(key, oValidatorsPool[key]);
        };
    },
    initField: function (el) {
        if (this._initValidateField(el)) {
            this._initErrorFromServer(el);
        };
    },
    initFields: function (els) {
        if (!els || els.length == 0) {
            return;
        };
        if (els[0].tagName == 'INPUT' && els[0].type == 'checkbox') {
            this.initField(els[0]);
        }
        else {
            for (var i = 0, j = els.length; i < j; i++) {
                this.initField(els[i]);
            };
        };
    },
    _initValidateField: function (el) {
        var oNode = this.comboView.getNodeByEl(el);
        if (!oNode) {
            return false;
        }
        var rules = this.getRulesByEl(el);
        if (!rules || rules.length == 0) {
            return false;
        };
        rules = this.formatRules(el, rules);
        if (this.addValidateFieldByRules(el, rules) == false) {
            return false;
        };
        return true;
    },
    addValidateFieldByRules: function (el, rules) {
        if (!el || !rules || rules.length == 0) {
            return;
        };
        var validatorsConfigs = null, fieldConfigs = {};
        var attrNameNode = this.comboView.getAttrNameByEl(el);
        for (var i = 0, j = rules.length; i < j; i++) {
            if (YL.isObject(rules[i])) {
                var fConfigs = this._getFieldConfigsByRuleName(el, rules[i].name);
            }
            else {
                var fConfigs = this._getFieldConfigsByRuleName(el, rules[i]);
            }
            if (fConfigs) {
                validatorsConfigs = AE.tools.depthMerge(validatorsConfigs || {}, fConfigs);
            }
        };
        if (!validatorsConfigs) {
            return false;
        }
        fieldConfigs[el.id] = this.formatParams(attrNameNode, validatorsConfigs);
        fieldConfigs[el.id] = this.formatErrorMsg(attrNameNode, validatorsConfigs);
        this.validator.addValidateField(fieldConfigs);
        this.allFields[el.id] = true;
        var o = fieldConfigs[el.id];
        if (el.tagName == 'INPUT' && el.type == 'checkbox') {
            this.addErrorMsgElement(el, 'TD');
        };
        return true;
    },
    addErrorMsgElement: function (el, sTagName, position) {
        if (!sTagName) {
            return;
        };
        var div = this.createErrorMsgElement(el);
        parentContainer = YUD.getAncestorByTagName(el, sTagName);
        if (parentContainer && div) {
            parentContainer.appendChild(div);
        };
    },
    createErrorMsgElement: function (el) {
        var sId = el.id + '-advice-error';
        if (get(sId)) {
            return;
        };
        var div = document.createElement('DIV');
        div.id = sId;
        div.className = 'board errorB';
        YUD.setStyle(div, 'display', 'none');
        return div;
    },
    delValidateField: function (fid) {
        if (!fid) {
            return;
        };
        if (this.validator.allErrorAdvisor[fid]) {
            var errorEl = get(this.validator.allErrorAdvisor[fid]);
            if (errorEl && errorEl.parentNode) {
                errorEl.parentNode.removeChild(errorEl);
            };
        };
        this.validator.delValidateField(fid);
        delete this.allFields[fid];
    },
    delValidateFieldsByEls: function (aEls) {
        if (!aEls) {
            return;
        }
        for (var i = 0, j = aEls.length; i < j; i++) {
            var b = this.allFields[aEls[i].id];
            if (aEls[i].id && this.allFields[aEls[i].id]) {
                this.delValidateField(aEls[i].id);
            };
        };
    },
    delAllValidateField: function () {
        for (var fieldId in this.allFields) {
            this.delValidateField(fieldId);
        };
    },
    formatErrorMsg: function (oAttrName, fieldConfigs) {
        var re = /\{attrName\}/g, sName = oAttrName.data.value, validators = fieldConfigs.validators;
        var reNumber = /\{attrNumber\}/g;
        if (!validators) {
            return null;
        };
        for (var ruleTitle in validators) {
            var errorMsg = validators[ruleTitle].errorMsg;
            if (errorMsg) {
                validators[ruleTitle].errorMsg = errorMsg.replace(re, sName);
                if (validators[ruleTitle].params && validators[ruleTitle].params.length > 0) {
                    validators[ruleTitle].errorMsg = errorMsg.replace(reNumber, validators[ruleTitle].params[0]);
                }
            };
        };
        return fieldConfigs;
    },
    formatParams: function (oAttrName, fieldConfigs) {
        var validators = fieldConfigs.validators;
        if (!validators) {
            return null;
        };
        if ('unit' in validators) {
            var params = new Array();
            var elId = oAttrName.parent.el.id;
            params.push(elId);
            var sibling = oAttrName.parent.previousSibling;
            while (sibling !== null) {
                elId = oAttrName.parent.previousSibling.el.id;
                params.push(elId);
                sibling = sibling.previousSibling;
            }
            validators['unit']['params'] = params;
        }
        for (var i = 0, len = oAttrName.data.rules.length; i < len; i++) {
            if (YL.isObject(oAttrName.data.rules[i]) && oAttrName.data.rules[i].name) {
                validators[oAttrName.data.rules[i].name]['params'] = oAttrName.data.rules[i].params;
            }
        }
        return fieldConfigs;
    },
    formatRules: function (el, rules) {
        var nIndex = rules.indexOf('required');
        if (nIndex != -1) {
            var oAttrName = this.comboView.getAttrNameByEl(el);
            if (oAttrName && oAttrName.data['showType']) {
                rules[nIndex] = 'required' + '_' + oAttrName.data['showType'];
            }
        };
        var nIndex = rules.indexOf('required_interval');
        if (nIndex != -1) {
            var node = this.comboView.getNodeByEl(el);
            if (node && node.nextSibling == null) {
                rules = rules.slice(0);
                rules.splice(nIndex, 1);
            }
        };
        for (var i = 0, len = rules.length; i < len; i++) {
            nIndex = -1;
            if (rules[i].indexOf) {
                nIndex = rules[i].indexOf('__');
            }
            if (nIndex != -1) {
                var arr = rules[i].split('__');
                var rulesName = arr[0];
                if (arr[1].indexOf(',') != -1) {
                    var rulesParams = arr[1].split(',');
                }
                else {
                    var rulesParams = [arr[1]];
                }
                rules[i] = {
                    'name': rulesName,
                    'params': rulesParams
                };
            }
        }
        return rules;
    },
    _getFieldConfigsByRuleName: function (el, sName) {
        if (this._config.ruleMaps[sName] && this._config.ruleMaps[sName]['validators']) {
            return YL.merge(this._config.ruleMaps[sName], {});
        };
        return null;
    },
    getRulesByEl: function (el) {
        var oNode = this.comboView.getNodeByEl(el);
        var rules;
        if (this.isAttrNameNode(oNode)) {
            rules = oNode.data.rules;
        }
        else
            if (oNode.parent) {
                rules = oNode.parent.data.rules;
            };
        return rules;
    },
    isAttrNameNode: function (oNode) {
        return (oNode.data['nodeType'] == this.comboView.NODE_TYPE.attrName);
    },
    _initErrorFromServer: function (el) {
        this.errorFromServer(el);
    },
    errorFromServer: function (el) {
        var oNode = this.comboView.getNodeByEl(el);
        if (!oNode) {
            return null;
        };
        if (el.tagName == 'SELECT') {
            oNode = oNode.children[0];
        };
        var errorMsg = oNode.data['errorMessage'];
        if (!errorMsg || errorMsg == '') {
            return;
        };
        oNode.data['errorMessage'] = '';
        if (this.validator.allErrorAdvisor[el.id]) {
            delete this.validator.allErrorAdvisor[el.id];
        };
        YUE.onDOMReady(function () {
            this.validator.errorFromServer(el.id, errorMsg);
        }, this, true);
    },
    getServerErrorMsgByEl: function (el) {
        var oNode = this.comboView.getNodeByEl(el);
        if (!oNode) {
            return null;
        };
        if (el.tagName == 'SELECT') {
            oNode = oNode.children[0];
        };
        return oNode.data['errorMessage'];
    },
    destroy: function () {
        this.delAllValidateField();
        this.allFields = {};
    }
};
if (!AE.widget.productAttribute) {
    AE.widget.productAttribute = function () {
        this._defConfig = {
            containerId: 'divAttribute',
            categoryId: 'commonCategoryIds',
            dataSrc: 'postProductAjax.php?iframe_delete=true&product_type=sourcing',
            MIME: 'script',
            loadingHintMsg: 'Loading, Please Wait...',
            failureHintMsg: 'attribute get failure',
            selectHint: '---please select---',
            inputHint: {
                inputIntHint: {
                    hintClass: 'inputHint',
                    hintMessage: 'Please enter numbers only',
                    appearOnce: true
                },
                inputStringHint: {
                    hintClass: 'inputHint',
                    hintMessage: 'Please enter details here',
                    appearOnce: true
                },
                intervalHint: {
                    hintClass: 'inputHint',
                    hintMessage: 'Numbers only',
                    appearOnce: true
                }
            },
            showTypeConfig: {
                'country': {
                    'provinceRequestUrl': 'productProvinceAjax.htm?iframe_delete=true'
                }
            },
            showTypePool: {},
            validateConfig: {
                validator: null,
                formId: '',
                ruleMaps: {}
            },
            onReadData: function (aData) {
            }
        };
        this.events = {
            'drawCompleteAll': new YAHOO.util.CustomEvent('drawCompleteAllEvent', this),
            'drawAttrValue': new YAHOO.util.CustomEvent('drawAttrValueEvent', this),
            'removeAttrView': new YAHOO.util.CustomEvent('removeAttrViewEvent', this),
            'removeElement': new YAHOO.util.CustomEvent('removeElementEvent', this),
            'onReadyData': new YAHOO.util.CustomEvent('onReadyDataEvent', this)
        };
    };
    AE.widget.productAttribute.prototype = {
        _config: {},
        _dContainer: null,
        productAttr: null,
        validate: null,
        inputHint: null,
        isDrawCompleteAll: false,
        init: function (oConfig) {
            this._config = YL.merge(this._defConfig, oConfig || {});
            this._dContainer = get(this._config.containerId);
            if (this._config.onReadData) {
                this.onReadData = this._config.onReadData;
            };
            this.events['drawCompleteAll'].subscribe(function (ev, o) {
                this.isDrawCompleteAll = true;
            }, this, true);
            this._initInputHint();
            this.build();
        },
        _initInputHint: function () {
            var oConfig = {};
            oConfig.containerId = this._config.containerId;
            oConfig = YL.merge(this._config.inputHint || {}, oConfig || {});
            this.inputHint = new AE.widget.productAttribute.inputHint();
            this.inputHint.init(oConfig);
        },
        build: function () {
            this.showLoadingHint();
            this.requestData();
        },
        requestData: function () {
       
            var dataSrc = this._config.dataSrc;
            	//  alert(dataSrc);
            	//alert('requestData');
            if (!YL.isString(dataSrc) && YL.isObject(dataSrc)) {
                this._requestSuccess({
                    'responseText': dataSrc
                });
            }
            else {
                var _self = this;
                var callbackFn = {
                    timeout: 20000,
                    success: function (o) {
                        _self._requestSuccess(o);
                    },
                    failure: function (o) {
                        try {
                            _self.onReadData([]);
                        }
                        catch (e) {
                        };
                        _self._requestFailure(o);
                    }
                };
                var url = this._config.dataSrc, qrid = this._config.categoryId;
              // alert(url);
                url = this._getUrlByParams(url, {
                    'catId': qrid,
                    '__updateTime': new Date().getTime()
                });
              //  alert(11);
                YAHOO.util.Connect.asyncRequest('GET', url, callbackFn);
            };
        },
        _getUrlByParams: function (url, oParam) {
            if (!url) {
                return '';
            }
            var sPar = '';
            for (var i in oParam) {
                sPar += i + '=' + oParam[i] + '&';
            };
            if (sPar != '') {
                sPar = sPar.substring(0, sPar.length - 1);
            };
            if (url.indexOf('?') != -1) {
                url += '&' + sPar;
            }
            else {
                url += '?' + sPar;
            };
            return url;
        },
        _requestSuccess: function (oResponse) {
            if (!oResponse.responseText) {
                return;
            }
            var oData = null;
            if (YL.isString(oResponse.responseText)) {
                if (this._config.MIME == 'json') {
                    try {
                        oData = YAHOO.lang.JSON.parse(oResponse.responseText);
                    }
                    catch (e) {
                        this._showMsg(this._config.failureHintMsg);
                        return;
                    }
                }
                else {
                    try {
                        oData = eval(oResponse.responseText);
                    }
                    catch (e) {
                        this._showMsg(this._config.failureHintMsg);
                        return;
                    }
                }
            }
            else
                if (YL.isObject(oResponse.responseText)) {
                    oData = oResponse.responseText;
                };
            if (oData) {
                oData = this.getCasheData(oData);
                this.bulidAttr(oData);
            };
        },
        getCasheData: function (oData) {
            if (oData.systemAttr) {
                var d = oData.systemAttr;
            }
            else {
                return oData;
            }
            for (var i = 0, iLen = d.length; i < iLen; i++) {
                if (d[i].data.showType == 'country') {
                    if (window.AE_GolbalCountryData) {
                        var copyCountryData = [];
                        for (var j = 0, jLen = AE_GolbalCountryData.length; j < jLen; j++) {
                            copyCountryData.push(AE.tools.depthMerge(AE_GolbalCountryData[j], {}));
                        }
                        if (!d[i].nodes || (d[i].nodes && d[i].nodes.length == 0)) {
                            d[i].nodes = [{
                                "data": {
                                    "id": ""
                                }
                            }];
                        }
                        d[i].nodes = this.assembleData(d[i].nodes[0], copyCountryData);
                    }
                    else {
                        return oData;
                    }
                }
            }
            return oData;
        },
        assembleData: function (tData, oData) {
            for (var i = 0, len = oData.length; i < len; i++) {
                if (oData[i].data.id == tData.data.id) {
                    oData[i].data.selected = tData.data.selected;
                    if (tData.nodes) {
                        oData[i].nodes = tData.nodes;
                    }
                    break;
                }
            }
            if (tData.data.errorMsg && tData.data.errorMsg != '') {
                oData[0].data.errorMsg = tData.data.errorMsg;
            }
            return oData;
        },
        _requestFailure: function (oResponse) {
            this._showMsg(this._config.failureHintMsg);
        },
        bulidAttr: function (dataSrc) {
            this._dContainer.innerHTML = '';
            var aDataSrc = [];
            if (YL.isArray(dataSrc)) {
                aDataSrc = dataSrc;
            }
            else {
                if (YL.isObject(dataSrc)) {
                    if (YL.isArray(dataSrc.fixAttr)) {
                        aDataSrc = aDataSrc.concat(dataSrc.fixAttr);
                    };
                    if (YL.isArray(dataSrc.systemAttr)) {
                        aDataSrc = aDataSrc.concat(dataSrc.systemAttr);
                    }
                };
            }
            this.onReadData(aDataSrc);
            this.events['onReadyData'].fire(aDataSrc);
            this.buildProductAttr(aDataSrc);
        },
        onReadData: function (aData) {
        },
        buildProductAttr: function (aDataSrc) {
            if (aDataSrc.length == 0) {
                this.events['drawCompleteAll'].fire();
                return false;
            }
            var defConfig = {
                'containerId': this._config.containerId,
                'showTypeConfig': this._config.showTypeConfig,
                'showTypePool': this._config.showTypePool,
                'validateConfig': this._config.validateConfig
            }
            var attrConfig = YL.merge(defConfig, {
                'dataSrc': aDataSrc,
                'MIME': this._config.MIME
            });
            this.productAttr = new AE.widget.attributeCombo();
            this.productAttr.init(attrConfig);
            this._initValidate(this.productAttr);
            var _self = this;
            this.productAttr.events['drawAttr'].subscribe(function (ev, o) {
                if (o && o.length > 0) {
                    _self.initNodeView(o[0].node);
                };
            });
            this.productAttr.events['beforeRemoveAttrView'].subscribe(function (ev, o) {
                if (o && o.length > 0) {
                    _self.removeElsField(o[0].node);
                };
            });
            this._bindProductAttrEvent(this.productAttr);
            this.productAttr.builder();
            return true;
        },
        _bindProductAttrEvent: function (oProductAttr) {
            var _self = this;
            oProductAttr.events['drawCompleteAll'].subscribe(function (ev, oArgs) {
                _self.events['drawCompleteAll'].fire(oArgs);
            });
            oProductAttr.events['drawAttrValue'].subscribe(function (ev, oArgs) {
                _self.events['drawAttrValue'].fire(oArgs[0]);
            });
            oProductAttr.events['removeAttrView'].subscribe(function (ev, oArgs) {
                _self.events['removeAttrView'].fire(oArgs[0]);
            });
            oProductAttr.events['removeElement'].subscribe(function (ev, oArgs) {
                _self.events['removeElement'].fire(oArgs[0]);
            });
        },
        _initValidate: function (attributeCombo) {
            var validateConfig = this._config.validateConfig;
            validateConfig.attributeCombo = attributeCombo;
            this.validate = new AE.widget.attributeCombo.validate;
            this.validate.init(validateConfig);
        },
        showLoadingHint: function () {
            this._showMsg(this._config.loadingHintMsg);
        },
        clearLoadingHint: function () {
            this._showMsg('');
        },
        _showMsg: function (sMsg) {
            this._dContainer.innerHTML = sMsg;
        },
        getTagEls: function (container) {
            if (this.productAttr) {
                return this.productAttr.getTagEls(container);
            }
            else {
                return [];
            }
        },
        removeElsField: function (oAttrNameNode) {
            var els = this.productAttr.getTagElsByAttrNameNode(oAttrNameNode);
            this.validate.delValidateFieldsByEls(els);
        },
        initNodeView: function (oAttrNameNode) {
            var els = this.productAttr.getTagElsByAttrNameNode(oAttrNameNode);
            YUD.batch(els, function (el) {
                this._initElStatus(el, oAttrNameNode);
            }, this, true);
            if (!this.validate) {
                return;
            };
            this.validate.initFields(els);
        },
        _initElStatus: function (el, oAttrNameNode) {
            switch (el.tagName) {
                case 'SELECT': 
                    {
                        this.addSelectHintOption(el, oAttrNameNode);
                        break;
                    }
                case 'INPUT': 
                    {
                        if (el.type == 'text') {
                            this._initInputTextStatus(el, oAttrNameNode);
                        };
                        break;
                    }
                case 'TEXTAREA': 
                    {
                        this._initInputTextStatus(el, oAttrNameNode);
                        break;
                    }
            };
        },
        addSelectHintOption: function (dSelect) {
            if (dSelect.tagName != 'SELECT') {
                return;
            };
            var hintMsg = this._config.selectHint;
            if (!hintMsg || hintMsg == '') {
                return;
            };
            var dOption = new Option();
            dOption.innerHTML = hintMsg;
            dOption.value = '';
            if (dSelect.options.length > 0) {
                dSelect.insertBefore(dOption, dSelect.options[0]);
            }
            else {
                dSelect.options.add(dOption);
            };
            if (dSelect.selectedIndex == 1) {
                var oNode = this.productAttr.getNodeByEl(dSelect.options[1]);
                if (oNode && oNode.data['selected'] != 'true') {
                    dSelect.selectedIndex = 0;
                };
            };
        },
        _initInputTextStatus: function (el, oAttrNameNode) {
            this.inputHint.addInputHint(el, oAttrNameNode);
        },
        clearAllHint: function () {
            this.inputHint.clearAllHint();
        },
        unsubscribeAll: function () {
            if (this.events) {
                for (var ev in this.events) {
                    if (this.events[ev]) {
                        this.events[ev].unsubscribeAll();
                    }
                }
            }
        },
        destroy: function () {
            if (this.productAttr) {
                this.productAttr.destroy();
            };
            if (this.validate) {
                this.validate.destroy();
            };
            this.unsubscribeAll();
            if (this._dContainer) {
                this._dContainer.innerHTML = '';
            }
        },
        _formatPostValue: function (_data) {
            var result = [];
            for (var i = 0, len = _data.length; i < len; i++) {
                var _name = 'sysAttrIdAndName=' + _data[i].data.id + '-' + _data[i].data.value;
                var _type = 'sysAttrShowType' + _data[i].data.id + '=' + _data[i].data.showType;
                var _valueName = '';
                var _value = [];
                switch (_data[i].data.showType) {
                    case 'country':
                        _valueName = 'contryValue';
                        break;
                    case 'province':
                        _valueName = 'provinceValue';
                        break;
                    case 'other_country':
                    case 'other':
                        _valueName = 'otherAttrContext' + _data[i].data.id;
                        break;
                    default:
                        _valueName = 'sysAttrValueIdAndValue' + _data[i].data.id;
                        break;
                }
                if (_data[i].data.showType == 'country' || _data[i].data.showType == 'province' || _data[i].data.showType == 'list_box') {
                    for (var j = 0, ken = _data[i].nodes.length; j < ken; j++) {
                        if (_data[i].nodes[j].data.selected == 'true') {
                            _value.push(_valueName + '=' + _data[i].nodes[j].data.id + '-' + _data[i].nodes[j].data.value);
                            if (_data[i].nodes[j].nodes) {
                                _value.push(this._formatPostValue(_data[i].nodes[j].nodes));
                            }
                            break;
                        }
                    }
                }
                else
                    if (_data[i].data.showType == 'check_box' || _data[i].data.showType == 'group_table' || _data[i].data.showType == 'group_item') {
                        for (var j = 0, ken = _data[i].nodes.length; j < ken; j++) {
                            if (_data[i].nodes[j].data.selected == 'true') {
                                _value.push(_valueName + '=' + _data[i].nodes[j].data.id + '-' + _data[i].nodes[j].data.value);
                            }
                            if (_data[i].nodes[j].nodes) {
                                _value.push(this._formatPostValue(_data[i].nodes[j].nodes));
                            }
                        }
                    }
                    else {
                        for (var j = 0, ken = _data[i].nodes.length; j < ken; j++) {
                            _value.push(_valueName + '=' + _data[i].nodes[j].data.value);
                        }
                    }
                if (_value.length == 0) {
                    _value.push(_valueName + '=');
                }
                if (_data[i].data.showType == 'other' || _data[i].data.showType == 'other_country') {
                    result.push(_value.join('&'));
                }
                else {
                    result.push(_name + '&' + _type + '&' + _value.join('&'));
                }
            }
            return result.join('&');
        },
        getUnitValueBatch: function (_data) {
            var result = [];
            for (var i = 0, len = _data.length; i < len; i++) {
                if (_data[i].nodes) {
                    if (_data[i].data.showType == 'unit') {
                        var unitSysAttrIdAndUnit;
                        if (_data[i].nodes.length == 1) {
                            var unitSysAttrIdAndUnit = 'sysAttrIdAndUnit' + _data[i].data.id + '=' + encodeURIComponent(_data[i].nodes[0].data.value);
                        }
                        else {
                            var selectVaule = '';
                            for (var unitI = 0, unitLen = _data[i].nodes.length; unitI < unitLen; unitI++) {
                                if (_data[i].nodes[unitI].data.selected == 'true') {
                                    selectVaule = _data[i].nodes[unitI].data.value;
                                }
                            }
                            unitSysAttrIdAndUnit = 'sysAttrIdAndUnit' + _data[i].data.id + '=' + selectVaule;
                        }
                        var unitSysAttrShowType = 'sysAttrShowType' + _data[i].data.id + '=unit';
                        result.push(unitSysAttrIdAndUnit);
                        result.push(unitSysAttrShowType);
                    }
                    var returnData = this.getUnitValueBatch(_data[i].nodes);
                    if (returnData.length > 0) {
                        result.push(returnData);
                    }
                }
            }
            return result.join('&');
        },
        
       
        
        
        getValue: function () {
            if (!this.productAttr) {
                return null;
            }
            var data = this.productAttr.treeData.getInitData();
            return data;
        },
        getPostValue: function () {
            if (!this.productAttr) {
                return '';
            }
            var aDataSrc = this.productAttr.treeData.getInitData();
            var data = this._formatPostValue(aDataSrc);
            var unitData = this.getUnitValueBatch(aDataSrc);
            if (unitData.length > 1) {
                return data + '&' + unitData;
            }
            else {
                return data;
            }
        },
        getContainerEl: function () {
            return this._dContainer;
        }
    };
    AE.widget.productAttribute.inputHint = function () {
        this._defConfig = {
            containerId: '',
            inputIntHint: {
                hintClass: 'inputHint',
                hintMessage: 'Please enter numbers only',
                appearOnce: true
            },
            inputStringHint: {
                hintClass: 'inputHint',
                hintMessage: 'Please enter details here',
                appearOnce: true
            }
        };
    };
    AE.widget.productAttribute.inputHint.prototype = {
        _config: null,
        init: function (oConfig) {
            this._config = YL.merge(this._defConfig, oConfig || {});
        },
        addInputHint: function (el, oAttrNameNode) {
            if (!oAttrNameNode || oAttrNameNode.data.showType == 'other') {
                return;
            };
            var oConfig;
            if (oAttrNameNode.data.showType == 'input_int') {
                oConfig = YL.merge(this._config.inputIntHint, {});
            };
            if (oAttrNameNode.data.showType == 'input_string') {
                oConfig = YL.merge(this._config.inputStringHint, {});
            };
            if (oAttrNameNode.data.showType == 'interval') {
                oConfig = YL.merge(this._config.intervalHint, {});
            };
            if (oAttrNameNode.data.showType == 'model_numbers') {
                oConfig = YL.merge(this._config.modelNumbersHint, {});
            };
            if (oConfig) {
                AE.widget.InputHint.decorate(el.id, oConfig);
            };
        },
        clearAllHint: function () {
            this.clearInputIntHint();
            this.clearInputStringHint();
            this.clearIntervalHint();
            this.clearModelNumbersHint();
        },
        clearInputIntHint: function () {
            this.clearInputHint(this._config.inputIntHint.hintClass, this._config.inputIntHint.hintMessage);
        },
        clearInputStringHint: function () {
            this.clearInputHint(this._config.inputStringHint.hintClass, this._config.inputStringHint.hintMessage);
        },
        clearIntervalHint: function () {
            this.clearInputHint(this._config.intervalHint.hintClass, this._config.intervalHint.hintMessage);
        },
        clearModelNumbersHint: function () {
            this.clearInputHint(this._config.modelNumbersHint.hintClass, this._config.modelNumbersHint.hintMessage);
        },
        clearInputHint: function (hintClass, hintMsg) {
            var aInputInt = YUD.getElementsByClassName(hintClass, 'input', this._dContainer) || [];
            YUD.batch(YUD.getElementsByClassName(hintClass, 'textarea', this._dContainer), function (el) {
                aInputInt.push(el)
            })
            YUD.batch(aInputInt, function (el) {
                var v = el.value, h = hintMsg;
                v = v.replace(/\n/g, "").replace(/\r/g, "");
                h = h.replace(/\n/g, "").replace(/\r/g, "");
                if (v == h) {
                    el.value = '';
                    YUD.removeClass(el, hintClass);
                };
            });
        }
    };
};
if (!AE.widget.userCustomAttribute) {
    AE.widget.userCustomAttribute = function () {
        this._defConfig = {
            maxNum: 10,
            minNum: 1,
            validator: null,
            containerId: 'attrContainerId',
            templateId: 'attrTemplate',
            overNumMsgId: 'trAttributeUserId',
            btnAddId: 'copyActionButton',
            btnAddDisabledClass: 'add-more-disabled',
            btnRemoveClass: 'del-custom-attr',
            attrClass: 'custom-attr-item',
            attrNameClass: 'custom-attr-name',
            attrValueClass: 'custom-attr-value',
            attrNameInputHint: {
                hintClass: 'inputHint',
                hintMessage: 'Attribute - e.g Color',
                appearOnce: true
            },
            attrValueInputHint: {
                hintClass: 'inputHint',
                hintMessage: 'Value - e.g Red',
                appearOnce: true
            },
            attrNameFieldsConfig: {},
            attrValueFieldsConfig: {}
        };
    };
    AE.widget.userCustomAttribute.prototype = {
        _config: null,
        _maxNum: 10,
        _minNum: 1,
        _num: 0,
        _autoNum: 0,
        _dOverNumMsg: null,
        _dBtnAdd: null,
        _container: null,
        validator: null,
        _attrHint: null,
        _attrNameInputName: null,
        _attrValueInputName: null,
        _allowAdd: true,
        events: null,
        init: function (oConfig) {
            this._config = YL.merge(this._defConfig, oConfig || {});
            this._initData();
            this._initValidator();
            this._initAttrHint();
            this._initEvent();
            this.autoFitElementsStatus();
        },
        _initData: function () {
        	//  alert("000");
            this._container = get(this._config.containerId);
            this._dBtnAdd = get(this._config.btnAddId);
            this._dOverNumMsg = get(this._config.overNumMsgId);
            this._num = this.countAttrNum();
            this._maxNum = this._config.maxNum;
            this._minNum = this._config.minNum;
            this._autoNum = this._num;
            this.validator = this._config.validator;
            var allAttr = this.getAllAttr();
        
            var allpost= this.getPostValue();
             //  alert(allpost);
            if (allAttr.length > 0) {
                var oAttr = this.getAttrAllElement(allAttr[0]);
                this._attrNameInputName = oAttr.attrName.name;
                this._attrValueInputName = oAttr.attrValue.name;
            };
        },
        _initAttrHint: function () {
            var oConfig = {};
            oConfig.containerId = this._config.containerId;
            oConfig.attrNameInputHint = this._config.attrNameInputHint;
            oConfig.attrValueInputHint = this._config.attrValueInputHint;
            this._attrHint = new AE.widget.userCustomAttribute.inputHint();
            this._attrHint.init(oConfig);
        },
        clearAllHint: function () {
            this._attrHint.clearAllHint();
        },
        _initEvent: function () {
            this.events = {
                'removeAttr': new YAHOO.util.CustomEvent('removeAttrEvent', this),
                'addAttr': new YAHOO.util.CustomEvent('addAttrEvent', this)
            };
            YUD.batch(this.getAllAttr(), function (dAttr) {
                this.regAttrEvent(this.getAttrAllElement(dAttr));
                var oAttr = this.getAttrAllElement(dAttr);
                this._initErrorFromServer(oAttr.attrValue);
                this._initErrorFromServer(oAttr.attrName);
            }, this, true);
            YUE.on(this._dBtnAdd, 'click', this.addAttr, null, this);
            this.events['addAttr'].subscribe(function (o) {
                this.autoFitElementsStatus();
            });
            this.events['removeAttr'].subscribe(function (o) {
                this.autoFitElementsStatus();
            });
        },
        countAttrNum: function () {
            var allAttr = this.getAllAttr();
            return allAttr.length;
        },
        getAllAttr: function () {
            return YUD.getElementsByClassName(this._config.attrClass, '*', this._container);
        },
        getValue: function () {
            var result = [];
            var allAttr = this.getAllAttr();
            var _name, _value;
            for (var i = 0; i < allAttr.length; i++) {
                _name = this.getAttrName(allAttr[i]);
                _value = this.getAttrValue(allAttr[i]);
                result.push({
                    'name': (_name.value == this._config.attrNameInputHint.hintMessage ? '' : _name.value),
                    'value': (_value.value == this._config.attrValueInputHint.hintMessage ? '' : _value.value),
                    'nameErrMsg': '',
                    'valueErrMsg': '',
                    'nameInput': _name.name,
                    'valueInput': _value.name
                });
            }
            return result;
        },
        
        getPostValueObj: function () {
            var result = [];
            var allAttr = this.getAllAttr();
            var _name, _value;
            for (var i = 0; i < allAttr.length; i++) {
                _name = this.getAttrName(allAttr[i]);
                _value = this.getAttrValue(allAttr[i]);
                result.push({
                    'name': (_name.value == this._config.attrNameInputHint.hintMessage ? '' : _name.value),
                    'value': (_value.value == this._config.attrValueInputHint.hintMessage ? '' : _value.value)
                });
            }
            return result;
        },
        getPostValue: function () {
            var result = [];
            var _value = this.getValue();
            for (var i = 0; i < _value.length; i++) {
                result.push(_value[i].nameInput + '=' + _value[i].name + '&' + _value[i].valueInput + '=' + _value[i].value);
            }
            return result.join('&');
        },
        setValue: function (value) {
            var allAttr = this.getAllAttr();
            if (!value || value.length < 1) {
                this.clearAttr();
                return;
            }
            for (var i = 0; i < allAttr.length; i++) {
                this.removeAttrEvent(this.getAttrAllElement(allAttr[i]));
                allAttr[i].parentNode.removeChild(allAttr[i]);
                this._num--;
            }
            for (var i = 0; i < value.length; i++) {
                this._allowAdd = true;
                this.addAttr();
            }
            allAttr = this.getAllAttr();
            var _name, _value;
            for (var i = 0; i < allAttr.length; i++) {
                _name = this.getAttrName(allAttr[i]);
                _value = this.getAttrValue(allAttr[i]);
                _name.value = value[i].name;
                _value.value = value[i].value;
                YUD.removeClass(_name, this._config.attrNameInputHint.hintClass);
                YUD.removeClass(_value, this._config.attrValueInputHint.hintClass);
            }
        },
        getAttrByEl: function (dEl) {
            if (!dEl) {
                return null;
            };
            return YUD.getAncestorByTagName(dEl, 'TR');
        },
        addAttr: function () {
            if (!this._allowAdd) {
                return;
            };
            var dAttr = this.cloneAttr();
            if (dAttr) {
                this._container.appendChild(dAttr);
                this.regAttrEvent(this.getAttrAllElement(dAttr));
                this._num++;
                this.events['addAttr'].fire({
                    'attrNum': this._num,
                    'attrItem': dAttr
                });
            };
        },
        cloneAttr: function () {
            var dAttr = get(this._config.templateId);
            if (!dAttr) {
                return null;
            }
            var dClone = dAttr.cloneNode(true);
            this._initCloneAttrEls(dClone);
            return dClone;
        },
        _initCloneAttrEls: function (dAttr) {
            if (!dAttr) {
                return;
            };
            dAttr.id = '';
            YUD.setStyle(dAttr, 'display', '');
            YUD.addClass(dAttr, this._config.attrClass);
            var oAttr = this.getAttrAllElement(dAttr);
            if (oAttr.attrName) {
                oAttr.attrName.id = this.generateId();
                oAttr.attrName.name = this._attrNameInputName;
            };
            if (oAttr.attrValue) {
                oAttr.attrValue.id = this.generateId();
                oAttr.attrValue.name = this._attrValueInputName;
            };
        },
        generateId: function (sPrefix) {
            if (!sPrefix) {
                sPrefix = 'custom-attr';
            };
            this._autoNum++;
            return sPrefix + '-' + this._autoNum;
        },
        getAttrAllElement: function (dAttr) {
            var attrElement = {
                attrName: this.getAttrName(dAttr),
                attrValue: this.getAttrValue(dAttr),
                btnRemove: this.getBtnRemove(dAttr)
            };
            return attrElement;
        },
        regAttrEvent: function (oAttr) {
            if (!oAttr.attrName.id) {
                oAttr.attrName.id = this.generateId();
            };
            if (!oAttr.attrValue.id) {
                oAttr.attrValue.id = this.generateId();
            };
            this.addValidateField(oAttr.attrName, this._config.attrNameFieldsConfig);
            this.addValidateField(oAttr.attrValue, this._config.attrValueFieldsConfig);
            this._attrHint.addAttrHint(oAttr);
            YUE.on(oAttr.btnRemove, 'click', this.removeAttr, {
                'el': oAttr.btnRemove
            }, this);
        },
        addValidateField: function (el, fieldsConfig) {
            var oConfig = {};
            oConfig[el.id] = AE.tools.depthMerge(fieldsConfig, {});
            this.validator.addValidateField(oConfig);
        },
        removeAttr: function (ev, o) {
            if (!o || this._num <= this._minNum) {
                return false;
            };
            var dBtn = o.el;
            if (dBtn) {
                var dAttr = this.getAttrByEl(dBtn);
                if (dAttr) {
                    this.removeAttrEvent(this.getAttrAllElement(dAttr));
                    dAttr.parentNode.removeChild(dAttr);
                    this._num--;
                    this.events['removeAttr'].fire({
                        'attrNum': this._num,
                        'attrItem': dAttr
                    });
                };
            };
        },
        removeAttrEvent: function (oAttr) {
            if (oAttr.attrName) {
                this.validator.delValidateField(oAttr.attrName.id);
            };
            if (oAttr.attrValue) {
                this.validator.delValidateField(oAttr.attrValue.id);
            };
            if (oAttr.btnRemove) {
                YUE.removeListener(oAttr.btnRemove);
            };
        },
        clearAttr: function () {
            var allAttr = this.getAllAttr();
            for (var i = allAttr.length - 1; i > 0; i--) {
                this.removeAttrEvent(this.getAttrAllElement(allAttr[i]));
                allAttr[i].parentNode.removeChild(allAttr[i]);
                this._num--;
            }
            var _name = this.getAttrName(allAttr[0]);
            var _value = this.getAttrValue(allAttr[0]);
            _name.value = this._config.attrNameInputHint.hintMessage;
            _value.value = this._config.attrValueInputHint.hintMessage;
            if (!YUD.hasClass(_name, this._config.attrNameInputHint.hintClass)) {
                YUD.addClass(_name, this._config.attrNameInputHint.hintClass);
            }
            if (!YUD.hasClass(_value, this._config.attrValueInputHint.hintClass)) {
                YUD.addClass(_value, this._config.attrValueInputHint.hintClass);
            }
        },
        getAllAttrName: function () {
            var allAttrName = YUD.getElementsByClassName(this._config.attrNameClass, '*', this._container);
            var templateAttrName = this.getAttrName(this._config.attrNameClass, '*', this._config.templateId);
            if (allAttrName.length > 0 && allAttrName[0] == templateAttrName) {
                allAttrName.shift();
            };
            return allAttrName;
        },
        getAttrName: function (containerEl) {
            return this.getElementByClassName(this._config.attrNameClass, 'input', containerEl);
        },
        getAttrValue: function (containerEl) {
            return this.getElementByClassName(this._config.attrValueClass, 'input', containerEl);
        },
        getBtnRemove: function (containerEl) {
            return this.getElementByClassName(this._config.btnRemoveClass, '*', containerEl)
        },
        getElementByClassName: function (sClassName, sTag, dRoot, fnApply) {
            var els = YUD.getElementsByClassName(sClassName, sTag, dRoot, fnApply);
            return (els.length == 0 ? null : els[0]);
        },
        autoFitElementsStatus: function () {
            this._fitBtnAddStatus();
            this._fitRemoveBtnStatus();
            this._fitOverNumHintMsgStatus();
        },
        _fitBtnAddStatus: function () {
            if (this._num >= this._maxNum) {
                this._lockBtnAdd();
            }
            else {
                this._unLockBtnAdd();
            };
        },
        _lockBtnAdd: function () {
            this._allowAdd = false;
            if (!YUD.hasClass(this._dBtnAdd, this._config.btnAddDisabledClass)) {
                YUD.addClass(this._dBtnAdd, this._config.btnAddDisabledClass);
            };
        },
        _unLockBtnAdd: function () {
            this._allowAdd = true;
            if (YUD.hasClass(this._dBtnAdd, this._config.btnAddDisabledClass)) {
                YUD.removeClass(this._dBtnAdd, this._config.btnAddDisabledClass);
            };
        },
        unLockAdd: function () {
            this._unLockBtnAdd();
        },
        _fitRemoveBtnStatus: function () {
            var allAttr = this.getAllAttr();
            var btn;
            for (var i = 0, len = allAttr.length; i < len; i++) {
                btn = this.getBtnRemove(allAttr[i]);
                if (this._num <= this._minNum) {
                    YUD.setStyle(btn, 'display', 'none');
                }
                else {
                    YUD.setStyle(btn, 'display', '');
                }
            }
        },
        _fitOverNumHintMsgStatus: function () {
            if (this._num <= this._maxNum) {
                if (YUD.getStyle(this._dOverNumMsg, 'display') != 'none') {
                    YUD.setStyle(this._dOverNumMsg, 'display', 'none');
                };
            }
            else {
                if (YUD.getStyle(this._dOverNumMsg, 'display') == 'none') {
                    YUD.setStyle(this._dOverNumMsg, 'display', '');
                };
            }
        },
        isOverNumber: function () {
            return (this._num > this._maxNum);
        },
        validateOverNumber: function () {
            if (this.isOverNumber()) {
                if (this._dOverNumMsg.style.display == 'none') {
                    YUD.setStyle(this._dOverNumMsg, 'display', '');
                };
                this.scrollToField(this._dOverNumMsg);
                return false;
            }
            else {
                if (this._dOverNumMsg.style.display != 'none') {
                    YUD.setStyle(this._dOverNumMsg, 'display', 'none');
                };
                return true;
            };
        },
        scrollToField: function (el) {
            var elOffsetHeight = el.offsetHeight;
            var elY = YUD.getY(el);
            var clientHeight = YUD.getClientHeight();
            var documentScrollTop = YUD.getDocumentScrollTop();
            if (documentScrollTop < elY + elOffsetHeight - clientHeight || documentScrollTop > elY) {
                window.scroll(0, elY - 15);
            }
        },
        _initValidator: function (oConfig) {
            var _self = this;
            var validatorsPool = {
                'onlyEnglishByUserAttr': function (val, el, params) {
                    if (_self._attrHint.hasHintMsg(el)) {
                        val = '';
                    }
                    else {
                        val = val.trim();
                    };
                    var re = /^[\x00-\x7F\u2264\u2265\u2030\u00b1\u33a1\u2103\u2109\u00b0\u03bc\u03a9\u00e9\u00b3]*$/;
                    return re.test(val);
                },
                'notRepeatAttrName': function (val, el, params) {
                    if (_self._attrHint.hasHintMsg(el)) {
                        val = '';
                    }
                    else {
                        val = val.trim();
                    };
                    if (val == '') {
                        return true;
                    };
                    var allAttrName = _self.getAllAttrName();
                    for (var i = 0, j = allAttrName.length; i < j; i++) {
                        if (allAttrName[i].value.trim() == val && el != allAttrName[i]) {
                            return false;
                        };
                    };
                    return true;
                },
                'isAttrValueSync': function (val, el, params) {
                    var dAttr = _self.getAttrByEl(el), oAttr = _self.getAttrAllElement(dAttr), attrValueValue = oAttr.attrValue.value.trim(), attrNameValue = oAttr.attrName.value.trim();
                    if (_self._attrHint.hasHintMsg(oAttr.attrName)) {
                        attrNameValue = '';
                    };
                    if (_self._attrHint.hasHintMsg(oAttr.attrValue)) {
                        attrValueValue = '';
                    };
                    if (attrNameValue != '' && attrValueValue == '') {
                        oAttr.attrValue.setAttribute('_attrSync', 'false');
                        return false;
                    };
                    oAttr.attrValue.setAttribute('_attrSync', 'true');
                    var attrSync = oAttr.attrName.getAttribute('_attrSync');
                    if (attrNameValue == '' && attrValueValue != '' || attrSync != 'true') {
                        _self.validator.configData.fields[oAttr.attrName.id].isInValidateProcess = true;
                        _self.validator.eventFuncPool['default_blur'](null, oAttr.attrName);
                    };
                    return true;
                },
                'isAttrNameSync': function (val, el, params) {
                    var dAttr = _self.getAttrByEl(el), oAttr = _self.getAttrAllElement(dAttr), attrValueValue = oAttr.attrValue.value.trim(), attrNameValue = oAttr.attrName.value.trim();
                    if (_self._attrHint.hasHintMsg(oAttr.attrName)) {
                        attrNameValue = '';
                    };
                    if (_self._attrHint.hasHintMsg(oAttr.attrValue)) {
                        attrValueValue = '';
                    };
                    if (attrValueValue != '' && attrNameValue == '') {
                        oAttr.attrName.setAttribute('_attrSync', 'false');
                        return false;
                    };
                    oAttr.attrName.setAttribute('_attrSync', 'true');
                    if ((attrValueValue == '' && attrNameValue == '') || (attrValueValue != '' && attrNameValue != '')) {
                        var attrSync = oAttr.attrValue.getAttribute('_attrSync');
                        if (attrSync == 'false') {
                            _self.validator.configData.fields[oAttr.attrValue.id].isInValidateProcess = true;
                            _self.validator.eventFuncPool['default_blur'](null, oAttr.attrValue);
                        }
                    };
                    return true;
                }
            };
            this._batchAddValidator(validatorsPool, this.validator);
        },
        _batchAddValidator: function (oValidatorsPool, oValidator) {
            for (var key in oValidatorsPool) {
                oValidator.addValidator(key, oValidatorsPool[key]);
            };
        },
        _initErrorFromServer: function (el) {
            var errorMsg = el.getAttribute('_errorMessage');
            if (errorMsg && errorMsg != '') {
                this.validator.errorFromServer(el.id, errorMsg);
            };
        }
    };
    AE.widget.userCustomAttribute.inputHint = function () {
        this._defConfig = {
            containerId: '',
            attrNameInputHint: {
                hintClass: 'inputHint',
                hintMessage: 'Attribute - e.g Color',
                appearOnce: true
            },
            attrValueInputHint: {
                hintClass: 'inputHint',
                hintMessage: 'Value - e.g Red',
                appearOnce: true
            }
        };
    };
    AE.widget.userCustomAttribute.inputHint.prototype = {
        _config: null,
        _dContainer: null,
        init: function (oConfig) {
            this._config = YL.merge(this._defConfig, oConfig || {});
            this._dContainer = get(this._config.containerId);
        },
        addAttrHint: function (oAttrElement) {
            if (oAttrElement && oAttrElement.attrName && !YUD.hasClass(oAttrElement.attrName, this._config.attrNameInputHint.hintClass) && (oAttrElement.attrName.value == '' || oAttrElement.attrName.value == this._config.attrNameInputHint.hintMessage)) {
                AE.widget.InputHint.decorate(oAttrElement.attrName.id, this._config.attrNameInputHint);
            };
            if (oAttrElement && oAttrElement.attrValue && !YUD.hasClass(oAttrElement.attrValue, this._config.attrNameInputHint.hintClass) && (oAttrElement.attrValue.value == '' || oAttrElement.attrValue.value == this._config.attrValueInputHint.hintMessage)) {
                AE.widget.InputHint.decorate(oAttrElement.attrValue.id, this._config.attrValueInputHint);
            };
        },
        clearAllHint: function () {
            this.clearAttrNameHint();
            this.clearAttrValueHint();
        },
        clearAttrNameHint: function () {
            this.clearInputHint(this._config.attrNameInputHint.hintClass, this._config.attrNameInputHint.hintMessage);
        },
        clearAttrValueHint: function () {
            this.clearInputHint(this._config.attrValueInputHint.hintClass, this._config.attrValueInputHint.hintMessage);
        },
        clearInputHint: function (hintClass, hintMsg) {
            var aInputInt = YUD.getElementsByClassName(hintClass, 'input', this._dContainer);
            YUD.batch(aInputInt, function (el) {
                if (el.value == hintMsg) {
                    el.value = '';
                    YUD.removeClass(el, hintClass);
                };
            });
        },
        hasHintMsg: function (el) {
            if (el.value == '') {
                return false;
            }
            var hintClass = this._config.attrNameInputHint.hintClass, attrNameHintMsg = this._config.attrNameInputHint.hintMessage, attrValueHintMsg = this._config.attrValueInputHint.hintMessage;
            if (YUD.hasClass(el, hintClass)) {
                if (attrNameHintMsg == el.value || attrValueHintMsg == el.value) {
                    return true;
                };
            };
            return false;
        }
    };
};


/*
*
*客户端验证代码
*/
var productFormClient = {
    focusOnError: true,
    validateImmediate: true,
    serviceIMContainerId: 'serviceIMContainer',
    tipsAdviceContainerClass: 'fieldTipsContainer',
    tipsAdviceClass: 'fieldTips',
    tipsAdviceMsgClass: 'fieldTipsMsg',
    errorAdviceContainerClass: 'fieldErrorContainer',
    errorAdviceClass: 'board errorB long',
    errorAdviceMsgClass: 'fieldErrorMsg',
    fieldSuccessClass: 'fieldSuccess',
    fieldFailClass: 'fieldFail',
    ifNeedValidate: true,
    fields: {
        'productName': {
            validators: {
                require: {
                    ruleName: 'notTrimedEmpty',
                    params: [],
                    errorMsg: I18n.pr_name_none
                },
                legalName: {
                    ruleName: 'onlyEnglishHint',
                    params: ['alert'],
                    errorMsg: I18n.pr_common_noenglish
                },
                minLength: {
                    ruleName: 'minLength',
                    params: [1],
                    errorMsg: I18n.ProductNameValidator
                },
                maxLength: {
                    ruleName: 'maxLength',
                    params: [128],
                    errorMsg: I18n.ProductNameValidator
                }
            }
        },
        'productKeyword': {
            validators: {
                require: {
                    ruleName: 'notTrimedEmpty',
                    params: [],
                    errorMsg: I18n.pr_keyword_none
                },
                minLength: {
                    ruleName: 'minLength',
                    params: [1],
                    errorMsg: I18n.pr_keyword_length
                },
                maxLength: {
                    ruleName: 'allKeywordsMaxLength',
                    params: [256],
                    errorMsg: I18n.pr_keyword_length
                },
                legalNameA: {
                    ruleName: 'onlyEnglishHint',
                    params: ['alert'],
                    errorMsg: I18n.pr_common_noenglish
                },
                legalNameB: {
                    ruleName: 'noSpecialChars',
                    params: ['alert'],
                    errorMsg: I18n.pr_common_invalid_char
                }
            }
        },
        'keywords2': {
            validators: {
                maxLength: {
                    ruleName: 'allKeywordsMaxLength',
                    params: [256],
                    errorMsg: I18n.pr_keyword_length
                },
                legalNameA: {
                    ruleName: 'onlyEnglishHint',
                    params: ['alert'],
                    errorMsg: I18n.pr_common_noenglish
                },
                legalNameB: {
                    ruleName: 'noSpecialChars',
                    params: ['alert'],
                    errorMsg: I18n.pr_common_invalid_char
                }
            }
        },
        'keywords3': {
            validators: {
                maxLength: {
                    ruleName: 'allKeywordsMaxLength',
                    params: [256],
                    errorMsg: I18n.pr_keyword_length
                },
                legalNameA: {
                    ruleName: 'onlyEnglishHint',
                    params: ['alert'],
                    errorMsg: I18n.pr_common_noenglish
                },
                legalNameB: {
                    ruleName: 'noSpecialChars',
                    params: ['alert'],
                    errorMsg: I18n.pr_common_invalid_char
                }
            }
        },
        'commonCategoryName': {
            validators: {
                require: {
                    ruleName: 'notTrimedCategorEmpty',
                    params: [],
                    errorMsg: I18n.pr_category_none
                }
            }
        },
        'summary': {
            validators: {
                require: {
                    ruleName: 'notTrimedEmpty',
                    params: [],
                    errorMsg: I18n.pr_summary_none
                },
                minLength: {
                    ruleName: 'minLength',
                    params: [4],
                    errorMsg: I18n.pr_summary_length
                },
                maxLength: {
                    ruleName: 'maxLength',
                    params: [128],
                    errorMsg: I18n.pr_summary_length
                },
                maxLines: {
                    ruleName: 'maxLines',
                    params: [5],
                    errorMsg: I18n.pr_summary_lines
                },
                legalName: {
                    ruleName: 'onlyEnglishHint',
                    params: ['alert'],
                    errorMsg: I18n.pr_common_noenglish
                },
                hasNotEmail: {
                    ruleName: 'notRegexp',
                    params: ['/\\w+(?:[-+.]\\w+)*@\\w+(?:[-.]\\w+)*\\.\\w+(?:[-.]\\w+)*/'],
                    errorMsg: I18n.pr_summary_no_email
                }
            }
        },
        'productDescription': {
            validators: {
                maxLength: {
                    ruleName: 'maxLength',
                    params: [8000],
                    errorMsg: I18n.pr_summary_length
                },
                legalNameA: {
                    ruleName: 'regexp',
                    params: ['/^[\\x00-\\xFF]*$/'],
                    errorMsg: I18n.pr_common_char
                },
                legalNameB: {
                    ruleName: 'regexpDescription',
                    params: [],
                    errorMsg: I18n.descriptions_includeEmailAndWebSiteInfo
                }
            }
        },
        'priceRangeMin': {
            validators: {
                legalNameA: {
                    ruleName: 'regexp',
                    params: ['/^[\\x00-\\x7F]*$/'],
                    errorMsg: I18n.ProductpriceRangeMaxValidator
                },
                legalNameB: {
                    ruleName: 'regexp',
                    params: ['/^[0-9,]*\\.?[0-9]*$/'],
                    errorMsg: I18n.ProductpriceRangeMaxValidator
                },
                legalNameC: {
                    ruleName: 'priceArea',
                    params: [0, 999999999],
                    errorMsg: I18n.minProductPriceRangeValidator
                },
                isPriceMax: {
                    ruleName: 'isPriceRangeMax',
                    params: [],
                    errorMsg: I18n.priceRangeSecondLessFirst
                },
                resetFollowedElEmpty: {
                    ruleName: 'resetFollowedElEmpty',
                    params: ['moneyType', 'priceUnit'],
                    errorMsg: ''
                }
            }
        },
        'priceRangeMax': {
            validators: {
                legalNameA: {
                    ruleName: 'regexp',
                    params: ['/^[\\x00-\\x7F]*$/'],
                    errorMsg: I18n.ProductpriceRangeMinValidator
                },
                legalNameB: {
                    ruleName: 'regexp',
                    params: ['/^[0-9,]*\\.?[0-9]*$/'],
                    errorMsg: I18n.ProductpriceRangeMinValidator
                },
                legalNameC: {
                    ruleName: 'priceArea',
                    params: [0, 999999999],
                    errorMsg: I18n.maxProductPriceRangeValidator
                },
                isPriceMax: {
                    ruleName: 'isPriceRangeMax',
                    params: [],
                    errorMsg: I18n.priceRangeSecondLessFirst
                },
                resetFollowedElEmpty: {
                    ruleName: 'resetFollowedElEmpty',
                    params: ['moneyType', 'priceUnit'],
                    errorMsg: ''
                }
            }
        },
        'moneyType': {
            validators: {
                selection: {
                    ruleName: 'isFollowedElEmpty',
                    params: ['priceRangeMin', 'priceRangeMax'],
                    errorMsg: I18n.moneyTypeMustChoose
                }
            }
        },
        'priceUnit': {
            validators: {
                selection: {
                    ruleName: 'isFollowedElEmpty',
                    params: ['priceRangeMin', 'priceRangeMax'],
                    errorMsg: I18n.orderUnitMustChoose
                }
            }
        },
        'port': {
            validators: {
                legalNameB: {
                    ruleName: 'regexp',
                    params: ['/^[\\x00-\\x7F]*$/'],
                    errorMsg: I18n.ProductPortValidator
                }
            }
        },
        'paymentMethodOtherDesc': {
            validators: {
                paymentNotTrimedEmpty: {
                    ruleName: 'paymentNotTrimedEmpty',
                    params: [],
                    errorMsg: I18n.product_payment_need
                },
                legalName: {
                    ruleName: 'regexp',
                    params: ['/^[\\x00-\\x7F]*$/'],
                    errorMsg: I18n.pr_common_char
                },
                maxLength: {
                    ruleName: 'maxLength',
                    params: [128],
                    errorMsg: I18n.ProductPaymentMethodOtherLengthValidator
                }
            }
        },
        'minOrderQuantity': {
            validators: {
                legalName: {
                    ruleName: 'regexp',
                    params: ['/^[0-9,]*\\.?[0-9]*$/'],
                    errorMsg: I18n.ProductMinOrderQuantityValidator
                },
                maxLength: {
                    ruleName: 'maxLength',
                    params: [64],
                    errorMsg: I18n.ProductMinOrderQuantityLengthValidator
                },
                resetFollowedElEmpty: {
                    ruleName: 'resetFollowedElEmpty',
                    params: ['minOrderUnit'],
                    errorMsg: ''
                }
            }
        },
        'minOrderUnit': {
            validators: {
                selection: {
                    ruleName: 'isFollowedElEmpty',
                    params: ['minOrderQuantity'],
                    errorMsg: I18n.orderUnitMustChoose
                }
            }
        },
        'minOrderOther': {
            validators: {
                legalName: {
                    ruleName: 'regexp',
                    params: ['/^[\\x00-\\x7F]*$/'],
                    errorMsg: I18n.pr_common_char
                },
                maxLength: {
                    ruleName: 'maxLength',
                    params: [64],
                    errorMsg: I18n.ProductMinOrderOtherLengthValidator
                }
            }
        },
        'supplyQuantity': {
            validators: {
                legalName: {
                    ruleName: 'regexp',
                    params: ['/^[0-9,]*\\.?[0-9]*$/'],
                    errorMsg: I18n.ProductSupplyQuantityValidator
                },
                maxLength: {
                    ruleName: 'maxLength',
                    params: [64],
                    errorMsg: I18n.ProductSupplyQuantityLengthValidator
                },
                resetFollowedElEmpty: {
                    ruleName: 'resetFollowedElEmpty',
                    params: ['supplyUnit', 'supplyPeriod'],
                    errorMsg: ''
                }
            }
        },
        'supplyUnit': {
            validators: {
                selection: {
                    ruleName: 'isFollowedElEmpty',
                    params: ['supplyQuantity'],
                    errorMsg: I18n.orderUnitMustChoose
                }
            }
        },
        'supplyPeriod': {
            validators: {
                selection: {
                    ruleName: 'isFollowedElEmpty',
                    params: ['supplyQuantity'],
                    errorMsg: I18n.pr_sp_supp
                }
            }
        },
        'supplyOther': {
            validators: {
                legalName: {
                    ruleName: 'regexp',
                    params: ['/^[\\x00-\\x7F]*$/'],
                    errorMsg: I18n.pr_common_char
                },
                maxLength: {
                    ruleName: 'maxLength',
                    params: [64],
                    errorMsg: I18n.ProductSupplyOtherLengthValidator
                }
            }
        },
        'consignmentTerm': {
            validators: {
                maxLength: {
                    ruleName: 'maxLength',
                    params: [64],
                    errorMsg: I18n.product_consignmentTerm_maxlen
                },
                legalName: {
                    ruleName: 'regexp',
                    params: ['/^[\\x00-\\x7F]*$/'],
                    errorMsg: I18n.pr_common_char
                }
            }
        },
        'packagingDesc': {
            validators: {
                maxLength: {
                    ruleName: 'maxLength',
                    params: [512],
                    errorMsg: I18n.product_packagingDesc_maxlen
                },
                legalName: {
                    ruleName: 'regexp',
                    params: ['/^[\\x00-\\x7F]*$/'],
                    errorMsg: I18n.pr_common_char
                },
                legalNameB: {
                    ruleName: 'notRegexp',
                    params: ['/\\w+(?:[-+.]\\w+)*@\\w+(?:[-.]\\w+)*\\.\\w+(?:[-.]\\w+)*/'],
                    errorMsg: I18n.packagingDesc_includeEmail
                }
            }
        }
    }
}
var uedclient = new AE.form.validator();
uedclient.init('productFormClient', productFormClient);
uedclient.initComplete = new YAHOO.util.CustomEvent("initCompleteEvent", uedclient);
var hasErrObj = [];
var hasActionStyle = false;
uedclient.customEvent.onFeildErrFire.subscribe(function (ev, args) {
    hasErrObj.push(args[2].id);
});
uedclient.addDisplayFunc('showErrorMsg_showMsgFollowOtherObj', function (el, advice, msg, ruleName) {
    if (typeof (postClickData) !== 'undefined' && postClickData !== null && typeof (ruleName) !== 'undefined' && ruleName !== null) {
        var data = clone(postClickData);
        data['action_name'] = 'js_fail_' + el.id;
        data['action_result'] = ruleName;
        postClickStat(data);
    }
    if (msg !== null) {
        var errorAdviceMsgClass = uedclient.configReader(el, 'errorAdviceMsgClass');
        var msgbox = YUD.getElementsByClassName(errorAdviceMsgClass, '*', advice)[0] || advice;
        msgbox.innerHTML = msg;
        setTimeout(function () {
            YUD.setStyle(advice, 'display', 'block');
        }, 0);
    }
});
uedclient.addDisplayFunc('getAdvice_getError', function (el) {
    var id = el.id;
    var advice;
    if (id in uedclient.allErrorAdvisor) {
        advice = uedclient.allErrorAdvisor[id];
    }
    else {
        var aid = (el.id) + '-advice-error';
        advice = get(aid);
        if (!advice) {
            var errorAdviceClass = uedclient.configReader(el, 'errorAdviceClass');
            var fieldStruct = uedclient.configReader(el, 'fieldStruct');
            advice = document.createElement('div');
            YUD.addClass(advice, errorAdviceClass);
            if (uedclient.configData.fields[el.id].errorAdviceContainerClass) {
                container.appendChild(advice);
            }
            else
                if (fieldStruct) {
                    switch (fieldStruct) {
                        case 'productAttribute':
                            el.parentNode.appendChild(advice, el);
                            break;
                        case 'userAttribute':
                            el.parentNode.parentNode.appendChild(advice, el);
                            break;
                    }
                }
                else {
                    switch (el.type.toLowerCase()) {
                        case 'checkbox':
                        case 'radio':
                            el.parentNode.appendChild(advice, el);
                            break;
                        default:
                            var ele = YUD.getAncestorByTagName(el, 'TD');
                            if (ele) {
                                ele.appendChild(advice, el);
                            }
                            break;
                    }
                }
            advice.id = aid;
        }
        uedclient.allErrorAdvisor[id] = advice;
    }
    YUD.setStyle(advice, 'display', 'none');
    return advice;
});
uedclient.addDisplayFunc('repositionAdvice', function () {
});
uedclient.addValidator('allowedChar', function (val, el, params) {
    for (i = 0; i < val.length; i++) {
        var ch = val.charCodeAt(i);
        if (ch > 127 || ch == 59 || ch == 44) {
            return false;
        }
    }
    return true;
});
uedclient.addValidator('validWordsNum', function (val, el, params) {
    var arr = val.split(params[0]);
    return arr.length <= params[1];
});
uedclient.addValidator('allKeywordsMaxLength', function (val, el, params) {
    var sMainKeywords = '', sKeywords2 = '', sKeywords3 = '', sAllKeywords = '';
    if (get("productKeyword")) {
        sMainKeywords = get("productKeyword").value;
    }
    if (get("keywords2")) {
        sKeywords2 = get("keywords2").value;
    }
    if (get("keywords3")) {
        sKeywords3 = get("keywords3").value;
    }
    sAllKeywords = sMainKeywords + sKeywords2 + sKeywords3;
    return sAllKeywords.length <= params[0];
});
uedclient.addValidator('onlyEnglishHint', function (val, el, params) {
    var re = /[^\x00-\xFF]+/;
    var tagClass = params[0] || 'alert';
    var obj = uedclient;
    var msg;
    if (val.trim() != '' && re.test(val)) {
        val = AE.widget.encodeConvert.encode(val, 'punctuationToEnglish');
        el.value = val;
    };
    var arr = re.exec(val);
    if (arr && arr.length) {
        try {
            var oFieldConfig = obj.configReader(el, 'validators');
            for (x in oFieldConfig) {
                if (oFieldConfig[x]['ruleName'] == 'onlyEnglishHint') {
                    msg = oFieldConfig[x]['errorMsg'];
                    break;
                }
            }
        }
        catch (e) {
            msg = '';
        }
        var errContent = AE.widget.encodeConvert.encode(arr[0], 'stringToHTML');
        var index = msg.indexOf('<span class="' + tagClass + '">');
        if (index != -1) {
            msg = msg.substring(0, index);
        }
        msg = msg + '<span class="' + tagClass + '">' + errContent + '</span>';
        if (msg != '') {
            oFieldConfig[x]['errorMsg'] = msg;
        }
        return false;
    }
    return true;
});
uedclient.addValidator('noSpecialChars', function (val, el, params) {
    var obj = uedclient, matches = /[,;]+/.exec(val), tagClass = params[0] || 'alert';
    if (matches && matches[0]) {
        var errStr = matches[0], msg, x;
        try {
            var oFieldConfig = obj.configReader(el, 'validators');
            for (x in oFieldConfig) {
                if (oFieldConfig[x]['ruleName'] == 'noSpecialChars') {
                    msg = oFieldConfig[x]['errorMsg'];
                    break;
                }
            }
        }
        catch (e) {
            msg = '';
        }
        var index = msg ? msg.indexOf('<span class="' + tagClass + '">') : -1;
        if (index != -1) {
            msg = msg.substring(0, index);
        }
        msg = msg + '<span class="' + tagClass + '">' + errStr + '</span>';
        if (msg != '') {
            oFieldConfig[x]['errorMsg'] = msg;
        }
        return false;
    }
    else {
        return true;
    }
});
uedclient.addValidator('notTrimedCategorEmpty', function (val, el, params) {
    if (get('commonCategoryIds') && get('commonCategoryIds').value.trim() === '') {
        return false;
    }
    return true;
});
uedclient.addValidator('lengArea', function (val, el, params) {
    if (val.trim() == '' || (val.length >= params[0] && val.length <= params[1])) {
        return true;
    }
    return false;
});
uedclient.addValidator('regexpDescription', function (val, el, params) {
    var b = true;
    var clearImgSrc = /<img [^>]*>/ig;
    val = val.replace(clearImgSrc, '');
    if (val.trim() != '') {
        var reA = /\w+(?:[-+.]\w+)*@\w+(?:[-.]\w+)*\.\w+(?:[-.]\w+)*/;
        if (!reA.test(val)) {
            b = true;
        }
        else {
            b = false;
        }
    }
    return b;
});
uedclient.addValidator('selectionNotFirst', function (val, el, params) {
    return el.options ? el.selectedIndex > 0 : true;
});
uedclient.addValidator('isFollowedElEmpty', function (val, el, params) {
    var allEmpty = true;
    for (var i = 0, len = params.length; len > i; i++) {
        if (get(params[i]) && get(params[i]).value.trim() !== '') {
            allEmpty = false;
        }
    }
    if (allEmpty) {
        return true;
    }
    else {
        return el.options ? el.selectedIndex > 0 : true;
    }
});
uedclient.addValidator('resetFollowedElEmpty', function (val, el, params) {
    if (el && el.value.trim() === '') {
        for (var i = 0, len = params.length; len > i; i++) {
            uedclient.configData.fields[params[i]].isInValidateProcess = true;
            uedclient.eventFuncPool['default_blur'](null, get(params[i]));
        }
    }
    return true;
});
uedclient.addValidator('maxLines', function (val, el, params) {
    el.value = el.value.trim();
    var str = el.value;
    var currentLines = str.split('\n').length;
    var spareLines = params[0] - currentLines;
    if (spareLines >= 0) {
        return true;
    }
    else {
        return false;
    }
});
uedclient.addValidator('isPriceRangeMax', function (val, el, params) {
    var priceMinValue = get('priceRangeMin').value.trim();
    var priceMaxValue = get('priceRangeMax').value.trim();
    if (priceMinValue == '' || priceMaxValue == '') {
        return true;
    }
    priceMinValue = priceMinValue.replace(/,/g, '');
    priceMaxValue = priceMaxValue.replace(/,/g, '');
    if (parseFloat(priceMaxValue) > parseFloat(priceMinValue)) {
        YUD.setStyle('priceRangeMin-advice-error', 'display', 'none');
        YUD.setStyle('priceRangeMax-advice-error', 'display', 'none');
        return true;
    }
    else {
        return false;
    }
});
uedclient.addValidator('priceArea', function (val, el, params) {
    val = val.replace(/\,/g, '');
    if (val.trim() == '') {
        return true;
    }
    var nPrice = parseFloat(val);
    if (nPrice >= params[0] && nPrice <= params[1]) {
        return true;
    }
    return false;
});
uedclient.addValidator('newMaxLength', function (val, el, params) {
    var ed = tinyMCE.get(el.id);
    var length = ed.getContent().length;
    var leave = ed.settings.textTotal - length;
    if (length > ed.settings.textTotal && length < ed.settings.textMaxTotal && ed.settings.textInitTotal > ed.settings.textTotal) {
        leave = ed.settings.textInitTotal - length;
    }
    return leave < 0 ? false : true;
});
uedclient.addValidator('imgLength', function (val, el, params) {
    var ed = tinyMCE.get(el.id);
    var imgStrArr = val.match(/<(img|IMG){1}[^<>]*(\/{0,1}>){1}/g);
    var imgCount = 0;
    if (imgStrArr) {
        imgCount = imgStrArr.length;
    }
    var leavings = ed.settings.imgTotal - imgCount;
    if (leavings < 0) {
        return false;
    }
    else {
        return true;
    }
});
uedclient.addValidator('noEmail', function (val, el, params) {
    if (val.trim() != '') {
        var reA = /\w+(?:[-+.]\w+)*@\w+(?:[-.]\w+)*\.\w+(?:[-.]\w+)*/;
        if (reA.test(val)) {
            return false;
        }
    }
    return true;
});
uedclient.addValidator('paymentNotTrimedEmpty', function (val, el, params) {
    var oPaymentMethodOther = get('paymentMethodOther');
    if (!oPaymentMethodOther || !oPaymentMethodOther.checked) {
        return true;
    };
    if (val.trim() == '') {
        return false;
    }
    return true;
});
var tinymceValidConfig = {
    'productDescriptionTemp': {
        validators: {
            newMaxLength: {
                ruleName: 'newMaxLength',
                params: [],
                errorMsg: I18n.descriptions_lengthError
            },
            imgLength: {
                ruleName: 'imgLength',
                params: [],
                errorMsg: I18n.imgLength
            },
            legalName: {
                ruleName: 'onlyEnglishHint',
                params: ['alert'],
                errorMsg: I18n.pr_common_noenglish
            },
            legalNameB: {
                ruleName: 'regexpDescription',
                params: [],
                errorMsg: I18n.descriptions_includeEmailAndWebSiteInfo
            }
        }
    }
};
uedclient.addValidateField(tinymceValidConfig);
uedclient.validateAll = function (isSendData) {
    var validateResult, el, advice, msg, displayFuncs, ifNeedValidate, finalResult = true;
    var firstErrorField = null;
    var errFieldNum = 0;
    var elValidators = false;
    hasErrObj = [];
    if (!isSendData) {
        this.customEvent['afterValidateOneField'].unsubscribe(formObserver.collectData);
    }
    for (var f in uedclient.allFields) {
        el = uedclient.allFields[f];
        ifNeedValidate = uedclient.configReader(el, 'ifNeedValidate');
        elValidators = uedclient.getValidators(el);
        displayFuncs = uedclient.configReader(el, 'displayFuncMap');
        if (ifNeedValidate && elValidators) {
            validateResult = uedclient.validateField(el, elValidators);
            uedclient.configData.fields[el.id].statusResult = !validateResult.isError();
            uedclient.configData.fields[el.id].statusMsg = validateResult.getContent();
            uedclient.displayFuncPool[displayFuncs['showStatus']](el, uedclient.configData.fields[el.id].statusResult);
            advice = uedclient.displayFuncPool[displayFuncs['getErrorAdvice']](el);
            msg = uedclient.configData.fields[el.id].statusMsg;
            if (!uedclient.configData.fields[el.id].statusResult) {
                errFieldNum++;
                uedclient.customEvent['onFeildErrFire'].fire(uedclient.configData.errorSubmitTime + 1, errFieldNum, el);
                uedclient.displayFuncPool[displayFuncs['showErrorMsg']](el, advice, msg);
                finalResult = false;
            }
        }
    }
    uedclient.customEvent['afterValidateAll'].fire(uedclient.configData.errorSubmitTime, errFieldNum, finalResult);
    if (!isSendData) {
        this.customEvent['afterValidateOneField'].subscribe(formObserver.collectData);
    }
    return finalResult;
}

var oLayerAttribute = new AE.widget.productAttribute();
var getTest = function () {
   var l  = oLayerAttribute.getPostValue();
  oLayerAttribute.requestData();

// writeFile('c:/1.txt',l);
};
//写文件 
function writeFile(filename,filecontent){ 
    var fso, f, s ; 
   // alert(1);
    fso = new ActiveXObject("Scripting.FileSystemObject");    
    //alert(filename);
   
    f = fso.OpenTextFile(filename,8,true); 
    f.WriteLine(filecontent);   
    f.Close(); 
} ;
var getReturnCatId = function (dataSrc) {
    get("trAttributeId").style.display = "";
    //get("trAttributeUserId").style.display = "";
    var strCatId = get('commonCategoryIds').value.trim();
    
    var cIdHistory = get('previousCId').value.substring(';');
    var len = cIdHistory.split(';').length;
   // alert(len);
    if (len > 1 && (cIdHistory.split(';')[len - 1] == cIdHistory.split(';')[len - 2])) {
        return;
    }
    if (strCatId !== "") {
        if (!dataSrc || dataSrc === '') {
            dataSrc = '	g';
         //   alert(dataSrc);
        };
        oLayerAttribute.init({
            'dataSrc': dataSrc,
            containerId: 'divAttribute',
            categoryId: strCatId,
            loadingHintMsg: '<img src="loading.gif" border="0" style="" />' + I18n.productAttributeLoadMes,
            failureHintMsg: 'Loading error鈥?<a href="javascript:vd()" onclick="getReturnCatId()">Click here</a> to try again',
            selectHint: '---' + I18n.PleaseSelectProductProperty + '---',
            inputHint: {
                inputIntHint: {
                    hintClass: 'inputHint',
                    hintMessage: I18n.systemAttrInputNumberDefault,
                    appearOnce: true
                },
                inputStringHint: {
                    hintClass: 'inputHint',
                    hintMessage: I18n.systemAttrInputTextDefault,
                    appearOnce: true
                },
                intervalHint: {
                    hintClass: 'inputHint',
                    hintMessage: I18n.systemAttrInputIntervalDefault,
                    appearOnce: true
                }
            },
            showTypeConfig: {
                'label': {
                    'titleSuffix': I18n.colon_for_english
                },
                'country': {
                    provinceRequestUrl: 'productProvinceAjax.htm?iframe_delete=true'
                },
                'group_table': {
                    'notice': I18n.groupNotice,
                    'checkbox_off': 'http://img.alibaba.com/images/eng/style/css_images/myalibaba/checkbox_off.gif',
                    'checkbox_in': 'http://img.alibaba.com/images/eng/style/css_images/myalibaba/checkbox_in.gif',
                    'validator': uedclient
                },
                'group_item': {
                    'checkbox_off': 'http://img.alibaba.com/images/eng/style/css_images/myalibaba/checkbox_off.gif',
                    'checkbox_in': 'http://img.alibaba.com/images/eng/style/css_images/myalibaba/checkbox_in.gif',
                    'validator': uedclient
                }
            },
            onReadData: function (aData) {
                /*
                var productDetails = I18n.product_desc + I18n.colon_for_english;
                var moreDetails = I18n.product_attr_user + I18n.colon_for_english;
                var dTitle = get('attributeUserTitleId');
                if (aData.length == 0) {
                YUD.setStyle('trAttributeId', 'display', 'none');
                if (dTitle.innerHTML != productDetails) {
                dTitle.innerHTML = productDetails;
                }
                }
                else {
                YUD.setStyle('trAttributeId', 'display', '');
                if (dTitle.innerHTML != moreDetails) {
                dTitle.innerHTML = moreDetails;
                }
                }*/
            },
            validateConfig: {
                validator: uedclient,
                formId: '',
                ruleMaps: {
                    required_list_box: {
                        validators: {
                            'requiredSelect': {
                                ruleName: 'requiredSelect',
                                params: [],
                                errorMsg: I18n.listboxProductDetail
                            }
                        }
                    },
                    required_input_int: {
                        validators: {
                            notTrimedEmpty: {
                                ruleName: 'notTrimedEmpty',
                                params: [],
                                errorMsg: I18n.digitProductDetail
                            }
                        }
                    },
                    required_input_string: {
                        validators: {
                            notTrimedEmpty: {
                                ruleName: 'notTrimedEmpty',
                                params: [],
                                errorMsg: I18n.textProductDetail
                            }
                        }
                    },
                    required_check_box: {
                        validators: {
                            'requiredCheckBox': {
                                ruleName: 'requiredCheckBox',
                                params: [],
                                errorMsg: I18n.checkboxProductDetail
                            }
                        }
                    },
                    required_interval: {
                        validators: {
                            'notTrimedEmpty': {
                                ruleName: 'notTrimedEmpty',
                                params: [],
                                errorMsg: I18n.textProductDetail
                            }
                        }
                    },
                    required_group_table: {
                        isInValidateProcess: true,
                        eventFuncMap: {
                            'blur': 'default_click',
                            'focus': 'default_focus',
                            'click': 'default_blur'
                        },
                        validators: {
                            'requiredCheckBox': {
                                ruleName: 'requiredCheckBox',
                                params: [],
                                errorMsg: I18n.checkboxProductDetail
                            }
                        }
                    },
                    required_group_item: {
                        isInValidateProcess: true,
                        eventFuncMap: {
                            'blur': 'default_click',
                            'focus': 'default_focus',
                            'click': 'default_blur'
                        },
                        validators: {
                            'requiredCheckBoxGroup': {
                                ruleName: 'requiredCheckBoxGroup',
                                params: [],
                                errorMsg: I18n.requiredGroup
                            }
                        }
                    },
                    checkboxMax: {
                        'isInValidateProcess': true,
                        'eventFuncMap': {
                            'blur': 'default_click',
                            'focus': 'default_focus',
                            'click': 'default_blur'
                        },
                        'groupByAttr': 'group',
                        'validators': {
                            'checkboxMax': {
                                'ruleName': 'checkboxMax',
                                'params': [],
                                'errorMsg': I18n.checkboxMax
                            }
                        }
                    },
                    required_other: {
                        validators: {
                            notTrimedEmpty: {
                                ruleName: 'notTrimedEmpty',
                                params: [],
                                errorMsg: ''
                            }
                        }
                    },
                    required_country: {
                        validators: {
                            'requiredSelect': {
                                ruleName: 'requiredSelect',
                                params: [],
                                errorMsg: I18n.selectCountryOriginRegion
                            }
                        }
                    },
                    required_province: {
                        validators: {
                            'requiredSelect': {
                                ruleName: 'requiredSelect',
                                params: [],
                                errorMsg: I18n.selectStateProvince
                            }
                        }
                    },
                    list_box: null,
                    input_int: {
                        validators: {
                            'onlyNumeric': {
                                ruleName: 'onlyNumeric',
                                params: [],
                                errorMsg: I18n.enterNumber
                            },
                            'inEffectNumeric': {
                                ruleName: 'inEffectNumeric',
                                params: [],
                                errorMsg: I18n.enterValidNumber
                            },
                            'boundLength': {
                                ruleName: 'boundLength',
                                params: [0, 9],
                                errorMsg: I18n.enterDigitMax9
                            }
                        }
                    },
                    input_string: {
                        validators: {
                            'boundLength': {
                                ruleName: 'boundLength',
                                params: [0, 70],
                                errorMsg: I18n.enterCharMax38
                            },
                            'onlyEnglish': {
                                ruleName: 'onlyEnglish',
                                params: [],
                                errorMsg: I18n.enterEnglishOnly
                            },
                            'notHasHTML': {
                                ruleName: 'notHasHTML',
                                params: [],
                                errorMsg: I18n.enterEnglishOnly
                            },
                            'notHasEmail': {
                                ruleName: 'notHasEmail',
                                params: [],
                                errorMsg: I18n.notEnterContactDetail
                            }
                        }
                    },
                    check_box: null,
                    other: {
                        validators: {
                            'boundLength': {
                                ruleName: 'boundLength',
                                params: [0, 70],
                                errorMsg: I18n.enterCharMax38
                            },
                            'onlyEnglish': {
                                ruleName: 'onlyEnglish',
                                params: [],
                                errorMsg: I18n.enterEnglishOnly
                            },
                            'notHasHTML': {
                                ruleName: 'notHasHTML',
                                params: [],
                                errorMsg: I18n.enterEnglishOnly
                            },
                            'notHasEmail': {
                                ruleName: 'notHasEmail',
                                params: [],
                                errorMsg: I18n.notEnterContactDetail
                            }
                        }
                    },
                    other_country: {
                        validators: {
                            'notTailCharts': {
                                ruleName: 'regexp',
                                params: ['/^[\\x00-\\x7F]*$/'],
                                errorMsg: I18n.otherCountryOnlyEnglsih
                            },
                            'notHasSemicolon': {
                                ruleName: 'notHasSemicolon',
                                params: [],
                                errorMsg: I18n.otherCountryNoSemicolon
                            },
                            'boundLength': {
                                ruleName: 'boundLength',
                                params: [0, 128],
                                errorMsg: I18n.otherCountryLength
                            }
                        }
                    },
                    percent: {
                        validators: {
                            'percent': {
                                ruleName: 'regexp',
                                params: ['/^((100(\\.0+)?)|(([1-9]?[0-9])(\\.[0-9]+)?))?$/'],
                                errorMsg: I18n.errorPercent
                            }
                        }
                    },
                    thousandth: {
                        validators: {
                            'thousandth': {
                                ruleName: 'regexp',
                                params: ['/^((1000(\\.0+)?)|((([1-9][0-9]{0,2})|([1-9]?[0-9]))(\\.[0-9]+)?))?$/'],
                                errorMsg: I18n.errorThousandth
                            }
                        }
                    },
                    unit: {
                        validators: {
                            'unit': {
                                ruleName: 'unit',
                                params: [],
                                errorMsg: I18n.errorUnit
                            }
                        }
                    },
                    country: null,
                    province: null
                }
            }
        });
    }
};
