var ProductCategories = {
	tree: [],
	formId: null,
	inputName: null,
	combo1: null,
	combo2: null,
	combo2List: null,
	onlyLeaf: true,
	init: function(formId, inputName, tree) {
		this.formId = formId;
		this.inputName = inputName;
		this.tree = tree;
		this.parentMap = {};
		this.nodeMap = {};
		for (var i = 0; i < this.tree.length; i++) {
			var node = this.tree[i];
			this.nodeMap[node.key] = node;
			for (var j = 0; j < node.children.length; j++) {
				var child = node.children[j];
				this.nodeMap[child.key] = child;
				this.parentMap[child.key] = node.key;
			}
		}
	},
	write: function(category_id) {
		var options1 = [];
		for (var i = 0; i < this.tree.length; i++) {
			options1[i] = {text:this.tree[i].name, value:this.tree[i].key};
		}
		this.combo1 = ComboBoxes.writeComboBox(this.formId, 'parent' + this.inputName, options1, {width:'100px'}, {'className': 'fL', onSelect: this.onSelect1.bind(this)});
		this.combo2 = ComboBoxes.writeComboBox(this.formId, this.inputName, [], {width:'136px'}, {'className': 'fL', onSelect: this.onSelect2.bind(this)});
		this.combo2List = $(this.combo2.id + '.options');

		if (category_id)
			this.select(category_id);
		else
			this.onSelect1(true);
	},
	select: function(category_id) {
		var parentId = this.parentMap[category_id];
		if (parentId) {
			FormUtils.set(this.combo1.inputObj, parentId);
			this.combo1.select(true);
			this.combo1.onSelect(true);
			FormUtils.set(this.combo2.inputObj, category_id);
			this.combo2.select();
		}
		else {
			FormUtils.set(this.combo1.inputObj, category_id);
			this.combo1.select();
		}
	},
	onSelect1: function(ignoreOnSelect2) {
		var parentId = this.combo1.getValue();
		var parent = this.nodeMap[parentId];
		if (!parent)
			return;

		var id = this.formId + '.' + this.inputName;
		var values = {
			id: id,
			inputName: this.inputName,
			text: 'ÇÏÀ§ Ä«Å×°í¸® ¼±ÅÃ',
			value: (this.onlyLeaf)? '': parentId,
			detail: ""
		};
		var html = ComboBoxes.templates.comboDefault.evaluate(values);
		for (var i = 0; i < parent.children.length; i++) {
			values['text'] = parent.children[i].name;
			values['value'] = parent.children[i].key;
			html += ComboBoxes.templates.comboRow.evaluate(values);
		}
		Element.update(this.combo2List, html);
		this.combo2 = new ComboBox(this.formId, this.inputName);
		this.combo2.onSelect = this.onSelect2.bind(this);
		this.combo2.select(ignoreOnSelect2);
	},
	onSelect2: function() {
	}
};
