//////////////////////////////////////
// IE Embed patch
//
// @author iezn@iezn.com
// @homepage http://iezn.com
// @create date 2006.04.19
// @last modify 2007.02.15
// @version 0.42
// 배포시 위내용을 포함해 주시기 바랍니다
//////////////////////////////////////
/**
* embed 패치 적용 컨테이너
* null인경우 document 값을 기본으로 합니다
* id값을 설정한경우 설정범위 내에만 적용이 됩니다
* 
* 본문이나 일부 노드에만 적용할경우 해당 노드의 id 값을 입력하실 수 있습니다
* 예)
* var __embed_target_id = "contents";
* 로 처리한경우 body 내에 <태그 id="contents">플래쉬,동영상...</태그>
* 안에 내용에만 패치가 적용됩니다
*/
if(typeof(__embed_target_id)=='undefined'){
	var __embed_target_id = null;
}

/**
* embed 패치를 적용할 태그를 설정합니다
* 기본값은 object,eembed,appelt 태그입니다
* false 값인경우 패치에서 제외됩니다
*/
if(typeof(__embed_tags)=='undefined'){
	var __embed_tags = {object:true,embed:true,applet:false}
}

/**
* 플래쉬파일중 flashvars 를 사용할경우 해당 플래쉬의 오브젝트아이디:true 값으로 object를 등록해 주세요
*/
var __flash_force_objs = {};
if(navigator.userAgent.toLowerCase().indexOf('opera')==-1){//opera out
	if(document.attachEvent){
		document.write('<style type="text/css">');
		document.write('object,embed{display:none;}');
		document.write('</style>');
		document.attachEvent('onreadystatechange',
			function (){				
				if(__embed_target_id===null){
					var __target = document;
				}else{
					var __target = document.getElementById(__embed_target_id);
				}
				if (document.readyState == "complete"){
					function _replace(obj){
						var obj_re = document.createElement(obj.outerHTML);					
						obj_re.style.display='inline';
						obj.parentNode.replaceChild(obj_re,obj);
					}
					function _inner(obj){
						obj.style.display='inline';					
						var html = obj.outerHTML;
						var classid = obj.classid.toLowerCase();
						if(classid=='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' && typeof(__flash_force_objs[obj.id])=='undefined'){//flash 인경우
							obj.insertAdjacentHTML('beforeBegin',html);
							obj.parentNode.removeChild(obj);
						}else if(classid=='clsid:02bf25d5-8c17-4b23-bc80-d3488abddc6b'){
							//퀵타임

						}else{
							//변경하고자하는 ActiveX classid 를 추가하시기 바랍니다
							if(classid=='clsid:6bf52a52-394a-11d3-b153-00c04f79faa6' || //media 7
							classid=='clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95' || //6.4
							classid=='clsid:6bf52a52-394a-11d3-b153-00c04f79faa6' ||
							classid=='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'
							){
								embed_pos = html.indexOf('embed');
								if(embed_pos!=-1){//embed 가 존재하는경우
									var embed = '<'+html.substr(embed_pos);
									embed = embed.substr(0,embed.length-9);
									obj.insertAdjacentHTML('beforeBegin',embed);
									obj.parentNode.removeChild(obj);
								}else{
									//object로만 되어 있는경우 동영상 부분만 패치한다
									var embed = document.createElement('embed');
									if(obj.id){
										embed.id = obj.id;
									}
									var total = obj.childNodes.length;
									//embed.setAttribute('autostart',0);
									if(obj.width){
										embed.setAttribute('width',obj.width);
									}
									if(obj.height){
										embed.setAttribute('height',obj.height);
									}
									for(var k=0;k<total;k++){
										n = obj.childNodes.item(k).getAttribute("name");
										v = obj.childNodes.item(k).getAttribute("value");
										if(n=='URL' || n=='url' || n=='FileName'){
											n = 'src';
										}
										embed.setAttribute(n,v);
									}
									if(embed.getAttribute('src')){
										embed.style.display = 'inline';
										obj.parentNode.replaceChild(embed,obj);
									}else{
										//파일엑세스 object가 아닌경우는 유지한다								
									}
								}
							}
						}
					}

					if(__embed_tags.object===true){
						var objs = __target.getElementsByTagName('object');
						var i = objs.length;
						while(i-->0){
							_inner(objs[i]);
						}
					}
					if(__embed_tags.embed===true){
						var objs = __target.getElementsByTagName('embed');
						var i = objs.length;
						while(i-->0){
							_replace(objs[i])
						}
					}

					if(__embed_tags.applet===true){
						var objs = __target.getElementsByTagName('applet');
						var i = objs.length;
						while(i-->0){
							_replace(objs[i])
						}
					}
				}
			}
		);
	}
}



