
// Add Event
var _isIE = (document.all) ? true : false;

function addEvent(element, event, callback) {
	if (!element) return;
	if (_isIE)	element.attachEvent('on'+event, callback);
	else		element.addEventListener(event, callback, true);
}

function removeEvent(element, event, callback) {
	if (!element) return;
	if (_isIE)	element.detachEvent('on'+event, callback);
	else		element.removeEventListener(event, callback, true);
}

function eventCancel(e) {
	if (_isIE && !e)
		e=window.event;
	if (e.preventDefault)
		e.preventDefault();
	else
		e.returnValue= false;
	return false;
}



// 레이어 토글 (v: 보여질 레이어 ID, h:숨겨질 레이어 ID)
function layer_toggle(v,h)  {
	if (v && h && $(v) && $(h)) {
		$(v).style.display = "block";
		$(h).style.display = "none";
	}
}

// 우편번호 찾기
function Winzip() {
	window.open('/member/zipcode.php', '_zipcode', 'width=417, height=400, scrollbars=1,toolbars=0,statusbar=0');
}


// 로그인 체크
function notLogin(url){
	alert ("먼저 로그인 하세요.");
	if(url)	window.location.href="/member/login.php?q_path_ec="+url
	else 	window.location.href="/member/login.php";
}

function cmtnotLogin(url){
	alert ("먼저 로그인 하세요.");
	if(url)	parent.window.location.href="/member/login.php?q_path_ec="+url
	else 	parent.window.location.href="/member/login.php";
}		




// 파일 첨부시 파일첨부 됐는지 체크
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;
}

/*----- Form 의 input type="text" 인 element 의 value를 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 ----------------------------------*/
/*
	field ID 와 필드이름을 전달한다.
	checkbox는 msg에 전체 경고문구를 전달한다.
	radio 버튼은 null_chk_field가 아닌 radio_chk_field 를 이용하여 체크한다.

	사용예 )
		function chk_f(f) {
			return (
					null_chk_field ("a_id"  , "Admin ID")
				&&  null_chk_field ("a_pass", "Password")
				&&  null_chk_field ("sel", "셀렉트박스")
				&&  radio_chk_field (f.radio_fld_name, "라디오버튼.")
				&&  null_chk_field ("chk", "체크박스를 체크하세요")
			);
		}
*/

// filed  null check (field : filed ID, msg : 미입력시 message)
function null_chk_field(field, msg) {

	// input type에따라 
	if ($(field))
	{
		switch ($(field).type.toLowerCase()) {
			case 'select-one': // 1개만 선택가능한 Select box 
				if($F(field) == '' || $F(field) == '선택' || $F(field) == null) {
					alert (msg+" : 필수입력 사항입니다.");
					$(field).activate();
					return false;
				}
				break;


			case 'checkbox': // Checkbox, msg에서 경고문구 전체를 받는다.
				if(!$(field).checked) {
					alert (msg);
					$(field).activate();
					return false;
				}
				break;


			default :	// text, textarea 필드
				if($F(field) == '' || $F(field) == null) {
					alert (msg+" : 필수입력 사항입니다.");
					//$(field).activate();
					if (field != 'content') $(field).activate(); // editor에서 field명이 content일경우를위해 content는 제외,,
					return false;
				}

				if ($(field).getAttribute("check") && $(field).getAttribute("check").toLowerCase() != "") { // check 항목이 있을경우

					switch ($(field).getAttribute("check").toLowerCase()) {

						case "email" :	// 이메일체크
							if (!chk_mail($F(field))) {
								alert ("올바른 메일주소가 아닙니다.");
								$(field).activate();
								return false;
							}
							break;

						
						case "number" : // 숫자만 입력.
							if (!chk_num1($F(field))) {
								alert (msg+" : 숫자만 입력 가능합니다..");
								$(field).activate();
								return false;
							}
							break;

						case "chk_engnum" : // 영문, 숫자, 언더바(_)
							if (!chk_hangul2($F(field))) {
								alert (msg+" : 영문, 숫자, 언더바(_)만 입력 가능합니다..");
								$(field).activate();
								return false;
							}
							break;

						case "min_len" :	// 최소 몇글자 이상?
							if ($(field).getAttribute("min_len")) {
								if ($F(field).length < Number($(field).getAttribute("min_len"))) {
									alert (msg+" : "+$(field).getAttribute("min_len")+" 글자 이상으로 입력하세요.");
									$(field).activate();
									return false;
								}
							}
							break;

						
						// case 추가,,,,,,,,,,,,,,,,,,,,,,,,,,,,
					}
				}
		}
	}

	return true;
}

