//********************************************************//
//	��ƿ��Ƽ ����Լ� ����
//********************************************************//

///////////////////////////////////////////////////////////////
//////  Ŭ������� ���� ���� (CTRL + C)
///////////////////////////////////////////////////////////////
function copyClip(meintext) {
	if (window.clipboardData)  {

		window.clipboardData.setData("Text", meintext);

	} else if (window.netscape) { 
		netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
		var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
		if (!clip) return;
		var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
		if (!trans) return;
		trans.addDataFlavor('text/unicode');

		var str = new Object();
		var len = new Object();
		var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);

		var copytext=meintext;
		str.data=copytext;
		trans.setTransferData("text/unicode",str,copytext.length*2);

		var clipid=Components.interfaces.nsIClipboard;
		if (!clip) return false;

		clip.setData(trans,null,clipid.kGlobalClipboard);
	}
	return false;
}


//popup
function popWindow(pop,width,height,scroll) {
	var url = pop;  
	var wd = width;
	var he = height;
	window.open(url,"","toolbar=0,menubar=0,scrollbars=" + scroll + ",resizable=no,width=" + wd +",height=" + he + ";")
}

//popup
function popWindowCenter(pop,width,height,scroll) {
	var url = pop;  
	var wd = width;
	var he = height;
	var top = (window.screen.height-he)/2;
	var left = (window.screen.width-wd)/2;
	window.open(url,"","toolbar=0,menubar=0,scrollbars=" + scroll + ",resizable=no,top="+top+",left="+left+",width=" + wd +",height=" + he + ";")
}

///////////////////////////////////////////////
///////// ����Ű�� ��� �Լ�
///////////////////////////////////////////////
function checkKeyDownNumber(e) {
	ev = (e||window.event);
	if(ev.srcElement) {
		var key = ev.keyCode;
		if ((key >= 48 && key <= 57) // Ű���� ��� ����Ű
	       //|| (key >= 96 && key <= 105) // Ű�е� ����Ű
	       || key == 8  // �齺���̽� Ű
	       || key == 37 // ���� ȭ��ǥ Ű
	       || key == 39 // ������ ȭ��ǥ Ű
	       || key == 46 // DEL Ű
	       || key == 13 // ���� Ű
	       || key == 9  // Tab Ű
	       )
			ev.returnValue=true;
		else
			ev.returnValue=false;
	}
}

///////////////////////////////////////////////
///////// ����Ű �Է½� �Լ����� �Լ�
///////////////////////////////////////////////
function keyPressHandler(code, funcName) { 
   if(isNaN(code)) {
    	return false;
   } else if(event.keyCode == code) {
     if(funcName){
     	eval(funcName);
     }
     return false;
   }
}

///////////////////////////////////////////////
///////// ��Ű��� �Լ�
///////////////////////////////////////////////
// ��Ű�� ���Ѵ� (Ȱ���ֱ�� �ʴ����� ����)
function setCookie(name, value, expireSeconds){
	var todayDate = new Date();
	if(expireSeconds > 0 ) todayDate.setSeconds( todayDate.getSeconds() + expireSeconds );
	var expires = expireSeconds > 0 ? "expires=" +todayDate.toGMTString()+";" : "";
	document.cookie = name + "=" + escape( value ) + "; path=/; "+expires;
}

// ��� ��Ű���� �����´�.
function getCookie(name){ 
	var nameOfCookie = name + "="; 
	var x = 0; 

	while ( x <= document.cookie.length ) {
		var y = (x+nameOfCookie.length); 
		if ( document.cookie.substring( x, y ) == nameOfCookie ) { 
			if ( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 ) 
				endOfCookie = document.cookie.length; 				
			return unescape( document.cookie.substring( y, endOfCookie ) ); 
		} 
		x = document.cookie.indexOf( " ", x ) + 1; 
		if ( x == 0 ) 
			break; 
	}
	return ""; 
}

function deleteCookie( cookieName ){
	var expireDate = new Date();
	expireDate.setDate( expireDate.getDate() - 1 );
	document.cookie = cookieName + "= " + "; path=/; expires=" + expireDate.toGMTString();
}

// ���� �긮������ ��Ű�� ����� �� �ִ��� üũ�Ѵ�.
function checkCookieEnabled() {
	setCookie("checkCookie","Y",5);
	var value = getCookie("checkCookie");
	return value == "Y" ? true : false;
}

