// 이메일 형식 확인 true or false로 반환
function CheckEmail(str) {
	if(str!="") {
		var num = str.indexOf("@");

		if(num < 1) {
			//alert('이메일 주소가 올바르지 않습니다. 올바른 이메일 주소를 입력하세요.') ;
			return false;
		}

		var email_first = str.substring(0,num);
		var email_latter = str.substring(num+1, str.length);

		if(str.charAt(0)=="." || str.charAt(str.length-1)==".") {
			//alert('이메일 주소는 \'.\'으로 시작하거나 \'.\'으로 끝날수 없습니다.') ;
			return false;
		}

		var str="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.";
		var i=0;
		for(i=0; i<email_first.length; i++) {
			var ch = email_first.charAt(i) ;
			if(str.indexOf(ch) < 0) {
				//alert('이메일 주소에 포함할 수 없는 특수 문자가 있습니다.') ;
				return false;
			}
		}

		for(i=0; i<email_latter.length ; i++) {
			var ch = email_latter.charAt(i);
			if(str.indexOf(ch) < 0) {
				//alert('이메일 주소에 포함할 수 없는 특수 문자가 있습니다.');
				return false;
			}
		}

		return true;
	}
}

// 새창 띄우기
function windowOpen(URL, TitleName, SizeWidth, SizeHeight, Scroll) {
	window.open(URL, TitleName, 'width='+SizeWidth+', height='+SizeHeight+', scrollbars='+Scroll+', resizable=0, status=0, menubar=0, toolbar=0');
}

// 이미지 사이즈를 브라우저 화면에 맞게 지정한 크기에 맞게 리사이징 한다.
function ResizingImage(target, iResize, iPercent) {
	// target : 이미지 오브젝트
	// iResize : 크기
	// iPercent : 크기에 비례하여 지정한 비율로 축소

	var image = new Image();
//	var bodyWidth = document.body.clientWidth;
	var bodyWidth = iResize;
	var iWidth;

	image.src = target.src;
	iWidth = image.width;

	if(iResize=="") iResize = bodyWidth

	if(iWidth >= iResize) {
		target.width = bodyWidth * (parseInt(iPercent)/100);
	}
}

// 랜덤숫자 생성 (최소, 최대값 지정)
function random(min, max){
	return Math.floor((Math.random()*1000)% (max - min)) + min;
}

// 쿠키 저장 설정 (쿠키명, 값, 만료일)
function setCookie(name, value, expiredays ) {
	var today = new Date();
	today.setDate(today.getDate() + expiredays );
	document.cookie = name + "=" + escape( value ) + ";path=/;expires=" + today.toGMTString() + ";";
}

// 쿠키 로드 설정 (쿠키명)
function getCookie(name) {
	var nameOfCookie = name + "=";
	var x = 0;

	while (x <= document.cookie.length) {
		var y = (x+nameOfCookie.length);

		if(document.cookie.substring( x, y ) == nameOfCookie) {
			if((endOfCookie=document.cookie.indexOf( ";", y )) == -1)
				endOfCookie = document.cookie.length; 
				return unescape(document.cookie.substring( y, endOfCookie ));
		}

		x = document.cookie.indexOf( " ", x ) + 1;
		if(x == 0) break;
	}

	return "";
}

// 이미지 확대보기
function ImageView(filepath, filename) {
	var fn = filepath + "/" + filename;
	fn = encodeURL(fn);

	windowOpen("/Script/ImageView.asp?fn="+fn, "ImageView", 450, 100, 0);
}

// 인코딩/디코딩
function encodeURL(str){
    var s0, i, s, u;
    s0 = "";                // encoded str
    for (i = 0; i < str.length; i++){   // scan the source
        s = str.charAt(i);
        u = str.charCodeAt(i);          // get unicode of the char
        if (s == " "){s0 += "+";}       // SP should be converted to "+"
        else {
            if ( u == 0x2a || u == 0x2d || u == 0x2e || u == 0x5f || ((u >= 0x30) && (u <= 0x39)) || ((u >= 0x41) && (u <= 0x5a)) || ((u >= 0x61) && (u <= 0x7a))){       // check for escape
                s0 = s0 + s;            // don't escape
            }
            else {                  // escape
                if ((u >= 0x0) && (u <= 0x7f)){     // single byte format
                    s = "0"+u.toString(16);
                    s0 += "%"+ s.substr(s.length-2);
                }
                else if (u > 0x1fffff){     // quaternary byte format (extended)
                    s0 += "%" + (0xf0 + ((u & 0x1c0000) >> 18)).toString(16);
                    s0 += "%" + (0x80 + ((u & 0x3f000) >> 12)).toString(16);
                    s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
                }
                else if (u > 0x7ff){        // triple byte format
                    s0 += "%" + (0xe0 + ((u & 0xf000) >> 12)).toString(16);
                    s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
                }
                else {                      // double byte format
                    s0 += "%" + (0xc0 + ((u & 0x7c0) >> 6)).toString(16);
                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
                }
            }
        }
    }
    return s0;
}

