
function Lib()
{
	this.printf=Lib_printf;
	this.isNO=Lib_isNO;
	this.isNO2=Lib_isNO2;
	this.isAmount=Lib_isAmount;
	this.isCode=Lib_isCode;
	this.isKorean=Lib_isKorean;
	this.isEmail=Lib_isEmail;
	this.isLength=Lib_isLength;
	this.isJumin=Lib_isJumin;
	this.newWin=Lib_newWin;
	this.newModal=Lib_newModal;
	this.getLength=Lib_getLength;
	this.viewTable=Lib_viewTable;
	this.passbySlt=Lib_passbySlt;
	this.listObject=Lib_listObject;
	this.getParam=Lib_getParam;
	this.getUrlSelf=Lib_getUrlSelf;
	this.popProcess=Lib_popProcess;
	this.useTabInTextarea=Lib_useTabInTextarea;
	this.getEnter=Lib_getEnter;
	this.numberFormat=Lib_numberFormat;
	this.cutAmount=Lib_cutAmount;
	this.viewCategory=Lib_viewCategory;
	this.setCookie=Lib_setCookie;
}

// print language //
function Lib_printf(lang)
{
	var args=this.printf.arguments;
	for(var i=0;i<args.length;i++)
	{
		if(typeof args[i+1]=='undefined') continue;
		lang=lang.replace('%s'+i,args[i+1]);
	}

	return lang;
}


//// Check Value - start ////

// Check Number //
function Lib_isNO(val)
{
	for(var i=0;i<val.length;i++)
	{
		var chr=val.substr(i,1);
		if(chr<'0'||chr>'9')
		{
			return false;
		}
	}
	return true;
}

// Check Number include Code //
function Lib_isNO2(val)
{
	for(var i=0;i<val.length;i++)
	{
		var chr=val.substr(i,1);
		if((chr<'0' || chr>'9') && chr!='-' && chr!='_')
		{
			return false;
		}
	}
	return true;
}

// Check Amount //
function Lib_isAmount(val)
{
	for(var i=0;i<val.length;i++)
	{
		var chr=val.substr(i,1);
		if((chr<'0' || chr>'9') && chr!='.')
		{
			return false;
		}
	}
	return true;
}

// Check Code //
function Lib_isCode(val)
{
	for(var i=0;i<val.length;i++)
	{
		var chr=val.substr(i,1);
		if((chr<'0' || chr>'9') && (chr<'a' || chr>'z') && (chr<'A' || chr>'Z') && chr!='-' && chr!='_' && chr!='.')
		{
			return false;
		}
	}
	return true;
}

// Check Korean //
function Lib_isKorean(val)
{
	var code=0;
	for(var i=0;i<val.length;i++)
	{
		var code=val.charCodeAt(i);
		var chr=val.substr(i,1).toUpperCase();
		code=parseInt(code);
		if((chr<'0' || chr>'9') && (chr<'A' || chr>'Z') && (code>255 || code<0))
		{
			return false;
		}
	}
	return true;
}

// Check Email //
function Lib_isEmail(val)
{
	if(val=='undefined') return false;
	for(var l=0;l<=(val.length-1);l++)
	{
		if(val.indexOf(' ')>=0)
		{
			return false;
		}
	}
	if(val.indexOf('/')!=-1 || val.indexOf(';')!=-1)
	{
		return false;
	}
	if(val.length!=0 && val.search(/(\S+)@(\S+)\.(\S+)/)==-1)
	{
		return false;
	}
	return true;
}

// Check Text Size //
function Lib_isLength(val)
{
	var t;
	var msglen;
	msglen=0;
	l=val.length;
	for(i=0;i<l;i++)
	{
		t=val.charAt(i);
		if(escape(t).length>4) msglen+=2;
		else msglen++;
	}
	return msglen;
}

// Check Jumin //
function Lib_isJumin(val1,val2)
{
	var chk=0
	var yy=val1.substring(0,2)
	var mm=val1.substring(2,4)
	var dd=val1.substring(4,6)
	var sex=val2.substring(0,1)
	if(val1.length!=6 || yy<25 || mm<1 || mm>12 || dd<1)
	{
		return false;
	}
	if((sex!=1 && sex!=2) || val2.length!=7)
	{
		return false;
	}
	for(var i=0;i<=5;i++)
	{
		chk=chk+((i%8+2)*parseInt(val1.substring(i,i+1)))
	}
	for(var i=6;i<=11;i++)
	{
		chk=chk+((i%8+2)*parseInt(val2.substring(i-6,i-5)))
	}
	chk=11-(chk%11)
	chk=chk%10
	if(chk!=val2.substring(6,7))
	{
		return false;
	}
	return true;
}

//// Check Value - end ////


//// Window Open - start ////

// New Windows in Center //
function Lib_newWin(url,name,wid,hei,option)
{
	var x=screen.width/2-wid/2;
	var y=screen.height/2-hei/2;

	var option_='left='+x+',top='+y+',width='+wid+',height='+hei+',scrollbars=1,resizable=1';
	if(option) option_+=','+option;

	newwindow=window.open(url,name,option_);
	newwindow.focus();
}

