﻿/* 윈도우 위치 재설정 */
function winResize(win_width, win_height) {
	if(win_width < 1 || win_height < 1){
		win_width	= 100;
		win_height	= 100;
	}
	win_left	= (window.screen.width-win_width) / 2;
	win_right	= (window.screen.height-win_height) / 2;
	window.moveTo(win_left, win_right);
	window.resizeTo(win_width, win_height);
}

/* 원하는 사이즈로 팝업열기 */
function winOpen(w, h, url, winName) {
	var x = (screen.width - w) / 2 - 10;
	var y = (screen.height - h) / 2 - 10;
	var exp = "width=" + w + ", height=" + h + ", top=" + y + ",left=" + x +
		  ", status=yes, resizable=no, toolbar=no, scrollbars=no ";
	return window.open(url, winName, exp);
}


/* 공백검사 */
function wordVoidCheck(strValue) {
	if (changeWord(strValue, " ", "") == 0 || changeWord(strValue, "&nbsp;", "") == 0) {
		return false;
	} else {
		return true;
	}
}

/* 공백 검사 */
function isSpace(s) { 
	if(s.replace(/(^\s*)|(\s*$)/g, "") && s != null) {
		return false; 
	} else {
		return true; 
	}
}

/* 공백및 길이 유효성검사 */
function wordVoidLenCheck(strValue, minNumber, maxNumber) {
	if (changeWord(strValue, " ", "") == 0 || changeWord(strValue, "&nbsp;", "") == 0) {
		return false;
	}

	if(strValue.length < minNumber || strValue.length > maxNumber) {
		return false;
	}
	return true;
}


/* 주로 공백 스페이스를 바꾸어준다 */
function changeWord(strOriginal, strFind, strChange){ 
    var position, strOri_Length; 
    position = strOriginal.indexOf(strFind);  
    while (position != -1){ 
      strOriginal	= strOriginal.replace(strFind, strChange); 
      position		= strOriginal.indexOf(strFind); 
    } 
    strOri_Length	= strOriginal.length; 
    return strOri_Length; 
}

/* 숫자와 알파벳이면 true */
function IsAlphaNumeric(checkStr) {
	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
	for (i = 0; i < checkStr.length; i++ ) {
		ch = checkStr.charAt(i);
		for (j = 0; j < checkOK.length; j++)
			if (ch == checkOK.charAt(j))
			break;
		if (j == checkOK.length) {
			return false;
			break;
		}
	}
	return true;
}
/* 양쪽 공백제거 */
function trim(value){
    if (value.length == 0) return value;
    
    var start = 0, end = value.length;
    var i;
    
    for (i = start; i < end; i++) {
        if (value.charAt(i) != ' ') {
            start = i;
            break;
        }
	}
    if (i!=end) {
        for (i = end-1; i >= start; i--) {
            if (value.charAt(i) != ' ') {
                end = i+1;
                break;
            }
		}
    } else {
        start = 0;
        end = 0;
    }
    return value.substring(start, end);
}

/*	숫자인지를 검사하는 */
function checkDigit(tocheck) {
	var isnum = true;
	if (( tocheck ==null ) || ( tocheck == "" )) {
		isnum = false;
        return isnum;
	}
	for (var j= 0 ; j< tocheck.length; j++ ) {
		 if ( ( tocheck.substring(j,j+1) != "0" ) &&
			( tocheck.substring(j,j+1) != "1" ) &&
			( tocheck.substring(j,j+1) != "2" ) &&
			( tocheck.substring(j,j+1) != "3" ) &&
			( tocheck.substring(j,j+1) != "4" ) &&
			( tocheck.substring(j,j+1) != "5" ) &&
			( tocheck.substring(j,j+1) != "6" ) &&
			( tocheck.substring(j,j+1) != "7" ) &&
			( tocheck.substring(j,j+1) != "8" ) &&
			( tocheck.substring(j,j+1) != "9" ) ) {
			isnum = false;
		}
	}

	return isnum;
}

/* 로그인 체크 */
function loginCheck(frm) {
	if(!wordVoidCheck(frm.userId.value)) {
		alert("아이디나 비밀번호가 올바르지 않습니다!!");
		frm.userId.focus();
		return false;
	}
	if(!wordVoidCheck(frm.userPasswd.value)) {
		alert("아이디나 비밀번호가 올바르지 않습니다!!");
		frm.userPasswd.focus();
		return false;
	}
	return true;
}

/* 로그아웃 */
function logout() {
	document.location.href = "/commons/logoutPro.asp";
}