function decodeURL(str)
{
    var s0, i, j, s, ss, u, n, f;
    s0 = "";                // decoded str
    for (i = 0; i < str.length; i++){   // scan the source str
        s = str.charAt(i);
        if (s == "+"){s0 += " ";}       // "+" should be changed to SP
        else {
            if (s != "%"){s0 += s;}     // add an unescaped char
            else{               // escape sequence decoding
                u = 0;          // unicode of the character
                f = 1;          // escape flag, zero means end of this sequence
                while (true) {
                    ss = "";        // local str to parse as int
                        for (j = 0; j < 2; j++ ) {  // get two maximum hex characters for parse
                            sss = str.charAt(++i);
                            if (((sss >= "0") && (sss <= "9")) || ((sss >= "a") && (sss <= "f"))  || ((sss >= "A") && (sss <= "F"))) {
                                ss += sss;      // if hex, add the hex character
                            } else {--i; break;}    // not a hex char., exit the loop
                        }
                    n = parseInt(ss, 16);           // parse the hex str as byte
                    if (n <= 0x7f){u = n; f = 1;}   // single byte format
                    if ((n >= 0xc0) && (n <= 0xdf)){u = n & 0x1f; f = 2;}   // double byte format
                    if ((n >= 0xe0) && (n <= 0xef)){u = n & 0x0f; f = 3;}   // triple byte format
                    if ((n >= 0xf0) && (n <= 0xf7)){u = n & 0x07; f = 4;}   // quaternary byte format (extended)
                    if ((n >= 0x80) && (n <= 0xbf)){u = (u << 6) + (n & 0x3f); --f;}         // not a first, shift and add 6 lower bits
                    if (f <= 1){break;}         // end of the utf byte sequence
                    if (str.charAt(i + 1) == "%"){ i++ ;}                   // test for the next shift byte
                    else {break;}                   // abnormal, format error
                }
            s0 += String.fromCharCode(u);           // add the escaped character
            }
        }
    }
    return s0;
}

// 플래쉬 write
function mFlash(swf, width, height) {
	var object;
		
	object = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\""+width+"\" height=\""+height+"\">";
	object = object + "<param name=\"movie\" value=\""+swf+"\">";
	//object = object + "<param name=\"wmode\" value=\"transparent\">";
	object = object + "<param name=\"quality\" value=\"high\">";
	object = object + "<embed src=\""+swf+"\" wmode=\"transparent\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\""+width+"\" height=\""+height+"\"></embed>";
	object = object + "</object>";

	document.write(object);
}

function mFlash_navigation(swf, width, height, id) {
	var object;
		
	object = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\""+width+"\" height=\""+height+"\" id=\""+id+"\">";
	object = object + "<param name=\"movie\" value=\""+swf+"\">";
	//object = object + "<param name=\"wmode\" value=\"transparent\">";
	object = object + "<param name=\"quality\" value=\"high\">";
	object = object + "<embed src=\""+swf+"\" wmode=\"transparent\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\""+width+"\" height=\""+height+"\"></embed>";
	object = object + "</object>";

	document.write(object);
}

// 레이어 펼침/접기
var order_show = new Array("", "");

function showHideLayer(id, depth) {
	var submenu = document.getElementById(id);

	if(order_show[depth] != submenu) {
		if(order_show[depth] != '') order_show[depth].style.display = "none";
		submenu.style.display = "block";
		order_show[depth] = submenu;
	} else {
		submenu.style.display = "none";
		order_show[depth] = "";
	}

	// 펼칠때와 접을때 프레임 크기를 조정
	self.setTimeout("resizePage()",60);
}

