// ====================================================================
//       URLEncode and URLDecode functions
//
// Copyright Albion Research Ltd. 2002
// http://www.albionresearch.com/
//
// You may copy these functions providing that
// (a) you leave this copyright notice intact, and
// (b) if you use these functions on a publicly accessible
//     web site you include a credit somewhere on the web site
//     with a link back to http://www.albionresarch.com/
//
// If you find or fix any bugs, please let us know at albionresearch.com
//
// SpecialThanks to Neelesh Thakur for being the first to
// report a bug in URLDecode() - now fixed 2003-02-19.
// ====================================================================
function URLEncode( )
{
// The Javascript escape and unescape functions do not correspond
// with what browsers actually do...
var SAFECHARS = "0123456789" +     // Numeric
     "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + // Alphabetic
     "abcdefghijklmnopqrstuvwxyz" +
     "-_.!~*'()";     // RFC2396 Mark characters
var HEX = "0123456789ABCDEF";

var plaintext = document.URLForm.F1.value;
var encoded = "";
for (var i = 0; i < plaintext.length; i++ ) {
  var ch = plaintext.charAt(i);
     if (ch == " ") {
      encoded += "+";    // x-www-urlencoded, rather than %20
  } else if (SAFECHARS.indexOf(ch) != -1) {
      encoded += ch;
  } else {
      var charCode = ch.charCodeAt(0);
   if (charCode > 255) {
       alert( "Unicode Character '"
                        + ch
                        + "' cannot be encoded using standard URL encoding.\n" +
              "(URL encoding only supports 8-bit characters.)\n" +
        "A space (+) will be substituted." );
    encoded += "+";
   } else {
    encoded += "%";
    encoded += HEX.charAt((charCode >> 4) & 0xF);
    encoded += HEX.charAt(charCode & 0xF);
   }
  }
} // for

document.URLForm.F2.value = encoded;
return false;
};

function URLDecode(strval)
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef";
   var encoded = strval;
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
    if (ch == "+") {
        plaintext += " ";
     i++;
    } else if (ch == "%") {
   if (i < (encoded.length-2)
     && HEXCHARS.indexOf(encoded.charAt(i+1)) != -1
     && HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
    plaintext += unescape( encoded.substr(i,3) );
    i += 3;
   } else {
    alert( 'Bad escape combination near ...' + encoded.substr(i) );
    plaintext += "%[ERROR]";
    i++;
   }
  } else {
     plaintext += ch;
     i++;
  }
} // while
   return plaintext;
};


function PopupReSizeWindow()
{
	PopupSizeAdjust();

	PopupPositionAdjust();
}

function PopupSizeAdjust()
{
	var winBody = window.document.body;

	window.resizeTo(winBody.scrollWidth-100, winBody.scrollHeight-100);

	var marginHeight = parseInt(winBody.topMargin)+parseInt(winBody.bottomMargin);
	var marginWidth = parseInt(winBody.leftMargin)+parseInt(winBody.rightMargin);

	var wid = winBody.scrollWidth + (winBody.offsetWidth - winBody.clientWidth) + marginWidth+5;
	var hei = winBody.scrollHeight + (winBody.offsetHeight - winBody.clientHeight) + marginHeight+30;

	if (hei > screen.availHeight)
	{
		hei = screen.availHeight - 34;
	}

	window.resizeTo(wid, hei);
}

function PopupPositionAdjust()
{
	var x, y;

	x = ( window.screen.availWidth - document.body.offsetWidth ) / 2;
	y = ( window.screen.availHeight - document.body.offsetHeight ) / 2;

	window.moveTo( x, y );
}



function activeflash(str, wid, hei)
{
	document.write("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'  codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0' width='" + wid + "' height='" + hei + "' id=ShockwaveFlash1>");
	document.write("  <param name=movie value='" + str + "'>");
	document.write("  <param name=quality value=high>");
	document.write("  <embed src='" + str + "' quality=high pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width='" + wid + "' height='" + hei + "'>");
	document.write("   </embed> ");
	document.write(" </object> ");
}

