
// cookies
function setCookie(name, value, expiredays, domain) {
	var todayDate = new Date();
	todayDate.setDate(todayDate.getDate() + expiredays);
	document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + "; domain=" + domain + ";";
} 

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 delCookie(name,domain) {
	var today = new Date() ;
	var value = getCookie(name);			

	today.setTime(today.getTime() - 1);											

	if (value != "") {
		document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + today.toGMTString() + "; domain=" + domain + ";";
	}
}



// 우편번호 찾기
function Winzip() {
	window.open('/member/zipcode.php', '_zipcode', 'width=417, height=400, scrollbars=1,toolbars=0,statusbar=0');
}


// 로그인 체크
function notLogin(url){
	if (confirm("회원전용 페이지입니다. 로그인 하시겠습니까?")) {
		window.location.href="/member/login.php?q_path_ec="+url
	}
}



function cmtnotLogin(url){
	//this.blur();
	if (confirm("회원전용 페이지입니다. 로그인 하시겠습니까?")) {
		parent.window.location.href="/member/login.php?q_path_ec="+url
	}
}		



// strip
String.prototype.strip =  function() {
    return this.replace(/^\s+/, '').replace(/\s+$/, '');
 }

// text 타입의 element strip
function form_strip(f) {
	var elList = f.getElementsByTagName("input");
	for (i=0;i<elList.length;i++ ){
		if (elList[i].type.toLowerCase() == "text" || elList[i].type.toLowerCase() == "textarea"){
			elList[i].value = elList[i].value.strip();
		}
	}
}



/* -------------------------- 필수 입력 필드의 입력값 체크 함수 START ----------------------------------*/
/*
chk_field 함수 이외에 chk_range, chk_radio를 함께 사용한다.

chk_field에서의 체크 종류
 - null    : 값이 없으면 false
 - email   : email 형식에 맞지 않으면 false
 - checked : checkbox가 체크되어있지 않으면 false
 - number  : 값이 숫자로만 되어있으면 true
 - alpha   : 값이 알파벳으로만 되어있으면 true
 - alnum   : 값이 알파벳, 숫자, 언더바로만 되어있으면 true


* 사용예 )
function chk_f(f) {
	return (chk_field ($("#usr_id")  , "null"     , "아이디")
		&&  chk_range ($("#usr_id")  , 4, 10      , "아이디")
		&&  chk_field ($("#usr_id")  , "email"    , "이메일")
		&&  chk_field ($("#usr_pass"), "null"     , "비밀번호")
		&&  chk_field ($("#chkbox")  , "checked"  , "체크박스")
		&&  chk_field ($("#sel")     , "null"     , "선택")
		&&  chk_radio (f.radioName   , "radio체크")
	);
}
*/
function chk_field(field, check, msg) {
	var v = field.val();
	if (v != undefined) {

		switch (check) {
			case "null" : // null 체크
				if (v == "") {
					alert (msg+" : 필수 입력 사항입니다.");
					field.select();
					field.focus();
					return false;
				}
			break;

			case "checked" : // 체크박스
				if(field.attr("checked")!=true) {
					alert (msg+" : 필수 체크 사항입니다.");
					field.focus();
					return false;
				}
			break;

			case "email" : // 이메일
				if (!chk_mail(v)) {
					alert ("올바른 메일주소가 아닙니다.");
					field.select();
					field.focus();
					return false;
				}
			break;

			case "number" : // 숫자만 입력.
				if (!chk_num1(v)) {
					alert (msg+" : 숫자만 입력 가능합니다..");
					field.select();
					field.focus();
					return false;
				}
			break;

			case "alpha" : // 영문
				if (!chk_alpha(v)) {
					alert (msg+" : 영문만 입력 가능합니다..");
					field.select();
					field.focus();
					return false;
				}
			break;

			case "alnum" : // 영문, 숫자, 언더바(_)
				if (!chk_hangul2(v)) {
					alert (msg+" : 영문, 숫자, 언더바(_)만 입력 가능합니다..");
					field.select();
					field.focus();
					return false;
				}
			break;
		}
	}

	return true;
}


// radio checked
function chk_radio(field, msg) {
	var TF = false;
	for(i=0; i<field.length; i++) {
		if (field[i].checked) {
			TF = true;
			break;
		}
	}
	if(!TF) alert (msg+" : 필수 선택 사항입니다.");
	return TF;
}

// 글자 수 체크.
//min: 최소글자수, max: 최대글자수
function chk_range(field, min, max, msg) {
	var v = field.val();
	if (v != undefined) {
		if (v.length >= min && v.length <= max) return true;
		else {
			alert (msg+" : "+min+"글자 이상, "+max+"글자 이하로 입력하세요.");
			field.select();
			field.focus();
			return false;
		}
	}
}
/* -------------------------- 필수 입력 필드의 입력값 체크 함수 END ---------------------------------- */




 
// number_format()
function number_format(num) {
	var num_str = num.toString()
	var result = ''

	for(var i=0; i<num_str.length; i++) {
		var tmp = num_str.length-(i+1)
		if(i%3==0 && i!=0) result = ',' + result
		result = num_str.charAt(tmp) + result
	}

	return result
}
 

// 숫자 check
function chk_num1(toCheck) 
{
   for (j = 0; j < toCheck.length ; j++)
   {
      if ( (toCheck.substring(j,j+1) < "0") || (toCheck.substring(j,j+1) > "9") ) return false;
   }
   return true;
}


