﻿/* ==========================================================

    UI script beta v0.11
    for Web Publisher
    
    본 스크립트는 개발자 및 웹 퍼블리셔들에게 있어 번거롭고
    불편했던 작업 및 표현에 있어 도움이 되고자 작업하였으며
    DOM 기반의 스크립트를 사용하되 코드를 최소화 하기위해
    지원폭이 넓은 innerHTML 등의 methods 를 병용하였습니다.
    
   =========================================================
    IE 5.5 / 6.0 / 7.0 / Firefox / Safari / Opera 
   ---------------------------------------------------------
    xhtml 1.0 Transitional / xhtml 1.0 strict / xhtml 1.1    
   ---------------------------------------------------------
    Publisher : su hyung, park [Park.]
    E-mail    : plognote@hotmail.com
    Support   : http://준비중
   --------------------------------------------------------- */


	var setting = new Object()
	
	setting.alert = 0     // alert()함수 Jacking 여부
	setting.confirm = 0 // confirm()함수 Jacking 여부
	setting.error = 0     // error()함수 Jacking 여부
	setting.skin =            // alert 및 innerpopup에 쓰일 skin html
		'<table style="width:100%;height:100%;"><tr><td>'+
		'<table border="0" cellpadding="0" cellspacing="0" style="margin:0 auto"><tr><td class="pop_image_tl"></td><td class="pop_image_tm"></td><td class="pop_image_tr"></td></tr>'+
		'<tr><td class="pop_image_ml"></td><td class="pop_desc"><!--msg--><br /><br /><!--btn--></td><td class="pop_image_mr"></td></tr>'+
		'<tr><td class="pop_image_bl"></td><td class="pop_image_bm"></td><td class="pop_image_br"></td></tr></table>'+
		'</tr></td></table>';
	setting.ok =              // alert 확인 버튼
		'<img src="/img/common/btn_ok.gif" alt="확인" onclick="<!--ok-->" class="btn" />'
	setting.cs =              // alert 취소 버튼
		'<img src="/img/common/btn_cs.gif" alt="취소" onclick="<!--cs-->" class="btn" />'



/* == Utility Function's ================================== */
// UI script를 시작함에 있어 코드를 단축시켜주는 Func입니다.


