//¿ÞÂÊ °ø¹é¹®ÀÚ Á¦°Å(º°·Î ¾ÈÁÁ¾Æº¸ÀÌ¹Ç·Î ´ã¿¡ ´Ù½Ã ¹Ù²ÙÀÚ)
function fn_Ltrim(strValue)
{
	try
	{
		while (strValue.length>0)
		{ 
			if(strValue.charAt(0) == ' ')
			{
				strValue=strValue.substring(1,strValue.length);
			} 
			else
			{
				return strValue;
			}
		} 
		return strValue; 
	}
	catch(e)
	{
		alert(e.description);
	}
}
//¿À¸¥ÂÊ °ø¹é¹®ÀÚ Á¦°Å(º°·Î ¾ÈÁÁ¾Æº¸ÀÌ¹Ç·Î ´ã¿¡ ´Ù½Ã ¹Ù²ÙÀÚ)
function fn_Rtrim(strValue)
{
	try
	{
		while (strValue.length>0)
		{ 
			if(strValue.charAt(strValue.length-1)==' ')
			{
				strValue=strValue.substring(0,strValue.length-1);
			} 
			else
			{
				return strValue;
			}
		} 
		return strValue; 
	}
	catch(e)
	{
		alert(e.description);
	}
}
//String ÀÇ °ø¹éÀ» ¸ðµÎ Á¦°ÅÇÑ´Ù.
function fn_Trim(sourceString)
{
	var strResult ;
	try
	{
		strResult = sourceString.replace(/\s/g,"");
		return strResult;
	}
	catch(exception){}
}

//String ÀÇ ¾çÂÊ°ø¹éÀ» ¸ðµÎ Á¦°ÅÇÑ´Ù.
function fn_RLTrim(strSource)
{
	try
	{
		return strSource.replace(/(^\s*)|(\s*$)/g, "");
	}
	catch(exception){}
}

//¹®ÀÚ¿­ ¹Ù²Þ
function fn_ReplaceAll(oldStr,findStr,repStr)
{
	try
	{
		var srchNdx = 0;
		var newStr = ""; 
		while (oldStr.indexOf(findStr,srchNdx) != -1)  
		{
			newStr += oldStr.substring(srchNdx,oldStr.indexOf(findStr,srchNdx));
			newStr += repStr;
			srchNdx = (oldStr.indexOf(findStr,srchNdx) + findStr.length);
		}
		newStr += oldStr.substring(srchNdx,oldStr.length);
		return newStr;
	}
	catch(exception){}
}

//À©µµ¿ìÃ¢ ¸ð´ÏÅÍÈ­¸é °¡¿îµ¥ ¶ç¿ì±â
function fn_OpenCenterWindow(url, width, height, winName, feature)
{
	var nTop = 0;
	var nLeft = 0;
	var nHeight = height;
	var nWidth = width;
	var strFeature = "";
	var oWindow = null;
	try
	{
		if(feature != null && feature.length > 0)
			strFeature = "," + feature;
		else
			strFeature = strFeature;

		nTop = (window.screen.height / 2) - (nHeight / 2);
		nLeft = (window.screen.width / 2) - (nWidth / 2);
	
		oWindow = window.open(url, winName, "width=" + nWidth + ",height=" + nHeight + ",top=" + nTop + ",left=" + nLeft + strFeature);
		oWindow.focus();
	}
	catch(e)
	{
		alert(e.description);
	}
	finally
	{
		oWindow = null;
	}
}

