//////////////////////////////////////////////////////////////////
//
// programed by kim dong man
//
//////////////////////////////////////////////////////////////////



//////////////////////////////////////////////////////////////////
// Table
//////////////////////////////////////////////////////////////////

function kTable(tbl)
{
	this.tbl = tbl;
	this.cell = new Object();
	this.num_dummyrow = 0;
	this.data_dummyrow = null;

	this.setCellAttribute = function(cell, name, value) {
		if(typeof this.cell[cell] == "undefined") this.cell[cell] = new Object();
		if(typeof this.cell[cell].attr == "undefined") this.cell[cell].attr = new Object();
		this.cell[cell].attr[name] = value;
	}

	this.getRowIndex = function(id) {
		for(var i=0; i<this.tbl.rows.length; i++) {
			if(typeof this.tbl.rows[i].kID != "undefined") {
				if(this.tbl.rows[i].kID == id)  return i;
			}
			else {
				if(this.tbl.rows[i].id == id)  return i;
			}
		}
		return -1;
	}

	this.addRow = function(id, rowsdata) {
		var oRow;
		var idx = this.getRowIndex(id);

		if(id == -1) idx = -1; // 더미 생성
		else if(idx == -1) idx = this.getRowIndex(-1); // 더미 Row

		if(idx == -1) { // 추가
			oRow = this.tbl.insertRow(-1);
			for(var i=0; i<rowsdata.length; i++) oRow.insertCell(i);
		}
		else { // 수정
			oRow = this.tbl.rows[idx];
		}
		oRow.kID = id;
		oRow.style.cursor = 'pointer';
		oRow.onclick = this.callback_click_row;
		oRow.ondblclick = this.callback_dblclick_row;
		oRow.onmouseover = this.callback_mouseover_row;
		oRow.onmouseout = this.callback_mouseout_row;
		oRow.oncontextmenu = this.callback_context_row;

		for(var i=0; i<rowsdata.length; i++) {
			if(typeof this.cell[i] == "undefined") continue;
			if(typeof this.cell[i].attr == "undefined") continue;
			for(var name in this.cell[i].attr) {
				var value = this.cell[i].attr[name];
				oRow.cells[i].setAttribute(name, value);
			}
		}

		for(var i=0; i<rowsdata.length; i++) {
			//oRow.cells[i].style.cursor = 'hand';
			oRow.cells[i].onclick = this.callback_click_cell;
			oRow.cells[i].onmouseover = this.callback_mouseover_cell;
			oRow.cells[i].onmouseout = this.callback_mouseout_cell;
			oRow.cells[i].innerHTML = rowsdata[i] == "" ? "&nbsp;" : rowsdata[i];
		}
		return oRow;
	}

	this.addDummyRow = function(rowsdata, num) {
		for(var i=0; i<num; i++) this.addRow(-1, rowsdata);
		this.data_dummyrow = rowsdata;
		this.num_dummyrow = num;
	}

	this.setData = function(id, col, data) {
		var idx = this.getRowIndex(id);
		if(idx == -1) return false;
		if(typeof this.tbl.rows[idx].cells[col] == "undefined") return false;
		this.tbl.rows[idx].cells[col].innerHTML = data;
		return true;
	}

	this.setDataFromIndex = function(idx, col, data) {
		if(typeof this.tbl.rows[idx].cells[col] == "undefined") return false;
		this.tbl.rows[idx].cells[col].innerHTML = data;
		return true;
	}

	this.delRow = function(id) {
		var idx = this.getRowIndex(id);
		if(idx == -1) return false;
		this.tbl.deleteRow(idx);

		var n = this.num_dummyrow - this.tbl.rows.length;
		for(var i=0; i<n; i++) {
			this.addRow(-1, this.data_dummyrow);
		}
		return true;
	}
	this.getRow = function(id) {
		var idx = this.getRowIndex(id);
		if(idx == -1) return null;
		return this.tbl.rows[idx];
	}
	this.reset = function() {
		var n = this.tbl.rows.length;
		for(var i=0; i<n; i++) this.tbl.deleteRow(0);
	}

	this.callback_click_row = function() { }
	this.callback_dblclick_row = function() { }
	this.callback_mouseover_row = function() { }
	this.callback_mouseout_row = function() { }
	this.callback_context_row = function() { }
	this.callback_click_cell = function() { }
	this.callback_mouseover_cell = function() { }
	this.callback_mouseout_cell = function() { }
}

//////////////////////////////////////////////////////////////////
// end of Table
//////////////////////////////////////////////////////////////////

function kImageList(img)
{
	this.img = img;
	this.files = new Array();
	this.num = 0;

	this.add = function(imgfile) {
		this.files[this.num] = imgfile;
		this.num++;
	}
	this.set = function(idx) {
		if(idx >= 0 && idx < this.num) {
			this.img.src = this.files[idx];
		}
	}
}

//////////////////////////////////////////////////////////////////
// sprintf
//////////////////////////////////////////////////////////////////

/*
**  sprintf.js -- POSIX sprintf(3) style formatting function for JavaScript
**  Copyright (c) 2006-2007 Ralf S. Engelschall <rse@engelschall.com>
**  Partly based on Public Domain code by Jan Moesen <http://jan.moesen.nu/>
**  Licensed under GPL <http://www.gnu.org/licenses/gpl.txt>
**
**  $LastChangedDate$
**  $LastChangedRevision$
*/

/*  make sure the ECMAScript 3.0 Number.toFixed() method is available  */
if (typeof Number.prototype.toFixed != "undefined") {
    (function(){
        /*  see http://www.jibbering.com/faq/#FAQ4_6 for details  */
        function Stretch(Q, L, c) {
            var S = Q
            if (c.length > 0)
                while (S.length < L)
                    S = c+S;
            return S;
        }
        function StrU(X, M, N) { /* X >= 0.0 */
            var T, S;
            S = new String(Math.round(X * Number("1e"+N)));
            if (S.search && S.search(/\D/) != -1)
                return ''+X;
            with (new String(Stretch(S, M+N, '0')))
                return substring(0, T=(length-N)) + '.' + substring(T);
        }
        function Sign(X) {
            return X < 0 ? '-' : '';
        }
        function StrS(X, M, N) {
            return Sign(X)+StrU(Math.abs(X), M, N);
        }
        Number.prototype.toFixed = function (n) { return StrS(this, 1, n) };
    })();
}

