
// String Extensions
String.prototype.Trim = function() { // trim class version
	var st, end;

	for(st=0; st<this.length; ++st) 
		if(this.charAt(st)!=" ") break;
	for(end=this.length-1; end>=0; --end)
		if(this.charAt(end)!=" ") break;
	end = end + 1
	
	if(end > st)
		return this.substring(st, end);
	else
		return "";
}

String.prototype.Left = function(i) {
	if(i<0) i=0;
	if(i<this.length) return this.substr(0,i);
	else return this;
}

String.prototype.Right = function(i) {
	if(i<0) i=0;
	if(i<this.length && i>=0) return this.substr(this.length-i,i);
	else return this;
}
//alert(("1234567890").right(3));




// ÇÑ±Û°ü·Ã ÇÔ¼öÀÓ´Ù
String.prototype.hLen = function(i) {
	var hlen = 0;
	for(var i=0; i<this.length; ++i) {
		++hlen;
		if(this.charCodeAt(i)>255) ++hlen;
	}
	return hlen;
}

String.prototype.hWrap = function(leng) {
	var i0, tmpch, tmpasc, hlen, hwrap;
	for(var i=i0=hlen=0,hwrap=""; i<this.length; ++i) {
		tmpch = this.charAt(i);
		tmpasc = this.charCodeAt(i);

		++hlen;
		if(tmpasc>255) ++hlen;

		if(tmpch=="\n") {
			hwrap += this.substr(i0, i-i0+1);
			i0 = i + 1;
			hlen = 0;
		}

		if(hlen>leng) {
			hwrap += this.substr(i0, i-i0) + "\n";
			i0 = i;
			hlen = 1;
			if(this.charCodeAt(i)>255) ++hlen;
		}
	}

	hwrap += this.substr(i0, i-i0);
	if(this.substr(hwrap, hwrap.length-1, 1)=="\n") hwrap = hwrap.substr(hwrap, 0, this.length-1);

	return hwrap;
}




// Number Extensions
Number.prototype.NumberFormat = function() {
	var result="", strnum="";

	strnum = ""+this;
	while(strnum.length) {
		result = "," + strnum.Right(3) + result;
		strnum = strnum.Left(strnum.length-3);
	}

	result = result.substr(1);
	return result;
}

Number.prototype.FillZero = function(len) {
	var ret="";
	var value = this;

	for(var i=0; i<len; ++i) {
		ret = ( value % 10 ) +""+ ret;
		value = Math.floor(value/10);
	}
	return(ret);
}
//alert((3000).numberformat());




// Date Extensions
Date.prototype.ToDbDate = function() {
	var year, mon, day;
	year = this.getYear();
	mon = ""+ (this.getMonth()+1);
	day = ""+ this.getDate();
	if(mon.length==1) mon = "0"+mon;
	if(day.length==1) day = "0"+day;
	return year +"-"+ mon +"-"+ day;
}

Date.prototype.ToDbTime = function() {
	var h, m, s;
	h = ""+ this.getDate();
	m = ""+ this.getMinutes();
	s = ""+ this.getSeconds();

	if(h.length==1) h = "0"+mon;
	if(m.length==1) m = "0"+mon;
	if(s.length==1) s = "0"+day;
	return h +":"+ m +":"+ s;
}

Date.prototype.ToDbDateTime = function() {
	return this.ToDbDate() +" "+ this.ToDbTime();
}

Date.prototype.GetWeekName = function() {
	//var arrweek = new Array("ÀÏ", "¿ù", "È­", "¼ö", "¸ñ", "±Ý", "Åä");
	var arrweek = ["ÀÏ", "¿ù", "È­", "¼ö", "¸ñ", "±Ý", "Åä"];
	return arrweek[this.getDay()]
}




// Window Extensions
window.GetAbsTop = function(obj) {
	return (obj.offsetParent==null)? 0 : obj.offsetTop+GetAbsTop(obj.offsetParent);
}
window.GetAbsTopById = function(str) {
	window.GetAbsTop(document.getElementById(str));
}

window.GetAbsLeft = function(obj) {
	return (obj.offsetParent==null)? 0 : obj.offsetLeft+GetAbsLeft(obj.offsetParent);
}
window.GetAbsLeftById = function(str) {
	window.GetAbsLeft(document.getElementById(str));
}




// iframe À©µµ¿ì Open/Close
var iWinNum = 0;

function iWin() {
	++iWinNum;

	document.writeln("<div id=LiWin"+ iWinNum +" style=position:absolute;visibility:hidden;z-index:10000><iframe id=WiWin"+ iWinNum +" name=WiWin"+ iWinNum +" src=about:blank frameborder=0 hspace=0 vspace=0 width=100 height=100 scrolling=no width=0 height=0></iframe></div>");

	// properties
	this.Win = document.getElementById("WiWin"+ iWinNum);
	this.Lay = document.getElementById("LiWin"+ iWinNum);
	this.iWinNum = iWinNum;

	// methos
	function _iOpen(url, left, top, wid, hei) {
		this.Lay.style.left = left;  this.Lay.style.top = top;
		this.Win.width = wid;  this.Win.height = hei;
		
		this.Win.src = url;
		//window.frames["WiWin"+ this.iWinNum].location.href = url;

		this.Lay.style.visibility = "visible";
		this.Lay.style.display = "inline";

	}
	function _iClose() {
		this.Lay.style.visibility = "hidden";
		this.Lay.style.display = "none";
	}
	function _iOpenClose(url, left, top, wid, hei) {
		if(!(this.Lay.style) || this.Lay.style==null || this.Lay.style.visibility=="hidden") this._iOpen(url, left, top, wid, hei);
		else this._iClose();
	}

	this._iOpen = _iOpen;
	this._iClose = _iClose;
	this.iOpen = _iOpen;
	this.iClose = _iClose;
	this.iOpenClose = _iOpenClose;
}
