if (typeof(COMMON_JS) == 'undefined') { // 한번만 실행
    var COMMON_JS = true;

    // 전역 변수
    var errmsg = "";
    var errfld;

    // 필드 검사
    function check_field(fld, msg) 
    {
        if ((fld.value = trim(fld.value)) == "") 			   
            error_field(fld, msg);
        else
            clear_field(fld);
        return;
    }

    // 필드 오류 표시
    function error_field(fld, msg) 
    {
        if (msg != "")
            errmsg += msg + "\n";
        if (!errfld) errfld = fld;
        fld.style.background = "#BDDEF7";
    }

    // 필드를 깨끗하게
    function clear_field(fld) 
    {
        fld.style.background = "#FFFFFF";
    }

    function trim(s)
    {
        var pattern = /(^\s*)|(\s*$)/g; // \s 공백 문자
        s = s.replace(pattern, "");
        return s;
    }

    function is_AlphaNumeric(fld) 
    { 
		var ret = false;
       if(fld.value.length > 0){
		   var pattern = /(^[a-zA-Z0-9]+$)/; 
		   if (pattern.test(fld.value)) 
		   { 
				ret = true;
		   } 
	   }
	   return ret;
    } 
    function is_Numeric(fld) { 
		var ret = false;
        if (fld.value.length > 0)  { 
		   var pattern = /(^[0-9]+$)/; 
		   if (pattern.test(fld.value)) 
		   { 
				ret = true;
		   } 			
        }
		return ret;
    }
    // 자바스크립트로 PHP의 number_format 흉내를 냄
    // 숫자에 , 를 출력
    function number_format(data) 
    {
        
        var tmp = '';
        var number = '';
        var cutlen = 3;
        var comma = ',';
        var i;
       
        len = data.length;
        mod = (len % cutlen);
        k = cutlen - mod;
        for (i=0; i<data.length; i++) 
        {
            number = number + data.charAt(i);
            
            if (i < data.length - 1) 
            {
                k++;
                if ((k % cutlen) == 0) 
                {
                    number = number + comma;
                    k = 0;
                }
            }
        }

        return number;
    }

    // 새 창
    function popup_window(url, winname, opt)
    {
        window.open(url, winname, opt);
    }


    // 폼메일 창
    function popup_formmail(url)
    {
        opt = 'scrollbars=yes,width=417,height=385,top=10,left=20';
        popup_window(url, "wformmail", opt);
    }

    // , 를 없앤다.
    function no_comma(data)
    {
        var tmp = '';
        var comma = ',';
        var i;

        for (i=0; i<data.length; i++)
        {
            if (data.charAt(i) != comma)
                tmp += data.charAt(i);
        }
        return tmp;
    }

    // 삭제 검사 확인
    function del(href) 
    {
        //ไม่สามารถกู้คืนข้อมูลที่ลบไปแล้ว .\n\n ฉันต้องการลบ
		//한번 삭제한 자료는 복구할 방법이 없습니다.\n\n정말 삭제하시겠습니까?
		if(confirm("ไม่สามารถกู้คืนข้อมูลที่ลบไปแล้ว \n\n ฉันต้องการลบ")) 
            document.location.href = href;
    }

    // 쿠키 입력
    function set_cookie(name, value, expirehours, domain) 
    {
        var today = new Date();
        today.setTime(today.getTime() + (60*60*1000*expirehours));
        document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + today.toGMTString() + ";";
        if (domain) {
            document.cookie += "domain=" + domain + ";";
        }
    }

    // 쿠키 얻음
    function get_cookie(name) 
    {
        var find_sw = false;
        var start, end;
        var i = 0;

        for (i=0; i<= document.cookie.length; i++)
        {
            start = i;
            end = start + name.length;

            if(document.cookie.substring(start, end) == name) 
            {
                find_sw = true
                break
            }
        }

        if (find_sw == true) 
        {
            start = end + 1;
            end = document.cookie.indexOf(";", start);

            if(end < start)
                end = document.cookie.length;

            return document.cookie.substring(start, end);
        }
        return "";
    }

    // 쿠키 지움
    function delete_cookie(name) 
    {
        var today = new Date();

        today.setTime(today.getTime() - 1);
        var value = get_cookie(name);
        if(value != "")
            document.cookie = name + "=" + value + "; path=/; expires=" + today.toGMTString();
    }

    // 이미지의 크기에 따라 새창의 크기가 변경됩니다.
    // zzzz님께서 알려주셨습니다. 2005/04/12
    function image_window(img)
    {
        var w = img.tmp_width; 
        var h = img.tmp_height; 
        var winl = (screen.width-w)/2; 
        var wint = (screen.height-h)/3; 

        if (w >= screen.width) { 
            winl = 0; 
            h = (parseInt)(w * (h / w)); 
        } 

        if (h >= screen.height) { 
            wint = 0; 
            w = (parseInt)(h * (w / h)); 
        } 

        var js_url = "<script language='JavaScript1.2'> \n"; 
            js_url += "<!-- \n"; 
            js_url += "var ie=document.all; \n"; 
            js_url += "var nn6=document.getElementById&&!document.all; \n"; 
            js_url += "var isdrag=false; \n"; 
            js_url += "var x,y; \n"; 
            js_url += "var dobj; \n"; 
            js_url += "function movemouse(e) \n"; 
            js_url += "{ \n"; 
            js_url += "  if (isdrag) \n"; 
            js_url += "  { \n"; 
            js_url += "    dobj.style.left = nn6 ? tx + e.clientX - x : tx + event.clientX - x; \n"; 
            js_url += "    dobj.style.top  = nn6 ? ty + e.clientY - y : ty + event.clientY - y; \n"; 
            js_url += "    return false; \n"; 
            js_url += "  } \n"; 
            js_url += "} \n"; 
            js_url += "function selectmouse(e) \n"; 
            js_url += "{ \n"; 
            js_url += "  var fobj      = nn6 ? e.target : event.srcElement; \n"; 
            js_url += "  var topelement = nn6 ? 'HTML' : 'BODY'; \n"; 
            js_url += "  while (fobj.tagName != topelement && fobj.className != 'dragme') \n"; 
            js_url += "  { \n"; 
            js_url += "    fobj = nn6 ? fobj.parentNode : fobj.parentElement; \n"; 
            js_url += "  } \n"; 
            js_url += "  if (fobj.className=='dragme') \n"; 
            js_url += "  { \n"; 
            js_url += "    isdrag = true; \n"; 
            js_url += "    dobj = fobj; \n"; 
            js_url += "    tx = parseInt(dobj.style.left+0); \n"; 
            js_url += "    ty = parseInt(dobj.style.top+0); \n"; 
            js_url += "    x = nn6 ? e.clientX : event.clientX; \n"; 
            js_url += "    y = nn6 ? e.clientY : event.clientY; \n"; 
            js_url += "    document.onmousemove=movemouse; \n"; 
            js_url += "    return false; \n"; 
            js_url += "  } \n"; 
            js_url += "} \n"; 
            js_url += "document.onmousedown=selectmouse; \n"; 
            js_url += "document.onmouseup=new Function('isdrag=false'); \n"; 
            js_url += "//--> \n"; 
            js_url += "</"+"script> \n"; 

        var settings;

        if (tc_is_gecko) {
            settings  ='width='+(w+10)+','; 
            settings +='height='+(h+10)+','; 
        } else {
            settings  ='width='+w+','; 
            settings +='height='+h+','; 
        }
        settings +='top='+wint+','; 
        settings +='left='+winl+','; 
        settings +='scrollbars=no,'; 
        settings +='resizable=yes,'; 
        settings +='status=no'; 


        win=window.open("","image_window",settings); 
        win.document.open(); 
        win.document.write ("<html><head> \n<meta http-equiv='imagetoolbar' CONTENT='no'> \n<meta http-equiv='content-type' content='text/html; charset="+tc_charset+"'>\n"); 
        var size = "이미지 사이즈 : "+w+" x "+h;
        win.document.write ("<title>"+size+"</title> \n"); 
        if(w >= screen.width || h >= screen.height) { 
            win.document.write (js_url); 
            //รูปภาพมีขนาดใหญ่เกินหน้าจอของคุณ \n คลิกปุ่มเมาส์ซ้ายค้างไว้เพื่อเคลื่อนย้าย \n\n ดับเบิลคลิกเพื่อปิด
			//이미지 사이즈가 화면보다 큽니다.\n 왼쪽 버튼을 클릭한 후 마우스를 움직여서 보세요. \n\n 더블 클릭하면 닫혀요.
			var click = "ondblclick='window.close();' style='cursor:move' title=' "+size+" \n\n รูปภาพมีขนาดใหญ่เกินหน้าจอของคุณ \n\n  คลิกปุ่มเมาส์ซ้ายค้างไว้เพื่อเคลื่อนย้าย. \n\n  ดับเบิลคลิกเพื่อปิด. '"; 
        } 
        else 
            //คลิกเพื่อปิด
			//클릭하면 닫혀요.
		    var click = "onclick='window.close();' style='cursor:pointer' title=' "+size+" \n\n คลิกเพื่อปิด '"; 
        win.document.write ("<style>.dragme{position:relative;}</style> \n"); 
        win.document.write ("</head> \n\n"); 
        win.document.write ("<body leftmargin=0 topmargin=0 bgcolor=#dddddd style='cursor:arrow;'> \n"); 
        win.document.write ("<table width=100% height=100% cellpadding=0 cellspacing=0><tr><td align=center valign=middle><img src='"+img.src+"' width='"+w+"' height='"+h+"' border=0 class='dragme' "+click+"></td></tr></table>");
        win.document.write ("</body></html>"); 
        win.document.close(); 

        if(parseInt(navigator.appVersion) >= 4){win.window.focus();} 
    }

    // a 태그에서 onclick 이벤트를 사용하지 않기 위해
    function win_open(url, name, option)
    {
        var popup = window.open(url, name, option);
        popup.focus();
    }

    // 우편번호 창
    function win_zip(frm_name, frm_zip, frm_addr)
    {
        url = tc_path + "/inc/zip.php?frm_name="+frm_name+"&frm_zip="+frm_zip+"&frm_addr="+frm_addr;
        win_open(url, "winZip", "left=50,top=50,width=616,height=460,scrollbars=1");
    }

    // 쪽지 창
    function win_memo(url)
    {
        if (!url)
            url = tc_path + "/memo/memo.php";
        win_open(url, "winMemo", "left=50,top=50,width=620,height=460,scrollbars=1");
    }

    // 포인트 창
    function win_point(url)
    {
        win_open(tc_path + "/bbs/point.php", "winPoint", "left=20, top=20, width=616, height=635, scrollbars=1");
    }

    // 스크랩 창
    function win_scrap(url)
    {
        if (!url)
            url = tc_path + "/bbs/scrap.php";
        win_open(url, "scrap", "left=20, top=20, width=616, height=500, scrollbars=1");
    }

    // 패스워드 분실 창
    function win_password_forget()
    {
        win_open(tc_path + "/bbs/password_forget.php", 'winPasswordForget', 'left=50, top=50, width=616, height=500, scrollbars=1');
    }

    // 코멘트 창
    function win_comment(url)
    {
        win_open(url, "winComment", "left=50, top=50, width=800, height=600, scrollbars=1");
    }

    // 폼메일 창
    function win_formmail(mb_id, name, email)
    {
		if (tc_charset.toLowerCase() == 'euc-kr')
	        win_open(tc_path+"/bbs/formmail.php?mb_id="+mb_id+"&name="+name+"&email="+email, "winFormmail", "left=50, top=50, width=600, height=500, scrollbars=0");
		else
	        win_open(tc_path+"/bbs/formmail.php?mb_id="+mb_id+"&name="+encodeURIComponent(name)+"&email="+email, "winFormmail", "left=50, top=50, width=600, height=480, scrollbars=0");
    }

    // 설문조사 창
    function win_poll(url)
    {
        if (!url)
            url = "";
        win_open(url, "winPoll", "left=50, top=50, width=616, height=500, scrollbars=1");
    }

    var last_id = null;
    function menu(id)
    {
        if (id != last_id)
        {
            if (last_id != null)
                document.getElementById(last_id).style.display = "none";
            document.getElementById(id).style.display = "block";
            last_id = id;
        }
        else
        {
            document.getElementById(id).style.display = "none";
            last_id = null;
        }
    }

    function textarea_decrease(id, row)
    {
        if (document.getElementById(id).rows - row > 0)
            document.getElementById(id).rows -= row;
    }

    function textarea_original(id, row)
    {
        document.getElementById(id).rows = row;
    }

    function textarea_increase(id, row)
    {
        document.getElementById(id).rows += row;
    }

    // 글숫자 검사
    function check_byte(content, target)
    {
        var i = 0;
        var cnt = 0;
        var ch = '';
        var cont = document.getElementById(content).value;

        for (i=0; i<cont.length; i++) {
            ch = cont.charAt(i);
            if (escape(ch).length > 4) {
                cnt += 2;
            } else {
                cnt += 1;
            }
        }
        // 숫자를 출력
        document.getElementById(target).innerHTML = cnt;

        return cnt;
    }

    // 브라우저에서 오브젝트의 왼쪽 좌표
    function get_left_pos(obj)
    {
        var parentObj = null;
        var clientObj = obj;
        //var left = obj.offsetLeft + document.body.clientLeft;
        var left = obj.offsetLeft;

        while((parentObj=clientObj.offsetParent) != null)
        {
            left = left + parentObj.offsetLeft;
            clientObj = parentObj;
        }

        return left;
    }

    // 브라우저에서 오브젝트의 상단 좌표
    function get_top_pos(obj)
    {
        var parentObj = null;
        var clientObj = obj;
        //var top = obj.offsetTop + document.body.clientTop;
        var top = obj.offsetTop;

        while((parentObj=clientObj.offsetParent) != null)
        {
            top = top + parentObj.offsetTop;
            clientObj = parentObj;
        }

        return top;
    }

    function flash_movie(src, ids, width, height, wmode)
    {
        var wh = "";
        if (parseInt(width) && parseInt(height)) 
            wh = " width='"+width+"' height='"+height+"' ";
        return "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' "+wh+" id="+ids+"><param name=wmode value="+wmode+"><param name=movie value="+src+"><param name=quality value=high><embed src="+src+" quality=high wmode="+wmode+" type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?p1_prod_version=shockwaveflash' "+wh+"></embed></object>";
    }

    function obj_movie(src, ids, width, height, autostart)
    {
        var wh = "";
        if (parseInt(width) && parseInt(height)) 
            wh = " width='"+width+"' height='"+height+"' ";
        if (!autostart) autostart = false;
        return "<embed src='"+src+"' "+wh+" autostart='"+autostart+"'></embed>";
    }

    function doc_write(cont)
    {
        document.write(cont);
    }

    function selectBoxHidden(layer_id) 
    {
        //var ly = eval(layer_id);
        var ly = document.getElementById(layer_id);

        // 레이어 좌표
        var ly_left   = ly.offsetLeft;
        var ly_top    = ly.offsetTop;
        var ly_right  = ly.offsetLeft + ly.offsetWidth;
        var ly_bottom = ly.offsetTop + ly.offsetHeight;

        // 셀렉트박스의 좌표
        var el;

        for (i=0; i<document.forms.length; i++) {
            for (k=0; k<document.forms[i].length; k++) {
                el = document.forms[i].elements[k];    
                if (el.type == "select-one") {
                    var el_left = el_top = 0;
                    var obj = el;
                    if (obj.offsetParent) {
                        while (obj.offsetParent) {
                            el_left += obj.offsetLeft;
                            el_top  += obj.offsetTop;
                            obj = obj.offsetParent;
                        }
                    }
                    el_left   += el.clientLeft;
                    el_top    += el.clientTop;
                    el_right  = el_left + el.clientWidth;
                    el_bottom = el_top + el.clientHeight;

                    // 좌표를 따져 레이어가 셀렉트 박스를 침범했으면 셀렉트 박스를 hidden 시킴
                    if ( (el_left >= ly_left && el_top >= ly_top && el_left <= ly_right && el_top <= ly_bottom) || 
                         (el_right >= ly_left && el_right <= ly_right && el_top >= ly_top && el_top <= ly_bottom) ||
                         (el_left >= ly_left && el_bottom >= ly_top && el_right <= ly_right && el_bottom <= ly_bottom) ||
                         (el_left >= ly_left && el_left <= ly_right && el_bottom >= ly_top && el_bottom <= ly_bottom) ||
                         (el_top <= ly_bottom && el_left <= ly_left && el_right >= ly_right)
                        )
                        el.style.visibility = 'hidden';
                }
            }
        }
    }

    // 감추어진 셀렉트 박스를 모두 보이게 함
    function selectBoxVisible() 
    {
        for (i=0; i<document.forms.length; i++) 
        {
            for (k=0; k<document.forms[i].length; k++) 
            {
                el = document.forms[i].elements[k];    
                if (el.type == "select-one" && el.style.visibility == 'hidden')
                    el.style.visibility = 'visible';
            }
        }
    }

    // 주소록 창
    function win_addr(frm, id, type){
        url = tc_path + "/mypage/address_list.php";
		if(frm && id)
			url += "?frm_name="+frm+"&mb_id="+id;
		if(type)
			url += "&type="+type;
        win_open(url, "winAddr", "left=50,top=50,width=807,height=450,scrollbars=1");
    }
    // 은행목록 창
    function win_bank(frm, id, type){
        url = tc_path + "/mypage/bank_list.php";
		if(frm && id)
			url += "?frm_name="+frm+"&mb_id="+id;
		if(type)
			url += "&type="+type;
        win_open(url, "winBank", "left=50,top=50,width=740,height=450,scrollbars=1");
    }

	function change_addr(fld, id, flag){
		var display = 'none';
		if(flag)
			display = 'block';

		fld.readonly = flag;
		document.getElementById(id).style.display = display;
	}

	function thumb_window(type, no){
		url = tc_path + "/inc/pop_thumb_view.php?type="+type+"&no="+no;
		win_open(url, "thumbImg", "left=50,top=50,width=600,height=600,scrollbars=yes,status=no,toolbar=no,resizable=no,location=no,menu=no");
	}


	function show_help(idx, left, top)
	{
		var id = 'show_help_'+idx;
		var img_id = 'show_help_img_'+idx;
		menu(id);

		var offset = $("#"+img_id).offset();
		$("#"+id).css({
			left : (offset.left - 50 + left),
			top : (offset.top + 27 + top)
		});
	}

	function show_help_box(obj_id, tar_id, left, top){
		var obj = $('#'+obj_id);
		var tar = $('#'+tar_id);
		if(tar.length < 1) return;
		var offset = obj.offset();
		if(!left) left = 0;
		if(!top) top = 0;
		obj.hover(function(){
			tar.css({
				position : 'absolute',
				left : offset.left + left,
				top : offset.top + top,
				display : 'block'
			});
		}, function(){
			tar.css({
				display : 'none'
			});
		});
	}
	function show_fx_comm(type, obj, left, top){
		var id;
		var offset = $(obj).offset();
		switch(type){
			case 'fx' : id = 'show_fx'; url = tc_path+'/inc/fx_view.php'; width = 427; break;
			case 'cok' : id = 'show_commission'; url = tc_path + '/inc/commission_view.php?type=kor';  width = 380; break;
			case 'cot' : id = 'show_commission'; url = tc_path + '/inc/commission_view.php?type=tha';  width = 380; break;
			case 'coj' : id = 'show_commission'; url = tc_path + '/inc/commission_view.php?type=jiro';  width = 380; break;
			case 'level' : id = 'show_level_help'; url = tc_path + '/inc/level_help_view.php'; width = 600; break;
		}
		if($('#'+id).length == 0){
			$('body').append('<div id="'+id+'"></div>');
			$('#'+id).load(url,'',function(){
				$(this).css({
					position: 'absolute',
					border: '2px solid #ff0000',
					backgroundColor: '#ffffff',
					width : width,
					left : offset.left + left,
					top : offset.top + top,
					cursor: 'pointer'
				});
				selectBoxHidden(id);
			}).click(function(){
				$(this).remove();
				selectBoxVisible();
			});
		} else {
			$('#'+id).remove();
			selectBoxVisible();
		}
	}
	
	function input_focus(fld, f_class, b_class, func){
		if($(fld).val() == $(fld).attr("defaultValue")) $(fld).val('');
		$(fld).addClass(f_class).removeClass(b_class).blur(function(){
			$(this).addClass(b_class).removeClass(f_class);
			if($(this).val() == ''){
				$(this).val($(this).attr("defaultValue"));
			}
		});
		if(func){
			var tmp = eval(func);
		}
	}
	function imagepreview(id, w, h)
	{

		menu(id);

		var el_id = document.getElementById(id);

		//submenu = eval(name+".style");
		submenu = el_id.style;
		//submenu.left = tempX - ( w + 11 );
		//submenu.top  = tempY - ( h / 2 );

		selectBoxVisible();

		if (el_id.style.display != 'none')
			selectBoxHidden(id);
	}

	function tab_menus(){
		this.init = function(argument){
			this._name = argument.name;
			this._id = argument.id;
			this._img = new Array('', '');
			if(typeof(argument.img) != 'undefined')
				this._img  = new Array(tc_path+'/images/'+argument.img+'.gif', tc_path+'/images/'+argument.img+'_o.gif');
			this._num = argument.start;
			if(typeof(this._num) == 'undefined') this._num = 0;
			this._control = true;
			this._class = argument.class_name;
			this._time = argument.interval;
			this.show(this._num);
			this.interval();
		}
		this.show = function(num){
			var class_name = this._name;
			this._num = num;
			if(typeof(this._class) != 'undefined')
				this.change_class();
			if(this._img[0] != '' && this._img[1] != '')
				this.change_img();
			this.change_content();
		}
		this.change_content = function(){
			var class_name = this._name;
			$('.'+this._id).hide().click(function(){
				eval(class_name+".clear()");
			}).hover(function(){
				eval(class_name+".clear()");
			},function(){
				eval(class_name+"._control=false");
				eval(class_name+".interval()");
			}).eq(this._num).show();
		}
		this.change_class = function(){
			var class_name = this._name;
			$('.'+this._id+'_title').removeClass(this._class).click(function(){
				eval(class_name+".clear()");
			}).hover(function(){
				eval(class_name+".clear()");
			},function(){
				eval(class_name+"._control=false");
				eval(class_name+".interval()");
			}).eq(this._num).addClass(this._class);
		}
		this.change_img = function(){
			var class_name = this._name;
			$('.'+this._id+'_img').attr("src", this._img[0]).click(function(){
				eval(class_name+".clear()");
			}).hover(function(){
				eval(class_name+".clear()");
			},function(){
				eval(class_name+"._control=false");
				eval(class_name+".interval()");
			}).eq(this._num).attr("src", this._img[1]);
		}

		this.next = function (){
			if(this._num + 1 > $('.'+this._id).length-1 )
				this._num = 0;
			else
				this._num++;
			this.show(this._num);
		}
		this.interval = function(){
			if(typeof(this._time) == 'undefined') return;
			if(!this._control)
				this.clear();
			var str = this._name+".next()";
			this._itv = setInterval(str, this._time);

		}
		this.clear = function(){
			if(typeof(this._itv) != 'undefined' || this._itv != null){
				clearInterval(this._itv);
				this._itv = null;
			}
		}
	}
	$(document).ready(function(){
		$(".input_blur").focus(function(){
			$(this).addClass('input_focus').removeClass('input_blur').blur(function(){
				$(this).addClass('input_blur').removeClass('input_focus');
				if($(this).val() == ''){
					$(this).val($(this).attr("defaultValue"));
				}
			});
		});

	});
}
