var UI={};
Object.extend=function(a, b){
  for (var property in b) a[property] = b[property];
  return a;
};
UI.$=function(s) { return document.getElementById(s) };
UI.trim=function(s) {return s.replace(/(^\s*)|(\s*$)/g, "") };
UI.toogle=function(id) { UI.$(id).style.display=(UI.getStyle(UI.$(id),'display')=='none') ? 'block':'none' };
UI.getEl=function(e){var E=UI.getE(e);return E.target || E.srcElement}
UI.getE=function(e){return e || window.event}
UI.random=function(min, max){ return Math.floor(Math.random() * (max - min + 1) + min) };
UI.addEvent=function(object, type, listener) {	
	if(object.addEventListener) {if(type=='mousewheel')type='DOMMouseScroll'; object.addEventListener(type, listener, false)}
	else { object.attachEvent("on"+type, listener); }
};
UI.delEvent=function(object, type, listener){
	if (object.removeEventListener) {if(type=='mousewheel')type='DOMMouseScroll'; object.removeEventListener(type, listener, false)}
	else object.detachEvent('on'+type, listener);
};
UI.stopEvent=function(event) {
	var e=event || window.event;
	if(e.preventDefault) {e.preventDefault(); e.stopPropagation(); }
	else {e.returnValue = false; e.cancelBubble = true;}
};
UI.getEventWheel=function(e){
	var delta=0;
	if(e.wheelDelta) delta=e.wheelDelta/120;
	else if(e.detail) delta=-e.detail/3;
	return delta;
};

UI.getBrowser=function(){
	var ua=navigator.userAgent.toLowerCase();
	var opera=/opera/.test(ua)
	UI._browser={
		ie:!opera && /msie/.test(ua),
		ie_ver: parseFloat(((ua.split('; '))[1].split(' '))[1]),
		opera:opera,
		ff:/firefox/.test(ua),
		gecko:/gecko/.test(ua)		
	};
	return UI._browser;
};
UI.resizeIframe=function(iframe_id) {
	var h = (self.innerHeight) ? document.documentElement.offsetHeight : document.body.scrollHeight;
	try{parent.document.getElementById(iframe_id).style.height = h+"px";}catch(e){}
};

//이전버전
UI.rollOver=function(s) {
	var img=(typeof(s)=="string") ? img=UI.$(s):s;
	img.onmouseover=function(){
		var src=img.src;
		if(src.indexOf("_over.")>-1) return;  
		img.src=src.substring(0,src.lastIndexOf("."))+"_over."+src.substring(src.lastIndexOf(".")+1);
	};
	img.onmouseout=function(){
		var src=img.src;
		if(src.indexOf("_over.")==-1) return;
		img.src=src.replace("_over.",".");
	};
};
UI.popUp=function(url,name,w,h,scroll,resize,status,center){
	if(!scroll) scroll=0;
	if(!resize) resize=0;
	if(!status) status=1;
	if(center)	
	{
		var x = (screen.width - w) / 2;
		var y = (screen.height - h) / 2;
		center = ",top="+y+",left="+x;
	}
	return window.open(url,name,"width="+w+",height="+h+",status="+status+",resizable="+resize+",scrollbars="+scroll+center);
};
UI.setCookie=function(name, value, expires, path, domain, secure){
	if(expires)//day로 설정
	{
		var d=new Date(); d.setDate(d.getDate()+expires);
		expires = d.toGMTString();
	}
	document.cookie = name + "=" + escape(value) +
	  ((expires) ? "; expires=" + expires : "") +
	  ((path) ? "; path=" + path : "") +
	  ((domain) ? "; domain=" + domain : "") +
	  ((secure) ? "; secure" : "");
};
UI.getCookie=function(name){
	name += "=";
	cookie = document.cookie + ";";
	start = cookie.indexOf(name);
	if (start != -1)
	{
		end = cookie.indexOf(";",start);
		return unescape(cookie.substring(start + name.length, end));
	}
	return "";
};

