var selected_phone_idx = -1;

document.attachEvent("onclick", function(e){HideFromPhoneListCheck(e);});

var oPopupFromPhoneSetting = null;	//È¸½Å¹øÈ£ ¼³Á¤ ÆË¾÷

function PopFromPhoneSetting_old(oThis)
{		
	if(oPopupFromPhoneSetting == null)
	{
		oPopupFromPhoneSetting = new Popup();
		
		oPopupFromPhoneSetting.width = "330px";
		oPopupFromPhoneSetting.top = (oThis.offsetTop + oThis.offsetHeight) + 'px';
		oPopupFromPhoneSetting.left = (oThis.offsetLeft - 250) + 'px';
		oPopupFromPhoneSetting.SetTitle("¢º º¸³»´Â»ç¶÷ ¹øÈ£ ¼³Á¤");
		oPopupFromPhoneSetting.oFirer = oThis;

		oPopupFromPhoneSetting.oCloseBtn.attachEvent("onclick", function() { CloseFromPhoneSettingBox(); } );

	}

	if(oPopupFromPhoneSetting.is_show)
	{
		oPopupFromPhoneSetting.Hide();
	}else {
	
		MakePopupFromPhoneSettingContent();
		oPopupFromPhoneSetting.Show();
		GetFromPhoneSettingInfo();
	}
}

