
// 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;
}


function notLogin() {
	alert("로그인 후 이용하세요");
}


// 기술단신 layer open (v: open, close)
// sel : id num (1 ~ 12)
// v   : open,close
function pop_overview(sel, v) {
	// 우선 모든 레이어 감춤
	for (var i=1; i<13; i++) {
		if($("pop_layer_overview_"+i)) {
			$("pop_layer_overview_"+i).style.visibility = "hidden";
		}
	}
	// overview5 우선 모든 레이어 감춤
	for (var i=1; i<13; i++) {
		if($("pop_layer_overview_5_"+i)) {
			$("pop_layer_overview_5_"+i).style.visibility = "hidden";
		}
	}
	if (v == 'open') $("pop_layer_overview_"+sel).style.visibility = "visible";	// open 선택된 레이어 보이기
}

		

// Flash Embed 스크립트 -- 사용예 : <script>swf("/images/flash/a.swf", 100, 50)</script>
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=8,0,0,0" 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 += '<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"><\/embed>';
	html += '<\/object>';
	document.write(html);
}


// Flash Embed 스크립트 -- 사용예 : <script>swf_tran("/images/flash/a.swf", 100, 50)</script>  -- 탑메뉴 
function swf_tran(src, w, h, v) {
	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=8,0,0,0" 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="wmode" value="transparent">';

	if (v != "") {
		html += '<param name="FlashVars" value="'+v+'">';
	}

	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+'" wmode="transparent"  type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"><\/embed>';
	html += '<\/object>';
	document.write(html);
}


// movie embed 스크립트
/*-------------------------------------------------------
 * 일반 asf, wmv 파일 출력
--------------------------------------------------------*/
function vod_play(play_url, width, height) {

    var width_val = 320;
    var height_val = 310;
    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=0 height=0 type='application/x-mplayer2' pluginspage='http://www.microsoft.com/Windows/MediaPlayer/download/default.asp' AutoStart='1' ShowControls='1' ShowStatusBar='1' ShowDisplay='1' ShowTracker='1' src='"+play_url+"'></embed>"

        + "</object>"

	document.write(str);
}




/* roll over-out image */
function menuOver() {
	this.src = this.src.replace(".jpg", "_on.jpg");
}
function menuOut() {
	this.src = this.src.replace("_on.jpg", ".jpg");
}
function initImgEffect(ImgEls,SelImg) {

	if (SelImg && SelImg > 0) SelImg = SelImg -1;
	else return;



	MenuImg = document.getElementById(ImgEls).getElementsByTagName("img");
	MenuImgLen = MenuImg.length;

	for (i=0; i<MenuImgLen; i++) {
		MenuImg.item(i).onmouseover = menuOver;
		MenuImg.item(i).onmouseout = menuOut;
		if (i == SelImg) {
			MenuImg.item(i).onmouseover();
			MenuImg.item(i).onmouseover = null;
			MenuImg.item(i).onmouseout = null;
		}
	}
}



// 좌측메뉴 롤오버.
function initSubmenu(depth1, depth2, depth3) {
	selectDepth1 = "menu" + depth1 + "-" + depth2;
	selectDepth2 = "menu" + depth1 + "-" + depth2 + "-" + depth3;

	nav = document.getElementById("leftmenu");
	menuEl = nav.getElementsByTagName("img");

	for(i = 0; i < menuEl.length; i++) {
		if (menuEl.item(i).id == selectDepth1 || menuEl.item(i).id == selectDepth2  ) {
			menuEl.item(i).src = menuEl.item(i).src.replace(".jpg", "_on.jpg");
		} 
	}
}



// FAQ 롤오버.
function txt_roll(str) {
	if (document.getElementById(str).style.display=="none") {document.getElementById(str).style.display="";}
	else if (document.getElementById(str).style.display=="") {document.getElementById(str).style.display="none";}
	else return false;

}


/*----- 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);
}




// 스크롤바 최상단의 위치.
function getScrollTop() {
	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;
	}
}

// iframe에서 부모창의 스크롤바 최상단의 위치.
function getScrollTop_parent() {
	if (parent.document.documentElement.scrollTop) {
		return parent.document.documentElement.scrollTop;
	} else if (parent.window.pageYOffset) {
		return parent.window.pageYOffset;
	} else if (parent.document.body.scrollTop) {
		return parent.document.body.scrollTop;
	} else {
		return 0;
	}
}

// wrap의 height가 일정크기 이하일경우 늘려주기
function body_height_resize() {
	var wrap_height;

	if ($("wrap")) {
		wrap_height = (document.all) ? document.getElementById("wrap").scrollHeight : document.getElementById("wrap").offsetHeight;

		if (wrap_height < 450) {

			// 내부에 iframe 있는지 확인
			var iframes = $("wrap").getElementsByTagName("iframe");
			if (iframes.length || $("faq1")) {
				//wrap_height = (document.all) ? iframes[0].contentWindow.document.body.scrollHeight : iframes[0].contentWindow.document.body.offsetHeight;
				//if (wrap_height < 360) $("wrap").style.height = "460px";
			}
			else {
				$("wrap").style.height = "450px";
			}
		}
	}
}


// onload 완료시 실행 func
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}