//-------------------------------------------------------
//����Ʈ ���, return �ѹ���Ʈ��
//-------------------------------------------------------
function getByte(instr) {
    var len = 0;
    for(i=0; i<instr.length; i++) {
        var chr = instr.charAt(i);
        if (escape(chr).length > 4) {
                len += 2;
        }
        else  {
                len++;
        }
    }
    return len;
}

//-------------------------------------------------------
// ���ڿ����� �յ� ��� ���� , return ��� ���ŵ� ���ڿ�
// ���� : "string".trim();
//-------------------------------------------------------
String.prototype.trim = function() {
	return this.replace(/\s/g, "");
}

//-------------------------------------------------------
// ���ڿ����� �� ��� ���� , return ��� ���ŵ� ���ڿ�
// ���� : "string".ltrim();
//-------------------------------------------------------
String.prototype.ltrim = function() {
	var i, j = 0;
	var objstr
	for (i = 0; i < this.length; i++) {
		if (this.charAt(i) == ' ') j = j + 1;
		else break;
	}
	return this.substr(j, this.length - j + 1)  
}


//-------------------------------------------------------
// ���ڿ����� �� ��� ���� , return ��� ���ŵ� ���ڿ�
// ���� : "string".rtrim();
//-------------------------------------------------------
String.prototype.rtrim = function() {
	var i, j = 0;
	for (i = this.length - 1; i >= 0; i--) {
		if (this.charAt(i) == ' ') j = j + 1;
		else break;
	}
	return this.substr(0, this.length - j);
}

//-------------------------------------------------------
// ����(�Ҽ��� ����)�� , �߰��� �������� ����
//-------------------------------------------------------
function formatNumber(strOrg) {
	strOrg = "" + strOrg;
	if(strOrg == "")	return "";

	var strNum = "";
	for(i=0; i<strOrg.length; i++) {
		if(strOrg.charAt(i) == ",")
			continue;
		strNum += strOrg.charAt(i);
	}

	if(!Validate.isNum(strNum))	return strOrg;

	var dot = strNum.indexOf(".");
	var strInt = "";
	var strFlt = "";
	if(dot > 0) {
		strInt = strNum.substring(0,dot);
		strFlt = strNum.substring(dot);
	}
	else
		strInt = strNum;

	var smod = strInt.length % 3;
	var strRtn = "";
	if(smod > 0)	strRtn = strInt.substring(0,smod);
	for(i=smod; i<strInt.length; i++) {
		if(smod != 0 && i == smod)	strRtn += ",";
		else if(i > 0 && (i - smod) % 3 == 0)
			strRtn += ","
		strRtn += strInt.charAt(i);
	}
	if(dot > 0)	strRtn += strFlt;

	return strRtn;
}

//-------------------------------------------------------
// ���ڿ���  , ����
//-------------------------------------------------------
function removeComma(str) {
	var len = str.length;
	var rstr = "";
	if (len > 0) {
		for (var i = 0; i < len; i++) {
			var ch = str.charAt(i);
			if (ch != ',') rstr += ch;
		}
	}
	return rstr;
}


//-------------------------------------------------------
// ���ڿ�  , �߰�
//-------------------------------------------------------
function insertComma(vstr) {
	var str = vstr;
	str += "";

	var comval = "";
	var inversecomval = "";

	for ( k = 0 ; k < str.length ; k++ ) {
		if ( k != 0 && k%3 == 0 ) {
			comval += ",";
		}
		comval += str.charAt(str.length-(k+1));
	}

	for ( k = 0 ; k < comval.length; k++ ) {
		inversecomval += comval.charAt(comval.length-(k+1));
	}
	return inversecomval;
}


function getFillZero(value, length) {
	var val = new String(value);
	var valLength = val.length;
	for(var i = 1; i <= length - valLength; i++) {
		val = "0"+val;
	}
	return val;
}

//-------------------------------------------------------------------------
//�̹��� ��������  : ���� ������ �Ķ���ͷ� �ѱ� 
//-------------------------------------------------------------------------
function imgResizeTo(idName, limitWidth) {

	var obj = document.getElementById(idName);
	var imgWidth = 0;
	var imgHeight = 0;
	var imgRatio = 0;
	var i = 0;

	if(obj == null) return;
	
	imgWidth = obj.width;
	imgHeight = obj.height;
	imgRatio = 0

	if (imgWidth > limitWidth) {
		imgRatio= imgHeight * limitWidth / imgWidth;
		obj.width= limitWidth;
		obj.height= imgRatio;
	}
	
}