// New Modal Window //
function Lib_newModal(url,name,wid,hei,option)
{
	if(navigator.userAgent.toLowerCase()=='mozilla/4.0 (compatible; msie 6.0; windows nt 5.1; sv1; .net clr 2.0.50727)')
	{
		var x, y;
		x=(document.layers) ? loc.pageX : event.clientX;
		y=(document.layers) ? loc.pageY : event.clientY;

		var rand=Math.random()*4;

		option_='dialogLeft='+x+'px;dialogTop='+y+'px;dialogWidth='+wid+'px;dialogHeight='+hei+'px;scroll=auto;resizable=1;';
		if(option) option_+=option;

		window.showModalDialog(url+'?rand='+rand,name,option_);
	}
	else
	{
		this.newWin(url,name,wid,hei,option);
	}
}

//// Window Open - end ////

// Get Value Length //
function Lib_getLength(val)
{
	var t;
	var msglen;

	msglen=0;
	l=val.length;

	for(i=0;i<l;i++)
	{
		t=val.charAt(i);
		if(escape(t).length>4) msglen+=2;
		else msglen++;
	}
	
	return msglen; 
}

// View Tables //
function Lib_viewTable(divname,opt)
{
	if(document.getElementById(divname))
	{
		if(opt)
		{
			document.getElementById(divname).style.display=opt;
		}
		else
		{
			if(document.getElementById(divname).style.display=='none') document.getElementById(divname).style.display='';
			else document.getElementById(divname).style.display='none';
		}
	}
}

// Pass Selected //
function Lib_passbySlt(inputname)
{
	if(inputname.options[inputname.selectedIndex].value)
	{
		location=inputname.options[inputname.selectedIndex].value;
	}
}

// list object //
function Lib_listObject()
{
	for (i in document)
	{
		document.write(i+'='+document[i]+'<br>');
	}
}

// Get Parameters //
function Lib_getParam(name)
{
	for(i in document)
	{
		if(i == 'URL') var url=document[i];
	}

	var que = url.split('?');
	var par = que[1].split('&');

	for(i=0;i<par.length;i++)
	{
		var val=par[i].split('=');
		if(val[0]==name) var rlt=val[1];
	}
	if(rlt) return rlt;
	else return 0;
}

// upload process bar //
function Lib_popProcess()
{
	if(process.style)
	{
		var x, y;

		//x = (document.layers) ? loc.pageX : event.clientX;
		//y = (document.layers) ? loc.pageY : event.clientY;
		//process.style.pixelTop = y - 50 + document.body.scrollTop;
		//process.style.pixelLeft = x - 150 + document.body.scrollLeft;

		//process.style.pixelTop = 0;
		//process.style.pixelLeft = 0;
		//process.style.width = x;
		//process.style.height = y;

		process.style.display = 'inline';
	}
}

// Get Parameters In Frames //
function Lib_getUrlSelf()
{
	for(i in top.document)
	{
		//document.write(top.document[i]+'<br>');
		if(i=='URL')
		{
			var url=top.document[i];
			//document.write(url+'<br>');
		}
	}
	var que=url.split('/');

	var self=que[que.length-1];

	if(self) return self;
	else return 0;
}

// Lets use ltrim, rtrim, trim about all variable use //
//String.prototype.ltrim=new Function("return this.replace(/^\\s+/,'')");
//String.prototype.rtrim=new Function("return this.replace(/\\s+$/,'')");
//String.prototype.trim= new Function("return this.replace(/^\\s+|¦Æ|\\s+$/g,'')");

// use tab key at textarea box element //
function Lib_useTabInTextarea(el)
{
	if(event.keyCode==9)
	{
		(el.selection=document.selection.createRange()).text="\t";
		event.returnValue=false;
	}
}


// enter num //
function Lib_getEnter(str)
{
	var cnt=1;
	var pos=-1;

	while(pos=str.indexOf("\n",pos+1)>=0)
	{
		cnt++;
	}

	return cnt;
}

function Lib_numberFormat(num)
{
	var arr=num.split('.');
	num=arr[0];

	var len=num.length-1;
	var tmp='';
	var ori='';
	var rlt='';

	for(i=len;i>=0;i--)
	{

		tmp = num.substr(i,1);
		ori = tmp + ori;
		rlt = tmp + rlt;

		if(ori.length % 3 == 0 && i!=0) rlt = ',' + rlt;
	}

	if(arr[1]) rlt=rlt + '.' + arr[1];
	return rlt;
}

function Lib_cutAmount(val,cut)
{
	var arr=val.split('.');
	val=arr[0];

	var len=val.length-1;
	var num=len-cut.length+1;
	var rlt_='';
	var chr;

	for(i=len;i>=0;i--)
	{
		chr = val.substr(i,1);

		if(i > num)
		{
			rlt_ = '0' + rlt_;
		}
		else rlt_ = chr + rlt_;
	}

	if(arr[1]) rlt_=rlt_ + '.' + arr[1];
	return rlt_;
}

function Lib_viewCategory(divname,src_on,src_off)
{
	if(document.getElementById(divname))
	{
		if(document.getElementById(divname).style.display=='none')
		{
			document.getElementById('bt_'+divname).src=src_on;
			document.getElementById(divname).style.display='';
		}
		else
		{
			document.getElementById('bt_'+divname).src=src_off;
			document.getElementById(divname).style.display='none';
		}
	}
}

function Lib_setCookie(name,value,expire)
{
	if(expire)
	{
		var expires = new Date();
		expires.setTime(expires.getTime() + expire);
	}
	
	var secure;
	var domain;
	var path='/';

	document.cookie = name + '=' + escape (value) + ((expires == null) ? '' : ('; expires=' + expires.toGMTString())) + ((path == null) ? '' : ('; path=' + path)) + ((domain == null) ? '' : ('; domain=' + domain)) + ((secure == true) ? '; secure' : '');
}
