function number_format(num)
{
	var f_num='';
	var a1 = num%1000;	
	var a2 = parseInt(num/1000);

	if(a2 == 0) 
	{	
		f_num = a1;
		return  f_num;
	
	}else {
		a2 = number_format(a2);
		var tmp=new String(1000+a1);
		a1=tmp.slice(1);
	}

	f_num = a2+','+a1;

	return f_num;
}

function ResizePopupWin(fWidth, fHeight)
{
	var myWidth;
	var myHeight;

	if (fWidth == null || isNaN(fWidth))
	{
		myWidth = parseInt(document.body.scrollWidth);
	}
	else
	{
		myWidth = fWidth;
	}

	if (fHeight == null || isNaN(fHeight))
	{
		myHeight = parseInt(document.body.scrollHeight);
	}
	else
	{
		myHeight = fHeight;
	}

	var oDiv = document.createElement("DIV");
	oDiv.style.position = "absolute";
	oDiv.style.left = "0px";
	oDiv.style.top = "0px";
	oDiv.style.width = "100%";
	oDiv.style.height = "100%";

	document.body.appendChild(oDiv);

	window.resizeBy(myWidth - oDiv.offsetWidth, myHeight - oDiv.offsetHeight);

	document.body.removeChild(oDiv);
}

function trim(str)
{
	return str.replace(/^\s+|\s+$/g, "");
} 

//¹®ÀÚ Á¦°Å
function RemoveChar(str)
{
	var pattern = new RegExp("[^0-9]", "g");
	
	var rtnStr = str.replace(pattern, '');

	return rtnStr;
}


function htmlspecialchars_decode(chars)
{
	var rtnChars = chars;
	rtnChars = rtnChars.replace(/&quot;/g, '"');
	rtnChars = rtnChars.replace(/&lt;/g, '<');
	rtnChars = rtnChars.replace(/&gt;/g, '>');
	rtnChars = rtnChars.replace(/&amp;/g, '&');

	return rtnChars;
}

function GetUniqueID(oElement)
{
	var u_id = oElement.uniqueID;
	oElement.id = u_id;

	if(typeof(u_id) == 'undefined')
	{
		while(1)
		{
			u_id = 'id_' + Math.floor(Math.random()*10000);
			if(document.getElementById(u_id) == null)
			{
				oElement.id = u_id;
				break;
			}
		}
	}

	return u_id;
}

function GetFirstChild(oParent, tagName)
{
	var oFirstCat = null;
	try
	{
		for(i in oParent.childNodes)
		{
			if(oParent.childNodes[i].tagName == tagName)
			{
				oFirstCat = oParent.childNodes[i];
				break;
			}
		}
	}
	catch(e)
	{
	}

	return oFirstCat;
}

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

	return oTarget;
}

function CreateRoundBox(width, top_bg_color, mid_bg_color, bottom_bg_color, bdr_color)
{
	var oBox = document.createElement('div');
	oBox.style.width = width;
	oBox.style.height = "auto";
	with(oBox)
	{
		var oTopRound = RtnTableTopRound("100%", top_bg_color, bdr_color);
		insertAdjacentHTML("beforeEnd",oTopRound);

		var oMiddleSec = document.createElement('div');
		oMiddleSec.style.textAlign = "center";
		oMiddleSec.style.height = "100%";
		oMiddleSec.style.backgroundColor = mid_bg_color;
		oMiddleSec.style.borderLeftWidth = "1px";
		oMiddleSec.style.borderLeftStyle = "solid";
		oMiddleSec.style.borderLeftColor = bdr_color;
		oMiddleSec.style.borderRightWidth = "1px";
		oMiddleSec.style.borderRightStyle = "solid";
		oMiddleSec.style.borderRightColor = bdr_color;
		oBox.oContentSec = oMiddleSec;
		insertAdjacentElement("beforeEnd",oMiddleSec);

		var oBottomRound = RtnTableBtmRound("100%", bottom_bg_color, bdr_color);
		insertAdjacentHTML("beforeEnd",oBottomRound);
	}

	return oBox;
}

