/*
theOpenWin(Width,Height,winName,url) : È­¸éÀÇ °¡¿îµ¥¿¡ Ã¢ ¶ç¿ì±â
Nwindow_outer(url, l, t, w, h, t_get) : ÁÂÃø»ó´ÜÀÇ À§Ä¡¸¦ ¹Þ¾Æ ¶ç¿î´Ù
check_alphanumber(char)	: ¼ýÀÚ È¤Àº ¿µ¹®ÀÎÁö °Ë»ç
check_number(char)	: ¼ýÀÚÀÎÁö °Ë»ç
check_email(char)	: ÀÌ¸ÞÀÏ °Ë»ç
check_null_int(char)	: null ÀÌ¸é "0" À» ¸®ÅÏÇÔ
onlyNumber()		: ex) onKeypress="onlyNumber()"
onlyMoney()		: ex) onKeypress="onlyMoney()"
FormatNumber(str, ¼Ò¼ýÁ¡ÀÚ¸®)
	ex) ½Ç¼ö·Î ¹Ù²Ù±â => total = parseFloat(check_null_int(val));
go_url_from_select(str)	: select ¹Ú½º¸¦ º¯°æ½Ã ÇØ´ç value ¿¡ ÀÖ´Â ÁÖ¼Ò·Î ÀÌµ¿
get_val_radio(str)	: radio ¹öÆ°¿¡¼­ ¼±ÅÃµÈ °ÍÀÇ °ªÀ» °¡Á®¿Â´Ù
get_val_select(str)	: select ¹Ú½º¿¡¼­ ¼±ÅÃµÈ °ÍÀÇ °ªÀ» °¡Á®¿Â´Ù
checkbox_check(str, act): true, false ¸®ÅÏÇÔ
checkbox_tool(str, flag): flag:T or F ÀüÃ¼¼±ÅÃ, ÀüÃ¼ÇØÁ¦
toggle(field,flag): flag:T or F or R ÀüÃ¼¼±ÅÃ, ÀüÃ¼ÇØÁ¦, ¹ÝÀü
trim(val)		: ¾ÕµÚ °ø¹é ¾ø¾Ö±â
Replace(strOriginal, strFind, strChange)
check_go_next(str_src, num, str_next)	: ´ÙÀ½ input ¹Ú½º·ÎÀÇ ÀÌµ¿
opener_exist()	: return => true or false;
view_large_image(img_url, title) : Å«ÀÌ¹ÌÁö º¸±â img_url -> /img/xx.gif
check_image_file_format(file) : ÀÌ¹ÌÁö°¡ ¾Æ´Ï¸é, °æ°í º¸ÀÌ°í false ¸®ÅÏÇÑ´Ù.
ChkLen(str,max_len) : byte ´ÜÀ§Ã¼Å©
check_dates(str) : ¿Ã¹Ù¸¥ ³¯Â¥ÀÎÁö Ã¼Å© str:input ¹Ú½º
close_fn()
roundTable_fn	: Å×ÀÌºí ¿Ü°û ºÎµå·´°Ô
*/