/* 인너프레임 높이사이즈를 구해와 부모프레임을 크기조정 */
function innerReSize(innerName) { 
	document.body.scrollIntoView(false);
	var pValue		= eval("parent.document.all." + innerName);
	pValue.height	= document.body.scrollHeight;
}

/* 한글인지 체크 */
function hanCheck(value){ 
    var pattern = new RegExp('[^가-힣\x20]', 'i'); 
    if (pattern.exec(value) != null) { 
        return false; 
    } else { 
        return true; 
    } 
} 

/* 해당글자수를 만족하면 다음포커스로 넘긴다 */
function focusMove(maxLength, fromName, toFormNext){
	var valueLength = fromName.value.length;
	if(valueLength == maxLength) {
		toFormNext.focus();
	}
}

/* 해당url로 간다 */
function goUrl(url) {
	self.top.location.href=url;	
}

/* 아이디나 패스워드 백이미지를 없앤다 */
function hiddenSearch(formStr) {
	document.all[formStr].style.backgroundImage	= "";
}

/* 자바스크립 롤오버 관련 드림위버함수--------------------------------------------------------- */
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
/*---------------------------------------------------------------------------------------------------*/

/* ---------------------------------------------------------------------- 
숫자포맷[값, 단위, 표시] - ex) number_format("1000000","4","-") => 출력: 100-0000  */
function number_format(input, input2, input3) { 
  var i, val=''; 
  var len = input.length; // 원래 값의 길이 
  var top = (len % input2);    // 컴마찍힐 이전의 길이 
  if(top==0) top=input2; 

  var topnum = input.substring(0,top); // 컴마찍힐 이전의 값 
  var midnum = input.substring(top);   // 컴마가 시작될 이후의 값 

  for(i=0;i<midnum.length;i++) { 
    if(i % input2 == 0) val = val + input3; 
    val = val + midnum.charAt(i); 
  } 
  return (topnum + val); 
} 


/**
*	연관배열 사용시 키소트 기능
*	들어있는 값만큼 배열을 length를 받아야할 경우도 사용 결과적으로 들어간 값만큼 length를 나타냄
*	
*/
function sortHashKeys(arr){
	var keys = new Array;
	for(key in arr){	
		keys[keys.length] = key;
	}
	//keys.sort();
	//keys.reverse(); // 역순을 원하시면 이 곳의 주석을 해제, 위의 keys.sort()는 지우면 안됨.
	return keys;
}
/*
ex)
var cat = new Array();
cat['c'] = '여성';
cat['b'] = '고양이';
cat['a'] = '생선';

var keys = sortHashKeys(cat); // 정렬된 키값을 배열로 돌려줍니다.
for( var i=0; i< keys.length; i++){ // 루프문을 사용하면 정렬된 키값 순으로 보실 수 있읍니다.
	document.write(keys[i] ,'-', cat[keys[i]],'<br />');
}
*/


/**
*	xp서비스팩2인가를 확인하는 함수
*	
*/
function isXpSp2(){
	try {
		var info = window.clientInformation;
		var reg1 = /[^A-Z0-9]MSIE[ ]+6.0[^A-Z0-9]/i;
		var reg2 = /[^A-Z0-9]WINDOWS[ ]+NT[ ]+5.1[^A-Z0-9]/i;

		if ((info.appMinorVersion.replace(/\s/g,"").toUpperCase().indexOf(";SP2;") >= 0) &&
			(reg1.test(info.userAgent) == true) && (reg2.test(info.userAgent) == true)) {
			return true;
		}
	} catch(e) {
		return false;
	}
	return false;
}


