//version: 0.1
//date: 2008.02.14
//write: heo young nam


//function $(id)
//{
//	return document.getElementById(id);
//}

//Object
Object.extend = function(a, b)
{
	for (var property in b)
	{
		a[property] = b[property];
	}
	return a;
}

//String Object
Object.extend(String.prototype, {
	trim: function(){
		return this.replace(/^[\s\xA0]+/,"").replace(/^[\s\xA0]+$/,"");
	},

	trimStart: function(){
		return this.replace(/^\s+/,"");
	},

	trimEnd: function(){
		return this.replace(/\s+$/,"");
	},

	startSlice: function(length){
		length = length || 30;
		return this.length > length ? this.slice(0,length) + "..." : this;
	},

	endSlice: function(length){
		length = length || 30;
		return this.length > length ?  "..." + this.substring(this.length-length,this.length) : this;
	},

	searching: function(str){
		var reg = new RegExp(str,"ig");
		return match = this.match(reg);
	},

	del: function(str){
		var reg = new RegExp(str,"ig");
		return this.replace(reg,"")
	},

	copy: function(count){
		var result = "";
		for (var i=0; i<count; i++)
		{
			result += this;
		}
		return result;
	},

	stripTag: function(){
		return this.replace(/<\/?[^>]+>/gi,"");
	},

//	clear: function(){
//		this = "";
//		return this;
//	},

	clone: function()
	{
		var result = this;
		return result;
	}
});


//Number Object
Object.extend(Number.prototype, {
	radix: function(num)
	{
		return this.toString(num);
	},
	each: function(iterator)
	{
		for (var i=0; i<this; i++)
		{
			iterator(this);
		}
	}
});


//Array Object
Object.extend(Array.prototype, {
	each: function(iterator, index)
	{
		if (index === undefined)
			index = this.length;
		else
			index = this.length < index? this.length : index;

		for (var i=0; i<index; i++)
		{
			iterator(this[i],i,this);
		}
	},

	trueCheck: function()
	{
		var result = [];
		this.each(function(){
			if (arguments[0])
				result.push(arguments[0]);
		});
		return result;
	},

	falseCheck: function()
	{
		var result = [];
		this.each(function(){
			if (!arguments[0])
				result.push(arguments[0]);
		});
		return result;
	},

	selectArray: function(/*arguments*/)
	{
		var result = [];
		for (var i=0; i<arguments.length; i++)
		{
			result.push(arguments[i]);
		}
		return result;
	},

	del: function()
	{
		var array = arguments;
		var i = 0;
		var result = [];
		this.each(function(){
			if (arguments[0] != array[i])
				result.push(arguments[0]);
			else
				i++;
		});
		return result;
	},

	clear: function()
	{
		this.length = 0;
		return this;
	},

	insert: function(array, index)
	{
		var result = [];
		this.each(function(){
			if (arguments[1] == index)
				result.push(array);
			result.push(arguments[0]);
		});
		return result;
	},

	clone: function()
	{
		var result = this;
		return result;
	}
});

//js 1.6
if (Array.prototype.forEach)
	Array.prototype.each = Array.prototype.forEach

//object --> Array
function $A(object)
{
	var reuslt = [];
	for (var i=0; i<object.length; i++)
	{
		reuslt.push(object[i]);
	}
	return reuslt;
}


//Ajax Object
var AjaxRequest = {
	 create: function ()
	 {
		var obj;
		try
		{
			if (window.XMLHttpRequest)
				obj = new XMLHttpRequest();
			else
			{
				try
				{
					obj = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e)
				{
					try
					{
						obj = new ActiveXObject("Msxml2.XMLHTTP");
					}
					catch (err)
					{
						obj = null;
					}
				}
			}
		 }
		 catch(e)
		 {
			 obj = null;
		 }
		 return obj;
	 }
};

//Ajax Object Method
Object.extend(AjaxRequest, {
	setQueryString: function(val)
	{
		var queryString = "";
		if (val !== undefined && val.id)
		{
			var child = $A($(val.id).childNodes);

			child.each(function(element){
				if (element.nodeType == 1)
				{
					if (element.type == "text" || element.type == "textarea" || element.type == "file")
					{
						queryString += element.id + "=" + encodeURIComponent(element.value)+"&";
					}
				}
			});
		}

		if (val !== undefined && val.value)
			queryString += val.value;

		return queryString;
	},

	indicate: function(on)
	{
		if (this.indicator.id)
			$(this.indicator.id).style.display = on ? "" : "none";

		if (this.timer == null)
			this.timer = window.setTimeout("AjaxRequest.onOpen();",this.indicator.value * 1000);
	}
});