function cellMergeChk(tableObj, rowIndex, cellIndex)
{
	var rowsCn = tableObj.rows.length;

	if(rowsCn-1 > rowIndex)
		cellMergeProcess(tableObj, rowIndex, cellIndex);
}

function cellMergeProcess(tableObj, rowIndex, cellIndex)
{
	var flag = 0;
	var rowsCn = tableObj.rows.length;
	var compareCellsLen = tableObj.rows(rowIndex).cells.length;		//½ÃÀÛ row¿¡ cell °³¼ö

	//ÃÊ±âÈ­
	var compareObj = tableObj.rows(rowIndex).cells(cellIndex);
	var compareValue = compareObj.innerHTML;
	var cn = 1;
	var delCells = new Array();
	var arrCellIndex = new Array();
	for(i=rowIndex+1; i < rowsCn; i++)
	{
		var cellsLen = tableObj.rows(i).cells.length;
		var bufCellIndex = cellIndex

		//½ÇÁúÀûÀÎ row¿¡ cellIndex¸¦ ±¸ÇÏÀÚ.
		if(compareCellsLen != cellsLen)
		{
			bufCellIndex = bufCellIndex - (compareCellsLen - cellsLen);
		}

		if (bufCellIndex < 0)
		{
			break;
		}

		cellObj = tableObj.rows(i).cells(bufCellIndex);

		if(compareValue == cellObj.innerHTML)
		{
			delCells[cn-1] = tableObj.rows(i);		//»èÁ¦ÇÒ cellÀÇ row¸¦ ÀúÀåÇÑ´Ù.
			arrCellIndex[cn - 1] = bufCellIndex;	//ÇØ´ç row cell index¸¦ ÀúÀåÇÑ´Ù.
			cn++;
			flag = 1;
		}
		else
		{

			//º´ÇÕ
			compareObj.rowSpan = cn;
			//»èÁ¦
			for(j=0; j < delCells.length; j++)
			{
				delCells[j].deleteCell(arrCellIndex[j]);
			}

			flag = 0;
			//ÃÊ±âÈ­
			compareObj = cellObj;
			compareValue = cellObj.innerHTML;
			cn = 1;
			delCells = new Array();
			arrCellIndex = new Array();
		}
	}

	if (flag == 1)
	{
		//º´ÇÕ
		compareObj.rowSpan = cn;
		//»èÁ¦
		for(j=0; j < delCells.length; j++)
		{
			delCells[j].deleteCell(arrCellIndex[j]);
		}
	}


}

// Left Function
function Left(str, n){
if (n <= 0)
   return "";
else if (n > String(str).length)
   return str;
else
   return String(str).substring(0,n);
}

// Right Function
function Right(str, n){
   if (n <= 0)
      return "";
   else if (n > String(str).length)
      return str;
   else {
      var iLen = String(str).length;
      return String(str).substring(iLen, iLen - n);
   }
}


// Ç³¼±µµ¿ò¸» »ç¿ë¹ý ¿¹Á¦
// onMouseMove="msgposit_list();" onMouseOut="msghide_list();" onMouseOver="msgset_list('µµ¿ò¸»À» ¾²±â');"
//<div id="helpbox" style="border-width:0px; border-style:none; width:0px; height:0px; position:absolute; left:0px; top:0px; z-index:0;background-color:#FFFFFF"" ></div>
function sitemapLink(strval)
{
	window.open (strval);
}



function msghide_list(){helpbox.innerHTML='';}

if(navigator.appName == "Netscape"){
	document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
	document.onmousemove = msgposit_list;
}

function msgposit_list(evt)
{
	if(navigator.appName == "Netscape"){
		helpbox.style.left = evt.pageX + 10;
		helpbox.style.top  = evt.pageY + 5;
	} else {
		helpbox.style.posLeft = event.x + 10 + document.body.scrollLeft;
		helpbox.style.posTop  = event.y + 5 + document.body.scrollTop;
	}
}


