// 이미지 리사이징 :  onload="changeImageSize(this, document.body.clientWidth, 10);"
function changeImageSize(obj, maxwidth, imgmargin) {
	if((' '+maxwidth).length-(' '+maxwidth).replace('%','').length>0) {
		obj.width = (document.body.clientWidth * eval(maxwidth.replace('%','')) / 100) - imgmargin;
	}
	else if(obj.width > maxwidth) {
		obj.width = maxwidth-imgmargin;

	}
}

// 체크박스 전체선택/해제
// obj : 체크여부, pid : 체크/해제될 체크박스의 상위 DOM ID, chkclass : 체크/해제할 체크박스 class name
function selectCheckbox(obj, pid, chkclass) {
	var items = $(pid).getElementsByClassName(chkclass);

	if(items == null) return;
	if(items.length == null) return;

	for(var i=0 ; i < items.length ; i++) {
		if(items[i].disabled == false) {
			if(obj.checked==true) {
				items[i].checked = true;
			}
			else {
				items[i].checked = false;
			}
		}
	}

}


/* 메쉬업 처리 관련 */
var chkitem = 0;
function conv(pid, post_id, type) {
    
	if($('PostConv_'+post_id).innerHTML == '' || chkitem != type+'_'+pid+'_'+post_id) { 
		$('PostConv_'+post_id).innerHTML = "<img id='loadingimg_"+post_id+"' src='/img/loading.gif'>";
		$('PostConv_'+post_id).style.display = '';

		new Ajax.Request( '/posts/conv/?id=' + pid + '&type=' + type + '&post_id=' + post_id + '&page=1&number=0', { 
				asynchronous:true, 
				evalScripts:true, 
				onComplete:function(t) {
					try {
						$('PostConv_'+post_id).innerHTML = t.responseText;
						chkitem = type+'_'+pid+'_'+post_id;
					}
					catch(e) {
						alert(e);
						return;
					}
					
				}
			} );
	}
	else {
		$('PostConv_'+post_id).innerHTML = ''
		$('PostConv_'+post_id).style.display = 'none';
	}

}

function conv_page(pid, post_id, type, page, number) {
    
		new Ajax.Request( '/posts/conv/?id=' + pid + '&type=' + type + '&post_id=' + post_id + '&page=' + page + '&number=' + number, { 
				asynchronous:true, 
				evalScripts:true, 
				onComplete:function(t) {
					try {
						$('PostConv_'+post_id).innerHTML = t.responseText;
					}
					catch(e) {
						alert(e);
						return;
					}
					
				}
			} );

}


function map() {

		new Ajax.Request( '/posts/map/', { 
				asynchronous:true, 
				evalScripts:true, 
				onComplete:function(t) {
					try {
						if($('post_add_map').style.display == ''){
				
							$('post_add_map').style.display = 'none';
						}else{

							$('post_add_map').style.display = '';
						}
						$('post_add_map').innerHTML = t.responseText;
					}
					catch(e) {
						alert(e);
						return;
					}
					
				}
			} );

}

function closeWinToday(arg) 
{ 
	setCookie( 'COOKIE_'+arg, 'TODAY' , 1)
}

function closeWinWeek(arg) 
{ 
	setCookie( 'COOKIE_'+arg, 'WEEK' , 7)
}

function closeWinNever(arg,obj) 
{ 
	if(confirm('현재 PC에서 앞으로 이창을 보지 않으시겠습니까?')) {
		setCookie( 'COOKIE_'+arg, 'NEVER' , 365)
		hs.close(obj);
	}
}

function popupWindow(mypage,w,h,scroll,location,windowname){
var win= null;
  if (scroll==0) {
    var scrollPrn = "no"
  }
  else {
    var scrollPrn = "yes"
  }

  if (location==0) {
    var winl = 0
    var wint = 0
  }
  else {
    var winl = (screen.width-w)/2;
    var wint = (screen.height-h)/2 - 50;
  }

  if (windowname==""||windowname==null) {
  	var popwindowname = "WIN_SUB_Second";

  }
  else {
  	var popwindowname = windowname
  }

  var settings  ='height='+h+',';
      settings +='width='+w+',';

      settings +='top='+wint+',';
      settings +='left='+winl+',menubar=0, toolbar=0,location=0,directory=0,scrollbars=' + scrollPrn + ',resizable=0';
  win=window.open(mypage,popwindowname,settings);

  if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}


/* body에 onload를 사용하지않고, window.onload에 두개이상의 액션을 주기 위한... */
function addLoadEvent(funct) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = funct;
	} 
	else {
		window.onload = function() {
			oldonload();
			funct();
		}
	}
}

