/*** Ä«Å×°í¸® ¼±ÅÃ¹Ú½º ***/
function selectCategory(name,num,type,category,hidden,cody)
{
	if (!arguments[1]) num = 4;

	var _self = this;
	var container = document.getElementById(name);
	var margin = (type=="multiple") ? "             " : "";

	this.selbox = [];
	this.value = "";

	this.updateChange = updateChange;
	this.setValue = setValue;
	this.init = init;
	this.setNullChild = setNullChild;
	this.init();

	function init()
	{		
		for (var i=0;i<num;i++){

			var obj = document.createElement("select");
			if (type=="multiple"){
				obj.multiple = true;
				with (obj.style){
					width = '202px';
					height = '141px';
				}
			}
			
			obj.name = name;
			obj.idx = i+1;
			obj.onchange = function(){_self.updateChange(this);};
			container.appendChild(obj);

			obj.options[0] = (num!=1) ? new Option(margin + '     ' + (i+1) + 'Â÷ ºÐ·ù     ','') : new Option(' »óÇ°ÀüÃ¼','');
			obj.options[0].style.color = "#fff";
			obj.options[0].style.backgroundColor = "#7186b0";
			if (type=="multiple") obj.selectedIndex = -1;

			this.selbox[i] = obj;
		}
		this.updateChange('');
	}

	function updateChange(obj,v)
	{
		if (!v && category) v = category;
		this.value = (obj) ? obj.value : "";
		
		if (obj && !obj.value){
			_self.setNullChild(obj);
			return;
		}

		var url = "../../ajax.php";

		var mode = (!cody) ? "category" : "cody_cate";
		var pars = "mode="+mode+"&category=" + this.value;

		if (_self.hidden || hidden) pars += "&hidden=1";
		
		new Ajax.Request(
		url,
		{
			parameters: pars,
			onComplete: showResponse
		});

		function showResponse(data)
		{
			var ret = data.responseText;
			if (!ret){ _self.setNullChild(obj); return; }
		
			var div = ret.split("^|^");
			var sobj = (obj) ? obj.nextSibling : _self.selbox[0];

			sobj.length = 1;
			for (var i=0;i<div.length;i++){
				var div2 = div[i].split("=");
				sobj.options[i+1] = new Option(" "+div2[1],div2[0]);				
				if (v){
					if (v.substring(0,sobj.idx*3)==div2[0]) sobj.selectedIndex = i+1;
					_self.value = sobj.value;
				}
			}
			if (v && v.length>=sobj.idx*3) _self.updateChange(sobj,v);
			else _self.setNullChild(sobj);
		}
	}

	function setValue(v)
	{
		this.updateChange('',v);
	}

	function setNullChild(obj)
	{
		var n = obj.nextSibling;
		if (n){
			n.length = 1;
			this.setNullChild(n);
		}
		category = null;
	}
}