// radio null check (field : filed name, msg : 미입력시 message)
function radio_chk_field(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;
}
/* -------------------------- 필수 입력 필드의 입력값 체크 함수 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(space 처리)
// null => true
function chk_null(toCheck) 
{
    for (var i = 0; i < toCheck.length; i++)
        if (toCheck.substring(i, i+1) != " ") return false;
        
    return true;
}

// 공백 check (값이 없을경우 true)
// null => true
function chk_null2(toCheck)
{
    var chkstr = toCheck + "";
        
    if ((chkstr == "") || (chkstr == null)) 
    {
        return true;
    }

    return false;
}

// 숫자만 입력받음
function NumObj(obj) {

	if (event.keyCode >= 48 && event.keyCode <= 57) { //숫자키만 입력
		return true;
	} else {
	event.returnValue = false;
	}
}

// 숫자 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
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_hangul3(toCheck) 
{
    var str = "1234567890`!@#$%^&*()-=_+~[]\{}|,./<>?";
    
    for (i=0; i< toCheck.length; i++)
    {
        idcheck = toCheck.charAt(i);
        
        for ( j = 0 ;  j < str.length ; j++)
        {
            if (idcheck == str.charAt(j)){
				return false;
			}                
            if (j+1 == str.length) break;
        }
    }
    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);
}





/* 
Flash Embed 스크립트 

function swf(src, src_id, w, h, _wmode, _zindex) {
	var wmode  = (_wmode)  ? _wmode  : 'window';
	var zIndex = (_zindex) ? _zindex : 0;

	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=8,0,0,0" id="'+src_id+'" width="'+w+'" height="'+h+'" z-index="'+zIndex+'">';
	html += '<param name="movie" value="'+src+'">';
	html += '<param name="wmode" value="'+wmode+'">';
	html += '<param name="quality" value="high">';
	html += '<param name="bgcolor" value="#ffffff">';
	html += '<param name="swliveconnect" value="true">';	
	html += '<embed src="'+src+'" quality=high bgcolor="#ffffff" width="'+w+'" height="'+h+'" swliveconnect="true" id="'+src_id+'" name="'+src_id+'" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"  wmode="'+wmode+'" z-index="'+zIndex+'"><\/embed>';
	html += '<\/object>';
	document.write(html);
}*/


function swf(src, w, h) {
	var src_arr = src.split("/");
	var src_file = src_arr[src_arr.length -1]
	var src_id = src_file.substr(0,src_file.length-4);
	//alert(src_id);

	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=10,0,22,87" id="'+src_id+'" 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="wmode" value="transparent">';
	html += '<embed src="'+src+'" quality=high bgcolor="#ffffff" width="'+w+'" height="'+h+'" swliveconnect="true" id="'+src_id+'" name="'+src_id+'" wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"><\/embed>';
	html += '<\/object>';
	document.write(html);
}

