	function addr_insert()
	{
		if (opener && opener.document.forms.write)
		{
			if (document.list.addr_list.selectedIndex > -1)
				addr_sel_add('to');

			var obj;
			var obj2;

			var is_add = false;
			
			obj = document.list.mf_to;
			if (obj.options.length > 0)
			{
				obj2 = opener.document.forms.write.mf_to;
				val = '';
				for (i=0; i<obj.options.length; i++)
				{
					if (i != 0)
						val += ', ';
					val += obj.options[i].value;
				}	// for()
				if (obj2.value != '')
					obj2.value += ', ';
				obj2.value += val;
				opener.rowsUp(obj2, 40, 10);

				is_add = true;
			}	// if()

			obj = document.list.mf_cc;
			if (obj.options.length > 0)
			{
				obj2 = opener.document.forms.write.mf_cc;
				val = '';
				for (i=0; i<obj.options.length; i++)
				{
					if (i != 0)
						val += ', ';
					val += obj.options[i].value;
				}	// for()
				if (obj2.value != '')
					obj2.value += ', ';
				obj2.value += val;
				opener.rowsUp(obj2, 40, 10);

				is_add = true;
			}	// if()

			obj = document.list.mf_bcc;
			if (obj.options.length > 0)
			{
				obj2 = opener.document.forms.write.mf_bcc;
				val = '';
				for (i=0; i<obj.options.length; i++)
				{
					if (i != 0)
						val += ', ';
					val += obj.options[i].value;
				}	// for()
				if (obj2.value != '')
					obj2.value += ', ';
				obj2.value += val;
				opener.rowsUp(obj2, 40, 10);

				is_add = true;
			}	// if()

			if (is_add == false)
			{
				alert("[받는사람/참조/숨은참조]에 추가된 주소가 없습니다.");
				return;				
			}	// if()
		} else
		{
			alert("편지쓰기 페이지가 존재하지 않습니다.\n\n확인후 다시 시도하여 주십시오.");
		}

		window.close();
	}	// function

	function addr_search()
	{
		var form = document.list;

		if (form_chk_value(form.s_word, "검색할 단어") == false) return;

		if (form.s_mc_no)
			var _s_mc_no = form.s_mc_no.value;
		else
			var _s_mc_no = '';

		addr_list_update(form.update_type.value, form.update_g_no.value, form.s_word.value, _s_mc_no);
	}	// function

	function addr_search_mc()
	{
		var form = document.list;

		if (form.s_mc_no)
			var _s_mc_no = form.s_mc_no.value;
		else
			var _s_mc_no = '';

		addr_list_update(form.update_type.value, form.update_g_no.value, form.s_word.value, _s_mc_no);
	}	// function

	function addr_search_cancel()
	{
		var form = document.list;
		form.s_word.value = '';

		addr_list_update(form.update_type.value, form.update_g_no.value, '', '');
	}	// function

	function check_click(chk_ad_no)
	{
		var element = document.list.elements;

		for (var i = 0; i < element.length; i++)
		{
			if (element[i].type == "checkbox" && element[i].name == 'chk_ad_no[]' && element[i].value == chk_ad_no)
			{
				if (element[i].checked == false)
				{
					element[i].checked = true;
				} else
				{
					element[i].checked = false;
				}
				break;
			}
		}
	}	// function

	function addr_type_click(ut)
	{
		document.getElementById('_nm_addr_select_group_frame').src = nmpath + "/addr_select_group.php?type=" + ut;
		addr_list_update(ut, '', '', '');
	}	// function()

	function addr_list_update(type, g_no, q, s_mc_no)
	{
		if (typeof s_mc_no == "undefined")
			s_mc_no = '';

		// tab
		if (document.getElementById('addr_type_G'))
			document.getElementById('addr_type_G').className = '';
		document.getElementById('addr_type_P').className = '';
		if (document.getElementById('addr_type_S'))
			document.getElementById('addr_type_S').className = '';
		var q_str_add = '';
		switch (type)
		{
			case 'G':
				if (document.getElementById('addr_type_G'))
					document.getElementById('addr_type_G').className = 'on';

				if (document.getElementById('s_mc_no'))
				{
					document.getElementById('s_mc_no').style.display = '';
					q_str_add = '&s_mc_no=' + s_mc_no;
				}
				break;
			case 'P':
				document.getElementById('addr_type_P').className = 'on';
				if (document.getElementById('s_mc_no'))
					document.getElementById('s_mc_no').style.display = 'none';
				break;
			case 'S':
				if (document.getElementById('addr_type_S'))
					document.getElementById('addr_type_S').className = 'on';
				if (document.getElementById('s_mc_no'))
					document.getElementById('s_mc_no').style.display = 'none';
				break;
		}	// switch()

		// 취소시 초기화 처리.
		document.list.update_type.value = type;
		document.list.update_g_no.value = g_no;
		document.list.s_word.value = q;
		if (document.list.s_mc_no && s_mc_no == '')
			document.list.s_mc_no[0].selected = true;

		// reset
		var obj = document.list.addr_list;
		for (i=0; i<obj.options.length; i++)
		{
			obj.options[i] = null;
			i--;
		}	// for()
	
		// title
		if (type == 'G')
		{
			document.getElementById('addr_list_text').innerHTML = '회원 목록';
		} else 
		{
			document.getElementById('addr_list_text').innerHTML = '주소 목록';
		}	// if()			

		new Ajax.Request(nmpath + '/addr_select_ajax.php', {
			method: 'post',
			parameters: 'type=' + type + '&g_no=' + g_no + '&q=' + q + q_str_add,
			onSuccess: function(transport) {
				var sp = transport.responseText.split('|!|');

				for (i=0; i<sp.length; i++)
				{
					if (sp[i] != '')
						obj.options[obj.options.length] = new Option(sp[i], sp[i]);
				}	// for()

				document.getElementById('addr_list_cnt').innerHTML = obj.options.length;
			},
			onFailure: function(transport) {
				alert('Error: '+transport.status+"\n\n"+transport.responseText);
			}
		});		

		var form = document.list;

		if (form.s_word.value == '' && form.s_mc_no && form.s_mc_no.value != '')
		{
			form.s_mc_no.focus();
		} else
		{
			form.s_word.focus();
			form.s_word.select();
		}
	}	// function()

	function addr_sel_all()
	{
		var obj = document.list.addr_list;
		if (obj.options.length == 0)
		{
			alert("선택할 주소가 없습니다.");
			return;
		}	// if()
		for (i=0; i<obj.options.length; i++)
		{
			obj.options[i].selected = true;
		}	// for()		
	}	// function()

	function addr_sel_add(kind)
	{
		var obj = document.list.addr_list;
		var obj2;
		var obj_cnt;
		switch (kind)
		{
			case 'to':
				obj2 = document.list.mf_to;
				obj_cnt = document.getElementById('mf_to_cnt');
				break;
		
			case 'cc':
				obj2 = document.list.mf_cc;
				obj_cnt = document.getElementById('mf_cc_cnt');
				break;

			case 'bcc':
				obj2 = document.list.mf_bcc;
				obj_cnt = document.getElementById('mf_bcc_cnt');
				break;
		}	// switch()

		if (obj.selectedIndex == -1)
		{
			alert("좌측 리스트에서 추가할 주소를 선택하십시오.");
			return;
		}	// if()
		
		var isDuplCnt = 0;
		var obj2_len = obj2.options.length;

		for (i=0; i<obj.options.length; i++)
		{
			if (obj.options[i].selected == true)
			{
				// 중복방지
				isDupl = false;
				if (obj2_len > 0)
				{
					for (j=0; j<obj2.options.length; j++)
					{
						if (obj.options[i].value == obj2.options[j].value)
						{
							isDupl = true;
							isDuplCnt++;
							break;
						}	// if()
					}	// for()
				}	// if()

				if (isDupl == false)
				{
					obj2.options[obj2.options.length] = new Option(obj.options[i].text, obj.options[i].value);
					obj.options[i].selected = false;
				}	// if()
			}	// if()
		}	// for()

		obj_cnt.innerHTML = obj2.options.length;


		if (isDuplCnt > 0)
			alert("우측 리스트에 이미 추가된 주소는 생략되었습니다.");
	}	// function()

	function addr_sel_del(kind)
	{
		var obj = document.list.addr_list;
		var obj2;
		var obj_cnt;
		switch (kind)
		{
			case 'to':
				obj2 = document.list.mf_to;
				obj_cnt = document.getElementById('mf_to_cnt');
				break;
		
			case 'cc':
				obj2 = document.list.mf_cc;
				obj_cnt = document.getElementById('mf_cc_cnt');
				break;

			case 'bcc':
				obj2 = document.list.mf_bcc;
				obj_cnt = document.getElementById('mf_bcc_cnt');
				break;
		}	// switch()

		if (obj2.selectedIndex == -1)
		{
			alert("우측 리스트에서 삭제할 주소를 선택하십시오.");
			return;
		}	// if()

		for (i=0; i<obj2.options.length; i++)
		{
			if (obj2.options[i].selected == true)
			{
				obj2.options[i] = null;
				i--;
			}	// if()
		}	// for()

		obj_cnt.innerHTML = obj2.options.length;
	}	// function()

	window.onload = function()
	{
		addr_list_update(document.list.update_type.value, '', '', '');
	}	// function