/* 올바른 이메일 인지 검사 */
function isEmail(emailValue) {
	var emailValue = trim(emailValue);

    if (!wordVoidCheck(emailValue)) {
        alert("이메일주소를 입력해 주시기 바랍니다");
        return false;
    }
    var i;
    for (i = 0; i < emailValue.length; i++) {
        if ( ((emailValue.charAt(i) >= '0') && (emailValue.charAt(i) <= '9'))
             || ((emailValue.charAt(i) >= 'a') && (emailValue.charAt(i) <= 'z'))
             || ((emailValue.charAt(i) >= 'A') && (emailValue.charAt(i) <= 'Z'))
             || (emailValue.charAt(i) == '@')
             || (emailValue.charAt(i) == '.')
             || (emailValue.charAt(i) == '-')
             || (emailValue.charAt(i) == '_')
             || (emailValue.charAt(i) == '%') )
            ;
        else {
            alert("이메일주소가 정확하지 않습니다");
            return false;
        }
    }
    if ((emailValue.indexOf("@") == -1)
        || (emailValue.indexOf("@") == 0)
        || (emailValue.indexOf("@") == (emailValue.length - 1)) ) {
            alert("이메일주소가 정확하지 않습니다");
            return false;
    }
	if ((emailValue.indexOf(".") == -1)
        || (emailValue.indexOf(".") == 0)
        || (emailValue.indexOf(".") == (emailValue.length - 1)) ) {
            alert("이메일주소가 정확하지 않습니다");
            return false;
    }
	
	/*	
	var x, txt;
		x = emailValue.indexOf("@");
		txt = emailValue.toLowerCase(); //소문자 변환
		
		if ( (txt.substring(x+1, x+9) == "daum.net")
		   || (txt.substring(x+1, x+12) == "hanmail.net") ) {
	            alert("죄송합니다. 한메일이 아닌 다른 이메일 주소로 입력해 주세요!");
				EMail.focus();
	            return 1;
	    }	
	*/		   
	return true;
}

function enterNoneAction() {
	if(event.keyCode == 13) {  
		event.returnValue	= false; 
        event.cancelBubble	= true; 
	} 
}

function faq(obj)
{
	if (eval("faq" + obj + ".style.display == 'inline'"))
	{
		for(i=1;i<7;i++){
				eval("faq" + i + ".style.display='none';");
		}
	}
	else if (eval("faq" + obj + ".style.display == 'none'"))
	{
		for(i=1;i<7;i++){
			if(obj == i){
				eval("faq" + obj + ".style.display='inline';");
			}else{
				eval("faq" + i + ".style.display='none';");
			}
		}
	}
}

function setCookie( name, value, expiredays) {
	var today = new Date();
	today.setDate( today.getDate() + expiredays );
	document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + today.toGMTString() + ";";
}
    
function closePop(name) {
	setCookie( name , "checked" ,1);
	self.close();
}

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 openPop() {
	var winState = "left=0,top=0,width=600,height=470,status=yes,resizable=no,toolbar=no,scrollbars=no";
	try {
		if(getCookie("mainPop20060801") != "checked"){
			var mainPop = window.open("/popup/20060801/","_pop20060801", winState).focus();
		} else {
			return;
		}
	} catch (e) {
		return;
	}
}

function openPop1() {
	var winState = "left=400,top=0,width=690,height=600,status=yes,resizable=no,toolbar=no,scrollbars=yes";
	try {
		if(getCookie("mainPop20060818") != "checked"){
			var mainPop = window.open("/popup/20060818/","_pop20060818", winState).focus();
		} else {
			return;
		}
	} catch (e) {
		return;
	}
}

function openPop2() {
	var winState = "left=400,top=0,width=690,height=600,status=yes,resizable=no,toolbar=no,scrollbars=yes";
	var mainPop = window.open("/popup/20060818/","_pop20060818", winState).focus();
}

function openPop3() {
	var winState = "left=400,top=0,width=650,height=548,status=no,resizable=no,toolbar=no,scrollbars=no";
	try {
		if(getCookie("mainPop20060901") != "checked"){
			var mainPop = window.open("/popup/20060901/","_pop20060901", winState).focus();
		} else {
			return;
		}
	} catch (e) {
		return;
	}
}

function openPop4() {
	var winState = "left=400,top=0,width=720,height=600,status=yes,resizable=no,toolbar=no,scrollbars=yes";
	var mainPop = window.open("/popup/20060907/","_pop20060907", winState).focus();
}

function init() {
	MM_preloadImages('image/com/quick2_.gif','image/com/quick3_.gif');
	//openPop();
	//openPop3();
}




// 코딩 추가




/* Main Tab */
function mlist(num) {
	for (var i=1;i<=2;i++) {
		var imgObj = document.getElementById("list_0"+i);		
		var viewObj = document.getElementById("view_0"+i);

		if (i == num) {
			imgObj.src = "images/Comm/mbtn_list_tab0" + i + "_on.gif";
			viewObj.style.display = "";
		} else {					
			imgObj.src = "images/Comm/mbtn_list_tab0" + i + "_off.gif";
			viewObj.style.display = "none";
		}
	}
}

function showDesc(_tr)	{

if( document.getElementById(_tr).style.display == "none")
	document.getElementById(_tr).style.display = "block";

else
document.getElementById(_tr).style.display = "none";
} 