/*-------------------------------------------------------
 * 일반 asf, wmv 파일 출력
--------------------------------------------------------*/
function vod_play(play_url, width, height) {

    var width_val = 550;
    var height_val = 410;
    if(width) width_val = width;
    if(height) height_val = height;
	str = "<object id=\"vodPlay\" width="+width_val+" height="+height_val+" viewastext style=\"z-index:1\" classid=\"CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6\" standby=\"Loading Microsoft Windows Media Player components...\" type=\"application/x-oleobject\">"
        + "<param name=\"URL\" value=\""+play_url+"\">"
        + "<param name=\"ANIMATIONATSTART\" value=\"0\">"
        + "<param name=\"AUTOSTART\" value=\"1\">"
        + "<param name=\"BALANCE\" value=\"0\">"
        + "<param name=\"CURRENTMARKER\" value=\"0\">"
        + "<param name=\"CURRENTPOSITION\" value=\"0\">"
//        + "<param name=\"DISPLAYMODE\" value=\"4\">"
        + "<param name=\"ENABLECONTEXTMENU\" value=\"0\">"
        + "<param name=\"ENABLED\" value=\"1\">"
        + "<param name=\"FULLSCREEN\" value=\"0\">"
        + "<param name=\"INVOKEURLS\" value=\"-1\">"
        + "<param name=\"PLAYCOUNT\" value=\"1\">"
        + "<param name=\"RATE\" value=\"1\">"
        + "<param name=\"SHOWCONTROLS\" value=\"1\">"
        + "<param name=\"SHOWSTATUSBAR\" value=\"1\">"
        + "<param name=\"STRETCHTOFIT\" value=\"1\">"
        + "<param name=\"TRANSPARENTATSTART\" value=\"1\">"
        + "<param name=\"UIMODE\" value=\"FULL\">"
        + "<embed width='"+width_val+"' height='"+height_val+"' ANIMATIONATSTART='0' AutoStart='1' CURRENTMARKER='0' CURRENTPOSITION='0' ENABLECONTEXTMENU='0' ENABLED='1' INVOKEURLS='-1' PLAYCOUNT='1' RATE='1' ShowControls='1' ShowStatusBar='1' STRETCHTOFIT='1' TRANSPARENTATSTART='1' UIMODE='FULL' type='video/x-ms-asf-plugin' pluginspage='http://www.microsoft.com/korea/windows/windowsmedia/' src='"+play_url+"'></embed>"
        + "</object>"
	document.write(str);
}

//quickmenu
function initMoving(target) {
	if (!target)
		return false;	
	var obj = target;
	obj.initTop = 0;	
	//obj.initLeft = document.body.offsetWidth/2 +417;
	obj.initLeft = 0;
	//obj.bottomLimit = document.body.scrollHeight - 220;
	obj.bottomLimit = document.documentElement.scrollHeight - 220;
	obj.topLimit = 0;

	obj.style.position = "absolute";
	obj.top = obj.initTop;
	obj.left = obj.initLeft;
	obj.style.top = obj.top + "px";
	obj.style.left = obj.left + "px";

	obj.getTop = function() {
		if (document.documentElement.scrollTop) {
			return document.documentElement.scrollTop;
		} else if (window.pageYOffset) {
			return window.pageYOffset;
		} else if (document.body.scrollTop) {
			return document.body.scrollTop;
		} else {
			return 0;
		}
	}
	obj.getHeight = function() {
		if (self.innerHeight) {
			return self.innerHeight;
		} else if(document.documentElement.clientHeight) {
			return document.documentElement.clientHeight;
		} else {
			return 500;
		}
	}

	obj.move = setInterval(function() {		
		//alert(obj.getTop());
		pos = obj.getTop();

		if (pos > obj.bottomLimit)
			pos = obj.bottomLimit
		if (pos < obj.topLimit)
			pos = obj.topLimit

		interval = obj.top - pos;
		obj.top = obj.top - (interval / 3);
		obj.style.top = obj.top + "px";		
	}, 40)	
}






// 메인 페잉지 팝업레이어 보기
var main_layer_pos = 0;
var main_layer_mod = false;
function main_search_layer(v) {

	main_layer_pos = -427;

	if (v==3 || (v==1 && !main_layer_mod)) {
		$("main_search_layer").style.left = main_layer_pos + "px";
		$("main_search_layer").style.visibility= "visible";
		$("open_btn").style.display= "none";
		$("close_btn").style.display= "block";
		all_menu_interval=setInterval(move_all_menu, 30);
	}
	else if (v==2 || (v==0 && !main_layer_mod)) {
		main_layer_pos = 427;
		$("open_btn").style.display= "block";
		$("close_btn").style.display= "none";
		all_menu_interval2=setInterval(move_all_menu2, 30);
	}

	if (v==2 || v==3) main_layer_mod=true;
	
}
function move_all_menu() {
	main_layer_pos = parseInt(main_layer_pos - (main_layer_pos*0.3));
	$("main_search_layer").style.left = main_layer_pos + "px";
	if (0 <= main_layer_pos) clearInterval(all_menu_interval);
}

function move_all_menu2() {
	main_layer_pos = parseInt(main_layer_pos - (main_layer_pos*0.3));
	$("main_search_layer").style.left = (main_layer_pos-427) + "px";
	if (0 >= main_layer_pos) clearInterval(all_menu_interval2);
}