//-------------------------------------------------------------------------
//�̹��� ��������  : ���� ������ �Ķ���ͷ� �ѱ�, num �ٲ� �̹��� ���� 
//-------------------------------------------------------------------------
function imgResizeToNumW(idName, limitWidth, num) {
	var obj
	var imgWidth = 0;
	var imgHeight = 0;
	var imgRatio = 0;
	var i = 0;

	for(i = 0; i <= num; i++) {
		obj = document.getElementById(idName + i);
		if(obj == null) continue;

		imgWidth = obj.width;
		imgHeight = obj.height;
		imgRatio = 0
	
		if (imgWidth > limitWidth) {
			imgRatio= imgHeight * limitWidth / imgWidth;
			obj.width= limitWidth;
			obj.height= imgRatio;
		}
	}
}

//-------------------------------------------------------------------------
//�̹��� ��������  : ���� ������ �Ķ���ͷ� �ѱ�, num �ٲ� �̹��� ���� 
//-------------------------------------------------------------------------
function imgResizeToNumH(idName, limitHeight, num) {

	var obj
	var imgWidth = 0;
	var imgHeight = 0;
	var imgRatio = 0;
	var i = 0;

	for(i = 0; i <= num; i++) {
		obj = document.getElementById(idName + i);
		if(obj == null) continue;

		imgWidth = obj.width;
		imgHeight = obj.height;
		imgRatio = 0
	
		if (imgHeight > limitHeight) {
				imgRatio= imgWidth * limitHeight  /  imgHeight;
				obj.height= limitHeight;
				obj.width= imgRatio;
		}
	}
}

//-------------------------------------------------------------------------
//iframe ������ ���� ���� 
// ���� : <iframe src="url" onload="resizeiFrameHeight(this)"></iframe>
//-------------------------------------------------------------------------
function resizeiFrameHeight(obj){

	var innerBody = obj.contentWindow.document.body;

	var innerHeight = innerBody.scrollHeight + (innerBody.offsetHeight - innerBody.clientHeight);

	if (navigator.appName != "Microsoft Internet Explorer") {	//ie�� �ƴ� ��� 
		innerHeight = innerBody.offsetHeight 
	}

	obj.style.height = innerHeight;

}

//-------------------------------------------------------------------------
//������ âũ�� ���� 
// ���� : <body onload="resizeWin()">
//-------------------------------------------------------------------------
function resizeWin(){

	var winW, winH, sizeToW, sizeToH;

	if ( parseInt(navigator.appVersion) > 3 ) {
		if ( navigator.appName=="Netscape" ) {
			winW = window.innerWidth;
			winH = window.innerHeight;
		}
		if ( navigator.appName.indexOf("Microsoft") != -1 ) {
			winW = document.body.scrollWidth;
			winH = document.body.scrollHeight;
		}
	}

	sizeToW = 0;
	sizeToH = 0;

	if ( winW > 1000 ) sizeToW = 1000 - document.body.clientWidth;
	else if ( Math.abs(document.body.clientWidth - winW ) > 3 ) sizeToW = winW - document.body.clientWidth;

	if ( winH > 680 ) sizeToH = 680 - document.body.clientHeight;
	else if ( Math.abs(document.body.clientHeight - winH) > 4 ) sizeToH = winH - document.body.clientHeight;

	if ( sizeToW != 0 || sizeToH != 0 ) window.resizeBy(sizeToW, sizeToH);

}

// Debug ��. ���� �޼��� �ڽ��� ��� �� ������ �ѷ��ش�.
var trace = function(text) {
	var debug = true;
	if(debug) {
		if(!$("traceMsg")) {
			var objDiv = new Element("div",{id:"traceMsg"});
			objDiv.setStyle({overflow:"auto",zIndex:"1200",position:"absolute",top:"30px",right:"30px",width:"300px",height:"500px",
							backgroundColor:"#FFFFFF",filter:"Alpha(opacity=70)",opacity:(70/100)});
			objDiv.update("<table border='1' width='100%' height='500'><tr><td valign='top' id='traceMsgOut'></td></tr></table>");
			$$("body")[0].insert(objDiv);
		}
		$("traceMsgOut").innerHTML = text+"<br>"+$("traceMsgOut").innerHTML;
	}
}