/**
 * 새로운 팝업창을 열 경우
 * @param pUrl  팝업URL
 * @param pNm  팝업이름
 * @param pStatus  팝업창의 상태바[yes, no]
 * @param pToolbar  팝업창의 툴바[yes, no]
 * @param pResize  팝업창의 리사이즈여부[yes, no]
 * @param pScroll  팝업창의 스크롤바여부[yes, auto, no]
 * @param pMenubar  팝업창의 메뉴바여부[yes, no]
 * @param pWidth  팝업창의 가로
 * @param pHeight  팝업창의 세로
 * @param pTop  팝업창의 상단여백
 * @param pLeft  팝업창의 왼쪽여백
 */
function WinPopupOpen(pUrl, pNm, pStatus, pToolbar, pResize, pScroll, pMenubar, pWidth, pHeight, pTop, pLeft){

	//쿠키에서 OS체크 : var OsVer = document.GNax.GetOsVer
	//win2000기준으로 하시면 될것같습니다.

	//변수 초기화
	pNm = (pNm == null) ? '' : pNm;
	pStatus = (pStatus == null) ? 'no' : pStatus;
	pToolbar = (pToolbar == null) ? 'no' : pToolbar;
	pResize = (pResize == null) ? 'no' : pResize;
	pScroll = (pScroll == null) ? 'no' : pScroll;
	pMenubar = (pMenubar == null) ? 'no' : pMenubar;
	pWidth = (pWidth == null) ? 0 : pWidth;
	pHeight = (pHeight == null) ? 0 : pHeight;

	pTop = (pTop == null) ? 0 : pTop;
	pLeft = (pLeft == null) ? 0 : pLeft;

	//팝업이름에따라 스크롤여부 지정
	if (pNm=="notice"){
		pScroll= 'yes';
	}

	var Option = "status="+pStatus+",toolbar="+pToolbar+",resizable="+pResize+",scrollbars="+pScroll+", menubar="+pMenubar+",width="+pWidth+",height="+pHeight+",top="+pTop+",left="+pLeft+"";
	var  ObjWin = window.open(pUrl, pNm, Option);
	ObjWin.focus();
}

//iframe height 자동조정
function ifr_load(name)
{
    var obj = eval("document.frames('"+name+"').document.body");
    var h = obj.scrollHeight + (obj.offsetHeight - obj.clientHeight);

    eval("document.all."+name+".style.height = h");
}


//email 체크
function isEmail(s)
{
  return s.search(/^\s*[\w\~\-\.]+\@[\w\~\-]+(\.[\w\~\-]+)+\s*$/g)>=0;
}

//url체크
function urlCheck(s){
  return s.search(/^\s*['http://']+[\w\~\-\.]+\.[\w\~\-]+(\.[\w\~\-]+)+\s*$/g)>=0;
}