function theOpenWin(openWidth,openHeight,winName,url) {
	var openWidth, openHeight, winName, url;
	var winl = (screen.width-openWidth)/2;
	var wint = (screen.height-openHeight)/2;
	window.open( url,winName,'toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=yes,resizable=1,copyhistory=0,width=' + openWidth + ',height=' + openHeight +',top=' + wint  + ',left=' + winl);
}
function theOpenWin_non_size(openWidth,openHeight,winName,url) {
	var winl = (screen.width-openWidth)/2;
	var wint = (screen.height-openHeight)/2;
	window.open(url,winName,'toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=0,resizable=0,copyhistory=0,width=' + openWidth + ',height=' + openHeight +',top=' + wint  + ',left=' + winl);
}
function theOpenWin_no_opt(openWidth,openHeight,winName,url) {
	var openWidth, openHeight, winName, url;
	var winl = (screen.width-openWidth)/2;
	var wint = (screen.height-openHeight)/2;
	window.open( url,winName,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=no,resizable=0,copyhistory=0,width=' + openWidth + ',height=' + openHeight +',top=' + wint  + ',left=' + winl);
}
function Nwindow_outer(url, l, t, w, h, t_get) {
	var str;
	str = "top=" + t + ", left=" + l + ", width=" + w + ", height=" + h;
	str = str + ",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes";
	ObjWindow = window.open(url, t_get, str);
	if ( ObjWindow ) {
		ObjWindow.location;
		ObjWindow.location;
		ObjWindow.focus();
	}
}

//¼ýÀÚ³ª ¿µ¹®ÀÚ ÀÎÁö Ã¼Å©
var alpha_numeric = new String("0123456789abcdefghijklmnopqrstuvwxyz");
function check_alphanumber(str) {
	var str, j, rtn;
	for(j=0;j<str.length;j++) {
		rtn = is_alpha_numeric(str.charAt(j));
		if(rtn == false) return rtn;
	}
	return rtn;
}
function is_alpha_numeric(cha1) {
	var cha1, i;
	for(i=0;i<alpha_numeric.length;i++) {
		if(alpha_numeric.charAt(i) == cha1) return true;
	}
	return false;
}

//¼ýÀÚÀÎÁö Ã¼Å©
var numeric = new String("0123456789");
function check_number(str) {
	var str, j, rtn;
	for(j=0;j<str.length;j++) {
		rtn = is_numeric(str.charAt(j));
		if(rtn == false) return rtn;
	}
	return rtn;
}
function is_numeric(cha1) {
	var cha1, i;
	for(i=0;i<numeric.length;i++) {
		if(numeric.charAt(i) == cha1) return true;
	}
	return false;
}

function check_email(email_str) {
	if (email_str.indexOf(' ')>=0) return false;
	if (email_str.search(/(\S+)@(\S+)\.(\S+)/) == -1) return false;
	return true;
}

function check_null_int(val) {
	var val;
	if(val == "") val = "0";
	return val;
}

function onlyNumber() {
	// event.keyCode==13 : enter key
	//if ((event.keyCode>=48 && event.keyCode<=57) || event.keyCode==13) {} event.returnValue=false;
	if (((event.keyCode<48) || (event.keyCode>57)) && event.keyCode!=13) event.returnValue=false;
}
function onlyMoney() {
	// event.keyCode==13 : enter key	event.keyCode==44 : comma	event.keyCode==45 : -
	//if ((event.keyCode>=48 && event.keyCode<=57) || event.keyCode==13) {} event.returnValue=false;
	if (((event.keyCode<48) || (event.keyCode>57)) && event.keyCode!=13 && event.keyCode!=44 && event.keyCode!=45) {
		event.returnValue=false;
	}
}

function FormatNumber(str, sosu_jari) {
	var str, str2, i, j, str_head, sosu_v, sosu_ori, sosu_jari, sosu_jari_v;

	if(isNaN(sosu_jari)) sosu_jari = 0;
	else sosu_jari = Number(sosu_jari);	// ÀÌ ¼ýÀÚ°¡ 2ÀÌ¸é ¼Ò¼ýÁ¡ 2ÀÚ¸®±îÁö Ç¥±âÇÏ¶ó´Â ÀÇ¹Ì
	
	str = "" + str;
	str2 = "";
	str_head = "";			// À½¼öÀÏ°æ¿ì - ¸¦ ´ã´Â º¯¼ö
	sosu_v = "";			// ¼Ò¼ýÁ¡ ÀÌÇÏ(Á¡ Æ÷ÇÔ)¸¦ ´ã´Â º¯¼ö
	if (str.charAt(0) == "-") {
		str_head = "-";
		str = str.substr(1, str.length-1);
	}
	i=str.indexOf(".");
	if (i > -1) {
		sosu_jari_v = 1;
		for (j=0;j<sosu_jari;j++) { sosu_jari_v *= 10; }
		str = str * sosu_jari_v;				//¼Ò¼ýÁ¡ 3ÀÚ¸®¿¡¼­ ¹Ý¿Ã¸², Áï 2ÀÚ¸®±îÁö Ç¥±â
		str = Math.round(str) / sosu_jari_v;
		str = "" + str;
		i=str.indexOf(".");
		if (i > -1) {
			sosu_ori = str;
			str = str.substr(0, i);
			sosu_v = sosu_ori.substr(i, sosu_ori.length-i);	// Á¡(.)À» Æ÷ÇÔÇÑ ¹®ÀÚ
			for(j=sosu_v.length-1;j<sosu_jari;j++) {	// º¯¼ö·Î ¹ÞÀº sosu_jari ¸¸Å­ ³¡¿¡ 0À» ¸¸µç´Ù.
				sosu_v += "0";
			}
		}
	}
	j=1;
	for (i=str.length-1; i>=0; i--) {	// ¼¼ ÀÚ¸®¸¶´Ù ÄÞ¸¶ Âï±â
		str2 = str.charAt(i) + str2;
		if(j>1 && j%3 == 0 && i>0) str2 = "," + str2;
		j++;
	}
	str = "" + str_head + str2 + sosu_v;
	return (str);
}

function go_url_from_select(str) {
	var str, val;
	val = str.options[str.selectedIndex].value;
	if (val != "") location.href = val;
}

function get_val_radio(str) {
	var str, i;
	var undefined, cnt;
	if (str) {
		cnt = str.length;
		if (cnt == undefined) {
			if (str.checked) return str.value;
		} else {
			for (i=0;i<str.length;i++) {
				if(str[i].checked) return str[i].value;
			}
		}
	} else {
		alert("Ã³¸®ÇÒ µ¥ÀÌÅÍ°¡ ¾ø½À´Ï´Ù.");
		return false;
	}
	return false;
}

function get_val_select(str) {
	return str.options[str.selectedIndex].value;
}

function get_val_selects(str) {
	//3. °°Àº ÀÌ¸§ÀÇ ¼±ÅÃ ¹Ú½º°¡ µÎ °³ ÀÌ»ó ÀÖÀ» ¶§ value °ª ¾ò±â
	//alert(str[i].options[str[i].selectedIndex].value);
}

function checkbox_check(str, act) {
	var str, act, i, exists;
	var undefined;
	if (str) {
		var cnt = str.length;
		if (act == 'go') {
			exists = 0;
			if (cnt == undefined) {
				if (str.checked) exists++;
			} else {
				for (i=0;i<str.length;i++) {
					if (str[i].checked) exists++;
				}
			}
			if (exists == 0) {
				alert("ÇÏ³ª ÀÌ»ó Ã¼Å©¸¦ ÇÏ¼Å¾ß ÇÕ´Ï´Ù.");
				return false;
			}
		}
	} else {
		alert("Ã³¸®ÇÒ µ¥ÀÌÅÍ°¡ ¾ø½À´Ï´Ù.");
		return false;
	}
	return true;
}

function checkbox_tool(str, flag) {
	var str, flag, i;
	var undefined;
	if (flag == 'T') flags = true;
	else if (flag == 'F') flags = false;
	if (checkbox_check(str, 'no')) {
		var cnt = str.length;
		if (cnt == undefined) {
			str.checked = flags;
		} else {
			for (i=0;i<str.length;i++) str[i].checked = flags;
		}
	}
}

function toggle(field,flag) {
	var field, flag, cnt, i;
	var undefined;
	field = eval(field);
	if (field) {
		cnt = field.length;
		if (flag == "T" || flag == "F") {
			if (flag == "T") flag = true;
			else if (flag == "F") flag = false;
			if (cnt == undefined) field.checked = flag;
			else {
				for(i=0;i<cnt;i++) field[i].checked = flag;
			}
		} else if (flag == "R") {
			if (cnt == undefined)
				if (field.checked) field.checked = false;
				else field.checked = true;
			else {
				for(i=0;i<cnt;i++) {
					if (field[i].checked) field[i].checked = false;
					else field[i].checked = true;
				}
			}
		} else alert("À¯È¿ÇÏÁö ¾ÊÀº flag ÀÔ´Ï´Ù.");
	} else alert("Á¸ÀçÇÏÁö ¾Ê´Â ÇÊµåÀÔ´Ï´Ù.");
}

function trim(val) {
	var val,i,val_t,start_i,end_i;
	val_t = "";
	start_i = -1;
	end_i = -1;
	if(val.length == 0) return val_t;
	for(i=0;i<val.length;i++) {
		if(val.charAt(i) != " ") {
			start_i = i;
			break;
		}
	}
	for(i=val.length-1;i>=0;i--) {
		if(val.charAt(i) != " ") {
			end_i = i;
			break;
		}
	}
	if(start_i == -1) return val_t;
	val_t = val.substr(start_i,end_i-start_i+1);
	return val_t;
}

function Replace(strOriginal, strFind, strChange) {
	return strOriginal.split(strFind).join(strChange);
}

function check_go_next(str, num, str_next) {
	if (str.value.length >= num) {
		if (str_next) {
			str_next.focus();
			if (str_next.type == "text") str_next.select();
		}
	}
}

function opener_exist() {
	var o_win = window.opener;
	var opener_TF = false;
	try {
		opener.window;
		opener_TF = true;
	} catch(e) { }		// opener closed
	return opener_TF;
}

function view_large_image(img_url, title) {
	if (title == "") title = "ÀÌ¹ÌÁö ºä";
	var imgwin = window.open("",'WIN','scrollbars=no,status=yes,toolbar=no,resizable=no,location=no,menu=no,width=10,height=10');
	imgwin.focus();
	imgwin.document.open();
	imgwin.document.write("<html>\n");
	imgwin.document.write("<head>\n");
	imgwin.document.write("<title>" + title + "</title>\n"); //¿ÀÇÂÃ¢ Å¸ÀÌÆ² ÀÌ¸§ ÁöÁ¤ÇÏ´Â ºÎºÐ

	imgwin.document.write('<sc'+'ript language="javascript">\n');
	imgwin.document.write('<!--\n');
	imgwin.document.write("function resize() { \n");
	imgwin.document.write("	pic = document.il;\n");
	imgwin.document.write("	if (eval(pic).height) { \n");
	imgwin.document.write("		var name = navigator.appName; \n");
	imgwin.document.write("		var w_width, w_height; \n");
	imgwin.document.write("		if (name == 'Microsoft Internet Explorer') { \n");
	imgwin.document.write("			myHeight = eval(pic).height + 0; myWidth = eval(pic).width + 0;\n");
	imgwin.document.write(" 	} else { \n");
	imgwin.document.write(" 		myHeight = eval(pic).height + 9; myWidth = eval(pic).width;\n");
	imgwin.document.write(" 	}\n");
	imgwin.document.write("		clearTimeout();\n");
	imgwin.document.write("		var height = screen.height;\n");
	imgwin.document.write("		var width = screen.width;\n");
	imgwin.document.write("		var leftpos = ((width - myWidth) / 2);\n");
	imgwin.document.write("		var toppos = ((height - myHeight) / 2); \n");
	
	imgwin.document.write("		w_width = myWidth; w_height = myHeight \n");
	imgwin.document.write("		if (leftpos < 0) { leftpos = 0; w_width = width-10; } else { w_width = w_width + 6; } \n");
	imgwin.document.write("		if (toppos < 0) { toppos = 0; w_height = height-30; document.body.scroll = 'yes';} else { w_height = w_height + 47; } \n");
	
	imgwin.document.write("		self.moveTo(leftpos, toppos);\n"); 
	imgwin.document.write("		self.resizeTo(w_width, w_height);\n"); 
	imgwin.document.write("	} else setTimeOut(resize(), 100);}\n");

	imgwin.document.write('function keypressed() { \n');
	imgwin.document.write('	event.keyCode = 0; \n');
	imgwin.document.write('	event.cancelBubble = true; \n');
	imgwin.document.write('	event.returnValue = false; \n');
	imgwin.document.write('} \n');
	imgwin.document.write('document.onkeydown=keypressed; \n');
	
	imgwin.document.write('//-->\n');
	imgwin.document.write("</sc"+"ript>\n"); 

	imgwin.document.write("</head>\n"); 
	imgwin.document.write('<body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0" bgcolor="#FFFFFF" oncontextmenu="return false">\n');

	imgwin.document.write("<a href=javascript:window.close()><img border=0 src="+img_url+" xwidth=100 xheight=9 name=il onload='resize();'></a>\n"); 
	imgwin.document.write("</body>\n"); 
	imgwin.document.close(); 
}

function check_image_file_format(file) {
    var allowSubmit = false;
    var extArray = new Array("gif", "jpeg", "jpg", "png");

    extArray.join(" ");

    if (!file) return false;

    while (file.indexOf("\\") != -1)
        file = file.slice(file.indexOf("\\") + 1);

    //var ext = file.slice(file.indexOf(".")).toLowerCase();
    var temp = file.split(".");
    var ext = temp[temp.length-1].toLowerCase();

    for (var i = 0; i < extArray.length; i++) {
        if (extArray[i] == ext) {
            allowSubmit = true;
            break;
        }
    }

    if (allowSubmit) return true;
    else {
        alert("±×¸² »ðÀÔÀº GIF, JPEG, JPG, PNG ÆÄÀÏ¸¸ °¡´ÉÇÕ´Ï´Ù. ´Ù½Ã ¼±ÅÃÇÏ¿© ÁÖ½Ê½Ã¿ä.");
        return false;
    }
}

function ChkLen(str,max_len) {
	var pos;
	var msglen = 0;
	var len = str.value.length;
	max_len = Number(max_len);
	for(i=0;i<len;i++){
		pos = str.value.charAt(i);
		if (escape(pos).length > 4)
			msglen += 2;
		else
			msglen++;
	}
    if(msglen > max_len ) {
	    alert(max_len + ' ¹ÙÀÌÆ®¸¦ ³ÑÀ» ¼ö ¾ø½À´Ï´Ù.');
	    str.focus();
    }
   // this_f.MSG_TXT_CNT.value = msglen;
}
function ChkLen_tf(str,max_len) {
	var pos;
	var msglen = 0;
	var len = str.value.length;
	max_len = Number(max_len);
	for(i=0;i<len;i++){
		pos = str.value.charAt(i);
		if (escape(pos).length > 4)
			msglen += 2;
		else
			msglen++;
	}
    if(msglen > max_len ) return false;
    else return true;
   // this_f.MSG_TXT_CNT.value = msglen;
}

// Á¦´ë·Î ÀÔ·ÂµÈ ³¯Â¥ÀÎÁö °Ë»ç
function check_dates(str) {
	// input º¯¼ö¸¦ int ·Î º¯È¯ÇØ¼­ ³Ñ±â¸é Á¦´ë·Î ¼öÇàÀÌ ¾ÈµÊ ¹Ýµå½Ã char ·Î ³Ñ°Ü¶ó...
	var temp;
	if (str.value != "") {
		temp = (str.value).split("-");
		if (temp.length != 3) {
			alert("³¯Â¥ Çü½ÄÀº YYYY-mm-dd ÀÔ´Ï´Ù.");
			return false;
		}
		if (temp[0].length != 4 || temp[1].length != 2 || temp[2].length != 2) {
			alert("³¯Â¥ Çü½ÄÀº YYYY-mm-dd ÀÔ´Ï´Ù.");
			return false;
		}
	} else return true;
	
	var v_year,v_month,v_day;
	v_year = temp[0];
	v_month = temp[1];
	v_day = temp[2];
	
	var err=0;
	if (isNaN(v_year)) return false;
	if (isNaN(v_month)) return false;
	if (isNaN(v_day)) return false;
	if ( v_year.length != 4) err=1;
	if ( v_month.length != 1 &&  v_month.length !=  2 ) err=1;
	if ( v_day.length != 1  &&  v_day.length !=  2) err=1;

	r_year = eval(v_year);
	r_month = eval(v_month);
	r_day = eval(v_day);

	if (r_month<1 || r_month>12) err = 1;
	if (r_day<1 || r_day>31) err = 1;
	if (r_year<0 ) err = 1;

	if (r_month==4 || r_month==6 || r_month==9 || r_month==11) {
		if (r_day==31) err=1;
	}

	// 2,À±³âÃ¼Å©
	if (r_month==2){
		var g=parseInt(r_year/4);

		if (isNaN(g)) err=1;	// À±³âÀº ¹Ýµå½Ã 4·Î ³ª´­¶§ ¸òÀÌ ¾ø¾î¾ß ÇÏ¹Ç·Î...
		if (r_day>29) err=1;
		if (r_day==29 && ((r_year/4)!=parseInt(r_year/4))) err=1;
		if (((r_year % 4 == 0) && (r_year % 100 != 0)) || (r_year % 400 == 0)) { }
		else
			if (r_day == 29) err=1;
	
	}
	
	if (err==1) {
		alert("¿Ã¹Ù¸¥ ³¯Â¥°¡ ¾Æ´Õ´Ï´Ù. ´Ù½Ã È®ÀÎ ÇØ ÁÖ½Ê½Ã¿À.");
		return false;
	} else return true;
}

function close_fn() {
	if (opener_exist()) opener.focus();
	self.close();
}

function ID_show_with_num(show_ID, num) {
	var show_ID, len, num, i;
	var undefined;
	
	if (show_ID != "") {
		show_ID = eval(show_ID);
		len = show_ID.length;
		if (len == undefined) show_ID.style.display="block";
		else {
			num = Number(num);
			for(i=0;i<len;i++) {
				if (i == num) show_ID(i).style.display="block";
				else show_ID(i).style.display="none";
			}
		}
	}
}

function roundTable_draw(obj) {
	var Parent, objTmp, Table, TBody, TR, TD; 
	var bdcolor, bgcolor, Space; 
	var trIDX, tdIDX, MAX; 
	var styleWidth, styleHeight; 
	
	Parent = obj.parentNode; 
	objTmp = document.createElement('SPAN'); 
	Parent.insertBefore(objTmp, obj); 
	Parent.removeChild(obj); 
	
	bdcolor = obj.getAttribute('rborder'); 
	bgcolor = obj.getAttribute('rbgcolor'); 
	radius = parseInt(obj.getAttribute('radius')); 
	if (radius == null || radius < 1) radius = 1; 
	else if (radius > 6) radius = 6; 
	
	MAX = radius * 2 + 1; 
	Table = document.createElement('TABLE'); 
	TBody = document.createElement('TBODY'); 
	Table.cellSpacing = 0; 
	Table.cellPadding = 0; 
	for (trIDX=0; trIDX < MAX; trIDX++) { 
		TR = document.createElement('TR'); 
		Space = Math.abs(trIDX - parseInt(radius)); 
		for (tdIDX=0; tdIDX < MAX; tdIDX++) { 
			TD = document.createElement('TD');
			styleWidth = '1px'; styleHeight = '1px';
			if (tdIDX == 0 || tdIDX == MAX - 1) styleHeight = null;
			else if (trIDX == 0 || trIDX == MAX - 1) styleWidth = null; 
			else if (radius > 2) { 
				if (Math.abs(tdIDX - radius) == 1) styleWidth = '2px'; 
				if (Math.abs(trIDX - radius) == 1) styleHeight = '2px'; 
			} 
			if (styleWidth != null) TD.style.width = styleWidth; 
			if (styleHeight != null) TD.style.height = styleHeight; 
			
			if (Space == tdIDX || Space == MAX - tdIDX - 1) TD.style.backgroundColor = bdcolor; 
			else if (tdIDX > Space && Space < MAX - tdIDX - 1)  TD.style.backgroundColor = bgcolor; 
			
			if (Space == 0 && tdIDX == radius) TD.appendChild(obj); 
			TR.appendChild(TD); 
		} 
		TBody.appendChild(TR); 
	} 
	Table.appendChild(TBody); 
	Parent.insertBefore(Table, objTmp);
} 
function roundTable_fn(show_ID) {
	var show_ID, len, num, i;
	var undefined;
	if (show_ID != "") {
		var tmp_TF = false;
		try {
			show_ID = eval(show_ID);
			tmp_TF = true;
		} catch(e) { }
	
		if (tmp_TF) {
			len = show_ID.length;
			if (len == undefined) roundTable_draw(show_ID);
			else {
				num = Number(num);
				for(i=0;i<len;i++) roundTable_draw(show_ID(i));
			}
		}
	}
}