//Ajax Object Request
Object.extend(AjaxRequest, {
	init: function(url, method, callback, query, indicator, sync)
	{
		this.url = url.toLowerCase()
		this.method = method.toLowerCase();
		this.callback = eval(callback);
		this.query = query;
		this.indicator = indicator;
		this.timer = null;
		this.sync = sync == false ? false : true;

		this.AjaxObj = AjaxRequest.create();

		if (this.indicator !== undefined)
			this.indicate(true);
		else
			this.onOpen();
	},

	onOpen: function()
	{
		if (this.AjaxObj != null) 
		{
			this.AjaxObj.onreadystatechange = this.onComplete;
			this.AjaxObj.open(this.method, this.url, this.sync);

			if(this.method == "post")
				this.AjaxObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=euc-kr");

			this.onSend();
		} 
		else 
		{
			alert ("Microsoft XML Package¸¦ ¼³Ä¡ÇØ¾ß ÇÕ´Ï´Ù.");
			return;
		}
	},

	onSend: function()
	{
		if (this.method == "get"){
			this.AjaxObj.send(null);
		}
		else{
			this.AjaxObj.send(this.setQueryString(this.query));
		}

	},

	onComplete: function()
	{
		if (AjaxRequest.AjaxObj.readyState == 4)
		{
			if (AjaxRequest.indicator !== undefined)
			{
				AjaxRequest.indicate(false);
				clearTimeout(AjaxRequest.timer);
				AjaxRequest.timer = null;
			}
			AjaxRequest.onSuccess();
		}
		else
		{
			if (AjaxRequest.indicator !== undefined)
				AjaxRequest.indicate(true);
		}
	},

	onSuccess: function()
	{
		switch(this.AjaxObj.status) 
		{
			case 200 :	
				this.callback(this.AjaxObj.responseText, this.AjaxObj.responseXML);
				break;
			case 404 :
				alert("URLÀ» È®ÀÎ ÈÄ ´Ù½Ã ¿äÃ»ÇÏ½Ã±â ¹Ù¶ø´Ï´Ù.");
				break;
			case 90000 :
				alert("½Ã½ºÅÛÀÇ ÀÌ»óÀ¸·Î ÀÎÇÏ¿© »ç¿ë ÇÒ ¼ö ¾ø½À´Ï´Ù.<br>Àá½Ã ÈÄ ´Ù½Ã ÀÌ¿ëÇÏ¿© ÁÖ½Ã±â ¹Ù¶ø´Ï´Ù.");
				break;
			default:
				alert("¼­¹ö¿¡¼­ ¾Ë¼ö ¾ø´Â ¿À·ù°¡ ¹ß»ýÇß½À´Ï´Ù. \n¿¡·¯ÄÚµå : " + this.AjaxObj.status + " [" + this.AjaxObj.statusText + "]");
		}
	}
});


//Key_Code Object
var Key_Code = {}
Object.extend(Key_Code, {
	Key_F1: 112,
	Key_F2: 113,
	Key_F3: 114,
	Key_F4: 115,
	Key_F5: 116,
	Key_F6: 117,
	Key_F7: 118,
	Key_F8: 119,
	Key_F9: 120,
	Key_F10: 121,
	Key_F11: 122,
	Key_F12: 123,

	Key_0: 48,
	Key_1: 49,
	Key_2: 50,
	Key_3: 51,
	Key_4: 52,
	Key_5: 53,
	Key_6: 54,
	Key_7: 55,
	Key_8: 56,
	Key_9: 57,

	Key_A: 65,
	Key_B: 66,
	Key_C: 67,
	Key_D: 68,
	Key_E: 69,
	Key_F: 70,
	Key_G: 71,
	Key_H: 72,
	Key_I: 73,
	Key_J: 74,
	Key_K: 75,
	Key_L: 76,
	Key_M: 77,
	Key_N: 78,
	Key_O: 79,
	Key_P: 80,
	Key_Q: 81,
	Key_R: 82,
	Key_S: 83,
	Key_T: 84,
	Key_U: 85,
	Key_V: 86,
	Key_W: 87,
	Key_X: 88,
	Key_Y: 89,
	Key_Z: 90,

	Key_ESC: 27,
	Key_BACKSPACE: 8,
	Key_TAB: 9,
	Key_ENTER: 13,
	Key_SCROLLLOCK: 145,
	Key_CAPSLOCK: 20,
	Key_SHIFT: 16,
	Key_LCTRL: 17,
	Key_LALT: 18,
	Key_SPACE: 32, 
	Key_RALT: 21,
	Key_RCTRL: 25,

	Key_INSERT: 45,
	Key_HOME: 36,
	Key_PAGEUP: 33,
	Key_DELETE: 46,
	Key_END: 35,
	Key_PAGEDOWN: 34,	

	Key_UP:38,
	Key_LEFT:37,
	Key_DOWN:40,
	Key_RIGHT:39
});