﻿if (!window.Ntreevsoft) alert('\nNtreev JS Message :\n\nntreev.common.js 가 먼저 삽입되어있어야 합니다.');

/*  Ntreev Global Script [ CSS Selector / 2009-06-25 ]
*   Copyright (c) 2009 Ntreevsoft, ALL right reserved.
*   Script by Su-hyung, park
*/

// DOM Selector
(function(){
	window['$']=function(q,c){return new u.fn(q,c)};var u=window.pRix={},w=document,x=w.createElement('div'),z=2,A=1,B={},C={},D={},E=!!x.compareDocumentPosition,F=!!x.querySelectorAll,G=(function(){x.innerHTML='<p class="s">test</p>';x.firstChild.className='a b';return x.getElementsByClassName?!!x.getElementsByClassName('b').length:false})(),H={'for':'htmlFor','class':'className','readonly':'readOnly','tabindex':'tabIndex','accesskey':'accessKey','maxlength':'maxLength'},I={'n':' ','1n':' ','odd':'2n+1','even':'2n'},J=x.innerText?'innerText':'textContent',K=/[^,]+(?:[[(][^\])]+[^[(]+){0,}[\])][^,]*|[^,]+/g,L=/(?:\W *)?(?:(?:[^[(>+~ ]+)?(?:(?:[[(][^)\]]*[^([]*[\])][^[( ]*){1,})|[^>+~ ]+)/g,M=/^ *([>+~])|\[ *(\w+) *(?:(.?=) *(.+['" ]|[^\]]*[^[]*))?\]|:([\w-]+)(?:\((.+['" ]|[^)]*[^(]*)\))?|#([\w\-]+)|\.([\w\-]+)|(\w+)/g,N=/^(\w*)(?:#([\w\-]+))?$/,O=/(\d+)(n)?(?:.*([\-+])+.*(\d+))?/,P=/^(?:FI|LE|BU|IN|SE|OP|TE)/,Q=/checkbox|radio/,R=/^:root/,S=function(s){return(s||'').replace(/^[\'\"]|[\'\"]$/g,'').replace(/([\W^\s])/g,'\\$1')},T=function(s){return String(s||'').replace(/\/[^)]+\)|\([^)]+\)\/$/g,'')},U=pRix.toArray=function(r){for(var a=[],i=0,m=r.length;i<m;a[i]=r[i++]);return a};if(z==2&&!(z=0)&&w.addEventListener)(function(){var m=['DOMSubtreeModified','DOMNodeInserted','DOMNodeRemoved','DOMAttrModified'],i=m.length;while(i--)(function(hr){x.addEventListener(hr,function(){z=1;w.addEventListener(hr,function(){D={}},false)},false)})(m[i]);x.id='__evtTest__'})();u.fn=function(q,c){var a=q.constructor;this.length=0;Array.prototype.push.apply(this,a==String?V.find(q,c):a==Array?q:q[0]?U(q):q?[q]:[])};u.extend=function(h){for(var m in h)u.fn.prototype[m]=(function(a){return function(){for(var i=0,m=this.length;i<m;i++)a.apply(this[i],U(arguments));return this}})(h[m])};u.fn.prototype={prev:function(q){return new u.fn(V.combinator(V.parser(q||'*',1,this[0])[0],this,'previousSibling'))},next:function(q){return new u.fn(V.combinator(V.parser(q||'*',1,this[0])[0],this,'nextSibling'))},parent:function(q){return new u.fn(V.combinator(V.parser(q||'*',1,this[0])[0],this,'parentNode'))},each:function(a){for(var i=0,e;e=this[i++];a.call(e));return this},search:function(q){var a=V.parser(q||'*',1)[0];for(var i=0,b=[],e;e=this[i++];){if(!V.match(a,e))b.push(e)}return new u.fn(b)},find:function(q){var a=this,b=V.parser(q,1),c=0;while(q=b[c++]){a=V.filter(q,a=V.combinator(q,a))}return new u.fn(a)},filter:function(a){for(var i=0,b=[],e;e=this[i++];){if(a(e))b.push(e)}return new u.fn(b)},switching:function(a){for(var i=0;this[i];i++){this[i].style.display='none'}this[a].style.display='block';return this}};var V=u.Selector={find:function(a,b){var c=[],d=0,y=0,q,f,e,b=b||w;if(z&&D[a])return D[a];if(F)try{return D[a]=U(b.querySelectorAll(a))}catch(e){};if(N.test(a)&&b==w)return this.quick(N.exec(a));while(p=K.exec(a)){var g=this.parser(p,0,b),h=0,j=g[0].length,q=g[1];var k=R.test(p)?[b.documentElement]:this.filter(q,U(q[2]&&!q[1]&&b==w?[w.getElementById(q[2])]:q[3]&&!q[1]&&G?b.getElementsByClassName(T(q[3][0])):b.getElementsByTagName(q[1]||'*')));while((q=g[0][--j])&&k.length){for(var i=0,y=0,l=[],m=f||k,f=[];e=m[i];i++){while(e=l[0]=e.parentNode){if(V.match(q,e))continue;f[y]=e;k[y++]=k[i];break}}k.length=y}while((q=g[2][h++])&&k.length){k=this.filter(q,k=this.combinator(q,k))}c=c.concat(k);d++}return D[a]=(d==1?c:this.order(c))},isHTML:function(a){return a?(a.ownerDocument||a)==w:true},combinator:function(q,r,a){var b=!q[1]&&q[3]&&G,c=[],i=0,y=0,n,d,e,t=q[1]||'*',m=A++,f=!!(q[1]||q[2]||q[4]||q[3]);if(q[0]=='>')while(e=r[i++]){for(n=0,d=e.childNodes;e=d[n++];){if(q[1]?e.nodeName==t:e.nodeName==1)c[y++]=e}}else if(q[0]=='+')while(e=r[i++]){while((e=e.nextSibling)&&e.nodeType!=1);if(e&&(!q[1]||e.nodeName==t))c[y++]=e}else if(q[0]=='~')while(e=r[i++]){while((e=e.nextSibling)&&e.cse!=m){if((q[1]?t==e.nodeName:e.nodeType==1)&&(e.cse=m))c[y++]=e}}else if(a)while(e=r[i++]){while(e=e[a]){if(!this.match(q,e)){c[y++]=e;break}}c=this.cleanUp(c)}else if(b)while(d=r[i++]){for(n=0,d=d.getElementsByClassName(T(q[3][0]));(e=d[n++])&&e.cse!=A;e.cse=A)c[y++]=e}else while(d=r[i++]){for(n=0,d=d.getElementsByTagName(t);(e=d[n++])&&e.cse!=A;e.cse=A)if(f||e.nodeType==1)c[y++]=e}return c},filter:function(q,r){var i,y,e,c,t,n,s,a,v,o,m,b='href';if(q[2])for(i=0,y=0;e=r[i++];)if(e.id==q[2])r=[e];if(q[3])for(n=0;c=q[3][n++];r.length=y){for(i=0,y=0;e=r[i++];){if((t=e.className)&&c.test(t))r[y++]=e}}if(q[4])for(var n=0,c;c=q[4][n++];r.length=y){for(var i=0,y=0,v;e=r[i++];){v=c[1]?e[c[1]]:c[0]==b?e.getAttribute(c[0],2):e.getAttribute(c[0]);if(v?!c[2]||(c[3]?!c[2].test(v):c[2].test(v)):c[3])r[y++]=e}}if(q[5])for(n=0;m=q[5][n++];V.pseudo[m[0]](r,m[1]));return r},quick:function(q,e){return q[2]?(e=w.getElementById(q[2]))&&(!q[1]||q[1].toUpperCase()==e.nodeName)?[e]:[]:U(w.getElementsByTagName(q[1]))},match:function(q,e){var a,m,b;if(q[1]&&q[1]!=e.nodeName)return true;if(q[2]&&q[2]!=e.id)return true;if(q[3])for(a=0;m=q[3][a++];)if(!(b=e.className)||!m.test(b))return true;if(q[4])for(a=0;m=q[4][a++];)if(!((b=m[1]?e[m[1]]:m[0]=='href'?e.getAttribute(m[0],2):e.getAttribute(m[0]))?!m[2]||(m[3]?!m[2].test(b):m[2].test(b)):m[3]))return true;if(q[5])for(a=0;m=q[5][a++];)if(!V.pseudo[m[0]]([e],m[1]))return true;return false},operator:function(n,o,v){return[n,H[n],o?RegExp(o=='~='?'(?:^| )'+v+'(?: |$)':o=='|='?'(?:^|-)'+v+'(?:-|$)':o=='^='?'^'+v:o=='$='?v+'$':o=='*='?v:'^'+v+'$'):null,o=='!=']},parser:function(q,a,b){if(B[q])return B[q];for(var s,c,d,e=[];c=L.exec(q);e.push(d)){if(C[c])d=C[c];else{d=[];while(s=M.exec(c)){if(s[1])d[0]=s[1];if(s[9])d[1]=this.isHTML(b)?s[9].toUpperCase():s[9];if(s[7])d[2]=s[7];if(s[8])(d[3]||(d[3]=[])).push(RegExp('(?:^| )'+S(s[8])+'(?: |$)'));if(s[2])(d[4]||(d[4]=[])).push(this.operator(s[2],s[3],S(s[4])));if(s[5])(d[5]||(d[5]=[])).push([s[5],S(s[6])])}d[6]=d[5]?0:d[2]?1:d[1]&&(d[3]||d[4])?2:d[1]?w.getElementsByTagName(d[1]).length:0;C[c]=d}}var i=0,p=0,f=9999;while((s=e[i++])&&!s[0]){if(f>=(s[6]||f+1)){p=i-1;f=s[6]}}return a?e:(B[q]=[e.splice(0,p),e.splice(0,1)[0],e])},cleanUp:function(r){for(var i=0,y=0,m=A++,e;e=r[i++];)if(e.cse!=m)e.cse=m,r[y++]=e;r.length=y;return r},order:function(r){return this.cleanUp(r).sort(E?function(a,b){return 3-(a.compareDocumentPosition(b)&6)}:function(a,b){return a.sourceIndex-b.sourceIndex})}};V.pseudo={};V.addPseudo=function(obj){var W='';for(var m in obj){if(m.indexOf('nth')!=-1)W='var n = expNth.exec(nthMap[n]||n); n = n ? [n[1], n[2] ? Number(n[3]+n[4]) || n[1] : 0] : null;';eval('this.pseudo["'+m+'"] = function(r,n) {'+W+' for(var i=0,y=0,m=A++,e,f,c,w,t;e=f=t=r[i++];) {'+obj[m]+'r[y++] = e;}r.length=y;return !!y;}')}};var X='var tag=e.nodeName.toUpperCase();';var Y='if (!n||(!n[1]?c==n[0]:(c-n[1])%n[0]==0&&c>=0))';V.addPseudo({'visibled' : 'if (e.style.display != "none" || pRix.Util.getStyle(e, "display") != "none")','enabled':'if (!e.disabled && expForm.test(e.nodeName) && e.type!="hidden")','disabled':'if (e.disabled)','checked':'if (e.checked) ','unchecked':'if (!e.checked && exps.ui.test(e.type))','empty':'if (!e.hasChildNodes() && !e.innerHTML)','contains':'if ((e[content]).indexOf(n)!=-1)','first-child':'while ( (f=f.previousSibling) && f.nodeType!=1); if (!f)','last-child':'while ( (f=f.nextSibling) && f.nodeType!=1); if (!f)','nth-child':'if (n && (f=e.parentNode) && f.cse!=m && (f.cse=m)) { for (var w=1,s=0,f=f.childNodes,x; x=f[s]; s++) if (x.nodeType==1) x.idx = w++; } c=e.idx;'+Y,'first-of-type':X+'while ((f=f.previousSibling) && f.nodeName!=tag); if (!f)','last-of-type':X+'while ((f=f.nextSibling) && f.nodeName!=tag); if (!f)','nth-of-type':'if (n && (f=e.parentNode) && f.cse!=m && (f.cse=m)) { for (var w=1,t=e.nodeName,s=0, f=f.childNodes, x; x=f[s]; s++) if (x.nodeName==t) x.idx = w++; } c=e.idx;'+Y,'only-child':'while ((f=f.nextSibling) && f.nodeType!=1); while (!f && (t=t.previousSibling) && t.nodeType!=1); if (!f&&!t)','only-of-type':'for (var tag=e.nodeName.toUpperCase(), w=0, f=e.parentNode.firstChild; f; f=p.nextSibling) { if (f.nodeName==tag && w++) break; } if (w==1)','nth':'if (!n||(!n[1]?i==n[0]:(i-n[1])%n[0]==0&&i>=0))'});V.pseudo.first=function(r){r.length=1};V.pseudo.last=function(r){r.reverse(),r.length=1};V.pseudo.odd=function(r,n){this.nth(r,'2n+1')};V.pseudo.even=function(r,n){this.nth(r,'2n')};V.pseudo.has=function(r,n){var q=V.parser(n,1)[0],t=q[1]||'*';for(var i=0,y=0,e;e=r[i++];){if(V.filter(q,e.getElementsByTagName(t))[0])r[y++]=e}r.length=y};V.pseudo.not=function(r,n){var q=V.parser(n,1)[0],i=0,y=0,e;while(e=r[i++]){if(V.match(q,e))r[y++]=e}r.length=y};x=null;
})();

// ad Event handler for Selector
(function() {
	var EventHandlers = 'click,dblclick,focus,blur,select,change,submit,mouseover,mouseout,mousedown,mouseup,keydown,keyup,keypress'.split(',');
	for (var i=0, en; en = EventHandlers[i++];) {
		eval('pRix.extend({ '+en+' : function(fn) { var temp = (function(el, f) { return function(){f.apply(el, pRix.toArray(arguments))} })(this, fn); Ns.Event.add(this, "'+en+'", temp); }})');
	};
})();

// add Camelizer
// 문자열을 단어간 첫번째 알파벳을 대문자로 표시하는 Camel 표현식으로 변환
String.prototype.toCamelize = function()
{
	var snc = this.toLowerCase().split('-');
	for (var i=1; snc[i]; i++) {
		snc[i] = snc[i].substr(0, 1).toUpperCase() + snc[i].substr(1);
	}
	return snc.join('');
};

// add CSS Utility for Selector
pRix.Util =
{
	hasClass : function(obj, cn)
	{
		return RegExp('(?:^| )'+cn+'(?: |$)').test(obj.className);
	},

	getStyle : function(obj, sn)
	{
		var snc = sn.toCamelize();
		return obj.style[snc] ? obj.style[snc]	// Inline Style
			: obj.currentStyle ? obj.currentStyle[snc]	// for MSIE
			: document.defaultView.getComputedStyle(obj, null).getPropertyValue(sn) || '';	// for Standard browser
	}
};

// add UI Utility for Selector
pRix.extend(
{
	show : function()
	{
		this.style.display = this._display || 'block';
	},

	hide : function()
	{
		this._display = pRix.Util.getStyle(this, 'display');
		this.style.display = 'none';
	},

	toggle : function()
	{
		this.style.display = pRix.Util.getStyle(this, 'display') == 'none' ? 'block' : 'none';
	},

	imgOver : function()
	{
		this.src = this.src.replace('_off.','_on.');
	},

	imgOut : function()
	{
		this.src = this.src.replace('_on.','_off.');
	},

	classOver : function()
	{
		this.className = this.className.replace('_off.','_on.');
	},

	classOut : function()
	{
		this.className = this.className.replace('_on.','_off.');
	},

	addClass : function(cn)
	{
		this.className += (pRix.Util.hasClass(this , cn) ? '' : ' '+cn);
	},

	setClass : function(cn)
	{
		this.className = cn;
	},

	removeClass : function(cn)
	{
		this.className = this.className.replace(RegExp('(?:^| )'+cn+'(?: |$)'), ' ');
	},

	setStyle : function(styles)
	{
		var prop = styles.split(';');
		for (var i=0, sn; sn = prop[i]; i++) {
			sn = sn.split(':');
			this.style[sn[0].toCamelize()] = sn[1] || '';;
		}
	},

	html : function(html)
	{
		this.innerHTML = html;
	},

	appendHTML : function(html)
	{
		this.innerHTML += html;
	},

	prependHTML : function(html)
	{
		this.innerHTML = this.innerHTML+html;
	},

	append : function(node)
	{
		this.appendChild(node);
	},

	prepend : function(node)
	{
		if (this.firstChild) {
			this.insertBefore(node, this.firstChild);
		} else {
			this.appendChild(node);
		}
	}
});


// Create Input Selector
var $F = Ns.Form = function(name)
{
	var fs = document.forms, i=0, f, put;
	if ( typeof name == 'object' ) put = name;
	if ( !put ) while ( (f = fs[i++]) && !(put = f[name]) );
	if ( put && !put.val ) {
		for ( var m in $F.methods ) put[m] = $F.methods[m];
	}

	return put;
};

// name에 해당하는 input의 다음 input 으로 focus 이동 ( dir값이 유효할시 이전의 input 으로 focus 이동 )
$F.find = function(name, dir) {
    var all = document.getElementsByTagName('*');
    var obj = $F(name);

    // get Start input
    for (var i = 0, el; el = all[i++]; ) {
        if (el == obj) break;
    }

    // find Next input
    while (el = all[dir ? i-- : i++]) {
        if (/|NPUT|SELECT|TEXTAREA|BUTTON/.test(el.nodeName)) try {
            return el.focus();
        } catch (e) { };
    }
};

$F.serialize =  function()
{
	var str = [], i = 0, f;
	if (arguments.length) {
		while (f = arguments[i++]) str.push($F(f).serialize());
	} else {
		while (f = document.forms[0][i++]) str.push($F(f).serialize());
	}
	return str.join('&');
};

$F.methods =
{
	// SELECT : 선택된 Option이 가지고있는 txt값
	txt : function()
	{
		return this.nodeName == 'SELECT' ? this.options[this.selectedIndex].text : '';
	},

	// SELECT : Option추가 ( 배열형태의 인자 : [옵션txt, 옵션Value], [옵션txt, 옵션Value], [옵션txt, 옵션Value] )
	addOptions : function()
	{
		for (var i=0, arg; arg = arguments[i++];) {
			try {
				this.add(arg, this.options.length);
			} catch (e) {
				this.add(arg, this.options[this.options.length]);
			}
		}
	},

	// SELECT : option에 지정된 txt값을 기준으로 selectedIndex 설정
	setIndex : function()
	{
		// txt 값 기반의  indexer
	},

	// ALL : input형식에 상관없이 유효한 value값을 trim 처리후 반환
	val : function(txt)
	{
		if (txt == undefined) {
			if (this.length) {
				for (var i=0, vals=[]; this[i]; i++) {
					if (this[i].checked || this[i].selected) vals.push(this[i].value);
				}
				return vals.join(',');
			}
		} else {
			this.value = txt;
		}
		return this.value.trim();
	},

	bytes : function()
	{
		return this.val().getSize();
	},

	// ALL : 다음위치에 존재하는 input 요소로 focus 이동
	next : function()
	{
		var next = $F.find(this);
		return next ? next.focus() : null;
	},

	// ALL : 이전위치에 존재하는 input 요소로 focus 이동
	prev : function()
	{
		var prev = $F.find(this, 1);
		return prev ? prev.focus() : null;
	},

	// ALL : 해당 요소의 name값을 기준으로 직렬화된 텍스트 반환
	serialize : function()
	{
		var str = (this.name||this.id) + '=' + escape(this.value);
		return str;
	},

	// ALL : value값의 크기 검사
	isRange : function(min, max)
	{
		var size = this.bytes();
		return size < min || size > max ? false : true;
	}
};