// Return to Element
function _(el,obj) {
	var element = obj ? obj : document
	if(/^#/.test(el)) return element.getElementsByName(el.replace('#',''));
	else if(/^@/.test(el)) return element.getElementsByTagName(el.replace('@',''));
	else if(typeof(el) == 'string') return element.getElementById(el)
	else if(typeof(el) == 'object') return el
	else return false;
}

// Create xmlhttpRequest
function xmlhttp() {
	if(window.XMLHttpRequest)
		_http = new XMLHttpRequest()
	else if(window.ActiveXObject)
		_http = new ActiveXObject("Microsoft.XMLHTTP")
	return _http
}

// Div create
function newDiv(_id,_co,_size,_zindex) {
	var _size = _size == 0 ? false : true;
	if (!_(_id)) {
		var _Div = document.createElement('div');
		_Div.setAttribute('id', _id);
		with(_Div.style) {
			display  = "none";
			position = "absolute";
			width = height = "100%";
			top = left = "0";
			backgroundColor = _co ? _co : "";
			zIndex = _zindex ? _zindex : 900;
		}
		document.body.appendChild(_Div)
		if(_size) {
			resizeElement(_id,'wrap')
			addEvent(window,'resize', function(){resizeElement(_id)})
		}
	}
	return ui(_id)
}

// Resize to target
function resizeElement(obj,tg) {
	_(obj).style.height = tg ? _(tg).scrollHeight + 'px' : document.body.scrollHeight + 'px';
	_(obj).style.width = tg ? _(tg).scrollWidth + 'px' : document.body.scrollWidth + 'px';
}

// Event add
function addEvent(obj,eventName,eventAct) {
	if(obj.addEventListener) obj.addEventListener(eventName, eval(eventAct), false);
	else if(obj.attachEvent) obj.attachEvent("on"+eventName, eval(eventAct));
}

// Object event chk
function eventChk(obj) {
	if (obj.target) var obj = obj.target; else if(obj.srcElement) var obj = obj.srcElement;
	return obj
}

// Element remove
function remove(obj) {
	_clear = _(obj)
	try {
		if(_clear.length > 1)
			for(var i=0;_clear[i];i++) _clear[i].parentNode.removeChild(_clear[i])
			if (_(obj).length > 1) remove(obj)
		else 
			_clear.parentNode.removeChild(_clear)
	} catch(e) {}
}

// Get element position
function objpos(obj) {
	var position = new Object;
	position.x = position.y = 0 ;
	if( obj ) {
		position.x = obj.offsetLeft;
		position.y = obj.offsetTop;
		if( obj.offsetParent ) {
			var parentpos = objpos(obj.offsetParent);
			position.x += parentpos.x;
			position.y += parentpos.y;
		}
	}
	return position;
}

// Get mouse position
document.onmousemove = function(e) {
	var evt = e ? e : window.event;
	var _Top = document.documentElement ? document.documentElement.scrollTop+"px" : document.body.scrollTop+"px";
	var _Left = document.documentElement ? document.documentElement.scrollLeft+"px" : document.body.scrollLeft+"px";
	mouse = {
		x : evt.clientX,
		y : evt.clientY + _Top
	}
}


/* == UI Function ========================================= */
// ui(obj) 를 사용하여 UI script를 시작합니다.
	
// UI Object return
function ui(obj) {
	
	// Element Array push
	if(arguments.length > 1) {
		var _obj = new Array
		for(var i=0;arguments[i];i++) _obj[i] = ui(arguments[i])
		return _obj
	}
	
	// Element check
	var _obj = _(obj); if(!_obj) return false;
	
	// object Array return
	if(_obj.length > 1) {
		var _array = new Array
		for(var i=0;_obj[i];i++) _array[i] = ui(_obj[i])
		return _array
	}
		
	// Default setting
	_obj.style.minWidth = "1px"
	
	// add methods start
	_obj.block = function() { this.style.display = "block"; return this; } 
	_obj.inline = function() { this.style.display = "inline"; return this; } 
	_obj.none = function() { this.style.display = "none"; return this; } 
	_obj.visible = function() { this.style.visibility = "visible"; return this; } 
	_obj.hidden = function() { this.style.visibility = "hidden"; return this; } 
	_obj.remove = function() { remove(this)	}
	_obj.get = function(el) { return _(el,this) }
	_obj.alpha = function(op,co) {
		if(co) this.style.background = co
		if(!op) op = 50
		this.style.filter = "alpha(opacity="+op+")"
		this.style.opacity = op / 100
		this.style.display = 'block'
		return this
	}
	_obj.fade = function(sp,ep,sd) {
		this.block()
		this.sp = sp ? sp : 0
		this.ep = ep ? ep : 0
		this.sd = sd ? sd : 2
		if(this.sp == this.ep)return false
		else if(this.sp < this.ep)this.sp = this.sp + this.sd > this.ep ? this.ep : this.sp + this.sd
		else if(this.sp > this.ep)this.sp = this.sp - this.sd < this.ep ? this.ep : this.sp - this.sd
		var s = this
		this.alpha(this.sp)
		if(this.sp == 0) this.style.display = 'none';
		if(this.sp != this.ep) 
			setTimeout(function(){s.fade(s.sp,s.ep,s.sd,1)}, 10);
		return this
	}
	_obj.stop = function() {
		this.ep_bak = !this.ep_bak ? this.ep : this.ep_bak;
		this.fade(this.sp,this.sp)
		return this
	}
	_obj.play = function() {
		if(this.ep_bak) this.fade(this.sp,this.ep_bak)
		return this
	}
	_obj.inAjax = function(url) {
		var Target = this
		inHtml = new xmlhttp()
		inHtml.open("GET", url)
		inHtml.onreadystatechange = function() {
		  if(inHtml.readyState == 4) Target.innerHTML = inHtml.responseText; 
		} 
		inHtml.send(null);
		return Target
	}
	_obj.moveTo = function(x,y,val) {
	}
	_obj.moveBy = function(x,y,val) {
	}
	// add methods end
	
	return _obj
}


/* == Default Function ==================================== */
// 윈도우의 기본 기능을 대체하는 Func입니다.

// Ajax popup
function popup(url) {
	newDiv('alphaDivision','#fff',1).alpha()
	var _popup = newDiv('popupDivision','','')
	_popup.inAjax(url)
	_popup.style.top = document.documentElement ? document.documentElement.scrollTop+"px" : document.body.scrollTop+"px";
	ui('popupDivision').block()
	document.onkeypress = function() { popupClose(); document.onkeypress = null; }
}
function popupClose() {
	ui('popupDivision').none()
	ui('alphaDivision').fade(50,0,10)
	setTimeout("ui('popupDivision').innerHTML = '';",300)
}

function msg(t,fn) {
	newDiv('alphaDivision','#fff',1).alpha()
	var _popup = newDiv('popupDivision','','')
	_popup.innerHTML = setting.skin.replace(/<!--msg-->/,t)
	_popup.innerHTML = _popup.innerHTML.replace(/<!--btn-->/,setting.ok.replace(/<!--ok-->/,fn ? fn : 'popupClose()'))
	ui('popupDivision').block()
	document.onkeyup = function() { popupClose(); document.onkeyup = null; }
}

function test() {
	alert('회원가입이 완료되었습니다')
}