// 숫자, ".", "-" 만 존재하면 true
function chk_num2(toCheck) 
{
   for (j = 0; j < toCheck.length ; j++) 
   {
      if ( (toCheck.substring(j,j+1) < "0") || (toCheck.substring(j,j+1) > "9") ) 
      {
         if ( (toCheck.substring(j,j+1) == ".") || (toCheck.substring(j,j+1) == "-") ) continue;
         return false;
      }
   }
   
   return true;
}

// 숫자, "-" 만 존재하면 true

function chk_num3(toCheck) 
{
   for (j = 0; j < toCheck.length ; j++) 
   {
      if ( (toCheck.substring(j,j+1) < "0") || (toCheck.substring(j,j+1) > "9") ) 
      {
         if (toCheck.substring(j,j+1) == "-") continue;
         return false;
      }
   }
   
   return true;
}

// 한글 check. 한글이 존재하면 false
function chk_hangul(toCheck) 
{
    var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890`!@#$%^&*()-=_+~[]\{}|,./<>?";
    
    for (i=0; i< toCheck.length; i++)
    {
        idcheck = toCheck.charAt(i);
        
        for ( j = 0 ;  j < str.length ; j++)
        {
        
            if (idcheck == str.charAt(j)) break;
                
            if (j+1 == str.length)
            {
                return false;
            }
        }
    }
    return true;
}

//영어,숫자, _ 만 가능
function chk_hangul2(toCheck) 
{
    var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890_";
    
    for (i=0; i< toCheck.length; i++)
    {
        idcheck = toCheck.charAt(i);
        
        for ( j = 0 ;  j < str.length ; j++)
        {
        
            if (idcheck == str.charAt(j)) break;
                
            if (j+1 == str.length)
            {
                return false;
            }
        }
    }
    return true;
}

//영어만 가능
function chk_alpha(toCheck) 
{
    var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    
    for (i=0; i< toCheck.length; i++)
    {
        idcheck = toCheck.charAt(i);
        
        for ( j = 0 ;  j < str.length ; j++)
        {
        
            if (idcheck == str.charAt(j)) break;
                
            if (j+1 == str.length)
            {
                return false;
            }
        }
    }
    return true;
}


// Email check
function chk_mail(toCheck) 
{
    // @표시 확인
    if (toCheck.indexOf('@') == -1 ) 
    { 
        return false; 
    }

    // .표시 확인
    if (toCheck.indexOf('.') == -1 ) 
    { 
        return false; 
    }
    
    // 한글 확인
    if ( chk_hangul(toCheck) == false ) 
    { 
        return false; 
    }
    
    return true;
}


// 주민번호 check
function chk_juminno(obj) 
{
	if (obj.length == 14) {
        var calStr1 = "2345670892345", biVal = 0, tmpCal, restCal;

        for (i=0; i <= 12; i++) {
            if (obj.substring(i,i+1) == "-") tmpCal = 1;
            else biVal = biVal + (parseFloat(obj.substring(i,i+1)) * parseFloat(calStr1.substring(i,i+1)));
        }
        restCal = 11 - (biVal % 11);
        if (restCal == 11) restCal = 1;
        if (restCal == 10) restCal = 0;
        if (restCal == parseFloat(obj.substring(13,14))) return true;
        else return false;
	}
	else return false;
}



// window 띄우기
function open_win(URL, name, width, height) 
{
    msgWindow=window.open(URL,name,'location=0,toolbar=no,width='+width+',height='+height+',directories=no,status=no,scrollbars=Yes,resizable=no,menubar=no,border=0');
    msgWindow.focus()
}

// window 띄우기, no scroll
function open_win1(URL, name, width, height) 
{
    msgWindow=window.open(URL,name,'location=0,toolbar=no,width='+width+',height='+height+',directories=no,status=no,scrollbars=No,resizable=no,menubar=no,border=0');
    msgWindow.focus()
}

// window 띄우기
function open_win_XY(URL, name, width, height) 
{
    msgWindow=window.open(URL,name,'location=0,toolbar=no,width='+width+',height='+height+',directories=no,status=no,scrollbars=Yes,resizable=Yes,menubar=no,border=0,screenX=0,screenY=0');
    msgWindow.focus()
}

// 기본 팝업창
function view_open(url,name,features) { 
    window.open(url,name,features);
}


// 파일 첨부시 파일첨부 됐는지 체크
function att_field_isNotnull() {
	var rtn = true;
	var iframe_att = document.getElementById("attach_iframe");
	if (iframe_att) {
		fDoc = iframe_att.contentWindow || iframe_att.contentDocument;
		if (fDoc.document.getElementById("pfile") && fDoc.document.getElementById("pfile").value) {
			alert("먼저 첨부하기 버튼을 클릭하여 파일첨부를 완료해 주세요.");
			rtn = false;
		}
	}
	return rtn;
}

//박선영추가
<!--  Flash Script -->
function write_swf(src,w,h,pnum,snum) {
 html = '';
 html += '<object type="application/x-shockwave-flash" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" id="param" width="'+w+'" height="'+h+'">';
 html += '<param name="movie" value="'+src+'">';
 html += '<param name="quality" value="high">';
 html += '<param name="bgcolor" value="#ffffff">';
 html += '<param name="swliveconnect" value="true">';
 html += '<param name="menu" value="false">';
 html += '<param name="wmode" value="transparent">';
 html += '<embed src="'+src+'" quality=high bgcolor="#ffffff" width="'+w+'" height="'+h+'" swliveconnect="true" id="param" name="param" wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="pNum='+pnum+'&sNum='+snum+'"><\/embed>';
 html += '<\/object>';
 document.write(html);
}

<!--  Flash Script End -->