// �Է��� ���� ���ڿ� ���� ���� (�ѱ�ó��)
var checkValueLength = function(obj,title,maxLength) {
	var str = new String();
	var strLength = 0;
	for(i=0; i < obj.value.length; i++) {
		var addLength = Validate.isKor(obj.value.charAt(i)) ? 2 : 1;
		strLength += addLength 
		if(strLength > maxLength) {
			alert(title+"��(��) �������� "+maxLength+"��, �ѱ۱��� "+Math.floor(maxLength/2)+"�� ���� �Է°����մϴ�.");
			obj.value = str;
			strLength -= addLength;
			break;
		}
		str += obj.value.charAt(i);
	}
	return strLength;
}


/*select box ���� ���̾� ���� */
// Internet Explorer���� ����Ʈ�ڽ��� ���̾ ��ĥ�� ���̾ ����Ʈ �ڽ� �ڷ� ��� ������ �ذ��ϴ� �Լ�
// ���̾ ����Ʈ �ڽ��� ħ���ϸ� ����Ʈ �ڽ��� hidden ��Ŵ
// ���� :
// <div id=LayerID style="display:none; position:absolute;" onpropertychange="selectbox_hidden('LayerID')">
var selectboxHidden = function(layer_id, tagName)
{
	tagName = (tagName||"SELECT");
	var ly = eval(layer_id);
	
	var selectBoxs = $(layer_id).getElementsByTagName(tagName);

	// ���̾� ��ǥ
	var ly_left  = ly.offsetLeft;
	var ly_top    = ly.offsetTop;
	var ly_right  = ly.offsetLeft + ly.offsetWidth;
	var ly_bottom = ly.offsetTop + ly.offsetHeight;

	// ����Ʈ�ڽ��� ��ǥ
	var el;

	for (i=0; i<document.forms.length; i++) {

		for (k=0; k<document.forms[i].length; k++) {
			el = document.forms[i].elements[k];
			if(tagName == "OBJECT") {
				var id = "CLSID:4D68446C-92A2-4A32-BD61-E18708016387";
				if(el.getAttribute("CLASSID") != id) continue;
			}

			//alert(el.tagName);

			if (el.tagName == tagName) {
				var checkSame = false;
				for(z = 0; z < selectBoxs.length; z++) {
					if(selectBoxs.item(z).name == el.name) {
						checkSame = true;
						break;
					}
				}
				if(!checkSame) {
					var el_left = el_top = 0;
					var obj = el;
					if (obj.offsetParent) {
						while (obj.offsetParent) {
							el_left += obj.offsetLeft;
							el_top  += obj.offsetTop;
							obj = obj.offsetParent;
						}
					}
					el_left  += el.clientLeft;
					el_top    += el.clientTop;
					el_right  = el_left + el.clientWidth;
					el_bottom = el_top + el.clientHeight;
	
					// ��ǥ�� ���� ���̾ ����Ʈ �ڽ��� ħ�������� ����Ʈ �ڽ��� hidden ��Ŵ
					if ( (el_left >= ly_left && el_top >= ly_top && el_left <= ly_right && el_top <= ly_bottom) ||
						(el_right >= ly_left && el_right <= ly_right && el_top >= ly_top && el_top <= ly_bottom) ||
						(el_left >= ly_left && el_bottom >= ly_top && el_right <= ly_right && el_bottom <= ly_bottom) ||
						(el_left >= ly_left && el_left <= ly_right && el_bottom >= ly_top && el_bottom <= ly_bottom) )
						el.style.visibility = 'hidden';
				}
			}
		}
	}
}

// ���߾��� ����Ʈ �ڽ��� ��� ���̰� ��
var selectboxVisible = function (tagName)
{
	tagName = (tagName||"SELECT");
	for (i=0; i<document.forms.length; i++) {
		for (k=0; k<document.forms[i].length; k++) {
			el = document.forms[i].elements[k];
			if (el.tagName == tagName && el.style.visibility == 'hidden')
				el.style.visibility = 'visible';
		}
	}
}

