﻿ //-----------------------------------------------------------------------------
 // 문자의 좌, 우 공백 제거
 // @return : String
 //-----------------------------------------------------------------------------
 String.prototype.trim = function() {
     return this.replace(/(^\s*)|(\s*$)/g, "");
 }

 //-----------------------------------------------------------------------------
 // 문자의 좌 공백 
 // @return : String
 //-----------------------------------------------------------------------------
 String.prototype.ltrim = function() {
     return this.replace(/(^\s*)/, "");
 }
 
 //-----------------------------------------------------------------------------
 // 문자의 우 공백 제거
 // @return : String
 //-----------------------------------------------------------------------------
 String.prototype.rtrim = function() {
     return this.replace(/(\s*$)/, "");    
 }

 //-----------------------------------------------------------------------------
 // 문자열의 byte 길이 반환
 // @return : int
 //-----------------------------------------------------------------------------
 String.prototype.byte = function() {
     var cnt = 0;
     for (var i = 0; i < this.length; i++) {

         if (this.charCodeAt(i) > 127)
             cnt += 2;
         else
             cnt++;
     }
     return cnt;
 }

 //-----------------------------------------------------------------------------
 // 정수형으로 변환
 // @return : String
 //-----------------------------------------------------------------------------

 String.prototype.int = function() {

     if(!isNaN(this)) {
         return parseInt(this, 10);
     }
     else {
         return null;    
     }
 }

 //-----------------------------------------------------------------------------
 // 숫자만 가져 오기 
 // @return : String
 //-----------------------------------------------------------------------------

 String.prototype.num = function() {
     return (this.trim().replace(/[^0-9]/g, "")); 
 }

 //-----------------------------------------------------------------------------
 // 숫자에 3자리마다 , 를 찍어서 반환
 // @return : String
 //-----------------------------------------------------------------------------

 String.prototype.cvtNumber = function() {
     var num = this.trim();
     while((/(-?[0-9]+)([0-9]{3})/).test(num)) {
         num = num.replace((/(-?[0-9]+)([0-9]{3})/), "$1,$2");
     }
     return num;
 }

 //-----------------------------------------------------------------------------
 // 숫자의 자리수(cnt)에 맞도록 반환
 // @return : String
 //-----------------------------------------------------------------------------

 String.prototype.digits = function(cnt) {
     var digit = "";
     if (this.length < cnt) {
         for(var i = 0; i < cnt - this.length; i++) {
             digit += "0";
         }
     }
     return digit + this;
 }

 //-----------------------------------------------------------------------------
 // " -> &#34; ' -> &#39;로 바꾸어서 반환
 // @return : String
 //-----------------------------------------------------------------------------

 String.prototype.quota = function() {

     return this.replace(/"/g, "&#34;").replace(/'/g, "&#39;");

 }

 //-----------------------------------------------------------------------------
 // html 제거
 // @return : String
 //-----------------------------------------------------------------------------

 String.prototype.stripHtml = function() {
	 return this.replace(/(<([^>]+)>)/ig,"");
 }
 
 //-----------------------------------------------------------------------------
 // 파일 확장자만 가져오기
 // @return : String
 //-----------------------------------------------------------------------------

 String.prototype.ext = function() {
     return (this.indexOf(".") < 0) ? "" : this.substring(this.lastIndexOf(".") + 1, this.length);    
 }

 //-----------------------------------------------------------------------------
 // URL에서 파라메터 제거한 순수한 url 얻기
 // @return : String
 //-----------------------------------------------------------------------------    

 String.prototype.uri = function() {

     var arr = this.split("?");
     arr = arr[0].split("#");
     return arr[0];    

 }


/*------------------------------------------------------------------------------*\
* 각종 체크 함수들
\*--------------------------------------------------------------------------------*/

 //-----------------------------------------------------------------------------
 // 정규식에 쓰이는 특수문자를 찾아서 이스케이프 한다.
 // @return : String
 //-----------------------------------------------------------------------------

 String.prototype.meta = function() {

     var str = this;
     var result = ""
     for(var i = 0; i < str.length; i++) {
         if((/([\$\(\)\*\+\.\[\]\?\\\^\{\}\|]{1})/).test(str.charAt(i))) {
             result += str.charAt(i).replace((/([\$\(\)\*\+\.\[\]\?\\\^\{\}\|]{1})/), "\\$1");
         }
         else {
             result += str.charAt(i);
         }
     }
     return result;
 }

 //-----------------------------------------------------------------------------
 // 정규식에 쓰이는 특수문자를 찾아서 이스케이프 한다.
 // @return : String
 //-----------------------------------------------------------------------------

 String.prototype.remove = function(pattern) {
     return (pattern == null) ? this : eval("this.replace(/[" + pattern.meta() + "]/g, \"\")");
 }

 //-----------------------------------------------------------------------------
 // 최소 최대 길이인지 검증
 // str.isLength(min [,max])
 // @return : boolean
 //-----------------------------------------------------------------------------

 String.prototype.isLength = function() {

     var min = arguments[0];
     var max = arguments[1] ? arguments[1] : null;
     var success = true;
     if(this.length < min) {
         success = false;
     }
     if(max && this.length > max) {
         success = false;
     }
     return success;
 }

 //-----------------------------------------------------------------------------
 // 최소 최대 바이트인지 검증
 // str.isByteLength(min [,max])
 // @return : boolean
 //-----------------------------------------------------------------------------

 String.prototype.isByteLength = function() {
     var min = arguments[0];
     var max = arguments[1] ? arguments[1] : null;
     var success = true;
     if(this.byte() < min) {
         success = false;
     }

     if(max && this.byte() > max) {
         success = false;
     }
     return success;
 }

 //-----------------------------------------------------------------------------
 // 공백이나 널인지 확인
 // @return : boolean
 //-----------------------------------------------------------------------------

 String.prototype.isBlank = function() {
     var str = this.trim();
     for(var i = 0; i < str.length; i++) {
         if ((str.charAt(i) != "\t") && (str.charAt(i) != "\n") && (str.charAt(i)!="\r")) {
             return false;
         }
     }
     return true;
 }

 //-----------------------------------------------------------------------------
 // 숫자로 구성되어 있는지 학인
 // arguments[0] : 허용할 문자셋
 // @return : boolean
 //-----------------------------------------------------------------------------

 String.prototype.isNum = function() {
     return (/^[0-9]+$/).test(this.remove(arguments[0])) ? true : false;
 }
 

 //-----------------------------------------------------------------------------
 // 영어만 허용 - arguments[0] : 추가 허용할 문자들
 // @return : boolean
 //-----------------------------------------------------------------------------

 String.prototype.isEng = function() {
     return (/^[a-zA-Z]+$/).test(this.remove(arguments[0])) ? true : false;
 }
 
 //-----------------------------------------------------------------------------
 // 영어와&nbsp; 만 허용 - arguments[0] : 추가 허용할 문자들
 // @return : boolean
 //-----------------------------------------------------------------------------

 String.prototype.isblankEng = function() {
     return (/^[a-zA-Z\s]+$/).test(this.remove(arguments[0])) ? true : false;
 }

 //-----------------------------------------------------------------------------
 // 숫자와 영어만 허용 - arguments[0] : 추가 허용할 문자들
 // @return : boolean
 //-----------------------------------------------------------------------------

 String.prototype.isEngNum = function() {
     return (/^[0-9a-zA-Z]+$/).test(this.remove(arguments[0])) ? true : false;
 }

 //-----------------------------------------------------------------------------
 // 숫자와 영어만 허용 - arguments[0] : 추가 허용할 문자들
 // @return : boolean
 //-----------------------------------------------------------------------------

 String.prototype.isNumEng = function() {
     return this.isEngNum(arguments[0]);
 }

 //-----------------------------------------------------------------------------
 // 아이디 체크 영어와 숫자만 체크 첫글자는 영어로 시작 - arguments[0] : 추가 허용할 문자들
 // @return : boolean
 //-----------------------------------------------------------------------------

 String.prototype.isUserid = function() {

     return (/^[0-9a-zA-Z]+$/).test(this.remove(arguments[0])) ? true : false;

 }

 //-----------------------------------------------------------------------------
 // 이메일의 유효성을 체크
 // @return : boolean
 //-----------------------------------------------------------------------------

 String.prototype.isEmail = function() {
     return (/\w+([-+.]\w+)*@\w+([-.]\w+)*\.[a-zA-Z]{2,4}$/).test(this.trim());
 }

 //-----------------------------------------------------------------------------
 // 전화번호 체크 - arguments[0] : 전화번호 구분자
 // @return : boolean
 //-----------------------------------------------------------------------------
 String.prototype.isPhone = function() {
     var arg = arguments[0] ? arguments[0] : "";
     return eval("(/(02|0[3-9]{1}[0-9]{1})" + arg + "[1-9]{1}[0-9]{2,3}" + arg + "[0-9]{4}$/).test(this)");
 }

 //-----------------------------------------------------------------------------
 // 핸드폰번호 체크 - arguments[0] : 핸드폰 구분자
 // @return : boolean
 //-----------------------------------------------------------------------------

	String.prototype.isMobile = function() {
     var arg = arguments[0] ? arguments[0] : "";
     return eval("(/01[016789]" + arg + "[1-9]{1}[0-9]{2,3}" + arg + "[0-9]{4}$/).test(this)");

	}
 
 
 //-----------------------------------------------------------------------------
 // replaceAll 사용자 정의 함수
 //-----------------------------------------------------------------------------

	String.prototype.replaceAll = function( searchStr, replaceStr ) 
	{ 
	    var temp = this; 
	    while( temp.indexOf( searchStr ) != -1 ) 
	    {     
	        temp = temp.replace( searchStr, replaceStr ); 
	    } 
	    return temp; 
	} 

	String.prototype.wordwrap = function(options){
	  if (this == null || this == "") return "";
	
	  var text = this;
	  if (options['byte_length'] != null)
	    text = text.multibyteTruncate(options['byte_length']);
	  text = text.split("").join("<wbr/>");
	  return options['break_line'] ? text.replace(/\n/g, "<br/>") : text;
	}


 //-----------------------------------------------------------------------------
 // 설명 : 폼에서 공백 체크해서 공백이면 메세지 보여지고 해당 폼값에 포커스
 // 예) checkSpace(frm,strMsg) checkSpace(폼.이름, 메세지)
 // 리턴) 공백이 아니면 true | 공백이면 false 
 //-----------------------------------------------------------------------------

function checkSpace(frm, strMsg, blnFocus) {
	if(frm.val().isBlank()){
		alert(strMsg);
		frm.val("");
		frm.focus();
		return false;
	}
	return true;
}


/************************************************************
설명 : 새창 띄워서 포커스 주기
예) windowOpen('주소','윈도우이름',가로,세로,'기타 설정')
,scrollbars=yes ,personalbar=no ,resizable=no ,directories=no ,status=no ,menubar=no
************************************************************/
function windowOpen(pUrl,pName,pW,pH,val){
	var winWidth  = window.screen.width;    //해상도가로
	var winHeight  = window.screen.height;     //해상도세로
	// XP인 경우 height 29 추가
	//if( window.navigator.userAgent.indexOf("SV1") != -1 ) {
	//	pH += 29;
	//}
	
	var pLeft,pTop;
	pLeft = parseInt((winWidth-pW)/2);
	pTop = parseInt((winHeight-pH)/2);
	
	var newWin=window.open(pUrl,pName,"width="+pW+",height="+pH+",left="+pLeft+",top="+pTop+" "+ val );
	newWin.focus(); 
}

/*******************************************************************
* 날짜 비교 함수
* sDate: 비교 대상 날짜 첫번째 ex: 2009-04-29 
* eDate : 비교 대상 날짜 두번째 ex: 2009-04-28 
*******************************************************************/
function compDate(sDate,eDate){
	var start_dates = sDate.split("-");
  var end_dates = eDate.split("-");
  var date1 = new Date(start_dates[0],start_dates[1],start_dates[2]).valueOf();
  var date2 = new Date(end_dates[0],end_dates[1],end_dates[2]).valueOf();
  if( (date2 - date1) < 0 ){
   	return false;
  }else{
  	return true;
  }
}


function windowOpenRtn(pUrl,pName,pW,pH,val){
	var winWidth  = window.screen.width;    //해상도가로
	var winHeight  = window.screen.height;     //해상도세로
	
	// XP인 경우 height 29 추가
	//if( window.navigator.userAgent.indexOf("SV1") != -1 ) {
	//	pH += 29;
	//}
	
	var pLeft,pTop;
	pLeft = parseInt((winWidth-pW)/2);
	pTop = parseInt((winHeight-pH)/2);
	
	var newWin=window.open(pUrl,pName,"width="+pW+",height="+pH+",left="+pLeft+",top="+pTop+" "+ val );
	newWin.focus(); 
	return newWin;
}

/***** 입력되면 다음으로 이동 *******/
function nextChk(arg,len,nextname) { 
	if (arg.value.length==len) {
		nextname.focus() ;
		return;
	}
}
	
	

/**********************************************************
name (form.이름 ) , ivalue(Value)
예) optionValueSel(form.job , 2)
해당 옵션에서 밸류값 같은것을 셀렉트 시킨다.
 *********************************************************/
function optionValueSel(name,ivalue)
{
	var i,sel = 0;
	for(i=0;i<name.length;i++)
	{
		if(name.options[i].value == ivalue ) {
			sel = i;
		}
	}
	name.options[sel].selected = true  
}


/**********************************************************
예) optionValueRtn(form.name)
해당 옵션에서 선택된 밸류값을 리턴 시킨다.
 *********************************************************/
function optionValueRtn(name)
{
	var name_value = "";
  
	for(i=0;i<name.length;i++)
	{
		if ( name[i].selected == true ) 
		{
			name_value = name[i].value;
		}
	}
	return name_value;
}

/**********************************************************
예) optionTextRtn(form.name)
해당 옵션에서 선택된 텍스트값을 리턴 시킨다.
 *********************************************************/
function optionTextRtn(name){
	var name_value = "";
  
	for(i=0;i<name.length;i++)
	{
		if ( name[i].selected == true ) 
		{
			name_value = name[i].text;
		}
	}
	return name_value;
}

/**********************************************************
예) optionSelectedCnt(form.name)
select에서 선택된 option의 갯수를 리턴 시킨다.
 *********************************************************/
function optionSelectedCnt(name){
	var cnt = 0;
  
	for(i=0;i<name.length;i++)
	{
		if ( name[i].selected == true ) 
		{
			cnt++;
		}
	}
	return cnt;
}

/**********************************************************
예) optionSelectedCnt(form.name)
select에서 선택된 option의 갯수를 리턴 시킨다.
 *********************************************************/
function selectedCnt(name){
	var cnt = 0;
	if(name){
		if(!name.length) {
			if(name.checked) {
				cnt++;
			}
		}else{	
			for(i=0;i<name.length;i++)
			{
				if ( name[i].checked == true ) 
				{
					cnt++;
				}
			}
		}
	}
	return cnt;
}


/************************************************************
예) checkRadio(name)
라디오 버튼에서 선택한 것의 밸류값을 리턴한다
선택한것이 없다면 "" 공백을 리턴한다.
************************************************************/
function checkRadio(name) {
	var radio = document.getElementsByName(name);
	if (radio) {
		if (!radio.length) {
			if (radio.checked) {
				return radio.value;
			}
		} else {
			for (var i = 0; i < radio.length; i++) {
				if (radio[i].checked) {
					return radio[i].value;
				}
			}
		}
	}
	return "";
}


/*************************************************************
예) checkInsert ( name (form이름 ) , ivalue(Int형 Value) )
radio나 checkbox 에서 해당 밸류값과 같은것이 선택 되도록 한다.
 ************************************************************/
function checkInsert(name,ivalue)
{
	if(name){
		if(!name.length) {
			if(name.value == ivalue) {
				name.checked = true;
			}
		} else {
			for(var i=0;i<name.length;i++) {
				if(name[i].value == ivalue) {
					name[i].checked = true;
				}
			}
		}
	}
}

//체크상자 초기화 체크된것을 모두 false 로 한다.
function checkInit(name)
{
	if(name){
		if(!name.length) {
			name.checked = false;
		} else {
			for(var i=0;i<name.length;i++) {
				name[i].checked = false;
			}
		}
	}
}


//이미지 자동 리사이즈 처리
var arrObjImg = new Array(); //이미지객체 담을 배열

function set_onload_resize(img,resizeWidth){
	var imgLen = arrObjImg.length;
	arrObjImg[imgLen] = new imgClass(img, resizeWidth);
	resize_img(imgLen);
}

function imgClass(img,resizeWidth){
	this.img = img;
	this.resizeWidth = resizeWidth;
}

function resize_img(idx){
	var objImg = arrObjImg[idx].img;
	var resizeWidth = arrObjImg[idx].resizeWidth;
	if (objImg) {
		if(objImg.complete == false){//이미지가 로드 되지 않았다면
			setTimeout("resize_img("+idx+")",100);
		}else{
			if(objImg.width>resizeWidth){
				objImg.height = parseInt((resizeWidth * objImg.height) / objImg.width);
				objImg.width = resizeWidth;
				if (objImg.style.width)
					objImg.style.width = resizeWidth;
				if (objImg.style.Height)
					objImg.style.height = parseInt((resizeWidth * objImg.height) / objImg.width);
				//objImg.onclick = function(){window.open(objImg.src);}
			}
		}
			
	}
}


//쓰기 document.write 
function dw(str){
	document.write(str); 
}


//익스플로러 패치에 따른 플래시 스크립로 write 처리
//(플래시주소,넓이,높이,넘겨받은값,아이디,이름,배경색)
function flashWrite(fSrc,sWidth,sHeight,fVars,fId,fName,fBgcolor){
	
	var strFlash;
	
	strFlash ='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0"';
	strFlash += ' id="'+fId+'" name="'+fName+'"';
	strFlash += ' width="'+sWidth+'" height="'+sHeight+'">';  
	strFlash += '<param name=flashVars value="'+fVars+'">';        
	strFlash += '<param name="movie" value="'+fSrc+'">';
	strFlash += '<param name="wmode" value="transparent">';
	strFlash += '<param name=bgcolor value="'+fBgcolor+'">';   
	strFlash += '<param name="quality" value="high">';
	strFlash += '<param name="menu" value="false">';
	strFlash += '<embed src="'+fSrc+'" quality="high" swLiveConnect=true pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"';
	strFlash += ' id="'+fId+'" name="'+fName+'"';	
	strFlash += ' width="'+sWidth+'" height="'+sHeight+'">';
	strFlash += '</embed></object>';
	
	document.write(strFlash);
}


/*
폼안에 있는 값들을 인코딩해서 리턴한다.
예) formData2QueryString(document.pageForm)
리턴) gotoPage=3&col=1&search=
*/
function formData2QueryString(docForm) {

	var submitContent = '';
	var formElem;
	var lastElemName = '';
	for (i = 0; i < docForm.elements.length; i++) {
    
		formElem = docForm.elements[i];

		switch (formElem.type) {
			// Text fields, hidden form elements
			case 'text':
			case 'hidden':
			case 'password':
			case 'textarea':
			case 'select-one':
				submitContent += formElem.name + '=' + escape(formElem.value) + '&'
				break;
        
			// Radio buttons
			case 'radio':
				if (formElem.checked) {
					submitContent += formElem.name + '=' + escape(formElem.value) + '&'
				}
				break;
        
			// Checkboxes
			case 'checkbox':
				if (formElem.checked) {
					// Continuing multiple, same-name checkboxes
					if (formElem.name == lastElemName) {
						// Strip of end ampersand if there is one
						if (submitContent.lastIndexOf('&') == submitContent.length-1) {
							submitContent = submitContent.substr(0, submitContent.length - 1);
						}
						// Append value as comma-delimited string
						submitContent += ',' + escape(formElem.value);
					}else {
						submitContent += formElem.name + '=' + escape(formElem.value);
					}
					submitContent += '&';
					lastElemName = formElem.name;
				}
			break;
		}
	}

	// Remove trailing separator
	submitContent = submitContent.substr(0, submitContent.length - 1);
	return submitContent;
}


/************************************************************
  함수 : window_center(넓이,높이)
  목적 : 예약창의 사이즈 조절
  방법 : window_center (넓이,높이)
          예) window_center(100,100)
        
************************************************************/

function window_center(w, h) { 
	
		width=screen.width;
		height=screen.height;
	
		x=(width/2)-(w/2);
		y=(height/2)-(h/2);
	
		window.resizeTo(w,h);
		window.moveTo(x,y);
	}

function getWeekEnd(str)
{
	var weekInfo = new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
	d = toTimeObject(str);
	day=d.getDay();
	
	return weekInfo[day];
}	

function lastday(calyear, calmonth)
{
var monthDays = new Array(31, 28, 31, 30, 31, 30, 31, 31,30, 31, 30, 31);
if (((calyear % 4 == 0) && (calyear % 100 != 0)) || (calyear % 400 == 0))
monthDays[1] = 29;
var nDays = monthDays[calmonth - 1];
return nDays;
}

function toTimeObject(time){
	var year = time.substr(0,4);
	var month = time.substr(4,2)-1;
	var day = time.substr(6,2);
	
	return new Date(year,month,day);
}

function GetSelectedVal(objSelect){
        var i;
        var selectedval ;
        for(i=0;i<objSelect.options.length;i++){
                if(objSelect.options[i].selected==true){
                        selectedval = objSelect.options[i].value;
                        break;
                }
        }
        return selectedval ;
}

function GetSelectedTxt(objSelect){
        var i;
        var selectedtext;
        for(i=0;i<objSelect.options.length;i++){
                if(objSelect.options[i].selected==true){
                        selectedtext= objSelect.options[i].text;
                        break;
                }
        }
        return selectedtext;
}

function allblur() {
	for (i = 0; i < document.links.length; i++) {
		var obj = document.links[i];
		if(obj.addEventListener) obj.addEventListener("focus", oneblur, false);
		else if(obj.attachEvent) obj.attachEvent("onfocus", oneblur);
	}
}
function oneblur(e) {
	var evt = e ? e : window.event;
	if(evt.target) evt.target.blur();
	else if(evt.srcElement) evt.srcElement.blur();
}

/* 
*Source Select의 요소(option)를 Target Select로 이동한다. 
*@author neoburi@nowonplay.com, 2005.12.27 
*/ 
function moveElement(sourceObj, targetObj, isSort){ 
	var elms = sourceObj.options; 
	for(i = 0, k = elms.length; i < k; i++){ 
		if( elms[i].selected ){ 
		targetObj.add(new Option(elms[i].text, elms[i].value, false, false)); 
		} 
	} 
	removeElement(sourceObj); 
	sourceObj.selectedIndex = -1; 
} 

/* 
*Source Select의 요소(option)를 제거한다. 
*@author neoburi@nowonplay.com, 2005.12.27 
*/ 
function removeElement(sourceObj){ 
	var elms = sourceObj.options; 
	var posArr = new Array(); 
	var increase = 0; 
	for( i = 0, k = elms.length; i < k; i++ ){ 
		if( elms[i].selected ){ 
			posArr[increase++] = elms[i].value; 
		} 
	} 
	for( i = 0, k = posArr.length; i < k; i++ ){ 
		for( x = 0, y = elms.length; x < y; x++ ){ 
			if( (posArr[i] == elms[x].value) && elms[x].selected ){ 
				sourceObj.remove(x); 
				x = 0; 
				y--; 
			} 
		} 
	} 
} 

/* 
*Source Select의 요소(option)의 상하순서를 바꾼다. 
*@author 아무게, 2005.12.27 
*/ 
function move_option_in(src,to) { 
	if(!src) return; 
	var src_index = src.selectedIndex; 
	if(src_index<0) return; 
	if(to == "up"){ 
		if(src_index==-1||src_index==0) return; 
		var tempoption = new Option(src.options[src_index].text, src.options[src_index].value); 
		src.options[src_index] = new Option(src.options[src_index-1].text, src.options[src_index-1].value); 
		src.options[src_index-1]=tempoption; 
		src.options[src_index-1].selected=true; 
	} 
	else if(to == "down"){ 
		if(src_index>=src.options.length-1) return; 
		var tempoption = new Option(src.options[src_index].text, src.options[src_index].value); 
		src.options[src_index] = new Option(src.options[src_index+1].text, src.options[src_index+1].value); 
		src.options[src_index+1]=tempoption; 
		src.options[src_index+1].selected=true; 
	} 
} 




/********************************************************************
object의 Left Position을 리턴한다.
********************************************************************/
function g_getLeftPos(obj) {
    var parentObj = null;
    var clientObj = obj;
    var left = obj.offsetLeft + document.body.clientLeft;

    while((parentObj=clientObj.offsetParent) != null){
        left = left + parentObj.offsetLeft;
        clientObj = parentObj;
    }
    return left;
}

/********************************************************************
object의 Top Position을 리턴한다.
********************************************************************/
function g_getTopPos(obj) {
    var parentObj = null;
    var clientObj = obj;
    var top = obj.offsetTop + document.body.clientTop;

    while((parentObj=clientObj.offsetParent) != null){
        top = top + parentObj.offsetTop;
        clientObj = parentObj;
    }
    return top;
}

/********************************************************************
코드값을 읽어온다
********************************************************************/
function g_getValue(obj) {
	if (typeof obj != "object") return null;
	if (select == null) return null;
	
  	return obj.options[obj.selectedIndex].value;
}


/*******************************************************************
objVal값 form file value 'C:\My Documents\My Pictures\감자도리\xxxx.jpg'
limitExt값 'jpg|gif|png|bmp' 
확장자가 해당하는 확장자가 아닐경우 리턴 false
*******************************************************************/

function fileExtCheck(objVal,limitExt){
	var val=objVal.toLowerCase();
	if(!val)
	    return false;
	fileExt = val.substr(val.lastIndexOf('.') + 1,val.length);
	if(limitExt.indexOf(fileExt) == -1){
	    alert("확장자가 " + limitExt.replace(/\|/gi,",") + "를 제외한 파일을 선택 할 수 없습니다");
	    return false;
	}
	return true;
}


function n2c(num) {
	if (parseInt(num) < 10 && num.length < 2)
		return "0" + num;
	else
		return "" + num;
}


/*******************************************************************
태그 입력 : 공백, 한글&영문 제외, 글자수 체크
*******************************************************************/
function TagSearchCheck(objVal1, objVal2, objVal3, strLength)
{
	if( (objVal1.value.length == 0) && (objVal2.value.length == 0) && (objVal3.value.length == 0) )
	{
		alert('태그를 1개이상 입력해 주세요!');
		objVal1.focus();
		return;
	}
	
	for(h=1; h <=3 ; h++)
	{
		var objVal = eval('objVal' + h);
		
		if(objVal.value.length > 0)
		{
		
			//공백제거
			var str = objVal.value;
			
			if (str.search(/\S/)<0){			//\S 공백이 아닌 문자를 찾는다.
				alert('공백문자는 입력할 수 없습니다.');
				objVal.focus();
				return false;
			}
			
			var temp=str.replace(' ','');
			if (str.indexOf(' ') > 0){
				alert('공백문자는 입력할 수 없습니다.');
				objVal.focus();
				return false;
			}
			
			var hFlag = true;
			var eFlag = false;
			// 한글 입력체크
			for(i=0;i<=str.length;i++){
				if(str.charCodeAt(i)<12644){
					hFlag = false;
					objVal.focus();
					break;
				}
			}
			
			// 영문 & 숫자 입력체크
			var strCheck='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890';
			for(i=0; i<str.length; i++) {
				for(j=0; j<strCheck.length; j++) {
					if(str.charAt(i) == strCheck.charAt(j)){
						eFlag = true;
						objVal.focus();
						break;
					}
				}
			}
			
			if(hFlag == false && eFlag == false)
			{
				alert('한글 및 영문만 입력할 수 있습니다!');
				objVal.focus();
				return;
			}
			
			if(str.length > strLength)
			{
				alert('최대 7자까지 입력할 수 있습니다.');
				objVal.focus();
				return false;
			}
		
		}
	
	}
	
	if( objVal2.value.length > 0 )
	{
		if( (objVal1.value == objVal2.value) || (objVal1.value == objVal3.value) || (objVal2.value == objVal3.value) )
		{
			alert('동일한 태그를 입력할 수 없습니다!');
			return;
		}
	}
	else if( objVal3.value.length > 0 )
	{
		if( objVal1.value == objVal3.value )
		{
			alert('동일한 태그를 입력할 수 없습니다!');
			return;
		}
	}
	
	return true;
}



function isNextChar(str, pos) {
	var code1 = str.charAt(pos).charCodeAt(0);
	var code2 = str.charAt(pos + 1).charCodeAt(0);
	//alert(str.charAt(pos) + " " + code1 + " - " + str.charAt(pos+1) + " " + code2 + " " + (code1 == (code2 - 1)));
	if (code1 == (code2 - 1))
		return true;
	else
		return false;
}

function isPreviousChar(str, pos) {
	var code1 = str.charAt(pos).charCodeAt(0);
	var code2 = str.charAt(pos + 1).charCodeAt(0);
	//alert(str.charAt(pos) + " " + code1 + " - " + str.charAt(pos+1) + " " + code2 + " " + (code1 == (code2 - 1)));
	if (code1 == (code2 + 1))
		return true;
	else
		return false;
}

function isContainSequentialString(str) {
	for (var i = 0; i < str.length - 3; i++) {
		if ((isNextChar(str, i) && isNextChar(str, i+1) && isNextChar(str, i+2)) ||
            (isPreviousChar(str, i) && isPreviousChar(str, i+1) && isPreviousChar(str, i+2)))
			return true;
	}
	return false;
}

function isContains(source, search) 
{
	if (source.search(search) != -1)
		return true;
	else
		return false;
} 

/*******************************************************************
파일업로드시 actionUrl을 리턴해준다 
예) http://aa.bb.co.kr/aaaa/bbb/ab.jsp 인경우
/aaaa/bbb 리턴
*******************************************************************/
function getActionUrl() {
	//action URL구하기
    var url = location.href;
		var urlArr = (url).split("/");
		url = "";
		for(i=3; i<urlArr.length-1; i++) {
			url += "/" + urlArr[i];
		}
		return url;
}


//우편번호 찾기 
function searchZipcodeAdmin(zipcode1FormName, zipcode2FormName, addrFormName) {
    windowOpen('/FvkAdminTool/Common/ZipcodePopup.aspx?Zipcode1FormName='+zipcode1FormName+'&Zipcode2FormName='+zipcode2FormName+'&AddrFormName='+addrFormName,'zipcodesearch',550,450,'');
}

//아이디 중복 체크 
function checkUserId(userIdFormName, UserIdCheckFormName, userId) {
    windowOpen('/FvkAdminTool/Member/CheckUserIDPopup.aspx?UserId='+ userId + '&UserIdFormName=' + userIdFormName + '&UserIdCheckFormName=' + UserIdCheckFormName, 'useridcheck', 300, 190, '');
}

//달력 아이콘 클릭
doClickbtnCal = function(id) {
    $("#"+id).click();
}

/************* Check Date ***************/

function cf_fmtDate(gubun){
	if((event.keyCode<48)||(event.keyCode>57))return false;
	var em=event.srcElement;	
	if((gubun==1)&&(em.value.length==4)){em.value=em.value+"-";return;}
	if(gubun==1){return;}
	if((em.value.length==4)||(em.value.length==7))em.value=em.value+"-";
}

function cf_chkDate(gubun){
	var val=event.srcElement.value;
	if(val.length==0)return;
	var yyyy=val.substr(0,4);
	var mm=val.substr(5,2)-1;
	var dd=val.substr(8,2);
	if(gubun==1){dd="01";}
	var d=new Date(yyyy,mm,dd);
	if(gubun==1){
		if((val.length!=7)||(d.getFullYear()!= yyyy)||(d.getMonth()!= mm)){
			alert("Invalid Date..");return false;
		}else{return;}
	}
	if((val.length!=10)||(d.getFullYear()!=yyyy)||(d.getMonth()!= mm)||(d.getDate()!= dd)){
		alert("Invalid Date..");return false;
	}
}

//디자이너 링크 붙여넣기 
function pasteDesignerLink(url) {
    oEditors.getById[textAreaId].exec("PASTE_HTML", [url]);
}

//멀티 이미지 업로드 
function pasteImages(html) {    
    oEditors.getById[textAreaId].exec("PASTE_HTML", [html]);
}

function doFlash(URL,width,height,vars,winmode)
{
	var id=URL.split("/")[URL.split("/").length-1].split(".")[0];
	if(vars==null) vars='';
	if(winmode==null) winmode='opaque';
	
	document.write("    <object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0' width='" + width + "' height='" + height+ "' id='"+id+"' align='middle'> ");
	document.write("    <param name='allowScriptAccess' value='sameDomain' /> ");
	document.write("    <param name='allowFullScreen' value='false' /> ");
	document.write("    <param name='movie' value=' " + URL + "' /> ");
	document.write("    <param name='FlashVars' value='" + vars + "' /> ");
	document.write("	<param name='wmode'	value='"+winmode+"' /> ");
	document.write("    <param name='quality' value='high' /> ");
	document.write("    <param name='bgcolor' value='#ffffff' /> ");	
	document.write("    <embed src='" + URL + "' flashVars='" + vars + "' quality='high' bgcolor='#ffffff' ");
	document.write("        wmode='" + winmode + "'width='" + width + "' height='" + height+ "' ");
	document.write("        name='" + id + "' align='middle' allowScriptAccess='sameDomain' allowFullScreen='false' ");
	document.write("        type='application/x-shockwave-flash' pluginspage='http://www.adobe.com/go/getflashplayer' /> ");
	document.write("    </object> ");
}

function doMsg(msg)
{
    alert(msg);
}

//print
doPrint = function() {
    if( navigator.appName.indexOf("Microsoft") > -1 ){
        if( navigator.appVersion.indexOf("MSIE 6") > -1){
            if(confirm("IE6 버전에서는 정상적으로 프린트가 되지 않을 수 있습니다.\n"
                + "Internet Explorer를 최신 버전으로 업데이트 하시거나, \n"
                + "프린트 용지옵션을 '가로'로 선택하여 프린트 하시면 잘림현상 없이 출력하실 수 있습니다.\n\n"
                + "Internet Explorer 최신 버전 다운로드 페이지로 연결하시겠습니까?")==true){
                window.open("http://www.microsoft.com/korea/windows/internet-explorer/?WT.mc_id=MicrosoftComKR_Homepage_MarCompo_IE8");
                location.reload();
                return false;
            }
        }
    }
    
    window.print();
}

function doBFlash(mode, idx, w, h)
{
    var sUrl = "/Board/BoardFlash.aspx?Mode=" + mode + "&idx=" + idx;
    var iW = eval(w);
    var iH = eval(h);
        
    windowOpen(sUrl, "BoardFlash", iW + 60, iH + 60, "fullscreen=yes,scrollbars=no,width=1000,height=700,left=30,top=30");
    //doView(mode, idx);
}

function doBPDF(mode, idx)
{
    var sUrl = "/Board/BoardPDFView.aspx?Mode=" + mode + "&idx=" + idx;
        
    windowOpen(sUrl, "BoardPDF", "", "", "fullscreen=yes,scrollbars=no,width=1000,height=700,left=30,top=30");
    //doView(mode, idx);
}

//이미지 리사이즈 
function img_resize(imgid, w, h){
	var fix_w = w;
	var fix_h = h;
	var pre_img = document.all[imgid];
	if(pre_img){
		if(pre_img.width>fix_w){
			pre_img.height = parseInt((fix_w * pre_img.height) / pre_img.width);
			pre_img.width=fix_w;
		}
		if(pre_img.height>fix_h) {
			pre_img.width = parseInt((fix_h * pre_img.width) / pre_img.height);
			pre_img.height=fix_h;		
			
		}
		for(var i = 0;i<pre_img.length;i++){
			if(pre_img[i].width>fix_w){
				pre_img[i].height = parseInt((fix_w * pre_img[i].height) / pre_img[i].width);
				pre_img[i].width=fix_w;
			}
			if(pre_img[i].height>fix_h) {
				pre_img[i].width = parseInt((fix_h * pre_img[i].width) / pre_img[i].height);
				pre_img[i].height=fix_h;		
				
			}
		}
	}	
}

//확대 이미지 보기 
function doZoomPop() {
    windowOpen("ImageZoomPop.aspx", "FVKzoom", 980, 800, "scrollbars=yes");
}