function InsertLoading(oParent)
{
	oParent.innerHTML = "";
	var oLoading = document.createElement('div');
	oLoading.style.padding = "20px 0 20px 0";
	oLoading.style.fontWeight = "bold";
	oLoading.style.textAlign = "center";
	oLoading.innerHTML = "Loading......";
	oParent.oLoading = oLoading;
	oParent.insertAdjacentElement("beforeEnd",oLoading);
}

function InsertSelectOption(oSelect, value, text)
{
	var oOption = null;
	oOption = document.createElement("option");
	oOption.value = value;
	oOption.text = text;

	if(typeof HTMLSelectElement!="undefined")
	{
		oSelect.add(oOption, null);				
	}else {
		oSelect.add(oOption);				
	}		
}

function InsertFilmOnBody()
{
	var oBody = document.body;

	var oFilm = document.createElement('div');
	oFilm.style.position = "absolute";
	oFilm.style.top = "0px";
	oFilm.style.left = "0px";
	oFilm.style.backgroundColor = "#ffffff";
	if(typeof HTMLSelectElement != "undefined")
	{
		oFilm.style.opacity = "0.5";
	}
	else 
	{
		oFilm.style.filter = "alpha(opacity=50)";
	}		
	oFilm.style.filter = "alpha(opacity=50)";
	oFilm.style.border = "0px solid red";
	oFilm.style.zIndex = "5";
	oFilm.style.width = oBody.clientWidth+"px";
	oFilm.style.height = oBody.scrollHeight+"px"; 
	oBody.oFilm = oFilm;
	oBody.insertAdjacentElement("beforeEnd",oFilm);
}

function RemovefilmOnBody()
{
	var oBody = document.body;
	try
	{
		oBody.removeChild(oBody.oFilm);
	}
	catch (e)
	{
	}
}

function ShowProcessingBox(oParent, top)
{
	var width = 250;
	var oProcessingBox = document.createElement('div'); 
	oProcessingBox.style.position = "absolute";
	oProcessingBox.style.width = width+"px";
	oProcessingBox.style.height = "80px";
	oProcessingBox.style.top = top+"px";
	oProcessingBox.style.left = ((oParent.clientWidth/2)-(width/2)) + 'px';
	oProcessingBox.style.backgroundColor = "#ffffff";
	oProcessingBox.style.textAlign = "center";
	oProcessingBox.style.border = "2px outset #EFDADA";
	oParent.oProcessingBox = oProcessingBox;
	oParent.insertAdjacentElement("beforeEnd",oProcessingBox);		
	with(oProcessingBox)
	{
		var oImg = document.createElement('img');
		oImg.src = "/phone_book/image/processing.gif";
		insertAdjacentElement("beforeEnd",oImg);
	}
}

function HideProcessingBox(oParent)
{
	try
	{
		oParent.removeChild(oParent.oProcessingBox);
	}
	catch (e)
	{
	}

}

//==================ÀüÈ­¹øÈ£ ¸ñ·Ï µî·Ï °ü·Ã==============================

var oPopupRegPhoneList = null;	//ÀüÈ­¹øÈ£ ¸ñ·Ï µî·Ï ÆË¾÷°´Ã¼

function PopRegPhoneList(oThis)
{		
	if(oPopupRegPhoneList == null)
	{
		oPopupRegPhoneList = new Popup();
		
		oPopupRegPhoneList.oPopup.style.zIndex = 910;
		oPopupRegPhoneList.width = "380px";
		oPopupRegPhoneList.top = (oThis.offsetTop + oThis.offsetHeight) + 'px';
		oPopupRegPhoneList.left = (oThis.offsetLeft) + 'px';
		oPopupRegPhoneList.oFirer = oThis;
		oPopupRegPhoneList.SetTitle("¢º ÁÖ¼Ò·Ï¿¡ µî·ÏÇÏ±â");
	}

	if(oPopupRegPhoneList.is_show)
	{
		oPopupRegPhoneList.Hide();
	}
	else 
	{		
		var content = MakePopupRegPhoneListContent();
		oPopupRegPhoneList.SetContent(content);

		oPopupRegPhoneList.Show();
	}
}