// �ش� �ܾ ���� ���縦 ���ؿ´� 
// type = 1 : (��/��), 2: (��/��), 3: (��/��)
function getAux(val, type){
	hanTable=new Array();
	hanTable[0]='��������������������������������������'; // 19 �ʼ�
	hanTable[1]='�������¤äĤŤƤǤȤɤʤˤ̤ͤΤϤФѤҤ�'; //21 �߼�
	hanTable[2]=' ������������������������������������������������������'; //28 ����

	b = val.charCodeAt(val.length-1);
	hcode = b-0xAC00;
	cho = new Array();
	cho[0] = parseInt(hcode / 588); //�ʼ�
	hcode2 = hcode % 588;
	cho[1] = parseInt(hcode2 / 28); //�߼�
	cho[2] = hcode2 % 28; //���� ��,,,�� 

	mun=new Array();
	mun[0]  =hanTable[0].charAt(cho[0]);
	mun[1] = hanTable[1].charAt(cho[1]); //����
	mun[2] = hanTable[2].charAt(cho[2]); //0���� ��������
	
	var aux = "���������̰�"
	return (mun[2].trim() != "") ? aux.charAt((type*2)-2) : aux.charAt((type*2)-1);
}

var zoomSize = 100; 
function zoom(obj,method) { 
    if(method == "in") { 
        zoomSize = zoomSize+10; 
    } else if(method == "out") { 
        if(zoomSize > 10) { 
			zoomSize = zoomSize-10;
        } 
    } else if(method == "reset") { 
        zoomSize = 100; 
    } 
    document.getElementById(obj).style.zoom = zoomSize + "%"; //Ư�� ������ ������
} 

// �Է��� �ڵ� ��Ŀ�� ��ȯ
function autoFocus(e, length, target) {
	ev = (e||window.event);
	var obj = ev.srcElement; 
	if(obj.value.length >= length 
			&& !$A([0,8,9,16,17,18,37,38,39,40,46]).include(ev.keyCode)) {
		target.focus();
	}
}

// ��¥��ȯ
function calculate(start, end) {
	var start = start.split("-");  
	var end = end.split("-");   

	var startdate = new Date(start[0], start[1]-1, start[2]);
	var enddate = new Date(end[0], end[1]-1, end[2]);
	return result = (enddate.getTime() - startdate.getTime() ) / 1000 / 60 / 60 / 24;    // Date ��ü�� �и��ʴ�����
}


// ���� ���
// strDate-YYYYMM, todate-YYYYMMDD, isFullAge-Y/N(�����̿���)
function getAge(strDate, todate, isFullAge){
	var Fage, Fage2, Ndate, Ndate2;

	Fage	= strDate.substring(0,2);
	Fage2	= strDate.substring(2,4);
	Fage3	= strDate.substring(2,6);
	Ndate	= todate.substring(0,4);
	Ndate2	= todate.substring(4,8);

	Fage2	= "20" + Fage;

	if(Fage2 >= Ndate){
		Fage2 = "19" + Fage;
	}

	Fage = Ndate - Fage2 + 1

	if(Fage > 100){
		Fage = Fage - 100;
	}

	// �� ���� ��� [isFullAge = Y]
	if(isFullAge == "Y"){
		if(Ndate2 > Fage3){
			Fage = Fage - 1;
		} else {
			Fage = Fage - 2;
		}
	}
	return Fage;
}


function setURL(param) {
	var query = $H(param).toQueryString();
	document.location.href = "#"+query;
}

function getURL() {
	var href = document.location.href;
	var param = $H({});
	if(href.indexOf("#") > 0) {
		query = href.substr(href.indexOf("#")+1);
		param = query.toQueryParams();
	}
	return param;
}

function replaceAll(str, oldChar,  newChar){
	while(str.indexOf(oldChar) > -1)
	{
		str = str.replace(oldChar, newChar);
	}
	return str;
}

/**
	 * ���� ��¥ �ѱ� ��¥�� ��ȯ 
	 * @param str
	 * @return
	 */
function getDateKr(str){
	str = str.replace("monday", "�����");
	str = str.replace("tuesday", "ȭ����");
	str = str.replace("wednesday", "������");
	str = str.replace("thursday", "�����");
	str = str.replace("friday", "�ݿ���");
	str = str.replace("saturday", "�����");
	str = str.replace("sunday", "�Ͽ���");
	str = str.replace("AM", "����");
	str = str.replace("PM", "����");
	return str;
}


