/* ------------------------------------------------------------------------------
[usage]
	var commonLib = JClass.Create();
	var targetObject = commonLib.GetEventTargetObj(event);

[MethodList]
	[ Object ] GetEventTargetObject(event)				// GetEventTargetObj 의 alias
	[ Object ] GetEventTargetObj(event)					// 현재 이벤트의 대상 개체를 리턴
	[ Object ] GetEventToElement(event)					// 현재 이벤트의 목표 개체를 리턴
	[ Object ] GetFirstChildNode(obj)					// 개체의 첫번째 자식 컨트롤 개체를 리턴
	[ Object ] GetNextNode(obj)							// 개체의 다음 컨트롤 개체를 리턴
	[ Object ] GetPrevNode(obj)							// 개체의 이전 컨트롤 개체를 리턴
	   [ int ] GetRealOffsetTop(obj)					// 주어진 개체의 실제 offsetTop 값을 리턴
	   [ int ] GetRealOffsetLeft(obj)					// 주어진 개체의 실제 offsetLeft 값을 리턴
	[ Object ] CreateDocumentStylesheet(doc,rel)		// 주어진 document 에 rel 경로의 스타일시트를 생성 
	[ String ] GetParameterFromQuery(queryString,arg)	// 쿼리스트링에서 arg의 값을 리턴

---------------------------------------------------------------------------------- */

var JClass =
{
	Create: function()
	{
		return function() {
			this._Constructor.apply(this, arguments);
		}
	}
}

var CommonLibary = JClass.Create();

CommonLibary.prototype = {

	_Constructor : function () { },
	
	GetEventTargetObject : function (event)
		{
			return this.GetEventTargetObj(event);
		},
		
	GetEventTargetObj : function (event)
		{
			var e = event || window.event;
			var tObj = e.target || e.srcElement;
	
			if (!tObj) return false;
	
			switch(tObj.nodeType)
			{
				case 3:
					tObj = tObj.parentNode;
					break;
				case 9:
					break;
			}
			return tObj? tObj : null;
		},

	GetEventToElement : function (event)
		{
			var e = event || window.event;
			var tObj = e.toElement || e.currentTarget;
	
			if (tObj && tObj.nodeType == 3)
				tObj = tObj.parentNode;
	
			return tObj? tObj : null;
		},

	GetFirstChildNode : function (obj)
		{
			if(!obj.firstChild) return false;
	
			var s = obj.firstChild;
	
			if(s.nodeType != 1)
				s = this.GetNextNode(s);
	
			return s;
		},

	GetNextNode : function (obj)
		{
			if(!obj.nextSibling) return false;
	
			if(obj.nextSibling.nodeType != 1)
				obj = obj.nextSibling.nextSibling;
			else
				obj = obj.nextSibling;
	
			return obj? obj : null;
		},

	GetPrevNode : function (obj)
		{
			if(!obj.previousSibling) return false;
	
			if(obj.previousSibling.nodeType != 1)
				obj = obj.previousSibling.previousSibling;
			else
				obj = obj.previousSibling;
	
			return obj;
		},

	GetRealOffsetTop : function (obj)
		{
			return obj ? obj.offsetTop + this.GetRealOffsetTop(obj.offsetParent) : 0;
		},

	GetRealOffsetLeft : function (obj)
		{
			return obj ? obj.offsetLeft + this.GetRealOffsetLeft(obj.offsetParent) : 0;
		},

	CreateDocumentStylesheet : function (doc,rel)
		{
			var ss = null;
			if(doc.createStyleSheet)		// for IE
			{
				ss = doc.createStyleSheet(rel);
				return ss;
			}
			else							// for FF
			{
				var arr = doc.getElementsByTagName("head");
				var arrCnt = arr.length;
	
				if(arrCnt == 0)
				{
					var h = doc.createElement("head");
					doc.documentElement.appendChild(h);
				}
				else
				{
					var h = arr[arr.length - 1];
				}
		
				var s = doc.createElement("style");
				s.type = "text/css";
				s.innerHTML = "@import url("+rel+");";
		
				h.appendChild(s);
		
				return s;
			}
		},

	GetParameterFromQuery : function (queryString,arg)
		{
			var regExp = new RegExp("[&?]" + arg + "=(.*?)(&|$)");
			if (arg) r = queryString.match(regExp);
	
			return r&&r[1]?r[1]:null;
		},
	
	WinOpen : function (a,url)
		{
			var jsonStatus = {
					"menubar" : "no",
					"toolbar" : "no",
					"location" : "no",
					"directories" : "no",
					"scrollbars" : "no",
					"status" : "no",
					"resizable" : "no",
					"copyhistory" : "no",
					"width" : "400px",
					"height" : "400px",
					"left" : "20px",
					"top" : "20px"
				}
			
			var status = "";
			var forLoop = 0;
			var str,iv;
			var URL = url;
			
			for(i in jsonStatus)
			{
				str = ',';
				if(forLoop == 0) str = '';
				
				iv = a[i]? a[i] : jsonStatus[i];
				
				status = status + str + i + '=' + iv;
				forLoop++;
			}
			var wName = "NewPopup" + Math.ceil(Math.random()*99);
			var w = window.open(URL,wName,status);
			return w;
		},
	WinOpenWithName : function (a,url,name)
		{
			var jsonStatus = {
					"menubar" : "no",
					"toolbar" : "no",
					"location" : "no",
					"directories" : "no",
					"scrollbars" : "no",
					"status" : "no",
					"resizable" : "no",
					"copyhistory" : "no",
					"width" : "400px",
					"height" : "400px",
					"left" : "20px",
					"top" : "20px"
				}
			
			var status = "";
			var forLoop = 0;
			var str,iv;
			var URL = url;
			
			for(i in jsonStatus)
			{
				str = ',';
				if(forLoop == 0) str = '';
				
				iv = a[i]? a[i] : jsonStatus[i];
				
				status = status + str + i + '=' + iv;
				forLoop++;
			}
			var wName = name;
			var w = window.open(URL,wName,status);
			return w;
		}

}

var CommonLib = new CommonLibary;

function drawSwf(filename, width, height){
	var str = "";
	str += "<div style=\"z-index:99;\">";
	str += "<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="+width+" height=" + height +">";
	str += "<param name='movie' value='" + filename + "'>";
	str += "<param name='quality' value=high>";
	str += "<PARAM NAME=\"WMODE\" VALUE=\"transparent\"> ";
	str += "<embed src='" + filename + "' quality=high pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width=" + width + " height=" + height + ">";
	str += "</embed> </object>";
	str += "</div>";

	document.write(str);

}

function debug(msg, withLineBreak){
	if($('debug') != undefined){
		if(withLineBreak != false)
			$('debug').innerHTML += "<BR />";

		$('debug').innerHTML += msg;
	}	
}

function debugClear(){
	if($('debug') != undefined){
		$('debug').innerHTML = "";
	}
}

function debugObject(obj){
	if(obj != undefined){
		debug("*******[Object properties]*******");
		for(prop in obj){
			debug(prop + " : " + obj[prop]);
		}
		debug("*******[End of object properties]*******");
	} else {
		debug("undefined");
	}
}