//À©µµ¿ìÃ¢ Å¬¸¯ÇÑ ºê¶ó¿ìÁ®ÀÇ °¡¿îµ¥¿¡ ¶ç¿ì±â
function fn_OpenCenterBrowserWindow(url, width, height, winName, feature)
{
	var nTop = 0;
	var nLeft = 0;
	var nHeight = height;
	var nWidth = width;
	var strFeature = "";
	var oWindow = null;
	try
	{
		if(feature != null && feature.length > 0)
			strFeature = "," + feature;
		else
			strFeature = strFeature;

		if(window.document.body.offsetHeight > height && window.document.body.offsetWidth > width)	
		{
			nTop = ((window.document.body.offsetHeight - height) / 2) + window.screenTop;
			nLeft = ((window.document.body.offsetWidth - width) / 2) + window.screenLeft;
		
			if(nTop < (window.screen.height - height) && nLeft < (window.screen.width - width))
			{
				oWindow = window.open(url, winName, "width=" + nWidth + ",height=" + nHeight + ",top=" + nTop + ",left=" + nLeft + strFeature);
				oWindow.focus();
			}
			else
			{
				//»õÃ¢ÀÌ ¸ð´ÏÅÍ È­¸éÀ» ¹þ¾î³ª¸é °¡¿îµ¥ ¿­±â
				fn_OpenCenterWindow(url, width, height, winName, feature);
			}
		}
		else
		{
			//»õÃ¢ÀÌ ´õ Å©¸é ¸ð´ÏÅÍÈ­¸é °¡¿îµ¥¿¡ ¿­±â
			fn_OpenCenterWindow(url, width, height, winName, feature);
		}
	}
	catch(e)
	{
		alert(e.description);
	}
	finally
	{
		oWindow = null;
	}
}

//¸¶¿ì½º Å¬¸¯ÇÑµ¥¼­ ¶ç¿ì±â
function fn_OpenMousePointWindow(url, width, height, winName, feature, MouseEvent)
{
	var nTop = 0;
	var nLeft = 0;
	var nHeight = height;
	var nWidth = width;
	var strFeature = "";
	var oWindow = null;
	var nMouseTop = 0;
	var nMouseLeft = 0;
	try
	{
		nMouseTop = MouseEvent.screenY;
		nMouseLeft = MouseEvent.screenX;

		if(feature != null && feature.length > 0)
			strFeature = "," + feature;
		else
			strFeature = strFeature;

		if((nMouseTop + height) > window.screen.height)
			nTop = (window.screen.height - height) - 90;
		else
			nTop = nMouseTop;
		
		if((nMouseLeft + width) > window.screen.width)
			nLeft = (window.screen.width - width) - 10;
		else
			nLeft = nMouseLeft;

		oWindow = window.open(url, winName, "width=" + nWidth + ",height=" + nHeight + ",top=" + nTop + ",left=" + nLeft + strFeature);
		oWindow.focus();
	}
	catch(e)
	{
		alert(e.description);
	}
	finally
	{
		oWindow = null;
	}
}

//¸ð´ÞÆË¾÷Ã¢À» ¶ì¿î´Ù.
function fn_OpenModalDialog(sUrl,sParam, sFeature)
{
	try
	{
		var strReturn = "";
		strReturn = window.showModalDialog("/include/html/ModalDialog.html?" + sUrl, sParam, sFeature);
		return strReturn;
	}
	catch(exception){}
}

//¸ð´Þ¸®½ºÆË¾÷Ã¢À» ¶ì¿î´Ù.
function fn_OpenModelessDialog(sUrl,sParam, sFeature)
{
	try
	{
		var strReturn = "";
		strReturn = window.showModelessDialog("/include/html/ModelessDialog.html?" + sUrl, sParam, sFeature);
		return strReturn;
	}
	catch(exception){}
}

//Xml¹Þ¾Æ¿À±â
function fn_GetXmlDomDocument(sPage)
{
	var oXmlDoc;
	try
	{
		oXmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		oXmlDoc.async = false;
		oXmlDoc.load(sPage);
		if(oXmlDoc.readyState != 4 && !oXmlDoc.parseError)
		{
			return null;
		}
		else
		{
			return oXmlDoc;
		}
	}
	catch(exception){}
}

//XML http
function fn_SetXmlHttpDocument(postXml, getUrl, sendMethod)
{
	var oXmlHttp;
	var strTemp;
	try
	{
		oXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		oXmlHttp.Open(sendMethod, getUrl, false);
		oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oXmlHttp.send(postXml);

		if(oXmlHttp.status == 500)
		{
			strTemp = "";
		}
		else
		{
			strTemp = oXmlHttp.responseText;
		}

		return strTemp;
	}
	catch(exception)
	{
		alert(exception.description);
	}
	finally
	{
		oXmlHttp = null;
	}
}

//¿ÀºêÁ§Æ® ½ºÅ©¸³Æ® Ãâ·Â
function RenderObjectScript(scriptValue)
{
	try
	{
	    document.write(scriptValue);
	}
	catch(exception){}
}