UI.getScroll=function () {
	if(document.all && typeof document.body.scrollTop != "undefined")
	{
		var cont=document.compatMode!="CSS1Compat"?document.body:document.documentElement;
		return {left:cont.scrollLeft, top:cont.scrollTop, width:cont.clientWidth, height:cont.clientHeight}
	}
	else 
		return {left:window.pageXOffset, top:window.pageYOffset, width:window.innerWidth, height:window.innerHeight}
};
UI.submit=function(f) { 
	var f=document.forms[f];
	if(f.onsubmit && !f.onsubmit()) return;
	f.submit();
};
UI.focus=function(n) { 
	var s=null;
	s = UI.$(n)||document.getElementsByName(n)[0];
	s.focus();
};
UI.$F=function(n) {
	var s=null;
	s = UI.$(n)||document.getElementsByName(n)[0];
	if(s.type=="checkbox")
	{
		var c=[];
		var r=document.getElementsByName(n);
		for(var i=0;i<r.length; i++) if(r[i].checked) c.push(r[i].value);
		return (c.length>0)?c:"";
	}
	else if(s.type=="radio")
	{
		var r=document.getElementsByName(n);
		for(var i=0;i<r.length; i++) if(r[i].checked) return r[i].value;
		return "";
	}
	return s.value;
};
UI.length=function(str,len,tail){
	if(!tail) tail="";
	var l=0, c=0, l2=0, u="", s="";
	if(len>0) l2=len;	
	for(var i=0;u=str.charCodeAt(i);i++)
	{
		if (u>127) l+=2;
		else l++;
		if(l2) {
			s+=str.charAt(i); 
			if(l>=l2)
			{
				if(l>l2) s=s.slice(0,-1);
				return s+tail;
			}
		}		
	}
	return l2 ? s:l;
};



UI.toolTip=function(event, options) {

	var e=event || window.event;
	var el= e.target || e.srcElement;

	el.options={
		className:'UItoolTip',
		mousemove:UI.toolTip.mousemove
	};
	Object.extend(el.options, options);

	if(!el.UItoolTip) 
	{
		el.stitle = el.alt || el.title || el.stitle;
		el.title = el.alt = "";
		if(!el.stitle) return;
		
		var d = document.createElement("DIV");		
		d.className = el.options.className;
		d.style.position="absolute";	
		UI.$('JESToolTip').appendChild(d);
		
		el.UItoolTip=d;
		el.UItoolTip.innerHTML=el.stitle;
	}
	var scroll = UI.getScroll();
	var x = (e.clientX+scroll.left+10) + "px";
	var y = (e.clientY+scroll.top+10) + "px";
	el.UItoolTip.style.left = x;
	el.UItoolTip.style.top =  y;
	el.UItoolTip.style.visibility="visible";

	UI.addEvent(el,'mouseout',UI.toolTip.mouseout);
	if(el.options.mousemove) UI.addEvent(document, "mousemove", el.options.mousemove);
}

document.write('<div id="JESToolTip"></div>');
UI.toolTip.seq = 1;
UI.toolTip.mousemove=function(event){
	var e=event || window.event; var el= e.target || e.srcElement;
	var scroll = UI.getScroll();
	el.UItoolTip.style.left=(e.clientX+scroll.left)+"px";
	el.UItoolTip.style.top=(e.clientY+scroll.top+20)+"px";
};
UI.toolTip.mouseout=function(event){
	var e=event || window.event; var el= e.target || e.srcElement;
	if(!el.UItoolTip) return;
	el.UItoolTip.style.visibility="hidden";
	if(el.options.mousemove) UI.delEvent(document, "mousemove",  el.options.mousemove);	
};