//탭메뉴
function tab_action(obj1, obj2) {
	for(i=0;i<=(eval(obj1).length-1);i++){
		if(eval(obj1)[obj2-1] == eval(obj1)[i]){
			eval(obj1)[i].style.display="block";
		}
		else{
			eval(obj1)[i].style.display="none";
		}
	}
}



function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

//투명
function setPng24(obj) {
	obj.width=obj.height=1;
	obj.className=obj.className.replace(/\bpng24\b/i,'');
	obj.style.filter =
	"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ obj.src +"',sizingMethod='image');"
	obj.src='';
	return '';
}


// image on/off Change
function imgChg(obj) {		/* onClick시 image-change, [ex:	imgChg(this); ] */
	if(obj.src.indexOf("off.gif") != -1) obj.src = obj.src.replace("off.gif", "on.gif");
	else if(obj.src.indexOf("on.gif") != -1) obj.src = obj.src.replace("on.gif", "off.gif");
}

// Content Display
function contView(obj) {	/* obj = id값(name), [ex:	contView('idname'); ]*/
	var target = document.getElementById(obj);
	target.style.display = (target.style.display=='none' ? 'block':'none');
}


/* 개인정보취급방침 */
function pri(num) {
	for (var i=1;i<=10;i++) {
		var imgObj = document.getElementById("plist_0"+i);		
		var viewObj = document.getElementById("pview_0"+i);

		if (i == num) {
			imgObj.src = "../images/etc/btn_privacy0" + i + "_on.gif";
			viewObj.style.display = "";
		} else {					
			imgObj.src = "../images/etc/btn_privacy0" + i + "_off.gif";
			viewObj.style.display = "none";
		}
	}
}

// FAQ
var old;

function menu(name)
{
	if(old!=null){
		old.style.display="none";
	}
	document.getElementById("submenu_"+name).style.display="block";
	old = document.getElementById("submenu_"+name);
}
function hide_menus1(){
  old = null;
	document.getElementById("submenu_1").style.display="none";
}
function hide_menus2(){
  old = null;
	document.getElementById("submenu_2").style.display="none";
}
function hide_menus3(){
  old = null;
	document.getElementById("submenu_3").style.display="none";
}




// AJAX
function textHttp(setUrl,setQuery) {
    var xh;
    var rs;

    if (window.ActiveXObject) {
        xh = new ActiveXObject("Microsoft.XMLHTTP");
    } else if (window.XMLHttpRequest) {
        xh = new XMLHttpRequest();
    }

    // 비동기적 접근
    xh.open("POST",setUrl,false);
    xh.setRequestHeader('Accept-Language','ko');
    xh.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=UTF-8');
    xh.setRequestHeader('Cache-Control','no-cache');
    xh.send(setQuery);

    if (xh.readyState == 4) {
        if (xh.status == 200) {
            rs = xh.responseText;
        } else {
            rs = xh.responseText;
        }
    }

    xh = null;
    return rs;
}


/*추가 : 쿤스*/
function DisplayMenu(menu,tabNum,num) {
     for (i=1; i<=tabNum; i++){
		if (num == i) {
			thisMenu = eval(menu + num + ".style");
			thisMenu.display = "block";
		}else{
			otherMenu = eval(menu + i + ".style"); 
			otherMenu.display = "none"; 
		}
	}
}

/* 추가 :  김진현 */
/* 주민등록 번호 검증*/
function valid_SSN_Kr(strng) {
    re = /^[0-9]{6}-?[0-9]{7}$/;
    if (!re.test(strng)) return false;
    strng_new = strng.replace("-","");
    var year = parseInt(strng_new.substr(0,2),10);
    var month = parseInt(strng_new.substr(2,2),10);
    var day = parseInt(strng_new.substr(4,2),10);
    var gender = parseInt(strng_new.charAt(6) ,10);
    if ( month<1 || month>12 || (gender>4 && gender<9) ) return false;

    var arrayOfLasts = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
    if(month==2) {
        d = new Date(year, 2, 0);
        arrayOfLasts[1] = d.getDate();
    }
    if(day<1 || day>arrayOfLasts[month-1]) return false;

    var tmp = 0;
    for(var n=0; n<12; n++) tmp += (n%8+2) * parseInt(strng_new.charAt(n),10);
    tmp = (11-(tmp%11))%10;
    if (tmp != strng_new.charAt(12)) return false;
    return true;
    
    
} 

// 로그아웃 확인
function ej_logout_check()
{
    if(confirm("로그아웃하시겠습니까?"))
    {
        return true;
    }else
    {
        return false;
    }              
}
