
// ****************************************************************************************************
//
// Filename		:	common.js
// Create Date	:	2005-07-05
// Modify Date  :   
// Description	:	±âº»ÀûÀÎ ÀÚ¹Ù ½ºÅ©¸³Æ® ÀÛ¾÷À» À§ÇÑ ÇÔ¼öµéÀ» Á¤ÀÇÇØ ³õÀº ÆÄÀÏ
// Reference	:	
//
// ****************************************************************************************************


// ****************************************************************************************************
//
// Create Date : 2006-07-12
// Modify Date :   
//
//	1. Description : ÆË¾÷ °ü·Ã ÇÔ¼ö Ex) open_window("/popup.asp", "popwin", 600, 500, "toolbar=0,menubar=0,resizable=no,scrollbars=no")
//	2. Parameters
//		- strURL : ¿­±â À§ÇÑ URL
//		- strWinName : À©µµ¿ì¸í
//		- nWidth : ³ÐÀÌ
//		- nHeight : ±æÀÌ
//		- strFeature : ¿É¼Ç
//	3. Return Type : Window °´Ã¼
//
// ****************************************************************************************************

function open_window( strURL, strWinName, nWidth, nHeight, strFeature )
{
	var oWnd;

	if ( navigator.appName == "Microsoft Internet Explorer" && parseInt( navigator.appVersion ) >= 4 )	// browser version >= ie 4	
	{ 
		if ( nWidth < window.screen.width && nHeight < window.screen.height ) 
		{
			var windowX = Math.ceil( (window.screen.width  - nWidth) / 2 );
			var windowY = Math.ceil( (window.screen.height - nHeight) / 2 );

			oWnd = window.open(strURL, strWinName, strFeature+",width=" + nWidth +",height=" + nHeight+",left="+windowX+",top="+windowY);
		}
		else 
		{
			oWnd = window.open(strURL, strWinName, strFeature+",width=" + nWidth +",height=" + nHeight);
		}
	}
	else 
	{
		oWnd = window.open(strURL, strWinName, strFeature+",width=" + nWidth +",height=" + nHeight);
	}
	
	return oWnd;
}

// ****************************************************************************************************
//
// Create Date : 2006-07-12
// Modify Date :   
//
//	1. Description : windowÀÇ ³ÐÀÌ´Â nResizeWidth¸¸Å­ °íÄ¡°í, ³ôÀÌ´Â nMaxheight°¡ ³ÑÁö ¾Ê´Â ¹üÀ§¾È¿¡¼­ Á¶Á¤
//	2. Parameters
//		- nResizeWidth : ResizeÇÒ ³ÐÀÌ
//		- nMaxheight : ResizeÇÒ ÃÖ´ë³ôÀÌ
//	3. Return Type : ¾øÀ½ 
//
// ****************************************************************************************************

function resizepopup( nResizeWidth, nMaxheight ) 	
{
	var winW, winH;
	
	winW = nResizeWidth;
	winH = document.body.scrollHeight;

	if ( winH > nMaxheight )
	{
		winH = nMaxheight;
	}
	
	window.resizeTo(winW, winH + 40);
}

// ****************************************************************************************************
//
// Create Date : 2006-07-12
// Modify Date :   
//
//	1. Description : »ç¿ëÇÒ ¼ö ¾ø´Â ÅÂ±×ÀÎÁö Ã¼Å©ÇÑ´Ù.
//	2. Parameters
//		- strValue : Ã¼Å©ÇÒ ½ºÆ®¸µ
//	3. Return Type : Boolean
//
// ****************************************************************************************************