function PopFromPhoneSetting(e, oThis)
{		
	if(oPopupFromPhoneSetting == null)
	{
		oPopupFromPhoneSetting = new Popup();

		var offset_x = 0;
		var offset_y = 0;
		if(typeof(e.offsetX) == 'undefined')
		{
			offset_x = e.layerX;
			offset_y = e.layerY;
		}
		else
		{
			offset_x = e.offsetX;
			offset_y = e.offsetY;
		}
		
		var offset_top = e.clientY - offset_y;
		var offset_left = e.clientX - offset_x;

		var body_scrollTop = (document.documentElement.scrollTop > document.body.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
		
		oPopupFromPhoneSetting.width = "330px";
		oPopupFromPhoneSetting.top = (body_scrollTop + offset_top + oThis.offsetHeight - 2) + 'px';
		oPopupFromPhoneSetting.left = (offset_left - 250) + 'px';
		oPopupFromPhoneSetting.SetTitle("¢º º¸³»´Â»ç¶÷ ¹øÈ£ ¼³Á¤");
		oPopupFromPhoneSetting.oFirer = oThis;

		oPopupFromPhoneSetting.oCloseBtn.attachEvent("onclick", function() { CloseFromPhoneSettingBox(); } );

	}

	if(oPopupFromPhoneSetting.is_show)
	{
		oPopupFromPhoneSetting.Hide();
	}else {
	
		MakePopupFromPhoneSettingContent();
		oPopupFromPhoneSetting.Show();
		GetFromPhoneSettingInfo();
	}
}


function MakePopupFromPhoneSettingContent()
{
	var oContent = oPopupFromPhoneSetting.oContent;
	oContent.innerHTML = '';
	oContent.style.backgroundColor = "#F4F4F5";

	var oGuide = document.createElement('div');
	oGuide.style.width = "300px";
	oGuide.style.height = "auto";
	oGuide.style.margin = "auto";
	oContent.oGuide = oGuide;
	oContent.insertAdjacentElement("beforeEnd",oGuide);
	{
		var oLabel = document.createElement('div');
		oLabel.style.padding = "5px 0 2px 0";
		oLabel.style.fontWeight = "bold";
		oLabel.innerHTML = "1.º¸³»´Â »ç¶÷ ¹øÈ£ ÀÚµ¿ ÀÔ·Â ¼³Á¤";
		oGuide.insertAdjacentElement("beforeEnd",oLabel);

		var top_round = RtnTableTopRound("100%", "#FFFFFF", "#D8D8D8");
		oGuide.insertAdjacentHTML("beforeEnd",top_round);

		var oFromPhoneAutoInputSetBox = document.createElement('div');
		oFromPhoneAutoInputSetBox.style.backgroundColor = "#ffffff";
		oFromPhoneAutoInputSetBox.style.width = (parseInt(oGuide.style.width) - 2) + "px";
		oFromPhoneAutoInputSetBox.style.height = "auto";
		oFromPhoneAutoInputSetBox.style.padding = "6px 0px";
		oFromPhoneAutoInputSetBox.style.borderLeft = "1px solid #D8D8D8";
		oFromPhoneAutoInputSetBox.style.borderRight = "1px solid #D8D8D8";
		oContent.oFromPhoneAutoInputSetBox = oFromPhoneAutoInputSetBox;
		oGuide.insertAdjacentElement("beforeEnd",oFromPhoneAutoInputSetBox);
		{
			var oAutoInputTypeSetSec = document.createElement('div');
			oAutoInputTypeSetSec.style.margin = "auto";
			oAutoInputTypeSetSec.style.textAlign = "center";
			oAutoInputTypeSetSec.style.border = "0px solid red";
			oFromPhoneAutoInputSetBox.insertAdjacentElement("beforeEnd",oAutoInputTypeSetSec);
			{
				var oRadioRecnetPhoneAutoInput = null;
				try
				{
					oRadioRecnetPhoneAutoInput = document.createElement('<input type="radio" name="from_phone_auto_input_set"/>');
				}
				catch (e)
				{
					oRadioRecnetPhoneAutoInput = document.createElement('input');
					oRadioRecnetPhoneAutoInput.type = "radio";
					oRadioRecnetPhoneAutoInput.name = "from_phone_auto_input_set";
				}
				oRadioRecnetPhoneAutoInput.id = "from_phone_auto_input_set1";
				oRadioRecnetPhoneAutoInput.value = "recent";
				oRadioRecnetPhoneAutoInput.style.cursor = "pointer";
				oFromPhoneAutoInputSetBox.oRadioRecnetPhoneAutoInput = oRadioRecnetPhoneAutoInput;
				oAutoInputTypeSetSec.insertAdjacentElement("beforeEnd",oRadioRecnetPhoneAutoInput);
				
				var oLabelRecnetPhoneAutoInput = document.createElement('label');
				oLabelRecnetPhoneAutoInput.style.cursor = "pointer";
				oLabelRecnetPhoneAutoInput.htmlFor = "from_phone_auto_input_set1";
				oLabelRecnetPhoneAutoInput.innerHTML = "ÃÖ±ÙÈ¸½Å¹øÈ£ ÀÚµ¿ÀÔ·Â";
				oAutoInputTypeSetSec.insertAdjacentElement("beforeEnd",oLabelRecnetPhoneAutoInput);
				
				var oRadioFixPhoneAutoInput = null;
				try
				{
					oRadioFixPhoneAutoInput = document.createElement('<input type="radio" name="from_phone_auto_input_set"/>');
				}
				catch (e)
				{
					oRadioFixPhoneAutoInput = document.createElement('input');
					oRadioFixPhoneAutoInput.type = "radio";
					oRadioFixPhoneAutoInput.name = "from_phone_auto_input_set";
				}
				oRadioFixPhoneAutoInput.id = "from_phone_auto_input_set2";
				oRadioFixPhoneAutoInput.value = "fix";
				oRadioFixPhoneAutoInput.style.margin = "0 0 0 8px";
				oRadioFixPhoneAutoInput.style.cursor = "pointer";
				oFromPhoneAutoInputSetBox.oRadioFixPhoneAutoInput = oRadioFixPhoneAutoInput;
				oAutoInputTypeSetSec.insertAdjacentElement("beforeEnd",oRadioFixPhoneAutoInput);

				var oLabelFixPhoneAutoInput = document.createElement('label');
				oLabelFixPhoneAutoInput.style.cursor = "pointer";
				oLabelFixPhoneAutoInput.htmlFor = "from_phone_auto_input_set2";
				oLabelFixPhoneAutoInput.innerHTML = "°íÁ¤¹øÈ£ ÀÚµ¿ÀÔ·Â";
				oAutoInputTypeSetSec.insertAdjacentElement("beforeEnd",oLabelFixPhoneAutoInput);
			}

			var oFixPhoneSetSec = document.createElement('div');
			oFixPhoneSetSec.style.position = "relative";
			oFixPhoneSetSec.style.margin = "5px auto";
			oFixPhoneSetSec.style.width = "80%";
			oFixPhoneSetSec.style.textAlign = "center";
			//oFixPhoneSetSec.style.border = "1px solid red";
			oFromPhoneAutoInputSetBox.insertAdjacentElement("beforeEnd",oFixPhoneSetSec);
			{
				var oLabelSec = document.createElement('span');
				oLabelSec.style.display = "inline-block";
				oLabelSec.style.verticalAlign = "middle";
				oLabelSec.style.padding = "4px 0 0 0";
				//oLabelSec.style.border = "1Px solid red";
				oLabelSec.innerHTML = "°íÁ¤¹øÈ£ :";
				oFixPhoneSetSec.insertAdjacentElement("beforeEnd",oLabelSec);

				var oFixPhoneSec = document.createElement('span');
				oFixPhoneSec.style.display = "inline-block";
				oFixPhoneSec.style.verticalAlign = "middle";
				oFixPhoneSec.style.margin = "0 0px 0 3px";
				//oFixPhoneSec.style.border = "1px solid red";
				oFixPhoneSetSec.insertAdjacentElement("beforeEnd",oFixPhoneSec);
				{
					var oInputFixPhone = document.createElement('input');
					oInputFixPhone.type = "text";
					oInputFixPhone.style.width = "120px";
					oFromPhoneAutoInputSetBox.oInputFixPhone = oInputFixPhone;
					oFixPhoneSec.insertAdjacentElement("beforeEnd",oInputFixPhone);
				}

				var oDisableSec1 = document.createElement('div');
				oDisableSec1.style.position = "absolute";
				oDisableSec1.style.top = "-2px";
				oDisableSec1.style.left = "0px";
				oDisableSec1.style.width = "100%";
				oDisableSec1.style.height = "27px";
				oDisableSec1.style.display = "none";
				oDisableSec1.style.backgroundColor = "#E5E3E3";
				oDisableSec1.style.filter = "alpha(opacity=50)";
				oDisableSec1.style.opacity = "0.5";
				oFromPhoneAutoInputSetBox.oDisableSec = oDisableSec1;
				oFixPhoneSetSec.insertAdjacentElement("beforeEnd",oDisableSec1);

			}

			oLabelRecnetPhoneAutoInput.attachEvent("onclick", function(e){oDisableSec1.style.display="block";} );
			oRadioFixPhoneAutoInput.attachEvent("onclick", function(e){oDisableSec1.style.display="none";} );
		}
		
		var bottom_round = RtnTableBtmRound("100%", "#FFFFFF", "#D8D8D8");
		oGuide.insertAdjacentHTML("beforeEnd",bottom_round);

		var oLabel = document.createElement('div');
		oLabel.style.padding = "10px 0 2px 0";
		oLabel.style.fontWeight = "bold";
		oLabel.innerHTML = "2.º¸³»´Â »ç¶÷ ¹øÈ£ ¸®½ºÆ® ¼³Á¤";
		oGuide.insertAdjacentElement("beforeEnd",oLabel);

		var top_round = RtnTableTopRound("100%", "#FFFFFF", "#D8D8D8");
		oGuide.insertAdjacentHTML("beforeEnd",top_round);

		var oFromPhoneListSetBox = document.createElement('div');
		oFromPhoneListSetBox.style.backgroundColor = "#ffffff";
		oFromPhoneListSetBox.style.width = (parseInt(oGuide.style.width) - 2) + "px";
		oFromPhoneListSetBox.style.height = "auto";
		oFromPhoneListSetBox.style.padding = "6px 0px";
		oFromPhoneListSetBox.style.borderLeft = "1px solid #D8D8D8";
		oFromPhoneListSetBox.style.borderRight = "1px solid #D8D8D8";
		oContent.oFromPhoneListSetBox = oFromPhoneListSetBox;
		oGuide.insertAdjacentElement("beforeEnd",oFromPhoneListSetBox);
		{
			var oFromPhoneListTypeSetSec = document.createElement('div');
			oFromPhoneListTypeSetSec.style.margin = "auto";
			oFromPhoneListTypeSetSec.style.textAlign = "center";
			oFromPhoneListTypeSetSec.style.border = "0px solid red";
			oFromPhoneListSetBox.insertAdjacentElement("beforeEnd",oFromPhoneListTypeSetSec);
			{
				var oRadioRecnetFromPhoneList = null;
				try
				{
					oRadioRecnetFromPhoneList = document.createElement('<input type="radio" name="from_phone_list_set"/>');
				}
				catch (e)
				{
					oRadioRecnetFromPhoneList = document.createElement('input');
					oRadioRecnetFromPhoneList.type = "radio";
					oRadioRecnetFromPhoneList.name = "from_phone_list_set";
				}
				oRadioRecnetFromPhoneList.id = "from_phone_list_set1";
				oRadioRecnetFromPhoneList.value = "recent";
				oRadioRecnetFromPhoneList.style.cursor = "pointer";
				oFromPhoneListSetBox.oRadioRecnetFromPhoneList = oRadioRecnetFromPhoneList;
				oFromPhoneListTypeSetSec.insertAdjacentElement("beforeEnd",oRadioRecnetFromPhoneList);
				
				var oLabelRecnetFromPhoneList = document.createElement('label');
				oLabelRecnetFromPhoneList.style.cursor = "pointer";
				oLabelRecnetFromPhoneList.htmlFor = "from_phone_list_set1";
				oLabelRecnetFromPhoneList.innerHTML = "ÃÖ±ÙÈ¸½Å¹øÈ£¸ñ·Ï Ç¥½Ã";
				oFromPhoneListTypeSetSec.insertAdjacentElement("beforeEnd",oLabelRecnetFromPhoneList);
				
				var oRadioFixPhoneList = null;
				try
				{
					oRadioFixPhoneList = document.createElement('<input type="radio" name="from_phone_list_set"/>');
				}
				catch (e)
				{
					oRadioFixPhoneList = document.createElement('input');
					oRadioFixPhoneList.type = "radio";
					oRadioFixPhoneList.name = "from_phone_list_set";
				}
				oRadioFixPhoneList.id = "from_phone_list_set2";
				oRadioFixPhoneList.value = "fix";
				oRadioFixPhoneList.style.margin = "0 0 0 8px";
				oRadioFixPhoneList.style.cursor = "pointer";
				oFromPhoneListSetBox.oRadioFixPhoneList = oRadioFixPhoneList;
				oFromPhoneListTypeSetSec.insertAdjacentElement("beforeEnd",oRadioFixPhoneList);

				var oLabelFixPhoneList = document.createElement('label');
				oLabelFixPhoneList.style.cursor = "pointer";
				oLabelFixPhoneList.htmlFor = "from_phone_list_set2";
				oLabelFixPhoneList.innerHTML = "°íÁ¤¹øÈ£¸ñ·Ï Ç¥½Ã";
				oFromPhoneListTypeSetSec.insertAdjacentElement("beforeEnd",oLabelFixPhoneList);
			}

			var oFixPhoneListSetSec = document.createElement('div');
			oFixPhoneListSetSec.style.position = "relative";
			oFixPhoneListSetSec.style.margin = "10px auto 0 auto";
			oFixPhoneListSetSec.style.width = "90%";
			oFixPhoneListSetSec.style.textAlign = "center";
			//oFixPhoneListSetSec.style.border = "1px solid red";
			oFromPhoneListSetBox.insertAdjacentElement("beforeEnd",oFixPhoneListSetSec);
			{
				var oLabelSec = document.createElement('span');
				oLabelSec.style.display = "inline-block";
				oLabelSec.style.cssFloat = "left";
				oLabelSec.style.styleFloat = "left";
				oLabelSec.style.verticalAlign = "middle";
				oLabelSec.style.margin = "0px 0 0 10px";
				oLabelSec.style.padding = "4px 0 0 0";
				//oLabelSec.style.border = "1Px solid red";
				oLabelSec.innerHTML = "°íÁ¤¹øÈ£¸ñ·Ï:";
				oFixPhoneListSetSec.insertAdjacentElement("beforeEnd",oLabelSec);

				var oFixPhoneListSec = document.createElement('ul');
				oFixPhoneListSec.style.listStyle = "none";
				oFixPhoneListSec.style.cssFloat = "left";
				oFixPhoneListSec.style.styleFloat = "left";
				oFixPhoneListSec.style.width = "150px";
				oFixPhoneListSec.style.height = "100px";
				oFixPhoneListSec.style.overflow = "auto";
				oFixPhoneListSec.style.margin = "0 0px 0 3px";
				oFixPhoneListSec.style.padding = "0px";
				oFixPhoneListSec.style.border = "1px solid #93A7D0";
				oFromPhoneListSetBox.oFixPhoneListSec = oFixPhoneListSec;
				oFixPhoneListSetSec.insertAdjacentElement("beforeEnd",oFixPhoneListSec);

				var oTmpSec = document.createElement('div');
				oTmpSec.style.clear = "both";
				oFixPhoneListSetSec.insertAdjacentElement("beforeEnd",oTmpSec);


				var oFixPhoneAddSec = document.createElement('div');
				oFixPhoneAddSec.style.margin = "10px auto 0 auto";
				oFixPhoneAddSec.style.textAlign = "center";
				//oFixPhoneAddSec.style.border = "1px solid red";
				oFixPhoneListSetSec.insertAdjacentElement("beforeEnd",oFixPhoneAddSec);
				{
					var oLabelSec = document.createElement('span');
					oLabelSec.style.display = "inline-block";
					oLabelSec.style.verticalAlign = "middle";
					oLabelSec.style.padding = "4px 0 0 0";
					//oLabelSec.style.border = "1Px solid red";
					oLabelSec.innerHTML = "¹øÈ£ :";
					oFixPhoneAddSec.insertAdjacentElement("beforeEnd",oLabelSec);

					var oFixPhoneSec = document.createElement('span');
					oFixPhoneSec.style.display = "inline-block";
					oFixPhoneSec.style.verticalAlign = "middle";
					oFixPhoneSec.style.margin = "0 0px 0 3px";
					//oFixPhoneSec.style.border = "1px solid red";
					oFixPhoneAddSec.insertAdjacentElement("beforeEnd",oFixPhoneSec);
					{
						var oInputFixPhone = document.createElement('input');
						oInputFixPhone.type = "text";
						oInputFixPhone.style.width = "120px";
						oFromPhoneListSetBox.oInputFixPhone = oInputFixPhone;
						oFixPhoneSec.insertAdjacentElement("beforeEnd",oInputFixPhone);
					}

					var oAddButtonSec = document.createElement('span');
					oAddButtonSec.style.display = "inline-block";
					oAddButtonSec.style.verticalAlign = "middle";
					oAddButtonSec.style.margin = "0 0 0 5px";
					oFixPhoneAddSec.insertAdjacentElement("beforeEnd",oAddButtonSec);
					{
						var oButtonAdd = document.createElement('button');
						oButtonAdd.style.width = "80px";
						oButtonAdd.innerHTML = "¹øÈ£ Ãß°¡";
						oButtonAdd.attachEvent("onclick", function(e){AddFromPhoneInInSettingBox();} );
						oAddButtonSec.insertAdjacentElement("beforeEnd",oButtonAdd);
					}
				}

				var oDisableSec2 = document.createElement('div');
				oDisableSec2.style.position = "absolute";
				oDisableSec2.style.top = "-5px";
				oDisableSec2.style.left = "0px";
				oDisableSec2.style.width = "100%";
				oDisableSec2.style.height = "145px";
				oDisableSec2.style.display = "none";
				oDisableSec2.style.backgroundColor = "#E5E3E3";
				oDisableSec2.style.filter = "alpha(opacity=50)";
				oDisableSec2.style.opacity = "0.5";
				oFromPhoneListSetBox.oDisableSec = oDisableSec2;
				oFixPhoneListSetSec.insertAdjacentElement("beforeEnd",oDisableSec2);
			}

			oRadioRecnetFromPhoneList.attachEvent("onclick", function(e){oDisableSec2.style.display="block";} );
			oRadioFixPhoneList.attachEvent("onclick", function(e){oDisableSec2.style.display="none";} );

		}
		
		var bottom_round = RtnTableBtmRound("100%", "#FFFFFF", "#D8D8D8");
		oGuide.insertAdjacentHTML("beforeEnd",bottom_round);		
	}

	var oMngSec = document.createElement('div');
	oMngSec.style.padding = "10px 0 20px 0";
	oMngSec.style.textAlign = "center";
	oContent.insertAdjacentElement("beforeEnd",oMngSec);
	{
		var oButtonSave = document.createElement('button');
		oButtonSave.style.width = "60px";
		oButtonSave.innerHTML = "Àú Àå";
		oButtonSave.attachEvent("onclick", function(e){SaveFromPhoneSetting();} );
		oMngSec.insertAdjacentElement("beforeEnd",oButtonSave);

		var oButtonCancel = document.createElement('button');
		oButtonCancel.style.width = "60px";
		oButtonCancel.style.margin = "0 0 0 10px";
		oButtonCancel.innerHTML = "Ãë ¼Ò";
		oButtonCancel.attachEvent("onclick", function(e){oPopupFromPhoneSetting.Hide();} );
		oMngSec.insertAdjacentElement("beforeEnd",oButtonCancel);
	}

	var oProcessingBox = document.createElement('div'); 
	oProcessingBox.style.position = "absolute";
	oProcessingBox.style.top = "80px";
	oProcessingBox.style.left = "40px";
	oProcessingBox.style.width = "250px";
	oProcessingBox.style.height = "80px";
	oProcessingBox.style.display = "none";
	oProcessingBox.style.backgroundColor = "#ffffff";
	oProcessingBox.style.textAlign = "center";
	oProcessingBox.style.border = "2px outset #EFDADA";
	oContent.oProcessingBox = oProcessingBox;
	oContent.insertAdjacentElement("beforeEnd",oProcessingBox);		
	{
		var oImgDel = document.createElement('img');
		oImgDel.src = "/phone_book/image/processing.gif";
		oProcessingBox.insertAdjacentElement("beforeEnd",oImgDel);
	}
}

function GetFromPhoneSettingInfo()
{
	var oAJAX = new AJAX();
	var args = 'action=from_phone_setting_info';
	oAJAX.Request("/process_fromphone.php", DisFromPhoneSettingInfo, args);
}

function DisFromPhoneSettingInfo(data)
{
	//alert(data);
	//return;

	var JSON = eval('(' + data + ')');

	if(JSON.result == 'err')
	{
		alert(JSON.result_str);
		oPopupFromPhoneSetting.Hide();
		return;
	}

	var oRadioRecnetPhoneAutoInput = oPopupFromPhoneSetting.oContent.oFromPhoneAutoInputSetBox.oRadioRecnetPhoneAutoInput;
	var oRadioFixPhoneAutoInput = oPopupFromPhoneSetting.oContent.oFromPhoneAutoInputSetBox.oRadioFixPhoneAutoInput;
	var oInputFixPhone = oPopupFromPhoneSetting.oContent.oFromPhoneAutoInputSetBox.oInputFixPhone;
	var oDisableFixPhoneSetSec = oPopupFromPhoneSetting.oContent.oFromPhoneAutoInputSetBox.oDisableSec;

	if(JSON.phone_type == "fix")
	{
		oRadioFixPhoneAutoInput.checked = true;
		oDisableFixPhoneSetSec.style.display = "none";
	}else {
		oRadioRecnetPhoneAutoInput.checked = true;
		oDisableFixPhoneSetSec.style.display = "block";
	}

	if(JSON.fromphone_list.length > 0)
	{
		oInputFixPhone.value = JSON.fromphone_list[0].phone;
	}

	var oRadioRecnetFromPhoneList = oPopupFromPhoneSetting.oContent.oFromPhoneListSetBox.oRadioRecnetFromPhoneList;
	var oRadioFixPhoneList = oPopupFromPhoneSetting.oContent.oFromPhoneListSetBox.oRadioFixPhoneList;
	var oDisableFixPhoneListSetSec = oPopupFromPhoneSetting.oContent.oFromPhoneListSetBox.oDisableSec;

	if(JSON.list_type == "fix")
	{
		oRadioFixPhoneList.checked = true;
		oDisableFixPhoneListSetSec.style.display = "none";
	}else {
		oRadioRecnetFromPhoneList.checked = true;
		oDisableFixPhoneListSetSec.style.display = "block";
	}

	DisFromPhoneListInSettingBox(JSON.fromphone_list)
}

function DisFromPhoneListInSettingBox(oListSet)
{
	var oListSec = oPopupFromPhoneSetting.oContent.oFromPhoneListSetBox.oFixPhoneListSec;

	var total_record = oListSet.length;

	if(total_record > 0)
	{
		var oList = null;
		for(i=0 ; i<total_record ; i++)
		{
			if(oListSet[i].o_pid != 0)
			{
				oList = CreateFromPhoneListInSettingBox(oListSet[i]);				
				
				oListSec.insertAdjacentElement("beforeEnd",oList);
			}
		}
	}
}

function CreateFromPhoneListInSettingBox(oListInfo)
{
	var oList = document.createElement('li');
	oList.pid = oListInfo.pid;
	oList.style.textAlign = "left";
	oList.style.padding = "2px 0 2px 5px";
	{
		var oPhoneSec = document.createElement('span');
		oPhoneSec.style.width = "80px";
		oPhoneSec.style.textAlign = "left";
		oPhoneSec.style.display = "inline-block";
		oPhoneSec.style.verticalAlign = "middle";
		//oPhoneSec.style.border = "1px solid red";
		oPhoneSec.style.margin = "0 0 0 0px";
		oPhoneSec.innerHTML = oListInfo.phone;
		oList.insertAdjacentElement("beforeEnd",oPhoneSec);

		var oImgDel = document.createElement('img');
		oImgDel.src = "/images/icon_close.gif";
		oImgDel.title = "»èÁ¦";
		oImgDel.style.cursor = "pointer";
		oImgDel.style.verticalAlign = "middle";
		oImgDel.style.margin = "0 0 0 5px";
		oImgDel.attachEvent("onclick", function(e){ DelFromPhoneInInSettingBox(oList); } );
		oList.oImgDel = oImgDel;
		oList.insertAdjacentElement("beforeEnd",oImgDel);
	}

	return oList;	
}

function DelFromPhoneInInSettingBox(oList)
{
	if(confirm("»èÁ¦ÇÏ½Ã°Ú½À´Ï±î?"))
	{
		var pid = oList.pid;
		var sel_obj_id = GetUniqueID(oList);
		
		var args = 'action=del_fromphone&sel_obj_id='+sel_obj_id+'&pid='+pid;
		var oAJAX = new AJAX();
		oAJAX.Request('./process_fromphone.php', ResultProcessFromPhone, args);
	}
}

function AddFromPhoneInInSettingBox()
{	
	var oFromPhone  = oPopupFromPhoneSetting.oContent.oFromPhoneListSetBox.oInputFixPhone;
	if(oFromPhone.value == 0)
	{
		alert("ÀüÈ­¹øÈ£¸¦ ÀÔ·ÂÇØÁÖ¼¼¿ä.");
		oFromPhone.focus();
		return false;
	}

	var args = 'action=add_fromphone&fromphone='+oFromPhone.value;
	var oAJAX = new AJAX();
	oAJAX.Request('./process_fromphone.php', ResultProcessFromPhone, args);
}

function SaveFromPhoneSetting()
{
	var oRadioRecnetPhoneAutoInput = oPopupFromPhoneSetting.oContent.oFromPhoneAutoInputSetBox.oRadioRecnetPhoneAutoInput;
	var oRadioFixPhoneAutoInput = oPopupFromPhoneSetting.oContent.oFromPhoneAutoInputSetBox.oRadioFixPhoneAutoInput;
	var oInputFixPhone = oPopupFromPhoneSetting.oContent.oFromPhoneAutoInputSetBox.oInputFixPhone;

	var fix_fromphone = oInputFixPhone.value;
		
	var phone_opt = '';
	if(oRadioRecnetPhoneAutoInput.checked == true)
	{
		phone_opt = oRadioRecnetPhoneAutoInput.value;
	}else {
		phone_opt = oRadioFixPhoneAutoInput.value;
	}

	var oRadioRecnetFromPhoneList = oPopupFromPhoneSetting.oContent.oFromPhoneListSetBox.oRadioRecnetFromPhoneList;
	var oRadioFixPhoneList = oPopupFromPhoneSetting.oContent.oFromPhoneListSetBox.oRadioFixPhoneList;

	var list_opt = '';
	if(oRadioRecnetFromPhoneList.checked == true)
	{
		list_opt = oRadioRecnetFromPhoneList.value;
	}else {
		list_opt = oRadioFixPhoneList.value;
	}

	var oProcessingBox = oPopupFromPhoneSetting.oContent.oProcessingBox;
	oProcessingBox.style.display = "block";

	var args = 'action=save_setting&fix_fromphone='+fix_fromphone+'&phone_opt='+phone_opt+'&list_opt='+list_opt;
	var oAJAX = new AJAX();
	oAJAX.Request('./process_fromphone.php', ResultProcessFromPhone, args);
}

function CloseFromPhoneSettingBox()
{
	if(confirm("ÇöÀç¼³Á¤À» ÀúÀåÇÏ½Ã°Ú½À´Ï±î?"))
	{
		SaveFromPhoneSetting();
	}else {
		oPopupFromPhoneSetting.Hide();
	}
}

function ResultProcessFromPhone(data)
{
	//alert(data);
	//return;
	
	var JSON = eval('(' + data + ')');

	if(JSON.result != 'ok')
	{
		alert(JSON.result_str);
		return;
	}else {
		switch (JSON.action)
		{
			case 'add_fromphone':	
				
				var oFromPhone = oPopupFromPhoneSetting.oContent.oFromPhoneListSetBox.oInputFixPhone;

				var oListInfo = new Object();
				oListInfo.pid = JSON.pid;
				oListInfo.phone = JSON.phone;

				var oList = CreateFromPhoneListInSettingBox(oListInfo);

				var oListSec = oPopupFromPhoneSetting.oContent.oFromPhoneListSetBox.oFixPhoneListSec;
						
				oListSec.insertAdjacentElement("beforeEnd",oList);
	
				oFromPhone.value = '';
				break

			case 'save_setting':
				var oProcessingBox = oPopupFromPhoneSetting.oContent.oProcessingBox;
				oProcessingBox.style.display = "none";

				alert("ÀúÀåµÇ¾ú½À´Ï´Ù.");
				document.getElementById("from_phone").value = JSON.from_phone;

				oPopupFromPhoneSetting.Hide();
			
				break

			case 'del_fromphone':
				
				var oList = document.getElementById(JSON.sel_obj_id)

				oList.parentNode.removeChild(oList);	
				break


		}
	}
}

function FromPhoneACArrow_Click()
{
	if (document.getElementById("from_phone_list_sec").style.display != "block")
	{
		GetFromvPhoneList(2);
	}else {
		HideFromPhoneList();
	}
}

function GetFromvPhoneList(mode)
{
	if(mode == 1)
	{
		var last_input_fromhone = document.getElementById("from_phone").value;
	}else {
		var last_input_fromhone = '';
	}

	var oAJAX = new AJAX();
	var args = 'action=fromphone_list&input_phone='+last_input_fromhone;
	oAJAX.Request("/process_fromphone.php", ShowFromPhoneList, args);
}

function ShowFromPhoneList(data)
{
	//alert(data);
	//return;

	var JSON = eval('(' + data + ')');

	if(JSON.result == 'err')
	{
		alert(JSON.result_str);
		return;
	}

	document.getElementById("from_phone_list_sec").style.display = "block";
	DisFromPhoneList(JSON);
}

function DisFromPhoneList(oInfo)
{
	var oListSec = document.getElementById("from_phone_list_sec");
	oListSec.innerHTML = '';

	var total_record = oInfo.list.length;

	if(total_record > 0)
	{
		var oList = null;
		for(i=0 ; i<total_record ; i++)
		{
			oList = CreateFromPhoneList(oInfo.list[i]);				
			
			oListSec.insertAdjacentElement("beforeEnd",oList);
		}
	}else {
		var list_HTML = '';
		list_HTML += '<li style="width:100%;text-align:center;padding:10px 0 10px 0;"></li>';

		oListSec.insertAdjacentHTML("beforeEnd",list_HTML);
	}

	if(oListSec.scrollHeight > 70)
	{
		oListSec.style.height = "80px";
	}
}

function CreateFromPhoneList(oListInfo)
{
	var oList = document.createElement('li');
	oList.from_phone = oListInfo.from_phone;
	oList.style.fontSize = "13px";
	oList.style.cursor = "pointer";
	oList.style.padding = "2px 0 2px 5px";
	oList.innerHTML = oListInfo.from_phone;
	oList.attachEvent("onclick", function(e){FromPhoneList_MouseClick(oList);} );
	oList.attachEvent("onmouseover", function(e){oList.style.background = "#f6f6f6";} );
	oList.attachEvent("onmouseout", function(e){oList.style.background = "#ffffff";} );
	return oList;	
}

function InitRcvInfo()
{
	selected_phone_idx = -1;
}


function HideFromPhoneListCheck(e)
{
	var oThis = null;
	if(typeof HTMLElement == "undefined")
	{
		oThis = e.srcElement;
	}else {
		oThis = e.target;
	}

	if (oThis.id != "from_phone" && oThis.id != "from_phone_list_sec" && typeof(oThis.parentNode) != "undefined" && oThis.parentNode.id != "fromphone_box")
	{
		HideFromPhoneList();
	}
}

function HideFromPhoneList()
{
	try
	{
		var destObj = document.getElementById("from_phone_list_sec");
		destObj.style.display = "none";
		selected_phone_idx = -1;		
	}
	catch (e)
	{
	}
}

function FromPhone_OnKeyDown(e)
{
	// UP
	if (e.keyCode == 38)
	{
		MovePhones("UP");
	}
	// DOWN
	else if (e.keyCode == 40)
	{
		if (document.getElementById("from_phone_list_sec").style.display == "block")
		{
			MovePhones("DOWN");
		}
		else
		{
			GetFromvPhoneList(1);
		}
	}
	else if ((e.keyCode >= 48 && e.keyCode <= 57) || (e.keyCode >= 96 && e.keyCode <= 105) || (e.keyCode >= 37 && e.keyCode <= 40) || (e.keyCode >= 8 && e.keyCode <= 9) || (e.keyCode == 46) || (e.keyCode >= 35 && e.keyCode <= 36) || (e.keyCode == 116))
	{

	}
	else
	{
		//event.returnValue = false;
	}
}

function FromPhone_OnKeyUp(e)
{
	if ((e.keyCode >= 48 && e.keyCode <= 57) || (e.keyCode >= 96 && e.keyCode <= 105) || (e.keyCode >= 8 && e.keyCode <= 9) || (e.keyCode == 46))

	{
		GetFromvPhoneList(1);
	}
	else if (e.keyCode == 13)
	{
		HideFromPhoneList();
	}
}


function MovePhones(dir)
{
	var destObj = document.getElementById("from_phone_list_sec");
	
	if (destObj.style.display != "block")
	{
		return;
	}
	
	var phones = destObj.childNodes;
	
	if (dir == "UP")
	{
		if (selected_phone_idx > 0)
		{
			selected_phone_idx--;
		}
		else
		{
			document.getElementById("from_phone").value = last_input_rcvphone;
			HideFromPhoneList();
			return;
		}
	}
	else if (dir == "DOWN")
	{
		if (selected_phone_idx+1 < phones.length)
		{
			selected_phone_idx++;
		}
	}
	
	for (var i=0; i<phones.length; i++)
	{
		if (i == selected_phone_idx)
		{
			phones[i].style.backgroundColor = "#f6f6f6";
			document.getElementById("from_phone").value = phones[i].innerHTML;
			
		}
		else
		{
			phones[i].style.backgroundColor = "#FFFFFF";
		}
	}
	
	destObj.scrollTop = Math.floor(selected_phone_idx / 7) * 120;
}

function FromPhoneList_MouseOver()
{
	var phones = document.getElementById("from_phone_list_sec").getElementsByTagName("LI");
	for (var i=0; i<phones.length; i++)
	{
		phones[i].style.backgroundColor = "#FFFFFF";
	}
	selected_phone_idx = -1;
	
	var destObj = event.srcElement;
	var phones = destObj.style.backgroundColor = "#f6f6f6";
}

function FromPhoneList_MouseOut()
{
	var destObj = event.srcElement;
	var phones = destObj.style.backgroundColor = "#FFFFFF";
}

function FromPhoneList_MouseClick(oList)
{
	document.getElementById("from_phone").value = oList.innerHTML;
	
	HideFromPhoneList();
}