UI.html2str=function(s,m){
	var s1=["&amp;","&#39;","&quot;","&lt;","&gt;"];
	var s2=["&","'","\"","<",">"];
	var s3=[];
	if(m) {s3=s1;s1=s2;s2=s3;}
	for(var i in s1) s=s.replace(new RegExp(s1[i],"g"), s2[i]);
	return s;
};
UI.filter=function(str){
	str=str.replace(/&#39;/g,"'"); // '
	str=str.replace(/&quot;/g,"\""); // "
	str=str.replace(/&amp;/g,"&"); // "
	return str;
};
UI.copyText=function(text,msg){
	if(window.clipboardData&&window.clipboardData.setData("Text",text)) 
	{if(msg)alert(msg); return true;}
	return false;
};
UI.getStyle=function(el, style) {
	//prototype.js 
	var value = el.style[style];
	if(!value)
	{
		if(document.defaultView && document.defaultView.getComputedStyle) 
		{
			var css = document.defaultView.getComputedStyle(el, null);
			value = css ? css[style] : null;
		} 
		else if (el.currentStyle) value = el.currentStyle[style];
	}
	return value == 'auto' ? null : value;
};
UI.random=function(min, max){ return Math.floor(Math.random() * (max - min + 1) + min) };

//---
UI.yScrolling=function(cid, millisec1,millisec2, speed, height)
{
	this.cid= cid;
	this.millisec1 = millisec1;	//처음시작 텀
	this.millisec2 = millisec2; //실행 텀
	this.speed = speed;			//한번에 이동할 px
	this.height = height;
	
	this.h =0;
	this.div = UI.$(this.cid);
	this.htmltxt = this.div.innerHTML;
	this.div.innerHTML = this.htmltxt+this.htmltxt;
	this.div.isover=false;
	this.div.onmouseover=function(){ this.isover=true; }
	this.div.onmouseout=function(){	this.isover=false; }
	var self =this;
	window.setTimeout(function(){self.play()}, this.millisec1);
}
UI.yScrolling.prototype={
	play : function(){
		var self =this;
		if(!this.div.isover)
		{	
			this.div.scrollTop += this.speed;
			if(this.div.scrollTop >= this.div.scrollHeight/2) 
			{
				this.div.scrollTop=0;
				//this.h=0;
			}
			else(this.height)
			{
				this.h += this.speed;
				if(this.h>=this.height)
				{
					if(this.h>this.height)
					{
						this.div.scrollTop -= this.h % this.height;
						//window.status = this.div.scrollTop +" : "+this.h % this.height;
					}
					this.h=0;
					window.setTimeout(function(){self.play()}, this.millisec1);					
					return;
				}
			}
		}		
		window.setTimeout(function(){self.play()}, this.millisec2);
	}
};
UI.xScrolling=function(cid, millisec1,millisec2, speed)
{
	this.cid= cid;
	this.millisec1 = millisec1;	//처음시작 텀
	this.millisec2 = millisec2; //실행 텀
	this.speed = speed;			//한번에 이동할 px

	this.div = UI.$(this.cid);
	this.htmltxt = this.div.innerHTML;
	this.div.innerHTML = '<div style="white-space:nowrap">'+this.htmltxt+this.htmltxt+'<\/div>';
	this.div.isover=false;
	this.div.onmouseover=function(){ this.isover=true; }
	this.div.onmouseout=function(){	this.isover=false; }
	var self =this;
	window.setTimeout(function(){self.play()}, this.millisec1);
}
UI.xScrolling.prototype={
	play : function(){
		if(!this.div.isover)
		{	
			this.div.scrollLeft += this.speed;		
			if(this.div.scrollLeft > this.div.scrollWidth/2) this.div.scrollLeft =0;//원위치			
		}
		var self =this;
		window.setTimeout(function(){self.play()}, this.millisec2);
	}
};
//param : 공통아이디,전체갯수,텀,처음활성화
UI.Rolling=function(cid,count,interval,n) {
	this.cid = cid;
	this.count = count;	
	this.n = (n)?n:"1";
	this.onchange = null;

	for(var k=1; k<=this.count; k++) UI.$(this.cid+"_"+k).style.display="none";
	UI.$(this.cid+"_"+this.n).style.display="block";

	this.div = UI.$(this.cid);//전체div
	this.div.onmouseover=function(){this.isover=true; }
	this.div.onmouseout=function() {this.isover=false;}
	this.btn_next = UI.$("btn_"+this.cid+"_next");
	this.btn_prev = UI.$("btn_"+this.cid+"_prev");

	var self=this;
	if(this.btn_next) this.btn_next.onclick=function(){self.next() }
	if(this.btn_prev) this.btn_prev.onclick=function(){self.prev() }
	if(interval>0) setInterval(function(){self.play()}, interval);
}
UI.Rolling.prototype = {
	play : function() {
		if(this.div.isover) return;
		this.next();
	},
	change :function(){
		if(this.onchange) this.onchange();
	},
	prev :function(){
		UI.$(this.cid+"_"+this.n).style.display="none";
		this.n=(this.n==1)?this.count:--this.n;
		UI.$(this.cid+"_"+this.n).style.display="block";
		this.change();
	},
	next :function(){
		UI.$(this.cid+"_"+this.n).style.display="none";
		this.n=(this.n==this.count)? 1:++this.n;
		UI.$(this.cid+"_"+this.n).style.display="block";
		this.change();
	},
	random : function() {
		var rn=Math.round((this.count-1)*Math.random());
		for(var i=0;i<rn;i++) this.next();
	}
};
UI.Tab=function(cid,count,start,click){
	this.cid=cid;
	this.count=count;
	this.n=start;	
	//mouseover 이벤트 추가
	var img=null;
	for(var i=1; i<=count; i++)
	{
		var img=UI.$("img_"+cid+"_"+i);
		img.n=i;
		var self=this;
		if(!click) img.onmouseover=function(){ self.on(this.n) }
		else img.onclick=function(){ self.on(this.n) }
	}
	this.on(this.n);//초기화
}
UI.Tab.prototype = {
	on : function(n){
		for(var k=1; k<=this.count; k++)
		{
			UI.$("div_"+this.cid+"_"+k).style.display="none";
			UI.$("img_"+this.cid+"_"+k).src=UI.$("img_"+this.cid+"_"+k).src.replace("_on.","_off.");
		}
		UI.$("div_"+this.cid+"_"+n).style.display="block";
		UI.$("img_"+this.cid+"_"+n).src=UI.$("img_"+this.cid+"_"+n).src.replace("_off.","_on.");
	}
};
//2007-10-29
UI.Tab2=function(cid,count,options){
	this.options={
		snum:1,					//시작번호
		event_type:'mouseover', //mouseover,click
		menu_type:'img',		//img,css
		class_over:'_on',		//over 시 css
		onChange:null			//변경될때 이벤트
	}
	Object.extend(this.options, options);
	this.cid=cid;
	this.count=count;
	var menu;
	for(var i=1; i<=count; i++)
	{
		menu=UI.$("menu_"+cid+"_"+i);
		menu.n=i;
		menu.css=menu.className;
		var self=this;
		menu['on'+this.options.event_type]=function(){ self.on(this.n) }
	}
	this.on(this.options.snum);
}
UI.Tab2.prototype = {
	on : function(n){
		this.n=n;
		var type=this.options.menu_type;
		for(var k=1; k<=this.count; k++)
		{
			UI.$("div_"+this.cid+"_"+k).style.display="none";
			if(type=='img')	UI.$("menu_"+this.cid+"_"+k).src=UI.$("menu_"+this.cid+"_"+k).src.replace("_on.","_off.");
			else UI.$("menu_"+this.cid+"_"+k).className=UI.$("menu_"+this.cid+"_"+k).css;
			
		}
		UI.$("div_"+this.cid+"_"+n).style.display="block";
		if(type=='img')	UI.$("menu_"+this.cid+"_"+n).src=UI.$("menu_"+this.cid+"_"+n).src.replace("_off.","_on.");
		else UI.$("menu_"+this.cid+"_"+n).className= UI.$("menu_"+this.cid+"_"+n).css + this.options.class_over;
		if(this.options.onChange) this.options.onChange.call(this);
	}
};
//----------------------------------------------
//2007-07-24 추가
UI.Move=function(id) {
	this.id=id;
	this.div=UI.$(id);
	this.x= parseInt(UI.getStyle(this.div,'left'))||0;
	this.y= parseInt(UI.getStyle(this.div,'top'))||0;
};
UI.Move.prototype={
	slide : function(pos) {
		this.pos = pos;
		this.pos_n = 0;
		this.speed=0.3;
		this.inteval = 20;
		this.setPos();
		this.playing =true;
		var self=this;
		this.tid=setInterval(function(){self.play()}, this.inteval);
	},
	play : function() {
		this.x += (this.x2-this.x)*this.speed;		
		this.y += (this.y2-this.y)*this.speed;
		this.set(this.x,this.y);
		if(Math.round(this.x)==this.x2 && Math.round(this.y)==this.y2)
		{
			this.x=Math.round(this.x);
			this.y=Math.round(this.y);
			this.set(this.x,this.y);

			if(this.pos_n>=this.pos.length)	{this.playing=false; clearInterval(this.tid)}
			else this.setPos();
		}
	},
	setPos:function(){
		var arr=this.pos[this.pos_n].split(",");
		this.x2 = arr[0];
		this.y2 = arr[1];
		this.pos_n++;
	},
	set:function(x,y){
		this.div.style.left = x+"px";
		this.div.style.top = y+"px";
	}
};

//----------------------------------------------
UI.Drag=function(drag, param){

	var el=UI.$(drag);
	el.isdrag=true;
	el.width=0;el.height=0;
	el.area_width=0;el.area_height=0;
	el.handle=null;
	el.move_mode=0; //1:horizontal 2,vertical
	el.limit_top=-1,el.limit_bottom=-1,el.limit_left=-1,el.limit_right=-1;
	
	UI.Drag.setXY(el);

	if(typeof param=="object")
	{
		if(param.handle)
		{
			el.handle=UI.$(param.handle);
			el.isdrag=false;
			el.handle.isdrag=true;
			el.handle.target=el;
		}
		if(param.container)
		{
			UI.$(param.container).style.position="relative";
			el.width=parseInt(UI.getStyle(el,"width")) || el.offsetWidth;
			el.height=parseInt(UI.getStyle(el,"height")) || el.offsetHeight;
			el.area_width=parseInt(UI.getStyle(UI.$(param.container),"width")) || UI.$(param.container).offsetWidth;
			el.area_height=parseInt(UI.getStyle(UI.$(param.container),"height")) || UI.$(param.container).offsetHeight;	
		}

		if(param.move_mode) el.move_mode=param.move_mode;
		if(param.limit_top>-1) el.limit_top=param.limit_top;
		if(param.limit_bottom>-1) el.limit_bottom=param.limit_bottom;
		if(param.limit_left>-1) el.limit_left=param.limit_left;
		if(param.limit_right>-1) el.limit_right=param.limit_right;

		if(typeof param.onStart=="function") el.onStart=param.onStart;
		if(typeof param.onStop=="function") el.onStop=param.onStop;
		if(typeof param.onDrag=="function") el.onDrag=param.onDrag;
	}
	this.obj=el;
};
UI.Drag.setXY=function(el){
	var pos=UI.getPosition(el);
	el.x=parseInt(UI.getStyle(el,"left"));
	el.y=parseInt(UI.getStyle(el,"top"));
	if(isNaN(el.x)) el.x=pos.x;
	if(isNaN(el.y)) el.y=pos.y;
};
UI.Drag.start=function(event){
	var e=event || window.event; var el=e.target || e.srcElement;
	if(!el.isdrag) return;
	if(el.target) el=el.target;
	
	_uiDrag.obj=el;
	UI.Drag.setXY(el);

	_uiDrag.gx = e.clientX;
	_uiDrag.gy = e.clientY;

	if(el.onStart) el.onStart.call(el);
	if(el.onStop) _uiDrag.onStop=el.onStop;
	if(el.onDrag) _uiDrag.onDrag=el.onDrag;
};
UI.Drag.move=function(event){
	var e=event || window.event; var el=e.target || e.srcElement;

	var drag=_uiDrag.obj;
	if(drag)
	{
		var top =drag.y + e.clientY - _uiDrag.gy;
		var left=drag.x + e.clientX - _uiDrag.gx;

		if(drag.area_width && drag.area_height)
		{
			if(top<=0) top=0;
			else if(top >= drag.area_height-drag.height) top=drag.area_height-drag.height; 
			if(left<=0) left=0;
			else if(left >= drag.area_width-drag.width) left=drag.area_width-drag.width; 
		}
		if(drag.limit_top>-1 && top<drag.limit_top) top=drag.limit_top;
		if(drag.limit_bottom>-1 && top>drag.limit_bottom) top=drag.limit_bottom;
		if(drag.limit_left>-1 && left<drag.limit_left) left=drag.limit_left;
		if(drag.limit_right>-1 && left>drag.limit_right) left=drag.limit_right;
		
		if(!drag.move_mode || drag.move_mode==2) drag.style.top = top+"px";
		if(!drag.move_mode || drag.move_mode==1) drag.style.left = left+"px";	
	}
	if(_uiDrag.onDrag) _uiDrag.onDrag.call(drag);
};
UI.Drag.end=function(event){
	if(_uiDrag.onStop) _uiDrag.onStop.call(_uiDrag.obj);
	_uiDrag.obj=null;	
	_uiDrag.onStop=null;
	_uiDrag.onDrag=null;
};

//전역변수
var _uiDrag={};
UI.addEvent(document, "mousedown", UI.Drag.start );
UI.addEvent(document, "mousemove", UI.Drag.move );
UI.addEvent(document, "mouseup", UI.Drag.end );



//2007-08-02
UI.setClip=function(s,m){
	try{
		var swf=null;
		if(navigator.appName.indexOf("Microsoft")!=-1) swf=window['UIclipSwf'];
		else swf=document['UIclipSwf'];
		swf.setClip(s);alert(m);
	}catch(e){
		alert("해당 브라우저에서는 지원하지 않습니다.");
	}
}
UI.setClip.url='/static/clip.swf';
UI.setClip.print=function()
{
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="1" height="1" id="UIclipSwf"><param name="allowScriptAccess" value="always" /><param name="movie" value="'+UI.setClip.url+'" /><embed src="'+UI.setClip.url+'" width="1" height="1" name="UIclipSwf" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>');
}


UI.setOpacity=function(el,value){
	el.style.filter="alpha(opacity="+value+")";
	el.style.opacity=(value/100);
	el.style.MozOpacity=(value/100);
	el.style.KhtmlOpacity=(value/100);
};

UI.getPosition=function(el)
{
	var left=0,top=0;
	while(el)
	{
		left+=el.offsetLeft || 0;
		top+=el.offsetTop || 0;
		el=el.offsetParent;
	}
	return {'x': left, 'y': top};
}


UI.indexOf=function(arr,s){
	for(var i=0;i<arr.length; i++) if(arr[i]==s) return i;
	return -1;
};

/* */
UI.Ajax = function(url, params, method, oncomplete , onerror) {
	this.url = url;
	this.params = params;
	this.oncomplete = oncomplete;
	this.onerror = onerror;
	this.method = method;
	this.send();
};
UI.Ajax.prototype={

	getHttpRequest:function(){
		var req=null;
		try { req = new XMLHttpRequest(); }
		catch(e)
		{
			try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
			catch(e)
			{
				try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
				catch(e) { }
			}
		}
		return req;
	},
	send:function(){
		this.req = this.getHttpRequest();
		var httpMethod = this.method ? this.method: 'GET';
		if (httpMethod != 'GET' && httpMethod != 'POST') httpMethod = 'GET';
		var httpParams = (this.params == null || this.params == '') ? null: this.params;
		var httpUrl = this.url;
		if (httpMethod == 'GET' && httpMethod != null) httpUrl = httpUrl+"?"+httpParams;
		this.req.open(httpMethod, httpUrl, true);
		this.req.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=UTF-8');
		var self = this;
		this.req.onreadystatechange = function() {
			self.onStateChange.call(self);
		}
		this.req.send(httpMethod == 'POST' ? httpParams: null);
	},
	onStateChange: function() {
		if(this.req.readyState==4)
		{
			if(this.req.status=="200") this.oncomplete(this.req);
			else
			{
				if(this.onerror) this.onerror(this.req);
				else alert("서버에러입니다! 잠시후에 다시 시도하세요!");
			}				
		}
	}
};

UI.StringBuffer=function(){this.buffer=new Array()}
UI.StringBuffer.prototype={append:function(s){this.buffer.push(s)},toString:function(){return this.buffer.join("")}};