/*  the sprintf() function  */
sprintf = function () {
    /*  argument sanity checking  */
    if (!arguments || arguments.length < 1)
        alert("sprintf:ERROR: not enough arguments");

    /*  initialize processing queue  */
    var argumentnum = 0;
    var done = "", todo = arguments[argumentnum++];

    /*  parse still to be done format string  */
    var m;
    while (m = /^([^%]*)%(\d+$)?([#0 +'-]+)?(\*|\d+)?(\.\*|\.\d+)?([%diouxXfFcs])(.*)$/.exec(todo)) {
        var pProlog    = m[1],
            pAccess    = m[2],
            pFlags     = m[3],
            pMinLength = m[4],
            pPrecision = m[5],
            pType      = m[6],
            pEpilog    = m[7];

        /*  determine substitution  */
        var subst;
        if (pType == '%')
            /*  special case: escaped percent character  */
            subst = '%';
        else {
            /*  parse padding and justify aspects of flags  */
            var padWith = ' ';
            var justifyRight = true;
            if (pFlags) {
                if (pFlags.indexOf('0') >= 0)
                    padWith = '0';
                if (pFlags.indexOf('-') >= 0) {
                    padWith = ' ';
                    justifyRight = false;
                }
            }
            else
                pFlags = "";

            /*  determine minimum length  */
            var minLength = -1;
            if (pMinLength) {
                if (pMinLength == "*") {
                    var access = argumentnum++;
                    if (access >= arguments.length)
                        alert("sprintf:ERROR: not enough arguments");
                    minLength = arguments[access];
                }
                else
                    minLength = parseInt(pMinLength, 10);
            }

            /*  determine precision  */
            var precision = -1;
            if (pPrecision) {
                if (pPrecision == ".*") {
                    var access = argumentnum++;
                    if (access >= arguments.length)
                        alert("sprintf:ERROR: not enough arguments");
                    precision = arguments[access];
                }
                else
                    precision = parseInt(pPrecision.substring(1), 10);
            }

            /*  determine how to fetch argument  */
            var access = argumentnum++;
            if (pAccess)
                access = parseInt(pAccess.substring(0, pAccess.length - 1), 10);
            if (access >= arguments.length)
                alert("sprintf:ERROR: not enough arguments");

            /*  dispatch into expansions according to type  */
            var prefix = "";
            switch (pType) {
                case 'd':
                case 'i':
                    subst = arguments[access];
                    if (typeof subst != "number")
						subst = parseInt(subst); // fixed dongman
                        //subst = 0;
                    subst = subst.toString(10);
                    if (pFlags.indexOf('#') >= 0 && subst >= 0)
                        subst = "+" + subst;
                    if (pFlags.indexOf(' ') >= 0 && subst >= 0)
                        subst = " " + subst;
                    break;
                case 'o':
                    subst = arguments[access];
                    if (typeof subst != "number")
						subst = parseInt(subst); // fixed dongman
                        //subst = 0;
                    subst = subst.toString(8);
                    break;
                case 'u':
                    subst = arguments[access];
                    if (typeof subst != "number")
						subst = parseInt(subst); // fixed dongman
                        //subst = 0;
                    subst = Math.abs(subst);
                    subst = subst.toString(10);
                    break;
                case 'x':
                    subst = arguments[access];
                    if (typeof subst != "number")
						subst = parseInt(subst); // fixed dongman
                        //subst = 0;
                    subst = subst.toString(16).toLowerCase();
                    if (pFlags.indexOf('#') >= 0)
                        prefix = "0x";
                    break;
                case 'X':
                    subst = arguments[access];
                    if (typeof subst != "number")
						subst = parseInt(subst); // fixed dongman
                        //subst = 0;
                    subst = subst.toString(16).toUpperCase();
                    if (pFlags.indexOf('#') >= 0)
                        prefix = "0X";
                    break;
                case 'f':
                case 'F':
                    subst = arguments[access];
                    if (typeof subst != "number")
						subst = parseFloat(subst); // fixed dongman
                        //subst = 0.0;
                    subst = 0.0 + subst;
                    if (precision > -1) {
                        if (subst.toFixed)
                            subst = subst.toFixed(precision);
                        else {
                            subst = (Math.round(subst * Math.pow(10, precision)) / Math.pow(10, precision));
                            subst += "0000000000";
                            subst = subst.substr(0, subst.indexOf(".")+precision+1);
                        }
                    }
                    subst = '' + subst;
                    if (pFlags.indexOf("'") >= 0) {
                        var k = 0;
                        for (var i = (subst.length - 1) - 3; i >= 0; i -= 3) {
                            subst = subst.substring(0, i) + (k == 0 ? "." : ",") + subst.substring(i);
                            k = (k + 1) % 2;
                        }
                    }
                    break;
                case 'c':
                    subst = arguments[access];
                    if (typeof subst != "number")
						subst = parseInt(subst); // fixed dongman
                        //subst = 0;
                    subst = String.fromCharCode(subst);
                    break;
                case 's':
                    subst = arguments[access];
                    if (precision > -1)
                        subst = subst.substr(0, precision);
                    if (typeof subst != "string")
                        subst = "";
                    break;
            }

            /*  apply optional padding  */
            var padding = minLength - subst.toString().length - prefix.toString().length;
            if (padding > 0) {
                var arrTmp = new Array(padding + 1);
                if (justifyRight)
                    subst = arrTmp.join(padWith) + subst;
                else
                    subst = subst + arrTmp.join(padWith);
            }

            /*  add optional prefix  */
            subst = prefix + subst;
        }

        /*  update the processing queue  */
        done = done + pProlog + subst;
        todo = pEpilog;
    }
    return (done + todo);
}

//////////////////////////////////////////////////////////////////
// end of sprintf
//////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////
// trim
//////////////////////////////////////////////////////////////////
String.prototype.ltrim = function() {
	var re = /\s*((\S+\s*)*)/;
	return this.replace(re, "$1");
}

String.prototype.rtrim = function() {
	var re = /((\s*\S+)*)\s*/;
	return this.replace(re, "$1");
}

String.prototype.trim = function() {
	return this.ltrim().rtrim();
}
//////////////////////////////////////////////////////////////////
// end of trim
//////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////
// mlength (multibytes length)
//////////////////////////////////////////////////////////////////
String.prototype.mlength = function() {
	var len = 0;
	for(var i=0; i<this.length; i++) {
		if(this.charCodeAt(i) > 128) len+=2;
		else len++;
	}
	return len;
}
//////////////////////////////////////////////////////////////////
// end of length
//////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////
// cut (한글포함 문자열 자르기)
//////////////////////////////////////////////////////////////////
String.prototype.cut = function(len) {
	var str = this;
	var l = 0;
	for (var i=0; i<str.length; i++) {
		l += (str.charCodeAt(i) > 128) ? 2 : 1;
		if (l > len) return str.substring(0,i) + "...";
	}
	return str;
}
//////////////////////////////////////////////////////////////////
// end of cut
//////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////
// bytes (byte 단위 문자열 길이)
//////////////////////////////////////////////////////////////////
String.prototype.bytes = function() {
	var str = this;
	var l = 0;
	for (var i=0; i<str.length; i++) l += (str.charCodeAt(i) > 128) ? 2 : 1;
	return l;
}
//////////////////////////////////////////////////////////////////
// end of bytes
//////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////
// substr2 (byte 단위 substr)
//////////////////////////////////////////////////////////////////
String.prototype.substr2 = function(start, multibyte_len) {
	var str = this, v = "";
	var c = 0;

	if(typeof multibyte_len == "undefined") { multibyte_len = str.length; c = 1; }

	for(var i=start; i<start+multibyte_len; i++) {
		v += str.charAt(i);
		if(c==0 && str.charCodeAt(i) > 128) multibyte_len--;
	}
	return v;
}
//////////////////////////////////////////////////////////////////
// end of substr2
//////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////
// toNumber
//////////////////////////////////////////////////////////////////
String.prototype.toNumber = function() {
	var str = this;
	if(str == '') return 0;
	var v = parseInt(str);
	if(v == 'NaN') return 0;
	return v;
}
//////////////////////////////////////////////////////////////////
// end of substr2
//////////////////////////////////////////////////////////////////

function number_format(num) {
	var num_str = parseInt(num).toString();
	var result = '';

	for(var i=0; i<num_str.length; i++) {
		var tmp = num_str.length-(i+1);
		if(i%3==0 && i!=0) result = ',' + result;
		result = num_str.charAt(tmp) + result;
	}

	return result;
}

function float_format(num) {
	var n2 = sprintf("%.1f", num - parseInt(num)).substr(1);
	return number_format(parseInt(num)) + n2;
}

//////////////////////////////////////////////////////////////////
// Queue
//////////////////////////////////////////////////////////////////

/* **************
// Create a new queue
q=new Queue();

// enqueue some elements
q.push(1);
q.push(2);

// dequeue and output some elements
alert(q.pop()); // 1
alert(q.pop()); // 2
alert(q.pop()); // undefined
************* */

function Queue(){
	var queue=new Array();

	this.push = function(element) {
		queue.push(element);
	}

	this.pop = function() {
		if(queue.length == 0) return undefined;
		var data = queue[queue.length-1];
		queue.splice(0, 1);
		return data;
	}

	this.drop = function(n) {
		if(queue.length == 0) return ;
		queue.splice(0, Math.min(n, queue.length));
	}

	this.data = function() {
		return queue;
	}
}


//////////////////////////////////////////////////////////////////
// AJAX
//////////////////////////////////////////////////////////////////

var g_kGlobalAjaxNO = 0;
var g_kGlobalAjaxSelf = [];
var g_kGlobalAjaxXmlCodeErrorFunction = null;
function kGlobalAjaxXmlCodeErrorFunction(func)
{
	g_kGlobalAjaxXmlCodeErrorFunction = func;
}

function kXmlCode() {
	var code = [];

	this._getnode = function(node) {
		if(node != null && node.nodeName == '#text') node = node.nextSibling;
		return node;
	}

	this.xml = function(xml) {
	    try {
		var kcode= xml.getElementsByTagName("kcode")[0];
		if(typeof kcode == "undefined") return null;

		delete code;

		var curNode = this._getnode(kcode.firstChild);

		while(curNode != null) {
			var itemNode = this._getnode(curNode.firstChild);
			var data = {};
			while(itemNode != null) {
				var name = itemNode.nodeName;
				var value = itemNode.firstChild.nodeValue;
				data[name] = value.replace(/&lt;/g, "<").replace(/&gt;/g, ">");
				if(data[name] == "#empty#") data[name] = "";

				code.push(data);	// 아래 주석처리하고 추가함. by nadaun 2011.08.21

				itemNode = this._getnode(itemNode.nextSibling);
			}

			//code.push(data);		// 주석처리하고 위 while 안에 추가함. by nadaun 2011.08.21
			curNode = this._getnode(curNode.nextSibling);
		}
	    } catch(e) {
//		if(g_kGlobalAjaxXmlCodeErrorFunction == null) alert('kXmlCode::xml parse error');
//		else g_kGlobalAjaxXmlCodeErrorFunction();
		if(g_kGlobalAjaxXmlCodeErrorFunction != null) g_kGlobalAjaxXmlCodeErrorFunction();
	    }

		//code.reverse();
		//for(i=0; i<code.length; i++) alert(code[i]['name']);
	}

	this.get = function(no, name) {
		try {
			if(typeof code[no][name] == "undefined") return "";
			return code[no][name];
		} catch(e) {
			return "";
		}
	}

	this.get_count = function() {
		try {
			return code.length;
		} catch(e) {
			return 0;
		}
	}
}

function kAjaxCB() {
	this.cb_xml = function(ajax, cb_func, param, param2, issilent) {
		return function() {
			if (ajax.xmlreq.readyState == 4) {
				if (ajax.xmlreq.status == 200) {
					cb_func(ajax.xmlreq.responseXML, param, param2);
				}
				else if(ajax.xmlreq.status == 404) {
					// Requested URL is not found
				}
				else if(ajax.xmlreq.status == 403) {
					// Access denied
				}
				ajax._Done(issilent);
			}
		}
	}
	this.cb_text = function(ajax, cb_func, param, param2, issilent) {
		return function() {
			if (ajax.xmlreq.readyState == 4) {
				if (ajax.xmlreq.status == 200) {
					cb_func(ajax.xmlreq.responseText, param, param2);
				}
				else if(ajax.xmlreq.status == 404) {
					// Requested URL is not found
				}
				else if(ajax.xmlreq.status == 403) {
					// Access denied
				}
				ajax._Done(issilent);
			}
			//alert(ajax.xmlreq.readyState + " , " + ajax.xmlreq.status);
		}
	}
}

function kAjax()
{
	this.xmlreq = null;
	this.is_running = false;

	this.silentmode_ontime = false;
	this.asyncmode = true;

	this.header = new Object();
	this.header.list = new Array();

	this.postv = [];
	this.stack_cb = new Array();

	this.func_start = null;
	this.func_end = null;

	this.ajax_no = g_kGlobalAjaxNO;
	g_kGlobalAjaxNO++;

	// [] Array, {} Object
	this.isRunning = function() { return this.is_running; }

	this.CB_Debug = function(html) {
		alert(html);
	}

	this._startUp = function() {
		if(this.xmlreq != null) return ;

		g_kGlobalAjaxSelf[this.ajax_no] = this;

		if (window.XMLHttpRequest) {
			this.xmlreq = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			try {
				this.xmlreq = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e1) {
				try {
					this.xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e2) {
					this.xmlreq = null;
				}
			}
		}
	}

	this.__Done = function(issilent) {
		this.xmlreq.abort();
		if(issilent == false && this.func_end != null) this.func_end();
		if(typeof this.stack_cb == "undefined" || this.stack_cb.length <= 0) {
			this.is_running = false;
			return ;
		}

		var a = this.stack_cb.shift();
		switch(a[0]) {
		case 0: this._XML(a[1], a[2], a[3], a[4], true); break;
		case 1: this._HTML(a[1], a[2], a[3], a[4], true); break;
		case 2: this._XML_POST(a[1], a[5], a[2], a[3], a[4], true); break;
		case 3: this._HTML_POST(a[1], a[5], a[2], a[3], a[4], true); break;
		}
	}
	this._Done = function(issilent) {
		if(issilent == true) setTimeout("g_kGlobalAjaxSelf["+this.ajax_no+"].__Done(true)", 1);
		else setTimeout("g_kGlobalAjaxSelf["+this.ajax_no+"].__Done(false)", 1);

	}

	this.ClearHeader = function() {
		this.header.splice(0, this.header.list.length);
	}

	this.SetHeader = function(name, value) {
		//if(typeof(this.header[name]) == 'undefined') {
		this.header[name] = value;
		this.header.list[this.header.list.length] = name;
		//}
	}

	this.SetFunc_Start = function(func) {
		this.func_start = func;
	}
	this.SetFunc_End = function(func) {
		this.func_end = func;
	}
	this.SetSilentMode_Onetime = function() {
		this.silentmode_ontime = true;
	}
	this.SetAyncMode = function(b) {
		this.asyncmode = b;
	}

	this._XML = function(url, cb_func, param, param2, isforce, issilent) {
		if(isforce == false && this.is_running == true) {
			this.stack_cb.push([0, url, cb_func, param, param2, null]);
			return ;
		}
		this.is_running = true;

		this._startUp();

		//this.SetHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
		//this.SetHeader("Pragma", "no-cache");
		//this.SetHeader("Cache-Control", "no-cache,must-revalidate");

		this.xmlreq.open("GET", url, this.asyncmode);

		var k = new kAjaxCB();
		this.xmlreq.onreadystatechange = k.cb_xml(this, cb_func, param, param2, issilent);

		for(var i=0; i<this.header.list.length; i++) {
			this.xmlreq.setRequestHeader(this.header.list[i], this.header[this.header.list[i]]);
		}
		this.xmlreq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
		this.xmlreq.setRequestHeader("Pragma", "no-cache");
		this.xmlreq.setRequestHeader("Cache-Control", "no-cache,must-revalidate");

		if(issilent == false && this.func_start != null) this.func_start();
		this.xmlreq.send(null);

		delete k;
	}

	this._HTML = function(url, cb_func, param, param2, isforce, issilent) {
		if(isforce == false && this.is_running == true) {
			this.stack_cb.push([1, url, cb_func, param, param2, null]);
			return ;
		}
		this.is_running = true;
		this._startUp();

		//this.SetHeader("Content-Type", "text/html;charset=utf-8");
		//this.SetHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
		//this.SetHeader("Pragma", "no-cache");
		//this.SetHeader("Cache-Control", "no-cache,must-revalidate");

		this.xmlreq.open("GET", url, this.asyncmode);

		var k = new kAjaxCB();
		this.xmlreq.onreadystatechange = k.cb_text(this, cb_func, param, param2, issilent);

		for(var i=0; i<this.header.list.length; i++) {
			this.xmlreq.setRequestHeader(this.header.list[i], this.header[this.header.list[i]]);
		}
		this.xmlreq.setRequestHeader("Content-Type", "text/html;charset=utf-8");
		this.xmlreq.setRequestHeader("Pragma", "no-cache");
		this.xmlreq.setRequestHeader("Cache-Control", "no-cache,must-revalidate");

		if(issilent == false && this.func_start != null) this.func_start();
		this.xmlreq.send(null);

		delete k;
	}

	this._XML_POST = function(url, data, cb_func, param, param2, isforce, issilent) {
		if(isforce == false && this.is_running == true) {
			this.stack_cb.push([2, url, cb_func, param, param2, data]);
			return ;
		}
		this.is_running = true;

		this._startUp();

		//this.SetHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
		//this.SetHeader("Content-length", data.length);
		//this.SetHeader("Connection", "Close");
		//this.SetHeader("Pragma", "no-cache");
		//this.SetHeader("Cache-Control", "no-cache,must-revalidate");

		this.xmlreq.open("POST", url, this.asyncmode);

		var k = new kAjaxCB();
		this.xmlreq.onreadystatechange = k.cb_xml(this, cb_func, param, param2, issilent);

		for(var i=0; i<this.header.list.length; i++) {
			this.xmlreq.setRequestHeader(this.header.list[i], this.header[this.header.list[i]]);
		}
		this.xmlreq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
		this.xmlreq.setRequestHeader("Content-length", data.length);
		this.xmlreq.setRequestHeader("Pragma", "no-cache");
		this.xmlreq.setRequestHeader("Cache-Control", "no-cache,must-revalidate");

		if(issilent == false && this.func_start != null) this.func_start();
		this.xmlreq.send(data);

		delete k;
	}

	this._HTML_POST = function(url, data, cb_func, param, param2, isforce, issilent) {
		if(isforce == false && this.is_running == true) {
			this.stack_cb.push([3, url, cb_func, param, param2, data]);
			return ;
		}
		this.is_running = true;

		this._startUp();

		//this.SetHeader("Content-Type", "text/html;charset=utf-8");
		//this.SetHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
		//this.SetHeader("Content-length", data.length);
		//this.SetHeader("Content-length", 0);
		//this.SetHeader("Connection", "Close");
		//this.SetHeader("Pragma", "no-cache");
		//this.SetHeader("Cache-Control", "no-cache,must-revalidate");

		this.xmlreq.open("POST", url, this.asyncmode);

		var k = new kAjaxCB();
		this.xmlreq.onreadystatechange = k.cb_text(this, cb_func, param, param2, issilent);

		for(var i=0; i<this.header.list.length; i++) {
			this.xmlreq.setRequestHeader(this.header.list[i], this.header[this.header.list[i]]);
		}
		this.xmlreq.setRequestHeader("Content-Type", "text/html;charset=utf-8");
		this.xmlreq.setRequestHeader("Content-length", data.length);
		this.xmlreq.setRequestHeader("Pragma", "no-cache");
		this.xmlreq.setRequestHeader("Cache-Control", "no-cache,must-revalidate");

		if(issilent == false && this.func_start != null) this.func_start();
		this.xmlreq.send(data);

		delete k;
	}

	this.XML = function(url, cb_func, param, param2) {
		var issilent = this.silentmode_ontime;
		this.silentmode_ontime = false;
		this._XML(url, cb_func, param, param2, false, issilent);
	}
	this.HTML = function(url, cb_func, param, param2) {
		var issilent = this.silentmode_ontime;
		this.silentmode_ontime = false;
		this._HTML(url, cb_func, param, param2, false, issilent);
	}
	this.XML_POST = function(url, cb_func, param, param2) {
		var data = '';
		var n = this.postv.length;

		for(var i=0; i<n; i++) {
			var p = this.postv.shift();
			if(i!=0) data += "&";
			data += p[0] + "=" + encodeURIComponent(p[1]);
		}

		var issilent = this.silentmode_ontime;
		this.silentmode_ontime = false;

		this._XML_POST(url, data, cb_func, param, param2, false, issilent);
	}
	this.HTML_POST = function(url, cb_func, param, param2) {
		var data = '';
		var n = this.postv.length;

		for(var i=0; i<n; i++) {
			var p = this.postv.shift();
			if(i!=0) data += "&";
			data += p[0] + "=" + encodeURIComponent(p[1]);
		}

		var issilent = this.silentmode_ontime;
		this.silentmode_ontime = false;

		this._HTML_POST(url, data, cb_func, param, param2, false, issilent);
	}

	this.PostV = function(name, value) {
		this.postv.push([name, value]);
	}
}

//////////////////////////////////////////////////////////////////
// end of AJAX
//////////////////////////////////////////////////////////////////

function getOffsetLeft(obj)
{
	var retval = typeof document.body.clientLeft == 'undefined' ? 0 : document.body.clientLeft;

	while (obj) {
		retval += obj.offsetLeft;
		obj = obj.offsetParent;
	}
	return retval;
}

function getOffsetTop(obj)
{
	var retval = typeof document.body.clientTop == 'undefined' ? 0 : document.body.clientTop;

	while (obj) {
		retval += obj.offsetTop;
		obj = obj.offsetParent;
	}
	return retval;
}

function getPosition(obj)
{
	var left = 0;
	var top  = 0;

	while(obj) {
		left += obj.offsetLeft;
		top  += obj.offsetTop;
		obj   = obj.offsetParent;
	}

	return { x:left, y:top };
}

function getAbsPosition(obj)
{
	var left = 0;
	var top  = 0;

	while(obj) {
		left += obj.offsetLeft;
		top  += obj.offsetTop;
		left += obj.scrollLeft;
		top  += obj.scrollTop;

		obj   = obj.offsetParent;

		if(obj.style.position != '') break;
	}

	return { x:left, y:top };
}

function getOffsetPosition(obj)
{
	var p1 = getPosition(obj);
	var p2 = getAbsPosition(obj);
	return { x: p1.x-p2.x, y: p1.y-p2.y }
}

function getMousePos(ev)
{
	if(ev.pageX || ev.pageY) {
		return { x:ev.pageX, y:ev.pageY };
	}

	var left, top
	if(document.compatMode == "CSS1Compat") {
		left = document.documentElement.scrollLeft;
		top = document.documentElement.scrollTop;
	}
	else {
		left = document.body.scrollLeft;
		top = document.body.scrollTop;
	}

	return {
		x:ev.clientX + left,
		y:ev.clientY + top
	};
}

function isInObject(x, y, obj)
{
	var m = getPosition(obj);
	//alert(sprintf("(%d,%d) (%d,%d, %d,%d)", x,y, m.x,m.y, m.x+obj.offsetWidth, m.y+obj.offsetHeight));
	if(x >= m.x && x <= m.x + obj.offsetWidth &&
	   y >= m.y && y <= m.y + obj.offsetHeight) return true;
	return false;
}

function DragDrop()
{
	var droplist = [];

	// 콜백
	this._cb_function = function(drag_obj, drop_obj) { alert(drop_obj); }

	var _drop_checker2 = function(obj) {
		var x = obj.offsetLeft + obj.ox + obj.offsetWidth/2;
		var y = obj.offsetTop + obj.oy + obj.offsetHeight/2;

		var drop_obj = null;
		var p;
		while((p = droplist.pop()) != null) {
			if(isInObject(x, y, p) == true) { drop_obj = p; break; }
		}

		var k = '';
		if(drop_obj) {
			var i = drop_obj.id.search(/\./);
			if(i!=-1) k = drop_obj.id.substr(i+1);
		}

		return { drag: obj, drop: drop_obj, key: k };
	}

	var _drop_checker = function(obj) {
		var x = obj.offsetLeft + obj.offsetWidth/2;
		var y = obj.offsetTop + obj.offsetHeight/2;

		var drop_obj = null;
		var p;
		while((p = droplist.pop()) != null) {
			if(isInObject(x, y, p) == true) { drop_obj = p; break; }
		}

		var k = '';
		if(drop_obj) {
			var i = drop_obj.id.search(/\./);
			if(i!=-1) k = drop_obj.id.substr(i+1);
		}

		return { drag: obj, drop: drop_obj, key: k };
	}

	this.drag_img = function(obj, id, cbfunc, param)
	{
		var a = document.getElementsByTagName("div");

		droplist.splice(0, droplist.length);
		for(var i=0; i<a.length; i++) {
			if(a[i].id.substr(0,id.length) == id) { droplist.push(a[i]); }
		}

		var o = obj.getElementsByTagName("img");
		if(o.length == 1) {
			obj.innerHTML = sprintf("<div style='background:url(%s);width:%dpx;height:%dpx'></div>",
				o[0].src, o[0].offsetWidth, o[0].offsetHeight);
		}
		this.drag(obj, id, cbfunc, param);
	}

	this.drag = function(obj, id, cbfunc, param)
	{
		//var p = getOffsetPosition(obj);
		//obj.ox = p.x;
		//obj.oy = p.y;

		//if(typeof obj.save_position == 'undefined') {
			//obj.save_position = obj.style.position;
			//obj.save_zIndex = obj.style.zIndex;
			//obj.save_left = obj.style.left;
			//obj.save_top = obj.style.top;
			//obj.save_offsetParent = obj.offsetParent;
		//}

		//if(typeof obj.drag_started == 'undefined') {
			//obj.drag_started = 'clicked';
		//}
		obj.drag_started = 'clicked';

		document.onmousemove = function(e) {
			e = e || window.event;

			try {
			if(obj.drag_started == 'clicked') {
				//obj.drag_started = '1';
				obj.drag_started = 'moving';

				obj.save_clonenode = obj.cloneNode(true);
				obj.save_clonenode.innerHTML = obj.innerHTML;
				document.body.appendChild(obj.save_clonenode);

				obj.save_clonenode.style.position = 'absolute';
				obj.save_clonenode.style.zIndex = 999999;
				obj.innerHTML = "&nbsp;";

				//obj.style.opacity = 0.4;
				//obj.filters.alpha.opacity = 40;
			}

			if(obj.drag_started == 'moving') {
				var m = getMousePos(e);
				obj.save_clonenode.style.left =m.x - obj.save_clonenode.offsetWidth/2;
				obj.save_clonenode.style.top = m.y - obj.save_clonenode.offsetHeight/2;
			}
			} catch(e) { ; }
		}

		document.onmouseup = function() {
			if(obj.drag_started != 'moving') {
				obj.drag_started = '';
				return ;
			}

			var a = _drop_checker(obj.save_clonenode);

			try {
			obj.drag_started = '';

			document.onmousedown = '';
			document.onmousemove = '';
			document.onmouseup = '';

			if(typeof tooltip != 'undefined') tooltip.hide();

			if(obj.save_clonenode) {
				obj.innerHTML = obj.save_clonenode.innerHTML;
				document.body.removeChild(obj.save_clonenode);
				obj.save_clonenode = '';
				if(typeof obj.cache_tooltip != 'undefined') obj.cache_tooltip = null;
			}
			} catch(e) { ; }

			if(a.drop) {
				cbfunc(obj, a.drop, a.key, param);
			}

		}

		document.onmousemove2 = function(e) {
			e = e || window.event;

			//if(obj.style.position == '') {
			if(obj.drag_started == '') {
				obj.drag_started = '1';
				obj.style.position = 'absolute';
				obj.style.zIndex = 999999;

				obj.save_clonenode = obj.cloneNode();
				document.body.appendChild(obj.save_clonenode);
			}

			var m = getMousePos(e);
			//obj.style.left = m.x - obj.offsetWidth/2;
			//obj.style.top = m.y - obj.offsetHeight/2;

			obj.style.left = (m.x - obj.ox) - obj.offsetWidth/2;
			obj.style.top = (m.y - obj.oy) - obj.offsetHeight/2;
		}

		document.onmouseup2 = function() {

			var a = _drop_checker(obj);

			document.onmousedown = '';
			document.onmousemove = '';
			document.onmouseup = '';
			obj.ondrag = '';

			obj.style.position = obj.save_position;
			obj.style.zIndex = obj.save_zIndex;
			obj.style.left = obj.save_left;
			obj.style.top = obj.save_top;
			obj.save_offsetParent.appendChild(obj); // <- 문제?

			obj.drag_started = '';
			obj.save_position = '';

			if(a.drop) {
				cbfunc(a.drag, a.drop, a.key, param);
			}
		}

		//obj.ondrag = window.onmousemove;
		//obj.ondragend = window.onmouseup;
	}
}

//////////////////////////////////////////////////////////////////
// Tooltip
//////////////////////////////////////////////////////////////////
function Tooltip()
{
	this.is_init = false;
	this.eventValue = null;
	this.v_hide = false;
	this.a_obj = null;

	this.init = function()
	{
		if(this.is_init == true) return ;
		this.is_init = true;

		var v = "<div id=tooltip style='display:none; position:absolute; left:0; top:0; width:100%; z-index:99999'><div style='position:absolute; left:0; top:0; opacity:0.8; filter:alpha(opacity=80)'><table id='tooltip_in' cellspacing=0 cellpadding=0 border=0 style='border:1px solid black;padding:6px; background:black'><tr><td id=var_tooltip1 style='color:white'></td></tr></table></div><div style='position:absolute; left:0; top:0'><table cellspacing=0 cellpadding=0 border=0 style='border:1px solid black;padding:6px'><tr><td id=var_tooltip2 style='color:white'></td></tr></table></div></div>";

		if(typeof vLastHTML == "undefined") document.body.innerHTML += v;
		else vLastHTML += v;
	}

	this.mesg = function(mesg)
	{
		var o1 = document.getElementById("var_tooltip1");
		var o2 = document.getElementById("var_tooltip2");
		if(o1 == null || o2 == null) return ;

		o1.innerHTML = mesg;
		o2.innerHTML = mesg;
	}

	this.show = function(obj, msg)
	{
		var o = document.getElementById("tooltip");
		if(o == null) {
			return ;
		}

		o.style.display = 'none';
		this.mesg(msg);
		//o.style.display = '';

		this.a_obj = obj;

		obj.onmouseout = function() { o.style.display = 'none'; obj.onmousemove = ''; this.onmousemove = ''; }
		obj.onmousemove = function(e) {
			var o = document.getElementById("tooltip");
			if(o == null) return ;

			var o_in = document.getElementById("tooltip_in");

			if(typeof event == 'undefined') {
				var x = e.pageX+10;
				var y = e.pageY+10;

				if(x + parseInt(o_in.offsetWidth) > document.body.clientWidth) x -= (parseInt(o_in.offsetWidth)+20);
				if(y + parseInt(o_in.offsetHeight) > document.body.clientHeight) y -= (parseInt(o_in.offsetHeight)+20);
				o.style.left = x;
				o.style.top = y;
				o.style.display = '';
			}
			else {
				var x = event.clientX+10 + document.body.scrollLeft - document.body.clientLeft;
				var y = event.clientY+10 + document.body.scrollTop - document.body.clientTop;

				if(x + parseInt(o_in.offsetWidth) > document.body.clientWidth) x -= (parseInt(o_in.offsetWidth)+20);
				if(y + parseInt(o_in.offsetHeight) > document.body.clientHeight) y -= (parseInt(o_in.offsetHeight)+20);

				o.style.left = x;
				o.style.top = y;
				o.style.display = '';
			}
		}

	}

	this.hide = function()
	{
		var o = document.getElementById("tooltip");
		if(o == null) return ;
		o.style.display = 'none';
		o.onmousemove = '';

		if(this.a_obj != null) this.a_obj.onmousemove = '';
	}
}
//////////////////////////////////////////////////////////////////
// end of Tooltip
//////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////
// Animation
//////////////////////////////////////////////////////////////////

function Animation()
{
	this.thisname = "";
	this.width = 0;
	this.height = 0;
	this.num = 0;
	this.tick = 100;
	this.screenwidth = 0;

	this.ani = [];
	this.interval = null;

	this.cb_end_func = null;

	this.cb_end = function(cb_func) // 끝났을때 Callback
	{
		this.cb_end_func = cb_func;
	}

	this.init = function(thisname, width, height, num, tick, screenwidth)
	{
		this.ani.splice(0, this.ani.length);
		this.cb_end_func = null;

		this.thisname = thisname;
		this.width = width;
		this.height = height;
		this.num = num;
		this.tick = tick;
		this.screenwidth = screenwidth;
	}

	// speed: 초당 이동거리
	this.add = function(objname, speed)
	{
		var obj = document.getElementById(objname);
		var obj_p = document.getElementById(objname + "_p");
		var obj_t = document.getElementById(objname + "_text");
		if(obj == null || obj_p == null) return ;

		var opos = { x:parseFloat(obj_p.style.left), y:parseFloat(obj_p.style.top) };
		var pos = { x:parseFloat(obj_p.style.left), y:parseFloat(obj_p.style.top) };

		if(obj_t != null) {
			obj_t.o_left = parseInt(obj_t.style.left);
			obj_t.o_top = parseInt(obj_t.style.top);
		}

		this.ani.push({obj:obj, obj_p:obj_p, obj_t:obj_t, speed:speed, opos:opos, pos:pos, end:true});
	}

	this.set_speed = function(no, speed)
	{
		this.ani[no].speed = speed;
	}

	this.set_opos = function(no, x, y) // 시작위치
	{
		this.ani[no].opos.x = x;
		this.ani[no].opos.y = y;
	}

	this.set_opos_x = function(no, x) // 시작위치
	{
		this.ani[no].opos.x = x;
	}

	this.set_opos_y = function(no, y) // 시작위치
	{
		this.ani[no].opos.y = y;
	}

	// get_speed
	this.get_speed = function(no)
	{
		return this.ani[no].speed;
	}

	this.get_pos = function(no)
	{
		return this.ani[no].pos;
	}

	this.get_aninum = function()
	{
		return this.ani.length;
	}

	this.stop = function()
	{
		if(this.interval != null) { clearInterval(this.interval); this.interval = null; }
		//EMBED_stop("snd_racebg");
	}

	this.run = function()
	{
		if(this.thisname == "") return ;

		this.stop();

		for(var i=0; i<this.ani.length; i++) {
			var x = this.width * (parseInt(Math.random()*1000) % this.num);
			this.ani[i].obj.style.left = "-" + x + "px";

			this.ani[i].obj_p.style.left = parseInt(this.ani[i].opos.x) + "px";
			this.ani[i].obj_p.style.top = parseInt(this.ani[i].opos.y) + "px";
			this.ani[i].obj_p.style.display = '';
			this.ani[i].laststep = -1;

			if(this.ani[i].obj_t) {
				var x = parseInt(this.ani[i].obj_p.style.left) + this.ani[i].obj_t.o_left;
				var y = parseInt(this.ani[i].obj_p.style.top) + this.ani[i].obj_t.o_top;
				this.ani[i].obj_t.style.left = x + "px";
				this.ani[i].obj_t.style.top = y + "px";
				this.ani[i].obj_t.style.display = '';
			}

			this.ani[i].pos.x = this.ani[i].opos.x;
			this.ani[i].pos.y = this.ani[i].opos.y;
		}

		this.interval = setInterval(this.thisname + '._run()', this.tick);
	}

	this._run = function()
	{
		var bEnd = true;
		for(var i=0; i<this.ani.length; i++) {
			if(this._run_obj(i) == false) {
				this.ani[i].end = false;
			}
			else bEnd = false;
		}

		if(bEnd == true) {
			this.stop();
			if(this.cb_end_func) this.cb_end_func();
		}

		//window.title =  "test";//Math.random()*1000;
	}

	this._run_obj = function(no)
	{
		// 프레임 이미지 변경
		var x = parseInt(this.ani[no].obj.style.left);
		if(x == -(this.width * (this.num-1))) x = 0;
		else x -= this.width;

		this.ani[no].obj.style.left = x + "px";

		if(x == 0) {
			if(no == 0) {
				EMBED_stop("snd_running");
				EMBED_play("snd_running");
			}
			if(no == 1) {
				if(EMBED_isplay("snd_racebg") == false) {
					EMBED_play("snd_racebg");
				}
			}
		}

		// 이동
		var mx = (this.tick / 1000.0) * this.ani[no].speed;
		this.ani[no].pos.x += mx;
		var x = parseInt(this.ani[no].pos.x);
		var y = parseInt(this.ani[no].pos.y);

		this.ani[no].obj_p.style.left = x + "px";
		this.ani[no].obj_p.style.top = y + "px";

		if(this.ani[no].obj_t) {
			var xx = x + this.ani[no].obj_t.o_left;
			var yy = y + this.ani[no].obj_t.o_top;
			this.ani[no].obj_t.style.left = xx + "px";
			this.ani[no].obj_t.style.top = yy + "px";
		}

		if(x > this.screenwidth) return false;

		return true;
	}
}

//////////////////////////////////////////////////////////////////
// end of Animation
//////////////////////////////////////////////////////////////////

function removeChildAll(o)
{
	try {
		while(o.childNodes[0]) {
			o.removeChild(o.childNodes[0]);
		}
	} catch(e) {
		;
	}

}

function cssValue(id, value)
{
	var obj = document.getElementById(id);
	if(obj == null) return false;

	removeChildAll(obj);

	obj.innerHTML = value;
	return true;
}

function cssValueImg(id, value)
{
	var obj = document.getElementById(id);
	if(obj == null) return false;
	obj.src = value;
	return true;
}

function cssShowLayer(id, b)
{
	var obj = document.getElementById(id);
	if(obj == null) return false;
	obj.style.display = b == true ? '' : 'none';
	return true;
}

function cssIsShowLayer(id)
{
	var obj = document.getElementById(id);
	if(obj == null) return ;
	return obj.style.display == 'none' ? false : true;
}

function cssGraph(id, width, value, maxvalue, msg_tooltip)
{
	var obj = document.getElementById(id);
	if(obj == null) return ;
	obj.style.width = (Math.min(value,maxvalue) / maxvalue) * width;
	obj.style.fontSize = '1px';

	obj.style.border = '1px solid #808080';
	obj.style.borderLeftColor = '#DDDDDD';
	obj.style.borderTopColor = '#DDDDDD';

	if(typeof msg_tooltip != 'undefined') {
		if(typeof tooltip != 'undefined') {
			obj.onmouseover = function() { tooltip.show(this, msg_tooltip); }
		}
		else obj.title = msg_tooltip;
	}
}

function cssGet(id, vtype)
{
	var obj = document.getElementById(id);
	if(obj == null) return "";

	if(typeof vtype != "undefined") {
		if(vtype == "obj") return obj;
		return eval("obj."+vtype);
	}

	return obj.value;
}

function cssGetChildNode(parentObj, childTagName)
{
	var obj = [], n = 0;
	for(var i=0; i<parentObj.childNodes.length; i++) {
		var o = parentObj.childNodes[i];
		if(o.nodeName == childTagName) {
			obj[n++] = o;
		}
	}
	return obj;
}

function isValidName(name)
{
	if(name == '') return false;
	if(name.search(/'/) != -1) return false;
	if(name.search(/"/) != -1) return false;
	if(name.search(/!/) != -1) return false;
	if(name.search(/#/) != -1) return false;
	if(name.search(/</) != -1) return false;
	if(name.search(/>/) != -1) return false;
	return true;
}

function go_url(url)
{
    var s1 = url.split("&");
    var s2;
    var u = [];
    for(var i=0; i<s1.length; i++) {
        s2 = s1[i].split("=");
        if(s2.length == 2) {
            u.push(s2[0] + "=" + escape(s2[1]));
        }
        else u.push(s1[i]);
    }
    url = u.join("&");

	document.location.href = url;
}

function confirm_url(msg, url)
{
	if(confirm(msg)) go_url(url);
}

function LIB_onEvSelectStart()
{
	var el = event.srcElement;
	if(el.type == 'text') return true;
	if(el.type == 'textarea') return true;
	// if(el.name == 'var_chatscreen') return true;
	// if(el.className == 'ScrollLayer') return true;
	return false;
}

function LIB_onEvContextMenu()
{
	var el = event.srcElement;
	if(el.type == 'text') return true;
	if(el.type == 'textarea') return true;
	// if(el.name == 'var_chatscreen') return true;
	// if(el.className == 'ScrollLayer') return true;
	return false;
}

// ex) EMBED_option("sound", "off");
function EMBED_option(id, mode)
{
	// 미구현
}

function EMBED_isplay(id)
{
	var snd = cssGet(id, "obj");
	if(snd == "") return false;
	if(typeof snd.PlayState == "undefined") return false;

	if(snd.PlayState == 2 || snd.PlayState == 3) return true;
	return false;
}

function EMBED_stop(id)
{
	if(EMBED_isplay(id) == false) return true;

	var snd = cssGet(id, "obj");
	if(snd == "") return false;
	if(typeof snd.stop == "undefined") return false;

	snd.stop();
	return true;
}

function EMBED_play(id)
{
	if(getCookie("sound") == "off") return ;

	var snd = cssGet(id, "obj");
	if(snd == "") return false;
	if(typeof snd.stop == "undefined") return false;

	snd.play();
	return true;
}

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 setCookie(name, value, expiredays)
{
	var todayDate = new Date();
	todayDate.setDate( todayDate.getDate() + expiredays );
	document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}

// 그누보드 따라하기
function kForm(frm) {
	this.frm = frm;
	this.check = function() {
		var omsg = "값을 입력 하셔야 합니다.";
		var f = this.frm;
		for(var i=0; i<f.elements.length; i++) {
			switch(f.elements[i].type) {
			case "select-one":
				omsg = "값을 선택 하셔야 합니다.";
			case "text":
			case "password":
			case "file":
			case "textarea":
				if(f.elements[i].getAttribute("rname") != null && f.elements[i].value.trim() == '') {
					var msg = f.elements[i].getAttribute("rname"); if(msg == null) msg = f.elements[i].name;
					msg = "[" + msg + "] " + omsg;
					alert(msg);
					try { f.elements[i].focus(); } catch(e) { ; }
					return false;
				}
			break;
			}
		}
		return true;
	}
}

var _resizeImage_objs = [];
function _resizeImage_traceNode(node, width)
{
	for(var i=0; i<node.length; i++) {
		if( (node[i].tagName == 'IMG') || (node[i].tagName == 'img')) {
			_resizeImage_objs.push([node[i],node[i].width]);
			if(node[i].width > width) node[i].style.width = "" + width + "px";
		}
		_resizeImage_traceNode(node[i].childNodes, width);
	}
}

function resizeImage(idName, width)
{
	var _onload = window.onload;

	window.onload = function() {
		if(_onload) _onload();
		var o = document.getElementById(idName);
		if(o) {
			_resizeImage_traceNode(o.childNodes, width, o);
		}
	}
}

function resize4AnswerImage(which, max) {
	  var elem = document.getElementById(which);
	  if (elem == undefined || elem == null) return false;
	  if (max == undefined) max = 600;
	  if (elem.width > elem.height) {
	    if (elem.width > max) elem.width = max;
	  } else {
	    if (elem.height > max) elem.height = max;
	  }
	}


function resizeImageOb(idName)
{
	var _onload = window.onload;

	window.onload = function() {
		if(_onload) _onload();
		var o = document.getElementById(idName);
		if(o) {
			_resizeImage_traceNode(o.childNodes, 1);

			var width = o.offsetWidth;
			for(var i=_resizeImage_objs.length; i>0; i--) {
				var objs = _resizeImage_objs.pop();
				var img = objs[0];
				var img_width = objs[1];
				if(img_width > width) img.style.width = "" + width + "px";
				else img.style.width = "" + img_width + "px";
			}

			var im = document.getElementById("p_image");
			if(im) {
				im.style.position = '';
				im.style.left = '';
				im.style.top = '';
			}
		}
	}
}

function _resizeFont(o, fSize, fFamily)
{
        try {
        o.style.fontSize = fSize;
        o.style.fontFamily = fFamily;
        o.style.lineHeight = "1.5";
        } catch(e) { ; }

        for(var i=0; i<o.childNodes.length; i++) {
                switch(o.childNodes[i].tagName) {
                case "DIV":
                case "P":
                case "FONT":
                case "SPAN":
                        _resizeFont(o.childNodes[i], fSize, fFamily); break;
                }
        }
}

function resizeFont(id, fSize, fFamily)
{
        var o = document.getElementById(id);
        if(o) _resizeFont(o, fSize, fFamily)
}

function isIE()
{
	if(navigator.appVersion.indexOf("MSIE")!=-1) return true;
	return false;
}

function getIEversion()
{
	var version;
	if(navigator.appVersion.indexOf("MSIE")!=-1) {
		var temp=navigator.appVersion.split("MSIE");
		version = parseFloat(temp[1]);
	}
	else version=999.0;
	return version;
}

function popup(url, name, width, height, resizeable, scrollbars)
{
	var p = "";

	if(typeof width == 'undefined') {
		name = "_blank";
	}

	if(typeof width != 'undefined') {
		p += " width="+width;
	} else p += " width=10";

	if(typeof height != 'undefined') {
		p += " height="+width;
	} else p += " height=10";

	if(typeof resizeable != 'undefined') {
		p += " resizeable=" + resizeable;
	} else p += " resizeable=1";

	if(typeof scrollbars != 'undefined') {
		p += " scrollbars=" + scrollbars;
	} else p += " scrollbars=1";

	return window.open(url, name, p);
}

function onlynumber()
{
	try {
        var e = event.keyCode;
        window.status = e;
        if (e>=48 && e<=57) return;
        if (e>=96 && e<=105) return;
        if (e>=37 && e<=40) return;
        if (e==8 || e==9 || e==13 || e==46) return;
        event.returnValue = false;
	} catch(e) { ; }
}

function input_maxnumber(o, max_n)
{
	if(o.value == '') return ;
	var n = parseInt(o.value);
	if(isNaN(n)) {
		alert("숫자를 입력하세요.");
	}
	if(n > max_n) {
		o.value = max_n;
	}
}

function toggleHTMLLayer(idname)
{
	var o = document.getElementById(idname);
	if(o) o.style.display = o.style.display == 'none' ? '' : 'none';
}

function myflash_v(argSRC, argWIDTH, argHEIGHT, argBGCOLOR, argVar, argID, argWMODE)
{
    var strTEMP;

    if(typeof argBGCOLOR == "undefined" || argBGCOLOR == "") {
        argBGCOLOR = "#ffffff";
    }
    if(typeof argVar == "undefined") {
        argVar = '';
    }
    if(typeof argWMODE == "undefined" || argWMODE == "") {
        argWMODE = 'transparent';
    }

    strTEMP ='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" ' ;
        if(argID)
        strTEMP = strTEMP + ' ID="' + argID + '" ' ;//ID
        strTEMP = strTEMP + ' width="'+ argWIDTH + '" height="' + argHEIGHT + '">';
        strTEMP = strTEMP + '<param name="allowScriptAccess" value="always" />';
        strTEMP = strTEMP + '<param name="allowFullscreen" value="true" />';
        strTEMP = strTEMP + '<param name="movie" value="' + argSRC + '">';
        strTEMP = strTEMP + '<param name="FlashVars" value="'+argVar+'" />';
        strTEMP = strTEMP + '<param name="bgcolor" value="'+argBGCOLOR+'" />';
        strTEMP = strTEMP + '<param name="quality" value="high" />';
        strTEMP = strTEMP + '<param name="memu" value="false" />';

        if(argWMODE)
        strTEMP = strTEMP + '<param name="wmode" value="' + argWMODE + '">';
        else
        strTEMP = strTEMP + '<param name="wmode" value="transparent">';
        strTEMP = strTEMP + '<embed src="'+ argSRC +'" FlashVars="'+ argVar +'" ';

        if (argWMODE)
        strTEMP = strTEMP + 'wmode="'+ argWMODE +'" ';
        else
        strTEMP = strTEMP + 'wmode="transparent" ';
        strTEMP = strTEMP + 'menu="false" quality="high" bgcolor="'+ argBGCOLOR +'" width="'+ argWIDTH +'" height="'+ argHEIGHT +'" name="'+ argID +'" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
        strTEMP = strTEMP + '</object>';
        //document.write(strTEMP);
    return strTEMP;
}

function myflash(argSRC, argWIDTH, argHEIGHT, argBGCOLOR, argVar, argID, argWMODE)
{
    document.write( myflash_v(argSRC, argWIDTH, argHEIGHT, argBGCOLOR, argVar, argID, argWMODE) );
}

function myflash_ssl(argSRC, argWIDTH, argHEIGHT, argBGCOLOR, argVar, argID, argWMODE)
{
    document.write( myflash_v(argSRC, argWIDTH, argHEIGHT, argBGCOLOR, argVar, argID, argWMODE).replace(/http:\/\//, "https://") );
}

function getFlashObject(name)
{
	if (window.document[name]) {
		return window.document[name];
	}
	if (navigator.appName.indexOf("Microsoft Internet")==-1) {
		if (document.embeds && document.embeds[name]) {
			return document.embeds[name];
		}
	} else {
		return document.getElementById(name);
	}
}

function getFlashSize(name)
{
	var movieObj = getFlashObject(name);
	var width = parseInt( movieObj.TGetProperty("/", 8) );
	var height= parseInt( movieObj.TGetProperty("/", 9) );
	return { width: width, height: height };
}





var o_board_mouseover = null;
var o_board_mouseover_color = '';
function board_mouseover(a)
{
    var node = a;
    board_mouseout();
    for(var node=a; node; node=node.parentNode) {
        if(node.tagName == "TR") break;
    }
    o_board_mouseover = node;
    o_board_mouseover_color = node.style.backgroundColor;
    node.style.backgroundColor = "#F6F6F6";
    //node.style.backgroundColor = "#FF0000";
	node.className = "board_link_none";
}

function board_mouseout()
{
    if(o_board_mouseover == null) return ;
    o_board_mouseover.style.backgroundColor = o_board_mouseover_color;
    o_board_mouseover = null;
    o_board_mouseover_color = "";
}