function afterLoad(obj,url) {
		new Ajax.Request( url, { 
				asynchronous:true, 
				evalScripts:true, 
				onComplete:function(t) {
					try {
						if(t.responseText ==null ) {
							obj.innerHTML = '';
							obj.style.display='none';
						}
						else {
							obj.innerHTML = t.responseText;
						}
					}
					catch(e) {
						alert(e.message);
						return;
					}
					
				}
			} );
}

/* 레이어 보임/감춤 */
function displayLayer(obj) {
	obj = $(obj);

	if(obj !=null) {
		if(obj.style.display==''){
			obj.style.display='none';
		}
		else {
			obj.style.display='';
		}
	}
}



/* 팝업 레이어 보임/감춤 */
function displayPopupLayer(obj,width) {
	var leftLocation = document.body.clientWidth/2 - width/2
	obj = $(obj);

	obj.style.left = leftLocation + 'px';
	obj.style.display = '';
}

/* 팝업 레이어 로그인 */
function loginLayer(id)  {
	if($('div_help_section')!=null) {
		$('div_help_section').style.display='none';
	} 

	if($('right_loginform_main')!=null) {
		if($('right_loginform_main').style.display=='none') {
			Effect.SlideDown('right_loginform_main', { duration: 0.3 });
			setTimeout("loginLayerFocus('"+id+"')", 400);
			
		} 
		else {
			Effect.SlideUp('right_loginform_main', { duration: 0.3 });
		}
	} 
	else {
		location.href='/users/outlogin';
	}
}

/* 도움말 레이어  */
function helpLayer()  {
	if($('div_help_section')!=null) {
		if($('div_help_section').style.display=='none') {
			Effect.BlindDown('div_help_section', { duration: 0.3 });
		} 
		else {
			Effect.BlindUp('div_help_section', { duration: 0.3 });
		}
	} 
}


function beforeSectionHelp()  {
	if($('top_gnb_help_active')!=null) {
		if($('top_gnb_help_active').style.display=='none') {
			if($('minicle_search_select') !=null) {
				$('minicle_search_select').style.display = 'none';

			}
			if($('circle_search_select') !=null) {
				$('circle_search_select').style.display = 'none';
			}
		} 
		else {
			if($('minicle_search_select') !=null) {
				$('minicle_search_select').style.display = '';

			}
			if($('circle_search_select') !=null) {
				$('circle_search_select').style.display = '';
			}
		}
	} 
}




/* 도움말 상세보기 레이어  */
function helpViewLayer(pid)  {
		if($('help_section_text') != null) {
			$('help_section_text').innerHTML = "<div style='text-align:center;padding-top:80px;'><img src='/img/loading.gif' align='center'></div>";
			displayPopupLayer('help_section_textarea',654);

			new Ajax.Request( '/customers/helptip/'+pid, { 
					asynchronous:true, 
					evalScripts:true, 
					onComplete:function(t) {
						try {
							$('help_section_text').innerHTML = t.responseText;
						}
						catch(e) {
							return;
						}
					}
				} );
		}
}


function loginLayerFocus(id)  {
	if($('loginpassword') != null && id !='') {
		$('loginpassword').focus();
	}
	else if($('loginid') != null) {
		$('loginid').focus();
	}
}


/* 오류 메세지 toggle */
function showMessage(msg)  {
	if(msg != "") {
		$('div-proc-message').style.display = "";
		$('span-proc-message').innerHTML = msg;

		setTimeout("hideMessage()", 1500);


	}
	else {
		$('div-proc-message').style.display = "none";
	}
}

/* 오류 메세지 감춤 */
function hideMessage()  {
		if(Effect!=null) {
			Effect.Fade('div-proc-message', { duration: 0.3 });
			//Effect.Fold('div-proc-message');
			//Effect.SwitchOff('div-proc-message');
			
		}
		else {
			$('div-proc-message').style.display = "none";
		}
}


/* 팝업등을 위한 쿠키 설정 : 쿠키값 받아옴 */
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 setCookie( name, value, expiredays ) {
	var todayDate = new Date();
	todayDate.setDate( todayDate.getDate() + expiredays );
	if(expiredays!=0) {
		document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
	}
	else {
		document.cookie = name + "=" + escape( value ) + "; path=/; "
	}
}