function checkTag( strValue )
{
	var regArr = new Array('(<)[\\s]*(table)' , '(<)[\\s]*(\\/)[\\s]*(table)' ,
	                       '(<)[\\s]*(tr)'    , '(<)[\\s]*(\\/)[\\s]*(tr)'    ,
	                       '(<)[\\s]*(td)'    , '(<)[\\s]*(\\/)[\\s]*(td)'    ,
	                       '(<)[\\s]*(div)'   , '(<)[\\s]*(\\/)[\\s]*(div)'   ,
	                       '(<)[\\s]*(iframe)', '(<)[\\s]*(\\/)[\\s]*(iframe)',
	                       '(<)[\\s]*(script)', '(<)[\\s]*(\\/)[\\s]*(script)',
	                       '(<)[\\s]*(embed)' , '(<)[\\s]*(\\/)[\\s]*(embed)');
	var strMyRe;

	strMyRe = '/';
	for( i = 0; i < regArr.length; i++ )
	{
		if ( i == regArr.length - 1 )
		{
			strMyRe += regArr[i];
			strMyRe += '/gi';
		}
		else
		{
			strMyRe += regArr[i];
			strMyRe += '|';
		}
	}
  
	myRe = eval(strMyRe);
	reArray = strValue.match(myRe);
	
	if ( reArray != null )
	{
		var alvar = "";
		for( j = 0; j < reArray.length; j++ )
		{
			if ( j != reArray.length - 1 )
				alvar += reArray[j] + ">,";
			else
				alvar += reArray[j] + ">";
		}

		alert(alvar + " °ú °°Àº ÅÂ±×´Â »ç¿ëÇÏ½Ç ¼ö ¾ø½À´Ï´Ù.");
   		return false;
	}
	else
	{
		return true;
	}
}

// ****************************************************************************************************
//
// Create Date : 2006-07-12
// Modify Date :   
//
//	1. Description : ÅÂ±×°¡ Á¸ÀçÇÏ´ÂÁö Ã¼Å©ÇÑ´Ù.
//	2. Parameters
//		- strValue : Ã¼Å©ÇÒ ½ºÆ®¸µ
//	3. Return Type : Boolean
//
// ****************************************************************************************************

function CheckNonTag( strValue )
{
	var opentag = '><';
	var i; 
		
	for( i = 0; i < strValue.length; i++ )  
	{
		if ( opentag.indexOf(strValue.substring(i, i + 1)) > 0 ) 
		{
			break ; 
		}
	}
	
	if ( i != strValue.length ) 
	{
		return false ; 
	}
	else
	{
		return true ;
	} 

	return false;
}

// ****************************************************************************************************
//
// Create Date : 2006-07-12
// Modify Date :   
//
//	1. Description : µû¿ÈÇ¥¿Í ¿ª½½·¡½¬ Ã³¸®
//	2. Parameters
//		- strValue : Ã³¸®ÇÒ ½ºÆ®¸µ
//	3. Return Type : String
//
// ****************************************************************************************************

function replaceBackslash( strValue ) 
{            
    var str = strValue;
    
    if ( str.indexOf("\\") >= 0 ) str = str.replace(/\\/g, "\\\\");
    if ( str.indexOf("\"") >= 0 ) str = str.replace(/\"/g, "\\\"");
    
    return str;
}

// ****************************************************************************************************
//
// Create Date : 2006-07-12
// Modify Date :   
//
//	1. Description : ÇØ´ç ÄíÅ°¸íÀÇ °ªÀ» ¾ò´Â´Ù.
//	2. Parameters
//		- strName : ÄíÅ°¸í
//	3. Return Type : String
//
// ****************************************************************************************************

function getCookie( strName ) 
{
	var search = strName + "="
	
	if ( document.cookie.length > 0 )	// if there are any cookies
	{		
		offset = document.cookie.indexOf(search)
		if ( offset != -1 )  // if cookie exists
		{
			offset += search.length
			
			// set index of beginning of value
			end = document.cookie.indexOf(";", offset)
			
			// set index of end of cookie value
			if ( end == -1 )
				end = document.cookie.length
			
			return unescape(document.cookie.substring(offset, end))
		}
	}
}

