// convert to utf-8 encoding.
function toUTF8(szInput) {
	var wch, x, uch="", szRet="";
	for (x=0; x<szInput.length; x++) {
		wch=szInput.charCodeAt(x);
		if (!(wch & 0xFF80)) {
			szRet += "%" + wch.toString(16);
		} else if (!(wch & 0xF000)) {
			uch = "%" + (wch>>6 | 0xC0).toString(16) + "%" + (wch & 0x3F | 0x80).toString(16);
			szRet += uch;
		} else {
			uch = "%" + (wch >> 12 | 0xE0).toString(16) + "%" + (((wch >> 6) & 0x3F) | 0x80).toString(16) + "%" + (wch & 0x3F | 0x80).toString(16);
			szRet += uch;
		}
	}
	return(szRet);
}

// trim string.
function trimString(str) {
    return str.replace(/(^\s*)|(\s*$)/gi, "");
}

// only number(48~57,96~105) and arrow(37~40)/delete(46)/backspace(8)/tab(9) allow
function numberOnlyAllowFunc() {
	var check = false;
	var ekey = event.keyCode;
	if ( (ekey>=48 && ekey<=57) || (ekey>=96 && ekey<=105) || (ekey>=37 && ekey<=40) || ekey==46 || ekey==8 || ekey==9 ) check = true;
	if ( !check ) event.returnValue = false;
}

//only number(48~57,96~105),dot(190) and arrow(37~40)/delete(46)/backspace(8)/tab(9) allow
function numberDotOnlyAllowFunc() {
	var check = false;
	var ekey = event.keyCode;
	if ( (ekey>=48 && ekey<=57) || (ekey>=96 && ekey<=105) || (ekey>=37 && ekey<=40)
			|| ekey==46 || ekey==8 || ekey==9 || ekey==189 || ekey==190 ) check = true;
	if ( !check ) event.returnValue = false;
}

// open popup window
function windowOpen(url, popupname, width, height){
	var w = width;
	var h = height;  
	var x = (screen.availWidth - w) / 2;
	var y = (screen.availHeight - h) / 2;
	return window.open(url, popupname===undefined?"":popupname, "toolbar=0, status=0, scrollbars=yes, location=0, menubar=0, width="+w+", height="+h+", left="+x+", top="+y);
}

// open resizable popup window
function windowOpenResizable(url, popupname, width, height){
	var w = width;
	var h = height;  
	var x = (screen.availWidth - w) / 2;
	var y = (screen.availHeight - h) / 2;
	return window.open(url, popupname===undefined?"":popupname, "resizable=yes, toolbar=0, status=0, scrollbars=yes, location=0, menubar=0, width="+w+", height="+h+", left="+x+", top="+y);
}

// resize frame itself
function resizeFrameItself(fDoc, fWin, fHeight) {
	var flexibleHeight = 0;
	if ( !isNaN(parseInt(fHeight)) ) flexibleHeight = parseInt(fHeight);
	var newHeight = fDoc.body.scrollHeight + flexibleHeight;
	fWin.frameElement.height = newHeight;
}

// resize frame external
function resizeFrameExternal(fObj, fHeight) {
	var flexibleHeight = 0;
	if ( !isNaN(parseInt(fHeight)) ) flexibleHeight = parseInt(fHeight);
	var newHeight = fObj.contentWindow.document.body.scrollHeight + flexibleHeight;
	fObj.contentWindow.frameElement.height = newHeight;
}
