
function EP_activate(num) {
    document.write(document.getElementById("DEACTIVATED_TEXT" + num).value);
}

// 숫자를 money포맷으로 3자리씩 끊어 표현한다.
String.prototype.formatMoney = function() {
    if (!this.isNumber()) return null;

	var start = 0;
	var distance =  parseInt(this.length % 3);
	var nComma =  parseInt(this.length / 3);

	if (distance == 0){
		distance = 3;
		nComma -= 1;
	}

	var arr = new Array();
	for (var i=0; i<nComma + 1; i++) {
		arr[i] = this.substring(start, start + distance);

		start += distance;
		distance = 3;
	}

	var sReturn = ""
	var isFirst = true;
	for (var i=0; i<arr.length; i++) {
		sReturn += (isFirst ? "" : ",") + arr[i];
		isFirst = false;
	}

	return sReturn;
}

// 날짜 형식 yyyymmdd 형식이 맞는지 체크한다
String.prototype.isDate = function() {
	if (this.length != 8) return false;

	var year = parseInt(this.substr(0, 4));
	var month = parseInt(this.substr(4, 2));
	var day = parseInt(this.substr(6, 2));

	if (isNaN(year) || isNaN(month) || isNaN(day)) return false;
	if (year < 0) return false;
	if (month < 1 && month > 12) return false;
	if (day < 1 && day > 31) return false;

	var months = new Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

	if (day > months[month - 1]) return false;

	if (month == 2 && day == 29) {
		if (!((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) return false;
	}

	return true;
}

function openPopup(sUrl, nWidth, nHeight, sOption){
	var newin1 = null;
	var tmp = '';
	tmp += 'width=' + nWidth + ',height=' + nHeight + ',top=' + (screen.availHeight-nHeight-50)/2 + ', left=' + (screen.availWidth-nWidth-10)/2 + ' ,';
	if(sOption == null)tmp += 'status=yes,menubar=no,scrollbars=no,resizable=no,toolbar=no';
	else if(sOption == 'set1')tmp += 'status=yes,menubar=no,scrollbars=yes,resizable=no,toolbar=no';
	else tmp += sOption;
	window.open(sUrl, '', tmp);
}


/* 간단 AJAX 컨트롤러
	사용 :
	var ax = new ajaxControl();
	ax.send('주소', this, this.result);
*/
function ajaxControl(){
	this.conn = null;
	this.url = null;
	this.init();
}
ajaxControl.prototype.init = function(){ // 초기화
	if(this.conn == null)this.setXHR();
}
ajaxControl.prototype.send = function(sUrl, oSelf, oTarget){ // ** 데이터 보내기
	if(this.conn == null)this.init();
	var self = this;
	this.url = sUrl;
	this.conn.open("GET", this.url, true);
	this.conn.onreadystatechange = function(){self.callback(oSelf, oTarget)};
	this.conn.send(null);
}
ajaxControl.prototype.setXHR = function(){
	if(window.XMLHttpRequest)this.conn = new XMLHttpRequest();
	else if (window.ActiveXObject)this.conn = new ActiveXObject("Microsoft.XMLHTTP");
}
ajaxControl.prototype.callback = function(oSelf, oTarget){
	if(this.conn.readyState == 4){
		if(this.conn.status == 200)oTarget(this.conn, oSelf);
		else alert('데이터 통신 실패');
	}
}


// 카테고리 리스트 콤보
var cateCombo = {
	ax:null,
	frm:null,
	obj:null,
	idx:0,
	autoSelect:true,

	init:function(){
		this.ax = new ajaxControl();
	},

	req:function(obj){
		if(this.ax == null){
			this.init();
			this.frm = obj.form;
		}
		AF_util.init(this.frm);

		this.idx = AF_util.getIndex(obj);

		if(obj.value == ''){
			AF_util.setField('cate2[' + this.idx + ']');
			AF_util.comboClear(-1);
		}else{
			this.ax.send('/include/util/getCode.asp?code2=' + obj.value, this, this.rst);
		}
	},

	rst:function(o, oSelf){
		var rst = eval('(' + o.responseText + ')');
		var cnt = rst.data.length;

		AF_util.setField('cate2[' + oSelf.idx + ']');
		AF_util.comboClear(-1);

		if(cnt > 0){
			for(var i=0; i<cnt ; i++){
				AF_util.comboAdd(rst.data[i].codes, rst.data[i].names);
			}
		}
		if(oSelf.autoSelect)AF_util.getObject().selectedIndex = 1;
	}
}



function addEvent(obj, type, fn)
{
    if (obj.addEventListener)
        obj.addEventListener(type, fn, false);
    else if (obj.attachEvent)
    {
        obj["e"+type+fn] = fn;
        obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
        obj.attachEvent("on"+type, obj[type+fn]);
    }
}


function makeEnterEvent(formName, searchFnName){
	var frm = document[formName];
	if(typeof frm != 'undefined'){
		for(var i=0 ; i<frm.length ; i++){
			if(frm.elements[i].type == 'text')addEvent(frm.elements[i], 'keydown', function(){if(event.keyCode==13)eval(searchFnName)});
		}
	}
}

function contentsFiltering(arg) {
	var s = arg.replace(/—/g, "-");
	var s = s.replace(/–/g, "-");

	return s;
}