var caution = false;
//ÄíÅ° ¼³Á¤
function fn_SetCookie(name, value, expires, path, domain, secure)
{
	var strCurCookie = "";	
	try
	{
		strCurCookie = name + "=" + escape(value) + 
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");

		if (!caution || (name + "=" + escape(value)).length <= 4000)
			document.cookie = strCurCookie;
		else
			if (confirm("Cookie exceeds 4KB and will be cut!"))
				document.cookie = strCurCookie;
	}
	catch(exception){}
}

//ÄíÅ° °¡Á®¿À±â
function fn_GetCookie(name)
{
	var strPrefix = "";
	var nCookieStartIndex = -1;
	var nCookieEndIndex = -1;
	try
	{
		strPrefix = name + "=";
		nCookieStartIndex = document.cookie.indexOf(strPrefix);

		if (nCookieStartIndex == -1)
			return null;

		nCookieEndIndex = document.cookie.indexOf(";", nCookieStartIndex + strPrefix.length);
		
		if (nCookieEndIndex == -1)
			nCookieEndIndex = document.cookie.length;
		
		return unescape(document.cookie.substring(nCookieStartIndex + strPrefix.length, nCookieEndIndex));
	}
	catch(exception){}
}

//ÄíÅ°¿­ Áß¿¡ uName2ÀÇ °ªÀ» ±¸ÇÑ´Ù 
function fn_GetCookie2(uName,uName2)
{
	var strReturnValue = "";
	var strString = "";
	var nFlag = -1;
	var nEnd = -1;
	try
	{
		strString = fn_GetCookie(uName);
		nFlag = strString.indexOf(uName2+'=');
		
		if (nFlag != -1) 
		{ 
			nFlag += uName2.length + 1
			nEnd = strString.indexOf('&', nFlag) 

			if (nEnd == -1) 
				nEnd = strString.length;

			strReturnValue = unescape(strString.substring(nFlag, nEnd));
		}
		else
		{
			strReturnValue = "";
		}
		
		return strReturnValue;
	}
	catch(exception){}
}

//Äí±â°ª Ãß°¡
function fn_CookieAdd(name,value)
{
	try
	{
		fn_SetCookie(name,value, 0,"/","");
	}
	catch(exception){}
}

//¼ýÀÚ Æ÷¸Ë.. ¼¼ÀÚ¸®¼ö¸¶´Ù.. ÄÞ¸¶ Ç¥½Ã
function fn_ReturnMoneyFormatString(numValue) 
{ 
	var strValue = "";
	var retValue = ""; 
	try
	{
		strValue = "" + numValue + "";

		for(i=0; i<strValue.length; i++) 
		{ 
			if(i > 0 && (i%3)==0)
				retValue = strValue.charAt(strValue.length - i -1) + "," + retValue; 
			else
				retValue = strValue.charAt(strValue.length - i -1) + retValue; 
		} 
		return retValue; 
	}
	catch(exception){}
}

//¸®½ºÆ® È­¸é¿¡¼­ ¾²´Â ÇÔ¼öÀÌ´Ù..
//³¯Â¥ °ü·ÃÇÔ¼ö (¼±ÅÃµÈ ¿ùÀÇ ¸¶Áö¸·³¯Â¥ ±¸ÇÏ°í Ãâ·Â)
function GetLastDay(oYear, oMonth, oDay, currentDay)
{
	try
	{
		oDay.options.length=1;
		month_day = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

		if(parseInt(oYear.value) % 4 == 0)
			month_day[1] = 29;

		for(i=0; i<12; i++)
		{
			if(oMonth[i].selected)
			{
				print_day = month_day[i]; 
				break;
			}
		}

		for(i=0; i<print_day; i++)
		{
			j = parseInt(i) + 1;
			j = j.toString().length == 1 ? "0" + j.toString() : j.toString();
			new_option = new Option(j,j);
			oDay.options[i] = new_option;

			if(isNaN(currentDay) == false && oDay.options[i].value == currentDay)
				oDay.options[i].selected = true;
			
		}
	}
	catch(e)
	{
		alert(e.description);
	}
}