////////////////////////////////// 팝업 레이어 //////////////////////////////////
var TnTL_clickTime;
function DragResize_DN(it_Resize,evt,div_id){

    if(div_id){
        mv_act_objt=document.getElementById(div_id);
        if(mv_act_objt.style.position!='absolute'){
            mv_act_objt.style.left=TnT_get_objLeft(mv_act_objt);
            mv_act_objt.style.top=TnT_get_objTop(mv_act_objt);
            mv_act_objt.style.position='absolute';
        }
        mv_act_objt.style.zIndex=++iwinzidx;
    }
    else{mv_act_objt=iwindowLAYER;}

    DragResize_start=1;
    Drg_x=(this_browser=='n')? evt.pageX : event.clientX;
    Drg_y=(this_browser=='n')? evt.pageY : event.clientY;

    if(it_Resize<1){// Drag
        temp1=parseInt(mv_act_objt.style.left);
        temp2=parseInt(mv_act_objt.style.top);
        if(this_browser=='n')  document.onmousemove=TnTmoveAct_n;
        else document.onmousemove=TnTmoveAct;
    }
    else{// Resize
        iwindoWidth=parseInt(TntiwindowTable.width); // 가로
        iwindoHeight=parseInt(TntiwindowTable.height); // 세로
        if(this_browser=='n')  document.onmousemove=TnTresizeAct_n;
        else document.onmousemove=TnTresizeAct;
    }
    TnTL_clickTime=1;
}


function TnTmoveAct(){ // drag
    if(DragResize_start==1){
        mv_act_objt.style.left=temp1+event.clientX-Drg_x;
        mv_act_objt.style.top=temp2+event.clientY-Drg_y;
        return false;
    }
}

// resize move
function TnTresizeAct(){
    if(DragResize_start==1){
        var re_x=iwindoWidth+event.clientX-Drg_x;
        var re_y=iwindoHeight+event.clientY-Drg_y;
        if(re_x<50 || re_y<50) return false;
        iwindow_RESIZE(re_x,re_y);
        return false;
    }
}

// 부라우저 바탕화면 클릭시 레이어 자동으로 닫히게함(지워 버려도 됨) ----------------------
 document.onclick=iwindow_CLOSE_AUTO;
function iwindow_CLOSE_AUTO(){
	DragResize_start=0;
	if(TnTL_clickTime==1) return; // iwindow 를 드래그 ro 크기변경 동작후에는 자동닫기 적용안함(무조건 자동닫기 적용하려면 이 라인을 삭제)
	if(this_browser=='e'){
		if (event.srcElement.className=="TnT_Layer_dragin") return; // iwindow: Drag, Resize
		if (event.srcElement.className=="TnT_Top_button") return; // iwindow : TopButton
		if (event.srcElement.className=="TnT_Editor_button") return; // editor : Button
	}
	if((TnTL_clickTime+500)<(new Date()).getTime()){iwindow_CLOSE();}
}


function TnTmoveAct_n(evt){ // drag
    if (DragResize_start==1){
        mv_act_objt.style.left=temp1+evt.pageX-Drg_x;
        mv_act_objt.style.top=temp2+evt.pageY-Drg_y;
        return false;
    }
}

// resize move
function TnTresizeAct_n(evt){
    if (DragResize_start==1){
        var re_x=iwindoWidth+evt.pageX-Drg_x;
        var re_y=iwindoHeight+evt.pageY-Drg_y;
        if(re_x<50 || re_y<50) return false;
        iwindow_RESIZE(re_x,re_y);
        return false;
    }
}

// thisobj 의 Top
function TnT_get_objTop(thisobj){
    if (thisobj.offsetParent==document.body) return thisobj.offsetTop;
    else return thisobj.offsetTop + TnT_get_objTop(thisobj.offsetParent);
}

// thisobj 의 Left
function TnT_get_objLeft(thisobj){
    if (thisobj.offsetParent==document.body) return thisobj.offsetLeft;
    else return thisobj.offsetLeft + TnT_get_objLeft(thisobj.offsetParent);
}


// onload 기본모드
mouseDN_X=0;
mouseDN_Y=0;
if(navigator.userAgent.indexOf('MSIE') == -1){
	this_browser='n';
	document.onmousedown=function(n_evt){
		mouseDN_X=n_evt.pageX;
		mouseDN_Y=n_evt.pageY;
	}
	it_img_tag='input type=image '; // iwindow title
}
else{
	this_browser='e';
	it_img_tag='img ';
}
iwinzidx=10;
tntactiwin='';