function MakePopupRegPhoneListContent()
{
	var contentHTML ='';

	contentHTML += '<div style="width:350px;height:100px;margin:5px auto 20px auto;text-align:center;">';
	contentHTML += '	<div id="reg_phone_list_content_notice" style="text-align:left;color:#006bff;margin-top:10px;">';
	contentHTML += '		¡Ø¿ì¼± ±×·ìÀ» ÇÏ³ª »ý¼ºÇÏ¼Å¾ß ÇÕ´Ï´Ù.';
	contentHTML += '	</div>';
	contentHTML += '	<div style="border:1px solid #d8d6d6;padding:2px;width:95%;margin-top:5px;">';
	contentHTML += '		<div id="reg_phone_list_content_main" style="background-color:#eeeaea;padding:10px 0px;">';
	contentHTML += '			<span>±×·ì¸í :</span>';
	contentHTML += '			<span><input type="text" id="group_name_for_reg_phone_list"/></span>';
	contentHTML += '			<span><button onclick="AddGroupForRegPhoneList();return false;">»ý ¼º</button></span>';
	contentHTML += '		</div>';
	contentHTML += '	</div>';
	contentHTML += '</div>';

	return contentHTML;
}

function AddGroupForRegPhoneList()
{
	var oGroupName = document.getElementById("group_name_for_reg_phone_list");

	if(oGroupName.value == 0)
	{
		alert("±×·ì¸íÀ» ÀÔ·ÂÇØÁÖ¼¼¿ä.");
		oGroupName.focus();
		return false;
	}

	var oAJAX = new AJAX();
	var args = 'action=group_add&group_name='+oGroupName.value;
	oAJAX.Request("/phone_book/process_group.php", ResultProcess_PhoneBook, args);

	var oContentBox = document.getElementById("reg_phone_list_content_main");
	var contentHTML ='<div>Ã³¸®Áß....</div>';
	oContentBox.innerHTML = contentHTML;
}

function AddMemberForRegPhoneList(group_pid)
{
	var add_list = '';
	
	var oRcvrMemberListSec = document.getElementById("rcvr_member_list_box");
	try
	{
		var tmp = '';
		for(i in oRcvrMemberListSec.childNodes)
		{
			if(oRcvrMemberListSec.childNodes[i].tagName == 'LI')
			{
				if(oRcvrMemberListSec.childNodes[i].oInputPhone.value != 0)
				{
					tmp = oRcvrMemberListSec.childNodes[i].oInputName.value + '*@' + oRcvrMemberListSec.childNodes[i].oInputPhone.value;
					add_list += tmp + '|';		
				}
			}
		}

	}
	catch(e)
	{
	}

	add_list = add_list.slice(0, -1);

	var oAJAX = new AJAX();
	var args = 'action=add_member&group_pid='+group_pid+'&add_list='+add_list;
	oAJAX.Request("/phone_book/process_phone_book.php", ResultProcess_PhoneBook, args);

	var oContentBox = document.getElementById("reg_phone_list_content_main");
	var contentHTML ='<div>Ã³¸®Áß....</div>';
	oContentBox.innerHTML = contentHTML;
}

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

	if(JSON.result != 'ok')
	{
		alert(JSON.result_str);
		return;
	}else {
		switch (JSON.action)
		{
			case 'group_add':
				var group_pid = JSON.group_pid;
				var group_name = JSON.group_name;

				var oContentBox = document.getElementById("reg_phone_list_content_main");
				var oNotice = document.getElementById("reg_phone_list_content_notice");

				oNotice.style.display="none";

				var contentHTML ='';
				contentHTML += '<div style="width:90%;margin:0 0 5px 0;text-align:left;">±×·ì¸í : <b>'+group_name+'</b></div>';
				contentHTML += '<div style="width:90%;margin:0 0 5px 0;text-align:left;">±×·ìÀÌ Á¤»óÀûÀ¸·Î »ý¼ºµÇ¾ú½À´Ï´Ù.<br>¾Æ·¡ ÀúÀå¹öÆ°À» ´©·ç½Ã¸é ÀÔ·ÂÇÏ¼Ì´ø ÀüÈ­¹øÈ£ ¸ñ·ÏÀÌ ÇØ´ç ±×·ì¿¡ ÀúÀåµË´Ï´Ù.ÀúÀåÀ» ´­·¯ÁÖ¼¼¿ä.</div>';
				contentHTML += '<div><button onclick="AddMemberForRegPhoneList('+group_pid+');return false;">Àú Àå</button></div>';
				
				oContentBox.innerHTML = contentHTML;
				oPopupRegPhoneList.AdjustSize();
				break
			case 'add_member':
				var oContentBox = document.getElementById("reg_phone_list_content_main");

				var contentHTML ='';
				contentHTML += '<div style="width:90%;margin:0 0 5px 0;text-align:left;">Á¤»óÀûÀ¸·Î µî·ÏµÇ¾ú½À´Ï´Ù.<br>µî·ÏµÈ ÀüÈ­¹øÈ£´Â ¾ðÁ¦µçÁö ÁÖ¼Ò·Ï¿¡¼­ ºÒ·¯¿Í »ç¿ëÇÏ½Ç ¼ö ÀÖ½À´Ï´Ù.<br>¶ÇÇÑ »ó´Ü¸Þ´º [ÁÖ¼Ò·Ï°ü¸®]¿¡¼­ È®ÀÎ ¹× °ü¸®¸¦ ÇÏ½Ç ¼ö ÀÖ½À´Ï´Ù.</div>';
				contentHTML += '<div><button onclick="oPopupRegPhoneList.Hide();return false;">È® ÀÎ</button></div>';
				
				oContentBox.innerHTML = contentHTML;
				oPopupRegPhoneList.AdjustSize();
				break
		}
	}
}
//================================================================