function na_open_window(name, url, left, top, width, height, toolbar, menubar, statusbar, scrollbar, resizable)
{
	toolbar_str = toolbar ? 'yes' : 'no';
	menubar_str = menubar ? 'yes' : 'no';
	statusbar_str = statusbar ? 'yes' : 'no';
	scrollbar_str = scrollbar ? 'yes' : 'no';
	resizable_str = resizable ? 'yes' : 'no';
	window.open(url, name,
	'left='+left+',top='+top+',width='+width+',height='+height+',toolbar='+toolbar_str+',menubar='+menubar_str+',status='+statusbar_str+',scrollbars='+scrollbar_str+',resizable='+resizable_str);
}

//ÅØ½ºÆ®¹Ú½º : onkeypress="entercheck();"
//°Ë»ö ÀÚ¹Ù½ºÅ©¸³Æ®ÇÔ¼ö : Search()
function entercheck()
{
	if (event.keyCode == 13)
	{
		Search();
	}
}


//ÅØ½ºÆ®¹Ú½º onkeypress="check_num();"
function check_num()
{
	if((event.keyCode<48)||(event.keyCode>57))
	{
		event.returnValue=false;
	}
}



function view(what) {
    var imgwin = window.open("",'WIN','scrollbars=no,status=no,toolbar=no,resizable=1,location=no,menu=no,width=10,height=10');
    imgwin.focus();
    imgwin.document.open();
    imgwin.document.write("<html>");
    imgwin.document.write("<head>");
    imgwin.document.write("<title>ÀÌ¹ÌÁö ¿øº¸»çÀÌÁî º¸±â</title>");
    imgwin.document.write("<sc"+"ript>\n");
    imgwin.document.write("function resize() {\n");
    imgwin.document.write("pic = document.il;\n");
    //imgwin.document.write("alert(eval(pic).height);\n");
    imgwin.document.write("if (eval(pic).height) { var name = navigator.appName\n");
    imgwin.document.write("  if (name == 'Microsoft Internet Explorer') { myHeight = eval(pic).height + 0; myWidth = eval(pic).width + 0;\n");
    // 40 12
    imgwin.document.write("  } else { myHeight = eval(pic).height + 0; myWidth = eval(pic).width; }\n");  // 9
    imgwin.document.write("  clearTimeout();\n");
    imgwin.document.write("  var height = screen.height;\n");
    imgwin.document.write("  var width = screen.width;\n");
    imgwin.document.write("  var leftpos = width / 2 - myWidth / 2;\n");
    imgwin.document.write("  var toppos = height / 2 - myHeight / 2; \n");
    imgwin.document.write("  self.moveTo(leftpos, toppos);\n");
    imgwin.document.write("  self.resizeTo(myWidth+12, myHeight+30);\n");
    imgwin.document.write("}else setTimeOut(resize(), 100);}\n");
    imgwin.document.write("</sc"+"ript>");
    imgwin.document.write("</head>");
    imgwin.document.write('<body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0" bgcolor="#FFFFFF">');
    imgwin.document.write("<a href=# onclick=window.close() onfocus=this.blur()><img border=0 src="+what+" xwidth=100 xheight=9 name=il onload='resize();'></a>");
    imgwin.document.write("</body>");
    imgwin.document.close();
    }