/* 플래시 구현을 위한 스크립트 */
function FlashEolas(FlashWidth,FlashHeight,FlashURL,FlashVer)
{
	var ObjNo = "";
	if(document.getElementById("FlashEolasSwfBasic1")==null) {
		ObjNo = 1;
	}
	else {
		for(var i=1;i<15;i++) {
			if(document.getElementById("FlashEolasSwfBasic"+i)==null) {
				ObjNo = i;
				break;
			}
		}
	}
	
	//if(FlashVer==null||FlashVer=="") { FlashVer = "7"; }
	FlashVer = 9;
	document.write("<object style='z-index:1;' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=" + FlashVer + ",0,0,0' width='" + FlashWidth + "' height='" + FlashHeight + "' id='FlashEolasSwfBasic"+ObjNo+"'><param name='movie' value='" + FlashURL + "'><param name='quality' value='high'><param name='wmode' value='transparent'><param name='allowScriptAccess' value='always'><embed src='" + FlashURL + "' quality='high' wmode='transparent' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='" + FlashWidth + "' height='" + FlashHeight + "' allowScriptAccess='always' name='FlashEolasSwfBasic"+ObjNo+"'></embed></object>")
}


// iframe resize
function do_resize(obj) {
	if($(obj)!=null) {
		resize_iframe(obj);
	}
}
function do_resize_people(obj,innerObj) {
	if($(obj)!=null) {
		resize_iframe_people(obj,innerObj);
	}
}

function resize_iframe(iframeID) {
	moz = document.getElementById && !document.all;
	document.getElementById(iframeID).height = 1; // required for Moz bug, value can be "", null, or integer
	if(moz==false) {
		document.getElementById(iframeID).height = window.frames[iframeID].document.body.scrollHeight;
	}
	else {
		mozHeightOffset = 20;
		document.getElementById(iframeID).height = document.getElementById(iframeID).contentWindow.document.body.scrollHeight;

	}
	

}
function resize_iframe_people(iframeID,innerObj) {
	moz = document.getElementById && !document.all;
	document.getElementById(iframeID).height = 1; // required for Moz bug, value can be "", null, or integer
	if(moz==false) {
		document.getElementById(iframeID).height = window.frames[iframeID].document.body.scrollHeight;
		document.getElementById(iframeID).focus();
	}
	else {
		mozHeightOffset = 20;
		document.getElementById(iframeID).height = document.getElementById(iframeID).contentWindow.document.body.scrollHeight + mozHeightOffset;
		innerObj.focus();

	}
	

}






/**
 *	문자열에서 원하는 길이(byte형식)를 돌려줍니다.
 *	@return int length
 *	@ IE,FF 에서 확인됨
 */
String.prototype.bytes = function(str) {
	str = this != window ? this : str; len = 0;
	for(var i=0; i < str.length; i++) {
		len += (str.charCodeAt(i) > 128) ? 2 : 1
	}
	return len;
}

/**
 *	문자열에서 원하는 길이(byte형식)만큼 잘라내어 돌려준다.
 *	@param Int (byte의 길이)
 *	@return String
 *	@ IE,FF 에서 확인됨
 */
String.prototype.cut = function(len,str) {
	str = this != window ? this : str;
	var l = 0;
	for (var i=0; i<str.length; i++) {
			l += (str.charCodeAt(i) > 128) ? 2 : 1;
			if (l > len) return str.substring(0,i);
	}
	return str;
}



function getByteLength(input) {
	var byteLength = 0;
	for (var inx = 0; inx < input.length; inx++) {
		var oneChar = escape(input.charAt(inx));
		if ( oneChar.length == 1 ) {
			byteLength ++;
		} else if (oneChar.indexOf("%u") != -1) {
			byteLength += 2;
		} else if (oneChar.indexOf("%") != -1) {
			byteLength += oneChar.length/3;
		}
	}
	return byteLength;
}




function isValidId(str)  {
	var re=new RegExp("^[_a-zA-Z0-9]{4,20}$","gi");
    var matchArray=str.match(re);
    if (matchArray) return true;
    else return false;
}