//==================ÆäÀÌÁö ³×ºñ °ü·Ã==============================
function CreatePageNavi(oInfo, oPageNaviSec, pCallback)
{
	oPageNaviSec.innerHTML = '';
	var page = oInfo.page;
	var total_page = oInfo.total_page;
	var first_page = oInfo.first_page;
	var last_page = oInfo.last_page;
	var isPrevBlock = oInfo.isPrevBlock;
	var PrevPage = oInfo.PrevPage;
	var isNextBlock = oInfo.isNextBlock;
	var NextPage = oInfo.NextPage;

	if( page > 10 ) 
	{
		var oFirstPage = CreateEachPage(1, pCallback);
		oFirstPage.innerHTML = '[1]';
		oPageNaviSec.insertAdjacentElement("beforeEnd",oFirstPage);
	}

	if (isPrevBlock)
	{
		var oPrevBlock = CreateEachPage(PrevPage, pCallback);
		oPrevBlock.innerHTML = '¢¸';
		oPageNaviSec.insertAdjacentElement("beforeEnd",oPrevBlock);
	}

	for(i=first_page; i<=parseInt(last_page); i++)
	{
		if (i == page)
		{
			var oCurrPage = document.createElement('span');
			oCurrPage.style.width = "25px";
			oCurrPage.style.fontSize = "13px";
			oCurrPage.style.margin = "0 0 0 2px";
			oCurrPage.style.padding = "4px 0px 2px 0px";
			oCurrPage.style.textAlign = "center";
			oCurrPage.style.display = "inline-block";
			oCurrPage.style.verticalAlign = "middle";
			oCurrPage.style.border = "1px solid #b8b2b2";
			oCurrPage.innerHTML = i;
			oPageNaviSec.insertAdjacentElement("beforeEnd",oCurrPage);
		}
		else
		{
			var oEachPage = CreateEachPage(i, pCallback);
			oEachPage.innerHTML = i;
			oPageNaviSec.insertAdjacentElement("beforeEnd",oEachPage);
		}
	}

	if (isNextBlock)
	{
		var oNextBlock = CreateEachPage(NextPage, pCallback);
		oNextBlock.innerHTML = '¢º';
		oPageNaviSec.insertAdjacentElement("beforeEnd",oNextBlock);
	}

	if( total_page > 10 && parseInt(last_page) < parseInt(total_page) ) 
	{
		var oLastPage = CreateEachPage(total_page, pCallback);
		oLastPage.innerHTML = '['+total_page+']';
		oPageNaviSec.insertAdjacentElement("beforeEnd",oLastPage);
	}
}