// ****************************************************************************************************
//
// Create Date : 2006-07-12
// Modify Date :   
//
//	1. Description : ÇØ´ç ÄíÅ°¸í¿¡ °ªÀ» µî·ÏÇÑ´Ù.
//	2. Parameters
//		- strName : ÄíÅ°¸í
//		- vValue : ÄíÅ°°ª
//		- strExpiredays : expire µÇ´Â ÀÏ½Ã
//		- strPath : °æ·Î
//		- strDomain : µµ¸ÞÀÎ
//		- bSecure : º¸¾È ¸Å°³ º¯¼ö
//	3. Return Type : ¾øÀ½
//
// ****************************************************************************************************

function setCookie( strName, vValue, strExpiredays, strPath, strDomain, bSecure ) 
{
    document.cookie = strName + "=" + escape (vValue) +
        ((strExpiredays) ? "; expires=" + strExpiredays : "") +
        ((strPath) ? "; path=" + strPath : "") +
        ((strDomain) ? "; domain=" + strDomain : "") +
        ((bSecure) ? "; secure" : "");
}

// ****************************************************************************************************
//
// Create Date : 2006-07-12
// Modify Date :   
//
//	1. Description : ÇØ´ç ÄíÅ°¸¦ »èÁ¦ÇÑ´Ù.
//	2. Parameters
//		- strName : ÄíÅ°¸í
//		- strPath : °æ·Î
//		- strDomain : µµ¸ÞÀÎ
//	3. Return Type : ¾øÀ½
//
// ****************************************************************************************************