function UrlCopy(url) {
	// IE
	if (window.clipboardData) {
		window.clipboardData.setData("Text", url);
		alert("¼±ÅÃÇÑ ÁÖ¼Ò°¡ Å¬¸³º¸µå¿¡ º¹»çµÇ¾ú½À´Ï´Ù.\r\n\r\nÁÖ¼ÒÃ¢ÀÌ³ª ¸Þ¸ðÀå, ¸Þ½ÅÀú µî¿¡ ºÙ¿©³Ö±â(Ctrl+V) ÇÏ¼¼¿ä!");
	}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function trim (strSource) 
{ re = /^\s+|\s+$/g; return strSource.replace(re, ''); } 


//±ÛÀÚ¼ö Ã¼Å©
//onkeyup="return ByteCheck(this, 5000)"
function ByteCheck(inputname, nMaxLength)
{
	strText = inputname.value + "";
	var strTemp	= "";
	var nByteLength = 0;
	var strChar;
	for( i=0; i<strText.length; i++ )
	{
		strChar = strText.charAt(i);

		if( nByteLength < nMaxLength )
		{
			if (escape(strChar).length < 5) //¿µ¹®, ¼ýÀÚ
			{
				nByteLength++;
				strTemp += strChar;
			}
			else //ÇÑ±Û
			{
				nByteLength = nByteLength+2;
				if( nByteLength <= nMaxLength  )
					strTemp += strChar;
			}

		}
		else
		{
			alert("ÇÑ±Û±âÁØ "+(nMaxLength/2)+"ÀÚ·Î Àû¾îÁÖ¼¼¿ä.");
			inputname.value = strTemp;

			return true;
		}

	}
}

function CE_getLength ( obj )
{
	var retobj = eval(obj);
	// 1.ÇØ´ç°´Ã¼ÀÇ Á¸ÀçÀ¯¹« ÆÇº°
	if ( typeof(eval(retobj)) == "undefined" )
	{
		return
	}

	// ³Ñ°Ü¹ÞÀº °´Ã¼°¡ Á¸ÀçÇÏ¸é¼­, ÇÏ³ªÀÎ °æ¿ì 
	if ( typeof(retobj.length) == 'undefined')
	{
		return 1 
	}
	// ³Ñ°Ü¹ÞÀº °´Ã¼°¡ µÎ°³ ÀÌ»óÀÏ¶§
	// ³Ñ°Ü¹ÞÀº °´Ã¼°¡ µÎ°³ ÀÌ»óÀÏ¶§
	else if ( typeof(retobj.length ) == 'number')
	{
		return retobj.length 
	}
	else
	{
		alert("ÀÌ·± °æ¿ì´Â ¾ø´Âµ¥,,´Ù½Ã±¸Çö")
	}
}


function CE_getObj ( objName , objNo )
{
	var retObj = eval( objName )

	// ³Ñ°Ü¹ÞÀº °´Ã¼°¡ ÇÏ³ªÀÏ¶§.
	if ( typeof(retObj[0]) == 'undefined')
	{
		
		return retObj 
	}
	// ³Ñ°Ü¹ÞÀº °´Ã¼°¡ µÎ°³ ÀÌ»óÀÏ¶§
	else 
	{
		if ( typeof(retObj[objNo]) != 'undefined' )
		{
			return retObj[objNo]
		}
		else
		{
			alert( "ÆÄ¶ó¹ÌÅÍ ¹è¿­¿ø¼Ò¼ö°¡ Àß¸øµÈ °ªÀÓ. ¼öÁ¤¿ä¸Á!")
		}
	}
}

//Ã¼Å©¹Ú½º ÀüÃ¼ ¼±ÅÃ/ÇØÁ¦
//<input type="checkbox" name="ALL_CHK" onClick="Check_All_Checkbox();">
//<input type="checkbox" name="ROW_CHK" value="XXXXX">
function Check_All_Checkbox()
{
	var chk_length	=	CE_getLength(document.all.ROW_CHK);
	var obj1;
	

	if (document.all.ALL_CHK.checked == true)
	{
		for (var i = 0; i < chk_length; i++)
		{
			obj1 = CE_getObj ( "document.all.ROW_CHK" , i);
			obj1.checked = true;
		}

	}
	else
	{
		for (var i = 0; i < chk_length; i++)
		{
			obj1 = CE_getObj ( "document.all.ROW_CHK" , i);
			obj1.checked = false;
		}
	}
}


function setCookie (name, value, expiredays)
{
	 var todayDate = new Date();
	 todayDate.setDate( todayDate.getDate() + expiredays );
	 document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";";
}

function getCookie(name)
{
	 var Found = false;
	 var start, end;
	 var i = 0;

	 while (i <= document.cookie.length)
	 {
		start = i;
		end = start + name.length;
		if (document.cookie.substring(start, end) == name)
		{
			Found = true;
			break;
		}
		i++;
	 }

	 if (Found == true)
	 {
		start = end + 1;
		end = document.cookie.indexOf(';', start);
		if (end < start) end = document.cookie.length;
		return document.cookie.substring(start, end);
	 }
	 return '';
}