function isValidEngNum(str)  {
	len = str.length; 
	ch = str.charAt(0); 

	for(i = 0; i < len; i++)  { 
		ch = str.charAt(i); 
		if( (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') )  { 
			continue; 
		} 
		else  { 
			return false; 
		} 
	}

	return true; 
}

function isValidEmail(str) 
{
    var re=new RegExp("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$","gi");
    var matchArray=str.match(re);
    if (matchArray) return true;
    else return false;
}


function isValidMobile(str) 
{
	var re=new RegExp("^([0]{1}[1]{1}[167890]{1})-?([1-9]{1}[0-9]{2,3})-?([0-9]{4})$","gi");
    var matchArray=str.match(re);
    if (matchArray) return true;
    else return false;
}

function isNumeric(str){
    var matchArray=str.match(/^\d+$/ig)
    if (matchArray) return true;
    else return false;
}


function checkCR(obj,maxLine) 
{

	var str_line = obj.value;
	line = str_line.split("\n");
	ln = line.length;
	if(ln == maxLine && event.keyCode == 13) {
		alert(maxLine+"줄까지만 입력가능합니다");
		event.returnValue = false;
	}


}

function isObject(a) {
    return (a && typeof a == 'object') || isFunction(a);
}

function isFunction(a) {
    return typeof a == 'function';
}

 //① 입력필드에 숫자키, 삭제키, 방향키, 탭키, 홈, 엔드키 만 입력할수 있음.
function handlerNum( obj ) {
//숫자만 입력 받게끔 하는 함수.
  e = window.event; //윈도우의 event를 잡는것입니다.
//  alert(e.keyCode);

   //입력 허용 키
  if( ( e.keyCode >=  48 && e.keyCode <=  57 ) ||   //숫자열 0 ~ 9 : 48 ~ 57
( e.keyCode >= 96 && e.keyCode <= 105 ) || //키패드 0 ~ 9 : 96 ~ 105
        e.keyCode ==   8 ||    //BackSpace
        e.keyCode ==  46 ||    //Delete
        e.keyCode == 110 ||    //소수점(.) : 문자키배열
        e.keyCode == 190 ||    //소수점(.) : 키패드
        e.keyCode ==  37 ||    //좌 화살표
        e.keyCode ==  39 ||    //우 화살표
        e.keyCode ==  35 ||    //End 키
        e.keyCode ==  36 ||    //Home 키
        e.keyCode ==   9       //Tab 키
    ) {
  
    if(e.keyCode == 48 || e.keyCode == 96) { //0을 눌렀을경우
      if ( obj.value == "" || obj.value == '0' ) //아무것도 없거나 현재 값이 0일 경우에서 0을 눌렀을경우
        e.returnValue=false; //-->입력되지않는다.
      else //다른숫자뒤에오는 0은
        return; //-->입력시킨다.
      }
      
    else if ( e.keyCode == 110 || e.keyCode == 190 ) { //소수점을 눌렀을 경우
      if ( obj.value == "" ) {  //아무것도 없는 상태에서 소수점을 입력했을경우 "0."으로 표기
        obj.value = "0";
        return;
      }
      
      if ( obj.value.indexOf(".") != -1 ) {  //기존에 소수점이 들어있다면
        e.returnValue=false;                 //입력시키지 않는다.
      }
    }
    else //0이 아닌숫자
      return; //-->입력시킨다.
    }
    else //숫자가 아니면 넣을수 없다.
  e.returnValue=false;
}
/**
 * 입력값이  null 인지 체크한다
 */
function isNull(input){
       if (input.value == null || input.value == ""){
             return true;
       }else{
             return false;
       }
}
/**
 * 입력값이 스페이스 이외의 의미있는 값이 있는지 체크한다
 * if (isEmpty(form.keyword)){
 *       alert('값을 입력하여주세요');
 * }
 */
function isEmpty(input){
       if (input.value == null || input.value.replace(/ /gi,"") == ""){
             return true;
       }else{
             return false;
       }
}

/**
 * 입력값이 사용자가 정의한 포맷 형식인지 체크
 * 자세한 format 형식은 자바스크립트의 'reqular expression' 참고한다
 */
function isValidFormat(input, format){
       if (input.value.search(format) != -1){
             return true; // 올바른 포멧형식
       }      
       return false;
}

/**
 * 입력값이 이메일 형식인지 체크한다
 * if (!isValidEmail(form.email)){
 *       alert("올바른 이메일 주소가 아닙니다");
 * }
 */
 /*
function isValidEmail(input){
       var format = /^((\w|[\-\.])+)@((\w|[\-\.])+)\.([A-Za-z]+)$/;
       return isValidFormat(input, format);
}
*/
/**
 * 입력값이 전화번호 형식(숫자-숫자-숫자)인지 체크한다
 */
function isValidPhone(input){
       var format = /^(\d+)-(\d+)-(\d+)$/;
       return isValidFormat(input, format);
}
/**
 * 입력값의 바이트 길이를 리턴한다.
 * if (getByteLength(form.title) > 100){
 *    alert("제목은 한글 50자 (영문 100자) 이상 입력할수 없습니다");
 * }
 */