//쿠키함수
function setCookie( name, value, expiredays )
{
	var todayDate = new Date();
	if(expiredays!="") todayDate.setDate( todayDate.getDate() + expiredays );	
	else todayDate.setDate( todayDate.getDate() - 30 );	
	document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.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 OnlyNumber(obj) {
	var data = obj.value;
	var s = '01234567890';
	var re_data = String(data);
	
	for ( var i = 0 ; i < re_data.length ; i++ ) {
		if ( s.indexOf( re_data.substring( i, i+1 ) ) == -1 ) {
			alert("숫자만 가능합니다.");
			obj.value = '';
			obj.focus();		
		}
	}
}

//넘버포맷체크
function isNumeric(data) {
	var s = '01234567890';
	var re_data = String(data);
	
	for ( var i = 0 ; i < re_data.length ; i++ ) {
		if ( s.indexOf( re_data.substring( i, i+1 ) ) == -1 )
			return true;
	}
	return false;
}
//영어포맷체크
function isNonAlpa(data) {
	var s = 'qwertyuiopasdfghjklzxcvbnm01234567890';
	var re_data = String(data);
	
	
	for ( var i = 0 ; i < re_data.length ; i++ ) {
		if ( s.indexOf( re_data.substring( i, i+1 ) ) > 0 )
			return false;
	}
	return true
}

//이미지 파일체크
function CheckImageFile(ImageFile)
{
	var extFile = ImageFile.split("\\");
	var ImgInfo = extFile[extFile.length-1];
	var ext = ImgInfo.split(".");
	if (ext[1].toUpperCase() == "JPG" || ext[1].toUpperCase() == "GIF"){
		if (isKorean(ext[0])){
			return true;
		}else{
			return false;
		}
	} else
		return false;
}

//한국어체크
function isKorean(ch)
{
	var numUnicode = ch.charCodeAt(0);
	if ( 44032 <= numUnicode && numUnicode <= 55203 ) return false;
		return true;
}


//================================================================ 
// 문자열 바이트 알아내기 
//================================================================ 
function cm_get_byte(str) { //문자열의 byte 길이를 알아냄(한글 2byte로 처리) 
    var i,m=str.length, re_count=0,val = 0;; 
    for(i=0;i<m;i++) { 
        val = escape(str.charAt(i)).length; 
        if(val>3) re_count++; 
        re_count++; 
    } return re_count; 
} 
function cm_get_byte_length(str,limit_byte){ //지정된 바이트 길이만큼의 length를 반환, 홀수로 짤리면 -1의 길이반환 
    var i,m=str.length, re_count=0,val = 0;; 
 var len_count = 0; 
    for(i=0;re_count<limit_byte ;i++) { 
        val = escape(str.charAt(i)).length; 
  len_count++; 
        if(val>3) re_count++; 
        re_count++; 
    } 
 if(re_count%2 == 1)  return (len_count-1); 
 else  return (len_count); 
} 
//================================================================ 
// 입력 글자바이트 제한 (필수 : 문자열 바이트 알아내기) 
//  textarea에 사용 
//================================================================ 
function input_textarea_limit_byte(ta,limit){ 
    var layout = document.createElement('table'); 
//    layout.border='2';     
    layout.style.padding='0px'; 
    layout.style.margin='0px'; 
    if(ta &&ta.style && ta.style.width){ 
        layout.style.width=ta.style.width 
    } 
    layout.border="0"; 
    layout.cellspacing="0"; 
    layout.cellpadding="0"; 
    var tr1 = layout.insertRow(-1); 
    var td1 = tr1.insertCell(-1); 
    td1.style.padding='0px'; 
    td1.style.textAlign='right'; 
    var tr2 = layout.insertRow(-1); 
    var td2 = tr2.insertCell(-1); 
    td2.style.padding='0px'; 
    td2.style.textAlign='right';     
     
    var txt_limit = document.createElement('input'); 
    txt_limit.type='text'; 
    txt_limit.style.borderStyle='none'; 
    txt_limit.style.textAlign='right'; 
    txt_limit.style.fontSize='10px'; 
    txt_limit.style.width='40px';     
    txt_limit.readOnly=true; 
    txt_limit.value=0; 
    var span_text1 = document.createElement('span'); 
    span_text1.innerHTML='Limit : '; 
    var span_text2 = document.createElement('span'); 
    if(limit){ 
        span_text2.innerHTML=' byte /'+limit+' byte';     
    }else{ 
        span_text2.innerHTML=' byte '; 
    } 
    var div_title = document.createElement('div'); 
    div_title.style.fontSize='10px'; 
    div_title.appendChild(span_text1); 
    div_title.appendChild(txt_limit); 
    div_title.appendChild(span_text2); 
if(ta.tagName.toString().toLowerCase()=='textarea'){    //textarea일 경우만 

    if(!ta.rows){ta.rows="3";}     
    var btn_0 = document.createElement('input'); 
    btn_0.type='button'; 
    btn_0.value='■'; 
    btn_0.style.fontSize="10px"; 
    btn_0.style.width="18px"; 
    btn_0.style.height="18px"; 
    btn_0.style.borderWidth="1px"; 
    btn_0.onclick=function(){ 
        this.blur(); 
        ta.rows='3'; 
    } 
    var btn_p = btn_0.cloneNode(true); 
    btn_p.value='▼'; 
    btn_p.onclick=function(){ 
        this.blur();         
        ta.rows=parseInt(ta.rows)+2; 
    } 
    div_title.appendChild(btn_0); 
    div_title.appendChild(btn_p); 
    } 
     
    ta.parentNode.insertBefore(layout,ta); 
    td1.appendChild(div_title); 
    td2.appendChild(ta); 
    ta.onkeyup=function(){ 
        txt_limit.value= cm_get_byte(this.value) 
        if(limit && txt_limit.value>limit){ 
            alert(limit+'Byte를 초과했습니다.'); 
            this.value = this.value.toString().substr(0,cm_get_byte_length(this.value,limit)); 
            txt_limit.value= cm_get_byte(this.value) 
        } 
    } 

    //처음 처리 
        txt_limit.value= cm_get_byte(ta.value)     
    if(limit && txt_limit.value>limit){ 
        ta.value = ta.value.toString().substr(0,cm_get_byte_length(ta.value,limit)); 
    } 
        txt_limit.value= cm_get_byte(ta.value)     
} 


// 주민등록 번호 규격에 맞게 123456-1234567 //검증하지 않음.
// 나머지 글자 무시
function nr_jumin(this_s) 
{ 
temp_value = this_s.value.toString();
temp_value = temp_value.replace(/[^0-9]/g,'');
temp_value = temp_value.substr(0,13);
temp_value = temp_value.replace(/([0-9]{6})([0-9]{7}$)/,"$1-$2"); 
this_s.value = temp_value;
}



/*-------------------------------------------------------------------------------*/

// 사업자 등록 번호 규격에 맞게 123-12-12345 //검증하지 않음.
// 나머지 글자 무시
function nr_company_num(this_s) 
{ 
temp_value = this_s.value.toString();
temp_value = temp_value.replace(/[^0-9]/g,'');
temp_value = temp_value.substr(0,10);
temp_value = temp_value.replace(/([0-9]{3})([0-9]{2})([0-9]{5}$)/,"$1-$2-$3"); 
this_s.value = temp_value;
} 

//============================================================================
// 이미지 자동 리사이즈
//============================================================================
function image_auto_resize(this_s,width,height){
 var ta_image = new Image();
 ta_image.src = this_s.src;
  if(!width){this_s.removeAttribute('width');
  this_s.style.width='auto';}
  else if(width < ta_image.width){
   this_s.width = width;
  }else{
   this_s.width = ta_image.width;
  }
  if(!height){this_s.removeAttribute('height');
  this_s.style.height='auto';}
  else if(height < ta_image.height){
   this_s.height = height;
  }else{
   this_s.height = ta_image.height;
  } 
}

function image_auto_resize_inarea(this_s,width,height,view){ 
//this_s안의 모든 이미지는 자동 리사이즈 된다.
 //alert(this_s.childNodes.length);
 if(!view){view=true;}
 if(!this_s){return;}
 if(this_s.nodeType!=1){return;}
 for(var i=0,m=this_s.childNodes.length;i<m;i++){
  var ta = this_s.childNodes[i];
  
  if(ta.nodeName=='IMG'){
   //ta.style.border='1px solid #333333';   
   image_auto_resize(ta,width,height);

   if(view){
    if(!ta.title){ta.title=ta.src;}
    if(!ta.onclick){
     ta.style.cursor='pointer';
     ta.onclick=function(){js_image_view(this,1);}
    }
    if(!ta.onload) 
     ta.onload=function(){image_auto_resize(this,width,height);}
    if(!ta.onmouseover)   
     ta.onmouseover=function(){image_auto_resize(this,width,height);}
   }
  }
  if(ta.childNodes.length>0){
   image_auto_resize_inarea(ta,width,height);
  }
 }
 return;

}

 /*
<img src=http://www.mins01.com/for2007/image_manager/middle/top/thisisweb.gif
onload="image_auto_resize(this,50,50);"
onmouseover="image_auto_resize(this,50,50);">
지정된 이미지에 자동 리사이즈를 적용합니다.

 image_auto_resize_inarea(document.getElementById('div_area'),100,'',true);
document.getElementById('div_area') 안에서의 모든 img에 자동 리사이즈를 적용합니다.
*/