function CreateEachPage(page, pCallback)
{
	var oEachPage = document.createElement('span');
	oEachPage.style.width = "25px";
	oEachPage.style.fontSize = "13px";
	oEachPage.style.margin = "0 0 0 2px";
	oEachPage.style.padding = "4px 0px 2px 0px";
	oEachPage.style.textAlign = "center";
	oEachPage.style.display = "inline-block";
	oEachPage.style.verticalAlign = "middle";
	oEachPage.style.border = "1px solid #ffffff";
	oEachPage.style.fontWeight = "bold";
	oEachPage.style.cursor = "pointer";
	oEachPage.attachEvent("onmouseover", function(e){oEachPage.style.border = "1px solid #b8b2b2";oEachPage.style.color = "#ff0000";} );
	oEachPage.attachEvent("onmouseout", function(e){oEachPage.style.border = "1px solid #FFFFFF";oEachPage.style.color = "#000000";} );
	oEachPage.attachEvent("onclick", function(e){pCallback(page);} );

	return oEachPage;
}
//============================================================================================================

//IE, FireFox ÀÏºÎ ÇÔ¼ö È£È¯
if(typeof HTMLElement!="undefined")
{
    HTMLElement.prototype.insertAdjacentElement = function(where,parsedNode)
	{
        switch (where){
            case 'beforeBegin':
            this.parentNode.insertBefore(parsedNode,this)
            break;
            case 'afterBegin':
            this.insertBefore(parsedNode,this.firstChild);
            break;
            case 'beforeEnd':
            this.appendChild(parsedNode);
            break;
            case 'afterEnd':
            if (this.nextSibling) this.parentNode.insertBefore(parsedNode,this.nextSibling);
            else this.parentNode.appendChild(parsedNode);
            break;
        }
    }

	HTMLElement.prototype.insertAdjacentHTML = function (sWhere, sHTML) {
	   var df;   // : DocumentFragment
	   var r = this.ownerDocument.createRange();
	   
	   switch (String(sWhere).toLowerCase()) {  // convert to string and unify case
		  case "beforebegin":
			 r.setStartBefore(this);
			 df = r.createContextualFragment(sHTML);
			 this.parentNode.insertBefore(df, this);
			 break;
			 
		  case "afterbegin":
			 r.selectNodeContents(this);
			 r.collapse(true);
			 df = r.createContextualFragment(sHTML);
			 this.insertBefore(df, this.firstChild);
			 break;
			 
		  case "beforeend":
			 r.selectNodeContents(this);
			 r.collapse(false);
			 df = r.createContextualFragment(sHTML);
			 this.appendChild(df);
			 break;
			 
		  case "afterend":
			 r.setStartAfter(this);
			 df = r.createContextualFragment(sHTML);
			 this.parentNode.insertBefore(df, this.nextSibling);
			 break;
	   }   
	};
    
    HTMLElement.prototype.insertAdjacentText = function(where,txtStr)
	{
        var parsedText = document.createTextNode(txtStr)
        this.insertAdjacentElement(where,parsedText)
    }

    HTMLElement.prototype.attachEvent = function(event,func)
	{
		this.addEventListener(event.replace(/^on/,""), func, false); 
    }

    HTMLElement.prototype.detachEvent = function(event,func)
	{
        this.removeEventListener(event.replace(/^on/,""), func, false); 
    }

    HTMLDocument.prototype.attachEvent = function(event,func)
	{
		this.addEventListener(event.replace(/^on/,""), func, false); 
    }

    HTMLDocument.prototype.detachEvent = function(event,func)
	{
        this.removeEventListener(event.replace(/^on/,""), func, false); 
    }
}

if(typeof HTMLDocument!="undefined")
{

}