function deleteCookie( strName, strPath, strDomain ) 
{
    if ( getCookie( strName ) ) 
    {
        document.cookie = strName + "=" +
            ((strPath) ? "; path=" + strPath : "") +
            ((strDomain) ? "; domain=" + strDomain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

// ****************************************************************************************************
//
// Create Date : 2006-07-12
// Modify Date :   
//
//	1. Description : URL ¹®ÀÚ¿­À» Encoding ÇÑ´Ù.
//	2. Parameters
//		- strValue : EncodingÇÒ URL ¹®ÀÚ¿­
//	3. Return Type : String
//
// ****************************************************************************************************

function URLEncode( strValue ) 
{
    return escape(strValue).replace(/"+/gi, '%2C').replace(/"/gi, '%22').replace(/\'/gi, '%27');
}

// ****************************************************************************************************
//
// Create Date : 2006-07-12
// Modify Date :   
//
//	1. Description : html ¹®ÀÚ¿­À» Encoding ÇÑ´Ù.
//	2. Parameters
//		- strValue : EncodingÇÒ html ¹®ÀÚ¿­
//	3. Return Type : String
//
// ****************************************************************************************************

function HTMLEncode( strValue ) 
{
	var strRetVal = "";

	strRetVal = strValue.replace(/>/gi, "&gt;");
	strRetVal = strRetVal.replace(/</gi, "&lt;");
	//strRetVal = strRetVal.replace(/\'/gi, "&quot;");
	//strRetVal = strRetVal.replace(/&/gi, "&amp;");

	return strRetVal;
}

// ****************************************************************************************************
//
// Create Date : 2006-07-12
// Modify Date :   
//
//	1. Description : EncodingµÈ html ¹®ÀÚ¿­À» Decoding ÇÑ´Ù.
//	2. Parameters
//		- strValue : EncodingµÈ html ¹®ÀÚ¿­
//	3. Return Type : String
//
// ****************************************************************************************************

function HTMLDecode( strValue ) 
{
	var strRetVal = "";

	strRetVal = strValue.replace(/&gt;/gi, ">");
	strRetVal = strRetVal.replace(/&lt;/gi, "<");
	//strRetVal = strRetVal.replace(/&quot;/gi, "\"");
	//strRetVal = strRetVal.replace(/&amp;/gi, "&");

	return strRetVal;
}

function replaceHTML(val)
{
	var x = val.replace(/&nbsp;/g," ").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&");
	x = x.split("\n").join("<BR>");
	x = x.split("\n").join("<br>");
	
	return x;
}

// ****************************************************************************************************
//
// Create Date : 2006-07-12
// Modify Date :   
//
//	1. Description : À¯Àú ºê¶ó¿ìÁ®ÀÇ Á¾·ù¸¦ ¾Ë¾Æ³»¼­ À©µµ¿ì XP ¼­ºñ½ºÆÑ 2°¡ ±ò·ÁÀÖ´ÂÁö Ã¼Å©ÇÑ´Ù.
//	2. Parameters : ¾øÀ½
//	3. Return Type : Boolean
//
// ****************************************************************************************************

function IsWinXPSP2()
{
	try
	{
		var info = window.clientInformation;
		var reg1 = /[^A-Z0-9]MSIE[ ]+6.0[^A-Z0-9]/i;
		var reg2 = /[^A-Z0-9]WINDOWS[ ]+NT[ ]+5.1[^A-Z0-9]/i;

		if ( ( info.appMinorVersion.replace(/\s/g,"").toUpperCase().indexOf(";SP2;") >= 0 ) &&
			( reg1.test(info.userAgent) == true ) && ( reg2.test(info.userAgent) == true ) )
		{
			return true;
		}
	}
	catch(e)
	{
		return false;
	}

	return false;
}

// ****************************************************************************************************
//
// Create Date : 2006-07-12
// Modify Date :   
//
//	1. Description : ÆÄÀÏ¸íÀÇ À¯È¿¼ºÀ» Ã¼Å©ÇÑ´Ù.
//	2. Parameters
//		- strValue : ÆÄÀÏ¸í
//	3. Return Type : Boolean
//
// ****************************************************************************************************

function isValidFilename( strValue )
{
    if ( !strValue.match(/[\\\/:\*\?\|<>]/) )
        return true;
    else
        return false;
}

// ****************************************************************************************************
//
// Create Date : 2006-07-12
// Modify Date :   
//
//	1. Description : keydown½Ã¿¡ ¿µ¾î¿Í ¼ýÀÚ¸¸ ÀÎ½ÄÇÏ°Ô ÇÑ´Ù.
//	2. Parameters : ¾øÀ½
//	3. Return Type : ¾øÀ½
//
// ****************************************************************************************************

function keydownEngNum() 
{
	if ( !(event.keyCode>=48 && event.keyCode<=57) && !(event.keyCode>=65 && event.keyCode<=90) && event.keyCode!=9 && event.keyCode!=8 && event.keyCode!=46 && event.keyCode!=37 && event.keyCode!=39 && event.keyCode!=45 ) 
	{
		event.keyCode = 0;
		event.cancelBubble = true;
		event.returnValue = false;
	}
}

// ****************************************************************************************************
//
// Create Date : 2006-09-05
// Modify Date :   
//
//	1. Description : Flash PluginÀÇ ¹öÀüÀ» ¾Ë¾Æ³½´Ù.
//	2. Parameters : ¾øÀ½
//	3. Return Type : ¾øÀ½
//
// ****************************************************************************************************

function FlashInfo() {
	var f = "-";	var n = navigator;
 	if ( n.plugins && n.plugins.length ) 	{
		for( var ii = 0; ii < n.plugins.length; ii++ ) 		{
			if ( n.plugins[ii].name.indexOf('Shockwave Flash') != -1 ) 			{
				f = n.plugins[ii].description.split('Shockwave Flash ')[1];
				break;
			}
		}
	} 	else if ( window.ActiveXObject ) 	{
		for( var ii = 10; ii >= 2; ii-- ) 		{
			try {
				var fl = eval( "new ActiveXObject('ShockwaveFlash.ShockwaveFlash." + ii + "');" );
				if ( fl ) 				{ 					f = ii + '.0'; 					break; 				}
			}
			catch(e) {}
		}
	}
 	return f;
}



